LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
createProductLookups.cc
Go to the documentation of this file.
2 // vim: set sw=2:
3 
7 
8 #include <cassert>
9 #include <unordered_map>
10 
11 using namespace art;
12 
13 namespace {
14 
15  class CheapTag {
16  public:
17  CheapTag(std::string const& label,
18  std::string const& instance,
19  std::string const& process)
20  : label_{label}, instance_{instance}, process_{process}
21  {}
22 
23  std::string const&
24  label() const
25  {
26  return label_;
27  }
28  std::string const&
29  instance() const
30  {
31  return instance_;
32  }
33  std::string const&
34  process() const
35  {
36  return process_;
37  }
38 
39  private:
40  std::string label_;
41  std::string instance_;
42  std::string process_;
43  };
44 
45  [[gnu::unused]] inline bool
46  operator==(CheapTag const& left, CheapTag const& right)
47  {
48  return left.label() == right.label() &&
49  left.instance() == right.instance() &&
50  left.process() == right.process();
51  }
52 
53  [[gnu::unused]] inline bool
54  operator!=(CheapTag const& left, CheapTag const& right)
55  {
56  return !(left == right);
57  }
58 
59  class PendingBTLEntry {
60  public:
61  PendingBTLEntry(std::string const& fcn,
62  std::string const& moduleLabel,
63  std::string const& instanceName,
64  std::string const& procName,
65  ProductID const pid)
66  : fcn_{fcn}, ct_{moduleLabel, instanceName, procName}, pid_{pid}
67  {}
68 
69  std::string const&
70  fcn() const
71  {
72  return fcn_;
73  }
74  CheapTag const&
75  ct() const
76  {
77  return ct_;
78  }
79  std::string const&
80  process() const
81  {
82  return ct_.process();
83  }
84  ProductID
85  pid() const
86  {
87  return pid_;
88  }
89 
90  private:
91  std::string fcn_;
92  CheapTag ct_;
93  ProductID pid_;
94  };
95 }
96 
99 {
100  // Computing the product lookups does not rely on any ROOT facilities.
101  ProductLookup_t result;
102  std::vector<PendingBTLEntry> pendingEntries;
103  std::unordered_map<ProductID, CheapTag, ProductID::Hash> insertedABVs;
104  for (auto const& pd : descriptions) {
105  auto const& prodFCN = pd.friendlyClassName();
106  auto const& procName = pd.processName();
107  auto const pid = pd.productID();
108  result[prodFCN][procName].emplace_back(pid);
109 
110  // Additional work only for Assns lookup
111  auto const& moduleLabel = pd.moduleLabel();
112  auto const& instanceName = pd.productInstanceName();
113  auto const& className = pd.producedClassName();
114 
115  if (!is_assns(className))
116  continue;
117 
118  auto const baseName = name_of_assns_base(className);
119  if (!baseName.empty()) {
120  // We're an Assns<A, B, D>, with a base Assns<A, B>.
121  pendingEntries.emplace_back(art::friendlyname::friendlyName(baseName),
122  moduleLabel,
123  instanceName,
124  procName,
125  pid);
126  } else {
127  // Add our pid to the list of real Assns<A, B, void>
128  // products already registered.
129  insertedABVs.emplace(pid, CheapTag{moduleLabel, instanceName, procName});
130  }
131  }
132 
133  auto const iend = insertedABVs.cend();
134  // Preserve useful ordering, only inserting if we don't already have
135  // a *real* Assns<A, B, void> for that module label / instance name
136  // combination.
137  std::for_each(
138  pendingEntries.cbegin(),
139  pendingEntries.cend(),
140  [&result, &insertedABVs, iend](auto const& pe) {
141  auto& pids = result[pe.fcn()][pe.process()];
142  if (pids.empty() ||
143  !std::any_of(pids.cbegin(),
144  pids.cend(),
145  [&insertedABVs, &iend, &pe](ProductID const pid) {
146  auto i = insertedABVs.find(pid);
147  return i != iend && pe.ct() == i->second;
148  })) {
149  pids.emplace_back(pe.pid());
150  }
151  });
152 
153  return result;
154 }
constexpr auto const & right(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:112
const std::string instance
std::vector< BranchDescription > ProductDescriptions
bool operator!=(debugging_allocator< X > const &, debugging_allocator< Y > const &)
std::string name_of_assns_base(std::string assns_type_name)
Definition: TypeID.cc:114
ProductLookup_t createProductLookups(ProductDescriptions const &descriptions)
bool is_assns(TypeID const &tid)
Definition: TypeID.h:145
std::string friendlyName(std::string const &iFullName)
constexpr auto const & left(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:104
HLT enums.
bool operator==(Provenance const &a, Provenance const &b)
Definition: Provenance.h:168
std::map< std::string, ProcessLookup > ProductLookup_t
Definition: type_aliases.h:20