LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
ProductRegistryHelper.cc
Go to the documentation of this file.
2 // vim: set sw=2:
3 
10 #include "cetlib/container_algorithms.h"
11 #include "fhiclcpp/ParameterSet.h"
13 
14 #include <cassert>
15 #include <string>
16 #include <tuple>
17 
18 namespace {
19 
20  // A user may wish to declare:
21  //
22  // produces<Assns<A,B>>(instance_name);
23  // produces<Assns<B,A>>(instance_name);
24  //
25  // in their module constructor. If the instance names are the same
26  // for both produces declarations, then this is a logic error, since
27  // Assns<A,B> and Assns<B,A> correspond to the same set of
28  // associations. This error can be detected by checking the
29  // friendlyClassName, which resolves to the same string for
30  // Assns<A,B> and Assns<B,A>.
31 
32  void
33  check_for_duplicate_Assns(std::set<art::TypeLabel> const& typeLabels)
34  {
35  std::map<std::string, std::set<std::string>> instanceToFriendlyNames;
36  for (auto const& tl : typeLabels) {
37  auto const& productInstanceName = tl.productInstanceName();
38  auto result = instanceToFriendlyNames[productInstanceName].emplace(
39  tl.friendlyClassName());
40  if (!result.second) {
42  "check_for_duplicate_Assns: ")
43  << "An attempt has been made to call the equivalent of\n\n"
44  << " produces<" << tl.className() << ">(\"" << productInstanceName
45  << "\")\n\n"
46  << "which results in a prepared (\"friendly\") name of:\n\n"
47  << " " << *result.first << "\n\n"
48  << "That friendly name has already been registered for this module.\n"
49  << "Please check to make sure that produces<> has not already been\n"
50  << "called for an Assns<> with reversed template arguments. Such\n"
51  << "behavior is not supported. Contact artists@fnal.gov for "
52  "guidance.\n";
53  }
54  }
55  }
56 }
57 
58 void
61  ProductDescriptions& productsToRegister,
62  ModuleDescription const& md)
63 {
64  // First update the MPR with any extant products.
65  if (productList_) {
66  cet::transform_all(*productList_,
67  back_inserter(productsToRegister),
68  [](auto const& pr) { return pr.second; });
69  mpr.updateFromModule(move(productList_));
70  }
71 
72  // Now go through products that will be produced in the current process.
73  check_for_duplicate_Assns(typeLabelList_[InEvent]);
74 
75  ProductDescriptions descriptions;
76  for (std::size_t ibt{}; ibt != NumBranchTypes; ++ibt) {
77  auto const bt = static_cast<BranchType>(ibt);
78  for (auto const& val : typeLabelList_[bt]) {
79  BranchDescription pd{bt, val, md};
80  productsToRegister.push_back(pd);
81  descriptions.push_back(std::move(pd));
82  }
83  }
84  mpr.addProductsFromModule(move(descriptions));
85 }
void registerProducts(MasterProductRegistry &mpr, ProductDescriptions &productsToRegister, ModuleDescription const &md)
void updateFromModule(std::unique_ptr< ProductList > &&)
std::vector< BranchDescription > ProductDescriptions
std::unique_ptr< ProductList > productList_
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
std::array< std::set< TypeLabel >, NumBranchTypes > typeLabelList_
BranchType
Definition: BranchType.h:18
void addProductsFromModule(ProductDescriptions &&)