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 name_; }
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_;
114  boost::shared_ptr<ActivityRegistry> actReg_;
116 
118  std::vector<EarlyDeleteHelper*> earlyDeleteHelpers_;
119 
121 
122  // Helper functions
123  // nwrwue = numWorkersRunWithoutUnhandledException (really!)
125  int nwrwue,
126  bool isEvent,
127  bool begin,
129  ModuleDescription const&,
130  std::string const& id);
131  static void exceptionContext(cms::Exception & ex,
132  bool isEvent,
133  bool begin,
135  ModuleDescription const&,
136  std::string const& id,
137  PathContext const&);
138  void recordStatus(int nwrwue, bool isEvent);
139  void updateCounters(bool succeed, bool isEvent);
140 
144  };
145 
146  namespace {
147  template <typename T>
148  class PathSignalSentry {
149  public:
150  PathSignalSentry(ActivityRegistry *a,
151  std::string const& name,
152  int const& nwrwue,
153  hlt::HLTState const& state,
154  PathContext const* pathContext) :
155  a_(a), name_(name), nwrwue_(nwrwue), state_(state), pathContext_(pathContext) {
156  if (a_) T::prePathSignal(a_, name_, pathContext_);
157  }
158  ~PathSignalSentry() {
159  HLTPathStatus status(state_, nwrwue_);
160  if(a_) T::postPathSignal(a_, name_, status, pathContext_);
161  }
162  private:
163  ActivityRegistry* a_;
164  std::string const& name_;
165  int const& nwrwue_;
166  hlt::HLTState const& state_;
167  PathContext const* pathContext_;
168  };
169  }
170 
171  template <typename T>
172  void Path::processOneOccurrence(typename T::MyPrincipal& ep, EventSetup const& es,
173  StreamID const& streamID, typename T::Context const* context) {
174 
175  //Create the PathSignalSentry before the RunStopwatch so that
176  // we only record the time spent in the path not from the signal
177  int nwrwue = -1;
178  PathSignalSentry<T> signaler(actReg_.get(), name_, nwrwue, state_, &pathContext_);
179 
180  // A RunStopwatch, but only if we are processing an event.
181  RunStopwatch stopwatch(T::isEvent_ ? stopwatch_ : RunStopwatch::StopwatchPointer());
182 
183  if (T::isEvent_) {
184  ++timesRun_;
185  }
186  state_ = hlt::Ready;
187 
188  // nwrue = numWorkersRunWithoutUnhandledException
189  bool should_continue = true;
190 
191  for (WorkersInPath::iterator i = workers_.begin(), end = workers_.end();
192  i != end && should_continue;
193  ++i) {
194  ++nwrwue;
195  try {
196  try {
197  if(T::isEvent_) {
198  should_continue = i->runWorker<T>(ep, es, streamID, context);
199  } else {
200  should_continue = i->runWorker<T>(ep, es, streamID, context);
201  }
202  }
203  catch (cms::Exception& e) { throw; }
204  catch(std::bad_alloc& bda) { convertException::badAllocToEDM(); }
205  catch (std::exception& e) { convertException::stdToEDM(e); }
207  catch(char const* c) { convertException::charPtrToEDM(c); }
208  catch (...) { convertException::unknownToEDM(); }
209  }
210  catch(cms::Exception& ex) {
211  // handleWorkerFailure may throw a new exception.
212  std::ostringstream ost;
213  ost << ep.id();
214  should_continue = handleWorkerFailure(ex, nwrwue, T::isEvent_, T::begin_, T::branchType_,
215  i->getWorker()->description(), ost.str());
216  }
217  }
218  if (not should_continue) {
219  handleEarlyFinish(ep);
220  }
221  updateCounters(should_continue, T::isEvent_);
222  recordStatus(nwrwue, T::isEvent_);
223  }
224 
225 }
226 
227 #endif
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:145
void handleEarlyFinish(EventPrincipal &)
Definition: Path.cc:196
not [yet] run
Definition: HLTenums.h:18
int timesFailed(size_type i) const
Definition: Path.h:90
std::vector< EarlyDeleteHelper * > earlyDeleteHelpers_
Definition: Path.h:118
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:120
size_type size() const
Definition: Path.h:87
State state() const
Definition: Path.h:85
actions
Definition: Schedule.cc:362
uint16_t size_type
void processOneOccurrence(typename T::MyPrincipal &, EventSetup const &, StreamID const &, typename T::Context const *)
Definition: Path.h:172
BranchType
Definition: BranchType.h:11
void handleEarlyFinish(RunPrincipal &)
Definition: Path.h:142
std::string name_
Definition: Path.h:112
TrigResPtr trptr_
Definition: Path.h:113
boost::shared_ptr< HLTGlobalStatus > TrigResPtr
Definition: Path.h:48
boost::shared_ptr< CPUTimer > StopwatchPointer
Definition: RunStopwatch.h:22
void stdToEDM(std::exception const &e)
int bitpos_
Definition: Path.h:111
Definition: Path.h:42
int timesPassed() const
Definition: Path.h:81
void handleEarlyFinish(LuminosityBlockPrincipal &)
Definition: Path.h:143
#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:114
WorkersInPath workers_
Definition: Path.h:117
static void exceptionContext(cms::Exception &ex, bool isEvent, bool begin, BranchType branchType, ModuleDescription const &, std::string const &id, PathContext const &)
Definition: Path.cc:106
void charPtrToEDM(char const *c)
void stringToEDM(std::string &s)
void updateCounters(bool succeed, bool isEvent)
Definition: Path.cc:152
void useStopwatch()
Definition: Path.cc:169
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:62
void setEarlyDeleteHelpers(std::map< const Worker *, EarlyDeleteHelper * > const &)
Definition: Path.cc:179
RunStopwatch::StopwatchPointer stopwatch_
Definition: Path.h:103
ExceptionToActionTable const * act_table_
Definition: Path.h:115
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
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:163
int timesFailed() const
Definition: Path.h:82