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