test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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
23 
24 // user include files
25 
26 namespace edm {
27 
28  class ModuleCallingContext;
29  class ParameterSet;
30 
32  public:
33  // We do not take ownership of passed stream.
34  explicit ProvenanceCheckerOutputModule(ParameterSet const& pset);
36  static void fillDescriptions(ConfigurationDescriptions& descriptions);
37 
38  private:
39  virtual void write(EventPrincipal const& e, ModuleCallingContext const*) override;
40  virtual void writeLuminosityBlock(LuminosityBlockPrincipal const&, ModuleCallingContext const*) override {}
41  virtual void writeRun(RunPrincipal const&, ModuleCallingContext const*) override {}
42  };
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  OutputModule(pset)
58  {
59  }
60 
61 // ProvenanceCheckerOutputModule::ProvenanceCheckerOutputModule(ProvenanceCheckerOutputModule const& rhs)
62 // {
63 // // do actual copying here;
64 // }
65 
67  {
68  }
69 
70 //
71 // assignment operators
72 //
73 // ProvenanceCheckerOutputModule const& ProvenanceCheckerOutputModule::operator=(ProvenanceCheckerOutputModule const& rhs)
74 // {
75 // //An exception safe implementation is
76 // ProvenanceCheckerOutputModule temp(rhs);
77 // swap(rhs);
78 //
79 // return *this;
80 // }
81 
82  namespace {
83  void markAncestors(ProductProvenance const& iInfo,
84  ProductProvenanceRetriever const& iMapper,
85  std::map<BranchID, bool>& oMap,
86  std::set<BranchID>& oMapperMissing) {
87  for(std::vector<BranchID>::const_iterator it = iInfo.parentage().parents().begin(),
88  itEnd = iInfo.parentage().parents().end();
89  it != itEnd;
90  ++it) {
91  //Don't look for parents if we've previously looked at the parents
92  if(oMap.find(*it) == oMap.end()) {
93  //use side effect of calling operator[] which is if the item isn't there it will add it as 'false'
94  oMap[*it];
95  ProductProvenance const* pInfo = iMapper.branchIDToProvenance(*it);
96  if(pInfo) {
97  markAncestors(*pInfo, iMapper, oMap, oMapperMissing);
98  } else {
99  oMapperMissing.insert(*it);
100  }
101  }
102  }
103  }
104  }
105 
106  void
108  //check ProductProvenance's parents to see if they are in the ProductProvenance list
109  std::shared_ptr<ProductProvenanceRetriever> mapperPtr = e.productProvenanceRetrieverPtr();
110 
111  std::map<BranchID, bool> seenParentInPrincipal;
112  std::set<BranchID> missingFromMapper;
113  std::set<BranchID> missingProductProvenance;
114 
115  std::map<BranchID, std::shared_ptr<ProductHolderBase> > idToProductHolder;
116  for(EventPrincipal::const_iterator it = e.begin(), itEnd = e.end();
117  it != itEnd;
118  ++it) {
119  if(*it && (*it)->singleProduct()) {
120  BranchID branchID = (*it)->branchDescription().branchID();
121  idToProductHolder[branchID] = (*it);
122  if((*it)->productUnavailable()) {
123  //This call seems to have a side effect of filling the 'ProductProvenance' in the ProductHolder
124  OutputHandle const oh = e.getForOutput(branchID, false, mcc);
125 
126  bool cannotFindProductProvenance=false;
127  if(!(*it)->productProvenancePtr()) {
128  missingProductProvenance.insert(branchID);
129  cannotFindProductProvenance=true;
130  }
131  ProductProvenance const* pInfo = mapperPtr->branchIDToProvenance(branchID);
132  if(!pInfo) {
133  missingFromMapper.insert(branchID);
134  continue;
135  }
136  if(cannotFindProductProvenance) {
137  continue;
138  }
139  markAncestors(*((*it)->productProvenancePtr()), *mapperPtr, seenParentInPrincipal, missingFromMapper);
140  }
141  seenParentInPrincipal[branchID] = true;
142  }
143  }
144 
145  //Determine what BranchIDs are in the product registry
146  ProductRegistry const& reg = e.productRegistry();
147  ProductRegistry::ProductList const prodList = reg.productList();
148  std::set<BranchID> branchesInReg;
149  for(ProductRegistry::ProductList::const_iterator it = prodList.begin(), itEnd = prodList.end();
150  it != itEnd;
151  ++it) {
152  branchesInReg.insert(it->second.branchID());
153  }
154 
155  std::set<BranchID> missingFromPrincipal;
156  std::set<BranchID> missingFromReg;
157  for(std::map<BranchID, bool>::iterator it = seenParentInPrincipal.begin(), itEnd = seenParentInPrincipal.end();
158  it != itEnd;
159  ++it) {
160  if(!it->second) {
161  missingFromPrincipal.insert(it->first);
162  }
163  if(branchesInReg.find(it->first) == branchesInReg.end()) {
164  missingFromReg.insert(it->first);
165  }
166  }
167 
168  if(missingFromMapper.size()) {
169  LogError("ProvenanceChecker") << "Missing the following BranchIDs from ProductProvenanceRetriever\n";
170  for(std::set<BranchID>::iterator it = missingFromMapper.begin(), itEnd = missingFromMapper.end();
171  it != itEnd;
172  ++it) {
173  LogProblem("ProvenanceChecker") << *it<<" "<<idToProductHolder[*it]->branchDescription();
174  }
175  }
176  if(missingFromPrincipal.size()) {
177  LogError("ProvenanceChecker") << "Missing the following BranchIDs from EventPrincipal\n";
178  for(std::set<BranchID>::iterator it = missingFromPrincipal.begin(), itEnd = missingFromPrincipal.end();
179  it != itEnd;
180  ++it) {
181  LogProblem("ProvenanceChecker") << *it;
182  }
183  }
184 
185  if(missingProductProvenance.size()) {
186  LogError("ProvenanceChecker") << "The ProductHolders for the following BranchIDs have no ProductProvenance\n";
187  for(std::set<BranchID>::iterator it = missingProductProvenance.begin(), itEnd = missingProductProvenance.end();
188  it != itEnd;
189  ++it) {
190  LogProblem("ProvenanceChecker") << *it<<" "<<idToProductHolder[*it]->branchDescription();
191  }
192  }
193 
194  if(missingFromReg.size()) {
195  LogError("ProvenanceChecker") << "Missing the following BranchIDs from ProductRegistry\n";
196  for(std::set<BranchID>::iterator it = missingFromReg.begin(), itEnd = missingFromReg.end();
197  it != itEnd;
198  ++it) {
199  LogProblem("ProvenanceChecker") << *it;
200  }
201  }
202 
203  if(missingFromMapper.size() || missingFromPrincipal.size() || missingProductProvenance.size() || missingFromReg.size()) {
204  throw cms::Exception("ProvenanceError")
205  << (missingFromMapper.size() || missingFromPrincipal.size() ? "Having missing ancestors" : "")
206  << (missingFromMapper.size() ? " from ProductProvenanceRetriever" : "")
207  << (missingFromMapper.size() && missingFromPrincipal.size() ? " and" : "")
208  << (missingFromPrincipal.size() ? " from EventPrincipal" : "")
209  << (missingFromMapper.size() || missingFromPrincipal.size() ? ".\n" : "")
210  << (missingProductProvenance.size() ? " Have missing ProductProvenance's from ProductHolder in EventPrincipal.\n" : "")
211  << (missingFromReg.size() ? " Have missing info from ProductRegistry.\n" : "");
212  }
213  }
214 
215 //
216 // const member functions
217 //
218 
219 //
220 // static member functions
221 //
222  void
226  descriptions.add("provenanceChecker", desc);
227  }
228 }
ProductRegistry const & productRegistry() const
Definition: Principal.h:152
const_iterator end() const
Definition: Principal.h:163
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::map< BranchKey, BranchDescription > ProductList
virtual void write(EventPrincipal const &e, ModuleCallingContext const *) override
std::vector< BranchID > const & parents() const
Definition: Parentage.h:37
ProductList const & productList() const
std::shared_ptr< ProductProvenanceRetriever > productProvenanceRetrieverPtr() const
OutputHandle getForOutput(BranchID const &bid, bool getProd, ModuleCallingContext const *mcc) const
Definition: Principal.cc:749
virtual void writeLuminosityBlock(LuminosityBlockPrincipal const &, ModuleCallingContext const *) override
virtual void writeRun(RunPrincipal const &, ModuleCallingContext const *) override
const_iterator begin() const
Definition: Principal.h:162
void add(std::string const &label, ParameterSetDescription const &psetDescription)
ProvenanceCheckerOutputModule(ParameterSet const &pset)
static void fillDescription(ParameterSetDescription &desc)
boost::filter_iterator< FilledProductPtr, ProductHolderCollection::const_iterator > const_iterator
Definition: Principal.h:57
ProductProvenance const * branchIDToProvenance(BranchID const &bid) const
static void fillDescriptions(ConfigurationDescriptions &descriptions)
Parentage const & parentage() const