Skip to content

Commit 4b4725d

Browse files
committed
[ntuple] Refactor AddAuxiliary away
1 parent 20d512c commit 4b4725d

File tree

2 files changed

+13
-45
lines changed

2 files changed

+13
-45
lines changed

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -562,15 +562,6 @@ private:
562562
std::unique_ptr<RNTupleModel> primaryModel = nullptr,
563563
std::vector<std::unique_ptr<RNTupleModel>> auxModels = {});
564564

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

tree/ntuple/v7/src/RNTupleProcessor.cxx

Lines changed: 13 additions & 36 deletions
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)
@@ -374,12 +376,6 @@ ROOT::Experimental::RNTupleJoinProcessor::RNTupleJoinProcessor(const RNTupleOpen
374376
auto &field = value.GetField();
375377
const auto &fieldName = field.GetQualifiedFieldName();
376378

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

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

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

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

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

0 commit comments

Comments
 (0)