CMS 3D CMS Logo

EDLooperBase.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: <package>
4 // Module: EDLooperBase
5 //
6 // Author: Valentin Kuznetsov
7 // Created: Wed Jul 5 11:44:26 EDT 2006
8 
34 
35 namespace edm {
36 
38  : iCounter_(0),
39  act_table_(nullptr),
40  moduleChanger_(nullptr),
41  moduleDescription_("Looper", "looper"),
42  moduleCallingContext_(&moduleDescription_) {}
44 
46 
48  const edm::EventSetupImpl& esi,
49  edm::ProcessingController& ioController,
50  StreamContext* streamContext) {
52  streamContext->setEventID(eventPrincipal.id());
53  streamContext->setRunIndex(eventPrincipal.luminosityBlockPrincipal().runPrincipal().index());
54  streamContext->setLuminosityBlockIndex(eventPrincipal.luminosityBlockPrincipal().index());
55  streamContext->setTimestamp(eventPrincipal.time());
56  ParentContext parentContext(streamContext);
57  ModuleContextSentry moduleContextSentry(&moduleCallingContext_, parentContext);
59  event.setConsumer(this);
60 
62  try {
64  const EventSetup es{
65  esi, static_cast<unsigned int>(Transition::Event), esGetTokenIndices(Transition::Event), parentC};
66  status = duringLoop(event, es, ioController);
67  } catch (cms::Exception& e) {
68  e.addContext("Calling the 'duringLoop' method of a looper");
71  edm::printCmsExceptionWarning("SkipEvent", e);
72  } else {
73  throw;
74  }
75  }
76  return status;
77  }
78 
81  const EventSetup es{
82  esi, static_cast<unsigned int>(Transition::EndRun), esGetTokenIndices(Transition::EndRun), parentC};
83  return endOfLoop(es, iCounter_);
84  }
85 
87  ++iCounter_;
88 
89  std::set<edm::eventsetup::EventSetupRecordKey> const& keys = modifyingRecords();
90  for_all(keys,
91  std::bind(&eventsetup::EventSetupProvider::resetRecordPlusDependentRecords, esp, std::placeholders::_1));
92  }
93 
97  iImpl, static_cast<unsigned int>(Transition::BeginRun), esGetTokenIndices(Transition::BeginRun), parentC});
98  }
101 
103 
104  void EDLooperBase::doBeginRun(RunPrincipal& iRP, EventSetupImpl const& iES, ProcessContext* processContext) {
106  LuminosityBlockID(iRP.run(), 0),
107  iRP.index(),
109  iRP.beginTime(),
110  processContext);
111  ParentContext parentContext(&globalContext);
112  ModuleContextSentry moduleContextSentry(&moduleCallingContext_, parentContext);
114  run.setConsumer(this);
116  const EventSetup es{
117  iES, static_cast<unsigned int>(Transition::BeginRun), esGetTokenIndices(Transition::BeginRun), parentC};
118  beginRun(run, es);
119  }
120 
121  void EDLooperBase::doEndRun(RunPrincipal& iRP, EventSetupImpl const& iES, ProcessContext* processContext) {
123  LuminosityBlockID(iRP.run(), 0),
124  iRP.index(),
126  iRP.endTime(),
127  processContext);
128  ParentContext parentContext(&globalContext);
129  ModuleContextSentry moduleContextSentry(&moduleCallingContext_, parentContext);
131  run.setConsumer(this);
133  const EventSetup es{
134  iES, static_cast<unsigned int>(Transition::EndRun), esGetTokenIndices(Transition::EndRun), parentC};
135  endRun(run, es);
136  }
138  EventSetupImpl const& iES,
139  ProcessContext* processContext) {
141  iLB.id(),
142  iLB.runPrincipal().index(),
143  iLB.index(),
144  iLB.beginTime(),
145  processContext);
146  ParentContext parentContext(&globalContext);
147  ModuleContextSentry moduleContextSentry(&moduleCallingContext_, parentContext);
148  LuminosityBlock luminosityBlock(iLB, moduleDescription_, &moduleCallingContext_, false);
149  luminosityBlock.setConsumer(this);
151  const EventSetup es{iES,
152  static_cast<unsigned int>(Transition::BeginLuminosityBlock),
154  parentC};
155  beginLuminosityBlock(luminosityBlock, es);
156  }
158  EventSetupImpl const& iES,
159  ProcessContext* processContext) {
161  iLB.id(),
162  iLB.runPrincipal().index(),
163  iLB.index(),
164  iLB.beginTime(),
165  processContext);
166  ParentContext parentContext(&globalContext);
167  ModuleContextSentry moduleContextSentry(&moduleCallingContext_, parentContext);
168  LuminosityBlock luminosityBlock(iLB, moduleDescription_, &moduleCallingContext_, true);
169  luminosityBlock.setConsumer(this);
171  const EventSetup es{iES,
172  static_cast<unsigned int>(Transition::EndLuminosityBlock),
174  parentC};
175  endLuminosityBlock(luminosityBlock, es);
176  }
177 
178  void EDLooperBase::beginRun(Run const&, EventSetup const&) {}
179  void EDLooperBase::endRun(Run const&, EventSetup const&) {}
182 
184 
186  ServiceToken const& token,
187  Transition iTrans,
188  Principal const& iPrincipal,
189  EventSetupImpl const& iImpl) const noexcept {
190  esPrefetchAsync(iTask, iImpl, iTrans, token);
191  edPrefetchAsync(std::move(iTask), token, iPrincipal);
192  }
193 
195  ServiceToken const& token,
196  Principal const& iPrincipal) const noexcept {
197  //Based on Worker edPrefetchAsync
198 
199  // Prefetch products the module declares it consumes
200  std::vector<ProductResolverIndexAndSkipBit> const& items = itemsToGetFrom(iPrincipal.branchType());
201 
202  for (auto const& item : items) {
203  ProductResolverIndex productResolverIndex = item.productResolverIndex();
204  bool skipCurrentProcess = item.skipCurrentProcess();
205  if (productResolverIndex != ProductResolverIndexAmbiguous) {
206  iPrincipal.prefetchAsync(iTask, productResolverIndex, skipCurrentProcess, token, &moduleCallingContext_);
207  }
208  }
209  }
210 
212  EventSetupImpl const& iImpl,
213  Transition iTrans,
214  ServiceToken const& iToken) const noexcept {
215  //Based on Worker::esPrefetchAsync
217  return;
218  }
219  auto const& recs = esGetTokenRecordIndicesVector(iTrans);
220  auto const& items = esGetTokenIndicesVector(iTrans);
221 
222  assert(items.size() == recs.size());
223  if (items.empty()) {
224  return;
225  }
226 
227  for (size_t i = 0; i != items.size(); ++i) {
228  if (recs[i] != ESRecordIndex{}) {
229  auto rec = iImpl.findImpl(recs[i]);
230  if (rec) {
231  rec->prefetchAsync(iTask, items[i], &iImpl, iToken, ESParentContext(&moduleCallingContext_));
232  }
233  }
234  }
235  }
236 
237  std::set<eventsetup::EventSetupRecordKey> EDLooperBase::modifyingRecords() const {
238  return std::set<eventsetup::EventSetupRecordKey>();
239  }
240 
241  void EDLooperBase::copyInfo(const ScheduleInfo& iInfo) { scheduleInfo_ = std::make_unique<ScheduleInfo>(iInfo); }
243 
245  const ScheduleInfo* EDLooperBase::scheduleInfo() const { return scheduleInfo_.get(); }
246 
247 } // namespace edm
void prefetchAsync(WaitingTaskHolder iTask, ServiceToken const &token, Transition iTrans, Principal const &iPrincipal, EventSetupImpl const &iImpl) const noexcept
void setConsumer(EDConsumerBase const *iConsumer)
void setTimestamp(Timestamp const &v)
Definition: StreamContext.h:70
Timestamp const & endTime() const
Definition: RunPrincipal.h:69
virtual Status endOfLoop(EventSetup const &, unsigned int iCounter)=0
void doEndLuminosityBlock(LuminosityBlockPrincipal &, EventSetupImpl const &, ProcessContext *)
unsigned int ProductResolverIndex
ModuleCallingContext moduleCallingContext_
Definition: EDLooperBase.h:173
RunPrincipal const & runPrincipal() const
unsigned int iCounter_
Definition: EDLooperBase.h:166
RunNumber_t run() const
Definition: RunPrincipal.h:61
Status doEndOfLoop(EventSetupImpl const &es)
Definition: EDLooperBase.cc:79
Timestamp const & time() const
LuminosityBlockPrincipal const & luminosityBlockPrincipal() const
ScheduleInfo const * scheduleInfo() const
This returns a non-zero value after the constructor has been called.
assert(be >=bs)
virtual Status duringLoop(Event const &, EventSetup const &, ProcessingController &)=0
virtual void beginLuminosityBlock(LuminosityBlock const &, EventSetup const &)
Called after all event modules have processed the begin of a LuminosityBlock.
void setTransition(Transition v)
Definition: StreamContext.h:66
Func for_all(ForwardSequence &s, Func f)
wrapper for std::for_each
Definition: Algorithms.h:14
virtual std::set< eventsetup::EventSetupRecordKey > modifyingRecords() const
Timestamp const & beginTime() const
Definition: RunPrincipal.h:67
ModuleDescription moduleDescription_
Definition: EDLooperBase.h:172
void setLuminosityBlockIndex(LuminosityBlockIndex const &v)
Definition: StreamContext.h:69
ESResolverIndex const * esGetTokenIndices(edm::Transition iTrans) const
Status doDuringLoop(EventPrincipal &eventPrincipal, EventSetupImpl const &es, ProcessingController &, StreamContext *)
Definition: EDLooperBase.cc:47
Transition
Definition: Transition.h:12
void esPrefetchAsync(WaitingTaskHolder iTask, EventSetupImpl const &iImpl, Transition iTrans, ServiceToken const &iToken) const noexcept
RunIndex index() const
Definition: RunPrincipal.h:56
virtual void endOfJob()
void doBeginRun(RunPrincipal &, EventSetupImpl const &, ProcessContext *)
void resetRecordPlusDependentRecords(EventSetupRecordKey const &)
Used when we need to force a Record to reset all its proxies.
Timestamp const & beginTime() const
~EDLooperBase() noexcept(false) override
Definition: EDLooperBase.cc:43
static LuminosityBlockIndex invalidLuminosityBlockIndex()
void setModuleChanger(ModuleChanger *)
edm::propagate_const< std::unique_ptr< ScheduleInfo > > scheduleInfo_
Definition: EDLooperBase.h:169
ExceptionToActionTable const * act_table_
Definition: EDLooperBase.h:167
void copyInfo(ScheduleInfo const &)
void doBeginLuminosityBlock(LuminosityBlockPrincipal &, EventSetupImpl const &, ProcessContext *)
virtual void beginOfJob()
exception_actions::ActionCodes find(const std::string &category) const
virtual void endRun(Run const &, EventSetup const &)
Called after all event modules have processed the end of a Run.
void prepareForNextLoop(eventsetup::EventSetupProvider *esp)
Definition: EDLooperBase.cc:86
virtual void beginRun(Run const &, EventSetup const &)
Called after all event modules have processed the begin of a Run.
virtual void startingNewLoop(unsigned int)=0
void setEventID(EventID const &v)
Definition: StreamContext.h:67
HLT enums.
LuminosityBlockIndex index() const
ModuleChanger * moduleChanger()
This only returns a non-zero value during the call to endOfLoop.
edm::propagate_const< ModuleChanger * > moduleChanger_
Definition: EDLooperBase.h:170
void doEndRun(RunPrincipal &, EventSetupImpl const &, ProcessContext *)
EventID const & id() const
void setRunIndex(RunIndex const &v)
Definition: StreamContext.h:68
virtual void attachTo(ActivityRegistry &)
Override this method if you need to monitor the state of the processing.
void doStartingNewLoop()
Definition: EDLooperBase.cc:45
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1
Definition: Run.h:45
void edPrefetchAsync(WaitingTaskHolder iTask, ServiceToken const &token, Principal const &iPrincipal) const noexcept
void printCmsExceptionWarning(char const *behavior, cms::Exception const &e)
virtual void endLuminosityBlock(LuminosityBlock const &, EventSetup const &)
Called after all event modules have processed the end of a LuminosityBlock.