Re: Adding a class

From: Axel Naumann <Axel.Naumann_at_cern.ch>
Date: Mon, 19 Nov 2007 15:07:47 +0100


Hi Marc de,

dictionaries only work for libraries, not for interpreted code. And I/O only works reliably for compiled types. In short: Just do

.L /home/csunix/dekamps/tmp/BlaClass.cpp+ (without any call to rootcint - the "+" will call it and use your compiler to build a library) and then whatever you want, e.g.

> root [1] BlaClass* p = new BlaClass;
> root [2] p->AddOne();
> root [3] p->AddOne();
> root [4] cout << p->Size() << endl;
> 2
> root [5] TFile* p_file = new TFile("bla.root","RECREATE");
> root [6] p->Write();
> root [7] p_file->Close();

etc

Cheers, Axel.

Marc de Kamps wrote:
> Hi,
>
> I'm using rootcint for the first time. It doesn't quite behave as expected
> and I'm probably overlooking something simple.
>
> Attached is a simple class. I'm running root 5.17/04 under Linux. I have
> generated dictionary files as follows.
> I run rootcint as follows:
> rootcint blaclassdict.cxx -c BlaClass.h
>
> The dictionary files are generated. I then run root as follows:
>
> root [0] .L /home/csunix/dekamps/tmp/BlaClass.cpp
> root [1] BlaClass* p = new BlaClass;
> root [2] p->AddOne();
> root [3] p->AddOne();
> root [4] cout << p->Size() << endl;
> 2
> root [5] TFile* p_file = new TFile("bla.root","RECREATE");
> root [6] p->Write();
> root [7] p_file->Close();
> root [8]
> So, far behaviour is expected. When I try to open the file I have just
> created, the object is of TObject type and not of BlaClass type, which
> causes problems when trying to read it back in:
> root [0] .L /home/csunix/dekamps/tmp/BlaClass.cpp
> root [1] TFile* p_file = new TFile("bla.root");
> root [2] p_file->ls();
> TFile** bla.root
> TFile* bla.root
> KEY: TObject TObject;1 Basic ROOT object
> root [3] BlaClass* p_bla = (BlaClass*)p_file->Get("TObject");
> root [4] cout << p_bla->Size() << endl;
> 201
>
> This looks like slicing and I have probably forgotten something simple.
> Is this usage of rootcint correct in principle? What goes wrong here?
>
> Input appreciated
>
> Marc
>
> -
> Dr. Marc de Kamps
> Biosystems Group
> School of Computing
> University of Leeds
> LS29JT, Leeds, UK
>
> dekamps_at_comp.leeds.ac.uk
> http:/www.comp.leeds.ac.uk/dekamps
>
>
Received on Mon Nov 19 2007 - 15:08:03 CET

This archive was generated by hypermail 2.2.0 : Tue Nov 20 2007 - 17:50:02 CET