File indexing completed on 2024-04-06 12:12:48
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/MakerMacros.h"
0024 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0025 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0026 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0027
0028
0029 #include <algorithm>
0030 #include <memory>
0031 #include <vector>
0032 #include <cstdlib>
0033
0034
0035
0036
0037
0038 class AbortOnEventIDAnalyzer : public edm::global::EDAnalyzer<> {
0039 public:
0040 explicit AbortOnEventIDAnalyzer(edm::ParameterSet const&);
0041 ~AbortOnEventIDAnalyzer() override;
0042 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0043
0044 private:
0045 void beginJob() override;
0046 void analyze(edm::StreamID, edm::Event const&, edm::EventSetup const&) const override;
0047 void endJob() override;
0048
0049
0050 std::vector<edm::EventID> ids_;
0051 bool throwException_;
0052 };
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065 AbortOnEventIDAnalyzer::AbortOnEventIDAnalyzer(edm::ParameterSet const& iConfig)
0066 : ids_(iConfig.getUntrackedParameter<std::vector<edm::EventID> >("eventsToAbort")),
0067 throwException_(iConfig.getUntrackedParameter<bool>("throwExceptionInsteadOfAbort")) {
0068
0069 }
0070
0071 AbortOnEventIDAnalyzer::~AbortOnEventIDAnalyzer() {
0072
0073
0074 }
0075
0076
0077
0078
0079
0080 namespace {
0081 struct CompareWithoutLumi {
0082 CompareWithoutLumi(edm::EventID const& iThis) : m_this(iThis) {}
0083 bool operator()(edm::EventID const& iOther) {
0084 return m_this.run() == iOther.run() && m_this.event() == iOther.event();
0085 }
0086 edm::EventID m_this;
0087 };
0088 }
0089
0090
0091 void AbortOnEventIDAnalyzer::analyze(edm::StreamID, edm::Event const& iEvent, edm::EventSetup const&) const {
0092 auto itFind = std::find_if(ids_.begin(), ids_.end(), CompareWithoutLumi(iEvent.id()));
0093 if (itFind != ids_.end()) {
0094 if (throwException_) {
0095 throw cms::Exception("AbortEvent") << "Found event " << iEvent.id() << "\n";
0096 } else {
0097 abort();
0098 }
0099 }
0100 }
0101
0102
0103 void AbortOnEventIDAnalyzer::beginJob() {}
0104
0105
0106 void AbortOnEventIDAnalyzer::endJob() {}
0107
0108
0109 void AbortOnEventIDAnalyzer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0110 edm::ParameterSetDescription desc;
0111 desc.addUntracked<std::vector<edm::EventID> >("eventsToAbort");
0112 desc.addUntracked<bool>("throwExceptionInsteadOfAbort", false);
0113 descriptions.add("abortOnEventID", desc);
0114 }
0115
0116
0117 DEFINE_FWK_MODULE(AbortOnEventIDAnalyzer);