File indexing completed on 2023-03-17 11:03:17
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #include "DataFormats/Provenance/interface/EventID.h"
0021 #include "FWCore/Framework/interface/global/EDAnalyzer.h"
0022 #include "FWCore/Framework/interface/Event.h"
0023 #include "FWCore/Framework/interface/LuminosityBlock.h"
0024 #include "FWCore/Framework/interface/MakerMacros.h"
0025 #include "FWCore/Framework/interface/Run.h"
0026 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0027 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0028 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0029 #include "FWCore/Utilities/interface/UnixSignalHandlers.h"
0030 #include "FWCore/Utilities/interface/propagate_const.h"
0031
0032
0033 #include <algorithm>
0034 #include <map>
0035 #include <memory>
0036 #include <vector>
0037 #include <map>
0038
0039
0040
0041
0042 namespace rlec {
0043 struct Cache {};
0044 }
0045
0046 class RunLumiEventChecker
0047 : public edm::global::EDAnalyzer<edm::RunCache<rlec::Cache>, edm::LuminosityBlockCache<rlec::Cache>> {
0048 public:
0049 explicit RunLumiEventChecker(edm::ParameterSet const&);
0050 ~RunLumiEventChecker() override;
0051 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0052
0053 private:
0054 void beginJob() override;
0055 void analyze(edm::StreamID, edm::Event const&, edm::EventSetup const&) const override;
0056 void endJob() override;
0057
0058 std::shared_ptr<rlec::Cache> globalBeginRun(edm::Run const& run, edm::EventSetup const& es) const override;
0059 void globalEndRun(edm::Run const& run, edm::EventSetup const& es) const override;
0060
0061 std::shared_ptr<rlec::Cache> globalBeginLuminosityBlock(edm::LuminosityBlock const& lumi,
0062 edm::EventSetup const& es) const override;
0063 void globalEndLuminosityBlock(edm::LuminosityBlock const& lumi, edm::EventSetup const& es) const override;
0064
0065 void check(edm::EventID const& iID, bool isEvent) const;
0066
0067
0068 std::vector<edm::EventID> ids_;
0069 mutable std::atomic<unsigned int> index_;
0070 bool unorderedEvents_;
0071 };
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084 RunLumiEventChecker::RunLumiEventChecker(edm::ParameterSet const& iConfig)
0085 : ids_(iConfig.getUntrackedParameter<std::vector<edm::EventID>>("eventSequence")),
0086 index_(0),
0087 unorderedEvents_(iConfig.getUntrackedParameter<bool>("unorderedEvents")) {
0088
0089 }
0090
0091 RunLumiEventChecker::~RunLumiEventChecker() {
0092
0093
0094 }
0095
0096
0097
0098
0099
0100 void RunLumiEventChecker::check(edm::EventID const& iEventID, bool iIsEvent) const {
0101 if (index_ >= ids_.size()) {
0102 throw cms::Exception("TooManyEvents")
0103 << "Was passes " << ids_.size() << " EventIDs but have processed more events than that\n";
0104 }
0105 if (unorderedEvents_) {
0106 auto itFound = std::find(ids_.begin(), ids_.end(), iEventID);
0107 if (itFound == ids_.end()) {
0108 throw cms::Exception("UnexpecedEvent") << "The event " << iEventID << " was not expected.";
0109 }
0110 } else {
0111 if (iEventID != ids_[index_]) {
0112 throw cms::Exception("WrongEvent") << "Was expecting event " << ids_[index_] << " but was given " << iEventID
0113 << "\n";
0114 }
0115 }
0116 ++index_;
0117 }
0118
0119
0120 void RunLumiEventChecker::analyze(edm::StreamID, edm::Event const& iEvent, edm::EventSetup const&) const {
0121 check(iEvent.id(), true);
0122 }
0123
0124 std::shared_ptr<rlec::Cache> RunLumiEventChecker::globalBeginRun(edm::Run const& run, edm::EventSetup const&) const {
0125 check(edm::EventID(run.id().run(), 0, 0), false);
0126 return std::shared_ptr<rlec::Cache>{};
0127 }
0128 void RunLumiEventChecker::globalEndRun(edm::Run const& run, edm::EventSetup const&) const {
0129 check(edm::EventID(run.id().run(), 0, 0), false);
0130 }
0131
0132 std::shared_ptr<rlec::Cache> RunLumiEventChecker::globalBeginLuminosityBlock(edm::LuminosityBlock const& lumi,
0133 edm::EventSetup const&) const {
0134 check(edm::EventID(lumi.id().run(), lumi.id().luminosityBlock(), 0), false);
0135 return std::shared_ptr<rlec::Cache>{};
0136 }
0137
0138 void RunLumiEventChecker::globalEndLuminosityBlock(edm::LuminosityBlock const& lumi, edm::EventSetup const&) const {
0139 check(edm::EventID(lumi.id().run(), lumi.id().luminosityBlock(), 0), false);
0140 }
0141
0142
0143 void RunLumiEventChecker::beginJob() {}
0144
0145
0146 void RunLumiEventChecker::endJob() {
0147 if (index_ != ids_.size()) {
0148 throw cms::Exception("WrongNumberOfEvents")
0149 << "Saw " << index_ << " events but was supposed to see " << ids_.size() << "\n";
0150 }
0151 }
0152
0153
0154 void RunLumiEventChecker::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0155 edm::ParameterSetDescription desc;
0156 desc.addUntracked<std::vector<edm::EventID>>("eventSequence");
0157 desc.addUntracked<bool>("unorderedEvents", false);
0158 descriptions.add("runLumiEventIDChecker", desc);
0159 }
0160
0161
0162 DEFINE_FWK_MODULE(RunLumiEventChecker);