ATLAS Offline Software
Loading...
Searching...
No Matches
xAOD::TObjectManager Class Reference

Manager for EDM objects created by ROOT. More...

#include <TObjectManager.h>

Inheritance diagram for xAOD::TObjectManager:
Collaboration diagram for xAOD::TObjectManager:

Public Member Functions

 TObjectManager (::TBranch *br=0, std::unique_ptr< THolder > holder=nullptr, ::Bool_t renewOnRead=kFALSE)
 Constructor, getting hold of the created objects.
 TObjectManager (const TObjectManager &parent)
 Copy constructor.
 ~TObjectManager ()
 Destructor.
TObjectManageroperator= (const TObjectManager &parent)
 Assignment operator.
::TBranch * branch ()
 Accessor to the branch.
::TBranch ** branchPtr ()
 Pointer to the branch's pointer.
virtual::Int_t getEntry (::Int_t getall=0) override
 Function for updating the object in memory if needed.
virtual const void * object () const override
 Function getting a const pointer to the object being handled.
virtual void * object () override
 Function getting a pointer to the object being handled.
virtual void setObject (void *obj) override
 Function replacing the object being handled.
virtual::Bool_t create () override
 Create the object for the current event.
virtual::Bool_t isSet () const override
 Check if the object was set for the current event.
virtual void reset () override
 Reset the object at the end of processing of an event.
const THolderholder () const
 Accessor to the Holder object.
THolderholder ()
 Accessor to the Holder object.

Private Attributes

::TBranch * m_branch
 Pointer keeping track of the branch.
::Long64_t m_entry
 The last entry that was loaded for this branch.
::Bool_t m_isSet
 Was the object set for the current event?
::Bool_t m_renewOnRead
 Should the object be recreated on each read?
std::unique_ptr< THolderm_holder
 Object holding onto an EDM object in memory.

Detailed Description

Manager for EDM objects created by ROOT.

This class is used when an EDM object is meant to be created by ROOT's schema evolution system, behind the scenes.

Author
Attila Krasznahorkay Attil.nosp@m.a.Kr.nosp@m.aszna.nosp@m.hork.nosp@m.ay@ce.nosp@m.rn.c.nosp@m.h

Definition at line 29 of file TObjectManager.h.

Constructor & Destructor Documentation

◆ TObjectManager() [1/2]

xAOD::TObjectManager::TObjectManager ( ::TBranch * br = 0,
std::unique_ptr< THolder > holder = nullptr,
::Bool_t renewOnRead = kFALSE )

Constructor, getting hold of the created objects.

Definition at line 18 of file TObjectManager.cxx.

21 : IObjectManager(std::move(holder)),
22 m_branch( br ), m_entry( -1 ), m_isSet( kTRUE ),
23 m_renewOnRead( renewOnRead ) {
24 }
IObjectManager(std::unique_ptr< THolder > holder)
Constructor.
const THolder * holder() const
Accessor to the Holder object.
::TBranch * m_branch
Pointer keeping track of the branch.
::Bool_t m_isSet
Was the object set for the current event?
::Bool_t m_renewOnRead
Should the object be recreated on each read?
::Long64_t m_entry
The last entry that was loaded for this branch.

◆ TObjectManager() [2/2]

xAOD::TObjectManager::TObjectManager ( const TObjectManager & parent)

Copy constructor.

Definition at line 26 of file TObjectManager.cxx.

27 : IObjectManager(parent),
28 m_branch( parent.m_branch ), m_entry( parent.m_entry ),
29 m_isSet( parent.m_isSet ), m_renewOnRead( parent.m_renewOnRead ) {
30
31 }

◆ ~TObjectManager()

xAOD::TObjectManager::~TObjectManager ( )
default

Destructor.

Member Function Documentation

◆ branch()

TBranch * xAOD::TObjectManager::branch ( )

Accessor to the branch.

Definition at line 51 of file TObjectManager.cxx.

51 {
52
53 return m_branch;
54 }

◆ branchPtr()

TBranch ** xAOD::TObjectManager::branchPtr ( )

Pointer to the branch's pointer.

This sort of access to the internal TBranch object is needed when connecting to the input tree.

One has to make sure that the correct pointer is being pointed to by the input tree.

Returns
A pointer to the internal branch pointer

Definition at line 62 of file TObjectManager.cxx.

62 {
63
64 return &m_branch;
65 }

◆ create()

Bool_t xAOD::TObjectManager::create ( )
overridevirtual

Create the object for the current event.

Dummy implementation as full objects can't be missing.

Implements xAOD::TVirtualManager.

Definition at line 171 of file TObjectManager.cxx.

171 {
172
173 return m_isSet;
174 }

◆ getEntry()

Int_t xAOD::TObjectManager::getEntry ( ::Int_t getall = 0)
overridevirtual

Function for updating the object in memory if needed.

This function is used to load the contents of a branch only when it needs to be done.

It keeps track of which entry was already loaded for a branch/object, and only asks the branch to load an entry when it really has to be done.

Returns
0 if no new entry was read, the number of read bytes otherwise

Implements xAOD::TVirtualManager.

Definition at line 74 of file TObjectManager.cxx.

74 {
75
76 // Make sure that the branch is associated to a tree
77 // as the entry to be read is retrieved from the tree
78 if (!m_branch->GetTree()){
79 Error("xAOD::TObjectManager::getEntry",
80 XAOD_MESSAGE("Branch=%s is not associated to any tree while reading of branches within this class relies on that"),
81 m_branch->GetName());
82 return -1;
83 }
84
85 // Get the entry that should be read
86 // The entry to be read is set with TTree::LoadTree()
87 // NB: for a branch from a friend tree and if the friend tree has an index built,
88 // then the entry to read is found when calling the TTree::LoadTree() function
89 // that matches the major and minor values between the main tree and the friend tree
90 ::Long64_t entry = m_branch->GetTree()->GetReadEntry();
91
92 if ( entry < 0 ){
93 // Raise error as it implies
94 // either that the TTree::LoadTree() function has not been called
95 // or
96 // the entry requested to be read by the user
97 // is not corresponding to any entry for the friend tree
98 Error("xAOD::TObjectManager::getEntry",
99 XAOD_MESSAGE( "Entry to read is not set for branch=%s from tree=%s. "
100 "It is either because TTree::LoadTree(entry) was not called "
101 "beforehand in the TEvent class OR "
102 "the entry requested to be read for the main tree is not corresponding to an event for the friend tree" ),
103 m_branch->GetName(),
104 m_branch->GetTree()->GetName());
105 return -1;
106 }
107
108 // Check if anything needs to be done:
109 if( entry == m_entry ) return 0;
110
111 // Make sure that the branch is not in "MakeClass mode":
112 if( m_branch->GetMakeClass() ) {
113 m_branch->SetMakeClass( 0 );
114 }
115
116 // Renew the object in memory if we are in such a mode:
117 if( m_renewOnRead ) {
118 holder()->renew();
119 }
120
121 // Load the entry.
122 const ::Int_t nbytes = m_branch->GetEntry( entry, getall );
123
124 // If the load was successful, remember that we loaded this entry.
125 if( nbytes >= 0 ) {
126 m_entry = entry;
127 }
128
129 // This is a tricky thing... Parts of the code try to minimise some
130 // operations to only happen when an object is getting updated. But
131 // it can happen that an interface or auxiliary store object doesn't
132 // actually store any data itself. So TBranch::GetEntry will return 0.
133 // But we still need to tell the code looking at this return value
134 // that we did go to a new event. So we should never return 0 at
135 // this point...
136 if( nbytes ) {
137 return nbytes;
138 } else {
139 return 1;
140 }
141 }
#define XAOD_MESSAGE(MESSAGE)
Simple macro for printing error/verbose messages.
void renew()
Renew the object in memory.
Definition THolder.cxx:421
Error
The different types of error that can be flagged in the L1TopoRDO.
Definition Error.h:16

◆ holder() [1/2]

THolder * xAOD::Details::IObjectManager::holder ( )
inherited

Accessor to the Holder object.

Definition at line 48 of file IObjectManager.cxx.

48 {
49
50 return m_holder.get();
51}
std::unique_ptr< THolder > m_holder
Object holding onto an EDM object in memory.

◆ holder() [2/2]

const THolder * xAOD::Details::IObjectManager::holder ( ) const
inherited

Accessor to the Holder object.

Definition at line 43 of file IObjectManager.cxx.

43 {
44
45 return m_holder.get();
46}

◆ isSet()

Bool_t xAOD::TObjectManager::isSet ( ) const
overridevirtual

Check if the object was set for the current event.

Returns
kTRUE if the object for this event was set, kFALSE otherwise

Implements xAOD::TVirtualManager.

Definition at line 179 of file TObjectManager.cxx.

179 {
180
181 return m_isSet;
182 }

◆ object() [1/2]

const void * xAOD::TObjectManager::object ( ) const
overridevirtual

Function getting a const pointer to the object being handled.

This function gives an easy access to the object managed by this object.

Returns
A typeless pointer to the object being managed

Implements xAOD::TVirtualManager.

Definition at line 148 of file TObjectManager.cxx.

148 {
149
150 return holder()->get();
151 }
const void * get() const
Return a typeless const pointer to the held object.
Definition THolder.cxx:216

◆ object() [2/2]

void * xAOD::TObjectManager::object ( )
overridevirtual

Function getting a pointer to the object being handled.

Implements xAOD::TVirtualManager.

Definition at line 153 of file TObjectManager.cxx.

153 {
154
155 return holder()->get();
156 }

◆ operator=()

TObjectManager & xAOD::TObjectManager::operator= ( const TObjectManager & parent)

Assignment operator.

Definition at line 35 of file TObjectManager.cxx.

35 {
36
37 // Check if we need to do anything:
38 if( this == &parent ) {
39 return *this;
40 }
41
42 m_branch = parent.m_branch;
43 IObjectManager::operator=(parent);
44 m_entry = parent.m_entry;
45 m_isSet = parent.m_isSet;
46 m_renewOnRead = parent.m_renewOnRead;
47
48 return *this;
49 }

◆ reset()

void xAOD::TObjectManager::reset ( )
overridevirtual

Reset the object at the end of processing of an event.

This function needs to be called after an event was filled into the output TTree.

It tells the manager object that it needs to wait for another object to be set up for the upcoming event.

Implements xAOD::TVirtualManager.

Definition at line 188 of file TObjectManager.cxx.

188 {
189
190 m_isSet = kFALSE;
191 return;
192 }

◆ setObject()

void xAOD::TObjectManager::setObject ( void * obj)
overridevirtual

Function replacing the object being handled.

This is just a convenient way of calling THolder::Set from TEvent.

Parameters
objThe object to replace the previously managed one

Implements xAOD::TVirtualManager.

Definition at line 162 of file TObjectManager.cxx.

162 {
163
164 holder()->set( obj );
165 m_isSet = kTRUE;
166 return;
167 }
virtual void set(void *obj)
Replace the managed object.
Definition THolder.cxx:231

Member Data Documentation

◆ m_branch

::TBranch* xAOD::TObjectManager::m_branch
private

Pointer keeping track of the branch.

Definition at line 68 of file TObjectManager.h.

◆ m_entry

::Long64_t xAOD::TObjectManager::m_entry
private

The last entry that was loaded for this branch.

Definition at line 70 of file TObjectManager.h.

◆ m_holder

std::unique_ptr<THolder> xAOD::Details::IObjectManager::m_holder
privateinherited

Object holding onto an EDM object in memory.

Definition at line 44 of file IObjectManager.h.

◆ m_isSet

::Bool_t xAOD::TObjectManager::m_isSet
private

Was the object set for the current event?

Definition at line 72 of file TObjectManager.h.

◆ m_renewOnRead

::Bool_t xAOD::TObjectManager::m_renewOnRead
private

Should the object be recreated on each read?

Definition at line 74 of file TObjectManager.h.


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