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  StreamID const&,
68  typename T::Context const*);
69 
71 
72  int bitPosition() const { return bitpos_; }
73  std::string const& name() const { return pathContext_.pathName(); }
74 
75  void clearCounters();
76 
77  int timesRun() const { return timesRun_; }
78  int timesPassed() const { return timesPassed_; }
79  int timesFailed() const { return timesFailed_; }
80  int timesExcept() const { return timesExcept_; }
81  //int abortWorker() const { return abortWorker_; }
82  State state() const { return state_; }
83 
84  size_type size() const { return workers_.size(); }
85  int timesVisited(size_type i) const { return workers_.at(i).timesVisited(); }
86  int timesPassed (size_type i) const { return workers_.at(i).timesPassed() ; }
87  int timesFailed (size_type i) const { return workers_.at(i).timesFailed() ; }
88  int timesExcept (size_type i) const { return workers_.at(i).timesExcept() ; }
89  Worker const* getWorker(size_type i) const { return workers_.at(i).getWorker(); }
90 
91  void setEarlyDeleteHelpers(std::map<const Worker*,EarlyDeleteHelper*> const&);
92 
93  void setPathStatusInserter(PathStatusInserter* pathStatusInserter,
94  Worker* pathStatusInserterWorker);
95 
96  private:
97 
98  // If you define this be careful about the pointer in the
99  // PlaceInPathContext object in the contained WorkerInPath objects.
100  Path const& operator=(Path const&) = delete; // stop default
101 
106  //int abortWorker_;
107  State state_;
108 
109  int bitpos_;
110  TrigResPtr trptr_;
111  std::shared_ptr<ActivityRegistry> actReg_; // We do not use propagate_const because the registry itself is mutable.
113 
114  WorkersInPath workers_;
115  std::vector<EarlyDeleteHelper*> earlyDeleteHelpers_;
116 
119  std::atomic<bool>* stopProcessingEvent_;
120 
123 
124  // Helper functions
125  // nwrwue = numWorkersRunWithoutUnhandledException (really!)
127  int nwrwue,
128  bool isEvent,
129  bool begin,
131  ModuleDescription const&,
132  std::string const& id);
133  static void exceptionContext(cms::Exception & ex,
134  bool isEvent,
135  bool begin,
137  ModuleDescription const&,
138  std::string const& id,
139  PathContext const&);
140  void recordStatus(int nwrwue, bool isEvent);
141  void updateCounters(bool succeed, bool isEvent);
142 
143  void finished(int iModuleIndex, bool iSucceeded, std::exception_ptr,
144  StreamContext const*,
145  EventPrincipal const& iEP,
146  EventSetup const& iES,
147  StreamID const& streamID);
148 
149  void handleEarlyFinish(EventPrincipal const&);
152 
153  //Handle asynchronous processing
154  void workerFinished(std::exception_ptr const* iException,
155  unsigned int iModuleIndex,
156  EventPrincipal const& iEP, EventSetup const& iES,
157  StreamID const& iID, StreamContext const* iContext);
158  void runNextWorkerAsync(unsigned int iNextModuleIndex,
159  EventPrincipal const&, EventSetup const&,
160  StreamID const&, StreamContext const*);
161 
162  };
163 
164  namespace {
165  template <typename T>
166  class PathSignalSentry {
167  public:
168  PathSignalSentry(ActivityRegistry *a,
169  int const& nwrwue,
170  hlt::HLTState const& state,
171  PathContext const* pathContext) :
172  a_(a), nwrwue_(nwrwue), state_(state), pathContext_(pathContext) {
173  if (a_) T::prePathSignal(a_, pathContext_);
174  }
175  ~PathSignalSentry() {
176  HLTPathStatus status(state_, nwrwue_);
177  if(a_) T::postPathSignal(a_, status, pathContext_);
178  }
179  private:
180  ActivityRegistry* a_; // We do not use propagate_const because the registry itself is mutable.
181  int const& nwrwue_;
182  hlt::HLTState const& state_;
183  PathContext const* pathContext_;
184  };
185  }
186 
187  template <typename T>
189  typename T::MyPrincipal const& p,
190  EventSetup const& es,
191  StreamID const& streamID,
192  typename T::Context const* context) {
193  for(auto& worker: workers_) {
194  worker.runWorkerAsync<T>(task,p,es,streamID,context);
195  }
196  }
197 
198 }
199 
200 #endif
std::string const & pathName() const
Definition: PathContext.h:37
int timesRun() const
Definition: Path.h:77
int bitPosition() const
Definition: Path.h:72
void recordStatus(int nwrwue, bool isEvent)
Definition: Path.cc:153
void handleEarlyFinish(EventPrincipal const &)
Definition: Path.cc:202
roAction_t actions[nactions]
Definition: GenABIO.cc:187
int timesFailed(size_type i) const
Definition: Path.h:87
std::vector< EarlyDeleteHelper * > earlyDeleteHelpers_
Definition: Path.h:115
int timesFailed_
Definition: Path.h:104
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:86
int timesExcept() const
Definition: Path.h:80
int timesExcept_
Definition: Path.h:105
void runNextWorkerAsync(unsigned int iNextModuleIndex, EventPrincipal const &, EventSetup const &, StreamID const &, StreamContext const *)
Definition: Path.cc:315
PathContext pathContext_
Definition: Path.h:117
size_type size() const
Definition: Path.h:84
WaitingTaskList waitingTasks_
Definition: Path.h:118
State state() const
Definition: Path.h:82
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:111
TrigResPtr trptr_
Definition: Path.h:110
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:109
Definition: Path.h:44
int timesPassed() const
Definition: Path.h:78
void handleEarlyFinish(LuminosityBlockPrincipal const &)
Definition: Path.h:151
void handleEarlyFinish(RunPrincipal const &)
Definition: Path.h:150
WorkersInPath workers_
Definition: Path.h:114
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:85
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:188
ExceptionToActionTable const * act_table_
Definition: Path.h:112
Path const & operator=(Path const &)=delete
State state_
Definition: Path.h:107
std::string const & name() const
Definition: Path.h:73
#define begin
Definition: vmac.h:30
HLT enums.
double a
Definition: hdecay.h:121
Worker const * getWorker(size_type i) const
Definition: Path.h:89
int timesExcept(size_type i) const
Definition: Path.h:88
long double T
int timesPassed_
Definition: Path.h:103
std::atomic< bool > * stopProcessingEvent_
Definition: Path.h:119
int timesRun_
Definition: Path.h:102
def branchType(schema, name)
Definition: revisionDML.py:112
Worker * pathStatusInserterWorker_
Definition: Path.h:122
void clearCounters()
Definition: Path.cc:171
int timesFailed() const
Definition: Path.h:79
PathStatusInserter * pathStatusInserter_
Definition: Path.h:121