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 
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  bool const parentageEnabled,
73  bool const rangesEnabled);
74 
75  template <typename T>
76  void process(typename T::MyPrincipal&);
77 
78  void beginJob();
79  void endJob();
80 
81  // Call respondToOpenInputFile() on all Modules
82  void respondToOpenInputFile(FileBlock const&);
83 
84  // Call respondToCloseInputFile() on all Modules
86 
87  // Call respondToOpenOutputFiles() on all Modules
89 
90  // Call respondToCloseOutputFiles() on all Modules
92 
93  private:
94  // Private initialization helpers.
97  ProductDescriptions& productsToProduce,
98  ActivityRegistry& areg);
99 
100  template <typename T>
101  bool runTriggerPaths_(typename T::MyPrincipal&);
102 
103  template <class F>
104  void doForAllWorkers_(F functor);
105 
106  template <class F>
107  void doForAllEnabledPaths_(F functor);
108 
109  // Data members.
115  std::vector<unsigned char> pathsEnabled_;
116  std::unique_ptr<Worker> results_inserter_{nullptr};
117  bool const parentageEnabled_{true};
118  bool const rangesEnabled_{true};
119  };
120 
121  template <typename T>
122  void
123  Schedule::process(typename T::MyPrincipal& principal)
124  {
125  doForAllWorkers_([](auto w) { w->reset(); });
127  if (T::level == Level::Event) {
129  }
130  try {
131  if (runTriggerPaths_<T>(principal) && T::level == Level::Event) {
133  }
134  if (results_inserter_.get()) {
135  results_inserter_->doWork<T>(principal, 0);
136  }
137  }
138  catch (cet::exception& e) {
139  actions::ActionCodes const action = {T::level == Level::Event ?
140  act_table_->find(e.root_cause()) :
143  assert(action != actions::FailPath);
144  assert(action != actions::FailModule);
145  if (action == actions::SkipEvent) {
146  mf::LogWarning(e.category())
147  << "an exception occurred and all paths for "
148  "the event are being skipped: \n"
149  << cet::trim_right_copy(e.what(), " \n");
150  } else {
151  throw;
152  }
153  }
154  }
155 
156  template <typename T>
157  inline bool
158  Schedule::runTriggerPaths_(typename T::MyPrincipal& ep)
159  {
160  doForAllEnabledPaths_([&ep](auto p) { p->template process<T>(ep); });
162  }
163 
164  template <class F>
165  void
167  {
168  for (auto const& val : triggerPathsInfo_.workers()) {
169  functor(val.second.get());
170  }
171  if (results_inserter_) {
172  // Do this last -- not part of main list.
173  functor(results_inserter_.get());
174  }
175  }
176 
177  template <class F>
178  void
180  {
181  size_t path_index = 0;
182  for (auto const& path : triggerPathsInfo_.pathPtrs()) {
183  if (pathsEnabled_[path_index++]) {
184  functor(path.get());
185  }
186  }
187  }
188 
189 } // namespace art
190 
191 // Local Variables:
192 // mode: c++
193 // End:
194 #endif /* art_Framework_Core_Schedule_h */
#define F(x, y, z)
void process(typename T::MyPrincipal &)
Definition: Schedule.h:123
std::vector< unsigned char > pathsEnabled_
Definition: Schedule.h:115
void respondToCloseOutputFiles(FileBlock const &)
void respondToCloseInputFile(FileBlock const &)
bool runTriggerPaths_(typename T::MyPrincipal &)
Definition: Schedule.h:158
actions::ActionCodes find(std::string const &category) const
ScheduleID const sID_
Definition: Schedule.h:110
void doForAllEnabledPaths_(F functor)
Definition: Schedule.h:179
const char * p
Definition: xmltok.h:285
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
void addPass()
Definition: PathsInfo.h:81
std::vector< BranchDescription > ProductDescriptions
std::string trim_right_copy(std::string source, std::string const &t=" ")
Definition: trim.h:54
WorkerMap const & workers() const
Definition: PathsInfo.h:87
void addEvent()
Definition: PathsInfo.h:75
void respondToOpenOutputFiles(FileBlock const &)
const std::string path
Definition: plot_BEN.C:43
std::string processName_
Definition: Schedule.h:113
PathsInfo & triggerPathsInfo_
Definition: Schedule.h:114
std::unique_ptr< Worker > results_inserter_
Definition: Schedule.h:116
HLTGlobalStatus & pathResults()
Definition: PathsInfo.h:69
bool const rangesEnabled_
Definition: Schedule.h:118
bool const parentageEnabled_
Definition: Schedule.h:117
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
bool accept() const
assert(nhit_max >=nhit_nbins)
Service to store calibration data products (CDP) in the SQLite3 metadatabase of a file...
Definition: FillParentInfo.h:8
fhicl::ParameterSet process_pset_
Definition: Schedule.h:111
void doForAllWorkers_(F functor)
Definition: Schedule.h:166
void makeTriggerResultsInserter_(fhicl::ParameterSet const &trig_pset, MasterProductRegistry &mpr, ProductDescriptions &productsToProduce, ActivityRegistry &areg)
double T
Definition: Xdiff_gwt.C:5
Schedule(ScheduleID, PathManager &, fhicl::ParameterSet const &, TriggerNamesService const &, MasterProductRegistry &, ProductDescriptions &, ActionTable &, ActivityRegistry &, bool const parentageEnabled, bool const rangesEnabled)
Float_t e
Definition: plot.C:35
void respondToOpenInputFile(FileBlock const &)
Float_t w
Definition: plot.C:20
ActionTable * act_table_
Definition: Schedule.h:112
PathPtrs const & pathPtrs() const
Definition: PathsInfo.h:93
enum BeamMode string