10#include "GaudiKernel/IIncidentSvc.h"
11#include "GaudiKernel/Incident.h"
12#include "GaudiKernel/ModuleIncident.h"
13#include "GaudiKernel/System.h"
14#include "GaudiKernel/MsgStream.h"
15#include "GaudiKernel/ServiceHandle.h"
23 bool tryNumeric (
const std::string& s,
CLID& clid)
26 char* endptr =
nullptr;
27 clid = strtol (
s.c_str(), &endptr, 10);
28 return clid != CLID_NULL && endptr == (
s.c_str() +
s.size());
33#define ATH_MSG_LVL(lvl, x) \
35 if (msgLevel(lvl)) { \
36 msgStream(lvl) << x << endmsg; \
40#define ATH_MSG_VERBOSE(x) ATH_MSG_LVL(MSG::VERBOSE, x)
41#define ATH_MSG_DEBUG(x) ATH_MSG_LVL(MSG::DEBUG, x)
42#define ATH_MSG_INFO(x) ATH_MSG_LVL(MSG::INFO, x)
43#define ATH_MSG_WARNING(x) ATH_MSG_LVL(MSG::WARNING, x)
44#define ATH_MSG_ERROR(x) ATH_MSG_LVL(MSG::ERROR, x)
46#define ATH_CONST_MSG_VERBOSE(x) \
48 if (msgLevel(MSG::VERBOSE)) { \
49 verbose() << x << endmsg; \
70 throw std::runtime_error(
"ClassIDSvc::nextAvailableID: none in range");
100 CLIDMap::const_iterator iID =
m_clidMap.find(
id);
102 typeName = iID->second.first;
104 return StatusCode::SUCCESS;
108 return StatusCode::FAILURE;
120 CLIDMap::const_iterator iID =
m_clidMap.find(
id);
122 typeInfoName = iID->second.second;
124 ") type-info name is " << typeInfoName );
125 return StatusCode::SUCCESS;
129 ") no associated type-info name found" );
130 return StatusCode::FAILURE;
142 NameMap::const_iterator iID =
m_nameMap.find(typeName);
146 return StatusCode::SUCCESS;
148 else if (tryNumeric (typeName,
id)) {
150 return StatusCode::SUCCESS;
154 return StatusCode::FAILURE;
166 NameMap::const_iterator iID =
m_tiNameMap.find(typeInfoName);
170 return StatusCode::SUCCESS;
174 return StatusCode::FAILURE;
182 const std::string& typeName,
183 const std::string& typeInfoName)
190 return StatusCode::FAILURE;
205 ATH_MSG_INFO(
"CLID: "<< clid <<
" - type name: NOT FOUND" );
208 ATH_MSG_INFO(
"CLID: "<< clid <<
" - type name: " << it->second.first );
220 CHECK( Service::initialize() );
224 CHECK( pIncSvc.retrieve() );
226 pIncSvc->addListener(
this, ModuleLoadedIncident::TYPE(), 100);
231 return StatusCode::SUCCESS;
239 return StatusCode::SUCCESS;
250 return StatusCode::RECOVERABLE;
253 const std::string& typeName =
m_clidMap[clid].first;
254 const std::string& tiName =
m_clidMap[clid].second;
255 outfile << clid <<
"; " << typeName <<
"; " << tiName << std::endl;
261 return Service::finalize();
268 const ModuleLoadedIncident& modInc(
dynamic_cast<const ModuleLoadedIncident&
>(inc));
276 : base_class(name,svc),
285 std::vector<CLID> ids;
288 ids.push_back (p.first);
299 for (
const std::string& DBFile :
m_DBFiles) {
300 DirSearchPath::path clidDB(DBFile);
302 if (clidDB.is_absolute()) {
305 std::list<DirSearchPath::path> paths(
m_clidDBPath.find_all(clidDB));
308 <<
" using DATAPATH. Skipping it." );
310 for (
const auto& p : paths) {
316 return StatusCode(allOK);
323 std::ifstream ifile(fileName);
330 unsigned int newEntries(0);
333 while (allOK && std::getline(ifile, line)) {
336 if (columns.size()>=2) {
339 id = std::stol(columns[0]);
340 }
catch (
const std::logic_error& e) {
341 ATH_MSG_ERROR(
"processCLIDDB: Can't cast ["<< columns[0] <<
"] to long (clid): " << e.what() );
346 columns.size()>2 ? columns[2] :
"")) {
354 <<
"' from CLIDDB file: " << fileName );
357 " entries from CLIDDB file: " << fileName );
370 size_t newEntries(0);
374 ATH_MSG_VERBOSE(
"reading [" << clid <<
", " << typeName <<
", " << typeInfoName <<
"]" );
385 <<
" CLIDRegistry entries for module " << moduleName );
387 ATH_MSG_ERROR(
"getRegistryEntries: can not read CLIDRegistry entries for module "
397 const std::string& typeName,
398 const std::string& typeInfoName)
401 std::string procName(typeName);
404 if (procName.empty()) {
406 return StatusCode::FAILURE;
410 std::string procTiName;
411 if (typeInfoName.empty()) {
412 procTiName = procName;
415 procTiName = typeInfoName;
420 const auto& [clid_it, clid_success] =
m_clidMap.try_emplace(
id, procName, procTiName);
421 if (!clid_success && clid_it->second!=std::make_pair(procName,procTiName)) {
422 ATH_MSG_ERROR(
"Cannot set type " << std::make_pair(procName,procTiName) <<
" for CLID " <<
423 id <<
": known type for this ID " << clid_it->second );
424 return StatusCode::FAILURE;
428 const auto& [name_it, name_success] =
m_nameMap.try_emplace(procName,
id);
429 if (!name_success && name_it->second!=
id) {
430 ATH_MSG_ERROR(
"Cannot set CLID " <<
id <<
" for type name '"
431 << procName <<
"': known CLID for this name " << name_it->second );
432 return StatusCode::FAILURE;
436 const auto& [info_it, info_success] =
m_tiNameMap.try_emplace(procTiName,
id);
437 if (!info_success && info_it->second!=
id) {
438 ATH_MSG_ERROR(
"Cannot set CLID " <<
id <<
" for type-info name '"
439 << procTiName <<
"' and type '" << procName
440 <<
"': known CLID for this type-info name " << info_it->second );
441 return StatusCode::FAILURE;
444 ATH_MSG_VERBOSE(
"Set type name '" << procName <<
"' for CLID " <<
id <<
445 " with type-info name '" << procTiName <<
"'" );
447 return StatusCode::SUCCESS;
460 bool status = nc->getRegistryEntries (
"ALL");
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
a static registry of CLID->typeName entries.
#define ATH_CONST_MSG_VERBOSE(x)
a service to manage and verify CLID assignments in athena
Helpers for checking error return status codes and reporting errors.
#define CHECK(...)
Evaluate an expression and check for errors.
uint32_t CLID
The Class ID type.
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
Define macros for attributes used to control the static checker.
#define ATLAS_THREAD_SAFE
static bool hasNewEntries()
registry accessors (used by ClassIDSvc)
static CLIDVector_t newEntries()
returns an iterator range over the entries added since last time newEntries was called
virtual StatusCode initialize() override
Gaudi Service Implementation.
StatusCode fillDB()
get clids from CLIDDB and from registry entries
Gaudi::Property< std::vector< std::string > > m_DBFiles
bool processCLIDDB(const std::string &fileName)
load clid/names from a "db" file
virtual StatusCode reinitialize() override
void handle(const Incident &inc) override
implement IIncidentListener
Gaudi::Property< std::string > m_outputFileName
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;
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).
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
ClassIDSvc(const std::string &name, ISvcLocator *svc)
Standard Constructor.
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
const unsigned long MINCLID
const unsigned long MAXCLID
2**31 - 1
std::string_view trimWhiteSpaces(std::string_view str) noexcept
Removes all trailing and starting whitespaces from a string.
std::vector< std::string > tokenize(std::string_view the_str, std::string_view delimiters)
Splits the string into smaller substrings.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.