# Reading TClonesArray in JITted RDF

**URL:** <https://root-forum.cern.ch/t/reading-tclonesarray-in-jitted-rdf/45784>\
**Category:** ROOT\
**Tags:** rdataframe\
**Created:** [July 10, 2021, 11:43am UTC](https://root-forum.cern.ch/t/reading-tclonesarray-in-jitted-rdf/45784 "2021-07-10T11:43:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pieterdavid](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pieterdavid/32/19783_2.png) [@pieterdavid](https://root-forum.cern.ch/u/pieterdavid)\
**Post date:** [July 10, 2021, 11:43am UTC](https://root-forum.cern.ch/t/reading-tclonesarray-in-jitted-rdf/45784/1 "2021-07-10T11:43:58Z")

</div>

Hi,  
I am trying to read Delphes trees (with split TClonesArrays) in RDataFrame with JITting, so I think my problem is the JITted version of

> [@Opening TClonesArray from Delphes Branches with RDataFrame](https://root-forum.cern.ch/t/opening-tclonesarray-from-delphes-branches-with-rdataframe/39392):
>
> Hi all, I’m trying to open a TTree created by Delphes with RDataFrames, remove events based on some cut and then write the events that pass the cut into a new TTree with the same format as the previous one. The relevant part of the code is #include \<algorithm\> #include "classes/DelphesClasses.h" #include \<ROOT/RDataFrame.hxx\> #include \<ROOT/RSnapshotOptions.hxx\> #include \<TFile.h\> auto low = ROOT::RDataFrame("Delphes", "inputfile.root") .Define("TruthLeptonPt", TruthLeptonPt, {"GenElec…

This fails:

```python
In [7]: df.Define("leadElPT", "Electron[0].PT")                                                                                                                                                                     
input_line_70:2:53: error: member reference type 'TObject *' is a pointer; did you mean to use '->'?
auto lambda0 = [](TClonesArray& var0){return var0[0].PT
                                             ~~~~~~~ ^
                                                    ->
input_line_70:2:54: error: no member named 'PT' in 'TObject'
auto lambda0 = [](TClonesArray& var0){return var0[0].PT
                                             ~~~~~~~ ^
input_line_74:2:53: error: member reference type 'TObject *' is a pointer; did you mean to use '->'?
auto lambda0 = [](TClonesArray& var0){return var0[0].PT
                                             ~~~~~~~ ^
                                                    ->
input_line_74:2:54: error: no member named 'PT' in 'TObject'
auto lambda0 = [](TClonesArray& var0){return var0[0].PT
                                             ~~~~~~~ ^
---------------------------------------------------------------------------

```

(very similar errors with `Electron[0]->PT`, then it’s just the missing attributes instead of `.` for a pointer).  
This works, but it’s a bit cumbersome…

```python
ROOT.gInterpreter.Declare("using delphes_electron = Electron;")
df.Define("leadElPT", "dynamic_cast<delphes_electron*>(Electron[0])->PT")

```

If there’s an easy way to define `RVec<Electron>` or `RVec<Electron*>` columns that’s probably good enough as a workaround, but my first attempts to find something for that failed.  
Do you have any suggestions?

Thanks,  
Pieter

* * *

_ROOT Version:_ 6.24/00  
_Platform:_ LCG\_100 (x86\_64-centos7-gcc10-opt) on lxplus  
_Compiler:_ GCC 10

* * *

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [July 12, 2021, 9:59am UTC](https://root-forum.cern.ch/t/reading-tclonesarray-in-jitted-rdf/45784/2 "2021-07-12T09:59:15Z")

</div>

Hi Pieter,  
if I understand correctly RDF correctly reads `Electron` as a `TClonesArray` branch.  
The problem is really that `TClonesArray`, being type-erased like all ROOT collections, has a clunky API: it requires that you downcast its elements from `TObject` to their actual types.  
That’s fairly different from [Opening TClonesArray from Delphes Branches with RDataFrame](https://root-forum.cern.ch/t/opening-tclonesarray-from-delphes-branches-with-rdataframe/39392) where RDF was not able to read `TClonesArray` branches at all (that was an I/O problem, this is an API problem).

Now naturally, you’d like RDF to perform an on-the-fly conversion from `TClonesArray` to a friendlier type such as `RVec<Electron>`. I think that would be a nice improvement – although I am not sure at this point if we could make that happen a) in a backward-compatible way and b) without a copy of the array elements.

As an aside you should be able to use a `static_cast` instead of a `dynamic_cast` for your workaround.

Can you please open a request for improvement at [github.com/root-project/root/issues](http://github.com/root-project/root/issues) ? I will see what we can do about this.

Cheers,  
Enrico

---

<div class="post-metadata">

**Author:** ![pieterdavid](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pieterdavid/32/19783_2.png) [@pieterdavid](https://root-forum.cern.ch/u/pieterdavid)\
**Post date:** [July 12, 2021, 10:34am UTC](https://root-forum.cern.ch/t/reading-tclonesarray-in-jitted-rdf/45784/3 "2021-07-12T10:34:59Z")

</div>

Hi Enrico,  
Thanks for the explanation! I see the difference now. I looked a bit more into `TClonesArray`, and I think I can define `RVec<Electron*>` columns (copying the pointers, or maybe even reusing the underlying array) with a helper function in the framework or analysis code, so that should be fine as a solution. I’m also checking with my colleagues because it’s not clear yet if we will use the Delphes trees directly or a reduced flat tree format, so it’s not very urgent; I’ll open an issue in any case.  
Thanks,  
Pieter

---

<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:** [July 26, 2021, 10:35am UTC](https://root-forum.cern.ch/t/reading-tclonesarray-in-jitted-rdf/45784/4 "2021-07-26T10:35:12Z")

</div>

Closed on July 26, 2021, 10:35am UTC

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