Skip to content

Commit f6b725e

Browse files
committed
Added FWIO/RNTupleTempTests items
- based on IOPool/Tests - includes changes needed to make tests work
1 parent 36aeb10 commit f6b725e

File tree

211 files changed

+17416
-21
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

211 files changed

+17416
-21
lines changed

FWIO/RNTupleTempInput/bin/CollUtil.cc

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "TObject.h"
1717
#include "TTree.h"
1818
#include "ROOT/RNTupleReader.hxx"
19+
#include "ROOT/RNTupleDescriptor.hxx"
1920

2021
#include <iomanip>
2122
#include <iostream>
@@ -71,7 +72,6 @@ namespace edm::rntuple_temp {
7172
}
7273
}
7374
Long64_t branchCompressedSizes(TBranch *branch) { return branch->GetZipBytes("*"); }
74-
7575
} // namespace
7676

7777
void printBranchNames(TTree *tree) {
@@ -100,6 +100,53 @@ namespace edm::rntuple_temp {
100100
}
101101
}
102102

103+
namespace {
104+
Long64_t storageForField(ROOT::RFieldDescriptor const &iField, ROOT::RNTupleDescriptor const &iDesc) {
105+
Long64_t storage = 0;
106+
for (auto &col : iDesc.GetColumnIterable(iField)) {
107+
if (col.IsAliasColumn()) {
108+
continue;
109+
}
110+
auto id = col.GetPhysicalId();
111+
112+
for (auto &cluster : iDesc.GetClusterIterable()) {
113+
auto columnRange = cluster.GetColumnRange(id);
114+
if (columnRange.IsSuppressed()) {
115+
continue;
116+
}
117+
const auto &pageRange = cluster.GetPageRange(id);
118+
for (const auto &page : pageRange.GetPageInfos()) {
119+
storage += page.GetLocator().GetNBytesOnStorage();
120+
}
121+
}
122+
}
123+
return storage;
124+
}
125+
126+
Long64_t storageForFieldAndSubFields(ROOT::RFieldDescriptor const &iField, ROOT::RNTupleDescriptor const &iDesc) {
127+
Long64_t storage = storageForField(iField, iDesc);
128+
for (auto const &sub : iDesc.GetFieldIterable(iField)) {
129+
storage += storageForFieldAndSubFields(sub, iDesc);
130+
}
131+
return storage;
132+
}
133+
} // namespace
134+
135+
void printFieldNames(ROOT::RNTupleReader &reader) {
136+
auto &desc = reader.GetDescriptor();
137+
auto topLevel = desc.GetTopLevelFields();
138+
unsigned int index = 0;
139+
for (auto const &topField : topLevel) {
140+
Long64_t storage = storageForFieldAndSubFields(topField, desc);
141+
std::cout << "Field " << index << " of " << desc.GetName() << " RNTuple: " << topField.GetFieldName()
142+
<< " Bytes On Storage = " << storage << std::endl;
143+
144+
++index;
145+
}
146+
}
147+
148+
void longFieldPrint(ROOT::RNTupleReader &reader) { reader.PrintInfo(ROOT::ENTupleInfo::kStorageDetails); }
149+
103150
namespace {
104151
class BranchBasketBytes {
105152
public:
@@ -283,6 +330,9 @@ namespace edm::rntuple_temp {
283330
processClusters(tr, BasketPrinter{}, branchName);
284331
}
285332

333+
void clusterPrint(ROOT::RNTupleReader &) {}
334+
void pagePrint(ROOT::RNTupleReader &, std::string const &) {}
335+
286336
std::string getUuid(ROOT::RNTupleReader *uuidTree) {
287337
FileID fid;
288338
auto entry = uuidTree->GetModel().CreateEntry();

FWIO/RNTupleTempInput/bin/CollUtil.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ namespace edm::rntuple_temp {
2525
void printUuids(ROOT::RNTupleReader *uuidTree);
2626
void printEventLists(TFile *tfl);
2727
void printEventsInLumis(TFile *tfl);
28+
29+
void printFieldNames(ROOT::RNTupleReader &tree);
30+
void longFieldPrint(ROOT::RNTupleReader &tr);
31+
void clusterPrint(ROOT::RNTupleReader &tr);
32+
void pagePrint(ROOT::RNTupleReader &tr, const std::string &branchName);
33+
2834
} // namespace edm::rntuple_temp
2935

3036
#endif

FWIO/RNTupleTempInput/bin/EdmRNTupleTempFileUtil.cpp

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#include "TFile.h"
2626
#include "TError.h"
27+
#include "TTree.h"
2728
#include "ROOT/RNTuple.hxx"
2829
#include "ROOT/RNTupleReader.hxx"
2930

@@ -267,27 +268,53 @@ int main(int argc, char* argv[]) {
267268
}
268269

269270
if (print or printBranchDetails or printClusters or not printBaskets.empty()) {
270-
TTree* printTree = (TTree*)tfile->Get(selectedTree.c_str());
271-
if (printTree == nullptr) {
272-
std::cout << "Tree " << selectedTree << " appears to be missing. Could not find it in the file.\n";
271+
auto container = tfile->GetObjectUnchecked(selectedTree.c_str());
272+
if (container == nullptr) {
273+
std::cout << "RNTuple " << selectedTree << " appears to be missing. Could not find it in the file.\n";
273274
std::cout << "Exiting\n";
274275
return 1;
275276
}
276-
// Print out each tree
277-
if (print) {
278-
edm::rntuple_temp::printBranchNames(printTree);
279-
}
277+
auto* printRNTuple = tfile->Get<ROOT::RNTuple>(selectedTree.c_str());
278+
if (printRNTuple) {
279+
auto reader = ROOT::RNTupleReader::Open(*printRNTuple);
280+
if (print) {
281+
edm::rntuple_temp::printFieldNames(*reader);
282+
}
280283

281-
if (printBranchDetails) {
282-
edm::rntuple_temp::longBranchPrint(printTree);
283-
}
284+
if (printBranchDetails) {
285+
edm::rntuple_temp::longFieldPrint(*reader);
286+
}
284287

285-
if (printClusters) {
286-
edm::rntuple_temp::clusterPrint(printTree);
287-
}
288+
if (printClusters) {
289+
edm::rntuple_temp::clusterPrint(*reader);
290+
}
291+
292+
if (not printBaskets.empty()) {
293+
edm::rntuple_temp::pagePrint(*reader, printBaskets);
294+
}
295+
} else {
296+
TTree* printTree = (TTree*)tfile->Get(selectedTree.c_str());
297+
if (printTree == nullptr) {
298+
std::cout << "Tree " << selectedTree << " appears to be missing. Could not find it in the file.\n";
299+
std::cout << "Exiting\n";
300+
return 1;
301+
}
302+
// Print out each tree
303+
if (print) {
304+
edm::rntuple_temp::printBranchNames(printTree);
305+
}
306+
307+
if (printBranchDetails) {
308+
edm::rntuple_temp::longBranchPrint(printTree);
309+
}
310+
311+
if (printClusters) {
312+
edm::rntuple_temp::clusterPrint(printTree);
313+
}
288314

289-
if (not printBaskets.empty()) {
290-
edm::rntuple_temp::basketPrint(printTree, printBaskets);
315+
if (not printBaskets.empty()) {
316+
edm::rntuple_temp::basketPrint(printTree, printBaskets);
317+
}
291318
}
292319
}
293320

FWIO/RNTupleTempInput/src/RootFile.cc

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,9 @@ namespace edm::rntuple_temp {
246246
metaDataEntry->BindRawPtr(poolNames::indexIntoFileBranchName(), &indexIntoFile_);
247247

248248
storedProcessBlockHelper_ = std::make_unique<StoredProcessBlockHelper>();
249-
if (inputType == InputType::Primary) {
249+
if (inputType == InputType::Primary and
250+
metaDataReader->GetModel().GetFieldNames().end() !=
251+
metaDataReader->GetModel().GetFieldNames().find(poolNames::processBlockHelperBranchName())) {
250252
metaDataEntry->BindRawPtr(poolNames::processBlockHelperBranchName(), storedProcessBlockHelper_.get());
251253
}
252254

@@ -478,9 +480,13 @@ namespace edm::rntuple_temp {
478480
processingOrderMerge(*processHistoryRegistry_, processingOrder);
479481
newReg->setProcessOrder(processingOrder);
480482

481-
// freeze the product registry
482-
newReg->setFrozen(inputType != InputType::Primary);
483-
productRegistry_.reset(newReg.release());
483+
if (not processingOrder.empty()) {
484+
// freeze the product registry
485+
newReg->setFrozen(inputType != InputType::Primary);
486+
productRegistry_.reset(newReg.release());
487+
} else {
488+
productRegistry_ = std::make_shared<ProductRegistry>();
489+
}
484490
}
485491

486492
// Set up information from the product registry.
@@ -541,6 +547,7 @@ namespace edm::rntuple_temp {
541547

542548
RootFile::~RootFile() {}
543549

550+
bool RootFile::empty() const { return runTree_.entries() == 0; }
544551
void RootFile::readEntryDescriptionTree(EntryDescriptionMap& entryDescriptionMap, InputType inputType) {
545552
// Called only for old format files.
546553
// We use a smart pointer so the tree will be deleted after use, and not kept for the life of the file.

FWIO/RNTupleTempInput/src/RootFile.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ namespace edm {
157157
std::array<bool, NumBranchTypes> const& hasNewlyDroppedBranch() const { return hasNewlyDroppedBranch_; }
158158
bool branchListIndexesUnchanged() const { return branchListIndexesUnchanged_; }
159159
bool modifiedIDs() const { return daqProvenanceHelper_.get() != nullptr; }
160+
//Are there no data stored in the file?
161+
bool empty() const;
160162
std::shared_ptr<FileBlock> createFileBlock();
161163
void updateFileBlock(FileBlock&);
162164

FWIO/RNTupleTempOutput/src/RootOutputFile.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,9 @@ namespace edm::rntuple_temp {
589589
model->AddField(setupBranchIDListRegistry());
590590
model->AddField(setupThinnedAssociationsHelper());
591591
model->AddField(setupProductDependencies());
592-
model->AddField(setupProcessBlockHelper());
592+
if (!om_->outputProcessBlockHelper().processesWithProcessBlockProducts().empty()) {
593+
model->AddField(setupProcessBlockHelper());
594+
}
593595
}
594596

595597
auto writeOptions = ROOT::RNTupleWriteOptions();
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import FWCore.ParameterSet.Config as cms
2+
3+
process = cms.Process("READ")
4+
5+
process.load("FWCore.MessageLogger.MessageLogger_cfi")
6+
7+
process.MessageLogger.cerr.enableStatistics = False
8+
9+
10+
process.load("FWCore.Framework.test.cmsExceptionsFatal_cff")
11+
12+
process.source = cms.Source("RNTupleTempSource",
13+
fileNames = cms.untracked.vstring(
14+
'file:AssociationMapTest.root'
15+
)
16+
)
17+
18+
process.test = cms.EDAnalyzer("AssociationMapAnalyzer",
19+
inputTag1 = cms.InputTag("intvec1"),
20+
inputTag2 = cms.InputTag("intvec2"),
21+
associationMapTag1 = cms.InputTag("associationMapProducer"),
22+
associationMapTag2 = cms.InputTag("associationMapProducer", "twoArg"),
23+
associationMapTag3 = cms.InputTag("associationMapProducer"),
24+
associationMapTag4 = cms.InputTag("associationMapProducer", "handleArg"),
25+
associationMapTag5 = cms.InputTag("associationMapProducer"),
26+
associationMapTag6 = cms.InputTag("associationMapProducer"),
27+
associationMapTag7 = cms.InputTag("associationMapProducer"),
28+
associationMapTag8 = cms.InputTag("associationMapProducer", "twoArg")
29+
)
30+
31+
process.p = cms.Path(process.test)
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import FWCore.ParameterSet.Config as cms
2+
3+
process = cms.Process("PROD")
4+
5+
process.load("FWCore.MessageLogger.MessageLogger_cfi")
6+
7+
process.MessageLogger.cerr.enableStatistics = False
8+
9+
10+
process.load("FWCore.Framework.test.cmsExceptionsFatal_cff")
11+
12+
process.maxEvents = cms.untracked.PSet(
13+
input = cms.untracked.int32(3)
14+
)
15+
16+
process.source = cms.Source("EmptySource")
17+
18+
process.intvec1 = cms.EDProducer("IntVectorProducer",
19+
count = cms.int32(9),
20+
ivalue = cms.int32(11),
21+
delta = cms.int32(1)
22+
)
23+
24+
process.intvec2 = cms.EDProducer("IntVectorProducer",
25+
count = cms.int32(9),
26+
ivalue = cms.int32(21),
27+
delta = cms.int32(1)
28+
)
29+
30+
process.associationMapProducer = cms.EDProducer("AssociationMapProducer",
31+
inputTag1 = cms.InputTag("intvec1"),
32+
inputTag2 = cms.InputTag("intvec2")
33+
)
34+
35+
process.test = cms.EDAnalyzer("AssociationMapAnalyzer",
36+
inputTag1 = cms.InputTag("intvec1"),
37+
inputTag2 = cms.InputTag("intvec2"),
38+
associationMapTag1 = cms.InputTag("associationMapProducer"),
39+
associationMapTag2 = cms.InputTag("associationMapProducer", "twoArg"),
40+
associationMapTag3 = cms.InputTag("associationMapProducer"),
41+
associationMapTag4 = cms.InputTag("associationMapProducer", "handleArg"),
42+
associationMapTag5 = cms.InputTag("associationMapProducer"),
43+
associationMapTag6 = cms.InputTag("associationMapProducer"),
44+
associationMapTag7 = cms.InputTag("associationMapProducer"),
45+
associationMapTag8 = cms.InputTag("associationMapProducer", "twoArg")
46+
)
47+
48+
process.out = cms.OutputModule("RNTupleTempOutputModule",
49+
fileName = cms.untracked.string('AssociationMapTest.root')
50+
)
51+
52+
process.p = cms.Path(process.intvec1 * process.intvec2 * process.associationMapProducer * process.test)
53+
54+
process.e = cms.EndPath(process.out)

0 commit comments

Comments
 (0)