Skip to content

Commit

Permalink
Merge pull request #6989 from Dr15Jones/refToAlias
Browse files Browse the repository at this point in the history
Fix ProductID problems when using an EDAlias
  • Loading branch information
cmsbuild committed Dec 19, 2014
2 parents 27feba7 + 93b1f84 commit 06c608b
Show file tree
Hide file tree
Showing 12 changed files with 253 additions and 41 deletions.
3 changes: 2 additions & 1 deletion DataFormats/Provenance/src/BranchIDListHelper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ namespace edm {
// Add entries for current process for ProductID to BranchID mapping.
for(ProductRegistry::ProductList::const_iterator it = preg.productList().begin(), itEnd = preg.productList().end();
it != itEnd; ++it) {
if(it->second.produced()) {
//In the case of the alias, we always use the original branches BranchID
if(it->second.produced() and not it->second.isAlias()) {
if(it->second.branchType() == InEvent) {
bidlist.push_back(it->second.branchID().id());
}
Expand Down
9 changes: 8 additions & 1 deletion FWCore/Framework/src/EventPrincipal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,14 @@ namespace edm {
// Fill in the product ID's in the product holders.
for(auto const& prod : *this) {
if (prod->singleProduct()) {
prod->setProvenance(productProvenanceRetrieverPtr(), processHistory(), branchIDToProductID(prod->branchDescription().branchID()));
// If an alias is in the same process as the original then isAlias will be true.
// Under that condition, we want the ProductID to be the same as the original.
// If not, then we've internally changed the original BranchID to the alias BranchID
// in the ProductID lookup so we need the alias BranchID.
auto const & bd =prod->branchDescription();
prod->setProvenance(productProvenanceRetrieverPtr(),
processHistory(),
branchIDToProductID(bd.isAlias()?bd.originalBranchID(): bd.branchID()));
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion FWCore/Integration/test/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@
<flags TEST_RUNNER_ARGS=" /bin/bash FWCore/Integration/test run_RefMerge.sh"/>
<use name="FWCore/Utilities"/>
</bin>
<bin file="TestIntegration.cpp" name="TestIntegrationRefAlias">
<flags TEST_RUNNER_ARGS=" /bin/bash FWCore/Integration/test run_RefAlias.sh"/>
<use name="FWCore/Utilities"/>
</bin>
<bin file="TestIntegration.cpp" name="TestIntegrationParameterSet">
<flags TEST_RUNNER_ARGS=" /bin/bash FWCore/Integration/test run_ParameterSet.sh"/>
<use name="FWCore/Utilities"/>
Expand Down Expand Up @@ -168,7 +172,7 @@
<use name="FWCore/ParameterSet"/>
<use name="FWCore/Framework"/>
</library>
<library file="OtherThingAnalyzer.cc" name="TestOtherThingAnalyzer">
<library file="OtherThingAnalyzer.cc,OtherThingRefComparer.cc" name="TestOtherThingAnalyzer">
<flags EDM_PLUGIN="1"/>
<use name="DataFormats/Common"/>
<use name="FWCore/Framework"/>
Expand Down
21 changes: 20 additions & 1 deletion FWCore/Integration/test/OtherThingAnalyzer.cc
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
#include <iostream>
#include "FWCore/Integration/test/OtherThingAnalyzer.h"
#include "DataFormats/TestObjects/interface/OtherThing.h"
#include "DataFormats/TestObjects/interface/OtherThingCollection.h"
#include "FWCore/Framework/interface/Event.h"
#include "DataFormats/Common/interface/Handle.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Utilities/interface/Exception.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/stream/EDAnalyzer.h"
#include "FWCore/Utilities/interface/InputTag.h"


namespace edmtest {

class OtherThingAnalyzer : public edm::stream::EDAnalyzer<> {
public:

explicit OtherThingAnalyzer(edm::ParameterSet const& pset);

virtual void analyze(edm::Event const& e, edm::EventSetup const& c) override;

void doit(edm::Event const& event, std::string const& label);

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
private:
bool thingWasDropped_;
edm::InputTag otherTag_;
};

OtherThingAnalyzer::OtherThingAnalyzer(edm::ParameterSet const& pset) :
thingWasDropped_(pset.getUntrackedParameter<bool>("thingWasDropped")),
otherTag_(pset.getUntrackedParameter<edm::InputTag>("other"))
Expand Down
29 changes: 0 additions & 29 deletions FWCore/Integration/test/OtherThingAnalyzer.h

This file was deleted.

76 changes: 76 additions & 0 deletions FWCore/Integration/test/OtherThingRefComparer.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include <iostream>
#include "DataFormats/TestObjects/interface/OtherThing.h"
#include "DataFormats/TestObjects/interface/OtherThingCollection.h"
#include "FWCore/Framework/interface/Event.h"
#include "DataFormats/Common/interface/Handle.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Utilities/interface/Exception.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/stream/EDAnalyzer.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "FWCore/Utilities/interface/EDGetToken.h"


namespace edmtest {

class OtherThingRefComparer : public edm::stream::EDAnalyzer<> {
public:

explicit OtherThingRefComparer(edm::ParameterSet const& pset);

virtual void analyze(edm::Event const& e, edm::EventSetup const& c) override;

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
private:
edm::EDGetTokenT<OtherThingCollection> token1_;
edm::EDGetTokenT<OtherThingCollection> token2_;
};

OtherThingRefComparer::OtherThingRefComparer(edm::ParameterSet const& pset) :
token1_(consumes<OtherThingCollection>(pset.getUntrackedParameter<edm::InputTag>("first"))),
token2_(consumes<OtherThingCollection>(pset.getUntrackedParameter<edm::InputTag>("second")))
{
}

void OtherThingRefComparer::analyze(edm::Event const& e, edm::EventSetup const&) {
edm::Handle<OtherThingCollection> handle1_;
e.getByToken(token1_,handle1_);
edm::Handle<OtherThingCollection> handle2_;
e.getByToken(token2_,handle2_);

assert(handle1_->size() == handle2_->size());

{
auto iter2 = handle2_->begin();
for(auto const& o1: *handle1_) {
if(o1.ref != iter2->ref) {
throw cms::Exception("RefCompareFailure")<<"edm::Refs are not equal"<< o1.ref.id()<<" "<<iter2->ref.id();
}
++iter2;
}
}

{
auto iter2 = handle2_->begin();
for(auto const& o1: *handle1_) {
if(o1.ptr != iter2->ptr) {
throw cms::Exception("RefCompareFailure")<<"edm::Ptrs are not equal"<<o1.ptr.id()<<" "<<iter2->ptr.id();
}
++iter2;
}
}


}

void OtherThingRefComparer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.addUntracked<edm::InputTag>("first",edm::InputTag("OtherThing","testUserTag"))->setComment("Where to get the first OtherThingCollection");
desc.addUntracked<edm::InputTag>("second",edm::InputTag("OtherThing","testUserTag"))->setComment("Where to get the second OtherThingCollection");
descriptions.add("otherThingRefComparer", desc);
}

}
using edmtest::OtherThingRefComparer;
DEFINE_FWK_MODULE(OtherThingRefComparer);
10 changes: 2 additions & 8 deletions FWCore/Integration/test/ThinningTestAnalyzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,8 @@ namespace edmtest {
}

if(!thinnedWasDropped_ && !associationShouldBeDropped_) {
if(!thinnedIsAlias_) {
if(associationCollection->thinnedCollectionID() != thinnedCollection.id()) {
throw cms::Exception("TestFailure") << "analyze thinned ProductID is not correct";
}
} else {
if(associationCollection->thinnedCollectionID() == thinnedCollection.id()) {
throw cms::Exception("TestFailure") << "analyze thinned ProductID is not correct";
}
if(associationCollection->thinnedCollectionID() != thinnedCollection.id()) {
throw cms::Exception("TestFailure") << "analyze thinned ProductID is not correct";
}
}

Expand Down
33 changes: 33 additions & 0 deletions FWCore/Integration/test/ref_alias_compare_drop_alias_cfg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import FWCore.ParameterSet.Config as cms

process = cms.Process("Test")
process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(10))

process.source = cms.Source("EmptySource")

process.thing = cms.EDProducer("ThingProducer")

process.thingAlias = cms.EDAlias( thing = cms.VPSet(
cms.PSet(type = cms.string('edmtestThings'),
fromProductInstance = cms.string('*'),
toProductInstance = cms.string('*'))))

process.otherThing1 = cms.EDProducer("OtherThingProducer",
thingTag=cms.InputTag("thing"))

process.otherThing2 = cms.EDProducer("OtherThingProducer",
thingTag=cms.InputTag("thingAlias"))

process.comparer = cms.EDAnalyzer("OtherThingRefComparer",
first = cms.untracked.InputTag("otherThing1:testUserTag"),
second = cms.untracked.InputTag("otherThing2:testUserTag")
)

process.out = cms.OutputModule("PoolOutputModule",
fileName = cms.untracked.string("ref_alias_drop_alias.root"),
outputCommands = cms.untracked.vstring("keep *",
"drop *_thingAlias_*_*")
)

process.p = cms.Path(process.thing+process.otherThing1+process.otherThing2+process.comparer)
process.o = cms.EndPath(process.out)
33 changes: 33 additions & 0 deletions FWCore/Integration/test/ref_alias_compare_drop_original_cfg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import FWCore.ParameterSet.Config as cms

process = cms.Process("Test")
process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(10))

process.source = cms.Source("EmptySource")

process.thing = cms.EDProducer("ThingProducer")

process.thingAlias = cms.EDAlias( thing = cms.VPSet(
cms.PSet(type = cms.string('edmtestThings'),
fromProductInstance = cms.string('*'),
toProductInstance = cms.string('*'))))

process.otherThing1 = cms.EDProducer("OtherThingProducer",
thingTag=cms.InputTag("thing"))

process.otherThing2 = cms.EDProducer("OtherThingProducer",
thingTag=cms.InputTag("thingAlias"))

process.comparer = cms.EDAnalyzer("OtherThingRefComparer",
first = cms.untracked.InputTag("otherThing1:testUserTag"),
second = cms.untracked.InputTag("otherThing2:testUserTag")
)

process.out = cms.OutputModule("PoolOutputModule",
fileName = cms.untracked.string("ref_alias_drop_original.root"),
outputCommands = cms.untracked.vstring("keep *",
"drop *_thing_*_*")
)

process.p = cms.Path(process.thing+process.otherThing1+process.otherThing2+process.comparer)
process.o = cms.EndPath(process.out)
26 changes: 26 additions & 0 deletions FWCore/Integration/test/ref_alias_compare_read_alias_cfg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import FWCore.ParameterSet.Config as cms

process = cms.Process("Analyze")

process.source = cms.Source("PoolSource", fileNames = cms.untracked.vstring("file:ref_alias_drop_original.root"))

process.otherThing3 = cms.EDProducer("OtherThingProducer",
thingTag=cms.InputTag("thingAlias"))

process.comparerA = cms.EDAnalyzer("OtherThingRefComparer",
first = cms.untracked.InputTag("otherThing1:testUserTag"),
second = cms.untracked.InputTag("otherThing2:testUserTag")
)

process.comparerB = cms.EDAnalyzer("OtherThingRefComparer",
first = cms.untracked.InputTag("otherThing1:testUserTag"),
second = cms.untracked.InputTag("otherThing3:testUserTag")
)

process.comparerC = cms.EDAnalyzer("OtherThingRefComparer",
first = cms.untracked.InputTag("otherThing2:testUserTag"),
second = cms.untracked.InputTag("otherThing3:testUserTag")
)

process.p = cms.Path(process.otherThing3+process.comparerA+process.comparerB+process.comparerC)

25 changes: 25 additions & 0 deletions FWCore/Integration/test/ref_alias_compare_read_original_cfg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import FWCore.ParameterSet.Config as cms

process = cms.Process("Analyze")

process.source = cms.Source("PoolSource", fileNames = cms.untracked.vstring("file:ref_alias_drop_alias.root"))

process.otherThing3 = cms.EDProducer("OtherThingProducer",
thingTag=cms.InputTag("thing"))

process.comparerA = cms.EDAnalyzer("OtherThingRefComparer",
first = cms.untracked.InputTag("otherThing1:testUserTag"),
second = cms.untracked.InputTag("otherThing2:testUserTag")
)

process.comparerB = cms.EDAnalyzer("OtherThingRefComparer",
first = cms.untracked.InputTag("otherThing1:testUserTag"),
second = cms.untracked.InputTag("otherThing3:testUserTag")
)

process.comparerC = cms.EDAnalyzer("OtherThingRefComparer",
first = cms.untracked.InputTag("otherThing2:testUserTag"),
second = cms.untracked.InputTag("otherThing3:testUserTag")
)

process.p = cms.Path(process.otherThing3+process.comparerA+process.comparerB+process.comparerC)
23 changes: 23 additions & 0 deletions FWCore/Integration/test/run_RefAlias.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
test=ref_alias_compare_

function die { echo Failure $1: status $2 ; exit $2 ; }

echo LOCAL_TMP_DIR = ${LOCAL_TMP_DIR}

pushd ${LOCAL_TMP_DIR}
echo ${test}drop_alias_cfg.py ------------------------------------------------------------
cmsRun -p ${LOCAL_TEST_DIR}/${test}drop_alias_cfg.py || die "cmsRun ${test}drop_alias_cfg.py" $?

echo ${test}drop_original_cfg.py ------------------------------------------------------------
cmsRun -p ${LOCAL_TEST_DIR}/${test}drop_original_cfg.py || die "cmsRun ${test}drop_original_cfg.py" $?

echo ${test}read_alias_cfg.py------------------------------------------------------------
cmsRun -p ${LOCAL_TEST_DIR}/${test}read_alias_cfg.py || die "cmsRun ${test}read_alias_cfg.py" $?

echo ${test}read_original_cfg.py------------------------------------------------------------
cmsRun -p ${LOCAL_TEST_DIR}/${test}read_original_cfg.py || die "cmsRun ${test}read_original_cfg.py" $?

popd

exit 0

0 comments on commit 06c608b

Please sign in to comment.