Re: writing/reading objects to/form a file

From: Axel Naumann <>
Date: Mon, 21 Nov 2005 11:29:15 +0100

Hi Chiara,

> But still I do not know why it crashes...
> Is it because of the initialization in the default constructor?

it's probably because you don't specify an array dimension for fPads. You should do

AliTOFCalParam *fPads[npad]; // assuming npad is a const int

so ROOT knows how many AliTOFCalParam objects to write. Attached files show that this works properly.

#include "MyClass.h"
MyClass::MyClass() {

   for (int i=0; i<5; ++i)


void MyClass::Init() {

   for (int i=0; i<5; ++i)

      fArray[i]=new TObject();

MyClass::~MyClass() {

   delete[] fArray;

#include "TObject.h"

class MyClass: public TObject {
   void Init();
   void PrintArray() {

   TObject *fArray[5];

void testwr(){

   MyClass* mc=new MyClass();
   TFile* f=new TFile("myclass.root","RECREATE");    mc->Write("mc");

   delete f;
   f=new TFile("myclass.root");
   delete f;
} Received on Mon Nov 21 2005 - 11:29:10 MET

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:13 MET