File indexing completed on 2021-02-14 13:27:43
0001 #ifndef FWCore_Framework_DataProxyProvider_h
0002 #define FWCore_Framework_DataProxyProvider_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044 #include <memory>
0045 #include <set>
0046 #include <string>
0047 #include <vector>
0048
0049
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
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
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
0098
0099
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
0178
0179
0180 void setAppendToDataLabel(const edm::ParameterSet&);
0181
0182 KeyedProxies& keyedProxies(const EventSetupRecordKey& iRecordKey, unsigned int iovIndex = 0);
0183
0184
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
0201 DataProxyContainer dataProxyContainer_;
0202 ComponentDescription description_;
0203 std::string appendToDataLabel_;
0204 };
0205
0206 }
0207 }
0208 #endif