Hi,
Removing a branch from a TTree is not officially supported (as, in particular, it does not really reclaim the disk space anyway).
To resolve the segmentation, you need to use the following code:
tree->GetListOfBranches()->Remove(br_a); tree->GetListOfBranches()->Compress();
which makes sure that the collection of branches in the state expected by the rest of the TTree code.
Cheers,
Philippe.
On 4/30/11 10:33 PM, Oleksandr Zenaiev wrote:
> Hello ROOTers,
>
> I have a problem with TTree class after removing one of branches.
>
> Here is my code (simplified enough to represent a problem):
>
> //file: test_tree.cxx
> #include "TTree.h"
> #include "TBranch.h"
>
> int main() {
> TTree* tree=new TTree("orange", "orange");
> int a;
> TBranch* br_a=tree->Branch("a",&a, "a/I");
> int b;
> TBranch* br_b=tree->Branch("b",&b, "b/I");
> for (int i=0; i<10; i++) {
> a=i;
> b=i*i;
> tree->Fill();
> }
> tree->GetListOfBranches()->Remove(br_a);
> int b1;
> tree->SetBranchAddress("b",&b1);
> return 0;
> }
>
> Then I tried to run it and got segmentation violation:
>
> *** Break *** segmentation violation
>
>
>
> ===========================================================
> There was a crash (#7 0x0031cd8c in SigHandler ()).
> This is the entire stack trace of all threads:
> ===========================================================
> from /lib/ld-linux.so.2
> #0 0x0086f7a2 in _dl_sysinfo_int80 () from /lib/ld-linux.so.2
> #1 0x0440a7e3 in __waitpid_nocancel () from /lib/tls/libc.so.6
> #2 0x043b4649 in do_system () from /lib/tls/libc.so.6
> #3 0x06f8b8bd in system () from /lib/tls/libpthread.so.0
> #4 0x0031a67f in TUnixSystem::Exec ()
> from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.26.00/lib/libCore.so.5.26
> #5 0x0032048c in TUnixSystem::StackTrace ()
> from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.26.00/lib/libCore.so.5.26
> #6 0x0031ccfe in TUnixSystem::DispatchSignals ()
> from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.26.00/lib/libCore.so.5.26
> #7 0x0031cd8c in SigHandler ()
> from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.26.00/lib/libCore.so.5.26
> #8 0x0031c025 in sighandler ()
> from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.26.00/lib/libCore.so.5.26
> #9<signal handler called>
> #10 0x059751e3 in TTree::GetBranch ()
> from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.26.00/lib/libTree.so.5.26
> #11 0x05979138 in TTree::SetBranchAddress ()
> from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.26.00/lib/libTree.so.5.26
> #12 0x08048d65 in TTree::SetBranchAddress<int> ()
> #13 0x08048c88 in main ()
> ===========================================================
>
>
> The lines below might hint at the cause of the crash.
> If they do not help you then please submit a bug report at
> http://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.
> ===========================================================
> #10 0x059751e3 in TTree::GetBranch ()
> from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.26.00/lib/libTree.so.5.26
> #11 0x05979138 in TTree::SetBranchAddress ()
> from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.26.00/lib/libTree.so.5.26
> #12 0x08048d65 in TTree::SetBranchAddress<int> ()
> #13 0x08048c88 in main ()
> ===========================================================
>
> I am using ROOT 5.26/00c (SLD, gcc 3.4.6).
>
> Thanks in advance,
> Oleksandr.
>
Received on Sun May 01 2011 - 06:20:23 CEST
This archive was generated by hypermail 2.2.0 : Mon May 02 2011 - 11:50:01 CEST