[ROOT] problem storing a pointed class in a TTree

From: Christophe Delaere (Christophe.Delaere@cern.ch)
Date: Fri Aug 09 2002 - 14:05:16 MEST


Hi Rooters,

I plan to store a set of classes with pointers between them. As a first
exercise I've just taken 2 classes, one having a pointer to the other.
I just want to store everything in a TTree, with the second class being
a sub-branch of the first one.

The problem I have is that the pointer seems not to be followed by the
streamer.
I can't figure out where is the problem. If I replace the pointer by a
simple member, everything woks then.

I've included the code of my test program, as well as the linkdef file
and the sequence I performed to compile it.

Can anybody tell me what I'm doing wrong ?


Thanks in advance,
Christophe.



/********************************************************
 * BankClasses.h
 *******************************************************/

#ifndef _ALPHACLASSES_H_
#define _ALPHACLASSES_H_

#include <TObject.h>

class RLEP : public TObject
{
public:
     virtual ~RLEP();
     int LE;
     int LF;
ClassDef(RLEP,1)  //LEP information
};

class QEXT : public TObject
{
public:
     virtual ~QEXT();
     RLEP* LP;
     int bb;
ClassDef(QEXT,1)  //external information access point
};

#endif

/********************************************************
 * BankClasses.cpp
 *******************************************************/

#include "BankClasses.h"

ClassImp(RLEP)

RLEP::~RLEP(){}


ClassImp(QEXT)

QEXT::~QEXT(){}

/************************************************************
 * Test main file
 ***********************************************************/

#include <iostream>
#include "TFile.h"
#include "TTree.h"
#include "BankClasses.h"

int main()
{
        cout << "starting" << endl;
        TFile f("alephtree.root","RECREATE");
        TTree t("altree","a test ALEPH tree");
        QEXT* mqext = new QEXT;
        RLEP* mrlep = new RLEP;
        mqext->bb = 45;
        mrlep->LE = 206;
        mrlep->LF = 123;
        mqext->LP = mrlep;
        t.Branch("external_bank","QEXT", &mqext);
        cout << "start filling" << endl;
        t.Fill();
        cout << "done. Writing" << endl;
        f.Write();
        cout << "printing" << endl;
        t.Print();
        cout << "closing" << endl;
        f.Close();
        cout << "test: " << mqext->bb << endl;
        cout << "test: " << mqext->LP->LE << endl;
        cout << "deleting object" << endl;
        delete mqext;
        delete mrlep;
        return 0;
}

/****************************************************************
 * BanksLinkDef.h
 ***************************************************************/

#ifdef __CINT__

#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;

#pragma link C++ class RLEP+;
#pragma link C++ class QEXT+;

#endif

/****************************************************************
 * "makefile"
 ***************************************************************/

#!/bin/sh

rootcint -f BankClassesDict.cpp -c BankClasses.h BanksLinkDef.h
g++ -O -Wall -fPIC -I/usr/include/root -c BankClasses.cpp
g++ -O -Wall -fPIC -I/usr/include/root -c BankClassesDict.cpp
g++ -O -Wall -fPIC -I/usr/include/root -c main.cpp
g++ -shared -O BankClasses.o  BankClassesDict.o -o libBankClasses.so
g++ -O main.o libBankClasses.so -L/usr/lib/root -lCore -lCint -lTree
-lRint -lg++ -lm -ldl -rdynamic -o test



-- 
+-----------------------------------------------------------\|/---+
| Christophe DELAERE            office: e253               !o o!  |
| UCL - FYNU                    phone : 32-(0)10-473234    ! i !  |
| chemin du cyclotron, 2        fax   : 32-(0)10-452183     `-'   |
| 1348 Louvain-la-Neuve BELGIUM e-mail: delaere@fynu.ucl.ac.be    |
+-----------------------------------------------------------------+



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:03 MET