LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
ConsumesInfo.cc
Go to the documentation of this file.
2 
8 #include "cetlib/HorizontalRule.h"
9 #include "cetlib/container_algorithms.h"
11 
12 #include <cstdlib>
13 #include <set>
14 
15 using namespace std;
16 
17 namespace art {
18 
19  ConsumesInfo::~ConsumesInfo() = default;
20 
21  ConsumesInfo::ConsumesInfo()
22  {
23  requireConsumes_ = false;
24  }
25 
28  {
29  static ConsumesInfo me;
30  return &me;
31  }
32 
33  string
34  ConsumesInfo::assemble_consumes_statement(BranchType const bt,
35  ProductInfo const& pi)
36  {
37  string result;
38  // Create "consumes" prefix
39  switch (pi.consumableType) {
40  case ProductInfo::ConsumableType::Product:
41  result += "consumes";
42  break;
43  case ProductInfo::ConsumableType::ViewElement:
44  result += "consumesView";
45  break;
46  case ProductInfo::ConsumableType::Many:
47  result += "consumesMany";
48  break;
49  }
50  // .. now time for the template arguments
51  result += '<';
52  result += pi.typeID.className();
53  if (bt != InEvent) {
54  result += ", In";
55  result += BranchTypeToString(bt);
56  }
57  result += '>';
58  // Form "(...);" string with appropriate arguments.
59  result += '(';
60  // Early bail out for consumesMany.
61  if (pi.consumableType == ProductInfo::ConsumableType::Many) {
62  result += ");";
63  return result;
64  }
65  result += '"';
66  result += pi.label;
67  // If the process name is non-empty, then all InputTag fields are
68  // required (e.g.):
69  // "myLabel::myProcess"
70  // "myLabel::myInstance::myProcess"
71  if (!pi.process.name().empty()) {
72  result += ':';
73  result += pi.instance;
74  result += ':';
75  result += pi.process.name();
76  } else if (!pi.instance.empty()) {
77  result += ':';
78  result += pi.instance;
79  }
80  result += "\");";
81  return result;
82  }
83 
84  string
85  ConsumesInfo::module_context(ModuleDescription const& md)
86  {
87  string result{"module label: '"};
88  result += md.moduleLabel();
89  result += "' of class type '";
90  result += md.moduleName();
91  result += '\'';
92  return result;
93  }
94 
95  void
96  ConsumesInfo::setRequireConsumes(bool const val)
97  {
98  requireConsumes_ = val;
99  }
100 
101  void
102  ConsumesInfo::collectConsumes(
103  string const& module_label,
104  array<vector<ProductInfo>, NumBranchTypes> const& consumables)
105  {
106  std::lock_guard sentry{mutex_};
107  consumables_.emplace(module_label, consumables);
108  }
109 
110  void
111  ConsumesInfo::validateConsumedProduct(BranchType const bt,
112  ModuleDescription const& md,
113  ProductInfo const& productInfo)
114  {
115 
116  std::lock_guard sentry{mutex_};
117  if (cet::binary_search_all(consumables_[md.moduleLabel()][bt],
118  productInfo)) {
119  // Found it, everything is ok.
120  return;
121  }
122  if (requireConsumes_.load()) {
124  "Consumer: an error occurred during validation of a "
125  "retrieved product\n\n")
126  << "The following consumes (or mayConsume) statement is missing from\n"
127  << module_context(md) << ":\n\n"
128  << " " << assemble_consumes_statement(bt, productInfo) << "\n\n";
129  }
130  missingConsumes_[md.moduleLabel()][bt].insert(productInfo);
131  }
132 
133  void
134  ConsumesInfo::showMissingConsumes() const
135  {
136  std::lock_guard sentry{mutex_};
137  for (auto const& [modLabel, arySetPI] : missingConsumes_) {
138  constexpr cet::HorizontalRule rule{60};
139  mf::LogPrint log{"MTdiagnostics"};
140  log << '\n'
141  << rule('=') << '\n'
142  << "The following consumes (or mayConsume) statements are missing "
143  "from\n"
144  << "module label: " << modLabel << '\n'
145  << rule('-') << '\n';
146  size_t i = 0;
147  for (auto const& setPI : arySetPI) {
148  for (auto const& pi : setPI) {
149  log << " "
150  << assemble_consumes_statement(static_cast<BranchType>(i), pi)
151  << '\n';
152  }
153  ++i;
154  }
155  log << rule('=');
156  }
157  }
158 
159 } // namespace art
std::string const & moduleLabel() const
const std::string instance
STL namespace.
std::string const & moduleName() const
auto array(Array const &a)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:250
std::string const & BranchTypeToString(BranchType const bt)
Definition: BranchType.cc:65
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
constexpr T pi()
Returns the constant pi (up to 35 decimal digits of precision)
BranchType
Definition: BranchType.h:20
Definition: MVAAlg.h:12