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

Throw on missing file in ChainEvent, revive unit tests that would have caught this #33550

Merged
merged 3 commits into from Apr 29, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions DataFormats/FWLite/src/ChainEvent.cc
Expand Up @@ -40,6 +40,9 @@ namespace fwlite {

for (auto const& fileName : iFileNames) {
TFile* tfilePtr = TFile::Open(fileName.c_str());
if (nullptr == tfilePtr) {
throw cms::Exception("FileOpenFailed") << "TFile::Open of " << fileName << " failed";
}
file_ = std::shared_ptr<TFile>(tfilePtr);
gROOT->GetListOfFiles()->Remove(tfilePtr);
TTree* tree = dynamic_cast<TTree*>(file_->Get(edm::poolNames::eventTreeName().c_str()));
Expand Down
69 changes: 27 additions & 42 deletions DataFormats/FWLite/test/test.cppunit.cpp
Expand Up @@ -34,6 +34,7 @@ class testRefInROOT : public CppUnit::TestFixture {

CPPUNIT_TEST(testOneGoodFile);
CPPUNIT_TEST_EXCEPTION(failOneBadFile, std::exception);
CPPUNIT_TEST_EXCEPTION(failChainWithMissingFile, std::exception);
CPPUNIT_TEST(testRefFirst);
CPPUNIT_TEST(testAllLabels);
CPPUNIT_TEST(testGoodChain);
Expand All @@ -46,7 +47,6 @@ class testRefInROOT : public CppUnit::TestFixture {
CPPUNIT_TEST(testTo);
CPPUNIT_TEST(testThinning);

// CPPUNIT_TEST_EXCEPTION(failChainWithMissingFile,std::exception);
//failTwoDifferentFiles
//CPPUNIT_TEST_EXCEPTION(failDidNotCallGetEntryForEvents,std::exception);

Expand Down Expand Up @@ -75,7 +75,7 @@ class testRefInROOT : public CppUnit::TestFixture {
void testEventBase();
void testSometimesMissingData();
void testTo();
// void failChainWithMissingFile();
void failChainWithMissingFile();
//void failDidNotCallGetEntryForEvents();
void testThinning();

Expand Down Expand Up @@ -339,51 +339,36 @@ void testRefInROOT::testTwoGoodFiles() {
}

void testRefInROOT::testGoodChain() {
/*
TChain eventChain(edm::poolNames::eventTreeName());
eventChain.Add((tmpdir + "goodDataFormatsFWLite.root").c_str());
eventChain.Add((tmpdir + "good2DataFormatsFWLite.root").c_str());
std::vector<std::string> files{(tmpdir + "goodDataFormatsFWLite.root").c_str(),
(tmpdir + "good2DataFormatsFWLite.root").c_str()};
dan131riley marked this conversation as resolved.
Show resolved Hide resolved
fwlite::ChainEvent events(files);

edm::Wrapper<edmtest::OtherThingCollection> *pOthers = nullptr;
eventChain.SetBranchAddress("edmtestOtherThings_OtherThing_testUserTag_TEST.",&pOthers);

edm::Wrapper<edmtest::ThingCollection>* pThings = nullptr;
eventChain.SetBranchAddress("edmtestThings_Thing__TEST.",&pThings);

int nev = eventChain.GetEntries();
for( int ev=0; ev<nev; ++ev) {
std::cout <<"event #" <<ev<<std::endl;
eventChain.GetEntry(ev);
CPPUNIT_ASSERT(pOthers != nullptr);
CPPUNIT_ASSERT(pThings != nullptr);
checkMatch(pOthers->product(),pThings->product());
for (events.toBegin(); not events.atEnd(); ++events) {
fwlite::Handle<edmtest::ThingCollection> pThings;
pThings.getByLabel(events, "Thing");

fwlite::Handle<edmtest::OtherThingCollection> pOthers;
pOthers.getByLabel(events, "OtherThing", "testUserTag");

checkMatch(pOthers.ptr(), pThings.ptr());
}
*/
}
/*
void testRefInROOT::failChainWithMissingFile()
{
TChain eventChain(edm::poolNames::eventTreeName());
eventChain.Add((tmpdir + "goodDataFormatsFWLite.root").c_str());
eventChain.Add("thisFileDoesNotExist.root");

edm::Wrapper<edmtest::OtherThingCollection> *pOthers = nullptr;
eventChain.SetBranchAddress("edmtestOtherThings_OtherThing_testUserTag_TEST.",&pOthers);

edm::Wrapper<edmtest::ThingCollection>* pThings = nullptr;
eventChain.SetBranchAddress("edmtestThings_Thing__TEST.",&pThings);

int nev = eventChain.GetEntries();
for( int ev=0; ev<nev; ++ev) {
std::cout <<"event #" <<ev<<std::endl;
eventChain.GetEntry(ev);
CPPUNIT_ASSERT(pOthers != nullptr);
CPPUNIT_ASSERT(pThings != nullptr);
checkMatch(pOthers->product(),pThings->product());

void testRefInROOT::failChainWithMissingFile() {
std::vector<std::string> files{(tmpdir + "goodDataFormatsFWLite.root").c_str(),
(tmpdir + "2ndFileDoesNotExist.root").c_str()};
dan131riley marked this conversation as resolved.
Show resolved Hide resolved
fwlite::ChainEvent events(files);

for (events.toBegin(); not events.atEnd(); ++events) {
fwlite::Handle<edmtest::ThingCollection> pThings;
pThings.getByLabel(events, "Thing");

fwlite::Handle<edmtest::OtherThingCollection> pOthers;
pOthers.getByLabel(events, "OtherThing", "testUserTag");

checkMatch(pOthers.ptr(), pThings.ptr());
}

}
*/

void testRefInROOT::testThinning() {
std::vector<std::string> files{(tmpdir + "goodDataFormatsFWLite.root").c_str(),
Expand Down