Tree manipulations

Hi
I have recently switched code to SL5 and find that my tree manipulations stopped working and ended in a crash. I have reduced this to a simple(ish) example that demonstrates what I used to do but fails. However, the situation is very odd. If I write the tree on SL4 and read it on SL5 with v5_22 of root, this works. If I write the tree with the same code built on SL5 and try to read it on SL5 with v5_22 of root, this fails.
#include “TFile.h”
#include "TTree.h"
void test(std::string filename){
TFile _file0=new TFile(filename.c_str());
TFile f = new TFile(“testfile.root”,“recreate”);
TTree
mytree=(TTree
)_file0->Get(“NNInput”);
TTree* scopy=0;
scopy=mytree->CopyTree(“Target==1”);
TTree* bcopy=0;
bcopy=mytree->CopyTree(“Target==0”);
}
bash-3.2$ root
root [0] .L test.C+
Info in TUnixSystem::ACLiC: creating shared library /home/stdenis/aaasl5/./test_C.so
/home/stdenis/aaasl5/./test.C: In function ‘void test(std::string)’:
/home/stdenis/aaasl5/./test.C:5: warning: unused variable 'f’
root [1] test(“OldSL4.root”);
root [2] test(“NewSL5.root”);

*** Break *** segmentation violation
Attaching to program: /proc/1283/exe, process 1283
[Thread debugging using libthread_db enabled]
0xffffe405 in __kernel_vsyscall ()
#1 0x0047a5b3 in __waitpid_nocancel () from /lib/libc.so.6
#2 0x0041f07b in do_system () from /lib/libc.so.6
#3 0x0056dead in system () from /lib/libpthread.so.0
#4 0xf7a2621d in TUnixSystem::Exec(char const*) ()
from /home/cdfsoft/products/root/v5_22_00-GCC_3_4_3/Linux+2.6/lib/libCore.so
#5 0xf7a2ca75 in TUnixSystem::StackTrace() ()
from /home/cdfsoft/products/root/v5_22_00-GCC_3_4_3/Linux+2.6/lib/libCore.so
#6 0xf7a28d59 in TUnixSystem::DispatchSignals(ESignals) ()
from /home/cdfsoft/products/root/v5_22_00-GCC_3_4_3/Linux+2.6/lib/libCore.so
#7 0xf7a28e03 in SigHandler(ESignals) ()
from /home/cdfsoft/products/root/v5_22_00-GCC_3_4_3/Linux+2.6/lib/libCore.so
#8 0xf7a27f1e in sighandler(int) ()
from /home/cdfsoft/products/root/v5_22_00-GCC_3_4_3/Linux+2.6/lib/libCore.so
#9
#10 0xf631f016 in TBranch::Streamer(TBuffer&) ()
from /home/cdfsoft/products/root/v5_22_00-GCC_3_4_3/Linux+2.6/lib/libTree.so
#11 0xf79e0061 in TClass::Streamer(void*, TBuffer&, TClass const*) const ()
from /home/cdfsoft/products/root/v5_22_00-GCC_3_4_3/Linux+2.6/lib/libCore.so
#12 0xf69967d6 in TBufferFile::ReadObjectAny(TClass const*) ()
from /home/cdfsoft/products/root/v5_22_00-GCC_3_4_3/Linux+2.6/lib/libRIO.so
#13 0xf79cf407 in TObjArray::Streamer(TBuffer&) ()
from /home/cdfsoft/products/root/v5_22_00-GCC_3_4_3/Linux+2.6/lib/libCore.so
#14 0xf6a57ee7 in int TStreamerInfo::ReadBuffer<char**>(TBuffer&, char** const&, int, int, int, int) ()
from /home/cdfsoft/products/root/v5_22_00-GCC_3_4_3/Linux+2.6/lib/libRIO.so
#15 0xf6998ac8 in TBufferFile::ReadClassBuffer(TClass const*, void*, int, unsigned int, unsigned int, TClass const*) ()
from /home/cdfsoft/products/root/v5_22_00-GCC_3_4_3/Linux+2.6/lib/libRIO.so
#16 0xf6379d6a in TTree::Streamer(TBuffer&) ()
from /home/cdfsoft/products/root/v5_22_00-GCC_3_4_3/Linux+2.6/lib/libTree.so
#17 0xf699ec7d in TDirectoryFile::CloneObject(TObject const*, bool) ()
from /home/cdfsoft/products/root/v5_22_00-GCC_3_4_3/Linux+2.6/lib/libRIO.so
#18 0xf795be6b in TObject::Clone(char const*) const ()
from /home/cdfsoft/products/root/v5_22_00-GCC_3_4_3/Linux+2.6/lib/libCore.so
#19 0xf795b04c in TNamed::Clone(char const*) const ()
from /home/cdfsoft/products/root/v5_22_00-GCC_3_4_3/Linux+2.6/lib/libCore.so
#20 0xf637267e in TTree::CloneTree(long long, char const*) ()
from /home/cdfsoft/products/root/v5_22_00-GCC_3_4_3/Linux+2.6/lib/libTree.so
#21 0xf53b2aa7 in TTreePlayer::CopyTree(char const*, char const*, long long, long long) ()
from /home/cdfsoft/products/root/v5_22_00-GCC_3_4_3/Linux+2.6/lib/libTreePlayer.so
#22 0xf63762a3 in TTree::CopyTree(char const*, char const*, long long, long long) ()
from /home/cdfsoft/products/root/v5_22_00-GCC_3_4_3/Linux+2.6/lib/libTree.so
#23 0xf6c36b84 in test(std::basic_string<char, std::char_traits, std::allocator >) () from /home/stdenis/aaasl5/./test_C.so
#24 0xf6c36c3e in G__test_C_ACLiC_dict__0_1557(G__value*, char const*, G__param*, int) () from /home/stdenis/aaasl5/./test_C.so
#25 0xf7048ab6 in Cint::G__ExceptionWrapper(int ()(G__value, char const*, G__param*, int), G__value*, char*, G__param*, int) ()
from /home/cdfsoft/products/root/v5_22_00-GCC_3_4_3/Linux+2.6/lib/libCint.so
#26 0xf7100fdf in G__execute_call ()
from /home/cdfsoft/products/root/v5_22_00-GCC_3_4_3/Linux+2.6/lib/libCint.so
#27 0xf7101334 in G__call_cppfunc ()
from /home/cdfsoft/products/root/v5_22_00-GCC_3_4_3/Linux+2.6/lib/libCint.so
#28 0xf70df09b in G__interpret_func ()
from /home/cdfsoft/products/root/v5_22_00-GCC_3_4_3/Linux+2.6/lib/libCint.so
#29 0xf70cbdf6 in G__getfunction ()
from /home/cdfsoft/products/root/v5_22_00-GCC_3_4_3/Linux+2.6/lib/libCint.so
#30 0xf709dac7 in G__getitem ()
from /home/cdfsoft/products/root/v5_22_00-GCC_3_4_3/Linux+2.6/lib/libCint.so
#31 0xf70a2940 in G__getexpr ()
from /home/cdfsoft/products/root/v5_22_00-GCC_3_4_3/Linux+2.6/lib/libCint.so
#32 0xf713bdee in G__exec_statement ()
from /home/cdfsoft/products/root/v5_22_00-GCC_3_4_3/Linux+2.6/lib/libCint.so
#33 0xf7088434 in G__exec_tempfile_core ()
from /home/cdfsoft/products/root/v5_22_00-GCC_3_4_3/Linux+2.6/lib/libCint.so
#34 0xf7089ab6 in G__exec_tempfile_fp ()
from /home/cdfsoft/products/root/v5_22_00-GCC_3_4_3/Linux+2.6/lib/libCint.so
#35 0xf71455ca in G__process_cmd ()
from /home/cdfsoft/products/root/v5_22_00-GCC_3_4_3/Linux+2.6/lib/libCint.so
#36 0xf7a0eb15 in TCint::ProcessLine(char const*, TInterpreter::EErrorCode*) ()
from /home/cdfsoft/products/root/v5_22_00-GCC_3_4_3/Linux+2.6/lib/libCore.so
#37 0xf79313fb in TApplication::ProcessLine(char const*, bool, int*) ()
from /home/cdfsoft/products/root/v5_22_00-GCC_3_4_3/Linux+2.6/lib/libCore.so
#38 0xf6cb89ac in TRint::HandleTermInput() ()
from /home/cdfsoft/products/root/v5_22_00-GCC_3_4_3/Linux+2.6/lib/libRint.so
#39 0xf6cb6ba5 in TTermInputHandler::Notify() ()
from /home/cdfsoft/products/root/v5_22_00-GCC_3_4_3/Linux+2.6/lib/libRint.so
#40 0xf6cb9454 in TTermInputHandler::ReadNotify() ()
from /home/cdfsoft/products/root/v5_22_00-GCC_3_4_3/Linux+2.6/lib/libRint.so
#41 0xf7a248b9 in TUnixSystem::CheckDescriptors() ()
from /home/cdfsoft/products/root/v5_22_00-GCC_3_4_3/Linux+2.6/lib/libCore.so
#42 0xf7a294b4 in TUnixSystem::DispatchOneEvent(bool) ()
from /home/cdfsoft/products/root/v5_22_00-GCC_3_4_3/Linux+2.6/lib/libCore.so
#43 0xf799359e in TSystem::InnerLoop() ()
from /home/cdfsoft/products/root/v5_22_00-GCC_3_4_3/Linux+2.6/lib/libCore.so
#44 0xf79933a9 in TSystem::Run() ()
from /home/cdfsoft/products/root/v5_22_00-GCC_3_4_3/Linux+2.6/lib/libCore.so
#45 0xf7931577 in TApplication::Run(bool) ()
from /home/cdfsoft/products/root/v5_22_00-GCC_3_4_3/Linux+2.6/lib/libCore.so
#46 0xf6cb7549 in TRint::Run(bool) ()
from /home/cdfsoft/products/root/v5_22_00-GCC_3_4_3/Linux+2.6/lib/libRint.so
#47 0x08048de1 in main ()
A debugging session is active.

    Inferior 1 [process 1283] will be detached.

Quit anyway? (y or n) [answered Y; input not from terminal]
Detaching from program: /proc/1283/exe, process 1283
Root >

I have tried a number of things such as setting directories before doing the copy, and also doing a TreeClone or a Clone first and the a copy with care taken with directories. None of this works.

So back to the fundamental question which is given a Tree, how can I manipulate it to extract portions
where I really dont want to know any details of the branches and leaves other than a few needed to do the selections?
Thanks
Rick

Hi,

This behavior is odd. Can you send me your testfile.root so that I can try to reproduce this issue?

[quote]So back to the fundamental question which is given a Tree, how can I manipulate it to extract portions
where I really dont want to know any details of the branches and leaves other than a few needed to do the selections?[/quote]CopyTree has you used it should be the answer :slight_smile:. (See other possible example in $ROOTSYS/tutorials/tree/copytree* , also see TFile::MakeProject in case you need a quick to recreate the user object shared library).

Cheers,
Philippe.

ppewww.physics.gla.ac.uk/~stdeni … eeProblem/
contains all my attempts to solve the problem.

The files

ppewww.physics.gla.ac.uk/~stdeni … ewSL5.root
ppewww.physics.gla.ac.uk/~stdeni … ldSL4.root

are the ones you want.
Thank you
Rick

I should add that the result below does work – so I thought that taking care with directories will help. It didn’t.
I also was not sure why the TTree copy examples to which you refer don’t do CopyTree but CloneTree – there are no examples of CopyTree itself.

I also note that the files used below by Aidan Robson are different from mine so I want to check on that.
I wonder if there is something gone bad on the input files – but those I posted so if you can check their integrity that would be helpful.

#include “TFile.h”
#include "TTree.h"
void testcopy(std::string filename){
TFile _file0=new TFile(filename.c_str());
TFile _file1=new TFile(filename.c_str());
TFile f = new TFile(“testfile.root”,“recreate”);
TTree
mytree1=(TTree
)_file0->Get(“CollectionTree”);
TTree
mytree2=(TTree*)_file1->Get(“CollectionTree”);

TTree* scopy=0;
scopy=mytree1->CopyTree(“Target==1”);

TTree* bcopy=0;
bcopy=mytree2->CopyTree(“Target==0”);

}

I checked that the script works with opening the file twice:
#include “TFile.h”
#include "TTree.h"
void testAidan1(std::string filename){
TFile _file0=new TFile(filename.c_str());
TFile _file1=new TFile(filename.c_str());
TFile f = new TFile(“testfile.root”,“recreate”);
TTree
mytree1=(TTree
)_file0->Get(“NNInput”);
TTree
mytree2=(TTree*)_file1->Get(“NNInput”);

TTree* scopy=0;
scopy=mytree1->CopyTree(“Target==1”);

TTree* bcopy=0;
bcopy=mytree2->CopyTree(“Target==0”);
}
bash-3.2$ root
root [0] .L testAidan1.C+
root [1] testAidan1(“OldSL4.root”)
root [2] testAidan1(“NewSL5.root”)
root [3] .q
bash-3.2$

I think the input file is causing the problem. I have taken the example “basic.C” and modified it to add a “Target” column. If I do this I can make something that separates target values of 1 and 0 into a “Signal” and “Background” directory in the output file. This works. When I read in the NewSL5.root file, it crashes.

The code is in ppewww.physics.gla.ac.uk/~stdeni … rootbasic/
(I modified basic.C slightly to just pick up the local basic.dat and add the target column).

You can see the effect if you run ./testit.sh
(and cleanup later with ./cleanit.sh)

Of course part of the effect is that these are all floats and the ntuple use is a mix of types.

Hi,

Indeed this is known problem in v5.22/00 which has been fixed in the patch release v5.22/00c (circa June 2009).

Also note, that with: TTree* scopy=0; scopy=mytree1->CopyTree("Target==1"); TTree* bcopy=0; bcopy=mytree2->CopyTree("Target==0");you end up with both copies of the TTree with the same and thus they are (almost) indistinguishable. Thus I recommend you put them in different directory (as you seem to have done in later tries) or that you renamed one for them:TTree* scopy=0; scopy=mytree1->CopyTree("Target==1"); scopy->SetName("CollectionTreeTargetEq1"); TTree* bcopy=0; bcopy=mytree2->CopyTree("Target==0");

Cheers,
Philippe.