Reading in custom class stored in tree


I have made a stand alone executable that writes an event class, that I wrote, to a tree. When writing the class to the tree it has no problem. I can open the root file and see that the information was stored correctly. However, When I try to read the event from the tree it seg faults (that is again in a stand alone executable).

I have tried with and without creating a shared object with no success.
Below is the back trace of the error. It happens when I call tree->GetEntry(0);

I have followed
in making the associated dictionary’s and linking everything together.
Below below is my make file

Thanks in advance

#0 0x080633b3 in std::__fill_n_a<double*, unsigned int, double> (__first=0x0, __n=3, __value=@0xbfffc8d8) at /usr/include/c++/4.4/bits/stl_algobase.h:758 #1 0x08063363 in std::fill_n<double*, unsigned int, double> (__first=0x0, __n=3, __value=@0xbfffc8d8) at /usr/include/c++/4.4/bits/stl_algobase.h:791 #2 0x080632cc in std::__uninitialized_fill_n<true>::uninitialized_fill_n<double*, unsigned int, double> (__first=0x0, __n=3, __x=@0xbfffc8d8) at /usr/include/c++/4.4/bits/stl_uninitialized.h:204 #3 0x08063223 in std::uninitialized_fill_n<double*, unsigned int, double> (__first=0x0, __n=3, __x=@0xbfffc8d8) at /usr/include/c++/4.4/bits/stl_uninitialized.h:223 #4 0x080630d6 in std::__uninitialized_fill_n_a<double*, unsigned int, double, double> (__first=0x0, __n=3, __x=@0xbfffc8d8) at /usr/include/c++/4.4/bits/stl_uninitialized.h:318 #5 0x08062d71 in std::vector<double, std::allocator<double> >::_M_fill_insert (this=0x8453f40, __position=..., __n=3, __x=@0xbfffc948) at /usr/include/c++/4.4/bits/vector.tcc:397 #6 0x080628be in std::vector<double, std::allocator<double> >::insert (this=0x8453f40, __position=..., __n=3, __x=@0xbfffc948) at /usr/include/c++/4.4/bits/stl_vector.h:851 #7 0x0806243a in std::vector<double, std::allocator<double> >::resize (this=0x8453f40, __new_size=3, __x=0) at /usr/include/c++/4.4/bits/stl_vector.h:557 #8 0x0806e27a in ROOT::TCollectionProxyInfo::Pushback<std::vector<double, std::allocator<double> > >::resize(void*) () #9 0x00f17ac3 in TGenCollectionStreamer::ReadPrimitives(int, TBuffer&) () from /soft/intel/lucid/root/5.26.00/lib/root/ #10 0x00f1ae03 in TGenCollectionStreamer::Streamer(TBuffer&) () from /soft/intel/lucid/root/5.26.00/lib/root/ #11 0x00ef35c7 in TCollectionStreamer::Streamer(TBuffer&, void*, int, TClass*) () from /soft/intel/lucid/root/5.26.00/lib/root/ #12 0x00ef4076 in TCollectionClassStreamer::operator()(TBuffer&, void*) () from /soft/intel/lucid/root/5.26.00/lib/root/ #13 0x0031a016 in TClass::Streamer(void*, TBuffer&, TClass const*) const () from /soft/intel/lucid/root/5.26.00/lib/root/ #14 0x00eef1d7 in TBufferFile::ReadFastArray(void*, TClass const*, int, TMemberStreamer*, TClass const*) () from /soft/intel/lucid/root/5.26.00/lib/root/ #15 0x00fa9d54 in int TStreamerInfo::ReadBuffer<char**>(TBuffer&, char** const&, int, int, int, int) () from /soft/intel/lucid/root/5.26.00/lib/root/ #16 0x019b0f22 in TBranchElement::ReadLeaves(TBuffer&) () from /soft/intel/lucid/root/5.26.00/lib/root/ #17 0x019a1442 in TBranch::GetEntry(long long, int) () from /soft/intel/lucid/root/5.26.00/lib/root/ #18 0x019a7be2 in TBranchElement::GetEntry(long long, int) () from /soft/intel/lucid/root/5.26.00/lib/root/ #19 0x019a7b75 in TBranchElement::GetEntry(long long, int) () from /soft/intel/lucid/root/5.26.00/lib/root/ #20 0x019f13b4 in TTree::GetEntry(long long, int) () from /soft/intel/lucid/root/5.26.00/lib/root/ #21 0x019be0bc in TChain::GetEntry(long long, int) () from /soft/intel/lucid/root/5.26.00/lib/root/ #22 0x080739ab in main (argc=4, argv=0xbffff474) at NeutronBuilder.C:225

[code]CXX=$(shell root-config --cxx)
CFLAGS=-c -g -Wall $(shell root-config --cflags) -I./src -I ./include
LDLIBS=$(shell root-config --glibs)
LDFLAGS=$(shell root-config --ldflags)
#SOURCES=./src/ ./src/ ./src/
SOURCES=$(shell ls ./src/.cc)
TEMP=$(shell ls ./src/
TEMP2=$(shell ls ./include/*.hh~)


DICTOBJ = $(addsuffix Dictionary.o, $(DICTNAME))

LIBOBJ = $(addsuffix, $(LIBNAME))

.PHONY: clean get put all test sclean


@echo “Building target” $@ “…”
@echo “Build succeed”

@echo “Compiling” $< “…”
@$(CXX) $(CFLAGS) $< -o $@

@echo “Compiling” $< “…”
@$(CXX) $(CFLAGS) $< -o $@

%Dictionary.o: include/%.hh src/%LinkDef.h
$(ROOTCINT) -f $(patsubst %.o,,$@) -c $^;
$(CXX) -p -fPIC $(CFLAGS) -c $(patsubst %.o,,$@) $(patsubst %.o,%.h,$@) %Dictionary.o src/%.o
$(CXX) root-config --cflags -fPIC -shared -Wl -o $@ $^;

Can you please post the code demonstrating how you’re reading the event out (from the TFile step to GetEntry()), and your class declaration? I assume you’re doing it correctly, but just to be safe!

I found my problem. I had been reading the tree with a Tchain like

That had worked when the tree in “file” had only simple type branches.
Switching to

TFile *inFile =new TFile("file");
TTree *inT = (TTree*) inFile->Get("nameOfTree");

Fixed the problem.

Thank you for the reply.

Hi all,

I had the same problem recently.
I solved it by using:

and this let me still use TChain’s.
Could please any expert comment?



The two problem mentioned here seems unrelated. For both of them I would need more input (more information about the original code) to decipher what might be wrong.