The Gaudi Framework  v41r0 (bdbe7744)
Loading...
Searching...
No Matches
Gaudi::PluginService::v2::Details Namespace Reference

Functions

std::string demangle (const std::string &id)
std::string demangle (const std::type_info &id)
void reportBadAnyCast (const std::type_info &factory_type, const std::string &id)
Logger & logger ()
void setLogger (Logger *logger)
std::string getDSONameFor (void *fptr)
std::string implicitPluginDir ()
const std::vector< std::string > & getPluginSearchPath ()

Function Documentation

◆ demangle() [1/2]

std::string Gaudi::PluginService::v2::Details::demangle ( const std::string & id)

Definition at line 91 of file PluginServiceV2.cpp.

91 {
92 int status;
93 auto realname = std::unique_ptr<char, decltype( free )*>(
94 abi::__cxa_demangle( id.c_str(), nullptr, nullptr, &status ), free );
95 if ( !realname ) return id;
96 std::string result = realname.get();
97 // Normalize libstdc++ (Linux) std::string representation
98 result = std::regex_replace(
99 result,
100 std::regex{ "std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >( (?=>))?" },
101 "std::string" );
102 // Normalize libc++ (macOS) inline namespace - remove std::__1:: prefix
103 result = std::regex_replace( result, std::regex{ "std::__1::" }, "std::" );
104 // Normalize libc++ basic_string (after removing __1::)
105 result = std::regex_replace(
106 result, std::regex{ "std::basic_string<char, std::char_traits<char>, std::allocator<char>>( (?=>))?" },
107 "std::string" );
108 // Normalize closing angle brackets: >> to > > (match libstdc++ C++03 style)
109 result = std::regex_replace( result, std::regex{ ">>" }, "> >" );
110 result = std::regex_replace( result, std::regex{ ">>" }, "> >" ); // twice for >>>
111 return result;
112 }

◆ demangle() [2/2]

std::string Gaudi::PluginService::v2::Details::demangle ( const std::type_info & id)

Definition at line 113 of file PluginServiceV2.cpp.

113{ return demangle( id.name() ); }
std::string demangle(const std::string &id)

◆ getDSONameFor()

std::string Gaudi::PluginService::v2::Details::getDSONameFor ( void * fptr)

Definition at line 299 of file PluginServiceV2.cpp.

299 {
300#if defined _GNU_SOURCE || defined __APPLE__
301 Dl_info info;
302 if ( dladdr( fptr, &info ) == 0 ) return "";
303
304 auto pos = std::strrchr( info.dli_fname, '/' );
305 if ( pos )
306 ++pos;
307 else
308 return info.dli_fname;
309 return pos;
310#else
311 return "";
312#endif
313 }

◆ getPluginSearchPath()

const std::vector< std::string > & Gaudi::PluginService::v2::Details::getPluginSearchPath ( )

Definition at line 332 of file PluginServiceV2.cpp.

332 {
333 // we search for plugin libraries in the following order:
334 // 1. GAUDI_PLUGIN_PATH environment variable
335 // 2. LD_LIBRARY_PATH environment variable (backward compatibility)
336 // 3. implicit plugin path (relative to the library)
337
338 constexpr char const* envVars[] =
339#if defined( __APPLE__ )
340 { "GAUDI_PLUGIN_PATH", "DYLD_LIBRARY_PATH" };
341#else
342 { "GAUDI_PLUGIN_PATH", "LD_LIBRARY_PATH" };
343#endif
344
345 // We cache the result to avoid recomputing it on every call
346 static std::vector<std::string> search_path;
347 static std::once_flag initialized;
348 std::call_once( initialized, [&]() {
349 for ( const auto& envVar : envVars ) {
350 if ( auto ptr = std::getenv( envVar ) ) {
351 std::string_view path{ ptr };
352 while ( !path.empty() ) {
353 auto sep = path.find( ':' );
354 std::string dirname = std::string{ path.substr( 0, sep ) };
355 // ignore duplicates
356 if ( find( search_path.begin(), search_path.end(), dirname ) == search_path.end() ) {
357 search_path.emplace_back( std::move( dirname ) );
358 }
359 // handle correctly missing separator
360 if ( sep != std::string_view::npos ) {
361 path = path.substr( sep + 1 );
362 } else {
363 path = {};
364 }
365 }
366 }
367 }
368 search_path.push_back( implicitPluginDir() );
369 } );
370 return search_path;
371 }
GAUDI_API std::string path(const AIDA::IBaseHistogram *aida)
get the path in THS for AIDA histogram

◆ implicitPluginDir()

std::string Gaudi::PluginService::v2::Details::implicitPluginDir ( )

Definition at line 315 of file PluginServiceV2.cpp.

315 {
316#ifdef PLUGIN_PATH_RELATIVE
317# define stringify( x ) stringify_( x )
318# define stringify_( x ) #x
319 std::string relative_path = stringify( PLUGIN_PATH_RELATIVE );
320#else
321 std::string relative_path = ".";
322#endif
323 Dl_info info;
324 if ( dladdr( (void*)_dso_marker, &info ) != 0 ) {
325 auto plugin_path = fs::path( info.dli_fname ).parent_path() / relative_path;
326 return plugin_path.string();
327 } else {
328 return relative_path;
329 }
330 }

◆ logger()

Logger & Gaudi::PluginService::v2::Details::logger ( )

Definition at line 295 of file PluginServiceV2.cpp.

295{ return *s_logger; }

◆ reportBadAnyCast()

void Gaudi::PluginService::v2::Details::reportBadAnyCast ( const std::type_info & factory_type,
const std::string & id )

Definition at line 121 of file PluginServiceV2.cpp.

121 {
122 if ( logger().level() <= Logger::Debug ) {
123 std::stringstream msg;
124 const auto& info = Registry::instance().getInfo( id );
125 msg << "bad any_cast: requested factory " << id << " of type " << demangle( factory_type ) << ", got ";
126 if ( info.is_set() )
127 msg << demangle( info.factory.type() ) << " from " << info.library;
128 else
129 msg << "nothing";
130 logger().debug( msg.str() );
131 }
132 }

◆ setLogger()

void Gaudi::PluginService::v2::Details::setLogger ( Logger * logger)

Definition at line 296 of file PluginServiceV2.cpp.

296{ s_logger.reset( logger ); }