ProvenanceCheckerOutput_module.cc
Go to the documentation of this file.
1 // ======================================================================
2 //
3 // ProvenanceCheckerOutput: Check the consistency of provenance stored
4 // in the framework
5 //
6 // ======================================================================
7 
14 #include "cetlib/exempt_ptr.h"
15 #include "cetlib_except/exception.h"
16 #include "fhiclcpp/ParameterSet.h"
19 
20 namespace art {
21 
23  public:
24  struct Config {
26  };
27 
28  using Parameters =
30  explicit ProvenanceCheckerOutput(Parameters const&);
31 
32  private:
33  void write(EventPrincipal& e) override;
34  void
36  {}
37  void
39  {}
40  }; // ProvenanceCheckerOutput
41 
42  //
43  // constructors and destructor
44  //
47  : OutputModule{ps().omConfig, ps.get_PSet()}
48  {}
49 
50  //
51  // member functions
52  //
53  static void
55  BranchMapper const& iMapper,
56  std::map<ProductID, bool>& oMap,
57  std::set<ProductID>& oMapperMissing)
58  {
59  for (art::ProductID const parent : iInfo.parentage().parents()) {
60  // Don't look for parents if we've previously looked at the parents
61  if (oMap.find(parent) == oMap.end()) {
62  // use side effect of calling operator[] which is if the item isn't
63  // there it will add it as 'false'
64  oMap[parent];
67  if (pInfo.get()) {
68  markAncestors(*pInfo, iMapper, oMap, oMapperMissing);
69  } else {
70  oMapperMissing.insert(parent);
71  }
72  }
73  }
74  }
75 
76  void
78  {
79  // check ProductProvenance's parents to see if they are in the
80  // ProductProvenance list
81  BranchMapper const& mapper =
82  const_cast<EventPrincipal const&>(e).branchMapper();
83 
84  std::map<ProductID, bool> seenParentInPrincipal;
85  std::set<ProductID> missingFromMapper;
86  std::set<ProductID> missingProductProvenance;
87 
88  for (auto const& group : e) {
89  if (group.second && !group.second->productUnavailable()) {
90  // This call seems to have a side effect of filling the
91  // 'ProductProvenance' in the Group
92  e.getForOutput(group.first, false);
93 
94  if (not group.second->productProvenancePtr().get()) {
95  missingProductProvenance.insert(group.first);
96  continue;
97  }
99  mapper.branchToProductProvenance(group.first);
100  if (!pInfo.get()) {
101  missingFromMapper.insert(group.first);
102  }
103  markAncestors(*(group.second->productProvenancePtr()),
104  mapper,
105  seenParentInPrincipal,
106  missingFromMapper);
107  }
108  seenParentInPrincipal[group.first] = true;
109  }
110 
111  // Determine what ProductIDs are in the product registry
112  auto const& prodList = ProductMetaData::instance().productList();
113  std::set<ProductID> branchesInReg;
114  for (auto const& prod : prodList) {
115  branchesInReg.insert(prod.second.productID());
116  }
117 
118  std::set<ProductID> missingFromPrincipal;
119  std::set<ProductID> missingFromReg;
120  for (auto const& seenParent : seenParentInPrincipal) {
121  if (!seenParent.second) {
122  missingFromPrincipal.insert(seenParent.first);
123  }
124  ProductID const pid{seenParent.first};
125  if (branchesInReg.find(pid) == branchesInReg.end()) {
126  missingFromReg.insert(pid);
127  }
128  }
129 
130  auto logProductID = [](auto const& missing) {
131  mf::LogProblem("ProvenanceChecker") << missing;
132  };
133 
134  if (missingFromMapper.size()) {
135  mf::LogError("ProvenanceChecker")
136  << "Missing the following ProductIDs from BranchMapper\n";
137  cet::for_all(missingFromMapper, logProductID);
138  }
139 
140  if (missingFromPrincipal.size()) {
141  mf::LogError("ProvenanceChecker")
142  << "Missing the following ProductIDs from EventPrincipal\n";
143  cet::for_all(missingFromPrincipal, logProductID);
144  }
145 
146  if (missingProductProvenance.size()) {
147  mf::LogError("ProvenanceChecker") << "The Groups for the following "
148  "ProductIDs have no "
149  "ProductProvenance\n";
150  cet::for_all(missingProductProvenance, logProductID);
151  }
152 
153  if (missingFromReg.size()) {
154  mf::LogError("ProvenanceChecker")
155  << "Missing the following ProductIDs from ProductRegistry\n";
156  cet::for_all(missingFromReg, logProductID);
157  }
158 
159  if (missingFromMapper.size() or missingFromPrincipal.size() or
160  missingProductProvenance.size() or missingFromReg.size()) {
161  throw cet::exception("ProvenanceError")
162  << (missingFromMapper.size() or missingFromPrincipal.size() ?
163  "Having missing ancestors" :
164  "")
165  << (missingFromMapper.size() ? " from BranchMapper" : "")
166  << (missingFromMapper.size() and missingFromPrincipal.size() ? " and" :
167  "")
168  << (missingFromPrincipal.size() ? " from EventPrincipal" : "")
169  << (missingFromMapper.size() or missingFromPrincipal.size() ? ".\n" :
170  "")
171  << (missingProductProvenance.size() ? " Have missing "
172  "ProductProvenance's from Group "
173  "in EventPrincipal.\n" :
174  "")
175  << (missingFromReg.size() ?
176  " Have missing info from ProductRegistry.\n" :
177  "");
178  }
179  }
180 
181 } // art
182 
183 // ======================================================================
184 
186 
187 // ======================================================================
auto const & get_PSet() const
void writeSubRun(SubRunPrincipal &) override
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
pointer get() const noexcept
Definition: exempt_ptr.h:146
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
DEFINE_ART_MODULE(TestTMapFile)
result_t branchToProductProvenance(ProductID const) const
MaybeLogger_< ELseverityLevel::ELsev_error, true > LogProblem
std::vector< ProductID > const & parents() const
Definition: Parentage.h:30
static ProductMetaData const & instance()
Parentage const & parentage() const
fhicl::TableFragment< OutputModule::Config > omConfig
T prod(const std::vector< T > &v)
Definition: prod.hpp:17
void writeRun(RunPrincipal &) override
ProductList const & productList() const
static void markAncestors(ProductProvenance const &iInfo, BranchMapper const &iMapper, std::map< ProductID, bool > &oMap, std::set< ProductID > &oMapperMissing)
void write(EventPrincipal &e) override
auto for_all(FwdCont &, Func)
Service to store calibration data products (CDP) in the SQLite3 metadatabase of a file...
Definition: FillParentInfo.h:8
Float_t e
Definition: plot.C:35