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