ATLAS Offline Software
Loading...
Searching...
No Matches
GlobalSim::AuxSpec Struct Reference

#include <BitSpec.h>

Collaboration diagram for GlobalSim::AuxSpec:

Static Public Member Functions

static constexpr std::size_t parseNumber (std::string_view str, std::size_t &pos, std::size_t end)
static constexpr AuxSpec parse (std::string_view spec)

Public Attributes

std::string_view name
std::uint64_t mask
std::size_t shift
bool has_mask

Detailed Description

Definition at line 40 of file BitSpec.h.

Member Function Documentation

◆ parse()

constexpr AuxSpec GlobalSim::AuxSpec::parse ( std::string_view spec)
inlinestaticconstexpr

Definition at line 61 of file BitSpec.h.

61 {
62 const auto open = spec.find('[');
63
64 // No mask specification.
65 if (open == std::string_view::npos) {
66 return {
67 spec,
68 std::numeric_limits<std::uint64_t>::max(),
69 0,
70 false
71 };
72 }
73
74 // Expected: name[lo:hi] or name[bit]
75 const auto colon = spec.find(':', open + 1);
76 const auto close = spec.find(']', open + 1);
77
78 if (close == std::string_view::npos ||close != spec.size() - 1) {
79 throw std::invalid_argument("Invalid AuxSpec");
80 }
81
82 std::size_t pos = open + 1;
83 const std::size_t lo = parseNumber(spec, pos, colon == std::string_view::npos ? close : colon);
84
85 std::size_t hi = lo;
86
87 if (colon != std::string_view::npos) {
88 // Range: [lo:hi]
89 if (colon == open + 1 || colon + 1 == close) {
90 throw std::invalid_argument("Invalid AuxSpec range");
91 }
92 pos = colon + 1;
93 hi = parseNumber(spec, pos, close);
94 }
95
96 if (pos != close || lo > hi || hi >= 64)
97 throw std::invalid_argument("Invalid bit range");
98
99 const std::size_t width = hi - lo + 1;
100
101 const std::uint64_t mask =
102 width == 64
103 ? std::numeric_limits<std::uint64_t>::max()
104 : ((std::uint64_t{1} << width) - 1) << lo;
105
106 return {
107 spec.substr(0, open),
108 mask,
109 lo,
110 true
111 };
112 }
const double width
@ open
Definition BinningType.h:40
std::uint64_t mask
Definition BitSpec.h:42
static constexpr std::size_t parseNumber(std::string_view str, std::size_t &pos, std::size_t end)
Definition BitSpec.h:46

◆ parseNumber()

constexpr std::size_t GlobalSim::AuxSpec::parseNumber ( std::string_view str,
std::size_t & pos,
std::size_t end )
inlinestaticconstexpr

Definition at line 46 of file BitSpec.h.

46 {
47 std::size_t value{};
48 const auto [ptr, ec] = std::from_chars(
49 str.data() + pos,
50 str.data() + end,
51 value
52 );
53
54 if (ec != std::errc{})
55 throw std::invalid_argument("Expected number");
56
57 pos = ptr - str.data();
58 return value;
59 }
void * ptr(T *p)
Definition SGImplSvc.cxx:74

Member Data Documentation

◆ has_mask

bool GlobalSim::AuxSpec::has_mask

Definition at line 44 of file BitSpec.h.

◆ mask

std::uint64_t GlobalSim::AuxSpec::mask

Definition at line 42 of file BitSpec.h.

◆ name

std::string_view GlobalSim::AuxSpec::name

Definition at line 41 of file BitSpec.h.

◆ shift

std::size_t GlobalSim::AuxSpec::shift

Definition at line 43 of file BitSpec.h.


The documentation for this struct was generated from the following file: