ATLAS Offline Software
Loading...
Searching...
No Matches
ClassIDSvc.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef CLIDCOMPS_CLASSIDSVC_H
6# define CLIDCOMPS_CLASSIDSVC_H
12
13#include <unordered_map>
14#include <mutex>
15#include <set>
16#include <string>
17#include <vector>
18#include <utility> // for std::pair
19
20#include "GaudiKernel/IIncidentListener.h"
21#include "GaudiKernel/IClassIDSvc.h"
22#include "GaudiKernel/Service.h"
23#include "GaudiKernel/DirSearchPath.h"
24
26
27
36
37class ClassIDSvc : public extends<Service, IClassIDSvc, IIncidentListener>
38{
39private:
40 typedef std::pair<std::string, std::string> TypeName; //typename+typeinfoname
41 typedef std::unordered_map<CLID, TypeName> CLIDMap;
42 typedef std::unordered_map<std::string, CLID> NameMap;
43
44public:
45 // Locking convention: public methods (except for gaudi state-change methods)
46 // take the lock. Protected/private methods do not take the lock.
47 // Public methods do not call each other.
48
49 //========================================================================
51
54 virtual CLID nextAvailableID() const override;
56 virtual bool isIDInUse(const CLID& id) const override;
58 virtual bool isNameInUse(const std::string& name) const override;
60 virtual StatusCode getTypeNameOfID(const CLID& id, std::string& typeName) const override;
62 virtual StatusCode getTypeInfoNameOfID(const CLID& id, std::string& typeInfoName) const override;
64 virtual StatusCode getIDOfTypeName(const std::string& typeName, CLID& id) const override;
66 virtual StatusCode getIDOfTypeInfoName(const std::string& typeInfoName, CLID& id) const override;
68 virtual StatusCode setTypeForID(const CLID& id,
69 const std::string& typeName,
70 const std::string& typeInfoName = "") override;
71
72 //========================================================================
74
76 void dump() const;
77
78
79 //========================================================================
81
83
84 virtual StatusCode initialize() override;
85 virtual StatusCode reinitialize() override;
87 virtual StatusCode finalize() override;
89
91 void handle(const Incident &inc) override;
92
93 // Standard Constructor
94 ClassIDSvc(const std::string& name, ISvcLocator* svc);
95
96private:
98 std::vector<CLID> sortedIDs() const;
99
101 StatusCode fillDB();
103 bool processCLIDDB(const std::string& fileName);
105 bool getRegistryEntries(const std::string& moduleName);
106
108 StatusCode
110 const std::string& typeName,
111 const std::string& typeInfoName);
112
114 bool maybeRescan() const;
115
117
118 Gaudi::Property<std::vector<std::string>> m_DBFiles{this, "CLIDDBFiles", {"clid.db"},
119 "List of db files with (CLID, class_name) entries. Loaded at init in svc maps. Files are looked up in DATAPATH",
120 "OrderedSet<std::string>"};
121
122 Gaudi::Property<std::string> m_outputFileName{this, "OutputFileName", "NULL",
123 "Path to clid.db file for writing. By default ('NULL') to not create the file."};
124
125 Gaudi::Property<std::set<CLID>> m_clidIgnore{this, "IgnoreCLIDs", {},
126 "Set of CLIDs to ignore. Can also be set via the ATLAS_CLID_IGNORE environment variable (comma-separated). "
127 "Useful for testing the removal of EDM classes in a local build."};
128
132
134 DirSearchPath m_clidDBPath;
135
136 // Mutex to protect internal structures.
137 typedef std::mutex mutex_t;
138 typedef std::lock_guard<mutex_t> lock_t;
140};
141
142
143#endif // CLIDCOMPS_CLASSIDSVC_H
a static registry of CLID->typeName entries.
uint32_t CLID
The Class ID type.
virtual StatusCode initialize() override
Gaudi Service Implementation.
StatusCode fillDB()
get clids from CLIDDB and from registry entries
NameMap m_tiNameMap
Definition ClassIDSvc.h:131
Gaudi::Property< std::vector< std::string > > m_DBFiles
Definition ClassIDSvc.h:118
bool processCLIDDB(const std::string &fileName)
load clid/names from a "db" file
virtual StatusCode reinitialize() override
CLIDMap m_clidMap
Definition ClassIDSvc.h:129
void handle(const Incident &inc) override
implement IIncidentListener
Gaudi::Property< std::string > m_outputFileName
Definition ClassIDSvc.h:122
virtual CLID nextAvailableID() const override
get next available CLID
void dump() const
dump to MsgStream contents of in memory DB
StatusCode uncheckedSetTypePackageForID(const CLID &id, const std::string &typeName, const std::string &typeInfoName)
associate type name with clID w/o checking CLID range
virtual StatusCode getIDOfTypeInfoName(const std::string &typeInfoName, CLID &id) const override
get id associated with type-info name (if any)
bool getRegistryEntries(const std::string &moduleName)
load clid/names from a DLL registry
std::vector< CLID > sortedIDs() const
Return all registered IDs in sorted order.
virtual bool isNameInUse(const std::string &name) const override
check if id is used
virtual StatusCode finalize() override
dump CLIDmap to outputFileName;
std::pair< std::string, std::string > TypeName
Definition ClassIDSvc.h:40
virtual StatusCode getTypeNameOfID(const CLID &id, std::string &typeName) const override
get type name associated with clID (if any)
virtual StatusCode getTypeInfoNameOfID(const CLID &id, std::string &typeInfoName) const override
get user assigned type-info name associated with clID
virtual bool isIDInUse(const CLID &id) const override
check if id is used
DirSearchPath m_clidDBPath
The path is which clid db files are to be searched (DATAPATH).
Definition ClassIDSvc.h:134
Gaudi::Property< std::set< CLID > > m_clidIgnore
Definition ClassIDSvc.h:125
bool maybeRescan() const
Test to see if anything new has been added to the registry.
virtual StatusCode getIDOfTypeName(const std::string &typeName, CLID &id) const override
get id associated with type name (if any)
std::lock_guard< mutex_t > lock_t
Definition ClassIDSvc.h:138
ClassIDSvc(const std::string &name, ISvcLocator *svc)
Standard Constructor.
std::unordered_map< CLID, TypeName > CLIDMap
Definition ClassIDSvc.h:41
mutex_t m_mutex
Definition ClassIDSvc.h:139
NameMap m_nameMap
Definition ClassIDSvc.h:130
std::unordered_map< std::string, CLID > NameMap
Definition ClassIDSvc.h:42
std::mutex mutex_t
Definition ClassIDSvc.h:137
virtual StatusCode setTypeForID(const CLID &id, const std::string &typeName, const std::string &typeInfoName="") override
associate type name, package info and type-info name with clID