8#include <boost/algorithm/string/trim.hpp>
9#include <boost/algorithm/string/split.hpp>
11#include "GaudiKernel/IIncidentSvc.h"
12#include "GaudiKernel/Incident.h"
13#include "GaudiKernel/ModuleIncident.h"
14#include "GaudiKernel/System.h"
15#include "GaudiKernel/MsgStream.h"
16#include "GaudiKernel/ServiceHandle.h"
24 bool tryNumeric (
const std::string& s,
CLID& clid)
27 char* endptr =
nullptr;
28 clid = strtol (
s.c_str(), &endptr, 10);
29 return clid != CLID_NULL && endptr == (
s.c_str() +
s.size());
34#define ATH_MSG_LVL(lvl, x) \
36 if (msgLevel(lvl)) { \
37 msgStream(lvl) << x << endmsg; \
41#define ATH_MSG_VERBOSE(x) ATH_MSG_LVL(MSG::VERBOSE, x)
42#define ATH_MSG_DEBUG(x) ATH_MSG_LVL(MSG::DEBUG, x)
43#define ATH_MSG_INFO(x) ATH_MSG_LVL(MSG::INFO, x)
44#define ATH_MSG_WARNING(x) ATH_MSG_LVL(MSG::WARNING, x)
45#define ATH_MSG_ERROR(x) ATH_MSG_LVL(MSG::ERROR, x)
47#define ATH_CONST_MSG_VERBOSE(x) \
49 if (msgLevel(MSG::VERBOSE)) { \
50 verbose() << x << endmsg; \
71 throw std::runtime_error(
"ClassIDSvc::nextAvailableID: none in range");
101 CLIDMap::const_iterator iID =
m_clidMap.find(
id);
103 typeName = iID->second.first;
105 return StatusCode::SUCCESS;
109 return StatusCode::FAILURE;
121 CLIDMap::const_iterator iID =
m_clidMap.find(
id);
123 typeInfoName = iID->second.second;
125 ") type-info name is " << typeInfoName );
126 return StatusCode::SUCCESS;
130 ") no associated type-info name found" );
131 return StatusCode::FAILURE;
143 NameMap::const_iterator iID =
m_nameMap.find(typeName);
147 return StatusCode::SUCCESS;
149 else if (tryNumeric (typeName,
id)) {
151 return StatusCode::SUCCESS;
155 return StatusCode::FAILURE;
167 NameMap::const_iterator iID =
m_tiNameMap.find(typeInfoName);
171 return StatusCode::SUCCESS;
175 return StatusCode::FAILURE;
183 const std::string& typeName,
184 const std::string& typeInfoName)
191 return StatusCode::FAILURE;
206 ATH_MSG_INFO(
"CLID: "<< clid <<
" - type name: NOT FOUND" );
209 ATH_MSG_INFO(
"CLID: "<< clid <<
" - type name: " << it->second.first );
221 CHECK( Service::initialize() );
225 CHECK( pIncSvc.retrieve() );
227 pIncSvc->addListener(
this, ModuleLoadedIncident::TYPE(), 100);
232 return StatusCode::SUCCESS;
240 return StatusCode::SUCCESS;
251 return StatusCode::RECOVERABLE;
254 const std::string& typeName =
m_clidMap[clid].first;
255 const std::string& tiName =
m_clidMap[clid].second;
256 outfile << clid <<
"; " << typeName <<
"; " << tiName << std::endl;
262 return Service::finalize();
269 const ModuleLoadedIncident& modInc(
dynamic_cast<const ModuleLoadedIncident&
>(inc));
277 : base_class(name,svc),
286 std::vector<CLID> ids;
289 ids.push_back (p.first);
300 for (
const std::string& DBFile :
m_DBFiles) {
301 DirSearchPath::path clidDB(DBFile);
303 if (clidDB.is_absolute()) {
306 std::list<DirSearchPath::path> paths(
m_clidDBPath.find_all(clidDB));
309 <<
" using DATAPATH. Skipping it." );
311 for (
const auto& p : paths) {
317 return StatusCode(allOK);
324 std::ifstream ifile(fileName);
331 unsigned int newEntries(0);
334 while (allOK && std::getline(ifile, line)) {
335 std::vector<std::string> columns;
336 boost::split(columns, line, boost::is_any_of(
";"));
338 if (columns.size()>=2) {
339 boost::trim(columns[0]);
341 id = std::stol(columns[0]);
342 }
catch (
const std::logic_error& e) {
343 ATH_MSG_ERROR(
"processCLIDDB: Can't cast ["<< columns[0] <<
"] to long (clid): " << e.what() );
348 columns.size()>2 ? columns[2] :
"")) {
356 <<
"' from CLIDDB file: " << fileName );
359 " entries from CLIDDB file: " << fileName );
372 size_t newEntries(0);
376 ATH_MSG_VERBOSE(
"reading [" << clid <<
", " << typeName <<
", " << typeInfoName <<
"]" );
387 <<
" CLIDRegistry entries for module " << moduleName );
389 ATH_MSG_ERROR(
"getRegistryEntries: can not read CLIDRegistry entries for module "
399 const std::string& typeName,
400 const std::string& typeInfoName)
403 std::string procName(typeName);
404 boost::trim(procName);
406 if (procName.empty()) {
408 return StatusCode::FAILURE;
412 std::string procTiName;
413 if (typeInfoName.empty()) {
414 procTiName = procName;
417 procTiName = typeInfoName;
418 boost::trim(procTiName);
422 const auto& [clid_it, clid_success] =
m_clidMap.try_emplace(
id, procName, procTiName);
423 if (!clid_success && clid_it->second!=std::make_pair(procName,procTiName)) {
424 ATH_MSG_ERROR(
"Cannot set type " << std::make_pair(procName,procTiName) <<
" for CLID " <<
425 id <<
": known type for this ID " << clid_it->second );
426 return StatusCode::FAILURE;
430 const auto& [name_it, name_success] =
m_nameMap.try_emplace(procName,
id);
431 if (!name_success && name_it->second!=
id) {
432 ATH_MSG_ERROR(
"Cannot set CLID " <<
id <<
" for type name '"
433 << procName <<
"': known CLID for this name " << name_it->second );
434 return StatusCode::FAILURE;
438 const auto& [info_it, info_success] =
m_tiNameMap.try_emplace(procTiName,
id);
439 if (!info_success && info_it->second!=
id) {
440 ATH_MSG_ERROR(
"Cannot set CLID " <<
id <<
" for type-info name '"
441 << procTiName <<
"' and type '" << procName
442 <<
"': known CLID for this type-info name " << info_it->second );
443 return StatusCode::FAILURE;
446 ATH_MSG_VERBOSE(
"Set type name '" << procName <<
"' for CLID " <<
id <<
447 " with type-info name '" << procTiName <<
"'" );
449 return StatusCode::SUCCESS;
462 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.
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
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.