Using a custom class function which return a vector<whatever> with TTree::Draw

Hello,
so I’ve been writing my own classes and made all the #pragma … thingy to be able to store them properly in a Tree.
I then implemented some functions returning specific members of my classes and tried to use them with the TTree::Draw command.

Something like

myTree->Draw(“myClass.MyFunction()”,"","")

It works perfctly well for any function returning a member which is of a “basic” type, like an int, a float…

But as soon as I try to return a member of type vector<…> it crashes with this error

Fatal: parent && element violated at line 2669 of `/home/alex/Softwares/root-6.04.14/tree/treeplayer/src/TFormLeafInfo.cxx’
aborting

I have to admit I’m out of ideas.
Any help would be welcome.

Cheers,
Alex

Hi,

We need much more information to debug this: could you provide us with the relevant code and the file?

Cheers, Axel.

Hi Axel,

I will send you the github link when I update it my changes including what causes the error.
For the moment I somehow worked around it by filling a TArray from my vector instead and accessing the fArray member of the resulting TArray.

While I am at it:

I noticed a significant size increase of the rootfile containing the TTree if I store my data in custom classes or as a bunch of vector.

Example:
Filling 6 vector and storing them as is in the TTree generate an output of 6GB for a specific file.
If now I make a class with 2 vector member and storing 3 objects belonging to this class instead, the output file inflate to 12GB.
Is there a reason well known behind this or I am just really bad at optimizing my code?

Thanks

Hi,

The likely cause is that somehow the data is duplicated in the new version. Can you copy/paste the relevant portion of your code or upload a small reproducer?

Cheers,
Philippe.

Dear Axel and Phillip,

I wrote a simple script which reproduces the error I am encountering with the functions returning vector used directly in the Draw command.

You just have to unzip it, build it with cmake and then do a “make install”.
Run the executable with the arguments “-nevents 100000”.
You will get a file called return_vector_issue.root
This file contains a tree with 2 branches.

“MyClass” is a custom class containing
a float member
a vector member
a function returning the float member: GetSimpleMember()
a function returning the vector member: GetVectorMember()
a function dumping the vector in a TArrayF and returning the TArrayF: DumpVectorToArray()

“MyClassVect” is a vector of the same custom class

Open the return_vector_issue.root

gSystem->Load("./libMyClass.so")

Then try

tree->Draw(“MyClass.GetSinpleMember()”,"","") produce the expected result

tree->Draw(“MyClass.GetVectorMember()”,"","") produce the following message
Warning in TSelectorDraw::ProcessFillObject: Not implemented for vector

tree->Draw(“MyClass.DumpVectorToArray()”,"","") produce the following message
Warning in TSelectorDraw::ProcessFillObject: Not implemented for TArrayF

tree->Draw(“MyClassVect.GetSinpleMember()”,"","") produce the expected result

tree->Draw(“MyClassVect.GetVectorMember()”,"","") or
tree->Draw(“MyClassVect[0].GetVectorMember()”,“MyClassVect@.size() > 0”,"") or anything similar
crash with the following error
Fatal: parent && element violated at line 2669 of `/home/alex/Softwares/root-6.04.14/tree/treeplayer/src/TFormLeafInfo.cxx’
aborting

tree->Draw(“MyClassVect.DumpVectorToArray()”,"","") produce the following message
Warning in TSelectorDraw::ProcessFillObject: Not implemented for TArrayF

For the other matter I was mentionning, I tried to reproduce it as well but it seems fine in this small example, so disregard the 2 other files generated. I will see if there is a mistake in the other program which is much more complex or if there is a condition to reproduce the issue that I did not include here.

Thanks,
Alex
returnVector.tar.gz (2.36 KB)

Hello,

so there was no answer to my last message.
Am I doing something incorrectly or is there actually an issue?

Thanks,
Alex