Belle II Software prerelease-11-00-00d
StoreEntry Struct Reference

Wraps a stored array/object, stored under unique (name, durability) key. More...

#include <StoreEntry.h>

Collaboration diagram for StoreEntry:

Public Member Functions

 StoreEntry ()
 default constructor.
 
 StoreEntry (bool isArray, TClass *cl, std::string name, bool dontWriteOut)
 useful constructor, creates 'object', but leaves 'ptr' NULL.
 
void invalidate ()
 invalidate entry for next event.
 
void resetForGetEntry ()
 Reset stored object to defaults, or nullptr.
 
void recoverFromNullObject ()
 Recreate object if null.
 
void recreate ()
 Reset stored object to defaults, set ptr to new object.
 
TClonesArray * getPtrAsArray () const
 Return ptr cast to TClonesArray.
 

Public Attributes

bool isArray
 Flag that indicates whether the object is a TClonesArray.
 
bool dontWriteOut
 Flag that indicates whether the object should be written to the output by default.
 
TClass * objClass
 class of object.
 
TObject * object
 The pointer to the actual object.
 
TObject * ptr
 The pointer to the returned object, either equal to 'object' or null, depending on whether the object was created in the current event.
 
std::string name
 Name of the entry.
 

Detailed Description

Wraps a stored array/object, stored under unique (name, durability) key.

See DataStore::m_storeEntryMap.

Definition at line 22 of file StoreEntry.h.

Constructor & Destructor Documentation

◆ StoreEntry() [1/2]

StoreEntry ( )
inline

default constructor.

Definition at line 24 of file StoreEntry.h.

24: isArray(false), dontWriteOut(false), objClass(nullptr), object(nullptr), ptr(nullptr), name() {};

◆ StoreEntry() [2/2]

StoreEntry ( bool isArray,
TClass * cl,
std::string name,
bool dontWriteOut )

useful constructor, creates 'object', but leaves 'ptr' NULL.

Definition at line 19 of file StoreEntry.cc.

19 :
20 isArray(isArray_),
21 dontWriteOut(dontWriteOut_),
22 objClass(cl),
23 object(nullptr),
24 ptr(nullptr),
25 name(std::move(name_))
26{
28}
TObject * ptr
The pointer to the returned object, either equal to 'object' or null, depending on whether the object...
Definition StoreEntry.h:52
bool dontWriteOut
Flag that indicates whether the object should be written to the output by default.
Definition StoreEntry.h:41
TObject * object
The pointer to the actual object.
Definition StoreEntry.h:49
bool isArray
Flag that indicates whether the object is a TClonesArray.
Definition StoreEntry.h:40
std::string name
Name of the entry.
Definition StoreEntry.h:54
void recoverFromNullObject()
Recreate object if null.
Definition StoreEntry.cc:30
TClass * objClass
class of object.
Definition StoreEntry.h:42

Member Function Documentation

◆ getPtrAsArray()

TClonesArray * getPtrAsArray ( ) const

Return ptr cast to TClonesArray.

If this is not an array, return null.

Definition at line 92 of file StoreEntry.cc.

93{
94 if (!isArray)
95 return nullptr;
96 return static_cast<TClonesArray*>(ptr);
97}

◆ invalidate()

void invalidate ( )

invalidate entry for next event.

(ptr will be null afterwards, memory may be reused.)

Definition at line 86 of file StoreEntry.cc.

87{
88 recreate();
89 ptr = nullptr;
90}
void recreate()
Reset stored object to defaults, set ptr to new object.
Definition StoreEntry.cc:77

◆ recoverFromNullObject()

void recoverFromNullObject ( )

Recreate object if null.

Used to recover from temporary invalid states after reading empty branches.

Definition at line 30 of file StoreEntry.cc.

31{
32 if (object)
33 return;
34 if (isArray) {
35 // The TClonesArray is created with a small initial capacity instead of the
36 // ROOT default of 1000: it grows geometrically as soon as it is filled, so
37 // nothing is lost for the arrays which are actually used, while resetting
38 // an array (TClonesArray::Delete(), see resetForGetEntry()) costs time
39 // proportional to the *capacity* and not to the number of stored objects.
40 // Most of the DataStore entries are empty most of the time, so this makes
41 // clearing them (e.g. in PruneDataStore or at the end of each event)
42 // essentially free.
43 // Same argument applies to the RelationContainer dataobject.
44 object = new TClonesArray(objClass, 10);
45 } else {
46 // Oh dear, where to begin. So we want to create a new object of the class
47 // we have and we require this class to be inheriting from TObject. Fine,
48 // but there could be classes with multiple inheritance where the TObject
49 // is not the first base class. In this case the memory layout puts the
50 // TObject not at the beginning of the instance but at an offset. The
51 // compiler knows this so a static_cast<> or c-style cast from one to the
52 // other will correctly modify the pointing address to point to the start
53 // of TObject, but TClass::New() gives us a void* pointer so the compiler
54 // doesn't know about that. So to be on the safe side we have to manually
55 // fix the pointer address using the BaseClassOffset from TClass. And since
56 // pointer arithmetic on void* is forbidden we have to go to char* first.
57 auto* rawPtr = reinterpret_cast<char*>(objClass->New());
58 int offset = objClass->GetBaseClassOffset(TObject::Class());
59 if (offset < 0) B2FATAL("Class " << objClass->GetName() << " does not inherit from TObject");
60 object = reinterpret_cast<TObject*>(rawPtr + offset);
61 }
62}

◆ recreate()

void recreate ( )

Reset stored object to defaults, set ptr to new object.

More or less equivalent to delete object; object = new X;, but optimized.

Definition at line 77 of file StoreEntry.cc.

78{
80 if (object == nullptr)
82
83 ptr = object;
84}
void resetForGetEntry()
Reset stored object to defaults, or nullptr.
Definition StoreEntry.cc:64

◆ resetForGetEntry()

void resetForGetEntry ( )

Reset stored object to defaults, or nullptr.

Only useful for input modules (before GetEntry()).

Definition at line 64 of file StoreEntry.cc.

65{
66 if (isArray) {
67 static_cast<TClonesArray*>(object)->Delete();
68 } else if (object->IsA() == RelationContainer::Class()) {
69 static_cast<RelationContainer*>(object)->Clear();
70 } else {
71 //we don't know anything about object, so we just delete it here (and recreate later)
72 delete object;
73 object = nullptr;
74 }
75}

Member Data Documentation

◆ dontWriteOut

bool dontWriteOut

Flag that indicates whether the object should be written to the output by default.

Definition at line 41 of file StoreEntry.h.

◆ isArray

bool isArray

Flag that indicates whether the object is a TClonesArray.

Definition at line 40 of file StoreEntry.h.

◆ name

std::string name

Name of the entry.

Equal to the key in the map.

Definition at line 54 of file StoreEntry.h.

◆ objClass

TClass* objClass

class of object.

If isArray==true, class of array objects

Definition at line 42 of file StoreEntry.h.

◆ object

TObject* object

The pointer to the actual object.

Associated memory may exceed object durability, and is kept until the object is replaced. In normal use, this should never be null. Temporary exceptions are allowed for input modules.

Definition at line 49 of file StoreEntry.h.

◆ ptr

TObject* ptr

The pointer to the returned object, either equal to 'object' or null, depending on whether the object was created in the current event.

Definition at line 52 of file StoreEntry.h.


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