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 
19 
20 #include "boost/shared_ptr.hpp"
21 
22 #include <string>
23 #include <vector>
24 
26 
27 namespace edm {
28 
29  class Path {
30  public:
32 
33  typedef std::vector<WorkerInPath> WorkersInPath;
35  typedef boost::shared_ptr<HLTGlobalStatus> TrigResPtr;
36 
37  Path(int bitpos, std::string const& path_name,
38  WorkersInPath const& workers,
39  TrigResPtr trptr,
40  ActionTable const& actions,
41  boost::shared_ptr<ActivityRegistry> reg,
42  bool isEndPath);
43 
44  template <typename T>
45  void processOneOccurrence(typename T::MyPrincipal&, EventSetup const&);
46 
47  int bitPosition() const { return bitpos_; }
48  std::string const& name() const { return name_; }
49 
50  std::pair<double, double> timeCpuReal() const {
51  if(stopwatch_) {
52  return std::pair<double, double>(stopwatch_->cpuTime(), stopwatch_->realTime());
53  }
54  return std::pair<double, double>(0., 0.);
55  }
56 
57  std::pair<double, double> timeCpuReal(unsigned int const i) const {
58  return workers_.at(i).timeCpuReal();
59  }
60 
61  void clearCounters();
62 
63  int timesRun() const { return timesRun_; }
64  int timesPassed() const { return timesPassed_; }
65  int timesFailed() const { return timesFailed_; }
66  int timesExcept() const { return timesExcept_; }
67  //int abortWorker() const { return abortWorker_; }
68  State state() const { return state_; }
69 
70  size_type size() const { return workers_.size(); }
71  int timesVisited(size_type i) const { return workers_.at(i).timesVisited(); }
72  int timesPassed (size_type i) const { return workers_.at(i).timesPassed() ; }
73  int timesFailed (size_type i) const { return workers_.at(i).timesFailed() ; }
74  int timesExcept (size_type i) const { return workers_.at(i).timesExcept() ; }
75  Worker const* getWorker(size_type i) const { return workers_.at(i).getWorker(); }
76 
77  void useStopwatch();
78  private:
80  int timesRun_;
84  //int abortWorker_;
86 
87  int bitpos_;
88  std::string name_;
90  boost::shared_ptr<ActivityRegistry> actReg_;
92 
94 
95  bool isEndPath_;
96 
97  // Helper functions
98  // nwrwue = numWorkersRunWithoutUnhandledException (really!)
99  bool handleWorkerFailure(cms::Exception const& e, int nwrwue, bool isEvent);
100  void recordUnknownException(int nwrwue, bool isEvent);
101  void recordStatus(int nwrwue, bool isEvent);
102  void updateCounters(bool succeed, bool isEvent);
103  };
104 
105  namespace {
106  template <typename T>
107  class PathSignalSentry {
108  public:
109  PathSignalSentry(ActivityRegistry *a,
110  std::string const& name,
111  int const& nwrwue,
112  hlt::HLTState const& state) :
113  a_(a), name_(name), nwrwue_(nwrwue), state_(state) {
114  if (a_) T::prePathSignal(a_, name_);
115  }
116  ~PathSignalSentry() {
117  HLTPathStatus status(state_, nwrwue_);
118  if(a_) T::postPathSignal(a_, name_, status);
119  }
120  private:
121  ActivityRegistry* a_;
122  std::string const& name_;
123  int const& nwrwue_;
124  hlt::HLTState const& state_;
125  };
126  }
127 
128  template <typename T>
129  void Path::processOneOccurrence(typename T::MyPrincipal& ep, EventSetup const& es) {
130 
131  //Create the PathSignalSentry before the RunStopwatch so that
132  // we only record the time spent in the path not from the signal
133  int nwrwue = -1;
134  std::auto_ptr<PathSignalSentry<T> > signaler(new PathSignalSentry<T>(actReg_.get(), name_, nwrwue, state_));
135 
136  // A RunStopwatch, but only if we are processing an event.
137  RunStopwatch stopwatch(T::isEvent_ ? stopwatch_ : RunStopwatch::StopwatchPointer());
138 
139  if (T::isEvent_) {
140  ++timesRun_;
141  }
142  state_ = hlt::Ready;
143 
144  // nwrue = numWorkersRunWithoutUnhandledException
145  bool should_continue = true;
147 
148  WorkersInPath::size_type idx = 0;
149  // It seems likely that 'nwrwue' and 'idx' can never differ ---
150  // if so, we should remove one of them!.
151  for (WorkersInPath::iterator i = workers_.begin(), end = workers_.end();
152  i != end && should_continue;
153  ++i, ++idx) {
154  ++nwrwue;
155  assert (static_cast<int>(idx) == nwrwue);
156  try {
157  cpc.activate(idx, i->getWorker()->descPtr());
158  should_continue = i->runWorker<T>(ep, es, &cpc);
159  }
160  catch(cms::Exception& e) {
161  // handleWorkerFailure may throw a new exception.
162  should_continue = handleWorkerFailure(e, nwrwue, T::isEvent_);
163  }
164  catch(...) {
165  recordUnknownException(nwrwue, T::isEvent_);
166  throw;
167  }
168  }
169  updateCounters(should_continue, T::isEvent_);
170  recordStatus(nwrwue, T::isEvent_);
171  }
172 
173 }
174 
175 #endif
int i
Definition: DBlmapReader.cc:9
int timesRun() const
Definition: Path.h:63
int bitPosition() const
Definition: Path.h:47
Path(int bitpos, std::string const &path_name, WorkersInPath const &workers, TrigResPtr trptr, ActionTable const &actions, boost::shared_ptr< ActivityRegistry > reg, bool isEndPath)
Definition: Path.cc:11
void recordStatus(int nwrwue, bool isEvent)
Definition: Path.cc:82
not [yet] run
Definition: HLTenums.h:21
roAction_t actions[nactions]
Definition: GenABIO.cc:200
int timesFailed(size_type i) const
Definition: Path.h:73
int timesFailed_
Definition: Path.h:82
std::vector< WorkerInPath > WorkersInPath
Definition: Path.h:33
bool handleWorkerFailure(cms::Exception const &e, int nwrwue, bool isEvent)
Definition: Path.cc:33
hlt::HLTState State
Definition: Path.h:31
WorkersInPath::size_type size_type
Definition: Path.h:34
ActionTable const * act_table_
Definition: Path.h:91
std::pair< double, double > timeCpuReal(unsigned int const i) const
Definition: Path.h:57
HLTState
status of a trigger path
Definition: HLTenums.h:21
int timesPassed(size_type i) const
Definition: Path.h:72
int timesExcept() const
Definition: Path.h:66
int timesExcept_
Definition: Path.h:83
size_type size() const
Definition: Path.h:70
State state() const
Definition: Path.h:68
uint16_t size_type
std::string name_
Definition: Path.h:88
bool isEndPath_
Definition: Path.h:95
TrigResPtr trptr_
Definition: Path.h:89
void activate(std::size_t theSlotInPath, ModuleDescription const *mod)
Set the context to reflect the active state.
void processOneOccurrence(typename T::MyPrincipal &, EventSetup const &)
Definition: Path.h:129
boost::shared_ptr< HLTGlobalStatus > TrigResPtr
Definition: Path.h:35
boost::shared_ptr< CPUTimer > StopwatchPointer
Definition: RunStopwatch.h:23
int bitpos_
Definition: Path.h:87
Definition: Path.h:29
int timesPassed() const
Definition: Path.h:64
#define end
Definition: vmac.h:38
void recordUnknownException(int nwrwue, bool isEvent)
Definition: Path.cc:73
boost::shared_ptr< ActivityRegistry > actReg_
Definition: Path.h:90
WorkersInPath workers_
Definition: Path.h:93
void updateCounters(bool succeed, bool isEvent)
Definition: Path.cc:89
void useStopwatch()
Definition: Path.cc:106
int timesVisited(size_type i) const
Definition: Path.h:71
std::pair< double, double > timeCpuReal() const
Definition: Path.h:50
RunStopwatch::StopwatchPointer stopwatch_
Definition: Path.h:79
char state
Definition: procUtils.cc:75
State state_
Definition: Path.h:85
std::string const & name() const
Definition: Path.h:48
double a
Definition: hdecay.h:121
Worker const * getWorker(size_type i) const
Definition: Path.h:75
tuple status
Definition: ntuplemaker.py:245
int timesExcept(size_type i) const
Definition: Path.h:74
long double T
int timesPassed_
Definition: Path.h:81
int timesRun_
Definition: Path.h:80
void clearCounters()
Definition: Path.cc:100
int timesFailed() const
Definition: Path.h:65