Skip to content

Commit ff493cd

Browse files
committed
[df] Use field tokens for RNTuple snapshotting
This is less expensive than string comparisons of field names during every call to Exec().
1 parent be17bbc commit ff493cd

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

tree/dataframe/inc/ROOT/RDF/SnapshotHelpers.hxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class TFile;
3232
namespace ROOT {
3333
class RNTupleWriter;
3434
class REntry;
35+
class RFieldToken;
3536
class TBufferMerger;
3637
class TBufferMergerFile;
3738
} // namespace ROOT
@@ -64,6 +65,7 @@ class R__CLING_PTRCHECK(off) UntypedSnapshotRNTupleHelper final : public RAction
6465
ColumnNames_t fInputFieldNames; // This contains the resolved aliases
6566
ColumnNames_t fOutputFieldNames;
6667
std::unique_ptr<ROOT::RNTupleWriter> fWriter;
68+
std::vector<ROOT::RFieldToken> fFieldTokens;
6769

6870
std::unique_ptr<ROOT::REntry> fOutputEntry;
6971

tree/dataframe/src/RDFSnapshotHelpers.cxx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <ROOT/RDF/SnapshotHelpers.hxx>
2121

2222
#include <ROOT/REntry.hxx>
23+
#include <ROOT/RFieldToken.hxx>
2324
#include <ROOT/RNTuple.hxx>
2425
#include <ROOT/RNTupleDS.hxx>
2526
#include <ROOT/RNTupleWriter.hxx>
@@ -831,6 +832,7 @@ void ROOT::Internal::RDF::UntypedSnapshotRNTupleHelper::Initialize()
831832
{
832833
auto model = ROOT::RNTupleModel::CreateBare();
833834
auto nFields = fOutputFieldNames.size();
835+
fFieldTokens.resize(nFields);
834836
for (decltype(nFields) i = 0; i < nFields; i++) {
835837
// Need to retrieve the type of every field to create as a string
836838
// If the input type for a field does not have RTTI, internally we store it as the tag UseNativeDataType. When
@@ -840,6 +842,7 @@ void ROOT::Internal::RDF::UntypedSnapshotRNTupleHelper::Initialize()
840842
fInputFieldNames[i], fOptions.fVector2RVec)
841843
: ROOT::Internal::RDF::TypeID2TypeName(*fInputColumnTypeIDs[i]);
842844
model->AddField(ROOT::RFieldBase::Create(fOutputFieldNames[i], typeName).Unwrap());
845+
fFieldTokens[i] = model->GetToken(fOutputFieldNames[i]);
843846
}
844847
model->Freeze();
845848
fOutputEntry = model->CreateBareEntry();
@@ -866,9 +869,9 @@ void ROOT::Internal::RDF::UntypedSnapshotRNTupleHelper::Initialize()
866869

867870
void ROOT::Internal::RDF::UntypedSnapshotRNTupleHelper::Exec(unsigned int /* slot */, const std::vector<void *> &values)
868871
{
869-
assert(values.size() == fOutputFieldNames.size());
872+
assert(values.size() == fFieldTokens.size());
870873
for (decltype(values.size()) i = 0; i < values.size(); i++) {
871-
fOutputEntry->BindRawPtr(fOutputFieldNames[i], values[i]);
874+
fOutputEntry->BindRawPtr(fFieldTokens[i], values[i]);
872875
}
873876
fWriter->Fill(*fOutputEntry);
874877
}

0 commit comments

Comments
 (0)