Skip to content

Commit cb6be30

Browse files
committed
DPL: drop obsolete TreeToTable code
Now using the arrow::Dataset API.
1 parent 0cdfe91 commit cb6be30

File tree

7 files changed

+0
-524
lines changed

7 files changed

+0
-524
lines changed

Framework/Core/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ add_executable(o2-test-framework-core
250250
test/test_Variants.cxx
251251
test/test_WorkflowHelpers.cxx
252252
test/test_WorkflowSerialization.cxx
253-
test/test_TreeToTable.cxx
254253
test/test_DataOutputDirector.cxx
255254
test/unittest_SimpleOptionsRetriever.cxx
256255
test/unittest_DataSpecUtils.cxx
@@ -348,7 +347,6 @@ foreach(b
348347
EventMixing
349348
HistogramRegistry
350349
TableToTree
351-
TreeToTable
352350
ExternalFairMQDeviceProxies
353351
)
354352
o2_add_executable(benchmark-${b}

Framework/Core/include/Framework/DataAllocator.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -233,15 +233,6 @@ class DataAllocator
233233
return tb;
234234
}
235235

236-
template <typename T, typename... Args>
237-
requires(requires { static_cast<struct TreeToTable>(std::declval<std::decay_t<T>>()); })
238-
decltype(auto) make(const Output& spec, Args... args)
239-
{
240-
auto t2t = std::move(LifetimeHolder<TreeToTable>(new std::decay_t<T>(args...)));
241-
adopt(spec, t2t);
242-
return t2t;
243-
}
244-
245236
template <typename T, typename... Args>
246237
requires(requires { static_cast<struct FragmentToBatch>(std::declval<std::decay_t<T>>()); })
247238
decltype(auto) make(const Output& spec, Args... args)
@@ -288,11 +279,6 @@ class DataAllocator
288279
void
289280
adopt(const Output& spec, LifetimeHolder<struct TableBuilder>&);
290281

291-
/// Adopt a Tree2Table in the framework and serialise / send
292-
/// it as an Arrow table to all consumers of @a spec once done
293-
void
294-
adopt(const Output& spec, LifetimeHolder<struct TreeToTable>&);
295-
296282
/// Adopt a Source2Batch in the framework and serialise / send
297283
/// it as an Arrow Dataset to all consumers of @a spec once done
298284
void

Framework/Core/include/Framework/TableTreeHelpers.h

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,6 @@ namespace o2::framework
3636
// OR t2t.addBranch(column.get(), field.get()), ...;
3737
// . t2t.process();
3838
//
39-
// .............................................................................
40-
// -----------------------------------------------------------------------------
41-
// TreeToTable allows to fill the contents of a given TTree to an arrow::Table
42-
// ColumnIterator is used by TreeToTable
43-
//
44-
// To copy the contents of a tree tr to a table ta do:
45-
// . TreeToTable t2t(tr);
46-
// . t2t.addColumn(columnname1); t2t.addColumn(columnname2); ...
47-
// OR
48-
// t2t.addAllColumns();
49-
// . auto ta = t2t.process();
50-
//
51-
// .............................................................................
5239
struct ROOTTypeInfo {
5340
EDataType type;
5441
char suffix[3];
@@ -127,24 +114,6 @@ class TableToTree
127114
std::vector<std::unique_ptr<ColumnToBranch>> mColumnReaders;
128115
};
129116

130-
class TreeToTable
131-
{
132-
public:
133-
TreeToTable(arrow::MemoryPool* pool = arrow::default_memory_pool());
134-
void setLabel(const char* label);
135-
void addAllColumns(TTree* tree, std::vector<std::string>&& names = {});
136-
void fill(TTree*);
137-
std::shared_ptr<arrow::Table> finalize();
138-
139-
private:
140-
arrow::MemoryPool* mArrowMemoryPool;
141-
std::vector<std::unique_ptr<BranchToColumn>> mBranchReaders;
142-
std::string mTableLabel;
143-
std::shared_ptr<arrow::Table> mTable;
144-
145-
void addReader(TBranch* branch, std::string const& name, bool VLA);
146-
};
147-
148117
class FragmentToBatch
149118
{
150119
public:

Framework/Core/src/DataAllocator.cxx

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -241,38 +241,6 @@ void DataAllocator::adopt(const Output& spec, LifetimeHolder<TableBuilder>& tb)
241241
context.addBuffer(std::move(header), buffer, std::move(finalizer), routeIndex);
242242
}
243243

244-
void DataAllocator::adopt(const Output& spec, LifetimeHolder<TreeToTable>& t2t)
245-
{
246-
auto& timingInfo = mRegistry.get<TimingInfo>();
247-
RouteIndex routeIndex = matchDataHeader(spec, timingInfo.timeslice);
248-
249-
auto header = headerMessageFromOutput(spec, routeIndex, o2::header::gSerializationMethodArrow, 0);
250-
auto& context = mRegistry.get<ArrowContext>();
251-
252-
auto creator = [transport = context.proxy().getOutputTransport(routeIndex)](size_t s) -> std::unique_ptr<fair::mq::Message> {
253-
return transport->CreateMessage(s);
254-
};
255-
auto buffer = std::make_shared<FairMQResizableBuffer>(creator);
256-
257-
t2t.callback = [buffer = buffer, transport = context.proxy().getOutputTransport(routeIndex)](TreeToTable& tree) {
258-
// Serialization happens in here, so that we can
259-
// get rid of the intermediate tree 2 table object, saving memory.
260-
auto table = tree.finalize();
261-
doWriteTable(buffer, table.get());
262-
// deletion happens in the caller
263-
};
264-
265-
/// To finalise this we write the table to the buffer.
266-
/// FIXME: most likely not a great idea. We should probably write to the buffer
267-
/// directly in the TableBuilder, incrementally.
268-
auto finalizer = [](std::shared_ptr<FairMQResizableBuffer> b) -> void {
269-
// This is empty because we already serialised the object when
270-
// the LifetimeHolder goes out of scope.
271-
};
272-
273-
context.addBuffer(std::move(header), buffer, std::move(finalizer), routeIndex);
274-
}
275-
276244
void DataAllocator::adopt(const Output& spec, LifetimeHolder<FragmentToBatch>& f2b)
277245
{
278246
auto& timingInfo = mRegistry.get<TimingInfo>();

Framework/Core/src/TableTreeHelpers.cxx

Lines changed: 0 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -447,11 +447,6 @@ std::shared_ptr<TTree> TableToTree::process()
447447
return mTree;
448448
}
449449

450-
TreeToTable::TreeToTable(arrow::MemoryPool* pool)
451-
: mArrowMemoryPool{pool}
452-
{
453-
}
454-
455450
namespace
456451
{
457452
struct BranchInfo {
@@ -461,113 +456,6 @@ struct BranchInfo {
461456
};
462457
} // namespace
463458

464-
void TreeToTable::addAllColumns(TTree* tree, std::vector<std::string>&& names)
465-
{
466-
auto branches = tree->GetListOfBranches();
467-
auto n = branches->GetEntries();
468-
if (n == 0) {
469-
throw runtime_error("Tree has no branches");
470-
}
471-
472-
std::vector<BranchInfo> branchInfos;
473-
for (auto i = 0; i < n; ++i) {
474-
auto branch = static_cast<TBranch*>(branches->At(i));
475-
auto name = std::string{branch->GetName()};
476-
auto pos = name.find(TableTreeHelpers::sizeBranchSuffix);
477-
if (pos != std::string::npos) {
478-
name.erase(pos);
479-
branchInfos.emplace_back(BranchInfo{name, (TBranch*)nullptr, true});
480-
} else {
481-
auto lookup = std::find_if(branchInfos.begin(), branchInfos.end(), [&](BranchInfo const& bi) {
482-
return bi.name == name;
483-
});
484-
if (lookup == branchInfos.end()) {
485-
branchInfos.emplace_back(BranchInfo{name, branch, false});
486-
} else {
487-
lookup->ptr = branch;
488-
}
489-
}
490-
}
491-
492-
if (names.empty()) {
493-
for (auto& bi : branchInfos) {
494-
addReader(bi.ptr, bi.name, bi.mVLA);
495-
}
496-
} else {
497-
for (auto& name : names) {
498-
auto lookup = std::find_if(branchInfos.begin(), branchInfos.end(), [&](BranchInfo const& bi) {
499-
return name == bi.name;
500-
});
501-
if (lookup != branchInfos.end()) {
502-
addReader(lookup->ptr, lookup->name, lookup->mVLA);
503-
}
504-
}
505-
if (names.size() != mBranchReaders.size()) {
506-
LOGF(warn, "Not all requested columns were found in the tree");
507-
}
508-
}
509-
if (mBranchReaders.empty()) {
510-
throw runtime_error("No columns will be read");
511-
}
512-
// Was affected by https://github.com/root-project/root/issues/8962
513-
// Re-enabling this seems to cut the number of IOPS in half
514-
tree->SetCacheSize(25000000);
515-
// tree->SetClusterPrefetch(true);
516-
for (auto& reader : mBranchReaders) {
517-
tree->AddBranchToCache(reader->branch());
518-
if (strncmp(reader->branch()->GetName(), "fIndexArray", strlen("fIndexArray")) == 0) {
519-
std::string sizeBranchName = reader->branch()->GetName();
520-
sizeBranchName += "_size";
521-
auto* sizeBranch = (TBranch*)tree->GetBranch(sizeBranchName.c_str());
522-
if (sizeBranch) {
523-
tree->AddBranchToCache(sizeBranch);
524-
}
525-
}
526-
}
527-
tree->StopCacheLearningPhase();
528-
}
529-
530-
void TreeToTable::setLabel(const char* label)
531-
{
532-
mTableLabel = label;
533-
}
534-
535-
void TreeToTable::fill(TTree* tree)
536-
{
537-
std::vector<std::shared_ptr<arrow::ChunkedArray>> columns;
538-
std::vector<std::shared_ptr<arrow::Field>> fields;
539-
static TBufferFile buffer{TBuffer::EMode::kWrite, 4 * 1024 * 1024};
540-
O2_SIGNPOST_ID_FROM_POINTER(sid, tabletree_helpers, &buffer);
541-
O2_SIGNPOST_START(tabletree_helpers, sid, "TreeToTable", "Filling %{public}s", tree->GetName());
542-
for (auto& reader : mBranchReaders) {
543-
buffer.Reset();
544-
auto arrayAndField = reader->read(&buffer);
545-
columns.push_back(arrayAndField.first);
546-
fields.push_back(arrayAndField.second);
547-
}
548-
O2_SIGNPOST_END(tabletree_helpers, sid, "TreeToTable", "Done filling.");
549-
550-
auto schema = std::make_shared<arrow::Schema>(fields, std::make_shared<arrow::KeyValueMetadata>(std::vector{std::string{"label"}}, std::vector{mTableLabel}));
551-
mTable = arrow::Table::Make(schema, columns);
552-
}
553-
554-
void TreeToTable::addReader(TBranch* branch, std::string const& name, bool VLA)
555-
{
556-
static TClass* cls;
557-
EDataType type;
558-
branch->GetExpectedType(cls, type);
559-
auto listSize = -1;
560-
if (!VLA) {
561-
listSize = static_cast<TLeaf*>(branch->GetListOfLeaves()->At(0))->GetLenStatic();
562-
}
563-
mBranchReaders.emplace_back(std::make_unique<BranchToColumn>(branch, VLA, name, type, listSize, mArrowMemoryPool));
564-
}
565-
566-
std::shared_ptr<arrow::Table> TreeToTable::finalize()
567-
{
568-
return mTable;
569-
}
570-
571459
FragmentToBatch::FragmentToBatch(StreamerCreator creator, std::shared_ptr<arrow::dataset::FileFragment> fragment, arrow::MemoryPool* pool)
572460
: mFragment{std::move(fragment)},
573461
mArrowMemoryPool{pool},

Framework/Core/test/benchmark_TreeToTable.cxx

Lines changed: 0 additions & 96 deletions
This file was deleted.

0 commit comments

Comments
 (0)