Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-04-30 22:24:14

0001 // -*- C++ -*-
0002 //
0003 // Package:     FWCore/TestProcessor
0004 // Class  :     EventSetupTestHelper
0005 //
0006 // Implementation:
0007 //     [Notes on implementation]
0008 //
0009 // Original Author:  root
0010 //         Created:  Tue, 08 May 2018 18:33:15 GMT
0011 //
0012 
0013 // system include files
0014 
0015 // user include files
0016 #include "FWCore/TestProcessor/interface/EventSetupTestHelper.h"
0017 #include "FWCore/Framework/interface/ESProductResolver.h"
0018 #include "FWCore/Framework/interface/ESModuleProducesInfo.h"
0019 
0020 namespace edm {
0021   namespace test {
0022 
0023     EventSetupTestHelper::EventSetupTestHelper(std::vector<ESProduceEntry> iResolvers)
0024         : resolvers_{std::move(iResolvers)} {
0025       //Deal with duplicates
0026       std::set<eventsetup::EventSetupRecordKey> records;
0027       for (auto const& p : resolvers_) {
0028         records.insert(p.recordKey_);
0029       }
0030       for (auto const& k : records) {
0031         usingRecordWithKey(k);
0032         findingRecordWithKey(k);
0033       }
0034     }
0035 
0036     void EventSetupTestHelper::setIntervalFor(const eventsetup::EventSetupRecordKey&,
0037                                               const IOVSyncValue& iSync,
0038                                               ValidityInterval& oIOV) {
0039       // Note that we manually invalidate the resolvers at the end of every call
0040       // to test. And the beginning of the call to test is the only opportunity
0041       // to reset this data, so we are not relying on the EventSetup system
0042       // to manage invalidating the resolvers in EventSetupTestHelper. The only
0043       // reasonable thing to do is return an interval for all time so the EventSetup
0044       // system does not invalidate these resolvers when it shouldn't. There are two
0045       // weaknesses to this:
0046       //
0047       //     1. If for the same record type there are ESProductResolvers both managed
0048       //     by this class and also others managed by the EventSetup, then
0049       //     at IOV boundaries for this record this will fail. The EventSetup
0050       //     will invalidate all the resolvers for the record after this class
0051       //     has set the ones it manages and they will stay invalid when they
0052       //     are needed.
0053       //
0054       //     2. TestProcessor does not support the special case where the different
0055       //     transitions executed in one call to test have different IOVs and different
0056       //     EventSetup data. That would be a pretty strange case, especially for a test.
0057 
0058       oIOV = edm::ValidityInterval(edm::IOVSyncValue::beginOfTime(), edm::IOVSyncValue::endOfTime());
0059     }
0060 
0061     eventsetup::ESProductResolverProvider::KeyedResolversVector EventSetupTestHelper::registerResolvers(
0062         const eventsetup::EventSetupRecordKey& iRecordKey, unsigned int iovIndex) {
0063       KeyedResolversVector keyedResolversVector;
0064       for (auto const& p : resolvers_) {
0065         if (p.recordKey_ == iRecordKey) {
0066           keyedResolversVector.emplace_back(p.dataKey_, p.resolver_);
0067         }
0068       }
0069       return keyedResolversVector;
0070     }
0071 
0072     std::shared_ptr<eventsetup::ESProductResolver> EventSetupTestHelper::getResolver(unsigned int iIndex) {
0073       return resolvers_[iIndex].resolver_;
0074     }
0075 
0076     std::vector<eventsetup::ESModuleProducesInfo> EventSetupTestHelper::producesInfo() const {
0077       std::vector<eventsetup::ESModuleProducesInfo> producesInfo;
0078       producesInfo.reserve(resolvers_.size());
0079       for (auto const& p : resolvers_) {
0080         producesInfo.emplace_back(p.recordKey_, p.dataKey_, p.resolver_->produceMethodID());
0081       }
0082       return producesInfo;
0083     }
0084 
0085     void EventSetupTestHelper::resetAllResolvers() {
0086       for (auto const& p : resolvers_) {
0087         p.resolver_->invalidate();
0088       }
0089     }
0090 
0091   }  // namespace test
0092 }  // namespace edm