LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
Consumer.cc
Go to the documentation of this file.
3 #include "cetlib/HorizontalRule.h"
4 #include "cetlib/container_algorithms.h"
7 
8 using namespace art;
9 
10 namespace {
11  std::string
12  assemble_consumes_statement(BranchType const bt, ProductInfo const& pi)
13  {
14  using ConsumableType = ProductInfo::ConsumableType;
15  std::string result;
16  // Create "consumes" prefix
17  switch (pi.consumableType_) {
18  case ConsumableType::Product:
19  result += "consumes";
20  break;
21  case ConsumableType::Many:
22  result += "consumesMany";
23  break;
24  case ConsumableType::ViewElement:
25  result += "consumesView";
26  }
27  // .. now time for the template arguments
28  result += '<';
29  result += pi.typeID_.className();
30  if (bt != art::InEvent) {
31  result += ", art::In";
32  result += art::BranchTypeToString(bt);
33  }
34  result += '>';
35 
36  // Form "(...);" string with appropriate arguments.
37  result += '(';
38  // Early bail out for consumesMany.
39  if (pi.consumableType_ == ConsumableType::Many) {
40  result += ");";
41  return result;
42  }
43 
44  result += '"';
45  result += pi.label_;
46  // If the process name is non-empty, then all InputTag fields are
47  // required (e.g.):
48  // "myLabel::myProcess"
49  // "myLabel::myInstance::myProcess"
50  if (!pi.process_.empty()) {
51  result += ':';
52  result += pi.instance_;
53  result += ':';
54  result += pi.process_;
55  } else if (!pi.instance_.empty()) {
56  result += ':';
57  result += pi.instance_;
58  }
59  result += "\");";
60  return result;
61  }
62 
63  std::string
64  module_context(cet::exempt_ptr<ModuleDescription const> md)
65  {
66  std::string result{"module label: '"};
67  result += (md ? md->moduleLabel() : "<invalid>");
68  result += "' of class type '";
69  result += (md ? md->moduleName() : "<invalid>");
70  result += '\'';
71  return result;
72  }
73 }
74 
75 cet::exempt_ptr<art::Consumer>
77 {
78  static Consumer invalid{InvalidTag{}};
79  return &invalid;
80 }
81 
82 void
84 {
85  moduleDescription_ = &md;
86 }
87 
88 void
90 {
91  if (!moduleContext_)
92  return;
93 
94  pset.get_if_present("errorOnMissingConsumes", requireConsumes_);
95  for (auto& consumablesPerBranch : consumables_) {
96  cet::sort_all(consumablesPerBranch);
97  }
98 }
99 
100 void
102  ProductInfo const& pi)
103 {
104  // Early exits if consumes tracking has been disabled or if the
105  // consumed product is an allowed consumable.
106  if (!moduleContext_)
107  return;
108 
109  if (cet::binary_search_all(consumables_[bt], pi))
110  return;
111 
112  if (requireConsumes_) {
114  "Consumer: an error occurred during validation of a "
115  "retrieved product\n\n")
116  << "The following consumes (or mayConsume) statement is missing from\n"
117  << module_context(moduleDescription_) << ":\n\n"
118  << " " << assemble_consumes_statement(bt, pi) << "\n\n";
119  }
120 
121  missingConsumes_[bt].insert(pi);
122 }
123 
124 void
126 {
127  if (!moduleContext_)
128  return;
129 
130  // If none of the branches have missing consumes statements, exit early.
131  if (std::all_of(cbegin(missingConsumes_),
132  cend(missingConsumes_),
133  [](auto const& perBranch) { return perBranch.empty(); }))
134  return;
135 
136  constexpr cet::HorizontalRule rule{60};
137  mf::LogPrint log{"MTdiagnostics"};
138  log << '\n'
139  << rule('=') << '\n'
140  << "The following consumes (or mayConsume) statements are missing from\n"
141  << module_context(moduleDescription_) << '\n'
142  << rule('-') << '\n';
143 
144  cet::for_all_with_index(
145  missingConsumes_, [&log](std::size_t const i, auto const& perBranch) {
146  for (auto const& pi : perBranch) {
147  log << " "
148  << assemble_consumes_statement(static_cast<BranchType>(i), pi)
149  << '\n';
150  }
151  });
152  log << rule('=');
153 }
std::string label_
Definition: ProductInfo.h:38
static cet::exempt_ptr< Consumer > non_module_context()
Definition: Consumer.cc:76
std::string process_
Definition: ProductInfo.h:40
std::string instance_
Definition: ProductInfo.h:39
void setModuleDescription(ModuleDescription const &md)
Definition: Consumer.cc:83
bool get_if_present(std::string const &key, T &value) const
Definition: ParameterSet.h:208
std::string className() const
Definition: TypeID.cc:21
std::string const & BranchTypeToString(BranchType const bt)
Definition: BranchType.cc:65
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
void prepareForJob(fhicl::ParameterSet const &pset)
Definition: Consumer.cc:89
constexpr T pi()
Returns the constant pi (up to 35 decimal digits of precision)
void showMissingConsumes() const
Definition: Consumer.cc:125
BranchType
Definition: BranchType.h:18
HLT enums.
ConsumableType consumableType_
Definition: ProductInfo.h:36
void validateConsumedProduct(BranchType const bt, ProductInfo const &pi)
Definition: Consumer.cc:101