ATLAS Offline Software
CLIDRegistry.cxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration.
3  */
4 
7 #include <unordered_map>
8 #include <mutex>
9 
10 
12 {
13 public:
14  bool hasNewEntries() const;
15 
17 
18  const std::type_info* CLIDToTypeinfo (CLID clid) const;
19  CLID typeinfoToCLID (const std::type_info& ti) const;
20 
21  bool addEntry (unsigned long clid,
22  const std::type_info& ti,
23  const char* typeName,
24  const std::string& typeInfoName);
25 
26 
27 private:
29  typedef std::lock_guard<mutex_t> lock_t;
30  mutable mutex_t m_mutex;
31 
33  size_t m_alreadyDone = 0;
34 
35  typedef std::unordered_map<CLID, const std::type_info*> clid_ti_map_t;
37 
38  typedef std::unordered_map<const std::type_info*, CLID> ti_clid_map_t;
40 };
41 
42 
44 {
45  lock_t lock (m_mutex);
46  return m_alreadyDone < m_vec.size();
47 }
48 
49 
52 {
53  lock_t lock (m_mutex);
54  size_t pos = m_alreadyDone;
55  m_alreadyDone = m_vec.size();
56  return CLIDRegistry::CLIDVector_t (m_vec.begin()+pos, m_vec.end());
57 }
58 
59 
66 const std::type_info* CLIDRegistryImpl::CLIDToTypeinfo (CLID clid) const
67 {
68  lock_t lock (m_mutex);
69  auto i = m_clid_ti_map.find (clid);
70  if (i != m_clid_ti_map.end()) {
71  return i->second;
72  }
73  return nullptr;
74 }
75 
76 
83 CLID CLIDRegistryImpl::typeinfoToCLID (const std::type_info& ti) const
84 {
85  lock_t lock (m_mutex);
86  auto i = m_ti_clid_map.find (&ti);
87  if (i != m_ti_clid_map.end()) {
88  return i->second;
89  }
90  return CLID_NULL;
91 }
92 
93 
94 bool CLIDRegistryImpl::addEntry (unsigned long clid,
95  const std::type_info& ti,
96  const char* typeName,
97  const std::string& typeInfoName)
98 {
99  lock_t lock (m_mutex);
100  m_vec.emplace_back (clid, std::string(typeName), typeInfoName);
101  m_clid_ti_map[clid] = &ti;
102  m_ti_clid_map[&ti] = clid;
103  return true;
104 }
105 
106 
107 //***************************************************************************
108 
109 
110 bool
112 {
113  return impl().hasNewEntries();
114 }
115 
118 {
119  return impl().newEntries();
120 }
121 
122 
124 {
126  return reg;
127 }
128 
129 
136 const std::type_info* CLIDRegistry::CLIDToTypeinfo (CLID clid)
137 {
138  return impl().CLIDToTypeinfo (clid);
139 }
140 
141 
148 CLID CLIDRegistry::typeinfoToCLID (const std::type_info& ti)
149 {
150  return impl().typeinfoToCLID (ti);
151 }
152 
153 
155 bool CLIDRegistry::addEntry (unsigned long clid,
156  const std::type_info& ti,
157  const char* typeName,
158  const std::string& typeInfoName)
159 {
160  return impl().addEntry (clid, ti, typeName, typeInfoName);
161 }
162 
CLIDRegistry::newEntries
static CLIDVector_t newEntries()
returns an iterator range over the entries added since last time newEntries was called
Definition: CLIDRegistry.cxx:117
CLIDRegistry::typeinfoToCLID
static CLID typeinfoToCLID(const std::type_info &ti)
Return the CLID corresponding to a type_info.
Definition: CLIDRegistry.cxx:148
CLIDRegistry::addEntry
static bool addEntry(const std::type_info &ti, const char *typeName, const std::string &typeInfoName)
to be called by the CLASS_DEFS
Definition: CLIDRegistry.h:74
BeamSpot::mutex
std::mutex mutex
Definition: InDetBeamSpotVertex.cxx:18
CLIDRegistryImpl::m_vec
CLIDRegistry::CLIDVector_t m_vec
Definition: CLIDRegistry.cxx:32
CLIDRegistry::CLIDToTypeinfo
static const std::type_info * CLIDToTypeinfo(CLID clid)
Translate between CLID and type_info.
Definition: CLIDRegistry.cxx:136
CLIDRegistryImpl::typeinfoToCLID
CLID typeinfoToCLID(const std::type_info &ti) const
Return the CLID corresponding to a type_info.
Definition: CLIDRegistry.cxx:83
CLIDRegistryImpl::mutex_t
std::mutex mutex_t
Definition: CLIDRegistry.cxx:28
CLIDRegistryImpl::newEntries
CLIDRegistry::CLIDVector_t newEntries()
Definition: CLIDRegistry.cxx:51
CLIDRegistryImpl::m_alreadyDone
size_t m_alreadyDone
Definition: CLIDRegistry.cxx:33
lumiFormat.i
int i
Definition: lumiFormat.py:85
CLIDRegistry::hasNewEntries
static bool hasNewEntries()
registry accessors (used by ClassIDSvc)
Definition: CLIDRegistry.cxx:111
CLIDRegistryImpl::CLIDToTypeinfo
const std::type_info * CLIDToTypeinfo(CLID clid) const
Return the type_info corresponding to a CLID.
Definition: CLIDRegistry.cxx:66
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
CLIDRegistryImpl::addEntry
bool addEntry(unsigned long clid, const std::type_info &ti, const char *typeName, const std::string &typeInfoName)
Definition: CLIDRegistry.cxx:94
CLIDRegistryImpl::clid_ti_map_t
std::unordered_map< CLID, const std::type_info * > clid_ti_map_t
Definition: CLIDRegistry.cxx:35
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
CLIDRegistry.h
a static registry of CLID->typeName entries. NOT for general use. Use ClassIDSvc instead.
CLIDRegistryImpl::lock_t
std::lock_guard< mutex_t > lock_t
Definition: CLIDRegistry.cxx:29
CLIDRegistryImpl::m_ti_clid_map
ti_clid_map_t m_ti_clid_map
Definition: CLIDRegistry.cxx:39
CLIDRegistryImpl::hasNewEntries
bool hasNewEntries() const
Definition: CLIDRegistry.cxx:43
CLIDRegistry::impl
static CLIDRegistryImpl & impl()
Definition: CLIDRegistry.cxx:123
CLIDRegistryImpl
Definition: CLIDRegistry.cxx:12
ReadCalibFromCool.typeName
typeName
Definition: ReadCalibFromCool.py:477
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
CLIDRegistryImpl::m_clid_ti_map
clid_ti_map_t m_clid_ti_map
Definition: CLIDRegistry.cxx:36
CLIDRegistryImpl::m_mutex
mutex_t m_mutex
Definition: CLIDRegistry.cxx:30
checker_macros.h
Define macros for attributes used to control the static checker.
CLIDRegistry::CLIDVector_t
std::vector< tuple_t > CLIDVector_t
Definition: CLIDRegistry.h:40
CLIDRegistryImpl::ti_clid_map_t
std::unordered_map< const std::type_info *, CLID > ti_clid_map_t
Definition: CLIDRegistry.cxx:38