ProducesCollector.h
Go to the documentation of this file.
1 #ifndef art_Framework_Core_ProducesCollector_h
2 #define art_Framework_Core_ProducesCollector_h
3 
12 
13 #include <array>
14 #include <string>
15 
16 namespace art {
17 
18  class ModuleDescription;
19 
20  namespace {
21 
22  inline void
24  {
25  std::string errMsg;
26  if (!detail::checkFriendlyName(fcn, errMsg)) {
28  << errMsg
29  << "In particular, underscores are not permissible anywhere in the "
30  "fully-scoped\n"
31  "class name, including namespaces.\n";
32  }
33  }
34 
35  inline void
36  verifyModuleLabel(std::string const& ml)
37  {
38  std::string errMsg;
39  if (!detail::checkModuleLabel(ml, errMsg)) {
40  throw Exception(errors::Configuration) << errMsg;
41  }
42  }
43 
44  inline void
45  verifyInstanceName(std::string const& instanceName)
46  {
47  std::string errMsg;
48  if (!detail::checkInstanceName(instanceName, errMsg)) {
49  throw Exception(errors::Configuration) << errMsg;
50  }
51  }
52 
53  } // unnamed namespace
54 
56  public:
57  // Record the production of an object of type P, with optional
58  // instance name, in the Event (by default), Run, or SubRun.
59  template <typename P, BranchType B = InEvent>
60  void produces(std::string const& instanceName = {},
61  Persistable const persistable = Persistable::Yes);
62 
63  // Record the reconstitution of an object of type P, in either the
64  // Run, SubRun, or Event, recording that this object was
65  // originally created by a module with label modLabel, and with an
66  // optional instance name.
67  template <typename P, BranchType B>
68  TypeLabel const& reconstitutes(std::string const& modLabel,
69  std::string const& instanceName = {});
70 
71  TypeLabelLookup_t const& expectedProducts(BranchType) const;
72  void fillDescriptions(ModuleDescription const& md);
73 
74  private:
75  TypeLabel const& insertOrThrow(BranchType const bt, TypeLabel const& tl);
76 
77  std::array<TypeLabelLookup_t, NumBranchTypes> typeLabelList_{{}};
78  };
79 
80  inline TypeLabelLookup_t const&
82  {
83  return typeLabelList_[bt];
84  }
85 
86  template <typename P, art::BranchType B>
87  inline void
89  Persistable const persistable)
90  {
91  verifyInstanceName(instanceName);
92  TypeID const productType{typeid(P)};
93  verifyFriendlyClassName(productType.friendlyClassName());
94  bool const isTransient = (persistable == Persistable::No);
95  TypeLabel const typeLabel{
96  productType, instanceName, SupportsView<P>::value, isTransient};
97  insertOrThrow(B, typeLabel);
98  }
99 
100  template <typename P, BranchType B>
101  TypeLabel const&
103  std::string const& instanceName)
104  {
105  verifyModuleLabel(emulatedModule);
106  verifyInstanceName(instanceName);
107  TypeID const productType{typeid(P)};
108  verifyFriendlyClassName(productType.friendlyClassName());
109  TypeLabel const typeLabel{
110  productType, instanceName, SupportsView<P>::value, emulatedModule};
111  return insertOrThrow(B, typeLabel);
112  }
113 
114 }
115 
116 #endif /* art_Framework_Core_ProducesCollector_h */
117 
118 // Local Variables:
119 // mode: c++
120 // End:
Persistable
Definition: Persistable.h:5
void verifyFriendlyClassName(std::string const &fcn)
Definition: verify_names.cc:16
std::string string
Definition: nybbler.cc:12
std::pair< float, std::string > P
std::map< TypeLabel, BranchDescription > TypeLabelLookup_t
Definition: type_aliases.h:20
bool checkInstanceName(std::string const &instanceName, std::string &errMsg)
void produces(std::string const &instanceName={}, Persistable const persistable=Persistable::Yes)
bt
Definition: tracks.py:83
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
bool checkFriendlyName(std::string const &friendlyName, std::string &errMsg)
BranchType
Definition: BranchType.h:20
TypeLabel const & reconstitutes(std::string const &modLabel, std::string const &instanceName={})
bool checkModuleLabel(std::string const &moduleLabel, std::string &errMsg)
TypeLabelLookup_t const & expectedProducts(BranchType) const
void verifyInstanceName(std::string const &in)
Definition: verify_names.cc:5