Skip to content

Commit e533960

Browse files
committed
Test provenance of dropped products
Only provenance of dropped ancestors are stored in ROOT files. Using untracked parameter for InputTag keeps the ProcessHistory the same so there is only one Run in the workflow.
1 parent eb45085 commit e533960

File tree

8 files changed

+110
-1
lines changed

8 files changed

+110
-1
lines changed

FWCore/Framework/interface/OccurrenceForOutput.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ namespace edm {
6464
Handle<PROD> getHandle(EDGetTokenT<PROD> token) const;
6565

6666
Provenance getProvenance(BranchID const& theID) const;
67+
StableProvenance const& getStableProvenance(BranchID const& ithID) const;
6768

6869
void getAllProvenance(std::vector<Provenance const*>& provenances) const;
6970

FWCore/Framework/src/OccurrenceForOutput.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ namespace edm {
2929
return provRecorder_.principal().getProvenance(bid);
3030
}
3131

32+
StableProvenance const& OccurrenceForOutput::getStableProvenance(BranchID const& bid) const {
33+
return provRecorder_.principal().getStableProvenance(bid);
34+
}
35+
3236
void OccurrenceForOutput::getAllProvenance(std::vector<Provenance const*>& provenances) const {
3337
provRecorder_.principal().getAllProvenance(provenances);
3438
}

FWCore/Framework/test/stubs/ToyIntProducers.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,13 +458,23 @@ namespace edmtest {
458458
for (auto const& label : labels) {
459459
tokens_.emplace_back(consumes(label));
460460
}
461+
{
462+
auto const& labels = p.getUntrackedParameter<std::vector<edm::InputTag>>("untrackedLabels");
463+
for (auto const& label : labels) {
464+
tokens_.emplace_back(consumes(label));
465+
}
466+
}
461467
}
462468
void produce(edm::StreamID, edm::Event& e, edm::EventSetup const& c) const override;
463469

464470
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
465471
edm::ParameterSetDescription desc;
466472
desc.addUntracked<unsigned int>("onlyGetOnEvent", 0u);
467473
desc.add<std::vector<edm::InputTag>>("labels");
474+
desc.addUntracked<std::vector<edm::InputTag>>("untrackedLabels", {})
475+
->setComment(
476+
"Using this can change the stored ProductRegistry for the same ProcessHistory if this is the only module "
477+
"that depends on these labels.");
468478
descriptions.addDefault(desc);
469479
}
470480

FWCore/Integration/test/BuildFile.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
<test name="TestIntegrationEmptyRootFile" command="run_TestEmptyRootFile.sh"/>
4444
<test name="TestStdProducts" command="cmsRun ${LOCALTOP}/src/FWCore/Integration/test/testStdProducts_cfg.py"/>
4545
<test name="TestPostInsertProducer" command="cmsRun ${LOCALTOP}/src/FWCore/Integration/test/testPostInsertProducer_cfg.py"/>
46+
<test name="TestFWCoreIntegrationProvenance" command ="provenance_test.sh"/>
4647

4748
<bin file="ProcessConfiguration_t.cpp,ProcessHistory_t.cpp" name="TestIntegrationDataFormatsProvenance">
4849
<use name="FWCore/ParameterSet"/>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import FWCore.ParameterSet.Config as cms
2+
3+
process = cms.Process("READ")
4+
5+
from IOPool.Input.modules import PoolSource
6+
7+
process.source = PoolSource(fileNames = ["file:prov.root", "file:prov_extra.root"])
8+
9+
from FWCore.Modules.modules import ProvenanceCheckerOutputModule, AsciiOutputModule
10+
process.out = ProvenanceCheckerOutputModule()
11+
process.prnt = AsciiOutputModule(verbosity = 2, allProvenance=True)
12+
13+
process.e = cms.EndPath(process.out+process.prnt)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import FWCore.ParameterSet.Config as cms
2+
from argparse import ArgumentParser
3+
4+
parser = ArgumentParser(description='Write streamer output file for provenance read test')
5+
parser.add_argument("--consumeProd2", help="add an extra producer to the job and drop on output", action="store_true")
6+
args = parser.parse_args()
7+
8+
9+
process = cms.Process("OUTPUT")
10+
11+
from FWCore.Modules.modules import EmptySource
12+
13+
runNumber = 1
14+
eventNumber = 1
15+
if args.consumeProd2:
16+
eventNumber = 2
17+
18+
process.source = EmptySource(firstRun = runNumber, firstEvent = eventNumber )
19+
20+
from FWCore.Framework.modules import AddIntsProducer, IntProducer
21+
22+
process.one = IntProducer(ivalue=1)
23+
process.two = IntProducer(ivalue=2)
24+
process.sum = AddIntsProducer(labels=['one'])
25+
process.t = cms.Task(process.one, process.two, process.sum)
26+
27+
baseOutFileName = "prov"
28+
if args.consumeProd2 :
29+
process.sum.untrackedLabels = ['two']
30+
baseOutFileName += "_extra"
31+
32+
33+
from IOPool.Output.modules import PoolOutputModule
34+
35+
process.out = PoolOutputModule(fileName = baseOutFileName+".root",
36+
outputCommands = ["drop *", "keep *_sum_*_*"])
37+
38+
from FWCore.Modules.modules import AsciiOutputModule
39+
process.prnt = AsciiOutputModule(verbosity = 2, allProvenance = True)
40+
process.e = cms.EndPath(process.out+process.prnt, process.t)
41+
process.maxEvents.input = 1
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
3+
4+
function die { echo $1: status $2 ; exit $2; }
5+
6+
#The two jobs will have different ProductRegistries in their output files but have the same ProcessHistory.
7+
# The ProductRegistry just differ because the internal dependencies between the data products is different
8+
# and PoolOutputModule only stores provenance of 'dropped' data products IFF they are parents of a kept product.
9+
# The check makes sure the provenance in the ProductRegistry is properly updated when the new file is read
10+
cmsRun ${SCRAM_TEST_PATH}/provenance_prod_cfg.py || die 'Failed in provenance_prod_cfg.py' $?
11+
cmsRun ${SCRAM_TEST_PATH}/provenance_prod_cfg.py --consumeProd2 || die 'Failed in provenance_prod_cfg.py --consumeProd2' $?
12+
cmsRun ${SCRAM_TEST_PATH}/provenance_check_cfg.py || die 'Failed test of provenance' $?

FWCore/Modules/src/AsciiOutputModule.cc

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,16 @@ namespace edm {
3434
int prescale_;
3535
int verbosity_;
3636
int counter_;
37+
bool allProvenance_;
3738
};
3839

3940
AsciiOutputModule::AsciiOutputModule(ParameterSet const& pset)
4041
: global::OutputModuleBase(pset),
4142
global::OutputModule<>(pset),
4243
prescale_(pset.getUntrackedParameter<unsigned int>("prescale")),
4344
verbosity_(pset.getUntrackedParameter<unsigned int>("verbosity")),
44-
counter_(0) {
45+
counter_(0),
46+
allProvenance_(pset.getUntrackedParameter<bool>("allProvenance")) {
4547
if (prescale_ == 0)
4648
prescale_ = 1;
4749
}
@@ -81,6 +83,29 @@ namespace edm {
8183
auto const& prov = e.getProvenance(desc.originalBranchID());
8284
LogAbsolute("AsciiOut") << prov;
8385

86+
if (verbosity_ > 2) {
87+
ProductDescription const& desc2 = prov.productDescription();
88+
std::string const& process = desc2.processName();
89+
std::string const& label = desc2.moduleLabel();
90+
ProcessHistory const& processHistory = e.processHistory();
91+
92+
for (ProcessConfiguration const& pc : processHistory) {
93+
if (pc.processName() == process) {
94+
ParameterSetID const& psetID = pc.parameterSetID();
95+
pset::Registry const* psetRegistry = pset::Registry::instance();
96+
ParameterSet const* processPset = psetRegistry->getMapped(psetID);
97+
if (processPset) {
98+
if (desc.isAlias()) {
99+
LogAbsolute("AsciiOut") << "Alias PSet\n" << processPset->getParameterSet(desc.moduleLabel());
100+
}
101+
LogAbsolute("AsciiOut") << processPset->getParameterSet(label) << "\n";
102+
}
103+
}
104+
}
105+
}
106+
} else if (allProvenance_) {
107+
auto const& prov = e.getStableProvenance(desc.originalBranchID());
108+
LogAbsolute("AsciiOut") << prov;
84109
if (verbosity_ > 2) {
85110
ProductDescription const& desc2 = prov.productDescription();
86111
std::string const& process = desc2.processName();
@@ -115,6 +140,8 @@ namespace edm {
115140
"1: event ID and timestamp only\n"
116141
"2: provenance for each kept product\n"
117142
">2: PSet and provenance for each kept product");
143+
desc.addUntracked("allProvenance", false)
144+
->setComment("when printing provenance info, also print stable provenance of non-kept data products.");
118145
OutputModule::fillDescription(desc);
119146
descriptions.add("asciiOutput", desc);
120147
}

0 commit comments

Comments
 (0)