Fill a TClonesArray in TTree

Please provide the following information:


ROOT Version (e.g.6.12/04):
Platform, compiler (Linux version 2.6.32-696.20.1.el6.x86_64 (mockbuild@sl6.fnal.gov) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC) ) #1 SMP Thu Jan 25 08:47:49 CST 2018):


Previously I use ROOT 5.28/00c, Now I have update to ROOT 6.12/04
In my code, I have define a class LHEvent, which include secondary TClonesArray, to store the data,
I use “rootcint -f LHEventDict.cc -c LHEvent.h LHEventLinkDef.h “
to produce the file. LHEventDict.cc
In the ROOT 5.28/00c this command can produce two files: LHEventDict.h and LHEventDict.cc
While
in the ROOT 6.12/04 this command can produce two files: LHEventDict_rdict.pcm and LHEventDict.cc
My first question is: what is purpose of the file LHEventDict_rdict.pcm and how to use this file?

In my program, I use the following code to store the data:
LHEvent *event = new LHEvent();
EventTree->Branch(“Event”,“LHEvent”,&event, 32000, 2);
EventTree->SetAutoSave(1000);

event->AddHitE(i,3.2,5.4,j,2);
This works well in the stand alone condition as the attached file Test.tar (180 KB).
While when I use the same method to store the data in my Geant4 program, the program can be compiled, but when I run it I obtain a Segmentation violation:

Error in <TClonesArray::SetClass>: called with a null pointer
Error in <TClonesArray::SetClass>: called with a null pointer
Error in <TClonesArray::SetClass>: called with a null pointer
Error in <TClonesArray::SetClass>: called with a null pointer
Error in <TClonesArray::SetClass>: called with a null pointer
    
    
HitsE 5
Error in <TClonesArray::operator[]>: invalid class specified in TClonesArray ctor

 *** Break *** segmentation violation
===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0  0x00000034142ac82e in waitpid () from /lib64/libc.so.6
#1  0x000000341423e479 in do_system () from /lib64/libc.so.6
#2  0x00007f00646aa8e5 in TUnixSystem::StackTrace() () at /afs/ihep.ac.cn/users/y/ybjx/anysw/repos/tmp_make/root-6.12.04/core/unix/src/TUnixSystem.cxx:2412
#3  0x00007f00646ad00c in TUnixSystem::DispatchSignals(ESignals) () at /afs/ihep.ac.cn/users/y/ybjx/anysw/repos/tmp_make/root-6.12.04/core/unix/src/TUnixSystem.cxx:3643
#4  <signal handler called>
#5  0x00007f00650fee1a in LHEvent::AddHitE(int, double, double, int, int) () from /eos/user/c/chensz/software/G4KM2A4.10/tmp/Linux-g++/G4KM2A/libG4KM2A.so
…
…

I track the code, find this program break in LHEvent.cc at:

event->AddHitE(nDet,pt,pe,t0,pid);
void LHEvent::AddHitE(Int_t p_id, Double_t p_time, Double_t p_pe,Int_t p_np, Int_t p_e){
   cout<<"HitsE 5"<<endl; 
   new((*HitsE)[NhitE++]) LHHit(p_id,p_time,p_pe,p_np,p_e) ;

   cout<<"HitsE 5"<<endl;
}

This code runs well in the previous ROOT 5.28/00c, while it break in ROOT 6.12/04.
My second question is what cause this problem and how solve it in ROOT 6.12/04?

It is part of the dictionary (a more compact form of the information and should be copied alongside the shared library that contain the class implementation).

Error in TClonesArray::SetClass: called with a null pointer

This indicates that the dictionary for the class of the object put into the TClonesArray is not loaded/missing. This is either because the pcm file is not available in LD_LIBRARY_PATH or because the library is missing the dictionary all together. (And if you do not have a shared library then it is likely that the dictionary .o file is not included at all in the executable).

Cheers,
Philippe.

Dear Philippe,
Thank you very much for your reply. Now I understand the difference and I have set the LHEventDict_rdict.pcm into the LD_LIBRARY_PATH, while I still cannot solve this problem. Can you help? Now I test the two methods to compile my simple program. One method is OK, while other is not OK:
My code is attached TestBagSub.tar (1.7 MB)

1: Use a simple compile command (this method is OK):

rootcint –f  $srcpath/LHEventDict.cc -c  $includepath/LHEvent.hh  $includepath LHEventLinkDef.h
g++ -o TestEventBag1 TestEventBag.cc src/LHEvent.cc src/LHEventDict.cc src/AG4Bag.cc -I include `root-config --cflags --libs`

The executable file runs well in this method.

  1. If I use a Makefile to compile. The compile is without no problem, while the executable file will be break during runs. My makefile is compile like this:
g++ -ggdb   -c TestEventBag.cc -o obj/TestEventBag.o -DSCAN -I include/ `root-config --cflags --libs`
rootcint -f src/LHEventDict.cc -c /afs/ihep.ac.cn/users/c/chensz/testevent/TestBag/include/LHEvent.hh /afs/ihep.ac.cn/users/c/chensz/testevent/TestBag/include/LHEventLinkDef.h 
g++ -ggdb   -c src/LHEventDict.cc -o obj/LHEventDict.o -DSCAN -I include/ `root-config --cflags --libs` 
g++ -ggdb   -c src/LHEvent.cc -o obj/LHEvent.o -DSCAN -I include/ `root-config --cflags --libs`  
g++ -ggdb   -c src/AG4Bag.cc -o obj/AG4Bag.o -DSCAN -I include/ `root-config --cflags --libs` 
ar -r obj/TestEventBag.a obj/TestEventBag.o obj/LHEventDict.o obj/LHEvent.o obj/AG4Bag.o  
g++ -o TestEventBag obj/TestEventBag.a `root-config --cflags --libs` -lMinuit -lMatrix

the error information are :

*** Break *** segmentation violation
===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0  0x00000035dfaac82e in waitpid () from /lib64/libc.so.6
#1  0x00000035dfa3e479 in do_system () from /lib64/libc.so.6
#2  0x00007f2f7ee918e5 in TUnixSystem::StackTrace() () at /afs/ihep.ac.cn/users/y/ybjx/anysw/repos/tmp_make/root-6.12.04/core/unix/src/TUnixSystem.cxx:2412
#3  0x00007f2f7ee9400c in TUnixSystem::DispatchSignals(ESignals) () at /afs/ihep.ac.cn/users/y/ybjx/anysw/repos/tmp_make/root-6.12.04/core/unix/src/TUnixSystem.cxx:3643
#4  <signal handler called>
#5  0x00007f2f7edffd69 in TClonesArray::operator[](int) () at /afs/ihep.ac.cn/users/y/ybjx/anysw/repos/tmp_make/root-6.12.04/core/cont/src/TClonesArray.cxx:872
#6  0x0000000000408918 in LHEvent::AddHitE(int, double, double, int, int) () at src/LHEvent.cc:52
#7  0x0000000000407df8 in main () at TestEventBag.cc:24

ar -r obj/TestEventBag.a obj/TestEventBag.o obj/LHEventDict.o obj/LHEvent.o obj/AG4Bag.o

Even-though you ‘could’ make it work with static library (by explicit request one of the symbol from the dictionary when linking the executable), it will be much easier to use a shared library (it will ‘just’ work).

Cheers,
Philippe.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.