ATLAS Offline Software
|
Base class for Root converters. More...
#include <string>
#include <typeinfo>
#include "Rtypes.h"
#include "RootConversions/TVirtualConverter.icc"
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... | |
Base class for Root converters.
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:
that you've saved to root. You later change this to:
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
Then make a converter class. The easiest thing to do is to use the template class TVirtualConverter_T:
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.