CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
edm::InputProductResolver Class Reference

#include <ProductResolvers.h>

Inheritance diagram for edm::InputProductResolver:
edm::DataManagingProductResolver edm::DataManagingOrAliasProductResolver edm::ProductResolverBase

Public Member Functions

 InputProductResolver (std::shared_ptr< BranchDescription const > bd)
 
void setupUnscheduled (UnscheduledConfigurator const &) final
 
- Public Member Functions inherited from edm::DataManagingProductResolver
void connectTo (ProductResolverBase const &, Principal const *) final
 
 DataManagingProductResolver (std::shared_ptr< BranchDescription const > bd, ProductStatus iDefaultStatus)
 
void resetStatus ()
 
template<bool callResolver, typename FUNC >
ProductResolverBase::Resolution resolveProductImpl (FUNC resolver) const
 
- Public Member Functions inherited from edm::DataManagingOrAliasProductResolver
 DataManagingOrAliasProductResolver ()
 
- Public Member Functions inherited from edm::ProductResolverBase
BranchDescription const & branchDescription () const
 
std::string const & moduleLabel () const
 
ProductResolverBaseoperator= (ProductResolverBase const &)=delete
 
void prefetchAsync (WaitingTask *waitTask, Principal const &principal, bool skipCurrentProcess, ServiceToken const &token, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const
 
std::string const & processName () const
 
ProductID const & productID () const
 
std::string const & productInstanceName () const
 
ProductProvenance const * productProvenancePtr () const
 
bool productResolved () const
 
 ProductResolverBase ()
 
 ProductResolverBase (ProductResolverBase const &)=delete
 
TypeID productType () const
 
bool productUnavailable () const
 
bool productWasDeleted () const
 
bool productWasFetchedAndIsValid (bool iSkipCurrentProcess) const
 
Provenance const * provenance () const
 
bool provenanceAvailable () const
 
void putOrMergeProduct (std::unique_ptr< WrapperBase > edp, MergeableRunProductMetadata const *mergeableRunProductMetadata=nullptr) const
 
void putProduct (std::unique_ptr< WrapperBase > edp) const
 
void resetBranchDescription (std::shared_ptr< BranchDescription const > bd)
 
void resetProductData ()
 
std::string const & resolvedModuleLabel () const
 
Resolution resolveProduct (Principal const &principal, bool skipCurrentProcess, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const
 
void retrieveAndMerge (Principal const &principal, MergeableRunProductMetadata const *mergeableRunProductMetadata) const
 
void setMergeableRunProductMetadata (MergeableRunProductMetadata const *mrpm)
 
void setProcessHistory (ProcessHistory const &ph)
 
void setProvenance (ProductProvenanceRetriever const *provRetriever, ProcessHistory const &ph, ProductID const &pid)
 
bool singleProduct () const
 
StableProvenance const * stableProvenance () const
 
void unsafe_deleteProduct () const
 
bool unscheduledWasNotRun () const
 
void write (std::ostream &os) const
 
virtual ~ProductResolverBase ()
 

Private Member Functions

bool isFromCurrentProcess () const final
 
void prefetchAsync_ (WaitingTask *waitTask, Principal const &principal, bool skipCurrentProcess, ServiceToken const &token, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const override
 
void putProduct_ (std::unique_ptr< WrapperBase > edp) const override
 
void resetProductData_ (bool deleteEarly) override
 
Resolution resolveProduct_ (Principal const &principal, bool skipCurrentProcess, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const override
 
void retrieveAndMerge_ (Principal const &principal, MergeableRunProductMetadata const *mergeableRunProductMetadata) const override
 
void setMergeableRunProductMetadata_ (MergeableRunProductMetadata const *) override
 
bool unscheduledWasNotRun_ () const final
 

Private Attributes

UnscheduledAuxiliary const * aux_
 
std::atomic< bool > m_prefetchRequested
 
WaitingTaskList m_waitingTasks
 

Additional Inherited Members

- Public Types inherited from edm::DataManagingProductResolver
enum  ProductStatus {
  ProductStatus::ProductSet, ProductStatus::NotPut, ProductStatus::ResolveFailed, ProductStatus::ResolveNotRun,
  ProductStatus::ProductDeleted
}
 
- Protected Member Functions inherited from edm::DataManagingProductResolver
ProductStatus defaultStatus () const
 
template<bool callResolver, typename FUNC >
Resolution resolveProductImpl (FUNC resolver) const
 
void setFailedStatus () const
 
void setMergeableRunProductMetadataInProductData (MergeableRunProductMetadata const *)
 
void setProduct (std::unique_ptr< WrapperBase > edp) const
 
ProductStatus status () const
 

Detailed Description

Definition at line 104 of file ProductResolvers.h.

Constructor & Destructor Documentation

edm::InputProductResolver::InputProductResolver ( std::shared_ptr< BranchDescription const >  bd)
inlineexplicit

Member Function Documentation

bool edm::InputProductResolver::isFromCurrentProcess ( ) const
finalprivatevirtual

Implements edm::DataManagingProductResolver.

Definition at line 305 of file ProductResolvers.cc.

305 { return false; }
void edm::InputProductResolver::prefetchAsync_ ( WaitingTask waitTask,
Principal const &  principal,
bool  skipCurrentProcess,
ServiceToken const &  token,
SharedResourcesAcquirer sra,
ModuleCallingContext const *  mcc 
) const
overrideprivatevirtual

Implements edm::ProductResolverBase.

Definition at line 243 of file ProductResolvers.cc.

References edm::ProductResolverBase::branchDescription(), edm::InEvent, edm::make_functor_task(), cmsRelvalreport::principal(), edm::ProductResolverBase::productResolved(), edm::SerialTaskQueueChain::push(), edm::ProductResolverBase::putProduct(), createBeamHaloJobs::queue, matplotRender::reader, and protons_cff::t.

248  {
249  m_waitingTasks.add(waitTask);
250 
251  bool expected = false;
252  if (m_prefetchRequested.compare_exchange_strong(expected, true)) {
253  auto workToDo = [this, mcc, &principal, token]() {
254  //need to make sure Service system is activated on the reading thread
255  ServiceRegistry::Operate guard(token);
256  try {
257  resolveProductImpl<true>([this, &principal, mcc]() {
258  if (principal.branchType() != InEvent) {
259  return;
260  }
261  if (auto reader = principal.reader()) {
262  std::unique_lock<std::recursive_mutex> guard;
263  if (auto sr = reader->sharedResources().second) {
264  guard = std::unique_lock<std::recursive_mutex>(*sr);
265  }
266  if (not productResolved()) {
267  //another thread could have finished this while we were waiting
268  putProduct(reader->getProduct(branchDescription().branchID(), &principal, mcc));
269  }
270  }
271  });
272  } catch (...) {
273  this->m_waitingTasks.doneWaiting(std::current_exception());
274  return;
275  }
276  this->m_waitingTasks.doneWaiting(nullptr);
277  };
278 
279  SerialTaskQueueChain* queue = nullptr;
280  if (auto reader = principal.reader()) {
281  if (auto shared_res = reader->sharedResources().first) {
282  queue = &(shared_res->serialQueueChain());
283  }
284  }
285  if (queue) {
286  queue->push(workToDo);
287  } else {
288  //Have to create a new task
289  auto t = make_functor_task(tbb::task::allocate_root(), workToDo);
290  tbb::task::spawn(*t);
291  }
292  }
293  }
FunctorTask< F > * make_functor_task(ALLOC &&iAlloc, F f)
Definition: FunctorTask.h:47
void add(WaitingTask *)
Adds task to the waiting list.
WaitingTaskList m_waitingTasks
void putProduct(std::unique_ptr< WrapperBase > edp) const
void doneWaiting(std::exception_ptr iPtr)
Signals that the resource is now available and tasks should be spawned.
def principal(options)
std::atomic< bool > m_prefetchRequested
BranchDescription const & branchDescription() const
void edm::InputProductResolver::putProduct_ ( std::unique_ptr< WrapperBase edp) const
overrideprivatevirtual

Implements edm::ProductResolverBase.

Definition at line 465 of file ProductResolvers.cc.

References eostools::move(), edm::ProductResolverBase::productResolved(), and edm::DataManagingProductResolver::setProduct().

465  {
466  if (not productResolved()) {
467  //Another thread could have set this
468  setProduct(std::move(edp));
469  }
470  }
void setProduct(std::unique_ptr< WrapperBase > edp) const
def move(src, dest)
Definition: eostools.py:511
void edm::InputProductResolver::resetProductData_ ( bool  deleteEarly)
overrideprivatevirtual

Reimplemented from edm::DataManagingProductResolver.

Definition at line 295 of file ProductResolvers.cc.

References edm::DataManagingProductResolver::resetProductData_().

295  {
296  m_prefetchRequested = false;
299  }
void resetProductData_(bool deleteEarly) override
WaitingTaskList m_waitingTasks
void reset()
Resets access to the resource so that added tasks will wait.
std::atomic< bool > m_prefetchRequested
ProductResolverBase::Resolution edm::InputProductResolver::resolveProduct_ ( Principal const &  principal,
bool  skipCurrentProcess,
SharedResourcesAcquirer sra,
ModuleCallingContext const *  mcc 
) const
overrideprivatevirtual

Implements edm::ProductResolverBase.

Definition at line 159 of file ProductResolvers.cc.

References edm::ProductResolverBase::branchDescription(), revisionDML::branchType(), edm::ModuleCallingContext::getStreamContext(), edm::InEvent, edm::make_sentry(), cmsRelvalreport::principal(), edm::ProductResolverBase::productResolved(), edm::ProductResolverBase::putProduct(), and matplotRender::reader.

162  {
163  return resolveProductImpl<true>([this, &principal, mcc]() {
164  auto branchType = principal.branchType();
165  if (branchType != InEvent) {
166  //delayed get has not been allowed with Run or Lumis
167  // The file may already be closed so the reader is invalid
168  return;
169  }
170  if (mcc and (branchType == InEvent) and aux_) {
171  aux_->preModuleDelayedGetSignal_.emit(*(mcc->getStreamContext()), *mcc);
172  }
173 
174  auto sentry(make_sentry(mcc, [this, branchType](ModuleCallingContext const* iContext) {
175  if (branchType == InEvent and aux_) {
176  aux_->postModuleDelayedGetSignal_.emit(*(iContext->getStreamContext()), *iContext);
177  }
178  }));
179 
180  if (auto reader = principal.reader()) {
181  std::unique_lock<std::recursive_mutex> guard;
182  if (auto sr = reader->sharedResources().second) {
183  guard = std::unique_lock<std::recursive_mutex>(*sr);
184  }
185  if (not productResolved()) {
186  //another thread could have beaten us here
187  putProduct(reader->getProduct(branchDescription().branchID(), &principal, mcc));
188  }
189  }
190  });
191  }
std::unique_ptr< T, F > make_sentry(T *iObject, F iFunc)
NOTE: if iObject is null, then iFunc will not be called.
Definition: make_sentry.h:30
UnscheduledAuxiliary const * aux_
void putProduct(std::unique_ptr< WrapperBase > edp) const
def principal(options)
BranchDescription const & branchDescription() const
def branchType(schema, name)
Definition: revisionDML.py:114
void edm::InputProductResolver::retrieveAndMerge_ ( Principal const &  principal,
MergeableRunProductMetadata const *  mergeableRunProductMetadata 
) const
overrideprivatevirtual

Reimplemented from edm::ProductResolverBase.

Definition at line 193 of file ProductResolvers.cc.

References edm::ProductResolverBase::branchDescription(), edm::BranchDescription::branchName(), edm::BranchDescription::branchType(), edm::DataManagingProductResolver::defaultStatus(), Exception, edm::InRun, edm::errors::LogicError, edm::errors::MismatchedInputFiles, eostools::move(), edm::DataManagingProductResolver::ProductSet, edm::ProductResolverBase::putOrMergeProduct(), edm::Principal::reader(), matplotRender::reader, edm::DataManagingProductResolver::ResolveFailed, edm::DataManagingProductResolver::setFailedStatus(), and edm::DataManagingProductResolver::status().

194  {
195  if (auto reader = principal.reader()) {
196  std::unique_lock<std::recursive_mutex> guard;
197  if (auto sr = reader->sharedResources().second) {
198  guard = std::unique_lock<std::recursive_mutex>(*sr);
199  }
200 
201  //Can't use resolveProductImpl since it first checks to see
202  // if the product was already retrieved and then returns if it is
203  std::unique_ptr<WrapperBase> edp(reader->getProduct(branchDescription().branchID(), &principal));
204 
205  if (edp.get() != nullptr) {
206  if (edp->isMergeable() && branchDescription().branchType() == InRun && !edp->hasSwap()) {
208  << "Missing definition of member function swap for branch name " << branchDescription().branchName()
209  << "\n"
210  << "Mergeable data types written to a Run must have the swap member function defined"
211  << "\n";
212  }
214  (status() == ProductStatus::ResolveFailed && !branchDescription().isMergeable())) {
215  putOrMergeProduct(std::move(edp), mergeableRunProductMetadata);
216  } else { // status() == ResolveFailed && branchDescription().isMergeable()
218  << "Merge of Run or Lumi product failed for branch " << branchDescription().branchName() << "\n"
219  << "The product branch was dropped in the first run or lumi fragment and present in a later one"
220  << "\n"
221  << "The solution is to drop the branch on input. Or better do not create inconsistent files\n"
222  << "that need to be merged in the first place.\n";
223  }
224  } else if (status() == defaultStatus()) {
225  setFailedStatus();
226  } else if (status() != ProductStatus::ResolveFailed && branchDescription().isMergeable()) {
228  << "Merge of Run or Lumi product failed for branch " << branchDescription().branchName() << "\n"
229  << "The product branch was present in first run or lumi fragment and dropped in a later one"
230  << "\n"
231  << "The solution is to drop the branch on input. Or better do not create inconsistent files\n"
232  << "that need to be merged in the first place.\n";
233  }
234  // Do nothing in other case. status is ResolveFailed already or
235  // it is not mergeable and the status is ProductSet
236  }
237  }
std::string const & branchName() const
BranchType const & branchType() const
ProductStatus status() const
void putOrMergeProduct(std::unique_ptr< WrapperBase > edp, MergeableRunProductMetadata const *mergeableRunProductMetadata=nullptr) const
def principal(options)
ProductStatus defaultStatus() const
BranchDescription const & branchDescription() const
def move(src, dest)
Definition: eostools.py:511
void edm::InputProductResolver::setMergeableRunProductMetadata_ ( MergeableRunProductMetadata const *  mrpm)
overrideprivatevirtual

Reimplemented from edm::ProductResolverBase.

Definition at line 239 of file ProductResolvers.cc.

References edm::DataManagingProductResolver::setMergeableRunProductMetadataInProductData().

239  {
241  }
void setMergeableRunProductMetadataInProductData(MergeableRunProductMetadata const *)
void edm::InputProductResolver::setupUnscheduled ( UnscheduledConfigurator const &  iConfigure)
finalvirtual

Reimplemented from edm::ProductResolverBase.

Definition at line 301 of file ProductResolvers.cc.

References edm::UnscheduledConfigurator::auxiliary().

301  {
302  aux_ = iConfigure.auxiliary();
303  }
UnscheduledAuxiliary const * aux_
bool edm::InputProductResolver::unscheduledWasNotRun_ ( ) const
inlinefinalprivatevirtual

Implements edm::ProductResolverBase.

Definition at line 131 of file ProductResolvers.h.

References edm::DataManagingOrAliasProductResolver::resetProductData_().

131 { return false; }

Member Data Documentation

UnscheduledAuxiliary const* edm::InputProductResolver::aux_
private

Definition at line 137 of file ProductResolvers.h.

std::atomic<bool> edm::InputProductResolver::m_prefetchRequested
mutableprivate

Definition at line 135 of file ProductResolvers.h.

WaitingTaskList edm::InputProductResolver::m_waitingTasks
mutableprivate

Definition at line 136 of file ProductResolvers.h.