CMS 3D CMS Logo

Path.h
Go to the documentation of this file.
1 #ifndef FWCore_Framework_Path_h
2 #define FWCore_Framework_Path_h
3 
4 /*
5  Author: Jim Kowalkowski 28-01-06
6 
7  An object of this type represents one path in a job configuration.
8  It holds the assigned bit position and the list of workers that are
9  an event must pass through when this parh is processed. The workers
10  are held in WorkerInPath wrappers so that per path execution statistics
11  can be kept for each worker.
12 */
13 
23 
24 #include <memory>
25 
26 #include <string>
27 #include <vector>
28 #include <map>
29 #include <exception>
30 #include <sstream>
31 
32 namespace edm {
33  class EventPrincipal;
34  class EventSetup;
35  class ModuleDescription;
36  class PathStatusInserter;
37  class RunPrincipal;
38  class LuminosityBlockPrincipal;
39  class EarlyDeleteHelper;
40  class StreamContext;
41  class StreamID;
42  class WaitingTask;
43 
44  class Path {
45  public:
47 
48  typedef std::vector<WorkerInPath> WorkersInPath;
50  typedef std::shared_ptr<HLTGlobalStatus> TrigResPtr;
51 
52  Path(int bitpos, std::string const& path_name,
53  WorkersInPath const& workers,
54  TrigResPtr trptr,
56  std::shared_ptr<ActivityRegistry> reg,
57  StreamContext const* streamContext,
58  std::atomic<bool>* stopProcessEvent,
59  PathContext::PathType pathType);
60 
61  Path(Path const&);
62 
63  template <typename T>
64  void processOneOccurrence(typename T::MyPrincipal const&, EventSetup const&,
65  StreamID const&, typename T::Context const*);
66 
67  template <typename T>
69  typename T::MyPrincipal const&,
70  EventSetup const&,
71  StreamID const&,
72  typename T::Context const*);
73 
75 
76  int bitPosition() const { return bitpos_; }
77  std::string const& name() const { return pathContext_.pathName(); }
78 
79  void clearCounters();
80 
81  int timesRun() const { return timesRun_; }
82  int timesPassed() const { return timesPassed_; }
83  int timesFailed() const { return timesFailed_; }
84  int timesExcept() const { return timesExcept_; }
85  //int abortWorker() const { return abortWorker_; }
86  State state() const { return state_; }
87 
88  size_type size() const { return workers_.size(); }
89  int timesVisited(size_type i) const { return workers_.at(i).timesVisited(); }
90  int timesPassed (size_type i) const { return workers_.at(i).timesPassed() ; }
91  int timesFailed (size_type i) const { return workers_.at(i).timesFailed() ; }
92  int timesExcept (size_type i) const { return workers_.at(i).timesExcept() ; }
93  Worker const* getWorker(size_type i) const { return workers_.at(i).getWorker(); }
94 
95  void setEarlyDeleteHelpers(std::map<const Worker*,EarlyDeleteHelper*> const&);
96 
97  void setPathStatusInserter(PathStatusInserter* pathStatusInserter,
98  Worker* pathStatusInserterWorker);
99 
100  private:
101 
102  // If you define this be careful about the pointer in the
103  // PlaceInPathContext object in the contained WorkerInPath objects.
104  Path const& operator=(Path const&) = delete; // stop default
105 
110  //int abortWorker_;
111  State state_;
112 
113  int bitpos_;
114  TrigResPtr trptr_;
115  std::shared_ptr<ActivityRegistry> actReg_; // We do not use propagate_const because the registry itself is mutable.
117 
118  WorkersInPath workers_;
119  std::vector<EarlyDeleteHelper*> earlyDeleteHelpers_;
120 
123  std::atomic<bool>* stopProcessingEvent_;
124 
127 
128  // Helper functions
129  // nwrwue = numWorkersRunWithoutUnhandledException (really!)
131  int nwrwue,
132  bool isEvent,
133  bool begin,
135  ModuleDescription const&,
136  std::string const& id);
137  static void exceptionContext(cms::Exception & ex,
138  bool isEvent,
139  bool begin,
141  ModuleDescription const&,
142  std::string const& id,
143  PathContext const&);
144  void recordStatus(int nwrwue, bool isEvent);
145  void updateCounters(bool succeed, bool isEvent);
146 
147  void finished(int iModuleIndex, bool iSucceeded, std::exception_ptr,
148  StreamContext const*,
149  EventPrincipal const& iEP,
150  EventSetup const& iES,
151  StreamID const& streamID);
152 
153  void handleEarlyFinish(EventPrincipal const&);
156 
157  //Handle asynchronous processing
158  void workerFinished(std::exception_ptr const* iException,
159  unsigned int iModuleIndex,
160  EventPrincipal const& iEP, EventSetup const& iES,
161  StreamID const& iID, StreamContext const* iContext);
162  void runNextWorkerAsync(unsigned int iNextModuleIndex,
163  EventPrincipal const&, EventSetup const&,
164  StreamID const&, StreamContext const*);
165 
166  };
167 
168  namespace {
169  template <typename T>
170  class PathSignalSentry {
171  public:
172  PathSignalSentry(ActivityRegistry *a,
173  int const& nwrwue,
174  hlt::HLTState const& state,
175  PathContext const* pathContext) :
176  a_(a), nwrwue_(nwrwue), state_(state), pathContext_(pathContext) {
177  if (a_) T::prePathSignal(a_, pathContext_);
178  }
179  ~PathSignalSentry() {
180  HLTPathStatus status(state_, nwrwue_);
181  if(a_) T::postPathSignal(a_, status, pathContext_);
182  }
183  private:
184  ActivityRegistry* a_; // We do not use propagate_const because the registry itself is mutable.
185  int const& nwrwue_;
186  hlt::HLTState const& state_;
187  PathContext const* pathContext_;
188  };
189  }
190 
191  template <typename T>
193  typename T::MyPrincipal const& p,
194  EventSetup const& es,
195  StreamID const& streamID,
196  typename T::Context const* context) {
197  for(auto& worker: workers_) {
198  worker.runWorkerAsync<T>(task,p,es,streamID,context);
199  }
200  }
201 
202  template <typename T>
203  void Path::processOneOccurrence(typename T::MyPrincipal const& ep, EventSetup const& es,
204  StreamID const& streamID, typename T::Context const* context) {
205 
206  int nwrwue = -1;
207  PathSignalSentry<T> signaler(actReg_.get(), nwrwue, state_, &pathContext_);
208 
209  if (T::isEvent_) {
210  ++timesRun_;
211  }
212  state_ = hlt::Ready;
213 
214  // nwrue = numWorkersRunWithoutUnhandledException
215  bool should_continue = true;
216  WorkersInPath::iterator i = workers_.begin(), end = workers_.end();
217 
218  auto earlyFinishSentry = make_sentry(this,[&i,end, &ep](Path*){
219  for(auto j=i; j!= end;++j) {
220  j->skipWorker(ep);
221  }
222  });
223  for (;
224  i != end && should_continue;
225  ++i) {
226  ++nwrwue;
227  try {
228  convertException::wrap([&]() {
229  should_continue = i->runWorker<T>(ep, es, streamID, context);
230  });
231  }
232  catch(cms::Exception& ex) {
233  // handleWorkerFailure may throw a new exception.
234  std::ostringstream ost;
235  ost << ep.id();
236  should_continue = handleWorkerFailure(ex, nwrwue, T::isEvent_, T::begin_, T::branchType_,
237  i->getWorker()->description(), ost.str());
238  //If we didn't rethrow, then we effectively skipped
239  i->skipWorker(ep);
240  }
241  }
242  if (not should_continue) {
243  handleEarlyFinish(ep);
244  }
245  updateCounters(should_continue, T::isEvent_);
246  recordStatus(nwrwue, T::isEvent_);
247  }
248 
249 }
250 
251 #endif
std::string const & pathName() const
Definition: PathContext.h:37
int timesRun() const
Definition: Path.h:81
std::unique_ptr< T, F > make_sentry(T *iObject, F iFunc)
NOTE: if iObject is null, then iFunc will not be called.
Definition: make_sentry.h:29
int bitPosition() const
Definition: Path.h:76
void recordStatus(int nwrwue, bool isEvent)
Definition: Path.cc:153
void handleEarlyFinish(EventPrincipal const &)
Definition: Path.cc:202
not [yet] run
Definition: HLTenums.h:18
roAction_t actions[nactions]
Definition: GenABIO.cc:187
int timesFailed(size_type i) const
Definition: Path.h:91
std::vector< EarlyDeleteHelper * > earlyDeleteHelpers_
Definition: Path.h:119
int timesFailed_
Definition: Path.h:108
std::vector< WorkerInPath > WorkersInPath
Definition: Path.h:48
hlt::HLTState State
Definition: Path.h:46
WorkersInPath::size_type size_type
Definition: Path.h:49
HLTState
status of a trigger path
Definition: HLTenums.h:18
int timesPassed(size_type i) const
Definition: Path.h:90
int timesExcept() const
Definition: Path.h:84
int timesExcept_
Definition: Path.h:109
void runNextWorkerAsync(unsigned int iNextModuleIndex, EventPrincipal const &, EventSetup const &, StreamID const &, StreamContext const *)
Definition: Path.cc:315
PathContext pathContext_
Definition: Path.h:121
size_type size() const
Definition: Path.h:88
WaitingTaskList waitingTasks_
Definition: Path.h:122
State state() const
Definition: Path.h:86
uint16_t size_type
BranchType
Definition: BranchType.h:11
void setPathStatusInserter(PathStatusInserter *pathStatusInserter, Worker *pathStatusInserterWorker)
Definition: Path.cc:195
std::shared_ptr< ActivityRegistry > actReg_
Definition: Path.h:115
TrigResPtr trptr_
Definition: Path.h:114
void workerFinished(std::exception_ptr const *iException, unsigned int iModuleIndex, EventPrincipal const &iEP, EventSetup const &iES, StreamID const &iID, StreamContext const *iContext)
Definition: Path.cc:231
std::shared_ptr< HLTGlobalStatus > TrigResPtr
Definition: Path.h:50
void processOneOccurrenceAsync(WaitingTask *, EventPrincipal const &, EventSetup const &, StreamID const &, StreamContext const *)
Definition: Path.cc:209
int bitpos_
Definition: Path.h:113
Definition: Path.h:44
int timesPassed() const
Definition: Path.h:82
#define end
Definition: vmac.h:37
void handleEarlyFinish(LuminosityBlockPrincipal const &)
Definition: Path.h:155
void handleEarlyFinish(RunPrincipal const &)
Definition: Path.h:154
WorkersInPath workers_
Definition: Path.h:118
static void exceptionContext(cms::Exception &ex, bool isEvent, bool begin, BranchType branchType, ModuleDescription const &, std::string const &id, PathContext const &)
Definition: Path.cc:118
void finished(int iModuleIndex, bool iSucceeded, std::exception_ptr, StreamContext const *, EventPrincipal const &iEP, EventSetup const &iES, StreamID const &streamID)
Definition: Path.cc:282
void updateCounters(bool succeed, bool isEvent)
Definition: Path.cc:160
Path(int bitpos, std::string const &path_name, WorkersInPath const &workers, TrigResPtr trptr, ExceptionToActionTable const &actions, std::shared_ptr< ActivityRegistry > reg, StreamContext const *streamContext, std::atomic< bool > *stopProcessEvent, PathContext::PathType pathType)
Definition: Path.cc:15
int timesVisited(size_type i) const
Definition: Path.h:89
bool handleWorkerFailure(cms::Exception &e, int nwrwue, bool isEvent, bool begin, BranchType branchType, ModuleDescription const &, std::string const &id)
Definition: Path.cc:67
void setEarlyDeleteHelpers(std::map< const Worker *, EarlyDeleteHelper * > const &)
Definition: Path.cc:178
void runAllModulesAsync(WaitingTask *, typename T::MyPrincipal const &, EventSetup const &, StreamID const &, typename T::Context const *)
Definition: Path.h:192
ExceptionToActionTable const * act_table_
Definition: Path.h:116
Path const & operator=(Path const &)=delete
State state_
Definition: Path.h:111
std::string const & name() const
Definition: Path.h:77
#define begin
Definition: vmac.h:30
HLT enums.
double a
Definition: hdecay.h:121
Worker const * getWorker(size_type i) const
Definition: Path.h:93
auto wrap(F iFunc) -> decltype(iFunc())
int timesExcept(size_type i) const
Definition: Path.h:92
long double T
int timesPassed_
Definition: Path.h:107
std::atomic< bool > * stopProcessingEvent_
Definition: Path.h:123
int timesRun_
Definition: Path.h:106
def branchType(schema, name)
Definition: revisionDML.py:112
Worker * pathStatusInserterWorker_
Definition: Path.h:126
void clearCounters()
Definition: Path.cc:171
int timesFailed() const
Definition: Path.h:83
PathStatusInserter * pathStatusInserter_
Definition: Path.h:125
void processOneOccurrence(typename T::MyPrincipal const &, EventSetup const &, StreamID const &, typename T::Context const *)
Definition: Path.h:203