CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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");
70  if (action != exception_actions::Rethrow) {
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 {
190  esPrefetchAsync(iTask, iImpl, iTrans, token);
191  edPrefetchAsync(std::move(iTask), token, iPrincipal);
192  }
193 
195  ServiceToken const& token,
196  Principal const& iPrincipal) const {
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 {
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
RunPrincipal const & runPrincipal() const
void setConsumer(EDConsumerBase const *iConsumer)
void setTimestamp(Timestamp const &v)
Definition: StreamContext.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:171
Timestamp const & beginTime() const
void prefetchAsync(WaitingTaskHolder iTask, ESProxyIndex iProxyIndex, EventSetupImpl const *, ServiceToken const &, ESParentContext) const
prefetch the data to setup for subsequent calls to getImplementation
unsigned int iCounter_
Definition: EDLooperBase.h:164
EventID const & id() const
list status
Definition: mps_update.py:107
Status doEndOfLoop(EventSetupImpl const &es)
Definition: EDLooperBase.cc:79
std::string const & category() const
Definition: Exception.cc:143
exception_actions::ActionCodes find(const std::string &category) const
LuminosityBlockIndex index() const
std::vector< ESProxyIndex > const & esGetTokenIndicesVector(edm::Transition iTrans) const
RunNumber_t run() const
Definition: RunPrincipal.h:61
assert(be >=bs)
virtual Status duringLoop(Event const &, EventSetup const &, ProcessingController &)=0
virtual std::set< eventsetup::EventSetupRecordKey > modifyingRecords() const
virtual void beginLuminosityBlock(LuminosityBlock const &, EventSetup const &)
Called after all event modules have processed the begin of a LuminosityBlock.
void prefetchAsync(WaitingTaskHolder iTask, ServiceToken const &token, Transition iTrans, Principal const &iPrincipal, EventSetupImpl const &iImpl) const
void setTransition(Transition v)
Definition: StreamContext.h:65
Func for_all(ForwardSequence &s, Func f)
wrapper for std::for_each
Definition: Algorithms.h:14
Timestamp const & time() const
void prefetchAsync(WaitingTaskHolder waitTask, ProductResolverIndex index, bool skipCurrentProcess, ServiceToken const &token, ModuleCallingContext const *mcc) const
Definition: Principal.cc:639
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom(BranchType iType) const
ModuleDescription moduleDescription_
Definition: EDLooperBase.h:170
void setLuminosityBlockIndex(LuminosityBlockIndex const &v)
Definition: StreamContext.h:68
LuminosityBlockPrincipal const & luminosityBlockPrincipal() const
Timestamp const & beginTime() const
Definition: RunPrincipal.h:67
BranchType const & branchType() const
Definition: Principal.h:181
Status doDuringLoop(EventPrincipal &eventPrincipal, EventSetupImpl const &es, ProcessingController &, StreamContext *)
Definition: EDLooperBase.cc:47
def move
Definition: eostools.py:511
Timestamp const & endTime() const
Definition: RunPrincipal.h:69
Transition
Definition: Transition.h:12
void edPrefetchAsync(WaitingTaskHolder iTask, ServiceToken const &token, Principal const &iPrincipal) const
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.
~EDLooperBase() noexcept(false) override
Definition: EDLooperBase.cc:43
ScheduleInfo const * scheduleInfo() const
This returns a non-zero value after the constructor has been called.
static LuminosityBlockIndex invalidLuminosityBlockIndex()
void setModuleChanger(ModuleChanger *)
edm::propagate_const< std::unique_ptr< ScheduleInfo > > scheduleInfo_
Definition: EDLooperBase.h:167
ExceptionToActionTable const * act_table_
Definition: EDLooperBase.h:165
void copyInfo(ScheduleInfo const &)
void doBeginLuminosityBlock(LuminosityBlockPrincipal &, EventSetupImpl const &, ProcessContext *)
virtual void beginOfJob()
void addContext(std::string const &context)
Definition: Exception.cc:165
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.
string action
Definition: mps_fire.py:183
RunIndex index() const
Definition: RunPrincipal.h:57
virtual void startingNewLoop(unsigned int)=0
void setEventID(EventID const &v)
Definition: StreamContext.h:66
std::vector< ESRecordIndex > const & esGetTokenRecordIndicesVector(edm::Transition iTrans) const
void esPrefetchAsync(WaitingTaskHolder iTask, EventSetupImpl const &iImpl, Transition iTrans, ServiceToken const &iToken) const
ModuleChanger * moduleChanger()
This only returns a non-zero value during the call to endOfLoop.
edm::propagate_const< ModuleChanger * > moduleChanger_
Definition: EDLooperBase.h:168
void doEndRun(RunPrincipal &, EventSetupImpl const &, ProcessContext *)
void setConsumer(EDConsumerBase const *iConsumer)
Definition: Run.h:52
eventsetup::EventSetupRecordImpl const * findImpl(const eventsetup::EventSetupRecordKey &) const
void setRunIndex(RunIndex const &v)
Definition: StreamContext.h:67
virtual void attachTo(ActivityRegistry &)
Override this method if you need to monitor the state of the processing.
void doStartingNewLoop()
Definition: EDLooperBase.cc:45
Definition: Run.h:45
void printCmsExceptionWarning(char const *behavior, cms::Exception const &e)
ESProxyIndex const * esGetTokenIndices(edm::Transition iTrans) const
virtual void endLuminosityBlock(LuminosityBlock const &, EventSetup const &)
Called after all event modules have processed the end of a LuminosityBlock.