 |
Belle II Software
release-05-01-25
|
18 #include "trg/trg/Utilities.h"
19 #include "trg/trg/State.h"
30 TRGState::_su =
sizeof(unsigned);
33 TRGState::_bsu = 8 *
sizeof(unsigned);
35 TRGState::TRGState(
unsigned bitSize)
56 for (
unsigned i = 0; i < bitSize; i++) {
57 const unsigned wp = i /
_bsu;
58 const unsigned bp = i %
_bsu;
74 for (
unsigned i = 0; i <
_size; i++) {
75 const unsigned wp = i /
_bsu;
76 const unsigned bp = i %
_bsu;
90 _size = states.size();
95 for (
unsigned i = 0; i <
_size; i++) {
96 const unsigned wp = i /
_bsu;
97 const unsigned bp = i %
_bsu;
119 for (
unsigned i = 0; i <
_n; i++) {
121 if (order == 0)
_state[i] = states[i];
122 else _state[
_n - 1 - i] = states[i];
136 _size = strlen(inChar);
138 for (
unsigned iBit = 0; iBit <
_size; iBit++) {
139 if (!(inChar[iBit] ==
'0' || inChar[iBit] ==
'1')) {
141 cout <<
"TRGState::TRGState !!! invalid char found : aborted"
143 cout <<
" invalid char = [" << inChar[iBit]
149 }
else if (inType == 1) {
150 _size = strlen(inChar) * 4;
152 for (
unsigned iChar = 0; iChar <
_size / 4; iChar++) {
153 if (!isxdigit(inChar[iChar])) {
155 cout <<
"TRGState::TRGState !!! invalid char found : aborted"
157 cout <<
" invalid char = ["
158 << inChar[iChar] <<
"]" << endl;
165 cout <<
"TRGState::TRGState !!! invalid type : aborted"
167 cout <<
" invalid type = " << inType
177 for (
unsigned iBit = 0; iBit <
_size; iBit++) {
178 const unsigned wp = iBit /
_bsu;
179 const unsigned bp = iBit %
_bsu;
180 if (inChar[
_size - 1 - iBit] ==
'1')
185 }
else if (inType == 1) {
186 for (
unsigned iChar = 0; iChar <
_size / 4; iChar++) {
187 if (iChar % 8 == 0)
_state[iChar / 8] = 0;
188 short unsigned t_int;
189 unsigned charP =
_size / 4 - 1 - iChar;
190 if (inChar[charP] > 47 && inChar[charP] < 58) t_int = inChar[charP] - 48;
191 else t_int = inChar[charP] - 97 + 10;
192 _state[iChar / 8] += t_int << ((iChar % 8) * 4);
205 const string& pre)
const
209 bool large = (
_size > 60) || msg.find(
"large") != string::npos;
212 cout << pre <<
"size=" <<
_size <<
",";
213 for (
unsigned i = 0; i <
_size; i++) {
214 const unsigned j =
_size - i - 1;
224 cout << pre <<
"size=" <<
_size << endl;
226 const unsigned nPerLines = 64;
227 const unsigned lines =
_size / nPerLines + 1;
228 const unsigned rem =
_size % nPerLines;
230 cout <<
"TRGState" <<
231 " +56 +48 +40 +32 +24 +16 +8"
234 bool skipLast =
false;
235 for (
unsigned i = 0; i < lines; i++) {
236 const unsigned n0 = (i == 0) ? rem - 1 : nPerLines - 1;
238 const int os = (lines - i - 1) * nPerLines;
250 if (skip && (! skipLast)) {
251 cout <<
"... (all zero)" << endl;
267 unsigned n = nPerLines - rem + (nPerLines - rem) / 8;
269 for (
unsigned j = 0; j < n; j++)
273 for (
int j = n0; j >= n1; --j) {
274 const unsigned v = (* this)[j + os];
325 const unsigned sizeNew =
_size + a.size();
326 const unsigned sizeMax =
_n *
_bsu;
327 const unsigned oldSize =
_size;
330 if (sizeNew > sizeMax) {
331 unsigned nNew = sizeNew /
_bsu;
332 if (sizeNew %
_bsu) ++nNew;
333 unsigned* tmp = (
unsigned*) calloc(nNew,
_su);
334 for (
unsigned i = 0; i <
_n; i++) {
344 for (
unsigned i = 0; i < a.size(); i++) {
345 unsigned j = i + oldSize;
346 const unsigned wp = j /
_bsu;
347 const unsigned bp = j %
_bsu;
365 for (
unsigned i = s; i < s + n; i++) {
367 stack.push_back(
true);
369 stack.push_back(
false);
383 for (
unsigned i = 0; i <
_n; i++) {
393 const unsigned long long n0(*
this);
394 const unsigned long long n1(a);
408 for (
unsigned i = 0; i < s.size(); i++) {
409 const unsigned j = s.size() - i - 1;
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.
void dump(const std::string &message="", const std::string &pre="") const
dumps contents.
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 std::string itostring(int i)
converts int to string. (Use boost::lexical_cast)
bool operator<(const TRGState &) const
Copy operator.
unsigned * _state
bit state.
TRGState & operator+=(const TRGState &)
appends TRGState (as MSB).