| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* This file is a part of NA64SW software. | ||
| 2 | * Copyright (C) 2015-2022 NA64 Collaboration, CERN | ||
| 3 | * | ||
| 4 | * NA64SW is free software: you can redistribute it and/or modify | ||
| 5 | * it under the terms of the GNU General Public License as published by | ||
| 6 | * the Free Software Foundation, either version 3 of the License, or | ||
| 7 | * (at your option) any later version. | ||
| 8 | * | ||
| 9 | * This program is distributed in the hope that it will be useful, | ||
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | * GNU General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU General Public License | ||
| 15 | * along with this program. If not, see <https://www.gnu.org/licenses/>. */ | ||
| 16 | |||
| 17 | #pragma once | ||
| 18 | |||
| 19 | #include <cstdint> | ||
| 20 | #include <cstdlib> | ||
| 21 | #include <cassert> | ||
| 22 | #include <unordered_map> | ||
| 23 | |||
| 24 | #include "na64sw-config.h" | ||
| 25 | |||
| 26 | namespace na64dp { | ||
| 27 | |||
| 28 | ///\brief Track numerical identifier type | ||
| 29 | /// | ||
| 30 | /// Leftmost 8 bits are reserved for zone pattern information. | ||
| 31 | typedef uint32_t TrackID_t; | ||
| 32 | |||
| 33 | ///\brief Tracking zone ID type | ||
| 34 | typedef uint8_t ZoneID_t; | ||
| 35 | |||
| 36 | /**\brief A track ID type | ||
| 37 | * | ||
| 38 | * This object interface wraps a single number representing a track ID. This | ||
| 39 | * number encodes two fields: | ||
| 40 | * - a zone pattern identifying geometrical zones of detectors contributing | ||
| 41 | * to track; | ||
| 42 | * - a number of track of arbitrary meaning. | ||
| 43 | * */ | ||
| 44 | struct TrackID { | ||
| 45 | TrackID_t code; | ||
| 46 | |||
| 47 | static constexpr size_t numberBitlen = 24; | ||
| 48 | static constexpr TrackID_t numberMax = (1 << numberBitlen) - 1; | ||
| 49 | static constexpr ZoneID_t zoneMax = (1 << (sizeof(TrackID_t)*8 - numberBitlen)) - 1; | ||
| 50 | |||
| 51 | 16 | explicit TrackID( ZoneID_t zones, TrackID_t nTrack ) | |
| 52 | 16 | : code((zones << numberBitlen) | nTrack) | |
| 53 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | { assert(nTrack < numberMax); } |
| 54 | TrackID() : code(0x0) {} | ||
| 55 | ✗ | TrackID(const TrackID & o) : code(o.code) {} | |
| 56 | |||
| 57 | 80 | ZoneID_t zones() const { return (ZoneID_t) (code >> numberBitlen); } | |
| 58 | void zones(ZoneID_t); // TODO | ||
| 59 | TrackID_t number() const; | ||
| 60 | void number(TrackID_t); // TODO | ||
| 61 | //void assign_zone(ZoneID_t zid) { code |= (((TrackID_t) zid) << 24); } | ||
| 62 | //void reset_zones() { code &= (~(((TrackID_t) 0xf) << 24)); } | ||
| 63 | }; | ||
| 64 | |||
| 65 | inline bool operator==(const TrackID & k1, const TrackID & k2) | ||
| 66 | { return k1.code == k2.code; } | ||
| 67 | |||
| 68 | inline bool operator<(const TrackID & k1, const TrackID & k2) | ||
| 69 | { return k1.code < k2.code; } | ||
| 70 | |||
| 71 | |||
| 72 | /// Special type used in type traits | ||
| 73 | struct ZoneID { | ||
| 74 | ZoneID_t zoneCode; | ||
| 75 | ZoneID(TrackID tID) : zoneCode(tID.zones()) {} | ||
| 76 | }; | ||
| 77 | |||
| 78 | inline bool operator==(const ZoneID & k1, const ZoneID & k2) | ||
| 79 | { return k1.zoneCode == k2.zoneCode; } | ||
| 80 | |||
| 81 | inline bool operator<(const ZoneID & k1, const ZoneID & k2) | ||
| 82 | { return k1.zoneCode < k2.zoneCode; } | ||
| 83 | |||
| 84 | } // namespace na64dp | ||
| 85 | |||
| 86 | namespace std { | ||
| 87 | |||
| 88 | template <> struct hash<na64dp::TrackID> { | ||
| 89 | std::size_t operator()(const na64dp::TrackID & k) const { | ||
| 90 | return k.code; | ||
| 91 | } | ||
| 92 | }; | ||
| 93 | |||
| 94 | template<> | ||
| 95 | struct less<na64dp::TrackID> { | ||
| 96 | bool operator()(const na64dp::TrackID a, const na64dp::TrackID & b) const { | ||
| 97 | return a.code < b.code; | ||
| 98 | } | ||
| 99 | }; | ||
| 100 | |||
| 101 | template <> struct hash<na64dp::ZoneID> { | ||
| 102 | std::size_t operator()(const na64dp::ZoneID & k) const { | ||
| 103 | return k.zoneCode; | ||
| 104 | } | ||
| 105 | }; | ||
| 106 | |||
| 107 | template<> | ||
| 108 | struct less<na64dp::ZoneID> { | ||
| 109 | bool operator()(const na64dp::ZoneID a, const na64dp::ZoneID & b) const { | ||
| 110 | return a.zoneCode < b.zoneCode; | ||
| 111 | } | ||
| 112 | }; | ||
| 113 | |||
| 114 | } // namespace std | ||
| 115 | |||
| 116 |