Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:12:33

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/ESTestData.h"
0020 #include "FWCore/Integration/interface/ESTestRecords.h"
0021 #include "FWCore/Integration/interface/IOVTestInfo.h"
0022 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0023 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0024 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0025 #include "FWCore/Utilities/interface/ESGetToken.h"
0026 #include "FWCore/Utilities/interface/ESInputTag.h"
0027 
0028 #include "FWCore/Utilities/interface/Exception.h"
0029 
0030 #include <vector>
0031 
0032 namespace edmtest {
0033 
0034   class ConcurrentIOVAnalyzer : public edm::global::EDAnalyzer<> {
0035   public:
0036     explicit ConcurrentIOVAnalyzer(edm::ParameterSet const&);
0037 
0038     void analyze(edm::StreamID, edm::Event const&, edm::EventSetup const&) const override;
0039 
0040     static void fillDescriptions(edm::ConfigurationDescriptions&);
0041 
0042   private:
0043     bool checkExpectedValues_;
0044     edm::ESGetToken<IOVTestInfo, ESTestRecordI> const esTokenFromESSource_;
0045     edm::ESGetToken<IOVTestInfo, ESTestRecordI> const esTokenFromESProducer_;
0046     edm::ESGetToken<ESTestDataI, ESTestRecordI> esTokenFromAcquireIntESProducer_;
0047     std::vector<int> expectedESAcquireTestResults_;
0048     edm::ESGetToken<ESTestDataI, ESTestRecordI> esTokenUniquePtrTestValue_;
0049     edm::ESGetToken<ESTestDataI, ESTestRecordI> esTokenLambdaUniquePtrTestValue_;
0050     int expectedUniquePtrTestValue_;
0051     edm::ESGetToken<ESTestDataI, ESTestRecordI> esTokenOptionalTestValue_;
0052     edm::ESGetToken<ESTestDataI, ESTestRecordI> esTokenLambdaOptionalTestValue_;
0053     int expectedOptionalTestValue_;
0054   };
0055 
0056   ConcurrentIOVAnalyzer::ConcurrentIOVAnalyzer(edm::ParameterSet const& pset)
0057       : checkExpectedValues_{pset.getUntrackedParameter<bool>("checkExpectedValues")},
0058         esTokenFromESSource_{esConsumes(pset.getUntrackedParameter<edm::ESInputTag>("fromSource"))},
0059         esTokenFromESProducer_{esConsumes(edm::ESInputTag("", "fromESProducer"))},
0060         expectedESAcquireTestResults_{pset.getUntrackedParameter<std::vector<int>>("expectedESAcquireTestResults")},
0061         expectedUniquePtrTestValue_{pset.getUntrackedParameter<int>("expectedUniquePtrTestValue")},
0062         expectedOptionalTestValue_{pset.getUntrackedParameter<int>("expectedOptionalTestValue")} {
0063     if (!expectedESAcquireTestResults_.empty()) {
0064       esTokenFromAcquireIntESProducer_ = esConsumes(edm::ESInputTag("", "fromAcquireIntESProducer"));
0065     }
0066     if (expectedUniquePtrTestValue_ != 0) {
0067       esTokenUniquePtrTestValue_ = esConsumes(edm::ESInputTag("", "uniquePtr"));
0068       esTokenLambdaUniquePtrTestValue_ = esConsumes(edm::ESInputTag("", "uniquePtrLambda"));
0069     }
0070     if (expectedOptionalTestValue_ != 0) {
0071       esTokenOptionalTestValue_ = esConsumes(edm::ESInputTag("", "optional"));
0072       esTokenLambdaOptionalTestValue_ = esConsumes(edm::ESInputTag("", "optionalLambda"));
0073     }
0074   }
0075 
0076   void ConcurrentIOVAnalyzer::analyze(edm::StreamID, edm::Event const& event, edm::EventSetup const& eventSetup) const {
0077     auto lumiNumber = event.eventAuxiliary().luminosityBlock();
0078 
0079     edm::ESHandle<IOVTestInfo> iovTestInfoFromESSource = eventSetup.getHandle(esTokenFromESSource_);
0080     edm::ESHandle<IOVTestInfo> iovTestInfoFromESProducer = eventSetup.getHandle(esTokenFromESProducer_);
0081 
0082     ESTestRecordI esTestRecordI = eventSetup.get<ESTestRecordI>();
0083     edm::ValidityInterval iov = esTestRecordI.validityInterval();
0084 
0085     if (iovTestInfoFromESSource->iovStartLumi_ != iov.first().luminosityBlockNumber() ||
0086         iovTestInfoFromESSource->iovEndLumi_ != iov.last().luminosityBlockNumber() ||
0087         iovTestInfoFromESSource->iovIndex_ != esTestRecordI.iovIndex() ||
0088         iovTestInfoFromESSource->cacheIdentifier_ != esTestRecordI.cacheIdentifier()) {
0089       throw cms::Exception("TestFailure") << "ConcurrentIOVAnalyzer::analyze,"
0090                                           << " values read from ESSource do not agree with record";
0091     }
0092 
0093     if (iovTestInfoFromESProducer->iovStartLumi_ != iov.first().luminosityBlockNumber() ||
0094         iovTestInfoFromESProducer->iovEndLumi_ != iov.last().luminosityBlockNumber() ||
0095         iovTestInfoFromESProducer->iovIndex_ != esTestRecordI.iovIndex() ||
0096         iovTestInfoFromESProducer->cacheIdentifier_ != esTestRecordI.cacheIdentifier()) {
0097       throw cms::Exception("TestFailure") << "ConcurrentIOVAnalyzer::analyze,"
0098                                           << " values read from ESProducer do not agree with record";
0099     }
0100 
0101     // First cacheIdentifier in the test is actually 3 (0, 1, and 2 just are ignored)
0102     unsigned int cacheIdentifier = esTestRecordI.cacheIdentifier();
0103     if (cacheIdentifier < expectedESAcquireTestResults_.size()) {
0104       int testResult = eventSetup.getData(esTokenFromAcquireIntESProducer_).value();
0105       if (testResult != expectedESAcquireTestResults_[cacheIdentifier]) {
0106         throw cms::Exception("TestFailure")
0107             << "ConcurrentIOVAnalyzer::analyze,"
0108             << " unexpected value for EventSetup acquire test.\n"
0109             << "Expected = " << expectedESAcquireTestResults_[cacheIdentifier] << " result = " << testResult
0110             << " cacheIdentifier = " << cacheIdentifier << "\n";
0111       }
0112     }
0113 
0114     if (expectedUniquePtrTestValue_ != 0) {
0115       if (eventSetup.getData(esTokenUniquePtrTestValue_).value() != expectedUniquePtrTestValue_) {
0116         throw cms::Exception("TestFailure")
0117             << "ConcurrentIOVAnalyzer::analyze,"
0118             << " value for unique_ptr test from EventSetup does not match expected value";
0119       }
0120       if (eventSetup.getData(esTokenLambdaUniquePtrTestValue_).value() != expectedUniquePtrTestValue_) {
0121         throw cms::Exception("TestFailure")
0122             << "ConcurrentIOVAnalyzer::analyze,"
0123             << " value for lambda unique_ptr test from EventSetup does not match expected value";
0124       }
0125     }
0126 
0127     if (expectedOptionalTestValue_ != 0) {
0128       if (eventSetup.getData(esTokenOptionalTestValue_).value() != expectedOptionalTestValue_) {
0129         throw cms::Exception("TestFailure") << "ConcurrentIOVAnalyzer::analyze,"
0130                                             << " value for optional test from EventSetup does not match expected value";
0131       }
0132       if (eventSetup.getData(esTokenLambdaOptionalTestValue_).value() != expectedOptionalTestValue_) {
0133         throw cms::Exception("TestFailure")
0134             << "ConcurrentIOVAnalyzer::analyze,"
0135             << " value for lambda optional test from EventSetup does not match expected value";
0136       }
0137     }
0138 
0139     if (!checkExpectedValues_) {
0140       return;
0141     }
0142 
0143     // cacheIdentifier starts at 2 for beginRun and 3 is next here for the first lumi
0144     if (lumiNumber == 1) {
0145       if (iovTestInfoFromESProducer->iovStartLumi_ != 1 || iovTestInfoFromESProducer->iovEndLumi_ != 3 ||
0146           iovTestInfoFromESProducer->cacheIdentifier_ != 3) {
0147         throw cms::Exception("TestFailure") << "ConcurrentIOVAnalyzer::analyze,"
0148                                             << " values read from ESProducer do not agree with expected values";
0149       }
0150     }
0151     if (lumiNumber == 2) {
0152       if (iovTestInfoFromESProducer->iovStartLumi_ != 1 || iovTestInfoFromESProducer->iovEndLumi_ != 3 ||
0153           iovTestInfoFromESProducer->cacheIdentifier_ != 3) {
0154         throw cms::Exception("TestFailure") << "ConcurrentIOVAnalyzer::analyze,"
0155                                             << " values read from ESProducer do not agree with expected values";
0156       }
0157     }
0158     if (lumiNumber == 3) {
0159       if (iovTestInfoFromESProducer->iovStartLumi_ != 1 || iovTestInfoFromESProducer->iovEndLumi_ != 3 ||
0160           iovTestInfoFromESProducer->cacheIdentifier_ != 3) {
0161         throw cms::Exception("TestFailure") << "ConcurrentIOVAnalyzer::analyze,"
0162                                             << " values read from ESProducer do not agree with expected values";
0163       }
0164     }
0165     if (lumiNumber == 4) {
0166       if (iovTestInfoFromESProducer->iovStartLumi_ != 4 || iovTestInfoFromESProducer->iovEndLumi_ != 5 ||
0167           iovTestInfoFromESProducer->cacheIdentifier_ != 4) {
0168         throw cms::Exception("TestFailure") << "ConcurrentIOVAnalyzer::analyze,"
0169                                             << " values read from ESProducer do not agree with expected values";
0170       }
0171     }
0172     if (lumiNumber == 5) {
0173       if (iovTestInfoFromESProducer->iovStartLumi_ != 4 || iovTestInfoFromESProducer->iovEndLumi_ != 5 ||
0174           iovTestInfoFromESProducer->cacheIdentifier_ != 4) {
0175         throw cms::Exception("TestFailure") << "ConcurrentIOVAnalyzer::analyze,"
0176                                             << " values read from ESProducer do not agree with expected values";
0177       }
0178     }
0179     if (lumiNumber == 6) {
0180       if (iovTestInfoFromESProducer->iovStartLumi_ != 6 || iovTestInfoFromESProducer->iovEndLumi_ != 6 ||
0181           iovTestInfoFromESProducer->cacheIdentifier_ != 5) {
0182         throw cms::Exception("TestFailure") << "ConcurrentIOVAnalyzer::analyze,"
0183                                             << " values read from ESProducer do not agree with expected values";
0184       }
0185     }
0186     if (lumiNumber == 7) {
0187       if (iovTestInfoFromESProducer->iovStartLumi_ != 7 || iovTestInfoFromESProducer->iovEndLumi_ != 7 ||
0188           iovTestInfoFromESProducer->cacheIdentifier_ != 6) {
0189         throw cms::Exception("TestFailure") << "ConcurrentIOVAnalyzer::analyze,"
0190                                             << " values read from ESProducer do not agree with expected values";
0191       }
0192     }
0193     if (lumiNumber == 8) {
0194       if (iovTestInfoFromESProducer->iovStartLumi_ != 8 || iovTestInfoFromESProducer->iovEndLumi_ != 8 ||
0195           iovTestInfoFromESProducer->cacheIdentifier_ != 7) {
0196         throw cms::Exception("TestFailure") << "ConcurrentIOVAnalyzer::analyze,"
0197                                             << " values read from ESProducer do not agree with expected values";
0198       }
0199     }
0200   }
0201 
0202   void ConcurrentIOVAnalyzer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0203     edm::ParameterSetDescription desc;
0204     desc.addUntracked<bool>("checkExpectedValues", true);
0205     desc.addUntracked<edm::ESInputTag>("fromSource", edm::ESInputTag("", ""));
0206     desc.addUntracked<std::vector<int>>("expectedESAcquireTestResults", std::vector<int>());
0207     desc.addUntracked<int>("expectedUniquePtrTestValue", 0);
0208     desc.addUntracked<int>("expectedOptionalTestValue", 0);
0209     descriptions.addDefault(desc);
0210   }
0211 }  // namespace edmtest
0212 using namespace edmtest;
0213 DEFINE_FWK_MODULE(ConcurrentIOVAnalyzer);