ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
DetectorDescription
Identifier
src
Identifier.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
6
#include "Identifier/Identifier.h"
7
#include "GaudiKernel/MsgStream.h"
8
#include <charconv>
9
#include <iostream>
10
11
12
template
<
typename
Stream>
13
void
streamIdentifier
(Stream& os,
unsigned
long
long
id
) {
14
//This is faster than std::format and uses no allocations.
15
//Please don't switch to std::format without performance checks
16
char
buf[32];
17
buf[0] =
'0'
;
18
buf[1] =
'x'
;
19
auto
[ptr, ec] = std::to_chars(buf + 2, buf +
sizeof
(buf),
id
, 16);
20
21
os << std::string_view(buf, ptr);
22
}
23
24
25
void
Identifier::set
(std::string_view
id
){
26
const
auto
start =
id
.data();
27
const
auto
end = start +
id
.size();
28
static
constexpr
int
base
= 16;
29
//add 2 to start to get past the Ox prefix.
30
const
auto
[p,ec] = std::from_chars(start+2, end,
m_id
,
base
);
31
if
(ec != std::errc()){
32
throw
std::runtime_error(
"Number was not parsed in Identifier::set"
);
33
}
34
}
35
36
37
std::string
Identifier::getString
()
const
{
38
//This is faster than std::format when checked
39
//Please don't switch to std::format without performance checks
40
char
buf[32];
41
buf[0] =
'0'
;
42
buf[1] =
'x'
;
43
auto
[ptr, ec] = std::to_chars(buf + 2, buf +
sizeof
(buf),
m_id
, 16);
44
return
std::string(buf, ptr);
45
}
46
47
void
Identifier::show
(std::ostream& out)
const
{
48
streamIdentifier
(out,
m_id
);
49
}
50
51
void
Identifier::show
(MsgStream& out)
const
{
52
streamIdentifier
(out,
m_id
);
53
}
54
55
MsgStream&
operator<<
(MsgStream& f,
const
Identifier
&
id
) {
56
streamIdentifier
(f,
id
.get_compact());
57
return
f;
58
}
59
60
std::ostream&
operator<<
(std::ostream& os,
const
Identifier
&
id
) {
61
streamIdentifier
(os,
id
.get_compact());
62
return
os;
63
}
64
streamIdentifier
void streamIdentifier(Stream &os, unsigned long long id)
Definition
Identifier.cxx:13
operator<<
MsgStream & operator<<(MsgStream &f, const Identifier &id)
Definition
Identifier.cxx:55
Identifier::getString
std::string getString() const
Provide a string form of the identifier - hexadecimal.
Definition
Identifier.cxx:37
Identifier::m_id
value_type m_id
The only data member.
Definition
DetectorDescription/Identifier/Identifier/Identifier.h:134
Identifier::show
void show(std::ostream &out) const
Print out in hex form.
Definition
Identifier.cxx:47
Identifier::set
void set(std::string_view id)
build from a string form - hexadecimal
Definition
Identifier.cxx:25
base
std::string base
Definition
hcg.cxx:83
Identifier
Definition
IdentifierFieldParser.cxx:14
Generated on
for ATLAS Offline Software by
1.17.0