LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
EndPathExecutor.h
Go to the documentation of this file.
1 #ifndef art_Framework_Core_EndPathExecutor_h
2 #define art_Framework_Core_EndPathExecutor_h
3 // ======================================================================
4 // EndPathExecutor
5 //
6 // Class to handle the execution of the end path. Invoked in all the
7 // right places by the event processor.
8 //
9 // The RangeSetHandlers manage the RangeSets that are to be assigned
10 // to (a) the (Sub)RunAuxiliaries and (b) the (Sub)Run products
11 // produced in the current process. Since all (Sub)Run
12 // products/auxiliaries produced in the current process are written to
13 // all output modules during write(Sub)Run, there is only one relevant
14 // RangeSet for the (Sub)Run at any given time. RangeSets
15 // corresponding to multiple (Sub)Run fragments are aggregated on
16 // input.
17 // ======================================================================
30 #include "cetlib/trim.h"
32 
33 #include <memory>
34 #include <vector>
35 
36 namespace art {
37  class EndPathExecutor;
38  class MasterProductRegistry;
39 }
40 
42 public:
44  ActionTable& actions,
45  ActivityRegistry& areg,
47 
48  template <typename T>
49  void process(typename T::MyPrincipal& principal);
50 
51  void beginJob();
52  void endJob();
53 
54  void writeEvent(EventPrincipal& ep);
55  void writeSubRun(SubRunPrincipal& srp);
56  void writeRun(RunPrincipal& rp);
57 
58  void seedRunRangeSet(std::unique_ptr<RangeSetHandler>);
59  void seedSubRunRangeSet(std::unique_ptr<RangeSetHandler>);
60 
63 
64  void closeAllOutputFiles();
66 
67  void closeSomeOutputFiles();
68  void openSomeOutputFiles(FileBlock const& fb);
70 
71  void respondToOpenInputFile(FileBlock const& fb);
72  void respondToCloseInputFile(FileBlock const& fb);
73  void respondToOpenOutputFiles(FileBlock const& fb);
74  void respondToCloseOutputFiles(FileBlock const& fb);
75 
76  // Allow output files to close that need to
78  bool outputsToOpen() const;
79  bool outputsToClose() const;
80  bool someOutputsOpen() const;
82 
83  // Return whether a module has reached its maximum count.
84  bool terminate() const;
85 
86  // Call selectProducts() on all OutputModules.
87  void selectProducts(ProductList const&);
88 
89 private:
90  using OutputWorkers = std::vector<OutputWorker*>;
91  using OutputWorkerSet = std::set<OutputWorker*>;
92 
93  void resetAll();
94 
95  template <typename T>
96  void runEndPaths(typename T::MyPrincipal&);
97 
98  template <class F>
99  void doForAllEnabledWorkers_(F f);
100  template <class F>
102 
109  std::vector<unsigned char> workersEnabled_;
110  std::vector<unsigned char> outputWorkersEnabled_;
112  std::unique_ptr<RangeSetHandler> runRangeSetHandler_{nullptr};
113  std::unique_ptr<RangeSetHandler> subRunRangeSetHandler_{nullptr};
114 };
115 
116 template <typename T>
117 void
118 art::EndPathExecutor::process(typename T::MyPrincipal& ep)
119 {
120  this->resetAll();
121 
122  if (T::level == Level::Event) {
124  }
125  try {
126  if (!endPathInfo_.pathPtrs().empty()) {
127  endPathInfo_.pathPtrs().front()->process<T>(ep);
128  }
129  }
130  catch (cet::exception& ex) {
131  actions::ActionCodes const action{T::level == Level::Event ?
132  act_table_->find(ex.root_cause()) :
134  switch (action) {
136  mf::LogWarning(ex.category())
137  << "exception being ignored for current event:\n"
138  << cet::trim_right_copy(ex.what(), " \n");
139  break;
140  }
141  default: {
142  throw art::Exception(errors::EventProcessorFailure, "EndPathExecutor:")
143  << "an exception occurred during current event processing\n"
144  << ex;
145  }
146  }
147  }
148  catch (...) {
149  mf::LogError("PassingThrough")
150  << "an exception occurred during current event processing\n";
151  throw;
152  }
154 }
155 
156 template <class F>
157 void
159 {
160  size_t index{0};
161  for (auto const& val : endPathInfo_.workers()) {
162  if (workersEnabled_[index++]) {
163  fcn(val.second.get());
164  }
165  }
166 }
167 
168 template <class F>
169 void
171 {
172  size_t index{0};
173  for (auto ow : outputWorkers_) {
174  if (outputWorkersEnabled_[index++]) {
175  fcn(ow);
176  }
177  }
178 }
179 
180  // Local Variables:
181  // mode: c++
182  // End:
183 
184 #endif /* art_Framework_Core_EndPathExecutor_h */
std::vector< unsigned char > workersEnabled_
void runEndPaths(typename T::MyPrincipal &)
bool outputsToClose() const
void writeEvent(EventPrincipal &ep)
ActionTable * act_table_
bool terminate() const
actions::ActionCodes find(std::string const &category) const
Definition: Actions.cc:87
EndPathExecutor(PathManager &pm, ActionTable &actions, ActivityRegistry &areg, MasterProductRegistry &mpr)
void doForAllEnabledWorkers_(F f)
std::map< BranchKey, BranchDescription > ProductList
Definition: ProductList.h:15
void writeSubRun(SubRunPrincipal &srp)
void addPass()
Definition: PathsInfo.h:75
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
void respondToOpenInputFile(FileBlock const &fb)
void respondToOpenOutputFiles(FileBlock const &fb)
void setAuxiliaryRangeSetID(SubRunPrincipal &srp)
void seedSubRunRangeSet(std::unique_ptr< RangeSetHandler >)
TFile f
Definition: plotHisto.C:6
void process(typename T::MyPrincipal &principal)
void recordOutputClosureRequests(Granularity)
void openAllOutputFiles(FileBlock &fb)
void respondToCloseOutputFiles(FileBlock const &fb)
void openSomeOutputFiles(FileBlock const &fb)
OutputFileStatus
WorkerMap const & workers() const
Definition: PathsInfo.h:81
void setOutputFileStatus(OutputFileStatus)
TFile fb("Li6.root")
bool someOutputsOpen() const
std::set< OutputWorker * > OutputWorkerSet
OutputWorkers outputWorkers_
std::unique_ptr< RangeSetHandler > subRunRangeSetHandler_
void writeRun(RunPrincipal &rp)
bool outputsToOpen() const
OutputWorkerSet outputWorkersToOpen_
void addEvent()
Definition: PathsInfo.h:69
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
std::vector< OutputWorker * > OutputWorkers
void selectProducts(ProductList const &)
void seedRunRangeSet(std::unique_ptr< RangeSetHandler >)
void respondToCloseInputFile(FileBlock const &fb)
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
HLT enums.
ActivityRegistry & actReg_
std::vector< unsigned char > outputWorkersEnabled_
void doForAllEnabledOutputWorkers_(F f)
OutputFileStatus fileStatus_
OutputWorkerSet outputWorkersToClose_
std::unique_ptr< RangeSetHandler > runRangeSetHandler_
PathPtrs const & pathPtrs() const
Definition: PathsInfo.h:87
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33