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 
17 
18 #include "boost/statechart/event.hpp"
19 #include "boost/statechart/state_machine.hpp"
20 #include <boost/statechart/state.hpp>
21 #include <boost/statechart/transition.hpp>
22 #include <boost/mpl/list.hpp>
23 #include <boost/statechart/custom_reaction.hpp>
24 #include <vector>
25 
26 namespace sc = boost::statechart;
27 namespace mpl = boost::mpl;
28 
29 namespace edm {
30  class IEventProcessor;
31 }
32 
33 namespace statemachine {
34 
36 
40  };
41 
42  // Define the classes representing the "boost statechart events".
43  // There are six of them.
44 
45  class Run : public sc::event<Run> {
46  public:
50 
51  bool operator==(Run const& rh) const {
52  return (runNumber_ == rh.runNumber()) &&
54  }
55 
56  bool operator!=(Run const& rh) const {
57  return (runNumber_ != rh.runNumber()) ||
59  }
60 
61  private:
64  };
65 
66  class Lumi : public sc::event<Lumi> {
67  public:
69  edm::LuminosityBlockNumber_t id() const { return id_; }
70  private:
72  };
73 
74  // It is slightly confusing that this one refers to
75  // both physics event and a boost statechart event ...
76  class Event : public sc::event<Event> { };
77 
78  class File : public sc::event<File> {};
79  class Stop : public sc::event<Stop> {};
80  class Restart : public sc::event<Restart> {};
81 
82  // Now define the machine and the states.
83  // For all these classes, the first template argument
84  // to the base class is the derived class. The second
85  // argument is the parent state or if it is a top level
86  // state the Machine. If there is a third template
87  // argument it is the substate that is entered
88  // by default on entry.
89 
90  class Starting;
91 
92  class Machine : public sc::state_machine<Machine, Starting>
93  {
94  public:
98 
99  edm::IEventProcessor& ep() const;
100  FileMode fileMode() const;
102 
103  void startingNewLoop(File const& file);
104  void startingNewLoop(Stop const& stop);
105  void rewindAndPrepareForNextLoop(Restart const& restart);
106 
107  private:
108 
112  };
113 
114  class Error;
115  class HandleFiles;
116  class EndingLoop;
117 
118  class Starting : public sc::state<Starting, Machine>
119  {
120  public:
121  Starting(my_context ctx);
122  ~Starting();
123 
124  typedef mpl::list<
125  sc::transition<Event, Error>,
126  sc::transition<Lumi, Error>,
127  sc::transition<Run, Error>,
128  sc::transition<File, HandleFiles, Machine, &Machine::startingNewLoop>,
129  sc::transition<Stop, EndingLoop, Machine, &Machine::startingNewLoop>,
130  sc::transition<Restart, Error> > reactions;
131  };
132 
133  class FirstFile;
134 
135  class HandleFiles : public sc::state<HandleFiles, Machine, FirstFile>
136  {
137  public:
138  HandleFiles(my_context ctx);
139  void exit();
140  ~HandleFiles();
141 
142  typedef mpl::list<
143  sc::transition<Event, Error>,
144  sc::transition<Lumi, Error>,
145  sc::transition<Run, Error>,
146  sc::transition<File, Error>,
147  sc::transition<Stop, EndingLoop>,
148  sc::transition<Restart, Error> > reactions;
149 
150  void closeFiles(bool cleaningUpAfterException);
151  void goToNewInputFile();
152  bool shouldWeCloseOutput();
153  private:
156  };
157 
158  class EndingLoop : public sc::state<EndingLoop, Machine>
159  {
160  public:
161  EndingLoop(my_context ctx);
162  ~EndingLoop();
163  typedef mpl::list<
164  sc::transition<Restart, Starting, Machine, &Machine::rewindAndPrepareForNextLoop>,
165  sc::custom_reaction<Stop> > reactions;
166 
167  sc::result react(Stop const&);
168  private:
170  };
171 
172  class Error : public sc::state<Error, Machine>
173  {
174  public:
175  Error(my_context ctx);
176  ~Error();
177  typedef sc::transition<Stop, EndingLoop> reactions;
178  private:
180  };
181 
182  class HandleRuns;
183 
184  class FirstFile : public sc::state<FirstFile, HandleFiles>
185  {
186  public:
187  FirstFile(my_context ctx);
188  ~FirstFile();
189 
190  typedef mpl::list<
191  sc::transition<Run, HandleRuns>,
192  sc::custom_reaction<File> > reactions;
193 
194  sc::result react(File const& file);
195  void openFiles();
196  private:
198  };
199 
200  class HandleNewInputFile1 : public sc::state<HandleNewInputFile1, HandleFiles>
201  {
202  public:
203  HandleNewInputFile1(my_context ctx);
205 
206  typedef mpl::list<
207  sc::transition<Run, HandleRuns>,
208  sc::custom_reaction<File> > reactions;
209 
210  sc::result react(File const& file);
211  };
212 
213  class NewInputAndOutputFiles : public sc::state<NewInputAndOutputFiles, HandleFiles>
214  {
215  public:
216  NewInputAndOutputFiles(my_context ctx);
218 
219  typedef mpl::list<
220  sc::transition<Run, HandleRuns>,
221  sc::custom_reaction<File> > reactions;
222 
223  sc::result react(File const& file);
224 
225  private:
226 
228 
230  };
231 
232  class NewRun;
233 
234  class HandleRuns : public sc::state<HandleRuns, HandleFiles, NewRun>
235  {
236  public:
237  HandleRuns(my_context ctx);
238  void exit();
239  ~HandleRuns();
240 
241  typedef sc::transition<File, NewInputAndOutputFiles> reactions;
242 
243  bool beginRunCalled() const;
244  Run const& currentRun() const;
245  bool runException() const;
246  void setupCurrentRun();
247  void beginRun(Run const& run);
248  void endRun(Run const& run, bool cleaningUpAfterException);
249  void finalizeRun(Run const&);
250  void finalizeRun(bool cleaningUpAfterException);
252  private:
258  };
259 
260  class HandleLumis;
261 
262  class NewRun : public sc::state<NewRun, HandleRuns>
263  {
264  public:
265  NewRun(my_context ctx);
266  ~NewRun();
267 
268  typedef mpl::list<
269  sc::transition<Lumi, HandleLumis>,
270  sc::custom_reaction<Run>,
271  sc::custom_reaction<File> > reactions;
272 
273  sc::result react(Run const& run);
274  sc::result react(File const& file);
275  };
276 
277  class ContinueRun1;
278 
279  class HandleNewInputFile2 : public sc::state<HandleNewInputFile2, HandleRuns>
280  {
281  public:
282  HandleNewInputFile2(my_context ctx);
284  bool checkInvariant();
285 
286  typedef mpl::list<
287  sc::custom_reaction<Run>,
288  sc::custom_reaction<File> > reactions;
289 
290  sc::result react(Run const& run);
291  sc::result react(File const& file);
292  };
293 
294  class ContinueRun1 : public sc::state<ContinueRun1, HandleRuns>
295  {
296  public:
297  ContinueRun1(my_context ctx);
298  ~ContinueRun1();
299  bool checkInvariant();
300 
301  typedef mpl::list<
302  sc::custom_reaction<Run>,
303  sc::custom_reaction<File>,
304  sc::transition<Lumi, HandleLumis> > reactions;
305 
306  sc::result react(Run const& run);
307  sc::result react(File const& file);
308  private:
310  };
311 
312  class FirstLumi;
313 
314  class HandleLumis : public sc::state<HandleLumis, HandleRuns, FirstLumi>
315  {
316  public:
317  class LumiID {
318  public:
321  edm::RunNumber_t run() const { return run_; }
323 
324  private:
328  };
329  HandleLumis(my_context ctx);
330  void exit();
331  ~HandleLumis();
332  bool checkInvariant();
333 
334  LumiID const& currentLumi() const;
335  bool currentLumiEmpty() const;
336  void setupCurrentLumi();
337  void finalizeLumi(bool cleaningUpAfterException);
338  void markLumiNonEmpty();
339 
340  typedef sc::transition<Run, NewRun, HandleRuns, &HandleRuns::finalizeRun> reactions;
341 
342  private:
348  };
349 
350  class HandleEvent;
351  class AnotherLumi;
352 
353  class FirstLumi : public sc::state<FirstLumi, HandleLumis>
354  {
355  public:
356  FirstLumi(my_context ctx);
357  ~FirstLumi();
358  bool checkInvariant();
359 
360  typedef mpl::list<
361  sc::transition<Event, HandleEvent>,
362  sc::custom_reaction<Lumi>,
363  sc::custom_reaction<File> > reactions;
364 
365  sc::result react(Lumi const& lumi);
366  sc::result react(File const& file);
367  };
368 
369  class AnotherLumi : public sc::state<AnotherLumi, HandleLumis>
370  {
371  public:
372  AnotherLumi(my_context ctx);
373  ~AnotherLumi();
374  bool checkInvariant();
375 
376  typedef mpl::list<
377  sc::transition<Event, HandleEvent>,
378  sc::custom_reaction<Lumi>,
379  sc::custom_reaction<File> > reactions;
380 
381  sc::result react(Lumi const& lumi);
382  sc::result react(File const& file);
383  };
384 
385  class HandleEvent : public sc::state<HandleEvent, HandleLumis>
386  {
387  public:
388  HandleEvent(my_context ctx);
389  ~HandleEvent();
390  bool checkInvariant();
391 
392  typedef mpl::list<
393  sc::transition<Event, HandleEvent>,
394  sc::transition<Lumi, AnotherLumi>,
395  sc::custom_reaction<File> > reactions;
396 
397  sc::result react(File const& file);
398  void readAndProcessEvent();
399  void markNonEmpty();
400  private:
402  };
403 
404  class HandleNewInputFile3 : public sc::state<HandleNewInputFile3, HandleLumis>
405  {
406  public:
407  HandleNewInputFile3(my_context ctx);
409  bool checkInvariant();
410 
411  typedef mpl::list<
412  sc::custom_reaction<Run>,
413  sc::custom_reaction<File> > reactions;
414 
415  sc::result react(Run const& run);
416  sc::result react(File const& file);
417  };
418 
419  class ContinueRun2 : public sc::state<ContinueRun2, HandleLumis>
420  {
421  public:
422  ContinueRun2(my_context ctx);
423  ~ContinueRun2();
424  bool checkInvariant();
425 
426  typedef mpl::list<
427  sc::custom_reaction<Run>,
428  sc::custom_reaction<Lumi>,
429  sc::custom_reaction<File> > reactions;
430 
431  sc::result react(Run const& run);
432  sc::result react(Lumi const& lumi);
433  sc::result react(File const& file);
434  private:
436  };
437 
438  class ContinueLumi : public sc::state<ContinueLumi, HandleLumis>
439  {
440  public:
441  ContinueLumi(my_context ctx);
442  ~ContinueLumi();
443  bool checkInvariant();
444 
445  typedef mpl::list<
446  sc::transition<Event, HandleEvent>,
447  sc::custom_reaction<Lumi>,
448  sc::custom_reaction<File> > reactions;
449 
450  sc::result react(Lumi const& lumi);
451  sc::result react(File const& file);
452  private:
454  };
455 }
456 
457 #endif
mpl::list< sc::transition< Event, HandleEvent >, sc::custom_reaction< Lumi >, sc::custom_reaction< File > > reactions
Definition: EPStates.h:379
HandleEvent(my_context ctx)
Definition: EPStates.cc:522
sc::result react(File const &file)
Definition: EPStates.cc:130
edm::IEventProcessor & ep_
Definition: EPStates.h:343
FirstFile(my_context ctx)
Definition: EPStates.cc:122
edm::IEventProcessor * ep_
Definition: EPStates.h:109
sc::transition< Run, NewRun, HandleRuns,&HandleRuns::finalizeRun > reactions
Definition: EPStates.h:340
void endRun(Run const &run, bool cleaningUpAfterException)
Definition: EPStates.cc:237
mpl::list< sc::transition< Run, HandleRuns >, sc::custom_reaction< File > > reactions
Definition: EPStates.h:221
HandleFiles(my_context ctx)
Definition: EPStates.cc:55
Starting(my_context ctx)
Definition: EPStates.cc:51
HandleLumis(my_context ctx)
Definition: EPStates.cc:365
HandleNewInputFile3(my_context ctx)
Definition: EPStates.cc:563
edm::IEventProcessor & ep_
Definition: EPStates.h:179
bool currentLumiEmpty() const
Definition: EPStates.cc:406
edm::IEventProcessor & ep_
Definition: EPStates.h:453
FileMode fileMode() const
Definition: EPStates.cc:34
tuple lumi
Definition: fjr2json.py:35
mpl::list< sc::transition< Lumi, HandleLumis >, sc::custom_reaction< Run >, sc::custom_reaction< File > > reactions
Definition: EPStates.h:271
edm::ProcessHistoryID const & processHistoryID() const
Definition: EPStates.h:320
edm::LuminosityBlockNumber_t lumi() const
Definition: EPStates.h:322
edm::ProcessHistoryID processHistoryID_
Definition: EPStates.h:62
edm::IEventProcessor & ep_
Definition: EPStates.h:435
sc::result react(File const &file)
Definition: EPStates.cc:543
sc::result react(File const &file)
Definition: EPStates.cc:168
sc::result react(Lumi const &lumi)
Definition: EPStates.cc:663
ContinueLumi(my_context ctx)
Definition: EPStates.cc:644
void closeFiles(bool cleaningUpAfterException)
Definition: EPStates.cc:78
edm::IEventProcessor & ep_
Definition: EPStates.h:154
mpl::list< sc::custom_reaction< Run >, sc::custom_reaction< File >, sc::transition< Lumi, HandleLumis > > reactions
Definition: EPStates.h:304
sc::result react(Run const &run)
Definition: EPStates.cc:308
unsigned int LuminosityBlockNumber_t
edm::LuminosityBlockNumber_t id_
Definition: EPStates.h:71
mpl::list< sc::transition< Restart, Starting, Machine,&Machine::rewindAndPrepareForNextLoop >, sc::custom_reaction< Stop > > reactions
Definition: EPStates.h:165
edm::IEventProcessor & ep_
Definition: EPStates.h:309
void startingNewLoop(File const &file)
Definition: EPStates.cc:37
mpl::list< sc::custom_reaction< Run >, sc::custom_reaction< File > > reactions
Definition: EPStates.h:413
FirstLumi(my_context ctx)
Definition: EPStates.cc:453
bool operator!=(Run const &rh) const
Definition: EPStates.h:56
EmptyRunLumiMode emptyRunLumiMode_
Definition: EPStates.h:111
edm::LuminosityBlockNumber_t id() const
Definition: EPStates.h:69
edm::IEventProcessor & ep() const
Definition: EPStates.cc:33
bool beginRunCalled() const
Definition: EPStates.cc:214
HandleRuns(my_context ctx)
Definition: EPStates.cc:188
edm::IEventProcessor & ep_
Definition: EPStates.h:253
EndingLoop(my_context ctx)
Definition: EPStates.cc:97
ContinueRun2(my_context ctx)
Definition: EPStates.cc:598
tuple result
Definition: query.py:137
LumiID const & currentLumi() const
Definition: EPStates.cc:404
HandleNewInputFile1(my_context ctx)
Definition: EPStates.cc:145
mpl::list< sc::transition< Event, HandleEvent >, sc::custom_reaction< Lumi >, sc::custom_reaction< File > > reactions
Definition: EPStates.h:363
bool operator==(Run const &rh) const
Definition: EPStates.h:51
edm::IEventProcessor & ep_
Definition: EPStates.h:229
sc::transition< Stop, EndingLoop > reactions
Definition: EPStates.h:177
sc::result react(Run const &run)
Definition: EPStates.cc:342
Run const & currentRun() const
Definition: EPStates.cc:215
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:448
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:148
ContinueRun1(my_context ctx)
Definition: EPStates.cc:326
edm::IEventProcessor & ep_
Definition: EPStates.h:401
edm::IEventProcessor & ep_
Definition: EPStates.h:197
AnotherLumi(my_context ctx)
Definition: EPStates.cc:487
sc::result react(Lumi const &lumi)
Definition: EPStates.cc:507
void finalizeLumi(bool cleaningUpAfterException)
Definition: EPStates.cc:425
mpl::list< sc::transition< Event, HandleEvent >, sc::transition< Lumi, AnotherLumi >, sc::custom_reaction< File > > reactions
Definition: EPStates.h:395
void finalizeRun(Run const &)
Definition: EPStates.cc:245
NewInputAndOutputFiles(my_context ctx)
Definition: EPStates.cc:160
Machine(edm::IEventProcessor *ep, FileMode fileMode, EmptyRunLumiMode emptyRunLumiMode)
Definition: EPStates.cc:25
void rewindAndPrepareForNextLoop(Restart const &restart)
Definition: EPStates.cc:46
NewRun(my_context ctx)
Definition: EPStates.cc:265
sc::result react(Run const &run)
Definition: EPStates.cc:581
Run(edm::ProcessHistoryID const &phid, edm::RunNumber_t runNumber)
Definition: EPStates.cc:18
sc::result react(Lumi const &lumi)
Definition: EPStates.cc:472
edm::RunNumber_t runNumber_
Definition: EPStates.h:63
mpl::list< sc::custom_reaction< Run >, sc::custom_reaction< File > > reactions
Definition: EPStates.h:288
edm::RunNumber_t run() const
Definition: EPStates.h:321
sc::result react(Stop const &)
Definition: EPStates.cc:106
HandleNewInputFile2(my_context ctx)
Definition: EPStates.cc:293
mpl::list< sc::custom_reaction< Run >, sc::custom_reaction< Lumi >, sc::custom_reaction< File > > reactions
Definition: EPStates.h:429
mpl::list< sc::transition< Run, HandleRuns >, sc::custom_reaction< File > > reactions
Definition: EPStates.h:208
edm::IEventProcessor & ep_
Definition: EPStates.h:169
edm::RunNumber_t runNumber() const
Definition: EPStates.h:49
void beginRun(Run const &run)
Definition: EPStates.cc:229
mpl::list< sc::transition< Run, HandleRuns >, sc::custom_reaction< File > > reactions
Definition: EPStates.h:192
edm::LuminosityBlockNumber_t lumi_
Definition: EPStates.h:327
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:130
Lumi(edm::LuminosityBlockNumber_t id)
Definition: EPStates.cc:23
edm::ProcessHistoryID const & processHistoryID() const
Definition: EPStates.h:48
Error(my_context ctx)
Definition: EPStates.cc:110
unsigned int RunNumber_t
sc::result react(Run const &run)
Definition: EPStates.cc:278
LumiID(edm::ProcessHistoryID const &phid, edm::RunNumber_t run, edm::LuminosityBlockNumber_t lumi)
Definition: EPStates.cc:359
sc::result react(Run const &run)
Definition: EPStates.cc:617
sc::transition< File, NewInputAndOutputFiles > reactions
Definition: EPStates.h:241
EmptyRunLumiMode emptyRunLumiMode() const
Definition: EPStates.cc:35
edm::ProcessHistoryID processHistoryID_
Definition: EPStates.h:325
sc::result react(File const &file)
Definition: EPStates.cc:152
bool runException() 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 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