ATLAS Offline Software
Identifier.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 /// Constructor from Identifier32
6 //-----------------------------------------------
7 inline Identifier::Identifier(const Identifier32& other)
8  : m_id(max_value)
9 {
10  if (other.is_valid()) {
11  m_id = (static_cast<value_type>(other.get_compact()) << 32);
12  }
13 }
14 
15 /// Constructor from Identifier32 value_type (unsigned int)
16 /// (only use in id64 case since otherwise redundant)
17 //-----------------------------------------------
18 inline Identifier::Identifier(Identifier32::value_type value)
19  : m_id(max_value)
20 {
21  if (value == ~static_cast<Identifier32::value_type>(0)) {
22  m_id = max_value;
23  } else {
24  m_id = (static_cast<value_type>(value) << 32);
25  }
26 }
27 inline Identifier::Identifier(int value)
28  : m_id(static_cast<value_type>(value) << 32)
29 {
30 }
31 
32 //-----------------------------------------------
33 inline Identifier::Identifier(value_type value)
34  : m_id(value)
35 {
36 
37  // Print out warning for potential call with value for a 32-bit id
38  // I.e. if lower bits are set and no upper bit set
39  const value_type upper = 0XFFFFFFFF00000000LL;
40  const value_type lower = 0X00000000FFFFFFFFLL;
41  const value_type testUpper = value & upper;
42  const value_type testLower = value & lower;
43  if (testUpper == 0 && testLower > 0) {
44  boost::io::ios_flags_saver ifs(std::cout);
45  std::cout << "Identifier::Identifier - WARNING Constructing 64-bit id "
46  "with empty upper and non-empty lower: "
47  << std::hex << testUpper << " " << testLower << std::endl;
48  m_id = (value << 32);
49  }
50 }
51 
52 // Modifications
53 //-----------------------------------------------
54 
55 inline Identifier&
56 Identifier::operator=(const Identifier32& old)
57 {
58  m_id = (static_cast<value_type>(old.get_compact()) << 32);
59  return (*this);
60 }
61 
62 inline Identifier&
63 Identifier::operator=(value_type value)
64 {
65 
66  // Print out warning for potential call with value for a 32-bit id
67  // I.e. if lower bits are set and no upper bit set
68  const value_type upper = 0XFFFFFFFF00000000LL;
69  const value_type lower = 0X00000000FFFFFFFFLL;
70  const value_type testUpper = value & upper;
71  const value_type testLower = value & lower;
72  if (testUpper == 0 && testLower > 0) {
73  boost::io::ios_flags_saver ifs(std::cout);
74  std::cout << "Identifier::opertor = - WARNING Constructing 64-bit id "
75  "with empty upper and non-empty lower: "
76  << std::hex << testUpper << " " << testLower << std::endl;
77  m_id = (value << 32);
78  return (*this);
79  }
80 
81  m_id = value;
82  return (*this);
83 }
84 
85 inline Identifier&
86 Identifier::operator=(Identifier32::value_type value)
87 {
88  if (value == ~static_cast<Identifier32::value_type>(0)) {
89  m_id = max_value;
90  } else {
91  m_id = static_cast<value_type>(value) << 32;
92  }
93  return (*this);
94 }
95 inline Identifier&
96 Identifier::operator=(int value)
97 {
98  m_id = static_cast<value_type>(value) << 32;
99  return (*this);
100 }
101 
102 inline Identifier&
103 Identifier::operator|=(value_type value)
104 {
105  m_id |= value;
106  return (*this);
107 }
108 
109 inline Identifier&
110 Identifier::operator&=(value_type value)
111 {
112  m_id &= value;
113  return (*this);
114 }
115 
116 inline Identifier&
117 Identifier::set_literal(value_type value)
118 {
119  m_id = value;
120  return (*this);
121 }
122 
123 inline void
124 Identifier::clear()
125 {
126  m_id = max_value;
127 }
128 
129 inline Identifier::value_type
130 Identifier::extract(Identifier::size_type shift,
131  Identifier::size_type mask) const
132 {
133  return (m_id >> shift) & static_cast<Identifier::value_type>(mask);
134 }
135 
136 inline Identifier::value_type
137 Identifier::mask_shift(Identifier::value_type mask,
138  Identifier::size_type shift) const
139 {
140  return (m_id & mask) >> shift;
141 }
142 
143 inline Identifier::value_type
144 Identifier::extract(Identifier::size_type shift) const
145 {
146  return (m_id >> shift);
147 }
148 
149 inline Identifier32
150 Identifier::get_identifier32(void) const
151 {
152  // test for bit set in lower 32
153  if (extract(0, 0xFFFFFFFF))
154  return (Identifier32());
155  return (Identifier32(extract(32)));
156 }
157 
158 inline Identifier::value_type
159 Identifier::get_compact(void) const
160 {
161  return (m_id);
162 }
163 
164 // Comparison operators
165 //----------------------------------------------------------------
166 inline bool
167 Identifier::operator==(const Identifier& other) const
168 {
169  return (m_id == other.m_id);
170 }
171 
172 //----------------------------------------------------------------
173 inline bool
174 Identifier::operator!=(const Identifier& other) const
175 {
176  return (m_id != other.m_id);
177 }
178 
179 //-----------------------------------------------
180 inline bool
181 Identifier::operator<(const Identifier& other) const
182 {
183  return (m_id < other.m_id);
184 }
185 
186 //-----------------------------------------------
187 inline bool
188 Identifier::operator>(const Identifier& other) const
189 {
190  return (m_id > other.m_id);
191 }
192 
193 //-----------------------------------------------
194 inline bool
195 Identifier::operator<=(const Identifier& other) const
196 {
197  return (m_id <= other.m_id);
198 }
199 
200 //-----------------------------------------------
201 inline bool
202 Identifier::operator>=(const Identifier& other) const
203 {
204  return (m_id >= other.m_id);
205 }
206 
207 //----------------------------------------------------------------
208 inline bool
209 Identifier::operator==(Identifier::value_type other) const
210 {
211  return (m_id == other);
212 }
213 
214 inline bool
215 Identifier::operator!=(Identifier::value_type other) const
216 {
217  return (m_id != other);
218 }
219 
220 inline bool
221 Identifier::operator==(Identifier32::value_type other) const
222 {
223  return ((*this) == Identifier(other));
224 }
225 
226 inline bool
227 Identifier::operator==(int other) const
228 {
229  return ((*this) == Identifier(other));
230 }
231 
232 inline bool
233 Identifier::operator!=(Identifier32::value_type other) const
234 {
235  return ((*this) != Identifier(other));
236 }
237 
238 inline bool
239 Identifier::operator!=(int other) const
240 {
241  return ((*this) != Identifier(other));
242 }
243 
244 /// This is for logging
245 
246 inline MsgStream&
247 operator<<(MsgStream& f, const Identifier& id)
248 {
249  f << id.getString();
250  return f;
251 }
252 
253 inline std::ostream&
254 operator<<(std::ostream& os, const Identifier& id)
255 {
256  os << id.getString();
257  return os;
258 }
259 
260 inline bool
261 Identifier::is_valid() const
262 {
263  return (!(max_value == m_id));
264 }
265