Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:03:48

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/DataProxy.h"
0018 
0019 namespace edm {
0020   namespace test {
0021 
0022     EventSetupTestHelper::EventSetupTestHelper(std::vector<ESProduceEntry> iProxies) : proxies_{std::move(iProxies)} {
0023       //Deal with duplicates
0024       std::set<eventsetup::EventSetupRecordKey> records;
0025       for (auto const& p : proxies_) {
0026         records.insert(p.recordKey_);
0027       }
0028       for (auto const& k : records) {
0029         usingRecordWithKey(k);
0030         findingRecordWithKey(k);
0031       }
0032     }
0033 
0034     void EventSetupTestHelper::setIntervalFor(const eventsetup::EventSetupRecordKey&,
0035                                               const IOVSyncValue& iSync,
0036                                               ValidityInterval& oIOV) {
0037       // Note that we manually invalidate the proxies at the end of every call
0038       // to test. And the beginning of the call to test is the only opportunity
0039       // to reset this data, so we are not relying on the EventSetup system
0040       // to manage invalidating the proxies in EventSetupTestHelper. The only
0041       // reasonable thing to do is return an interval for all time so the EventSetup
0042       // system does not invalidate these proxies when it shouldn't. There are two
0043       // weaknesses to this:
0044       //
0045       //     1. If for the same record type there are DataProxies both managed
0046       //     by this class and also others managed by the EventSetup, then
0047       //     at IOV boundaries for this record this will fail. The EventSetup
0048       //     will invalidate all the proxies for the record after this class
0049       //     has set the ones it manages and they will stay invalid when they
0050       //     are needed.
0051       //
0052       //     2. TestProcessor does not support the special case where the different
0053       //     transitions executed in one call to test have different IOVs and different
0054       //     EventSetup data. That would be a pretty strange case, especially for a test.
0055 
0056       oIOV = edm::ValidityInterval(edm::IOVSyncValue::beginOfTime(), edm::IOVSyncValue::endOfTime());
0057     }
0058 
0059     eventsetup::DataProxyProvider::KeyedProxiesVector EventSetupTestHelper::registerProxies(
0060         const eventsetup::EventSetupRecordKey& iRecordKey, unsigned int iovIndex) {
0061       KeyedProxiesVector keyedProxiesVector;
0062       for (auto const& p : proxies_) {
0063         if (p.recordKey_ == iRecordKey) {
0064           keyedProxiesVector.emplace_back(p.dataKey_, p.proxy_);
0065         }
0066       }
0067       return keyedProxiesVector;
0068     }
0069 
0070     std::shared_ptr<eventsetup::DataProxy> EventSetupTestHelper::getProxy(unsigned int iIndex) {
0071       return proxies_[iIndex].proxy_;
0072     }
0073 
0074     void EventSetupTestHelper::resetAllProxies() {
0075       for (auto const& p : proxies_) {
0076         p.proxy_->invalidate();
0077       }
0078     }
0079 
0080   }  // namespace test
0081 }  // namespace edm