Skip to content

Commit fd429bb

Browse files
committed
DPL: allow plugins to account for bytes
1 parent ad5c282 commit fd429bb

4 files changed

Lines changed: 26 additions & 3 deletions

File tree

Framework/AnalysisSupport/src/DataInputDirector.cxx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,14 @@ bool DataInputDescriptor::readTree(DataAllocator& outputs, header::DataHeader dh
537537
if (handle) {
538538
format = capability.factory().format();
539539
creator = capability.factory().deferredOutputStreamer;
540+
// Account for the bytes we are about to read. This used to sit further down, where
541+
// the TTree was opened by hand; moving the reading to the arrow::Dataset API left
542+
// the accounting behind, which is why aod-bytes-read-* and the --aod-max-read-rate
543+
// pacing that derives from them both read zero. Each format reports its own size,
544+
// so we just ask; here is where the object is resolved and its size is known.
545+
if (capability.accountBytes) {
546+
capability.accountBytes(handle, totalSizeCompressed, totalSizeUncompressed);
547+
}
540548
break;
541549
}
542550
}

Framework/AnalysisSupport/src/TTreePlugin.cxx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,10 @@ class TTreeFileFormat : public arrow::dataset::FileFormat
392392
class SingleTreeFileSystem : public TTreeFileSystem
393393
{
394394
public:
395-
SingleTreeFileSystem(TTree* tree)
395+
SingleTreeFileSystem(TTree* tree, size_t& totalCompressedSize, size_t& totalUncompressedSize)
396396
: TTreeFileSystem(),
397+
mTotUncompressedSize(totalUncompressedSize),
398+
mTotCompressedSize(totalCompressedSize),
397399
mTree(tree)
398400
{
399401
}
@@ -417,8 +419,11 @@ class SingleTreeFileSystem : public TTreeFileSystem
417419
}
418420

419421
private:
420-
size_t mTotUncompressedSize;
421-
size_t mTotCompressedSize;
422+
// References, not values: a TTreeFileFormat built in GetObjectHandler binds to these,
423+
// so by-value members would have it accumulate into copies that are thrown away (and,
424+
// being uninitialised here, read as indeterminate).
425+
size_t& mTotUncompressedSize;
426+
size_t& mTotCompressedSize;
422427
std::unique_ptr<TTree> mTree;
423428
};
424429

Framework/Core/include/Framework/RootArrowFilesystem.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ struct RootObjectReadingCapability {
123123
// Wether or not this actually supports reading an object of the following class
124124
std::function<bool(char const*)> checkSupport;
125125

126+
// Accounts the bytes of the object behind `handle` against the two counters, so that
127+
// the generic reading code need not know how a given format reports its size. Left
128+
// null by formats which cannot report it.
129+
std::function<void(void* handle, size_t& compressed, size_t& uncompressed)> accountBytes = nullptr;
130+
126131
// This must be implemented to load the actual RootArrowFactory plugin which
127132
// implements this capability. This way the detection of the file format
128133
// (via get handle) does not need to know about the actual code which performs

Framework/Core/src/Plugin.cxx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "Framework/PluginManager.h"
2020
#include <TBufferFile.h>
2121
#include <TDirectory.h>
22+
#include <TTree.h>
2223
#include <TDirectoryFile.h>
2324
#include <TClass.h>
2425
#include <arrow/dataset/file_base.h>
@@ -272,6 +273,10 @@ struct TTreeObjectReadingCapability : o2::framework::RootObjectReadingCapability
272273
.lfn2objectPath = [](std::string s) { return s; },
273274
.getHandle = getHandleByClass("TTree"),
274275
.checkSupport = matchClassByName("TTree"),
276+
.accountBytes = [](void* handle, size_t& compressed, size_t& uncompressed) {
277+
auto* tree = (TTree*)handle;
278+
compressed += tree->GetZipBytes();
279+
uncompressed += tree->GetTotBytes(); },
275280
.factory = [context]() -> RootArrowFactory& {
276281
lazyLoadFactory(context->implementations, "O2FrameworkAnalysisTTreeSupport:TTreeObjectReadingImplementation");
277282
return context->implementations.back();

0 commit comments

Comments
 (0)