LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
Schedule.h
Go to the documentation of this file.
1 #ifndef art_Framework_Core_Schedule_h
2 #define art_Framework_Core_Schedule_h
3 // vim: set sw=2:
4 
5 // ======================================================================
6 // Schedule
7 //
8 // A schedule is a sequence of trigger paths. After construction, events
9 // can be fed to the object and passed through all the modules in the
10 // schedule. All accounting about processing of events by modules and
11 // paths is contained here or in object held by containment.
12 //
13 // The trigger results producer is generated and managed here. This
14 // class also manages calls to endjob and beginjob.
15 //
16 // A TriggerResults object will always be inserted into the event for
17 // any schedule. The producer of the TriggerResults EDProduct is always
18 // the last module in the trigger path. The TriggerResultInserter is
19 // given a fixed label of "TriggerResults".
20 //
21 // Processing of an event happens by pushing the event through the
22 // Paths. The scheduler performs the reset() on each of the workers
23 // independent of the Path objects.
24 // ======================================================================
25 
41 #include "cetlib/container_algorithms.h"
42 #include "cetlib/exempt_ptr.h"
43 #include "cetlib/trim.h"
44 #include "fhiclcpp/ParameterSet.h"
46 
47 #include <functional>
48 #include <map>
49 #include <memory>
50 #include <set>
51 #include <string>
52 #include <utility>
53 #include <vector>
54 
55 namespace art {
56 
57  class ActivityRegistry;
58  class MasterProductRegistry;
59  class TriggerNamesService;
60  class Schedule;
61 
62  class Schedule {
63  public:
65  PathManager&,
66  fhicl::ParameterSet const&,
67  TriggerNamesService const&,
70  ActionTable&,
72 
73  template <typename T>
74  void process(typename T::MyPrincipal&);
75 
76  void beginJob();
77  void endJob();
78 
79  // Call respondToOpenInputFile() on all Modules
80  void respondToOpenInputFile(FileBlock const&);
81 
82  // Call respondToCloseInputFile() on all Modules
84 
85  // Call respondToOpenOutputFiles() on all Modules
87 
88  // Call respondToCloseOutputFiles() on all Modules
90 
91  private:
92  // Private initialization helpers.
95  ProductDescriptions& productsToProduce,
96  ActivityRegistry& areg);
97 
98  template <typename T>
99  bool runTriggerPaths_(typename T::MyPrincipal&);
100 
101  template <class F>
102  void doForAllWorkers_(F functor);
103 
104  template <class F>
105  void doForAllEnabledPaths_(F functor);
106 
107  // Data members.
111  std::string processName_;
113  std::vector<unsigned char> pathsEnabled_;
114  std::unique_ptr<Worker> results_inserter_{nullptr};
115  };
116 
117  template <typename T>
118  void
119  Schedule::process(typename T::MyPrincipal& principal)
120  {
121  doForAllWorkers_([](auto w) { w->reset(); });
123  if (T::level == Level::Event) {
125  }
126  try {
127  if (runTriggerPaths_<T>(principal) && T::level == Level::Event) {
129  }
130  if (results_inserter_.get()) {
131  results_inserter_->doWork<T>(principal, 0);
132  }
133  }
134  catch (cet::exception& e) {
135  actions::ActionCodes const action = {T::level == Level::Event ?
136  act_table_->find(e.root_cause()) :
138  assert(action != actions::IgnoreCompletely);
139  assert(action != actions::FailPath);
140  assert(action != actions::FailModule);
141  if (action == actions::SkipEvent) {
142  mf::LogWarning(e.category())
143  << "an exception occurred and all paths for "
144  "the event are being skipped: \n"
145  << cet::trim_right_copy(e.what(), " \n");
146  } else {
147  throw;
148  }
149  }
150  }
151 
152  template <typename T>
153  inline bool
154  Schedule::runTriggerPaths_(typename T::MyPrincipal& ep)
155  {
156  doForAllEnabledPaths_([&ep](auto p) { p->template process<T>(ep); });
158  }
159 
160  template <class F>
161  void
163  {
164  for (auto const& val : triggerPathsInfo_.workers()) {
165  functor(val.second.get());
166  }
167  if (results_inserter_) {
168  // Do this last -- not part of main list.
169  functor(results_inserter_.get());
170  }
171  }
172 
173  template <class F>
174  void
176  {
177  size_t path_index = 0;
178  for (auto const& path : triggerPathsInfo_.pathPtrs()) {
179  if (pathsEnabled_[path_index++]) {
180  functor(path.get());
181  }
182  }
183  }
184 
185 } // namespace art
186 
187 // Local Variables:
188 // mode: c++
189 // End:
190 #endif /* art_Framework_Core_Schedule_h */
void endJob()
Definition: Schedule.cc:51
void process(typename T::MyPrincipal &)
Definition: Schedule.h:119
std::vector< unsigned char > pathsEnabled_
Definition: Schedule.h:113
void respondToCloseOutputFiles(FileBlock const &)
Definition: Schedule.cc:98
Schedule(ScheduleID, PathManager &, fhicl::ParameterSet const &, TriggerNamesService const &, MasterProductRegistry &, ProductDescriptions &, ActionTable &, ActivityRegistry &)
Definition: Schedule.cc:29
void respondToCloseInputFile(FileBlock const &)
Definition: Schedule.cc:86
bool runTriggerPaths_(typename T::MyPrincipal &)
Definition: Schedule.h:154
actions::ActionCodes find(std::string const &category) const
Definition: Actions.cc:87
ScheduleID const sID_
Definition: Schedule.h:108
void doForAllEnabledPaths_(F functor)
Definition: Schedule.h:175
void addPass()
Definition: PathsInfo.h:75
std::vector< BranchDescription > ProductDescriptions
void beginJob()
Definition: Schedule.cc:104
WorkerMap const & workers() const
Definition: PathsInfo.h:81
void addEvent()
Definition: PathsInfo.h:69
void respondToOpenOutputFiles(FileBlock const &)
Definition: Schedule.cc:92
std::string processName_
Definition: Schedule.h:111
PathsInfo & triggerPathsInfo_
Definition: Schedule.h:112
std::unique_ptr< Worker > results_inserter_
Definition: Schedule.h:114
HLTGlobalStatus & pathResults()
Definition: PathsInfo.h:63
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
bool accept() const
HLT enums.
fhicl::ParameterSet process_pset_
Definition: Schedule.h:109
void doForAllWorkers_(F functor)
Definition: Schedule.h:162
void makeTriggerResultsInserter_(fhicl::ParameterSet const &trig_pset, MasterProductRegistry &mpr, ProductDescriptions &productsToProduce, ActivityRegistry &areg)
Definition: Schedule.cc:110
Float_t e
Definition: plot.C:34
void respondToOpenInputFile(FileBlock const &)
Definition: Schedule.cc:80
Float_t w
Definition: plot.C:23
ActionTable * act_table_
Definition: Schedule.h:110
PathPtrs const & pathPtrs() const
Definition: PathsInfo.h:87
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33