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 
24 
25 #include <memory>
26 
27 #include <string>
28 #include <vector>
29 #include <map>
30 #include <exception>
31 #include <sstream>
32 
33 namespace edm {
34  class EventTransitionInfo;
35  class ModuleDescription;
36  class PathStatusInserter;
37  class EarlyDeleteHelper;
38  class StreamContext;
39  class StreamID;
40 
41  class Path {
42  public:
44 
45  typedef std::vector<WorkerInPath> WorkersInPath;
47  typedef std::shared_ptr<HLTGlobalStatus> TrigResPtr;
48 
49  Path(int bitpos,
50  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  Path& operator=(Path const&) = delete;
62 
63  template <typename T>
65  typename T::TransitionInfoType const&,
66  ServiceToken const&,
67  StreamID const&,
68  typename T::Context const*);
69 
72 
73  int bitPosition() const { return bitpos_; }
74  std::string const& name() const { return pathContext_.pathName(); }
75 
76  void clearCounters();
77 
78  int timesRun() const { return timesRun_; }
79  int timesPassed() const { return timesPassed_; }
80  int timesFailed() const { return timesFailed_; }
81  int timesExcept() const { return timesExcept_; }
82  //int abortWorker() const { return abortWorker_; }
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  unsigned int bitPosition(size_type i) const { return workers_.at(i).bitPosition(); }
91 
92  void setEarlyDeleteHelpers(std::map<const Worker*, EarlyDeleteHelper*> const&);
93 
94  void setPathStatusInserter(PathStatusInserter* pathStatusInserter, Worker* pathStatusInserterWorker);
95 
96  private:
97  int timesRun_;
101  //int abortWorker_;
102  //When an exception happens, it is possible for multiple modules in a path to fail
103  // and then try to change the state concurrently.
104  std::atomic<bool> stateLock_ = false;
107 
108  int const bitpos_;
110  // We do not use propagate_const because the registry itself is mutable.
111  std::shared_ptr<ActivityRegistry> const actReg_;
113 
115 
118  std::atomic<bool>* const stopProcessingEvent_;
119  std::atomic<unsigned int> modulesToRun_;
120 
123 
124  // Helper functions
125  // nwrwue = numWorkersRunWithoutUnhandledException (really!)
127  int nwrwue,
128  bool isEvent,
129  bool begin,
130  BranchType branchType,
131  ModuleDescription const&,
132  std::string const& id) const;
133  static void exceptionContext(cms::Exception& ex,
134  bool isEvent,
135  bool begin,
136  BranchType branchType,
137  ModuleDescription const&,
138  std::string const& id,
139  PathContext const&);
140  void threadsafe_setFailedModuleInfo(int nwrwue, std::exception_ptr);
141  void recordStatus(int nwrwue, hlt::HLTState state);
143 
144  void finished(std::exception_ptr, StreamContext const*, EventTransitionInfo const&, StreamID const&);
145 
146  //Handle asynchronous processing
147  void workerFinished(std::exception_ptr const*,
148  unsigned int iModuleIndex,
149  EventTransitionInfo const&,
150  ServiceToken const&,
151  StreamID const&,
152  StreamContext const*,
153  oneapi::tbb::task_group& iGroup);
154  void runNextWorkerAsync(unsigned int iNextModuleIndex,
155  EventTransitionInfo const&,
156  ServiceToken const&,
157  StreamID const&,
158  StreamContext const*,
159  oneapi::tbb::task_group& iGroup);
160  };
161 
162  namespace {
163  template <typename T>
164  class PathSignalSentry {
165  public:
166  PathSignalSentry(ActivityRegistry* a,
167  int const& nwrwue,
168  hlt::HLTState const& state,
169  PathContext const* pathContext)
170  : a_(a), nwrwue_(nwrwue), state_(state), pathContext_(pathContext) {
171  if (a_)
172  T::prePathSignal(a_, pathContext_);
173  }
174  ~PathSignalSentry() {
175  HLTPathStatus status(state_, nwrwue_);
176  if (a_)
177  T::postPathSignal(a_, status, pathContext_);
178  }
179 
180  private:
181  ActivityRegistry* a_; // We do not use propagate_const because the registry itself is mutable.
182  int const& nwrwue_;
183  hlt::HLTState const& state_;
184  PathContext const* pathContext_;
185  };
186  } // namespace
187 
188  template <typename T>
190  typename T::TransitionInfoType const& info,
191  ServiceToken const& token,
192  StreamID const& streamID,
193  typename T::Context const* context) {
194  for (auto& worker : workers_) {
195  worker.runWorkerAsync<T>(task, info, token, streamID, context);
196  }
197  }
198 
199 } // namespace edm
200 
201 #endif
Worker const * getWorker(size_type i) const
Definition: Path.h:89
TrigResPtr const trptr_
Definition: Path.h:109
bool handleWorkerFailure(cms::Exception &e, int nwrwue, bool isEvent, bool begin, BranchType branchType, ModuleDescription const &, std::string const &id) const
Definition: Path.cc:70
static const TGPicture * info(bool iBackgroundIsBlack)
int timesPassed(size_type i) const
Definition: Path.h:86
std::atomic< unsigned int > modulesToRun_
Definition: Path.h:119
void recordStatus(int nwrwue, hlt::HLTState state)
Definition: Path.cc:175
roAction_t actions[nactions]
Definition: GenABIO.cc:181
int timesFailed_
Definition: Path.h:99
std::vector< WorkerInPath > WorkersInPath
Definition: Path.h:45
hlt::HLTState State
Definition: Path.h:43
void threadsafe_setFailedModuleInfo(int nwrwue, std::exception_ptr)
Definition: Path.cc:149
WorkersInPath::size_type size_type
Definition: Path.h:46
HLTState
status of a trigger path
Definition: HLTenums.h:16
int timesExcept() const
Definition: Path.h:81
void runNextWorkerAsync(unsigned int iNextModuleIndex, EventTransitionInfo const &, ServiceToken const &, StreamID const &, StreamContext const *, oneapi::tbb::task_group &iGroup)
Definition: Path.cc:353
int timesExcept_
Definition: Path.h:100
PathContext pathContext_
Definition: Path.h:116
WaitingTaskList waitingTasks_
Definition: Path.h:117
int const bitpos_
Definition: Path.h:108
uint16_t size_type
BranchType
Definition: BranchType.h:11
void setPathStatusInserter(PathStatusInserter *pathStatusInserter, Worker *pathStatusInserterWorker)
Definition: Path.cc:213
void workerFinished(std::exception_ptr const *, unsigned int iModuleIndex, EventTransitionInfo const &, ServiceToken const &, StreamID const &, StreamContext const *, oneapi::tbb::task_group &iGroup)
Definition: Path.cc:244
int timesFailed(size_type i) const
Definition: Path.h:87
Path & operator=(Path const &)=delete
int timesExcept(size_type i) const
Definition: Path.h:88
void setEarlyDeleteHelpers(std::map< const Worker *, EarlyDeleteHelper *> const &)
Definition: Path.cc:204
std::shared_ptr< HLTGlobalStatus > TrigResPtr
Definition: Path.h:47
void finished(std::exception_ptr, StreamContext const *, EventTransitionInfo const &, StreamID const &)
Definition: Path.cc:324
Definition: Path.h:41
#define CMS_THREAD_GUARD(_var_)
void updateCounters(hlt::HLTState state)
Definition: Path.cc:181
std::atomic< bool > *const stopProcessingEvent_
Definition: Path.h:118
int timesVisited(size_type i) const
Definition: Path.h:85
int timesFailed() const
Definition: Path.h:80
ExceptionToActionTable const *const act_table_
Definition: Path.h:112
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:119
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:18
int failedModuleIndex_
Definition: Path.h:105
size_type size() const
Definition: Path.h:84
std::shared_ptr< ActivityRegistry > const actReg_
Definition: Path.h:111
State state_
Definition: Path.h:106
HLT enums.
int timesPassed() const
Definition: Path.h:79
double a
Definition: hdecay.h:119
unsigned int bitPosition(size_type i) const
Definition: Path.h:90
int bitPosition() const
Definition: Path.h:73
std::string const & pathName() const
Definition: PathContext.h:30
long double T
std::string const & name() const
Definition: Path.h:74
std::atomic< bool > stateLock_
Definition: Path.h:104
void runAllModulesAsync(WaitingTaskHolder, typename T::TransitionInfoType const &, ServiceToken const &, StreamID const &, typename T::Context const *)
Definition: Path.h:189
int timesPassed_
Definition: Path.h:98
int timesRun_
Definition: Path.h:97
Worker * pathStatusInserterWorker_
Definition: Path.h:122
void clearCounters()
Definition: Path.cc:198
void processOneOccurrenceAsync(WaitingTaskHolder, EventTransitionInfo const &, ServiceToken const &, StreamID const &, StreamContext const *)
Definition: Path.cc:218
PathStatusInserter * pathStatusInserter_
Definition: Path.h:121
int timesRun() const
Definition: Path.h:78