Re: [ROOTDEV] compiling program with TTree

From: Rene Brun <Rene.Brun_at_cern.ch>
Date: Tue, 30 Jan 2007 08:54:57 +0100


Christian,

In your interpreted script treeTestMacro.C, you must load the shared library containing
TTestBranch or use ACLIC (see below).

Rene Brun

#include "iostream"
//#include "TTestBranch.h"

void treeTestMacro() {
  gROOT->ProcessLine(".L TTestBranch.cpp+");   TFile* File = new TFile("testTree.root");   //TTree* Tree = new TTree();
  TTree *Tree = (TTree*)File->Get("tree");  

  TTestBranch* branch = 0;  

  Tree->SetBranchAddress("testBranch", &branch);

  int nbrEntries = Tree->GetEntries();
  cout<<" nbr entries: "<<nbrEntries<<endl;

  for (int i = 0; i < nbrEntries; i++) {     Tree->GetEntry(i);
    cout<<"Event number "<<branch->GetEventNumber()<<" event code "<<branch->GetEventCode()<<endl;

    cout<<"Is cool "<<branch->GetIsCool()<<" Energy "<<branch->GetE()<<endl;
  }  

}

Christian Hansen wrote:
> Dear Rene,
>
> Thanks alot! Those changes helped to get my test program
> to work. However when I add some more variables to the
> TTree it seems as if the macro cannot properly read in
> the TTree. Why is that?
>
> I show with an example:
>
> In attached test.tgz the branch TTestBranch has these
> variables:
> int EventNumber; int EventCode; double Energy; bool IsCool;
> After I produced the tree with TMakeTestTree I read it
> with the macro, treeTestMacro. The variables EventNumber
> and EventCode gets correct numbers but the other variables
> are not assigned correctly.
>
> In attached testWithoutCode.tgz I have taken away the
> variable EventCode from the TTestBranch. Then all the
> other variables gets correct values when I read in the
> TTree from the macro file.
>
> I use ROOT Version 5.04/00 and Fedora 4.
>
> What could be the reason that it doesnt work if the
> tree has too many variables?
>
> With best regards
> /Christian
>
>
>
>
>
>
>> Hi Christian,
>>
>> You need two changes in your program:
>>
>> -In treeTestMacro.C, replace
>> TTestBranch* branch;
>> by
>> TTestBranch* branch=0;
>>
>> -In TTestBranch.h, just before the line "};", add
>> ClassDef(TTestBranch,1)
>>
>> -then modify your makefile to generate the dictionary with rootcint like
>> shown below
>> rootcint -f TTestBranchDict.cpp -c TTestBranch.h
>> g++ -o runMakeTestTree.run runMakeTestTree.cpp TMakeTestTree.cpp \
>> TTestBranch.cpp TTestBranchDict.cpp `root-config --cflags --libs`
>>
>>
>> Rene Brun
>>
>>
>> Christian Hansen wrote:
>>
>>> Dear Rooters,
>>>
>>> I'm having problems getting a small test program
>>> working where I tried to follow the instructions
>>> for TTree.
>>>
>>> I'm trying to produce a tree with an "home made" branch
>>> that I call TTestBranch;
>>>
>>> TTestBranch* testBranch = new TTestBranch();
>>> fTree->Branch("testBranch","TTestBranch",&testBranch,64000,99);
>>>
>>> When I run the program I get the error:
>>>
>>> [chris_at_localhost test]$ ./runMakeTestTree.run
>>> Error in <TTree::Bronch>: Cannot find class:TTestBranch
>>>
>>> But still a tree is produced in the file "testTree.root".
>>> When I try to read in the produced tree with a macro
>>> (treeTestMacro.C) I also get error:
>>>
>>> root [0] .x treeTestMacro.C
>>> Error in <TTree::SetBranchAddress>: unknown branch -> testBranch
>>>
>>> All files are attached in the tar ball test.tgz.
>>>
>>> I did some research and found out that I have to
>>> produce a dictionary with rootcint. So I tried
>>>
>>> rootcint -v -l -f tTestBranchDict.cpp -c TTestBranch.h
>>>
>>> and added ClassDef(TTestBranch, 1); in TTestBranch.h
>>> and ClassImp(TTestBranch); in TTestBranch.cpp.
>>> I also tried to change in the Makefile but it does not
>>> want to compile; "gmake" gives me errors like:
>>>
>>> TTestBranch.o(.text+0x1a9): In function `__static_initialization_and_destruction_0(int, int)':
>>> TTestBranch.cpp: undefined reference to `ROOT::GenerateInitInstance(TTestBranch const*)'
>>>
>>> All files are attached in the tar ball dictTest.tgz.
>>>
>>> I use Fedora 4 and ROOT Version 5.04/00.
>>>
>>> If someone could point out to me what I have to change
>>> to get this small test program working I would be very
>>> thanksful!
>>>
>>> Thanks!
>>> / Christian Hansen
>>>
>>> ================================================
>>> Dep. of Phys. Office: +1 250 721 7710
>>> Univ of Victoria Mobile: +1 250 588 0860
>>> PO Box 3055
>>> V8W 3P6 Victoria BC
>>> Canada
>>> ------------------------------------------------
>>> Home Page : http://particle.phys.uvic.ca/~hansen
>>> http://cern.ch/christian.hansen
>>>
>>
>
> / Christian Hansen
>
> ================================================
> Dep. of Phys. Office: +1 250 721 7710
> Univ of Victoria Mobile: +1 250 588 0860
> PO Box 3055
> V8W 3P6 Victoria BC
> Canada
> ------------------------------------------------
> Home Page : http://particle.phys.uvic.ca/~hansen
> http://cern.ch/christian.hansen
Received on Tue Jan 30 2007 - 08:55:18 CET

This archive was generated by hypermail 2.2.0 : Tue Jan 30 2007 - 11:50:01 CET