Re: using `my classes'

From: Rene Brun (Rene.Brun@cern.ch)
Date: Tue Jun 10 1997 - 15:11:18 MEST


Wouter Hulsbergen wrote:
> 
> Hello there,
> 
> I am not that much of a C++ programmer yet, so this might be a silly
> question, but:
> 
> I am using some CLHEP classes and have tried to store them in a TTree.
> Although the following code is compiling (g++) and running
> 
>           Hep3Vector *p = new Hep3Vector(mtrIt->px,mtrIt->py,mtrIt->pz) ;
>           if (branch) branch->SetAddress(p) ;
>           else branch = tree->Branch("momentum", "Hep3Vector",0,64000,1) ;
>           tree->Fill() ;
> 
> (where mtrIt is an iterator over an (Hera-B) Arte table and Hep3Vector
> is a CLHEP class name), I don't have a clue if it is legal. In root, I can
> open the TFile and TTree.GetEntries() returns the right number of events,
> but I haven't managed to read the "Hep3Vector".
> 
> According to the TTree class description, storing objects in a tree only
> works for objects inherited from TObject. Then, why does my code run
> and how should I build the CLHEP classes, such that they are
> inherited from TObject, in a proper (OO) way?

The ROOT class TTree has 3 member functions to create branches: 
  a, Branch(const Text_t *name, TClonesArray *list, Int_t bufsize=32000, Int_t splitlevel=1);
  b, Branch(const Text_t *name, const Text_t *classname, void *addobj, Int_t bufsize=32000, Int_t splitlevel=1);
  c, Branch(const Text_t *name, void *address, const Text_t *leaflist, Int_t bufsize=32000);
 
type a can be used to create a branch corresponding to one or few variables.
type b can be used to create a branch corresponding to an object derived from TObject
type c can be used to create a branch corresponding to a special list type TClonesArray.

In your case, you call a type b function. This is not legal because your object
is not derived from TObject. You should proceed as follows:
  - Create a class with a data member being a pointer to the Hep3Vector object
  - Run rootcint on the corresponding header file
  - Edit the generated function Streamer to include the relevant code
    to serialize the Hep3Vector object. This code can use the TBuffer::WriteFastArray
    functions. see for example TGraph::Streamer.

It is clear that progressively we should instrument the few widely utility classes
of CLHEP in the ROOT framework to provide an automatic I/O and an interactive
interface as well.

Rene Brun



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:26:19 MET