Hello rooters,
Is it possible to store the object of My own class in ROOT Tree.
When i am trying to do that, i am getting following message while running
Error in TTree::Branch: The pointer specified for InComingTrack is not of a class or type known to ROOT
where inComingTrack is the ojbect of my class, Track.h
Hi Raman, if you are doing this for VecGeom and GeantV, have a look at the CMake system of GeantV, as there are examples there of how to do this in CMake. Search for ROOT_GENERATE_DICTIONARY. Cheers,
Hello,
Now after creating the dictionary for my class, i am able to read data from Root Tree branches that stores object of my class.
But in some branches i have stored some typedef which are defined in my MyDefs.h file and one of which are as follows
typedef std::vector < unsigned int > Channel ;
getting following error Error in TTreeReaderValueBase::CreateProxy(): The template argument type T of T accessing branch TEST_BRANCH (which contains data of type vector) is not known to ROOT. You will need to create a dictionary for it. Error in <Get()>: Value reader not properly initialized, did you remember to call TTreeReader.Set(Next)Entry()?
i think again i have to create dictionary of for the typedefs defined in MyDefs.h
and i don’t know how to write selection.xml for that.
Could you please help me in that.
I also read that the same thing can be done using LinkDef.h file, still no success in that.
I am having a tree that contains branches as follows
branch0 = (vector< unsigned int >)
branch1 = (vector< unsigned int >)
branch2 = (vector< unsigned int >*)
.
.
I have checked that ROOT does not contains dictionaries for such,
I think there are no dictionaries for any types of pointers, (Please correct me if i am wrong at some place.)
so even if i have something like
testbranch = (int *),
i have to create dictionary.
Coming back to my Tree,
i have a typedef like
typedef std::vector< unsigned int > Channel;
So basically the branches are of type ( Channel* )
TDataFrame is really very useful and helpful
Now i want to read the Tree that has branches of type (vector< unsigned int >*) using TDataFrame.
Could you please suggest me how to handle this.
there is nothing like a dictionary of a “pointer type”, only for “types”, i.e. one has a dictionary for the class MyClass and those allow to do I/O for MyClass* as well. What counts is the layout in memory of the MyClass instances (objects).
I am not sure I understand. I propose that you try this:
Hi rasehgal,
thank you for trying TDataFrame. It is a new feature and we need all the feedback we can get.
I can reproduce your problem, I will come back with more info asap.
Hi rasehgal,
you found a bug
We are not dealing correctly with Takeing columns that are themselves collections.
This is now fixed in the master branch and will be fixed in the 6.10-02 patch release, coming very soon – i.e. in the next days. In the meanwhile, as a workaround, you can use Foreach:
// from the prompt (i.e. at global scope)
ROOT::Experimental::TDataFrame d("BSC_DATA_TREE", "hello.root");
std::vector<std::vector<unsigned int>> vecTrack;
d.Range(10,11).Foreach([](std::vector<unsigned int> &b0) { vecTrack.emplace_back(b0); }, {"branch0"});
// from a compiled `main` (we need to capture `vecTrack` from the lambda)
#include "ROOT/TDataFrame.hxx"
int main() {
ROOT::Experimental::TDataFrame d("BSC_DATA_TREE", "hello.root");
std::vector<std::vector<unsigned int>> vecTrack;
d.Range(10,11).Foreach([&vecTrack](std::vector<unsigned int> &b0) { vecTrack.emplace_back(b0); }, {"branch0"});
return 0;
}
A vector<vector>> is not a very performant data structure, so it’s up to you whether you prefer doing something different there
Again thank you for the feedback, and let me know if you have further questions!