Problem in TTreeFormula usage

Hello,

I tried to use the TTreeFormula, but my code is crashing… Could you check what is wrong?

Thanks a lot in advance!
Alexander.

void r(void)
{
    f = TFile::Open("merge/u1.root");
    gSystem->Load("/home/zvyagin/opt/OC-dev/lib/libDmesonDict.so");
    TTree *t = f->Get("Dtree");
    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);
    
    for( int i=0; i<t.GetEntries(); i++ )
    {
        t->GetEntry(i);
        printf("%d %d\n",f1->EvalInstance(0),f2->EvalInstance(0));
    }
}

the problem does not occur if I create a dummy root TTree:

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;
}

but if I read my objects from TTree of a file, it crashes…

Any hints?

Hi,

It then plausible that the problem is somewhere in the code for Dmeson.
What is the stack trace? What does valgrind complains about?

Philippe.

[quote=“pcanal”]Hi,

It then plausible that the problem is somewhere in the code for Dmeson.
What is the stack trace? What does valgrind complains about?

Philippe.[/quote]

The code of Dmeson is very simple, I don’t manipulate with memory at all.

The stack trace is not informative at all:

 *** Break *** segmentation violation
Attaching to program: /proc/3511/exe, process 3511
[Thread debugging using libthread_db enabled]
[New Thread 0xb6d056d0 (LWP 3511)]
0xb80b1430 in __kernel_vsyscall ()
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/3511/exe, process 3511
Root > Function r1() busy flag cleared

Here is the ouput from valgrind:

  *******************************************
  *                                         *
  *        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 r1.C...
==3241== Invalid read of size 4
==3241==    at 0x9CCAE5A: TTreeFormula::EvalInstance(int, char const**) (in /opt/root-5.24.00/lib/root/libTreePlayer.so)
==3241==    by 0x9CC13D5: TTreeFormula::PrintValue(int, int, char const*) const (in /opt/root-5.24.00/lib/root/libTreePlayer.so)
==3241==    by 0x9CBD908: TTreeFormula::PrintValue(int) const (in /opt/root-5.24.00/lib/root/libTreePlayer.so)
==3241==    by 0x9D3B15F: G__G__TreePlayer_163_0_46(G__value*, char const*, G__param*, int) (in /opt/root-5.24.00/lib/root/libTreePlayer.so)
==3241==    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)
==3241==    by 0x48B0F0B: G__execute_call (in /opt/root-5.24.00/lib/root/libCint.so)
==3241==    by 0x48B20B5: G__call_cppfunc (in /opt/root-5.24.00/lib/root/libCint.so)
==3241==    by 0x4888A07: G__interpret_func (in /opt/root-5.24.00/lib/root/libCint.so)
==3241==    by 0x4876E1E: G__getfunction (in /opt/root-5.24.00/lib/root/libCint.so)
==3241==    by 0x496BB12: G__getstructmem (in /opt/root-5.24.00/lib/root/libCint.so)
==3241==    by 0x496458F: G__getvariable (in /opt/root-5.24.00/lib/root/libCint.so)
==3241==    by 0x48472FE: G__getitem (in /opt/root-5.24.00/lib/root/libCint.so)
==3241==  Address 0x99b5da4 is 260 bytes inside a block of size 460 free'd
==3241==    at 0x402599A: operator delete(void*) (vg_replace_malloc.c:342)
==3241==    by 0x41B1942: TStorage::ObjectDealloc(void*) (in /opt/root-5.24.00/lib/root/libCore.so)
==3241==    by 0x418F497: TObject::operator delete(void*) (in /opt/root-5.24.00/lib/root/libCore.so)
==3241==    by 0x6B78356: TBranchElement::~TBranchElement() (in /opt/root-5.24.00/lib/root/libTree.so)
==3241==    by 0x41F9C2C: TCollection::GarbageCollect(TObject*) (in /opt/root-5.24.00/lib/root/libCore.so)
==3241==    by 0x4203B73: TObjArray::Delete(char const*) (in /opt/root-5.24.00/lib/root/libCore.so)
==3241==    by 0x6B6A4BB: TBranch::~TBranch() (in /opt/root-5.24.00/lib/root/libTree.so)
==3241==    by 0x6B7834E: TBranchElement::~TBranchElement() (in /opt/root-5.24.00/lib/root/libTree.so)
==3241==    by 0x41F9C2C: TCollection::GarbageCollect(TObject*) (in /opt/root-5.24.00/lib/root/libCore.so)
==3241==    by 0x4203B73: TObjArray::Delete(char const*) (in /opt/root-5.24.00/lib/root/libCore.so)
==3241==    by 0x6BBAF09: TTree::~TTree() (in /opt/root-5.24.00/lib/root/libTree.so)
==3241==    by 0x41F9C2C: TCollection::GarbageCollect(TObject*) (in /opt/root-5.24.00/lib/root/libCore.so)
==3241== 
==3241== Invalid read of size 4
==3241==    at 0x9CCAE60: TTreeFormula::EvalInstance(int, char const**) (in /opt/root-5.24.00/lib/root/libTreePlayer.so)
==3241==    by 0x9CC13D5: TTreeFormula::PrintValue(int, int, char const*) const (in /opt/root-5.24.00/lib/root/libTreePlayer.so)
==3241==    by 0x9CBD908: TTreeFormula::PrintValue(int) const (in /opt/root-5.24.00/lib/root/libTreePlayer.so)
==3241==    by 0x9D3B15F: G__G__TreePlayer_163_0_46(G__value*, char const*, G__param*, int) (in /opt/root-5.24.00/lib/root/libTreePlayer.so)
==3241==    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)
==3241==    by 0x48B0F0B: G__execute_call (in /opt/root-5.24.00/lib/root/libCint.so)
==3241==    by 0x48B20B5: G__call_cppfunc (in /opt/root-5.24.00/lib/root/libCint.so)
==3241==    by 0x4888A07: G__interpret_func (in /opt/root-5.24.00/lib/root/libCint.so)
==3241==    by 0x4876E1E: G__getfunction (in /opt/root-5.24.00/lib/root/libCint.so)
==3241==    by 0x496BB12: G__getstructmem (in /opt/root-5.24.00/lib/root/libCint.so)
==3241==    by 0x496458F: G__getvariable (in /opt/root-5.24.00/lib/root/libCint.so)
==3241==    by 0x48472FE: G__getitem (in /opt/root-5.24.00/lib/root/libCint.so)
==3241==  Address 0x0 is not stack'd, malloc'd or (recently) free'd

 *** Break *** segmentation violation
Attaching to program: /proc/3241/exe, process 3241
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/3241/exe, process 3241
Root > Function r1() busy flag cleared
==3241== 
==3241== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 756 from 4)
==3241== malloc/free: in use at exit: 6,749,743 bytes in 78,382 blocks.
==3241== malloc/free: 919,304 allocs, 840,922 frees, 66,284,265 bytes allocated.
==3241== For counts of detected errors, rerun with: -v
==3241== searching for pointers to 78,382 not-freed blocks.
==3241== checked 9,877,948 bytes.
==3241== 
==3241== LEAK SUMMARY:
==3241==    definitely lost: 34,747 bytes in 34 blocks.
==3241==      possibly lost: 362,986 bytes in 8,253 blocks.
==3241==    still reachable: 6,352,010 bytes in 70,095 blocks.
==3241==         suppressed: 0 bytes in 0 blocks.
==3241== Rerun with --leak-check=full to see details of leaked memory.

Hi,

I see ==3241== by 0x6BBAF09: TTree::~TTree() (in /opt/root-5.24.00/lib/root/libTree.so) ==3241== by 0x41F9C2C: TCollection::GarbageCollect(TObject*) (in /opt/root-5.24.00/lib/root/libCore.so) which indicates that the TTree the TTreeFormula are pointing to have been deleted. Nothing in your code fragment indicates that the TTree has been deleted between the Get and the EvalInstance … unless Dtree on the file is actually a TChain.

I may help to re-run valgrind with --num-callers=35

Cheers,
Philippe.

here is the output…

$ valgrind --num-callers=35  root.exe -b -q r1.C
==11780== Memcheck, a memory error detector.
==11780== Copyright (C) 2002-2008, and GNU GPL'd, by Julian Seward et al.
==11780== Using LibVEX rev 1884, a library for dynamic binary translation.
==11780== Copyright (C) 2004-2008, and GNU GPL'd, by OpenWorks LLP.
==11780== Using valgrind-3.4.1-Debian, a dynamic binary instrumentation framework.
==11780== Copyright (C) 2000-2008, and GNU GPL'd, by Julian Seward et al.
==11780== For more details, rerun with: -v
==11780== 
  *******************************************
  *                                         *
  *        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 r1.C...
==11780== Invalid read of size 4
==11780==    at 0x9CCAE5A: TTreeFormula::EvalInstance(int, char const**) (in /opt/root-5.24.00/lib/root/libTreePlayer.so)
==11780==    by 0x9CC13D5: TTreeFormula::PrintValue(int, int, char const*) const (in /opt/root-5.24.00/lib/root/libTreePlayer.so)
==11780==    by 0x9CBD908: TTreeFormula::PrintValue(int) const (in /opt/root-5.24.00/lib/root/libTreePlayer.so)
==11780==    by 0x9D3B15F: G__G__TreePlayer_163_0_46(G__value*, char const*, G__param*, int) (in /opt/root-5.24.00/lib/root/libTreePlayer.so)
==11780==    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)
==11780==    by 0x48B0F0B: G__execute_call (in /opt/root-5.24.00/lib/root/libCint.so)
==11780==    by 0x48B20B5: G__call_cppfunc (in /opt/root-5.24.00/lib/root/libCint.so)
==11780==    by 0x4888A07: G__interpret_func (in /opt/root-5.24.00/lib/root/libCint.so)
==11780==    by 0x4876E1E: G__getfunction (in /opt/root-5.24.00/lib/root/libCint.so)
==11780==    by 0x496BB12: G__getstructmem (in /opt/root-5.24.00/lib/root/libCint.so)
==11780==    by 0x496458F: G__getvariable (in /opt/root-5.24.00/lib/root/libCint.so)
==11780==    by 0x48472FE: G__getitem (in /opt/root-5.24.00/lib/root/libCint.so)
==11780==    by 0x484D15B: G__getexpr (in /opt/root-5.24.00/lib/root/libCint.so)
==11780==    by 0x48E1C60: G__exec_statement (in /opt/root-5.24.00/lib/root/libCint.so)
==11780==    by 0x48E48AE: G__exec_loop (in /opt/root-5.24.00/lib/root/libCint.so)
==11780==    by 0x48E2398: G__exec_statement (in /opt/root-5.24.00/lib/root/libCint.so)
==11780==    by 0x488A02F: G__interpret_func (in /opt/root-5.24.00/lib/root/libCint.so)
==11780==    by 0x4876869: G__getfunction (in /opt/root-5.24.00/lib/root/libCint.so)
==11780==    by 0x4847407: G__getitem (in /opt/root-5.24.00/lib/root/libCint.so)
==11780==    by 0x484D15B: G__getexpr (in /opt/root-5.24.00/lib/root/libCint.so)
==11780==    by 0x485B507: G__calc_internal (in /opt/root-5.24.00/lib/root/libCint.so)
==11780==    by 0x48EC972: G__process_cmd (in /opt/root-5.24.00/lib/root/libCint.so)
==11780==    by 0x4240A63: TCint::ProcessLine(char const*, TInterpreter::EErrorCode*) (in /opt/root-5.24.00/lib/root/libCore.so)
==11780==    by 0x423D6DE: TCint::ProcessLineSynch(char const*, TInterpreter::EErrorCode*) (in /opt/root-5.24.00/lib/root/libCore.so)
==11780==    by 0x415F5A2: TApplication::ExecuteFile(char const*, int*, bool) (in /opt/root-5.24.00/lib/root/libCore.so)
==11780==    by 0x415F8CB: TApplication::ProcessFile(char const*, int*, bool) (in /opt/root-5.24.00/lib/root/libCore.so)
==11780==    by 0x415DE75: TApplication::ProcessLine(char const*, bool, int*) (in /opt/root-5.24.00/lib/root/libCore.so)
==11780==    by 0x50BDE79: TRint::Run(bool) (in /opt/root-5.24.00/lib/root/libRint.so)
==11780==    by 0x8048EC4: main (in /opt/root-5.24.00/bin/root.exe)
==11780==  Address 0x99b5824 is 260 bytes inside a block of size 460 free'd
==11780==    at 0x402599A: operator delete(void*) (vg_replace_malloc.c:342)
==11780==    by 0x41B1942: TStorage::ObjectDealloc(void*) (in /opt/root-5.24.00/lib/root/libCore.so)
==11780==    by 0x418F497: TObject::operator delete(void*) (in /opt/root-5.24.00/lib/root/libCore.so)
==11780==    by 0x6B78356: TBranchElement::~TBranchElement() (in /opt/root-5.24.00/lib/root/libTree.so)
==11780==    by 0x41F9C2C: TCollection::GarbageCollect(TObject*) (in /opt/root-5.24.00/lib/root/libCore.so)
==11780==    by 0x4203B73: TObjArray::Delete(char const*) (in /opt/root-5.24.00/lib/root/libCore.so)
==11780==    by 0x6B6A4BB: TBranch::~TBranch() (in /opt/root-5.24.00/lib/root/libTree.so)
==11780==    by 0x6B7834E: TBranchElement::~TBranchElement() (in /opt/root-5.24.00/lib/root/libTree.so)
==11780==    by 0x41F9C2C: TCollection::GarbageCollect(TObject*) (in /opt/root-5.24.00/lib/root/libCore.so)
==11780==    by 0x4203B73: TObjArray::Delete(char const*) (in /opt/root-5.24.00/lib/root/libCore.so)
==11780==    by 0x6BBAF09: TTree::~TTree() (in /opt/root-5.24.00/lib/root/libTree.so)
==11780==    by 0x41F9C2C: TCollection::GarbageCollect(TObject*) (in /opt/root-5.24.00/lib/root/libCore.so)
==11780==    by 0x41FFC0D: TList::Delete(char const*) (in /opt/root-5.24.00/lib/root/libCore.so)
==11780==    by 0x41FC906: THashList::Delete(char const*) (in /opt/root-5.24.00/lib/root/libCore.so)
==11780==    by 0x684AD0F: TDirectoryFile::Close(char const*) (in /opt/root-5.24.00/lib/root/libRIO.so)
==11780==    by 0x6860EB3: TFile::Close(char const*) (in /opt/root-5.24.00/lib/root/libRIO.so)
==11780==    by 0x6861FD3: TFile::~TFile() (in /opt/root-5.24.00/lib/root/libRIO.so)
==11780==    by 0x6B8550F: TChain::LoadTree(long long) (in /opt/root-5.24.00/lib/root/libTree.so)
==11780==    by 0x6B82198: TChain::GetEntries() const (in /opt/root-5.24.00/lib/root/libTree.so)
==11780==    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)
==11780==    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)
==11780==    by 0x48B0F0B: G__execute_call (in /opt/root-5.24.00/lib/root/libCint.so)
==11780==    by 0x48B20B5: G__call_cppfunc (in /opt/root-5.24.00/lib/root/libCint.so)
==11780==    by 0x4888A07: G__interpret_func (in /opt/root-5.24.00/lib/root/libCint.so)
==11780==    by 0x4876E1E: G__getfunction (in /opt/root-5.24.00/lib/root/libCint.so)
==11780==    by 0x496BB12: G__getstructmem (in /opt/root-5.24.00/lib/root/libCint.so)
==11780==    by 0x496458F: G__getvariable (in /opt/root-5.24.00/lib/root/libCint.so)
==11780==    by 0x48472FE: G__getitem (in /opt/root-5.24.00/lib/root/libCint.so)
==11780==    by 0x484D15B: G__getexpr (in /opt/root-5.24.00/lib/root/libCint.so)
==11780==    by 0x485A8C4: G__test (in /opt/root-5.24.00/lib/root/libCint.so)
==11780==    by 0x48E4696: G__exec_loop (in /opt/root-5.24.00/lib/root/libCint.so)
==11780==    by 0x48E2398: G__exec_statement (in /opt/root-5.24.00/lib/root/libCint.so)
==11780==    by 0x488A02F: G__interpret_func (in /opt/root-5.24.00/lib/root/libCint.so)
==11780==    by 0x4876869: G__getfunction (in /opt/root-5.24.00/lib/root/libCint.so)
==11780==    by 0x4847407: G__getitem (in /opt/root-5.24.00/lib/root/libCint.so)
==11780== 
==11780== Invalid read of size 4
==11780==    at 0x9CCAE60: TTreeFormula::EvalInstance(int, char const**) (in /opt/root-5.24.00/lib/root/libTreePlayer.so)
==11780==    by 0x9CC13D5: TTreeFormula::PrintValue(int, int, char const*) const (in /opt/root-5.24.00/lib/root/libTreePlayer.so)
==11780==    by 0x9CBD908: TTreeFormula::PrintValue(int) const (in /opt/root-5.24.00/lib/root/libTreePlayer.so)
==11780==    by 0x9D3B15F: G__G__TreePlayer_163_0_46(G__value*, char const*, G__param*, int) (in /opt/root-5.24.00/lib/root/libTreePlayer.so)
==11780==    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)
==11780==    by 0x48B0F0B: G__execute_call (in /opt/root-5.24.00/lib/root/libCint.so)
==11780==    by 0x48B20B5: G__call_cppfunc (in /opt/root-5.24.00/lib/root/libCint.so)
==11780==    by 0x4888A07: G__interpret_func (in /opt/root-5.24.00/lib/root/libCint.so)
==11780==    by 0x4876E1E: G__getfunction (in /opt/root-5.24.00/lib/root/libCint.so)
==11780==    by 0x496BB12: G__getstructmem (in /opt/root-5.24.00/lib/root/libCint.so)
==11780==    by 0x496458F: G__getvariable (in /opt/root-5.24.00/lib/root/libCint.so)
==11780==    by 0x48472FE: G__getitem (in /opt/root-5.24.00/lib/root/libCint.so)
==11780==    by 0x484D15B: G__getexpr (in /opt/root-5.24.00/lib/root/libCint.so)
==11780==    by 0x48E1C60: G__exec_statement (in /opt/root-5.24.00/lib/root/libCint.so)
==11780==    by 0x48E48AE: G__exec_loop (in /opt/root-5.24.00/lib/root/libCint.so)
==11780==    by 0x48E2398: G__exec_statement (in /opt/root-5.24.00/lib/root/libCint.so)
==11780==    by 0x488A02F: G__interpret_func (in /opt/root-5.24.00/lib/root/libCint.so)
==11780==    by 0x4876869: G__getfunction (in /opt/root-5.24.00/lib/root/libCint.so)
==11780==    by 0x4847407: G__getitem (in /opt/root-5.24.00/lib/root/libCint.so)
==11780==    by 0x484D15B: G__getexpr (in /opt/root-5.24.00/lib/root/libCint.so)
==11780==    by 0x485B507: G__calc_internal (in /opt/root-5.24.00/lib/root/libCint.so)
==11780==    by 0x48EC972: G__process_cmd (in /opt/root-5.24.00/lib/root/libCint.so)
==11780==    by 0x4240A63: TCint::ProcessLine(char const*, TInterpreter::EErrorCode*) (in /opt/root-5.24.00/lib/root/libCore.so)
==11780==    by 0x423D6DE: TCint::ProcessLineSynch(char const*, TInterpreter::EErrorCode*) (in /opt/root-5.24.00/lib/root/libCore.so)
==11780==    by 0x415F5A2: TApplication::ExecuteFile(char const*, int*, bool) (in /opt/root-5.24.00/lib/root/libCore.so)
==11780==    by 0x415F8CB: TApplication::ProcessFile(char const*, int*, bool) (in /opt/root-5.24.00/lib/root/libCore.so)
==11780==    by 0x415DE75: TApplication::ProcessLine(char const*, bool, int*) (in /opt/root-5.24.00/lib/root/libCore.so)
==11780==    by 0x50BDE79: TRint::Run(bool) (in /opt/root-5.24.00/lib/root/libRint.so)
==11780==    by 0x8048EC4: main (in /opt/root-5.24.00/bin/root.exe)
==11780==  Address 0x0 is not stack'd, malloc'd or (recently) free'd

 *** Break *** segmentation violation
Attaching to program: /proc/11780/exe, process 11780
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/11780/exe, process 11780
Root > Function r1() busy flag cleared
==11780== 
==11780== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 755 from 4)
==11780== malloc/free: in use at exit: 6,750,504 bytes in 78,345 blocks.
==11780== malloc/free: 919,268 allocs, 840,923 frees, 66,285,378 bytes allocated.
==11780== For counts of detected errors, rerun with: -v
==11780== searching for pointers to 78,345 not-freed blocks.
==11780== checked 9,878,796 bytes.
==11780== 
==11780== LEAK SUMMARY:
==11780==    definitely lost: 34,747 bytes in 34 blocks.
==11780==      possibly lost: 362,986 bytes in 8,253 blocks.
==11780==    still reachable: 6,352,771 bytes in 70,058 blocks.
==11780==         suppressed: 0 bytes in 0 blocks.
==11780== Rerun with --leak-check=full to see details of leaked memory.

Hi,

==11780== by 0x6B82198: TChain::GetEntries() const (in /opt/root-5.24.00/lib/root/libTree.so) ==11780== 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) so clearly you are using a TChain in which case the use of TTreeFormula is a bit more complex:
(i.e. the TTreeFormula needs to be informed when the chain opens a new file)

f1 = new TTreeFormula("f1","id==12||id==122",t); f2 = new TTreeFormula("f2","id==21||id==211",t); Long_t treenumber = t.GetTreeNumber(); for( int i=0; i<t.GetEntriesFast(); i++ ) { if ( t->LoadEntry(i) < 0 ) break; if (t->GetTreeNumber() != treenuber) { f1->UpdateFormulaLeaves(); f2->UpdateFormulaLeaves(); treenumber = t->GetTreeNumber(); } printf("%d %d\n",f1->EvalInstance(0),f2->EvalInstance(0)); }

Cheers,
Philippe.

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.

Hi,

Unfortunately the changes: for( int i=0; i<t->GetEntries(); i++ ) { if ( t->GetEntry(i) < 0 ) break; are not innocuous and you really need: for( int i=0; i<t->GetEntriesFast(); i++ ) { if ( t->LoadEntry(i) < 0 ) break; ‘t->GetEntries()’ force a scan through the whole chain and thus modifying the value of GetTreeNumber (so by changing in back to GetEntriesFast you gain in performance and ‘correctness’ :slight_smile:).
‘t->GetEntry(i)’ is more than you need since it will not only move the ‘cursor’ to the requested entry but also read the data from the disk. TTreeFormula will itself read the information that it needs (if it has not already been read). So keeping LoadEntry you gain in performance.

Cheers,
Philippe.

Ah, I see…

But ROOT tells me:

Error: Can't call TChain::LoadEntry(i) in current scope r2.C:44:
Possible candidates are...
(in TChain)
(in TTree)
*** Interpreter error recovered ***

… I am trying some tricks now …

Hi,

My apologies, the right spelling is t->LoadTree(i);

Cheers,
Philippe.

no… still no luck:

TTree *get_tree()
{
    f = TFile::Open("merge/u1.root");
    TTree *t = f->Get("Dtree");
    return t;
}

void r2(void)
{
    gSystem->Load("/home/zvyagin/opt/OC/lib/libDmesonDict.so");

    TTree *t = get_tree();
    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();
    
    for( int i=0; i<t->GetEntries(); i++ )
    {
        if ( t->LoadTree(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));
    }
}

the crash:

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...
==13159== Invalid read of size 4
==13159==    at 0x9CCAE5A: TTreeFormula::EvalInstance(int, char const**) (in /opt/root-5.24.00/lib/root/libTreePlayer.so)
==13159==    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)
==13159==    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)
==13159==    by 0x48B0F0B: G__execute_call (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x48B20B5: G__call_cppfunc (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x4888A07: G__interpret_func (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x4876E1E: G__getfunction (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x496BB12: G__getstructmem (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x496458F: G__getvariable (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x48472FE: G__getitem (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x484D15B: G__getexpr (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x4876262: G__getfunction (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x4847407: G__getitem (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x484D15B: G__getexpr (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x48E1C60: G__exec_statement (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x48E48AE: G__exec_loop (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x48E2398: G__exec_statement (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x488A02F: G__interpret_func (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x4876869: G__getfunction (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x4847407: G__getitem (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x484D15B: G__getexpr (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x485B507: G__calc_internal (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x48EC972: G__process_cmd (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x4240A63: TCint::ProcessLine(char const*, TInterpreter::EErrorCode*) (in /opt/root-5.24.00/lib/root/libCore.so)
==13159==    by 0x423D6DE: TCint::ProcessLineSynch(char const*, TInterpreter::EErrorCode*) (in /opt/root-5.24.00/lib/root/libCore.so)
==13159==    by 0x415F5A2: TApplication::ExecuteFile(char const*, int*, bool) (in /opt/root-5.24.00/lib/root/libCore.so)
==13159==    by 0x415F8CB: TApplication::ProcessFile(char const*, int*, bool) (in /opt/root-5.24.00/lib/root/libCore.so)
==13159==    by 0x415DE75: TApplication::ProcessLine(char const*, bool, int*) (in /opt/root-5.24.00/lib/root/libCore.so)
==13159==    by 0x50BDE79: TRint::Run(bool) (in /opt/root-5.24.00/lib/root/libRint.so)
==13159==    by 0x8048EC4: main (in /opt/root-5.24.00/bin/root.exe)
==13159==  Address 0x99b5c64 is 260 bytes inside a block of size 460 free'd
==13159==    at 0x402599A: operator delete(void*) (vg_replace_malloc.c:342)
==13159==    by 0x41B1942: TStorage::ObjectDealloc(void*) (in /opt/root-5.24.00/lib/root/libCore.so)
==13159==    by 0x418F497: TObject::operator delete(void*) (in /opt/root-5.24.00/lib/root/libCore.so)
==13159==    by 0x6B78356: TBranchElement::~TBranchElement() (in /opt/root-5.24.00/lib/root/libTree.so)
==13159==    by 0x41F9C2C: TCollection::GarbageCollect(TObject*) (in /opt/root-5.24.00/lib/root/libCore.so)
==13159==    by 0x4203B73: TObjArray::Delete(char const*) (in /opt/root-5.24.00/lib/root/libCore.so)
==13159==    by 0x6B6A4BB: TBranch::~TBranch() (in /opt/root-5.24.00/lib/root/libTree.so)
==13159==    by 0x6B7834E: TBranchElement::~TBranchElement() (in /opt/root-5.24.00/lib/root/libTree.so)
==13159==    by 0x41F9C2C: TCollection::GarbageCollect(TObject*) (in /opt/root-5.24.00/lib/root/libCore.so)
==13159==    by 0x4203B73: TObjArray::Delete(char const*) (in /opt/root-5.24.00/lib/root/libCore.so)
==13159==    by 0x6BBAF09: TTree::~TTree() (in /opt/root-5.24.00/lib/root/libTree.so)
==13159==    by 0x41F9C2C: TCollection::GarbageCollect(TObject*) (in /opt/root-5.24.00/lib/root/libCore.so)
==13159==    by 0x41FFC0D: TList::Delete(char const*) (in /opt/root-5.24.00/lib/root/libCore.so)
==13159==    by 0x41FC906: THashList::Delete(char const*) (in /opt/root-5.24.00/lib/root/libCore.so)
==13159==    by 0x684AD0F: TDirectoryFile::Close(char const*) (in /opt/root-5.24.00/lib/root/libRIO.so)
==13159==    by 0x6860EB3: TFile::Close(char const*) (in /opt/root-5.24.00/lib/root/libRIO.so)
==13159==    by 0x6861FD3: TFile::~TFile() (in /opt/root-5.24.00/lib/root/libRIO.so)
==13159==    by 0x6B8550F: TChain::LoadTree(long long) (in /opt/root-5.24.00/lib/root/libTree.so)
==13159==    by 0x6B82198: TChain::GetEntries() const (in /opt/root-5.24.00/lib/root/libTree.so)
==13159==    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)
==13159==    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)
==13159==    by 0x48B0F0B: G__execute_call (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x48B20B5: G__call_cppfunc (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x4888A07: G__interpret_func (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x4876E1E: G__getfunction (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x496BB12: G__getstructmem (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x496458F: G__getvariable (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x48472FE: G__getitem (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x484D15B: G__getexpr (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x485A8C4: G__test (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x48E4696: G__exec_loop (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x48E2398: G__exec_statement (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x488A02F: G__interpret_func (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x4876869: G__getfunction (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x4847407: G__getitem (in /opt/root-5.24.00/lib/root/libCint.so)
==13159== 
==13159== Invalid read of size 4
==13159==    at 0x9CCAE60: TTreeFormula::EvalInstance(int, char const**) (in /opt/root-5.24.00/lib/root/libTreePlayer.so)
==13159==    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)
==13159==    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)
==13159==    by 0x48B0F0B: G__execute_call (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x48B20B5: G__call_cppfunc (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x4888A07: G__interpret_func (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x4876E1E: G__getfunction (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x496BB12: G__getstructmem (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x496458F: G__getvariable (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x48472FE: G__getitem (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x484D15B: G__getexpr (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x4876262: G__getfunction (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x4847407: G__getitem (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x484D15B: G__getexpr (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x48E1C60: G__exec_statement (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x48E48AE: G__exec_loop (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x48E2398: G__exec_statement (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x488A02F: G__interpret_func (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x4876869: G__getfunction (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x4847407: G__getitem (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x484D15B: G__getexpr (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x485B507: G__calc_internal (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x48EC972: G__process_cmd (in /opt/root-5.24.00/lib/root/libCint.so)
==13159==    by 0x4240A63: TCint::ProcessLine(char const*, TInterpreter::EErrorCode*) (in /opt/root-5.24.00/lib/root/libCore.so)
==13159==    by 0x423D6DE: TCint::ProcessLineSynch(char const*, TInterpreter::EErrorCode*) (in /opt/root-5.24.00/lib/root/libCore.so)
==13159==    by 0x415F5A2: TApplication::ExecuteFile(char const*, int*, bool) (in /opt/root-5.24.00/lib/root/libCore.so)
==13159==    by 0x415F8CB: TApplication::ProcessFile(char const*, int*, bool) (in /opt/root-5.24.00/lib/root/libCore.so)
==13159==    by 0x415DE75: TApplication::ProcessLine(char const*, bool, int*) (in /opt/root-5.24.00/lib/root/libCore.so)
==13159==    by 0x50BDE79: TRint::Run(bool) (in /opt/root-5.24.00/lib/root/libRint.so)
==13159==    by 0x8048EC4: main (in /opt/root-5.24.00/bin/root.exe)
==13159==  Address 0x0 is not stack'd, malloc'd or (recently) free'd

 *** Break *** segmentation violation
Attaching to program: /proc/13159/exe, process 13159
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/13159/exe, process 13159
Root > Function r2() busy flag cleared
==13159== 
==13159== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 756 from 4)
==13159== malloc/free: in use at exit: 6,695,449 bytes in 78,033 blocks.
==13159== malloc/free: 917,774 allocs, 839,741 frees, 64,073,972 bytes allocated.
==13159== For counts of detected errors, rerun with: -v
==13159== searching for pointers to 78,033 not-freed blocks.
==13159== checked 9,867,824 bytes.
==13159== 
==13159== LEAK SUMMARY:
==13159==    definitely lost: 34,747 bytes in 34 blocks.
==13159==      possibly lost: 359,824 bytes in 8,163 blocks.
==13159==    still reachable: 6,300,878 bytes in 69,836 blocks.
==13159==         suppressed: 0 bytes in 0 blocks.
==13159== Rerun with --leak-check=full to see details of leaked memory.

I have missed that GetEntriesFast() call!!!

Now everything works!!! Thanks a lot!

In my opinion all these complications with TChain and TTree diferences must be hidden from an end user…

Again,
THANKS!