CMS 3D CMS Logo

ConcurrentIOVAnalyzer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: FWCore/Integration
4 // Class: ConcurrentIOVAnalyzer
5 //
11 // Original Author: Chris Jones
12 // Created: Fri Jun 24 19:13:25 EDT 2005
13 
27 
29 
30 #include <vector>
31 
32 namespace edmtest {
33 
35  public:
37 
38  void analyze(edm::StreamID, edm::Event const&, edm::EventSetup const&) const override;
39 
41 
42  private:
52  };
53 
55  : checkExpectedValues_{pset.getUntrackedParameter<bool>("checkExpectedValues")},
56  esTokenFromESSource_{esConsumes(pset.getUntrackedParameter<edm::ESInputTag>("fromSource"))},
57  esTokenFromESProducer_{esConsumes(edm::ESInputTag("", "fromESProducer"))},
58  expectedESAcquireTestResults_{pset.getUntrackedParameter<std::vector<int>>("expectedESAcquireTestResults")},
59  expectedUniquePtrTestValue_{pset.getUntrackedParameter<int>("expectedUniquePtrTestValue")},
60  expectedOptionalTestValue_{pset.getUntrackedParameter<int>("expectedOptionalTestValue")} {
61  if (!expectedESAcquireTestResults_.empty()) {
62  esTokenFromAcquireIntESProducer_ = esConsumes(edm::ESInputTag("", "fromAcquireIntESProducer"));
63  }
64  if (expectedUniquePtrTestValue_ != 0) {
65  esTokenUniquePtrTestValue_ = esConsumes(edm::ESInputTag("", "uniquePtr"));
66  }
67  if (expectedOptionalTestValue_ != 0) {
68  esTokenOptionalTestValue_ = esConsumes(edm::ESInputTag("", "optional"));
69  }
70  }
71 
73  auto lumiNumber = event.eventAuxiliary().luminosityBlock();
74 
75  edm::ESHandle<IOVTestInfo> iovTestInfoFromESSource = eventSetup.getHandle(esTokenFromESSource_);
76  edm::ESHandle<IOVTestInfo> iovTestInfoFromESProducer = eventSetup.getHandle(esTokenFromESProducer_);
77 
78  ESTestRecordI esTestRecordI = eventSetup.get<ESTestRecordI>();
79  edm::ValidityInterval iov = esTestRecordI.validityInterval();
80 
81  if (iovTestInfoFromESSource->iovStartLumi_ != iov.first().luminosityBlockNumber() ||
82  iovTestInfoFromESSource->iovEndLumi_ != iov.last().luminosityBlockNumber() ||
83  iovTestInfoFromESSource->iovIndex_ != esTestRecordI.iovIndex() ||
84  iovTestInfoFromESSource->cacheIdentifier_ != esTestRecordI.cacheIdentifier()) {
85  throw cms::Exception("TestFailure") << "ConcurrentIOVAnalyzer::analyze,"
86  << " values read from ESSource do not agree with record";
87  }
88 
89  if (iovTestInfoFromESProducer->iovStartLumi_ != iov.first().luminosityBlockNumber() ||
90  iovTestInfoFromESProducer->iovEndLumi_ != iov.last().luminosityBlockNumber() ||
91  iovTestInfoFromESProducer->iovIndex_ != esTestRecordI.iovIndex() ||
92  iovTestInfoFromESProducer->cacheIdentifier_ != esTestRecordI.cacheIdentifier()) {
93  throw cms::Exception("TestFailure") << "ConcurrentIOVAnalyzer::analyze,"
94  << " values read from ESProducer do not agree with record";
95  }
96 
97  // First cacheIdentifier in the test is actually 3 (0, 1, and 2 just are ignored)
98  unsigned int cacheIdentifier = esTestRecordI.cacheIdentifier();
99  if (cacheIdentifier < expectedESAcquireTestResults_.size()) {
100  int testResult = eventSetup.getData(esTokenFromAcquireIntESProducer_).value();
101  if (testResult != expectedESAcquireTestResults_[cacheIdentifier]) {
102  throw cms::Exception("TestFailure")
103  << "ConcurrentIOVAnalyzer::analyze,"
104  << " unexpected value for EventSetup acquire test.\n"
105  << "Expected = " << expectedESAcquireTestResults_[cacheIdentifier] << " result = " << testResult
106  << " cacheIdentifier = " << cacheIdentifier << "\n";
107  }
108  }
109 
110  if (expectedUniquePtrTestValue_ != 0) {
112  throw cms::Exception("TestFailure")
113  << "ConcurrentIOVAnalyzer::analyze,"
114  << " value for unique_ptr test from EventSetup does not match expected value";
115  }
116  }
117 
118  if (expectedOptionalTestValue_ != 0) {
120  throw cms::Exception("TestFailure") << "ConcurrentIOVAnalyzer::analyze,"
121  << " value for optional test from EventSetup does not match expected value";
122  }
123  }
124 
125  if (!checkExpectedValues_) {
126  return;
127  }
128 
129  // cacheIdentifier starts at 2 for beginRun and 3 is next here for the first lumi
130  if (lumiNumber == 1) {
131  if (iovTestInfoFromESProducer->iovStartLumi_ != 1 || iovTestInfoFromESProducer->iovEndLumi_ != 3 ||
132  iovTestInfoFromESProducer->cacheIdentifier_ != 3) {
133  throw cms::Exception("TestFailure") << "ConcurrentIOVAnalyzer::analyze,"
134  << " values read from ESProducer do not agree with expected values";
135  }
136  }
137  if (lumiNumber == 2) {
138  if (iovTestInfoFromESProducer->iovStartLumi_ != 1 || iovTestInfoFromESProducer->iovEndLumi_ != 3 ||
139  iovTestInfoFromESProducer->cacheIdentifier_ != 3) {
140  throw cms::Exception("TestFailure") << "ConcurrentIOVAnalyzer::analyze,"
141  << " values read from ESProducer do not agree with expected values";
142  }
143  }
144  if (lumiNumber == 3) {
145  if (iovTestInfoFromESProducer->iovStartLumi_ != 1 || iovTestInfoFromESProducer->iovEndLumi_ != 3 ||
146  iovTestInfoFromESProducer->cacheIdentifier_ != 3) {
147  throw cms::Exception("TestFailure") << "ConcurrentIOVAnalyzer::analyze,"
148  << " values read from ESProducer do not agree with expected values";
149  }
150  }
151  if (lumiNumber == 4) {
152  if (iovTestInfoFromESProducer->iovStartLumi_ != 4 || iovTestInfoFromESProducer->iovEndLumi_ != 5 ||
153  iovTestInfoFromESProducer->cacheIdentifier_ != 4) {
154  throw cms::Exception("TestFailure") << "ConcurrentIOVAnalyzer::analyze,"
155  << " values read from ESProducer do not agree with expected values";
156  }
157  }
158  if (lumiNumber == 5) {
159  if (iovTestInfoFromESProducer->iovStartLumi_ != 4 || iovTestInfoFromESProducer->iovEndLumi_ != 5 ||
160  iovTestInfoFromESProducer->cacheIdentifier_ != 4) {
161  throw cms::Exception("TestFailure") << "ConcurrentIOVAnalyzer::analyze,"
162  << " values read from ESProducer do not agree with expected values";
163  }
164  }
165  if (lumiNumber == 6) {
166  if (iovTestInfoFromESProducer->iovStartLumi_ != 6 || iovTestInfoFromESProducer->iovEndLumi_ != 6 ||
167  iovTestInfoFromESProducer->cacheIdentifier_ != 5) {
168  throw cms::Exception("TestFailure") << "ConcurrentIOVAnalyzer::analyze,"
169  << " values read from ESProducer do not agree with expected values";
170  }
171  }
172  if (lumiNumber == 7) {
173  if (iovTestInfoFromESProducer->iovStartLumi_ != 7 || iovTestInfoFromESProducer->iovEndLumi_ != 7 ||
174  iovTestInfoFromESProducer->cacheIdentifier_ != 6) {
175  throw cms::Exception("TestFailure") << "ConcurrentIOVAnalyzer::analyze,"
176  << " values read from ESProducer do not agree with expected values";
177  }
178  }
179  if (lumiNumber == 8) {
180  if (iovTestInfoFromESProducer->iovStartLumi_ != 8 || iovTestInfoFromESProducer->iovEndLumi_ != 8 ||
181  iovTestInfoFromESProducer->cacheIdentifier_ != 7) {
182  throw cms::Exception("TestFailure") << "ConcurrentIOVAnalyzer::analyze,"
183  << " values read from ESProducer do not agree with expected values";
184  }
185  }
186  }
187 
190  desc.addUntracked<bool>("checkExpectedValues", true);
191  desc.addUntracked<edm::ESInputTag>("fromSource", edm::ESInputTag("", ""));
192  desc.addUntracked<std::vector<int>>("expectedESAcquireTestResults", std::vector<int>());
193  desc.addUntracked<int>("expectedUniquePtrTestValue", 0);
194  desc.addUntracked<int>("expectedOptionalTestValue", 0);
195  descriptions.addDefault(desc);
196  }
197 } // namespace edmtest
198 using namespace edmtest;
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
unsigned int iovEndLumi_
Definition: IOVTestInfo.h:24
ConcurrentIOVAnalyzer(edm::ParameterSet const &)
unsigned int iovIndex_
Definition: IOVTestInfo.h:25
static void fillDescriptions(edm::ConfigurationDescriptions &)
edm::ESGetToken< IOVTestInfo, ESTestRecordI > const esTokenFromESProducer_
unsigned long long cacheIdentifier() const
edm::ESGetToken< ESTestDataI, ESTestRecordI > esTokenOptionalTestValue_
void addDefault(ParameterSetDescription const &psetDescription)
edm::ESGetToken< IOVTestInfo, ESTestRecordI > const esTokenFromESSource_
unsigned int iovStartLumi_
Definition: IOVTestInfo.h:22
std::vector< int > expectedESAcquireTestResults_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void analyze(edm::StreamID, edm::Event const &, edm::EventSetup const &) const override
unsigned long long cacheIdentifier_
Definition: IOVTestInfo.h:26
ValidityInterval validityInterval() const
edm::ESGetToken< ESTestDataI, ESTestRecordI > esTokenUniquePtrTestValue_
Definition: event.py:1
edm::ESGetToken< ESTestDataI, ESTestRecordI > esTokenFromAcquireIntESProducer_