Skip to content

Commit b9c4d2c

Browse files
committed
Simplifying input code for RNTuple migration
1 parent 149ace9 commit b9c4d2c

File tree

12 files changed

+43
-679
lines changed

12 files changed

+43
-679
lines changed

FWIO/RNTupleTempInput/src/InputFile.h

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ Holder for an input TFile.
1111

1212
#include "TFile.h"
1313
#include "TTree.h"
14-
#include "TTreeCache.h"
1514

1615
#include <map>
1716
#include <string>
@@ -52,33 +51,7 @@ namespace edm::rntuple_temp {
5251
T* Get(char const* name) {
5352
return file_->Get<T>(name);
5453
}
55-
std::unique_ptr<TTreeCache> createCacheWithSize(TTree& iTree, unsigned int cacheSize) {
56-
iTree.SetCacheSize(static_cast<Long64_t>(cacheSize));
57-
std::unique_ptr<TTreeCache> newCache(dynamic_cast<TTreeCache*>(file_->GetCacheRead(&iTree)));
58-
file_->SetCacheRead(nullptr, &iTree, TFile::kDoNotDisconnect);
59-
return newCache;
60-
}
61-
62-
class CacheGuard {
63-
public:
64-
CacheGuard(TFile* file, TObject* tree, TFileCacheRead* tfcr) : file_(file), tree_(tree) {
65-
file_->SetCacheRead(tfcr, tree_, TFile::kDoNotDisconnect);
66-
}
67-
CacheGuard() = delete;
68-
CacheGuard(CacheGuard const&) = delete;
69-
CacheGuard& operator=(CacheGuard const&) = delete;
70-
CacheGuard(CacheGuard&&) = delete;
71-
CacheGuard& operator=(CacheGuard&&) = delete;
72-
~CacheGuard() { file_->SetCacheRead(nullptr, tree_, TFile::kDoNotDisconnect); }
7354

74-
private:
75-
TFile* file_;
76-
TObject* tree_;
77-
};
78-
[[nodiscard]] CacheGuard setCacheReadTemporarily(TFileCacheRead* tfcr, TObject* iTree) {
79-
return CacheGuard(file_.get(), iTree, tfcr);
80-
}
81-
void clearCacheRead(TObject* iTree) { file_->SetCacheRead(nullptr, iTree, TFile::kDoNotDisconnect); }
8255
void logFileAction(char const* msg, char const* fileName) const;
8356

8457
private:

FWIO/RNTupleTempInput/src/RootDelayedReader.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ namespace edm::rntuple_temp {
5252
throw;
5353
}
5454
}
55-
auto branchInfo = getBranchInfo(k);
55+
auto branchInfo = getProductInfo(k);
5656
if (not branchInfo) {
5757
if (nextReader_) {
5858
return nextReader_->getProduct(k, ep);

FWIO/RNTupleTempInput/src/RootDelayedReader.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ namespace edm::rntuple_temp {
3434

3535
class RootDelayedReader : public RootDelayedReaderBase {
3636
public:
37-
typedef rootrntuple::BranchInfo BranchInfo;
38-
typedef rootrntuple::BranchMap BranchMap;
37+
typedef rootrntuple::ProductInfo ProductInfo;
38+
typedef rootrntuple::ProductMap ProductMap;
3939
typedef rootrntuple::EntryNumber EntryNumber;
4040
RootDelayedReader(RootRNTuple const& tree, std::shared_ptr<InputFile> filePtr, InputType inputType);
4141

@@ -52,8 +52,8 @@ namespace edm::rntuple_temp {
5252
void reset_() override { nextReader_ = nullptr; }
5353
std::pair<SharedResourcesAcquirer*, std::recursive_mutex*> sharedResources_() const override;
5454

55-
BranchMap const& branches() const { return tree_.branches(); }
56-
BranchInfo const* getBranchInfo(BranchID const& k) const { return branches().find(k); }
55+
ProductMap const& branches() const { return tree_.branches(); }
56+
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.
5959
RootRNTuple const& tree_;

FWIO/RNTupleTempInput/src/RootEmbeddedFileSequence.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ namespace edm::rntuple_temp {
5151
// have defined descriptions, the defaults in the getUntrackedParameterSet function calls can
5252
// and should be deleted from the code.
5353
initialNumberOfEventsToSkip_(pset.getUntrackedParameter<unsigned int>("skipEvents", 0U)),
54-
treeCacheSize_(pset.getUntrackedParameter<unsigned int>("cacheSize", rootrntuple::defaultCacheSize)),
5554
enablePrefetching_(false),
5655
enforceGUIDInFileName_(pset.getUntrackedParameter<bool>("enforceGUIDInFileName", false)),
5756
maxFileSkips_(pset.getUntrackedParameter<unsigned int>("maxFileSkips", std::min(3_uz, numberOfFiles()))) {
@@ -63,9 +62,6 @@ namespace edm::rntuple_temp {
6362
// The SiteLocalConfig controls the TTreeCache size and the prefetching settings.
6463
Service<SiteLocalConfig> pSLC;
6564
if (pSLC.isAvailable()) {
66-
if (treeCacheSize_ != 0U && pSLC->sourceTTreeCacheSize()) {
67-
treeCacheSize_ = *(pSLC->sourceTTreeCacheSize());
68-
}
6965
enablePrefetching_ = pSLC->enablePrefetching();
7066
}
7167

FWIO/RNTupleTempInput/src/RootFile.cc

Lines changed: 9 additions & 237 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
#include "TClass.h"
6767
#include "TString.h"
6868
#include "TTree.h"
69-
#include "TTreeCache.h"
7069

7170
#include "ROOT/RNTuple.hxx"
7271
#include "ROOT/RNTupleReader.hxx"
@@ -79,26 +78,6 @@
7978
namespace edm::rntuple_temp {
8079

8180
// Algorithm classes for making ProvenanceReader:
82-
class MakeDummyProvenanceReader : public MakeProvenanceReader {
83-
public:
84-
std::unique_ptr<ProvenanceReaderBase> makeReader(RootRNTuple& eventTree,
85-
DaqProvenanceHelper const* daqProvenanceHelper) const override;
86-
};
87-
class MakeOldProvenanceReader : public MakeProvenanceReader {
88-
public:
89-
MakeOldProvenanceReader(std::unique_ptr<EntryDescriptionMap>&& entryDescriptionMap)
90-
: MakeProvenanceReader(), entryDescriptionMap_(std::move(entryDescriptionMap)) {}
91-
std::unique_ptr<ProvenanceReaderBase> makeReader(RootRNTuple& eventTree,
92-
DaqProvenanceHelper const* daqProvenanceHelper) const override;
93-
94-
private:
95-
edm::propagate_const<std::unique_ptr<EntryDescriptionMap>> entryDescriptionMap_;
96-
};
97-
class MakeFullProvenanceReader : public MakeProvenanceReader {
98-
public:
99-
std::unique_ptr<ProvenanceReaderBase> makeReader(RootRNTuple& eventTree,
100-
DaqProvenanceHelper const* daqProvenanceHelper) const override;
101-
};
10281
class MakeReducedProvenanceReader : public MakeProvenanceReader {
10382
public:
10483
MakeReducedProvenanceReader(std::vector<ParentageID> const& parentageIDLookup)
@@ -389,8 +368,6 @@ namespace edm::rntuple_temp {
389368
processHistoryRegistry.registerProcessHistory(history);
390369
}
391370

392-
eventTree_.trainCache(BranchTypeToAuxiliaryBranchName(InEvent).c_str());
393-
394371
// Update the branch id info. This has to be done before validateFile since
395372
// depending on the file format, the branchIDListHelper_ may have its fixBranchListIndexes call made
396373
if (inputType == InputType::Primary) {
@@ -524,16 +501,6 @@ namespace edm::rntuple_temp {
524501

525502
// We are done with our initial reading of EventAuxiliary.
526503
indexIntoFile_.doneFileInitialization();
527-
528-
// Tell the event tree to begin training at the next read.
529-
eventTree_.resetTraining();
530-
531-
// Train the run and lumi trees.
532-
runTree_.trainCache("*");
533-
lumiTree_.trainCache("*");
534-
for (auto& processBlockTree : processBlockTrees_) {
535-
processBlockTree->trainCache("*");
536-
}
537504
}
538505

539506
RootFile::~RootFile() {}
@@ -632,11 +599,11 @@ namespace edm::rntuple_temp {
632599
}
633600
return std::make_shared<FileBlock>(fileFormatVersion(),
634601
eventTree_.tree(),
635-
eventTree_.metaTree(),
602+
nullptr,
636603
lumiTree_.tree(),
637-
lumiTree_.metaTree(),
604+
nullptr,
638605
runTree_.tree(),
639-
runTree_.metaTree(),
606+
nullptr,
640607
std::move(processBlockTrees),
641608
std::move(processesWithProcessBlockTrees),
642609
0,
@@ -657,11 +624,11 @@ namespace edm::rntuple_temp {
657624
processesWithProcessBlockTrees.push_back(processBlockTree->processName());
658625
}
659626
fileBlock.updateTTreePointers(eventTree_.tree(),
660-
eventTree_.metaTree(),
627+
nullptr,
661628
lumiTree_.tree(),
662-
lumiTree_.metaTree(),
629+
nullptr,
663630
runTree_.tree(),
664-
runTree_.metaTree(),
631+
nullptr,
665632
std::move(processBlockTrees),
666633
std::move(processesWithProcessBlockTrees));
667634
}
@@ -1988,19 +1955,9 @@ namespace edm::rntuple_temp {
19881955
}
19891956

19901957
std::unique_ptr<MakeProvenanceReader> RootFile::makeProvenanceReaderMaker(InputType inputType) {
1991-
if (fileFormatVersion_.storedProductProvenanceUsed()) {
1992-
readParentageTree(inputType);
1993-
return std::make_unique<MakeReducedProvenanceReader>(parentageIDLookup_);
1994-
} else if (fileFormatVersion_.splitProductIDs()) {
1995-
readParentageTree(inputType);
1996-
return std::make_unique<MakeFullProvenanceReader>();
1997-
} else if (fileFormatVersion_.perEventProductIDs()) {
1998-
auto entryDescriptionMap = std::make_unique<EntryDescriptionMap>();
1999-
readEntryDescriptionTree(*entryDescriptionMap, inputType);
2000-
return std::make_unique<MakeOldProvenanceReader>(std::move(entryDescriptionMap));
2001-
} else {
2002-
return std::make_unique<MakeDummyProvenanceReader>();
2003-
}
1958+
//if (fileFormatVersion_.storedProductProvenanceUsed()) {
1959+
readParentageTree(inputType);
1960+
return std::make_unique<MakeReducedProvenanceReader>(parentageIDLookup_);
20041961
}
20051962

20061963
std::shared_ptr<ProductProvenanceRetriever> RootFile::makeProductProvenanceRetriever(unsigned int iStreamID) {
@@ -2171,191 +2128,6 @@ namespace edm::rntuple_temp {
21712128
return retValue;
21722129
}
21732130

2174-
class FullProvenanceReader : public ProvenanceReaderBase {
2175-
public:
2176-
explicit FullProvenanceReader(RootRNTuple* rootTree, DaqProvenanceHelper const* daqProvenanceHelper);
2177-
~FullProvenanceReader() override {}
2178-
std::set<ProductProvenance> readProvenance(unsigned int transitionIndex) const override;
2179-
2180-
private:
2181-
void readProvenanceAsync(WaitingTaskHolder task,
2182-
ModuleCallingContext const* moduleCallingContext,
2183-
unsigned int transitionIndex,
2184-
std::atomic<const std::set<ProductProvenance>*>& writeTo) const noexcept override;
2185-
2186-
RootRNTuple* rootTree_;
2187-
ProductProvenanceVector infoVector_;
2188-
//All access to a ROOT file is serialized
2189-
CMS_SA_ALLOW mutable ProductProvenanceVector* pInfoVector_;
2190-
DaqProvenanceHelper const* daqProvenanceHelper_;
2191-
std::shared_ptr<std::recursive_mutex> mutex_;
2192-
SharedResourcesAcquirer acquirer_;
2193-
};
2194-
2195-
FullProvenanceReader::FullProvenanceReader(RootRNTuple* rootTree, DaqProvenanceHelper const* daqProvenanceHelper)
2196-
: ProvenanceReaderBase(),
2197-
rootTree_(rootTree),
2198-
infoVector_(),
2199-
pInfoVector_(&infoVector_),
2200-
daqProvenanceHelper_(daqProvenanceHelper),
2201-
mutex_(SharedResourcesRegistry::instance()->createAcquirerForSourceDelayedReader().second),
2202-
acquirer_(SharedResourcesRegistry::instance()->createAcquirerForSourceDelayedReader().first) {}
2203-
2204-
void FullProvenanceReader::readProvenanceAsync(
2205-
WaitingTaskHolder task,
2206-
ModuleCallingContext const* moduleCallingContext,
2207-
unsigned int transitionIndex,
2208-
std::atomic<const std::set<ProductProvenance>*>& writeTo) const noexcept {
2209-
readProvenanceAsyncImpl(this,
2210-
acquirer_.serialQueueChain(),
2211-
task,
2212-
transitionIndex,
2213-
writeTo,
2214-
moduleCallingContext,
2215-
rootTree_->rootDelayedReader()->preEventReadFromSourceSignal(),
2216-
rootTree_->rootDelayedReader()->postEventReadFromSourceSignal());
2217-
}
2218-
2219-
std::set<ProductProvenance> FullProvenanceReader::readProvenance(unsigned int transitionIndex) const {
2220-
{
2221-
std::lock_guard<std::recursive_mutex> guard(*mutex_);
2222-
rootTree_->fillBranchEntryMeta(
2223-
rootTree_->branchEntryInfoBranch(), rootTree_->entryNumberForIndex(transitionIndex), pInfoVector_);
2224-
}
2225-
std::set<ProductProvenance> retValue;
2226-
if (daqProvenanceHelper_) {
2227-
for (auto const& info : infoVector_) {
2228-
retValue.emplace(daqProvenanceHelper_->mapBranchID(info.branchID()),
2229-
daqProvenanceHelper_->mapParentageID(info.parentageID()));
2230-
}
2231-
} else {
2232-
for (auto const& info : infoVector_) {
2233-
retValue.emplace(info);
2234-
}
2235-
}
2236-
return retValue;
2237-
}
2238-
2239-
class OldProvenanceReader : public ProvenanceReaderBase {
2240-
public:
2241-
explicit OldProvenanceReader(RootRNTuple* rootTree,
2242-
EntryDescriptionMap const& theMap,
2243-
DaqProvenanceHelper const* daqProvenanceHelper);
2244-
~OldProvenanceReader() override {}
2245-
std::set<ProductProvenance> readProvenance(unsigned int transitionIndex) const override;
2246-
2247-
private:
2248-
void readProvenanceAsync(WaitingTaskHolder task,
2249-
ModuleCallingContext const* moduleCallingContext,
2250-
unsigned int transitionIndex,
2251-
std::atomic<const std::set<ProductProvenance>*>& writeTo) const noexcept override;
2252-
2253-
edm::propagate_const<RootRNTuple*> rootTree_;
2254-
std::vector<EventEntryInfo> infoVector_;
2255-
//All access to ROOT file are serialized
2256-
CMS_SA_ALLOW mutable std::vector<EventEntryInfo>* pInfoVector_;
2257-
EntryDescriptionMap const& entryDescriptionMap_;
2258-
DaqProvenanceHelper const* daqProvenanceHelper_;
2259-
std::shared_ptr<std::recursive_mutex> mutex_;
2260-
SharedResourcesAcquirer acquirer_;
2261-
};
2262-
2263-
OldProvenanceReader::OldProvenanceReader(RootRNTuple* rootTree,
2264-
EntryDescriptionMap const& theMap,
2265-
DaqProvenanceHelper const* daqProvenanceHelper)
2266-
: ProvenanceReaderBase(),
2267-
rootTree_(rootTree),
2268-
infoVector_(),
2269-
pInfoVector_(&infoVector_),
2270-
entryDescriptionMap_(theMap),
2271-
daqProvenanceHelper_(daqProvenanceHelper),
2272-
mutex_(SharedResourcesRegistry::instance()->createAcquirerForSourceDelayedReader().second),
2273-
acquirer_(SharedResourcesRegistry::instance()->createAcquirerForSourceDelayedReader().first) {}
2274-
2275-
void OldProvenanceReader::readProvenanceAsync(
2276-
WaitingTaskHolder task,
2277-
ModuleCallingContext const* moduleCallingContext,
2278-
unsigned int transitionIndex,
2279-
std::atomic<const std::set<ProductProvenance>*>& writeTo) const noexcept {
2280-
readProvenanceAsyncImpl(this,
2281-
acquirer_.serialQueueChain(),
2282-
task,
2283-
transitionIndex,
2284-
writeTo,
2285-
moduleCallingContext,
2286-
rootTree_->rootDelayedReader()->preEventReadFromSourceSignal(),
2287-
rootTree_->rootDelayedReader()->postEventReadFromSourceSignal());
2288-
}
2289-
2290-
std::set<ProductProvenance> OldProvenanceReader::readProvenance(unsigned int transitionIndex) const {
2291-
{
2292-
std::lock_guard<std::recursive_mutex> guard(*mutex_);
2293-
rootTree_->branchEntryInfoBranch()->SetAddress(&pInfoVector_);
2294-
rootrntuple::getEntry(rootTree_->branchEntryInfoBranch(), rootTree_->entryNumberForIndex(transitionIndex));
2295-
}
2296-
std::set<ProductProvenance> retValue;
2297-
for (auto const& info : infoVector_) {
2298-
EntryDescriptionMap::const_iterator iter = entryDescriptionMap_.find(info.entryDescriptionID());
2299-
assert(iter != entryDescriptionMap_.end());
2300-
Parentage parentage(iter->second.parents());
2301-
if (daqProvenanceHelper_) {
2302-
retValue.emplace(daqProvenanceHelper_->mapBranchID(info.branchID()),
2303-
daqProvenanceHelper_->mapParentageID(parentage.id()));
2304-
} else {
2305-
retValue.emplace(info.branchID(), parentage.id());
2306-
}
2307-
}
2308-
return retValue;
2309-
}
2310-
2311-
class DummyProvenanceReader : public ProvenanceReaderBase {
2312-
public:
2313-
DummyProvenanceReader();
2314-
~DummyProvenanceReader() override {}
2315-
2316-
private:
2317-
std::set<ProductProvenance> readProvenance(unsigned int) const override;
2318-
void readProvenanceAsync(WaitingTaskHolder task,
2319-
ModuleCallingContext const* moduleCallingContext,
2320-
unsigned int transitionIndex,
2321-
std::atomic<const std::set<ProductProvenance>*>& writeTo) const noexcept override;
2322-
};
2323-
2324-
DummyProvenanceReader::DummyProvenanceReader() : ProvenanceReaderBase() {}
2325-
2326-
std::set<ProductProvenance> DummyProvenanceReader::readProvenance(unsigned int) const {
2327-
// Not providing parentage!!!
2328-
return std::set<ProductProvenance>{};
2329-
}
2330-
void DummyProvenanceReader::readProvenanceAsync(
2331-
WaitingTaskHolder task,
2332-
ModuleCallingContext const* moduleCallingContext,
2333-
unsigned int transitionIndex,
2334-
std::atomic<const std::set<ProductProvenance>*>& writeTo) const noexcept {
2335-
if (nullptr == writeTo.load()) {
2336-
auto emptyProv = std::make_unique<const std::set<ProductProvenance>>();
2337-
const std::set<ProductProvenance>* expected = nullptr;
2338-
if (writeTo.compare_exchange_strong(expected, emptyProv.get())) {
2339-
emptyProv.release();
2340-
}
2341-
}
2342-
}
2343-
2344-
std::unique_ptr<ProvenanceReaderBase> MakeDummyProvenanceReader::makeReader(RootRNTuple&,
2345-
DaqProvenanceHelper const*) const {
2346-
return std::make_unique<DummyProvenanceReader>();
2347-
}
2348-
2349-
std::unique_ptr<ProvenanceReaderBase> MakeOldProvenanceReader::makeReader(
2350-
RootRNTuple& rootTree, DaqProvenanceHelper const* daqProvenanceHelper) const {
2351-
return std::make_unique<OldProvenanceReader>(&rootTree, *entryDescriptionMap_, daqProvenanceHelper);
2352-
}
2353-
2354-
std::unique_ptr<ProvenanceReaderBase> MakeFullProvenanceReader::makeReader(
2355-
RootRNTuple& rootTree, DaqProvenanceHelper const* daqProvenanceHelper) const {
2356-
return std::make_unique<FullProvenanceReader>(&rootTree, daqProvenanceHelper);
2357-
}
2358-
23592131
std::unique_ptr<ProvenanceReaderBase> MakeReducedProvenanceReader::makeReader(
23602132
RootRNTuple& rootTree, DaqProvenanceHelper const* daqProvenanceHelper) const {
23612133
return std::make_unique<ReducedProvenanceReader>(&rootTree, parentageIDLookup_, daqProvenanceHelper);

0 commit comments

Comments
 (0)