13#include "GaudiKernel/IIncidentSvc.h"
14#include "GaudiKernel/Incident.h"
15#include "GaudiKernel/ModuleIncident.h"
16#include "GaudiKernel/System.h"
17#include "GaudiKernel/MsgStream.h"
18#include "GaudiKernel/ServiceHandle.h"
26 bool tryNumeric (
const std::string& s,
CLID& clid)
29 char* endptr =
nullptr;
30 clid = strtol (
s.c_str(), &endptr, 10);
31 return clid != CLID_NULL && endptr == (
s.c_str() +
s.size());
37#define ATH_MSG_CLOSE )
38#define ATH_MSG_LVL(lvl, x, ...) \
40 if (msgLevel(lvl)) { \
41 msgStream(lvl) << __VA_OPT__(std::format ATH_MSG_OPEN ) x __VA_OPT__ (, __VA_ARGS__ ATH_MSG_CLOSE) << endmsg; \
45#define ATH_MSG_VERBOSE(x, ...) ATH_MSG_LVL(MSG::VERBOSE, x __VA_OPT__(, __VA_ARGS__))
46#define ATH_MSG_DEBUG(x, ...) ATH_MSG_LVL(MSG::DEBUG, x __VA_OPT__(, __VA_ARGS__))
47#define ATH_MSG_INFO(x, ...) ATH_MSG_LVL(MSG::INFO, x __VA_OPT__(, __VA_ARGS__))
48#define ATH_MSG_WARNING(x, ...) ATH_MSG_LVL(MSG::WARNING, x __VA_OPT__(, __VA_ARGS__))
49#define ATH_MSG_ERROR(x, ...) ATH_MSG_LVL(MSG::ERROR, x __VA_OPT__(, __VA_ARGS__))
51#define ATH_CONST_MSG_VERBOSE(x, ...) \
53 if (msgLevel(MSG::VERBOSE)) { \
54 verbose() << __VA_OPT__(std::format ATH_MSG_OPEN ) x __VA_OPT__ (, __VA_ARGS__ ATH_MSG_CLOSE) << endmsg; \
75 throw std::runtime_error(
"ClassIDSvc::nextAvailableID: none in range");
105 CLIDMap::const_iterator iID =
m_clidMap.find(
id);
107 typeName = iID->second.first;
109 return StatusCode::SUCCESS;
113 return StatusCode::FAILURE;
125 CLIDMap::const_iterator iID =
m_clidMap.find(
id);
127 typeInfoName = iID->second.second;
130 return StatusCode::SUCCESS;
134 return StatusCode::FAILURE;
146 NameMap::const_iterator iID =
m_nameMap.find(typeName);
150 return StatusCode::SUCCESS;
152 else if (tryNumeric (typeName,
id)) {
154 return StatusCode::SUCCESS;
158 return StatusCode::FAILURE;
170 NameMap::const_iterator iID =
m_tiNameMap.find(typeInfoName);
174 return StatusCode::SUCCESS;
178 return StatusCode::FAILURE;
186 const std::string& typeName,
187 const std::string& typeInfoName)
191 ATH_MSG_ERROR(
"setTypeNameForID: input id {} is out of allowed range {} : {}",
193 return StatusCode::FAILURE;
208 ATH_MSG_INFO(
"CLID: {} - type name: NOT FOUND", clid );
211 ATH_MSG_INFO(
"CLID: {} - type name: ", clid, it->second.first );
221 using namespace std::string_view_literals;
225 CHECK( Service::initialize() );
228 if (
const char* clid_ignore = std::getenv(
"ATLAS_CLID_IGNORE")) {
234 CHECK( pIncSvc.retrieve() );
236 pIncSvc->addListener(
this, ModuleLoadedIncident::TYPE(), 100);
241 return StatusCode::SUCCESS;
249 return StatusCode::SUCCESS;
260 return StatusCode::RECOVERABLE;
263 const std::string& typeName =
m_clidMap[clid].first;
264 const std::string& tiName =
m_clidMap[clid].second;
265 std::println (outfile,
"{}; {}; {}", clid, typeName, tiName);
267 ATH_MSG_INFO(
"finalize: wrote {} entries to output CLIDDB file: {}",
271 return Service::finalize();
278 const ModuleLoadedIncident& modInc(
dynamic_cast<const ModuleLoadedIncident&
>(inc));
286 : base_class(name,svc),
295 std::vector<CLID> ids;
298 ids.push_back (p.first);
309 for (
const std::string& DBFile :
m_DBFiles) {
310 DirSearchPath::path clidDB(DBFile);
312 if (clidDB.is_absolute()) {
315 std::list<DirSearchPath::path> paths(
m_clidDBPath.find_all(clidDB));
318 <<
" using DATAPATH. Skipping it." );
320 for (
const auto& p : paths) {
326 return StatusCode(allOK);
333 std::ifstream ifile(fileName);
340 unsigned int newEntries(0);
343 while (allOK && std::getline(ifile, line)) {
346 if (columns.size()>=2) {
349 id = std::stol(columns[0]);
350 }
catch (
const std::logic_error& e) {
351 ATH_MSG_ERROR(
"processCLIDDB: Can't cast [{}] to long (clid): {}",
352 columns[0], e.what() );
357 columns.size()>2 ? columns[2] :
"")) {
364 ATH_MSG_ERROR(
"processCLIDDB: processing record '{}' from CLIDDB file: {}",
367 ATH_MSG_DEBUG(
"processCLIDDB: read {} entries from CLIDDB file: {}",
368 newEntries, fileName );
381 size_t newEntries(0);
385 ATH_MSG_VERBOSE(
"reading [{}, {}, {}]", clid, typeName, typeInfoName);
395 ATH_MSG_INFO(
"getRegistryEntries: read {} CLIDRegistry entries for module {}",
396 newEntries, moduleName );
398 ATH_MSG_ERROR(
"getRegistryEntries: can not read CLIDRegistry entries for module {}",
408 const std::string& typeName,
409 const std::string& typeInfoName)
412 std::string procName(typeName);
415 if (procName.empty()) {
417 return StatusCode::FAILURE;
422 return StatusCode::SUCCESS;
426 std::string procTiName;
427 if (typeInfoName.empty()) {
428 procTiName = procName;
431 procTiName = typeInfoName;
436 const auto& [clid_it, clid_success] =
m_clidMap.try_emplace(
id, procName, procTiName);
437 if (!clid_success && clid_it->second!=std::make_pair(procName,procTiName)) {
438 ATH_MSG_ERROR(
"Cannot set type {} for CLID {}: known type for this ID {}",
439 std::make_pair(procName,procTiName),
id, clid_it->second);
440 return StatusCode::FAILURE;
444 const auto& [name_it, name_success] =
m_nameMap.try_emplace(procName,
id);
445 if (!name_success && name_it->second!=
id) {
446 ATH_MSG_ERROR(
"Cannot set CLID {} for type name '{}': known CLID for this name {}",
447 id, procName, name_it->second);
448 return StatusCode::FAILURE;
452 const auto& [info_it, info_success] =
m_tiNameMap.try_emplace(procTiName,
id);
453 if (!info_success && info_it->second!=
id) {
454 ATH_MSG_ERROR(
"Cannot set CLID {} for type-info name '{}' and type '{}': known CLID for this type-info name {}",
455 id, procTiName, procName, info_it->second);
456 return StatusCode::FAILURE;
459 ATH_MSG_VERBOSE(
"Set type name '{}' for CLID {} with type-info name '{}'",
460 procName,
id, procTiName);
462 return StatusCode::SUCCESS;
475 bool status = nc->getRegistryEntries (
"ALL");
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_VERBOSE(x,...)
#define ATH_MSG_INFO(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).
Gaudi::Property< std::set< CLID > > m_clidIgnore
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< int > tokenizeInt(std::string_view str, std::string_view delimiter)
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.