Hi,
I have written a class that i would like to add to a tree (including doing the necessary rootcint, etc to make the dictionaries). I can do this if i am adding a single object from the class, but if i try to add multiple members of this class in a loop by using elements of a vector, the code segfaults. Here is a schematic example, if i need to add more detail and the real scripts, please let me know.
in MyAlg.h:
std::vector<MyClass *> *m_classVect;
MyClass *m_classElement;
TTree *m_nt;
in MyAlg.cxx, the following works:
m_nt = new TTree(TString(ntupleTreeName), “Cosmics”);
m_classElement = new MyClass();
m_nt->Bronch(TString(name+ “.”), “MyClass”,
&m_classElement,bsize,split);
But this segfaults:
m_nt = new TTree(TString(ntupleTreeName), “Cosmics”);
m_classVect = new std::vector< MyClass * >;
for(int i = 0; i< m_trackCollKeys.size(); i++){
m_classVect->push_back(new MyTrackColl());
m_nt->Bronch(TString(m_trackCollKeys[i]+ “.”), “MyClass”,
&m_classVect[i],bsize,split);
}
The segfault that occurs is:
0xffffe600
0xf65fc128 _ZN5TTree17BuildStreamerInfoEP6TClassPv + 0x34 [/common/atlas/kits/14.5.0/LCGCMT/LCGCMT_55b/InstallArea/i686-slc4-gcc34-opt/lib/libTree.so]
0xf65fc37e _ZN5TTree6BronchEPKcS1_Pvii + 0x106 [/common/atlas/kits/14.5.0/LCGCMT/LCGCMT_55b/InstallArea/i686-slc4-gcc34-opt/lib/libTree.so]
0xe7736ffd _ZN14CosNtupleMaker10BookNtupleEv + 0x4ad [/u/tompkins/testareaSL4/14.5.0.5/InstallArea/i686-slc4-gcc34-opt/lib/libHalfTrackDetective.so]
0xe7737f5f _ZN14CosNtupleMaker10initializeEv + 0xc3f [/u/tompkins/testareaSL4/14.5.0.5/InstallArea/i686-slc4-gcc34-opt/lib/libHalfTrackDetective.so]
Also, at the end of MyClass.h I’ve added:
#ifdef MAKECINT
#pragma link C++ vector<MyTrackColl*>;
#endif
I’m wondering if somehow i’m missing dictionaries for the vector or something? This happens both when i run inside of root or when i run outside with compiled c++ code (the segfault is an example of the later).
thanks for your time!
~lauren