Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-04-30 22:24:06

0001 // -*- C++ -*-
0002 #ifndef FWCore_Framework_ESProductResolverProvider_h
0003 #define FWCore_Framework_ESProductResolverProvider_h
0004 //
0005 // Package:     Framework
0006 // Class  :     ESProductResolverProvider
0007 //
0008 /**\class edm::eventsetup::ESProductResolverProvider
0009 
0010  Description: Lowest level base class for modules which produce
0011               data for the EventSetup system.
0012 
0013  Usage:
0014 
0015     In most cases, the methods in this class are used exclusively by the
0016     Framework. Usually, EventSetup modules producing data inherit from
0017     the ESProducer base class which inherits from this class. The ESProducer
0018     base class takes care of overriding the registerResolvers function
0019     and calling usingRecord or usingRecordWithKey.
0020 
0021     In cases where the ESProducer base class is not used (PoolDBESSource/
0022     CondDBESSource is the main such class) then the registerResolvers
0023     function must be overridden. For the same EventSetupRecordKey, the
0024     vector returned should contain the same DataKeys in the same order for
0025     all the different iovIndexes. ESProductResolver's associated with the same
0026     EventSetupRecordKey should have caches that use different memory, but
0027     other than that they should also be the same.
0028 
0029     Classes that derive from this class should also call usingRecord
0030     or usingRecordWithKey in their constructor to announce the records
0031     they provide data for.
0032 
0033     All other functions are intended for use by the Framework or tests
0034     and should not be called in classes derived from ESProductResolverProvider.
0035     They are primarily used when initializing the EventSetup system
0036     so the ESProductResolver's are available for use when needed.
0037 */
0038 //
0039 // Author:      Chris Jones
0040 // Created:     Mon Mar 28 14:21:58 EST 2005
0041 //
0042 
0043 // system include files
0044 #include <memory>
0045 #include <set>
0046 #include <string>
0047 #include <vector>
0048 
0049 // user include files
0050 #include "FWCore/Framework/interface/DataKey.h"
0051 #include "FWCore/Framework/interface/ComponentDescription.h"
0052 #include "FWCore/Framework/interface/EventSetupRecordKey.h"
0053 #include "FWCore/Utilities/interface/propagate_const.h"
0054 
0055 // forward declarations
0056 namespace edm {
0057   class ConfigurationDescriptions;
0058   class ParameterSet;
0059 
0060   namespace eventsetup {
0061     class ESProductResolver;
0062     class ESRecordsToProductResolverIndices;
0063     class ESModuleProducesInfo;
0064 
0065     class ESProductResolverProvider {
0066     public:
0067       ESProductResolverProvider();
0068       ESProductResolverProvider(const ESProductResolverProvider&) = delete;
0069       const ESProductResolverProvider& operator=(const ESProductResolverProvider&) = delete;
0070       virtual ~ESProductResolverProvider() noexcept(false);
0071 
0072       class ESProductResolverContainer;
0073 
0074       class KeyedResolvers {
0075       public:
0076         KeyedResolvers(ESProductResolverContainer*, unsigned int recordIndex);
0077 
0078         bool unInitialized() const;
0079 
0080         EventSetupRecordKey const& recordKey() const;
0081 
0082         void insert(std::vector<std::pair<DataKey, std::shared_ptr<ESProductResolver>>>&&,
0083                     std::string const& appendToDataLabel);
0084 
0085         bool contains(DataKey const& dataKey) const;
0086 
0087         unsigned int size() const;
0088 
0089         // Not an STL iterator and cannot be used as one
0090         class Iterator {
0091         public:
0092           DataKey& dataKey() { return *dataKeysIter_; }
0093           ESProductResolver* productResolver() { return productResolversIter_->get(); }
0094           Iterator& operator++();
0095 
0096           bool operator!=(Iterator const& right) const { return dataKeysIter_ != right.dataKeysIter_; }
0097 
0098           // Warning: dereference operator does not return a reference to an element in a container.
0099           // The return type is nonstandard because the iteration is simultaneous over 2 containers.
0100           // This return type is used in "ranged-based for" loops.
0101           struct KeyedResolver {
0102             KeyedResolver(DataKey& dataKey, ESProductResolver* productResolver)
0103                 : dataKey_(dataKey), productResolver_(productResolver) {}
0104             DataKey& dataKey_;
0105             ESProductResolver* productResolver_;
0106           };
0107           KeyedResolver operator*() { return KeyedResolver(dataKey(), productResolver()); }
0108 
0109         private:
0110           friend KeyedResolvers;
0111           Iterator(std::vector<DataKey>::iterator dataKeysIter,
0112                    std::vector<edm::propagate_const<std::shared_ptr<ESProductResolver>>>::iterator productResolversIter);
0113 
0114           std::vector<DataKey>::iterator dataKeysIter_;
0115           std::vector<edm::propagate_const<std::shared_ptr<ESProductResolver>>>::iterator productResolversIter_;
0116         };
0117 
0118         Iterator begin();
0119         Iterator end();
0120 
0121       private:
0122         edm::propagate_const<ESProductResolverContainer*> productResolverContainer_;
0123         unsigned int recordIndex_;
0124         unsigned int productResolversIndex_;
0125       };
0126 
0127       struct PerRecordInfo {
0128         PerRecordInfo(const EventSetupRecordKey&);
0129         bool operator<(const PerRecordInfo& right) const { return recordKey_ < right.recordKey_; }
0130         bool operator==(const PerRecordInfo& right) const { return recordKey_ == right.recordKey_; }
0131 
0132         EventSetupRecordKey recordKey_;
0133         unsigned int nDataKeys_ = 0;
0134         unsigned int indexToDataKeys_;
0135         unsigned int nIOVs_ = 0;
0136         unsigned int indexToKeyedResolvers_ = 0;
0137       };
0138 
0139       class ESProductResolverContainer {
0140       public:
0141         void usingRecordWithKey(const EventSetupRecordKey&);
0142         bool isUsingRecord(const EventSetupRecordKey&) const;
0143         std::set<EventSetupRecordKey> usingRecords() const;
0144         void fillRecordsNotAllowingConcurrentIOVs(std::set<EventSetupRecordKey>& recordsNotAllowingConcurrentIOVs) const;
0145 
0146         void sortEventSetupRecordKeys();
0147         void createKeyedResolvers(EventSetupRecordKey const& key, unsigned int nConcurrentIOVs);
0148 
0149         KeyedResolvers& keyedResolvers(const EventSetupRecordKey& iRecordKey, unsigned int iovIndex);
0150 
0151       private:
0152         friend KeyedResolvers;
0153 
0154         std::vector<PerRecordInfo> perRecordInfos_;
0155         std::vector<KeyedResolvers> keyedResolversCollection_;
0156         std::vector<DataKey> dataKeys_;
0157         std::vector<edm::propagate_const<std::shared_ptr<ESProductResolver>>> productResolvers_;
0158       };
0159 
0160       bool isUsingRecord(const EventSetupRecordKey& key) const { return productResolverContainer_.isUsingRecord(key); }
0161       std::set<EventSetupRecordKey> usingRecords() const { return productResolverContainer_.usingRecords(); }
0162       void fillRecordsNotAllowingConcurrentIOVs(std::set<EventSetupRecordKey>& recordsNotAllowingConcurrentIOVs) const {
0163         productResolverContainer_.fillRecordsNotAllowingConcurrentIOVs(recordsNotAllowingConcurrentIOVs);
0164       }
0165       /// @brief Provides information about each product that this module produces.
0166       /// If the value of produceMethodID is same for different infos it means they are produced by the same call.
0167       /// @return the vector of ESModuleProducesInfo objects, one for each product produced by this module.
0168       virtual std::vector<ESModuleProducesInfo> producesInfo() const = 0;
0169 
0170       virtual void initConcurrentIOVs(EventSetupRecordKey const& key, unsigned int nConcurrentIOVs) {}
0171 
0172       void createKeyedResolvers(EventSetupRecordKey const& key, unsigned int nConcurrentIOVs) {
0173         productResolverContainer_.createKeyedResolvers(key, nConcurrentIOVs);
0174         initConcurrentIOVs(key, nConcurrentIOVs);
0175       }
0176 
0177       const ComponentDescription& description() const { return description_; }
0178 
0179       virtual void updateLookup(ESRecordsToProductResolverIndices const&);
0180 
0181       void setDescription(const ComponentDescription& iDescription) { description_ = iDescription; }
0182 
0183       /**This method is only to be called by the framework, it sets the string
0184         which will be appended to the labels of all data products being produced
0185       **/
0186       void setAppendToDataLabel(const edm::ParameterSet&);
0187 
0188       KeyedResolvers& keyedResolvers(const EventSetupRecordKey& iRecordKey, unsigned int iovIndex = 0);
0189 
0190       /**Used to add parameters available to all inheriting classes
0191       */
0192       static void prevalidate(ConfigurationDescriptions&);
0193 
0194     protected:
0195       template <class T>
0196       void usingRecord() {
0197         usingRecordWithKey(EventSetupRecordKey::makeKey<T>());
0198       }
0199 
0200       void usingRecordWithKey(const EventSetupRecordKey& key) { productResolverContainer_.usingRecordWithKey(key); }
0201 
0202       using KeyedResolversVector = std::vector<std::pair<DataKey, std::shared_ptr<ESProductResolver>>>;
0203       virtual KeyedResolversVector registerResolvers(const EventSetupRecordKey&, unsigned int iovIndex) = 0;
0204 
0205     private:
0206       // ---------- member data --------------------------------
0207       ESProductResolverContainer productResolverContainer_;
0208       ComponentDescription description_;
0209       std::string appendToDataLabel_;
0210     };
0211 
0212   }  // namespace eventsetup
0213 }  // namespace edm
0214 #endif