CMS 3D CMS Logo

RunLumiEventChecker.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Modules
4 // Class: RunLumiEventChecker
5 //
13 //
14 // Original Author: Chris Jones
15 // Created: Tue Jun 16 15:42:17 CDT 2009
16 //
17 //
18 
19 // user include files
31 
32 // system include files
33 #include <algorithm>
34 #include <map>
35 #include <memory>
36 #include <vector>
37 #include <map>
38 
39 //
40 // class decleration
41 //
42 namespace rlec {
43  struct Cache {};
44 } // namespace rlec
45 
47  : public edm::global::EDAnalyzer<edm::RunCache<rlec::Cache>, edm::LuminosityBlockCache<rlec::Cache>> {
48 public:
49  explicit RunLumiEventChecker(edm::ParameterSet const&);
50  ~RunLumiEventChecker() override;
51  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
52 
53 private:
54  void beginJob() override;
55  void analyze(edm::StreamID, edm::Event const&, edm::EventSetup const&) const override;
56  void endJob() override;
57 
58  std::shared_ptr<rlec::Cache> globalBeginRun(edm::Run const& run, edm::EventSetup const& es) const override;
59  void globalEndRun(edm::Run const& run, edm::EventSetup const& es) const override;
60 
61  std::shared_ptr<rlec::Cache> globalBeginLuminosityBlock(edm::LuminosityBlock const& lumi,
62  edm::EventSetup const& es) const override;
63  void globalEndLuminosityBlock(edm::LuminosityBlock const& lumi, edm::EventSetup const& es) const override;
64 
65  void check(edm::EventID const& iID, bool isEvent) const;
66 
67  // ----------member data ---------------------------
68  std::vector<edm::EventID> ids_;
69  mutable std::atomic<unsigned int> index_;
70  unsigned int minNEvents_ = 0;
71  unsigned int maxNEvents_ = 0;
73 };
74 
75 //
76 // constants, enums and typedefs
77 //
78 
79 //
80 // static data member definitions
81 //
82 
83 //
84 // constructors and destructor
85 //
87  : ids_(iConfig.getUntrackedParameter<std::vector<edm::EventID>>("eventSequence")),
88  index_(0),
89  minNEvents_(iConfig.getUntrackedParameter<unsigned int>("minNumberOfEvents")),
90  maxNEvents_(iConfig.getUntrackedParameter<unsigned int>("maxNumberOfEvents")),
91  unorderedEvents_(iConfig.getUntrackedParameter<bool>("unorderedEvents")) {
92  //now do what ever initialization is needed
93 }
94 
96  // do anything here that needs to be done at desctruction time
97  // (e.g. close files, deallocate resources etc.)
98 }
99 
100 //
101 // member functions
102 //
103 
104 void RunLumiEventChecker::check(edm::EventID const& iEventID, bool iIsEvent) const {
105  if (index_ >= ids_.size()) {
106  throw cms::Exception("TooManyEvents")
107  << "Was passes " << ids_.size() << " EventIDs but have processed more events than that\n";
108  }
109  if (unorderedEvents_) {
110  auto itFound = std::find(ids_.begin(), ids_.end(), iEventID);
111  if (itFound == ids_.end()) {
112  throw cms::Exception("UnexpecedEvent") << "The event " << iEventID << " was not expected.";
113  }
114  } else {
115  if (iEventID != ids_[index_]) {
116  throw cms::Exception("WrongEvent") << "Was expecting event " << ids_[index_] << " but was given " << iEventID
117  << "\n";
118  }
119  }
120  ++index_;
121 }
122 
123 // ------------ method called to for each event ------------
125  check(iEvent.id(), true);
126 }
127 
128 std::shared_ptr<rlec::Cache> RunLumiEventChecker::globalBeginRun(edm::Run const& run, edm::EventSetup const&) const {
129  check(edm::EventID(run.id().run(), 0, 0), false);
130  return std::shared_ptr<rlec::Cache>{};
131 }
133  check(edm::EventID(run.id().run(), 0, 0), false);
134 }
135 
137  edm::EventSetup const&) const {
138  check(edm::EventID(lumi.id().run(), lumi.id().luminosityBlock(), 0), false);
139  return std::shared_ptr<rlec::Cache>{};
140 }
141 
143  check(edm::EventID(lumi.id().run(), lumi.id().luminosityBlock(), 0), false);
144 }
145 
146 // ------------ method called once each job just before starting event loop ------------
148 
149 // ------------ method called once each job just after ending the event loop ------------
151  if (maxNEvents_ == 0 and index_ != ids_.size()) {
152  throw cms::Exception("WrongNumberOfEvents")
153  << "Saw " << index_ << " (begin runs)+(begin lumis)+events+(end lumis)+(end runs) but was supposed to see "
154  << ids_.size() << "\n";
155  }
156  if (maxNEvents_ != 0 and (index_ < minNEvents_ or index_ > maxNEvents_)) {
157  throw cms::Exception("WrongNumberOfEvents")
158  << "Saw " << index_
159  << " (begin runs)+(begin lumis)+events+(end lumis)+(end runs) but was supposed to see between " << minNEvents_
160  << " and " << maxNEvents_;
161  }
162 }
163 
164 // ------------ method called once each job for validation
167  desc.addUntracked<std::vector<edm::EventID>>("eventSequence");
168  desc.addUntracked<unsigned int>("minNumberOfEvents", 0)
169  ->setComment(
170  "minimum number of Events that must be seen. If max is 0 then this will be ignored and all Events must be "
171  "present");
172  desc.addUntracked<unsigned int>("maxNumberOfEvents", 0)
173  ->setComment("maximum number of Events that must be seen. If set to 0, min and max are ignored");
174  desc.addUntracked<bool>("unorderedEvents", false)
175  ->setComment("set to true if events are not guaranteed to be in same order as 'eventSequence' specifies.");
176  descriptions.add("runLumiEventIDChecker", desc);
177 }
178 
179 //define this as a plug-in
std::vector< edm::EventID > ids_
void globalEndLuminosityBlock(edm::LuminosityBlock const &lumi, edm::EventSetup const &es) const override
std::shared_ptr< rlec::Cache > globalBeginLuminosityBlock(edm::LuminosityBlock const &lumi, edm::EventSetup const &es) const override
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
RunLumiEventChecker(edm::ParameterSet const &)
std::shared_ptr< rlec::Cache > globalBeginRun(edm::Run const &run, edm::EventSetup const &es) const override
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void analyze(edm::StreamID, edm::Event const &, edm::EventSetup const &) const override
void globalEndRun(edm::Run const &run, edm::EventSetup const &es) const override
std::atomic< unsigned int > index_
void check(edm::EventID const &iID, bool isEvent) const
void add(std::string const &label, ParameterSetDescription const &psetDescription)
HLT enums.
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: Run.h:45