LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
put_product_in_principal.h
Go to the documentation of this file.
1 #ifndef art_Framework_IO_Sources_put_product_in_principal_h
2 #define art_Framework_IO_Sources_put_product_in_principal_h
3 // vim: set sw=2 expandtab :
4 
5 //
6 // Helper class to put products directly into the {Run, SubRun, Event}
7 // Principal.
8 //
9 // NOTE that this should *not* be used to put products in the event that
10 // require parentage information to be filled in.
11 //
12 
24 
25 #include <memory>
26 #include <string>
27 
28 namespace art {
29 
30  inline RangeSet
32  {
33  return RangeSet::forRun(rp.runID());
34  }
35 
36  inline RangeSet
38  {
39  return RangeSet::forSubRun(srp.subRunID());
40  }
41 
42  template <typename T, typename P>
43  std::enable_if_t<!detail::range_sets_supported(P::branch_type)>
44  put_product_in_principal(std::unique_ptr<T>&& product,
45  P& principal,
46  std::string const& module_label,
47  std::string const& instance_name = {})
48  {
49  TypeID const typeID{typeid(T)};
50  if (product.get() == nullptr) {
52  << "put_product_in_principal: A null unique_ptr was passed to 'put'.\n"
53  << "The pointer is of type " << typeID << ".\n"
54  << "The specified product instance name was '" << instance_name
55  << "'.\n";
56  }
57 
58  auto const& process_name = principal.processConfiguration().processName();
59  auto const& product_name = canonicalProductName(
60  typeID.friendlyClassName(), module_label, instance_name, process_name);
61  ProductID const pid{product_name};
62  auto desc = principal.getProductDescription(pid);
63  if (!desc) {
65  "put_product_in_principal: error while trying to "
66  "retrieve product description:\n")
67  << "No product is registered for\n"
68  << " process name: '" << process_name << "'\n"
69  << " module label: '" << module_label << "'\n"
70  << " product friendly class name: '" << typeID.friendlyClassName()
71  << "'\n"
72  << " product instance name: '" << instance_name << "'\n"
73  << " branch type: '" << principal.branchType()
74  << "'\n";
75  }
76 
77  principal.put(
78  *desc,
79  std::make_unique<ProductProvenance const>(pid, productstatus::present()),
80  std::make_unique<Wrapper<T>>(std::move(product)),
81  std::make_unique<RangeSet>(RangeSet::invalid()));
82  }
83 
84  template <typename T, typename P>
85  std::enable_if_t<detail::range_sets_supported(P::branch_type)>
86  put_product_in_principal(std::unique_ptr<T>&& product,
87  P& principal,
88  std::string const& module_label,
89  std::string const& instance_name = {},
90  RangeSet&& rs = RangeSet::invalid())
91  {
92  TypeID const typeID{typeid(T)};
93  if (product.get() == nullptr) {
95  << "put_product_in_principal: A null unique_ptr was passed to 'put'.\n"
96  << "The pointer is of type " << typeID << ".\n"
97  << "The specified product instance name was '" << instance_name
98  << "'.\n";
99  }
100 
101  auto const& process_name = principal.processConfiguration().processName();
102  auto const& product_name = canonicalProductName(
103  typeID.friendlyClassName(), module_label, instance_name, process_name);
104  ProductID const pid{product_name};
105  auto desc = principal.getProductDescription(pid);
106  if (!desc) {
108  "put_product_in_principal: error while trying to "
109  "retrieve product description:\n")
110  << "No product is registered for\n"
111  << " process name: '" << process_name << "'\n"
112  << " module label: '" << module_label << "'\n"
113  << " product friendly class name: '" << typeID.friendlyClassName()
114  << "'\n"
115  << " product instance name: '" << instance_name << "'\n"
116  << " branch type: '" << principal.branchType()
117  << "'\n";
118  }
119 
120  // If the provided RangeSet is invalid, assign it a RangeSet
121  // corresponding to the full (Sub)Run.
122  if (!rs.is_valid()) {
123  rs = rangeSetFor(principal);
124  }
125 
126  principal.put(
127  *desc,
128  std::make_unique<ProductProvenance const>(pid, productstatus::present()),
129  std::make_unique<Wrapper<T>>(std::move(product)),
130  std::make_unique<RangeSet>(rs));
131  }
132 
133 } // namespace art
134 
135 #endif /* art_Framework_IO_Sources_put_product_in_principal_h */
136 
137 // Local Variables:
138 // mode: c++
139 // End:
bool is_valid() const
Definition: RangeSet.cc:117
RangeSet rangeSetFor(RunPrincipal const &rp)
static RangeSet forSubRun(SubRunID)
Definition: RangeSet.cc:57
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::enable_if_t<!detail::range_sets_supported(P::branch_type)> put_product_in_principal(std::unique_ptr< T > &&product, P &principal, std::string const &module_label, std::string const &instance_name={})
static RangeSet invalid()
Definition: RangeSet.cc:45
Definition: MVAAlg.h:12
static RangeSet forRun(RunID)
Definition: RangeSet.cc:51
SubRunID subRunID() const
constexpr ProductStatus present() noexcept
Definition: ProductStatus.h:10
RunID runID() const
Definition: RunPrincipal.cc:54