CMS 3D CMS Logo

WhatsItAnalyzer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: WhatsItAnalyzer
4 // Class: WhatsItAnalyzer
5 //
13 //
14 // Original Author: Chris Jones
15 // Created: Fri Jun 24 19:13:25 EDT 2005
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 #include <iostream>
22 #include <vector>
23 
24 // user include files
26 
28 
29 #include "WhatsIt.h"
30 #include "GadgetRcd.h"
31 
35 
36 //
37 // class decleration
38 //
39 
40 namespace edmtest {
41 
43  public:
44  explicit WhatsItAnalyzer(const edm::ParameterSet&);
45  ~WhatsItAnalyzer() override;
46 
47  void analyze(const edm::Event&, const edm::EventSetup&) override;
48 
49  private:
50  void getAndTest(edm::EventSetup const&,
52  int expectedValue,
53  const char* label);
54 
55  // ----------member data ---------------------------
56  std::vector<int> expectedValues_;
57  std::vector<std::pair<edm::ESGetToken<WhatsIt, GadgetRcd>, const char*>> tokenAndLabel_;
58  unsigned int index_;
59  };
60 
61  //
62  // constants, enums and typedefs
63  //
64 
65  //
66  // static data member definitions
67  //
68 
69  //
70  // constructors and destructor
71  //
73  : expectedValues_(iConfig.getUntrackedParameter<std::vector<int>>("expectedValues", std::vector<int>())),
74  tokenAndLabel_(5),
75  index_(0) {
76  //now do what ever initialization is needed
77  int i = 0;
78  for (auto l : std::vector<const char*>({"", "A", "B", "C", "D"})) {
80  tokenAndLabel_[i++].second = l;
81  }
82  }
83 
85  // do anything here that needs to be done at desctruction time
86  // (e.g. close files, deallocate resources etc.)
87  }
88 
89  //
90  // member functions
91  //
92 
93  // ------------ method called to produce the data ------------
94  void WhatsItAnalyzer::analyze(const edm::Event& /*iEvent*/, const edm::EventSetup& iSetup) {
95  if (index_ < expectedValues_.size()) {
96  int expectedValue = expectedValues_.at(index_);
97  for (auto const& tl : tokenAndLabel_) {
98  getAndTest(iSetup, tl.first, expectedValue, tl.second);
99  }
100  ++index_;
101  }
102  }
103 
106  int expectedValue,
107  const char* label) {
108  auto const& v = iSetup.getData(token);
109  if (expectedValue != v.a) {
110  throw cms::Exception("TestFail") << label << ": expected value " << expectedValue << " but got " << v.a;
111  }
112  }
113 } // namespace edmtest
114 using namespace edmtest;
115 //define this as a plug-in
WhatsItAnalyzer(const edm::ParameterSet &)
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
char const * label
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< int > expectedValues_
void getAndTest(edm::EventSetup const &, edm::ESGetToken< WhatsIt, GadgetRcd > token, int expectedValue, const char *label)
void analyze(const edm::Event &, const edm::EventSetup &) override
std::vector< std::pair< edm::ESGetToken< WhatsIt, GadgetRcd >, const char * > > tokenAndLabel_