Re: [ROOT] IO Problem with a TObjArray of non-TObjects

From: Rene Brun (Rene.Brun@cern.ch)
Date: Wed Apr 10 2002 - 11:50:22 MEST


Hi David,

I have no problems executing you small test program. I do:

rootcint -f cint.cxx -c RtObj.h LinkDef.h
g++ -fPIC -I$ROOTSYS/include -c cint.cxx mytest.cxx
g++ -o mytest mytest.o cint.o `root-config --glibs`

running mytest produces the two output lines (as expected):

hello
world

I take this opportunity to remind people that the old statement like 
in your code:

  TROOT rdummy("dummy","dummy") ;
and the corresponding 
#include <TROOT.h>

are not necessary since with introduced version 3.0

Rene Brun

David Chamont wrote:
> 
> Rene Brun wrote:
> 
> > Hi David,
> >
> > Which version are you using ?
> 
> I am a little late : 3.03/02
> 
> > I cannot reproduce this problem.
> > Your program works OK for me.
> 
> I apologize. The example I posted was a little simplified as compared
> to the real one, and I just checked that this simplified version also works
> for me ! I did some additionnal tests so to extract the minimal program
> which crash, and attached it below. As a summary, the program crash
> when I store a single RtObj<TString> before the array.
> 
> > Note that to store a string in a TObjArray or any other ROOT container,
> > you can use the class TObjString.
> 
> I use TString only for the program which demonstrates the
> crash. In real life, I instanciate RtObj with more complex existing
> classes which do not inherit from TObject and which  I cannot
> modify directly.
> 
> >
> > > ===================================================
> > > the file with the template
> > > ===================================================
> > >
> > > #include <TObject.h>
> > >
> > > template <class T>
> > > class RtObj : public TObject, public T
> > >  {
> > >   public:
> > >     RtObj() {}
> > >     RtObj( const T & val ) : T(val) {}
> > >     ClassDefT(RtObj,1)
> > >  } ;
> > >
> > > ClassDefT2(RtObj,T)
> > >
> > > ClassImpT(RtObj,T)
> > >
> > > ===================================================
> > > the linkdef file
> > > ===================================================
> > >
> > > #ifdef __CINT__
> > >
> > > #pragma link off all globals;
> > > #pragma link off all classes;
> > > #pragma link off all functions;
> > >
> > > #pragma link C++ class RtObj<TString>+;
> > >
> > > #endif
> > >
> > >
> 
> ====================================================
> The new main file
> ====================================================
> 
> #include <TObjArray.h>
> #include <TString.h>
> #include <TROOT.h>
> #include <TFile.h>
> #include <iostream>
> 
> int main()
>  {
>   // begin
>   TROOT rdummy("dummy","dummy") ;
>   TFile * file ;
> 
>   // write
>   file =  new TFile("Temp.root","recreate") ;
>   RtObj<TString> obj("hello") ;
>   obj.Write("obj") ;
>   TObjArray array ;
>   array.AddLast( new RtObj<TString>("world") ) ;
>   array.Write("array",TObject::kSingleKey) ;
>   file->Close() ;
>   delete file ;
> 
>   // read
>   file =  new TFile("Temp.root","read") ;
>   RtObj<TString> * pobj = (RtObj<TString> *)(file->Get("obj")) ;
>   cout<<*pobj<<endl ;
>   TObjArray * parray = (TObjArray *)(file->Get("array")) ;
>   cout<<*((RtObj<TString> *)((*parray)[0]))<<endl ;
>   file->Close() ;
>   delete file ;
> 
>   // end
>   return 0 ;
>  }



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