CMS 3D CMS Logo

AbortOnEventIDAnalyzer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Modules
4 // Class: AbortOnEventIDAnalyzer
5 //
13 //
14 // Original Author: Chris Jones
15 // Created: Tue Jun 16 15:42:17 CDT 2009
16 //
17 //
18 
19 // user include files
27 
28 // system include files
29 #include <algorithm>
30 #include <memory>
31 #include <vector>
32 #include <cstdlib>
33 
34 //
35 // class decleration
36 //
37 
39 public:
41  ~AbortOnEventIDAnalyzer() override;
42  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
43 
44 private:
45  void beginJob() override;
46  void analyze(edm::Event const&, edm::EventSetup const&) override;
47  void endJob() override;
48 
49  // ----------member data ---------------------------
50  std::vector<edm::EventID> ids_;
52 };
53 
54 //
55 // constants, enums and typedefs
56 //
57 
58 //
59 // static data member definitions
60 //
61 
62 //
63 // constructors and destructor
64 //
66  : ids_(iConfig.getUntrackedParameter<std::vector<edm::EventID> >("eventsToAbort")),
67  throwException_(iConfig.getUntrackedParameter<bool>("throwExceptionInsteadOfAbort")) {
68  //now do what ever initialization is needed
69 }
70 
72  // do anything here that needs to be done at desctruction time
73  // (e.g. close files, deallocate resources etc.)
74 }
75 
76 //
77 // member functions
78 //
79 
80 namespace {
81  struct CompareWithoutLumi {
82  CompareWithoutLumi(edm::EventID const& iThis) : m_this(iThis) {}
83  bool operator()(edm::EventID const& iOther) {
84  return m_this.run() == iOther.run() && m_this.event() == iOther.event();
85  }
86  edm::EventID m_this;
87  };
88 } // namespace
89 
90 // ------------ method called to for each event ------------
92  std::vector<edm::EventID>::iterator itFind = std::find_if(ids_.begin(), ids_.end(), CompareWithoutLumi(iEvent.id()));
93  if (itFind != ids_.end()) {
94  if (throwException_) {
95  throw cms::Exception("AbortEvent") << "Found event " << iEvent.id() << "\n";
96  } else {
97  abort();
98  }
99  }
100 }
101 
102 // ------------ method called once each job just before starting event loop ------------
104 
105 // ------------ method called once each job just after ending the event loop ------------
107 
108 // ------------ method called once each job for validation
111  desc.addUntracked<std::vector<edm::EventID> >("eventsToAbort");
112  desc.addUntracked<bool>("throwExceptionInsteadOfAbort", false);
113  descriptions.add("abortOnEventID", desc);
114 }
115 
116 //define this as a plug-in
RunNumber_t run() const
Definition: EventID.h:39
EventNumber_t event() const
Definition: EventID.h:41
std::vector< edm::EventID > ids_
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void add(std::string const &label, ParameterSetDescription const &psetDescription)
AbortOnEventIDAnalyzer(edm::ParameterSet const &)
edm::EventID id() const
Definition: EventBase.h:59
HLT enums.
void analyze(edm::Event const &, edm::EventSetup const &) override