File indexing completed on 2025-01-18 09:57:33
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef GAUDIALG_GAUDICOMMONIMP_H
0012 #define GAUDIALG_GAUDICOMMONIMP_H 1
0013
0014
0015
0016 #include <algorithm>
0017
0018
0019
0020 #include "GaudiAlg/GaudiCommon.h"
0021 #include "GaudiAlg/GetData.h"
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033 template <class PBASE>
0034 template <class TYPE>
0035 typename Gaudi::Utils::GetData<TYPE>::return_type
0036 GaudiCommon<PBASE>::get( IDataProviderSvc* service, std::string_view location, const bool useRootInTES ) const {
0037
0038 Assert( service, "get():: IDataProvider* points to NULL!" );
0039
0040 Gaudi::Utils::GetData<TYPE> getter;
0041 return getter( *this, service, this->fullTESLocation( location, useRootInTES ) );
0042 }
0043
0044
0045
0046 template <class PBASE>
0047 template <class TYPE>
0048 typename Gaudi::Utils::GetData<TYPE>::return_type
0049 GaudiCommon<PBASE>::getIfExists( IDataProviderSvc* service, std::string_view location, const bool useRootInTES ) const {
0050
0051 Assert( service, "get():: IDataProvider* points to NULL!" );
0052
0053 Gaudi::Utils::GetData<TYPE> getter;
0054 return getter( *this, service, this->fullTESLocation( location, useRootInTES ), false );
0055 }
0056
0057
0058
0059 template <class PBASE>
0060 template <class TYPE>
0061 bool GaudiCommon<PBASE>::exist( IDataProviderSvc* service, std::string_view location, const bool useRootInTES ) const {
0062
0063 Assert( service, "exist():: IDataProvider* points to NULL!" );
0064
0065 Gaudi::Utils::CheckData<TYPE> checker;
0066 return checker( service, this->fullTESLocation( location, useRootInTES ) );
0067 }
0068
0069
0070
0071
0072
0073 template <class PBASE>
0074 template <class TYPE, class TYPE2>
0075 typename Gaudi::Utils::GetData<TYPE>::return_type
0076 GaudiCommon<PBASE>::getOrCreate( IDataProviderSvc* service, std::string_view location, const bool useRootInTES ) const {
0077
0078 Assert( service, "getOrCreate():: svc points to NULL!" );
0079
0080 Gaudi::Utils::GetOrCreateData<TYPE, TYPE2> getter;
0081 return getter( *this, service, this->fullTESLocation( location, useRootInTES ), location );
0082 }
0083
0084
0085
0086 template <class PBASE>
0087 template <class TOOL>
0088 TOOL* GaudiCommon<PBASE>::tool( std::string_view type, std::string_view name, const IInterface* parent,
0089 bool create ) const {
0090
0091 if ( name.empty() ) return tool<TOOL>( type, parent, create );
0092 Assert( this->toolSvc(), "tool():: IToolSvc* points to NULL!" );
0093
0094 TOOL* Tool = nullptr;
0095 const StatusCode sc = this->toolSvc()->retrieveTool( type, name, Tool, parent, create );
0096 if ( sc.isFailure() ) {
0097 Exception(
0098 std::string{ "tool():: Could not retrieve Tool '" }.append( type ).append( "'/'" ).append( name ).append( "'" ),
0099 sc );
0100 }
0101 if ( !Tool ) {
0102 Exception( std::string{ "tool():: Could not retrieve Tool '" }.append( type ).append( "'/'" ).append( name ).append(
0103 "'" ) );
0104 }
0105
0106 PBASE::registerTool( Tool );
0107 m_managedTools.push_back( Tool );
0108
0109 return Tool;
0110 }
0111
0112
0113
0114 template <class PBASE>
0115 template <class TOOL>
0116 TOOL* GaudiCommon<PBASE>::tool( std::string_view type, const IInterface* parent, bool create ) const {
0117
0118 Assert( PBASE::toolSvc(), "IToolSvc* points to NULL!" );
0119
0120 TOOL* Tool = nullptr;
0121 const StatusCode sc = this->toolSvc()->retrieveTool( type, Tool, parent, create );
0122 if ( sc.isFailure() ) {
0123 Exception( std::string{ "tool():: Could not retrieve Tool '" }.append( type ).append( "'" ), sc );
0124 }
0125 if ( !Tool ) { Exception( std::string{ "tool():: Could not retrieve Tool '" }.append( type ).append( "'" ) ); }
0126
0127 PBASE::registerTool( Tool );
0128 m_managedTools.push_back( Tool );
0129
0130 return Tool;
0131 }
0132
0133
0134
0135 template <class PBASE>
0136 template <class SERVICE>
0137 SmartIF<SERVICE> GaudiCommon<PBASE>::svc( std::string_view name, const bool create ) const {
0138 Assert( this->svcLoc(), "ISvcLocator* points to NULL!" );
0139 SmartIF<SERVICE> s;
0140
0141 auto it = std::lower_bound( std::begin( m_services ), std::end( m_services ), name, GaudiCommon_details::svc_lt );
0142 if ( it != std::end( m_services ) && GaudiCommon_details::svc_eq( *it, name ) ) {
0143
0144 s = *it;
0145
0146 if ( !s ) {
0147 Exception( std::string{ "svc():: Could not retrieve Svc '" }.append( name ).append( "'" ), StatusCode::FAILURE );
0148 }
0149 } else {
0150 auto baseSvc = this->svcLoc()->service( name, create );
0151
0152 s = baseSvc;
0153
0154 if ( !baseSvc || !s ) {
0155 Exception( std::string{ "svc():: Could not retrieve Svc '" }.append( name ).append( "'" ), StatusCode::FAILURE );
0156 }
0157
0158 addToServiceList( baseSvc );
0159 }
0160
0161 return s;
0162 }
0163
0164
0165
0166 template <class PBASE>
0167 IUpdateManagerSvc* GaudiCommon<PBASE>::updMgrSvc() const {
0168 if ( !m_updMgrSvc ) { m_updMgrSvc = svc<IUpdateManagerSvc>( "UpdateManagerSvc", true ); }
0169 return m_updMgrSvc;
0170 }
0171
0172
0173
0174 template <class PBASE>
0175 void GaudiCommon<PBASE>::Assert( const bool ok, std::string_view msg, const StatusCode sc ) const {
0176 if ( !ok ) Exception( msg, sc );
0177 }
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193 #define ALG_ERROR( message, code ) \
0194 ( Error( message + std::string( " [ at line " ) + std::to_string( __LINE__ ) + std::string( " in file '" ) + \
0195 std::string( __FILE__ ) + "']", \
0196 code ) )
0197
0198
0199
0200
0201 #endif