Elementary problem with variable length arrays

I don’t understand why I can’t manage to have a tree with working variable length array.

I tried to follow the Event example and tried to write a very simple program to use a variable length array of Int_t but root complains when trying to access the variable length array
in an interactive session.

The tar file attached contains all the files of my working directory (very short code)
simple_event.h contains class definition
simple_event.cxx is the implementation of a method of class simple_event to fill the variable length array
build_simple_root.cxx builds a root file containing a tree built with simple_event class
make_simple is the makefile I use to compile the code (generating the dictionary, and a dinamically linkable file from the dictionary and the class implementation)

root complains with commands like

where t is the tree built by my program and hits is the branch with the variable length array.

Many thanks for any suggestion.

archive.tar (130 KB)


Use an Int_t (instead of UInt_t) for the counter (i.e hits_num).


I tried.
I substituted all the UInt_t with Int_t in my class definition and implementation;
it still doesn’t work.
Could it be something to do with the generation of the dictionary, the pragma directives?!


As indicated by Philippe, change
UInt_t hist_num
Int_t hist_num

then compile/link with
rootcint -f simple_event_dict.cxx -c simple_event.h provaLinkDef.h
g++ -O -Wall -fPIC root-config --cflags -o simple_event_dict.o -c simple_event_dict.cxx
g++ -O -Wall -fPIC root-config --cflags -o simple_event.o -c simple_event.cxx
g++ -shared -O simple_event.o simple_event_dict.o -o simple_event_dll.so
g++ -O -Wall -fPIC root-config --cflags -o build_simple_root.o -c build_simple_root.cxx
g++ build_simple_root.o simple_event_dll.so root-config --libs -o build_simple_root

Then produce the data file with:
build_simple_root junk.root

Then run a Root session
root [0] TFile f(“junk.root”)
root [1] TTree T=(TTree)f.Get(“Albero eventi”)
root [2] T.Draw(“hits”)



Thanks, Philippe and Rene.

Indeed to use Int_t was necessary (anyway my instinct would be to use an unsigned int as an array index).

My second post saying it was still not working was due to an overlapping mistake I did; before opening the file in the root session I called:
'cause root was warning for the absence of the dictionary.
And if you do that it causes a segmentation violation:
/usr/local/gcc-alt-3.2/bin/c++filt: unknown demangling style 'gnu-new-abi’
If I don’t load that dll, it works (with your correction).
So my simple_event_dll.so is not doing a good job.

Many thanks indeed.


PS: I recently started using ROOT and I find it amazing.