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