LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
MasterProductRegistry.cc
Go to the documentation of this file.
2 // vim: set sw=2:
3 
5 #include "cetlib/assert_only_one_thread.h"
6 #include "cetlib_except/exception.h"
7 
8 #include <cassert>
9 #include <ostream>
10 
11 using namespace art;
12 
13 void
15 {
16  CET_ASSERT_ONLY_ONE_THREAD();
17  // Product registration can still happen implicitly whenever an
18  // input file is opened--via calls to updateFromInputFile.
19  allowExplicitRegistration_ = false;
20  cet::for_all(productListUpdatedCallbacks_,
21  [this](auto const& callback) { callback(productList_); });
22 }
23 
24 void
26  ProductDescriptions&& descriptions)
27 {
28  CET_ASSERT_ONLY_ONE_THREAD();
29  for (auto&& desc : descriptions) {
30  addProduct_(std::move(desc));
31  }
32 }
33 
34 void
35 art::MasterProductRegistry::updateFromModule(std::unique_ptr<ProductList>&& pl)
36 {
37  CET_ASSERT_ONLY_ONE_THREAD();
38  if (!pl)
39  return;
40  updateProductLists_(*pl);
41 }
42 
43 void
45 {
46  CET_ASSERT_ONLY_ONE_THREAD();
47  updateProductLists_(pl);
48  cet::for_all(productListUpdatedCallbacks_,
49  [this](auto const& callback) { callback(productList_); });
50 }
51 
52 void
55 {
56  CET_ASSERT_ONLY_ONE_THREAD();
57  productListUpdatedCallbacks_.push_back(cb);
58 }
59 
60 void
61 art::MasterProductRegistry::print(std::ostream& os) const
62 {
63  // TODO: Shouldn't we print the BranchKey too?
64  for (auto const& val : productList_) {
65  os << val.second << "\n-----\n";
66  }
67 }
68 
69 //=====================================================================================
70 // Private member functions
71 
72 void
74 {
75  CET_ASSERT_ONLY_ONE_THREAD();
76 
77  // The below check exists primarily to ensure that the framework
78  // does not accidentally call addProduct at a time when it should
79  // not.
80  if (!allowExplicitRegistration_) {
82  << "An attempt to register the product\n"
83  << bdp << "was made after the product registry was frozen.\n"
84  << "Product registration can be done only in module constructors.\n";
85  }
86 
87  assert(bdp.produced());
88 
89  auto it = productList_.emplace(BranchKey{bdp}, BranchDescription{});
90  if (!it.second) {
92  << "The process name " << bdp.processName()
93  << " was previously used on these products.\n"
94  << "Please modify the configuration file to use a "
95  << "distinct process name.\n";
96  }
97  auto& productListEntry = *it.first;
98  auto& pd = productListEntry.second;
99  pd.swap(bdp);
100  productProduced_[pd.branchType()] = true;
101 }
102 
103 void
105 {
106  for (auto const& val : pl) {
107  auto const& pd = val.second;
108  assert(!pd.produced());
109  auto bk = BranchKey{pd};
110  auto it = productList_.find(bk);
111  if (it == productList_.end()) {
112  // New product
113  productList_.emplace(bk, pd);
114  continue;
115  }
116  auto& found_pd = it->second;
117  assert(combinable(found_pd, pd));
118  found_pd.merge(pd);
119  }
120 }
121 
122 std::ostream&
123 art::operator<<(std::ostream& os, MasterProductRegistry const& mpr)
124 {
125  mpr.print(os);
126  return os;
127 }
std::ostream & operator<<(std::ostream &os, EDAnalyzer::Table< T > const &t)
Definition: EDAnalyzer.h:184
void print(std::ostream &) const
std::map< BranchKey, BranchDescription > ProductList
Definition: ProductList.h:15
void updateFromModule(std::unique_ptr< ProductList > &&)
std::vector< BranchDescription > ProductDescriptions
void registerProductListUpdatedCallback(ProductListUpdatedCallback cb)
void updateProductLists_(ProductList const &pl)
void updateFromInputFile(ProductList const &)
std::function< void(ProductList const &)> ProductListUpdatedCallback
bool combinable(BranchDescription const &a, BranchDescription const &b)
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
void addProduct_(BranchDescription &&)
HLT enums.
void addProductsFromModule(ProductDescriptions &&)