Hi Rene,
here is the smallest possible setup I can imagine. It consists of 5 files:
A.rdl - defiitions for two persistent classes: A, B
ALinkDef.h - instructions for “rootcint” compiler
Writer.cc - a simplest writer for A (and B)
Reader.cc - a simplest reader illustrating the problem
HowToBuild - a sequence of actions to build the “project”
Here is the code:
// ======
// File: A.rdl
// ======
#ifndef A_RDL
#define A_RDL
#include “TObject.h”
#include “TRef.h”
class B : public TObject {
ClassDef(B,1) // A child class
};
class A : public TObject {
public:
A() : _b(new B()) {}
B* b( ) const { return (B*)(_b.GetObject( )); }
private:
TRef _b;
ClassDef(A,1) // A parent class
};
#endif
// ==========
// File: ALinkDef.h
// ==========
#ifdef CINT
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ class A+;
#pragma link C++ class B+;
#endif
// =========
// File: Writer.cc
// =========
#include “ADict.h”
#include <TFile.h>
#include <TApplication.h>
int
main( int argc, char* argv[] )
{
TApplication theApp(“App”, &argc, argv);
TFile f( “AData.root”, “recreate” );
A a;
f.WriteObject( &a, “A” );
f.Close( );
return 0;
}
// ==========
// File: Reader.cc
// ==========
#include <iostream.h>
#include <TFile.h>
#include <TApplication.h>
#include “ADict.h”
int
main( int argc, char* argv[] )
{
TApplication theApp(“App”, &argc, argv);
TFile f( “AData.root” );
A* a = 0;
f.GetObject( “A”, a );
B* b = a->b( );
cout << "a = " << a << ", b = " << b << “.” << endl;
return 0;
}
// ===========
// File: HowToBuild
// ===========
$ROOTSYS/bin/rootcint -f ADict.cc -c A.rdl ALinkDef.h
g++ -g -o Writer Writer.cc ADict.cc -I$ROOTSYS/include -L$ROOTSYS/lib -lCore -lCint
g++ -g -o Reader Reader.cc ADict.cc -I$ROOTSYS/include -L$ROOTSYS/lib -lCore -lCint
After you build the “project” run “Writer”. It will create a file called “AData.root”. You can see differences by trying to inspect this file either by the “Reader” or directly from “root” shell using the following script:
#include "A.rdl"
TFile f( “AData.root” );
A* a = 0;
f.GetObject( “A”, a );
B* b = a->b( );
cout << "a = " << a << ", b = " << b << “.” << endl;
Igor