ATLAS Offline Software
Loading...
Searching...
No Matches
FakeProxy.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
5// $Id: FakeProxy.cxx 487276 2012-03-08 11:04:56Z krasznaa $
6
7// ROOT include(s):
8#include <TClass.h>
9#include <TROOT.h>
10
11// Gaudi/Athena include(s):
13
14// Local include(s):
15#include "FakeProxy.h"
16
17namespace D3PD {
18
28 FakeProxy::FakeProxy( void* object, const std::type_info& ti )
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:
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 }
43
49
50 if( m_dict && m_object ) {
51 m_dict->Destructor( m_object );
52 } else if( m_object ) {
54 }
55 }
56
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 }
70
79 ::TClass* FakeProxy::getClass( const std::type_info& ti ) {
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 }
93
101 void* FakeProxy::newPrimitive( const std::type_info& ti ) {
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 }
132
140 void FakeProxy::deletePrimitive( void* ptr, const std::type_info& ti ) {
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 }
172
173} // namespace D3PD
Helpers for checking error return status codes and reporting errors.
#define REPORT_MESSAGE_WITH_CONTEXT(LVL, CONTEXT_NAME)
Report a message, with an explicitly specified context name.
static void deletePrimitive(void *ptr, const std::type_info &ti)
Delete a primitive.
void * m_object
The owned object.
Definition FakeProxy.h:65
~FakeProxy()
Destructor deleting the encapsulated object.
Definition FakeProxy.cxx:48
void clear()
Clear the contents of this variable.
Definition FakeProxy.cxx:61
::TClass * m_dict
Dictionary for class types.
Definition FakeProxy.h:68
const std::type_info & m_type
The type of the owned object.
Definition FakeProxy.h:66
static void * newPrimitive(const std::type_info &ti)
Create a new instance of a primitive.
ClearType m_clearType
The variable clearing type for this object.
Definition FakeProxy.h:63
::TClass * getClass(const std::type_info &ti)
Access the dictionary of a specific object.
Definition FakeProxy.cxx:79
@ ZERO
Clear the variable by filling it with zeroes.
Definition FakeProxy.h:60
@ CLEAR
Clear the variable by calling clear() on it.
Definition FakeProxy.h:61
FakeProxy(void *object, const std::type_info &ti)
Constructor taking ownership of an object.
Definition FakeProxy.cxx:28
::TMethodCall m_clear
Method calling clear on the object.
Definition FakeProxy.h:67
Block filler tool for noisy FEB information.