1 // Dear emacs, this is -*- c++ -*-
4 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
7 #ifndef XAODROOTACCESS_TOOLS_TCDVHOLDERT_ICC
8 #define XAODROOTACCESS_TOOLS_TCDVHOLDERT_ICC
16 TCDVHolderT< T >::TCDVHolderT( ConstDataVector< T >* object,
17 const std::type_info& type,
19 : THolder( static_cast< const void* >( object ), type, owner ),
20 m_cdvObject( object ),
21 m_holderHelper( object->asDataVector(),
22 ::TClass::GetClass( typeid( typename Object_t::base_data_vector ) ),
25 // In case there's no dictionary for the underlying DataVector type
26 // (which should only happen for some tests), let's give a type ID for the
28 if( ! m_holderHelper.getClass() ) {
29 m_holderHelper = THolder( object->asDataVector(),
30 typeid( typename Object_t::base_data_vector ), kFALSE );
33 // Set our type to the underlying DataVector type
34 m_type = m_holderHelper.getClass();
35 m_typeInfo = m_holderHelper.getTypeInfo();
39 void TCDVHolderT< T >::set( void* obj ) {
41 // Set our own pointer:
42 m_cdvObject = reinterpret_cast< ConstDataVector< T >* >( obj );
44 // Update the helper object:
45 void* nc_dv ATLAS_THREAD_SAFE = // we hold non-const pointers but check on retrieve
46 const_cast< void* >( static_cast< const void* >( m_cdvObject->asDataVector() ) );
48 m_holderHelper.set( nc_dv );
50 // Finally, update the base class:
57 void* TCDVHolderT< T >::getAs( const std::type_info& tid,
58 ::Bool_t silent ) const {
60 // Non-const retrieval of ConstDataVector is never allowed:
62 const std::string heldType =
63 SG::normalizedTypeinfoName( typeid( Object_t ) );
64 const std::string reqType =
65 SG::normalizedTypeinfoName( tid );
66 ::Warning( "xAOD::TCDVHolder::getAs",
67 "Trying to retrieve %s object with a non-const %s pointer",
68 heldType.c_str(), reqType.c_str() );
75 const void* TCDVHolderT< T >::getAsConst( const std::type_info& tid,
76 ::Bool_t silent ) const {
78 // Check if the helper holder can handle the request:
79 const void* result = m_holderHelper.getAsConst( tid, kTRUE );
81 // If yes, then we're done:
85 // In case there was no dictionary for the base class, check whether the
86 // user is just asking for the base type:
87 if( tid == typeid( typename Object_t::base_data_vector ) ) {
88 return m_cdvObject->asDataVector();
90 // or the original type:
91 else if( tid == typeid( Object_t ) ) {
95 // Otherwise rely on the base class to do its thing:
96 return THolder::getAsConst( tid, silent );
101 #endif // XAODROOTACCESS_TOOLS_TCDVHOLDERT_ICC