TTree empty with C++ exececutable

Hi,
I’ve tried a basic TTree example and in prinziple this is working with CINT. But now I have to include this into a C++ application.
When I run the executable, the tree stays empty.

The code is attached:

#include "TFile.h"
#include "TTree.h"

typedef struct {Float_t x,y,z;} POINT;

int main(){
        TFile* hfile = new TFile("test.root","RECREATE");

        TTree *tree = new TTree("tree","MicroMegaS-Simulation");
        POINT initial;
        POINT final;
        Int_t status;

        TBranch* b_initial = tree->Branch("initial",&initial,"x/F:y/F:z/F");
        TBranch* b_final = tree->Branch("final",&final,"x/F:y/F:z/F");
        TBranch* b_status = tree->Branch("status", &status, "status/I");

        for(int i=0; i<10; i++){
                status = i;

                initial.x = i;
                initial.y = i*i;
                initial.z = i*i;

                final.x = i;
                final.y = i;
                final.z = i;

                tree -> Fill();
        }
        tree -> Print();

        hfile -> Write();
        return 0;
}

and this produces the following output.

******************************************************************************
*Tree    :tree      : MicroMegaS-Simulation                                  *
*Entries :        0 : Total =             827 bytes  File  Size =          0 *
*        :          : Tree compression factor =   1.00                       *
******************************************************************************
*Br    0 :TRefTable : List of branch numbers with referenced objects         *
*Entries :        0 : Total  Size=        436 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*

From the CINT-macro I would expect three branches with each 10 entries. But somehow I get only one branch with no entries. I have no idea what I’m doing wrong.

Cheers,

Jochen

1 Like

I’m afraid you need to report the details of your operating system, compiler version, ROOT version.

If I try: `root-config --cxx --cflags` -O2 -W -Wall -o main main.cxx `root-config --libs` ./main I get: [code]******************************************************************************
*Tree :tree : MicroMegaS-Simulation *
*Entries : 10 : Total = 2762 bytes File Size = 0 *

  •    :          : Tree compression factor =   1.00                       *
    

*Br 0 :initial : x/F:y/F:z/F *
*Entries : 10 : Total Size= 888 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 1 :final : x/F:y/F:z/F *
*Entries : 10 : Total Size= 882 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 2 :status : status/I *
*Entries : 10 : Total Size= 680 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *
[/code]

BTW. instead of “hfile -> Write();” use: tree -> Write(); delete hfile; // automatically deletes "tree", too

Thanks for your reply. I tried the command, you suggested, but also this does not fill the tree.

Here is the evironment data, which I have to compile and operate with.
My Root Version root-config --version: 5.34/00
My GCC version gcc --version: gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-52)

All this is operating in a Scientific Linux.

I do the compilation via

g++ -Wall -Wextra -c  `root-config --cflags` test_tree.cc
g++ -o test_tree test_tree.o `root-config --glibs` -lGeom -lgfortran -lm

Cheers,
Jochen

Try to modify the linking command line:
root-config --ldflags --glibs

I’ve tried also this, but this only adds a -m64 to my compile command. Unfortunately the behaviour does not change.

Try to execute “ldd test_tree” and carefully inspect the returned list of libraries (i.e. check that they come from your “root-config --libdir” subdirectory or from “/lib64”, “/usr/lib64”, …).

Also, try to execute “root-config --etcdir” and inspect files inside of the returned subdirectory (i.e. check that they really belong to your ROOT distribution and not to another version of ROOT which may possibly be installed on your system).
Note: different ROOT versions / distributions must NOT share the “root-config --etcdir” subdirectory.

Thanks a lot, this was the right hint. Something went wrong with my LD_LIBRARY_PATH. Somehow a old root version appeared there and due to this the libs got mixed up.

Thanks

Jochen