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
ConfigurationDescriptions.h
edm::StreamID
Definition: StreamID.h:30
electrons_cff.bool
bool
Definition: electrons_cff.py:372
propagate_const.h
edm::LuminosityBlock
Definition: LuminosityBlock.h:50
edm::Run
Definition: Run.h:45
LuminosityBlock.h
edm
HLT enums.
Definition: AlignableModifier.h:19
RunLumiEventChecker::check
void check(edm::EventID const &iID, bool isEvent) const
Definition: RunLumiEventChecker.cc:100
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
RunLumiEventChecker::globalEndLuminosityBlock
void globalEndLuminosityBlock(edm::LuminosityBlock const &lumi, edm::EventSetup const &es) const override
Definition: RunLumiEventChecker.cc:138
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
RunLumiEventChecker::analyze
void analyze(edm::StreamID, edm::Event const &, edm::EventSetup const &) const override
Definition: RunLumiEventChecker.cc:120
MakerMacros.h
RunLumiEventChecker::ids_
std::vector< edm::EventID > ids_
Definition: RunLumiEventChecker.cc:68
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
RunLumiEventChecker::globalBeginLuminosityBlock
std::shared_ptr< rlec::Cache > globalBeginLuminosityBlock(edm::LuminosityBlock const &lumi, edm::EventSetup const &es) const override
Definition: RunLumiEventChecker.cc:132
EventID.h
Run.h
RunLumiEventChecker
Definition: RunLumiEventChecker.cc:46
ParameterSetDescription.h
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
RunLumiEventChecker::unorderedEvents_
bool unorderedEvents_
Definition: RunLumiEventChecker.cc:70
UnixSignalHandlers.h
RunLumiEventChecker::globalBeginRun
std::shared_ptr< rlec::Cache > globalBeginRun(edm::Run const &run, edm::EventSetup const &es) const override
Definition: RunLumiEventChecker.cc:124
edm::ParameterSetDescription::addUntracked
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:100
edm::ParameterSet
Definition: ParameterSet.h:36
RunLumiEventChecker::index_
std::atomic< unsigned int > index_
Definition: RunLumiEventChecker.cc:69
Event.h
iEvent
int iEvent
Definition: GenABIO.cc:224
RunLumiEventChecker::~RunLumiEventChecker
~RunLumiEventChecker() override
Definition: RunLumiEventChecker.cc:91
rlec::Cache
Definition: RunLumiEventChecker.cc:43
edm::EventSetup
Definition: EventSetup.h:57
RunLumiEventChecker::beginJob
void beginJob() override
Definition: RunLumiEventChecker.cc:143
RunLumiEventChecker::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: RunLumiEventChecker.cc:154
RunLumiEventChecker::globalEndRun
void globalEndRun(edm::Run const &run, edm::EventSetup const &es) const override
Definition: RunLumiEventChecker.cc:128
RunLumiEventChecker::endJob
void endJob() override
Definition: RunLumiEventChecker.cc:146
std
Definition: JetResolutionObject.h:76
writedatasetfile.run
run
Definition: writedatasetfile.py:27
rlec
Definition: RunLumiEventChecker.cc:42
Exception
Definition: hltDiff.cc:246
RunLumiEventChecker::RunLumiEventChecker
RunLumiEventChecker(edm::ParameterSet const &)
Definition: RunLumiEventChecker.cc:84
ParameterSet.h
edm::EventID
Definition: EventID.h:31
edm::Event
Definition: Event.h:73
lumi
Definition: LumiSectionData.h:20
EDAnalyzer.h
edm::global::EDAnalyzer
Definition: EDAnalyzer.h:32