Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:28:06

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