LArSoft  v06_85_00
Liquid Argon Software toolkit - http://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 
5 // Helper class to put products directly into the {Run, SubRun, Event}
6 // Principal.
7 //
8 // NOTE that this should *not* be used to put products in the event that
9 // require parentage information to be filled in.
10 //
11 // 2011/03/15 CG,
13 
24 
25 #include <memory>
26 #include <string>
27 
28 namespace art {
29  template <typename T, typename P>
30  std::enable_if_t<P::branch_type == InEvent || P::branch_type == InResults>
31  put_product_in_principal(std::unique_ptr<T>&& product,
32  P& principal,
33  std::string const& module_label,
34  std::string const& instance_name = {});
35 
36  template <typename T, typename P>
37  std::enable_if_t<P::branch_type == InSubRun || P::branch_type == InRun>
38  put_product_in_principal(std::unique_ptr<T>&& product,
39  P& principal,
40  std::string const& module_label,
41  std::string const& instance_name = {},
42  RangeSet&& = RangeSet::invalid());
43 
44  inline RangeSet
46  {
47  return RangeSet::forRun(rp.id());
48  }
49 
50  inline RangeSet
52  {
53  return RangeSet::forSubRun(srp.id());
54  }
55 }
56 
57 template <typename T, typename P>
58 std::enable_if_t<P::branch_type == art::InEvent ||
59  P::branch_type == art::InResults>
60 art::put_product_in_principal(std::unique_ptr<T>&& product,
61  P& principal,
62  std::string const& module_label,
63  std::string const& instance_name)
64 {
65  if (product.get() == nullptr) {
66  TypeID const typeID{typeid(T)};
68  << "put_product_in_principal: A null unique_ptr was passed to 'put'.\n"
69  << "The pointer is of type " << typeID << ".\n"
70  << "The specified product instance name was '" << instance_name << "'.\n";
71  }
72 
73  BranchDescription const& desc =
74  get_ProductDescription<T>(principal, module_label, instance_name);
75 
76  std::unique_ptr<EDProduct> wp =
77  std::make_unique<Wrapper<T>>(std::move(product));
78  principal.put(std::move(wp),
79  desc,
80  std::make_unique<ProductProvenance const>(
82 }
83 
84 template <typename T, typename P>
85 std::enable_if_t<P::branch_type == art::InSubRun ||
86  P::branch_type == art::InRun>
87 art::put_product_in_principal(std::unique_ptr<T>&& product,
88  P& principal,
89  std::string const& module_label,
90  std::string const& instance_name,
91  RangeSet&& rs)
92 {
93  if (product.get() == nullptr) {
94  TypeID const typeID{typeid(T)};
96  << "put_product_in_principal: A null unique_ptr was passed to 'put'.\n"
97  << "The pointer is of type " << typeID << ".\n"
98  << "The specified product instance name was '" << instance_name << "'.\n";
99  }
100 
101  BranchDescription const& desc =
102  get_ProductDescription<T>(principal, module_label, instance_name);
103 
104  // If the provided RangeSet is invalid, assign it a RangeSet
105  // corresponding to the full (Sub)Run.
106  if (!rs.is_valid())
107  rs = rangeSetFor(principal);
108 
109  std::unique_ptr<EDProduct> wp =
110  std::make_unique<Wrapper<T>>(std::move(product));
111  principal.put(std::move(wp),
112  desc,
113  std::make_unique<ProductProvenance const>(
115  std::move(rs));
116 }
117 
118 #endif /* art_Framework_IO_Sources_put_product_in_principal_h */
119 
120 // Local Variables:
121 // mode: c++
122 // End:
std::enable_if_t< P::branch_type==InEvent||P::branch_type==InResults > put_product_in_principal(std::unique_ptr< T > &&product, P &principal, std::string const &module_label, std::string const &instance_name={})
RangeSet rangeSetFor(RunPrincipal const &rp)
SubRunID id() const
ProductID productID() const
static RangeSet forRun(RunID)
Definition: RangeSet.cc:52
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
static RangeSet forSubRun(SubRunID)
Definition: RangeSet.cc:58
RunID const & id() const
Definition: RunPrincipal.h:46
static RangeSet invalid()
Definition: RangeSet.cc:46
HLT enums.
ProductStatus present()
Definition: ProductStatus.h:16