00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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
00024
00025 namespace edm {
00026 class ParameterSet;
00027 class ProvenanceCheckerOutputModule : public OutputModule {
00028 public:
00029
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
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 ProvenanceCheckerOutputModule::ProvenanceCheckerOutputModule(ParameterSet const& pset) :
00052 OutputModule(pset)
00053 {
00054 }
00055
00056
00057
00058
00059
00060
00061 ProvenanceCheckerOutputModule::~ProvenanceCheckerOutputModule()
00062 {
00063 }
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
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
00089 if(oMap.find(*it) == oMap.end()) {
00090
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
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
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
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
00206
00207
00208
00209
00210
00211 }
00212 using edm::ProvenanceCheckerOutputModule;
00213 DEFINE_FWK_MODULE(ProvenanceCheckerOutputModule);