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
181
182
183
184
185
186
187
188
189
190
|
#include "DataFormats/Common/interface/Handle.h"
#include "DataFormats/Common/interface/TriggerResults.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/Framework/interface/one/EDAnalyzer.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/EDGetToken.h"
#include "FWCore/Utilities/interface/Exception.h"
#include <cassert>
#include <vector>
namespace edmtest {
class RunLumiEventAnalyzer : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one::WatchLuminosityBlocks> {
public:
explicit RunLumiEventAnalyzer(edm::ParameterSet const& pset);
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
void analyze(edm::Event const& event, edm::EventSetup const& es) final;
void beginRun(edm::Run const& run, edm::EventSetup const& es) final;
void endRun(edm::Run const& run, edm::EventSetup const& es) final;
void beginLuminosityBlock(edm::LuminosityBlock const& lumi, edm::EventSetup const& es) final;
void endLuminosityBlock(edm::LuminosityBlock const& lumi, edm::EventSetup const& es) final;
void endJob();
private:
std::vector<unsigned long long> const expectedRunLumisEvents0_;
std::vector<unsigned long long> const expectedRunLumisEvents1_;
std::vector<unsigned long long> const* const expectedRunLumisEvents_;
bool const verbose_;
bool const dumpTriggerResults_;
int const expectedEndingIndex0_;
int const expectedEndingIndex1_;
int const expectedEndingIndex_;
edm::EDGetTokenT<edm::TriggerResults> triggerResultsToken_;
int index_ = 0;
};
RunLumiEventAnalyzer::RunLumiEventAnalyzer(edm::ParameterSet const& pset)
: expectedRunLumisEvents0_(pset.getUntrackedParameter<std::vector<unsigned long long>>("expectedRunLumiEvents")),
expectedRunLumisEvents1_(pset.getUntrackedParameter<std::vector<unsigned long long>>("expectedRunLumiEvents1")),
expectedRunLumisEvents_(&expectedRunLumisEvents0_),
verbose_(pset.getUntrackedParameter<bool>("verbose")),
dumpTriggerResults_(pset.getUntrackedParameter<bool>("dumpTriggerResults")),
expectedEndingIndex0_(pset.getUntrackedParameter<int>("expectedEndingIndex")),
expectedEndingIndex1_(pset.getUntrackedParameter<int>("expectedEndingIndex1")),
expectedEndingIndex_(expectedEndingIndex0_) {
if (dumpTriggerResults_) {
triggerResultsToken_ = consumes(edm::InputTag("TriggerResults"));
}
}
void RunLumiEventAnalyzer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.addUntracked<bool>("verbose", false);
desc.addUntracked<bool>("dumpTriggerResults", false);
desc.addUntracked<int>("expectedEndingIndex", -1);
desc.addUntracked<int>("expectedEndingIndex1", -1);
desc.addUntracked<std::vector<unsigned long long>>("expectedRunLumiEvents", {});
desc.addUntracked<std::vector<unsigned long long>>("expectedRunLumiEvents1", {});
descriptions.addDefault(desc);
}
void RunLumiEventAnalyzer::analyze(edm::Event const& event, edm::EventSetup const&) {
if (verbose_) {
edm::LogAbsolute("RunLumiEvent") << "RUN_LUMI_EVENT " << event.run() << ", " << event.luminosityBlock() << ", "
<< event.id().event();
}
if (dumpTriggerResults_) {
if (auto triggerResults = event.getHandle(triggerResultsToken_)) {
edm::LogAbsolute("RunLumiEvent") << "TestFailuresAnalyzer dumping TriggerResults";
edm::LogAbsolute("RunLumiEvent") << *triggerResults;
} else {
edm::LogAbsolute("RunLumiEvent") << "TriggerResults not found\n";
}
}
if ((index_ + 2U) < expectedRunLumisEvents_->size()) {
assert(expectedRunLumisEvents_->at(index_) == event.run());
++index_;
assert(expectedRunLumisEvents_->at(index_) == event.luminosityBlock());
++index_;
assert(expectedRunLumisEvents_->at(index_) == event.id().event());
++index_;
}
}
void RunLumiEventAnalyzer::beginRun(edm::Run const& run, edm::EventSetup const&) {
if (verbose_) {
edm::LogAbsolute("RunLumiEvent") << "RUN_LUMI_EVENT " << run.run() << ", " << 0 << ", " << 0;
}
if ((index_ + 2U) < expectedRunLumisEvents_->size()) {
assert(expectedRunLumisEvents_->at(index_) == run.run());
++index_;
assert(expectedRunLumisEvents_->at(index_) == 0);
++index_;
assert(expectedRunLumisEvents_->at(index_) == 0);
++index_;
}
}
void RunLumiEventAnalyzer::endRun(edm::Run const& run, edm::EventSetup const&) {
if (verbose_) {
edm::LogAbsolute("RunLumiEvent") << "RUN_LUMI_EVENT " << run.run() << ", " << 0 << ", " << 0;
}
if ((index_ + 2U) < expectedRunLumisEvents_->size()) {
if (!(expectedRunLumisEvents_->at(index_) == run.run())) {
throw cms::Exception("UnexpectedRun") << "RunLumiEventAnalyzer::endRun unexpected run\n"
" expected "
<< expectedRunLumisEvents_->at(index_) << " found " << run.run();
}
++index_;
if (!(expectedRunLumisEvents_->at(index_) == 0)) {
throw cms::Exception("UnexpectedLumi") << "RunLumiEventAnalyzer::endRun unexpected lumi\n"
" expected "
<< expectedRunLumisEvents_->at(index_) << " found 0";
}
++index_;
if (!(expectedRunLumisEvents_->at(index_) == 0)) {
throw cms::Exception("UnexpectedEvent") << "RunLumiEventAnalyzer::endRun unexpected event\n"
" expected "
<< expectedRunLumisEvents_->at(index_) << " found 0";
}
++index_;
}
}
void RunLumiEventAnalyzer::beginLuminosityBlock(edm::LuminosityBlock const& lumi, edm::EventSetup const&) {
if (verbose_) {
edm::LogAbsolute("RunLumiEvent") << "RUN_LUMI_EVENT " << lumi.run() << ", " << lumi.luminosityBlock() << ", "
<< 0;
}
if ((index_ + 2U) < expectedRunLumisEvents_->size()) {
assert(expectedRunLumisEvents_->at(index_) == lumi.run());
++index_;
assert(expectedRunLumisEvents_->at(index_) == lumi.luminosityBlock());
++index_;
assert(expectedRunLumisEvents_->at(index_) == 0);
++index_;
}
}
void RunLumiEventAnalyzer::endLuminosityBlock(edm::LuminosityBlock const& lumi, edm::EventSetup const&) {
if (verbose_) {
edm::LogAbsolute("RunLumiEvent") << "RUN_LUMI_EVENT " << lumi.run() << ", " << lumi.luminosityBlock() << ", "
<< 0;
}
if ((index_ + 2U) < expectedRunLumisEvents_->size()) {
if (!(expectedRunLumisEvents_->at(index_) == lumi.run())) {
throw cms::Exception("UnexpectedRun") << "RunLumiEventAnalyzer::endLuminosityBlock unexpected run\n"
" expected "
<< expectedRunLumisEvents_->at(index_) << " found " << lumi.run();
}
++index_;
if (!(expectedRunLumisEvents_->at(index_) == lumi.luminosityBlock())) {
throw cms::Exception("UnexpectedLumi")
<< "RunLumiEventAnalyzer::endLuminosityBlock unexpected lumi"
" expected "
<< expectedRunLumisEvents_->at(index_) << " found " << lumi.luminosityBlock();
}
++index_;
if (!(expectedRunLumisEvents_->at(index_) == 0)) {
throw cms::Exception("UnexpectedEvent") << "RunLumiEventAnalyzer::endLuminosityBlock unexpected event"
" expected "
<< expectedRunLumisEvents_->at(index_) << " found 0";
}
++index_;
}
}
void RunLumiEventAnalyzer::endJob() {
if (expectedEndingIndex_ != -1 && index_ != expectedEndingIndex_) {
throw cms::Exception("UnexpectedEvent",
"RunLumiEventAnalyzer::endJob. Unexpected number of runs, lumis, and events");
}
}
} // namespace edmtest
using edmtest::RunLumiEventAnalyzer;
DEFINE_FWK_MODULE(RunLumiEventAnalyzer);
|