Skip to content

Commit 893970c

Browse files
committed
edmRNTupleTempFileUtil now complete
1 parent b9c4d2c commit 893970c

File tree

2 files changed

+55
-166
lines changed

2 files changed

+55
-166
lines changed

FWIO/RNTupleTempInput/bin/CollUtil.cc

Lines changed: 47 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "TTree.h"
1818
#include "ROOT/RNTupleReader.hxx"
1919
#include "ROOT/RNTupleDescriptor.hxx"
20+
#include "ROOT/RNTuple.hxx"
2021

2122
#include <iomanip>
2223
#include <iostream>
@@ -52,13 +53,19 @@ namespace edm::rntuple_temp {
5253

5354
// number of entries in a tree
5455
Long64_t numEntries(TFile *hdl, std::string const &trname) {
55-
TTree *tree = (TTree *)hdl->Get(trname.c_str());
56-
if (tree) {
57-
return tree->GetEntries();
56+
auto tuple = hdl->Get<ROOT::RNTuple>(trname.c_str());
57+
if (tuple) {
58+
auto reader = ROOT::RNTupleReader::Open(*tuple);
59+
return reader->GetNEntries();
5860
} else {
59-
std::cout << "ERR cannot find a TTree named \"" << trname << "\"" << std::endl;
60-
return -1;
61+
// Try as a TTree
62+
TTree *tree = (TTree *)hdl->Get(trname.c_str());
63+
if (tree) {
64+
return tree->GetEntries();
65+
}
6166
}
67+
std::cout << "ERR cannot find a RNTuple named \"" << trname << "\"" << std::endl;
68+
return -1;
6269
}
6370

6471
namespace {
@@ -344,75 +351,31 @@ namespace edm::rntuple_temp {
344351

345352
void printUuids(ROOT::RNTupleReader *uuidTree) { std::cout << "UUID: " << getUuid(uuidTree) << std::endl; }
346353

347-
static void preIndexIntoFilePrintEventLists(TFile *,
348-
FileFormatVersion const &fileFormatVersion,
349-
TTree *metaDataTree) {
350-
FileIndex fileIndex;
351-
FileIndex *findexPtr = &fileIndex;
352-
if (metaDataTree->FindBranch(poolNames::fileIndexBranchName().c_str()) != nullptr) {
353-
TBranch *fndx = metaDataTree->GetBranch(poolNames::fileIndexBranchName().c_str());
354-
fndx->SetAddress(&findexPtr);
355-
fndx->GetEntry(0);
356-
} else {
357-
std::cout << "FileIndex not found. If this input file was created with release 1_8_0 or later\n"
358-
"this indicates a problem with the file. This condition should be expected with\n"
359-
"files created with earlier releases and printout of the event list will fail.\n";
354+
static void postIndexIntoFilePrintEventLists(TFile *tfl, ROOT::RNTupleReader &metaDataReader) {
355+
if (metaDataReader.GetModel().GetFieldNames().find(poolNames::indexIntoFileBranchName()) ==
356+
metaDataReader.GetModel().GetFieldNames().end()) {
357+
std::cout << "IndexIntoFile not found this indicates a problem with the file.";
360358
return;
361359
}
362-
363-
std::cout << "\n" << fileIndex;
364-
365-
std::cout << "\nFileFormatVersion = " << fileFormatVersion << ". ";
366-
if (fileFormatVersion.fastCopyPossible())
367-
std::cout << "This version supports fast copy\n";
368-
else
369-
std::cout << "This version does not support fast copy\n";
370-
371-
if (fileIndex.allEventsInEntryOrder()) {
372-
std::cout << "Events are sorted such that fast copy is possible in the \"noEventSort = False\" mode\n";
373-
} else {
374-
std::cout << "Events are sorted such that fast copy is NOT possible in the \"noEventSort = False\" mode\n";
375-
}
376-
377-
fileIndex.sortBy_Run_Lumi_EventEntry();
378-
if (fileIndex.allEventsInEntryOrder()) {
379-
std::cout << "Events are sorted such that fast copy is possible in the \"noEventSort\" mode\n";
380-
} else {
381-
std::cout << "Events are sorted such that fast copy is NOT possible in the \"noEventSort\" mode\n";
382-
}
383-
std::cout << "(Note that other factors can prevent fast copy from occurring)\n\n";
384-
}
385-
386-
static void postIndexIntoFilePrintEventLists(TFile *tfl,
387-
FileFormatVersion const &fileFormatVersion,
388-
TTree *metaDataTree) {
389360
IndexIntoFile indexIntoFile;
390-
IndexIntoFile *findexPtr = &indexIntoFile;
391-
if (metaDataTree->FindBranch(poolNames::indexIntoFileBranchName().c_str()) != nullptr) {
392-
TBranch *fndx = metaDataTree->GetBranch(poolNames::indexIntoFileBranchName().c_str());
393-
fndx->SetAddress(&findexPtr);
394-
fndx->GetEntry(0);
395-
} else {
396-
std::cout << "IndexIntoFile not found. If this input file was created with release 1_8_0 or later\n"
397-
"this indicates a problem with the file. This condition should be expected with\n"
398-
"files created with earlier releases and printout of the event list will fail.\n";
399-
return;
400-
}
361+
auto metaDataEntry = metaDataReader.GetModel().CreateEntry();
362+
metaDataEntry->BindRawPtr(poolNames::indexIntoFileBranchName(), &indexIntoFile);
363+
metaDataReader.LoadEntry(0, *metaDataEntry);
364+
401365
//need to read event # from the EventAuxiliary branch
402-
TTree *eventsTree = dynamic_cast<TTree *>(tfl->Get(poolNames::eventTreeName().c_str()));
403-
TBranch *eventAuxBranch = nullptr;
404-
assert(nullptr != eventsTree);
405-
char const *const kEventAuxiliaryBranchName = "EventAuxiliary";
406-
if (eventsTree->FindBranch(kEventAuxiliaryBranchName) != nullptr) {
407-
eventAuxBranch = eventsTree->GetBranch(kEventAuxiliaryBranchName);
408-
} else {
409-
std::cout << "Failed to find " << kEventAuxiliaryBranchName
410-
<< " branch in Events TTree. Something is wrong with this file." << std::endl;
366+
auto *eventsTuple = tfl->Get<ROOT::RNTuple>(poolNames::eventTreeName().c_str());
367+
assert(nullptr != eventsTuple);
368+
auto eventsReader = ROOT::RNTupleReader::Open(*eventsTuple);
369+
if (eventsReader->GetModel().GetFieldNames().find("EventAuxiliary") ==
370+
eventsReader->GetModel().GetFieldNames().end()) {
371+
std::cout << "Failed to find EventAuxiliary Field in Events RNTuple. Something is wrong with this file."
372+
<< std::endl;
411373
return;
412374
}
375+
413376
EventAuxiliary eventAuxiliary;
414-
EventAuxiliary *eAPtr = &eventAuxiliary;
415-
eventAuxBranch->SetAddress(&eAPtr);
377+
auto eventAuxEntry = eventsReader->GetModel().CreateEntry();
378+
eventAuxEntry->BindRawPtr("EventAuxiliary", &eventAuxiliary);
416379
std::cout << "\nPrinting IndexIntoFile contents. This includes a list of all Runs, LuminosityBlocks\n"
417380
<< "and Events stored in the root file.\n\n";
418381
std::cout << std::setw(15) << "Run" << std::setw(15) << "Lumi" << std::setw(15) << "Event" << std::setw(15)
@@ -435,7 +398,7 @@ namespace edm::rntuple_temp {
435398
type = "(Lumi)";
436399
break;
437400
case IndexIntoFile::kEvent:
438-
eventAuxBranch->GetEntry(it.entry());
401+
eventsReader->LoadEntry(it.entry(), *eventAuxEntry);
439402
eventNum = eventAuxiliary.id().event();
440403
break;
441404
default:
@@ -444,12 +407,6 @@ namespace edm::rntuple_temp {
444407
std::cout << std::setw(15) << eventNum << std::setw(15) << it.entry() << " " << type << std::endl;
445408
}
446409

447-
std::cout << "\nFileFormatVersion = " << fileFormatVersion << ". ";
448-
if (fileFormatVersion.fastCopyPossible())
449-
std::cout << "This version supports fast copy\n";
450-
else
451-
std::cout << "This version does not support fast copy\n";
452-
453410
if (indexIntoFile.iterationWillBeInEntryOrder(IndexIntoFile::firstAppearanceOrder)) {
454411
std::cout << "Events are sorted such that fast copy is possible in the \"noEventSort = false\" mode\n";
455412
} else {
@@ -467,79 +424,21 @@ namespace edm::rntuple_temp {
467424
}
468425

469426
void printEventLists(TFile *tfl) {
470-
TTree *metaDataTree = dynamic_cast<TTree *>(tfl->Get(poolNames::metaDataTreeName().c_str()));
471-
assert(nullptr != metaDataTree);
472-
473-
FileFormatVersion fileFormatVersion;
474-
FileFormatVersion *fftPtr = &fileFormatVersion;
475-
if (metaDataTree->FindBranch(poolNames::fileFormatVersionBranchName().c_str()) != nullptr) {
476-
TBranch *fft = metaDataTree->GetBranch(poolNames::fileFormatVersionBranchName().c_str());
477-
fft->SetAddress(&fftPtr);
478-
fft->GetEntry(0);
479-
}
480-
if (fileFormatVersion.hasIndexIntoFile()) {
481-
postIndexIntoFilePrintEventLists(tfl, fileFormatVersion, metaDataTree);
482-
} else {
483-
preIndexIntoFilePrintEventLists(tfl, fileFormatVersion, metaDataTree);
484-
}
485-
}
427+
auto metaDataTuple = tfl->Get<ROOT::RNTuple>(edm::poolNames::metaDataTreeName().c_str());
428+
assert(nullptr != metaDataTuple);
429+
auto reader = ROOT::RNTupleReader::Open(*metaDataTuple);
486430

487-
static void preIndexIntoFilePrintEventsInLumis(TFile *,
488-
FileFormatVersion const &fileFormatVersion,
489-
TTree *metaDataTree) {
490-
FileIndex fileIndex;
491-
FileIndex *findexPtr = &fileIndex;
492-
if (metaDataTree->FindBranch(poolNames::fileIndexBranchName().c_str()) != nullptr) {
493-
TBranch *fndx = metaDataTree->GetBranch(poolNames::fileIndexBranchName().c_str());
494-
fndx->SetAddress(&findexPtr);
495-
fndx->GetEntry(0);
496-
} else {
497-
std::cout << "FileIndex not found. If this input file was created with release 1_8_0 or later\n"
498-
"this indicates a problem with the file. This condition should be expected with\n"
499-
"files created with earlier releases and printout of the event list will fail.\n";
500-
return;
501-
}
502-
503-
std::cout << "\n"
504-
<< std::setw(15) << "Run" << std::setw(15) << "Lumi" << std::setw(15) << "# Events"
505-
<< "\n";
506-
unsigned long nEvents = 0;
507-
unsigned long runID = 0;
508-
unsigned long lumiID = 0;
509-
for (std::vector<FileIndex::Element>::const_iterator it = fileIndex.begin(), itEnd = fileIndex.end(); it != itEnd;
510-
++it) {
511-
if (it->getEntryType() == FileIndex::kEvent) {
512-
++nEvents;
513-
} else if (it->getEntryType() == FileIndex::kLumi) {
514-
if (runID != it->run_ || lumiID != it->lumi_) {
515-
//print the previous one
516-
if (lumiID != 0) {
517-
std::cout << std::setw(15) << runID << std::setw(15) << lumiID << std::setw(15) << nEvents << "\n";
518-
}
519-
nEvents = 0;
520-
runID = it->run_;
521-
lumiID = it->lumi_;
522-
}
523-
}
524-
}
525-
//print the last one
526-
if (lumiID != 0) {
527-
std::cout << std::setw(15) << runID << std::setw(15) << lumiID << std::setw(15) << nEvents << "\n";
528-
}
529-
530-
std::cout << "\n";
431+
postIndexIntoFilePrintEventLists(tfl, *reader);
531432
}
532433

533-
static void postIndexIntoFilePrintEventsInLumis(TFile *tfl,
534-
FileFormatVersion const &fileFormatVersion,
535-
TTree *metaDataTree) {
434+
static void postIndexIntoFilePrintEventsInLumis(ROOT::RNTupleReader &metaDataReader) {
536435
IndexIntoFile indexIntoFile;
537-
IndexIntoFile *findexPtr = &indexIntoFile;
538-
if (metaDataTree->FindBranch(poolNames::indexIntoFileBranchName().c_str()) != nullptr) {
539-
TBranch *fndx = metaDataTree->GetBranch(poolNames::indexIntoFileBranchName().c_str());
540-
fndx->SetAddress(&findexPtr);
541-
fndx->GetEntry(0);
542-
} else {
436+
auto metaDataEntry = metaDataReader.GetModel().CreateEntry();
437+
metaDataEntry->BindRawPtr(poolNames::indexIntoFileBranchName(), &indexIntoFile);
438+
metaDataReader.LoadEntry(0, *metaDataEntry);
439+
440+
if (metaDataReader.GetModel().GetFieldNames().find(poolNames::indexIntoFileBranchName()) ==
441+
metaDataReader.GetModel().GetFieldNames().end()) {
543442
std::cout << "IndexIntoFile not found. If this input file was created with release 1_8_0 or later\n"
544443
"this indicates a problem with the file. This condition should be expected with\n"
545444
"files created with earlier releases and printout of the event list will fail.\n";
@@ -587,20 +486,10 @@ namespace edm::rntuple_temp {
587486
}
588487

589488
void printEventsInLumis(TFile *tfl) {
590-
TTree *metaDataTree = dynamic_cast<TTree *>(tfl->Get(poolNames::metaDataTreeName().c_str()));
591-
assert(nullptr != metaDataTree);
592-
593-
FileFormatVersion fileFormatVersion;
594-
FileFormatVersion *fftPtr = &fileFormatVersion;
595-
if (metaDataTree->FindBranch(poolNames::fileFormatVersionBranchName().c_str()) != nullptr) {
596-
TBranch *fft = metaDataTree->GetBranch(poolNames::fileFormatVersionBranchName().c_str());
597-
fft->SetAddress(&fftPtr);
598-
fft->GetEntry(0);
599-
}
600-
if (fileFormatVersion.hasIndexIntoFile()) {
601-
postIndexIntoFilePrintEventsInLumis(tfl, fileFormatVersion, metaDataTree);
602-
} else {
603-
preIndexIntoFilePrintEventsInLumis(tfl, fileFormatVersion, metaDataTree);
604-
}
489+
auto metaDataTuple = tfl->Get<ROOT::RNTuple>(edm::poolNames::metaDataTreeName().c_str());
490+
assert(nullptr != metaDataTuple);
491+
auto reader = ROOT::RNTupleReader::Open(*metaDataTuple);
492+
493+
postIndexIntoFilePrintEventsInLumis(*reader);
605494
}
606495
} // namespace edm::rntuple_temp

FWIO/RNTupleTempInput/bin/EdmRNTupleTempFileUtil.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ int main(int argc, char* argv[]) {
5858
"eventsInLumis", "Print how many Events are in each LuminosityBlock.");
5959

6060
// What trees do we require for this to be a valid collection?
61-
std::vector<std::string> expectedTrees;
62-
expectedTrees.push_back(edm::poolNames::metaDataTreeName());
63-
expectedTrees.push_back(edm::poolNames::eventTreeName());
61+
std::vector<std::string> expectedRNTuples;
62+
expectedRNTuples.push_back(edm::poolNames::metaDataTreeName());
63+
expectedRNTuples.push_back(edm::poolNames::eventTreeName());
6464

6565
boost::program_options::positional_options_description p;
6666
p.add("file", -1);
@@ -187,20 +187,20 @@ int main(int argc, char* argv[]) {
187187
}
188188

189189
// Ok. Do we have the expected trees?
190-
for (unsigned int i = 0; i < expectedTrees.size(); ++i) {
191-
TTree* t = (TTree*)tfile->Get(expectedTrees[i].c_str());
190+
for (unsigned int i = 0; i < expectedRNTuples.size(); ++i) {
191+
auto* t = tfile->Get<ROOT::RNTuple>(expectedRNTuples[i].c_str());
192192
if (t == nullptr) {
193-
std::cout << "Tree " << expectedTrees[i] << " appears to be missing. Not a valid collection\n";
193+
std::cout << "RNTuple " << expectedRNTuples[i] << " appears to be missing. Not a valid collection\n";
194194
std::cout << "Exiting\n";
195195
return 1;
196196
} else {
197197
if (verbose)
198-
std::cout << "ECU:: Found Tree " << expectedTrees[i] << std::endl;
198+
std::cout << "ECU:: Found RNTuple " << expectedRNTuples[i] << std::endl;
199199
}
200200
}
201201

202202
if (verbose)
203-
std::cout << "ECU:: Found all expected trees\n";
203+
std::cout << "ECU:: Found all expected RNTuples\n";
204204

205205
std::ostringstream auout;
206206
if (adler32) {

0 commit comments

Comments
 (0)