ATLAS Offline Software
Classes
TVirtualConverter.h File Reference

Base class for Root converters. More...

#include <string>
#include <typeinfo>
#include "Rtypes.h"
#include "RootConversions/TVirtualConverter.icc"
Include dependency graph for TVirtualConverter.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  TVirtualConverter
 Base class for converters for Root schema evolution. More...
 
class  TVirtualConverter_T< TTrans, TPers >
 Easy-to-use templated class for defining converters. More...
 

Detailed Description

Base class for Root converters.

Author
scott snyder snyde.nosp@m.r@bn.nosp@m.l.gov
Date
Dec, 2006 This header defines the base class TVirtualConverter, to be used for conversions between different versions of a class when reading data.

We need to keep track of a couple different classes here. The ‘transient’ class is the class that we want to read. It must have the same name in the persistent store (this restriction may be removed later). The ‘shape’ of the persistent version of the class may, however, differ from the transient version. We thus identify a second, ‘persistent’ class which gives the shape of the class that's expected in the persistent store. (In the future, we may remove the limitation that this be an actual class known to root and allow root ‘emulated’ classes to be used.) The converter must then know how to initialize a transient object from a persistent one.

Three pieces of information are needed to properly register the converter. First, the name of the transient class. Second, the name of the persistent class. Third, the root checksum for the persistent class shape we want to read. If this is not supplied, then one will be calculated based on the name of the transient class and the contents of the persistent class. This is usually what's needed; however, if you're relying on automatic schema evolution to read the persistent class (i.e., what you've declared in your program isn't exactly the same as the stored class), then you'll need to specify the checksum explicitly.

To make this a little more concrete, say you have:

struct T { int a; };

that you've saved to root. You later change this to:

struct T { double a2; };

Now, root's automatic schema evolution won't be able to read this properly, because it doesn't have any way to connect a2 to a. You can still read the data with a converter. Make an additional class

struct T_old { int a; };

Then make a converter class. The easiest thing to do is to use the template class TVirtualConverter_T:

class T_Conv
: public TVirtualConverter_T<T, T_old>
{
public:
void Convert (T* transobj, const T_old* persobj)
{ transobj->a2 = persobj->a; }
};

Here, the class names and the checksum are all provided by default. If you need to override them, they can be specified to the base class constructor.

In order to perform the conversion, a temporary instance of the persistent object must be created. By default, this is done via TClass::New, and then later destroyed using TClass::Destructor. This can be changed by overriding the NewPersObj and DeletePersObjs methods of TVirtualConverter.

Once a converter instance has been created, it should be registered with TConverterRegistry.

Definition in file TVirtualConverter.h.

TVirtualConverter_T::Convert
virtual void Convert(TTrans *transobj, const TPers *persobj)=0
Do the conversion.
a
TList * a
Definition: liststreamerinfos.cxx:10
TVirtualConverter_T
Easy-to-use templated class for defining converters.
Definition: TVirtualConverter.h:285
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35