| The Gaudi Framework v27r1

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

144 : 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
ReadAndWriteWhiteBoard.dst
tuple dst
Definition: ReadAndWriteWhiteBoard.py:17
std::ostringstream
STL class.
std::ostringstream::str
T str(T...args)
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 238 of file PluginService.cpp.

241 {
242 REG_SCOPE_LOCK
243 FactoryMap &facts = factories();
244 auto entry = facts.find(id);
245 if (entry == facts.end())
246 {
247 // this factory was not known yet
248 entry = facts.emplace( id, FactoryInfo("unknown", factory,
249 type, rtype, className, props) ).first;
250 } else {
251 // do not replace an existing factory with a new one
252 if (!entry->second.ptr) entry->second.ptr = factory;
253 factoryInfoSetHelper(entry->second.type, type, "type", id);
254 factoryInfoSetHelper(entry->second.rtype, rtype, "return type", id);
255 factoryInfoSetHelper(entry->second.className, className, "class", id);
256 }
257 #ifdef GAUDI_REFLEX_COMPONENT_ALIASES
258 // add an alias for the factory using the Reflex convention
259 std::string old_name = old_style_name(id);
260 if (id != old_name)
261 add(old_name, factory, type, rtype, className, props)
262 .properties["ReflexName"] = "true";
263 #endif
264 return entry->second;
265 }
REG_SCOPE_LOCK
#define REG_SCOPE_LOCK
Definition: PluginService.cpp:37
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 305 of file PluginService.cpp.

307 {
308 REG_SCOPE_LOCK
309 FactoryMap &facts = factories();
310 auto f = facts.find(id);
311 if (f != facts.end()) f->second.properties[k] = v;
312 return *this;
313 }
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: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:144
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:146
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:146
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 267 of file PluginService.cpp.

267 {
268 REG_SCOPE_LOCK
269 const FactoryMap &facts = factories();
270 auto f = facts.find(id);
271 if (f != facts.end())
272 {
273 #ifdef GAUDI_REFLEX_COMPONENT_ALIASES
274 const Properties& props = f->second.properties;
275 if (props.find("ReflexName") != props.end())
276 logger().warning("requesting factory via old name '" + id + "'"
277 "use '" + f->second.className + "' instead");
278 #endif
279 if (!f->second.ptr) {
280 if (!dlopen(f->second.library.c_str(), RTLD_LAZY | RTLD_GLOBAL)) {
281 logger().warning("cannot load " + f->second.library +
282 " for factory " + id);
283 char *dlmsg = dlerror();
284 if (dlmsg) logger().warning(dlmsg);
285 return nullptr;
286 }
287 f = facts.find(id); // ensure that the iterator is valid
288 }
289 if (f->second.type == type) return f->second.ptr;
290 logger().warning("found factory " + id + ", but of wrong type: " +
291 demangle(f->second.type) + " instead of " + demangle(type));
292 }
293 return nullptr; // factory not found
294 }
REG_SCOPE_LOCK
#define REG_SCOPE_LOCK
Definition: PluginService.cpp:37
Gaudi::PluginService::Details::logger
GAUDIPS_API Logger & logger()
Return the current logger instance.
Definition: PluginService.cpp:337
Gaudi::PluginService::Details::Registry::Properties
std::map< KeyType, std::string > Properties
Type used for the properties implementation.
Definition: PluginServiceDetails.h:104
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:134
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
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 296 of file PluginService.cpp.

296 {
297 REG_SCOPE_LOCK
298 static const FactoryInfo unknown("unknown");
299 const FactoryMap &facts = factories();
300 auto f = facts.find(id);
301 return (f != facts.end()) ? f->second : unknown;
302 }
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: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 146 of file PluginService.cpp.

146 {
147 REG_SCOPE_LOCK
148 if (m_initialized) return;
149 m_initialized = true;
150 #ifdef WIN32
151 const char* envVar = "PATH";
152 const char sep = ';';
153 #else
154 const char* envVar = "LD_LIBRARY_PATH";
155 const char sep = ':';
156 #endif
157 char *search_path = ::getenv(envVar);
158 if (search_path) {
159 logger().debug(std::string("searching factories in ") + envVar);
160 std::string path(search_path);
161 std::string::size_type pos = 0;
162 std::string::size_type newpos = 0;
163 while (pos != std::string::npos) {
164 std::string dirName;
165 // get the next entry in the path
166 newpos = path.find(sep, pos);
167 if (newpos != std::string::npos) {
168 dirName = path.substr(pos, newpos - pos);
169 pos = newpos+1;
170 } else {
171 dirName = path.substr(pos);
172 pos = newpos;
173 }
174 logger().debug(std::string(" looking into ") + dirName);
175 // look for files called "*.components" in the directory
176 DIR *dir = opendir(dirName.c_str());
177 if (dir) {
178 struct dirent * entry;
179 while ((entry = readdir(dir))) {
180 std::string name(entry->d_name);
181 // check if the file name ends with ".components"
182 std::string::size_type extpos = name.find(".components");
183 if ((extpos != std::string::npos) &&
184 ((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 // look for the separator
204 auto pos = line.find(':');
205 if (pos == std::string::npos) {
206 logger().warning( "failed to parse line "
207 + fullPath + ':'
208 + std::to_string(lineCount) );
209 continue;
210 }
211 const std::string lib(line, 0, pos);
212 const std::string fact(line, pos+1);
213 m_factories.emplace(fact, FactoryInfo(lib));
214 #ifdef GAUDI_REFLEX_COMPONENT_ALIASES
215 // add an alias for the factory using the Reflex convention
216 std::string old_name = old_style_name(fact);
217 if (fact != old_name) {
218 FactoryInfo old_info(lib);
219 old_info.properties["ReflexName"] = "true";
220 m_factories.emplace(old_name, old_info);
221 }
222 #endif
223 ++factoriesCount;
224 }
225 if (logger().level() <= Logger::Debug) {
226 logger().debug( " found " + std::to_string( factoriesCount )
227 + " factories" );
228 }
229 }
230 }
231 closedir(dir);
232 }
233 }
234 }
235 }
std::string::empty
T empty(T...args)
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
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:337
std::string
STL class.
plotSpeedupsPyRoot.line
tuple line
Definition: plotSpeedupsPyRoot.py:164
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
Gaudi::Utils::Histos::path
GAUDI_API std::string path(const AIDA::IBaseHistogram *aida)
get the path in THS for AIDA histogram
Definition: HistoTableFormat.cpp:191
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)
std::string::substr
T substr(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.
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 138 of file PluginService.cpp.

138 {
139 SINGLETON_LOCK
140 static Registry r;
141 return r;
142 }
Gaudi::PluginService::Details::Registry::Registry
Registry()
Private constructor for the singleton pattern.
Definition: PluginService.cpp:144
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 315 of file PluginService.cpp.

315 {
316 REG_SCOPE_LOCK
317 const FactoryMap &facts = factories();
318 std::set<KeyType> l;
319 for (const auto& f : facts )
320 {
321 if (f.second.ptr) l.insert(f.first);
322 }
323 return l;
324 }
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: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