LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
art::Principal Class Referenceabstract

#include "Principal.h"

Inheritance diagram for art::Principal:
art::EDProductGetterFinder art::EventPrincipal art::ResultsPrincipal art::RunPrincipal art::SubRunPrincipal

Public Types

using GroupCollection = std::map< ProductID, std::unique_ptr< Group >>
 
using const_iterator = GroupCollection::const_iterator
 
using ProcessNameConstIterator = ProcessHistory::const_iterator
 
using GroupQueryResultVec = std::vector< GroupQueryResult >
 
using size_type = GroupCollection::size_type
 
using ProcessName = std::string
 

Public Member Functions

virtual ~Principal () noexcept=default
 
 Principal (Principal const &)=delete
 
Principaloperator= (Principal const &)=delete
 
 Principal (ProcessConfiguration const &, ProcessHistoryID const &, cet::exempt_ptr< ProductTable const > presentProducts, std::unique_ptr< BranchMapper > &&, std::unique_ptr< DelayedReader > &&)
 
EDProductGetter const * productGetter (ProductID const pid) const
 
OutputHandle getForOutput (ProductID const, bool resolveProd) const
 
GroupQueryResult getBySelector (WrappedTypeID const &wrapped, SelectorBase const &) const
 
GroupQueryResult getByProductID (ProductID const pid) const
 
GroupQueryResult getByLabel (WrappedTypeID const &wrapped, std::string const &label, std::string const &productInstanceName, std::string const &processName) const
 
GroupQueryResultVec getMany (WrappedTypeID const &wrapped, SelectorBase const &) const
 
GroupQueryResultVec getMatchingSequence (SelectorBase const &) const
 
void removeCachedProduct (ProductID const pid) const
 
void addSecondaryPrincipal (std::unique_ptr< Principal > &&val)
 
void setProducedProducts (ProductTable const &producedProducts)
 
void readImmediate () const
 
void readProvenanceImmediate () const
 
ProcessHistory const & processHistory () const
 
ProcessConfiguration const & processConfiguration () const
 
BranchMapper const & branchMapper () const
 
size_t size () const
 
const_iterator begin () const
 
const_iterator cbegin () const
 
const_iterator end () const
 
const_iterator cend () const
 
void addToProcessHistory ()
 
virtual BranchType branchType () const =0
 
virtual void fillGroup (BranchDescription const &)=0
 
virtual RangeSet seenRanges () const =0
 
EDProductGetter const * getEDProductGetter (ProductID const pid) const
 

Protected Member Functions

BranchMapperbranchMapper ()
 
DelayedReaderproductReader ()
 
void fillGroup (std::unique_ptr< Group > &&group)
 
int tryNextSecondaryFile () const
 
cet::exempt_ptr< Group const > getGroupForPtr (ProductID const pid) const
 
cet::exempt_ptr< Group const > getGroup (ProductID const pid) const
 
cet::exempt_ptr< Group const > getResolvedGroup (ProductID const pid, bool resolveProd) const
 

Private Member Functions

virtual ProcessHistoryID const & processHistoryID () const =0
 
virtual void setProcessHistoryID (ProcessHistoryID const &)=0
 
GroupQueryResultVec matchingSequenceFromInputFile (SelectorBase const &) const
 
GroupQueryResultVec findGroupsForProduct (WrappedTypeID const &wrapped, SelectorBase const &, bool stopIfProcessHasMatch) const
 
size_t findGroupsFromInputFile (WrappedTypeID const &wrapped, SelectorBase const &, GroupQueryResultVec &results, bool stopIfProcessHasMatch) const
 
size_t findGroups (ProcessLookup const &, SelectorBase const &, GroupQueryResultVec &results, bool stopIfProcessHasMatch, TypeID wanted_wrapper=TypeID{}) const
 
size_t findGroupsForProcess (std::vector< ProductID > const &vpid, SelectorBase const &selector, GroupQueryResultVec &results, TypeID wanted_wrapper) const
 
bool presentFromSource (ProductID) const
 
EDProductGetter const * deferredGetter_ (ProductID const pid) const
 
EDProductGetter const * getEDProductGetterImpl (ProductID const pid) const final override
 

Private Attributes

ProcessHistory processHistory_ {}
 
ProcessConfiguration const & processConfiguration_
 
cet::exempt_ptr< ProductTable const > presentProducts_
 
cet::exempt_ptr< ProductTable const > producedProducts_ {nullptr}
 
std::map< ProductID, std::shared_ptr< DeferredProductGetter const > > deferredGetters_ {}
 
bool processHistoryModified_ {false}
 
GroupCollection groups_ {}
 
std::unique_ptr< BranchMapperbranchMapperPtr_
 
std::unique_ptr< DelayedReaderstore_
 
std::vector< std::unique_ptr< Principal > > secondaryPrincipals_ {}
 
int nextSecondaryFileIdx_ {}
 

Detailed Description

Definition at line 48 of file Principal.h.

Member Typedef Documentation

using art::Principal::const_iterator = GroupCollection::const_iterator

Definition at line 52 of file Principal.h.

using art::Principal::GroupCollection = std::map<ProductID, std::unique_ptr<Group>>

Definition at line 51 of file Principal.h.

Definition at line 54 of file Principal.h.

using art::Principal::ProcessName = std::string

Definition at line 56 of file Principal.h.

using art::Principal::size_type = GroupCollection::size_type

Definition at line 55 of file Principal.h.

Constructor & Destructor Documentation

virtual art::Principal::~Principal ( )
virtualdefaultnoexcept
art::Principal::Principal ( Principal const &  )
delete
Principal::Principal ( ProcessConfiguration const &  pc,
ProcessHistoryID const &  hist,
cet::exempt_ptr< ProductTable const >  presentProducts,
std::unique_ptr< BranchMapper > &&  mapper,
std::unique_ptr< DelayedReader > &&  reader 
)

Definition at line 59 of file Principal.cc.

References branchMapperPtr_, art::thread_safe_registry_via_id< K, M >::empty(), art::thread_safe_registry_via_id< K, M >::get(), hist, presentProducts_, processHistory_, store_, and std::swap().

65  , presentProducts_{presentProducts}
66  , branchMapperPtr_{std::move(mapper)}
67  , store_{std::move(reader)}
68 {
69  if (!hist.isValid()) {
70  return;
71  }
73  ProcessHistory ph;
74  bool const found[[gnu::unused]]{ProcessHistoryRegistry::get(hist, ph)};
75  assert(found);
77 }
cet::exempt_ptr< ProductTable const > presentProducts_
Definition: Principal.h:271
std::unique_ptr< BranchMapper > branchMapperPtr_
Definition: Principal.h:284
ProcessHistory processHistory_
Definition: Principal.h:268
std::unique_ptr< DelayedReader > store_
Definition: Principal.h:288
static collection_type const & get()
void swap(art::HLTGlobalStatus &lhs, art::HLTGlobalStatus &rhs)
TH2F * hist
Definition: plot.C:136
ProcessConfiguration const & processConfiguration_
Definition: Principal.h:270

Member Function Documentation

void art::Principal::addSecondaryPrincipal ( std::unique_ptr< Principal > &&  val)
inline

Definition at line 100 of file Principal.h.

References secondaryPrincipals_.

101  {
102  secondaryPrincipals_.emplace_back(std::move(val));
103  }
std::vector< std::unique_ptr< Principal > > secondaryPrincipals_
Definition: Principal.h:293
void Principal::addToProcessHistory ( )

Definition at line 80 of file Principal.cc.

References art::errors::Configuration, art::thread_safe_registry_via_id< K, M >::emplace(), processConfiguration_, processHistory_, processHistoryModified_, art::ProcessConfiguration::processName(), and setProcessHistoryID().

Referenced by cend(), art::EventPrincipal::EventPrincipal(), art::RunPrincipal::RunPrincipal(), art::SubRunPrincipal::SubRunPrincipal(), art::RootOutput::write(), art::RootOutput::writeRun(), and art::RootOutput::writeSubRun().

81 {
83  return;
84  }
85  string const& processName = processConfiguration_.processName();
86  for (auto const& val : processHistory_) {
87  if (processName == val.processName()) {
89  << "The process name " << processName
90  << " was previously used on these products.\n"
91  << "Please modify the configuration file to use a "
92  << "distinct process name.\n";
93  }
94  }
95  processHistory_.push_back(processConfiguration_);
96  // OPTIMIZATION NOTE: As of 0_9_0_pre3 For very simple Sources
97  // (e.g. EmptyEvent) this routine takes up nearly 50% of the time
98  // per event, and 96% of the time for this routine is spent in
99  // computing the ProcessHistory id which happens because we are
100  // reconstructing the ProcessHistory for each event. It would
101  // probably be better to move the ProcessHistory construction out to
102  // somewhere which persists for longer than one Event.
103  auto const phid = processHistory_.id();
104  ProcessHistoryRegistry::emplace(phid, processHistory_);
105  setProcessHistoryID(phid);
107 }
ProcessHistory processHistory_
Definition: Principal.h:268
bool processHistoryModified_
Definition: Principal.h:277
std::string const & processName() const
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
ProcessConfiguration const & processConfiguration_
Definition: Principal.h:270
static auto emplace(value_type const &value)
virtual void setProcessHistoryID(ProcessHistoryID const &)=0
const_iterator art::Principal::begin ( ) const
inline

Definition at line 156 of file Principal.h.

References groups_.

157  {
158  return groups_.begin();
159  }
GroupCollection groups_
Definition: Principal.h:280
BranchMapper const& art::Principal::branchMapper ( ) const
inline
BranchMapper& art::Principal::branchMapper ( )
inlineprotected

Definition at line 192 of file Principal.h.

References branchMapperPtr_.

193  {
194  return *branchMapperPtr_;
195  }
std::unique_ptr< BranchMapper > branchMapperPtr_
Definition: Principal.h:284
virtual BranchType art::Principal::branchType ( ) const
pure virtual
const_iterator art::Principal::cbegin ( ) const
inline

Definition at line 162 of file Principal.h.

References groups_.

163  {
164  return groups_.cbegin();
165  }
GroupCollection groups_
Definition: Principal.h:280
const_iterator art::Principal::cend ( ) const
inline

Definition at line 174 of file Principal.h.

References addToProcessHistory(), branchType(), fillGroup(), groups_, and seenRanges().

175  {
176  return groups_.cend();
177  }
GroupCollection groups_
Definition: Principal.h:280
EDProductGetter const * Principal::deferredGetter_ ( ProductID const  pid) const
private

Definition at line 412 of file Principal.cc.

References deferredGetters_.

Referenced by fillGroup(), and productGetter().

413 {
414  auto it = deferredGetters_.find(pid);
415  if (it != deferredGetters_.end()) {
416  return it->second.get();
417  }
418  deferredGetters_[pid] = std::make_shared<DeferredProductGetter>(
419  cet::exempt_ptr<Principal const>{this}, pid);
420  return deferredGetters_[pid].get();
421 }
std::map< ProductID, std::shared_ptr< DeferredProductGetter const > > deferredGetters_
Definition: Principal.h:275
const_iterator art::Principal::end ( void  ) const
inline

Definition at line 168 of file Principal.h.

References groups_.

169  {
170  return groups_.end();
171  }
GroupCollection groups_
Definition: Principal.h:280
void art::Principal::fillGroup ( std::unique_ptr< Group > &&  group)
inlineprotected

Definition at line 205 of file Principal.h.

References branchMapper(), deferredGetter_(), findGroups(), findGroupsForProcess(), findGroupsForProduct(), findGroupsFromInputFile(), art::BranchDescription::friendlyClassName(), getGroup(), getGroupForPtr(), getResolvedGroup(), groups_, matchingSequenceFromInputFile(), art::BranchDescription::moduleLabel(), presentFromSource(), processHistoryID(), art::BranchDescription::processName(), art::BranchDescription::producedClassName(), art::BranchDescription::productID(), setProcessHistoryID(), store_, and tryNextSecondaryFile().

206  {
207  BranchDescription const& pd = group->productDescription();
208  assert(!pd.producedClassName().empty());
209  assert(!pd.friendlyClassName().empty());
210  assert(!pd.moduleLabel().empty());
211  assert(!pd.processName().empty());
212  group->setResolvers(branchMapper(), *store_);
213  groups_[pd.productID()] = std::move(group);
214  }
GroupCollection groups_
Definition: Principal.h:280
std::unique_ptr< DelayedReader > store_
Definition: Principal.h:288
BranchMapper const & branchMapper() const
Definition: Principal.h:144
std::size_t Principal::findGroups ( ProcessLookup const &  pl,
SelectorBase const &  sel,
GroupQueryResultVec results,
bool  stopIfProcessHasMatch,
TypeID  wanted_wrapper = TypeID{} 
) const
private

Definition at line 355 of file Principal.cc.

References findGroupsForProcess(), and processHistory().

Referenced by fillGroup(), findGroupsForProduct(), findGroupsFromInputFile(), getMatchingSequence(), and matchingSequenceFromInputFile().

360 {
361  // Loop over processes in reverse time order. Sometimes we want to
362  // stop after we find a process with matches so check for that at
363  // each step.
364  std::size_t found{};
365  for (auto const& h : reverse_iteration(processHistory())) {
366  auto it = pl.find(h.processName());
367  if (it != pl.end()) {
368  found += findGroupsForProcess(it->second, sel, res, wanted_wrapper);
369  }
370  if (stopIfProcessHasMatch && !res.empty())
371  break;
372  }
373  return found;
374 }
ProcessHistory const & processHistory() const
Definition: Principal.h:132
size_t findGroupsForProcess(std::vector< ProductID > const &vpid, SelectorBase const &selector, GroupQueryResultVec &results, TypeID wanted_wrapper) const
Definition: Principal.cc:377
std::size_t Principal::findGroupsForProcess ( std::vector< ProductID > const &  vpid,
SelectorBase const &  selector,
GroupQueryResultVec results,
TypeID  wanted_wrapper 
) const
private

Definition at line 377 of file Principal.cc.

References getGroup(), and art::SelectorBase::match().

Referenced by fillGroup(), and findGroups().

381 {
382  std::size_t found{}; // Horrible hack that should go away
383  for (auto const pid : vpid) {
384  auto group = getGroup(pid);
385  if (!group) {
386  continue;
387  }
388  if (!sel.match(group->productDescription())) {
389  continue;
390  }
391  if (group->productUnavailable()) {
392  continue;
393  }
394  if (wanted_wrapper) {
395  group->resolveProduct(wanted_wrapper);
396  } else {
397  group->resolveProduct(group->producedWrapperType());
398  }
399  // If the product is a dummy filler, group will now be marked unavailable.
400  // Unscheduled execution can fail to produce the EDProduct so check.
401  if (group->productUnavailable()) {
402  continue;
403  }
404  // Found a good match, save it.
405  res.emplace_back(group);
406  ++found;
407  }
408  return found;
409 }
cet::exempt_ptr< Group const > getGroup(ProductID const pid) const
Definition: Principal.cc:525
Principal::GroupQueryResultVec Principal::findGroupsForProduct ( WrappedTypeID const &  wrapped,
SelectorBase const &  selector,
bool  stopIfProcessHasMatch 
) const
private

Definition at line 278 of file Principal.cc.

References findGroups(), findGroupsFromInputFile(), art::TypeID::friendlyClassName(), producedProducts_, art::WrappedTypeID::product_type, secondaryPrincipals_, tryNextSecondaryFile(), and art::WrappedTypeID::wrapped_product_type.

Referenced by fillGroup(), getByLabel(), getBySelector(), and getMany().

281 {
282  GroupQueryResultVec results;
283 
284  unsigned ret{};
285  // Find groups from current process
286  if (producedProducts_) {
287  auto const& lookup = producedProducts_->productLookup;
288  auto it = lookup.find(wrapped.product_type.friendlyClassName());
289  if (it != lookup.end()) {
290  ret += findGroups(it->second,
291  selector,
292  results,
293  stopIfProcessHasMatch,
294  wrapped.wrapped_product_type);
295  }
296  }
297 
298  // Look through currently opened input files
299  ret +=
300  findGroupsFromInputFile(wrapped, selector, results, stopIfProcessHasMatch);
301  if (ret) {
302  return results;
303  }
304 
305  for (auto const& sp : secondaryPrincipals_) {
306  if (sp->findGroupsFromInputFile(
307  wrapped, selector, results, stopIfProcessHasMatch)) {
308  return results;
309  }
310  }
311 
312  // Open more secondary files if necessary
313  while (true) {
314  int const err = tryNextSecondaryFile();
315  if (err == -2) {
316  // No more files.
317  break;
318  }
319  if (err == -1) {
320  // Run, SubRun, or Event not found.
321  continue;
322  }
323  assert(!secondaryPrincipals_.empty());
324  auto& new_sp = secondaryPrincipals_.back();
325  if (new_sp->findGroupsFromInputFile(
326  wrapped, selector, results, stopIfProcessHasMatch)) {
327  return results;
328  }
329  }
330  return results;
331 }
size_t findGroupsFromInputFile(WrappedTypeID const &wrapped, SelectorBase const &, GroupQueryResultVec &results, bool stopIfProcessHasMatch) const
Definition: Principal.cc:334
int tryNextSecondaryFile() const
Definition: Principal.cc:184
cet::exempt_ptr< ProductTable const > producedProducts_
Definition: Principal.h:272
size_t findGroups(ProcessLookup const &, SelectorBase const &, GroupQueryResultVec &results, bool stopIfProcessHasMatch, TypeID wanted_wrapper=TypeID{}) const
Definition: Principal.cc:355
std::vector< GroupQueryResult > GroupQueryResultVec
Definition: Principal.h:54
std::vector< std::unique_ptr< Principal > > secondaryPrincipals_
Definition: Principal.h:293
std::size_t Principal::findGroupsFromInputFile ( WrappedTypeID const &  wrapped,
SelectorBase const &  selector,
GroupQueryResultVec results,
bool  stopIfProcessHasMatch 
) const
private

Definition at line 334 of file Principal.cc.

References findGroups(), art::TypeID::friendlyClassName(), presentProducts_, art::WrappedTypeID::product_type, and art::WrappedTypeID::wrapped_product_type.

Referenced by fillGroup(), and findGroupsForProduct().

338 {
339  if (!presentProducts_) {
340  return 0;
341  }
342  auto const& lookup = presentProducts_->productLookup;
343  auto it = lookup.find(wrapped.product_type.friendlyClassName());
344  if (it == lookup.end()) {
345  return 0;
346  }
347  return findGroups(it->second,
348  selector,
349  results,
350  stopIfProcessHasMatch,
351  wrapped.wrapped_product_type);
352 }
cet::exempt_ptr< ProductTable const > presentProducts_
Definition: Principal.h:271
size_t findGroups(ProcessLookup const &, SelectorBase const &, GroupQueryResultVec &results, bool stopIfProcessHasMatch, TypeID wanted_wrapper=TypeID{}) const
Definition: Principal.cc:355
GroupQueryResult Principal::getByLabel ( WrappedTypeID const &  wrapped,
std::string const &  label,
std::string const &  productInstanceName,
std::string const &  processName 
) const

Definition at line 143 of file Principal.cc.

References findGroupsForProduct(), art::WrappedTypeID::product_type, and art::errors::ProductNotFound.

Referenced by art::DataViewImpl::getByLabel_().

147 {
148  Selector const sel{ModuleLabelSelector{label} &&
149  ProductInstanceNameSelector{productInstanceName} &&
150  ProcessNameSelector{processName}};
151  auto const& results = findGroupsForProduct(wrapped, sel, true);
152  if (results.empty()) {
153  auto whyFailed =
154  std::make_shared<art::Exception>(art::errors::ProductNotFound);
155  *whyFailed << "getByLabel: Found zero products matching all criteria\n"
156  << "Looking for type: " << wrapped.product_type << "\n"
157  << "Looking for module label: " << label << "\n"
158  << "Looking for productInstanceName: " << productInstanceName
159  << "\n"
160  << (processName.empty() ? "" : "Looking for process: ")
161  << processName;
162  return GroupQueryResult{whyFailed};
163  }
164  if (results.size() > 1) {
166  << "getByLabel: Found " << results.size()
167  << " products rather than one which match all criteria\n"
168  << "Looking for type: " << wrapped.product_type << "\n"
169  << "Looking for module label: " << label << "\n"
170  << "Looking for productInstanceName: " << productInstanceName << "\n"
171  << (processName.empty() ? "" : "Looking for process: ") << processName
172  << "\n";
173  }
174  return results[0];
175 }
GroupQueryResultVec findGroupsForProduct(WrappedTypeID const &wrapped, SelectorBase const &, bool stopIfProcessHasMatch) const
Definition: Principal.cc:278
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
GroupQueryResult Principal::getByProductID ( ProductID const  pid) const

Definition at line 131 of file Principal.cc.

References getGroupForPtr(), and art::errors::ProductNotFound.

Referenced by art::DataViewImpl::getByProductID_(), getEDProductGetterImpl(), and productGetter().

132 {
133  if (auto const g = getGroupForPtr(pid)) {
134  return GroupQueryResult{g};
135  }
136  auto whyFailed =
137  std::make_shared<art::Exception>(art::errors::ProductNotFound, "InvalidID");
138  *whyFailed << "getGroup: no product with given product id: " << pid << "\n";
139  return GroupQueryResult{whyFailed};
140 }
cet::exempt_ptr< Group const > getGroupForPtr(ProductID const pid) const
Definition: Principal.cc:481
GroupQueryResult Principal::getBySelector ( WrappedTypeID const &  wrapped,
SelectorBase const &  sel 
) const

Definition at line 110 of file Principal.cc.

References findGroupsForProduct(), art::WrappedTypeID::product_type, and art::errors::ProductNotFound.

Referenced by art::DataViewImpl::get_().

112 {
113  auto const& results = findGroupsForProduct(wrapped, sel, true);
114  if (results.empty()) {
115  auto whyFailed =
116  std::make_shared<art::Exception>(art::errors::ProductNotFound);
117  *whyFailed << "getBySelector: Found zero products matching all criteria\n"
118  << "Looking for type: " << wrapped.product_type << "\n";
119  return GroupQueryResult{whyFailed};
120  }
121  if (results.size() > 1) {
123  << "getBySelector: Found " << results.size()
124  << " products rather than one which match all criteria\n"
125  << "Looking for type: " << wrapped.product_type << "\n";
126  }
127  return results[0];
128 }
GroupQueryResultVec findGroupsForProduct(WrappedTypeID const &wrapped, SelectorBase const &, bool stopIfProcessHasMatch) const
Definition: Principal.cc:278
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
EDProductGetter const* art::EDProductGetterFinder::getEDProductGetter ( ProductID const  pid) const
inlineinherited

Definition at line 25 of file EDProductGetterFinder.h.

References art::EDProductGetterFinder::getEDProductGetterImpl().

26  {
28  }
virtual EDProductGetter const * getEDProductGetterImpl(ProductID) const =0
EDProductGetter const* art::Principal::getEDProductGetterImpl ( ProductID const  pid) const
inlinefinaloverrideprivatevirtual

Implements art::EDProductGetterFinder.

Definition at line 263 of file Principal.h.

References getByProductID(), and art::GroupQueryResult::result().

264  {
265  return getByProductID(pid).result().get();
266  }
cet::exempt_ptr< Group const > result() const
GroupQueryResult getByProductID(ProductID const pid) const
Definition: Principal.cc:131
OutputHandle Principal::getForOutput ( ProductID const  pid,
bool  resolveProd 
) const

Definition at line 424 of file Principal.cc.

References getResolvedGroup(), art::OutputHandle::invalid(), and art::OutputHandle::rangeOfValidity().

Referenced by art::RootOutputFile::fillBranches(), art::detail::KeptProvenance::insertAncestors(), and art::ProvenanceCheckerOutput::write().

425 {
426  auto const& g = getResolvedGroup(pid, resolveProd);
427  if (g.get() == nullptr) {
428  return OutputHandle::invalid();
429  }
430 
431  if (resolveProd) {
432  // If a request to resolve the product is made, then it should
433  // exist and be marked as present. Return invalid handles if this
434  // is not the case.
435  if (g->anyProduct() == nullptr) {
436  return OutputHandle::invalid();
437  }
438  if (!g->anyProduct()->isPresent()) {
439  return OutputHandle::invalid();
440  }
441  }
442  if (!g->anyProduct() && !g->productProvenancePtr()) {
443  return OutputHandle{g->rangeOfValidity()};
444  }
445  return OutputHandle{g->anyProduct(),
446  &g->productDescription(),
447  g->productProvenancePtr(),
448  g->rangeOfValidity()};
449 }
RangeSet const & rangeOfValidity() const
Definition: OutputHandle.h:78
cet::exempt_ptr< Group const > getResolvedGroup(ProductID const pid, bool resolveProd) const
Definition: Principal.cc:452
static OutputHandle invalid()
Definition: OutputHandle.h:52
cet::exempt_ptr< Group const > Principal::getGroup ( ProductID const  pid) const
protected

Definition at line 525 of file Principal.cc.

References groups_.

Referenced by fillGroup(), findGroupsForProcess(), getGroupForPtr(), art::EventPrincipal::history(), removeCachedProduct(), and art::EventPrincipal::throwIfExistingGroup().

526 {
527  auto it = groups_.find(pid);
528  return it != groups_.cend() ? it->second.get() : nullptr;
529 }
GroupCollection groups_
Definition: Principal.h:280
cet::exempt_ptr< Group const > Principal::getGroupForPtr ( ProductID const  pid) const
protected

Definition at line 481 of file Principal.cc.

References getGroup(), presentFromSource(), producedProducts_, secondaryPrincipals_, and tryNextSecondaryFile().

Referenced by fillGroup(), getByProductID(), and getResolvedGroup().

482 {
483  bool produced{false};
484  if (producedProducts_) {
485  auto const& availableProducts = producedProducts_->availableProducts;
486  if (availableProducts.find(pid) != availableProducts.cend()) {
487  produced = true;
488  }
489  }
490 
491  // Look through current process and currently opened primary input file.
492  if (produced || presentFromSource(pid)) {
493  return getGroup(pid);
494  }
495 
496  // Look through secondary files
497  for (auto const& sp : secondaryPrincipals_) {
498  if (sp->presentFromSource(pid)) {
499  return sp->getGroup(pid);
500  }
501  }
502 
503  // Try new secondary files
504  while (true) {
505  int const err = tryNextSecondaryFile();
506  if (err == -2) {
507  // No more files.
508  return nullptr;
509  }
510  if (err == -1) {
511  // Run, SubRun, or Event not found.
512  continue;
513  }
514  assert(!secondaryPrincipals_.empty());
515  auto& new_sp = secondaryPrincipals_.back();
516  if (new_sp->presentFromSource(pid)) {
517  return new_sp->getGroup(pid);
518  }
519  }
520 
521  return nullptr;
522 }
bool presentFromSource(ProductID) const
Definition: Principal.cc:470
cet::exempt_ptr< Group const > getGroup(ProductID const pid) const
Definition: Principal.cc:525
int tryNextSecondaryFile() const
Definition: Principal.cc:184
cet::exempt_ptr< ProductTable const > producedProducts_
Definition: Principal.h:272
std::vector< std::unique_ptr< Principal > > secondaryPrincipals_
Definition: Principal.h:293
Principal::GroupQueryResultVec Principal::getMany ( WrappedTypeID const &  wrapped,
SelectorBase const &  sel 
) const

Definition at line 178 of file Principal.cc.

References findGroupsForProduct().

Referenced by art::DataViewImpl::getMany_().

179 {
180  return findGroupsForProduct(wrapped, sel, false);
181 }
GroupQueryResultVec findGroupsForProduct(WrappedTypeID const &wrapped, SelectorBase const &, bool stopIfProcessHasMatch) const
Definition: Principal.cc:278
Principal::GroupQueryResultVec Principal::getMatchingSequence ( SelectorBase const &  selector) const

Definition at line 195 of file Principal.cc.

References findGroups(), matchingSequenceFromInputFile(), producedProducts_, secondaryPrincipals_, and tryNextSecondaryFile().

Referenced by art::DataViewImpl::getMatchingSequenceByLabel_().

196 {
197  GroupQueryResultVec results;
198 
199  // Find groups from current process
200  if (producedProducts_) {
201  if (findGroups(producedProducts_->viewLookup, selector, results, true) !=
202  0) {
203  return results;
204  }
205  }
206 
207  // Look through currently opened input files
208  if (results.empty()) {
209  results = matchingSequenceFromInputFile(selector);
210  if (!results.empty()) {
211  return results;
212  }
213 
214  for (auto const& sp : secondaryPrincipals_) {
215  results = sp->matchingSequenceFromInputFile(selector);
216  if (!results.empty()) {
217  return results;
218  }
219  }
220  }
221 
222  // Open more secondary files if necessary
223  if (results.empty()) {
224  while (true) {
225  int const err = tryNextSecondaryFile();
226  if (err == -2) {
227  // No more files.
228  break;
229  }
230  if (err == -1) {
231  // Run, SubRun, or Event not found.
232  continue;
233  }
234  assert(!secondaryPrincipals_.empty());
235  auto& new_sp = secondaryPrincipals_.back();
236  results = new_sp->matchingSequenceFromInputFile(selector);
237  if (!results.empty()) {
238  return results;
239  }
240  }
241  }
242 
243  return results;
244 }
int tryNextSecondaryFile() const
Definition: Principal.cc:184
cet::exempt_ptr< ProductTable const > producedProducts_
Definition: Principal.h:272
size_t findGroups(ProcessLookup const &, SelectorBase const &, GroupQueryResultVec &results, bool stopIfProcessHasMatch, TypeID wanted_wrapper=TypeID{}) const
Definition: Principal.cc:355
std::vector< GroupQueryResult > GroupQueryResultVec
Definition: Principal.h:54
GroupQueryResultVec matchingSequenceFromInputFile(SelectorBase const &) const
Definition: Principal.cc:247
std::vector< std::unique_ptr< Principal > > secondaryPrincipals_
Definition: Principal.h:293
cet::exempt_ptr< Group const > Principal::getResolvedGroup ( ProductID const  pid,
bool  resolveProd 
) const
protected

Definition at line 452 of file Principal.cc.

References getGroupForPtr().

Referenced by fillGroup(), and getForOutput().

453 {
454  // FIXME: This reproduces the behavior of the original getGroup with
455  // resolveProv == false but I am not sure this is correct in the
456  // case of an unavailable product.
457  auto const g = getGroupForPtr(pid);
458  if (!g.get() || !resolveProd) {
459  return g;
460  }
461  bool const gotIt = g->resolveProductIfAvailable(g->producedWrapperType());
462  if (!gotIt) {
463  // Behavior is the same as if the group wasn't there.
464  return nullptr;
465  }
466  return g;
467 }
cet::exempt_ptr< Group const > getGroupForPtr(ProductID const pid) const
Definition: Principal.cc:481
Principal::GroupQueryResultVec Principal::matchingSequenceFromInputFile ( SelectorBase const &  selector) const
private

Definition at line 247 of file Principal.cc.

References findGroups(), and presentProducts_.

Referenced by fillGroup(), and getMatchingSequence().

248 {
249  GroupQueryResultVec results;
250  if (!presentProducts_) {
251  return results;
252  }
253 
254  findGroups(presentProducts_->viewLookup, selector, results, true);
255  return results;
256 }
cet::exempt_ptr< ProductTable const > presentProducts_
Definition: Principal.h:271
size_t findGroups(ProcessLookup const &, SelectorBase const &, GroupQueryResultVec &results, bool stopIfProcessHasMatch, TypeID wanted_wrapper=TypeID{}) const
Definition: Principal.cc:355
std::vector< GroupQueryResult > GroupQueryResultVec
Definition: Principal.h:54
Principal& art::Principal::operator= ( Principal const &  )
delete
bool Principal::presentFromSource ( ProductID  pid) const
private

Definition at line 470 of file Principal.cc.

References art::productstatus::present(), and presentProducts_.

Referenced by fillGroup(), and getGroupForPtr().

471 {
472  bool present{false};
473  if (presentProducts_) {
474  auto const& lookup = presentProducts_->availableProducts;
475  present = (lookup.find(pid) != lookup.cend());
476  }
477  return present;
478 }
cet::exempt_ptr< ProductTable const > presentProducts_
Definition: Principal.h:271
ProductStatus present()
Definition: ProductStatus.h:16
ProcessConfiguration const& art::Principal::processConfiguration ( ) const
inline

Definition at line 138 of file Principal.h.

References processConfiguration_.

Referenced by art::get_ProductDescription().

139  {
140  return processConfiguration_;
141  }
ProcessConfiguration const & processConfiguration_
Definition: Principal.h:270
ProcessHistory const& art::Principal::processHistory ( ) const
inline

Definition at line 132 of file Principal.h.

References processHistory_.

Referenced by findGroups(), and art::DataViewImpl::processHistory().

133  {
134  return processHistory_;
135  }
ProcessHistory processHistory_
Definition: Principal.h:268
virtual ProcessHistoryID const& art::Principal::processHistoryID ( ) const
privatepure virtual
EDProductGetter const * Principal::productGetter ( ProductID const  pid) const

Definition at line 532 of file Principal.cc.

References deferredGetter_(), getByProductID(), and art::GroupQueryResult::result().

Referenced by art::SourceHelper::makePtr(), art::Results::productGetter(), art::Run::productGetter(), art::SubRun::productGetter(), and art::Event::productGetter().

533 {
534  EDProductGetter const* result{getByProductID(pid).result().get()};
535  return result ? result : deferredGetter_(pid);
536 }
cet::exempt_ptr< Group const > result() const
EDProductGetter const * deferredGetter_(ProductID const pid) const
Definition: Principal.cc:412
GroupQueryResult getByProductID(ProductID const pid) const
Definition: Principal.cc:131
DelayedReader& art::Principal::productReader ( )
inlineprotected

Definition at line 198 of file Principal.h.

References store_.

Referenced by art::EventPrincipal::EventPrincipal(), art::ResultsPrincipal::ResultsPrincipal(), art::RunPrincipal::RunPrincipal(), and art::SubRunPrincipal::SubRunPrincipal().

199  {
200  return *store_;
201  }
std::unique_ptr< DelayedReader > store_
Definition: Principal.h:288
void art::Principal::readImmediate ( ) const
inline

Definition at line 112 of file Principal.h.

References groups_, and readProvenanceImmediate().

113  {
115  for (auto const& val : groups_) {
116  if (!val.second->productUnavailable()) {
117  val.second->resolveProduct(val.second->producedWrapperType());
118  }
119  }
120  }
GroupCollection groups_
Definition: Principal.h:280
void readProvenanceImmediate() const
Definition: Principal.h:123
void art::Principal::readProvenanceImmediate ( ) const
inline

Definition at line 123 of file Principal.h.

References branchMapperPtr_, and groups_.

Referenced by readImmediate().

124  {
125  for (auto const& val : groups_) {
126  (void)val.second->productProvenancePtr();
127  }
128  branchMapperPtr_->setDelayedRead(false);
129  }
std::unique_ptr< BranchMapper > branchMapperPtr_
Definition: Principal.h:284
GroupCollection groups_
Definition: Principal.h:280
void Principal::removeCachedProduct ( ProductID const  pid) const

Definition at line 259 of file Principal.cc.

References getGroup(), art::errors::ProductNotFound, and secondaryPrincipals_.

Referenced by art::DataViewImpl::removeCachedProduct_().

260 {
261  if (auto g = getGroup(pid)) {
262  g->removeCachedProduct();
263  return;
264  }
265  for (auto const& sp : secondaryPrincipals_) {
266  if (auto g = sp->getGroup(pid)) {
267  g->removeCachedProduct();
268  return;
269  }
270  }
271  throw Exception(errors::ProductNotFound, "removeCachedProduct")
272  << "Attempt to remove unknown product corresponding to ProductID: " << pid
273  << '\n'
274  << "Please contact artists@fnal.gov\n";
275 }
cet::exempt_ptr< Group const > getGroup(ProductID const pid) const
Definition: Principal.cc:525
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
std::vector< std::unique_ptr< Principal > > secondaryPrincipals_
Definition: Principal.h:293
virtual RangeSet art::Principal::seenRanges ( ) const
pure virtual
virtual void art::Principal::setProcessHistoryID ( ProcessHistoryID const &  )
privatepure virtual
void art::Principal::setProducedProducts ( ProductTable const &  producedProducts)
inline

Definition at line 106 of file Principal.h.

References producedProducts_.

107  {
108  producedProducts_ = cet::make_exempt_ptr(&producedProducts);
109  }
cet::exempt_ptr< ProductTable const > producedProducts_
Definition: Principal.h:272
size_t art::Principal::size ( void  ) const
inline

Definition at line 150 of file Principal.h.

References groups_.

Referenced by art::DataViewImpl::size().

151  {
152  return groups_.size();
153  }
GroupCollection groups_
Definition: Principal.h:280
int Principal::tryNextSecondaryFile ( ) const
protected

Definition at line 184 of file Principal.cc.

References nextSecondaryFileIdx_, and store_.

Referenced by fillGroup(), findGroupsForProduct(), getGroupForPtr(), and getMatchingSequence().

185 {
186  int const err = store_->openNextSecondaryFile(nextSecondaryFileIdx_);
187  if (err != -2) {
188  // there are more files to try
190  }
191  return err;
192 }
std::unique_ptr< DelayedReader > store_
Definition: Principal.h:288
int nextSecondaryFileIdx_
Definition: Principal.h:297

Member Data Documentation

std::unique_ptr<BranchMapper> art::Principal::branchMapperPtr_
private

Definition at line 284 of file Principal.h.

Referenced by branchMapper(), Principal(), and readProvenanceImmediate().

std::map<ProductID, std::shared_ptr<DeferredProductGetter const> > art::Principal::deferredGetters_ {}
mutableprivate

Definition at line 275 of file Principal.h.

Referenced by deferredGetter_().

GroupCollection art::Principal::groups_ {}
private
int art::Principal::nextSecondaryFileIdx_ {}
mutableprivate

Definition at line 297 of file Principal.h.

Referenced by tryNextSecondaryFile().

cet::exempt_ptr<ProductTable const> art::Principal::presentProducts_
private
ProcessConfiguration const& art::Principal::processConfiguration_
private

Definition at line 270 of file Principal.h.

Referenced by addToProcessHistory(), and processConfiguration().

ProcessHistory art::Principal::processHistory_ {}
private

Definition at line 268 of file Principal.h.

Referenced by addToProcessHistory(), Principal(), and processHistory().

bool art::Principal::processHistoryModified_ {false}
mutableprivate

Definition at line 277 of file Principal.h.

Referenced by addToProcessHistory().

cet::exempt_ptr<ProductTable const> art::Principal::producedProducts_ {nullptr}
private
std::vector<std::unique_ptr<Principal> > art::Principal::secondaryPrincipals_ {}
private
std::unique_ptr<DelayedReader> art::Principal::store_
private

Definition at line 288 of file Principal.h.

Referenced by fillGroup(), Principal(), productReader(), and tryNextSecondaryFile().


The documentation for this class was generated from the following files: