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 
64 
65  int bitPosition() const { return bitpos_; }
66  std::string const& name() const { return pathContext_.pathName(); }
67 
68  void clearCounters();
69 
70  int timesRun() const { return timesRun_; }
71  int timesPassed() const { return timesPassed_; }
72  int timesFailed() const { return timesFailed_; }
73  int timesExcept() const { return timesExcept_; }
74  //int abortWorker() const { return abortWorker_; }
75 
76  size_type size() const { return workers_.size(); }
77  int timesVisited(size_type i) const { return workers_.at(i).timesVisited(); }
78  int timesPassed(size_type i) const { return workers_.at(i).timesPassed(); }
79  int timesFailed(size_type i) const { return workers_.at(i).timesFailed(); }
80  int timesExcept(size_type i) const { return workers_.at(i).timesExcept(); }
81  Worker const* getWorker(size_type i) const { return workers_.at(i).getWorker(); }
82  unsigned int bitPosition(size_type i) const { return workers_.at(i).bitPosition(); }
83 
84  void setEarlyDeleteHelpers(std::map<const Worker*, EarlyDeleteHelper*> const&);
85 
86  void setPathStatusInserter(PathStatusInserter* pathStatusInserter, Worker* pathStatusInserterWorker);
87 
88  private:
89  int timesRun_;
93  //int abortWorker_;
94  std::atomic<bool> printedException_ = false;
95  //When an exception happens, it is possible for multiple modules in a path to fail
96  // and then try to change the state concurrently.
97  std::atomic<bool> stateLock_ = false;
100 
101  int const bitpos_;
103  // We do not use propagate_const because the registry itself is mutable.
104  std::shared_ptr<ActivityRegistry> const actReg_;
106 
108 
111  std::atomic<unsigned int> modulesToRun_;
112 
115 
116  // Helper functions
117  // nwrwue = numWorkersRunWithoutUnhandledException (really!)
118  void handleWorkerFailure(cms::Exception& e, int nwrwue, ModuleDescription const&, std::string const& id);
119  static void exceptionContext(cms::Exception& ex,
120  bool isEvent,
121  bool begin,
122  BranchType branchType,
123  ModuleDescription const&,
124  std::string const& id,
125  PathContext const&);
126  void threadsafe_setFailedModuleInfo(int nwrwue, bool iExceptionHappened);
127  void recordStatus(int nwrwue, hlt::HLTState state);
129 
130  void finished(std::exception_ptr, StreamContext const*, EventTransitionInfo const&, StreamID const&);
131 
132  //Handle asynchronous processing
133  void workerFinished(std::exception_ptr const*,
134  unsigned int iModuleIndex,
135  EventTransitionInfo const&,
136  ServiceToken const&,
137  StreamID const&,
138  StreamContext const*,
139  oneapi::tbb::task_group& iGroup);
140  void runNextWorkerAsync(unsigned int iNextModuleIndex,
141  EventTransitionInfo const&,
142  ServiceToken const&,
143  StreamID const&,
144  StreamContext const*,
145  oneapi::tbb::task_group& iGroup);
146  };
147 
148  namespace {
149  template <typename T>
150  class PathSignalSentry {
151  public:
152  PathSignalSentry(ActivityRegistry* a,
153  int const& nwrwue,
154  hlt::HLTState const& state,
155  PathContext const* pathContext)
156  : a_(a), nwrwue_(nwrwue), state_(state), pathContext_(pathContext) {
157  if (a_)
158  T::prePathSignal(a_, pathContext_);
159  }
160  ~PathSignalSentry() {
161  HLTPathStatus status(state_, nwrwue_);
162  if (a_)
163  T::postPathSignal(a_, status, pathContext_);
164  }
165 
166  private:
167  ActivityRegistry* a_; // We do not use propagate_const because the registry itself is mutable.
168  int const& nwrwue_;
169  hlt::HLTState const& state_;
170  PathContext const* pathContext_;
171  };
172  } // namespace
173 
174 } // namespace edm
175 
176 #endif
Worker const * getWorker(size_type i) const
Definition: Path.h:81
TrigResPtr const trptr_
Definition: Path.h:102
void processEventUsingPathAsync(WaitingTaskHolder, EventTransitionInfo const &, ServiceToken const &, StreamID const &, StreamContext const *)
Definition: Path.cc:203
int timesPassed(size_type i) const
Definition: Path.h:78
std::atomic< unsigned int > modulesToRun_
Definition: Path.h:111
void recordStatus(int nwrwue, hlt::HLTState state)
Definition: Path.cc:160
roAction_t actions[nactions]
Definition: GenABIO.cc:181
int timesFailed_
Definition: Path.h:91
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:73
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:92
PathContext pathContext_
Definition: Path.h:109
WaitingTaskList waitingTasks_
Definition: Path.h:110
int const bitpos_
Definition: Path.h:101
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:79
Path & operator=(Path const &)=delete
int timesExcept(size_type i) const
Definition: Path.h:80
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:77
int timesFailed() const
Definition: Path.h:72
ExceptionToActionTable const *const act_table_
Definition: Path.h:105
WorkersInPath workers_
Definition: Path.h:107
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:98
size_type size() const
Definition: Path.h:76
std::shared_ptr< ActivityRegistry > const actReg_
Definition: Path.h:104
State state_
Definition: Path.h:99
HLT enums.
std::atomic< bool > printedException_
Definition: Path.h:94
int timesPassed() const
Definition: Path.h:71
double a
Definition: hdecay.h:121
unsigned int bitPosition(size_type i) const
Definition: Path.h:82
int bitPosition() const
Definition: Path.h:65
std::string const & pathName() const
Definition: PathContext.h:30
std::string const & name() const
Definition: Path.h:66
std::atomic< bool > stateLock_
Definition: Path.h:97
int timesPassed_
Definition: Path.h:90
int timesRun_
Definition: Path.h:89
Worker * pathStatusInserterWorker_
Definition: Path.h:114
void clearCounters()
Definition: Path.cc:183
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:113
int timesRun() const
Definition: Path.h:70