Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cc09ee6

Browse files
committedMar 12, 2025·
[ntuple] Refactor out AddAuxiliary
1 parent 72e8b72 commit cc09ee6

File tree

2 files changed

+13
-45
lines changed

2 files changed

+13
-45
lines changed
 

‎tree/ntuple/v7/inc/ROOT/RNTupleProcessor.hxx

-9
Original file line numberDiff line numberDiff line change
@@ -563,15 +563,6 @@ private:
563563
std::unique_ptr<RNTupleModel> primaryModel = nullptr,
564564
std::vector<std::unique_ptr<RNTupleModel>> auxModels = {});
565565

566-
/////////////////////////////////////////////////////////////////////////////
567-
/// \brief Add an auxiliary RNTuple to the processor.
568-
///
569-
/// \param[in] auxNTuple The source specification (name and storage location) of the auxiliary RNTuple.
570-
/// \param[in] joinFields The names of the fields used in the join.
571-
/// \param[in] ntupleIdx The index of the ntuple according to fNTuples.
572-
void
573-
AddAuxiliary(const RNTupleOpenSpec &auxNTuple, const std::vector<std::string> &joinFields, std::size_t ntupleIdx);
574-
575566
/////////////////////////////////////////////////////////////////////////////
576567
/// \brief Connect all fields, once the primary and all auxiliary RNTuples have been added.
577568
void ConnectFields();

‎tree/ntuple/v7/src/RNTupleProcessor.cxx

+13-36
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,8 @@ ROOT::Experimental::RNTupleJoinProcessor::RNTupleJoinProcessor(const RNTupleOpen
351351

352352
for (const auto &auxNTuple : auxNTuples) {
353353
fAuxiliaryPageSources.emplace_back(Internal::RPageSource::Create(auxNTuple.fNTupleName, auxNTuple.fStorage));
354+
if (!joinFields.empty())
355+
fJoinTables.emplace_back(Internal::RNTupleJoinTable::Create(joinFields));
354356
}
355357

356358
if (!primaryModel)
@@ -371,12 +373,6 @@ ROOT::Experimental::RNTupleJoinProcessor::RNTupleJoinProcessor(const RNTupleOpen
371373
auto &field = value.GetField();
372374
const auto &fieldName = field.GetQualifiedFieldName();
373375

374-
auto isAuxParent = std::find_if(auxNTuples.cbegin(), auxNTuples.cend(), [&fieldName](const RNTupleOpenSpec &n) {
375-
return fieldName.substr(0, n.fNTupleName.size()) == n.fNTupleName;
376-
});
377-
if (isAuxParent != auxNTuples.end())
378-
continue;
379-
380376
// If the model provided by the user has a default entry, use the value pointers from the default entry of the
381377
// model that was passed to this constructor. This way, the pointers returned by RNTupleModel::MakeField can be
382378
// used in the processor loop to access the corresponding field values.
@@ -385,11 +381,18 @@ ROOT::Experimental::RNTupleJoinProcessor::RNTupleJoinProcessor(const RNTupleOpen
385381
fEntry->BindValue(fieldName, valuePtr);
386382
}
387383

388-
fFieldContexts.try_emplace(fieldName, field.Clone(fieldName), fEntry->GetToken(fieldName));
389-
}
384+
auto auxNTupleName = std::find_if(auxNTuples.cbegin(), auxNTuples.cend(), [&fieldName](const RNTupleOpenSpec &n) {
385+
return fieldName.substr(0, n.fNTupleName.size()) == n.fNTupleName;
386+
});
390387

391-
for (unsigned i = 0; i < auxNTuples.size(); ++i) {
392-
AddAuxiliary(auxNTuples[i], joinFields, i + 1 /* ntupleIdx */);
388+
if (auxNTupleName == auxNTuples.end()) {
389+
fFieldContexts.try_emplace(fieldName, field.Clone(field.GetFieldName()), fEntry->GetToken(fieldName));
390+
} else if (fieldName != auxNTupleName->fNTupleName) {
391+
// Add 1 because we also have to take into account the primary ntuple.
392+
auto ntupleIdx = std::distance(auxNTuples.begin(), auxNTupleName) + 1;
393+
fFieldContexts.try_emplace(fieldName, field.Clone(field.GetFieldName()), fEntry->GetToken(fieldName),
394+
ntupleIdx);
395+
}
393396
}
394397
}
395398

@@ -436,32 +439,6 @@ void ROOT::Experimental::RNTupleJoinProcessor::SetModel(std::unique_ptr<RNTupleM
436439
fModel->Freeze();
437440
}
438441

439-
void ROOT::Experimental::RNTupleJoinProcessor::AddAuxiliary(const RNTupleOpenSpec &auxNTuple,
440-
const std::vector<std::string> &joinFields,
441-
std::size_t ntupleIdx)
442-
{
443-
assert(fNEntriesProcessed == 0 && "cannot add auxiliary ntuples after processing has started");
444-
445-
auto &auxParentField = fModel->GetConstField(auxNTuple.fNTupleName);
446-
447-
for (const auto &field : auxParentField.GetConstSubfields()) {
448-
// If the model was provided by the user and it has a default entry, use the value pointers from the entry in
449-
// the entry managed by the processor. This way, the pointers returned by RNTupleModel::MakeField can be used
450-
// in the processor loop to access the corresponding field values.
451-
if (!fModel->IsBare()) {
452-
auto valuePtr = fModel->GetDefaultEntry().GetPtr<void>(field->GetQualifiedFieldName());
453-
fEntry->BindValue(field->GetQualifiedFieldName(), valuePtr);
454-
}
455-
456-
auto token = fEntry->GetToken(field->GetQualifiedFieldName());
457-
fFieldContexts.try_emplace(field->GetQualifiedFieldName(), field->Clone(field->GetFieldName()), token, ntupleIdx);
458-
}
459-
460-
// If no join fields have been specified, an aligned join is assumed and an join table won't be created.
461-
if (!joinFields.empty())
462-
fJoinTables.emplace_back(Internal::RNTupleJoinTable::Create(joinFields));
463-
}
464-
465442
void ROOT::Experimental::RNTupleJoinProcessor::ConnectFields()
466443
{
467444
for (auto &[_, fieldContext] : fFieldContexts) {

0 commit comments

Comments
 (0)
Please sign in to comment.