32 TRGState(
unsigned bitSize,
unsigned value);
39 TRGState(
unsigned bitSize,
const bool*
const states);
42 TRGState(std::vector<unsigned>& states,
unsigned order);
45 TRGState(
const char*,
unsigned type);
56 unsigned size(
void)
const;
62 bool active(
unsigned bitPosition)
const;
72 void dump(
const std::string& message =
"",
73 const std::string& pre =
"")
const;
81 const TRGState&
set(
unsigned position,
bool state =
true);
86 const bool*
const array);
99 operator unsigned()
const;
102 operator unsigned long long()
const;
105 operator std::string()
const;
125 static unsigned toUnsigned(
unsigned n,
const bool* array);
130 static const unsigned _su;
158 for (
unsigned i = 0; i <
_n; i++)
168 const unsigned wp = a /
_bsu;
169 const unsigned bp = a %
_bsu;
170 if (
_state[wp] & (1 << bp))
182 std::cout <<
"TRGState::operator[] !!! bit size overflow"
183 <<
":bit size=" <<
_size <<
",specified position=" << a
187 const unsigned wp = a /
_bsu;
188 const unsigned bp = a %
_bsu;
189 if (
_state[wp] & (1 << bp))
196 TRGState::operator unsigned()
const
199 unsigned n = _size / _bsu;
200 if (_size % _bsu) ++n;
202 std::cout <<
"TRGState::operator unsigned() !!! bit size overflow"
203 <<
":bit size=" << _size <<
",max bit size with unsigned="
204 << _bsu << std::endl;
211 TRGState::operator
unsigned long long()
const
213 unsigned n = _size / _bsu;
214 if (_size % _bsu) ++n;
215 const unsigned c =
sizeof(
unsigned long long);
218 std::cout <<
"TRGState::operator unsigned long long() "
219 <<
"!!! bit size overflow"
220 <<
":bit size=" << _size
221 <<
",max bit size with unsigned long long="
225 unsigned long long a = 0;
226 const unsigned s = _bsu;
227 for (
unsigned i = 0; i < n; i++) {
228 const unsigned long long b = _state[i];
235 TRGState::operator std::string()
const
237 unsigned nWords = _size / _bsu;
238 if (_size % _bsu) ++nWords;
239 unsigned lastNHex = (_size % _bsu);
240 if (lastNHex == 0) lastNHex = 8;
242 lastNHex = lastNHex / 4;
243 if ((_size % _bsu) % 4) ++lastNHex;
245 std::stringstream t_stringstream;
246 t_stringstream << std::setw(lastNHex) << std::setfill(
'0') << std::hex << _state[nWords - 1];
247 for (
unsigned iWord = 1; iWord < nWords; iWord++) {
248 t_stringstream << std::setw(8) << std::setfill(
'0') << std::hex << _state[nWords - 1 - iWord];
250 return t_stringstream.str();
257 for (
unsigned i = 0; i <
_size; i++) {
258 const unsigned wp = i /
_bsu;
259 const unsigned bp = i %
_bsu;
260 if (
_state[wp] & (1 << bp))
272 for (
unsigned i = 0; i < n; i++) {
273 const unsigned wp = (p + i) /
_bsu;
274 const unsigned bp = (p + i) %
_bsu;
282 else std::cout <<
"NULL pointer found in TRGState::set"
292 for (
unsigned i = 0; i < n; i++) {
293 const unsigned wp = (p + i) /
_bsu;
294 const unsigned bp = (p + i) %
_bsu;
307 const unsigned wp = n /
_bsu;
308 const unsigned bp = n %
_bsu;
320 const unsigned n = s.size();
321 for (
unsigned i = 0; i < n; i++) {
322 const unsigned wp = (p + i) /
_bsu;
323 const unsigned bp = (p + i) %
_bsu;
337 if (n > 8) std::cout <<
"given array size(" << n <<
") is too big"
342 for (
unsigned i = 0; i < n; i++) {
344 const unsigned bp = i %
_bsu;
356 if (!
active())
return *
this;
358 if (a == 0)
return *
this;
360 for (
int i =
_size - 1; i >= 0; --i) {
374 for (
unsigned i = 0; i <
_n; i++)
A class to represent a state of multi bits.
TRGState(const TRGState &)=default
Default copy constructor.
unsigned _n
bit storage size.
unsigned * _state
bit state.
TRGState & shift(unsigned i)
shifts bits.
unsigned size(void) const
returns bit size.
virtual ~TRGState()
Destructor.
static unsigned toUnsigned(unsigned n, const bool *array)
Coverts from bool array to unsigned.
TRGState subset(unsigned i, unsigned n) const
returns subset from i with n bits.
void copy2bool(bool *array) const
returns a filled array.
static const unsigned _bsu
bit size of unsigned.
bool operator<(const TRGState &) const
Copy operator.
static const unsigned _su
size of unsigned.
const TRGState & set(unsigned position, bool state=true)
sets state at bit i.
TRGState & operator+=(const TRGState &)
appends TRGState (as MSB).
bool operator[](unsigned i) const
returns state of i'th bit.
TRGState & operator=(const TRGState &)
Copy operator.
bool active(void) const
returns true if there are active bits.
void clear(void)
clears state.
void dump(const std::string &message="", const std::string &pre="") const
dumps contents.
Abstract base class for different kinds of events.