ProductRegistryHelper.h
Go to the documentation of this file.
1 #ifndef art_Framework_Core_ProductRegistryHelper_h
2 #define art_Framework_Core_ProductRegistryHelper_h
3 // vim: set sw=2 expandtab :
4 
5 // ===================================================================
6 // This class provides the produces() and reconstitutes() function
7 // templates used by modules and sources, respectively, to register
8 // what products they create or read in respectively.
9 //
10 // The constructors of an EDProducer or an EDFilter should call
11 // produces() for each product inserted into a principal. Instance
12 // names should be provided only when the module makes more than one
13 // instance of the same product per event.
14 //
15 // The constructors of an InputSource should call reconstitutes() for
16 // each product if and only if it does not update the
17 // UpdateOutputCallbacks with a product list.
18 // ===================================================================
19 
28 #include "cetlib_except/demangle.h"
29 #include "cetlib_except/exception.h"
30 
31 #include <memory>
32 #include <string>
33 
34 namespace art {
35 
36  class ModuleDescription;
37 
40  public:
43 
46  ProductRegistryHelper& operator=(ProductRegistryHelper const&) = delete;
47  ProductRegistryHelper& operator=(ProductRegistryHelper&&) = delete;
48 
49  // Used by an input source to provide a product list to be merged
50  // into the set of products that will be registered.
51  void
52  productList(std::unique_ptr<ProductList> p)
53  {
54  productList_ = move(p);
55  }
56 
57  void registerProducts(ProductDescriptions& productsToRegister,
58  ModuleDescription const& md);
59 
60  void fillDescriptions(ModuleDescription const& md);
61 
62  // Record the reconstitution of an object of type P, in either the
63  // Run, SubRun, or Event, recording that this object was
64  // originally created by a module with label modLabel, and with an
65  // optional instance name.
66  template <typename P, BranchType B>
67  TypeLabel const& reconstitutes(std::string const& modLabel,
68  std::string const& instanceName = {});
69 
70  template <BranchType B>
71  TypeLabelLookup_t const& expectedProducts() const;
72 
73  // Record the production of an object of type P, with optional
74  // instance name, in the Event (by default), Run, or SubRun.
75  template <typename P, BranchType B = InEvent>
76  void produces(std::string const& instanceName = {},
77  Persistable const persistable = Persistable::Yes);
78 
80  producesCollector() noexcept
81  {
82  return collector_;
83  }
84 
85  private:
86  std::unique_ptr<ProductList const> productList_{nullptr};
89  };
90 
91  template <BranchType B>
92  inline TypeLabelLookup_t const&
94  {
95  return collector_.expectedProducts(B);
96  }
97 
98  template <typename P, art::BranchType B>
99  inline void
101  Persistable const persistable)
102  {
105  "An error occurred while registering a product.\n"}
106  << "The following product was registered with 'produces' when\n"
107  "'reconstitutes' should have been called instead.\n"
108  << " Branch type: " << B << '\n'
109  << " Class name: " << cet::demangle_symbol(typeid(P).name()) << '\n'
110  << " Instance name: '" << instanceName << "'\n";
111  }
112  collector_.produces<P, B>(instanceName, persistable);
113  }
114 
115  template <typename P, BranchType B>
116  TypeLabel const&
118  std::string const& instanceName)
119  {
120  if (mode_ == product_creation_mode::produces) {
122  "An error occurred while registering a product.\n"}
123  << "The following product was registered with 'reconstitutes' when\n"
124  "'produces' should have been called instead.\n"
125  << " Branch type: " << B << '\n'
126  << " Class name: " << cet::demangle_symbol(typeid(P).name()) << '\n'
127  << " Emulated module name: '" << emulatedModule << "'\n"
128  << " Instance name: '" << instanceName << "'\n";
129  }
130  return collector_.reconstitutes<P, B>(emulatedModule, instanceName);
131  }
132 
133 } // namespace art
134 
135 #endif /* art_Framework_Core_ProductRegistryHelper_h */
136 
137 // Local Variables:
138 // mode: c++
139 // End:
static QCString name
Definition: declinfo.cpp:673
Persistable
Definition: Persistable.h:5
std::string string
Definition: nybbler.cc:12
void produces(std::string const &instanceName={}, Persistable const persistable=Persistable::Yes)
std::pair< float, std::string > P
std::vector< BranchDescription > ProductDescriptions
void productList(std::unique_ptr< ProductList > p)
std::map< TypeLabel, BranchDescription > TypeLabelLookup_t
Definition: type_aliases.h:20
TypeLabel const & reconstitutes(std::string const &modLabel, std::string const &instanceName={})
def move(depos, offset)
Definition: depos.py:107
p
Definition: test.py:223
ProducesCollector & producesCollector() noexcept
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
TypeLabelLookup_t const & expectedProducts() const