15#include <fmt/format.h>
28void assertRange(
int a,
int b, T
s)
30 if (
a >
b ||
b -
a >=
sizeof(T) * 8) {
31 throw std::invalid_argument(fmt::format(
"Range [a,b]=[{0},{1}] is incorrect (max range={2}])",
a,
b,
sizeof(T) * 8));
36void setRangeFromIntegerFast(BitSet& bs,
int a,
int b, T
v)
38 assertRange<T>(
a,
b,
v);
42 for (
int i = 0;
i <=
b -
a;
i++) {
49T uint(
const BitSet& bs,
int a,
int b)
54 if (
a < 0 ||
b < 0 || (
b -
a) > (
sizeof(T) * 8) ||
a >= bs.size() ||
b >= bs.size()) {
55 throw std::out_of_range(fmt::format(
"Range [{0},{1}] out of range. bs.size()={2}",
a,
b, bs.size()));
58 for (T
i =
a;
i <=
b;
i++) {
60 value |= (
static_cast<T>(1) << (
i -
a));
67int appendT(BitSet& bs, T
val,
int n)
77 if (
n >
sizeof(T) * 8) {
78 throw std::invalid_argument(fmt::format(
"n={0} is invalid : should be between 0 and {1}",
82 for (T
i = 0; i < static_cast<T>(
n);
i++) {
83 T p =
static_cast<T>(1) <<
i;
93bool isValidString(std::string_view
s)
96 auto zeros = std::count(
begin(
s),
end(
s),
'0');
97 return s.size() == ones + zeros;
100void assertString(std::string_view
s)
102 if (!isValidString(
s)) {
103 throw std::invalid_argument(fmt::format(
"{0} is not a valid bitset string (should only get 0 and 1 in there",
s));
118 assertRange(1,
n - 1,
v);
127 assertRange(1,
n - 1,
v);
136 assertRange(1,
n - 1,
v);
145 assertRange(1,
n - 1,
v);
156 if (
len() != rhs.len()) {
159 for (
int i = 0;
i <
len();
i++) {
160 if (
get(
i) != rhs.get(
i)) {
169 return !(*
this == rhs);
180 return appendT<uint8_t>(*
this,
val,
n);
185 return appendT<uint16_t>(*
this,
val,
n);
190 return appendT<uint32_t>(*
this,
val,
n);
195 return appendT<uint64_t>(*
this,
val,
n);
200 for (
int i = 0;
i <
len();
i++) {
210 std::fill(begin(mBytes),
end(mBytes), 0);
217 for (
int i = 0;
i <
len();
i++) {
227 if (pos < 0 || pos >=
size()) {
228 throw std::out_of_range(fmt::format(
"pos {0} is out of bounds",
pos));
230 auto b = mBytes[
pos / 8];
231 return ((
b >> (
pos % 8)) & 1) == 1;
237 throw std::invalid_argument(
"n should be >= 0");
243 throw std::length_error(fmt::format(
"trying to allocate a bitset of more than {0} bytes",
BitSet::maxSize()));
245 auto nbytes = mBytes.size();
246 while (nbytes * 8 <
n) {
249 mBytes.resize(nbytes, 0);
250 mSize = mBytes.size() * 8;
257 throw std::length_error(fmt::format(
"cannot get {0} bits out of a bitset of size {1}",
n,
len()));
260 if (subbs.len() !=
n) {
261 throw std::logic_error(
"subset not of the expected len");
269 throw std::invalid_argument(fmt::format(
"cannot prune {0} bits",
n));
271 for (
int i = 0;
i <
len() -
n;
i++) {
283 throw std::invalid_argument(
"pos should be > 0");
301 if ((
pos + 1) > mLen) {
303 mMaxLen = std::max(mMaxLen, mLen);
309 if (mSize <
bytes.size() * 8) {
313 std::copy(
bytes.begin(),
bytes.end(), std::back_inserter(mBytes));
314 mBytes.resize(
bytes.size());
315 mLen = mBytes.size() * 8;
316 mMaxLen = std::max(mMaxLen, mLen);
324 throw std::invalid_argument(fmt::format(
"range [{0},{1}] is invalid : {0} > {1}",
a,
b));
326 if (
b -
a + 1 !=
s.size()) {
327 throw std::invalid_argument(fmt::format(
"range [{0},{1}] is not the same size as string={2}",
a,
b,
s));
332 for (
int i = 0;
i <
s.size();
i++) {
339 setRangeFromIntegerFast<uint8_t>(*
this,
a,
b,
v);
344 setRangeFromIntegerFast<uint16_t>(*
this,
a,
b,
v);
349 setRangeFromIntegerFast<uint32_t>(*
this,
a,
b,
v);
354 setRangeFromIntegerFast<uint64_t>(*
this,
a,
b,
v);
360 for (
int i = 0;
i <
len();
i++) {
373 for (
int i =
len() - 1;
i >= 0;
i--) {
386 auto msg = fmt::format(
"BitSet::subset : range [{},{}] is incorrect. size={}",
a,
b,
size());
387 throw std::invalid_argument(
msg);
391 for (
int i =
a;
i <=
b;
i++) {
399 return uint<uint8_t>(*
this,
a,
b);
404 return uint<uint16_t>(*
this,
a,
b);
409 return uint<uint32_t>(*
this,
a,
b);
414 return uint<uint64_t>(*
this,
a,
b);
429 ix %= ringBuffer.
len();
445 if (bs.
size() < 49) {
452 while (
i + 49 < bs.
len()) {
454 while (
i + 49 < bs.
len() && bs.
subset(
i,
i + 49) == syncWord) {
460 s += fmt::format(
"[{}SYNC]", nsync);
463 s += bs.
get(
i) ?
"1" :
"0";
467 for (
int j =
i;
j < bs.
len();
j++) {
468 s += bs.
get(
j) ?
"1" :
"0";
unsigned short int uint16_t
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error s
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char Directory with events to Events directory is and not inside events Show standalone event Run event generator maximum time bin of continuous for triggered for automatic continuous for automatic continuous triggered uint64_t
uint8_t uint8(int a, int b) const
uint16_t uint16(int a, int b) const
uint64_t uint64(int a, int b) const
void setFromBytes(gsl::span< uint8_t > bytes)
bool operator!=(const BitSet &rhs) const
std::string stringLSBLeft() const
void setRangeFromString(int a, int b, std::string_view s)
void setFast(int pos, bool val)
void setRangeFromUint(int a, int b, uint8_t v)
bool operator==(const BitSet &rhs) const
uint32_t uint32(int a, int b) const
BitSet subset(int a, int b) const
void set(int pos, bool val)
std::string stringLSBRight() const
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * value
GLboolean GLboolean GLboolean GLboolean a
void check(const std::vector< std::string > &arguments, const std::vector< ConfigParamSpec > &workflowOptions, const std::vector< DeviceSpec > &deviceSpecs, CheckMatrix &matrix)
int circularAppend(BitSet &bs, const BitSet &ringBuffer, int startBit, int n)
SampaHeader sampaSync()
The 50-bits Sampa SYNC word.
std::string compactString(const BitSet &bs)
Enum< T >::Iterator begin(Enum< T >)
std::ostream & operator<<(std::ostream &stream, o2::InteractionRecord const &ir)
uint64_t const void const *restrict const msg