Skip to content

Commit 4ca6c13

Browse files
committed
Move input to only use RNTuple
1 parent 556a6fb commit 4ca6c13

16 files changed

+179
-376
lines changed

FWIO/RNTupleTempInput/src/RootDelayedReader.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@
1313

1414
#include "FWCore/Utilities/interface/EDMException.h"
1515

16-
#include "TBranch.h"
1716
#include "TClass.h"
1817

1918
#include <cassert>
2019

2120
namespace edm::rntuple_temp {
2221

23-
RootDelayedReader::RootDelayedReader(RootRNTuple const& tree, std::shared_ptr<InputFile> filePtr, InputType inputType)
24-
: tree_(tree), filePtr_(filePtr), nextReader_(), inputType_(inputType) {
22+
RootDelayedReader::RootDelayedReader(RootRNTuple const& tuple,
23+
std::shared_ptr<InputFile> filePtr,
24+
InputType inputType)
25+
: rntuple_(tuple), filePtr_(filePtr), nextReader_(), inputType_(inputType) {
2526
if (inputType == InputType::Primary) {
2627
auto resources = SharedResourcesRegistry::instance()->createAcquirerForSourceDelayedReader();
2728
resourceAcquirer_ = std::make_unique<SharedResourcesAcquirer>(std::move(resources.first));
@@ -60,8 +61,7 @@ namespace edm::rntuple_temp {
6061
return std::shared_ptr<WrapperBase>();
6162
}
6263
}
63-
TBranch* br = branchInfo->productBranch_;
64-
if (br == nullptr) {
64+
if (not branchInfo->valid()) {
6565
if (nextReader_) {
6666
return nextReader_->getProduct(k, ep);
6767
} else {
@@ -71,19 +71,19 @@ namespace edm::rntuple_temp {
7171

7272
RefCoreStreamerGuard guard(ep);
7373
std::unique_ptr<WrapperBase> edp = branchInfo->newWrapper();
74-
void* edpPtr = edp.get();
75-
branchInfo->productBranch_->SetAddress(&edpPtr);
74+
branchInfo->view().BindRawPtr(edp.get());
7675

7776
try {
7877
//Run, Lumi, and ProcessBlock only have 1 entry number, which is index 0
79-
tree_.getEntry(br, tree_.entryNumberForIndex(tree_.branchType() == InEvent ? ep->transitionIndex() : 0));
78+
rntuple_.getEntry(branchInfo->view(),
79+
rntuple_.entryNumberForIndex(rntuple_.branchType() == InEvent ? ep->transitionIndex() : 0));
8080
} catch (...) {
8181
lastException_ = std::current_exception();
8282
std::rethrow_exception(lastException_);
8383
}
84-
if (tree_.branchType() == InEvent) {
84+
if (rntuple_.branchType() == InEvent) {
8585
// CMS-THREADING For the primary input source calls to this function need to be serialized
86-
InputFile::reportReadBranch(inputType_, std::string(br->GetName()));
86+
InputFile::reportReadBranch(inputType_, std::string(branchInfo->productDescription().branchName()));
8787
}
8888
return edp;
8989
}

FWIO/RNTupleTempInput/src/RootDelayedReader.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ namespace edm::rntuple_temp {
5252
void reset_() override { nextReader_ = nullptr; }
5353
std::pair<SharedResourcesAcquirer*, std::recursive_mutex*> sharedResources_() const override;
5454

55-
ProductMap const& branches() const { return tree_.branches(); }
55+
ProductMap const& branches() const { return rntuple_.branches(); }
5656
ProductInfo const* getProductInfo(BranchID const& k) const { return branches().find(k); }
5757
// NOTE: filePtr_ appears to be unused, but is needed to prevent
5858
// the file containing the branch from being reclaimed.
59-
RootRNTuple const& tree_;
59+
RootRNTuple const& rntuple_;
6060
edm::propagate_const<std::shared_ptr<InputFile>> filePtr_;
6161
edm::propagate_const<DelayedReader*> nextReader_;
6262
std::unique_ptr<SharedResourcesAcquirer>

FWIO/RNTupleTempInput/src/RootFile.cc

Lines changed: 41 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@
7676
#include <iostream>
7777

7878
namespace edm::rntuple_temp {
79+
namespace {
80+
std::string fixName(std::string_view iName) {
81+
if (not iName.empty() and iName.back() == '.') {
82+
iName.remove_suffix(1);
83+
}
84+
return std::string(iName);
85+
}
86+
} // namespace
7987

8088
// Algorithm classes for making ProvenanceReader:
8189
class MakeReducedProvenanceReader : public MakeProvenanceReader {
@@ -186,10 +194,9 @@ namespace edm::rntuple_temp {
186194
processingMode_(processingOptions.processingMode),
187195
runHelper_(crossFileInfo.runHelper),
188196
newBranchToOldBranch_(),
189-
eventToProcessBlockIndexesBranch_(
190-
inputType == InputType::Primary
191-
? eventTree_.tree()->GetBranch(poolNames::eventToProcessBlockIndexesBranchName().c_str())
192-
: nullptr),
197+
eventToProcessBlockIndexesView_(inputType == InputType::Primary
198+
? eventTree_.view(poolNames::eventToProcessBlockIndexesBranchName())
199+
: std::optional<ROOT::RNTupleView<void>>()),
193200
productDependencies_(new ProductDependencies),
194201
duplicateChecker_(crossFileInfo.duplicateChecker),
195202
provenanceReaderMaker_(),
@@ -491,11 +498,11 @@ namespace edm::rntuple_temp {
491498
auto it = std::find(processes.begin(), processes.end(), prod.processName());
492499
if (it != processes.end()) {
493500
auto index = std::distance(processes.begin(), it);
494-
treePointers_[numberOfRunLumiEventProductTrees + index]->addBranch(prod,
495-
newBranchToOldBranch(prod.branchName()));
501+
treePointers_[numberOfRunLumiEventProductTrees + index]->addBranch(
502+
prod, fixName(newBranchToOldBranch(prod.branchName())));
496503
}
497504
} else {
498-
treePointers_[prod.branchType()]->addBranch(prod, newBranchToOldBranch(prod.branchName()));
505+
treePointers_[prod.branchType()]->addBranch(prod, fixName(newBranchToOldBranch(prod.branchName())));
499506
}
500507
}
501508

@@ -506,51 +513,6 @@ namespace edm::rntuple_temp {
506513
RootFile::~RootFile() {}
507514

508515
bool RootFile::empty() const { return runTree_.entries() == 0; }
509-
void RootFile::readEntryDescriptionTree(EntryDescriptionMap& entryDescriptionMap, InputType inputType) {
510-
// Called only for old format files.
511-
// We use a smart pointer so the tree will be deleted after use, and not kept for the life of the file.
512-
std::unique_ptr<TTree> entryDescriptionTree(
513-
dynamic_cast<TTree*>(filePtr_->Get(poolNames::entryDescriptionTreeName().c_str())));
514-
if (nullptr == entryDescriptionTree.get()) {
515-
throw Exception(errors::FileReadError)
516-
<< "Could not find tree " << poolNames::entryDescriptionTreeName() << " in the input file.\n";
517-
}
518-
519-
EntryDescriptionID idBuffer;
520-
EntryDescriptionID* pidBuffer = &idBuffer;
521-
entryDescriptionTree->SetBranchAddress(poolNames::entryDescriptionIDBranchName().c_str(), &pidBuffer);
522-
523-
EventEntryDescription entryDescriptionBuffer;
524-
EventEntryDescription* pEntryDescriptionBuffer = &entryDescriptionBuffer;
525-
entryDescriptionTree->SetBranchAddress(poolNames::entryDescriptionBranchName().c_str(), &pEntryDescriptionBuffer);
526-
527-
// Fill in the parentage registry.
528-
ParentageRegistry& registry = *ParentageRegistry::instance();
529-
530-
for (Long64_t i = 0, numEntries = entryDescriptionTree->GetEntries(); i < numEntries; ++i) {
531-
rootrntuple::getEntry(entryDescriptionTree.get(), i);
532-
if (idBuffer != entryDescriptionBuffer.id()) {
533-
throw Exception(errors::EventCorruption) << "Corruption of EntryDescription tree detected.\n";
534-
}
535-
entryDescriptionMap.insert(std::make_pair(entryDescriptionBuffer.id(), entryDescriptionBuffer));
536-
Parentage parents;
537-
parents.setParents(entryDescriptionBuffer.parents());
538-
if (daqProvenanceHelper_) {
539-
ParentageID const oldID = parents.id();
540-
daqProvenanceHelper_->fixMetaData(parents.parentsForUpdate());
541-
ParentageID newID = parents.id();
542-
if (newID != oldID) {
543-
daqProvenanceHelper_->setOldParentageIDToNew(oldID, newID);
544-
}
545-
}
546-
// For thread safety, don't update global registries when a secondary source opens a file.
547-
if (inputType != InputType::SecondarySource) {
548-
registry.insertMapped(parents);
549-
}
550-
}
551-
entryDescriptionTree->SetBranchAddress(poolNames::entryDescriptionIDBranchName().c_str(), nullptr);
552-
entryDescriptionTree->SetBranchAddress(poolNames::entryDescriptionBranchName().c_str(), nullptr);
553-
}
554516

555517
void RootFile::readParentageTree(InputType inputType) {
556518
// New format file
@@ -593,16 +555,12 @@ namespace edm::rntuple_temp {
593555
std::vector<std::string> processesWithProcessBlockTrees;
594556
processBlockTrees.reserve(processBlockTrees_.size());
595557
processesWithProcessBlockTrees.reserve(processBlockTrees_.size());
596-
for (auto& processBlockTree : processBlockTrees_) {
597-
processBlockTrees.push_back(processBlockTree->tree());
598-
processesWithProcessBlockTrees.push_back(processBlockTree->processName());
599-
}
600558
return std::make_shared<FileBlock>(fileFormatVersion(),
601-
eventTree_.tree(),
602559
nullptr,
603-
lumiTree_.tree(),
604560
nullptr,
605-
runTree_.tree(),
561+
nullptr,
562+
nullptr,
563+
nullptr,
606564
nullptr,
607565
std::move(processBlockTrees),
608566
std::move(processesWithProcessBlockTrees),
@@ -617,17 +575,11 @@ namespace edm::rntuple_temp {
617575
void RootFile::updateFileBlock(FileBlock& fileBlock) {
618576
std::vector<TTree*> processBlockTrees;
619577
std::vector<std::string> processesWithProcessBlockTrees;
620-
processBlockTrees.reserve(processBlockTrees_.size());
621-
processesWithProcessBlockTrees.reserve(processBlockTrees_.size());
622-
for (auto& processBlockTree : processBlockTrees_) {
623-
processBlockTrees.push_back(processBlockTree->tree());
624-
processesWithProcessBlockTrees.push_back(processBlockTree->processName());
625-
}
626-
fileBlock.updateTTreePointers(eventTree_.tree(),
578+
fileBlock.updateTTreePointers(nullptr,
579+
nullptr,
580+
nullptr,
627581
nullptr,
628-
lumiTree_.tree(),
629582
nullptr,
630-
runTree_.tree(),
631583
nullptr,
632584
std::move(processBlockTrees),
633585
std::move(processesWithProcessBlockTrees));
@@ -1143,8 +1095,7 @@ namespace edm::rntuple_temp {
11431095
}
11441096

11451097
void RootFile::fillEventToProcessBlockIndexes() {
1146-
TBranch* eventToProcessBlockIndexesBranch = get_underlying_safe(eventToProcessBlockIndexesBranch_);
1147-
if (eventToProcessBlockIndexesBranch == nullptr) {
1098+
if (not eventToProcessBlockIndexesView_.has_value()) {
11481099
if (processBlockHelper_.get() == nullptr) {
11491100
eventToProcessBlockIndexes_.setIndex(0);
11501101
} else {
@@ -1154,8 +1105,8 @@ namespace edm::rntuple_temp {
11541105
if (processBlockHelper_->cacheIndexVectorsPerFile().back() == 1u) {
11551106
eventToProcessBlockIndexes_.setIndex(processBlockHelper_->outerOffset());
11561107
} else {
1157-
EventToProcessBlockIndexes* pEventToProcessBlockIndexes = &eventToProcessBlockIndexes_;
1158-
eventTree_.fillBranchEntry(eventToProcessBlockIndexesBranch, pEventToProcessBlockIndexes);
1108+
eventToProcessBlockIndexesView_->BindRawPtr(&eventToProcessBlockIndexes_);
1109+
eventTree_.fillEntry(*eventToProcessBlockIndexesView_);
11591110
unsigned int updatedIndex = eventToProcessBlockIndexes_.index() + processBlockHelper_->outerOffset();
11601111
eventToProcessBlockIndexes_.setIndex(updatedIndex);
11611112
}
@@ -1176,14 +1127,14 @@ namespace edm::rntuple_temp {
11761127
// for backward compatibility.
11771128
} else if (fileFormatVersion().noMetaDataTrees()) {
11781129
// Current format
1179-
EventSelectionIDVector* pESV = &eventSelectionIDs;
1180-
TBranch* eventSelectionIDBranch = eventTree_.tree()->GetBranch(poolNames::eventSelectionsBranchName().c_str());
1181-
assert(eventSelectionIDBranch != nullptr);
1182-
eventTree_.fillBranchEntry(eventSelectionIDBranch, pESV);
1183-
BranchListIndexes* pBLI = &branchListIndexes;
1184-
TBranch* branchListIndexesBranch = eventTree_.tree()->GetBranch(poolNames::branchListIndexesBranchName().c_str());
1185-
assert(branchListIndexesBranch != nullptr);
1186-
eventTree_.fillBranchEntry(branchListIndexesBranch, pBLI);
1130+
auto eventSelectionIDsView = eventTree_.view(poolNames::eventSelectionsBranchName());
1131+
assert(eventSelectionIDsView.has_value());
1132+
eventSelectionIDsView->BindRawPtr(&eventSelectionIDs);
1133+
eventTree_.fillEntry(*eventSelectionIDsView);
1134+
auto branchListIndexesView = eventTree_.view(poolNames::branchListIndexesBranchName());
1135+
assert(branchListIndexesView.has_value());
1136+
branchListIndexesView->BindRawPtr(&branchListIndexes);
1137+
eventTree_.fillEntry(*branchListIndexesView);
11871138
}
11881139
if (daqProvenanceHelper_) {
11891140
evtAux.setProcessHistoryID(daqProvenanceHelper_->mapProcessHistoryID(evtAux.processHistoryID()));
@@ -1701,14 +1652,14 @@ namespace edm::rntuple_temp {
17011652
auto it = std::find(processes.begin(), processes.end(), prod.processName());
17021653
if (it != processes.end()) {
17031654
auto index = std::distance(processes.begin(), it);
1704-
processBlockTrees_[index]->setPresence(prod, newBranchToOldBranch(prod.branchName()));
1655+
processBlockTrees_[index]->setPresence(prod, fixName(newBranchToOldBranch(prod.branchName())));
17051656
} else {
17061657
// Given current rules for saving ProductDescriptions, this case should only occur
17071658
// in non-Primary sequences.
17081659
prod.setDropped(true);
17091660
}
17101661
} else {
1711-
treePointers_[prod.branchType()]->setPresence(prod, newBranchToOldBranch(prod.branchName()));
1662+
treePointers_[prod.branchType()]->setPresence(prod, fixName(newBranchToOldBranch(prod.branchName())));
17121663
}
17131664
if (prod.present()) {
17141665
prod.initFromDictionary();
@@ -1829,9 +1780,9 @@ namespace edm::rntuple_temp {
18291780
auto it = std::find(processes.begin(), processes.end(), prod.processName());
18301781
assert(it != processes.end());
18311782
auto index = std::distance(processes.begin(), it);
1832-
processBlockTrees_[index]->dropBranch(newBranchToOldBranch(prod.branchName()));
1783+
processBlockTrees_[index]->dropBranch(fixName(newBranchToOldBranch(prod.branchName())));
18331784
} else {
1834-
treePointers_[prod.branchType()]->dropBranch(newBranchToOldBranch(prod.branchName()));
1785+
treePointers_[prod.branchType()]->dropBranch(fixName(newBranchToOldBranch(prod.branchName())));
18351786
}
18361787
hasNewlyDroppedBranch_[prod.branchType()] = true;
18371788
}
@@ -1859,7 +1810,7 @@ namespace edm::rntuple_temp {
18591810
int offset = cp->GetBaseClassOffset(edProductClass_);
18601811
std::unique_ptr<WrapperBase> edp = getWrapperBasePtr(p, offset);
18611812
if (edp->isMergeable()) {
1862-
treePointers_[prod.branchType()]->dropBranch(newBranchToOldBranch(prod.branchName()));
1813+
treePointers_[prod.branchType()]->dropBranch(fixName(newBranchToOldBranch(prod.branchName())));
18631814
ProductRegistry::ProductList::iterator icopy = it;
18641815
++it;
18651816
prodList.erase(icopy);
@@ -1990,7 +1941,7 @@ namespace edm::rntuple_temp {
19901941
std::atomic<const std::set<ProductProvenance>*>& writeTo) const noexcept override;
19911942

19921943
edm::propagate_const<RootRNTuple*> rootTree_;
1993-
edm::propagate_const<TBranch*> provBranch_;
1944+
ROOT::DescriptorId_t provID_;
19941945
StoredProductProvenanceVector provVector_;
19951946
StoredProductProvenanceVector const* pProvVector_;
19961947
std::vector<ParentageID> const& parentageIDLookup_;
@@ -2004,14 +1955,12 @@ namespace edm::rntuple_temp {
20041955
DaqProvenanceHelper const* daqProvenanceHelper)
20051956
: ProvenanceReaderBase(),
20061957
rootTree_(iRootRNTuple),
1958+
provID_(rootTree_->descriptorFor(BranchTypeToProductProvenanceBranchName(rootTree_->branchType()))),
20071959
pProvVector_(&provVector_),
20081960
parentageIDLookup_(iParentageIDLookup),
20091961
daqProvenanceHelper_(daqProvenanceHelper),
20101962
mutex_(SharedResourcesRegistry::instance()->createAcquirerForSourceDelayedReader().second),
2011-
acquirer_(SharedResourcesRegistry::instance()->createAcquirerForSourceDelayedReader().first) {
2012-
provBranch_ =
2013-
rootTree_->tree()->GetBranch(BranchTypeToProductProvenanceBranchName(rootTree_->branchType()).c_str());
2014-
}
1963+
acquirer_(SharedResourcesRegistry::instance()->createAcquirerForSourceDelayedReader().first) {}
20151964

20161965
namespace {
20171966
using SignalType = signalslot::Signal<void(StreamContext const&, ModuleCallingContext const&)>;
@@ -2091,16 +2040,14 @@ namespace edm::rntuple_temp {
20912040
//
20922041
void ReducedProvenanceReader::unsafe_fillProvenance(unsigned int transitionIndex) const {
20932042
ReducedProvenanceReader* me = const_cast<ReducedProvenanceReader*>(this);
2094-
me->rootTree_->fillBranchEntry(
2095-
me->provBranch_, me->rootTree_->entryNumberForIndex(transitionIndex), me->pProvVector_);
2043+
me->rootTree_->fillEntry(me->provID_, me->rootTree_->entryNumberForIndex(transitionIndex), &me->provVector_);
20962044
}
20972045

20982046
std::set<ProductProvenance> ReducedProvenanceReader::readProvenance(unsigned int transitionIndex) const {
20992047
if (provVector_.empty()) {
21002048
std::lock_guard<std::recursive_mutex> guard(*mutex_);
21012049
ReducedProvenanceReader* me = const_cast<ReducedProvenanceReader*>(this);
2102-
me->rootTree_->fillBranchEntry(
2103-
me->provBranch_, me->rootTree_->entryNumberForIndex(transitionIndex), me->pProvVector_);
2050+
me->rootTree_->fillEntry(me->provID_, me->rootTree_->entryNumberForIndex(transitionIndex), &me->provVector_);
21042051
}
21052052
std::set<ProductProvenance> retValue;
21062053
if (daqProvenanceHelper_) {

FWIO/RNTupleTempInput/src/RootFile.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ RootFile.h // used by ROOT input sources
3030
#include "FWCore/Utilities/interface/get_underlying_safe.h"
3131
#include "FWCore/Utilities/interface/propagate_const.h"
3232

33-
#include "TBranch.h"
34-
3533
#include <array>
3634
#include <map>
3735
#include <memory>
@@ -243,8 +241,6 @@ namespace edm {
243241
ProcessBlockHelper const*);
244242

245243
void readParentageTree(InputType inputType);
246-
void readEntryDescriptionTree(EntryDescriptionMap& entryDescriptionMap,
247-
InputType inputType); // backward compatibility
248244
bool isDuplicateEvent();
249245

250246
void initializeDuplicateChecker(std::vector<std::shared_ptr<IndexIntoFile>> const& indexesIntoFiles,
@@ -308,7 +304,7 @@ namespace edm {
308304
edm::propagate_const<InputSourceRunHelperBase*> runHelper_;
309305
std::map<std::string, std::string> newBranchToOldBranch_;
310306
EventToProcessBlockIndexes eventToProcessBlockIndexes_;
311-
edm::propagate_const<TBranch*> eventToProcessBlockIndexesBranch_;
307+
std::optional<ROOT::RNTupleView<void>> eventToProcessBlockIndexesView_;
312308
edm::propagate_const<std::shared_ptr<ProductDependencies>> productDependencies_;
313309
edm::propagate_const<std::shared_ptr<DuplicateChecker>> duplicateChecker_;
314310
edm::propagate_const<std::unique_ptr<MakeProvenanceReader>> provenanceReaderMaker_;

0 commit comments

Comments
 (0)