CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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:
51 
52  bool operator==(Run const& rh) const {
53  return (runNumber_ == rh.runNumber()) &&
55  }
56 
57  bool operator!=(Run const& rh) const {
58  return (runNumber_ != rh.runNumber()) ||
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:
99 
100  edm::IEventProcessor const& ep() const;
102  FileMode fileMode() 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 
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);
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:
323  edm::RunNumber_t run() const { return run_; }
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
HandleEvent(my_context ctx)
Definition: EPStates.cc:523
edm::IEventProcessor const & ep() const
Definition: EPStates.cc:33
sc::result react(File const &file)
Definition: EPStates.cc:131
edm::IEventProcessor & ep_
Definition: EPStates.h:345
FirstFile(my_context ctx)
Definition: EPStates.cc:123
sc::transition< Run, NewRun, HandleRuns,&HandleRuns::finalizeRun > reactions
Definition: EPStates.h:342
void endRun(Run const &run, bool cleaningUpAfterException)
Definition: EPStates.cc:238
mpl::list< sc::transition< Run, HandleRuns >, sc::custom_reaction< File > > reactions
Definition: EPStates.h:223
HandleFiles(my_context ctx)
Definition: EPStates.cc:56
Starting(my_context ctx)
Definition: EPStates.cc:52
HandleLumis(my_context ctx)
Definition: EPStates.cc:366
HandleNewInputFile3(my_context ctx)
Definition: EPStates.cc:564
edm::IEventProcessor & ep_
Definition: EPStates.h:181
bool currentLumiEmpty() const
Definition: EPStates.cc:407
edm::IEventProcessor & ep_
Definition: EPStates.h:455
FileMode fileMode() const
Definition: EPStates.cc:35
tuple lumi
Definition: fjr2json.py:35
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
sc::result react(File const &file)
Definition: EPStates.cc:544
sc::result react(File const &file)
Definition: EPStates.cc:169
sc::result react(Lumi const &lumi)
Definition: EPStates.cc:664
ContinueLumi(my_context ctx)
Definition: EPStates.cc:645
void closeFiles(bool cleaningUpAfterException)
Definition: EPStates.cc:79
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
sc::result react(Run const &run)
Definition: EPStates.cc:309
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
void startingNewLoop(File const &file)
Definition: EPStates.cc:38
mpl::list< sc::custom_reaction< Run >, sc::custom_reaction< File > > reactions
Definition: EPStates.h:415
FirstLumi(my_context ctx)
Definition: EPStates.cc:454
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
bool beginRunCalled() const
Definition: EPStates.cc:215
HandleRuns(my_context ctx)
Definition: EPStates.cc:189
edm::IEventProcessor & ep_
Definition: EPStates.h:255
EndingLoop(my_context ctx)
Definition: EPStates.cc:98
ContinueRun2(my_context ctx)
Definition: EPStates.cc:599
tuple result
Definition: query.py:137
LumiID const & currentLumi() const
Definition: EPStates.cc:405
HandleNewInputFile1(my_context ctx)
Definition: EPStates.cc:146
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
sc::result react(Run const &run)
Definition: EPStates.cc:343
Run const & currentRun() const
Definition: EPStates.cc:216
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
ContinueRun1(my_context ctx)
Definition: EPStates.cc:327
edm::IEventProcessor & ep_
Definition: EPStates.h:403
edm::IEventProcessor & ep_
Definition: EPStates.h:199
AnotherLumi(my_context ctx)
Definition: EPStates.cc:488
sc::result react(Lumi const &lumi)
Definition: EPStates.cc:508
void finalizeLumi(bool cleaningUpAfterException)
Definition: EPStates.cc:426
mpl::list< sc::transition< Event, HandleEvent >, sc::transition< Lumi, AnotherLumi >, sc::custom_reaction< File > > reactions
Definition: EPStates.h:397
void finalizeRun(Run const &)
Definition: EPStates.cc:246
NewInputAndOutputFiles(my_context ctx)
Definition: EPStates.cc:161
Machine(edm::IEventProcessor *ep, FileMode fileMode, EmptyRunLumiMode emptyRunLumiMode)
Definition: EPStates.cc:25
void rewindAndPrepareForNextLoop(Restart const &restart)
Definition: EPStates.cc:47
NewRun(my_context ctx)
Definition: EPStates.cc:266
sc::result react(Run const &run)
Definition: EPStates.cc:582
Run(edm::ProcessHistoryID const &phid, edm::RunNumber_t runNumber)
Definition: EPStates.cc:18
sc::result react(Lumi const &lumi)
Definition: EPStates.cc:473
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
sc::result react(Stop const &)
Definition: EPStates.cc:107
HandleNewInputFile2(my_context ctx)
Definition: EPStates.cc:294
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
void beginRun(Run const &run)
Definition: EPStates.cc:230
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
Lumi(edm::LuminosityBlockNumber_t id)
Definition: EPStates.cc:23
edm::ProcessHistoryID const & processHistoryID() const
Definition: EPStates.h:49
Error(my_context ctx)
Definition: EPStates.cc:111
unsigned int RunNumber_t
sc::result react(Run const &run)
Definition: EPStates.cc:279
LumiID(edm::ProcessHistoryID const &phid, edm::RunNumber_t run, edm::LuminosityBlockNumber_t lumi)
Definition: EPStates.cc:360
sc::result react(Run const &run)
Definition: EPStates.cc:618
sc::transition< File, NewInputAndOutputFiles > reactions
Definition: EPStates.h:243
EmptyRunLumiMode emptyRunLumiMode() const
Definition: EPStates.cc:36
edm::propagate_const< edm::IEventProcessor * > ep_
Definition: EPStates.h:111
edm::ProcessHistoryID processHistoryID_
Definition: EPStates.h:327
sc::result react(File const &file)
Definition: EPStates.cc:153
bool runException() const
Definition: EPStates.cc:217
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