CMS 3D CMS Logo

ProvenanceCheckerOutputModule.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Modules
4 // Class : ProvenanceCheckerOutputModule
5 //
6 // Implementation:
7 // Checks the consistency of provenance stored in the framework
8 //
9 // Original Author: Chris Jones
10 // Created: Thu Sep 11 19:24:13 EDT 2008
11 //
12 
13 // system include files
24 
25 // user include files
26 
27 namespace edm {
28 
29  class ModuleCallingContext;
30  class ParameterSet;
31 
33  public:
34  // We do not take ownership of passed stream.
37  static void fillDescriptions(ConfigurationDescriptions& descriptions);
38 
39  private:
40  void write(EventForOutput const& e) override;
42  void writeRun(RunForOutput const&) override {}
43  };
44 
45  //
46  // constants, enums and typedefs
47  //
48 
49  //
50  // static data member definitions
51  //
52 
53  //
54  // constructors and destructor
55  //
57  : one::OutputModuleBase(pset), one::OutputModule<>(pset) {}
58 
59  // ProvenanceCheckerOutputModule::ProvenanceCheckerOutputModule(ProvenanceCheckerOutputModule const& rhs)
60  // {
61  // // do actual copying here;
62  // }
63 
65 
66  //
67  // assignment operators
68  //
69  // ProvenanceCheckerOutputModule const& ProvenanceCheckerOutputModule::operator=(ProvenanceCheckerOutputModule const& rhs)
70  // {
71  // //An exception safe implementation is
72  // ProvenanceCheckerOutputModule temp(rhs);
73  // swap(rhs);
74  //
75  // return *this;
76  // }
77 
78  namespace {
79  void markAncestors(EventForOutput const& e,
80  ProductProvenance const& iInfo,
81  std::map<BranchID, bool>& oMap,
82  std::set<BranchID>& oMapperMissing) {
83  for (BranchID const id : iInfo.parentage().parents()) {
84  //Don't look for parents if we've previously looked at the parents
85  if (oMap.find(id) == oMap.end()) {
86  //use side effect of calling operator[] which is if the item isn't there it will add it as 'false'
87  oMap[id];
88  ProductProvenance const* pInfo = e.getProvenance(id).productProvenance();
89  if (pInfo) {
90  markAncestors(e, *pInfo, oMap, oMapperMissing);
91  } else {
92  oMapperMissing.insert(id);
93  }
94  }
95  }
96  }
97  } // namespace
98 
100  //check ProductProvenance's parents to see if they are in the ProductProvenance list
101 
102  std::map<BranchID, bool> seenParentInPrincipal;
103  std::set<BranchID> missingFromMapper;
104  std::set<BranchID> missingProductProvenance;
105 
106  std::map<BranchID, const BranchDescription*> idToBranchDescriptions;
107  for (auto const& product : keptProducts()[InEvent]) {
108  BranchDescription const* branchDescription = product.first;
109  BranchID branchID = branchDescription->branchID();
110  idToBranchDescriptions[branchID] = branchDescription;
111  TypeID const& tid(branchDescription->unwrappedTypeID());
112  EDGetToken const& token = product.second;
113  BasicHandle bh = e.getByToken(token, tid);
114  bool cannotFindProductProvenance = false;
115  if (!(bh.provenance() and bh.provenance()->productProvenance())) {
116  missingProductProvenance.insert(branchID);
117  cannotFindProductProvenance = true;
118  }
119  ProductProvenance const* pInfo = e.getProvenance(branchID).productProvenance();
120  if (!pInfo) {
121  missingFromMapper.insert(branchID);
122  continue;
123  }
124  if (cannotFindProductProvenance) {
125  continue;
126  }
127  markAncestors(e, *(bh.provenance()->productProvenance()), seenParentInPrincipal, missingFromMapper);
128  seenParentInPrincipal[branchID] = true;
129  }
130 
131  //Determine what BranchIDs are in the product registry
133  ProductRegistry::ProductList const& prodList = reg->productList();
134  std::set<BranchID> branchesInReg;
135  for (auto const& product : prodList) {
136  branchesInReg.insert(product.second.branchID());
137  idToBranchDescriptions[product.second.branchID()] = &product.second;
138  }
139 
140  std::set<BranchID> missingFromReg;
141  for (auto const& item : seenParentInPrincipal) {
142  if (branchesInReg.find(item.first) == branchesInReg.end()) {
143  missingFromReg.insert(item.first);
144  }
145  }
146 
147  if (!missingFromMapper.empty()) {
148  LogError("ProvenanceChecker") << "Missing the following BranchIDs from ProductProvenanceRetriever\n";
149  for (std::set<BranchID>::iterator it = missingFromMapper.begin(), itEnd = missingFromMapper.end(); it != itEnd;
150  ++it) {
151  LogProblem("ProvenanceChecker") << *it << " " << *(idToBranchDescriptions[*it]);
152  }
153  }
154 
155  if (!missingProductProvenance.empty()) {
156  LogError("ProvenanceChecker") << "The ProductResolvers for the following BranchIDs have no ProductProvenance\n";
157  for (std::set<BranchID>::iterator it = missingProductProvenance.begin(), itEnd = missingProductProvenance.end();
158  it != itEnd;
159  ++it) {
160  LogProblem("ProvenanceChecker") << *it << " " << *(idToBranchDescriptions[*it]);
161  }
162  }
163 
164  if (!missingFromReg.empty()) {
165  LogError("ProvenanceChecker") << "Missing the following BranchIDs from ProductRegistry\n";
166  for (auto const& item : missingFromReg) {
167  LogProblem("ProvenanceChecker") << item << " " << *(idToBranchDescriptions[item]);
168  }
169  }
170 
171  if (!missingFromMapper.empty() || !missingProductProvenance.empty() || !missingFromReg.empty()) {
172  throw cms::Exception("ProvenanceError")
173  << (!missingFromMapper.empty() ? "Having missing ancestors from ProductProvenanceRetriever.\n" : "")
174  << (!missingProductProvenance.empty() ? " Have missing ProductProvenance's from ProductResolver in Event.\n"
175  : "")
176  << (!missingFromReg.empty() ? " Have missing info from ProductRegistry.\n" : "");
177  }
178  }
179 
180  //
181  // const member functions
182  //
183 
184  //
185  // static member functions
186  //
190  descriptions.add("provenanceChecker", desc);
191  }
192 } // namespace edm
ProductProvenance const * productProvenance() const
Definition: Provenance.cc:24
BranchID const & branchID() const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::map< BranchKey, BranchDescription > ProductList
TypeID unwrappedTypeID() const
std::vector< BranchID > const & parents() const
Definition: Parentage.h:44
Log< level::Error, false > LogError
SelectedProductsForBranchType const & keptProducts() const
void write(EventForOutput const &e) override
void add(std::string const &label, ParameterSetDescription const &psetDescription)
ProvenanceCheckerOutputModule(ParameterSet const &pset)
HLT enums.
static void fillDescriptions(ConfigurationDescriptions &descriptions)
Provenance const * provenance() const noexcept(true)
Definition: BasicHandle.h:75
static void fillDescription(ParameterSetDescription &desc, std::vector< std::string > const &iDefaultOutputCommands=ProductSelectorRules::defaultSelectionStrings())
void writeLuminosityBlock(LuminosityBlockForOutput const &) override
Log< level::Error, true > LogProblem
Parentage const & parentage() const
void writeRun(RunForOutput const &) override