TTree::SetDirectory does not work as expected in PROOF

Hi,

I found that the following code crashed with multiple files on PROOF-Lite.

[code]void mySelector::Init(TTree *tree)
{

if (!newTree) {
newTree = (TTree*)tree->CloneTree(0);
newTree->SetName(“newTree”);
newTree->SetDirectory(fFile);
newTree->AutoSave();
} else {
tree->CopyAddresses(newTree);
}
}

Bool_t tmySelector::Process(Long64_t entry)
{
GetEntry(entry);

… selection here …

newTree->Fill();
return kTRUE;
}
[/code]

and got error at processing the second file on each worker:

[quote]15:55:45 19124 Wrk-0.0 | *** Break ***: segmentation violation

There was a crash.
This is the entire stack trace of all threads:

#0 0x00002b95caf7c335 in waitpid () from /lib64/libc.so.6
#1 0x00002b95caf1f2e1 in do_system () from /lib64/libc.so.6
#2 0x00002b95c8fb6e9a in TUnixSystem::StackTrace ()
from /afs/usatlas.bnl.gov/cernsw/lcg/app/releases/ROOT/5.26.00/x86_64-slc5-gcc43
-opt/root/lib/libCore.so
#3 0x00002b95c8fb7895 in TUnixSystem::DispatchSignals ()
from /afs/usatlas.bnl.gov/cernsw/lcg/app/releases/ROOT/5.26.00/x86_64-slc5-gcc43
-opt/root/lib/libCore.so
#4
#5 0x00002b95cc648402 in TBranch::GetFile ()
from /afs/usatlas.bnl.gov/cernsw/lcg/app/releases/ROOT/5.26.00/x86_64-slc5-gcc43
-opt/root/lib/libTree.so
#6 0x00002b95cc64114e in TBasket::WriteBuffer ()
from /afs/usatlas.bnl.gov/cernsw/lcg/app/releases/ROOT/5.26.00/x86_64-slc5-gcc43
-opt/root/lib/libTree.so
#7 0x00002b95cc648f15 in TBranch::WriteBasket ()
from /afs/usatlas.bnl.gov/cernsw/lcg/app/releases/ROOT/5.26.00/x86_64-slc5-gcc43
-opt/root/lib/libTree.so
#8 0x00002b95cc649543 in TBranch::Fill ()
from /afs/usatlas.bnl.gov/cernsw/lcg/app/releases/ROOT/5.26.00/x86_64-slc5-gcc43-opt/root/lib/libTree.so
#9 0x00002b95cc68f8d5 in TTree::Fill ()
from /afs/usatlas.bnl.gov/cernsw/lcg/app/releases/ROOT/5.26.00/x86_64-slc5-gcc43-opt/root/lib/libTree.so
#10 0x00002b95ceae9980 in mySelector::Process ()
[/quote]

But if I changed the directory to fFile prior to CloneTree, everything started to work fine.

[code]void mySelector::Init(TTree *tree)
{

if (!newTree) {
fFile->cd();
newTree = (TTree*)tree->CloneTree(0);
newTree->SetName(“newTree”);
// newTree->SetDirectory(fFile);
newTree->AutoSave();
} else {
tree->CopyAddresses(newTree);
}
}
[/code]

Any idea why the first one without “fFile->cd()” failed on PROOF?

–Shuwei

Hi,

Thanks for reporting this bug. My guess is that you TTree does have a BranchRef in which case I just uploaded a fix as revision 33313 of the trunk and you can work around the problem by using:newTree->SetDirectory(fFile); if (newTree->GetBranchRef()) newTree->GetBranchRef()->SetFile(fFile);

Cheers,
Philipe.

Hi Philipe,

You are right. After adding “newTree->GetBranchRef()->SetFile(fFile)”, the crash is gone. The BranchRef must be added by PROOF. Because there is no BranchRef at local ROOT. Many thanks.

–Shuwei