TSelector with dynamically allocated memory

I wrote a class deriving from TSelector, with the goal of having dynamic behavior based on what branches were present, what type they had, etc.

What I wrote compiles fine, and runs fine on a single file, but crashes during fChain->GetTree()->GetEntry(entry) when another file is reached. In fact, in some cases, root simply exits without any crash or message at all…

Any suggestions would be highly appreciated.

Thanks,
Andrew Meade

What I’m doing (simplified a bit):
header:
map<string, vector *> myVarMap;

Init():

fChain->SetBranchStatus("*",0);
if (some condition) {
fChain->SetBranchStatus(“branchName”,1);
vector * myVec = new vector;
myVarMap[“myVar”] = myVec;
fChain->SetBranchAddress(“branchName”, &myVec);
}

The crash I get:

*** Break *** segmentation violation
(no debugging symbols found)
Attaching to program: /proc/32598/exe, process 32598
(no debugging symbols found)…done.
(no debugging symbols found)…done.
[Thread debugging using libthread_db enabled]
[New Thread 0xf70868e0 (LWP 32598)]
(no debugging symbols found)…done.
(no debugging symbols found)…done.
0xffffe410 in __kernel_vsyscall ()
#1 0x005044a3 in __waitpid_nocancel () from /lib/libc.so.6
#2 0x004a907b in do_system () from /lib/libc.so.6
#3 0x005c8ccd in system () from /lib/libpthread.so.0
#4 0xf7b485e3 in TUnixSystem::Exec () from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libCore.so
#5 0xf7b4e27b in TUnixSystem::StackTrace ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libCore.so
#6 0xf7b4ac76 in TUnixSystem::DispatchSignals ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libCore.so
#7 0xf7b4ad04 in SigHandler () from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libCore.so
#8 0xf7b49f81 in sighandler () from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libCore.so
#9
#10 0xf58c2482 in std::fill_n<float*, unsigned int, float> ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libvectorDict.so
#11 0xf58c4cee in std::vector<float, std::allocator >::_M_fill_insert ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libvectorDict.so
#12 0xf58c4ec8 in ROOT::TCollectionProxyInfo::Pushback<std::vector<float, std::allocator > >::resize ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libvectorDict.so
#13 0xf6ee92b8 in TGenCollectionStreamer::ReadPrimitives ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libRIO.so
#14 0xf6eeb853 in TGenCollectionStreamer::Streamer ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libRIO.so
#15 0xf6ec1d99 in TCollectionStreamer::Streamer ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libRIO.so
#16 0xf6ec27b7 in TCollectionClassStreamer::operator() ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libRIO.so
#17 0xf7b0b1a6 in TClass::Streamer () from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libCore.so
#18 0xf6ebcb6f in TBufferFile::ReadFastArray ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libRIO.so
#19 0xf6f78383 in TStreamerInfo::ReadBuffer<char**> ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libRIO.so
#20 0xf5ce58b3 in TBranchElement::ReadLeaves ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libTree.so
#21 0xf5cdf664 in TBranch::GetEntry () from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libTree.so
#22 0xf5ce19f7 in TBranchElement::GetEntry ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libTree.so
#23 0xf5d2a525 in TTree::GetEntry () from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libTree.so
#24 0xf4873f31 in anyTree::Process (this=0xa972398, entry=0) at /home/ameade/bugUMAnalysis/run/./anyTree.C:92
#25 0xf5d6ef91 in G__G__Tree_199_0_14 () from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libTree.so
#26 0xf72f5061 in Cint::G__CallFunc::Execute ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libCint.so
#27 0xf7b3d2e6 in TCint::CallFunc_ExecInt ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libCore.so
#28 0xf5d1967a in TSelectorCint::Process () from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libTree.so
#29 0xf551f563 in TTreePlayer::Process ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libTreePlayer.so
#30 0xf551ef72 in TTreePlayer::Process ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libTreePlayer.so
#31 0xf5d2d009 in TTree::Process () from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libTree.so
#32 0xf5cfd08d in TChain::Process () from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libTree.so
#33 0xf5d574e0 in G__G__Tree_109_0_135 () from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libTree.so
#34 0xf72c54b7 in Cint::G__ExceptionWrapper ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libCint.so
#35 0xf735a520 in G__execute_call () from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libCint.so
#36 0xf735a832 in G__call_cppfunc () from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libCint.so
#37 0xf733b2ff in G__interpret_func () from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libCint.so
#38 0xf7329cf0 in G__getfunction () from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libCint.so
#39 0xf7410b91 in G__getstructmem () from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libCint.so
#40 0xf74085e2 in G__getvariable () from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libCint.so
#41 0xf730dcf2 in G__getitem () from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libCint.so
#42 0xf7310c87 in G__getexpr () from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libCint.so
#43 0xf7386ccc in G__exec_statement () from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libCint.so
#44 0xf733ce27 in G__interpret_func () from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libCint.so
#45 0xf7329b32 in G__getfunction () from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libCint.so
#46 0xf730e03c in G__getitem () from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libCint.so
#47 0xf7310c87 in G__getexpr () from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libCint.so
#48 0xf7319f9c in G__calc_internal () from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libCint.so
#49 0xf7397fd5 in G__process_cmd () from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libCint.so
#50 0xf7b3685b in TCint::ProcessLine () from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libCore.so
#51 0xf7b369dc in TCint::ProcessLineSynch ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libCore.so
#52 0xf7a70fa2 in TApplication::ExecuteFile ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libCore.so
#53 0xf7a7132e in TApplication::ProcessFile ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libCore.so
#54 0xf7a6f1f2 in TApplication::ProcessLine ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libCore.so
#55 0xf70e9e45 in TRint::Run () from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.22.00d/slc4_ia32_gcc34/root/lib/libRint.so
#56 0x08048d46 in main ()
anyTree.C (7.84 KB)
anyTree.h (7.08 KB)

Could you replace:

fChain->GetTree()->GetEntry(entry); by

fChain->GetEntry(entry);

Rene