# RDataFrame with user-defined object columns containing RVec as class members

**URL:** <https://root-forum.cern.ch/t/rdataframe-with-user-defined-object-columns-containing-rvec-as-class-members/43232>\
**Category:** ROOT\
**Tags:** rdataframe\
**Created:** [January 24, 2021, 12:44am UTC](https://root-forum.cern.ch/t/rdataframe-with-user-defined-object-columns-containing-rvec-as-class-members/43232 "2021-01-24T00:44:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Massimo\_Girola](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/massimo_girola/32/20527_2.png) [@Massimo\_Girola](https://root-forum.cern.ch/u/Massimo_Girola)\
**Post date:** [January 24, 2021, 12:44am UTC](https://root-forum.cern.ch/t/rdataframe-with-user-defined-object-columns-containing-rvec-as-class-members/43232/1 "2021-01-24T00:44:40Z")

</div>

Hi experts,  
I am analyzing some data using RDataFrame and I encountered a problem:  
I am trying to extract some info from my data and I’d like to use Define to produce a TTree with branches and leaves (I want the leaves to be both containers (RVec) and normal types).  
So I have tried to create both a class and a typedef struct to define columns but in my final TTree RVecs are also treated like objects and so in the TBrowser they appear as subbranches of my class and I also can see some of their methods (?) (I hope the screenshot will clarify). What I expected was just to see them as if I was just defining normal RVec columns or any other collection type associated to a contiguous storage in memory.

 ![Schermata da 2021-01-24 01-17-49](https://root-forum.cern.ch/uploads/default/original/3X/9/0/90eb8e1528f8da2080c9f2737176313845680b93.png)  
Here is the code I am using:

```auto
TUPLE_WITH_8_RVEC_DOUBLE analyze ( ROOT::VecOps::RVec<int> v ){
/*my calculation*/
}
class myClass
{
	public:
		int Nup;
		int Ndwn;
		ROOT::VecOps::RVec<double> timeUp;
		ROOT::VecOps::RVec<double> timeDwn;
};

int main(int argc, char** argv){
//code to obtain input directories...
    gInterpreter->Declare("class myClass { public: int Nup; int Ndwn; ROOT::VecOps::RVec<double> timeUp; ROOT::VecOps::RVec<double> timeDwn; };");
	auto g = [=]( TUPLE_WITH_8_RVEC_DOUBLE WVF_dec )->myClass{ 
		myClass a;
		a.Nup = (int)get<0>(WVF_dec).size();  
		a.Ndwn = (int)get<1>(WVF_dec).size(); 
		a.timeUp = get<2>(WVF_dec);
		a.timeDwn = get<3>(WVF_dec);
		return a; };
	
ROOT::EnableImplicitMT();
	ROOT::RDataFrame d(treeInName.c_str(), rootIn.c_str());
    auto d0 = d.Define("WVFdecoded" , []( ROOT::VecOps::RVec<int> ADC_ch ){ return analyze(ADC_ch); }, {"ch0"} ) 
			   .Define("ch00" , g , {"WVFdecoded" } );
	d0.Snapshot(treeOutName.c_str(), rootOut.c_str(), {"event","ch00"});
    return 0;
}

```

The easiest way out would be to give up using myClass and just call each column with a prefix but I think it would be more general using branches and leaves so I would appreciate any help to solve this.  
Thanks in advance.

* * *

_ROOT Version:_ 6.22/07  
_Platform:_ Ubuntu 20.10  
_Compiler:_ GCC 10.2.0

* * *

---

<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:** [January 25, 2021, 9:08am UTC](https://root-forum.cern.ch/t/rdataframe-with-user-defined-object-columns-containing-rvec-as-class-members/43232/2 "2021-01-25T09:08:11Z")

</div>

Hi Massimo,  
I’m not sure I understand the issue, that’s the typical behavior of TBrowser when objects are written to file – you should see the data when you double-click on `timeUp.fData`. If you write RVecs “directly”, i.e. not as data members of your class, you should see the same kind of TBrowser output.

If you want to see fewer levels of branching you can try playing with the `fSplitLevel` attribute of [RSnapshotOption](https://root.cern/doc/master/structROOT_1_1RDF_1_1RSnapshotOptions.html#a9fb5a5db5880f744da7b8a42209d0d16) (which you can pass to `Snapshot` to configure its behavior). [Searching for “splitlevel” here](https://root.cern/doc/master/classTTree.html) should provide some more context.

Alternatively, you can simply use a size/array pair, such as `int Nup; double *timeUp` as data members of `myClass`.

As a side-note, we are going to introduce some optimizations in RVec soon that will change their data layout. We will of course do our very best to not break RVec I/O across ROOT versions (if that should ever happen, please report it as a bug) – just a heads-up that you might see slightly different output from TBrowser in v6.24 or v6.26.

Cheers,  
Enrico

---

<div class="post-metadata">

**Author:** ![Massimo\_Girola](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/massimo_girola/32/20527_2.png) [@Massimo\_Girola](https://root-forum.cern.ch/u/Massimo_Girola)\
**Post date:** [January 31, 2021, 2:48pm UTC](https://root-forum.cern.ch/t/rdataframe-with-user-defined-object-columns-containing-rvec-as-class-members/43232/3 "2021-01-31T14:48:53Z")

</div>

I think that the fSplitLevel is what I was looking for, thanks a lot!  
Btw if I write my RVecs “directly” I see a totally different behaviour: I do not see the RVecName.fData leaf and, assuming I have both RVec data and ints I just see the following leaves structure:  
leaf #1: RVecName.RVecName  
leaf#2: intName  
leaf#3: …  
…  
and so on. I can post a pic of the TBrowser also in this case if you want.  
Probably I am just not understanding how ROOT treats these type of data, I’m sorry.  
Anyway now everything seems to work as I wanted to so thanks a lot!

---

<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:** [February 14, 2021, 2:49pm UTC](https://root-forum.cern.ch/t/rdataframe-with-user-defined-object-columns-containing-rvec-as-class-members/43232/4 "2021-02-14T14:49:09Z")

</div>

Closed on February 14, 2021, 2:49pm UTC

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