File indexing completed on 2024-10-07 04:59:29
0001
0002 #ifndef FWCore_Framework_ESProductResolverProvider_h
0003 #define FWCore_Framework_ESProductResolverProvider_h
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 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
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
0098
0099
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
0179
0180
0181 void setAppendToDataLabel(const edm::ParameterSet&);
0182
0183 KeyedResolvers& keyedResolvers(const EventSetupRecordKey& iRecordKey, unsigned int iovIndex = 0);
0184
0185
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
0202 ESProductResolverContainer productResolverContainer_;
0203 ComponentDescription description_;
0204 std::string appendToDataLabel_;
0205 };
0206
0207 }
0208 }
0209 #endif