RE: Adding new Branch to TTree

From: Philippe Canal <pcanal_at_fnal.gov>
Date: Tue, 1 Jul 2008 20:58:57 -0500


Hi,

Upon closer inspection, you code will work if you replace   TTree* tnew = (TTree*)t->Clone();
with
  TTree* tnew = (TTree*)t->CloneTree();

Cheers,
Philippe.

The difference is that CloneTree is _also_ copying the TTree's data. [Clone only copies the metadata which contains amongst other things where each 'part' of the TTree data is in the file. So when you use the file new.root as created by this script, the TTree looks at places where the data is __not__ (at least not in this file). Also the fact that you did put _some_ data in the file (when adding the branch) means that the address
(at least as the beginning of the TTree) that it look for actually
exist in the file and so the system has no good way to know that the data is not there and read random bits].

-----Original Message-----
From: owner-roottalk_at_root.cern.ch [mailto:owner-roottalk_at_root.cern.ch] On Behalf Of OKUMURA, Akira
Sent: Tuesday, July 01, 2008 3:32 PM
To: ROOT Talk
Subject: [ROOT] Adding new Branch to TTree

Hello ROOTers,

My colleague wrote a PyROOT script which adds a new branches to an existing tree and saves it to new file. I ran this script but I cannot access to the original branches in the resultant file. I wrote an C++ equivalent code and tried it. But I got same error. Where should it be modified?

I also tried TTree::SetEntries(), TTree::SetBranchStatus() and TTree::Fill(). But these did not solve this error.

5.20.00 & 5.18.00 (OS X Leopard Intel 32 bit) 5.20.00 (Fedora Core 8 64 bit)

Float_t a;
TBranch* aBra = tnew->Branch("a", &a, "a/F"); for(int i=0; i<t->GetEntries(); i++){

   t->GetEntry(i);
   // Other calculations here...
   aBra->Fill();
} // i

tnew->Write();
fnew->Close();

(no debugging symbols found)

0x0000003a33e9a835 in waitpid () from /lib64/libc.so.6 Missing separate debuginfos, use: debuginfo-install expat.x86_64 fontconfig.x86_64 freetype.x86_64 gcc.x86_64 giflib.x86_64 glibc.x86_64 libICE.x86_64 libSM.x86_64 libX11.x86_64 libXau.x86_64 libXcursor.x86_64 libXdmcp.x86_64 libXext.x86_64 libXfixes.x86_64 libXft.x86_64 libXpm.x86_64 libXrender.x86_64 libjpeg.x86_64 libpng.x86_64 libtiff.x86_64 libxcb.x86_64 zlib.x86_64 #1 0x0000003a33e3ce39 in do_system () from /lib64/libc.so.6 #2 0x000000000084f4e2 in TUnixSystem::StackTrace ()

    from /usr/local/root_v5.20.00/lib/libCore.so #3 0x000000000084ddaa in TUnixSystem::DispatchSignals ()

    from /usr/local/root_v5.20.00/lib/libCore.so

#4  <signal handler called>
#5  0x0000003a33e7b6af in memcpy () from /lib64/libc.so.6
#6  0x00007fa1d1ed0fcb in TBasket::ReadBasketBuffers ()

    from /usr/local/root_v5.20.00/lib/libTree.so #7 0x00007fa1d1ed8a40 in TBranch::GetBasket ()

    from /usr/local/root_v5.20.00/lib/libTree.so #8 0x00007fa1d1ed9018 in TBranch::GetEntry ()

    from /usr/local/root_v5.20.00/lib/libTree.so #9 0x00007fa1cfdddd1c in TTreeFormula::EvalInstance ()

    from /usr/local/root_v5.20.00/lib/libTreePlayer.so #10 0x00007fa1cfdcdbad in TSelectorDraw::ProcessFill ()

    from /usr/local/root_v5.20.00/lib/libTreePlayer.so #11 0x00007fa1cfded2f8 in TTreePlayer::Process ()

    from /usr/local/root_v5.20.00/lib/libTreePlayer.so #12 0x00007fa1cfdeee09 in TTreePlayer::DrawSelect ()

    from /usr/local/root_v5.20.00/lib/libTreePlayer.so #13 0x00000000009be9e3 in G__G__Base2_10_0_15 ()

    from /usr/local/root_v5.20.00/lib/libCore.so #14 0x0000000000fe58fd in Cint::G__ExceptionWrapper ()

    from /usr/local/root_v5.20.00/lib/libCint.so #15 0x000000000108ffdc in G__execute_call ()

    from /usr/local/root_v5.20.00/lib/libCint.so #16 0x0000000001090d70 in G__call_cppfunc ()

    from /usr/local/root_v5.20.00/lib/libCint.so #17 0x000000000106b036 in G__interpret_func ()

    from /usr/local/root_v5.20.00/lib/libCint.so #18 0x000000000105acb2 in G__getfunction ()

    from /usr/local/root_v5.20.00/lib/libCint.so #19 0x000000000113d939 in G__getstructmem ()

    from /usr/local/root_v5.20.00/lib/libCint.so #20 0x0000000001133df0 in G__getvariable ()

    from /usr/local/root_v5.20.00/lib/libCint.so #21 0x000000000102ebac in G__getitem ()

    from /usr/local/root_v5.20.00/lib/libCint.so #22 0x000000000102eeb9 in G__getitem ()

    from /usr/local/root_v5.20.00/lib/libCint.so #23 0x0000000001035edb in G__getexpr ()

    from /usr/local/root_v5.20.00/lib/libCint.so #24 0x00000000010bb334 in G__exec_statement ()

    from /usr/local/root_v5.20.00/lib/libCint.so #25 0x000000000101c0f6 in G__exec_tempfile_core ()

    from /usr/local/root_v5.20.00/lib/libCint.so #26 0x000000000101c3fe in G__exec_tempfile_fp ()

    from /usr/local/root_v5.20.00/lib/libCint.so #27 0x00000000010c4fe5 in G__process_cmd ()

    from /usr/local/root_v5.20.00/lib/libCint.so #28 0x000000000083f697 in TCint::ProcessLine ()

    from /usr/local/root_v5.20.00/lib/libCore.so #29 0x0000000000788069 in TApplication::ProcessLine ()

    from /usr/local/root_v5.20.00/lib/libCore.so #30 0x0000000000120801 in TRint::HandleTermInput ()

    from /usr/local/root_v5.20.00/lib/libRint.so #31 0x000000000011f1c7 in TTermInputHandler::Notify ()

    from /usr/local/root_v5.20.00/lib/libRint.so #32 0x000000000012110d in TTermInputHandler::ReadNotify ()

    from /usr/local/root_v5.20.00/lib/libRint.so #33 0x000000000084d9e3 in TUnixSystem::CheckDescriptors ()

    from /usr/local/root_v5.20.00/lib/libCore.so #34 0x000000000084e458 in TUnixSystem::DispatchOneEvent ()

    from /usr/local/root_v5.20.00/lib/libCore.so #35 0x00000000007da666 in TSystem::InnerLoop ()

    from /usr/local/root_v5.20.00/lib/libCore.so #36 0x00000000007dda41 in TSystem::Run ()

    from /usr/local/root_v5.20.00/lib/libCore.so #37 0x0000000000786e3f in TApplication::Run ()

    from /usr/local/root_v5.20.00/lib/libCore.so #38 0x0000000000120d00 in TRint::Run ()

    from /usr/local/root_v5.20.00/lib/libRint.so #39 0x000000000040102d in main ()
The program is running. Quit anyway (and detach it)? (y or n) [answered Y; input not from terminal]
Detaching from program: /proc/9045/exe, process 9045 Root >

Regards,

OKUMURA, Akira oxon_at_ceres.phys.s.u-tokyo.ac.jp Department of Physics, The University of Tokyo 7-3-1 Hongo, Bunkyo-ku, Tokyo 113-0033
TEL/FAX +81 3-5841-4173/4059
Skype : okumura.akira Received on Wed Jul 02 2008 - 03:59:23 CEST

This archive was generated by hypermail 2.2.0 : Wed Jul 02 2008 - 11:50:02 CEST