Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:27:43

0001 #ifndef FWCore_Framework_DataProxyProvider_h
0002 #define FWCore_Framework_DataProxyProvider_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     Framework
0006 // Class  :     DataProxyProvider
0007 //
0008 /**\class edm::eventsetup::DataProxyProvider
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 registerProxies 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 registerProxies
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. DataProxies 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 DataProxyProvider.
0035     They are primarily used when initializing the EventSetup system
0036     so the DataProxies 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 DataProxy;
0062     class ESRecordsToProxyIndices;
0063 
0064     class DataProxyProvider {
0065     public:
0066       DataProxyProvider();
0067       DataProxyProvider(const DataProxyProvider&) = delete;
0068       const DataProxyProvider& operator=(const DataProxyProvider&) = delete;
0069       virtual ~DataProxyProvider() noexcept(false);
0070 
0071       class DataProxyContainer;
0072 
0073       class KeyedProxies {
0074       public:
0075         KeyedProxies(DataProxyContainer*, 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<DataProxy>>>&&,
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           DataProxy* dataProxy() { return dataProxiesIter_->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 KeyedProxy {
0101             KeyedProxy(DataKey& dataKey, DataProxy* dataProxy) : dataKey_(dataKey), dataProxy_(dataProxy) {}
0102             DataKey& dataKey_;
0103             DataProxy* dataProxy_;
0104           };
0105           KeyedProxy operator*() { return KeyedProxy(dataKey(), dataProxy()); }
0106 
0107         private:
0108           friend KeyedProxies;
0109           Iterator(std::vector<DataKey>::iterator dataKeysIter,
0110                    std::vector<edm::propagate_const<std::shared_ptr<DataProxy>>>::iterator dataProxiesIter);
0111 
0112           std::vector<DataKey>::iterator dataKeysIter_;
0113           std::vector<edm::propagate_const<std::shared_ptr<DataProxy>>>::iterator dataProxiesIter_;
0114         };
0115 
0116         Iterator begin();
0117         Iterator end();
0118 
0119       private:
0120         edm::propagate_const<DataProxyContainer*> dataProxyContainer_;
0121         unsigned int recordIndex_;
0122         unsigned int dataProxiesIndex_;
0123       };
0124 
0125       struct PerRecordInfo {
0126         PerRecordInfo(const EventSetupRecordKey&);
0127         bool operator<(const PerRecordInfo& right) const { return recordKey_ < right.recordKey_; }
0128         bool operator==(const PerRecordInfo& right) const { return recordKey_ == right.recordKey_; }
0129 
0130         EventSetupRecordKey recordKey_;
0131         unsigned int nDataKeys_ = 0;
0132         unsigned int indexToDataKeys_;
0133         unsigned int nIOVs_ = 0;
0134         unsigned int indexToKeyedProxies_ = 0;
0135       };
0136 
0137       class DataProxyContainer {
0138       public:
0139         void usingRecordWithKey(const EventSetupRecordKey&);
0140         bool isUsingRecord(const EventSetupRecordKey&) const;
0141         std::set<EventSetupRecordKey> usingRecords() const;
0142         void fillRecordsNotAllowingConcurrentIOVs(std::set<EventSetupRecordKey>& recordsNotAllowingConcurrentIOVs) const;
0143 
0144         void sortEventSetupRecordKeys();
0145         void createKeyedProxies(EventSetupRecordKey const& key, unsigned int nConcurrentIOVs);
0146 
0147         KeyedProxies& keyedProxies(const EventSetupRecordKey& iRecordKey, unsigned int iovIndex);
0148 
0149       private:
0150         friend KeyedProxies;
0151 
0152         std::vector<PerRecordInfo> perRecordInfos_;
0153         std::vector<KeyedProxies> keyedProxiesCollection_;
0154         std::vector<DataKey> dataKeys_;
0155         std::vector<edm::propagate_const<std::shared_ptr<DataProxy>>> dataProxies_;
0156       };
0157 
0158       bool isUsingRecord(const EventSetupRecordKey& key) const { return dataProxyContainer_.isUsingRecord(key); }
0159       std::set<EventSetupRecordKey> usingRecords() const { return dataProxyContainer_.usingRecords(); }
0160       void fillRecordsNotAllowingConcurrentIOVs(std::set<EventSetupRecordKey>& recordsNotAllowingConcurrentIOVs) const {
0161         dataProxyContainer_.fillRecordsNotAllowingConcurrentIOVs(recordsNotAllowingConcurrentIOVs);
0162       }
0163 
0164       virtual void initConcurrentIOVs(EventSetupRecordKey const& key, unsigned int nConcurrentIOVs) {}
0165 
0166       void createKeyedProxies(EventSetupRecordKey const& key, unsigned int nConcurrentIOVs) {
0167         dataProxyContainer_.createKeyedProxies(key, nConcurrentIOVs);
0168         initConcurrentIOVs(key, nConcurrentIOVs);
0169       }
0170 
0171       const ComponentDescription& description() const { return description_; }
0172 
0173       virtual void updateLookup(ESRecordsToProxyIndices const&);
0174 
0175       void setDescription(const ComponentDescription& iDescription) { description_ = iDescription; }
0176 
0177       /**This method is only to be called by the framework, it sets the string
0178         which will be appended to the labels of all data products being produced
0179       **/
0180       void setAppendToDataLabel(const edm::ParameterSet&);
0181 
0182       KeyedProxies& keyedProxies(const EventSetupRecordKey& iRecordKey, unsigned int iovIndex = 0);
0183 
0184       /**Used to add parameters available to all inheriting classes
0185       */
0186       static void prevalidate(ConfigurationDescriptions&);
0187 
0188     protected:
0189       template <class T>
0190       void usingRecord() {
0191         usingRecordWithKey(EventSetupRecordKey::makeKey<T>());
0192       }
0193 
0194       void usingRecordWithKey(const EventSetupRecordKey& key) { dataProxyContainer_.usingRecordWithKey(key); }
0195 
0196       using KeyedProxiesVector = std::vector<std::pair<DataKey, std::shared_ptr<DataProxy>>>;
0197       virtual KeyedProxiesVector registerProxies(const EventSetupRecordKey&, unsigned int iovIndex) = 0;
0198 
0199     private:
0200       // ---------- member data --------------------------------
0201       DataProxyContainer dataProxyContainer_;
0202       ComponentDescription description_;
0203       std::string appendToDataLabel_;
0204     };
0205 
0206   }  // namespace eventsetup
0207 }  // namespace edm
0208 #endif