CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EventIDChecker.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Modules
4 // Class: EventIDChecker
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 
33 //
34 // class decleration
35 //
36 
38 public:
39  explicit EventIDChecker(edm::ParameterSet const&);
41  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
42 
43 
44 private:
45  virtual void beginJob() override;
46  virtual void analyze(edm::Event const&, edm::EventSetup const&) override;
47  virtual void endJob() override;
48  virtual void postForkReacquireResources(unsigned int iChildIndex, unsigned int iNumberOfChildren) override;
49 
50  // ----------member data ---------------------------
51  std::vector<edm::EventID> ids_;
52  unsigned int index_;
53 
57 };
58 
59 //
60 // constants, enums and typedefs
61 //
62 
63 //
64 // static data member definitions
65 //
66 
67 //
68 // constructors and destructor
69 //
71  ids_(iConfig.getUntrackedParameter<std::vector<edm::EventID> >("eventSequence")),
72  index_(0),
73  multiProcessSequentialEvents_(iConfig.getUntrackedParameter<unsigned int>("multiProcessSequentialEvents")),
74  numberOfEventsLeftBeforeSearch_(0),
75  mustSearch_(false)
76 {
77  //now do what ever initialization is needed
78 
79 }
80 
81 
83 
84  // do anything here that needs to be done at desctruction time
85  // (e.g. close files, deallocate resources etc.)
86 
87 }
88 
89 
90 //
91 // member functions
92 //
93 
94 namespace {
95  struct CompareWithoutLumi {
96  CompareWithoutLumi(edm::EventID const& iThis) : m_this(iThis) {
97  }
98  bool operator()(edm::EventID const& iOther) {
99  return m_this.run() == iOther.run() && m_this.event() == iOther.event();
100  }
101  edm::EventID m_this;
102  };
103 }
104 
105 // ------------ method called to for each event ------------
106 void
108  if(mustSearch_) {
111  //the event must be after the last event in our list since multicore doesn't go backwards
112  std::vector<edm::EventID>::iterator itFind= std::find_if(ids_.begin()+index_, ids_.end(), CompareWithoutLumi(iEvent.id()));
113  if(itFind == ids_.end()) {
114  throw cms::Exception("MissedEvent") << "The event " << iEvent.id() << "is not in the list.\n";
115  }
116  index_ = itFind-ids_.begin();
117  }
119  }
120 
121  if(index_ >= ids_.size()) {
122  throw cms::Exception("TooManyEvents") << "Was passes " << ids_.size() << " EventIDs but have processed more events than that\n";
123  }
124  if(iEvent.id().run() != ids_[index_].run() || iEvent.id().event() != ids_[index_].event()) {
125  throw cms::Exception("WrongEvent") << "Was expecting event " << ids_[index_] << " but was given " << iEvent.id() << "\n";
126  }
127  ++index_;
128 }
129 
130 // ------------ method called once each job just before starting event loop ------------
131 void
133 }
134 
135 // ------------ method called once each job just after ending the event loop ------------
136 void
138 }
139 
140 // ------------ method called once each job for validation
141 void
144  desc.addUntracked<std::vector<edm::EventID> >("eventSequence");
145  desc.addUntracked<unsigned int>("multiProcessSequentialEvents", 0U);
146  descriptions.add("eventIDChecker", desc);
147 }
148 
149 void
150 EventIDChecker::postForkReacquireResources(unsigned int /*iChildIndex*/, unsigned int /*iNumberOfChildren*/) {
151  mustSearch_ = true;
152 }
153 
154 //define this as a plug-in
RunNumber_t run() const
Definition: EventID.h:39
EventNumber_t event() const
Definition: EventID.h:41
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
unsigned int multiProcessSequentialEvents_
int iEvent
Definition: GenABIO.cc:230
virtual void analyze(edm::Event const &, edm::EventSetup const &) override
unsigned int index_
std::vector< edm::EventID > ids_
unsigned int numberOfEventsLeftBeforeSearch_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
EventIDChecker(edm::ParameterSet const &)
edm::EventID id() const
Definition: EventBase.h:59
virtual void endJob() override
virtual void beginJob() override
virtual void postForkReacquireResources(unsigned int iChildIndex, unsigned int iNumberOfChildren) override
volatile std::atomic< bool > shutdown_flag false