ATLAS Offline Software
ClassIDSvc.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef CLIDCOMPS_CLASSIDSVC_H
6 # define CLIDCOMPS_CLASSIDSVC_H
7 
13 #include <unordered_map>
14 #include <mutex>
15 #include <string>
16 #include <vector>
17 #include <utility> // for std::pair
18 
19 #include "GaudiKernel/IIncidentListener.h"
20 #include "GaudiKernel/IClassIDSvc.h"
21 #include "GaudiKernel/Service.h"
22 #include "GaudiKernel/DirSearchPath.h"
23 
25 
26 
36 class ClassIDSvc : public extends<Service, IClassIDSvc, IIncidentListener>
37 {
38 private:
39  typedef std::pair<std::string, std::string> TypeName; //typename+typeinfoname
40  typedef std::unordered_map<CLID, TypeName> CLIDMap;
41  typedef std::unordered_map<std::string, CLID> NameMap;
42 
43 public:
44  // Locking convention: public methods (except for gaudi state-change methods)
45  // take the lock. Protected/private methods do not take the lock.
46  // Public methods do not call each other.
47 
48  //========================================================================
51  virtual CLID nextAvailableID() const override;
55  virtual bool isIDInUse(const CLID& id) const override;
57  virtual bool isNameInUse(const std::string& name) const override;
59  virtual StatusCode getTypeNameOfID(const CLID& id, std::string& typeName) const override;
61  virtual StatusCode getTypeInfoNameOfID(const CLID& id, std::string& typeInfoName) const override;
63  virtual StatusCode getIDOfTypeName(const std::string& typeName, CLID& id) const override;
65  virtual StatusCode getIDOfTypeInfoName(const std::string& typeInfoName, CLID& id) const override;
67  virtual StatusCode setTypeForID(const CLID& id,
68  const std::string& typeName,
69  const std::string& typeInfoName = "") override;
70 
71  //========================================================================
74  void dump() const;
76 
77 
78  //========================================================================
81 
83  virtual StatusCode initialize() override;
84  virtual StatusCode reinitialize() override;
86  virtual StatusCode finalize() override;
88 
90  void handle(const Incident &inc) override;
91 
92  // Standard Constructor
93  ClassIDSvc(const std::string& name, ISvcLocator* svc);
94 
95 private:
97  std::vector<CLID> sortedIDs() const;
98 
100  StatusCode fillDB();
102  bool processCLIDDB(const std::string& fileName);
104  bool getRegistryEntries(const std::string& moduleName);
105 
107  StatusCode
109  const std::string& typeName,
110  const std::string& typeInfoName);
111 
113  bool maybeRescan() const;
114 
116 
117  Gaudi::Property<std::vector<std::string>> m_DBFiles{this, "CLIDDBFiles", {"clid.db"},
118  "List of db files with (CLID, class_name) entries. Loaded at init in svc maps. Files are looked up in DATAPATH",
119  "OrderedSet<std::string>"};
120 
121  Gaudi::Property<std::string> m_outputFileName{this, "OutputFileName", "NULL",
122  "Path to clid.db file for writing. By default ('NULL') to not create the file."};
127 
129  DirSearchPath m_clidDBPath;
130 
131  // Mutex to protect internal structures.
133  typedef std::lock_guard<mutex_t> lock_t;
134  mutable mutex_t m_mutex;
135 };
136 
137 
138 #endif // CLIDCOMPS_CLASSIDSVC_H
ClassIDSvc::CLIDMap
std::unordered_map< CLID, TypeName > CLIDMap
Definition: ClassIDSvc.h:40
ClassIDSvc::getTypeInfoNameOfID
virtual StatusCode getTypeInfoNameOfID(const CLID &id, std::string &typeInfoName) const override
get user assigned type-info name associated with clID
Definition: ClassIDSvc.cxx:116
ClassIDSvc::m_nameMap
NameMap m_nameMap
Definition: ClassIDSvc.h:125
BeamSpot::mutex
std::mutex mutex
Definition: InDetBeamSpotVertex.cxx:18
ClassIDSvc::isIDInUse
virtual bool isIDInUse(const CLID &id) const override
check if id is used
Definition: ClassIDSvc.cxx:79
ClassIDSvc::NameMap
std::unordered_map< std::string, CLID > NameMap
Definition: ClassIDSvc.h:41
ClassIDSvc::m_mutex
mutex_t m_mutex
Definition: ClassIDSvc.h:134
ClassIDSvc::fillDB
StatusCode fillDB()
get clids from CLIDDB and from registry entries
Definition: ClassIDSvc.cxx:293
ClassIDSvc::dump
void dump() const
dump to MsgStream contents of in memory DB
Definition: ClassIDSvc.cxx:198
ClassIDSvc::m_tiNameMap
NameMap m_tiNameMap
Definition: ClassIDSvc.h:126
ClassIDSvc::handle
void handle(const Incident &inc) override
implement IIncidentListener
Definition: ClassIDSvc.cxx:261
ClassIDSvc::finalize
virtual StatusCode finalize() override
dump CLIDmap to outputFileName;
Definition: ClassIDSvc.cxx:240
ClassIDSvc::m_clidDBPath
DirSearchPath m_clidDBPath
The path is which clid db files are to be searched (DATAPATH)
Definition: ClassIDSvc.h:129
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
ClassIDSvc::getTypeNameOfID
virtual StatusCode getTypeNameOfID(const CLID &id, std::string &typeName) const override
get type name associated with clID (if any)
Definition: ClassIDSvc.cxx:96
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ClassIDSvc::initialize
virtual StatusCode initialize() override
Gaudi Service Implementation.
Definition: ClassIDSvc.cxx:212
ClassIDSvc::setTypeForID
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
Definition: ClassIDSvc.cxx:182
ClassIDSvc::isNameInUse
virtual bool isNameInUse(const std::string &name) const override
check if id is used
Definition: ClassIDSvc.cxx:87
Handler::svc
AthROOTErrorHandlerSvc * svc
Definition: AthROOTErrorHandlerSvc.cxx:10
ClassIDSvc::getRegistryEntries
bool getRegistryEntries(const std::string &moduleName)
load clid/names from a DLL registry
Definition: ClassIDSvc.cxx:361
ClassIDSvc::processCLIDDB
bool processCLIDDB(const std::string &fileName)
load clid/names from a "db" file
Definition: ClassIDSvc.cxx:317
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
ClassIDSvc::mutex_t
std::mutex mutex_t
Definition: ClassIDSvc.h:132
ClassIDSvc::reinitialize
virtual StatusCode reinitialize() override
Definition: ClassIDSvc.cxx:232
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
ClassIDSvc::ClassIDSvc
ClassIDSvc(const std::string &name, ISvcLocator *svc)
Standard Constructor.
Definition: ClassIDSvc.cxx:271
ClassIDSvc::sortedIDs
std::vector< CLID > sortedIDs() const
Return all registered IDs in sorted order.
Definition: ClassIDSvc.cxx:279
ClassIDSvc::maybeRescan
bool maybeRescan() const
Test to see if anything new has been added to the registry.
Definition: ClassIDSvc.cxx:448
ClassIDSvc::m_clidMap
CLIDMap m_clidMap
Definition: ClassIDSvc.h:124
CLIDRegistry.h
a static registry of CLID->typeName entries. NOT for general use. Use ClassIDSvc instead.
ClassIDSvc::uncheckedSetTypePackageForID
StatusCode uncheckedSetTypePackageForID(const CLID &id, const std::string &typeName, const std::string &typeInfoName)
associate type name with clID w/o checking CLID range
Definition: ClassIDSvc.cxx:393
ClassIDSvc::m_outputFileName
Gaudi::Property< std::string > m_outputFileName
Definition: ClassIDSvc.h:121
ReadCalibFromCool.typeName
typeName
Definition: ReadCalibFromCool.py:477
ClassIDSvc
a service to manage and verify CLID assignments in athena.
Definition: ClassIDSvc.h:37
ClassIDSvc::nextAvailableID
virtual CLID nextAvailableID() const override
get next available CLID
Definition: ClassIDSvc.cxx:60
ClassIDSvc::getIDOfTypeName
virtual StatusCode getIDOfTypeName(const std::string &typeName, CLID &id) const override
get id associated with type name (if any)
Definition: ClassIDSvc.cxx:138
ClassIDSvc::lock_t
std::lock_guard< mutex_t > lock_t
Definition: ClassIDSvc.h:133
ClassIDSvc::m_DBFiles
Gaudi::Property< std::vector< std::string > > m_DBFiles
Definition: ClassIDSvc.h:117
ClassIDSvc::TypeName
std::pair< std::string, std::string > TypeName
Definition: ClassIDSvc.h:39
ClassIDSvc::getIDOfTypeInfoName
virtual StatusCode getIDOfTypeInfoName(const std::string &typeInfoName, CLID &id) const override
get id associated with type-info name (if any)
Definition: ClassIDSvc.cxx:162