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

Add enforceGUIDInFileName option to PoolSource and EmbeddedRootSource #28561

Merged
merged 7 commits into from
Dec 7, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 2 additions & 1 deletion FWCore/Framework/python/test/cmsExceptionsFatalOption_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@
'ProductDoesNotSupportViews',
'ProductDoesNotSupportPtr',
'NotFound',
'FormatIncompatibility'
'FormatIncompatibility',
'FileNameInconsistentWithGUID',
)
5 changes: 3 additions & 2 deletions FWCore/Utilities/interface/EDMException.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ namespace edm {
namespace errors {

// If you add a new entry to the set of values, make sure to
// update the translation map in EDMException.cc, the actions
// table in FWCore/Framework/src/Actions.cc, and the configuration
makortel marked this conversation as resolved.
Show resolved Hide resolved
// update the translation map in EDMException.cc, and the configuration
// fragment FWCore/Framework/python/test/cmsExceptionsFatalOption_cff.py.

enum ErrorCodes {
Expand Down Expand Up @@ -66,6 +65,8 @@ namespace edm {

FileWriteError = 8033,

FileNameInconsistentWithGUID = 8034,

EventGenerationFailure = 8501,

CaughtSignal = 9000
Expand Down
1 change: 1 addition & 0 deletions FWCore/Utilities/src/EDMException.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ namespace edm {
FILLENTRY(ExceededResourceRSS),
FILLENTRY(ExceededResourceTime),
FILLENTRY(FileWriteError),
FILLENTRY(FileNameInconsistentWithGUID),
FILLENTRY(EventGenerationFailure),
FILLENTRY(CaughtSignal)};
static const std::string kUnknownCode("unknownCode");
Expand Down
10 changes: 8 additions & 2 deletions IOPool/Input/src/RootEmbeddedFileSequence.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ namespace edm {
// and should be deleted from the code.
initialNumberOfEventsToSkip_(pset.getUntrackedParameter<unsigned int>("skipEvents", 0U)),
treeCacheSize_(pset.getUntrackedParameter<unsigned int>("cacheSize", roottree::defaultCacheSize)),
enablePrefetching_(false) {
enablePrefetching_(false),
enforceGUIDInFileName_(pset.getUntrackedParameter<bool>("enforceGUIDInFileName", false)) {
if (noFiles()) {
throw Exception(errors::NoSecondaryFiles)
<< "RootEmbeddedFileSequence no input files specified for secondary input source.\n";
Expand Down Expand Up @@ -138,7 +139,8 @@ namespace edm {
currentIndexIntoFile,
orderedProcessHistoryIDs_,
input_.bypassVersionCheck(),
enablePrefetching_);
enablePrefetching_,
enforceGUIDInFileName_);
}

void RootEmbeddedFileSequence::skipEntries(unsigned int offset) {
Expand Down Expand Up @@ -336,5 +338,9 @@ namespace edm {
"Skip the first 'skipEvents' events. Used only if 'sequential' is True and 'sameLumiBlock' is False");
desc.addUntracked<unsigned int>("cacheSize", roottree::defaultCacheSize)
->setComment("Size of ROOT TTree prefetch cache. Affects performance.");
desc.addUntracked<bool>("enforceGUIDInFileName", false)
->setComment(
"True: file name part is required to be equal to the GUID of the file\n"
"False: file name can be anything");
}
} // namespace edm
1 change: 1 addition & 0 deletions IOPool/Input/src/RootEmbeddedFileSequence.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ namespace edm {
int initialNumberOfEventsToSkip_;
unsigned int treeCacheSize_;
bool enablePrefetching_;
bool enforceGUIDInFileName_;
}; // class RootEmbeddedFileSequence
} // namespace edm
#endif
25 changes: 24 additions & 1 deletion IOPool/Input/src/RootFile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ namespace edm {
bool bypassVersionCheck,
bool labelRawDataLikeMC,
bool usingGoToEvent,
bool enablePrefetching)
bool enablePrefetching,
bool enforceGUIDInFileName)
: file_(fileName),
logicalFile_(logicalFileName),
processConfiguration_(processConfiguration),
Expand All @@ -187,6 +188,7 @@ namespace edm {
savedRunAuxiliary_(),
skipAnyEvents_(skipAnyEvents),
noEventSort_(noEventSort),
enforceGUIDInFileName_(enforceGUIDInFileName),
whyNotFastClonable_(0),
hasNewlyDroppedBranch_(),
branchListIndexesUnchanged_(false),
Expand Down Expand Up @@ -1139,6 +1141,27 @@ namespace edm {
throw Exception(errors::EventCorruption) << "'Events' tree is corrupted or not present\n"
<< "in the input file.\n";
}
if (enforceGUIDInFileName_) {
auto begin = file_.rfind("/");
if (begin == std::string::npos) {
begin = file_.rfind(":");
if (begin == std::string::npos) {
// shouldn't really happen?
begin = 0;
} else {
begin += 1;
}
} else {
begin += 1;
}
auto end = file_.find(".", begin);
auto guidFromName = std::string_view(file_).substr(begin, end - begin);
if (guidFromName != fid_.fid()) {
throw edm::Exception(edm::errors::FileNameInconsistentWithGUID)
<< "GUID " << guidFromName << " extracted from file name " << file_
<< " is inconsistent with the GUID read from the file " << fid_.fid();
}
}

if (fileFormatVersion().hasIndexIntoFile()) {
if (runTree().entries() > 0) {
Expand Down
16 changes: 11 additions & 5 deletions IOPool/Input/src/RootFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ namespace edm {
bool bypassVersionCheck,
bool labelRawDataLikeMC,
bool usingGoToEvent,
bool enablePrefetching);
bool enablePrefetching,
bool enforceGUIDInFileName);

RootFile(std::string const& fileName,
ProcessConfiguration const& processConfiguration,
Expand All @@ -113,7 +114,8 @@ namespace edm {
std::vector<ProcessHistoryID>& orderedProcessHistoryIDs,
bool bypassVersionCheck,
bool labelRawDataLikeMC,
bool enablePrefetching)
bool enablePrefetching,
bool enforceGUIDInFileName)
: RootFile(fileName,
processConfiguration,
logicalFileName,
Expand Down Expand Up @@ -142,7 +144,8 @@ namespace edm {
bypassVersionCheck,
labelRawDataLikeMC,
false,
enablePrefetching) {}
enablePrefetching,
enforceGUIDInFileName) {}

RootFile(std::string const& fileName,
ProcessConfiguration const& processConfiguration,
Expand All @@ -159,7 +162,8 @@ namespace edm {
std::vector<std::shared_ptr<IndexIntoFile>>::size_type currentIndexIntoFile,
std::vector<ProcessHistoryID>& orderedProcessHistoryIDs,
bool bypassVersionCheck,
bool enablePrefetching)
bool enablePrefetching,
bool enforceGUIDInFileName)
: RootFile(fileName,
processConfiguration,
logicalFileName,
Expand Down Expand Up @@ -188,7 +192,8 @@ namespace edm {
bypassVersionCheck,
false,
false,
enablePrefetching) {}
enablePrefetching,
enforceGUIDInFileName) {}

~RootFile();

Expand Down Expand Up @@ -325,6 +330,7 @@ namespace edm {
edm::propagate_const<std::shared_ptr<RunAuxiliary>> savedRunAuxiliary_;
bool skipAnyEvents_;
bool noEventSort_;
bool enforceGUIDInFileName_;
int whyNotFastClonable_;
std::array<bool, NumBranchTypes> hasNewlyDroppedBranch_;
bool branchListIndexesUnchanged_;
Expand Down
10 changes: 8 additions & 2 deletions IOPool/Input/src/RootPrimaryFileSequence.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ namespace edm {
treeCacheSize_(noEventSort_ ? pset.getUntrackedParameter<unsigned int>("cacheSize") : 0U),
duplicateChecker_(new DuplicateChecker(pset)),
usingGoToEvent_(false),
enablePrefetching_(false) {
enablePrefetching_(false),
enforceGUIDInFileName_(pset.getUntrackedParameter<bool>("enforceGUIDInFileName")) {
// The SiteLocalConfig controls the TTreeCache size and the prefetching settings.
Service<SiteLocalConfig> pSLC;
if (pSLC.isAvailable()) {
Expand Down Expand Up @@ -137,7 +138,8 @@ namespace edm {
input_.bypassVersionCheck(),
input_.labelRawDataLikeMC(),
usingGoToEvent_,
enablePrefetching_);
enablePrefetching_,
enforceGUIDInFileName_);
}

bool RootPrimaryFileSequence::nextFile() {
Expand Down Expand Up @@ -322,6 +324,10 @@ namespace edm {
->setComment(
"'strict': Branches in each input file must match those in the first file.\n"
"'permissive': Branches in each input file may be any subset of those in the first file.");
desc.addUntracked<bool>("enforceGUIDInFileName", false)
->setComment(
"True: file name part is required to be equal to the GUID of the file\n"
"False: file name can be anything");

EventSkipperByID::fillDescription(desc);
DuplicateChecker::fillDescription(desc);
Expand Down
1 change: 1 addition & 0 deletions IOPool/Input/src/RootPrimaryFileSequence.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ namespace edm {
edm::propagate_const<std::shared_ptr<DuplicateChecker>> duplicateChecker_;
bool usingGoToEvent_;
bool enablePrefetching_;
bool enforceGUIDInFileName_;
}; // class RootPrimaryFileSequence
} // namespace edm
#endif
9 changes: 7 additions & 2 deletions IOPool/Input/src/RootSecondaryFileSequence.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ namespace edm {
RootSecondaryFileSequence::RootSecondaryFileSequence(ParameterSet const& pset,
PoolSource& input,
InputFileCatalog const& catalog)
: RootInputFileSequence(pset, catalog), input_(input), orderedProcessHistoryIDs_(), enablePrefetching_(false) {
: RootInputFileSequence(pset, catalog),
input_(input),
orderedProcessHistoryIDs_(),
enablePrefetching_(false),
enforceGUIDInFileName_(pset.getUntrackedParameter<bool>("enforceGUIDInFileName")) {
// The SiteLocalConfig controls the TTreeCache size and the prefetching settings.
Service<SiteLocalConfig> pSLC;
if (pSLC.isAvailable()) {
Expand Down Expand Up @@ -85,7 +89,8 @@ namespace edm {
orderedProcessHistoryIDs_,
input_.bypassVersionCheck(),
input_.labelRawDataLikeMC(),
enablePrefetching_);
enablePrefetching_,
enforceGUIDInFileName_);
}

void RootSecondaryFileSequence::initAssociationsFromSecondary(std::set<BranchID> const& associationsFromSecondary) {
Expand Down
1 change: 1 addition & 0 deletions IOPool/Input/src/RootSecondaryFileSequence.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ namespace edm {
std::vector<BranchID> associationsFromSecondary_;
std::vector<ProcessHistoryID> orderedProcessHistoryIDs_;
bool enablePrefetching_;
bool enforceGUIDInFileName_;
}; // class RootSecondaryFileSequence
} // namespace edm
#endif
31 changes: 31 additions & 0 deletions IOPool/Input/test/PoolGUIDTest_cfg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Configuration file for PoolInputTest

import FWCore.ParameterSet.Config as cms
import sys

argv = []
foundpy = False
for a in sys.argv:
if foundpy:
argv.append(a)
if ".py" in a:
foundpy = True

process = cms.Process("TESTRECO")
process.load("FWCore.Framework.test.cmsExceptionsFatal_cff")

process.maxEvents = cms.untracked.PSet(
makortel marked this conversation as resolved.
Show resolved Hide resolved
input = cms.untracked.int32(-1)
)
process.OtherThing = cms.EDProducer("OtherThingProducer")
process.Analysis = cms.EDAnalyzer("OtherThingAnalyzer")

process.source = cms.Source("PoolSource",
setRunNumber = cms.untracked.uint32(621),
fileNames = cms.untracked.vstring(argv[0]),
enforceGUIDInFileName = cms.untracked.bool(True)
)

process.p = cms.Path(process.OtherThing*process.Analysis)


22 changes: 15 additions & 7 deletions IOPool/Input/test/PrePoolInputTest_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,34 @@
# Configuration file for PrePoolInputTest

import FWCore.ParameterSet.Config as cms
from sys import argv
import sys

argv = []
foundpy = False
for a in sys.argv:
if foundpy:
argv.append(a)
if ".py" in a:
foundpy = True

process = cms.Process("TESTPROD")
process.load("FWCore.Framework.test.cmsExceptionsFatal_cff")

process.maxEvents = cms.untracked.PSet(
input = cms.untracked.int32(int(argv[3]))
input = cms.untracked.int32(int(argv[1]))
)

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

process.output = cms.OutputModule("PoolOutputModule",
fileName = cms.untracked.string(argv[2])
fileName = cms.untracked.string(argv[0])
)

process.source = cms.Source("EmptySource",
firstRun = cms.untracked.uint32(int(argv[4])),
numberEventsInRun = cms.untracked.uint32(int(argv[5])),
firstLuminosityBlock = cms.untracked.uint32(int(argv[6])),
numberEventsInLuminosityBlock = cms.untracked.uint32(int(argv[7]))
firstRun = cms.untracked.uint32(int(argv[2])),
numberEventsInRun = cms.untracked.uint32(int(argv[3])),
firstLuminosityBlock = cms.untracked.uint32(int(argv[4])),
numberEventsInLuminosityBlock = cms.untracked.uint32(int(argv[5]))
)

process.p = cms.Path(process.Thing)
Expand Down
8 changes: 7 additions & 1 deletion IOPool/Input/test/TestPoolInput.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ function die { echo $1: status $2 ; exit $2; }

pushd ${LOCAL_TMP_DIR}

cmsRun ${LOCAL_TEST_DIR}/PrePoolInputTest_cfg.py PoolInputTest.root 11 561 7 6 3 || die 'Failure using PrePoolInputTest_cfg.py' $?
cmsRun -j PoolInputTest_jobreport.xml ${LOCAL_TEST_DIR}/PrePoolInputTest_cfg.py PoolInputTest.root 11 561 7 6 3 || die 'Failure using PrePoolInputTest_cfg.py' $?

cmsRun ${LOCAL_TEST_DIR}/PoolGUIDTest_cfg.py file:PoolInputTest.root && die 'PoolGUIDTest_cfg.py PoolInputTest.root did not throw an exception' 1
GUID_NAME=$(fgrep GUID PoolInputTest_jobreport.xml | sed -E 's/<.?GUID>//g').root
cp PoolInputTest.root ${GUID_NAME}
cmsRun ${LOCAL_TEST_DIR}/PoolGUIDTest_cfg.py file:${GUID_NAME} || die 'Failure using PoolGUIDTest_cfg.py ${GUID_NAME}' $?


cp PoolInputTest.root PoolInputOther.root

Expand Down