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 ModuleDescription;
35  class RunPrincipal;
36  class LuminosityBlockPrincipal;
37  class EarlyDeleteHelper;
38  class StreamContext;
39  class StreamID;
40  class WaitingTask;
41 
42  class Path {
43  public:
45 
46  typedef std::vector<WorkerInPath> WorkersInPath;
48  typedef std::shared_ptr<HLTGlobalStatus> TrigResPtr;
49 
50  Path(int bitpos, std::string const& path_name,
51  WorkersInPath const& workers,
52  TrigResPtr trptr,
54  std::shared_ptr<ActivityRegistry> reg,
55  StreamContext const* streamContext,
56  std::atomic<bool>* stopProcessEvent,
57  PathContext::PathType pathType);
58 
59  Path(Path const&);
60 
61  template <typename T>
62  void processOneOccurrence(typename T::MyPrincipal const&, EventSetup const&,
63  StreamID const&, typename T::Context const*);
64 
66 
67  int bitPosition() const { return bitpos_; }
68  std::string const& name() const { return pathContext_.pathName(); }
69 
70  void clearCounters();
71 
72  int timesRun() const { return timesRun_; }
73  int timesPassed() const { return timesPassed_; }
74  int timesFailed() const { return timesFailed_; }
75  int timesExcept() const { return timesExcept_; }
76  //int abortWorker() const { return abortWorker_; }
77  State state() const { return state_; }
78 
79  size_type size() const { return workers_.size(); }
80  int timesVisited(size_type i) const { return workers_.at(i).timesVisited(); }
81  int timesPassed (size_type i) const { return workers_.at(i).timesPassed() ; }
82  int timesFailed (size_type i) const { return workers_.at(i).timesFailed() ; }
83  int timesExcept (size_type i) const { return workers_.at(i).timesExcept() ; }
84  Worker const* getWorker(size_type i) const { return workers_.at(i).getWorker(); }
85 
86  void setEarlyDeleteHelpers(std::map<const Worker*,EarlyDeleteHelper*> const&);
87 
88  private:
89 
90  // If you define this be careful about the pointer in the
91  // PlaceInPathContext object in the contained WorkerInPath objects.
92  Path const& operator=(Path const&) = delete; // stop default
93 
94  int timesRun_;
98  //int abortWorker_;
99  State state_;
100 
101  int bitpos_;
102  TrigResPtr trptr_;
103  std::shared_ptr<ActivityRegistry> actReg_; // We do not use propagate_const because the registry itself is mutable.
105 
106  WorkersInPath workers_;
107  std::vector<EarlyDeleteHelper*> earlyDeleteHelpers_;
108 
111  std::atomic<bool>* stopProcessingEvent_;
112 
113 
114 
115  // Helper functions
116  // nwrwue = numWorkersRunWithoutUnhandledException (really!)
118  int nwrwue,
119  bool isEvent,
120  bool begin,
122  ModuleDescription const&,
123  std::string const& id);
124  static void exceptionContext(cms::Exception & ex,
125  bool isEvent,
126  bool begin,
128  ModuleDescription const&,
129  std::string const& id,
130  PathContext const&);
131  void recordStatus(int nwrwue, bool isEvent);
132  void updateCounters(bool succeed, bool isEvent);
133 
134  void finished(int iModuleIndex, bool iSucceeded, std::exception_ptr,
135  StreamContext const*);
136 
137  void handleEarlyFinish(EventPrincipal const&);
140 
141  //Handle asynchronous processing
142  void workerFinished(std::exception_ptr const* iException,
143  unsigned int iModuleIndex,
144  EventPrincipal const& iEP, EventSetup const& iES,
145  StreamID const& iID, StreamContext const* iContext);
146  void runNextWorkerAsync(unsigned int iNextModuleIndex,
147  EventPrincipal const&, EventSetup const&,
148  StreamID const&, StreamContext const*);
149 
150  };
151 
152  namespace {
153  template <typename T>
154  class PathSignalSentry {
155  public:
156  PathSignalSentry(ActivityRegistry *a,
157  int const& nwrwue,
158  hlt::HLTState const& state,
159  PathContext const* pathContext) :
160  a_(a), nwrwue_(nwrwue), state_(state), pathContext_(pathContext) {
161  if (a_) T::prePathSignal(a_, pathContext_);
162  }
163  ~PathSignalSentry() {
164  HLTPathStatus status(state_, nwrwue_);
165  if(a_) T::postPathSignal(a_, status, pathContext_);
166  }
167  private:
168  ActivityRegistry* a_; // We do not use propagate_const because the registry itself is mutable.
169  int const& nwrwue_;
170  hlt::HLTState const& state_;
171  PathContext const* pathContext_;
172  };
173  }
174 
175  template <typename T>
176  void Path::processOneOccurrence(typename T::MyPrincipal const& ep, EventSetup const& es,
177  StreamID const& streamID, typename T::Context const* context) {
178 
179  int nwrwue = -1;
180  PathSignalSentry<T> signaler(actReg_.get(), nwrwue, state_, &pathContext_);
181 
182  if (T::isEvent_) {
183  ++timesRun_;
184  }
185  state_ = hlt::Ready;
186 
187  // nwrue = numWorkersRunWithoutUnhandledException
188  bool should_continue = true;
189  WorkersInPath::iterator i = workers_.begin(), end = workers_.end();
190 
191  auto earlyFinishSentry = make_sentry(this,[&i,end, &ep](Path*){
192  for(auto j=i; j!= end;++j) {
193  j->skipWorker(ep);
194  }
195  });
196  for (;
197  i != end && should_continue;
198  ++i) {
199  ++nwrwue;
200  try {
201  convertException::wrap([&]() {
202  should_continue = i->runWorker<T>(ep, es, streamID, context);
203  });
204  }
205  catch(cms::Exception& ex) {
206  // handleWorkerFailure may throw a new exception.
207  std::ostringstream ost;
208  ost << ep.id();
209  should_continue = handleWorkerFailure(ex, nwrwue, T::isEvent_, T::begin_, T::branchType_,
210  i->getWorker()->description(), ost.str());
211  //If we didn't rethrow, then we effectively skipped
212  i->skipWorker(ep);
213  }
214  }
215  if (not should_continue) {
216  handleEarlyFinish(ep);
217  }
218  updateCounters(should_continue, T::isEvent_);
219  recordStatus(nwrwue, T::isEvent_);
220  }
221 
222 }
223 
224 #endif
std::string const & pathName() const
Definition: PathContext.h:37
int i
Definition: DBlmapReader.cc:9
int timesRun() const
Definition: Path.h:72
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:67
void recordStatus(int nwrwue, bool isEvent)
Definition: Path.cc:150
void handleEarlyFinish(EventPrincipal const &)
Definition: Path.cc:192
not [yet] run
Definition: HLTenums.h:18
roAction_t actions[nactions]
Definition: GenABIO.cc:187
int timesFailed(size_type i) const
Definition: Path.h:82
std::vector< EarlyDeleteHelper * > earlyDeleteHelpers_
Definition: Path.h:107
int timesFailed_
Definition: Path.h:96
std::vector< WorkerInPath > WorkersInPath
Definition: Path.h:46
hlt::HLTState State
Definition: Path.h:44
WorkersInPath::size_type size_type
Definition: Path.h:47
HLTState
status of a trigger path
Definition: HLTenums.h:18
int timesPassed(size_type i) const
Definition: Path.h:81
int timesExcept() const
Definition: Path.h:75
int timesExcept_
Definition: Path.h:97
void runNextWorkerAsync(unsigned int iNextModuleIndex, EventPrincipal const &, EventSetup const &, StreamID const &, StreamContext const *)
Definition: Path.cc:290
PathContext pathContext_
Definition: Path.h:109
size_type size() const
Definition: Path.h:79
WaitingTaskList waitingTasks_
Definition: Path.h:110
State state() const
Definition: Path.h:77
uint16_t size_type
BranchType
Definition: BranchType.h:11
std::shared_ptr< ActivityRegistry > actReg_
Definition: Path.h:103
TrigResPtr trptr_
Definition: Path.h:102
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:221
std::shared_ptr< HLTGlobalStatus > TrigResPtr
Definition: Path.h:48
void processOneOccurrenceAsync(WaitingTask *, EventPrincipal const &, EventSetup const &, StreamID const &, StreamContext const *)
Definition: Path.cc:199
int bitpos_
Definition: Path.h:101
Definition: Path.h:42
int timesPassed() const
Definition: Path.h:73
int j
Definition: DBlmapReader.cc:9
#define end
Definition: vmac.h:37
void handleEarlyFinish(LuminosityBlockPrincipal const &)
Definition: Path.h:139
void handleEarlyFinish(RunPrincipal const &)
Definition: Path.h:138
WorkersInPath workers_
Definition: Path.h:106
static void exceptionContext(cms::Exception &ex, bool isEvent, bool begin, BranchType branchType, ModuleDescription const &, std::string const &id, PathContext const &)
Definition: Path.cc:110
void updateCounters(bool succeed, bool isEvent)
Definition: Path.cc:157
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:12
int timesVisited(size_type i) const
Definition: Path.h:80
bool handleWorkerFailure(cms::Exception &e, int nwrwue, bool isEvent, bool begin, BranchType branchType, ModuleDescription const &, std::string const &id)
Definition: Path.cc:60
void setEarlyDeleteHelpers(std::map< const Worker *, EarlyDeleteHelper * > const &)
Definition: Path.cc:175
ExceptionToActionTable const * act_table_
Definition: Path.h:104
Path const & operator=(Path const &)=delete
State state_
Definition: Path.h:99
std::string const & name() const
Definition: Path.h:68
#define begin
Definition: vmac.h:30
HLT enums.
double a
Definition: hdecay.h:121
Worker const * getWorker(size_type i) const
Definition: Path.h:84
void finished(int iModuleIndex, bool iSucceeded, std::exception_ptr, StreamContext const *)
Definition: Path.cc:272
auto wrap(F iFunc) -> decltype(iFunc())
int timesExcept(size_type i) const
Definition: Path.h:83
long double T
int timesPassed_
Definition: Path.h:95
std::atomic< bool > * stopProcessingEvent_
Definition: Path.h:111
int timesRun_
Definition: Path.h:94
def branchType(schema, name)
Definition: revisionDML.py:112
void clearCounters()
Definition: Path.cc:168
int timesFailed() const
Definition: Path.h:74
void processOneOccurrence(typename T::MyPrincipal const &, EventSetup const &, StreamID const &, typename T::Context const *)
Definition: Path.h:176