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  trptr_(trptr),
28  actReg_(areg),
29  act_table_(&actions),
30  workers_(workers),
31  pathContext_(path_name, streamContext, bitpos, pathType) {
32 
33  for (auto& workerInPath : workers_) {
34  workerInPath.setPathContext(&pathContext_);
35  }
36  }
37 
38  Path::Path(Path const& r) :
39  stopwatch_(r.stopwatch_),
40  timesRun_(r.timesRun_),
41  timesPassed_(r.timesPassed_),
42  timesFailed_(r.timesFailed_),
43  timesExcept_(r.timesExcept_),
44  state_(r.state_),
45  bitpos_(r.bitpos_),
46  trptr_(r.trptr_),
47  actReg_(r.actReg_),
48  act_table_(r.act_table_),
49  workers_(r.workers_),
50  earlyDeleteHelpers_(r.earlyDeleteHelpers_),
51  pathContext_(r.pathContext_) {
52 
53  for (auto& workerInPath : workers_) {
54  workerInPath.setPathContext(&pathContext_);
55  }
56  }
57 
58 
59  bool
61  int nwrwue,
62  bool isEvent,
63  bool begin,
65  ModuleDescription const& desc,
66  std::string const& id) {
67 
68  exceptionContext(e, isEvent, begin, branchType, desc, id, pathContext_);
69 
70  bool should_continue = true;
71 
72  // there is no support as of yet for specific paths having
73  // different exception behavior
74 
75  // If not processing an event, always rethrow.
77  switch(action) {
79  should_continue = false;
80  edm::printCmsExceptionWarning("FailPath", e);
81  break;
82  }
83  default: {
84  if (isEvent) ++timesExcept_;
86  recordStatus(nwrwue, isEvent);
87  if (action == exception_actions::Rethrow) {
89  if (e.category() == pNF) {
90  std::ostringstream ost;
91  ost << "If you wish to continue processing events after a " << pNF << " exception,\n" <<
92  "add \"SkipEvent = cms.untracked.vstring('ProductNotFound')\" to the \"options\" PSet in the configuration.\n";
93  e.addAdditionalInfo(ost.str());
94  }
95  }
96  throw;
97  }
98  }
99 
100  return should_continue;
101  }
102 
103  void
105  bool isEvent,
106  bool begin,
108  ModuleDescription const& desc,
109  std::string const& id,
110  PathContext const& pathContext) {
111  std::ostringstream ost;
112  if (isEvent) {
113  ost << "Calling event method";
114  }
115  else if (begin && branchType == InRun) {
116  ost << "Calling beginRun";
117  }
118  else if (begin && branchType == InLumi) {
119  ost << "Calling beginLuminosityBlock";
120  }
121  else if (!begin && branchType == InLumi) {
122  ost << "Calling endLuminosityBlock";
123  }
124  else if (!begin && branchType == InRun) {
125  ost << "Calling endRun";
126  }
127  else {
128  // It should be impossible to get here ...
129  ost << "Calling unknown function";
130  }
131  ost << " for module " << desc.moduleName() << "/'" << desc.moduleLabel() << "'";
132  ex.addContext(ost.str());
133  ost.str("");
134  ost << "Running path '" << pathContext.pathName() << "'";
135  ex.addContext(ost.str());
136  ost.str("");
137  ost << "Processing ";
138  ost << id;
139  ex.addContext(ost.str());
140  }
141 
142  void
143  Path::recordStatus(int nwrwue, bool isEvent) {
144  if(isEvent && trptr_) {
145  (*trptr_)[bitpos_]=HLTPathStatus(state_, nwrwue);
146  }
147  }
148 
149  void
150  Path::updateCounters(bool success, bool isEvent) {
151  if (success) {
152  if (isEvent) ++timesPassed_;
153  state_ = hlt::Pass;
154  } else {
155  if(isEvent) ++timesFailed_;
156  state_ = hlt::Fail;
157  }
158  }
159 
160  void
163  for_all(workers_, boost::bind(&WorkerInPath::clearCounters, _1));
164  }
165 
166  void
168  stopwatch_.reset(new RunStopwatch::StopwatchPointer::element_type);
169  for(WorkersInPath::iterator it=workers_.begin(), itEnd = workers_.end();
170  it != itEnd;
171  ++it) {
172  it->useStopwatch();
173  }
174  }
175 
176  void
177  Path::setEarlyDeleteHelpers(std::map<const Worker*,EarlyDeleteHelper*> const& iWorkerToDeleter) {
178  //we use a temp so we can overset the size but then when moving to earlyDeleteHelpers we only
179  // have to use the space necessary
180  std::vector<EarlyDeleteHelper*> temp;
181  temp.reserve(iWorkerToDeleter.size());
182  for(unsigned int index=0; index !=size();++index) {
183  auto found = iWorkerToDeleter.find(getWorker(index));
184  if(found != iWorkerToDeleter.end()) {
185  temp.push_back(found->second);
186  found->second->addedToPath();
187  }
188  }
189  std::vector<EarlyDeleteHelper*> tempCorrectSize(temp.begin(),temp.end());
190  earlyDeleteHelpers_.swap(tempCorrectSize);
191  }
192 
193  void
195  for(auto helper: earlyDeleteHelpers_) {
196  helper->pathFinished(iEvent);
197  }
198  }
199 
200 }
std::string const & pathName() const
Definition: PathContext.h:37
void recordStatus(int nwrwue, bool isEvent)
Definition: Path.cc:143
void handleEarlyFinish(EventPrincipal &)
Definition: Path.cc:194
not [yet] run
Definition: HLTenums.h:18
std::vector< EarlyDeleteHelper * > earlyDeleteHelpers_
Definition: Path.h:117
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:119
size_type size() const
Definition: Path.h:87
actions
Definition: Schedule.cc:369
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:112
int iEvent
Definition: GenABIO.cc:230
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:56
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:369
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
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: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
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:161