Hello,
I am trying to save an object of a user defined class into a TTree. This class is declared in a namespace and contains a private member which is a std::vector of types that are declared with typedef. If I use typedef to declare the types outside of the namespace, then I have no problems. However, if I use the typedef in the namespace, I have problems saving the object to a TTree. The macro seg. faults when closing the root file.
I have made a simplified macro of what I am doing to hopefully illustrate this problem.
When I use the following macro I have no problems when I run “root -l -b -q testGood.C+” at the prompt:
#include <vector>
#include "TFile.h"
#include "TTree.h"
#include "TObject.h"
typedef Float_t AddressValue_t; //takes 4 bytes
typedef UInt_t AddressIndex_t; //takes 4 bytes
class Address : public TObject
{
private:
std::vector< std::pair<AddressIndex_t, AddressValue_t> > _coordinates;
public:
Address(){};
~Address(){};
ClassDef(Address, 1)
}; //End class Address
void testGood()
{
TFile f_address("address.root","RECREATE");
TTree t_address("t_address","A Tree with Addresses");
Address *address = new Address();
t_address.Branch("Addresses", "Address", &address);
t_address.Fill();
t_address.Write();
f_address.Close();
}
However, when I use the following macro where the typedef is moved into the namespace and run “root -l -b -q testBad.C+” at the prompt, the code seg. faults upon closing:
#include <vector>
#include "TFile.h"
#include "TTree.h"
#include "TObject.h"
namespace acb
{
typedef Float_t AddressValue_t; //takes 4 bytes
typedef UInt_t AddressIndex_t; //takes 4 bytes
class Address : public TObject
{
private:
std::vector< std::pair<acb::AddressIndex_t, acb::AddressValue_t> > _coordinates;
public:
Address(){};
~Address(){};
ClassDef(Address, 1)
}; //End class Address
}//End namespace acb
void testBad()
{
TFile f_address("address.root","RECREATE");
TTree t_address("t_address","A Tree with Addresses");
acb::Address *address = new acb::Address();
t_address.Branch("Addresses", "acb::Address", &address);
t_address.Fill();
t_address.Write();
f_address.Close();
}
Here is the stack trace:
#0 0x000000326fe99fc5 in waitpid () from /lib64/libc.so.6
#1 0x000000326fe3c331 in do_system () from /lib64/libc.so.6
#2 0x00002b6a34fc7aa1 in TUnixSystem::Exec (this=0x2088360, shellcmd=0x27b4e28 “/grid/fermiapp/nova/novagpvm/root/root.5.26.00/etc/gdb-backtrace.sh 27296 1>&2”)
at core/unix/src/TUnixSystem.cxx:1978
#3 0x00002b6a34fc6e23 in TUnixSystem::StackTrace (this=0x2088360) at core/unix/src/TUnixSystem.cxx:2188
#4 0x00002b6a34fc9e5d in TUnixSystem::DispatchSignals (this=0x2088360, sig=kSigSegmentationViolation) at core/unix/src/TUnixSystem.cxx:1106
#5 0x00002b6a34fc9f81 in SigHandler (sig=kSigSegmentationViolation) at core/unix/src/TUnixSystem.cxx:350
#6 0x00002b6a34fc0123 in sighandler (sig=11) at core/unix/src/TUnixSystem.cxx:3428
#7
#8 0x00002b6a36f5bf56 in TFile::WriteStreamerInfo (this=0x7fff8b233980) at io/io/src/TFile.cxx:2521
#9 0x00002b6a36f5c44d in TFile::Close (this=0x7fff8b233980, option=0x2b6a36cdb540 “”) at io/io/src/TFile.cxx:780
#10 0x00002b6a36cd819b in testBad () at /afs/fnal.gov/files/data/nova/d26/pawloski/AddressClassifier/test/./testBad.C:34
#11 0x00002b6a36cd822e in G__testBad_C_ACLiC_dict__0_1625 (result7=0x7fff8b23fe60, funcname=0x26d4ed0 “\001”, libp=0x7fff8b235450, hash=0)
at /afs/fnal.gov/files/data/nova/d26/pawloski/AddressClassifier/test/./testBad_C_ACLiC_dict.cxx:421
#12 0x00002b6a358328fb in Cint::G__ExceptionWrapper (funcp=0x2b6a36cd8212 <G__testBad_C_ACLiC_dict__0_1625>, result7=0x7fff8b23fe60, funcname=0x26d4ed0 “\001”,
libp=0x7fff8b235450, hash=0) at cint/cint/src/Api.cxx:385
#13 0x00002b6a35927ed3 in G__execute_call (result7=0x7fff8b23fe60, libp=0x7fff8b235450, ifunc=0x26d4ed0, ifn=0) at cint/cint/src/newlink.cxx:2332
#14 0x00002b6a3592d6cb in G__call_cppfunc (result7=0x7fff8b23fe60, libp=0x7fff8b235450, ifunc=0x26d4ed0, ifn=0) at cint/cint/src/newlink.cxx:2518
#15 0x00002b6a358e3f65 in G__interpret_func (result7=0x7fff8b23fe60, funcname=0x1fba5c0 “testBad”, libp=0x7fff8b235450, hash=711, p_ifunc=0x26d4ed0, funcmatch=1,
memfunc_flag=0) at cint/cint/src/ifunc.cxx:5240
#16 0x00002b6a358d1a82 in G__getfunction (item=0x1f87080 “testBad()”, known3=0x7fff8b240378, memfunc_flag=0) at cint/cint/src/func.cxx:2639
#17 0x00002b6a358963d1 in G__getitem (item=0x1f87080 “testBad()”) at cint/cint/src/expr.cxx:1894
#18 0x00002b6a358ac97e in G__getexpr (expression=0x24b4860 “testBad()”) at cint/cint/src/expr.cxx:1464
#19 0x00002b6a358ae615 in G__calc_internal (exprwithspace=0x1f78710 “testBad()”) at cint/cint/src/expr.cxx:1066
#20 0x00002b6a3595ba44 in G__process_cmd (line=0x20dbaa8 “.X /grid/fermiapp/nova/novagpvm/root/root.5.26.00/etc/plugins/TVirtualStreamerInfo/P010_TStreamerInfo.C”,
prompt=0x208dac8 “”, more=0x208dac0, err=0x7fff8b2453dc, rslt=0x7fff8b245370) at cint/cint/src/pause.cxx:2277
#21 0x00002b6a34fb37df in TCint::ProcessLine (this=0x208da90,
line=0x20dbaa8 “.X /grid/fermiapp/nova/novagpvm/root/root.5.26.00/etc/plugins/TVirtualStreamerInfo/P010_TStreamerInfo.C”, error=0x7fff8b2481b4)
at core/meta/src/TCint.cxx:419
#22 0x00002b6a34faa1d6 in TCint::ProcessLineSynch (this=0x208da90,
line=0x20dbaa8 “.X /grid/fermiapp/nova/novagpvm/root/root.5.26.00/etc/plugins/TVirtualStreamerInfo/P010_TStreamerInfo.C”, error=0x7fff8b2481b4)
at core/meta/src/TCint.cxx:486
#23 0x00002b6a34ea60c4 in TApplication::ExecuteFile (file=0x7fff8b246163 “testBad.C+”, error=0x7fff8b2481b4, keep=false) at core/base/src/TApplication.cxx:977
#24 0x00002b6a34ea6244 in TApplication::ProcessFile (this=0x20d2440, file=0x7fff8b246163 “testBad.C+”, error=0x7fff8b2481b4, keep=false) at core/base/src/TApplication.cxx:853
#25 0x00002b6a34ea8edb in TApplication::ProcessLine (this=0x20d2440, line=0x7fff8b246160 “.x testBad.C+”, sync=false, err=0x7fff8b2481b4) at core/base/src/TApplication.cxx:826
#26 0x00002b6a3666962c in TRint::Run (this=0x20d2440, retrn=false) at core/rint/src/TRint.cxx:407
#27 0x000000000040109a in main (argc=1, argv=0x7fff8b248338) at main/src/rmain.cxx:29
Thank you in advance for any assistance.
Update:
It appears that the code will execute fine even if I declare the typedef in the namespace as long as I change how I declare _coordinates.
If I replace the single line:
std::vector< std::pair<acb::AddressIndex_t, acb::AddressValue_t> > _coordinates;
with:
std::vector< std::pair<AddressIndex_t, AddressValue_t> > _coordinates;
then everything works fine. It appears that using the scope operator within the same namespace is causing the trouble. I guess that is the work around.
I discovered that I was using an older version of ROOT 5.26/00. In the later versions, this is fixed, and the problem goes away.