Write nested vector to TTree

Dear experts,

I am trying to write a nested vector into TTree using the following (the original .cpp script is here: DUNE_ND_GeoEff/runGeoEffFDEvtSim.cpp at FD_Wei · weishi10141993/DUNE_ND_GeoEff · GitHub):

gInterpreter->GenerateDictionary("vector<vector<vector<uint64_t>>>", "vector");
vector<vector<vector<uint64_t>>> HadronContainThrowResultList;
TTree * effTreeFD = new TTree("effTreeFD", "FD eff Tree");
effTreeFD->Branch("HadronContainThrowResultList", &HadronContainThrowResultList);

The nested vector HadronContainThrowResultList is returned from this function: DUNE_ND_GeoEff/geoEff.cpp at FD_Wei · weishi10141993/DUNE_ND_GeoEff · GitHub

The .cpp code compiles fine, but when running the executable, it reports error below and it seems the generated dictionary for the nested vector above didn’t work well. I wonder if there is an easy fix for this?

*** Break *** segmentation violation
#5  0x00007f584d688b84 in std::vector<float, std::allocator<float> >::resize(unsigned long) () from /cvmfs/larsoft.opensciencegrid.org/products/root/v6_12_06a/Linux64bit+3.10-2.17-e15-prof/lib/libRIO.so.  
#6  0x00007f584d68991d in int TStreamerInfoActions::VectorLooper::ReadCollectionBasicType<float>(TBuffer&, void*, TStreamerInfoActions::TConfiguration const*) () from /cvmfs/larsoft.opensciencegrid.org/products/root/v6_12_06a/Linux64bit+3.10-2.17-e15-prof/lib/libRIO.so
#7  0x00007f584d5f92e8 in TBufferFile::ApplySequence(TStreamerInfoActions::TActionSequence const&, void*) () from /cvmfs/larsoft.opensciencegrid.org/products/root/v6_12_06a/Linux64bit+3.10-2.17-e15-prof/lib/libRIO.so
#8  0x00007f584c236c67 in TBranchElement::ReadLeavesMember(TBuffer&) () from /cvmfs/larsoft.opensciencegrid.org/products/root/v6_12_06a/Linux64bit+3.10-2.17-e15-prof/lib/libTree.so
#9  0x00007f584c22e776 in TBranch::GetEntry(long long, int) () from /cvmfs/larsoft.opensciencegrid.org/products/root/v6_12_06a/Linux64bit+3.10-2.17-e15-prof/lib/libTree.so
#10 0x00007f584c23cdde in TBranchElement::GetEntry(long long, int) () from /cvmfs/larsoft.opensciencegrid.org/products/root/v6_12_06a/Linux64bit+3.10-2.17-e15-prof/lib/libTree.so
#11 0x00007f584c26b6ed in TTree::GetEntry(long long, int) () from /cvmfs/larsoft.opensciencegrid.org/products/root/v6_12_06a/Linux64bit+3.10-2.17-e15-prof/lib/libTree.so
#12 0x0000000000403a72 in main ()

Thanks,
Wei

PS if I remove the line “gInterpreter->GenerateDictionary…”, it reports the error

Error in <TTree::Branch>: The class requested (vector<vector<vector<unsigned long> > >) for the branch "HadronContainThrowResultList" is an instance of an stl collection and does not have a compiled CollectionProxy. Please generate the dictionary for this collection (vector<vector<vector<unsigned long> > >) to avoid to write corrupted data.

ROOT Version: v6_12_06a
_Platform:CentOS7
_Compiler:gcc v6_4_0


Try with:

if (!(gInterpreter->IsLoaded("vector")))
  gInterpreter->ProcessLine("#include <vector>");
gSystem->Exec("rm -f AutoDict*vector*vector*vector*unsigned*long*");
gSystem->Exec("rm -f AutoDict*vector*vector*vector*uint64_t*");
// gInterpreter->GenerateDictionary("vector<vector<vector<unsigned long> > >", "vector");
gInterpreter->GenerateDictionary("vector<vector<vector<uint64_t> > >", "vector");

Hi Wile,

Thanks, I tried this, it seems to report similar segment violations as before. Any other solutions?

#5 0x00007f2683f92b84 in std::vector<float, std::allocator<float> >::resize(unsigned long) () from /cvmfs/larsoft.opensciencegrid.org/products/root/v6_12_06a/Linux64bit+3.10-2.17-e15-prof/lib/libRIO.so
#6 0x00007f2683f9391d in int TStreamerInfoActions::VectorLooper::ReadCollectionBasicType<float>(TBuffer&, void*, TStreamerInfoActions::TConfiguration const*) () from /cvmfs/larsoft.opensciencegrid.org/products/root/v6_12_06a/Linux64bit+3.10-2.17-e15-prof/lib/libRIO.so
#7 0x00007f2683f032e8 in TBufferFile::ApplySequence(TStreamerInfoActions::TActionSequence const&, void*) () from /cvmfs/larsoft.opensciencegrid.org/products/root/v6_12_06a/Linux64bit+3.10-2.17-e15-prof/lib/libRIO.so
#8 0x00007f2682b40c67 in TBranchElement::ReadLeavesMember(TBuffer&) () from /cvmfs/larsoft.opensciencegrid.org/products/root/v6_12_06a/Linux64bit+3.10-2.17-e15-prof/lib/libTree.so
#9 0x00007f2682b38776 in TBranch::GetEntry(long long, int) () from /cvmfs/larsoft.opensciencegrid.org/products/root/v6_12_06a/Linux64bit+3.10-2.17-e15-prof/lib/libTree.so
#10 0x00007f2682b46dde in TBranchElement::GetEntry(long long, int) () from /cvmfs/larsoft.opensciencegrid.org/products/root/v6_12_06a/Linux64bit+3.10-2.17-e15-prof/lib/libTree.so
#11 0x00007f2682b756ed in TTree::GetEntry(long long, int) () from /cvmfs/larsoft.opensciencegrid.org/products/root/v6_12_06a/Linux64bit+3.10-2.17-e15-prof/lib/libTree.so
#12 0x0000000000403b12 in main ()

Wei

This error speaks about a “vector<float>”, so you need to debug the code and find which variable it is (and why it happens).

Hi Wile,

I’ve found the bug and everything works now! Thanks a lot!

Wei

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