# Proper handling of custom classes implementing a Fill method with RDataFrames

**URL:** <https://root-forum.cern.ch/t/proper-handling-of-custom-classes-implementing-a-fill-method-with-rdataframes/64406>\
**Category:** ROOT\
**Tags:** rdataframe\
**Created:** [November 14, 2025, 12:21pm UTC](https://root-forum.cern.ch/t/proper-handling-of-custom-classes-implementing-a-fill-method-with-rdataframes/64406 "2025-11-14T12:21:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![asopio](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/asopio/32/39632_2.png) [@asopio](https://root-forum.cern.ch/u/asopio)\
**Post date:** [November 14, 2025, 12:21pm UTC](https://root-forum.cern.ch/t/proper-handling-of-custom-classes-implementing-a-fill-method-with-rdataframes/64406/1 "2025-11-14T12:21:11Z")

</div>

Dear ROOT experts,

I have a question concerning the design philosophy of custom object fills using RDataFrames.

I have a program which I have adapted from sinlge-threaded TTree loop to an RDataFrame graph with implicit multithreading. My program defined its own class for computing 2-dimensional sidebands, `SB2x2D`, which implements it’s own `Fill` method that essentially fills a collection of histograms associated with the `SB2x2D` object. I have adapted this class to hold, in addition to the histograms themselves, a `RResultPtr` for each histogram so that the histograms can be initialized using the `RDF::Histo1d` method (wrapped inside another method on `SB2x2D`) during the defintion of the run graph. The `Fill` method on `SB2x2D`then finally collects the `THX` object using `GetValue`, executing the run graph.

I have noticed that this leads to some weird behaviour as soon as I define multiple `SB2x2D` objects in order to fill them, creating a new RDataFrame for each of them. The `RResultPtr` members `SB2x2D` sometimes point to the results of previous fills, unless I explicitly call `RDF_hN_2D.GetSharedPtr().reset();` at the end of `Fill`. I am wondering if this is bad design on my part. The ownership of the `RResultPtr` object is effectively shared between the `RDataFrame` and `SB2x2D`objects, which creates ambiguities whenever either `RDataFrame`s or `SB2x2D`s are created or destroyed. I understand there is a way to create new objects inside the run graph of the `RDataFrame` using the `book` method, to make sure they go out of scope when the RDF is finished – however I have also read that this method is quite limited wrt. the kinds ofobject you can book. In my case, my `SB2x2D` class also includes methods for performing fits on the histograms and is designed to persist between fills. How would you handle this problem? Looking forward to hearing your advice.

Cheers,  
Alex

_ROOT Version:_ 6.36  
_Platform:_ Linux  
_Compiler:_ Not Provided

* * *

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [November 14, 2025, 12:35pm UTC](https://root-forum.cern.ch/t/proper-handling-of-custom-classes-implementing-a-fill-method-with-rdataframes/64406/2 "2025-11-14T12:35:12Z")

</div>

Maybe @vpadulan can help

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [November 28, 2025, 12:36pm UTC](https://root-forum.cern.ch/t/proper-handling-of-custom-classes-implementing-a-fill-method-with-rdataframes/64406/3 "2025-11-28T12:36:01Z")

</div>

Closed on November 28, 2025, 12:36pm UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
