CMS 3D CMS Logo

EPStates.h
Go to the documentation of this file.
1 #ifndef Framework_EPStates_h
2 #define Framework_EPStates_h
3 
4 /*
5 
6 The state machine that controls the processing of runs, luminosity
7 blocks, events, and loops is implemented using the boost statechart
8 library and the states and events defined here. This machine is
9 used by the EventProcessor.
10 
11 Original Authors: W. David Dagenhart, Marc Paterno
12 */
13 
18 
19 #include "boost/statechart/event.hpp"
20 #include "boost/statechart/state_machine.hpp"
21 #include <boost/statechart/state.hpp>
22 #include <boost/statechart/transition.hpp>
23 #include <boost/mpl/list.hpp>
24 #include <boost/statechart/custom_reaction.hpp>
25 #include <vector>
26 
27 namespace sc = boost::statechart;
28 namespace mpl = boost::mpl;
29 
30 namespace edm {
31  class IEventProcessor;
32 }
33 
34 namespace statemachine {
35 
37 
41  };
42 
43  // Define the classes representing the "boost statechart events".
44  // There are six of them.
45 
46  class Run : public sc::event<Run> {
47  public:
49  edm::ProcessHistoryID const& processHistoryID() const { return processHistoryID_; }
51 
52  bool operator==(Run const& rh) const {
53  return (runNumber_ == rh.runNumber()) &&
54  (processHistoryID_ == rh.processHistoryID());
55  }
56 
57  bool operator!=(Run const& rh) const {
58  return (runNumber_ != rh.runNumber()) ||
59  (processHistoryID_ != rh.processHistoryID());
60  }
61 
62  private:
65  };
66 
67  class Lumi : public sc::event<Lumi> {
68  public:
70  edm::LuminosityBlockNumber_t id() const { return id_; }
71  private:
73  };
74 
75  // It is slightly confusing that this one refers to
76  // both physics event and a boost statechart event ...
77  class Event : public sc::event<Event> { };
78 
79  class File : public sc::event<File> {};
80  class Stop : public sc::event<Stop> {};
81  class Restart : public sc::event<Restart> {};
82 
83  // Now define the machine and the states.
84  // For all these classes, the first template argument
85  // to the base class is the derived class. The second
86  // argument is the parent state or if it is a top level
87  // state the Machine. If there is a third template
88  // argument it is the substate that is entered
89  // by default on entry.
90 
91  class Starting;
92 
93  class Machine : public sc::state_machine<Machine, Starting>
94  {
95  public:
97  FileMode fileMode,
98  EmptyRunLumiMode emptyRunLumiMode);
99 
100  edm::IEventProcessor const& ep() const;
101  edm::IEventProcessor& ep();
102  FileMode fileMode() const;
103  EmptyRunLumiMode emptyRunLumiMode() const;
104 
105  void startingNewLoop(File const& file);
106  void startingNewLoop(Stop const& stop);
107  void rewindAndPrepareForNextLoop(Restart const& restart);
108 
109  private:
110 
114  };
115 
116  class Error;
117  class HandleFiles;
118  class EndingLoop;
119 
120  class Starting : public sc::state<Starting, Machine>
121  {
122  public:
123  Starting(my_context ctx);
124  ~Starting();
125 
126  typedef mpl::list<
127  sc::transition<Event, Error>,
128  sc::transition<Lumi, Error>,
129  sc::transition<Run, Error>,
130  sc::transition<File, HandleFiles, Machine, &Machine::startingNewLoop>,
131  sc::transition<Stop, EndingLoop, Machine, &Machine::startingNewLoop>,
132  sc::transition<Restart, Error> > reactions;
133  };
134 
135  class FirstFile;
136 
137  class HandleFiles : public sc::state<HandleFiles, Machine, FirstFile>
138  {
139  public:
140  HandleFiles(my_context ctx);
141  void exit();
142  ~HandleFiles();
143 
144  typedef mpl::list<
145  sc::transition<Event, Error>,
146  sc::transition<Lumi, Error>,
147  sc::transition<Run, Error>,
148  sc::transition<File, Error>,
149  sc::transition<Stop, EndingLoop>,
150  sc::transition<Restart, Error> > reactions;
151 
152  void closeFiles(bool cleaningUpAfterException);
153  void goToNewInputFile();
154  bool shouldWeCloseOutput();
155  private:
158  };
159 
160  class EndingLoop : public sc::state<EndingLoop, Machine>
161  {
162  public:
163  EndingLoop(my_context ctx);
164  ~EndingLoop();
165  typedef mpl::list<
166  sc::transition<Restart, Starting, Machine, &Machine::rewindAndPrepareForNextLoop>,
167  sc::custom_reaction<Stop> > reactions;
168 
169  sc::result react(Stop const&);
170  private:
172  };
173 
174  class Error : public sc::state<Error, Machine>
175  {
176  public:
177  Error(my_context ctx);
178  ~Error();
179  typedef sc::transition<Stop, EndingLoop> reactions;
180  private:
182  };
183 
184  class HandleRuns;
185 
186  class FirstFile : public sc::state<FirstFile, HandleFiles>
187  {
188  public:
189  FirstFile(my_context ctx);
190  ~FirstFile();
191 
192  typedef mpl::list<
193  sc::transition<Run, HandleRuns>,
194  sc::custom_reaction<File> > reactions;
195 
196  sc::result react(File const& file);
197  void openFiles();
198  private:
200  };
201 
202  class HandleNewInputFile1 : public sc::state<HandleNewInputFile1, HandleFiles>
203  {
204  public:
205  HandleNewInputFile1(my_context ctx);
207 
208  typedef mpl::list<
209  sc::transition<Run, HandleRuns>,
210  sc::custom_reaction<File> > reactions;
211 
212  sc::result react(File const& file);
213  };
214 
215  class NewInputAndOutputFiles : public sc::state<NewInputAndOutputFiles, HandleFiles>
216  {
217  public:
218  NewInputAndOutputFiles(my_context ctx);
220 
221  typedef mpl::list<
222  sc::transition<Run, HandleRuns>,
223  sc::custom_reaction<File> > reactions;
224 
225  sc::result react(File const& file);
226 
227  private:
228 
229  void goToNewInputAndOutputFiles();
230 
232  };
233 
234  class NewRun;
235 
236  class HandleRuns : public sc::state<HandleRuns, HandleFiles, NewRun>
237  {
238  public:
239  HandleRuns(my_context ctx);
240  void exit();
241  ~HandleRuns();
242 
243  typedef sc::transition<File, NewInputAndOutputFiles> reactions;
244 
245  bool beginRunCalled() const;
246  Run const& currentRun() const;
247  bool runException() const;
248  void setupCurrentRun();
249  void beginRun(Run const& run);
250  void endRun(Run const& run, bool cleaningUpAfterException);
251  void finalizeRun(Run const&);
252  void finalizeRun(bool cleaningUpAfterException);
253  void beginRunIfNotDoneAlready();
254  private:
260  };
261 
262  class HandleLumis;
263 
264  class NewRun : public sc::state<NewRun, HandleRuns>
265  {
266  public:
267  NewRun(my_context ctx);
268  ~NewRun();
269 
270  typedef mpl::list<
271  sc::transition<Lumi, HandleLumis>,
272  sc::custom_reaction<Run>,
273  sc::custom_reaction<File> > reactions;
274 
275  sc::result react(Run const& run);
276  sc::result react(File const& file);
277  };
278 
279  class ContinueRun1;
280 
281  class HandleNewInputFile2 : public sc::state<HandleNewInputFile2, HandleRuns>
282  {
283  public:
284  HandleNewInputFile2(my_context ctx);
286  bool checkInvariant();
287 
288  typedef mpl::list<
289  sc::custom_reaction<Run>,
290  sc::custom_reaction<File> > reactions;
291 
292  sc::result react(Run const& run);
293  sc::result react(File const& file);
294  };
295 
296  class ContinueRun1 : public sc::state<ContinueRun1, HandleRuns>
297  {
298  public:
299  ContinueRun1(my_context ctx);
300  ~ContinueRun1();
301  bool checkInvariant();
302 
303  typedef mpl::list<
304  sc::custom_reaction<Run>,
305  sc::custom_reaction<File>,
306  sc::transition<Lumi, HandleLumis> > reactions;
307 
308  sc::result react(Run const& run);
309  sc::result react(File const& file);
310  private:
312  };
313 
314  class FirstLumi;
315 
316  class HandleLumis : public sc::state<HandleLumis, HandleRuns, FirstLumi>
317  {
318  public:
319  class LumiID {
320  public:
322  edm::ProcessHistoryID const& processHistoryID() const { return processHistoryID_; }
323  edm::RunNumber_t run() const { return run_; }
324  edm::LuminosityBlockNumber_t lumi() const { return lumi_; }
325 
326  private:
330  };
331  HandleLumis(my_context ctx);
332  void exit();
333  ~HandleLumis();
334  bool checkInvariant();
335 
336  LumiID const& currentLumi() const;
337  bool currentLumiEmpty() const;
338  void setupCurrentLumi();
339  void finalizeLumi(bool cleaningUpAfterException);
340  void markLumiNonEmpty();
341 
342  typedef sc::transition<Run, NewRun, HandleRuns, &HandleRuns::finalizeRun> reactions;
343 
344  private:
350  };
351 
352  class HandleEvent;
353  class AnotherLumi;
354 
355  class FirstLumi : public sc::state<FirstLumi, HandleLumis>
356  {
357  public:
358  FirstLumi(my_context ctx);
359  ~FirstLumi();
360  bool checkInvariant();
361 
362  typedef mpl::list<
363  sc::transition<Event, HandleEvent>,
364  sc::custom_reaction<Lumi>,
365  sc::custom_reaction<File> > reactions;
366 
367  sc::result react(Lumi const& lumi);
368  sc::result react(File const& file);
369  };
370 
371  class AnotherLumi : public sc::state<AnotherLumi, HandleLumis>
372  {
373  public:
374  AnotherLumi(my_context ctx);
375  ~AnotherLumi();
376  bool checkInvariant();
377 
378  typedef mpl::list<
379  sc::transition<Event, HandleEvent>,
380  sc::custom_reaction<Lumi>,
381  sc::custom_reaction<File> > reactions;
382 
383  sc::result react(Lumi const& lumi);
384  sc::result react(File const& file);
385  };
386 
387  class HandleEvent : public sc::state<HandleEvent, HandleLumis>
388  {
389  public:
390  HandleEvent(my_context ctx);
391  ~HandleEvent();
392  bool checkInvariant();
393 
394  typedef mpl::list<
395  sc::transition<Event, HandleEvent>,
396  sc::transition<Lumi, AnotherLumi>,
397  sc::custom_reaction<File> > reactions;
398 
399  sc::result react(File const& file);
400  void readAndProcessEvent();
401  void markNonEmpty();
402  private:
404  };
405 
406  class HandleNewInputFile3 : public sc::state<HandleNewInputFile3, HandleLumis>
407  {
408  public:
409  HandleNewInputFile3(my_context ctx);
411  bool checkInvariant();
412 
413  typedef mpl::list<
414  sc::custom_reaction<Run>,
415  sc::custom_reaction<File> > reactions;
416 
417  sc::result react(Run const& run);
418  sc::result react(File const& file);
419  };
420 
421  class ContinueRun2 : public sc::state<ContinueRun2, HandleLumis>
422  {
423  public:
424  ContinueRun2(my_context ctx);
425  ~ContinueRun2();
426  bool checkInvariant();
427 
428  typedef mpl::list<
429  sc::custom_reaction<Run>,
430  sc::custom_reaction<Lumi>,
431  sc::custom_reaction<File> > reactions;
432 
433  sc::result react(Run const& run);
434  sc::result react(Lumi const& lumi);
435  sc::result react(File const& file);
436  private:
438  };
439 
440  class ContinueLumi : public sc::state<ContinueLumi, HandleLumis>
441  {
442  public:
443  ContinueLumi(my_context ctx);
444  ~ContinueLumi();
445  bool checkInvariant();
446 
447  typedef mpl::list<
448  sc::transition<Event, HandleEvent>,
449  sc::custom_reaction<Lumi>,
450  sc::custom_reaction<File> > reactions;
451 
452  sc::result react(Lumi const& lumi);
453  sc::result react(File const& file);
454  private:
456  };
457 }
458 
459 #endif
mpl::list< sc::transition< Event, HandleEvent >, sc::custom_reaction< Lumi >, sc::custom_reaction< File > > reactions
Definition: EPStates.h:381
static const char runNumber_[]
edm::IEventProcessor & ep_
Definition: EPStates.h:345
sc::transition< Run, NewRun, HandleRuns,&HandleRuns::finalizeRun > reactions
Definition: EPStates.h:342
mpl::list< sc::transition< Run, HandleRuns >, sc::custom_reaction< File > > reactions
Definition: EPStates.h:223
edm::IEventProcessor & ep_
Definition: EPStates.h:181
edm::IEventProcessor & ep_
Definition: EPStates.h:455
mpl::list< sc::transition< Lumi, HandleLumis >, sc::custom_reaction< Run >, sc::custom_reaction< File > > reactions
Definition: EPStates.h:273
edm::ProcessHistoryID const & processHistoryID() const
Definition: EPStates.h:322
edm::LuminosityBlockNumber_t lumi() const
Definition: EPStates.h:324
edm::ProcessHistoryID processHistoryID_
Definition: EPStates.h:63
edm::IEventProcessor & ep_
Definition: EPStates.h:437
edm::IEventProcessor & ep_
Definition: EPStates.h:156
mpl::list< sc::custom_reaction< Run >, sc::custom_reaction< File >, sc::transition< Lumi, HandleLumis > > reactions
Definition: EPStates.h:306
unsigned int LuminosityBlockNumber_t
edm::LuminosityBlockNumber_t id_
Definition: EPStates.h:72
mpl::list< sc::transition< Restart, Starting, Machine,&Machine::rewindAndPrepareForNextLoop >, sc::custom_reaction< Stop > > reactions
Definition: EPStates.h:167
edm::IEventProcessor & ep_
Definition: EPStates.h:311
mpl::list< sc::custom_reaction< Run >, sc::custom_reaction< File > > reactions
Definition: EPStates.h:415
bool operator!=(Run const &rh) const
Definition: EPStates.h:57
EmptyRunLumiMode emptyRunLumiMode_
Definition: EPStates.h:113
edm::LuminosityBlockNumber_t id() const
Definition: EPStates.h:70
edm::IEventProcessor & ep_
Definition: EPStates.h:255
mpl::list< sc::transition< Event, HandleEvent >, sc::custom_reaction< Lumi >, sc::custom_reaction< File > > reactions
Definition: EPStates.h:365
bool operator==(Run const &rh) const
Definition: EPStates.h:52
edm::IEventProcessor & ep_
Definition: EPStates.h:231
sc::transition< Stop, EndingLoop > reactions
Definition: EPStates.h:179
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
mpl::list< sc::transition< Event, HandleEvent >, sc::custom_reaction< Lumi >, sc::custom_reaction< File > > reactions
Definition: EPStates.h:450
mpl::list< sc::transition< Event, Error >, sc::transition< Lumi, Error >, sc::transition< Run, Error >, sc::transition< File, Error >, sc::transition< Stop, EndingLoop >, sc::transition< Restart, Error > > reactions
Definition: EPStates.h:150
edm::IEventProcessor & ep_
Definition: EPStates.h:403
edm::IEventProcessor & ep_
Definition: EPStates.h:199
mpl::list< sc::transition< Event, HandleEvent >, sc::transition< Lumi, AnotherLumi >, sc::custom_reaction< File > > reactions
Definition: EPStates.h:397
edm::RunNumber_t runNumber_
Definition: EPStates.h:64
mpl::list< sc::custom_reaction< Run >, sc::custom_reaction< File > > reactions
Definition: EPStates.h:290
edm::RunNumber_t run() const
Definition: EPStates.h:323
mpl::list< sc::custom_reaction< Run >, sc::custom_reaction< Lumi >, sc::custom_reaction< File > > reactions
Definition: EPStates.h:431
mpl::list< sc::transition< Run, HandleRuns >, sc::custom_reaction< File > > reactions
Definition: EPStates.h:210
edm::IEventProcessor & ep_
Definition: EPStates.h:171
edm::RunNumber_t runNumber() const
Definition: EPStates.h:50
HLT enums.
mpl::list< sc::transition< Run, HandleRuns >, sc::custom_reaction< File > > reactions
Definition: EPStates.h:194
edm::LuminosityBlockNumber_t lumi_
Definition: EPStates.h:329
mpl::list< sc::transition< Event, Error >, sc::transition< Lumi, Error >, sc::transition< Run, Error >, sc::transition< File, HandleFiles, Machine,&Machine::startingNewLoop >, sc::transition< Stop, EndingLoop, Machine,&Machine::startingNewLoop >, sc::transition< Restart, Error > > reactions
Definition: EPStates.h:132
edm::ProcessHistoryID const & processHistoryID() const
Definition: EPStates.h:49
unsigned int RunNumber_t
sc::transition< File, NewInputAndOutputFiles > reactions
Definition: EPStates.h:243
edm::propagate_const< edm::IEventProcessor * > ep_
Definition: EPStates.h:111
edm::ProcessHistoryID processHistoryID_
Definition: EPStates.h:327
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run