Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing OutputModules only get products they consume #13467

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 15 additions & 32 deletions FWCore/Modules/src/GetProductCheckerOutputModule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,54 +79,37 @@ namespace edm {
//
// member functions
//
static void check(Principal const& p, std::string const& id, edm::ModuleCallingContext const* mcc) {
for(Principal::const_iterator it = p.begin(), itEnd = p.end();
it != itEnd;
++it) {
if(*it) {
if (!(*it)->singleProduct()) continue;

BranchID branchID = (*it)->branchDescription().branchID();
OutputHandle const oh = p.getForOutput(branchID, false, mcc);

if(0 != oh.desc() && oh.desc()->branchID() != branchID) {
throw cms::Exception("BranchIDMissMatch") << "While processing " << id << " request for BranchID " << branchID << " returned BranchID " << oh.desc()->branchID() << "\n";
}

TypeID const& tid((*it)->branchDescription().unwrappedTypeID());
static void check(Principal const& p, std::string const& id, SelectedProducts const& iProducts, edm::ModuleCallingContext const* mcc) {
for(auto const& branchDescription : iProducts) {
TypeID const& tid(branchDescription->unwrappedTypeID());
BasicHandle bh = p.getByLabel(PRODUCT_TYPE, tid,
(*it)->branchDescription().moduleLabel(),
(*it)->branchDescription().productInstanceName(),
(*it)->branchDescription().processName(),
branchDescription->moduleLabel(),
branchDescription->productInstanceName(),
branchDescription->processName(),
nullptr, nullptr, mcc);

/*This doesn't appear to be an error, it just means the Product isn't available, which can be legitimate
if(!bh.product()) {
throw cms::Exception("GetByLabelFailure") << "While processing " << id << " getByLabel request for " << (*it)->productDescription().moduleLabel()
<< " '" << (*it)->productDescription().productInstanceName() << "' " << (*it)->productDescription().processName() << " failed\n.";
}*/
if(0 != bh.provenance() && bh.provenance()->branchDescription().branchID() != branchID) {
throw cms::Exception("BranchIDMissMatch") << "While processing " << id << " getByLabel request for " << (*it)->branchDescription().moduleLabel()
<< " '" << (*it)->branchDescription().productInstanceName() << "' " << (*it)->branchDescription().processName()
<< "\n should have returned BranchID " << branchID << " but returned BranchID " << bh.provenance()->branchDescription().branchID() << "\n";
}
}
if(0 != bh.provenance() && bh.provenance()->branchDescription().branchID() != branchDescription->branchID()) {
throw cms::Exception("BranchIDMissMatch") << "While processing " << id << " getByLabel request for " << branchDescription->moduleLabel()
<< " '" << branchDescription->productInstanceName() << "' " << branchDescription->processName()
<< "\n should have returned BranchID " << branchDescription->branchID() << " but returned BranchID " << bh.provenance()->branchDescription().branchID() << "\n";
}

}
}
void GetProductCheckerOutputModule::write(EventPrincipal const& e, edm::ModuleCallingContext const* mcc) {
std::ostringstream str;
str << e.id();
check(e, str.str(), mcc);
check(e, str.str(), keptProducts()[InEvent], mcc);
}
void GetProductCheckerOutputModule::writeLuminosityBlock(LuminosityBlockPrincipal const& l, edm::ModuleCallingContext const* mcc) {
std::ostringstream str;
str << l.id();
check(l, str.str(), mcc);
check(l, str.str(), keptProducts()[InLumi], mcc);
}
void GetProductCheckerOutputModule::writeRun(RunPrincipal const& r, edm::ModuleCallingContext const* mcc) {
std::ostringstream str;
str << r.id();
check(r, str.str(), mcc);
check(r, str.str(), keptProducts()[InRun], mcc);
}

//
Expand Down
78 changes: 32 additions & 46 deletions FWCore/Modules/src/ProvenanceCheckerOutputModule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,32 +112,33 @@ namespace edm {
std::set<BranchID> missingFromMapper;
std::set<BranchID> missingProductProvenance;

std::map<BranchID, std::shared_ptr<ProductHolderBase const>> idToProductHolder;
for(auto const& product : e) {
if(product && product->singleProduct()) {
BranchID branchID = product->branchDescription().branchID();
idToProductHolder[branchID] = get_underlying_safe(product);
if(product->productUnavailable()) {
//This call seems to have a side effect of filling the 'ProductProvenance' in the ProductHolder
OutputHandle const oh = e.getForOutput(branchID, false, mcc);

bool cannotFindProductProvenance=false;
if(!product->productProvenancePtr()) {
missingProductProvenance.insert(branchID);
cannotFindProductProvenance=true;
}
ProductProvenance const* pInfo = mapperPtr->branchIDToProvenance(branchID);
if(!pInfo) {
missingFromMapper.insert(branchID);
continue;
}
if(cannotFindProductProvenance) {
continue;
}
markAncestors(*(product->productProvenancePtr()), *mapperPtr, seenParentInPrincipal, missingFromMapper);
}
std::map<BranchID, const BranchDescription*> idToBranchDescriptions;
for(auto const branchDescription : keptProducts()[InEvent]) {
BranchID branchID = branchDescription->branchID();
idToBranchDescriptions[branchID] = branchDescription;

TypeID const& tid(branchDescription->unwrappedTypeID());
BasicHandle bh = e.getByLabel(PRODUCT_TYPE, tid,
branchDescription->moduleLabel(),
branchDescription->productInstanceName(),
branchDescription->processName(),
nullptr, nullptr, mcc);

bool cannotFindProductProvenance=false;
if(!(bh.provenance() and bh.provenance()->productProvenance())) {
missingProductProvenance.insert(branchID);
cannotFindProductProvenance=true;
}
ProductProvenance const* pInfo = mapperPtr->branchIDToProvenance(branchID);
if(!pInfo) {
missingFromMapper.insert(branchID);
continue;
}
if(cannotFindProductProvenance) {
continue;
}
markAncestors(*(bh.provenance()->productProvenance()), *mapperPtr, seenParentInPrincipal, missingFromMapper);
seenParentInPrincipal[branchID] = true;
}
}

//Determine what BranchIDs are in the product registry
Expand All @@ -148,16 +149,13 @@ namespace edm {
it != itEnd;
++it) {
branchesInReg.insert(it->second.branchID());
idToBranchDescriptions[it->second.branchID()] = &(it->second);
}

std::set<BranchID> missingFromPrincipal;
std::set<BranchID> missingFromReg;
for(std::map<BranchID, bool>::iterator it = seenParentInPrincipal.begin(), itEnd = seenParentInPrincipal.end();
it != itEnd;
++it) {
if(!it->second) {
missingFromPrincipal.insert(it->first);
}
if(branchesInReg.find(it->first) == branchesInReg.end()) {
missingFromReg.insert(it->first);
}
Expand All @@ -168,15 +166,7 @@ namespace edm {
for(std::set<BranchID>::iterator it = missingFromMapper.begin(), itEnd = missingFromMapper.end();
it != itEnd;
++it) {
LogProblem("ProvenanceChecker") << *it<<" "<<idToProductHolder[*it]->branchDescription();
}
}
if(missingFromPrincipal.size()) {
LogError("ProvenanceChecker") << "Missing the following BranchIDs from EventPrincipal\n";
for(std::set<BranchID>::iterator it = missingFromPrincipal.begin(), itEnd = missingFromPrincipal.end();
it != itEnd;
++it) {
LogProblem("ProvenanceChecker") << *it;
LogProblem("ProvenanceChecker") << *it<<" "<<*(idToBranchDescriptions[*it]);
}
}

Expand All @@ -185,7 +175,7 @@ namespace edm {
for(std::set<BranchID>::iterator it = missingProductProvenance.begin(), itEnd = missingProductProvenance.end();
it != itEnd;
++it) {
LogProblem("ProvenanceChecker") << *it<<" "<<idToProductHolder[*it]->branchDescription();
LogProblem("ProvenanceChecker") << *it<<" "<<*(idToBranchDescriptions[*it]);
}
}

Expand All @@ -194,17 +184,13 @@ namespace edm {
for(std::set<BranchID>::iterator it = missingFromReg.begin(), itEnd = missingFromReg.end();
it != itEnd;
++it) {
LogProblem("ProvenanceChecker") << *it;
LogProblem("ProvenanceChecker") << *it<<" "<<*(idToBranchDescriptions[*it]);
}
}

if(missingFromMapper.size() || missingFromPrincipal.size() || missingProductProvenance.size() || missingFromReg.size()) {
if(missingFromMapper.size() || missingProductProvenance.size() || missingFromReg.size()) {
throw cms::Exception("ProvenanceError")
<< (missingFromMapper.size() || missingFromPrincipal.size() ? "Having missing ancestors" : "")
<< (missingFromMapper.size() ? " from ProductProvenanceRetriever" : "")
<< (missingFromMapper.size() && missingFromPrincipal.size() ? " and" : "")
<< (missingFromPrincipal.size() ? " from EventPrincipal" : "")
<< (missingFromMapper.size() || missingFromPrincipal.size() ? ".\n" : "")
<< (missingFromMapper.size() ? "Having missing ancestors from ProductProvenanceRetriever.\n" : "")
<< (missingProductProvenance.size() ? " Have missing ProductProvenance's from ProductHolder in EventPrincipal.\n" : "")
<< (missingFromReg.size() ? " Have missing info from ProductRegistry.\n" : "");
}
Expand Down