Problem filling cloned TTree

Hello,

The problem I am facing, in pseudo-code is as follows:

class MyClass {
public:
init();
fun ();
private:
TChain* thisChain;
TTree* myTree;
};

MyClass::init () {
// Initialise thisChain;
thisChain->Add(…);
myTree = thisChain->CloneTree(0);
fun();
}

MyClass::fun () {

for (…) { // Loop over thisChain
if (…) myTree->Fill(); // Fill Cloned tree after applying some selection criteria
}

}

This crashes while trying to fill the cloned tree, with the stack trace [1]. It is definitely a memory allocation problem but I’m not sure what the workaround could be.

Thanks!

[1]
The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug report at
root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.

#5 0x0000003d8107c60c in memcpy () from /lib64/libc.so.6
#6 0x00002b852af79dd9 in TBufferFile::WriteFastArray(char const*, int) ()
from /afs/cern.ch/cms/slc5_amd64_gcc434/cms/cmssw/CMSSW_4_2_8/external/slc5_amd64_gcc434/lib/libRIO.so
#7 0x00002b85280cf5dc in TBranch::FillLeaves(TBuffer&) ()
from /afs/cern.ch/cms/slc5_amd64_gcc434/cms/cmssw/CMSSW_4_2_8/external/slc5_amd64_gcc434/lib/libTree.so
#8 0x00002b85280d1b1c in TBranch::Fill() ()
from /afs/cern.ch/cms/slc5_amd64_gcc434/cms/cmssw/CMSSW_4_2_8/external/slc5_amd64_gcc434/lib/libTree.so
#9 0x00002b8528116d2b in TTree::Fill() ()
from /afs/cern.ch/cms/slc5_amd64_gcc434/cms/cmssw/CMSSW_4_2_8/external/slc5_amd64_gcc434/lib/libTree.so
#10 0x000000000040c566 in myAnalyzer::evtLoop_() ()
#11 0x0000000000407464 in myAnalyzer::process_() ()
#12 0x0000000000404f34 in main ()

}

[quote]thisChain->Add(…);
myTree = thisChain->CloneTree(0);[/quote]The output/cloned TTree is likely to be attached to the input file (and thus deleted when one of the input file is closed). Make sure to explicitly attached it to your output file:myTree->SetDirectory(fOutputFile);

Cheers,
Philippe.