Skip to content

Commit 2fbb680

Browse files
committed
[df] Improve exception safety of RDataSource range processing
Create an internal RAII struct to manage the calls to the initialization and finalization routines for the nodes of the computation graphs and the data source.
1 parent 494fe02 commit 2fbb680

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

Diff for: tree/dataframe/inc/ROOT/RDF/RLoopManager.hxx

+3
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ public:
9797
}
9898
};
9999

100+
struct RDSRangeRAII;
101+
100102
} // namespace RDF
101103
} // namespace Internal
102104
} // namespace ROOT
@@ -126,6 +128,7 @@ class RLoopManager : public RNodeBase {
126128
};
127129

128130
friend struct RCallCleanUpTask;
131+
friend struct ROOT::Internal::RDF::RDSRangeRAII;
129132

130133
std::vector<RDFInternal::RActionBase *> fBookedActions; ///< Non-owning pointers to actions to be run
131134
std::vector<RDFInternal::RActionBase *> fRunActions; ///< Non-owning pointers to actions already run

Diff for: tree/dataframe/src/RLoopManager.cxx

+13-6
Original file line numberDiff line numberDiff line change
@@ -721,15 +721,25 @@ struct DSRunRAII {
721721
};
722722
} // namespace
723723

724+
struct ROOT::Internal::RDF::RDSRangeRAII {
725+
ROOT::Detail::RDF::RLoopManager &fLM;
726+
unsigned int fSlot;
727+
RDSRangeRAII(ROOT::Detail::RDF::RLoopManager &lm, unsigned int slot, ULong64_t firstEntry) : fLM(lm), fSlot(slot)
728+
{
729+
fLM.InitNodeSlots(nullptr, fSlot);
730+
fLM.GetDataSource()->InitSlot(fSlot, firstEntry);
731+
}
732+
~RDSRangeRAII() { fLM.GetDataSource()->FinalizeSlot(fSlot); }
733+
};
734+
724735
/// Run event loop over data accessed through a DataSource, in sequence.
725736
void RLoopManager::RunDataSource()
726737
{
727738
assert(fDataSource != nullptr);
728739
DSRunRAII _{*fDataSource};
729740
auto ranges = fDataSource->GetEntryRanges();
730741
while (!ranges.empty() && fNStopsReceived < fNChildren) {
731-
InitNodeSlots(nullptr, 0u);
732-
fDataSource->InitSlot(0u, 0ull);
742+
RDSRangeRAII __{*this, 0u, 0ull};
733743
RCallCleanUpTask cleanup(*this);
734744
try {
735745
for (const auto &range : ranges) {
@@ -746,7 +756,6 @@ void RLoopManager::RunDataSource()
746756
std::cerr << "RDataFrame::Run: event loop was interrupted\n";
747757
throw;
748758
}
749-
fDataSource->FinalizeSlot(0u);
750759
ranges = fDataSource->GetEntryRanges();
751760
}
752761
}
@@ -763,9 +772,8 @@ void RLoopManager::RunDataSourceMT()
763772
auto runOnRange = [this, &slotStack](const std::pair<ULong64_t, ULong64_t> &range) {
764773
ROOT::Internal::RSlotStackRAII slotRAII(slotStack);
765774
const auto slot = slotRAII.fSlot;
766-
InitNodeSlots(nullptr, slot);
775+
RDSRangeRAII _{*this, slot, range.first};
767776
RCallCleanUpTask cleanup(*this, slot);
768-
fDataSource->InitSlot(slot, range.first);
769777
const auto start = range.first;
770778
const auto end = range.second;
771779
R__LOG_DEBUG(0, RDFLogChannel()) << LogRangeProcessing({fDataSource->GetLabel(), start, end, slot});
@@ -779,7 +787,6 @@ void RLoopManager::RunDataSourceMT()
779787
std::cerr << "RDataFrame::Run: event loop was interrupted\n";
780788
throw;
781789
}
782-
fDataSource->FinalizeSlot(slot);
783790
};
784791

785792
DSRunRAII _{*fDataSource};

0 commit comments

Comments
 (0)