CMS 3D CMS Logo

ESTestAnalyzers.cc
Go to the documentation of this file.
5 #include "DataFormats/TestObjects/interface/ToyProducts.h"
17 
18 #include <algorithm>
19 #include <vector>
20 
21 namespace edmtest {
22 
24  public:
25  explicit ESTestAnalyzerA(edm::ParameterSet const&);
26  void analyze(const edm::Event&, const edm::EventSetup&) override;
27 
28  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
29 
30  private:
31  std::vector<int> const runsToGetDataFor_;
32  std::vector<int> const expectedValues_;
34  };
35 
37  : runsToGetDataFor_(pset.getParameter<std::vector<int>>("runsToGetDataFor")),
38  expectedValues_(pset.getUntrackedParameter<std::vector<int>>("expectedValues")),
39  token_(esConsumes()) {
40  assert(expectedValues_.empty() or expectedValues_.size() == runsToGetDataFor_.size());
41  }
42 
44  auto found = std::find(runsToGetDataFor_.begin(), runsToGetDataFor_.end(), ev.run());
45  if (found != runsToGetDataFor_.end()) {
46  auto const& dataA = es.getData(token_);
47  edm::LogAbsolute("ESTestAnalyzerA")
48  << "ESTestAnalyzerA: process = " << moduleDescription().processName() << ": Data value = " << dataA.value();
49  if (not expectedValues_.empty()) {
50  if (expectedValues_[found - runsToGetDataFor_.begin()] != dataA.value()) {
51  throw cms::Exception("TestError") << "Exptected value " << expectedValues_[found - runsToGetDataFor_.begin()]
52  << " but saw " << dataA.value();
53  }
54  }
55  }
56  }
57 
59  //The following says we do not know what parameters are allowed so do no validation
60  // Please change this to state exactly what you do use, even if it is no parameters
62  desc.setComment("Test module for the EventSetup");
63  desc.add<std::vector<int>>("runsToGetDataFor")
64  ->setComment("ID number for each Run for which we should get EventSetup data.");
65  desc.addUntracked<std::vector<int>>("expectedValues", std::vector<int>())
66  ->setComment("EventSetup value expected for each Run. If empty, no values compared.");
67  descriptions.addDefault(desc);
68  }
69 
71  public:
72  explicit ESTestAnalyzerB(edm::ParameterSet const&);
73  void analyze(const edm::Event&, const edm::EventSetup&) override;
74 
75  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
76 
77  private:
78  const std::vector<int> runsToGetDataFor_;
79  const std::vector<int> expectedValues_;
81 
82  unsigned int expectedIndex_ = 0;
83  };
84 
86  : runsToGetDataFor_(pset.getParameter<std::vector<int>>("runsToGetDataFor")),
87  expectedValues_(pset.getUntrackedParameter<std::vector<int>>("expectedValues")),
88  dataBToken_(esConsumes()) {}
89 
91  if (std::find(runsToGetDataFor_.begin(), runsToGetDataFor_.end(), ev.run()) != runsToGetDataFor_.end()) {
93  edm::LogAbsolute("ESTestAnalyzerB")
94  << "ESTestAnalyzerB: process = " << moduleDescription().processName() << ": Data value = " << dataB->value();
95 
96  if (expectedIndex_ < expectedValues_.size()) {
97  if (expectedValues_[expectedIndex_] != dataB->value()) {
98  throw cms::Exception("TestError")
99  << "Expected does not match actual value, "
100  << "expected value = " << expectedValues_[expectedIndex_] << " actual value = " << dataB->value();
101  }
102  ++expectedIndex_;
103  }
104  }
105  }
106 
109  desc.add<std::vector<int>>("runsToGetDataFor")
110  ->setComment("ID number for each Run for which we should get EventSetup data.");
111  desc.addUntracked<std::vector<int>>("expectedValues", std::vector<int>())
112  ->setComment("EventSetup value expected for each Run. If empty, no values compared.");
113  descriptions.addDefault(desc);
114  }
115 
117  public:
118  explicit ESTestAnalyzerK(edm::ParameterSet const&);
119  void analyze(edm::StreamID, const edm::Event&, const edm::EventSetup&) const override;
120 
121  private:
122  const std::vector<int> runsToGetDataFor_;
124  };
125 
127  : runsToGetDataFor_(pset.getParameter<std::vector<int>>("runsToGetDataFor")), dataKToken_(esConsumes()) {}
128 
130  if (std::find(runsToGetDataFor_.begin(), runsToGetDataFor_.end(), ev.run()) != runsToGetDataFor_.end()) {
131  ESTestDataK const& dataK = es.getData(dataKToken_);
132  edm::LogAbsolute("ESTestAnalyzerK")
133  << "ESTestAnalyzerK: process = " << moduleDescription().processName() << ": Data value = " << dataK.value();
134  }
135  }
136 
138  public:
139  explicit ESTestAnalyzerAZ(edm::ParameterSet const&);
140  void analyze(edm::StreamID, const edm::Event&, const edm::EventSetup&) const override;
141 
142  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
143 
144  private:
145  std::vector<int> const runsToGetDataFor_;
146  std::vector<int> const expectedValuesA_;
147  std::vector<int> const expectedValuesZ_;
150  };
151 
153  : runsToGetDataFor_(pset.getParameter<std::vector<int>>("runsToGetDataFor")),
154  expectedValuesA_(pset.getUntrackedParameter<std::vector<int>>("expectedValuesA")),
155  expectedValuesZ_(pset.getUntrackedParameter<std::vector<int>>("expectedValuesZ")),
156  dataAToken_(esConsumes(edm::ESInputTag("", "foo"))),
157  dataZToken_(esConsumes(edm::ESInputTag("", "foo"))) {
158  assert(expectedValuesA_.empty() or expectedValuesA_.size() == runsToGetDataFor_.size());
159  assert(expectedValuesZ_.empty() or expectedValuesZ_.size() == runsToGetDataFor_.size());
160  }
161 
163  auto found = std::find(runsToGetDataFor_.begin(), runsToGetDataFor_.end(), ev.run());
164 
165  if (found != runsToGetDataFor_.end()) {
166  ESTestDataA const& dataA = es.getData(dataAToken_);
167 
168  ESTestDataZ const& dataZ = es.getData(dataZToken_);
169 
170  edm::LogAbsolute("ESTestAnalyzerAZ") << "ESTestAnalyzerAZ: process = " << moduleDescription().processName()
171  << ": Data values = " << dataA.value() << " " << dataZ.value();
172 
173  if (not expectedValuesA_.empty()) {
174  if (expectedValuesA_[found - runsToGetDataFor_.begin()] != dataA.value()) {
175  throw cms::Exception("TestError")
176  << "Exptected value for A " << expectedValuesA_[found - runsToGetDataFor_.begin()] << " but saw "
177  << dataA.value();
178  }
179  }
180 
181  if (not expectedValuesZ_.empty()) {
182  if (expectedValuesZ_[found - runsToGetDataFor_.begin()] != dataZ.value()) {
183  throw cms::Exception("TestError")
184  << "Exptected value for Z " << expectedValuesZ_[found - runsToGetDataFor_.begin()] << " but saw "
185  << dataZ.value();
186  }
187  }
188  }
189  }
190 
193  desc.setComment("Test module for the EventSetup");
194  desc.add<std::vector<int>>("runsToGetDataFor")
195  ->setComment("ID number for each Run for which we should get EventSetup data.");
196  desc.addUntracked<std::vector<int>>("expectedValuesA", std::vector<int>())
197  ->setComment("EventSetup value for ESTestDataA:foo expected for each Run. If empty, no values compared.");
198  desc.addUntracked<std::vector<int>>("expectedValuesZ", std::vector<int>())
199  ->setComment("EventSetup value for ESTestDataZ:foo expected for each Run. If empty, no values compared.");
200  descriptions.addDefault(desc);
201  }
202 
204  public:
206  void analyze(const edm::Event&, const edm::EventSetup&) override;
207 
208  private:
210  };
211 
213  ESTestDataJ const& dataJ = es.getData(dataJToken_);
214  edm::LogAbsolute("ESTestAnalyzerJ") << "ESTestAnalyzerJ: process = " << moduleDescription().processName()
215  << ": Data values = " << dataJ.value();
216  }
217 
219  public:
220  explicit ESTestAnalyzerL(edm::ParameterSet const& iConfig)
221  : edToken_(consumes(iConfig.getParameter<edm::InputTag>("src"))), esToken_(esConsumes()) {}
222  void analyze(const edm::Event&, const edm::EventSetup&) override;
223 
224  private:
227  };
228 
230  auto const& intData = ev.get(edToken_);
231  auto const& dataJ = es.getData(esToken_);
232  edm::LogAbsolute("ESTestAnalyzerJ") << "ESTestAnalyzerL: process = " << moduleDescription().processName()
233  << ": ED value " << intData.value << ": ES value = " << dataJ.value();
234  }
235 
237  public:
239  void analyze(const edm::Event&, const edm::EventSetup&) override;
240 
241  private:
243  };
244 
246  esToken_ = esConsumes();
247  edm::LogAbsolute("ESTestAnalyzerIncorrectConsumes")
248  << "Succeeded to call esConsumes() in analyze(), should not happen!";
249  }
250 
251 } // namespace edmtest
252 using namespace edmtest;
const edm::ESGetToken< ESTestDataB, ESTestRecordB > dataBToken_
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
edm::ESGetToken< ESTestDataZ, ESTestRecordZ > dataZToken_
const edm::ESGetToken< ESTestDataJ, ESTestRecordJ > dataJToken_
std::vector< int > const expectedValues_
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
ModuleDescription const & moduleDescription() const
const edm::ESGetToken< ESTestDataK, ESTestRecordK > dataKToken_
void analyze(const edm::Event &, const edm::EventSetup &) override
const std::vector< int > expectedValues_
std::vector< int > const runsToGetDataFor_
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
assert(be >=bs)
std::vector< int > const expectedValuesZ_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
ESTestAnalyzerJ(edm::ParameterSet const &)
ESTestAnalyzerIncorrectConsumes(edm::ParameterSet const &iConfig)
edm::ESGetToken< ESTestDataA, ESTestRecordA > const token_
void addDefault(ParameterSetDescription const &psetDescription)
const std::vector< int > runsToGetDataFor_
edm::ESGetToken< ESTestDataJ, ESTestRecordJ > esToken_
void analyze(const edm::Event &, const edm::EventSetup &) override
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
void analyze(const edm::Event &, const edm::EventSetup &) override
ESTestAnalyzerB(edm::ParameterSet const &)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
ESTestAnalyzerL(edm::ParameterSet const &iConfig)
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
void analyze(edm::StreamID, const edm::Event &, const edm::EventSetup &) const override
edm::EDGetTokenT< IntProduct > edToken_
std::string const & processName() const
void analyze(const edm::Event &, const edm::EventSetup &) override
ESTestAnalyzerAZ(edm::ParameterSet const &)
ModuleDescription const & moduleDescription() const
const std::vector< int > runsToGetDataFor_
edm::ESGetToken< ESTestDataA, ESTestRecordA > dataAToken_
HLT enums.
ESTestAnalyzerA(edm::ParameterSet const &)
ModuleDescription const & moduleDescription() const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void analyze(edm::StreamID, const edm::Event &, const edm::EventSetup &) const override
Log< level::System, true > LogAbsolute
void analyze(const edm::Event &, const edm::EventSetup &) override
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::vector< int > const expectedValuesA_
ESTestAnalyzerK(edm::ParameterSet const &)
edm::ESGetToken< ESTestDataJ, ESTestRecordJ > esToken_
std::vector< int > const runsToGetDataFor_