ATLAS Offline Software
DetectorDescription/Identifier/Identifier/Identifier.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef IDENTIFIER_IDENTIFIER_H
6 #define IDENTIFIER_IDENTIFIER_H
7 
8 #include "GaudiKernel/MsgStream.h"
10 #include <string>
11 
12 /*
13  *
14  * @brief Identifier is a simple type-safe 64 bit unsigned integer. An
15  * Identifier relies on other classes - IdHelpers - to encode and
16  * decode its information.
17  *
18  * The default constructor created an Identifier an invalid state
19  * which can be check with the "is_valid" method to allow some error
20  * checking.
21  *
22  */
23 class Identifier{
24 public:
25 
27  using value_type = unsigned long long;
28  using diff_type = long long;
29  using size_type = unsigned long long ;
30 
31  enum bit_defs{
32  NBITS = sizeof(value_type) * 8, // bits per byte
33  MAX_BIT = (static_cast<value_type>(1) << (NBITS - 1)),
34  ALL_BITS = ~(static_cast<value_type>(0))
35  };
36 
38  Identifier() = default;
39 
44 
47 
51  explicit Identifier (int value);
53 
60 
61 private:
65 
66 public:
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;}
101  bool operator == (int other) const;
102 
104  bool is_valid () const;
105 
107  std::string getString() const;
108 
110  void show () const;
111 
112 private:
115 
118 
121 
122  // allow IdDict access to the following private methods
123  friend class IdDictDictionary;
125  friend class AtlasDetectorID;
126  friend class PixelID;
127 
129  max_value = ~(static_cast<value_type>(0))
130  };
133 };
134 
135 
137 namespace std {
138  template<>
139  struct hash<Identifier>{
140  size_t operator()(const Identifier& id) const{
141  return static_cast<size_t>(id.get_compact());
142  }
143  };
144 }
145 
146 #include "Identifier/Identifier.icc"
147 
148 #endif
Identifier32
Definition: Identifier32.h:25
Identifier::set
void set(const std::string &id)
build from a string form - hexadecimal
Definition: Identifier.cxx:12
Identifier::MAX_BIT
@ MAX_BIT
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:33
Identifier::operator|=
Identifier & operator|=(value_type value)
Bitwise operations.
Identifier::mask_shift
value_type mask_shift(value_type mask, size_type shift) const
extract field(s) by masking first, then shifting
Identifier::max_value
@ max_value
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:129
Identifier::get_identifier32
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
Identifier::get_compact
value_type get_compact() const
Get the compact id.
std::hash< Identifier >::operator()
size_t operator()(const Identifier &id) const
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:140
athena.value
value
Definition: athena.py:124
Identifier::operator&=
Identifier & operator&=(value_type value)
Identifier::set_literal
Identifier & set_literal(value_type value)
Set literal value.
Identifier::diff_type
long long diff_type
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:28
Identifier::is_valid
bool is_valid() const
Check if id is in a valid state.
Identifier::m_id
value_type m_id
The only data member.
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:132
Identifier::Identifier
Identifier(value_type value)
python.utils.AtlRunQueryLookup.mask
string mask
Definition: AtlRunQueryLookup.py:460
Identifier::operator=
Identifier & operator=(const Identifier32 &old)
Assignment operators overloads.
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:23
Identifier::Identifier
Identifier(int value)
Identifier::bit_defs
bit_defs
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:31
Identifier::show
void show() const
Print out in hex form.
Definition: Identifier.cxx:30
Identifier::ALL_BITS
@ ALL_BITS
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:34
Identifier::clear
void clear()
Reset to invalid state.
Identifier::get_compact_func
A get_compact functional for use in STL algorithms.
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:85
Identifier::NBITS
@ NBITS
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
IdDictDictionary
Definition: IdDictDictionary.h:30
Identifier::Identifier
Identifier(Identifier32::value_type value)
Constructor from 32-bit value_type and int (to avoid common implicit conversions)
Identifier.icc
Identifier::getString
std::string getString() const
Provide a string form of the identifier - hexadecimal.
Definition: Identifier.cxx:25
Identifier::max_value_type
max_value_type
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:128
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
CSV_InDetExporter.old
old
Definition: CSV_InDetExporter.py:145
Identifier::get_compact_func::operator()
value_type operator()(const Identifier &id)
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:86
Identifier::operator==
bool operator==(const Identifier &other) const =default
Identifier::value_type
unsigned long long value_type
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:27
Identifier::Identifier
Identifier(const Identifier32 &other)
Constructor from Identifier32.
Identifier::size_type
unsigned long long size_type
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:29
IdDictFieldImplementation
IdDictFieldImplementation is used to capture the specification of a single field of an Identifier.
Definition: IdDictFieldImplementation.h:58
PixelID
Definition: PixelID.h:67
value_type
Definition: EDM_MasterSearch.h:11
Identifier32.h
Identifier::extract
value_type extract(size_type shift, size_type mask) const
extract field from identifier (shift first, then mask)
AtlasDetectorID
This class provides an interface to generate or decode an identifier for the upper levels of the dete...
Definition: AtlasDetectorID.h:57
Identifier::Identifier
Identifier()=default
Default constructor.
Identifier32::value_type
unsigned int value_type
Definition: Identifier32.h:28
Identifier::extract
value_type extract(size_type shift) const
extract field, no mask
Identifier
Definition: IdentifierFieldParser.cxx:14