CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Path.cc
Go to the documentation of this file.
1 
8 
9 #include <algorithm>
10 #include "boost/bind.hpp"
11 
12 namespace edm {
13  Path::Path(int bitpos, std::string const& path_name,
14  WorkersInPath const& workers,
15  TrigResPtr trptr,
17  boost::shared_ptr<ActivityRegistry> areg,
18  StreamContext const* streamContext,
19  PathContext::PathType pathType) :
20  stopwatch_(),
21  timesRun_(),
22  timesPassed_(),
23  timesFailed_(),
24  timesExcept_(),
25  state_(hlt::Ready),
26  bitpos_(bitpos),
27  name_(path_name),
28  trptr_(trptr),
29  actReg_(areg),
30  act_table_(&actions),
31  workers_(workers),
32  pathContext_(path_name, streamContext, bitpos, pathType) {
33 
34  for (auto& workerInPath : workers_) {
35  workerInPath.setPathContext(&pathContext_);
36  }
37  }
38 
39  Path::Path(Path const& r) :
40  stopwatch_(r.stopwatch_),
41  timesRun_(r.timesRun_),
42  timesPassed_(r.timesPassed_),
43  timesFailed_(r.timesFailed_),
44  timesExcept_(r.timesExcept_),
45  state_(r.state_),
46  bitpos_(r.bitpos_),
47  name_(r.name_),
48  trptr_(r.trptr_),
49  actReg_(r.actReg_),
50  act_table_(r.act_table_),
51  workers_(r.workers_),
52  earlyDeleteHelpers_(r.earlyDeleteHelpers_),
53  pathContext_(r.pathContext_) {
54 
55  for (auto& workerInPath : workers_) {
56  workerInPath.setPathContext(&pathContext_);
57  }
58  }
59 
60 
61  bool
63  int nwrwue,
64  bool isEvent,
65  bool begin,
67  ModuleDescription const& desc,
68  std::string const& id) {
69 
70  exceptionContext(e, isEvent, begin, branchType, desc, id, pathContext_);
71 
72  bool should_continue = true;
73 
74  // there is no support as of yet for specific paths having
75  // different exception behavior
76 
77  // If not processing an event, always rethrow.
79  switch(action) {
81  should_continue = false;
82  edm::printCmsExceptionWarning("FailPath", e);
83  break;
84  }
85  default: {
86  if (isEvent) ++timesExcept_;
88  recordStatus(nwrwue, isEvent);
89  if (action == exception_actions::Rethrow) {
91  if (e.category() == pNF) {
92  std::ostringstream ost;
93  ost << "If you wish to continue processing events after a " << pNF << " exception,\n" <<
94  "add \"SkipEvent = cms.untracked.vstring('ProductNotFound')\" to the \"options\" PSet in the configuration.\n";
95  e.addAdditionalInfo(ost.str());
96  }
97  }
98  throw;
99  }
100  }
101 
102  return should_continue;
103  }
104 
105  void
107  bool isEvent,
108  bool begin,
110  ModuleDescription const& desc,
111  std::string const& id,
112  PathContext const& pathContext) {
113  std::ostringstream ost;
114  if (isEvent) {
115  ost << "Calling event method";
116  }
117  else if (begin && branchType == InRun) {
118  ost << "Calling beginRun";
119  }
120  else if (begin && branchType == InLumi) {
121  ost << "Calling beginLuminosityBlock";
122  }
123  else if (!begin && branchType == InLumi) {
124  ost << "Calling endLuminosityBlock";
125  }
126  else if (!begin && branchType == InRun) {
127  ost << "Calling endRun";
128  }
129  else {
130  // It should be impossible to get here ...
131  ost << "Calling unknown function";
132  }
133  ost << " for module " << desc.moduleName() << "/'" << desc.moduleLabel() << "'";
134  ex.addContext(ost.str());
135  ost.str("");
136  ost << "Running path '" << pathContext.pathName() << "'";
137  ex.addContext(ost.str());
138  ost.str("");
139  ost << "Processing ";
140  ost << id;
141  ex.addContext(ost.str());
142  }
143 
144  void
145  Path::recordStatus(int nwrwue, bool isEvent) {
146  if(isEvent && trptr_) {
147  (*trptr_)[bitpos_]=HLTPathStatus(state_, nwrwue);
148  }
149  }
150 
151  void
152  Path::updateCounters(bool success, bool isEvent) {
153  if (success) {
154  if (isEvent) ++timesPassed_;
155  state_ = hlt::Pass;
156  } else {
157  if(isEvent) ++timesFailed_;
158  state_ = hlt::Fail;
159  }
160  }
161 
162  void
165  for_all(workers_, boost::bind(&WorkerInPath::clearCounters, _1));
166  }
167 
168  void
170  stopwatch_.reset(new RunStopwatch::StopwatchPointer::element_type);
171  for(WorkersInPath::iterator it=workers_.begin(), itEnd = workers_.end();
172  it != itEnd;
173  ++it) {
174  it->useStopwatch();
175  }
176  }
177 
178  void
179  Path::setEarlyDeleteHelpers(std::map<const Worker*,EarlyDeleteHelper*> const& iWorkerToDeleter) {
180  //we use a temp so we can overset the size but then when moving to earlyDeleteHelpers we only
181  // have to use the space necessary
182  std::vector<EarlyDeleteHelper*> temp;
183  temp.reserve(iWorkerToDeleter.size());
184  for(unsigned int index=0; index !=size();++index) {
185  auto found = iWorkerToDeleter.find(getWorker(index));
186  if(found != iWorkerToDeleter.end()) {
187  temp.push_back(found->second);
188  found->second->addedToPath();
189  }
190  }
191  std::vector<EarlyDeleteHelper*> tempCorrectSize(temp.begin(),temp.end());
192  earlyDeleteHelpers_.swap(tempCorrectSize);
193  }
194 
195  void
197  for(auto helper: earlyDeleteHelpers_) {
198  helper->pathFinished(iEvent);
199  }
200  }
201 
202 }
std::string const & pathName() const
Definition: PathContext.h:37
void recordStatus(int nwrwue, bool isEvent)
Definition: Path.cc:145
void handleEarlyFinish(EventPrincipal &)
Definition: Path.cc:196
not [yet] run
Definition: HLTenums.h:18
std::vector< EarlyDeleteHelper * > earlyDeleteHelpers_
Definition: Path.h:118
int timesFailed_
Definition: Path.h:106
std::vector< WorkerInPath > WorkersInPath
Definition: Path.h:46
reject
Definition: HLTenums.h:20
std::string const & moduleName() const
std::string const & category() const
Definition: Exception.cc:183
exception_actions::ActionCodes find(const std::string &category) const
int timesExcept_
Definition: Path.h:107
PathContext pathContext_
Definition: Path.h:120
size_type size() const
Definition: Path.h:87
actions
Definition: Schedule.cc:362
std::string const & moduleLabel() const
BranchType
Definition: BranchType.h:11
Func for_all(ForwardSequence &s, Func f)
wrapper for std::for_each
Definition: Algorithms.h:16
TrigResPtr trptr_
Definition: Path.h:113
int iEvent
Definition: GenABIO.cc:243
boost::shared_ptr< HLTGlobalStatus > TrigResPtr
Definition: Path.h:48
accept
Definition: HLTenums.h:19
int bitpos_
Definition: Path.h:111
Definition: Path.h:42
void printCmsExceptionWarning(char const *behavior, cms::Exception const &e, edm::JobReport *jobRep=0, int rc=-1)
void addAdditionalInfo(std::string const &info)
Definition: Exception.cc:235
static std::string codeToString(Code)
-----------— implementation details ---------------—
Definition: EDMException.cc:55
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
areg
Definition: Schedule.cc:362
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 updateCounters(bool succeed, bool isEvent)
Definition: Path.cc:152
void useStopwatch()
Definition: Path.cc:169
void addContext(std::string const &context)
Definition: Exception.cc:227
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
State state_
Definition: Path.h:109
#define begin
Definition: vmac.h:30
Worker const * getWorker(size_type i) const
Definition: Path.h:92
int timesPassed_
Definition: Path.h:105
int timesRun_
Definition: Path.h:104
void clearCounters()
Definition: Path.cc:163