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