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>
65  typename T::MyPrincipal const&,
66  EventSetup const&,
67  ServiceToken const&,
68  StreamID const&,
69  typename T::Context const*);
70 
72  ServiceToken const&, StreamID const&, StreamContext const*);
73 
74  int bitPosition() const { return bitpos_; }
75  std::string const& name() const { return pathContext_.pathName(); }
76 
77  void clearCounters();
78 
79  int timesRun() const { return timesRun_; }
80  int timesPassed() const { return timesPassed_; }
81  int timesFailed() const { return timesFailed_; }
82  int timesExcept() const { return timesExcept_; }
83  //int abortWorker() const { return abortWorker_; }
84  State state() const { return state_; }
85 
86  size_type size() const { return workers_.size(); }
87  int timesVisited(size_type i) const { return workers_.at(i).timesVisited(); }
88  int timesPassed (size_type i) const { return workers_.at(i).timesPassed() ; }
89  int timesFailed (size_type i) const { return workers_.at(i).timesFailed() ; }
90  int timesExcept (size_type i) const { return workers_.at(i).timesExcept() ; }
91  Worker const* getWorker(size_type i) const { return workers_.at(i).getWorker(); }
92 
93  void setEarlyDeleteHelpers(std::map<const Worker*,EarlyDeleteHelper*> const&);
94 
95  void setPathStatusInserter(PathStatusInserter* pathStatusInserter,
96  Worker* pathStatusInserterWorker);
97 
98  private:
99 
100  // If you define this be careful about the pointer in the
101  // PlaceInPathContext object in the contained WorkerInPath objects.
102  Path const& operator=(Path const&) = delete; // stop default
103 
108  //int abortWorker_;
109  State state_;
110 
111  int bitpos_;
112  TrigResPtr trptr_;
113  std::shared_ptr<ActivityRegistry> actReg_; // We do not use propagate_const because the registry itself is mutable.
115 
116  WorkersInPath workers_;
117  std::vector<EarlyDeleteHelper*> earlyDeleteHelpers_;
118 
121  std::atomic<bool>* stopProcessingEvent_;
122 
125 
126  // Helper functions
127  // nwrwue = numWorkersRunWithoutUnhandledException (really!)
129  int nwrwue,
130  bool isEvent,
131  bool begin,
133  ModuleDescription const&,
134  std::string const& id);
135  static void exceptionContext(cms::Exception & ex,
136  bool isEvent,
137  bool begin,
139  ModuleDescription const&,
140  std::string const& id,
141  PathContext const&);
142  void recordStatus(int nwrwue, bool isEvent);
143  void updateCounters(bool succeed, bool isEvent);
144 
145  void finished(int iModuleIndex, bool iSucceeded, std::exception_ptr,
146  StreamContext const*,
147  EventPrincipal const& iEP,
148  EventSetup const& iES,
149  StreamID const& streamID);
150 
151  void handleEarlyFinish(EventPrincipal const&);
154 
155  //Handle asynchronous processing
156  void workerFinished(std::exception_ptr const* iException,
157  unsigned int iModuleIndex,
158  EventPrincipal const& iEP, EventSetup const& iES,
159  ServiceToken const& iToken,
160  StreamID const& iID, StreamContext const* iContext);
161  void runNextWorkerAsync(unsigned int iNextModuleIndex,
162  EventPrincipal const&, EventSetup const&,
163  ServiceToken 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  ServiceToken const& token,
196  StreamID const& streamID,
197  typename T::Context const* context) {
198  for(auto& worker: workers_) {
199  worker.runWorkerAsync<T>(task,p,es,token,streamID,context);
200  }
201  }
202 
203 }
204 
205 #endif
void processOneOccurrenceAsync(WaitingTask *, EventPrincipal const &, EventSetup const &, ServiceToken const &, StreamID const &, StreamContext const *)
Definition: Path.cc:209
std::string const & pathName() const
Definition: PathContext.h:37
int timesRun() const
Definition: Path.h:79
int bitPosition() const
Definition: Path.h:74
void recordStatus(int nwrwue, bool isEvent)
Definition: Path.cc:153
void handleEarlyFinish(EventPrincipal const &)
Definition: Path.cc:202
void runAllModulesAsync(WaitingTask *, typename T::MyPrincipal const &, EventSetup const &, ServiceToken const &, StreamID const &, typename T::Context const *)
Definition: Path.h:192
roAction_t actions[nactions]
Definition: GenABIO.cc:187
int timesFailed(size_type i) const
Definition: Path.h:89
std::vector< EarlyDeleteHelper * > earlyDeleteHelpers_
Definition: Path.h:117
int timesFailed_
Definition: Path.h:106
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:88
int timesExcept() const
Definition: Path.h:82
int timesExcept_
Definition: Path.h:107
PathContext pathContext_
Definition: Path.h:119
size_type size() const
Definition: Path.h:86
WaitingTaskList waitingTasks_
Definition: Path.h:120
State state() const
Definition: Path.h:84
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:113
void runNextWorkerAsync(unsigned int iNextModuleIndex, EventPrincipal const &, EventSetup const &, ServiceToken const &, StreamID const &, StreamContext const *)
Definition: Path.cc:320
TrigResPtr trptr_
Definition: Path.h:112
std::shared_ptr< HLTGlobalStatus > TrigResPtr
Definition: Path.h:50
int bitpos_
Definition: Path.h:111
Definition: Path.h:44
int timesPassed() const
Definition: Path.h:80
void handleEarlyFinish(LuminosityBlockPrincipal const &)
Definition: Path.h:153
void handleEarlyFinish(RunPrincipal const &)
Definition: Path.h:152
WorkersInPath workers_
Definition: Path.h:116
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:287
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:87
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 workerFinished(std::exception_ptr const *iException, unsigned int iModuleIndex, EventPrincipal const &iEP, EventSetup const &iES, ServiceToken const &iToken, StreamID const &iID, StreamContext const *iContext)
Definition: Path.cc:234
ExceptionToActionTable const * act_table_
Definition: Path.h:114
Path const & operator=(Path const &)=delete
State state_
Definition: Path.h:109
std::string const & name() const
Definition: Path.h:75
#define begin
Definition: vmac.h:32
HLT enums.
double a
Definition: hdecay.h:121
Worker const * getWorker(size_type i) const
Definition: Path.h:91
int timesExcept(size_type i) const
Definition: Path.h:90
long double T
int timesPassed_
Definition: Path.h:105
std::atomic< bool > * stopProcessingEvent_
Definition: Path.h:121
int timesRun_
Definition: Path.h:104
def branchType(schema, name)
Definition: revisionDML.py:112
Worker * pathStatusInserterWorker_
Definition: Path.h:124
void clearCounters()
Definition: Path.cc:171
int timesFailed() const
Definition: Path.h:81
PathStatusInserter * pathStatusInserter_
Definition: Path.h:123