I’ve created a Class of Event objects which contains elements of Class station (1 element):
class Event
{
private:
public:
Station stations[NSTATIONS];
which contains elements of class Module (4 elements)
class Station
{
private:
public:
int position;
Module modules[NMODULES_PERSTATION];
which contains a vector of Stubs elements
class Module
{
private:
public:
vector<Stub> stubs;
I would like to have a TTree filled with Event objects, with of course all the other class members in the branches (station[1], modules[4], stubs[N, dynamically filled]).
I’ve succeeded to create the dictionary for all the classes with rootcling and also the .so shared library (following this suggestion Error in <TTree::Branch> - Vector issue - #9 by dpiparo) but the problem is that in my tree I have only 1 Station (and there is Station [1]) and 4 modules, but the 4 modules are not displayed, as shown in the picture.
Anyone knows why this could happen? Could it be a problem of copy constructors, move assignment operator or other c++ classes stuff? Of course I can give more details on the classes if needed-
Thank you so much for any help
This is how I generate the .root file and the tree
I say that it can be c++ classes stuff issue because when I was trying to generate the dictionary I’ve tried the MakeProject() function and It gave as an error the following:
MyProjectProjectSource.cxx: In copy constructor ‘Station::Station(const Station&)’:
MyProjectProjectSource.cxx:60:39: error: use of deleted function ‘Module& Module::operator=(const Module&)’
for (Int_t i=0;i<4;i++) modules[i] = rhs.modules[i];
^
In file included from Station.h:13:0,
from Event.h:13,
from MyProjectProjectHeaders.h:1,
from MyProjectProjectSource.cxx:3:
Module.h:23:7: note: ‘Module& Module::operator=(const Module&)’ is implicitly declared as deleted because ‘Module’ declares a move constructor or move assignment operator
class Module {
^
c++: error: MyProjectProjectSource.o: File o directory non esistente
Error in <TUnixSystem::FindDynamicLibrary>: MyProject/MyProject.so does not exist in /usr/lib64/root:.:/usr/lib64/root:/lib64/tls/x86_64:/lib64/tls:/lib64/x86_64:/lib64:/usr/lib64/tls/x86_64:/usr/lib64/tls:/usr/lib64/x86_64:/usr/lib64
Sorry, I missed replying to this topic. The TBrowser view shows only TTree branches (i.e., data columns). Holding a fixed-size array as part of each entry does not create more columns; it just makes the nested columns contain N values for each entry.
In your particular use case, for each Station, the modules member will hold 4 values for each of the columns that Module is decomposed to - but the number of data columns is still the same.
Actually, if you try to read the TTree (see below), you will get the expected results:
std::unique_ptr<TFile> f(TFile::Open("file.root"));
auto tree = f->Get<TTree>("tree");
Event *CurrentEvent = nullptr;
tree->SetBranchAddress("Event", &CurrentEvent);
for (int i = 0; tree->LoadTree(i) >= 0; ++i) {
tree->GetEntry(i);
// do something with `CurrentEvent` here...
}
Also, if not all the entries contain exactly 4 instances of Module, note that TTree also supports variable-length arrays using the //[numer_of_elements] notation as part of the class definition. For more information, see Chapter: InputOutput, section 13.3.4 Variable Length Array.