CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 
22 
23 #include <memory>
24 
25 #include <string>
26 #include <vector>
27 #include <map>
28 #include <exception>
29 #include <sstream>
30 
31 namespace edm {
32  class EventPrincipal;
33  class ModuleDescription;
34  class RunPrincipal;
35  class LuminosityBlockPrincipal;
36  class EarlyDeleteHelper;
37  class StreamContext;
38  class StreamID;
39 
40  class Path {
41  public:
43 
44  typedef std::vector<WorkerInPath> WorkersInPath;
46  typedef std::shared_ptr<HLTGlobalStatus> TrigResPtr;
47 
48  Path(int bitpos, std::string const& path_name,
49  WorkersInPath const& workers,
50  TrigResPtr trptr,
52  std::shared_ptr<ActivityRegistry> reg,
53  StreamContext const* streamContext,
54  PathContext::PathType pathType);
55 
56  Path(Path const&);
57 
58  template <typename T>
59  void processOneOccurrence(typename T::MyPrincipal const&, EventSetup const&,
60  StreamID const&, typename T::Context const*);
61 
62  int bitPosition() const { return bitpos_; }
63  std::string const& name() const { return pathContext_.pathName(); }
64 
65  void clearCounters();
66 
67  int timesRun() const { return timesRun_; }
68  int timesPassed() const { return timesPassed_; }
69  int timesFailed() const { return timesFailed_; }
70  int timesExcept() const { return timesExcept_; }
71  //int abortWorker() const { return abortWorker_; }
72  State state() const { return state_; }
73 
74  size_type size() const { return workers_.size(); }
75  int timesVisited(size_type i) const { return workers_.at(i).timesVisited(); }
76  int timesPassed (size_type i) const { return workers_.at(i).timesPassed() ; }
77  int timesFailed (size_type i) const { return workers_.at(i).timesFailed() ; }
78  int timesExcept (size_type i) const { return workers_.at(i).timesExcept() ; }
79  Worker const* getWorker(size_type i) const { return workers_.at(i).getWorker(); }
80 
81  void setEarlyDeleteHelpers(std::map<const Worker*,EarlyDeleteHelper*> const&);
82 
83  private:
84 
85  // If you define this be careful about the pointer in the
86  // PlaceInPathContext object in the contained WorkerInPath objects.
87  Path const& operator=(Path const&) = delete; // stop default
88 
89  int timesRun_;
93  //int abortWorker_;
95 
96  int bitpos_;
98  std::shared_ptr<ActivityRegistry> actReg_; // We do not use propagate_const because the registry itself is mutable.
100 
102  std::vector<EarlyDeleteHelper*> earlyDeleteHelpers_;
103 
105 
106  // Helper functions
107  // nwrwue = numWorkersRunWithoutUnhandledException (really!)
109  int nwrwue,
110  bool isEvent,
111  bool begin,
113  ModuleDescription const&,
114  std::string const& id);
115  static void exceptionContext(cms::Exception & ex,
116  bool isEvent,
117  bool begin,
119  ModuleDescription const&,
120  std::string const& id,
121  PathContext const&);
122  void recordStatus(int nwrwue, bool isEvent);
123  void updateCounters(bool succeed, bool isEvent);
124 
125  void handleEarlyFinish(EventPrincipal const&);
128  };
129 
130  namespace {
131  template <typename T>
132  class PathSignalSentry {
133  public:
134  PathSignalSentry(ActivityRegistry *a,
135  int const& nwrwue,
136  hlt::HLTState const& state,
137  PathContext const* pathContext) :
138  a_(a), nwrwue_(nwrwue), state_(state), pathContext_(pathContext) {
139  if (a_) T::prePathSignal(a_, pathContext_);
140  }
141  ~PathSignalSentry() {
142  HLTPathStatus status(state_, nwrwue_);
143  if(a_) T::postPathSignal(a_, status, pathContext_);
144  }
145  private:
146  ActivityRegistry* a_; // We do not use propagate_const because the registry itself is mutable.
147  int const& nwrwue_;
148  hlt::HLTState const& state_;
149  PathContext const* pathContext_;
150  };
151  }
152 
153  template <typename T>
154  void Path::processOneOccurrence(typename T::MyPrincipal const& ep, EventSetup const& es,
155  StreamID const& streamID, typename T::Context const* context) {
156 
157  int nwrwue = -1;
158  PathSignalSentry<T> signaler(actReg_.get(), nwrwue, state_, &pathContext_);
159 
160  if (T::isEvent_) {
161  ++timesRun_;
162  }
163  state_ = hlt::Ready;
164 
165  // nwrue = numWorkersRunWithoutUnhandledException
166  bool should_continue = true;
167 
168  for (WorkersInPath::iterator i = workers_.begin(), end = workers_.end();
169  i != end && should_continue;
170  ++i) {
171  ++nwrwue;
172  try {
173  convertException::wrap([&]() {
174  if(T::isEvent_) {
175  should_continue = i->runWorker<T>(ep, es, streamID, context);
176  } else {
177  should_continue = i->runWorker<T>(ep, es, streamID, context);
178  }
179  });
180  }
181  catch(cms::Exception& ex) {
182  // handleWorkerFailure may throw a new exception.
183  std::ostringstream ost;
184  ost << ep.id();
185  should_continue = handleWorkerFailure(ex, nwrwue, T::isEvent_, T::begin_, T::branchType_,
186  i->getWorker()->description(), ost.str());
187  }
188  }
189  if (not should_continue) {
190  handleEarlyFinish(ep);
191  }
192  updateCounters(should_continue, T::isEvent_);
193  recordStatus(nwrwue, T::isEvent_);
194  }
195 
196 }
197 
198 #endif
std::string const & pathName() const
Definition: PathContext.h:37
int i
Definition: DBlmapReader.cc:9
int timesRun() const
Definition: Path.h:67
int bitPosition() const
Definition: Path.h:62
void recordStatus(int nwrwue, bool isEvent)
Definition: Path.cc:140
void handleEarlyFinish(EventPrincipal const &)
Definition: Path.cc:182
not [yet] run
Definition: HLTenums.h:18
int timesFailed(size_type i) const
Definition: Path.h:77
std::vector< EarlyDeleteHelper * > earlyDeleteHelpers_
Definition: Path.h:102
int timesFailed_
Definition: Path.h:91
std::vector< WorkerInPath > WorkersInPath
Definition: Path.h:44
hlt::HLTState State
Definition: Path.h:42
WorkersInPath::size_type size_type
Definition: Path.h:45
HLTState
status of a trigger path
Definition: HLTenums.h:18
int timesPassed(size_type i) const
Definition: Path.h:76
int timesExcept() const
Definition: Path.h:70
int timesExcept_
Definition: Path.h:92
PathContext pathContext_
Definition: Path.h:104
size_type size() const
Definition: Path.h:74
State state() const
Definition: Path.h:72
actions
Definition: Schedule.cc:374
uint16_t size_type
BranchType
Definition: BranchType.h:11
std::shared_ptr< ActivityRegistry > actReg_
Definition: Path.h:98
TrigResPtr trptr_
Definition: Path.h:97
std::shared_ptr< HLTGlobalStatus > TrigResPtr
Definition: Path.h:46
int bitpos_
Definition: Path.h:96
Definition: Path.h:40
int timesPassed() const
Definition: Path.h:68
#define end
Definition: vmac.h:37
void handleEarlyFinish(LuminosityBlockPrincipal const &)
Definition: Path.h:127
void handleEarlyFinish(RunPrincipal const &)
Definition: Path.h:126
WorkersInPath workers_
Definition: Path.h:101
static void exceptionContext(cms::Exception &ex, bool isEvent, bool begin, BranchType branchType, ModuleDescription const &, std::string const &id, PathContext const &)
Definition: Path.cc:101
void updateCounters(bool succeed, bool isEvent)
Definition: Path.cc:147
int timesVisited(size_type i) const
Definition: Path.h:75
bool handleWorkerFailure(cms::Exception &e, int nwrwue, bool isEvent, bool begin, BranchType branchType, ModuleDescription const &, std::string const &id)
Definition: Path.cc:57
void setEarlyDeleteHelpers(std::map< const Worker *, EarlyDeleteHelper * > const &)
Definition: Path.cc:165
ExceptionToActionTable const * act_table_
Definition: Path.h:99
Path const & operator=(Path const &)=delete
State state_
Definition: Path.h:94
std::string const & name() const
Definition: Path.h:63
#define begin
Definition: vmac.h:30
double a
Definition: hdecay.h:121
Worker const * getWorker(size_type i) const
Definition: Path.h:79
auto wrap(F iFunc) -> decltype(iFunc())
int timesExcept(size_type i) const
Definition: Path.h:78
long double T
int timesPassed_
Definition: Path.h:90
int timesRun_
Definition: Path.h:89
void clearCounters()
Definition: Path.cc:158
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:12
tuple status
Definition: mps_update.py:57
int timesFailed() const
Definition: Path.h:69
void processOneOccurrence(typename T::MyPrincipal const &, EventSetup const &, StreamID const &, typename T::Context const *)
Definition: Path.h:154