File indexing completed on 2024-04-06 12:12:33
0001 #include "FWCore/Framework/interface/DataKey.h"
0002 #include "FWCore/Framework/interface/ESProductResolverProvider.h"
0003 #include "FWCore/Framework/interface/ESProductResolverTemplate.h"
0004 #include "FWCore/Framework/interface/ESProducer.h"
0005 #include "FWCore/Framework/interface/ESProductHost.h"
0006 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0009 #include "FWCore/Integration/interface/ESTestData.h"
0010 #include "FWCore/Integration/interface/ESTestRecords.h"
0011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0012 #include "FWCore/Framework/interface/ModuleFactory.h"
0013 #include "FWCore/Utilities/interface/Exception.h"
0014 #include "FWCore/Utilities/interface/ReusableObjectHolder.h"
0015
0016 #include <memory>
0017 #include <vector>
0018
0019 namespace edmtest {
0020
0021 class ESTestProducerA : public edm::ESProducer {
0022 public:
0023 ESTestProducerA(edm::ParameterSet const&);
0024 std::unique_ptr<ESTestDataA> produce(ESTestRecordA const&);
0025
0026 private:
0027 int value_;
0028 };
0029
0030 ESTestProducerA::ESTestProducerA(edm::ParameterSet const&) : value_(0) { setWhatProduced(this); }
0031
0032 std::unique_ptr<ESTestDataA> ESTestProducerA::produce(ESTestRecordA const& rec) {
0033 ++value_;
0034 return std::make_unique<ESTestDataA>(value_);
0035 }
0036
0037
0038
0039 class ESTestProducerB : public edm::ESProducer {
0040 public:
0041 ESTestProducerB(edm::ParameterSet const&);
0042 std::unique_ptr<ESTestDataB> produce(ESTestRecordB const&);
0043
0044 private:
0045 int value_;
0046 };
0047
0048 ESTestProducerB::ESTestProducerB(edm::ParameterSet const&) : value_(0) { setWhatProduced(this); }
0049
0050 std::unique_ptr<ESTestDataB> ESTestProducerB::produce(ESTestRecordB const& rec) {
0051 ++value_;
0052 return std::make_unique<ESTestDataB>(value_);
0053 }
0054
0055
0056
0057
0058 class ESTestProducerBUsingHost : public edm::ESProducer {
0059 public:
0060 ESTestProducerBUsingHost(edm::ParameterSet const&);
0061
0062 std::shared_ptr<ESTestDataB> produce(ESTestRecordB const&);
0063
0064 private:
0065 using HostType = edm::ESProductHost<ESTestDataB,
0066 ESTestRecordC,
0067 ESTestRecordD,
0068 ESTestRecordE,
0069 ESTestRecordF,
0070 ESTestRecordG,
0071 ESTestRecordH>;
0072
0073 edm::ReusableObjectHolder<HostType> holder_;
0074 };
0075
0076 ESTestProducerBUsingHost::ESTestProducerBUsingHost(edm::ParameterSet const&) { setWhatProduced(this); }
0077
0078 std::shared_ptr<ESTestDataB> ESTestProducerBUsingHost::produce(ESTestRecordB const& record) {
0079 auto host = holder_.makeOrGet([]() { return new HostType(100, 1000); });
0080
0081
0082 if (host->numberOfRecordTypes() != 6 || host->index<ESTestRecordC>() != 0 || host->index<ESTestRecordD>() != 1 ||
0083 host->index<ESTestRecordE>() != 2 || host->index<ESTestRecordF>() != 3 || host->index<ESTestRecordG>() != 4 ||
0084 host->index<ESTestRecordH>() != 5) {
0085 throw cms::Exception("TestError") << "Either function numberOfRecordTypes or index returns incorrect value";
0086 }
0087
0088 host->ifRecordChanges<ESTestRecordC>(record, [h = host.get()](auto const& rec) { ++h->value(); });
0089
0090 ++host->value();
0091 return host;
0092 }
0093
0094
0095
0096 class ESTestProducerC : public edm::ESProducer {
0097 public:
0098 ESTestProducerC(edm::ParameterSet const&);
0099 std::unique_ptr<ESTestDataC> produce(ESTestRecordC const&);
0100
0101 private:
0102 int value_;
0103 };
0104
0105 ESTestProducerC::ESTestProducerC(edm::ParameterSet const&) : value_(0) { setWhatProduced(this); }
0106
0107 std::unique_ptr<ESTestDataC> ESTestProducerC::produce(ESTestRecordC const& rec) {
0108 ++value_;
0109 return std::make_unique<ESTestDataC>(value_);
0110 }
0111
0112
0113
0114 class ESTestProducerD : public edm::ESProducer {
0115 public:
0116 ESTestProducerD(edm::ParameterSet const&);
0117 std::unique_ptr<ESTestDataD> produce(ESTestRecordD const&);
0118
0119 private:
0120 int value_;
0121 };
0122
0123 ESTestProducerD::ESTestProducerD(edm::ParameterSet const&) : value_(0) { setWhatProduced(this); }
0124
0125 std::unique_ptr<ESTestDataD> ESTestProducerD::produce(ESTestRecordD const& rec) {
0126 ++value_;
0127 return std::make_unique<ESTestDataD>(value_);
0128 }
0129
0130
0131
0132 class ESTestProducerE : public edm::ESProducer {
0133 public:
0134 ESTestProducerE(edm::ParameterSet const&);
0135 std::unique_ptr<ESTestDataE> produce(ESTestRecordE const&);
0136
0137 private:
0138 int value_;
0139 };
0140
0141 ESTestProducerE::ESTestProducerE(edm::ParameterSet const&) : value_(0) { setWhatProduced(this); }
0142
0143 std::unique_ptr<ESTestDataE> ESTestProducerE::produce(ESTestRecordE const& rec) {
0144 ++value_;
0145 return std::make_unique<ESTestDataE>(value_);
0146 }
0147
0148
0149
0150 class ESTestProducerF : public edm::ESProducer {
0151 public:
0152 ESTestProducerF(edm::ParameterSet const&);
0153 std::unique_ptr<ESTestDataF> produce(ESTestRecordF const&);
0154
0155 private:
0156 int value_;
0157 };
0158
0159 ESTestProducerF::ESTestProducerF(edm::ParameterSet const&) : value_(0) { setWhatProduced(this); }
0160
0161 std::unique_ptr<ESTestDataF> ESTestProducerF::produce(ESTestRecordF const& rec) {
0162 ++value_;
0163 return std::make_unique<ESTestDataF>(value_);
0164 }
0165
0166
0167
0168 class ESTestProducerG : public edm::ESProducer {
0169 public:
0170 ESTestProducerG(edm::ParameterSet const&);
0171 std::unique_ptr<ESTestDataG> produce(ESTestRecordG const&);
0172
0173 private:
0174 int value_;
0175 };
0176
0177 ESTestProducerG::ESTestProducerG(edm::ParameterSet const&) : value_(0) { setWhatProduced(this); }
0178
0179 std::unique_ptr<ESTestDataG> ESTestProducerG::produce(ESTestRecordG const& rec) {
0180 ++value_;
0181 return std::make_unique<ESTestDataG>(value_);
0182 }
0183
0184
0185
0186 class ESTestProducerH : public edm::ESProducer {
0187 public:
0188 ESTestProducerH(edm::ParameterSet const&);
0189 std::unique_ptr<ESTestDataH> produce(ESTestRecordH const&);
0190
0191 private:
0192 int value_;
0193 };
0194
0195 ESTestProducerH::ESTestProducerH(edm::ParameterSet const&) : value_(0) { setWhatProduced(this); }
0196
0197 std::unique_ptr<ESTestDataH> ESTestProducerH::produce(ESTestRecordH const& rec) {
0198 ++value_;
0199 return std::make_unique<ESTestDataH>(value_);
0200 }
0201
0202
0203
0204 class ESTestProducerI : public edm::ESProducer {
0205 public:
0206 ESTestProducerI(edm::ParameterSet const&);
0207 std::unique_ptr<ESTestDataI> produce(ESTestRecordI const&);
0208
0209 private:
0210 int value_;
0211 };
0212
0213 ESTestProducerI::ESTestProducerI(edm::ParameterSet const&) : value_(0) { setWhatProduced(this); }
0214
0215 std::unique_ptr<ESTestDataI> ESTestProducerI::produce(ESTestRecordI const& rec) {
0216 ++value_;
0217 return std::make_unique<ESTestDataI>(value_);
0218 }
0219
0220
0221
0222 class ESTestProducerJ : public edm::ESProducer {
0223 public:
0224 ESTestProducerJ(edm::ParameterSet const&);
0225 std::unique_ptr<ESTestDataJ> produce(ESTestRecordJ const&);
0226
0227 private:
0228 int value_;
0229 };
0230
0231 ESTestProducerJ::ESTestProducerJ(edm::ParameterSet const&) : value_(0) { setWhatProduced(this); }
0232
0233 std::unique_ptr<ESTestDataJ> ESTestProducerJ::produce(ESTestRecordJ const& rec) {
0234 ++value_;
0235 return std::make_unique<ESTestDataJ>(value_);
0236 }
0237
0238
0239
0240 class ESTestProducerK : public edm::ESProducer {
0241 public:
0242 ESTestProducerK(edm::ParameterSet const&);
0243 std::unique_ptr<ESTestDataK> produce(ESTestRecordK const&);
0244
0245 private:
0246 int value_;
0247 };
0248
0249 ESTestProducerK::ESTestProducerK(edm::ParameterSet const&) : value_(0) { setWhatProduced(this); }
0250
0251 std::unique_ptr<ESTestDataK> ESTestProducerK::produce(ESTestRecordK const& rec) {
0252 ++value_;
0253 return std::make_unique<ESTestDataK>(value_);
0254 }
0255
0256
0257
0258 class ESTestProducerAZ : public edm::ESProducer {
0259 public:
0260 ESTestProducerAZ(edm::ParameterSet const&);
0261 std::unique_ptr<ESTestDataA> produceA(ESTestRecordA const&);
0262 std::unique_ptr<ESTestDataZ> produceZ(ESTestRecordZ const&);
0263
0264 private:
0265 int valueA_;
0266 int valueZ_;
0267 };
0268
0269 ESTestProducerAZ::ESTestProducerAZ(edm::ParameterSet const&) : valueA_(0), valueZ_(0) {
0270 setWhatProduced(this, &edmtest::ESTestProducerAZ::produceA, edm::es::Label("foo"));
0271 setWhatProduced(this, &edmtest::ESTestProducerAZ::produceZ, edm::es::Label("foo"));
0272 }
0273
0274 std::unique_ptr<ESTestDataA> ESTestProducerAZ::produceA(ESTestRecordA const& rec) {
0275 ++valueA_;
0276 return std::make_unique<ESTestDataA>(valueA_);
0277 }
0278
0279 std::unique_ptr<ESTestDataZ> ESTestProducerAZ::produceZ(ESTestRecordZ const& rec) {
0280 ++valueZ_;
0281 return std::make_unique<ESTestDataZ>(valueZ_);
0282 }
0283
0284 class TestESProductResolverTemplateJ : public edm::eventsetup::ESProductResolverTemplate<ESTestRecordJ, ESTestDataJ> {
0285 public:
0286 TestESProductResolverTemplateJ(std::vector<unsigned int> const* expectedCacheIds)
0287 : testDataJ_(1), expectedCacheIds_(expectedCacheIds) {}
0288
0289 private:
0290 const ESTestDataJ* make(const ESTestRecordJ& record, const edm::eventsetup::DataKey& key) override {
0291 ESTestRecordK recordK = record.getRecord<ESTestRecordK>();
0292
0293
0294
0295 if (index_ < expectedCacheIds_->size() && recordK.cacheIdentifier() != expectedCacheIds_->at(index_)) {
0296 throw cms::Exception("TestError") << "TestESProductResolverTemplateJ::make, unexpected cacheIdentifier";
0297 }
0298 ++index_;
0299 return &testDataJ_;
0300 }
0301
0302 void invalidateCache() override {}
0303 void const* getAfterPrefetchImpl() const override { return &testDataJ_; }
0304
0305 ESTestDataJ testDataJ_;
0306 std::vector<unsigned> const* expectedCacheIds_;
0307 unsigned int index_ = 0;
0308 };
0309
0310 class ESTestESProductResolverProviderJ : public edm::eventsetup::ESProductResolverProvider {
0311 public:
0312 ESTestESProductResolverProviderJ(edm::ParameterSet const&);
0313
0314 static void fillDescriptions(edm::ConfigurationDescriptions&);
0315
0316 private:
0317 KeyedResolversVector registerResolvers(const edm::eventsetup::EventSetupRecordKey&, unsigned int iovIndex) override;
0318
0319 std::vector<std::shared_ptr<TestESProductResolverTemplateJ>> proxies_;
0320 std::vector<unsigned> expectedCacheIds_;
0321 };
0322
0323 ESTestESProductResolverProviderJ::ESTestESProductResolverProviderJ(edm::ParameterSet const& pset)
0324 : expectedCacheIds_(pset.getUntrackedParameter<std::vector<unsigned int>>("expectedCacheIds")) {
0325 usingRecord<ESTestRecordJ>();
0326 }
0327
0328 void ESTestESProductResolverProviderJ::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0329 edm::ParameterSetDescription desc;
0330 std::vector<unsigned int> emptyDefaultVector;
0331 desc.addUntracked<std::vector<unsigned int>>("expectedCacheIds", emptyDefaultVector);
0332 descriptions.addDefault(desc);
0333 }
0334
0335 edm::eventsetup::ESProductResolverProvider::KeyedResolversVector ESTestESProductResolverProviderJ::registerResolvers(
0336 const edm::eventsetup::EventSetupRecordKey& iRecord, unsigned int iovIndex) {
0337 KeyedResolversVector keyedResolversVector;
0338 while (iovIndex >= proxies_.size()) {
0339 proxies_.push_back(std::make_shared<TestESProductResolverTemplateJ>(&expectedCacheIds_));
0340 }
0341 edm::eventsetup::DataKey dataKey(edm::eventsetup::DataKey::makeTypeTag<ESTestDataJ>(), "");
0342 keyedResolversVector.emplace_back(dataKey, proxies_[iovIndex]);
0343 return keyedResolversVector;
0344 }
0345 }
0346
0347 namespace edm::test {
0348 namespace other {
0349 class ESTestProducerA : public edm::ESProducer {
0350 public:
0351 ESTestProducerA(edm::ParameterSet const& pset) : value_(pset.getParameter<int>("valueOther")) {
0352 setWhatProduced(this);
0353 }
0354 std::optional<edmtest::ESTestDataA> produce(ESTestRecordA const& rec) {
0355 ++value_;
0356 return edmtest::ESTestDataA(value_);
0357 }
0358
0359 private:
0360 int value_;
0361 };
0362 }
0363 namespace cpu {
0364 class ESTestProducerA : public edm::ESProducer {
0365 public:
0366 ESTestProducerA(edm::ParameterSet const& pset) : value_(pset.getParameter<int>("valueCpu")) {
0367 setWhatProduced(this);
0368 }
0369 std::optional<edmtest::ESTestDataA> produce(ESTestRecordA const& rec) {
0370 ++value_;
0371 return edmtest::ESTestDataA(value_);
0372 }
0373
0374 private:
0375 int value_;
0376 };
0377 }
0378 }
0379
0380 using namespace edmtest;
0381 DEFINE_FWK_EVENTSETUP_MODULE(ESTestProducerA);
0382 DEFINE_FWK_EVENTSETUP_MODULE(ESTestProducerB);
0383 DEFINE_FWK_EVENTSETUP_MODULE(ESTestProducerBUsingHost);
0384 DEFINE_FWK_EVENTSETUP_MODULE(ESTestProducerC);
0385 DEFINE_FWK_EVENTSETUP_MODULE(ESTestProducerD);
0386 DEFINE_FWK_EVENTSETUP_MODULE(ESTestProducerE);
0387 DEFINE_FWK_EVENTSETUP_MODULE(ESTestProducerF);
0388 DEFINE_FWK_EVENTSETUP_MODULE(ESTestProducerG);
0389 DEFINE_FWK_EVENTSETUP_MODULE(ESTestProducerH);
0390 DEFINE_FWK_EVENTSETUP_MODULE(ESTestProducerI);
0391 DEFINE_FWK_EVENTSETUP_MODULE(ESTestProducerJ);
0392 DEFINE_FWK_EVENTSETUP_MODULE(ESTestProducerK);
0393 DEFINE_FWK_EVENTSETUP_MODULE(ESTestProducerAZ);
0394 DEFINE_FWK_EVENTSETUP_MODULE(ESTestESProductResolverProviderJ);
0395 DEFINE_FWK_EVENTSETUP_MODULE(edm::test::other::ESTestProducerA);
0396 DEFINE_FWK_EVENTSETUP_MODULE(edm::test::cpu::ESTestProducerA);