CMS 3D CMS Logo

ProvenanceCheckerOutputModule.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Modules
00004 // Class  :     ProvenanceCheckerOutputModule
00005 // 
00006 // Implementation:
00007 //     Checks the consistency of provenance stored in the framework
00008 //
00009 // Original Author:  Chris Jones
00010 //         Created:  Thu Sep 11 19:24:13 EDT 2008
00011 // $Id: ProvenanceCheckerOutputModule.cc,v 1.1 2008/09/16 18:12:26 chrjones Exp $
00012 //
00013 
00014 // system include files
00015 #include "FWCore/Framework/interface/Frameworkfwd.h"
00016 #include "FWCore/Framework/interface/OutputModule.h"
00017 #include "FWCore/Framework/interface/MakerMacros.h"
00018 #include "FWCore/Framework/interface/EventPrincipal.h"
00019 #include "FWCore/Utilities/interface/Exception.h"
00020 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00021 #include "DataFormats/Provenance/interface/ProductRegistry.h"
00022 
00023 // user include files
00024 
00025 namespace edm {
00026    class ParameterSet;
00027    class ProvenanceCheckerOutputModule : public OutputModule {
00028    public:
00029       // We do not take ownership of passed stream.
00030       explicit ProvenanceCheckerOutputModule(ParameterSet const& pset);
00031       virtual ~ProvenanceCheckerOutputModule();
00032       
00033    private:
00034       virtual void write(EventPrincipal const& e);
00035       virtual void writeLuminosityBlock(LuminosityBlockPrincipal const&){}
00036       virtual void writeRun(RunPrincipal const&){}
00037    };
00038 
00039 
00040 //
00041 // constants, enums and typedefs
00042 //
00043 
00044 //
00045 // static data member definitions
00046 //
00047 
00048 //
00049 // constructors and destructor
00050 //
00051    ProvenanceCheckerOutputModule::ProvenanceCheckerOutputModule(ParameterSet const& pset) :
00052    OutputModule(pset)
00053    {
00054    }
00055 
00056 // ProvenanceCheckerOutputModule::ProvenanceCheckerOutputModule(const ProvenanceCheckerOutputModule& rhs)
00057 // {
00058 //    // do actual copying here;
00059 // }
00060 
00061    ProvenanceCheckerOutputModule::~ProvenanceCheckerOutputModule()
00062    {
00063    }
00064 
00065 //
00066 // assignment operators
00067 //
00068 // const ProvenanceCheckerOutputModule& ProvenanceCheckerOutputModule::operator=(const ProvenanceCheckerOutputModule& rhs)
00069 // {
00070 //   //An exception safe implementation is
00071 //   ProvenanceCheckerOutputModule temp(rhs);
00072 //   swap(rhs);
00073 //
00074 //   return *this;
00075 // }
00076 
00077 //
00078 // member functions
00079 //
00080    static void markAncestors(const EventEntryInfo& iInfo,
00081                              const BranchMapper& iMapper,
00082                              std::map<BranchID,bool>& oMap, 
00083                              std::set<BranchID>& oMapperMissing) {
00084       for(std::vector<BranchID>::const_iterator it = iInfo.entryDescription().parents().begin(),
00085           itEnd = iInfo.entryDescription().parents().end();
00086           it != itEnd;
00087           ++it) {
00088          //Don't look for parents if we've previously looked at the parents
00089          if(oMap.find(*it) == oMap.end()) {
00090             //use side effect of calling operator[] which is if the item isn't there it will add it as 'false'
00091             oMap[*it];
00092             boost::shared_ptr<EventEntryInfo> pInfo = iMapper.branchToEntryInfo(*it);
00093             if(pInfo.get()) {
00094                markAncestors(*pInfo,iMapper,oMap,oMapperMissing);
00095             } else {
00096                oMapperMissing.insert(*it);
00097             }
00098          }
00099       }
00100    }
00101    
00102     void 
00103    ProvenanceCheckerOutputModule::write(EventPrincipal const& e) {
00104       //check EventEntryInfo's parents to see if they are in the EventEntryInfo list
00105       boost::shared_ptr<BranchMapper> mapperPtr= e.branchMapperPtr();
00106                        
00107       std::map<BranchID,bool> seenParentInPrincipal;
00108       std::set<BranchID> missingFromMapper;
00109       std::set<BranchID> missingEventEntryInfo;
00110 
00111       for(EventPrincipal::const_iterator it = e.begin(), itEnd = e.end();
00112           it != itEnd;
00113           ++it) {
00114          if(it->second && !it->second->productUnavailable()) {
00115             //This call seems to have a side effect of filling the 'EventEntryInfo' in the Group
00116             OutputHandle<EventEntryInfo> const oh = e.getForOutput<EventEntryInfo>(it->first, false);
00117 
00118             if(not it->second->entryInfoPtr().get() ) {
00119                missingEventEntryInfo.insert(it->first);
00120                continue;
00121             }
00122             boost::shared_ptr<EventEntryInfo> pInfo = mapperPtr->branchToEntryInfo(it->first);
00123             if(!pInfo.get()) {
00124                missingFromMapper.insert(it->first);
00125             }
00126             markAncestors(*(it->second->entryInfoPtr()),*mapperPtr,seenParentInPrincipal, missingFromMapper);
00127          }
00128          seenParentInPrincipal[it->first]=true;
00129       }
00130       
00131       //Determine what BranchIDs are in the product registry
00132       const ProductRegistry& reg = e.productRegistry();
00133       const ProductRegistry::ProductList prodList = reg.productList();
00134       std::set<BranchID> branchesInReg;
00135       for(ProductRegistry::ProductList::const_iterator it = prodList.begin(), itEnd = prodList.end();
00136           it != itEnd;
00137           ++it) {
00138          branchesInReg.insert(it->second.branchID());
00139       }
00140       
00141       
00142       std::set<BranchID> missingFromPrincipal;
00143       std::set<BranchID> missingFromReg;
00144       for(std::map<BranchID,bool>::iterator it=seenParentInPrincipal.begin(), itEnd = seenParentInPrincipal.end();
00145           it != itEnd;
00146           ++it) {
00147          if(!it->second) {
00148             missingFromPrincipal.insert(it->first);
00149          }
00150          if(branchesInReg.find(it->first) == branchesInReg.end()) {
00151             missingFromReg.insert(it->first);
00152          }
00153       }
00154       
00155       
00156       if(missingFromMapper.size()) {
00157          edm::LogError("ProvenanceChecker") <<"Missing the following BranchIDs from BranchMapper\n";
00158          for(std::set<BranchID>::iterator it=missingFromMapper.begin(), itEnd = missingFromMapper.end();
00159              it!=itEnd;
00160              ++it) {
00161             edm::LogProblem("ProvenanceChecker")<<*it;
00162          }
00163       }
00164       if(missingFromPrincipal.size()) {
00165          edm::LogError("ProvenanceChecker") <<"Missing the following BranchIDs from EventPrincipal\n";
00166          for(std::set<BranchID>::iterator it=missingFromPrincipal.begin(), itEnd = missingFromPrincipal.end();
00167              it!=itEnd;
00168              ++it) {
00169             edm::LogProblem("ProvenanceChecker")<<*it;
00170          }
00171       }
00172       
00173       if(missingEventEntryInfo.size()) {
00174          edm::LogError("ProvenanceChecker") <<"The Groups for the following BranchIDs have no EventEntryInfo\n";
00175          for(std::set<BranchID>::iterator it=missingEventEntryInfo.begin(), itEnd = missingEventEntryInfo.end();
00176              it!=itEnd;
00177              ++it) {
00178             edm::LogProblem("ProvenanceChecker")<<*it;
00179          }      
00180       }
00181 
00182       if(missingFromReg.size()) {
00183          edm::LogError("ProvenanceChecker") <<"Missing the following BranchIDs from ProductRegistry\n";
00184          for(std::set<BranchID>::iterator it=missingFromReg.begin(), itEnd = missingFromReg.end();
00185              it!=itEnd;
00186              ++it) {
00187             edm::LogProblem("ProvenanceChecker")<<*it;
00188          }
00189       }
00190       
00191       
00192       if(missingFromMapper.size() or missingFromPrincipal.size() or missingEventEntryInfo.size() or missingFromReg.size()) {
00193          throw cms::Exception("ProvenanceError")
00194          <<(missingFromMapper.size() or missingFromPrincipal.size()?"Having missing ancestors": "")
00195          <<(missingFromMapper.size()?" from BranchMapper":"")
00196          <<(missingFromMapper.size() and missingFromPrincipal.size()?" and":"")
00197          <<(missingFromPrincipal.size()?" from EventPrincipal":"")
00198          <<(missingFromMapper.size() or missingFromPrincipal.size()?".\n":"")
00199          <<(missingEventEntryInfo.size()?" Have missing EventEntryInfo's from Group in EventPrincipal.\n":"")
00200          <<(missingFromReg.size()?" Have missing info from ProductRegistry.\n":"");
00201       }
00202    }
00203 
00204 //
00205 // const member functions
00206 //
00207 
00208 //
00209 // static member functions
00210 //
00211 }
00212 using edm::ProvenanceCheckerOutputModule;
00213 DEFINE_FWK_MODULE(ProvenanceCheckerOutputModule);

Generated on Tue Jun 9 17:36:22 2009 for CMSSW by  doxygen 1.5.4