ATLAS Offline Software
Identifier.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 /// Constructor from Identifier32
6 inline Identifier::Identifier(const Identifier32& other)
7  : m_id(max_value){
8  if (other.is_valid()) {
9  m_id = (static_cast<value_type>(other.get_compact()) << 32);
10  }
11 }
12 
13 /// Constructor from Identifier32 value_type (unsigned int)
14 /// (only use in id64 case since otherwise redundant)
15 inline Identifier::Identifier(Identifier32::value_type value)
16  : m_id(max_value){
17  if (value == ~static_cast<Identifier32::value_type>(0)) {
18  m_id = max_value;
19  } else {
20  m_id = (static_cast<value_type>(value) << 32);
21  }
22 }
23 
24 inline Identifier::Identifier(int value)
25  : m_id(static_cast<value_type>(value) << 32)
26 {/* */}
27 
28 //-----------------------------------------------
29 inline Identifier::Identifier(value_type value)
30  : m_id(value){
31 
32  // Print out warning for potential call with value for a 32-bit id
33  // I.e. if lower bits are set and no upper bit set
34  const value_type upper = 0XFFFFFFFF00000000LL;
35  const value_type lower = 0X00000000FFFFFFFFLL;
36  const value_type testUpper = value & upper;
37  const value_type testLower = value & lower;
38  if (testUpper == 0 && testLower > 0) {
39  std::cout << "Identifier::Identifier - WARNING Constructing 64-bit id "
40  "with empty upper and non-empty lower: "
41  << std::hex << testUpper << " " << testLower << std::dec << std::endl;
42  m_id = (value << 32);
43  }
44 }
45 
46 
47 inline Identifier&
48 Identifier::operator=(const Identifier32& old){
49  m_id = (static_cast<value_type>(old.get_compact()) << 32);
50  return (*this);
51 }
52 
53 inline Identifier&
54 Identifier::operator=(value_type value){
55  // Print out warning for potential call with value for a 32-bit id
56  // I.e. if lower bits are set and no upper bit set
57  const value_type upper = 0XFFFFFFFF00000000LL;
58  const value_type lower = 0X00000000FFFFFFFFLL;
59  const value_type testUpper = value & upper;
60  const value_type testLower = value & lower;
61  if (testUpper == 0 && testLower > 0) {
62  std::cout << "Identifier::operator = - WARNING Constructing 64-bit id "
63  "with empty upper and non-empty lower: "
64  << std::hex << testUpper << " " << testLower << std::dec << std::endl;
65  m_id = (value << 32);
66  return (*this);
67  }
68  m_id = value;
69  return (*this);
70 }
71 
72 inline Identifier&
73 Identifier::operator=(Identifier32::value_type value){
74  if (value == ~static_cast<Identifier32::value_type>(0)) {
75  m_id = max_value;
76  } else {
77  m_id = static_cast<value_type>(value) << 32;
78  }
79  return (*this);
80 }
81 
82 inline Identifier&
83 Identifier::operator=(int value){
84  m_id = static_cast<value_type>(value) << 32;
85  return (*this);
86 }
87 
88 inline Identifier&
89 Identifier::operator|=(value_type value){
90  m_id |= value;
91  return (*this);
92 }
93 
94 inline Identifier&
95 Identifier::operator&=(value_type value){
96  m_id &= value;
97  return (*this);
98 }
99 
100 inline Identifier&
101 Identifier::set_literal(value_type value){
102  m_id = value;
103  return (*this);
104 }
105 
106 inline void
107 Identifier::clear(){
108  m_id = max_value;
109 }
110 
111 inline Identifier::value_type
112 Identifier::extract(Identifier::size_type shift,
113  Identifier::size_type mask) const{
114  return (m_id >> shift) & static_cast<Identifier::value_type>(mask);
115 }
116 
117 inline Identifier::value_type
118 Identifier::mask_shift(Identifier::value_type mask,
119  Identifier::size_type shift) const{
120  return (m_id & mask) >> shift;
121 }
122 
123 inline Identifier::value_type
124 Identifier::extract(Identifier::size_type shift) const{
125  return (m_id >> shift);
126 }
127 
128 inline Identifier32
129 Identifier::get_identifier32() const{
130  // test for bit set in lower 32
131  if (extract(0, 0xFFFFFFFF)) return (Identifier32());
132  return (Identifier32(extract(32)));
133 }
134 
135 inline Identifier::value_type
136 Identifier::get_compact() const{
137  return (m_id);
138 }
139 
140 
141 inline bool
142 Identifier::operator==(Identifier::value_type other) const{
143  return (m_id == other);
144 }
145 
146 inline bool
147 Identifier::operator==(Identifier32::value_type other) const{
148  return ((*this) == Identifier(other));
149 }
150 
151 inline bool
152 Identifier::operator==(int other) const{
153  return ((*this) == Identifier(other));
154 }
155 
156 /// This is for logging
157 
158 inline MsgStream&
159 operator<<(MsgStream& f, const Identifier& id){
160  f << id.getString();
161  return f;
162 }
163 
164 inline std::ostream&
165 operator<<(std::ostream& os, const Identifier& id){
166  os << id.getString();
167  return os;
168 }
169 
170 inline bool
171 Identifier::is_valid() const{
172  return (!(max_value == m_id));
173 }
174