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