CMS 3D CMS Logo

EventIDChecker.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Modules
4 // Class: EventIDChecker
5 //
13 //
14 // Original Author: Chris Jones
15 // Created: Tue Jun 16 15:42:17 CDT 2009
16 //
17 //
18 
19 // user include files
27 
28 // system include files
29 #include <algorithm>
30 #include <memory>
31 #include <vector>
32 
33 //
34 // class decleration
35 //
36 
37 class EventIDChecker : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one::WatchLuminosityBlocks> {
38 public:
39  explicit EventIDChecker(edm::ParameterSet const&);
40  ~EventIDChecker() override;
41  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
42 
43 private:
44  void beginJob() override;
45  void beginRun(edm::Run const&, edm::EventSetup const&) override;
46  void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
47  void analyze(edm::Event const&, edm::EventSetup const&) override;
48  void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
49  void endRun(edm::Run const&, edm::EventSetup const&) override;
50  void endJob() override;
51 
52  // ----------member data ---------------------------
53  std::vector<edm::EventID> ids_;
54  unsigned int index_;
57 
61 };
62 
63 //
64 // constants, enums and typedefs
65 //
66 
67 //
68 // static data member definitions
69 //
70 
71 //
72 // constructors and destructor
73 //
75  : ids_(iConfig.getUntrackedParameter<std::vector<edm::EventID> >("eventSequence")),
76  index_(0),
77  multiProcessSequentialEvents_(iConfig.getUntrackedParameter<unsigned int>("multiProcessSequentialEvents")),
78  numberOfEventsLeftBeforeSearch_(0),
79  mustSearch_(false) {
80  //now do what ever initialization is needed
81 }
82 
84  // do anything here that needs to be done at desctruction time
85  // (e.g. close files, deallocate resources etc.)
86 }
87 
88 //
89 // member functions
90 //
91 
92 namespace {
93  struct CompareWithoutLumi {
94  CompareWithoutLumi(edm::EventID const& iThis) : m_this(iThis) {}
95  bool operator()(edm::EventID const& iOther) {
96  return m_this.run() == iOther.run() && m_this.event() == iOther.event();
97  }
98  edm::EventID m_this;
99  };
100 } // namespace
101 
102 // ------------ method called to for each event ------------
104  if (mustSearch_) {
107  //the event must be after the last event in our list since multicore doesn't go backwards
108  std::vector<edm::EventID>::iterator itFind =
109  std::find_if(ids_.begin() + index_, ids_.end(), CompareWithoutLumi(iEvent.id()));
110  if (itFind == ids_.end()) {
111  throw cms::Exception("MissedEvent") << "The event " << iEvent.id() << "is not in the list.\n";
112  }
113  index_ = itFind - ids_.begin();
114  }
116  }
117 
118  if (index_ >= ids_.size()) {
119  throw cms::Exception("TooManyEvents")
120  << "Was passes " << ids_.size() << " EventIDs but have processed more events than that\n";
121  }
122  if (iEvent.id().run() != ids_[index_].run() || iEvent.id().event() != ids_[index_].event()) {
123  throw cms::Exception("WrongEvent") << "Was expecting event " << ids_[index_] << " but was given " << iEvent.id()
124  << "\n";
125  }
126 
127  if (presentRun_ != iEvent.run()) {
128  throw cms::Exception("MissingRunTransitionForEvent")
129  << "at event expected Run " << presentRun_ << " but got " << iEvent.run();
130  }
131  if (presentLumi_ != iEvent.luminosityBlock()) {
132  throw cms::Exception("MissingLuminosityBlockTransitionForEvent")
133  << "expected LuminosityBlock " << presentLumi_ << " but got " << iEvent.luminosityBlock();
134  }
135 
136  ++index_;
137 }
138 
139 void EventIDChecker::beginRun(edm::Run const& iRun, edm::EventSetup const&) { presentRun_ = iRun.run(); }
141  if (presentRun_ != iLumi.run()) {
142  throw cms::Exception("WrongRunForLuminosityBlock")
143  << "at beginLuminosityBlock expected Run " << presentRun_ << " but got " << iLumi.run();
144  }
145  presentLumi_ = iLumi.luminosityBlock();
146 }
147 
149  if (presentRun_ != iLumi.run()) {
150  throw cms::Exception("WrongRunForLuminosityBlock")
151  << "at endLuminosityBlock expected Run " << presentRun_ << " but got " << iLumi.run();
152  }
153  if (presentLumi_ != iLumi.luminosityBlock()) {
154  throw cms::Exception("WrongEndLuminosityBlock")
155  << "expected LuminosityBlock " << presentLumi_ << " but got " << iLumi.luminosityBlock();
156  }
157 }
159  if (presentRun_ != iRun.run()) {
160  throw cms::Exception("WrongEndRun") << "expected Run " << presentRun_ << " but got " << iRun.run();
161  }
162 }
163 
164 // ------------ method called once each job just before starting event loop ------------
166 
167 // ------------ method called once each job just after ending the event loop ------------
169 
170 // ------------ method called once each job for validation
173  desc.addUntracked<std::vector<edm::EventID> >("eventSequence");
174  desc.addUntracked<unsigned int>("multiProcessSequentialEvents", 0U);
175  descriptions.add("eventIDChecker", desc);
176 }
177 
178 //define this as a plug-in
~EventIDChecker() override
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
unsigned int multiProcessSequentialEvents_
unsigned int LuminosityBlockNumber_t
int iEvent
Definition: GenABIO.cc:224
RunNumber_t run() const
Definition: RunBase.h:40
void analyze(edm::Event const &, edm::EventSetup const &) override
void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
unsigned int index_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::RunNumber_t presentRun_
RunNumber_t run() const
Definition: EventID.h:38
std::vector< edm::EventID > ids_
unsigned int numberOfEventsLeftBeforeSearch_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
EventIDChecker(edm::ParameterSet const &)
HLT enums.
void endJob() override
void endRun(edm::Run const &, edm::EventSetup const &) override
unsigned int RunNumber_t
void beginJob() override
void beginRun(edm::Run const &, edm::EventSetup const &) override
LuminosityBlockNumber_t luminosityBlock() const
void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
EventNumber_t event() const
Definition: EventID.h:40
Definition: Run.h:45
edm::LuminosityBlockNumber_t presentLumi_