Problems with TBranchOld

Hi ,
I’m trying to read an ASCII file and fill in a Tree some data and ojects; the single data doesn’t worry me at all , but with the object I’m getting trouble. Here is the part of the code who caused the segmentation violation during the run of the executable(compilation is ok)

#include “io_gcc.hh”
#include “Track.hh”
#include “HitsEvent.hh”
#include “OfflineTrigger.hh”

#include “TFILE.h”
#include “TH1.h”
#include “TFile.h”
#include “TTree.h”
#include “TBranch.h”

int main(int argc, char *argv[])
{
TFile *outputfile = new TFile(“prova.root”,“RECREATE”);
TTree *ttr = new TTree(“ttr”,“Physics”);

TBranch *bra = ttr->BranchOld(“neutrino”,“Neutrino”,&nu,4000,1);
//makes me problem

ttr->Branch(“num_hit”,&num_hit,“num_hit/i”);
//does work



and here is the output during the run

*** Break *** segmentation violation
Generating stack trace…
0x003061e8 in G__CallFunc::Exec(void*) + 0x6e from /usr/local/root/lib/libCint.so
0x00c33e2b in TClass::BuildRealData(void*) + 0x2f7 from /usr/local/root/lib/libCore.so
0x00803571 in TTree::BuildStreamerInfo(TClass*, void*) + 0x31 from /usr/local/root/lib/libTree.so
0x007e9577 in TBranchObject::TBranchObject[in-charge](char const*, char const*, void*, int, int, int) + 0xb7 from /usr/local/root/lib/libTree.so
0x00801fd1 in TTree::BranchOld(char const*, char const*, void*, int, int) + 0x8f from /usr/local/root/lib/libTree.so
0x08050708 in main + 0x3d0 from ./analisi
0x0838d770 in __libc_start_main + 0xf0 from /lib/tls/libc.so.6
0x080502a9 in __gxx_personality_v0 + 0x1b1 from ./analisi
Aborted

Hi,

We do not recommend using BranchOld directly.
(Use Branch instead).

Also what is ‘v’? The 3rd argument to BranchOld
(and Branch when using objects) is supposed to
be the address of a pointer (You probably meant
&v).

Cheers.
Philippe.

Hi and thanks for your reply

v is wrong , instead I got &nu in my code
I defined a pointer (*nu) to a class Neutrino, that holds all the physical information that I’m getting from the file

#include “TFILE.h”
#include “TH1.h”
#include “TFile.h”
#include “TTree.h”
#include “TBranch.h”

int main(int argc, char *argv[])
{
int num_hit;
Neutrino *nu;
TFile *outputfile = new TFile(“prova.root”,“RECREATE”);
TTree *ttr = new TTree(“ttr”,“Physics”);

ttr->Branch(“neutrino”,“Neutrino”,&nu,4000,1);
//makes still problems

ttr->Branch(“num_hit”,&num_hit,“num_hit/i”);
//does work

how can I manage an entire object with Branch?

sorry “&nu” not &nu

I mean “adress of nu”!

Instaed of
Neutrino *nu;
you should preset your pointer to 0
Neutrino *nu=0;

Rene

Thanks to all,
my program is now working fine , using only Branch and with the presetted pointer…
and including some libraries that I forgot…!
bye