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 << " \n FileFormatVersion = " << 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 << " \n Printing 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 << " \n FileFormatVersion = " << 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
0 commit comments