Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // Package:    WhatsItAnalyzer
0004 // Class:      WhatsItAnalyzer
0005 //
0006 /**\class WhatsItAnalyzer WhatsItAnalyzer.cc test/WhatsItAnalyzer/src/WhatsItAnalyzer.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Chris Jones
0015 //         Created:  Fri Jun 24 19:13:25 EDT 2005
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 #include <iostream>
0022 #include <vector>
0023 
0024 // user include files
0025 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0026 
0027 #include "FWCore/Framework/interface/MakerMacros.h"
0028 
0029 #include "WhatsIt.h"
0030 #include "GadgetRcd.h"
0031 
0032 #include "FWCore/Framework/interface/ESHandle.h"
0033 #include "FWCore/Framework/interface/EventSetup.h"
0034 #include "FWCore/Utilities/interface/Exception.h"
0035 
0036 //
0037 // class decleration
0038 //
0039 
0040 namespace edmtest {
0041 
0042   class WhatsItAnalyzer : public edm::one::EDAnalyzer<> {
0043   public:
0044     explicit WhatsItAnalyzer(const edm::ParameterSet&);
0045     ~WhatsItAnalyzer() override;
0046 
0047     void analyze(const edm::Event&, const edm::EventSetup&) override;
0048 
0049   private:
0050     void getAndTest(edm::EventSetup const&,
0051                     edm::ESGetToken<WhatsIt, GadgetRcd> token,
0052                     int expectedValue,
0053                     const char* label);
0054 
0055     // ----------member data ---------------------------
0056     std::vector<int> expectedValues_;
0057     std::vector<std::pair<edm::ESGetToken<WhatsIt, GadgetRcd>, const char*>> tokenAndLabel_;
0058     unsigned int index_;
0059   };
0060 
0061   //
0062   // constants, enums and typedefs
0063   //
0064 
0065   //
0066   // static data member definitions
0067   //
0068 
0069   //
0070   // constructors and destructor
0071   //
0072   WhatsItAnalyzer::WhatsItAnalyzer(const edm::ParameterSet& iConfig)
0073       : expectedValues_(iConfig.getUntrackedParameter<std::vector<int>>("expectedValues", std::vector<int>())),
0074         tokenAndLabel_(5),
0075         index_(0) {
0076     //now do what ever initialization is needed
0077     int i = 0;
0078     for (auto l : std::vector<const char*>({"", "A", "B", "C", "D"})) {
0079       tokenAndLabel_[i].first = esConsumes(edm::ESInputTag("", l));
0080       tokenAndLabel_[i++].second = l;
0081     }
0082   }
0083 
0084   WhatsItAnalyzer::~WhatsItAnalyzer() {
0085     // do anything here that needs to be done at desctruction time
0086     // (e.g. close files, deallocate resources etc.)
0087   }
0088 
0089   //
0090   // member functions
0091   //
0092 
0093   // ------------ method called to produce the data  ------------
0094   void WhatsItAnalyzer::analyze(const edm::Event& /*iEvent*/, const edm::EventSetup& iSetup) {
0095     if (index_ < expectedValues_.size()) {
0096       int expectedValue = expectedValues_.at(index_);
0097       for (auto const& tl : tokenAndLabel_) {
0098         getAndTest(iSetup, tl.first, expectedValue, tl.second);
0099       }
0100       ++index_;
0101     }
0102   }
0103 
0104   void WhatsItAnalyzer::getAndTest(const edm::EventSetup& iSetup,
0105                                    edm::ESGetToken<WhatsIt, GadgetRcd> token,
0106                                    int expectedValue,
0107                                    const char* label) {
0108     auto const& v = iSetup.getData(token);
0109     if (expectedValue != v.a) {
0110       throw cms::Exception("TestFail") << label << ": expected value " << expectedValue << " but got " << v.a;
0111     }
0112   }
0113 }  // namespace edmtest
0114 using namespace edmtest;
0115 //define this as a plug-in
0116 DEFINE_FWK_MODULE(WhatsItAnalyzer);