CMS 3D CMS Logo

RunLumiESAnalyzer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: FWCore/Integration
4 // Class: RunLumiESAnalyzer
5 //
12 // Original Author: W. David Dagenhart
13 // Created: 18 April 2019
14 
22 #include "IOVTestInfo.h"
29 
30 #include <memory>
31 
32 namespace {
33  struct Cache {
34  Cache() : value(0) {}
35  //Using mutable since we want to update the value.
36  mutable std::atomic<unsigned int> value;
37  };
38 
39  struct UnsafeCache {
40  UnsafeCache() : value(0) {}
41  unsigned int value;
42  };
43 } //end anonymous namespace
44 
45 namespace edmtest {
46 
47  class RunLumiESAnalyzer : public edm::global::EDAnalyzer<edm::StreamCache<UnsafeCache>,
48  edm::RunCache<Cache>,
49  edm::LuminosityBlockCache<Cache>> {
50  public:
51  explicit RunLumiESAnalyzer(edm::ParameterSet const&);
52 
53  std::unique_ptr<UnsafeCache> beginStream(edm::StreamID) const override;
54  void streamBeginRun(edm::StreamID, edm::Run const&, edm::EventSetup const&) const override;
57  void streamEndRun(edm::StreamID, edm::Run const&, edm::EventSetup const&) const override;
58 
59  std::shared_ptr<Cache> globalBeginRun(edm::Run const&, edm::EventSetup const&) const override;
60  void globalEndRun(edm::Run const& iRun, edm::EventSetup const&) const override;
61  std::shared_ptr<Cache> globalBeginLuminosityBlock(edm::LuminosityBlock const&,
62  edm::EventSetup const&) const override;
63  void globalEndLuminosityBlock(edm::LuminosityBlock const& iLB, edm::EventSetup const&) const override;
64 
65  void analyze(edm::StreamID, edm::Event const&, edm::EventSetup const&) const override;
66 
68 
69  private:
71  unsigned int run,
72  unsigned int lumiNumber,
73  edm::ESHandle<IOVTestInfo> const& iovTestInfo,
74  const char* functionName) const;
75 
81  };
82 
84  : esToken_{esConsumes(edm::ESInputTag("", ""))},
85  tokenBeginRun_{esConsumes<edm::Transition::BeginRun>(edm::ESInputTag("", ""))},
86  tokenBeginLumi_{esConsumes<edm::Transition::BeginLuminosityBlock>(edm::ESInputTag("", ""))},
87  tokenEndLumi_{esConsumes<edm::Transition::EndLuminosityBlock>(edm::ESInputTag("", ""))},
88  tokenEndRun_{esConsumes<edm::Transition::EndRun>(edm::ESInputTag("", ""))} {}
89 
90  std::unique_ptr<UnsafeCache> RunLumiESAnalyzer::beginStream(edm::StreamID iID) const {
91  return std::make_unique<UnsafeCache>();
92  }
93 
95  unsigned int run,
96  unsigned int lumiNumber,
97  edm::ESHandle<IOVTestInfo> const& iovTestInfo,
98  const char* functionName) const {
99  ESTestRecordC recordC = eventSetup.get<ESTestRecordC>();
100  edm::ValidityInterval iov = recordC.validityInterval();
101 
102  if (iovTestInfo->iovStartRun_ != run || iovTestInfo->iovEndRun_ != run ||
103  iovTestInfo->iovStartLumi_ != lumiNumber || iovTestInfo->iovEndLumi_ != lumiNumber) {
104  throw cms::Exception("TestFailure")
105  << functionName << ": values read from EventSetup do not agree with auxiliary";
106  }
107 
108  if (iov.first().eventID().run() != run || iov.last().eventID().run() != run ||
109  iov.first().luminosityBlockNumber() != lumiNumber || iov.last().luminosityBlockNumber() != lumiNumber) {
110  throw cms::Exception("TestFailure") << functionName << ": values from EventSetup IOV do not agree with auxiliary";
111  }
112  }
113 
115  auto run = iRun.runAuxiliary().run();
116  unsigned int lumiNumber = 0;
117  edm::ESHandle<IOVTestInfo> iovTestInfo = eventSetup.getHandle(tokenBeginRun_);
118  checkIOVInfo(eventSetup, run, lumiNumber, iovTestInfo, "RunLumiESAnalyzer::streamBeginRun");
119  }
120 
122  edm::LuminosityBlock const& iLumi,
123  edm::EventSetup const& eventSetup) const {
124  auto run = iLumi.luminosityBlockAuxiliary().run();
125  unsigned int lumiNumber = iLumi.luminosityBlockAuxiliary().luminosityBlock();
126  edm::ESHandle<IOVTestInfo> iovTestInfo = eventSetup.getHandle(tokenBeginLumi_);
127  checkIOVInfo(eventSetup, run, lumiNumber, iovTestInfo, "RunLumiESAnalyzer::streamBeginLuminosityBlock");
128  }
129 
131  edm::LuminosityBlock const& iLumi,
132  edm::EventSetup const& eventSetup) const {
133  auto run = iLumi.luminosityBlockAuxiliary().run();
134  unsigned int lumiNumber = iLumi.luminosityBlockAuxiliary().luminosityBlock();
135  edm::ESHandle<IOVTestInfo> iovTestInfo = eventSetup.getHandle(tokenEndLumi_);
136  checkIOVInfo(eventSetup, run, lumiNumber, iovTestInfo, "RunLumiESAnalyzer::streamEndLuminosityBlock");
137  }
138 
140  auto run = iRun.runAuxiliary().run();
141  unsigned int lumiNumber = 4294967295;
142  edm::ESHandle<IOVTestInfo> iovTestInfo = eventSetup.getHandle(tokenEndRun_);
143  checkIOVInfo(eventSetup, run, lumiNumber, iovTestInfo, "RunLumiESAnalyzer::streamEndRun");
144  }
145 
146  std::shared_ptr<Cache> RunLumiESAnalyzer::globalBeginRun(edm::Run const& iRun,
147  edm::EventSetup const& eventSetup) const {
148  auto run = iRun.runAuxiliary().run();
149  unsigned int lumiNumber = 0;
150  edm::ESHandle<IOVTestInfo> iovTestInfo = eventSetup.getHandle(tokenBeginRun_);
151  checkIOVInfo(eventSetup, run, lumiNumber, iovTestInfo, "RunLumiESAnalyzer::globalBeginRun");
152  return std::make_shared<Cache>();
153  }
154 
156  auto run = iRun.runAuxiliary().run();
157  unsigned int lumiNumber = 4294967295;
158  edm::ESHandle<IOVTestInfo> iovTestInfo = eventSetup.getHandle(tokenEndRun_);
159  checkIOVInfo(eventSetup, run, lumiNumber, iovTestInfo, "RunLumiESAnalyzer::globalEndRun");
160  }
161 
163  edm::EventSetup const& eventSetup) const {
164  auto run = iLumi.luminosityBlockAuxiliary().run();
165  unsigned int lumiNumber = iLumi.luminosityBlockAuxiliary().luminosityBlock();
166  edm::ESHandle<IOVTestInfo> iovTestInfo = eventSetup.getHandle(tokenBeginLumi_);
167  checkIOVInfo(eventSetup, run, lumiNumber, iovTestInfo, "RunLumiESAnalyzer::globalBeginLuminosityBlock");
168  return std::make_shared<Cache>();
169  }
170 
172  edm::EventSetup const& eventSetup) const {
173  auto run = iLumi.luminosityBlockAuxiliary().run();
174  unsigned int lumiNumber = iLumi.luminosityBlockAuxiliary().luminosityBlock();
175  edm::ESHandle<IOVTestInfo> iovTestInfo = eventSetup.getHandle(tokenEndLumi_);
176  checkIOVInfo(eventSetup, run, lumiNumber, iovTestInfo, "RunLumiESAnalyzer::globalEndLuminosityBlock");
177  }
178 
180  auto run = event.eventAuxiliary().run();
181  auto lumiNumber = event.eventAuxiliary().luminosityBlock();
182  edm::ESHandle<IOVTestInfo> iovTestInfo = eventSetup.getHandle(esToken_);
183  checkIOVInfo(eventSetup, run, lumiNumber, iovTestInfo, "RunLumiESAnalyzer::analyzer");
184  }
185 
188  descriptions.addDefault(desc);
189  }
190 } // namespace edmtest
191 using namespace edmtest;
std::unique_ptr< UnsafeCache > beginStream(edm::StreamID) const override
LuminosityBlockAuxiliary const & luminosityBlockAuxiliary() const final
void globalEndLuminosityBlock(edm::LuminosityBlock const &iLB, edm::EventSetup const &) const override
unsigned int iovEndLumi_
Definition: IOVTestInfo.h:24
void globalEndRun(edm::Run const &iRun, edm::EventSetup const &) const override
edm::ESGetToken< IOVTestInfo, ESTestRecordC > const esToken_
RunAuxiliary const & runAuxiliary() const final
Definition: Run.cc:24
edm::ESGetToken< IOVTestInfo, ESTestRecordC > const tokenEndLumi_
RunNumber_t run() const
Definition: RunAuxiliary.h:30
void streamEndRun(edm::StreamID, edm::Run const &, edm::EventSetup const &) const override
edm::ESGetToken< IOVTestInfo, ESTestRecordC > const tokenBeginRun_
void addDefault(ParameterSetDescription const &psetDescription)
edm::ESGetToken< IOVTestInfo, ESTestRecordC > const tokenBeginLumi_
unsigned int iovEndRun_
Definition: IOVTestInfo.h:23
void analyze(edm::StreamID, edm::Event const &, edm::EventSetup const &) const override
unsigned int iovStartLumi_
Definition: IOVTestInfo.h:22
LuminosityBlockNumber_t luminosityBlock() const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::shared_ptr< Cache > globalBeginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) const override
Definition: value.py:1
void streamBeginRun(edm::StreamID, edm::Run const &, edm::EventSetup const &) const override
static void fillDescriptions(edm::ConfigurationDescriptions &)
void streamEndLuminosityBlock(edm::StreamID, edm::LuminosityBlock const &, edm::EventSetup const &) const override
void streamBeginLuminosityBlock(edm::StreamID, edm::LuminosityBlock const &, edm::EventSetup const &) const override
std::shared_ptr< Cache > globalBeginRun(edm::Run const &, edm::EventSetup const &) const override
unsigned int iovStartRun_
Definition: IOVTestInfo.h:21
void checkIOVInfo(edm::EventSetup const &eventSetup, unsigned int run, unsigned int lumiNumber, edm::ESHandle< IOVTestInfo > const &iovTestInfo, const char *functionName) const
RunLumiESAnalyzer(edm::ParameterSet const &)
edm::ESGetToken< IOVTestInfo, ESTestRecordC > const tokenEndRun_
ValidityInterval validityInterval() const
Definition: event.py:1
Definition: Run.h:45