@@ -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.
725736void 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