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 }
45 
46 class RunLumiEventChecker : public edm::global::EDAnalyzer<edm::RunCache<rlec::Cache>, edm::LuminosityBlockCache<rlec::Cache>> {
47 public:
48  explicit RunLumiEventChecker(edm::ParameterSet const&);
49  ~RunLumiEventChecker() override;
50  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
51 
52 private:
53  void beginJob() override;
54  void analyze(edm::StreamID, edm::Event const&, edm::EventSetup const&) const override;
55  void endJob() override;
56 
57  std::shared_ptr<rlec::Cache> globalBeginRun(edm::Run const& run, edm::EventSetup const& es) const override;
58  void globalEndRun(edm::Run const& run, edm::EventSetup const& es) const override;
59 
60  std::shared_ptr<rlec::Cache> globalBeginLuminosityBlock(edm::LuminosityBlock const& lumi, edm::EventSetup const& es) const override;
61  void globalEndLuminosityBlock(edm::LuminosityBlock const& lumi, edm::EventSetup const& es) const override;
62 
63  void check(edm::EventID const& iID, bool isEvent) const;
64 
65  // ----------member data ---------------------------
66  std::vector<edm::EventID> ids_;
67  mutable std::atomic<unsigned int> index_;
69 
70 };
71 
72 //
73 // constants, enums and typedefs
74 //
75 
76 //
77 // static data member definitions
78 //
79 
80 //
81 // constructors and destructor
82 //
84  ids_(iConfig.getUntrackedParameter<std::vector<edm::EventID> >("eventSequence")),
85  index_(0),
86  unorderedEvents_(iConfig.getUntrackedParameter<bool>("unorderedEvents"))
87 {
88  //now do what ever initialization is needed
89 }
90 
91 
93  // do anything here that needs to be done at desctruction time
94  // (e.g. close files, deallocate resources etc.)
95 }
96 
97 //
98 // member functions
99 //
100 
101 void
102 RunLumiEventChecker::check(edm::EventID const& iEventID, bool iIsEvent) const {
103  if(index_ >= ids_.size()) {
104  throw cms::Exception("TooManyEvents") << "Was passes " << ids_.size() << " EventIDs but have processed more events than that\n";
105  }
106  if(unorderedEvents_) {
107  auto itFound =std::find(ids_.begin(),ids_.end(), iEventID);
108  if(itFound == ids_.end()) {
109  throw cms::Exception("UnexpecedEvent") <<"The event "<<iEventID<<" was not expected.";
110  }
111  } else {
112  if(iEventID != ids_[index_]) {
113  throw cms::Exception("WrongEvent") << "Was expecting event " << ids_[index_] << " but was given " << iEventID << "\n";
114  }
115  }
116  ++index_;
117 }
118 
119 // ------------ method called to for each event ------------
120 void
122  check(iEvent.id(), true);
123 }
124 
125 std::shared_ptr<rlec::Cache>
127  check(edm::EventID(run.id().run(), 0, 0), false);
128  return std::shared_ptr<rlec::Cache>{};
129 }
130 void
132  check(edm::EventID(run.id().run(), 0, 0), false);
133 }
134 
135 std::shared_ptr<rlec::Cache>
137  check(edm::EventID(lumi.id().run(), lumi.id().luminosityBlock(), 0), false);
138  return std::shared_ptr<rlec::Cache>{};
139 }
140 
141 void
143  check(edm::EventID(lumi.id().run(), lumi.id().luminosityBlock(), 0), false);
144 }
145 
146 
147 // ------------ method called once each job just before starting event loop ------------
148 void
150 }
151 
152 // ------------ method called once each job just after ending the event loop ------------
153 void
155  if(index_ != ids_.size()) {
156  throw cms::Exception("WrongNumberOfEvents")<<"Saw "<<index_<<" events but was supposed to see "<<ids_.size()<<"\n";
157  }
158 }
159 
160 // ------------ method called once each job for validation
161 void
164  desc.addUntracked<std::vector<edm::EventID> >("eventSequence");
165  desc.addUntracked<bool>("unorderedEvents",false);
166  descriptions.add("runLumiEventIDChecker", desc);
167 }
168 
169 //define this as a plug-in
LuminosityBlockID id() const
std::shared_ptr< rlec::Cache > globalBeginLuminosityBlock(edm::LuminosityBlock const &lumi, edm::EventSetup const &es) const override
std::vector< edm::EventID > ids_
RunID const & id() const
Definition: RunBase.h:39
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
RunNumber_t run() const
Definition: RunID.h:39
virtual example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
void check(edm::EventID const &iID, bool isEvent) const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void globalEndRun(edm::Run const &run, 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:20
std::shared_ptr< rlec::Cache > globalBeginRun(edm::Run const &run, edm::EventSetup const &es) const override
void beginJob()
Definition: Breakpoints.cc:15
RunLumiEventChecker(edm::ParameterSet const &)
void globalEndLuminosityBlock(edm::LuminosityBlock const &lumi, edm::EventSetup const &es) const override
int iEvent
Definition: GenABIO.cc:230
void analyze(edm::StreamID, edm::Event const &, edm::EventSetup const &) const override
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
RunNumber_t run() const
std::atomic< unsigned int > index_
LuminosityBlockNumber_t luminosityBlock() const
void add(std::string const &label, ParameterSetDescription const &psetDescription)
edm::EventID id() const
Definition: EventBase.h:60
HLT enums.
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
def check(config)
Definition: trackerTree.py:14
Definition: Run.h:43