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  PathContext::PathType pathType);
57 
58  Path(Path const&);
59 
60  Path& operator=(Path const&) = delete;
61 
62  template <typename T>
64  typename T::TransitionInfoType const&,
65  ServiceToken const&,
66  StreamID const&,
67  typename T::Context const*);
68 
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 
83  size_type size() const { return workers_.size(); }
84  int timesVisited(size_type i) const { return workers_.at(i).timesVisited(); }
85  int timesPassed(size_type i) const { return workers_.at(i).timesPassed(); }
86  int timesFailed(size_type i) const { return workers_.at(i).timesFailed(); }
87  int timesExcept(size_type i) const { return workers_.at(i).timesExcept(); }
88  Worker const* getWorker(size_type i) const { return workers_.at(i).getWorker(); }
89  unsigned int bitPosition(size_type i) const { return workers_.at(i).bitPosition(); }
90 
91  void setEarlyDeleteHelpers(std::map<const Worker*, EarlyDeleteHelper*> const&);
92 
93  void setPathStatusInserter(PathStatusInserter* pathStatusInserter, Worker* pathStatusInserterWorker);
94 
95  private:
96  int timesRun_;
100  //int abortWorker_;
101  std::atomic<bool> printedException_ = false;
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<unsigned int> modulesToRun_;
119 
122 
123  // Helper functions
124  // nwrwue = numWorkersRunWithoutUnhandledException (really!)
125  void handleWorkerFailure(cms::Exception& e, int nwrwue, ModuleDescription const&, std::string const& id);
126  static void exceptionContext(cms::Exception& ex,
127  bool isEvent,
128  bool begin,
129  BranchType branchType,
130  ModuleDescription const&,
131  std::string const& id,
132  PathContext const&);
133  void threadsafe_setFailedModuleInfo(int nwrwue, bool iExceptionHappened);
134  void recordStatus(int nwrwue, hlt::HLTState state);
136 
137  void finished(std::exception_ptr, StreamContext const*, EventTransitionInfo const&, StreamID const&);
138 
139  //Handle asynchronous processing
140  void workerFinished(std::exception_ptr const*,
141  unsigned int iModuleIndex,
142  EventTransitionInfo const&,
143  ServiceToken const&,
144  StreamID const&,
145  StreamContext const*,
146  oneapi::tbb::task_group& iGroup);
147  void runNextWorkerAsync(unsigned int iNextModuleIndex,
148  EventTransitionInfo const&,
149  ServiceToken const&,
150  StreamID const&,
151  StreamContext const*,
152  oneapi::tbb::task_group& iGroup);
153  };
154 
155  namespace {
156  template <typename T>
157  class PathSignalSentry {
158  public:
159  PathSignalSentry(ActivityRegistry* a,
160  int const& nwrwue,
161  hlt::HLTState const& state,
162  PathContext const* pathContext)
163  : a_(a), nwrwue_(nwrwue), state_(state), pathContext_(pathContext) {
164  if (a_)
165  T::prePathSignal(a_, pathContext_);
166  }
167  ~PathSignalSentry() {
168  HLTPathStatus status(state_, nwrwue_);
169  if (a_)
170  T::postPathSignal(a_, status, pathContext_);
171  }
172 
173  private:
174  ActivityRegistry* a_; // We do not use propagate_const because the registry itself is mutable.
175  int const& nwrwue_;
176  hlt::HLTState const& state_;
177  PathContext const* pathContext_;
178  };
179  } // namespace
180 
181  template <typename T>
183  typename T::TransitionInfoType const& info,
184  ServiceToken const& token,
185  StreamID const& streamID,
186  typename T::Context const* context) {
187  for (auto& worker : workers_) {
188  worker.runWorkerAsync<T>(task, info, token, streamID, context);
189  }
190  }
191 
192 } // namespace edm
193 
194 #endif
Worker const * getWorker(size_type i) const
Definition: Path.h:88
TrigResPtr const trptr_
Definition: Path.h:109
static const TGPicture * info(bool iBackgroundIsBlack)
int timesPassed(size_type i) const
Definition: Path.h:85
std::atomic< unsigned int > modulesToRun_
Definition: Path.h:118
void recordStatus(int nwrwue, hlt::HLTState state)
Definition: Path.cc:160
roAction_t actions[nactions]
Definition: GenABIO.cc:181
int timesFailed_
Definition: Path.h:98
std::vector< WorkerInPath > WorkersInPath
Definition: Path.h:45
hlt::HLTState State
Definition: Path.h:43
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:80
void runNextWorkerAsync(unsigned int iNextModuleIndex, EventTransitionInfo const &, ServiceToken const &, StreamID const &, StreamContext const *, oneapi::tbb::task_group &iGroup)
Definition: Path.cc:331
int timesExcept_
Definition: Path.h:99
PathContext pathContext_
Definition: Path.h:116
WaitingTaskList waitingTasks_
Definition: Path.h:117
int const bitpos_
Definition: Path.h:108
uint16_t size_type
void handleWorkerFailure(cms::Exception &e, int nwrwue, ModuleDescription const &, std::string const &id)
Definition: Path.cc:68
BranchType
Definition: BranchType.h:11
void setPathStatusInserter(PathStatusInserter *pathStatusInserter, Worker *pathStatusInserterWorker)
Definition: Path.cc:198
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:230
int timesFailed(size_type i) const
Definition: Path.h:86
Path & operator=(Path const &)=delete
int timesExcept(size_type i) const
Definition: Path.h:87
void setEarlyDeleteHelpers(std::map< const Worker *, EarlyDeleteHelper *> const &)
Definition: Path.cc:189
std::shared_ptr< HLTGlobalStatus > TrigResPtr
Definition: Path.h:47
void finished(std::exception_ptr, StreamContext const *, EventTransitionInfo const &, StreamID const &)
Definition: Path.cc:300
Definition: Path.h:41
#define CMS_THREAD_GUARD(_var_)
void updateCounters(hlt::HLTState state)
Definition: Path.cc:166
int timesVisited(size_type i) const
Definition: Path.h:84
int timesFailed() const
Definition: Path.h:79
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:104
int failedModuleIndex_
Definition: Path.h:105
size_type size() const
Definition: Path.h:83
std::shared_ptr< ActivityRegistry > const actReg_
Definition: Path.h:111
State state_
Definition: Path.h:106
HLT enums.
std::atomic< bool > printedException_
Definition: Path.h:101
int timesPassed() const
Definition: Path.h:78
double a
Definition: hdecay.h:121
unsigned int bitPosition(size_type i) const
Definition: Path.h:89
int bitPosition() const
Definition: Path.h:72
std::string const & pathName() const
Definition: PathContext.h:30
long double T
std::string const & name() const
Definition: Path.h:73
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:182
int timesPassed_
Definition: Path.h:97
int timesRun_
Definition: Path.h:96
Worker * pathStatusInserterWorker_
Definition: Path.h:121
void clearCounters()
Definition: Path.cc:183
void processOneOccurrenceAsync(WaitingTaskHolder, EventTransitionInfo const &, ServiceToken const &, StreamID const &, StreamContext const *)
Definition: Path.cc:203
Path(int bitpos, std::string const &path_name, WorkersInPath const &workers, TrigResPtr trptr, ExceptionToActionTable const &actions, std::shared_ptr< ActivityRegistry > reg, StreamContext const *streamContext, PathContext::PathType pathType)
Definition: Path.cc:19
void threadsafe_setFailedModuleInfo(int nwrwue, bool iExceptionHappened)
Definition: Path.cc:134
PathStatusInserter * pathStatusInserter_
Definition: Path.h:120
int timesRun() const
Definition: Path.h:77