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