| The Gaudi Framework v30r0 (c919700c)

- 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 > | loadedFactoryNames () 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...
std::recursive_mutex | m_mutex
| Mutex used to control concurrent access to the internal data. More...

## Detailed Description

In-memory database of the loaded factories.

Definition at line 110 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 145 of file PluginServiceDetails.h.

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

Definition at line 113 of file PluginServiceDetails.h.

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

Type used for the properties implementation.

Definition at line 116 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 155 of file PluginService.cpp.

155 : 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:210

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

Private copy constructor for the singleton pattern.

Definition at line 192 of file PluginServiceDetails.h.

192 : 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:210

## 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 152 of file PluginServiceDetails.h.

153 {
154 union {
155 typename F::FuncType src;
156 void* dst;
157 } p2p;
158 p2p.src = ptr;
159 std::ostringstream o;
160 o << id;
161 return add( o.str(), p2p.dst, typeid( typename F::FuncType ).name(), typeid( typename F::ReturnType ).name(),
162 demangle<T>() );
163 }
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:152

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 248 of file PluginService.cpp.

251 {
252 REG_SCOPE_LOCK
253 FactoryMap& facts = factories();
254 auto entry = facts.find( id );
255 if ( entry == facts.end() ) {
256 // this factory was not known yet
257 entry = facts.emplace( id, FactoryInfo( "unknown", factory, type, rtype, className, props ) ).first;
258 } else {
259 // do not replace an existing factory with a new one
260 if ( !entry->second.ptr ) entry->second.ptr = factory;
261 factoryInfoSetHelper( entry->second.type, type, "type", id );
262 factoryInfoSetHelper( entry->second.rtype, rtype, "return type", id );
263 factoryInfoSetHelper( entry->second.className, className, "class", id );
264 }
265 #ifdef GAUDI_REFLEX_COMPONENT_ALIASES
266 // add an alias for the factory using the Reflex convention
267 std::string old_name = old_style_name( id );
268 if ( id != old_name ) add( old_name, factory, type, rtype, className, props ).properties["ReflexName"] = "true";
269 #endif
270 return entry->second;
271 }
REG_SCOPE_LOCK
#define REG_SCOPE_LOCK
Definition: PluginService.cpp:28
Gaudi::PluginService::Details::Registry::FactoryInfo::properties
Properties properties
Definition: PluginServiceDetails.h:135
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:178
Gaudi::PluginService::Details::Registry::add
FactoryInfo & add(const I &id, typename F::FuncType ptr)
Add a factory to the database.
Definition: PluginServiceDetails.h:152
Gaudi::PluginService::Details::Registry::FactoryMap
std::map< KeyType, FactoryInfo > FactoryMap
Type used for the database implementation.
Definition: PluginServiceDetails.h:145

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 311 of file PluginService.cpp.

312 {
313 REG_SCOPE_LOCK
314 FactoryMap& facts = factories();
315 auto f = facts.find( id );
316 if ( f != facts.end() ) f->second.properties[k] = v;
317 return *this;
318 }
REG_SCOPE_LOCK
#define REG_SCOPE_LOCK
Definition: PluginService.cpp:28
Gaudi::PluginService::Details::Registry::factories
const FactoryMap & factories() const
Return the known factories (loading the list if not yet done).
Definition: PluginServiceDetails.h:178
Gaudi::PluginService::Details::Registry::FactoryMap
std::map< KeyType, FactoryInfo > FactoryMap
Type used for the database implementation.
Definition: PluginServiceDetails.h:145

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

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

Definition at line 178 of file PluginServiceDetails.h.

179 {
180 if ( !m_initialized ) const_cast<Registry*>( this )->initialize();
181 return m_factories;
182 }
Gaudi::PluginService::Details::Registry::Registry
Registry()
Private constructor for the singleton pattern.
Definition: PluginService.cpp:155
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:157
Gaudi::PluginService::Details::Registry::m_factories
FactoryMap m_factories
Internal storage for factories.
Definition: PluginServiceDetails.h:213
Gaudi::PluginService::Details::Registry::m_initialized
bool m_initialized
Flag recording if the registry has been initialized or not.
Definition: PluginServiceDetails.h:210

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

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

Definition at line 199 of file PluginServiceDetails.h.

200 {
201 if ( !m_initialized ) initialize();
202 return m_factories;
203 }
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:157
Gaudi::PluginService::Details::Registry::m_factories
FactoryMap m_factories
Internal storage for factories.
Definition: PluginServiceDetails.h:213
Gaudi::PluginService::Details::Registry::m_initialized
bool m_initialized
Flag recording if the registry has been initialized or not.
Definition: PluginServiceDetails.h:210

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 273 of file PluginService.cpp.

274 {
275 REG_SCOPE_LOCK
276 const FactoryMap& facts = factories();
277 auto f = facts.find( id );
278 if ( f != facts.end() ) {
279 #ifdef GAUDI_REFLEX_COMPONENT_ALIASES
280 const Properties& props = f->second.properties;
281 if ( props.find( "ReflexName" ) != props.end() )
282 logger().warning( "requesting factory via old name '" + id + "'"
283 "use '" +
284 f->second.className + "' instead" );
285 #endif
286 if ( !f->second.ptr ) {
287 if ( !dlopen( f->second.library.c_str(), RTLD_LAZY | RTLD_GLOBAL ) ) {
288 logger().warning( "cannot load " + f->second.library + " for factory " + id );
289 char* dlmsg = dlerror();
290 if ( dlmsg ) logger().warning( dlmsg );
291 return nullptr;
292 }
293 f = facts.find( id ); // ensure that the iterator is valid
294 }
295 if ( f->second.type == type ) return f->second.ptr;
296 logger().warning( "found factory " + id + ", but of wrong type: " + demangle( f->second.type ) +
297 " instead of " + demangle( type ) );
298 }
299 return nullptr; // factory not found
300 }
REG_SCOPE_LOCK
#define REG_SCOPE_LOCK
Definition: PluginService.cpp:28
std::vector::end
T end(T...args)
Gaudi::PluginService::Details::logger
GAUDIPS_API Logger & logger()
Return the current logger instance.
Definition: PluginService.cpp:339
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:146
Gaudi::PluginService::Details::Registry::factories
const FactoryMap & factories() const
Return the known factories (loading the list if not yet done).
Definition: PluginServiceDetails.h:178
Gaudi::PluginService::Details::Logger::warning
void warning(const std::string &msg)
Definition: PluginServiceDetails.h:230
std::vector< Gaudi::Details::PropertyBase * >
Gaudi::PluginService::Details::Registry::FactoryMap
std::map< KeyType, FactoryInfo > FactoryMap
Type used for the database implementation.
Definition: PluginServiceDetails.h:145

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

Retrieve the FactoryInfo object for an id.

Definition at line 302 of file PluginService.cpp.

303 {
304 REG_SCOPE_LOCK
305 static const FactoryInfo unknown( "unknown" );
306 const FactoryMap& facts = factories();
307 auto f = facts.find( id );
308 return ( f != facts.end() ) ? f->second : unknown;
309 }
REG_SCOPE_LOCK
#define REG_SCOPE_LOCK
Definition: PluginService.cpp:28
Gaudi::PluginService::Details::Registry::factories
const FactoryMap & factories() const
Return the known factories (loading the list if not yet done).
Definition: PluginServiceDetails.h:178
Gaudi::PluginService::Details::Registry::FactoryMap
std::map< KeyType, FactoryInfo > FactoryMap
Type used for the database implementation.
Definition: PluginServiceDetails.h:145

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 157 of file PluginService.cpp.

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

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

Retrieve the singleton instance of Registry.

Definition at line 148 of file PluginService.cpp.

149 {
150 SINGLETON_LOCK
151 static Registry r;
152 return r;
153 }
Gaudi::PluginService::Details::Registry::Registry
Registry()
Private constructor for the singleton pattern.
Definition: PluginService.cpp:155
SINGLETON_LOCK
#define SINGLETON_LOCK
Definition: PluginService.cpp:34

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

Return a list of all the known and loaded factories.

Definition at line 320 of file PluginService.cpp.

321 {
322 REG_SCOPE_LOCK
323 std::set<KeyType> l;
324 for ( const auto& f : factories() ) {
325 if ( f.second.ptr ) l.insert( f.first );
326 }
327 return l;
328 }
REG_SCOPE_LOCK
#define REG_SCOPE_LOCK
Definition: PluginService.cpp:28
Gaudi::PluginService::Details::Registry::factories
const FactoryMap & factories() const
Return the known factories (loading the list if not yet done).
Definition: PluginServiceDetails.h:178
gaudirun.l
dictionary l
Definition: gaudirun.py:440
std::set
STL class.

## Member Data Documentation

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

Internal storage for factories.

Definition at line 213 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 210 of file PluginServiceDetails.h.

std::recursive_mutex Gaudi::PluginService::Details::Registry::m_mutex
| mutable private

Mutex used to control concurrent access to the internal data.

Definition at line 216 of file PluginServiceDetails.h.

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

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