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