ATLAS Offline Software
Public Member Functions | Static Public Member Functions | Private Types | Private Attributes | List of all members
D3PD::FakeProxy Class Reference

Proxy class for storing any kind of object. More...

#include <FakeProxy.h>

Collaboration diagram for D3PD::FakeProxy:

Public Member Functions

 FakeProxy (void *object, const std::type_info &ti)
 Constructor taking ownership of an object. More...
 
 ~FakeProxy ()
 Destructor deleting the encapsulated object. More...
 
void clear ()
 Clear the contents of this variable. More...
 

Static Public Member Functions

::TClass * getClass (const std::type_info &ti)
 Access the dictionary of a specific object. More...
 
static void * newPrimitive (const std::type_info &ti)
 Create a new instance of a primitive. More...
 
static void deletePrimitive (void *ptr, const std::type_info &ti)
 Delete a primitive. More...
 

Private Types

enum  ClearType { UNKNOWN, ZERO, CLEAR }
 Variable clearing method. More...
 

Private Attributes

ClearType m_clearType
 The variable clearing type for this object. More...
 
void * m_object
 The owned object. More...
 
const std::type_info & m_type
 The type of the owned object. More...
 
::TMethodCall m_clear
 Method calling clear on the object. More...
 
::TClass * m_dict
 Dictionary for class types. More...
 

Detailed Description

Proxy class for storing any kind of object.

   This proxy is used to create and take ownership of object
   types that will not be written out to the D3PD file, but the
   block filler tools still need them to exist in memory.

   The class can handle both primitive and class types.
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
Revision
487276
Date
2012-03-08 12:04:56 +0100 (Thu, 08 Mar 2012)

Definition at line 33 of file FakeProxy.h.

Member Enumeration Documentation

◆ ClearType

Variable clearing method.

Primitive types are just zeroed out, while for class types the code checks if they have a clear() function. If they do, it will be used to clear the variable.

Enumerator
UNKNOWN 

Can't clear the variable.

ZERO 

Clear the variable by filling it with zeroes.

CLEAR 

Clear the variable by calling clear() on it.

Definition at line 58 of file FakeProxy.h.

58  {
59  UNKNOWN,
60  ZERO,
61  CLEAR
62  };

Constructor & Destructor Documentation

◆ FakeProxy()

D3PD::FakeProxy::FakeProxy ( void *  object,
const std::type_info &  ti 
)

Constructor taking ownership of an object.

The constructor figures out how the variable will need to be cleared later on event by event.

It issues a warning if it didn't manage to do so. (It's not an error condition not to be able to clear the variable...)

Parameters
objectPointer to the object the proxy is to take posession of
tiThe type info of the object

Definition at line 28 of file FakeProxy.cxx.

29  : m_clearType( ZERO ), m_object( object ), m_type( ti ),
30  m_clear(), m_dict( 0 ) {
31 
32  // Handle the case when it's an object that we received:
33  m_dict = getClass( m_type );
34  if( m_dict ) {
35  // Check if there is a "clear" function defined for this object:
36  TMethodCall method( m_dict, "clear", "" );
37  if( method.IsValid() ) {
39  m_clear = method;
40  }
41  }
42  }

◆ ~FakeProxy()

D3PD::FakeProxy::~FakeProxy ( )

Destructor deleting the encapsulated object.

The destructor tries to free the memory allocated by the object in the correct way.

Definition at line 48 of file FakeProxy.cxx.

48  {
49 
50  if( m_dict && m_object ) {
51  m_dict->Destructor( m_object );
52  } else if( m_object ) {
54  }
55  }

Member Function Documentation

◆ clear()

void D3PD::FakeProxy::clear ( )

Clear the contents of this variable.

This function also uses the dictionary of the object to try to clear it.

For primitive types we don't do anything for now...

Definition at line 61 of file FakeProxy.cxx.

61  {
62 
63  // Execute the clear function if it is defined:
64  if( m_clearType == CLEAR ) {
65  m_clear.Execute( m_object );
66  }
67 
68  return;
69  }

◆ deletePrimitive()

void D3PD::FakeProxy::deletePrimitive ( void *  ptr,
const std::type_info &  ti 
)
static

Delete a primitive.

This function is used to delete previously created primitive types from memory.

Parameters
ptrPointer to the primitive object
tiThe type info for the primitive type

Definition at line 140 of file FakeProxy.cxx.

140  {
141 
142  if( ti == typeid( bool ) ) {
143  delete reinterpret_cast< bool* >( ptr );
144  } else if ( ti == typeid( char ) ) {
145  delete reinterpret_cast< char* >( ptr );
146  } else if ( ti == typeid( short ) ) {
147  delete reinterpret_cast< short* >( ptr );
148  } else if ( ti == typeid( unsigned short ) ) {
149  delete reinterpret_cast< unsigned short* >( ptr );
150  } else if ( ti == typeid( int ) ) {
151  delete reinterpret_cast< int* >( ptr );
152  } else if ( ti == typeid( unsigned int ) ) {
153  delete reinterpret_cast< unsigned int* >( ptr );
154  } else if ( ti == typeid( long ) ) {
155  delete reinterpret_cast< long* >( ptr );
156  } else if ( ti == typeid( unsigned long ) ) {
157  delete reinterpret_cast< unsigned long* >( ptr );
158  } else if ( ti == typeid( unsigned long long ) ) {
159  delete reinterpret_cast< unsigned long long* >( ptr );
160  } else if ( ti == typeid( float ) ) {
161  delete reinterpret_cast< float* >( ptr );
162  } else if ( ti == typeid( double ) ) {
163  delete reinterpret_cast< double* >( ptr );
164  } else {
165  REPORT_MESSAGE_WITH_CONTEXT( MSG::WARNING, "D3PD::FakeProxy" )
166  << "Couldn't delete type: " << ti.name() << "; There is a mistake "
167  << "in the code!";
168  }
169 
170  return;
171  }

◆ getClass()

TClass * D3PD::FakeProxy::getClass ( const std::type_info &  ti)
static

Access the dictionary of a specific object.

I took this implementation basically from D3PD::RootD3PD, as I needed the same functionality here as well.

Parameters
tiThe type info of the type in question
Returns
A dictionary for the type if found, or a zero pointer if it's not

Definition at line 79 of file FakeProxy.cxx.

79  {
80 
81  TClass* cls = gROOT->GetClass( ti );
82  if( ! cls ) {
83  cls = gROOT->GetClass( System::typeinfoName( ti ).c_str() );
84  }
85 
86  if( ! cls ) {
87  REPORT_MESSAGE_WITH_CONTEXT( MSG::DEBUG, "D3PD::FakeProxy" )
88  << "Can't find class for typeinfo " << ti.name();
89  }
90 
91  return cls;
92  }

◆ newPrimitive()

void * D3PD::FakeProxy::newPrimitive ( const std::type_info &  ti)
static

Create a new instance of a primitive.

This function is used to create a new primitive type in memory.

Parameters
tiThe type info for the primitive type
Returns
A pointer to the newly created primitive, or a null pointer if the type is not known.

Definition at line 101 of file FakeProxy.cxx.

101  {
102 
103  if( ti == typeid( bool ) ) {
104  return new bool;
105  } else if ( ti == typeid( char ) ) {
106  return new char;
107  } else if ( ti == typeid( short ) ) {
108  return new short;
109  } else if ( ti == typeid( unsigned short ) ) {
110  return new unsigned short;
111  } else if ( ti == typeid( int ) ) {
112  return new int;
113  } else if ( ti == typeid( unsigned int ) ) {
114  return new unsigned int;
115  } else if ( ti == typeid( long ) ) {
116  return new long;
117  } else if ( ti == typeid( unsigned long ) ) {
118  return new unsigned long;
119  } else if ( ti == typeid( unsigned long long ) ) {
120  return new unsigned long long;
121  } else if ( ti == typeid( float ) ) {
122  return new float;
123  } else if ( ti == typeid( double ) ) {
124  return new double;
125  }
126 
127  REPORT_MESSAGE_WITH_CONTEXT( MSG::WARNING, "D3PD::FakeProxy" )
128  << "Type '" << ti.name() << "' is not a known primitive";
129 
130  return 0;
131  }

Member Data Documentation

◆ m_clear

::TMethodCall D3PD::FakeProxy::m_clear
private

Method calling clear on the object.

Definition at line 67 of file FakeProxy.h.

◆ m_clearType

ClearType D3PD::FakeProxy::m_clearType
private

The variable clearing type for this object.

Definition at line 63 of file FakeProxy.h.

◆ m_dict

::TClass* D3PD::FakeProxy::m_dict
private

Dictionary for class types.

Definition at line 68 of file FakeProxy.h.

◆ m_object

void* D3PD::FakeProxy::m_object
private

The owned object.

Definition at line 65 of file FakeProxy.h.

◆ m_type

const std::type_info& D3PD::FakeProxy::m_type
private

The type of the owned object.

Definition at line 66 of file FakeProxy.h.


The documentation for this class was generated from the following files:
RunTileTBRec.method
method
Definition: RunTileTBRec.py:73
D3PD::FakeProxy::m_object
void * m_object
The owned object.
Definition: FakeProxy.h:65
xAOD::short
short
Definition: Vertex_v1.cxx:165
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
D3PD::FakeProxy::m_dict
::TClass * m_dict
Dictionary for class types.
Definition: FakeProxy.h:68
xAOD::char
char
Definition: TrigDecision_v1.cxx:38
D3PD::FakeProxy::CLEAR
@ CLEAR
Clear the variable by calling clear() on it.
Definition: FakeProxy.h:61
CaloClusterListBadChannel.cls
cls
Definition: CaloClusterListBadChannel.py:8
dbg::ptr
void * ptr(T *p)
Definition: SGImplSvc.cxx:74
D3PD::FakeProxy::UNKNOWN
@ UNKNOWN
Can't clear the variable.
Definition: FakeProxy.h:59
D3PD::FakeProxy::deletePrimitive
static void deletePrimitive(void *ptr, const std::type_info &ti)
Delete a primitive.
Definition: FakeProxy.cxx:140
D3PD::FakeProxy::getClass
::TClass * getClass(const std::type_info &ti)
Access the dictionary of a specific object.
Definition: FakeProxy.cxx:79
Athena::typeinfoName
std::string typeinfoName(const std::type_info &ti)
Convert a type_info to a demangled string.
Definition: AthenaKernel/src/ClassName.cxx:23
xAOD::double
double
Definition: CompositeParticle_v1.cxx:159
REPORT_MESSAGE_WITH_CONTEXT
#define REPORT_MESSAGE_WITH_CONTEXT(LVL, CONTEXT_NAME)
Report a message, with an explicitly specified context name.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:345
D3PD::FakeProxy::ZERO
@ ZERO
Clear the variable by filling it with zeroes.
Definition: FakeProxy.h:60
D3PD::FakeProxy::m_type
const std::type_info & m_type
The type of the owned object.
Definition: FakeProxy.h:66
DEBUG
#define DEBUG
Definition: page_access.h:11
xAOD::bool
setBGCode setTAP setLVL2ErrorBits bool
Definition: TrigDecision_v1.cxx:60
readCCLHist.float
float
Definition: readCCLHist.py:83
D3PD::FakeProxy::m_clear
::TMethodCall m_clear
Method calling clear on the object.
Definition: FakeProxy.h:67
D3PD::FakeProxy::m_clearType
ClearType m_clearType
The variable clearing type for this object.
Definition: FakeProxy.h:63