ATLAS Offline Software
Loading...
Searching...
No Matches
DetectorDescription/Identifier/Identifier/Identifier.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef IDENTIFIER_IDENTIFIER_H
6#define IDENTIFIER_IDENTIFIER_H
7
8
10#include <string>
11#include <iostream>
12
13class MsgStream;
14/*
15 *
16 * @brief Identifier is a simple type-safe 64 bit unsigned integer. An
17 * Identifier relies on other classes - IdHelpers - to encode and
18 * decode its information.
19 *
20 * The default constructor created an Identifier an invalid state
21 * which can be check with the "is_valid" method to allow some error
22 * checking.
23 *
24 */
26public:
27
29 using value_type = unsigned long long;
30 using diff_type = long long;
31 using size_type = unsigned long long ;
32
33 static constexpr unsigned int NBITS = sizeof(value_type) * 8; // bits per byte
34 static constexpr value_type MAX_BIT = (static_cast<value_type>(1) << (NBITS - 1));
35 static constexpr value_type ALL_BITS = ~(static_cast<value_type>(0));
36
38 Identifier() = default;
39
43 explicit Identifier (value_type value);
44
46 Identifier (const Identifier32& other);
47
51 explicit Identifier (int value);
53
55 Identifier& operator = (const Identifier32& old);
56 Identifier& operator = (value_type value);
59 Identifier& operator = (int value);
60
61private:
65
66public:
67
69 void set (const std::string& id);
70
72 void clear ();
73
76
80
83
87 return id.get_compact();
88 }
89 };
90
91 bool operator == (const Identifier& other) const = default;
92 inline auto operator <=> (const Identifier & other) const {return m_id <=> other.m_id;}
99 bool operator == (value_type other) const;
101 bool operator == (int other) const;
102
104 bool is_valid () const;
105
107 std::string getString() const;
108
110 void show (std::ostream & out = std::cout) const;
111 void show (MsgStream & out) const;
112
113private:
116
119
122
123 // allow IdDict access to the following private methods
124 friend class IdDictDictionary;
126 friend class AtlasDetectorID;
127 friend class PixelID;
128
130 max_value = ~(static_cast<value_type>(0))
131 };
132
134};
135
136MsgStream&
137operator<<(MsgStream& f, const Identifier& id);
138
139std::ostream&
140operator<<(std::ostream& os, const Identifier& id);
141
143namespace std {
144 template<>
145 struct hash<Identifier>{
146 size_t operator()(const Identifier& id) const{
147 return static_cast<size_t>(id.get_compact());
148 }
149 };
150}
151
153
154#endif
bool operator==(const DataVector< T > &a, const DataVector< T > &b)
Vector equality comparison.
MsgStream & operator<<(MsgStream &f, const Identifier &id)
constexpr std::enable_if_t< is_bitmask_v< E >, E & > operator&=(E &lhs, E rhs)
operator&=
Definition bitmask.h:185
constexpr std::enable_if_t< is_bitmask_v< E >, E & > operator|=(E &lhs, E rhs)
operator|=
Definition bitmask.h:197
unsigned int value_type
std::string getString() const
Provide a string form of the identifier - hexadecimal.
bool is_valid() const
Check if id is in a valid state.
void show(std::ostream &out=std::cout) const
Print out in hex form.
void clear()
Reset to invalid state.
value_type get_compact() const
Get the compact id.
Identifier(const Identifier32 &other)
Constructor from Identifier32.
Identifier(Identifier32::value_type value)
Constructor from 32-bit value_type and int (to avoid common implicit conversions)
Identifier & set_literal(value_type value)
Set literal value.
value_type extract(size_type shift, size_type mask) const
extract field from identifier (shift first, then mask)
value_type mask_shift(value_type mask, size_type shift) const
extract field(s) by masking first, then shifting
value_type extract(size_type shift) const
extract field, no mask
Identifier()=default
Default constructor.
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
Identifier(value_type value)
Identifier(int value)
void set(const std::string &id)
build from a string form - hexadecimal
STL namespace.
A get_compact functional for use in STL algorithms.