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

#include "ProductInserter.h"

Classes

struct  PMValue
 

Public Member Functions

 ~ProductInserter ()
 
 ProductInserter (BranchType bt, Principal &p, ModuleContext const &mc)
 
 ProductInserter (ProductInserter const &)=delete
 
ProductInserteroperator= (ProductInserter const &)=delete
 
 ProductInserter (ProductInserter &&)=default
 
ProductInserteroperator= (ProductInserter &&)=default
 
template<typename PROD >
PutHandle< PROD > put (std::unique_ptr< PROD > &&edp, std::string const &instance={})
 
template<typename PROD >
PutHandle< PROD > put (std::unique_ptr< PROD > &&edp, std::string const &instance, RangeSet const &rs)
 
void commitProducts ()
 
void commitProducts (bool checkProducts, std::map< TypeLabel, BranchDescription > const *expectedProducts, std::vector< ProductID > retrievedPIDs)
 

Private Member Functions

BranchDescription const & getProductDescription_ (TypeID const &type, std::string const &instance, bool const alwaysEnableLookupOfProducedProducts=false) const
 
EDProductGetter const * productGetter_ (ProductID id) const
 
Provenance provenance_ (ProductID id) const
 

Private Attributes

std::unique_ptr< std::recursive_mutex > mutex_
 
BranchType branchType_
 
Principalprincipal_
 
ModuleDescription const * md_
 
std::map< TypeLabel, PMValueputProducts_ {}
 

Detailed Description

Definition at line 37 of file ProductInserter.h.

Constructor & Destructor Documentation

art::ProductInserter::~ProductInserter ( )
default
art::ProductInserter::ProductInserter ( BranchType  bt,
Principal p,
ModuleContext const &  mc 
)
explicit

Definition at line 37 of file ProductInserter.cc.

References md_, and principal_.

40  : branchType_{bt}, principal_{&principal}, md_{&mc.moduleDescription()}
41  {}
ModuleDescription const * md_
art::ProductInserter::ProductInserter ( ProductInserter const &  )
delete
art::ProductInserter::ProductInserter ( ProductInserter &&  )
default

Member Function Documentation

void art::ProductInserter::commitProducts ( )

Definition at line 87 of file ProductInserter.cc.

References branchType_, art::RangeSet::invalid(), mutex_, art::productstatus::present(), principal_, art::Principal::put(), putProducts_, art::detail::range_sets_supported(), and util::values().

88  {
89  std::lock_guard lock{*mutex_};
90  for (auto&& [product, pd, range_set] :
92  auto pp = make_unique<ProductProvenance const>(pd.productID(),
95  make_unique<RangeSet>(std::move(range_set)) :
96  make_unique<RangeSet>(RangeSet::invalid());
97  principal_->put(pd, std::move(pp), std::move(product), std::move(rs));
98  }
99  putProducts_.clear();
100  }
decltype(auto) values(Coll &&coll)
Range-for loop helper iterating across the values of the specified collection.
void put(BranchDescription const &, std::unique_ptr< ProductProvenance const > &&, std::unique_ptr< EDProduct > &&, std::unique_ptr< RangeSet > &&)
Definition: Principal.cc:713
std::map< TypeLabel, PMValue > putProducts_
std::unique_ptr< std::recursive_mutex > mutex_
static RangeSet invalid()
Definition: RangeSet.cc:45
constexpr bool range_sets_supported(BranchType const bt)
constexpr ProductStatus present() noexcept
Definition: ProductStatus.h:10
void art::ProductInserter::commitProducts ( bool  checkProducts,
std::map< TypeLabel, BranchDescription > const *  expectedProducts,
std::vector< ProductID retrievedPIDs 
)

Definition at line 44 of file ProductInserter.cc.

References branchType_, art::InEvent, art::RangeSet::invalid(), art::errors::LogicError, mutex_, art::productstatus::present(), principal_, art::Principal::put(), putProducts_, and util::values().

48  {
49  assert(branchType_ == InEvent);
50  std::lock_guard lock{*mutex_};
51  if (checkProducts) {
52  vector<string> missing;
53  for (auto const& [typeLabel, bd] : *expectedProducts) {
54  if (putProducts_.find(typeLabel) != putProducts_.cend()) {
55  continue;
56  }
57  ostringstream desc;
58  desc << bd;
59  missing.emplace_back(desc.str());
60  }
61  if (!missing.empty()) {
62  ostringstream errmsg;
63  HorizontalRule rule{25};
64  errmsg << "The following products have been declared with 'produces',\n"
65  << "but they have not been placed onto the event:\n"
66  << rule('=') << '\n';
67  for (auto const& desc : missing) {
68  errmsg << desc << rule('=') << '\n';
69  }
70  throw Exception{errors::LogicError, "ProductInserter::checkPutProducts"}
71  << errmsg.str();
72  }
73  }
74 
75  for (auto&& [product, pd, rs] : putProducts_ | ::ranges::views::values) {
76  auto pp = make_unique<ProductProvenance const>(
77  pd.productID(), productstatus::present(), retrievedPIDs);
78  principal_->put(pd,
79  std::move(pp),
80  std::move(product),
81  make_unique<RangeSet>(RangeSet::invalid()));
82  }
83  putProducts_.clear();
84  }
decltype(auto) values(Coll &&coll)
Range-for loop helper iterating across the values of the specified collection.
void put(BranchDescription const &, std::unique_ptr< ProductProvenance const > &&, std::unique_ptr< EDProduct > &&, std::unique_ptr< RangeSet > &&)
Definition: Principal.cc:713
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
std::map< TypeLabel, PMValue > putProducts_
std::unique_ptr< std::recursive_mutex > mutex_
static RangeSet invalid()
Definition: RangeSet.cc:45
constexpr ProductStatus present() noexcept
Definition: ProductStatus.h:10
BranchDescription const & art::ProductInserter::getProductDescription_ ( TypeID const &  type,
std::string const &  instance,
bool const  alwaysEnableLookupOfProducedProducts = false 
) const
private

Definition at line 103 of file ProductInserter.cc.

References branchType_, art::canonicalProductName(), art::TypeID::className(), art::TypeID::friendlyClassName(), art::Principal::getProductDescription(), instance, md_, art::ModuleDescription::moduleLabel(), mutex_, principal_, art::ModuleDescription::processName(), and art::errors::ProductRegistrationFailure.

Referenced by put().

107  {
108  std::lock_guard lock{*mutex_};
109  auto const product_name = canonicalProductName(type.friendlyClassName(),
110  md_->moduleLabel(),
111  instance,
112  md_->processName());
113  ProductID const pid{product_name};
115  pid, alwaysEnableLookupOfProducedProducts);
116  if (!bd || (bd->producedClassName() != type.className())) {
117  // Either we did not find the product, or the product we
118  // did find does not match (which can happen with Assns
119  // since Assns(A,B) and Assns(B,A) have the same ProductID
120  // but not the same class name.
122  "ProductInserter::getProductDescription_: error while "
123  "trying to retrieve product description:\n")
124  << "No product is registered for\n"
125  << " process name: '" << md_->processName() << "'\n"
126  << " module label: '" << md_->moduleLabel() << "'\n"
127  << " product class name: '" << type.className() << "'\n"
128  << " product friendly class name: '" << type.friendlyClassName()
129  << "'\n"
130  << " product instance name: '" << instance << "'\n"
131  << " branch type: '" << branchType_ << "'\n";
132  }
133  // The description object is owned by either the source or the
134  // event processor, whose lifetimes exceed that of the
135  // ProductInserter object. It is therefore safe to dereference.
136  return *bd;
137  }
std::string const & moduleLabel() const
const std::string instance
std::string const & processName() const
cet::exempt_ptr< BranchDescription const > getProductDescription(ProductID const pid, bool const alwaysEnableLookupOfProducedProducts=false) const
Definition: Principal.cc:779
std::string canonicalProductName(std::string const &friendlyClassName, std::string const &moduleLabel, std::string const &productInstanceName, std::string const &processName)
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
std::unique_ptr< std::recursive_mutex > mutex_
ModuleDescription const * md_
ProductInserter& art::ProductInserter::operator= ( ProductInserter const &  )
delete
ProductInserter& art::ProductInserter::operator= ( ProductInserter &&  )
default
EDProductGetter const * art::ProductInserter::productGetter_ ( ProductID  id) const
private

Definition at line 140 of file ProductInserter.cc.

References principal_, and art::Principal::productGetter().

Referenced by put().

141  {
142  return principal_->productGetter(id);
143  }
EDProductGetter const * productGetter(ProductID id) const
Definition: Principal.cc:177
Provenance art::ProductInserter::provenance_ ( ProductID  id) const
private

Definition at line 146 of file ProductInserter.cc.

References principal_, and art::Principal::provenance().

147  {
148  return principal_->provenance(id);
149  }
Provenance provenance(ProductID id) const
Definition: Principal.cc:189
template<typename PROD >
PutHandle< PROD > art::ProductInserter::put ( std::unique_ptr< PROD > &&  edp,
std::string const &  instance = {} 
)

Definition at line 102 of file ProductInserter.h.

References art::RangeSet::invalid().

103  {
104  return put(std::move(edp), instance, RangeSet::invalid());
105  }
const std::string instance
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
static RangeSet invalid()
Definition: RangeSet.cc:45
template<typename PROD >
PutHandle< PROD > art::ProductInserter::put ( std::unique_ptr< PROD > &&  edp,
std::string const &  instance,
RangeSet const &  rs 
)

Definition at line 109 of file ProductInserter.h.

References getProductDescription_(), art::ProductID::invalid(), md_, mutex_, art::errors::NullPointerError, art::ProductInserter::PMValue::product, productGetter_(), art::errors::ProductPutFailure, putProducts_, and art::detail::type_label_for().

112  {
113  TypeID const tid{typeid(PROD)};
114  if (!edp) {
116  << "A null unique_ptr was passed to 'put'.\n"
117  << "The pointer is of type " << tid << ".\n"
118  << "The specified productInstanceName was '" << instance << "'.\n";
119  }
120 
121  std::lock_guard lock{*mutex_};
122  auto const& bd = getProductDescription_(tid, instance, true);
123  assert(bd.productID() != ProductID::invalid());
124  auto const typeLabel =
126  auto wp = std::make_unique<Wrapper<PROD>>(std::move(edp));
127 
128  // Mind the product ownership! The wrapper is the final resting
129  // place of the product before it is taken out of memory.
130  cet::exempt_ptr<PROD const> product{wp->product()};
131  auto result =
132  putProducts_.try_emplace(typeLabel, PMValue{std::move(wp), bd, rs})
133  .second;
134  if (!result) {
135  constexpr cet::HorizontalRule rule{30};
137  << "Attempt to put multiple products with the following descriptions.\n"
138  << "Each product must be unique.\n"
139  << rule('=') << '\n'
140  << bd << rule('=') << '\n';
141  }
142  return PutHandle{
143  product.get(), productGetter_(bd.productID()), bd.productID()};
144  }
EDProductGetter const * productGetter_(ProductID id) const
TypeLabel type_label_for(TypeID const typeID, std::string const &instance, bool const supportsView, ModuleDescription const &md)
const std::string instance
double value
Definition: spectrum.C:18
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
BranchDescription const & getProductDescription_(TypeID const &type, std::string const &instance, bool const alwaysEnableLookupOfProducedProducts=false) const
std::map< TypeLabel, PMValue > putProducts_
std::unique_ptr< std::recursive_mutex > mutex_
static constexpr ProductID invalid() noexcept
Definition: ProductID.h:26
second_as<> second
Type of time stored in seconds, in double precision.
Definition: spacetime.h:82
ModuleDescription const * md_

Member Data Documentation

BranchType art::ProductInserter::branchType_
private

Definition at line 86 of file ProductInserter.h.

Referenced by commitProducts(), and getProductDescription_().

ModuleDescription const* art::ProductInserter::md_
private

Definition at line 92 of file ProductInserter.h.

Referenced by getProductDescription_(), ProductInserter(), and put().

std::unique_ptr<std::recursive_mutex> art::ProductInserter::mutex_
mutableprivate
Initial value:
{
std::make_unique<std::recursive_mutex>()}

Definition at line 82 of file ProductInserter.h.

Referenced by commitProducts(), getProductDescription_(), and put().

Principal* art::ProductInserter::principal_
private
std::map<TypeLabel, PMValue> art::ProductInserter::putProducts_ {}
private

Definition at line 95 of file ProductInserter.h.

Referenced by commitProducts(), and put().


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