LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
art::Principal Class Reference

#include "Principal.h"

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

Public Types

enum  allowed_processes { allowed_processes::current_process, allowed_processes::input_source, allowed_processes::all }
 
using GroupCollection = std::map< ProductID, std::unique_ptr< Group >>
 
using const_iterator = GroupCollection::const_iterator
 

Public Member Functions

virtual ~Principal () noexcept=default
 
 Principal (BranchType, ProcessConfiguration const &, cet::exempt_ptr< ProductTable const > presentProducts, ProcessHistoryID const &id, std::unique_ptr< DelayedReader > &&reader=std::make_unique< NoDelayedReader >())
 
 Principal (Principal const &)=delete
 
Principaloperator= (Principal const &)=delete
 
GroupQueryResult getByProductID (ProductID const pid) const
 
GroupQueryResult getBySelector (ModuleContext const &mc, WrappedTypeID const &wrapped, SelectorBase const &, ProcessTag const &) const
 
GroupQueryResult getByLabel (ModuleContext const &mc, WrappedTypeID const &wrapped, std::string const &label, std::string const &productInstanceName, ProcessTag const &processTag) const
 
std::vector< GroupQueryResultgetMany (ModuleContext const &mc, WrappedTypeID const &wrapped, SelectorBase const &, ProcessTag const &) const
 
std::vector< InputTaggetInputTags (ModuleContext const &mc, WrappedTypeID const &wrapped, SelectorBase const &, ProcessTag const &) const
 
std::vector< cet::exempt_ptr< Group > > getMatchingSequence (ModuleContext const &, SelectorBase const &, ProcessTag const &) const
 
EDProductGetter const * productGetter (ProductID id) const
 
Provenance provenance (ProductID id) const
 
ProcessHistory const & processHistory () const
 
OutputHandle getForOutput (ProductID const &, bool resolveProd) const
 
cet::exempt_ptr< BranchDescription const > getProductDescription (ProductID const pid, bool const alwaysEnableLookupOfProducedProducts=false) const
 
void createGroupsForProducedProducts (ProductTables const &producedProducts)
 
void enableLookupOfProducedProducts ()
 
void markProcessHistoryAsModified ()
 
void readImmediate () const
 
ProcessConfiguration const & processConfiguration () const
 
ProcessHistoryID const & processHistoryID () const
 
cet::exempt_ptr< ProductProvenance const > branchToProductProvenance (ProductID const &) const
 
size_t size () const
 
const_iterator begin () const
 
const_iterator cbegin () const
 
const_iterator end () const
 
const_iterator cend () const
 
void addToProcessHistory ()
 
BranchType branchType () const
 
RangeSet seenRanges () const
 
void put (BranchDescription const &, std::unique_ptr< ProductProvenance const > &&, std::unique_ptr< EDProduct > &&, std::unique_ptr< RangeSet > &&)
 
EDProductGetter const * getEDProductGetter (ProductID const &pid) const
 

Protected Member Functions

std::optional< ProductInsertermakeInserter (ModuleContext const &mc)
 
void fillGroup (BranchDescription const &)
 
void setProcessHistoryIDcombined (ProcessHistoryID const &)
 
void updateSeenRanges (RangeSet const &rs)
 

Private Member Functions

void ctor_create_groups (cet::exempt_ptr< ProductTable const >)
 
void ctor_read_provenance ()
 
void ctor_fetch_process_history (ProcessHistoryID const &)
 
cet::exempt_ptr< GroupgetGroupLocal (ProductID const) const
 
std::vector< cet::exempt_ptr< Group > > matchingSequenceFromInputFile (ModuleContext const &, SelectorBase const &) const
 
size_t findGroupsFromInputFile (ModuleContext const &, WrappedTypeID const &wrapped, SelectorBase const &, std::vector< cet::exempt_ptr< Group >> &results) const
 
size_t findGroups (ProcessLookup const &, ModuleContext const &, SelectorBase const &, std::vector< cet::exempt_ptr< Group >> &groups) const
 
size_t findGroupsForProcess (std::vector< ProductID > const &vpid, ModuleContext const &mc, SelectorBase const &selector, std::vector< cet::exempt_ptr< Group >> &groups) const
 
bool producedInProcess (ProductID) const
 
bool presentFromSource (ProductID) const
 
auto tryNextSecondaryFile () const
 
std::vector< cet::exempt_ptr< Group > > findGroupsForProduct (ModuleContext const &mc, WrappedTypeID const &wrapped, SelectorBase const &, ProcessTag const &) const
 
EDProductGetter const * getEDProductGetter_ (ProductID const &) const override
 
cet::exempt_ptr< GroupgetGroupTryAllFiles (ProductID const) const
 

Private Attributes

BranchType branchType_ {}
 
ProcessHistory processHistory_ {}
 
std::atomic< bool > processHistoryModified_ {false}
 
ProcessConfiguration const & processConfiguration_
 
std::atomic< ProductTable const * > presentProducts_
 
std::atomic< ProductTable const * > producedProducts_ {nullptr}
 
std::atomic< bool > enableLookupOfProducedProducts_ {false}
 
std::recursive_mutex groupMutex_ {}
 
GroupCollection groups_ {}
 
std::unique_ptr< DelayedReaderdelayedReader_ {nullptr}
 
std::vector< std::unique_ptr< Principal > > secondaryPrincipals_ {}
 
int nextSecondaryFileIdx_ {}
 
RangeSet rangeSet_ {RangeSet::invalid()}
 

Detailed Description

Definition at line 49 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.

Member Enumeration Documentation

Enumerator
current_process 
input_source 
all 

Definition at line 53 of file Principal.h.

53 { current_process, input_source, all };

Constructor & Destructor Documentation

virtual art::Principal::~Principal ( )
virtualdefaultnoexcept
art::Principal::Principal ( BranchType  branchType,
ProcessConfiguration const &  pc,
cet::exempt_ptr< ProductTable const >  presentProducts,
ProcessHistoryID const &  id,
std::unique_ptr< DelayedReader > &&  reader = std::make_unique<NoDelayedReader>() 
)

Definition at line 119 of file Principal.cc.

References ctor_create_groups(), ctor_fetch_process_history(), ctor_read_provenance(), delayedReader_, hist, presentProducts_, and processConfiguration_.

127  , presentProducts_{presentProducts.get()}
128  , delayedReader_{std::move(reader)}
129  {
130  delayedReader_->setPrincipal(this);
131  ctor_create_groups(presentProducts);
134  }
BranchType branchType_
Definition: Principal.h:230
std::atomic< ProductTable const * > presentProducts_
Definition: Principal.h:236
void ctor_fetch_process_history(ProcessHistoryID const &)
Definition: Principal.cc:109
void ctor_create_groups(cet::exempt_ptr< ProductTable const >)
Definition: Principal.cc:68
TH2F * hist
Definition: plot.C:134
ProcessConfiguration const & processConfiguration_
Definition: Principal.h:233
void ctor_read_provenance()
Definition: Principal.cc:89
std::unique_ptr< DelayedReader > delayedReader_
Definition: Principal.h:250
BranchType branchType() const
Definition: Principal.cc:807
art::Principal::Principal ( Principal const &  )
delete

Member Function Documentation

void art::Principal::addToProcessHistory ( )

Definition at line 423 of file Principal.cc.

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

Referenced by createGroupsForProducedProducts(), and processHistoryID().

424  {
425  bool expected = false;
426  if (processHistoryModified_.compare_exchange_strong(expected, true)) {
427  // MT note: We have now locked out any other task trying to
428  // modify the process history. Now we have to block
429  // tasks that already have a pointer to the process
430  // history from accessing its internals while we update
431  // it. We do not protect the iteration interface, the
432  // begin(), end(), and size() are all separate calls
433  // and we cannot lock in each one because there is no
434  // way to automatically unlock.
435  std::lock_guard sentry{processHistory_.get_mutex()};
436  string const& processName = processConfiguration_.processName();
437  for (auto const& val : processHistory_) {
438  if (processName == val.processName()) {
440  << "The process name " << processName
441  << " was previously used on these products.\n"
442  << "Please modify the configuration file to use a "
443  << "distinct process name.\n";
444  }
445  }
446  processHistory_.push_back(processConfiguration_);
447  // Optimization note: As of 0_9_0_pre3 For very simple Sources
448  // (e.g. EmptyEvent) this routine takes up nearly 50% of the
449  // time per event, and 96% of the time for this routine is spent
450  // in computing the ProcessHistory id which happens because we
451  // are reconstructing the ProcessHistory for each event. It
452  // would probably be better to move the ProcessHistory
453  // construction out to somewhere which persists for longer than
454  // one Event.
455  auto const phid = processHistory_.id();
456  ProcessHistoryRegistry::emplace(phid, processHistory_);
457  }
458  }
std::atomic< bool > processHistoryModified_
Definition: Principal.h:232
ProcessHistory processHistory_
Definition: Principal.h:231
std::recursive_mutex & get_mutex() const
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
ProcessConfiguration const & processConfiguration_
Definition: Principal.h:233
std::string const & processName() const noexcept
static auto emplace(value_type const &value)
Principal::const_iterator art::Principal::begin ( ) const

Definition at line 270 of file Principal.cc.

References groupMutex_, and groups_.

Referenced by processHistoryID().

271  {
272  std::lock_guard sentry{groupMutex_};
273  return groups_.begin();
274  }
GroupCollection groups_
Definition: Principal.h:246
std::recursive_mutex groupMutex_
Definition: Principal.h:241
cet::exempt_ptr< ProductProvenance const > art::Principal::branchToProductProvenance ( ProductID const &  pid) const

Definition at line 298 of file Principal.cc.

References getGroupLocal().

Referenced by art::markAncestors(), and processHistoryID().

299  {
300  // Note: The input source lock will be held when this routine is called.
301  //
302  // MT-TODO: For right now ignore the delay reading option for
303  // product provenance. If we do the delay reading then we
304  // must use a lock to interlock all fetches of provenance
305  // because the delay read fills the pp_by_pid_ one entry
306  // at a time, and we do not want other threads to find
307  // the info only partly there.
308  cet::exempt_ptr<ProductProvenance const> ret;
309  auto g = getGroupLocal(pid);
310  if (g.get() != nullptr) {
311  ret = g->productProvenance();
312  }
313  return ret;
314  }
cet::exempt_ptr< Group > getGroupLocal(ProductID const) const
Definition: Principal.cc:852
BranchType art::Principal::branchType ( ) const

Definition at line 807 of file Principal.cc.

References branchType_.

Referenced by art::SourceHelper::makePtr(), and processHistoryID().

808  {
809  return branchType_;
810  }
BranchType branchType_
Definition: Principal.h:230
Principal::const_iterator art::Principal::cbegin ( ) const

Definition at line 277 of file Principal.cc.

References groupMutex_, and groups_.

Referenced by processHistoryID().

278  {
279  std::lock_guard sentry{groupMutex_};
280  return groups_.cbegin();
281  }
GroupCollection groups_
Definition: Principal.h:246
std::recursive_mutex groupMutex_
Definition: Principal.h:241
Principal::const_iterator art::Principal::cend ( ) const

Definition at line 291 of file Principal.cc.

References groupMutex_, and groups_.

Referenced by processHistoryID().

292  {
293  std::lock_guard sentry{groupMutex_};
294  return groups_.cend();
295  }
GroupCollection groups_
Definition: Principal.h:246
std::recursive_mutex groupMutex_
Definition: Principal.h:241
void art::Principal::createGroupsForProducedProducts ( ProductTables const &  producedProducts)

Definition at line 201 of file Principal.cc.

References addToProcessHistory(), branchType_, fillGroup(), art::ProductTables::get(), producedProducts_, and util::values().

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

203  {
204  auto const& produced = producedProducts.get(branchType_);
205  producedProducts_ = &produced;
206  if (produced.descriptions.empty()) {
207  return;
208  }
209  // The process history is expanded if there is a product that is
210  // produced in this process.
212  for (auto const& pd : produced.descriptions | ::ranges::views::values) {
213  assert(pd.branchType() == branchType_);
214  // Create a group for the produced product.
215  fillGroup(pd);
216  }
217  }
void addToProcessHistory()
Definition: Principal.cc:423
BranchType branchType_
Definition: Principal.h:230
std::atomic< ProductTable const * > producedProducts_
Definition: Principal.h:237
decltype(auto) values(Coll &&coll)
Range-for loop helper iterating across the values of the specified collection.
void fillGroup(BranchDescription const &)
Definition: Principal.cc:137
void art::Principal::ctor_create_groups ( cet::exempt_ptr< ProductTable const >  presentProducts)
private

Definition at line 68 of file Principal.cc.

References util::values().

Referenced by Principal(), and processHistoryID().

70  {
71  if (!presentProducts) {
72  return;
73  }
74  // Note: Dropped products are a problem. We should not create
75  // groups for them now because later we may open a secondary
76  // file which actually contains them and we want the
77  // secondary principal to have those groups. However some
78  // code expects to be able to find a group for dropped
79  // products, so getGroupTryAllFiles ignores groups for
80  // dropped products instead.
81  for (auto const& pd :
82  presentProducts->descriptions | ::ranges::views::values) {
83  assert(pd.branchType() == branchType_);
84  fillGroup(pd);
85  }
86  }
BranchType branchType_
Definition: Principal.h:230
decltype(auto) values(Coll &&coll)
Range-for loop helper iterating across the values of the specified collection.
void fillGroup(BranchDescription const &)
Definition: Principal.cc:137
void art::Principal::ctor_fetch_process_history ( ProcessHistoryID const &  phid)
private

Definition at line 109 of file Principal.cc.

References util::get(), art::Hash< I >::isValid(), and std::swap().

Referenced by Principal(), and processHistoryID().

110  {
111  if (!phid.isValid()) {
112  return;
113  }
114  ProcessHistory processHistory;
115  ProcessHistoryRegistry::get(phid, processHistory);
116  std::swap(processHistory_, processHistory);
117  }
ProcessHistory processHistory_
Definition: Principal.h:231
static collection_type const & get()
ProcessHistory const & processHistory() const
Definition: Principal.cc:247
void swap(lar::deep_const_fwd_iterator_nested< CITER, INNERCONTEXTRACT > &a, lar::deep_const_fwd_iterator_nested< CITER, INNERCONTEXTRACT > &b)
void art::Principal::ctor_read_provenance ( )
private

Definition at line 89 of file Principal.cc.

References art::productstatus::dummyToPreventDoubleCount(), and art::productstatus::unknown().

Referenced by Principal(), and processHistoryID().

90  {
91  for (auto&& provenance : delayedReader_->readProvenance()) {
93  if (g.get() == nullptr) {
94  continue;
95  }
97  g->setProductProvenance(make_unique<ProductProvenance>(provenance));
98  } else {
99  // We have an old format file, convert.
100  g->setProductProvenance(make_unique<ProductProvenance>(
104  }
105  }
106  }
Parentage const & parentage() const
Definition: Provenance.cc:103
ProductID productID() const noexcept
Definition: Provenance.cc:72
std::vector< ProductID > const & parents() const
Definition: Parentage.cc:37
constexpr ProductStatus dummyToPreventDoubleCount() noexcept
Definition: ProductStatus.h:25
constexpr ProductStatus unknown() noexcept
Definition: ProductStatus.h:31
cet::exempt_ptr< Group > getGroupLocal(ProductID const) const
Definition: Principal.cc:852
std::unique_ptr< DelayedReader > delayedReader_
Definition: Principal.h:250
ProductStatus productStatus() const
Definition: Provenance.cc:97
Provenance provenance(ProductID id) const
Definition: Principal.cc:189
void art::Principal::enableLookupOfProducedProducts ( )

Definition at line 220 of file Principal.cc.

References enableLookupOfProducedProducts_.

221  {
223  }
std::atomic< bool > enableLookupOfProducedProducts_
Definition: Principal.h:238
Principal::const_iterator art::Principal::end ( void  ) const

Definition at line 284 of file Principal.cc.

References groupMutex_, and groups_.

Referenced by processHistoryID().

285  {
286  std::lock_guard sentry{groupMutex_};
287  return groups_.end();
288  }
GroupCollection groups_
Definition: Principal.h:246
std::recursive_mutex groupMutex_
Definition: Principal.h:241
void art::Principal::fillGroup ( BranchDescription const &  pd)
protected

Definition at line 137 of file Principal.cc.

References util::cend(), art::combinable(), art::errors::Configuration, delayedReader_, groupMutex_, groups_, art::BranchDescription::processName(), art::BranchDescription::productID(), and art::errors::ProductRegistrationFailure.

Referenced by createGroupsForProducedProducts(), and processHistoryID().

138  {
139  std::lock_guard sentry{groupMutex_};
140  auto it = groups_.find(pd.productID());
141  if (it != std::cend(groups_)) {
142  // The 'combinable' call does not require that the processing
143  // history be the same, which is not what we are checking for here.
144  auto const& found_pd = it->second->productDescription();
145  if (combinable(found_pd, pd)) {
147  << "The process name " << pd.processName()
148  << " was previously used on these products.\n"
149  << "Please modify the configuration file to use a "
150  << "distinct process name.\n";
151  }
153  << "The product ID " << pd.productID() << " of the new product:\n"
154  << pd
155  << " collides with the product ID of the already-existing product:\n"
156  << found_pd
157  << "Please modify the instance name of the new product so as to avoid "
158  "the product ID collision.\n"
159  << "In addition, please notify artists@fnal.gov of this error.\n";
160  }
161 
162  groups_[pd.productID()] = create_group(delayedReader_.get(), pd);
163  }
decltype(auto) constexpr cend(T &&obj)
ADL-aware version of std::cend.
Definition: StdUtils.h:93
GroupCollection groups_
Definition: Principal.h:246
std::recursive_mutex groupMutex_
Definition: Principal.h:241
bool combinable(BranchDescription const &a, BranchDescription const &b)
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
std::unique_ptr< DelayedReader > delayedReader_
Definition: Principal.h:250
std::size_t art::Principal::findGroups ( ProcessLookup const &  pl,
ModuleContext const &  mc,
SelectorBase const &  sel,
std::vector< cet::exempt_ptr< Group >> &  groups 
) const
private

Definition at line 461 of file Principal.cc.

References findGroupsForProcess(), art::ProcessHistory::get_mutex(), and processHistory_.

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

465  {
466  // Loop over processes in reverse time order. Sometimes we want
467  // to stop after we find a process with matches so check for that
468  // at each step.
469  std::size_t found{};
470  // MT note: We must protect the process history iterators here
471  // against possible invalidation by output modules
472  // inserting a process history entry while we are
473  // iterating.
474  std::lock_guard sentry{processHistory_.get_mutex()};
475  // We must skip over duplicate entries of the same process
476  // configuration in the process history. This unfortunately
477  // happened with the SamplingInput source.
478  for (auto const& h :
479  ::ranges::views::reverse(processHistory_) | ::ranges::views::unique) {
480  if (auto it = pl.find(h.processName()); it != pl.end()) {
481  found += findGroupsForProcess(it->second, mc, sel, groups);
482  }
483  }
484  return found;
485  }
ProcessHistory processHistory_
Definition: Principal.h:231
std::recursive_mutex & get_mutex() const
size_t findGroupsForProcess(std::vector< ProductID > const &vpid, ModuleContext const &mc, SelectorBase const &selector, std::vector< cet::exempt_ptr< Group >> &groups) const
Definition: Principal.cc:667
std::size_t art::Principal::findGroupsForProcess ( std::vector< ProductID > const &  vpid,
ModuleContext const &  mc,
SelectorBase const &  selector,
std::vector< cet::exempt_ptr< Group >> &  groups 
) const
private

Definition at line 667 of file Principal.cc.

References getGroupLocal(), art::SelectorBase::match(), art::ModuleContext::onSamePathAs(), and art::ModuleContext::onTriggerPath().

Referenced by findGroups(), and processHistoryID().

672  {
673  std::size_t found{}; // Horrible hack that should go away
674  for (auto const pid : vpid) {
675  auto group = getGroupLocal(pid);
676  if (!group) {
677  continue;
678  }
679  auto const& pd = group->productDescription();
680  if (pd.dropped()) {
681  continue;
682  }
683  // If we are processing a trigger path, the only visible
684  // produced products are those that originate from modules on
685  // the same path we're currently processing.
686  if (mc.onTriggerPath() && pd.produced() &&
687  !mc.onSamePathAs(pd.moduleLabel())) {
688  continue;
689  }
690  if (!sel.match(pd)) {
691  continue;
692  }
693  // Found a good match, save it.
694  res.emplace_back(group);
695  ++found;
696  }
697  return found;
698  }
cet::exempt_ptr< Group > getGroupLocal(ProductID const) const
Definition: Principal.cc:852
std::vector< cet::exempt_ptr< Group > > art::Principal::findGroupsForProduct ( ModuleContext const &  mc,
WrappedTypeID const &  wrapped,
SelectorBase const &  selector,
ProcessTag const &  processTag 
) const
private

Definition at line 625 of file Principal.cc.

References art::ProcessTag::current_process_search_allowed(), enableLookupOfProducedProducts_, findGroups(), findGroupsFromInputFile(), art::TypeID::friendlyClassName(), art::ProcessTag::input_source_search_allowed(), producedProducts_, art::WrappedTypeID::product_type, secondaryPrincipals_, and tryNextSecondaryFile().

Referenced by getBySelector(), getInputTags(), getMany(), and processHistoryID().

629  {
630  std::vector<cet::exempt_ptr<Group>> results;
631  unsigned ret{};
632  // Find groups from current process
633  if (processTag.current_process_search_allowed() &&
635  auto const& lookup = producedProducts_.load()->productLookup;
636  auto it = lookup.find(wrapped.product_type.friendlyClassName());
637  if (it != lookup.end()) {
638  ret += findGroups(it->second, mc, selector, results);
639  }
640  }
641 
642  if (!processTag.input_source_search_allowed()) {
643  return results;
644  }
645 
646  // Look through currently opened input files
647  ret += findGroupsFromInputFile(mc, wrapped, selector, results);
648  if (ret) {
649  return results;
650  }
651  for (auto const& sp : secondaryPrincipals_) {
652  if (sp->findGroupsFromInputFile(mc, wrapped, selector, results)) {
653  return results;
654  }
655  }
656  // Open more secondary files if necessary
657  while (auto sp = tryNextSecondaryFile()) {
658  auto& new_sp = secondaryPrincipals_.emplace_back(std::move(sp));
659  if (new_sp->findGroupsFromInputFile(mc, wrapped, selector, results)) {
660  return results;
661  }
662  }
663  return results;
664  }
size_t findGroups(ProcessLookup const &, ModuleContext const &, SelectorBase const &, std::vector< cet::exempt_ptr< Group >> &groups) const
Definition: Principal.cc:461
std::atomic< bool > enableLookupOfProducedProducts_
Definition: Principal.h:238
auto tryNextSecondaryFile() const
Definition: Principal.cc:544
size_t findGroupsFromInputFile(ModuleContext const &, WrappedTypeID const &wrapped, SelectorBase const &, std::vector< cet::exempt_ptr< Group >> &results) const
Definition: Principal.cc:607
std::atomic< ProductTable const * > producedProducts_
Definition: Principal.h:237
std::vector< std::unique_ptr< Principal > > secondaryPrincipals_
Definition: Principal.h:260
std::size_t art::Principal::findGroupsFromInputFile ( ModuleContext const &  mc,
WrappedTypeID const &  wrapped,
SelectorBase const &  selector,
std::vector< cet::exempt_ptr< Group >> &  results 
) const
private

Definition at line 607 of file Principal.cc.

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

Referenced by findGroupsForProduct(), and processHistoryID().

612  {
613  if (!presentProducts_.load()) {
614  return 0;
615  }
616  auto const& lookup = presentProducts_.load()->productLookup;
617  auto it = lookup.find(wrapped.product_type.friendlyClassName());
618  if (it == lookup.end()) {
619  return 0;
620  }
621  return findGroups(it->second, mc, selector, groups);
622  }
size_t findGroups(ProcessLookup const &, ModuleContext const &, SelectorBase const &, std::vector< cet::exempt_ptr< Group >> &groups) const
Definition: Principal.cc:461
std::atomic< ProductTable const * > presentProducts_
Definition: Principal.h:236
GroupQueryResult art::Principal::getByLabel ( ModuleContext const &  mc,
WrappedTypeID const &  wrapped,
std::string const &  label,
std::string const &  productInstanceName,
ProcessTag const &  processTag 
) const

Definition at line 506 of file Principal.cc.

References getBySelector(), and art::ProcessTag::name().

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

511  {
512  auto const& processName = processTag.name();
513  Selector const sel{ModuleLabelSelector{label} &&
514  ProductInstanceNameSelector{productInstanceName} &&
515  ProcessNameSelector{processName}};
516  return getBySelector(mc, wrapped, sel, processTag);
517  }
GroupQueryResult getBySelector(ModuleContext const &mc, WrappedTypeID const &wrapped, SelectorBase const &, ProcessTag const &) const
Definition: Principal.cc:488
GroupQueryResult art::Principal::getByProductID ( ProductID const  pid) const

Definition at line 839 of file Principal.cc.

References branchType_, getGroupTryAllFiles(), and art::errors::ProductNotFound.

Referenced by art::ProductRetriever::getByProductID_(), and art::ProductRetriever::getProductProvenance().

840  {
841  if (auto g = getGroupTryAllFiles(pid)) {
842  return GroupQueryResult{g};
843  }
844  auto whyFailed =
845  make_shared<Exception>(errors::ProductNotFound, "InvalidID");
846  *whyFailed << "Principal::getByProductID: no product with branch type: "
847  << branchType_ << " product id: " << pid << '\n';
848  return GroupQueryResult{whyFailed};
849  }
BranchType branchType_
Definition: Principal.h:230
cet::exempt_ptr< Group > getGroupTryAllFiles(ProductID const) const
Definition: Principal.cc:860
GroupQueryResult art::Principal::getBySelector ( ModuleContext const &  mc,
WrappedTypeID const &  wrapped,
SelectorBase const &  sel,
ProcessTag const &  processTag 
) const

Definition at line 488 of file Principal.cc.

References findGroupsForProduct(), art::detail::indent(), art::SelectorBase::print(), art::WrappedTypeID::product_type, art::errors::ProductNotFound, and art::resolve_unique_product().

Referenced by getByLabel(), and art::ProductRetriever::getBySelector_().

492  {
493  auto const groups = findGroupsForProduct(mc, wrapped, sel, processTag);
494  auto const result = resolve_unique_product(groups, wrapped);
495  if (!result.has_value()) {
496  auto whyFailed = std::make_shared<Exception>(errors::ProductNotFound);
497  *whyFailed << "Found zero products matching all selection criteria\n"
498  << indent << "C++ type: " << wrapped.product_type << '\n'
499  << sel.print(indent) << '\n';
500  return GroupQueryResult{whyFailed};
501  }
502  return *result;
503  }
std::optional< GroupQueryResult > resolve_unique_product(std::vector< cet::exempt_ptr< art::Group >> const &product_groups, art::WrappedTypeID const &wrapped)
Definition: Group.cc:387
std::string indent(std::size_t const i)
std::vector< cet::exempt_ptr< Group > > findGroupsForProduct(ModuleContext const &mc, WrappedTypeID const &wrapped, SelectorBase const &, ProcessTag const &) const
Definition: Principal.cc:625
EDProductGetter const * art::PrincipalBase::getEDProductGetter ( ProductID const &  pid) const
inherited

Definition at line 12 of file PrincipalBase.cc.

References art::PrincipalBase::getEDProductGetter_().

13  {
14  return getEDProductGetter_(pid);
15  }
virtual EDProductGetter const * getEDProductGetter_(ProductID const &) const =0
EDProductGetter const * art::Principal::getEDProductGetter_ ( ProductID const &  pid) const
overrideprivatevirtual

Implements art::PrincipalBase.

Definition at line 195 of file Principal.cc.

References productGetter().

Referenced by processHistoryID().

196  {
197  return productGetter(pid);
198  }
EDProductGetter const * productGetter(ProductID id) const
Definition: Principal.cc:177
OutputHandle art::Principal::getForOutput ( ProductID const &  pid,
bool  resolveProd 
) const

Definition at line 750 of file Principal.cc.

References getGroupTryAllFiles(), art::OutputHandle::invalid(), art::OutputHandle::productProvenance(), and art::OutputHandle::rangeOfValidity().

751  {
752  // MT-FIXME: Uses of group!
753  auto g = getGroupTryAllFiles(pid);
754  if (g.get() == nullptr) {
755  return OutputHandle::invalid();
756  }
757  if (resolveProd) {
758  if (!g->resolveProductIfAvailable()) {
759  // Behavior is the same as if the group wasn't there.
760  return OutputHandle::invalid();
761  }
762  if (g->anyProduct() == nullptr) {
763  return OutputHandle::invalid();
764  }
765  if (!g->anyProduct()->isPresent()) {
766  return OutputHandle::invalid();
767  }
768  }
769  if (!g->anyProduct() && !g->productProvenance()) {
770  return OutputHandle{g->rangeOfValidity()};
771  }
772  return OutputHandle{g->anyProduct(),
773  &g->productDescription(),
774  g->productProvenance(),
775  g->rangeOfValidity()};
776  }
cet::exempt_ptr< Group > getGroupTryAllFiles(ProductID const) const
Definition: Principal.cc:860
static OutputHandle invalid()
Definition: OutputHandle.h:44
cet::exempt_ptr< Group > art::Principal::getGroupLocal ( ProductID const  pid) const
private

Definition at line 852 of file Principal.cc.

References groupMutex_, and groups_.

Referenced by branchToProductProvenance(), findGroupsForProcess(), getGroupTryAllFiles(), processHistoryID(), provenance(), and put().

853  {
854  std::lock_guard sentry{groupMutex_};
855  auto it = groups_.find(pid);
856  return it != groups_.cend() ? it->second.get() : nullptr;
857  }
GroupCollection groups_
Definition: Principal.h:246
std::recursive_mutex groupMutex_
Definition: Principal.h:241
cet::exempt_ptr< Group > art::Principal::getGroupTryAllFiles ( ProductID const  pid) const
private

Definition at line 860 of file Principal.cc.

References getGroupLocal(), presentFromSource(), producedInProcess(), secondaryPrincipals_, and tryNextSecondaryFile().

Referenced by getByProductID(), getForOutput(), processHistoryID(), and productGetter().

861  {
862  // Look through current process and currently opened primary input file.
864  return getGroupLocal(pid);
865  }
866  // Look through secondary files
867  for (auto const& sp : secondaryPrincipals_) {
868  if (sp->presentFromSource(pid)) {
869  return sp->getGroupLocal(pid);
870  }
871  }
872  // Try new secondary files
873  while (auto sp = tryNextSecondaryFile()) {
874  auto& new_sp = secondaryPrincipals_.emplace_back(std::move(sp));
875  if (new_sp->presentFromSource(pid)) {
876  return new_sp->getGroupLocal(pid);
877  }
878  }
879  return nullptr;
880  }
auto tryNextSecondaryFile() const
Definition: Principal.cc:544
bool presentFromSource(ProductID) const
Definition: Principal.cc:829
cet::exempt_ptr< Group > getGroupLocal(ProductID const) const
Definition: Principal.cc:852
std::vector< std::unique_ptr< Principal > > secondaryPrincipals_
Definition: Principal.h:260
bool producedInProcess(ProductID) const
Definition: Principal.cc:819
std::vector< InputTag > art::Principal::getInputTags ( ModuleContext const &  mc,
WrappedTypeID const &  wrapped,
SelectorBase const &  sel,
ProcessTag const &  processTag 
) const

Definition at line 520 of file Principal.cc.

References findGroupsForProduct().

Referenced by art::ProductRetriever::getInputTags_().

524  {
525  std::vector<InputTag> tags;
526  auto const groups = findGroupsForProduct(mc, wrapped, sel, processTag);
527  cet::transform_all(groups, back_inserter(tags), [](auto const g) {
528  return g->productDescription().inputTag();
529  });
530  return tags;
531  }
std::vector< cet::exempt_ptr< Group > > findGroupsForProduct(ModuleContext const &mc, WrappedTypeID const &wrapped, SelectorBase const &, ProcessTag const &) const
Definition: Principal.cc:625
std::vector< GroupQueryResult > art::Principal::getMany ( ModuleContext const &  mc,
WrappedTypeID const &  wrapped,
SelectorBase const &  sel,
ProcessTag const &  processTag 
) const

Definition at line 534 of file Principal.cc.

References findGroupsForProduct(), art::resolve_products(), and art::WrappedTypeID::wrapped_product_type.

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

538  {
539  auto const groups = findGroupsForProduct(mc, wrapped, sel, processTag);
540  return resolve_products(groups, wrapped.wrapped_product_type);
541  }
std::vector< cet::exempt_ptr< Group > > findGroupsForProduct(ModuleContext const &mc, WrappedTypeID const &wrapped, SelectorBase const &, ProcessTag const &) const
Definition: Principal.cc:625
std::vector< GroupQueryResult > resolve_products(std::vector< cet::exempt_ptr< art::Group >> const &groups, art::TypeID const &wrapped_type)
Definition: Group.cc:428
std::vector< cet::exempt_ptr< Group > > art::Principal::getMatchingSequence ( ModuleContext const &  mc,
SelectorBase const &  selector,
ProcessTag const &  processTag 
) const

Definition at line 550 of file Principal.cc.

References art::ProcessTag::current_process_search_allowed(), enableLookupOfProducedProducts_, findGroups(), art::ProcessTag::input_source_search_allowed(), matchingSequenceFromInputFile(), producedProducts_, secondaryPrincipals_, and tryNextSecondaryFile().

Referenced by art::ProductRetriever::getContainerForView_().

553  {
554  std::vector<cet::exempt_ptr<Group>> groups;
555  // Find groups from current process
556  if (processTag.current_process_search_allowed() &&
558  if (findGroups(
559  producedProducts_.load()->viewLookup, mc, selector, groups) != 0) {
560  return groups;
561  }
562  }
563 
564  if (!processTag.input_source_search_allowed()) {
565  return groups;
566  }
567 
568  // Look through currently opened input files
569  if (groups.empty()) {
570  groups = matchingSequenceFromInputFile(mc, selector);
571  if (!groups.empty()) {
572  return groups;
573  }
574  for (auto const& sp : secondaryPrincipals_) {
575  groups = sp->matchingSequenceFromInputFile(mc, selector);
576  if (!groups.empty()) {
577  return groups;
578  }
579  }
580  }
581  // Open more secondary files if necessary
582  if (groups.empty()) {
583  while (auto sp = tryNextSecondaryFile()) {
584  auto& new_sp = secondaryPrincipals_.emplace_back(std::move(sp));
585  groups = new_sp->matchingSequenceFromInputFile(mc, selector);
586  if (!groups.empty()) {
587  return groups;
588  }
589  }
590  }
591  return groups;
592  }
size_t findGroups(ProcessLookup const &, ModuleContext const &, SelectorBase const &, std::vector< cet::exempt_ptr< Group >> &groups) const
Definition: Principal.cc:461
std::atomic< bool > enableLookupOfProducedProducts_
Definition: Principal.h:238
auto tryNextSecondaryFile() const
Definition: Principal.cc:544
std::vector< cet::exempt_ptr< Group > > matchingSequenceFromInputFile(ModuleContext const &, SelectorBase const &) const
Definition: Principal.cc:595
std::atomic< ProductTable const * > producedProducts_
Definition: Principal.h:237
std::vector< std::unique_ptr< Principal > > secondaryPrincipals_
Definition: Principal.h:260
cet::exempt_ptr< BranchDescription const > art::Principal::getProductDescription ( ProductID const  pid,
bool const  alwaysEnableLookupOfProducedProducts = false 
) const

Definition at line 779 of file Principal.cc.

References enableLookupOfProducedProducts_, presentProducts_, producedProducts_, and secondaryPrincipals_.

Referenced by art::ProductRetriever::getProductDescription(), art::ProductInserter::getProductDescription_(), and art::ProductRetriever::getProductID_().

782  {
783  // Find groups from current process
784  if (alwaysEnableLookupOfProducedProducts ||
786  if (producedProducts_.load() != nullptr) {
787  if (auto result = producedProducts_.load()->description(pid)) {
788  return result;
789  }
790  }
791  }
792  if (presentProducts_.load()) {
793  // Look through currently opened input files
794  if (auto result = presentProducts_.load()->description(pid)) {
795  return result;
796  }
797  }
798  for (auto const& sp : secondaryPrincipals_) {
799  if (auto result = sp->getProductDescription(pid)) {
800  return result;
801  }
802  }
803  return nullptr;
804  }
std::atomic< bool > enableLookupOfProducedProducts_
Definition: Principal.h:238
std::atomic< ProductTable const * > producedProducts_
Definition: Principal.h:237
std::atomic< ProductTable const * > presentProducts_
Definition: Principal.h:236
std::vector< std::unique_ptr< Principal > > secondaryPrincipals_
Definition: Principal.h:260
std::optional< ProductInserter > art::Principal::makeInserter ( ModuleContext const &  mc)
protected

Definition at line 813 of file Principal.cc.

References branchType_.

Referenced by art::EventPrincipal::makeEvent(), art::ResultsPrincipal::makeResults(), art::RunPrincipal::makeRun(), art::SubRunPrincipal::makeSubRun(), and processHistoryID().

814  {
815  return std::make_optional<ProductInserter>(branchType_, *this, mc);
816  }
BranchType branchType_
Definition: Principal.h:230
void art::Principal::markProcessHistoryAsModified ( )

Definition at line 170 of file Principal.cc.

References processHistoryModified_.

171  {
173  }
std::atomic< bool > processHistoryModified_
Definition: Principal.h:232
std::vector< cet::exempt_ptr< Group > > art::Principal::matchingSequenceFromInputFile ( ModuleContext const &  mc,
SelectorBase const &  selector 
) const
private

Definition at line 595 of file Principal.cc.

References findGroups(), and presentProducts_.

Referenced by getMatchingSequence(), and processHistoryID().

597  {
598  std::vector<cet::exempt_ptr<Group>> groups;
599  if (!presentProducts_.load()) {
600  return groups;
601  }
602  findGroups(presentProducts_.load()->viewLookup, mc, selector, groups);
603  return groups;
604  }
size_t findGroups(ProcessLookup const &, ModuleContext const &, SelectorBase const &, std::vector< cet::exempt_ptr< Group >> &groups) const
Definition: Principal.cc:461
std::atomic< ProductTable const * > presentProducts_
Definition: Principal.h:236
Principal& art::Principal::operator= ( Principal const &  )
delete
bool art::Principal::presentFromSource ( ProductID  pid) const
private

Definition at line 829 of file Principal.cc.

References presentProducts_.

Referenced by getGroupTryAllFiles(), and processHistoryID().

830  {
831  if (!presentProducts_.load()) {
832  return false;
833  }
834  auto pd = presentProducts_.load()->description(pid);
835  return pd == nullptr ? false : pd->present();
836  }
std::atomic< ProductTable const * > presentProducts_
Definition: Principal.h:236
ProcessConfiguration const & art::Principal::processConfiguration ( ) const

Definition at line 257 of file Principal.cc.

References processConfiguration_.

258  {
259  return processConfiguration_;
260  }
ProcessConfiguration const & processConfiguration_
Definition: Principal.h:233
ProcessHistory const & art::Principal::processHistory ( ) const

Definition at line 247 of file Principal.cc.

References processHistory_.

Referenced by art::ProductRetriever::getProcessParameterSet(), art::Event::processHistory(), art::Run::processHistory(), and art::SubRun::processHistory().

248  {
249  // MT note: We make no attempt to protect callers who use this
250  // call to get access to the iteration interface of the
251  // process history. See the threading notes there and
252  // here for the reasons why.
253  return processHistory_;
254  }
ProcessHistory processHistory_
Definition: Principal.h:231
bool art::Principal::producedInProcess ( ProductID  pid) const
private

Definition at line 819 of file Principal.cc.

References enableLookupOfProducedProducts_, and producedProducts_.

Referenced by getGroupTryAllFiles(), and processHistoryID().

820  {
821  if (!enableLookupOfProducedProducts_.load()) {
822  return false;
823  }
824  auto pd = producedProducts_.load()->description(pid);
825  return pd == nullptr ? false : pd->produced();
826  }
std::atomic< bool > enableLookupOfProducedProducts_
Definition: Principal.h:238
std::atomic< ProductTable const * > producedProducts_
Definition: Principal.h:237
EDProductGetter const * art::Principal::productGetter ( ProductID  id) const

Definition at line 177 of file Principal.cc.

References getGroupTryAllFiles().

Referenced by getEDProductGetter_(), art::SourceHelper::makePtr(), art::ProductRetriever::productGetter(), and art::ProductInserter::productGetter_().

178  {
179  auto g = getGroupTryAllFiles(pid);
180  if (g.get() != nullptr) {
181  // Note: All produced products should be found.
182  return g.get();
183  }
184  return nullptr;
185  }
cet::exempt_ptr< Group > getGroupTryAllFiles(ProductID const) const
Definition: Principal.cc:860
Provenance art::Principal::provenance ( ProductID  id) const

Definition at line 189 of file Principal.cc.

References getGroupLocal().

Referenced by art::ProductInserter::provenance_().

190  {
191  return Provenance{getGroupLocal(pid)};
192  }
cet::exempt_ptr< Group > getGroupLocal(ProductID const) const
Definition: Principal.cc:852
void art::Principal::put ( BranchDescription const &  bd,
std::unique_ptr< ProductProvenance const > &&  pp,
std::unique_ptr< EDProduct > &&  edp,
std::unique_ptr< RangeSet > &&  rs 
)

Definition at line 713 of file Principal.cc.

References art::BranchDescription::branchName(), branchType_, getGroupLocal(), art::RangeSet::invalid(), art::BranchDescription::productID(), art::errors::ProductRegistrationFailure, and art::detail::range_sets_supported().

Referenced by art::ProductInserter::commitProducts(), and processHistoryID().

717  {
718  assert(edp);
720  // Note: We intentionally allow group and provenance replacement
721  // for run and subrun products.
722  auto group = getGroupLocal(bd.productID());
723  assert(group);
724  group->setProductAndProvenance(
725  std::move(pp), std::move(edp), std::move(rs));
726  } else {
727  auto group = getGroupLocal(bd.productID());
728  assert(group);
729  if (group->anyProduct() != nullptr) {
730  throw Exception(errors::ProductRegistrationFailure, "Principal::put:")
731  << "Problem found during put of " << branchType_
732  << " product: product already put for " << bd.branchName() << '\n';
733  }
734  group->setProductAndProvenance(
735  std::move(pp),
736  std::move(edp),
737  make_unique<RangeSet>(RangeSet::invalid()));
738  }
739  }
BranchType branchType_
Definition: Principal.h:230
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
static RangeSet invalid()
Definition: RangeSet.cc:45
cet::exempt_ptr< Group > getGroupLocal(ProductID const) const
Definition: Principal.cc:852
constexpr bool range_sets_supported(BranchType const bt)
void art::Principal::readImmediate ( ) const

Definition at line 226 of file Principal.cc.

References groupMutex_, groups_, and util::values().

227  {
228  // Read all data products and provenance immediately, if
229  // available. Used only by RootInputFile to implement the
230  // delayedRead*Products config options.
231  //
232  // Note: The input source lock will be held when this routine is called.
233  //
234  // MT-TODO: For right now ignore the delay reading option for
235  // product provenance. If we do the delay reading then we
236  // must use a lock to interlock all fetches of provenance
237  // because the delay read fills the pp_by_pid_ one entry
238  // at a time, and we do not want other threads to find
239  // the info only partly there.
240  std::lock_guard sentry{groupMutex_};
241  for (auto const& group : groups_ | ::ranges::views::values) {
242  group->resolveProductIfAvailable();
243  }
244  }
GroupCollection groups_
Definition: Principal.h:246
std::recursive_mutex groupMutex_
Definition: Principal.h:241
decltype(auto) values(Coll &&coll)
Range-for loop helper iterating across the values of the specified collection.
RangeSet art::Principal::seenRanges ( ) const
void art::Principal::setProcessHistoryIDcombined ( ProcessHistoryID const &  )
protected

Referenced by processHistoryID().

size_t art::Principal::size ( void  ) const

Definition at line 263 of file Principal.cc.

References groupMutex_, and groups_.

Referenced by processHistoryID().

264  {
265  std::lock_guard sentry{groupMutex_};
266  return groups_.size();
267  }
GroupCollection groups_
Definition: Principal.h:246
std::recursive_mutex groupMutex_
Definition: Principal.h:241
auto art::Principal::tryNextSecondaryFile ( ) const
private

Definition at line 544 of file Principal.cc.

References delayedReader_, and nextSecondaryFileIdx_.

Referenced by findGroupsForProduct(), getGroupTryAllFiles(), getMatchingSequence(), and processHistoryID().

545  {
546  return delayedReader_->readFromSecondaryFile(nextSecondaryFileIdx_);
547  }
int nextSecondaryFileIdx_
Definition: Principal.h:264
std::unique_ptr< DelayedReader > delayedReader_
Definition: Principal.h:250
void art::Principal::updateSeenRanges ( RangeSet const &  rs)
protected

Definition at line 707 of file Principal.cc.

References rangeSet_.

Referenced by processHistoryID().

708  {
709  rangeSet_ = rs;
710  }
RangeSet rangeSet_
Definition: Principal.h:266

Member Data Documentation

BranchType art::Principal::branchType_ {}
private
std::unique_ptr<DelayedReader> art::Principal::delayedReader_ {nullptr}
private

Definition at line 250 of file Principal.h.

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

std::atomic<bool> art::Principal::enableLookupOfProducedProducts_ {false}
private
std::recursive_mutex art::Principal::groupMutex_ {}
mutableprivate

Definition at line 241 of file Principal.h.

Referenced by begin(), cbegin(), cend(), end(), fillGroup(), getGroupLocal(), readImmediate(), and size().

GroupCollection art::Principal::groups_ {}
private

Definition at line 246 of file Principal.h.

Referenced by begin(), cbegin(), cend(), end(), fillGroup(), getGroupLocal(), readImmediate(), and size().

int art::Principal::nextSecondaryFileIdx_ {}
mutableprivate

Definition at line 264 of file Principal.h.

Referenced by tryNextSecondaryFile().

std::atomic<ProductTable const*> art::Principal::presentProducts_
private
ProcessConfiguration const& art::Principal::processConfiguration_
private

Definition at line 233 of file Principal.h.

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

ProcessHistory art::Principal::processHistory_ {}
private

Definition at line 231 of file Principal.h.

Referenced by addToProcessHistory(), findGroups(), processHistory(), and processHistoryID().

std::atomic<bool> art::Principal::processHistoryModified_ {false}
private

Definition at line 232 of file Principal.h.

Referenced by addToProcessHistory(), and markProcessHistoryAsModified().

std::atomic<ProductTable const*> art::Principal::producedProducts_ {nullptr}
private
RangeSet art::Principal::rangeSet_ {RangeSet::invalid()}
private

Definition at line 266 of file Principal.h.

Referenced by seenRanges(), and updateSeenRanges().

std::vector<std::unique_ptr<Principal> > art::Principal::secondaryPrincipals_ {}
mutableprivate

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