Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // Package:    Framework
0004 // Class:      TestESDummyDataAnalyzer
0005 //
0006 /**\class TestESDummyDataAnalyzer TestESDummyDataAnalyzer.cc FWCore/Framework/test/stubs/TestESDummyDataAnalyzer.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Chris Jones
0015 //         Created:  Thu Dec 22 11:02:00 EST 2005
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 
0022 // user include files
0023 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0024 
0025 #include "FWCore/Framework/interface/ESHandle.h"
0026 #include "FWCore/Framework/interface/EventSetup.h"
0027 #include "FWCore/Framework/interface/MakerMacros.h"
0028 
0029 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0030 #include "FWCore/Framework/test/DummyData.h"
0031 
0032 #include "FWCore/Utilities/interface/Exception.h"
0033 
0034 namespace testesdummydata {
0035   struct DummyRunCache {};
0036 }  // namespace testesdummydata
0037 
0038 using testesdummydata::DummyRunCache;
0039 
0040 class TestESDummyDataAnalyzer : public edm::one::EDAnalyzer<edm::RunCache<DummyRunCache>> {
0041 public:
0042   explicit TestESDummyDataAnalyzer(const edm::ParameterSet&);
0043 
0044 private:
0045   void endJob() override;
0046   std::shared_ptr<DummyRunCache> globalBeginRun(const edm::Run&, const edm::EventSetup&) const override { return {}; }
0047   void analyze(const edm::Event&, const edm::EventSetup&) override;
0048   void globalEndRun(const edm::Run&, const edm::EventSetup&) override {}
0049 
0050   int m_expectedValue;
0051   int const m_nEventsValue;
0052   int m_counter{};
0053   int m_totalCounter{};
0054   int const m_totalNEvents;
0055   // At the moment the begin run token is not used to get anything,
0056   // but just its existence tests the indexing used in the esConsumes
0057   // function call
0058   edm::ESGetToken<edm::eventsetup::test::DummyData, edm::DefaultRecord> const m_esTokenBeginRun;
0059   edm::ESGetToken<edm::eventsetup::test::DummyData, edm::DefaultRecord> const m_esToken;
0060 };
0061 
0062 TestESDummyDataAnalyzer::TestESDummyDataAnalyzer(const edm::ParameterSet& iConfig)
0063     : m_expectedValue{iConfig.getParameter<int>("expected")},
0064       m_nEventsValue{iConfig.getUntrackedParameter<int>("nEvents", 0)},
0065       m_totalNEvents{iConfig.getUntrackedParameter<int>("totalNEvents", -1)},
0066       m_esTokenBeginRun{esConsumes<edm::Transition::BeginRun>()},
0067       m_esToken{esConsumes()} {}
0068 
0069 void TestESDummyDataAnalyzer::analyze(const edm::Event&, const edm::EventSetup& iSetup) {
0070   using namespace edm;
0071 
0072   ++m_totalCounter;
0073   if (m_nEventsValue) {
0074     ++m_counter;
0075     if (m_nEventsValue < m_counter) {
0076       ++m_expectedValue;
0077       m_counter = 0;
0078     }
0079   }
0080 
0081   ESHandle<edm::eventsetup::test::DummyData> pData = iSetup.getHandle(m_esToken);
0082 
0083   if (m_expectedValue != pData->value_) {
0084     throw cms::Exception("WrongValue") << "got value " << pData->value_ << " but expected " << m_expectedValue;
0085   }
0086 }
0087 
0088 void TestESDummyDataAnalyzer::endJob() {
0089   if (-1 != m_totalNEvents && m_totalNEvents != m_totalCounter) {
0090     throw cms::Exception("WrongNumberOfEvents")
0091         << "expected " << m_totalNEvents << " but instead saw " << m_totalCounter << "\n";
0092   }
0093 }
0094 
0095 DEFINE_FWK_MODULE(TestESDummyDataAnalyzer);