File indexing completed on 2024-04-06 12:12:38
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #include <memory>
0021 #include <iostream>
0022 #include <vector>
0023
0024
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
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
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
0063
0064
0065
0066
0067
0068
0069
0070
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
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
0086
0087 }
0088
0089
0090
0091
0092
0093
0094 void WhatsItAnalyzer::analyze(const edm::Event& , 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 }
0114 using namespace edmtest;
0115
0116 DEFINE_FWK_MODULE(WhatsItAnalyzer);