CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Worker.cc
Go to the documentation of this file.
1 
2 /*----------------------------------------------------------------------
3 ----------------------------------------------------------------------*/
4 
8 
9 namespace edm {
10  namespace {
11  class ModuleBeginJobSignalSentry {
12 public:
13  ModuleBeginJobSignalSentry(ActivityRegistry* a, ModuleDescription const& md):a_(a), md_(&md) {
14  if(a_) a_->preModuleBeginJobSignal_(*md_);
15  }
16  ~ModuleBeginJobSignalSentry() {
17  if(a_) a_->postModuleBeginJobSignal_(*md_);
18  }
19 private:
20  ActivityRegistry* a_;
21  ModuleDescription const* md_;
22  };
23 
24  class ModuleEndJobSignalSentry {
25 public:
26  ModuleEndJobSignalSentry(ActivityRegistry* a, ModuleDescription const& md):a_(a), md_(&md) {
27  if(a_) a_->preModuleEndJobSignal_(*md_);
28  }
29  ~ModuleEndJobSignalSentry() {
30  if(a_) a_->postModuleEndJobSignal_(*md_);
31  }
32 private:
33  ActivityRegistry* a_;
34  ModuleDescription const* md_;
35  };
36 
37  class ModuleBeginStreamSignalSentry {
38  public:
39  ModuleBeginStreamSignalSentry(ActivityRegistry* a,
40  StreamContext const& sc,
41  ModuleCallingContext const& mcc) : a_(a), sc_(sc), mcc_(mcc) {
42  if(a_) a_->preModuleBeginStreamSignal_(sc_, mcc_);
43  }
44  ~ModuleBeginStreamSignalSentry() {
45  if(a_) a_->postModuleBeginStreamSignal_(sc_, mcc_);
46  }
47  private:
48  ActivityRegistry* a_;
49  StreamContext const& sc_;
50  ModuleCallingContext const& mcc_;
51  };
52 
53  class ModuleEndStreamSignalSentry {
54  public:
55  ModuleEndStreamSignalSentry(ActivityRegistry* a,
56  StreamContext const& sc,
57  ModuleCallingContext const& mcc) : a_(a), sc_(sc), mcc_(mcc) {
58  if(a_) a_->preModuleEndStreamSignal_(sc_, mcc_);
59  }
60  ~ModuleEndStreamSignalSentry() {
61  if(a_) a_->postModuleEndStreamSignal_(sc_, mcc_);
62  }
63  private:
64  ActivityRegistry* a_;
65  StreamContext const& sc_;
66  ModuleCallingContext const& mcc_;
67  };
68 
69  cms::Exception& exceptionContext(ModuleDescription const& iMD,
70  cms::Exception& iEx) {
71  iEx << iMD.moduleName() << "/" << iMD.moduleLabel() << "\n";
72  return iEx;
73  }
74 
75  }
76 
78  ExceptionToActionTable const* iActions) :
79  stopwatch_(),
80  timesRun_(),
81  timesVisited_(),
82  timesPassed_(),
83  timesFailed_(),
84  timesExcept_(),
85  state_(Ready),
86  moduleCallingContext_(&iMD),
87  actions_(iActions),
88  cached_exception_(),
89  actReg_(),
90  earlyDeleteHelper_(nullptr)
91  {
92  }
93 
95  }
96 
97  void Worker::setActivityRegistry(boost::shared_ptr<ActivityRegistry> areg) {
98  actReg_ = areg;
99  }
100 
102  earlyDeleteHelper_=iHelper;
103  }
104 
109  }
110 
112  try {
113  try {
114  ModuleBeginJobSignalSentry cpp(actReg_.get(), description());
115  implBeginJob();
116  }
117  catch (cms::Exception& e) { throw; }
118  catch(std::bad_alloc& bda) { convertException::badAllocToEDM(); }
119  catch (std::exception& e) { convertException::stdToEDM(e); }
121  catch(char const* c) { convertException::charPtrToEDM(c); }
122  catch (...) { convertException::unknownToEDM(); }
123  }
124  catch(cms::Exception& ex) {
125  state_ = Exception;
126  std::ostringstream ost;
127  ost << "Calling beginJob for module " << description().moduleName() << "/'" << description().moduleLabel() << "'";
128  ex.addContext(ost.str());
129  throw;
130  }
131  }
132 
133  void Worker::endJob() {
134  try {
135  try {
136  ModuleEndJobSignalSentry cpp(actReg_.get(), description());
137  implEndJob();
138  }
139  catch (cms::Exception& e) { throw; }
140  catch(std::bad_alloc& bda) { convertException::badAllocToEDM(); }
141  catch (std::exception& e) { convertException::stdToEDM(e); }
143  catch(char const* c) { convertException::charPtrToEDM(c); }
144  catch (...) { convertException::unknownToEDM(); }
145  }
146  catch(cms::Exception& ex) {
147  state_ = Exception;
148  std::ostringstream ost;
149  ost << "Calling endJob for module " << description().moduleName() << "/'" << description().moduleLabel() << "'";
150  ex.addContext(ost.str());
151  throw;
152  }
153  }
154 
155  void Worker::beginStream(StreamID id, StreamContext& streamContext) {
156  try {
157  try {
159  streamContext.setEventID(EventID(0, 0, 0));
160  streamContext.setRunIndex(RunIndex::invalidRunIndex());
162  streamContext.setTimestamp(Timestamp());
163  ParentContext parentContext(&streamContext);
164  ModuleContextSentry moduleContextSentry(&moduleCallingContext_, parentContext);
166  ModuleBeginStreamSignalSentry beginSentry(actReg_.get(), streamContext, moduleCallingContext_);
167  implBeginStream(id);
168  }
169  catch (cms::Exception& e) { throw; }
170  catch(std::bad_alloc& bda) { convertException::badAllocToEDM(); }
171  catch (std::exception& e) { convertException::stdToEDM(e); }
173  catch(char const* c) { convertException::charPtrToEDM(c); }
174  catch (...) { convertException::unknownToEDM(); }
175  }
176  catch(cms::Exception& ex) {
177  state_ = Exception;
178  std::ostringstream ost;
179  ost << "Calling beginStream for module " << description().moduleName() << "/'" << description().moduleLabel() << "'";
180  ex.addContext(ost.str());
181  throw;
182  }
183  }
184 
185  void Worker::endStream(StreamID id, StreamContext& streamContext) {
186  try {
187  try {
189  streamContext.setEventID(EventID(0, 0, 0));
190  streamContext.setRunIndex(RunIndex::invalidRunIndex());
192  streamContext.setTimestamp(Timestamp());
193  ParentContext parentContext(&streamContext);
194  ModuleContextSentry moduleContextSentry(&moduleCallingContext_, parentContext);
196  ModuleEndStreamSignalSentry endSentry(actReg_.get(), streamContext, moduleCallingContext_);
197  implEndStream(id);
198  }
199  catch (cms::Exception& e) { throw; }
200  catch(std::bad_alloc& bda) { convertException::badAllocToEDM(); }
201  catch (std::exception& e) { convertException::stdToEDM(e); }
203  catch(char const* c) { convertException::charPtrToEDM(c); }
204  catch (...) { convertException::unknownToEDM(); }
205  }
206  catch(cms::Exception& ex) {
207  state_ = Exception;
208  std::ostringstream ost;
209  ost << "Calling endStream for module " << description().moduleName() << "/'" << description().moduleLabel() << "'";
210  ex.addContext(ost.str());
211  throw;
212  }
213  }
214 
216  stopwatch_.reset(new RunStopwatch::StopwatchPointer::element_type);
217  }
218 
220  if(earlyDeleteHelper_) {
222  }
223  }
225  if(earlyDeleteHelper_) {
226  earlyDeleteHelper_->moduleRan(iEvent);
227  }
228  }
229 }
void pathFinished(EventPrincipal &)
Definition: Worker.cc:219
void resetModuleDescription(ModuleDescription const *)
Definition: Worker.cc:105
void setTimestamp(Timestamp const &v)
Definition: StreamContext.h:69
ModuleDescription const & description() const
Definition: Worker.h:97
not [yet] run
Definition: HLTenums.h:18
void setEarlyDeleteHelper(EarlyDeleteHelper *iHelper)
Definition: Worker.cc:101
virtual ~Worker()
Definition: Worker.cc:94
void endJob()
Definition: Worker.cc:133
boost::shared_ptr< ActivityRegistry > actReg_
Definition: Worker.h:186
#define nullptr
void setActivityRegistry(boost::shared_ptr< ActivityRegistry > areg)
Definition: Worker.cc:97
std::string const & moduleName() const
void beginStream(StreamID id, StreamContext &streamContext)
Definition: Worker.cc:155
std::string const & moduleLabel() const
EarlyDeleteHelper * earlyDeleteHelper_
Definition: Worker.h:188
ParentContext const & parent() const
ModuleCallingContext moduleCallingContext_
Definition: Worker.h:181
void setTransition(Transition v)
Definition: StreamContext.h:65
static RunIndex invalidRunIndex()
Definition: RunIndex.cc:9
int iEvent
Definition: GenABIO.cc:243
void setLuminosityBlockIndex(LuminosityBlockIndex const &v)
Definition: StreamContext.h:68
void stdToEDM(std::exception const &e)
void useStopwatch()
Definition: Worker.cc:215
Worker(ModuleDescription const &iMD, ExceptionToActionTable const *iActions)
Definition: Worker.cc:77
virtual void implEndJob()=0
void moduleRan(EventPrincipal &)
static LuminosityBlockIndex invalidLuminosityBlockIndex()
areg
Definition: Schedule.cc:362
void postDoEvent(EventPrincipal &)
Definition: Worker.cc:224
void charPtrToEDM(char const *c)
void stringToEDM(std::string &s)
virtual void implBeginJob()=0
void addContext(std::string const &context)
Definition: Exception.cc:227
virtual void implBeginStream(StreamID)=0
virtual void implEndStream(StreamID)=0
void setEventID(EventID const &v)
Definition: StreamContext.h:66
ModuleCallingContext const * previousModuleOnThread() const
double a
Definition: hdecay.h:121
void beginJob()
Definition: Worker.cc:111
void endStream(StreamID id, StreamContext &streamContext)
Definition: Worker.cc:185
RunStopwatch::StopwatchPointer stopwatch_
Definition: Worker.h:172
void setRunIndex(RunIndex const &v)
Definition: StreamContext.h:67
State state_
Definition: Worker.h:179
void pathFinished(EventPrincipal &)