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 RunPrincipal;
36  class LuminosityBlockPrincipal;
37  class EarlyDeleteHelper;
38 
39  class Path {
40  public:
42 
43  typedef std::vector<WorkerInPath> WorkersInPath;
45  typedef boost::shared_ptr<HLTGlobalStatus> TrigResPtr;
46 
47  Path(int bitpos, std::string const& path_name,
48  WorkersInPath const& workers,
49  TrigResPtr trptr,
50  ActionTable const& actions,
51  boost::shared_ptr<ActivityRegistry> reg,
52  bool isEndPath);
53 
54  template <typename T>
55  void processOneOccurrence(typename T::MyPrincipal&, EventSetup const&);
56 
57  int bitPosition() const { return bitpos_; }
58  std::string const& name() const { return name_; }
59 
60  std::pair<double, double> timeCpuReal() const {
61  if(stopwatch_) {
62  return std::pair<double, double>(stopwatch_->cpuTime(), stopwatch_->realTime());
63  }
64  return std::pair<double, double>(0., 0.);
65  }
66 
67  std::pair<double, double> timeCpuReal(unsigned int const i) const {
68  return workers_.at(i).timeCpuReal();
69  }
70 
71  void clearCounters();
72 
73  int timesRun() const { return timesRun_; }
74  int timesPassed() const { return timesPassed_; }
75  int timesFailed() const { return timesFailed_; }
76  int timesExcept() const { return timesExcept_; }
77  //int abortWorker() const { return abortWorker_; }
78  State state() const { return state_; }
79 
80  size_type size() const { return workers_.size(); }
81  int timesVisited(size_type i) const { return workers_.at(i).timesVisited(); }
82  int timesPassed (size_type i) const { return workers_.at(i).timesPassed() ; }
83  int timesFailed (size_type i) const { return workers_.at(i).timesFailed() ; }
84  int timesExcept (size_type i) const { return workers_.at(i).timesExcept() ; }
85  Worker const* getWorker(size_type i) const { return workers_.at(i).getWorker(); }
86 
87  void setEarlyDeleteHelpers(std::map<const Worker*,EarlyDeleteHelper*> const&);
88 
89  void useStopwatch();
90  private:
92  int timesRun_;
96  //int abortWorker_;
98 
99  int bitpos_;
102  boost::shared_ptr<ActivityRegistry> actReg_;
104 
106  std::vector<EarlyDeleteHelper*> earlyDeleteHelpers_;
107 
109 
110  // Helper functions
111  // nwrwue = numWorkersRunWithoutUnhandledException (really!)
113  int nwrwue,
114  bool isEvent,
115  bool begin,
117  CurrentProcessingContext const& cpc,
118  std::string const& id);
119  static void exceptionContext(cms::Exception & ex,
120  bool isEvent,
121  bool begin,
123  CurrentProcessingContext const& cpc,
124  std::string const& id);
125  void recordStatus(int nwrwue, bool isEvent);
126  void updateCounters(bool succeed, bool isEvent);
127 
131  };
132 
133  namespace {
134  template <typename T>
135  class PathSignalSentry {
136  public:
137  PathSignalSentry(ActivityRegistry *a,
138  std::string const& name,
139  int const& nwrwue,
140  hlt::HLTState const& state) :
141  a_(a), name_(name), nwrwue_(nwrwue), state_(state) {
142  if (a_) T::prePathSignal(a_, name_);
143  }
144  ~PathSignalSentry() {
145  HLTPathStatus status(state_, nwrwue_);
146  if(a_) T::postPathSignal(a_, name_, status);
147  }
148  private:
149  ActivityRegistry* a_;
150  std::string const& name_;
151  int const& nwrwue_;
152  hlt::HLTState const& state_;
153  };
154  }
155 
156  template <typename T>
157  void Path::processOneOccurrence(typename T::MyPrincipal& ep, EventSetup const& es) {
158 
159  //Create the PathSignalSentry before the RunStopwatch so that
160  // we only record the time spent in the path not from the signal
161  int nwrwue = -1;
162  PathSignalSentry<T> signaler(actReg_.get(), name_, nwrwue, state_);
163 
164  // A RunStopwatch, but only if we are processing an event.
165  RunStopwatch stopwatch(T::isEvent_ ? stopwatch_ : RunStopwatch::StopwatchPointer());
166 
167  if (T::isEvent_) {
168  ++timesRun_;
169  }
170  state_ = hlt::Ready;
171 
172  // nwrue = numWorkersRunWithoutUnhandledException
173  bool should_continue = true;
175 
177  // It seems likely that 'nwrwue' and 'idx' can never differ ---
178  // if so, we should remove one of them!.
179  for (WorkersInPath::iterator i = workers_.begin(), end = workers_.end();
180  i != end && should_continue;
181  ++i, ++idx) {
182  ++nwrwue;
183  assert (static_cast<int>(idx) == nwrwue);
184  try {
185  try {
186  cpc.activate(idx, i->getWorker()->descPtr());
187  should_continue = i->runWorker<T>(ep, es, &cpc);
188  }
189  catch (cms::Exception& e) { throw; }
190  catch(std::bad_alloc& bda) { convertException::badAllocToEDM(); }
191  catch (std::exception& e) { convertException::stdToEDM(e); }
193  catch(char const* c) { convertException::charPtrToEDM(c); }
194  catch (...) { convertException::unknownToEDM(); }
195  }
196  catch(cms::Exception& ex) {
197  // handleWorkerFailure may throw a new exception.
198  std::ostringstream ost;
199  ost << ep.id();
200  should_continue = handleWorkerFailure(ex, nwrwue, T::isEvent_, T::begin_, T::branchType_, cpc, ost.str());
201  }
202  }
203  if (not should_continue) {
204  handleEarlyFinish(ep);
205  }
206  updateCounters(should_continue, T::isEvent_);
207  recordStatus(nwrwue, T::isEvent_);
208  }
209 
210 }
211 
212 #endif
int i
Definition: DBlmapReader.cc:9
int timesRun() const
Definition: Path.h:73
int bitPosition() const
Definition: Path.h:57
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:13
void recordStatus(int nwrwue, bool isEvent)
Definition: Path.cc:125
void handleEarlyFinish(EventPrincipal &)
Definition: Path.cc:176
not [yet] run
Definition: HLTenums.h:21
roAction_t actions[nactions]
Definition: GenABIO.cc:200
int timesFailed(size_type i) const
Definition: Path.h:83
std::vector< EarlyDeleteHelper * > earlyDeleteHelpers_
Definition: Path.h:106
int timesFailed_
Definition: Path.h:94
std::vector< WorkerInPath > WorkersInPath
Definition: Path.h:43
hlt::HLTState State
Definition: Path.h:41
WorkersInPath::size_type size_type
Definition: Path.h:44
ActionTable const * act_table_
Definition: Path.h:103
std::pair< double, double > timeCpuReal(unsigned int const i) const
Definition: Path.h:67
HLTState
status of a trigger path
Definition: HLTenums.h:21
bool handleWorkerFailure(cms::Exception &e, int nwrwue, bool isEvent, bool begin, BranchType branchType, CurrentProcessingContext const &cpc, std::string const &id)
Definition: Path.cc:35
int timesPassed(size_type i) const
Definition: Path.h:82
int timesExcept() const
Definition: Path.h:76
int timesExcept_
Definition: Path.h:95
size_type size() const
Definition: Path.h:80
State state() const
Definition: Path.h:78
uint16_t size_type
BranchType
Definition: BranchType.h:11
void handleEarlyFinish(RunPrincipal &)
Definition: Path.h:129
std::string name_
Definition: Path.h:100
bool isEndPath_
Definition: Path.h:108
TrigResPtr trptr_
Definition: Path.h:101
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:157
boost::shared_ptr< HLTGlobalStatus > TrigResPtr
Definition: Path.h:45
boost::shared_ptr< CPUTimer > StopwatchPointer
Definition: RunStopwatch.h:23
void stdToEDM(std::exception const &e)
int bitpos_
Definition: Path.h:99
Definition: Path.h:39
int timesPassed() const
Definition: Path.h:74
void handleEarlyFinish(LuminosityBlockPrincipal &)
Definition: Path.h:130
#define end
Definition: vmac.h:38
boost::shared_ptr< ActivityRegistry > actReg_
Definition: Path.h:102
WorkersInPath workers_
Definition: Path.h:105
void charPtrToEDM(char const *c)
void stringToEDM(std::string &s)
void updateCounters(bool succeed, bool isEvent)
Definition: Path.cc:132
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
void useStopwatch()
Definition: Path.cc:149
static void exceptionContext(cms::Exception &ex, bool isEvent, bool begin, BranchType branchType, CurrentProcessingContext const &cpc, std::string const &id)
Definition: Path.cc:79
int timesVisited(size_type i) const
Definition: Path.h:81
std::pair< double, double > timeCpuReal() const
Definition: Path.h:60
void setEarlyDeleteHelpers(std::map< const Worker *, EarlyDeleteHelper * > const &)
Definition: Path.cc:159
RunStopwatch::StopwatchPointer stopwatch_
Definition: Path.h:91
char state
Definition: procUtils.cc:75
State state_
Definition: Path.h:97
std::string const & name() const
Definition: Path.h:58
#define begin
Definition: vmac.h:31
double a
Definition: hdecay.h:121
Worker const * getWorker(size_type i) const
Definition: Path.h:85
tuple status
Definition: ntuplemaker.py:245
int timesExcept(size_type i) const
Definition: Path.h:84
long double T
int timesPassed_
Definition: Path.h:93
int timesRun_
Definition: Path.h:92
void clearCounters()
Definition: Path.cc:143
int timesFailed() const
Definition: Path.h:75