| The Gaudi Framework v29r0 (ff2e7097)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
Gaudi::PluginService::Details::Registry Class Reference

In-memory database of the loaded factories. More...

`#include <Gaudi/Details/PluginServiceDetails.h>`

Collaboration diagram for Gaudi::PluginService::Details::Registry:
[legend]

## Classes
struct | FactoryInfo

## Public Types
typedef std::string | KeyType
typedef std::map< KeyType, std::string > | Properties
| Type used for the properties implementation. More...
typedef std::map< KeyType, FactoryInfo > | FactoryMap
| Type used for the database implementation. More...

## Public Member Functions
template<typename F , typename T , typename I >
FactoryInfo & | add (const I &id, typename F::FuncType ptr)
| Add a factory to the database. More...
void * | get (const std::string &id, const std::string &type) const
| Retrieve the factory for the given id. More...
const FactoryInfo & | getInfo (const std::string &id) const
| Retrieve the FactoryInfo object for an id. More...
Registry & | addProperty (const std::string &id, const std::string &k, const std::string &v)
| Add a property to an already existing FactoryInfo object (via its id.) More...
std::set< KeyType > | loadedFactories () const
| Return a list of all the known and loaded factories. More...
const FactoryMap & | factories () const
| Return the known factories (loading the list if not yet done). More...

## Static Public Member Functions
static Registry & | instance ()
| Retrieve the singleton instance of Registry. More...

## Private Member Functions
| Registry ()
| Private constructor for the singleton pattern. More...
| Registry (const Registry &)
| Private copy constructor for the singleton pattern. More...
FactoryInfo & | add (const std::string &id, void *factory, const std::string &type, const std::string &rtype, const std::string &className, const Properties &props=Properties())
| Add a factory to the database. More...
FactoryMap & | factories ()
| Return the known factories (loading the list if not yet done). More...
void | initialize ()
| Initialize the registry loading the list of factories from the .component files in the library search path. More...

## Private Attributes
bool | m_initialized
| Flag recording if the registry has been initialized or not. More...
FactoryMap | m_factories
| Internal storage for factories. More...

## Detailed Description

In-memory database of the loaded factories.

Definition at line 112 of file PluginServiceDetails.h.

## Member Typedef Documentation

typedef std::map<KeyType, FactoryInfo> Gaudi::PluginService::Details::Registry::FactoryMap

Type used for the database implementation.

Definition at line 147 of file PluginServiceDetails.h.

typedef std::string Gaudi::PluginService::Details::Registry::KeyType

Definition at line 115 of file PluginServiceDetails.h.

typedef std::map<KeyType, std::string> Gaudi::PluginService::Details::Registry::Properties

Type used for the properties implementation.

Definition at line 118 of file PluginServiceDetails.h.

## Constructor & Destructor Documentation

Gaudi::PluginService::Details::Registry::Registry | ( |  | ) |
| private

Private constructor for the singleton pattern.

At construction time, the internal database of known factories is filled with the name of the libraries containing them, using the ".components" files in the LD_LIBRARY_PATH.

Definition at line 160 of file PluginService.cpp.

160 : m_initialized( false ) {}
Gaudi::PluginService::Details::Registry::m_initialized
bool m_initialized
Flag recording if the registry has been initialized or not.
Definition: PluginServiceDetails.h:212

Gaudi::PluginService::Details::Registry::Registry | ( | const Registry & |  | ) |
| inline private

Private copy constructor for the singleton pattern.

Definition at line 194 of file PluginServiceDetails.h.

194 : m_initialized( false ) {}
Gaudi::PluginService::Details::Registry::m_initialized
bool m_initialized
Flag recording if the registry has been initialized or not.
Definition: PluginServiceDetails.h:212

## Member Function Documentation

template<typename F , typename T , typename I >

FactoryInfo& Gaudi::PluginService::Details::Registry::add | ( | const I & | id,
|  | typename F::FuncType | ptr
| ) |  |
| inline

Add a factory to the database.

Definition at line 154 of file PluginServiceDetails.h.

155 {
156 union {
157 typename F::FuncType src;
158 void* dst;
159 } p2p;
160 p2p.src = ptr;
161 std::ostringstream o;
162 o << id;
163 return add( o.str(), p2p.dst, typeid( typename F::FuncType ).name(), typeid( typename F::ReturnType ).name(),
164 demangle<T>() );
165 }
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:32
std::ostringstream
STL class.
std::ostringstream::str
T str(T...args)
ReadAndWriteWhiteBoard.dst
dst
Definition: ReadAndWriteWhiteBoard.py:17
Gaudi::PluginService::Details::Registry::add
FactoryInfo & add(const I &id, typename F::FuncType ptr)
Add a factory to the database.
Definition: PluginServiceDetails.h:154

Registry::FactoryInfo & Gaudi::PluginService::Details::Registry::add | ( | const std::string & | id,
|  | void * | factory,
|  | const std::string & | type,
|  | const std::string & | rtype,
|  | const std::string & | className,
|  | const Properties & | props = `Properties()`
| ) |  |
| private

Add a factory to the database.

Definition at line 253 of file PluginService.cpp.

256 {
257 REG_SCOPE_LOCK
258 FactoryMap& facts = factories();
259 auto entry = facts.find( id );
260 if ( entry == facts.end() ) {
261 // this factory was not known yet
262 entry = facts.emplace( id, FactoryInfo( "unknown", factory, type, rtype, className, props ) ).first;
263 } else {
264 // do not replace an existing factory with a new one
265 if ( !entry->second.ptr ) entry->second.ptr = factory;
266 factoryInfoSetHelper( entry->second.type, type, "type", id );
267 factoryInfoSetHelper( entry->second.rtype, rtype, "return type", id );
268 factoryInfoSetHelper( entry->second.className, className, "class", id );
269 }
270 #ifdef GAUDI_REFLEX_COMPONENT_ALIASES
271 // add an alias for the factory using the Reflex convention
272 std::string old_name = old_style_name( id );
273 if ( id != old_name ) add( old_name, factory, type, rtype, className, props ).properties["ReflexName"] = "true";
274 #endif
275 return entry->second;
276 }
REG_SCOPE_LOCK
#define REG_SCOPE_LOCK
Definition: PluginService.cpp:37
Gaudi::PluginService::Details::Registry::FactoryInfo::properties
Properties properties
Definition: PluginServiceDetails.h:137
std::string
STL class.
Gaudi::PluginService::Details::Registry::factories
const FactoryMap & factories() const
Return the known factories (loading the list if not yet done).
Definition: PluginServiceDetails.h:180
Gaudi::PluginService::Details::Registry::add
FactoryInfo & add(const I &id, typename F::FuncType ptr)
Add a factory to the database.
Definition: PluginServiceDetails.h:154
Gaudi::PluginService::Details::Registry::FactoryMap
std::map< KeyType, FactoryInfo > FactoryMap
Type used for the database implementation.
Definition: PluginServiceDetails.h:147

Registry & Gaudi::PluginService::Details::Registry::addProperty | ( | const std::string & | id,
|  | const std::string & | k,
|  | const std::string & | v
| ) |  |

Add a property to an already existing FactoryInfo object (via its id.)

Definition at line 316 of file PluginService.cpp.

317 {
318 REG_SCOPE_LOCK
319 FactoryMap& facts = factories();
320 auto f = facts.find( id );
321 if ( f != facts.end() ) f->second.properties[k] = v;
322 return *this;
323 }
REG_SCOPE_LOCK
#define REG_SCOPE_LOCK
Definition: PluginService.cpp:37
Gaudi::PluginService::Details::Registry::factories
const FactoryMap & factories() const
Return the known factories (loading the list if not yet done).
Definition: PluginServiceDetails.h:180
Gaudi::PluginService::Details::Registry::FactoryMap
std::map< KeyType, FactoryInfo > FactoryMap
Type used for the database implementation.
Definition: PluginServiceDetails.h:147

const FactoryMap& Gaudi::PluginService::Details::Registry::factories | ( |  | ) | const
| inline

Return the known factories (loading the list if not yet done).

Definition at line 180 of file PluginServiceDetails.h.

181 {
182 if ( !m_initialized ) const_cast<Registry*>( this )->initialize();
183 return m_factories;
184 }
Gaudi::PluginService::Details::Registry::Registry
Registry()
Private constructor for the singleton pattern.
Definition: PluginService.cpp:160
Gaudi::PluginService::Details::Registry::initialize
void initialize()
Initialize the registry loading the list of factories from the .component files in the library search...
Definition: PluginService.cpp:162
Gaudi::PluginService::Details::Registry::m_factories
FactoryMap m_factories
Internal storage for factories.
Definition: PluginServiceDetails.h:215
Gaudi::PluginService::Details::Registry::m_initialized
bool m_initialized
Flag recording if the registry has been initialized or not.
Definition: PluginServiceDetails.h:212

FactoryMap& Gaudi::PluginService::Details::Registry::factories | ( |  | ) |
| inline private

Return the known factories (loading the list if not yet done).

Definition at line 201 of file PluginServiceDetails.h.

202 {
203 if ( !m_initialized ) initialize();
204 return m_factories;
205 }
Gaudi::PluginService::Details::Registry::initialize
void initialize()
Initialize the registry loading the list of factories from the .component files in the library search...
Definition: PluginService.cpp:162
Gaudi::PluginService::Details::Registry::m_factories
FactoryMap m_factories
Internal storage for factories.
Definition: PluginServiceDetails.h:215
Gaudi::PluginService::Details::Registry::m_initialized
bool m_initialized
Flag recording if the registry has been initialized or not.
Definition: PluginServiceDetails.h:212

void * Gaudi::PluginService::Details::Registry::get | ( | const std::string & | id,
|  | const std::string & | type
| ) |  | const

Retrieve the factory for the given id.

Definition at line 278 of file PluginService.cpp.

279 {
280 REG_SCOPE_LOCK
281 const FactoryMap& facts = factories();
282 auto f = facts.find( id );
283 if ( f != facts.end() ) {
284 #ifdef GAUDI_REFLEX_COMPONENT_ALIASES
285 const Properties& props = f->second.properties;
286 if ( props.find( "ReflexName" ) != props.end() )
287 logger().warning( "requesting factory via old name '" + id + "'"
288 "use '" +
289 f->second.className + "' instead" );
290 #endif
291 if ( !f->second.ptr ) {
292 if ( !dlopen( f->second.library.c_str(), RTLD_LAZY | RTLD_GLOBAL ) ) {
293 logger().warning( "cannot load " + f->second.library + " for factory " + id );
294 char* dlmsg = dlerror();
295 if ( dlmsg ) logger().warning( dlmsg );
296 return nullptr;
297 }
298 f = facts.find( id ); // ensure that the iterator is valid
299 }
300 if ( f->second.type == type ) return f->second.ptr;
301 logger().warning( "found factory " + id + ", but of wrong type: " + demangle( f->second.type ) +
302 " instead of " + demangle( type ) );
303 }
304 return nullptr; // factory not found
305 }
REG_SCOPE_LOCK
#define REG_SCOPE_LOCK
Definition: PluginService.cpp:37
std::vector::end
T end(T...args)
Gaudi::PluginService::Details::logger
GAUDIPS_API Logger & logger()
Return the current logger instance.
Definition: PluginService.cpp:345
Gaudi::PluginService::Details::demangle
GAUDIPS_API std::string demangle(const std::type_info &id)
Return a canonical name for type_info object (implementation borrowed from GaudiKernel/System).
Definition: PluginService.cpp:151
Gaudi::PluginService::Details::Registry::factories
const FactoryMap & factories() const
Return the known factories (loading the list if not yet done).
Definition: PluginServiceDetails.h:180
Gaudi::PluginService::Details::Logger::warning
void warning(const std::string &msg)
Definition: PluginServiceDetails.h:234
std::vector< Gaudi::Details::PropertyBase * >
Gaudi::PluginService::Details::Registry::FactoryMap
std::map< KeyType, FactoryInfo > FactoryMap
Type used for the database implementation.
Definition: PluginServiceDetails.h:147

const Registry::FactoryInfo & Gaudi::PluginService::Details::Registry::getInfo | ( | const std::string & | id | ) | const

Retrieve the FactoryInfo object for an id.

Definition at line 307 of file PluginService.cpp.

308 {
309 REG_SCOPE_LOCK
310 static const FactoryInfo unknown( "unknown" );
311 const FactoryMap& facts = factories();
312 auto f = facts.find( id );
313 return ( f != facts.end() ) ? f->second : unknown;
314 }
REG_SCOPE_LOCK
#define REG_SCOPE_LOCK
Definition: PluginService.cpp:37
Gaudi::PluginService::Details::Registry::factories
const FactoryMap & factories() const
Return the known factories (loading the list if not yet done).
Definition: PluginServiceDetails.h:180
Gaudi::PluginService::Details::Registry::FactoryMap
std::map< KeyType, FactoryInfo > FactoryMap
Type used for the database implementation.
Definition: PluginServiceDetails.h:147

void Gaudi::PluginService::Details::Registry::initialize | ( |  | ) |
| private

Initialize the registry loading the list of factories from the .component files in the library search path.

Definition at line 162 of file PluginService.cpp.

163 {
164 REG_SCOPE_LOCK
165 if ( m_initialized ) return;
166 m_initialized = true;
167 #if defined( _WIN32 )
168 const char* envVar = "PATH";
169 const char sep = ';';
170 #elif defined( __APPLE__ )
171 const char* envVar = "DYLD_LIBRARY_PATH";
172 const char sep = ':';
173 #else
174 const char* envVar = "LD_LIBRARY_PATH";
175 const char sep = ':';
176 #endif
177 char* search_path = ::getenv( envVar );
178 if ( search_path ) {
179 logger().debug( std::string( "searching factories in " ) + envVar );
180 std::string path( search_path );
181 std::string::size_type pos = 0;
182 std::string::size_type newpos = 0;
183 while ( pos != std::string::npos ) {
184 std::string dirName;
185 // get the next entry in the path
186 newpos = path.find( sep, pos );
187 if ( newpos != std::string::npos ) {
188 dirName = path.substr( pos, newpos - pos );
189 pos = newpos + 1;
190 } else {
191 dirName = path.substr( pos );
192 pos = newpos;
193 }
194 logger().debug( std::string( " looking into " ) + dirName );
195 // look for files called "*.components" in the directory
196 DIR* dir = opendir( dirName.c_str() );
197 if ( dir ) {
198 struct dirent* entry;
199 while ( ( entry = readdir( dir ) ) ) {
200 std::string name( entry->d_name );
201 // check if the file name ends with ".components"
202 std::string::size_type extpos = name.find( ".components" );
203 if ( ( extpos != std::string::npos ) && ( ( extpos + 11 ) == name.size() ) ) {
204 std::string fullPath = ( dirName + '/' + name );
205 { // check if it is a regular file
206 struct stat buf;
207 stat( fullPath.c_str(), &buf );
208 if ( !S_ISREG( buf.st_mode ) ) continue;
209 }
210 // read the file
211 logger().debug( std::string( " reading " ) + name );
212 std::ifstream factories{fullPath};
213 std::string line;
214 int factoriesCount = 0;
215 int lineCount = 0;
216 while ( !factories.eof() ) {
217 ++lineCount;
218 std::getline( factories, line );
219 trim( line );
220 // skip empty lines and lines starting with '#'
221 if ( line.empty() || line[0] == '#' ) continue;
222 // look for the separator
223 auto pos = line.find( ':' );
224 if ( pos == std::string::npos ) {
225 logger().warning( "failed to parse line " + fullPath + ':' + std::to_string( lineCount ) );
226 continue;
227 }
228 const std::string lib( line, 0, pos );
229 const std::string fact( line, pos + 1 );
230 m_factories.emplace( fact, FactoryInfo( lib ) );
231 #ifdef GAUDI_REFLEX_COMPONENT_ALIASES
232 // add an alias for the factory using the Reflex convention
233 std::string old_name = old_style_name( fact );
234 if ( fact != old_name ) {
235 FactoryInfo old_info( lib );
236 old_info.properties["ReflexName"] = "true";
237 m_factories.emplace( old_name, old_info );
238 }
239 #endif
240 ++factoriesCount;
241 }
242 if ( logger().level() <= Logger::Debug ) {
243 logger().debug( " found " + std::to_string( factoriesCount ) + " factories" );
244 }
245 }
246 }
247 closedir( dir );
248 }
249 }
250 }
251 }
std::string::empty
T empty(T...args)
GaudiPython.HistoUtils.path
path
Definition: HistoUtils.py:895
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:32
REG_SCOPE_LOCK
#define REG_SCOPE_LOCK
Definition: PluginService.cpp:37
std::getline
T getline(T...args)
std::to_string
T to_string(T...args)
Gaudi::PluginService::Details::logger
GAUDIPS_API Logger & logger()
Return the current logger instance.
Definition: PluginService.cpp:345
std::string
STL class.
Gaudi::PluginService::Details::Registry::factories
const FactoryMap & factories() const
Return the known factories (loading the list if not yet done).
Definition: PluginServiceDetails.h:180
Gaudi::PluginService::Details::Logger::warning
void warning(const std::string &msg)
Definition: PluginServiceDetails.h:234
std::string::find
T find(T...args)
Gaudi::PluginService::Details::Logger::Debug
Definition: PluginServiceDetails.h:227
std::string::c_str
T c_str(T...args)
std::map::emplace
T emplace(T...args)
gaudirun.level
level
Definition: gaudirun.py:271
Gaudi::PluginService::Details::Registry::m_factories
FactoryMap m_factories
Internal storage for factories.
Definition: PluginServiceDetails.h:215
std::ifstream
STL class.
plotSpeedupsPyRoot.line
line
Definition: plotSpeedupsPyRoot.py:172
Gaudi::PluginService::Details::Registry::m_initialized
bool m_initialized
Flag recording if the registry has been initialized or not.
Definition: PluginServiceDetails.h:212
Gaudi::PluginService::Details::Logger::debug
void debug(const std::string &msg)
Definition: PluginServiceDetails.h:233

Registry & Gaudi::PluginService::Details::Registry::instance | ( |  | ) |
| static

Retrieve the singleton instance of Registry.

Definition at line 153 of file PluginService.cpp.

154 {
155 SINGLETON_LOCK
156 static Registry r;
157 return r;
158 }
Gaudi::PluginService::Details::Registry::Registry
Registry()
Private constructor for the singleton pattern.
Definition: PluginService.cpp:160
SINGLETON_LOCK
#define SINGLETON_LOCK
Definition: PluginService.cpp:38

std::set< Registry::KeyType > Gaudi::PluginService::Details::Registry::loadedFactories | ( |  | ) | const

Return a list of all the known and loaded factories.

Definition at line 325 of file PluginService.cpp.

326 {
327 REG_SCOPE_LOCK
328 const FactoryMap& facts = factories();
329 std::set<KeyType> l;
330 for ( const auto& f : facts ) {
331 if ( f.second.ptr ) l.insert( f.first );
332 }
333 return l;
334 }
REG_SCOPE_LOCK
#define REG_SCOPE_LOCK
Definition: PluginService.cpp:37
Gaudi::PluginService::Details::Registry::factories
const FactoryMap & factories() const
Return the known factories (loading the list if not yet done).
Definition: PluginServiceDetails.h:180
gaudirun.l
dictionary l
Definition: gaudirun.py:440
std::set::insert
T insert(T...args)
std::set
STL class.
Gaudi::PluginService::Details::Registry::FactoryMap
std::map< KeyType, FactoryInfo > FactoryMap
Type used for the database implementation.
Definition: PluginServiceDetails.h:147

## Member Data Documentation

FactoryMap Gaudi::PluginService::Details::Registry::m_factories
| private

Internal storage for factories.

Definition at line 215 of file PluginServiceDetails.h.

bool Gaudi::PluginService::Details::Registry::m_initialized
| private

Flag recording if the registry has been initialized or not.

Definition at line 212 of file PluginServiceDetails.h.

The documentation for this class was generated from the following files:

- GaudiPluginService/Gaudi/Details/PluginServiceDetails.h
- GaudiPluginService/src/PluginService.cpp