R3BROOT
R3B analysis software
Toggle main menu visibility
Loading...
Searching...
No Matches
R3BUcesbMappingFlag.h
Go to the documentation of this file.
1
#pragma once
2
/******************************************************************************
3
* Copyright (C) 2019 GSI Helmholtzzentrum für Schwerionenforschung GmbH *
4
* Copyright (C) 2019-2025 Members of R3B Collaboration *
5
* *
6
* This software is distributed under the terms of the *
7
* GNU General Public Licence (GPL) version 3, *
8
* copied verbatim in the file "LICENSE". *
9
* *
10
* In applying this license GSI does not waive the privileges and immunities *
11
* granted to it by virtue of its status as an Intergovernmental Organization *
12
* or submit itself to any jurisdiction. *
13
******************************************************************************/
14
15
#include <bitset>
16
#include <cstdint>
17
#include <ext_data_client.h>
18
#include <fmt/core.h>
19
#include <fmt/format.h>
20
#include <iostream>
21
#include <string>
22
#include <type_traits>
23
24
constexpr
auto
UCESB_MAP_BITSIZE
= 32;
25
26
namespace
R3B
27
{
28
enum class
UcesbMap
: uint32_t
29
{
30
zero
= 0x0000U,
31
match
= EXT_DATA_ITEM_MAP_MATCH,
32
no_dest
= EXT_DATA_ITEM_MAP_NO_DEST,
33
not_found
= EXT_DATA_ITEM_MAP_NOT_FOUND,
34
type_mismatch
= EXT_DATA_ITEM_MAP_TYPE_MISMATCH,
35
ctrl_mismatch
= EXT_DATA_ITEM_MAP_CTRL_MISMATCH,
36
array_fewer
= EXT_DATA_ITEM_MAP_ARRAY_FEWER,
37
array_more
= EXT_DATA_ITEM_MAP_ARRAY_MORE,
38
not_done
= EXT_DATA_ITEM_MAP_NOT_DONE,
39
ok
= EXT_DATA_ITEM_MAP_OK,
40
ok_no_dest
= EXT_DATA_ITEM_MAP_OK_NO_DEST,
41
};
42
43
using
UcesbMapUType
= std::underlying_type<UcesbMap>::type;
44
45
inline
auto
operator|
(
const
UcesbMap
& left,
const
UcesbMap
& right) ->
UcesbMap
46
{
47
auto
res =
static_cast<
UcesbMapUType
>
(
left
) |
static_cast<
UcesbMapUType
>
(
right
);
48
return
static_cast<
UcesbMap
>
(res);
49
}
50
inline
void
operator|=
(
UcesbMap
& left,
const
UcesbMap
& right) {
left
=
left
|
right
; }
51
52
inline
auto
operator&
(
const
UcesbMap
& left,
const
UcesbMap
& right) ->
UcesbMap
53
{
54
auto
res =
static_cast<
UcesbMapUType
>
(
left
) &
static_cast<
UcesbMapUType
>
(
right
);
55
return
static_cast<
UcesbMap
>
(res);
56
}
57
58
inline
void
operator&=
(
UcesbMap
& left,
const
UcesbMap
& right) {
left
=
left
&
right
; }
59
60
inline
auto
operator~
(
const
UcesbMap
&
map
) ->
UcesbMap
61
{
62
return
static_cast<
UcesbMap
>
(~(
static_cast<
UcesbMapUType
>
(
map
)));
63
}
64
65
inline
auto
operator<<
(std::ostream& ostream,
const
UcesbMap
&
map
) -> std::ostream&
66
{
67
ostream << std::bitset<UCESB_MAP_BITSIZE>(
static_cast<
UcesbMapUType
>
(
map
));
68
return
ostream;
69
}
70
71
inline
auto
UcesbMap2String
(
UcesbMap
map
) -> std::string
72
{
73
switch
(
map
)
74
{
75
case
UcesbMap::zero
:
76
return
std::string{
"zero"
};
77
case
UcesbMap::match
:
78
return
std::string{
"match"
};
79
case
UcesbMap::no_dest
:
80
return
std::string{
"no_dest"
};
81
case
UcesbMap::not_found
:
82
return
std::string{
"not_found"
};
83
case
UcesbMap::type_mismatch
:
84
return
std::string{
"type_mismatch"
};
85
case
UcesbMap::ctrl_mismatch
:
86
return
std::string{
"ctrl_mismatch"
};
87
case
UcesbMap::array_fewer
:
88
return
std::string{
"array_fewer"
};
89
case
UcesbMap::array_more
:
90
return
std::string{
"array_more"
};
91
case
UcesbMap::not_done
:
92
return
std::string{
"not_done"
};
93
case
UcesbMap::ok
:
94
return
std::string{
"ok"
};
95
case
UcesbMap::ok_no_dest
:
96
return
std::string{
"ok_no_dest"
};
97
default
:
98
return
fmt::format(
""
, std::bitset<UCESB_MAP_BITSIZE>(
static_cast<
UcesbMapUType
>
(
map
)).to_string());
99
}
100
}
101
}
// namespace R3B
102
103
template
<>
104
class
fmt::formatter<
R3B
::UcesbMap>
105
{
106
public
:
107
constexpr
auto
parse
(format_parse_context& ctx)
108
{
109
if
(ctx.begin() == ctx.end())
110
{
111
return
ctx.end();
112
}
113
const
auto
* specifier_iter = ctx.begin();
114
if
(*specifier_iter ==
's'
or *specifier_iter ==
'b'
)
115
{
116
presentation_
= *specifier_iter;
117
++specifier_iter;
// NOLINT
118
}
119
120
if
(specifier_iter == ctx.end())
121
{
122
throw
fmt::format_error(
"UcesbMap format failed: missing right curly bracket!"
);
123
}
124
125
if
(*specifier_iter !=
'}'
)
126
{
127
throw
fmt::format_error(
"UcesbMap format failed: only one speicifier is allowed"
);
128
}
129
return
specifier_iter;
130
}
131
132
template
<
typename
FmtContent>
133
constexpr
auto
format
(
const
R3B::UcesbMap
& flag, FmtContent& ctn)
const
134
{
135
switch
(
presentation_
)
136
{
137
default
:
138
case
's'
:
139
return
fmt::format_to(ctn.out(),
"{}"
,
R3B::UcesbMap2String
(flag));
140
case
'b'
:
141
return
fmt::format_to(ctn.out(),
"0x{:b}"
,
static_cast<
R3B::UcesbMapUType
>
(flag));
142
}
143
}
144
145
private
:
146
char
presentation_
=
's'
;
147
};
UCESB_MAP_BITSIZE
constexpr auto UCESB_MAP_BITSIZE
Definition
R3BUcesbMappingFlag.h:24
fmt::formatter< R3B::UcesbMap >::parse
constexpr auto parse(format_parse_context &ctx)
Definition
R3BUcesbMappingFlag.h:107
fmt::formatter< R3B::UcesbMap >::presentation_
char presentation_
Definition
R3BUcesbMappingFlag.h:146
fmt::formatter< R3B::UcesbMap >::format
constexpr auto format(const R3B::UcesbMap &flag, FmtContent &ctn) const
Definition
R3BUcesbMappingFlag.h:133
map
STL class.
R3B
Definition
R3BNeulandAnalysisApp.cxx:44
R3B::operator<<
auto operator<<(std::ostream &ostream, const UcesbMap &map) -> std::ostream &
Definition
R3BUcesbMappingFlag.h:65
R3B::Side::right
@ right
Definition
R3BShared.h:114
R3B::Side::left
@ left
Definition
R3BShared.h:113
R3B::operator|
auto operator|(const UcesbMap &left, const UcesbMap &right) -> UcesbMap
Definition
R3BUcesbMappingFlag.h:45
R3B::operator|=
void operator|=(UcesbMap &left, const UcesbMap &right)
Definition
R3BUcesbMappingFlag.h:50
R3B::UcesbMap2String
auto UcesbMap2String(UcesbMap map) -> std::string
Definition
R3BUcesbMappingFlag.h:71
R3B::operator~
auto operator~(const UcesbMap &map) -> UcesbMap
Definition
R3BUcesbMappingFlag.h:60
R3B::operator&=
void operator&=(UcesbMap &left, const UcesbMap &right)
Definition
R3BUcesbMappingFlag.h:58
R3B::operator&
auto operator&(const UcesbMap &left, const UcesbMap &right) -> UcesbMap
Definition
R3BUcesbMappingFlag.h:52
R3B::UcesbMap
UcesbMap
Definition
R3BUcesbMappingFlag.h:29
R3B::UcesbMap::ctrl_mismatch
@ ctrl_mismatch
Definition
R3BUcesbMappingFlag.h:35
R3B::UcesbMap::ok
@ ok
Definition
R3BUcesbMappingFlag.h:39
R3B::UcesbMap::type_mismatch
@ type_mismatch
Definition
R3BUcesbMappingFlag.h:34
R3B::UcesbMap::ok_no_dest
@ ok_no_dest
Definition
R3BUcesbMappingFlag.h:40
R3B::UcesbMap::array_more
@ array_more
Definition
R3BUcesbMappingFlag.h:37
R3B::UcesbMap::not_found
@ not_found
Definition
R3BUcesbMappingFlag.h:33
R3B::UcesbMap::no_dest
@ no_dest
Definition
R3BUcesbMappingFlag.h:32
R3B::UcesbMap::array_fewer
@ array_fewer
Definition
R3BUcesbMappingFlag.h:36
R3B::UcesbMap::not_done
@ not_done
Definition
R3BUcesbMappingFlag.h:38
R3B::UcesbMap::zero
@ zero
Definition
R3BUcesbMappingFlag.h:30
R3B::UcesbMap::match
@ match
Definition
R3BUcesbMappingFlag.h:31
R3B::UcesbMapUType
std::underlying_type< UcesbMap >::type UcesbMapUType
Definition
R3BUcesbMappingFlag.h:43
r3bsource
base
utils
R3BUcesbMappingFlag.h
Generated by
1.18.0