ATLAS Offline Software
Loading...
Searching...
No Matches
TVirtualConverter Class Referenceabstract

Base class for converters for Root schema evolution. More...

#include <TVirtualConverter.h>

Inheritance diagram for TVirtualConverter:
Collaboration diagram for TVirtualConverter:

Public Member Functions

 TVirtualConverter (UInt_t checksum, TClass *trans_cls, TClass *pers_cls)
 Constructor, with checksum and class pointers.
 TVirtualConverter (TClass *trans_cls, TClass *pers_cls)
 Constructor, with class pointers.
 TVirtualConverter (UInt_t checksum, const std::string &trans_cls, const std::string &pers_cls)
 Constructor, with checksum and class names.
 TVirtualConverter (const std::string &trans_cls, const std::string &pers_cls)
 Constructor, with class names.
virtual ~TVirtualConverter ()
 Destructor.
TClass * GetTransClass ()
 Return the transient class, to which we're converting.
TClass * GetPersClass ()
 Return the persistent class, from which we're converting.
int GetCheckSum () const
 Return the checksum of the class from which we're converting.
virtual void * NewPersObj ()
 Create a new instance of the persistent class.
virtual void DeletePersObj (void *persobj)
 Destroy an instance of the persistent class.
virtual void ConvertVoid (void *transobj, const void *persobj)=0
 Do the conversion.
virtual void ReadBuffer (TBuffer &b, void *obj, Version_t version, UInt_t R__S, UInt_t R__c)
 Read object in non-split mode.

Static Public Member Functions

static TClass * ToClass (const std::string &name)
 Helper to convert a class name to a Root class pointer.
static TClass * ToClass (const std::type_info &id)
 Helper to convert a type_info to a Root class pointer.

Protected Member Functions

 TVirtualConverter ()
 Default constructor.
void SetCtorInfo (UInt_t checksum, TClass *trans_cls, TClass *pers_cls)
 Set the parameters that would normally be passed to the constructor.

Protected Attributes

void * fPersObj
 The temporary persistent object instance, used for conversions (in non-split mode).

Private Member Functions

void CheckStreamInfos ()
 Helper to allow for automatic schema evolution for persistent classes.
void CheckClasses ()
 Helper to check that the classes have been defined properly.

Private Attributes

TClass * fTransClass
 The declared transient class.
TClass * fPersClass
 The declared persistent class.
UInt_t fCheckSum
 The declared checksum.
int fOldLast
 Used by CheckStreamInfos: the length of the streamerinfo list that we saw on the last CheckStreamInfos call.

Detailed Description

Base class for converters for Root schema evolution.

Derive from this and define the Convert method to do the conversion. You must specify both the transient and persistent classes in the constructor. The checksum must also be specified if the actual shape in the file is different than the provided persistent class.

Definition at line 109 of file TVirtualConverter.h.

Constructor & Destructor Documentation

◆ TVirtualConverter() [1/5]

TVirtualConverter::TVirtualConverter ( UInt_t checksum,
TClass * trans_cls,
TClass * pers_cls )

Constructor, with checksum and class pointers.

Parameters
checksumThe Root checksum of the persistent class we'll convert.
trans_clsThe transient class to which we will be converting.
pers_clsThe persistent class from which we will be converting.

Definition at line 110 of file TVirtualConverter.cxx.

113 : fTransClass (trans_cls),
114 fPersClass (pers_cls),
115 fCheckSum (checksum),
116 fOldLast (-3),
117 fPersObj (nullptr)
118{
119 CheckClasses();
120}
TClass * fPersClass
The declared persistent class.
int fOldLast
Used by CheckStreamInfos: the length of the streamerinfo list that we saw on the last CheckStreamInfo...
void * fPersObj
The temporary persistent object instance, used for conversions (in non-split mode).
TClass * fTransClass
The declared transient class.
UInt_t fCheckSum
The declared checksum.
void CheckClasses()
Helper to check that the classes have been defined properly.

◆ TVirtualConverter() [2/5]

TVirtualConverter::TVirtualConverter ( TClass * trans_cls,
TClass * pers_cls )

Constructor, with class pointers.

Parameters
trans_clsThe transient class to which we will be converting.
pers_clsThe persistent class from which we will be converting.

The checksum will be calculated automatically from the provided classes.

Definition at line 130 of file TVirtualConverter.cxx.

132 : fTransClass (trans_cls),
133 fPersClass (pers_cls),
135 CalculateCheckSum (fPersClass, fTransClass->GetName()) : 0),
136 fOldLast (-3),
137 fPersObj (nullptr)
138{
139 CheckClasses();
140}

◆ TVirtualConverter() [3/5]

TVirtualConverter::TVirtualConverter ( UInt_t checksum,
const std::string & trans_cls,
const std::string & pers_cls )

Constructor, with checksum and class names.

Parameters
checksumThe Root checksum of the persistent class we'll convert.
trans_clsThe name of the transient class to which we will be converting.
pers_clsThe name of the persistent class from which we will be converting.

Definition at line 151 of file TVirtualConverter.cxx.

154 : fTransClass (ToClass (trans_cls)),
155 fPersClass (ToClass (pers_cls)),
156 fCheckSum (checksum),
157 fOldLast (-3),
158 fPersObj (nullptr)
159{
160 CheckClasses();
161}
static TClass * ToClass(const std::string &name)
Helper to convert a class name to a Root class pointer.

◆ TVirtualConverter() [4/5]

TVirtualConverter::TVirtualConverter ( const std::string & trans_cls,
const std::string & pers_cls )

Constructor, with class names.

Parameters
trans_clsThe name of the transient class to which we will be converting.
pers_clsThe name of the persistent class from which we will be converting.

The checksum will be calculated automatically from the provided classes.

Definition at line 173 of file TVirtualConverter.cxx.

175 : fTransClass (ToClass (trans_cls)),
176 fPersClass (ToClass (pers_cls)),
177 fCheckSum (CalculateCheckSum (fPersClass, fTransClass->GetName())),
178 fOldLast (-3),
179 fPersObj (nullptr)
180{
181 CheckClasses();
182}

◆ ~TVirtualConverter()

TVirtualConverter::~TVirtualConverter ( )
virtual

Destructor.

Definition at line 209 of file TVirtualConverter.cxx.

210{
211 // If we made an instance of the persistent class, get rid of it here.
212 if (fPersObj)
214}
virtual void DeletePersObj(void *persobj)
Destroy an instance of the persistent class.

◆ TVirtualConverter() [5/5]

TVirtualConverter::TVirtualConverter ( )
protected

Default constructor.

Intended for use with T_AthenaRootConverter only! You must call SetCtorInfo after this!

Definition at line 412 of file TVirtualConverter.cxx.

413 : fTransClass (nullptr),
414 fPersClass (nullptr),
415 fCheckSum (0),
416 fOldLast (-3),
417 fPersObj (nullptr)
418{
419}

Member Function Documentation

◆ CheckClasses()

void TVirtualConverter::CheckClasses ( )
private

Helper to check that the classes have been defined properly.

Check that the class pointers got defined.

Definition at line 188 of file TVirtualConverter.cxx.

189{
190 if (fTransClass == nullptr) {
191 if (fPersClass == nullptr)
192 Error ("TVirtualConverter",
193 "Both transient and persistent classes are null.");
194 else
195 Error ("TVirtualConverter",
196 "Transient class is null for persistent class `%s'",
197 fPersClass->GetName());
198 }
199 else if (fPersClass == nullptr)
200 Error ("TVirtualConverter",
201 "Persistent class is null for transient class `%s'",
202 fTransClass->GetName());
203}
Error
The different types of error that can be flagged in the L1TopoRDO.
Definition Error.h:16

◆ CheckStreamInfos()

void TVirtualConverter::CheckStreamInfos ( )
private

Helper to allow for automatic schema evolution for persistent classes.

Automatic schema evolution doesn't work for persistent classes ‘out-of-the-box’ because we're reading the ‘persistent class’, but the relevant StreamerInfo stored in the file will have the name of the ‘transient class’.

This gets called each time we try to read an object (in non-split mode).

Definition at line 368 of file TVirtualConverter.cxx.

369{
370 // First check to see if the list of TStreamerInfo's for the transient
371 // class has changed since the last time we were called. If not,
372 // then don't do anything.
373 const TObjArray* trans_sis = fTransClass->GetStreamerInfos();
374 if (trans_sis->GetLast() != fOldLast) {
375 // There was a change. Compare the TStreamerInfo list for the
376 // persistent class and the transient class. Look for entries
377 // where the transient class has a TStreamerInfo but the persistent
378 // class does not.
379 //
380 // Note: don't do this for `version' -1.
381 // That should always be built from the internal dictionary.
382 // (Otherwise, root can crash.)
383 const TObjArray* pers_sis = fPersClass->GetStreamerInfos();
384 assert (trans_sis->LowerBound() == pers_sis->LowerBound());
385 for (Int_t v = trans_sis->LowerBound(); v <= trans_sis->GetLast(); ++v) {
386 if (v != -1 &&
387 trans_sis->At(v) != 0 &&
388 (v > pers_sis->GetLast() || pers_sis->At(v) == 0))
389 {
390 // Ok, at this index, the transient class has a TStreamerInfo
391 // but the persistent class does not. Copy the TStreamerInfo
392 // (changing the class that it applies to to the persistent
393 // class), and add it to the persistent class's list.
394 TStreamerInfo* new_si =(TStreamerInfo*)(trans_sis->At(v)->Clone());
395 new_si->SetClass (fPersClass);
396 fPersClass->RegisterStreamerInfo (new_si);
397 }
398 }
399
400 // Remember how many entries there were in the list for next time.
401 fOldLast = trans_sis->GetLast();
402 }
403}

◆ ConvertVoid()

virtual void TVirtualConverter::ConvertVoid ( void * transobj,
const void * persobj )
pure virtual

Do the conversion.

Parameters
transobjPointer to an instance of the transient class.
persobjPointer to an instance of the persistent class.

An implementation of this must be provided in derived classes. It should initialize the object at transobj from the one at persobj.

Implemented in TVirtualConverter_T< TTrans, TPers >, TVirtualConverter_T< Identifier, DetDescrCondIdentifier_old >, TVirtualConverter_T< TauJetContainer_p1, TauJetContainer_p1_old >, TVirtualConverter_T< TrigInDetTrackTruthMap, TrigInDetTrackTruthMap_old >, and TVirtualConverter_T< TrigSpacePointCounts_p1, TrigSpacePointCounts_p1_old >.

◆ DeletePersObj()

void TVirtualConverter::DeletePersObj ( void * persobj)
virtual

Destroy an instance of the persistent class.

Parameters
persobjPointer to the instance to destroy.

The provided implementation of this uses TClass::Destructor, but you can override it if need be.

Definition at line 263 of file TVirtualConverter.cxx.

264{
265 return fPersClass->Destructor (persobj);
266}

◆ GetCheckSum()

int TVirtualConverter::GetCheckSum ( ) const

Return the checksum of the class from which we're converting.

Definition at line 238 of file TVirtualConverter.cxx.

239{
240 return fCheckSum;
241}

◆ GetPersClass()

TClass * TVirtualConverter::GetPersClass ( )

Return the persistent class, from which we're converting.

Definition at line 229 of file TVirtualConverter.cxx.

230{
231 return fPersClass;
232}

◆ GetTransClass()

TClass * TVirtualConverter::GetTransClass ( )

Return the transient class, to which we're converting.

Definition at line 220 of file TVirtualConverter.cxx.

221{
222 return fTransClass;
223}

◆ NewPersObj()

void * TVirtualConverter::NewPersObj ( )
virtual

Create a new instance of the persistent class.

The provided implementation of this uses TClass::New, but you can override it if need be.

Definition at line 250 of file TVirtualConverter.cxx.

251{
252 return fPersClass->New();
253}

◆ ReadBuffer()

void TVirtualConverter::ReadBuffer ( TBuffer & b,
void * obj,
Version_t version,
UInt_t R__s,
UInt_t R__c )
virtual

Read object in non-split mode.

Parameters
bThe source of the data.
objThe object into which we're reading. (This will be the transient object.)
versionThe version number of the class.
R__sThe starting position in the buffer.
R__cThe number of bytes for this object in the buffer.

You normally shouldn't have to worry about this, but it's exposed here so that it can be overridden if needed. It's only used when reading in non-split mode.

Definition at line 282 of file TVirtualConverter.cxx.

287{
288 // Make sure that we've done automatic schema evolution on the
289 // persistent side.
291
292 // Make an instance of the persistent class, if we haven't done so already.
293 if (fPersObj == nullptr)
295
296 // Read in the object, as an instance of the persistent class.
297 fPersClass->ReadBuffer (b, fPersObj, version, R__s, R__c);
298
299 // Convert to the transient representation.
300 ConvertVoid (obj, fPersObj);
301}
virtual void * NewPersObj()
Create a new instance of the persistent class.
void CheckStreamInfos()
Helper to allow for automatic schema evolution for persistent classes.
virtual void ConvertVoid(void *transobj, const void *persobj)=0
Do the conversion.

◆ SetCtorInfo()

void TVirtualConverter::SetCtorInfo ( UInt_t checksum,
TClass * trans_cls,
TClass * pers_cls )
protected

Set the parameters that would normally be passed to the constructor.

Parameters
checksumThe Root checksum of the persistent class we'll convert.
trans_clsThe transient class to which we will be converting.
pers_clsThe persistent class from which we will be converting.

Intended for use with T_AthenaRootConverter only!

Definition at line 430 of file TVirtualConverter.cxx.

433{
434 assert (fTransClass == nullptr);
435
436 fCheckSum = checksum;
437 fTransClass = trans_cls;
438 fPersClass = pers_cls;
439 CheckClasses();
440}

◆ ToClass() [1/2]

TClass * TVirtualConverter::ToClass ( const std::string & name)
static

Helper to convert a class name to a Root class pointer.

Parameters
nameThe name of the class to convert.

Returns nullptr on failure.

Definition at line 310 of file TVirtualConverter.cxx.

311{
312 return gROOT->GetClass (name.c_str());
313}

◆ ToClass() [2/2]

TClass * TVirtualConverter::ToClass ( const std::type_info & id)
static

Helper to convert a type_info to a Root class pointer.

Parameters
nameThe type_info of the class to convert.

Returns nullptr on failure.

Definition at line 322 of file TVirtualConverter.cxx.

323{
324 TClass* cl = gROOT->GetClass (id);
325 if (cl) return cl;
326
327 // This may fail if the dictionary hasn't been loaded yet,
328 // since we can auto-load only on the name.
329 // Make some attempt to get a name from the type_info.
330 const char* name = id.name();
331 cl = gROOT->GetClass (name);
332 if (cl) return cl;
333
334 const char* n2 = name;
335 while (isdigit(*n2))
336 ++n2;
337 cl = gROOT->GetClass (n2);
338 if (cl) return cl;
339
340 int errorCode = 0;
341 char* demname = nullptr;
342 {
343 // Protect against data race inside TClassEdit.
344 // https://github.com/root-project/root/issues/10353
345 // Should be fixed in root 6.26.02.
346 R__WRITE_LOCKGUARD(ROOT::gCoreMutex);
347 demname = TClassEdit::DemangleTypeIdName (id, errorCode);
348 }
349 if (demname) {
350 cl = gROOT->GetClass (demname);
351 free (demname);
352 }
353 return cl;
354}
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]

Member Data Documentation

◆ fCheckSum

UInt_t TVirtualConverter::fCheckSum
private

The declared checksum.

Definition at line 261 of file TVirtualConverter.h.

◆ fOldLast

int TVirtualConverter::fOldLast
private

Used by CheckStreamInfos: the length of the streamerinfo list that we saw on the last CheckStreamInfos call.

Definition at line 265 of file TVirtualConverter.h.

◆ fPersClass

TClass* TVirtualConverter::fPersClass
private

The declared persistent class.

Definition at line 258 of file TVirtualConverter.h.

◆ fPersObj

void* TVirtualConverter::fPersObj
protected

The temporary persistent object instance, used for conversions (in non-split mode).

Definition at line 271 of file TVirtualConverter.h.

◆ fTransClass

TClass* TVirtualConverter::fTransClass
private

The declared transient class.

Definition at line 255 of file TVirtualConverter.h.


The documentation for this class was generated from the following files: