Dear Philippe,
thank you a lot for analysis of my problem.
You are right!! Indeed in the file I have a TChain. When I run my code on a single file (with a TTree) it does work without crash!
But for the TChain your modifications (as I adopted them) did not help me, I have a crash on the very first event.
TTree *get_tree1()
{
f = TFile::Open("merge/u1.root");
TTree *t = f->Get("Dtree");
return t;
}
TTree *get_tree2()
{
TTree *t = new TTree("D","D");
Dmeson *d = new Dmeson();
t->Branch("Dmeson",&d);
t->Fill();
t->Fill();
t->Fill();
return t;
}
void r2(void)
{
gSystem->Load("/home/zvyagin/opt/OC/lib/libDmesonDict.so");
TTree *t = get_tree1();
Dmeson *d = new Dmeson();
t -> SetBranchAddress("Dmeson",&d);
f1 = new TTreeFormula("f1","id==12||id==122",t);
f2 = new TTreeFormula("f2","id==21||id==211",t);
Long_t treenumber = t->GetTreeNumber();
printf("Tree: %d\n",treenumber);
for( int i=0; i<t->GetEntries(); i++ )
{
if ( t->GetEntry(i) < 0 )
break;
if(t->GetTreeNumber() != treenumber)
{
treenumber = t->GetTreeNumber();
printf("New TTree: %d\n",treenumber);
f1->UpdateFormulaLeaves();
f2->UpdateFormulaLeaves();
}
printf("%d %d\n",f1->EvalInstance(0),f2->EvalInstance(0));
}
}
$ valgrind --num-callers=35 root.exe -b -q r2.C
==14109== Memcheck, a memory error detector.
==14109== Copyright (C) 2002-2008, and GNU GPL'd, by Julian Seward et al.
==14109== Using LibVEX rev 1884, a library for dynamic binary translation.
==14109== Copyright (C) 2004-2008, and GNU GPL'd, by OpenWorks LLP.
==14109== Using valgrind-3.4.1-Debian, a dynamic binary instrumentation framework.
==14109== Copyright (C) 2000-2008, and GNU GPL'd, by Julian Seward et al.
==14109== For more details, rerun with: -v
==14109==
*******************************************
* *
* W E L C O M E to R O O T *
* *
* Version 5.24/00 29 June 2009 *
* *
* You are welcome to visit our Web site *
* http://root.cern.ch *
* *
*******************************************
ROOT 5.24/00 (trunk@29257, Jun 30 2009, 09:23:51 on linux)
CINT/ROOT C/C++ Interpreter version 5.17.00, Dec 21, 2008
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
root [0]
Processing r2.C...
Tree: 0
==14109== Invalid read of size 4
==14109== at 0x9CCAE5A: TTreeFormula::EvalInstance(int, char const**) (in /opt/root-5.24.00/lib/root/libTreePlayer.so)
==14109== by 0x9DA2B36: G__G__TreePlayer_163_0_32(G__value*, char const*, G__param*, int) (in /opt/root-5.24.00/lib/root/libTreePlayer.so)
==14109== by 0x47F6BFF: Cint::G__ExceptionWrapper(int (*)(G__value*, char const*, G__param*, int), G__value*, char*, G__param*, int) (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x48B0F0B: G__execute_call (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x48B20B5: G__call_cppfunc (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x4888A07: G__interpret_func (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x4876E1E: G__getfunction (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x496BB12: G__getstructmem (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x496458F: G__getvariable (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x48472FE: G__getitem (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x484D15B: G__getexpr (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x4876262: G__getfunction (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x4847407: G__getitem (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x484D15B: G__getexpr (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x48E1C60: G__exec_statement (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x48E48AE: G__exec_loop (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x48E2398: G__exec_statement (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x488A02F: G__interpret_func (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x4876869: G__getfunction (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x4847407: G__getitem (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x484D15B: G__getexpr (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x485B507: G__calc_internal (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x48EC972: G__process_cmd (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x4240A63: TCint::ProcessLine(char const*, TInterpreter::EErrorCode*) (in /opt/root-5.24.00/lib/root/libCore.so)
==14109== by 0x423D6DE: TCint::ProcessLineSynch(char const*, TInterpreter::EErrorCode*) (in /opt/root-5.24.00/lib/root/libCore.so)
==14109== by 0x415F5A2: TApplication::ExecuteFile(char const*, int*, bool) (in /opt/root-5.24.00/lib/root/libCore.so)
==14109== by 0x415F8CB: TApplication::ProcessFile(char const*, int*, bool) (in /opt/root-5.24.00/lib/root/libCore.so)
==14109== by 0x415DE75: TApplication::ProcessLine(char const*, bool, int*) (in /opt/root-5.24.00/lib/root/libCore.so)
==14109== by 0x50BDE79: TRint::Run(bool) (in /opt/root-5.24.00/lib/root/libRint.so)
==14109== by 0x8048EC4: main (in /opt/root-5.24.00/bin/root.exe)
==14109== Address 0x99b4ddc is 260 bytes inside a block of size 460 free'd
==14109== at 0x402599A: operator delete(void*) (vg_replace_malloc.c:342)
==14109== by 0x41B1942: TStorage::ObjectDealloc(void*) (in /opt/root-5.24.00/lib/root/libCore.so)
==14109== by 0x418F497: TObject::operator delete(void*) (in /opt/root-5.24.00/lib/root/libCore.so)
==14109== by 0x6B78356: TBranchElement::~TBranchElement() (in /opt/root-5.24.00/lib/root/libTree.so)
==14109== by 0x41F9C2C: TCollection::GarbageCollect(TObject*) (in /opt/root-5.24.00/lib/root/libCore.so)
==14109== by 0x4203B73: TObjArray::Delete(char const*) (in /opt/root-5.24.00/lib/root/libCore.so)
==14109== by 0x6B6A4BB: TBranch::~TBranch() (in /opt/root-5.24.00/lib/root/libTree.so)
==14109== by 0x6B7834E: TBranchElement::~TBranchElement() (in /opt/root-5.24.00/lib/root/libTree.so)
==14109== by 0x41F9C2C: TCollection::GarbageCollect(TObject*) (in /opt/root-5.24.00/lib/root/libCore.so)
==14109== by 0x4203B73: TObjArray::Delete(char const*) (in /opt/root-5.24.00/lib/root/libCore.so)
==14109== by 0x6BBAF09: TTree::~TTree() (in /opt/root-5.24.00/lib/root/libTree.so)
==14109== by 0x41F9C2C: TCollection::GarbageCollect(TObject*) (in /opt/root-5.24.00/lib/root/libCore.so)
==14109== by 0x41FFC0D: TList::Delete(char const*) (in /opt/root-5.24.00/lib/root/libCore.so)
==14109== by 0x41FC906: THashList::Delete(char const*) (in /opt/root-5.24.00/lib/root/libCore.so)
==14109== by 0x684AD0F: TDirectoryFile::Close(char const*) (in /opt/root-5.24.00/lib/root/libRIO.so)
==14109== by 0x6860EB3: TFile::Close(char const*) (in /opt/root-5.24.00/lib/root/libRIO.so)
==14109== by 0x6861FD3: TFile::~TFile() (in /opt/root-5.24.00/lib/root/libRIO.so)
==14109== by 0x6B8550F: TChain::LoadTree(long long) (in /opt/root-5.24.00/lib/root/libTree.so)
==14109== by 0x6B82198: TChain::GetEntries() const (in /opt/root-5.24.00/lib/root/libTree.so)
==14109== by 0x6C405B2: G__G__Tree_109_0_61(G__value*, char const*, G__param*, int) (in /opt/root-5.24.00/lib/root/libTree.so)
==14109== by 0x47F6BFF: Cint::G__ExceptionWrapper(int (*)(G__value*, char const*, G__param*, int), G__value*, char*, G__param*, int) (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x48B0F0B: G__execute_call (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x48B20B5: G__call_cppfunc (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x4888A07: G__interpret_func (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x4876E1E: G__getfunction (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x496BB12: G__getstructmem (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x496458F: G__getvariable (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x48472FE: G__getitem (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x484D15B: G__getexpr (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x485A8C4: G__test (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x48E4696: G__exec_loop (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x48E2398: G__exec_statement (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x488A02F: G__interpret_func (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x4876869: G__getfunction (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x4847407: G__getitem (in /opt/root-5.24.00/lib/root/libCint.so)
==14109==
==14109== Invalid read of size 4
==14109== at 0x9CCAE60: TTreeFormula::EvalInstance(int, char const**) (in /opt/root-5.24.00/lib/root/libTreePlayer.so)
==14109== by 0x9DA2B36: G__G__TreePlayer_163_0_32(G__value*, char const*, G__param*, int) (in /opt/root-5.24.00/lib/root/libTreePlayer.so)
==14109== by 0x47F6BFF: Cint::G__ExceptionWrapper(int (*)(G__value*, char const*, G__param*, int), G__value*, char*, G__param*, int) (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x48B0F0B: G__execute_call (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x48B20B5: G__call_cppfunc (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x4888A07: G__interpret_func (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x4876E1E: G__getfunction (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x496BB12: G__getstructmem (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x496458F: G__getvariable (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x48472FE: G__getitem (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x484D15B: G__getexpr (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x4876262: G__getfunction (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x4847407: G__getitem (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x484D15B: G__getexpr (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x48E1C60: G__exec_statement (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x48E48AE: G__exec_loop (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x48E2398: G__exec_statement (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x488A02F: G__interpret_func (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x4876869: G__getfunction (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x4847407: G__getitem (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x484D15B: G__getexpr (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x485B507: G__calc_internal (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x48EC972: G__process_cmd (in /opt/root-5.24.00/lib/root/libCint.so)
==14109== by 0x4240A63: TCint::ProcessLine(char const*, TInterpreter::EErrorCode*) (in /opt/root-5.24.00/lib/root/libCore.so)
==14109== by 0x423D6DE: TCint::ProcessLineSynch(char const*, TInterpreter::EErrorCode*) (in /opt/root-5.24.00/lib/root/libCore.so)
==14109== by 0x415F5A2: TApplication::ExecuteFile(char const*, int*, bool) (in /opt/root-5.24.00/lib/root/libCore.so)
==14109== by 0x415F8CB: TApplication::ProcessFile(char const*, int*, bool) (in /opt/root-5.24.00/lib/root/libCore.so)
==14109== by 0x415DE75: TApplication::ProcessLine(char const*, bool, int*) (in /opt/root-5.24.00/lib/root/libCore.so)
==14109== by 0x50BDE79: TRint::Run(bool) (in /opt/root-5.24.00/lib/root/libRint.so)
==14109== by 0x8048EC4: main (in /opt/root-5.24.00/bin/root.exe)
==14109== Address 0x0 is not stack'd, malloc'd or (recently) free'd
*** Break *** segmentation violation
Attaching to program: /proc/14109/exe, process 14109
vgModuleLocal_do_syscall_for_client_WRK () at m_syswrap/syscall-x86-linux.S:115
115 m_syswrap/syscall-x86-linux.S: No such file or directory.
in m_syswrap/syscall-x86-linux.S
error detected on stdin
The program is running. Quit anyway (and detach it)? (y or n) [answered Y; input not from terminal]
Detaching from program: /proc/14109/exe, process 14109
Root > Function r2() busy flag cleared
==14109==
==14109== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 756 from 4)
==14109== malloc/free: in use at exit: 6,750,851 bytes in 78,356 blocks.
==14109== malloc/free: 919,307 allocs, 840,951 frees, 66,298,594 bytes allocated.
==14109== For counts of detected errors, rerun with: -v
==14109== searching for pointers to 78,356 not-freed blocks.
==14109== checked 9,879,664 bytes.
==14109==
==14109== LEAK SUMMARY:
==14109== definitely lost: 34,747 bytes in 34 blocks.
==14109== possibly lost: 362,986 bytes in 8,253 blocks.
==14109== still reachable: 6,353,118 bytes in 70,069 blocks.
==14109== suppressed: 0 bytes in 0 blocks.
==14109== Rerun with --leak-check=full to see details of leaked memory.