Re: ClassDef version

From: Nick West (n.west1@physics.oxford.ac.uk)
Date: Thu Jul 01 1999 - 16:02:14 MEST


Hi Rene,

of course I understand why you write:-

> > I have a question about increasing the id of ClassDef ; I add members to
> > a existing class
> > but I want to be able to read older objects of this class. I understood
> > that I have to modify the streamer function to take that into account in
> > the Dictonary file. I have done that and all seems to work but is there
> > a way to do that automatically (because in the make file I use, the
> > dictonary file is automatically generated without the modification
> > if(R__v>1){...}?
> > Thanks a lot
> > Olivier Meplan
> 
> Hi Olivier,
> By definition, this process cannot be automatized.
> You should follow the following steps:
>   - Increase class version in ClassDef
>   - Take a copy of your old Streamer in the dictionary and add this
>     function in your class implementation.
>   - Modify your Linkdef.h file to add the symbol "-" after the class
> name
>     This instructs rootcint to not generate the Streamer function.
>   - run rootcint with the new Linkdef.

but this is a problem that is going to hit a lot of people.  Schema evolution is
essential, many structures change over the lifetime of an experiment, but the
price to be paid is to take control and loose all the power of CINT to build
streamer methods.  How about if we were to adopt a convention that old
Streamer methods were renamed with a postfix of the version number?  So, CINT
builds:-

  void MyClass::Streamer(TBuffer &R__b)

for version 1.  When we move to version 2 we manually rename this to:-

  void MyClass::Streamer_v1(TBuffer &R__b)

the linkdef.h option is extended to offer 2 choices:-

  1)   No streamer generation
  2)   Backward support generation

in the second case the code for any version greater than 1 looks like this:-

   Version_t R__v = R__b.ReadVersion(); 
   if (R__v==1) { 
    Streamer_v1(R__b); 
    return;
   } else if (R__v==2) {
    Streamer_v2(R__b);
    return;
   } else if (R__v==3) {
    Streamer_v2(R__b);
    return;
   }

   etc.

that covers all old cases.  Of course that is not always going to work, but if
the MyClass ctor properly initialises everything at least everything is in a
well defined state.  At the very least this allows people to have the streamer
generated for the latest version and gives them a starting point to patch up
old versions.

Cheers,

Nick.



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