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_;
71 };
72 
73 //
74 // constants, enums and typedefs
75 //
76 
77 //
78 // static data member definitions
79 //
80 
81 //
82 // constructors and destructor
83 //
85  : ids_(iConfig.getUntrackedParameter<std::vector<edm::EventID>>("eventSequence")),
86  index_(0),
87  unorderedEvents_(iConfig.getUntrackedParameter<bool>("unorderedEvents")) {
88  //now do what ever initialization is needed
89 }
90 
92  // do anything here that needs to be done at desctruction time
93  // (e.g. close files, deallocate resources etc.)
94 }
95 
96 //
97 // member functions
98 //
99 
100 void RunLumiEventChecker::check(edm::EventID const& iEventID, bool iIsEvent) const {
101  if (index_ >= ids_.size()) {
102  throw cms::Exception("TooManyEvents")
103  << "Was passes " << ids_.size() << " EventIDs but have processed more events than that\n";
104  }
105  if (unorderedEvents_) {
106  auto itFound = std::find(ids_.begin(), ids_.end(), iEventID);
107  if (itFound == ids_.end()) {
108  throw cms::Exception("UnexpecedEvent") << "The event " << iEventID << " was not expected.";
109  }
110  } else {
111  if (iEventID != ids_[index_]) {
112  throw cms::Exception("WrongEvent") << "Was expecting event " << ids_[index_] << " but was given " << iEventID
113  << "\n";
114  }
115  }
116  ++index_;
117 }
118 
119 // ------------ method called to for each event ------------
121  check(iEvent.id(), true);
122 }
123 
124 std::shared_ptr<rlec::Cache> RunLumiEventChecker::globalBeginRun(edm::Run const& run, edm::EventSetup const&) const {
125  check(edm::EventID(run.id().run(), 0, 0), false);
126  return std::shared_ptr<rlec::Cache>{};
127 }
129  check(edm::EventID(run.id().run(), 0, 0), false);
130 }
131 
133  edm::EventSetup const&) const {
134  check(edm::EventID(lumi.id().run(), lumi.id().luminosityBlock(), 0), false);
135  return std::shared_ptr<rlec::Cache>{};
136 }
137 
139  check(edm::EventID(lumi.id().run(), lumi.id().luminosityBlock(), 0), false);
140 }
141 
142 // ------------ method called once each job just before starting event loop ------------
144 
145 // ------------ method called once each job just after ending the event loop ------------
147  if (index_ != ids_.size()) {
148  throw cms::Exception("WrongNumberOfEvents")
149  << "Saw " << index_ << " events but was supposed to see " << ids_.size() << "\n";
150  }
151 }
152 
153 // ------------ method called once each job for validation
156  desc.addUntracked<std::vector<edm::EventID>>("eventSequence");
157  desc.addUntracked<bool>("unorderedEvents", false);
158  descriptions.add("runLumiEventIDChecker", desc);
159 }
160 
161 //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