| The Gaudi Framework v32r1 (f65d50dc)

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

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

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

Collaboration diagram for Gaudi::PluginService::v1::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 83 of file PluginServiceDetailsV1.h.

## Member Typedef Documentation

## ◆ FactoryMap

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

Type used for the database implementation.

Definition at line 114 of file PluginServiceDetailsV1.h.

## ◆ KeyType

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

Definition at line 85 of file PluginServiceDetailsV1.h.

## ◆ Properties

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

Type used for the properties implementation.

Definition at line 88 of file PluginServiceDetailsV1.h.

## Constructor & Destructor Documentation

## ◆ Registry() [1/2]

Gaudi::PluginService::v2::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 142 of file PluginServiceV1.cpp.

142 : m_initialized( false ) {}
Gaudi::PluginService::v1::Details::Registry::m_initialized
bool m_initialized
Flag recording if the registry has been initialized or not.
Definition: PluginServiceDetailsV1.h:176

## ◆ Registry() [2/2]

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

Private copy constructor for the singleton pattern.

Definition at line 159 of file PluginServiceDetailsV1.h.

159 : m_initialized( false ) {}
Gaudi::PluginService::v1::Details::Registry::m_initialized
bool m_initialized
Flag recording if the registry has been initialized or not.
Definition: PluginServiceDetailsV1.h:176

## Member Function Documentation

## ◆ add() [1/2]

template<typename F , typename T , typename I >

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

Add a factory to the database.

Definition at line 121 of file PluginServiceDetailsV1.h.

121 {
122 union {
123 typename F::FuncType src;
124 void* dst;
125 } p2p;
126 p2p.src = ptr;
127 std::ostringstream o;
128 o << id;
129 return add( o.str(), p2p.dst, typeid( typename F::FuncType ).name(),
130 typeid( typename F::ReturnType ).name(), demangle<T>() );
131 }
Gaudi::PluginService::v1::Details::Registry::add
FactoryInfo & add(const I &id, typename F::FuncType ptr)
Add a factory to the database.
Definition: PluginServiceDetailsV1.h:121
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:41
std::ostringstream
STL class.
std::ostringstream::str
T str(T... args)
ReadAndWriteWhiteBoard.dst
dst
Definition: ReadAndWriteWhiteBoard.py:17

## ◆ add() [2/2]

Registry::FactoryInfo & Gaudi::PluginService::v1::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 239 of file PluginServiceV1.cpp.

241 {
242 REG_SCOPE_LOCK
243 FactoryMap& facts = factories();
244 auto entry = facts.find( id );
245 if ( entry == facts.end() ) {
246 // this factory was not known yet
247 entry = facts.emplace( id, FactoryInfo( "unknown", factory, type, rtype, className, props ) ).first;
248 } else {
249 // do not replace an existing factory with a new one
250 if ( !entry->second.ptr ) entry->second.ptr = factory;
251 factoryInfoSetHelper( entry->second.type, type, "type", id );
252 factoryInfoSetHelper( entry->second.rtype, rtype, "return type", id );
253 factoryInfoSetHelper( entry->second.className, className, "class", id );
254 }
255 #ifdef GAUDI_REFLEX_COMPONENT_ALIASES
256 // add an alias for the factory using the Reflex convention
257 std::string old_name = old_style_name( id );
258 if ( id != old_name )
259 add( old_name, factory, type, rtype, className, props ).properties["ReflexName"] = "true";
260 #endif
261 return entry->second;
262 }
Gaudi::PluginService::v1::Details::Registry::factories
const FactoryMap & factories() const
Return the known factories (loading the list if not yet done).
Definition: PluginServiceDetailsV1.h:146
Gaudi::PluginService::v1::Details::Registry::add
FactoryInfo & add(const I &id, typename F::FuncType ptr)
Add a factory to the database.
Definition: PluginServiceDetailsV1.h:121
std::string
STL class.
Gaudi::PluginService::v1::Details::Registry::FactoryInfo::properties
Properties properties
Definition: PluginServiceDetailsV1.h:105
gaudirun.type
type
Definition: gaudirun.py:142
Gaudi::PluginService::v1::Details::Registry::FactoryMap
std::map< KeyType, FactoryInfo > FactoryMap
Type used for the database implementation.
Definition: PluginServiceDetailsV1.h:114
REG_SCOPE_LOCK
#define REG_SCOPE_LOCK
Definition: PluginServiceV1.cpp:29

## ◆ addProperty()

Registry & Gaudi::PluginService::v2::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 301 of file PluginServiceV1.cpp.

301 {
302 REG_SCOPE_LOCK
303 FactoryMap& facts = factories();
304 auto f = facts.find( id );
305 if ( f != facts.end() ) f->second.properties[k] = v;
306 return *this;
307 }
Gaudi::PluginService::v1::Details::Registry::factories
const FactoryMap & factories() const
Return the known factories (loading the list if not yet done).
Definition: PluginServiceDetailsV1.h:146
Gaudi::PluginService::v1::Details::Registry::FactoryMap
std::map< KeyType, FactoryInfo > FactoryMap
Type used for the database implementation.
Definition: PluginServiceDetailsV1.h:114
REG_SCOPE_LOCK
#define REG_SCOPE_LOCK
Definition: PluginServiceV1.cpp:29

## ◆ factories() [1/2]

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

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

Definition at line 146 of file PluginServiceDetailsV1.h.

146 {
147 if ( !m_initialized ) const_cast<Registry*>( this )->initialize();
148 return m_factories;
149 }
Gaudi::PluginService::v1::Details::Registry::m_factories
FactoryMap m_factories
Internal storage for factories.
Definition: PluginServiceDetailsV1.h:179
Gaudi::PluginService::v1::Details::Registry::m_initialized
bool m_initialized
Flag recording if the registry has been initialized or not.
Definition: PluginServiceDetailsV1.h:176

## ◆ factories() [2/2]

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

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

Definition at line 166 of file PluginServiceDetailsV1.h.

166 {
167 if ( !m_initialized ) initialize();
168 return m_factories;
169 }
Gaudi::PluginService::v1::Details::Registry::m_factories
FactoryMap m_factories
Internal storage for factories.
Definition: PluginServiceDetailsV1.h:179
Gaudi::PluginService::v1::Details::Registry::initialize
void initialize()
Initialize the registry loading the list of factories from the .component files in the library search...
Definition: PluginServiceV1.cpp:144
Gaudi::PluginService::v1::Details::Registry::m_initialized
bool m_initialized
Flag recording if the registry has been initialized or not.
Definition: PluginServiceDetailsV1.h:176

## ◆ get()

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

Retrieve the factory for the given id.

Definition at line 264 of file PluginServiceV1.cpp.

264 {
265 REG_SCOPE_LOCK
266 const FactoryMap& facts = factories();
267 auto f = facts.find( id );
268 if ( f != facts.end() ) {
269 #ifdef GAUDI_REFLEX_COMPONENT_ALIASES
270 const Properties& props = f->second.properties;
271 if ( props.find( "ReflexName" ) != props.end() )
272 logger().warning( "requesting factory via old name '" + id +
273 "'"
274 "use '" +
275 f->second.className + "' instead" );
276 #endif
277 if ( !f->second.ptr ) {
278 if ( !dlopen( f->second.library.c_str(), RTLD_LAZY | RTLD_GLOBAL ) ) {
279 logger().warning( "cannot load " + f->second.library + " for factory " + id );
280 char* dlmsg = dlerror();
281 if ( dlmsg ) logger().warning( dlmsg );
282 return nullptr;
283 }
284 f = facts.find( id ); // ensure that the iterator is valid
285 }
286 if ( f->second.type == type ) return f->second.ptr;
287 logger().warning( "found factory " + id + ", but of wrong type: " + demangle( f->second.type ) +
288 " instead of " + demangle( type ) );
289 }
290 return nullptr; // factory not found
291 }
Gaudi::PluginService::v1::Details::Registry::Properties
std::map< KeyType, std::string > Properties
Type used for the properties implementation.
Definition: PluginServiceDetailsV1.h:88
Gaudi::PluginService::v1::Details::Registry::factories
const FactoryMap & factories() const
Return the known factories (loading the list if not yet done).
Definition: PluginServiceDetailsV1.h:146
Gaudi::PluginService::v1::Details::Logger::warning
void warning(const std::string &msg)
Definition: PluginServiceDetailsV1.h:195
Gaudi::PluginService::v1::Details::logger
GAUDIPS_API Logger & logger()
Return the current logger instance.
Definition: PluginServiceV1.cpp:324
gaudirun.type
type
Definition: gaudirun.py:142
Gaudi::PluginService::v1::Details::Registry::FactoryMap
std::map< KeyType, FactoryInfo > FactoryMap
Type used for the database implementation.
Definition: PluginServiceDetailsV1.h:114
REG_SCOPE_LOCK
#define REG_SCOPE_LOCK
Definition: PluginServiceV1.cpp:29
Gaudi::PluginService::v1::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: PluginServiceV1.cpp:134

## ◆ getInfo()

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

Retrieve the FactoryInfo object for an id.

Definition at line 293 of file PluginServiceV1.cpp.

293 {
294 REG_SCOPE_LOCK
295 static const FactoryInfo unknown( "unknown" );
296 const FactoryMap& facts = factories();
297 auto f = facts.find( id );
298 return ( f != facts.end() ) ? f->second : unknown;
299 }
Gaudi::PluginService::v1::Details::Registry::factories
const FactoryMap & factories() const
Return the known factories (loading the list if not yet done).
Definition: PluginServiceDetailsV1.h:146
Gaudi::PluginService::v1::Details::Registry::FactoryMap
std::map< KeyType, FactoryInfo > FactoryMap
Type used for the database implementation.
Definition: PluginServiceDetailsV1.h:114
REG_SCOPE_LOCK
#define REG_SCOPE_LOCK
Definition: PluginServiceV1.cpp:29

## ◆ initialize()

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

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

Definition at line 144 of file PluginServiceV1.cpp.

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

## ◆ instance()

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

Retrieve the singleton instance of Registry.

Definition at line 136 of file PluginServiceV1.cpp.

136 {
137 SINGLETON_LOCK
138 static Registry r;
139 return r;
140 }
Gaudi::PluginService::v1::Details::Registry::Registry
Registry()
Private constructor for the singleton pattern.
Definition: PluginServiceV1.cpp:142
SINGLETON_LOCK
#define SINGLETON_LOCK
Definition: PluginServiceV1.cpp:34

## ◆ loadedFactoryNames()

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

Return a list of all the known and loaded factories.

Definition at line 309 of file PluginServiceV1.cpp.

309 {
310 REG_SCOPE_LOCK
311 std::set<KeyType> l;
312 for ( const auto& f : factories() ) {
313 if ( f.second.ptr ) l.insert( f.first );
314 }
315 return l;
316 }
Gaudi::PluginService::v1::Details::Registry::factories
const FactoryMap & factories() const
Return the known factories (loading the list if not yet done).
Definition: PluginServiceDetailsV1.h:146
REG_SCOPE_LOCK
#define REG_SCOPE_LOCK
Definition: PluginServiceV1.cpp:29
gaudirun.l
dictionary l
Definition: gaudirun.py:521
std::set
STL class.

## Member Data Documentation

## ◆ m_factories

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

Internal storage for factories.

Definition at line 179 of file PluginServiceDetailsV1.h.

## ◆ m_initialized

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

Flag recording if the registry has been initialized or not.

Definition at line 176 of file PluginServiceDetailsV1.h.

## ◆ m_mutex

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

Mutex used to control concurrent access to the internal data.

Definition at line 182 of file PluginServiceDetailsV1.h.

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

- GaudiPluginService/Gaudi/Details/PluginServiceDetailsV1.h
- GaudiPluginService/src/PluginServiceV1.cpp
- GaudiPluginService/src/PluginServiceV2.cpp