ATLAS Offline Software
Loading...
Searching...
No Matches
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
6inline 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)
15inline 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
24inline Identifier::Identifier(int value)
25 : m_id(static_cast<value_type>(value) << 32)
26{/* */}
27
28//-----------------------------------------------
29inline 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
47inline Identifier&
48Identifier::operator=(const Identifier32& old){
49 m_id = (static_cast<value_type>(old.get_compact()) << 32);
50 return (*this);
51}
52
53inline Identifier&
54Identifier::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
72inline Identifier&
73Identifier::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
82inline Identifier&
83Identifier::operator=(int value){
84 m_id = static_cast<value_type>(value) << 32;
85 return (*this);
86}
87
88inline Identifier&
89Identifier::operator|=(value_type value){
90 m_id |= value;
91 return (*this);
92}
93
94inline Identifier&
95Identifier::operator&=(value_type value){
96 m_id &= value;
97 return (*this);
98}
99
100inline Identifier&
101Identifier::set_literal(value_type value){
102 m_id = value;
103 return (*this);
104}
105
106inline void
107Identifier::clear(){
108 m_id = max_value;
109}
110
111inline Identifier::value_type
112Identifier::extract(Identifier::size_type shift,
113 Identifier::size_type mask) const{
114 return (m_id >> shift) & static_cast<Identifier::value_type>(mask);
115}
116
117inline Identifier::value_type
118Identifier::mask_shift(Identifier::value_type mask,
119 Identifier::size_type shift) const{
120 return (m_id & mask) >> shift;
121}
122
123inline Identifier::value_type
124Identifier::extract(Identifier::size_type shift) const{
125 return (m_id >> shift);
126}
127
128inline Identifier32
129Identifier::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
135inline Identifier::value_type
136Identifier::get_compact() const{
137 return (m_id);
138}
139
140
141inline bool
142Identifier::operator==(Identifier::value_type other) const{
143 return (m_id == other);
144}
145
146inline bool
147Identifier::operator==(Identifier32::value_type other) const{
148 return ((*this) == Identifier(other));
149}
150
151inline bool
152Identifier::operator==(int other) const{
153 return ((*this) == Identifier(other));
154}
155
156/// This is for logging
157
158inline MsgStream&
159operator<<(MsgStream& f, const Identifier& id){
160 f << id.getString();
161 return f;
162}
163
164inline std::ostream&
165operator<<(std::ostream& os, const Identifier& id){
166 os << id.getString();
167 return os;
168}
169
170inline bool
171Identifier::is_valid() const{
172 return (!(max_value == m_id));
173}
174