| The Gaudi Framework v28r2p1 (f1a77ff4)

- 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 99 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 130 of file PluginServiceDetails.h.

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

Definition at line 101 of file PluginServiceDetails.h.

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

Type used for the properties implementation.

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

151 : 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:196

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

Private copy constructor for the singleton pattern.

Definition at line 176 of file PluginServiceDetails.h.

176 : 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:196

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

137 {
138 union { typename F::FuncType src; void* dst; } p2p;
139 p2p.src = ptr;
140 std::ostringstream o; o << id;
141 return add(o.str(), p2p.dst,
142 typeid(typename F::FuncType).name(),
143 typeid(typename F::ReturnType).name(),
144 demangle<T>());
145 }
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
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:137

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

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

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

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

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

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

Definition at line 163 of file PluginServiceDetails.h.

163 {
164 if (!m_initialized) const_cast<Registry*>(this)->initialize();
165 return m_factories;
166 }
Gaudi::PluginService::Details::Registry::Registry
Registry()
Private constructor for the singleton pattern.
Definition: PluginService.cpp:151
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:153
Gaudi::PluginService::Details::Registry::m_factories
FactoryMap m_factories
Internal storage for factories.
Definition: PluginServiceDetails.h:199
Gaudi::PluginService::Details::Registry::m_initialized
bool m_initialized
Flag recording if the registry has been initialized or not.
Definition: PluginServiceDetails.h:196

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

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

Definition at line 186 of file PluginServiceDetails.h.

186 {
187 if (!m_initialized) initialize();
188 return m_factories;
189 }
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:153
Gaudi::PluginService::Details::Registry::m_factories
FactoryMap m_factories
Internal storage for factories.
Definition: PluginServiceDetails.h:199
Gaudi::PluginService::Details::Registry::m_initialized
bool m_initialized
Flag recording if the registry has been initialized or not.
Definition: PluginServiceDetails.h:196

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 274 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 {
280 #ifdef GAUDI_REFLEX_COMPONENT_ALIASES
281 const Properties& props = f->second.properties;
282 if (props.find("ReflexName") != props.end())
283 logger().warning("requesting factory via old name '" + id + "'"
284 "use '" + 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 +
289 " for factory " + id);
290 char *dlmsg = dlerror();
291 if (dlmsg) logger().warning(dlmsg);
292 return nullptr;
293 }
294 f = facts.find(id); // ensure that the iterator is valid
295 }
296 if (f->second.type == type) return f->second.ptr;
297 logger().warning("found factory " + id + ", but of wrong type: " +
298 demangle(f->second.type) + " instead of " + demangle(type));
299 }
300 return nullptr; // factory not found
301 }
REG_SCOPE_LOCK
#define REG_SCOPE_LOCK
Definition: PluginService.cpp:38
std::vector::end
T end(T...args)
Gaudi::PluginService::Details::logger
GAUDIPS_API Logger & logger()
Return the current logger instance.
Definition: PluginService.cpp:344
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:141
Gaudi::PluginService::Details::Registry::factories
const FactoryMap & factories() const
Return the known factories (loading the list if not yet done).
Definition: PluginServiceDetails.h:163
Gaudi::PluginService::Details::Logger::warning
void warning(const std::string &msg)
Definition: PluginServiceDetails.h:217
std::vector< Gaudi::Details::PropertyBase * >
Gaudi::PluginService::Details::Registry::FactoryMap
std::map< KeyType, FactoryInfo > FactoryMap
Type used for the database implementation.
Definition: PluginServiceDetails.h:130

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

Retrieve the FactoryInfo object for an id.

Definition at line 303 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:38
Gaudi::PluginService::Details::Registry::factories
const FactoryMap & factories() const
Return the known factories (loading the list if not yet done).
Definition: PluginServiceDetails.h:163
Gaudi::PluginService::Details::Registry::FactoryMap
std::map< KeyType, FactoryInfo > FactoryMap
Type used for the database implementation.
Definition: PluginServiceDetails.h:130

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

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

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

Retrieve the singleton instance of Registry.

Definition at line 145 of file PluginService.cpp.

145 {
146 SINGLETON_LOCK
147 static Registry r;
148 return r;
149 }
Gaudi::PluginService::Details::Registry::Registry
Registry()
Private constructor for the singleton pattern.
Definition: PluginService.cpp:151
SINGLETON_LOCK
#define SINGLETON_LOCK
Definition: PluginService.cpp:39

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

Return a list of all the known and loaded factories.

Definition at line 322 of file PluginService.cpp.

322 {
323 REG_SCOPE_LOCK
324 const FactoryMap &facts = factories();
325 std::set<KeyType> l;
326 for (const auto& f : facts )
327 {
328 if (f.second.ptr) l.insert(f.first);
329 }
330 return l;
331 }
REG_SCOPE_LOCK
#define REG_SCOPE_LOCK
Definition: PluginService.cpp:38
Gaudi::PluginService::Details::Registry::factories
const FactoryMap & factories() const
Return the known factories (loading the list if not yet done).
Definition: PluginServiceDetails.h:163
gaudirun.l
dictionary l
Definition: gaudirun.py:421
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:130

## Member Data Documentation

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

Internal storage for factories.

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

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

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