@@ -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-
455450namespace
456451{
457452struct 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-
571459FragmentToBatch::FragmentToBatch (StreamerCreator creator, std::shared_ptr<arrow::dataset::FileFragment> fragment, arrow::MemoryPool* pool)
572460 : mFragment {std::move (fragment)},
573461 mArrowMemoryPool {pool},
0 commit comments