clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -O3 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name State.cc -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/data/b2soft/buildbot/development/build -fcoverage-compilation-dir=/data/b2soft/buildbot/development/build -resource-dir /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/lib/clang/21 -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/c++ -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/c++/x86_64-redhat-linux -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/c++/backward -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/include -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/python3.12 -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/include/CLHEP -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/Geant4 -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/include/root -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/include/belle_legacy -I include/ -D _PACKAGE_="trg" -D G4UI_USE_TCSH -D RaveDllExport= -D HAS_SQLITE -D HAS_CALLGRIND -I include -I /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/libxml2 -internal-isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/bin/../lib64/gcc/x86_64-redhat-linux/15.2.0/../../../../include/c++ -internal-isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/bin/../lib64/gcc/x86_64-redhat-linux/15.2.0/../../../../include/c++/x86_64-redhat-linux -internal-isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/bin/../lib64/gcc/x86_64-redhat-linux/15.2.0/../../../../include/c++/backward -internal-isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/lib/clang/21/include -internal-isystem /usr/local/include -internal-isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/bin/../lib64/gcc/x86_64-redhat-linux/15.2.0/../../../../x86_64-redhat-linux/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-missing-braces -Wno-unused-command-line-argument -std=c++20 -fdeprecated-macro -ferror-limit 19 -fgnuc-version=4.2.1 -fno-implicit-modules -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /scan_build/2026-05-31-004316-385593-1 -x c++ trg/trg/src/State.cc
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | #include <algorithm> |
| 10 | #include <iostream> |
| 11 | #include <ctype.h> |
| 12 | #include <cstring> |
| 13 | #include "trg/trg/Utilities.h" |
| 14 | #include "trg/trg/State.h" |
| 15 | |
| 16 | using namespace std; |
| 17 | |
| 18 | namespace Belle2 { |
| 19 | |
| 20 | const unsigned |
| 21 | TRGState::_su = sizeof(unsigned); |
| 22 | |
| 23 | const unsigned |
| 24 | TRGState::_bsu = 8 * sizeof(unsigned); |
| 25 | |
| 26 | TRGState::TRGState(unsigned bitSize) |
| 27 | : _size(bitSize), |
| 28 | _n(0), |
| 29 | _state(0) |
| 30 | { |
| 31 | _n = _size / _bsu; |
| 32 | if (_size % _bsu) ++_n; |
| 33 | if (_n) |
| 34 | _state = (unsigned*) calloc(_n, _su); |
| 35 | } |
| 36 | |
| 37 | TRGState::TRGState(unsigned bitSize, unsigned value) |
| 38 | : _size(bitSize), |
| 39 | _n(0), |
| 40 | _state(0) |
| 41 | { |
| 42 | _n = _size / _bsu; |
| 43 | if (_size % _bsu) ++_n; |
| 44 | if (_n) |
| 45 | _state = (unsigned*) calloc(_n, _su); |
| 46 | |
| 47 | for (unsigned i = 0; i < bitSize; i++) { |
| 48 | const unsigned wp = i / _bsu; |
| 49 | const unsigned bp = i % _bsu; |
| 50 | if (value & (1 << i)) |
| 51 | _state[wp] |= (1 << bp); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | TRGState::TRGState(unsigned bitSize, const bool* const s) |
| 56 | : _size(bitSize), |
| 57 | _n(0), |
| 58 | _state(0) |
| 59 | { |
| 60 | |
| 61 | _n = _size / _bsu; |
| 62 | if (_size % _bsu) ++_n; |
| 63 | _state = (unsigned*) calloc(_n, _su); |
| 64 | |
| 65 | for (unsigned i = 0; i < _size; i++) { |
| 66 | const unsigned wp = i / _bsu; |
| 67 | const unsigned bp = i % _bsu; |
| 68 | if (s[i]) |
| 69 | _state[wp] |= (1 << bp); |
| 70 | else |
| 71 | _state[wp] &= ~(1 << bp); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | TRGState::TRGState(vector<bool> states) |
| 76 | : _size(0), |
| 77 | _n(0), |
| 78 | _state(0) |
| 79 | { |
| 80 | |
| 81 | _size = states.size(); |
| 82 | _n = _size / _bsu; |
| 83 | if (_size % _bsu) ++_n; |
| 84 | _state = (unsigned*) calloc(_n, _su); |
| 85 | |
| 86 | for (unsigned i = 0; i < _size; i++) { |
| 87 | const unsigned wp = i / _bsu; |
| 88 | const unsigned bp = i % _bsu; |
| 89 | if (states[i]) |
| 90 | _state[wp] |= (1 << bp); |
| 91 | else |
| 92 | _state[wp] &= ~(1 << bp); |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | TRGState::TRGState(vector<unsigned>& states, unsigned order) |
| 101 | : _size(0), |
| 102 | _n(0), |
| 103 | _state(0) |
| 104 | { |
| 105 | |
| 106 | _size = states.size() * _bsu; |
| 107 | _n = _size / _bsu; |
| 108 | _state = (unsigned*) calloc(_n, _su); |
| 109 | |
| 110 | for (unsigned i = 0; i < _n; i++) { |
| 111 | |
| 112 | if (order == 0) _state[i] = states[i]; |
| 113 | else _state[_n - 1 - i] = states[i]; |
| 114 | |
| 115 | |
| 116 | |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | TRGState::TRGState(const char* inChar, unsigned inType) |
| 121 | : _size(0), |
| 122 | _n(0), |
| 123 | _state(0) |
| 124 | { |
| 125 | |
| 126 | if (inType == 0) { |
| 127 | _size = strlen(inChar); |
| 128 | |
| 129 | for (unsigned iBit = 0; iBit < _size; iBit++) { |
| 130 | if (!(inChar[iBit] == '0' || inChar[iBit] == '1')) { |
| 131 | #ifdef TRG_DEBUG |
| 132 | cout << "TRGState::TRGState !!! invalid char found : aborted" |
| 133 | << endl; |
| 134 | cout << " invalid char = [" << inChar[iBit] |
| 135 | << "]" << endl; |
| 136 | #endif |
| 137 | return; |
| 138 | } |
| 139 | } |
| 140 | } else if (inType == 1) { |
| 141 | _size = strlen(inChar) * 4; |
| 142 | |
| 143 | for (unsigned iChar = 0; iChar < _size / 4; iChar++) { |
| 144 | if (!isxdigit(inChar[iChar])) { |
| 145 | #ifdef TRG_DEBUG |
| 146 | cout << "TRGState::TRGState !!! invalid char found : aborted" |
| 147 | << endl; |
| 148 | cout << " invalid char = [" |
| 149 | << inChar[iChar] << "]" << endl; |
| 150 | #endif |
| 151 | return; |
| 152 | } |
| 153 | } |
| 154 | } else { |
| 155 | #ifdef TRG_DEBUG |
| 156 | cout << "TRGState::TRGState !!! invalid type : aborted" |
| 157 | << endl; |
| 158 | cout << " invalid type = " << inType |
| 159 | << endl; |
| 160 | #endif |
| 161 | return; |
| 162 | } |
| 163 | |
| 164 | _n = _size / _bsu; |
| 165 | if (_size % _bsu) ++_n; |
| 166 | _state = (unsigned*) calloc(_n, _su); |
| 167 | if (inType == 0) { |
| 168 | for (unsigned iBit = 0; iBit < _size; iBit++) { |
| 169 | const unsigned wp = iBit / _bsu; |
| 170 | const unsigned bp = iBit % _bsu; |
| 171 | if (inChar[_size - 1 - iBit] == '1') |
| 172 | _state[wp] |= (1 << bp); |
| 173 | else |
| 174 | _state[wp] &= ~(1 << bp); |
| 175 | } |
| 176 | } else if (inType == 1) { |
| 177 | for (unsigned iChar = 0; iChar < _size / 4; iChar++) { |
| 178 | if (iChar % 8 == 0) _state[iChar / 8] = 0; |
| 179 | short unsigned t_int; |
| 180 | unsigned charP = _size / 4 - 1 - iChar; |
| 181 | if (inChar[charP] > 47 && inChar[charP] < 58) t_int = inChar[charP] - 48; |
| 182 | else t_int = inChar[charP] - 97 + 10; |
| 183 | _state[iChar / 8] += t_int << ((iChar % 8) * 4); |
| 184 | } |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | TRGState::~TRGState() |
| 189 | { |
| 190 | if (_state) |
| 191 | free(_state); |
| 192 | } |
| 193 | |
| 194 | void |
| 195 | TRGState::dump(const string& msg, |
| 196 | const string& pre) const |
| 197 | { |
| 198 | |
| 199 | |
| 200 | bool large = (_size > 60) || msg.find("large") != string::npos; |
| 201 | |
| 202 | if (! large) { |
| 203 | cout << pre << "size=" << _size << ","; |
| 204 | for (unsigned i = 0; i < _size; i++) { |
| 205 | const unsigned j = _size - i - 1; |
| 206 | if ((j % 8) == 7) |
| 207 | cout << "_"; |
| 208 | if ((* this)[j]) |
| 209 | cout << "1"; |
| 210 | else |
| 211 | cout << "0"; |
| 212 | } |
| 213 | cout << dec << endl; |
| 214 | } else { |
| 215 | cout << pre << "size=" << _size << endl; |
| 216 | |
| 217 | const unsigned nPerLines = 64; |
| 218 | const unsigned lines = _size / nPerLines + 1; |
| 219 | const unsigned rem = _size % nPerLines; |
| 220 | |
| 221 | cout << "TRGState" << |
| 222 | " +56 +48 +40 +32 +24 +16 +8" |
| 223 | << " +0" << endl; |
| 224 | |
| 225 | bool skipLast = false; |
| 226 | for (unsigned i = 0; i < lines; i++) { |
| 227 | const unsigned n0 = (i == 0) ? rem - 1 : nPerLines - 1; |
| 228 | const int n1 = 0; |
| 229 | const int os = (lines - i - 1) * nPerLines; |
| 230 | |
| 231 | const string b = TRGUtilities::itostring(os); |
| 232 | |
| 233 | TRGState s = subset(n1 + os, n0 - n1 + 1); |
| 234 | |
| 235 | |
| 236 | |
| 237 | bool skip = false; |
| 238 | if (! s.active()) |
| 239 | skip = true; |
| 240 | |
| 241 | if (skip) { |
| 242 | if (!skipLast) { |
| 243 | cout << "... (all zero)" << endl; |
| 244 | } |
| 245 | |
| 246 | skipLast = true; |
| 247 | continue; |
| 248 | } |
| 249 | |
| 250 | skipLast = false; |
| 251 | |
| 252 | cout.width(5); |
| 253 | cout << b; |
| 254 | cout << " "; |
| 255 | |
| 256 | if (i == 0) { |
| 257 | unsigned n = nPerLines - rem + (nPerLines - rem) / 8; |
| 258 | if (rem % 8) ++n; |
| 259 | for (unsigned j = 0; j < n; j++) |
| 260 | cout << " "; |
| 261 | } |
| 262 | |
| 263 | for (int j = n0; j >= n1; --j) { |
| 264 | const unsigned v = (* this)[j + os]; |
| 265 | |
| 266 | if ((j % 8) == 7) |
| 267 | cout << "_"; |
| 268 | if (v) |
| 269 | cout << "1"; |
| 270 | else |
| 271 | cout << "0"; |
| 272 | } |
| 273 | cout << endl; |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | |
| 278 | |
| 279 | |
| 280 | |
| 281 | |
| 282 | |
| 283 | |
| 284 | |
| 285 | |
| 286 | |
| 287 | |
| 288 | |
| 289 | |
| 290 | |
| 291 | |
| 292 | |
| 293 | |
| 294 | |
| 295 | |
| 296 | |
| 297 | |
| 298 | |
| 299 | |
| 300 | |
| 301 | |
| 302 | |
| 303 | |
| 304 | |
| 305 | |
| 306 | |
| 307 | |
| 308 | } |
| 309 | |
| 310 | TRGState& |
| 311 | TRGState::operator+=(const TRGState& a) |
| 312 | { |
| 313 | |
| 314 | |
| 315 | const unsigned sizeNew = _size + a.size(); |
| 316 | const unsigned sizeMax = _n * _bsu; |
| 317 | const unsigned oldSize = _size; |
| 318 | |
| 319 | |
| 320 | if (sizeNew > sizeMax) { |
| 321 | unsigned nNew = sizeNew / _bsu; |
| 322 | if (sizeNew % _bsu) ++nNew; |
| 323 | unsigned* tmp = (unsigned*) calloc(nNew, _su); |
| 324 | for (unsigned i = 0; i < _n; i++) { |
| 325 | tmp[i] = _state[i]; |
| 326 | } |
| 327 | if (_state) |
| 328 | free(_state); |
| 329 | _state = tmp; |
| 330 | _n = nNew; |
| 331 | } |
| 332 | _size = sizeNew; |
| 333 | |
| 334 | for (unsigned i = 0; i < a.size(); i++) { |
| 335 | unsigned j = i + oldSize; |
| 336 | const unsigned wp = j / _bsu; |
| 337 | const unsigned bp = j % _bsu; |
| 338 | if (a[i]) |
| 339 | _state[wp] |= (1 << bp); |
| 340 | else |
| 341 | _state[wp] &= ~(1 << bp); |
| 342 | |
| 343 | |
| 344 | |
| 345 | |
| 346 | } |
| 347 | |
| 348 | return (* this); |
| 349 | } |
| 350 | |
| 351 | TRGState |
| 352 | TRGState::subset(unsigned s, unsigned n) const |
| 353 | { |
| 354 | vector<bool> stack; |
| 355 | for (unsigned i = s; i < s + n; i++) { |
| 356 | if ((* this)[i]) |
| 357 | stack.push_back(true); |
| 358 | else |
| 359 | stack.push_back(false); |
| 360 | } |
| 361 | return TRGState(stack); |
| 362 | } |
| 363 | |
| 364 | TRGState& TRGState::operator=(const TRGState& a) |
| 365 | { |
| 366 | if (_state) |
| 367 | free(_state); |
| 368 | |
| 369 | _size = a._size; |
| 370 | _n = a._n; |
| 371 | _state = (unsigned*) calloc(_n, _su); |
| 372 | for (unsigned i = 0; i < _n; i++) { |
| 373 | _state[i] = a._state[i]; |
| 374 | } |
| 375 | |
| 376 | return * this; |
| 377 | } |
| 378 | |
| 379 | bool |
| 380 | TRGState::operator<(const TRGState& a) const |
| 381 | { |
| 382 | const unsigned long long n0(* this); |
| 1 | Calling 'TRGState::operator unsigned long long' | |
|
| 383 | const unsigned long long n1(a); |
| 384 | if (n0 < n1) |
| 385 | return true; |
| 386 | return false; |
| 387 | } |
| 388 | |
| 389 | } |
| 390 | |
| 391 | namespace std { |
| 392 | |
| 393 | ostream& |
| 394 | operator<<(ostream& out, const Belle2::TRGState& s) |
| 395 | { |
| 396 | for (unsigned i = 0; i < s.size(); i++) { |
| 397 | const unsigned j = s.size() - i - 1; |
| 398 | if (s.active(j)) |
| 399 | out << "1"; |
| 400 | else |
| 401 | out << "0"; |
| 402 | } |
| 403 | return out; |
| 404 | } |
| 405 | |
| 406 | } |
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | #ifndef TRGState_FLAG_ |
| 10 | #define TRGState_FLAG_ |
| 11 | |
| 12 | #include <vector> |
| 13 | #include <iomanip> |
| 14 | #include <iostream> |
| 15 | #include <sstream> |
| 16 | |
| 17 | namespace Belle2 { |
| 18 | |
| 19 | |
| 20 | class TRGState { |
| 21 | |
| 22 | public: |
| 23 | |
| 24 | |
| 25 | TRGState(unsigned bitSize = 0); |
| 26 | |
| 27 | |
| 28 | TRGState(unsigned bitSize, unsigned value); |
| 29 | |
| 30 | |
| 31 | |
| 32 | TRGState(std::vector<bool> states); |
| 33 | |
| 34 | |
| 35 | TRGState(unsigned bitSize, const bool* const states); |
| 36 | |
| 37 | |
| 38 | TRGState(std::vector<unsigned>& states, unsigned order); |
| 39 | |
| 40 | |
| 41 | TRGState(const char*, unsigned type); |
| 42 | |
| 43 | |
| 44 | TRGState(const TRGState&) = default; |
| 45 | |
| 46 | |
| 47 | virtual ~TRGState(); |
| 48 | |
| 49 | public: |
| 50 | |
| 51 | |
| 52 | unsigned size(void) const; |
| 53 | |
| 54 | |
| 55 | bool active(void) const; |
| 56 | |
| 57 | |
| 58 | bool active(unsigned bitPosition) const; |
| 59 | |
| 60 | |
| 61 | void copy2bool(bool* array) const; |
| 62 | |
| 63 | |
| 64 | TRGState subset(unsigned i, unsigned n) const; |
| 65 | |
| 66 | |
| 67 | |
| 68 | void dump(const std::string& message = "", |
| 69 | const std::string& pre = "") const; |
| 70 | |
| 71 | public: |
| 72 | |
| 73 | |
| 74 | void clear(void); |
| 75 | |
| 76 | |
| 77 | const TRGState& set(unsigned position, bool state = true); |
| 78 | |
| 79 | |
| 80 | const TRGState& set(unsigned position, |
| 81 | unsigned size, |
| 82 | const bool* const array); |
| 83 | |
| 84 | |
| 85 | const TRGState& set(unsigned position, |
| 86 | unsigned size, |
| 87 | unsigned value); |
| 88 | |
| 89 | |
| 90 | const TRGState& set(unsigned position, const TRGState&); |
| 91 | |
| 92 | public: |
| 93 | |
| 94 | |
| 95 | operator unsigned() const; |
| 96 | |
| 97 | |
| 98 | operator unsigned long long() const; |
| 99 | |
| 100 | |
| 101 | operator std::string() const; |
| 102 | |
| 103 | |
| 104 | TRGState& operator+=(const TRGState&); |
| 105 | |
| 106 | |
| 107 | bool operator[](unsigned i) const; |
| 108 | |
| 109 | |
| 110 | TRGState& operator=(const TRGState&); |
| 111 | |
| 112 | |
| 113 | bool operator<(const TRGState&) const; |
| 114 | |
| 115 | |
| 116 | TRGState& shift(unsigned i); |
| 117 | |
| 118 | public: |
| 119 | |
| 120 | |
| 121 | static unsigned toUnsigned(unsigned n, const bool* array); |
| 122 | |
| 123 | private: |
| 124 | |
| 125 | |
| 126 | static const unsigned _su; |
| 127 | |
| 128 | |
| 129 | static const unsigned _bsu; |
| 130 | |
| 131 | |
| 132 | unsigned _size; |
| 133 | |
| 134 | |
| 135 | unsigned _n; |
| 136 | |
| 137 | |
| 138 | unsigned* _state; |
| 139 | }; |
| 140 | |
| 141 | |
| 142 | |
| 143 | inline |
| 144 | unsigned |
| 145 | TRGState::size(void) const |
| 146 | { |
| 147 | return _size; |
| 148 | } |
| 149 | |
| 150 | inline |
| 151 | bool |
| 152 | TRGState::active(void) const |
| 153 | { |
| 154 | for (unsigned i = 0; i < _n; i++) |
| 155 | if (_state[i]) |
| 156 | return true; |
| 157 | return false; |
| 158 | } |
| 159 | |
| 160 | inline |
| 161 | bool |
| 162 | TRGState::active(unsigned a) const |
| 163 | { |
| 164 | const unsigned wp = a / _bsu; |
| 165 | const unsigned bp = a % _bsu; |
| 166 | if (_state[wp] & (1 << bp)) |
| 167 | return true; |
| 168 | else |
| 169 | return false; |
| 170 | } |
| 171 | |
| 172 | inline |
| 173 | bool |
| 174 | TRGState::operator[](unsigned a) const |
| 175 | { |
| 176 | #ifdef TRG_DEBUG |
| 177 | if (a >= _size) |
| 178 | std::cout << "TRGState::operator[] !!! bit size overflow" |
| 179 | << ":bit size=" << _size << ",specified position=" << a |
| 180 | << std::endl; |
| 181 | #endif |
| 182 | |
| 183 | const unsigned wp = a / _bsu; |
| 184 | const unsigned bp = a % _bsu; |
| 185 | if (_state[wp] & (1 << bp)) |
| 186 | return true; |
| 187 | else |
| 188 | return false; |
| 189 | } |
| 190 | |
| 191 | inline |
| 192 | TRGState::operator unsigned() const |
| 193 | { |
| 194 | #ifdef TRG_DEBUG |
| 195 | unsigned n = _size / _bsu; |
| 196 | if (_size % _bsu) ++n; |
| 197 | if (n > 1) |
| 198 | std::cout << "TRGState::operator unsigned() !!! bit size overflow" |
| 199 | << ":bit size=" << _size << ",max bit size with unsigned=" |
| 200 | << _bsu << std::endl; |
| 201 | #endif |
| 202 | return _state[0]; |
| 203 | |
| 204 | } |
| 205 | |
| 206 | inline |
| 207 | TRGState::operator unsigned long long() const |
| 208 | { |
| 209 | unsigned n = _size / _bsu; |
| 210 | if (_size % _bsu) ++n; |
| 2 | | Assuming the condition is false | |
|
| |
| 211 | const unsigned c = sizeof(unsigned long long); |
| 212 | if (n > c) |
| |
| |
| 213 | #ifdef TRG_DEBUG |
| 214 | std::cout << "TRGState::operator unsigned long long() " |
| 215 | << "!!! bit size overflow" |
| 216 | << ":bit size=" << _size |
| 217 | << ",max bit size with unsigned long long=" |
| 218 | << c << std::endl; |
| 219 | #endif |
| 220 | n = c; |
| 221 | unsigned long long a = 0; |
| 222 | const unsigned s = _bsu; |
| 223 | for (unsigned i = 0; i < n; i++) { |
| 6 | | Loop condition is true. Entering loop body | |
|
| 7 | | Loop condition is true. Entering loop body | |
|
| 8 | | The value 2 is assigned to 'i' | |
|
| 9 | | Loop condition is true. Entering loop body | |
|
| 224 | const unsigned long long b = _state[i]; |
| |
| 225 | a += b << (i * s); |
| 11 | | The result of left shift is undefined because the right operand '64' is not smaller than 64, the capacity of 'unsigned long long' |
|
| 226 | } |
| 227 | return a; |
| 228 | } |
| 229 | |
| 230 | inline |
| 231 | TRGState::operator std::string() const |
| 232 | { |
| 233 | unsigned nWords = _size / _bsu; |
| 234 | if (_size % _bsu) ++nWords; |
| 235 | unsigned lastNHex = (_size % _bsu); |
| 236 | if (lastNHex == 0) lastNHex = 8; |
| 237 | else { |
| 238 | lastNHex = lastNHex / 4; |
| 239 | if ((_size % _bsu) % 4) ++lastNHex; |
| 240 | } |
| 241 | std::stringstream t_stringstream; |
| 242 | t_stringstream << std::setw(lastNHex) << std::setfill('0') << std::hex << _state[nWords - 1]; |
| 243 | for (unsigned iWord = 1; iWord < nWords; iWord++) { |
| 244 | t_stringstream << std::setw(8) << std::setfill('0') << std::hex << _state[nWords - 1 - iWord]; |
| 245 | } |
| 246 | return t_stringstream.str(); |
| 247 | } |
| 248 | |
| 249 | inline |
| 250 | void |
| 251 | TRGState::copy2bool(bool* a) const |
| 252 | { |
| 253 | for (unsigned i = 0; i < _size; i++) { |
| 254 | const unsigned wp = i / _bsu; |
| 255 | const unsigned bp = i % _bsu; |
| 256 | if (_state[wp] & (1 << bp)) |
| 257 | a[i] = true; |
| 258 | else |
| 259 | a[i] = false; |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | inline |
| 264 | const TRGState& |
| 265 | TRGState::set(unsigned p, unsigned n, const bool* const a) |
| 266 | { |
| 267 | if (a) { |
| 268 | for (unsigned i = 0; i < n; i++) { |
| 269 | const unsigned wp = (p + i) / _bsu; |
| 270 | const unsigned bp = (p + i) % _bsu; |
| 271 | if (a[i]) |
| 272 | _state[wp] |= (1 << bp); |
| 273 | else |
| 274 | _state[wp] &= ~(1 << bp); |
| 275 | } |
| 276 | } |
| 277 | #ifdef TRG_DEBUG |
| 278 | else std::cout << "NULL pointer found in TRGState::set" |
| 279 | << std::endl; |
| 280 | #endif |
| 281 | return * this; |
| 282 | } |
| 283 | |
| 284 | inline |
| 285 | const TRGState& |
| 286 | TRGState::set(unsigned p, unsigned n, unsigned a) |
| 287 | { |
| 288 | for (unsigned i = 0; i < n; i++) { |
| 289 | const unsigned wp = (p + i) / _bsu; |
| 290 | const unsigned bp = (p + i) % _bsu; |
| 291 | if (a & (1 << i)) |
| 292 | _state[wp] |= (1 << bp); |
| 293 | else |
| 294 | _state[wp] &= ~(1 << bp); |
| 295 | } |
| 296 | return * this; |
| 297 | } |
| 298 | |
| 299 | inline |
| 300 | const TRGState& |
| 301 | TRGState::set(unsigned n, bool a) |
| 302 | { |
| 303 | const unsigned wp = n / _bsu; |
| 304 | const unsigned bp = n % _bsu; |
| 305 | if (a) |
| 306 | _state[wp] |= (1 << bp); |
| 307 | else |
| 308 | _state[wp] &= ~(1 << bp); |
| 309 | return * this; |
| 310 | } |
| 311 | |
| 312 | inline |
| 313 | const TRGState& |
| 314 | TRGState::set(unsigned p, const TRGState& s) |
| 315 | { |
| 316 | const unsigned n = s.size(); |
| 317 | for (unsigned i = 0; i < n; i++) { |
| 318 | const unsigned wp = (p + i) / _bsu; |
| 319 | const unsigned bp = (p + i) % _bsu; |
| 320 | if (s[i]) |
| 321 | _state[wp] |= (1 << bp); |
| 322 | else |
| 323 | _state[wp] &= ~(1 << bp); |
| 324 | } |
| 325 | return * this; |
| 326 | } |
| 327 | |
| 328 | inline |
| 329 | unsigned |
| 330 | TRGState::toUnsigned(unsigned n, const bool* a) |
| 331 | { |
| 332 | #ifdef TRG_DEBUG |
| 333 | if (n > 8) std::cout << "given array size(" << n << ") is too big" |
| 334 | << std::endl; |
| 335 | #endif |
| 336 | |
| 337 | unsigned b = 0; |
| 338 | for (unsigned i = 0; i < n; i++) { |
| 339 | if (a[i]) { |
| 340 | const unsigned bp = i % _bsu; |
| 341 | b |= (1 << bp); |
| 342 | } |
| 343 | } |
| 344 | return b; |
| 345 | } |
| 346 | |
| 347 | inline |
| 348 | TRGState& |
| 349 | TRGState::shift(unsigned a) |
| 350 | { |
| 351 | |
| 352 | if (! active()) return * this; |
| 353 | |
| 354 | if (a == 0) return * this; |
| 355 | |
| 356 | for (int i = _size - 1; i >= 0; --i) { |
| 357 | if (i < int(a)) |
| 358 | set(i, false); |
| 359 | else |
| 360 | set(i, active(i - a)); |
| 361 | } |
| 362 | |
| 363 | return * this; |
| 364 | } |
| 365 | |
| 366 | inline |
| 367 | void |
| 368 | TRGState::clear(void) |
| 369 | { |
| 370 | for (unsigned i = 0; i < _n; i++) |
| 371 | _state[i] = 0; |
| 372 | } |
| 373 | |
| 374 | } |
| 375 | |
| 376 | |
| 377 | |
| 378 | namespace std { |
| 379 | |
| 380 | ostream& operator<<(ostream&, const Belle2::TRGState&); |
| 381 | |
| 382 | } |
| 383 | |
| 384 | #endif /* TRGState_FLAG_ */ |