File indexing completed on 2025-01-14 02:38:41
0001 #include "DataFormats/Common/interface/Handle.h"
0002 #include "DataFormats/Common/interface/TriggerResults.h"
0003 #include "FWCore/Framework/interface/Event.h"
0004 #include "FWCore/Framework/interface/LuminosityBlock.h"
0005 #include "FWCore/Framework/interface/MakerMacros.h"
0006 #include "FWCore/Framework/interface/Run.h"
0007 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0010 #include "FWCore/Utilities/interface/EDGetToken.h"
0011 #include "FWCore/Utilities/interface/Exception.h"
0012
0013 #include <cassert>
0014 #include <vector>
0015
0016 namespace edmtest {
0017 class RunLumiEventAnalyzer : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one::WatchLuminosityBlocks> {
0018 public:
0019 explicit RunLumiEventAnalyzer(edm::ParameterSet const& pset);
0020
0021 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0022
0023 void analyze(edm::Event const& event, edm::EventSetup const& es) final;
0024 void beginRun(edm::Run const& run, edm::EventSetup const& es) final;
0025 void endRun(edm::Run const& run, edm::EventSetup const& es) final;
0026 void beginLuminosityBlock(edm::LuminosityBlock const& lumi, edm::EventSetup const& es) final;
0027 void endLuminosityBlock(edm::LuminosityBlock const& lumi, edm::EventSetup const& es) final;
0028 void endJob();
0029
0030 private:
0031 std::vector<unsigned long long> const expectedRunLumisEvents0_;
0032 std::vector<unsigned long long> const expectedRunLumisEvents1_;
0033 std::vector<unsigned long long> const* const expectedRunLumisEvents_;
0034 bool const verbose_;
0035 bool const dumpTriggerResults_;
0036 int const expectedEndingIndex0_;
0037 int const expectedEndingIndex1_;
0038 int const expectedEndingIndex_;
0039 edm::EDGetTokenT<edm::TriggerResults> triggerResultsToken_;
0040 int index_ = 0;
0041 };
0042
0043 RunLumiEventAnalyzer::RunLumiEventAnalyzer(edm::ParameterSet const& pset)
0044 : expectedRunLumisEvents0_(pset.getUntrackedParameter<std::vector<unsigned long long>>("expectedRunLumiEvents")),
0045 expectedRunLumisEvents1_(pset.getUntrackedParameter<std::vector<unsigned long long>>("expectedRunLumiEvents1")),
0046 expectedRunLumisEvents_(&expectedRunLumisEvents0_),
0047 verbose_(pset.getUntrackedParameter<bool>("verbose")),
0048 dumpTriggerResults_(pset.getUntrackedParameter<bool>("dumpTriggerResults")),
0049 expectedEndingIndex0_(pset.getUntrackedParameter<int>("expectedEndingIndex")),
0050 expectedEndingIndex1_(pset.getUntrackedParameter<int>("expectedEndingIndex1")),
0051 expectedEndingIndex_(expectedEndingIndex0_) {
0052 if (dumpTriggerResults_) {
0053 triggerResultsToken_ = consumes(edm::InputTag("TriggerResults"));
0054 }
0055 }
0056
0057 void RunLumiEventAnalyzer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0058 edm::ParameterSetDescription desc;
0059 desc.addUntracked<bool>("verbose", false);
0060 desc.addUntracked<bool>("dumpTriggerResults", false);
0061 desc.addUntracked<int>("expectedEndingIndex", -1);
0062 desc.addUntracked<int>("expectedEndingIndex1", -1);
0063 desc.addUntracked<std::vector<unsigned long long>>("expectedRunLumiEvents", {});
0064 desc.addUntracked<std::vector<unsigned long long>>("expectedRunLumiEvents1", {});
0065
0066 descriptions.addDefault(desc);
0067 }
0068
0069 void RunLumiEventAnalyzer::analyze(edm::Event const& event, edm::EventSetup const&) {
0070 if (verbose_) {
0071 edm::LogAbsolute("RunLumiEvent") << "RUN_LUMI_EVENT " << event.run() << ", " << event.luminosityBlock() << ", "
0072 << event.id().event();
0073 }
0074
0075 if (dumpTriggerResults_) {
0076 if (auto triggerResults = event.getHandle(triggerResultsToken_)) {
0077 edm::LogAbsolute("RunLumiEvent") << "TestFailuresAnalyzer dumping TriggerResults";
0078 edm::LogAbsolute("RunLumiEvent") << *triggerResults;
0079 } else {
0080 edm::LogAbsolute("RunLumiEvent") << "TriggerResults not found\n";
0081 }
0082 }
0083
0084 if ((index_ + 2U) < expectedRunLumisEvents_->size()) {
0085 assert(expectedRunLumisEvents_->at(index_) == event.run());
0086 ++index_;
0087 assert(expectedRunLumisEvents_->at(index_) == event.luminosityBlock());
0088 ++index_;
0089 assert(expectedRunLumisEvents_->at(index_) == event.id().event());
0090 ++index_;
0091 }
0092 }
0093
0094 void RunLumiEventAnalyzer::beginRun(edm::Run const& run, edm::EventSetup const&) {
0095 if (verbose_) {
0096 edm::LogAbsolute("RunLumiEvent") << "RUN_LUMI_EVENT " << run.run() << ", " << 0 << ", " << 0;
0097 }
0098
0099 if ((index_ + 2U) < expectedRunLumisEvents_->size()) {
0100 assert(expectedRunLumisEvents_->at(index_) == run.run());
0101 ++index_;
0102 assert(expectedRunLumisEvents_->at(index_) == 0);
0103 ++index_;
0104 assert(expectedRunLumisEvents_->at(index_) == 0);
0105 ++index_;
0106 }
0107 }
0108
0109 void RunLumiEventAnalyzer::endRun(edm::Run const& run, edm::EventSetup const&) {
0110 if (verbose_) {
0111 edm::LogAbsolute("RunLumiEvent") << "RUN_LUMI_EVENT " << run.run() << ", " << 0 << ", " << 0;
0112 }
0113
0114 if ((index_ + 2U) < expectedRunLumisEvents_->size()) {
0115 if (!(expectedRunLumisEvents_->at(index_) == run.run())) {
0116 throw cms::Exception("UnexpectedRun") << "RunLumiEventAnalyzer::endRun unexpected run\n"
0117 " expected "
0118 << expectedRunLumisEvents_->at(index_) << " found " << run.run();
0119 }
0120 ++index_;
0121 if (!(expectedRunLumisEvents_->at(index_) == 0)) {
0122 throw cms::Exception("UnexpectedLumi") << "RunLumiEventAnalyzer::endRun unexpected lumi\n"
0123 " expected "
0124 << expectedRunLumisEvents_->at(index_) << " found 0";
0125 }
0126 ++index_;
0127 if (!(expectedRunLumisEvents_->at(index_) == 0)) {
0128 throw cms::Exception("UnexpectedEvent") << "RunLumiEventAnalyzer::endRun unexpected event\n"
0129 " expected "
0130 << expectedRunLumisEvents_->at(index_) << " found 0";
0131 }
0132 ++index_;
0133 }
0134 }
0135
0136 void RunLumiEventAnalyzer::beginLuminosityBlock(edm::LuminosityBlock const& lumi, edm::EventSetup const&) {
0137 if (verbose_) {
0138 edm::LogAbsolute("RunLumiEvent") << "RUN_LUMI_EVENT " << lumi.run() << ", " << lumi.luminosityBlock() << ", "
0139 << 0;
0140 }
0141
0142 if ((index_ + 2U) < expectedRunLumisEvents_->size()) {
0143 assert(expectedRunLumisEvents_->at(index_) == lumi.run());
0144 ++index_;
0145 assert(expectedRunLumisEvents_->at(index_) == lumi.luminosityBlock());
0146 ++index_;
0147 assert(expectedRunLumisEvents_->at(index_) == 0);
0148 ++index_;
0149 }
0150 }
0151
0152 void RunLumiEventAnalyzer::endLuminosityBlock(edm::LuminosityBlock const& lumi, edm::EventSetup const&) {
0153 if (verbose_) {
0154 edm::LogAbsolute("RunLumiEvent") << "RUN_LUMI_EVENT " << lumi.run() << ", " << lumi.luminosityBlock() << ", "
0155 << 0;
0156 }
0157
0158 if ((index_ + 2U) < expectedRunLumisEvents_->size()) {
0159 if (!(expectedRunLumisEvents_->at(index_) == lumi.run())) {
0160 throw cms::Exception("UnexpectedRun") << "RunLumiEventAnalyzer::endLuminosityBlock unexpected run\n"
0161 " expected "
0162 << expectedRunLumisEvents_->at(index_) << " found " << lumi.run();
0163 }
0164 ++index_;
0165 if (!(expectedRunLumisEvents_->at(index_) == lumi.luminosityBlock())) {
0166 throw cms::Exception("UnexpectedLumi")
0167 << "RunLumiEventAnalyzer::endLuminosityBlock unexpected lumi"
0168 " expected "
0169 << expectedRunLumisEvents_->at(index_) << " found " << lumi.luminosityBlock();
0170 }
0171 ++index_;
0172 if (!(expectedRunLumisEvents_->at(index_) == 0)) {
0173 throw cms::Exception("UnexpectedEvent") << "RunLumiEventAnalyzer::endLuminosityBlock unexpected event"
0174 " expected "
0175 << expectedRunLumisEvents_->at(index_) << " found 0";
0176 }
0177 ++index_;
0178 }
0179 }
0180
0181 void RunLumiEventAnalyzer::endJob() {
0182 if (expectedEndingIndex_ != -1 && index_ != expectedEndingIndex_) {
0183 throw cms::Exception("UnexpectedEvent",
0184 "RunLumiEventAnalyzer::endJob. Unexpected number of runs, lumis, and events");
0185 }
0186 }
0187
0188 }
0189 using edmtest::RunLumiEventAnalyzer;
0190 DEFINE_FWK_MODULE(RunLumiEventAnalyzer);