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  }
70 
72  ExceptionToActionTable const* iActions) :
73  stopwatch_(),
74  timesRun_(),
75  timesVisited_(),
76  timesPassed_(),
77  timesFailed_(),
78  timesExcept_(),
79  state_(Ready),
80  moduleCallingContext_(&iMD),
81  actions_(iActions),
82  cached_exception_(),
83  actReg_(),
84  earlyDeleteHelper_(nullptr)
85  {
86  }
87 
89  }
90 
91  void Worker::setActivityRegistry(boost::shared_ptr<ActivityRegistry> areg) {
92  actReg_ = areg;
93  }
94 
96  earlyDeleteHelper_=iHelper;
97  }
98 
103  }
104 
106  try {
107  convertException::wrap([&]() {
108  ModuleBeginJobSignalSentry cpp(actReg_.get(), description());
109  implBeginJob();
110  });
111  }
112  catch(cms::Exception& ex) {
113  state_ = Exception;
114  std::ostringstream ost;
115  ost << "Calling beginJob for module " << description().moduleName() << "/'" << description().moduleLabel() << "'";
116  ex.addContext(ost.str());
117  throw;
118  }
119  }
120 
121  void Worker::endJob() {
122  try {
123  convertException::wrap([&]() {
124  ModuleEndJobSignalSentry cpp(actReg_.get(), description());
125  implEndJob();
126  });
127  }
128  catch(cms::Exception& ex) {
129  state_ = Exception;
130  std::ostringstream ost;
131  ost << "Calling endJob for module " << description().moduleName() << "/'" << description().moduleLabel() << "'";
132  ex.addContext(ost.str());
133  throw;
134  }
135  }
136 
137  void Worker::beginStream(StreamID id, StreamContext& streamContext) {
138  try {
139  convertException::wrap([&]() {
141  streamContext.setEventID(EventID(0, 0, 0));
142  streamContext.setRunIndex(RunIndex::invalidRunIndex());
144  streamContext.setTimestamp(Timestamp());
145  ParentContext parentContext(&streamContext);
146  ModuleContextSentry moduleContextSentry(&moduleCallingContext_, parentContext);
148  ModuleBeginStreamSignalSentry beginSentry(actReg_.get(), streamContext, moduleCallingContext_);
149  implBeginStream(id);
150  });
151  }
152  catch(cms::Exception& ex) {
153  state_ = Exception;
154  std::ostringstream ost;
155  ost << "Calling beginStream for module " << description().moduleName() << "/'" << description().moduleLabel() << "'";
156  ex.addContext(ost.str());
157  throw;
158  }
159  }
160 
161  void Worker::endStream(StreamID id, StreamContext& streamContext) {
162  try {
163  convertException::wrap([&]() {
165  streamContext.setEventID(EventID(0, 0, 0));
166  streamContext.setRunIndex(RunIndex::invalidRunIndex());
168  streamContext.setTimestamp(Timestamp());
169  ParentContext parentContext(&streamContext);
170  ModuleContextSentry moduleContextSentry(&moduleCallingContext_, parentContext);
172  ModuleEndStreamSignalSentry endSentry(actReg_.get(), streamContext, moduleCallingContext_);
173  implEndStream(id);
174  });
175  }
176  catch(cms::Exception& ex) {
177  state_ = Exception;
178  std::ostringstream ost;
179  ost << "Calling endStream for module " << description().moduleName() << "/'" << description().moduleLabel() << "'";
180  ex.addContext(ost.str());
181  throw;
182  }
183  }
184 
186  stopwatch_.reset(new RunStopwatch::StopwatchPointer::element_type);
187  }
188 
190  if(earlyDeleteHelper_) {
192  }
193  }
195  if(earlyDeleteHelper_) {
196  earlyDeleteHelper_->moduleRan(iEvent);
197  }
198  }
199 }
void pathFinished(EventPrincipal &)
Definition: Worker.cc:189
void resetModuleDescription(ModuleDescription const *)
Definition: Worker.cc:99
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:95
virtual ~Worker()
Definition: Worker.cc:88
void endJob()
Definition: Worker.cc:121
boost::shared_ptr< ActivityRegistry > actReg_
Definition: Worker.h:189
#define nullptr
void setActivityRegistry(boost::shared_ptr< ActivityRegistry > areg)
Definition: Worker.cc:91
std::string const & moduleName() const
void beginStream(StreamID id, StreamContext &streamContext)
Definition: Worker.cc:137
std::string const & moduleLabel() const
EarlyDeleteHelper * earlyDeleteHelper_
Definition: Worker.h:191
ParentContext const & parent() const
ModuleCallingContext moduleCallingContext_
Definition: Worker.h:184
void setTransition(Transition v)
Definition: StreamContext.h:65
static RunIndex invalidRunIndex()
Definition: RunIndex.cc:9
int iEvent
Definition: GenABIO.cc:230
void setLuminosityBlockIndex(LuminosityBlockIndex const &v)
Definition: StreamContext.h:68
void useStopwatch()
Definition: Worker.cc:185
Worker(ModuleDescription const &iMD, ExceptionToActionTable const *iActions)
Definition: Worker.cc:71
virtual void implEndJob()=0
void moduleRan(EventPrincipal &)
static LuminosityBlockIndex invalidLuminosityBlockIndex()
areg
Definition: Schedule.cc:369
void postDoEvent(EventPrincipal &)
Definition: Worker.cc:194
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:105
void endStream(StreamID id, StreamContext &streamContext)
Definition: Worker.cc:161
RunStopwatch::StopwatchPointer stopwatch_
Definition: Worker.h:175
auto wrap(F iFunc) -> decltype(iFunc())
void setRunIndex(RunIndex const &v)
Definition: StreamContext.h:67
State state_
Definition: Worker.h:182
void pathFinished(EventPrincipal &)