Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-10-07 04:59:29

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 
0064     class ESProductResolverProvider {
0065     public:
0066       ESProductResolverProvider();
0067       ESProductResolverProvider(const ESProductResolverProvider&) = delete;
0068       const ESProductResolverProvider& operator=(const ESProductResolverProvider&) = delete;
0069       virtual ~ESProductResolverProvider() noexcept(false);
0070 
0071       class ESProductResolverContainer;
0072 
0073       class KeyedResolvers {
0074       public:
0075         KeyedResolvers(ESProductResolverContainer*, unsigned int recordIndex);
0076 
0077         bool unInitialized() const;
0078 
0079         EventSetupRecordKey const& recordKey() const;
0080 
0081         void insert(std::vector<std::pair<DataKey, std::shared_ptr<ESProductResolver>>>&&,
0082                     std::string const& appendToDataLabel);
0083 
0084         bool contains(DataKey const& dataKey) const;
0085 
0086         unsigned int size() const;
0087 
0088         // Not an STL iterator and cannot be used as one
0089         class Iterator {
0090         public:
0091           DataKey& dataKey() { return *dataKeysIter_; }
0092           ESProductResolver* productResolver() { return productResolversIter_->get(); }
0093           Iterator& operator++();
0094 
0095           bool operator!=(Iterator const& right) const { return dataKeysIter_ != right.dataKeysIter_; }
0096 
0097           // Warning: dereference operator does not return a reference to an element in a container.
0098           // The return type is nonstandard because the iteration is simultaneous over 2 containers.
0099           // This return type is used in "ranged-based for" loops.
0100           struct KeyedResolver {
0101             KeyedResolver(DataKey& dataKey, ESProductResolver* productResolver)
0102                 : dataKey_(dataKey), productResolver_(productResolver) {}
0103             DataKey& dataKey_;
0104             ESProductResolver* productResolver_;
0105           };
0106           KeyedResolver operator*() { return KeyedResolver(dataKey(), productResolver()); }
0107 
0108         private:
0109           friend KeyedResolvers;
0110           Iterator(std::vector<DataKey>::iterator dataKeysIter,
0111                    std::vector<edm::propagate_const<std::shared_ptr<ESProductResolver>>>::iterator productResolversIter);
0112 
0113           std::vector<DataKey>::iterator dataKeysIter_;
0114           std::vector<edm::propagate_const<std::shared_ptr<ESProductResolver>>>::iterator productResolversIter_;
0115         };
0116 
0117         Iterator begin();
0118         Iterator end();
0119 
0120       private:
0121         edm::propagate_const<ESProductResolverContainer*> productResolverContainer_;
0122         unsigned int recordIndex_;
0123         unsigned int productResolversIndex_;
0124       };
0125 
0126       struct PerRecordInfo {
0127         PerRecordInfo(const EventSetupRecordKey&);
0128         bool operator<(const PerRecordInfo& right) const { return recordKey_ < right.recordKey_; }
0129         bool operator==(const PerRecordInfo& right) const { return recordKey_ == right.recordKey_; }
0130 
0131         EventSetupRecordKey recordKey_;
0132         unsigned int nDataKeys_ = 0;
0133         unsigned int indexToDataKeys_;
0134         unsigned int nIOVs_ = 0;
0135         unsigned int indexToKeyedResolvers_ = 0;
0136       };
0137 
0138       class ESProductResolverContainer {
0139       public:
0140         void usingRecordWithKey(const EventSetupRecordKey&);
0141         bool isUsingRecord(const EventSetupRecordKey&) const;
0142         std::set<EventSetupRecordKey> usingRecords() const;
0143         void fillRecordsNotAllowingConcurrentIOVs(std::set<EventSetupRecordKey>& recordsNotAllowingConcurrentIOVs) const;
0144 
0145         void sortEventSetupRecordKeys();
0146         void createKeyedResolvers(EventSetupRecordKey const& key, unsigned int nConcurrentIOVs);
0147 
0148         KeyedResolvers& keyedResolvers(const EventSetupRecordKey& iRecordKey, unsigned int iovIndex);
0149 
0150       private:
0151         friend KeyedResolvers;
0152 
0153         std::vector<PerRecordInfo> perRecordInfos_;
0154         std::vector<KeyedResolvers> keyedResolversCollection_;
0155         std::vector<DataKey> dataKeys_;
0156         std::vector<edm::propagate_const<std::shared_ptr<ESProductResolver>>> productResolvers_;
0157       };
0158 
0159       bool isUsingRecord(const EventSetupRecordKey& key) const { return productResolverContainer_.isUsingRecord(key); }
0160       std::set<EventSetupRecordKey> usingRecords() const { return productResolverContainer_.usingRecords(); }
0161       void fillRecordsNotAllowingConcurrentIOVs(std::set<EventSetupRecordKey>& recordsNotAllowingConcurrentIOVs) const {
0162         productResolverContainer_.fillRecordsNotAllowingConcurrentIOVs(recordsNotAllowingConcurrentIOVs);
0163       }
0164 
0165       virtual void initConcurrentIOVs(EventSetupRecordKey const& key, unsigned int nConcurrentIOVs) {}
0166 
0167       void createKeyedResolvers(EventSetupRecordKey const& key, unsigned int nConcurrentIOVs) {
0168         productResolverContainer_.createKeyedResolvers(key, nConcurrentIOVs);
0169         initConcurrentIOVs(key, nConcurrentIOVs);
0170       }
0171 
0172       const ComponentDescription& description() const { return description_; }
0173 
0174       virtual void updateLookup(ESRecordsToProductResolverIndices const&);
0175 
0176       void setDescription(const ComponentDescription& iDescription) { description_ = iDescription; }
0177 
0178       /**This method is only to be called by the framework, it sets the string
0179         which will be appended to the labels of all data products being produced
0180       **/
0181       void setAppendToDataLabel(const edm::ParameterSet&);
0182 
0183       KeyedResolvers& keyedResolvers(const EventSetupRecordKey& iRecordKey, unsigned int iovIndex = 0);
0184 
0185       /**Used to add parameters available to all inheriting classes
0186       */
0187       static void prevalidate(ConfigurationDescriptions&);
0188 
0189     protected:
0190       template <class T>
0191       void usingRecord() {
0192         usingRecordWithKey(EventSetupRecordKey::makeKey<T>());
0193       }
0194 
0195       void usingRecordWithKey(const EventSetupRecordKey& key) { productResolverContainer_.usingRecordWithKey(key); }
0196 
0197       using KeyedResolversVector = std::vector<std::pair<DataKey, std::shared_ptr<ESProductResolver>>>;
0198       virtual KeyedResolversVector registerResolvers(const EventSetupRecordKey&, unsigned int iovIndex) = 0;
0199 
0200     private:
0201       // ---------- member data --------------------------------
0202       ESProductResolverContainer productResolverContainer_;
0203       ComponentDescription description_;
0204       std::string appendToDataLabel_;
0205     };
0206 
0207   }  // namespace eventsetup
0208 }  // namespace edm
0209 #endif