Problems with C++ std::vector and branches in TTree

Hello all,
I have to write a macro that

  1. reads a TTree, in a ROOT file, which is made of branches whose elements are simple numbers and some other whose elements are std::vector, both Int_t and Double_t;
  2. searches for some conditions and in case do some operations and write to ANOTHER TTree, within the same ROOT file, in form of std::vector.

In this macro I included as dictionary for CINT. when I read the first TTree I use

std::vector<Vec_type> vec_name1; 
T1->SetBranchAddress("branch_name1", &vec_name1);

where “branch_name” is a branch in which the elements are std::vector.
In creating the vectors that will be the entries for the branches of the new TTree I use

std::vector<Vec_type> vec_name2;
T2->Branch("branch_name2",& vec_name2);

where the numbers 1 and 2 after branch and vec name indicates the fact that they belong to the first or second TTree of the ROOT file.

Then I simply put
T2->Fill();
file_ptr->Write();
to fill the new TTree and write the new file.
Unfortunately when I try to plot branches initiating a TBrowser I get empty canvases, when I try to Scan the new TTree I get this segmentation fault signal:

(no debugging symbols found)
Using host libthread_db library "/lib/tls/libthread_db.so.1".
Attaching to program: /proc/2152/exe, process 2152
(no debugging symbols found)...done.
[Thread debugging using libthread_db enabled]
[New Thread -1208285504 (LWP 2152)]
(no debugging symbols found)...done.
(no debugging symbols found)...done.
(no debugging symbols found)...done.
(no debugging symbols found)...done.
(no debugging symbols found)...done.
(no debugging symbols found)...done.
(no debugging symbols found)...done.
0x00b2a7a2 in _dl_sysinfo_int80 () from /lib/ld-linux.so.2
#1  0x069dc7d3 in __waitpid_nocancel () from /lib/tls/libc.so.6
#2  0x06986649 in do_system () from /lib/tls/libc.so.6
#3  0x00a128bd in system () from /lib/tls/libpthread.so.0
#4  0x0041ff07 in TUnixSystem::Exec () from /disk3/sw/root/5.22.00/lib/libCore.so
#5  0x00425b9f in TUnixSystem::StackTrace () from /disk3/sw/root/5.22.00/lib/libCore.so
#6  0x0042259a in TUnixSystem::DispatchSignals () from /disk3/sw/root/5.22.00/lib/libCore.so
#7  0x00422628 in SigHandler () from /disk3/sw/root/5.22.00/lib/libCore.so
#8  0x004218a5 in sighandler () from /disk3/sw/root/5.22.00/lib/libCore.so
#9  <signal handler called>
#10 0x008e2bb5 in std::fill_n<double*, unsigned int, double> () from /disk3/sw/root/5.22.00/lib/libMathCore.so
#11 0x008e36cc in std::vector<double, std::allocator<double> >::_M_fill_insert () from /disk3/sw/root/5.22.00/lib/libMathCore.so
#12 0x0098790d in std::vector<double, std::allocator<double> >::insert () from /disk3/sw/root/5.22.00/lib/libMathCore.so
#13 0x0098748b in std::vector<double, std::allocator<double> >::resize () from /disk3/sw/root/5.22.00/lib/libMathCore.so
#14 0x009873d5 in std::vector<double, std::allocator<double> >::resize () from /disk3/sw/root/5.22.00/lib/libMathCore.so
#15 0x00987bb0 in ROOT::TCollectionProxyInfo::Pushback<std::vector<double, std::allocator<double> > >::resize () from /disk3/sw/root/5.22.00/lib/libMathCore.so
#16 0x06d7591c in TGenCollectionStreamer::ReadPrimitives () from /disk3/sw/root/5.22.00/lib/libRIO.so
#17 0x06d77eb7 in TGenCollectionStreamer::Streamer () from /disk3/sw/root/5.22.00/lib/libRIO.so
#18 0x06d4e92d in TCollectionStreamer::Streamer () from /disk3/sw/root/5.22.00/lib/libRIO.so
#19 0x06d4f343 in TCollectionClassStreamer::operator() () from /disk3/sw/root/5.22.00/lib/libRIO.so
#20 0x003e2ea6 in TClass::Streamer () from /disk3/sw/root/5.22.00/lib/libCore.so
#21 0x06d4970b in TBufferFile::ReadFastArray () from /disk3/sw/root/5.22.00/lib/libRIO.so
#22 0x06e049af in TStreamerInfo::ReadBuffer<char**> () from /disk3/sw/root/5.22.00/lib/libRIO.so
#23 0x02b51f6b in TBranchElement::ReadLeaves () from /disk3/sw/root/5.22.00/lib/libTree.so
#24 0x02b4c5fc in TBranch::GetEntry () from /disk3/sw/root/5.22.00/lib/libTree.so
#25 0x02b4e89b in TBranchElement::GetEntry () from /disk3/sw/root/5.22.00/lib/libTree.so
#26 0x0276e4ba in TTreeFormula::LoadCurrentDim () from /disk3/sw/root/5.22.00/lib/libTreePlayer.so
#27 0x0277a981 in TTreeFormulaManager::GetNdata () from /disk3/sw/root/5.22.00/lib/libTreePlayer.so
#28 0x0276c147 in TTreeFormula::GetNdata () from /disk3/sw/root/5.22.00/lib/libTreePlayer.so
#29 0x02788d7e in TTreePlayer::Scan () from /disk3/sw/root/5.22.00/lib/libTreePlayer.so
#30 0x02b9a1eb in TTree::Scan () from /disk3/sw/root/5.22.00/lib/libTree.so
#31 0x02bc5332 in G__G__Tree_109_0_144 () from /disk3/sw/root/5.22.00/lib/libTree.so
#32 0x00b7ebd7 in Cint::G__ExceptionWrapper () from /disk3/sw/root/5.22.00/lib/libCint.so
#33 0x00c13adc in G__execute_call () from /disk3/sw/root/5.22.00/lib/libCint.so
#34 0x00c13dee in G__call_cppfunc () from /disk3/sw/root/5.22.00/lib/libCint.so
#35 0x00bf4a1f in G__interpret_func () from /disk3/sw/root/5.22.00/lib/libCint.so
#36 0x00be3410 in G__getfunction () from /disk3/sw/root/5.22.00/lib/libCint.so
#37 0x00cc79fd in G__getstructmem () from /disk3/sw/root/5.22.00/lib/libCint.so
#38 0x00cbf4f3 in G__getvariable () from /disk3/sw/root/5.22.00/lib/libCint.so
#39 0x00bc7412 in G__getitem () from /disk3/sw/root/5.22.00/lib/libCint.so
#40 0x00bc78a5 in G__getitem () from /disk3/sw/root/5.22.00/lib/libCint.so
#41 0x00bca3a7 in G__getexpr () from /disk3/sw/root/5.22.00/lib/libCint.so
#42 0x00c400bc in G__exec_statement () from /disk3/sw/root/5.22.00/lib/libCint.so
#43 0x00bb552c in G__exec_tempfile_core () from /disk3/sw/root/5.22.00/lib/libCint.so
#44 0x00bb6867 in G__exec_tempfile_fp () from /disk3/sw/root/5.22.00/lib/libCint.so
#45 0x00c4f790 in G__process_cmd () from /disk3/sw/root/5.22.00/lib/libCint.so
#46 0x0040e1af in TCint::ProcessLine () from /disk3/sw/root/5.22.00/lib/libCore.so
#47 0x00346eaa in TApplication::ProcessLine () from /disk3/sw/root/5.22.00/lib/libCore.so
#48 0x0011e1b3 in TRint::HandleTermInput () from /disk3/sw/root/5.22.00/lib/libRint.so
#49 0x0011c684 in TTermInputHandler::Notify () from /disk3/sw/root/5.22.00/lib/libRint.so
#50 0x0011ead2 in TTermInputHandler::ReadNotify () from /disk3/sw/root/5.22.00/lib/libRint.so
#51 0x0041e892 in TUnixSystem::CheckDescriptors () from /disk3/sw/root/5.22.00/lib/libCore.so
#52 0x00422a78 in TUnixSystem::DispatchOneEvent () from /disk3/sw/root/5.22.00/lib/libCore.so
#53 0x0039f788 in TSystem::InnerLoop () from /disk3/sw/root/5.22.00/lib/libCore.so
#54 0x0039f54f in TSystem::Run () from /disk3/sw/root/5.22.00/lib/libCore.so
#55 0x0034702a in TApplication::Run () from /disk3/sw/root/5.22.00/lib/libCore.so
#56 0x0011cf6a in TRint::Run () from /disk3/sw/root/5.22.00/lib/libRint.so
#57 0x08048d46 in main ()

Can anyone help me?
Thank you for helping me.
PS I’m running on a ROOT v5.22/00 with SLC v4.5

Hi,

can you give us (or me via personal mail) access to one of the broken files?

Cheers, Axel.

hi axel,
of course I can, i’m attaching one of these files
in this file you will find two trees one named T and the other named W.
The first one is the tree that I read and analyze, the second one is the one I’m having some problems with.
thank you for helping me
cheers,
Davide
singlearmpruned.0001.root (269 KB)

Hi,

I can look at the tree called T without problems with a TBrowser with the current trunk. W is empty. Is that expected?

Cheers, Axel.

no it’s not supoposed. it’s supposed to be filled.
However I’ve already solved this problem.
I’m sorry that I’ve asked to you for help but the fact is that I’ve declared a branch in a wrong way, and since it is the first branch of the second tree probably this is what messed up all writing operations, moreover, since it was the first I couldn’t see what difference did it make with respect to the other branches, for example if this branch would have been the fourth one I would be able to read the first three branches but not the fourth and the followers, and this could make me solve my problem.

Anyway, i apologyze again for wasting your time, thank you so much for the help and for your kindness.
Cheers, Davide

Hi Davide,

no problem - these things happen. Glad you found it.

Cheers, Axel.