 |
Belle II Software
release-05-02-19
|
14 #ifndef TRGState_FLAG_
15 #define TRGState_FLAG_
37 TRGState(
unsigned bitSize,
unsigned value);
43 TRGState(
unsigned bitSize,
const bool*
const states);
46 TRGState(std::vector<unsigned>& states,
unsigned order);
49 TRGState(
const char*,
unsigned type);
60 unsigned size(
void)
const;
66 bool active(
unsigned bitPosition)
const;
76 void dump(
const std::string& message =
"",
77 const std::string& pre =
"")
const;
85 const TRGState&
set(
unsigned position,
bool state =
true);
90 const bool*
const array);
103 operator unsigned()
const;
106 operator unsigned long long()
const;
109 operator std::string()
const;
129 static unsigned toUnsigned(
unsigned n,
const bool* array);
134 static const unsigned _su;
162 for (
unsigned i = 0; i <
_n; i++)
172 const unsigned wp = a /
_bsu;
173 const unsigned bp = a %
_bsu;
174 if (
_state[wp] & (1 << bp))
186 std::cout <<
"TRGState::operator[] !!! bit size overflow"
187 <<
":bit size=" <<
_size <<
",specified position=" << a
191 const unsigned wp = a /
_bsu;
192 const unsigned bp = a %
_bsu;
193 if (
_state[wp] & (1 << bp))
200 TRGState::operator unsigned()
const
203 unsigned n = _size / _bsu;
204 if (_size % _bsu) ++n;
206 std::cout <<
"TRGState::operator unsigned() !!! bit size overflow"
207 <<
":bit size=" << _size <<
",max bit size with unsigned="
208 << _bsu << std::endl;
215 TRGState::operator
unsigned long long()
const
217 unsigned n = _size / _bsu;
218 if (_size % _bsu) ++n;
219 const unsigned c =
sizeof(
unsigned long long);
222 std::cout <<
"TRGState::operator unsigned long long() "
223 <<
"!!! bit size overflow"
224 <<
":bit size=" << _size
225 <<
",max bit size with unsigned long long="
229 unsigned long long a = 0;
230 const unsigned s = _bsu;
231 for (
unsigned i = 0; i < n; i++) {
232 const unsigned long long b = _state[i];
239 TRGState::operator std::string()
const
241 unsigned nWords = _size / _bsu;
242 if (_size % _bsu) ++nWords;
243 unsigned lastNHex = (_size % _bsu);
244 if (lastNHex == 0) lastNHex = 8;
246 lastNHex = lastNHex / 4;
247 if ((_size % _bsu) % 4) ++lastNHex;
249 std::stringstream t_stringstream;
250 t_stringstream << std::setw(lastNHex) << std::setfill(
'0') << std::hex << _state[nWords - 1];
251 for (
unsigned iWord = 1; iWord < nWords; iWord++) {
252 t_stringstream << std::setw(8) << std::setfill(
'0') << std::hex << _state[nWords - 1 - iWord];
254 return t_stringstream.str();
261 for (
unsigned i = 0; i <
_size; i++) {
262 const unsigned wp = i /
_bsu;
263 const unsigned bp = i %
_bsu;
264 if (
_state[wp] & (1 << bp))
276 for (
unsigned i = 0; i < n; i++) {
277 const unsigned wp = (p + i) /
_bsu;
278 const unsigned bp = (p + i) %
_bsu;
286 else std::cout <<
"NULL pointer found in TRGState::set"
296 for (
unsigned i = 0; i < n; i++) {
297 const unsigned wp = (p + i) /
_bsu;
298 const unsigned bp = (p + i) %
_bsu;
311 const unsigned wp = n /
_bsu;
312 const unsigned bp = n %
_bsu;
324 const unsigned n = s.size();
325 for (
unsigned i = 0; i < n; i++) {
326 const unsigned wp = (p + i) /
_bsu;
327 const unsigned bp = (p + i) %
_bsu;
341 if (n > 8) std::cout <<
"given array size(" << n <<
") is too big"
346 for (
unsigned i = 0; i < n; i++) {
348 const unsigned bp = i %
_bsu;
360 if (!
active())
return *
this;
362 if (a == 0)
return *
this;
364 for (
int i =
_size - 1; i >= 0; --i) {
378 for (
unsigned i = 0; i <
_n; i++)
TRGState(unsigned bitSize=0)
Default constructor.
std::ostream & operator<<(std::ostream &output, const IntervalOfValidity &iov)
unsigned _n
bit storage size.
TRGState subset(unsigned i, unsigned n) const
returns subset from i with n bits.
A class to represent a state of multi bits.
static const unsigned _su
size of unsigned.
bool active(void) const
returns true if there are active bits.
void dump(const std::string &message="", const std::string &pre="") const
dumps contents.
const TRGState & set(unsigned position, bool state=true)
sets state at bit i.
TRGState & shift(unsigned i)
shifts bits.
static const unsigned _bsu
bit size of unsigned.
virtual ~TRGState()
Destructor.
Abstract base class for different kinds of events.
TRGState & operator=(const TRGState &)
Copy operator.
static unsigned toUnsigned(unsigned n, const bool *array)
Coverts from bool array to unsigned.
unsigned size(void) const
returns bit size.
bool operator<(const TRGState &) const
Copy operator.
bool operator[](unsigned i) const
returns state of i'th bit.
void clear(void)
clears state.
unsigned * _state
bit state.
void copy2bool(bool *array) const
returns a filled array.
TRGState & operator+=(const TRGState &)
appends TRGState (as MSB).