CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
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  //When an exception happens, it is possible for multiple modules in a path to fail
102  // and then try to change the state concurrently.
103  std::atomic<bool> stateLock_ = false;
106 
109  // We do not use propagate_const because the registry itself is mutable.
110  std::shared_ptr<ActivityRegistry> const actReg_;
112 
114 
117  std::atomic<bool>* const stopProcessingEvent_;
118  std::atomic<unsigned int> modulesToRun_;
119 
122 
123  // Helper functions
124  // nwrwue = numWorkersRunWithoutUnhandledException (really!)
125  bool handleWorkerFailure(cms::Exception& e,
126  int nwrwue,
127  bool isEvent,
128  bool begin,
129  BranchType branchType,
131  std::string const& id) const;
132  static void exceptionContext(cms::Exception& ex,
133  bool isEvent,
134  bool begin,
135  BranchType branchType,
136  ModuleDescription const&,
137  std::string const& id,
138  PathContext const&);
139  void threadsafe_setFailedModuleInfo(int nwrwue, std::exception_ptr);
140  void recordStatus(int nwrwue, hlt::HLTState state);
141  void updateCounters(hlt::HLTState state);
142 
143  void finished(std::exception_ptr, StreamContext const*, EventTransitionInfo const&, StreamID const&);
144 
145  //Handle asynchronous processing
146  void workerFinished(std::exception_ptr const*,
147  unsigned int iModuleIndex,
148  EventTransitionInfo const&,
149  ServiceToken const&,
150  StreamID const&,
151  StreamContext const*,
152  oneapi::tbb::task_group& iGroup);
153  void runNextWorkerAsync(unsigned int iNextModuleIndex,
154  EventTransitionInfo const&,
155  ServiceToken const&,
156  StreamID const&,
157  StreamContext const*,
158  oneapi::tbb::task_group& iGroup);
159  };
160 
161  namespace {
162  template <typename T>
163  class PathSignalSentry {
164  public:
165  PathSignalSentry(ActivityRegistry* a,
166  int const& nwrwue,
167  hlt::HLTState const& state,
168  PathContext const* pathContext)
169  : a_(a), nwrwue_(nwrwue), state_(state), pathContext_(pathContext) {
170  if (a_)
171  T::prePathSignal(a_, pathContext_);
172  }
173  ~PathSignalSentry() {
174  HLTPathStatus status(state_, nwrwue_);
175  if (a_)
176  T::postPathSignal(a_, status, pathContext_);
177  }
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  } // namespace
186 
187  template <typename T>
189  typename T::TransitionInfoType const& info,
190  ServiceToken const& token,
191  StreamID const& streamID,
192  typename T::Context const* context) {
193  for (auto& worker : workers_) {
194  worker.runWorkerAsync<T>(task, info, token, streamID, context);
195  }
196  }
197 
198 } // namespace edm
199 
200 #endif
std::string const & pathName() const
Definition: PathContext.h:30
TrigResPtr const trptr_
Definition: Path.h:108
int timesRun() const
Definition: Path.h:78
const auto & workers
int bitPosition() const
Definition: Path.h:73
static const TGPicture * info(bool iBackgroundIsBlack)
std::atomic< unsigned int > modulesToRun_
Definition: Path.h:118
void recordStatus(int nwrwue, hlt::HLTState state)
Definition: Path.cc:175
int timesFailed(size_type i) const
Definition: Path.h:87
int timesFailed_
Definition: Path.h:98
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
void runNextWorkerAsync(unsigned int iNextModuleIndex, EventTransitionInfo const &, ServiceToken const &, StreamID const &, StreamContext const *, oneapi::tbb::task_group &iGroup)
Definition: Path.cc:352
list status
Definition: mps_update.py:107
int timesPassed(size_type i) const
Definition: Path.h:86
int timesExcept() const
Definition: Path.h:81
int timesExcept_
Definition: Path.h:99
PathContext pathContext_
Definition: Path.h:115
size_type size() const
Definition: Path.h:84
WaitingTaskList waitingTasks_
Definition: Path.h:116
int const bitpos_
Definition: Path.h:107
actions
Definition: Schedule.cc:687
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
Path & operator=(Path const &)=delete
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
int timesPassed() const
Definition: Path.h:79
#define CMS_THREAD_GUARD(_var_)
void updateCounters(hlt::HLTState state)
Definition: Path.cc:181
std::atomic< bool > *const stopProcessingEvent_
Definition: Path.h:117
ExceptionToActionTable const *const act_table_
Definition: Path.h:111
WorkersInPath workers_
Definition: Path.h:113
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:104
int timesVisited(size_type i) const
Definition: Path.h:85
std::shared_ptr< ActivityRegistry > const actReg_
Definition: Path.h:110
void setEarlyDeleteHelpers(std::map< const Worker *, EarlyDeleteHelper * > const &)
Definition: Path.cc:204
State state_
Definition: Path.h:105
std::string const & name() const
Definition: Path.h:74
double a
Definition: hdecay.h:119
Worker const * getWorker(size_type i) const
Definition: Path.h:89
bool handleWorkerFailure(cms::Exception &e, int nwrwue, bool isEvent, bool begin, BranchType branchType, ModuleDescription const &, std::string const &id) const
Definition: Path.cc:70
int timesExcept(size_type i) const
Definition: Path.h:88
long double T
std::atomic< bool > stateLock_
Definition: Path.h:103
void runAllModulesAsync(WaitingTaskHolder, typename T::TransitionInfoType const &, ServiceToken const &, StreamID const &, typename T::Context const *)
Definition: Path.h:188
int timesPassed_
Definition: Path.h:97
int timesRun_
Definition: Path.h:96
Worker * pathStatusInserterWorker_
Definition: Path.h:121
void clearCounters()
Definition: Path.cc:198
void processOneOccurrenceAsync(WaitingTaskHolder, EventTransitionInfo const &, ServiceToken const &, StreamID const &, StreamContext const *)
Definition: Path.cc:218
int timesFailed() const
Definition: Path.h:80
PathStatusInserter * pathStatusInserter_
Definition: Path.h:120