LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
EventProcessor.h
Go to the documentation of this file.
1 #ifndef art_Framework_EventProcessor_EventProcessor_h
2 #define art_Framework_EventProcessor_EventProcessor_h
3 
4 // ======================================================================
5 //
6 // EventProcessor - This defines the 'framework application' object. It
7 // is configured in the user's main() function, and is set running.
8 //
9 // ======================================================================
10 
30 #include "cetlib/cpu_timer.h"
31 #include "cetlib/trim.h"
32 #include "cetlib_except/exception.h"
33 #include "fhiclcpp/ParameterSet.h"
35 
36 #include "tbb/task_scheduler_init.h"
37 
38 #include <memory>
39 #include <string>
40 #include <vector>
41 
42 namespace art {
43  class EventProcessor;
44 }
45 
47 public:
48  // Status codes:
49  // 0 successful completion
50  // 3 signal received
51  // values are for historical reasons.
52  enum Status { epSuccess = 0, epSignal = 3 };
53 
54  // Eventually, we might replace StatusCode with a class. This
55  // class should have an automatic conversion to 'int'.
56 
57  using StatusCode = Status;
58 
59  EventProcessor(EventProcessor const&) = delete;
60  EventProcessor& operator=(EventProcessor const&) = delete;
61 
62  explicit EventProcessor(fhicl::ParameterSet const& pset);
64 
65  //------------------------------------------------------------------
66  // The function "runToCompletion" will run until the job is "complete",
67  // which means:
68  // 1 - no more input data
69  // 2 - input maxEvents parameter limit reached
70  // 3 - output maxEvents parameter limit reached
71  // 4 - input maxSubRuns parameter limit reached
72  //
73  // The return values from runToCompletion are as follows:
74  // epSignal - processing terminated early, SIGUSR2 encountered
75  // epSuccess - all other cases
76  //
78 
79 private:
80  // Event-loop infrastructure
81  template <Level L>
82  bool levelsToProcess();
83 
84  template <Level L>
85  std::enable_if_t<is_above_most_deeply_nested_level(L)> begin();
86  template <Level L>
87  void process();
88  template <Level L>
89  void finalize();
90  template <Level L>
91  void
93  {}
94  template <Level L>
95  void
97  {}
98 
99  void markLevelAsProcessed();
101 
102  // Level-specific member functions
103  void beginJob();
104  void endJob();
105 
106  void openInputFile();
107  void openSomeOutputFiles();
108  void openAllOutputFiles();
109 
110  void closeInputFile();
111  void closeSomeOutputFiles();
112  void closeAllOutputFiles();
113  void closeAllFiles();
114 
115  void respondToOpenInputFile();
119 
120  void readRun();
121  void beginRun();
124  void endRun();
125  void writeRun();
126 
127  void readSubRun();
128  void beginSubRun();
131  void endSubRun();
132  void writeSubRun();
133 
134  void readEvent();
135  void processEvent();
136  void writeEvent();
137 
138  bool shouldWeStop() const;
139 
141 
143  std::vector<Level> activeLevels_{highest_level()};
145  cet::cpu_timer timer_{};
146 
147  bool beginRunCalled_{false}; // Should be stack variable local to run loop
149  false}; // Should be stack variable local to subrun loop
150 
153 
155  ActivityRegistry& areg,
156  ServiceToken& token);
157  void initSchedules_(fhicl::ParameterSet const& pset);
159 
160  template <typename T>
161  void process_(typename T::MyPrincipal& p);
162 
164  void servicesDeactivate_();
165  void terminateAbnormally_();
166 
167  //------------------------------------------------------------------
168  //
169  // Data members below.
170  // Are all these data members really needed? Some of them are used
171  // only during construction, and never again. If they aren't
172  // really needed, we should remove them.
173 
181  tbb::task_scheduler_init tbbManager_{tbb::task_scheduler_init::deferred};
182  std::unique_ptr<ServiceRegistry::Operate> servicesSentry_{};
183  PathManager pathManager_; // Must outlive schedules.
185  std::unique_ptr<InputSource> input_{nullptr};
186  std::unique_ptr<Schedule> schedule_{nullptr};
187  std::unique_ptr<EndPathExecutor> endPathExecutor_{nullptr};
188  std::unique_ptr<FileBlock> fb_{nullptr};
189 
190  std::unique_ptr<RunPrincipal> runPrincipal_{nullptr};
191  std::unique_ptr<SubRunPrincipal> subRunPrincipal_{nullptr};
192  std::unique_ptr<EventPrincipal> eventPrincipal_{nullptr};
194  bool shouldWeStop_{false};
195  bool const handleEmptyRuns_;
197 
198 }; // EventProcessor
199 
201 template <typename T>
202 void
203 art::EventProcessor::process_(typename T::MyPrincipal& p) try {
204  T::preScheduleSignal(actReg_, p);
205  schedule_->process<T>(p);
206  endPathExecutor_->process<T>(p);
207  T::postScheduleSignal(actReg_, p);
208 }
209 catch (cet::exception const& ex) {
210  actions::ActionCodes const action{T::level == Level::Event ?
211  act_table_.find(ex.root_cause()) :
213  switch (action) {
215  mf::LogWarning(ex.category())
216  << "exception being ignored for current event:\n"
217  << cet::trim_right_copy(ex.what(), " \n");
218  break;
219  }
220  default: {
221  throw art::Exception{
223  "EventProcessor: an exception occurred during current event processing",
224  ex};
225  }
226  }
227 }
228 catch (...) {
229  mf::LogError("PassingThrough")
230  << "an exception occurred during current event processing\n";
231  throw;
232 }
233 
234 #endif /* art_Framework_EventProcessor_EventProcessor_h */
235 
236 // Local Variables:
237 // mode: c++
238 // End:
StatusCode runToCompletion()
std::unique_ptr< EndPathExecutor > endPathExecutor_
actions::ActionCodes find(std::string const &category) const
Definition: Actions.cc:87
bool const handleEmptyRuns_
std::unique_ptr< Schedule > schedule_
ProducingServiceSignals psSignals_
std::unique_ptr< InputSource > input_
Level
Definition: Level.h:12
bool const handleEmptySubRuns_
std::vector< BranchDescription > ProductDescriptions
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
MasterProductRegistry preg_
EventProcessor & operator=(EventProcessor const &)=delete
void setOutputFileStatus(OutputFileStatus)
std::enable_if_t< is_above_most_deeply_nested_level(L)> begin()
void recordOutputModuleClosureRequests()
void servicesActivate_(ServiceToken st)
ServiceToken serviceToken_
std::unique_ptr< SubRunPrincipal > subRunPrincipal_
cet::cpu_timer timer_
std::unique_ptr< ServiceRegistry::Operate > servicesSentry_
OutputFileStatus
void finalizeContainingLevels()
ServiceDirector serviceDirector_
void process_(typename T::MyPrincipal &p)
PathManager pathManager_
MFStatusUpdater mfStatusUpdater_
tbb::task_scheduler_init tbbManager_
void initSchedules_(fhicl::ParameterSet const &pset)
static ProductTables invalid()
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
std::unique_ptr< RunPrincipal > runPrincipal_
ProductDescriptions productsToProduce_
std::unique_ptr< FileBlock > fb_
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
ProductTables producedProducts_
ActionTable act_table_
bool shouldWeStop() const
HLT enums.
ActivityRegistry actReg_
constexpr auto highest_level() noexcept
Definition: Level.h:39
std::unique_ptr< EventPrincipal > eventPrincipal_
std::vector< Level > activeLevels_
void beginSubRunIfNotDoneAlready()
detail::ExceptionCollector ec_
ServiceDirector initServices_(fhicl::ParameterSet const &top_pset, ActivityRegistry &areg, ServiceToken &token)
static auto createInvalid()
Definition: ServiceToken.h:37
EventProcessor(EventProcessor const &)=delete
void setSubRunAuxiliaryRangeSetID()
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33