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