Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-22 01:53:31

0001 // -*- C++ -*-
0002 //
0003 // Package:    FWCore/Integration
0004 // Class:      ConcurrentIOVAnalyzer
0005 //
0006 /**\class edmtest::ConcurrentIOVAnalyzer
0007 
0008  Description: Used in tests of the concurrent IOV features of the
0009  EventSetup system
0010 */
0011 // Original Author:  Chris Jones
0012 //         Created:  Fri Jun 24 19:13:25 EDT 2005
0013 
0014 #include "FWCore/Framework/interface/global/EDAnalyzer.h"
0015 #include "FWCore/Framework/interface/ESHandle.h"
0016 #include "FWCore/Framework/interface/Event.h"
0017 #include "FWCore/Framework/interface/EventSetup.h"
0018 #include "FWCore/Framework/interface/MakerMacros.h"
0019 #include "FWCore/Integration/interface/ESTestRecords.h"
0020 #include "FWCore/Integration/test/IOVTestInfo.h"
0021 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0022 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0023 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0024 #include "FWCore/Utilities/interface/ESGetToken.h"
0025 #include "FWCore/Utilities/interface/ESInputTag.h"
0026 
0027 #include "FWCore/Utilities/interface/Exception.h"
0028 
0029 namespace edmtest {
0030 
0031   class ConcurrentIOVAnalyzer : public edm::global::EDAnalyzer<> {
0032   public:
0033     explicit ConcurrentIOVAnalyzer(edm::ParameterSet const&);
0034 
0035     void analyze(edm::StreamID, edm::Event const&, edm::EventSetup const&) const override;
0036 
0037     static void fillDescriptions(edm::ConfigurationDescriptions&);
0038 
0039   private:
0040     bool checkExpectedValues_;
0041     edm::ESGetToken<IOVTestInfo, ESTestRecordI> const esTokenFromESSource_;
0042     edm::ESGetToken<IOVTestInfo, ESTestRecordI> const esTokenFromESProducer_;
0043   };
0044 
0045   ConcurrentIOVAnalyzer::ConcurrentIOVAnalyzer(edm::ParameterSet const& pset)
0046       : checkExpectedValues_{pset.getUntrackedParameter<bool>("checkExpectedValues")},
0047         esTokenFromESSource_{esConsumes(pset.getUntrackedParameter<edm::ESInputTag>("fromSource"))},
0048         esTokenFromESProducer_{esConsumes(edm::ESInputTag("", "fromESProducer"))} {}
0049 
0050   void ConcurrentIOVAnalyzer::analyze(edm::StreamID, edm::Event const& event, edm::EventSetup const& eventSetup) const {
0051     auto lumiNumber = event.eventAuxiliary().luminosityBlock();
0052 
0053     edm::ESHandle<IOVTestInfo> iovTestInfoFromESSource = eventSetup.getHandle(esTokenFromESSource_);
0054     edm::ESHandle<IOVTestInfo> iovTestInfoFromESProducer = eventSetup.getHandle(esTokenFromESProducer_);
0055 
0056     ESTestRecordI esTestRecordI = eventSetup.get<ESTestRecordI>();
0057     edm::ValidityInterval iov = esTestRecordI.validityInterval();
0058 
0059     if (iovTestInfoFromESSource->iovStartLumi_ != iov.first().luminosityBlockNumber() ||
0060         iovTestInfoFromESSource->iovEndLumi_ != iov.last().luminosityBlockNumber() ||
0061         iovTestInfoFromESSource->iovIndex_ != esTestRecordI.iovIndex() ||
0062         iovTestInfoFromESSource->cacheIdentifier_ != esTestRecordI.cacheIdentifier()) {
0063       throw cms::Exception("TestFailure") << "ConcurrentIOVAnalyzer::analyze,"
0064                                           << " values read from ESSource do not agree with record";
0065     }
0066 
0067     if (iovTestInfoFromESProducer->iovStartLumi_ != iov.first().luminosityBlockNumber() ||
0068         iovTestInfoFromESProducer->iovEndLumi_ != iov.last().luminosityBlockNumber() ||
0069         iovTestInfoFromESProducer->iovIndex_ != esTestRecordI.iovIndex() ||
0070         iovTestInfoFromESProducer->cacheIdentifier_ != esTestRecordI.cacheIdentifier()) {
0071       throw cms::Exception("TestFailure") << "ConcurrentIOVAnalyzer::analyze,"
0072                                           << " values read from ESProducer do not agree with record";
0073     }
0074 
0075     if (!checkExpectedValues_) {
0076       return;
0077     }
0078 
0079     // cacheIdentifier starts at 2 for beginRun and 3 is next here for the first lumi
0080     if (lumiNumber == 1) {
0081       if (iovTestInfoFromESProducer->iovStartLumi_ != 1 || iovTestInfoFromESProducer->iovEndLumi_ != 3 ||
0082           iovTestInfoFromESProducer->cacheIdentifier_ != 3) {
0083         throw cms::Exception("TestFailure") << "ConcurrentIOVAnalyzer::analyze,"
0084                                             << " values read from ESProducer do not agree with expected values";
0085       }
0086     }
0087     if (lumiNumber == 2) {
0088       if (iovTestInfoFromESProducer->iovStartLumi_ != 1 || iovTestInfoFromESProducer->iovEndLumi_ != 3 ||
0089           iovTestInfoFromESProducer->cacheIdentifier_ != 3) {
0090         throw cms::Exception("TestFailure") << "ConcurrentIOVAnalyzer::analyze,"
0091                                             << " values read from ESProducer do not agree with expected values";
0092       }
0093     }
0094     if (lumiNumber == 3) {
0095       if (iovTestInfoFromESProducer->iovStartLumi_ != 1 || iovTestInfoFromESProducer->iovEndLumi_ != 3 ||
0096           iovTestInfoFromESProducer->cacheIdentifier_ != 3) {
0097         throw cms::Exception("TestFailure") << "ConcurrentIOVAnalyzer::analyze,"
0098                                             << " values read from ESProducer do not agree with expected values";
0099       }
0100     }
0101     if (lumiNumber == 4) {
0102       if (iovTestInfoFromESProducer->iovStartLumi_ != 4 || iovTestInfoFromESProducer->iovEndLumi_ != 5 ||
0103           iovTestInfoFromESProducer->cacheIdentifier_ != 4) {
0104         throw cms::Exception("TestFailure") << "ConcurrentIOVAnalyzer::analyze,"
0105                                             << " values read from ESProducer do not agree with expected values";
0106       }
0107     }
0108     if (lumiNumber == 5) {
0109       if (iovTestInfoFromESProducer->iovStartLumi_ != 4 || iovTestInfoFromESProducer->iovEndLumi_ != 5 ||
0110           iovTestInfoFromESProducer->cacheIdentifier_ != 4) {
0111         throw cms::Exception("TestFailure") << "ConcurrentIOVAnalyzer::analyze,"
0112                                             << " values read from ESProducer do not agree with expected values";
0113       }
0114     }
0115     if (lumiNumber == 6) {
0116       if (iovTestInfoFromESProducer->iovStartLumi_ != 6 || iovTestInfoFromESProducer->iovEndLumi_ != 6 ||
0117           iovTestInfoFromESProducer->cacheIdentifier_ != 5) {
0118         throw cms::Exception("TestFailure") << "ConcurrentIOVAnalyzer::analyze,"
0119                                             << " values read from ESProducer do not agree with expected values";
0120       }
0121     }
0122     if (lumiNumber == 7) {
0123       if (iovTestInfoFromESProducer->iovStartLumi_ != 7 || iovTestInfoFromESProducer->iovEndLumi_ != 7 ||
0124           iovTestInfoFromESProducer->cacheIdentifier_ != 6) {
0125         throw cms::Exception("TestFailure") << "ConcurrentIOVAnalyzer::analyze,"
0126                                             << " values read from ESProducer do not agree with expected values";
0127       }
0128     }
0129     if (lumiNumber == 8) {
0130       if (iovTestInfoFromESProducer->iovStartLumi_ != 8 || iovTestInfoFromESProducer->iovEndLumi_ != 8 ||
0131           iovTestInfoFromESProducer->cacheIdentifier_ != 7) {
0132         throw cms::Exception("TestFailure") << "ConcurrentIOVAnalyzer::analyze,"
0133                                             << " values read from ESProducer do not agree with expected values";
0134       }
0135     }
0136   }
0137 
0138   void ConcurrentIOVAnalyzer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0139     edm::ParameterSetDescription desc;
0140     desc.addUntracked<bool>("checkExpectedValues", true);
0141     desc.addUntracked<edm::ESInputTag>("fromSource", edm::ESInputTag("", ""));
0142     descriptions.addDefault(desc);
0143   }
0144 }  // namespace edmtest
0145 using namespace edmtest;
0146 DEFINE_FWK_MODULE(ConcurrentIOVAnalyzer);