CbmRoot
Loading...
Searching...
No Matches
CbmStsAddress.h
Go to the documentation of this file.
1/* Copyright (C) 2013-2020 GSI/JINR-LIT, Darmstadt/Dubna
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Volker Friese, Andrey Lebedev [committer] */
4
10#ifndef CBMSTSADDRESS_H
11#define CBMSTSADDRESS_H 1
12
14#include "CbmDefs.h" // for ECbmModuleId
15
16#include <cassert> // for assert
17#include <cstdint> // for uint32_t
18#include <sstream> // for string
19
20#include <xpu/defines.h> // for XPU_D
21
34
35
54{
55
56 inline constexpr uint32_t kCurrentVersion = 1;
57
58 // --- These values are not to be changed if backward compatibility
59 // --- shall be maintained.
60 inline constexpr int32_t kVersionSize = 4; // Bits for version number
61 inline constexpr int32_t kVersionShift = 28; // First bit for version number
62 inline constexpr int32_t kVersionMask = (1 << kVersionSize) - 1;
63
64 namespace Detail
65 {
66 // clang-format off
67 // ----- Definition of address bit field ------------------------------
68 inline constexpr uint16_t kBits[kCurrentVersion + 1][kStsNofLevels] = {
69
70 // Version 0 (until 23 August 2017)
71 {
72 4, // system
73 4, // unit / station
74 4, // ladder
75 1, // half-ladder
76 3, // module
77 2, // sensor
78 1 // side
79 },
80
81 // Version 1 (current, since 23 August 2017)
82 {
83 4, // system
84 6, // unit
85 5, // ladder
86 1, // half-ladder
87 5, // module
88 4, // sensor
89 1 // side
90 }
91
92 };
93 // -------------------------------------------------------------------------
94
95 // ----- Bit shifts -----------------------------------------------------
96 inline constexpr int32_t kShift[kCurrentVersion + 1][kStsNofLevels] = {
97 {0, kShift[0][0] + kBits[0][0], kShift[0][1] + kBits[0][1], kShift[0][2] + kBits[0][2], kShift[0][3] + kBits[0][3],
98 kShift[0][4] + kBits[0][4], kShift[0][5] + kBits[0][5]},
99
100 {0, kShift[1][0] + kBits[1][0], kShift[1][1] + kBits[1][1], kShift[1][2] + kBits[1][2], kShift[1][3] + kBits[1][3],
101 kShift[1][4] + kBits[1][4], kShift[1][5] + kBits[1][5]}};
102 // -------------------------------------------------------------------------
103
104 // ----- Bit masks -----------------------------------------------------
105 inline constexpr int32_t kMask[kCurrentVersion + 1][kStsNofLevels] = {
106 {(1 << kBits[0][0]) - 1, (1 << kBits[0][1]) - 1, (1 << kBits[0][2]) - 1, (1 << kBits[0][3]) - 1,
107 (1 << kBits[0][4]) - 1, (1 << kBits[0][5]) - 1, (1 << kBits[0][6]) - 1},
108
109 {(1 << kBits[1][0]) - 1, (1 << kBits[1][1]) - 1, (1 << kBits[1][2]) - 1, (1 << kBits[1][3]) - 1,
110 (1 << kBits[1][4]) - 1, (1 << kBits[1][5]) - 1, (1 << kBits[1][6]) - 1}};
111 // -------------------------------------------------------------------------
112 // clang-format on
113 } // Namespace Detail
114
115
126 int32_t GetAddress(uint32_t unit = 0, uint32_t ladder = 0, uint32_t halfladder = 0, uint32_t module = 0,
127 uint32_t sensor = 0, uint32_t side = 0, uint32_t version = kCurrentVersion);
128
129
134 int32_t GetAddress(uint32_t* elementId, uint32_t version);
135
136
146 int32_t GetMotherAddress(int32_t address, int32_t level);
147
148
154 uint32_t GetElementId(int32_t address, int32_t level);
155
156
160 ECbmModuleId GetSystemId(int32_t address);
161
162
170 uint32_t GetVersion(int32_t address);
171
172
180 int32_t SetElementId(int32_t address, int32_t level, uint32_t newId);
181
186 XPU_D inline int32_t UnpackDigiAddress(int32_t digiAddress)
187 {
188 using namespace Detail;
189 return digiAddress << kShift[1][kStsUnit] | ToIntegralType(ECbmModuleId::kSts) << kShift[1][kStsSystem]
190 | 1u << kVersionShift;
191 }
192
197 XPU_D inline int32_t PackDigiAddress(int32_t address)
198 {
199 using namespace Detail;
200 constexpr int32_t kDMask = kMask[1][kStsUnit] << kShift[1][kStsUnit] | kMask[1][kStsLadder] << kShift[1][kStsLadder]
201 | kMask[1][kStsHalfLadder] << kShift[1][kStsHalfLadder]
202 | kMask[1][kStsModule] << kShift[1][kStsModule];
203
204 int32_t ret = (address & kDMask) >> kShift[1][kStsUnit];
205
206#if XPU_IS_CPU
207 // Check that no bits were set, that are stripped by this function.
208 if (address != UnpackDigiAddress(ret)) {
209 LOG(error) << "Address " << address << " contains bits that are stripped by PackDigiAddress";
210 }
211#endif
212 assert(address == UnpackDigiAddress(ret));
213
214 return ret;
215 }
216
220 std::string ToString(int32_t address);
221
222} // Namespace CbmStsAddress
223
224
225#endif // CBMSTSADDRESS_H
XPU_D constexpr auto ToIntegralType(T enumerator) -> typename std::underlying_type< T >::type
Definition CbmDefs.h:29
ECbmModuleId
Definition CbmDefs.h:39
@ kSts
Silicon Tracking System.
EStsElementLevel
@ kStsModule
@ kStsLadder
@ kStsSystem
@ kStsSide
@ kStsNofLevels
@ kStsHalfLadder
@ kStsSensor
@ kStsUnit
constexpr uint16_t kBits[kCurrentVersion+1][kStsNofLevels]
constexpr int32_t kMask[kCurrentVersion+1][kStsNofLevels]
constexpr int32_t kShift[kCurrentVersion+1][kStsNofLevels]
Functions to encode or decode the address field of STS data.
constexpr int32_t kVersionMask
uint32_t GetVersion(int32_t address)
Extract version number.
int32_t GetMotherAddress(int32_t address, int32_t level)
Construct the address of an element from the address of a descendant element.
int32_t SetElementId(int32_t address, int32_t level, uint32_t newId)
Set the index of an element, leaving the other element levels untouched.
constexpr int32_t kVersionSize
int32_t GetAddress(uint32_t unit=0, uint32_t ladder=0, uint32_t halfladder=0, uint32_t module=0, uint32_t sensor=0, uint32_t side=0, uint32_t version=kCurrentVersion)
Construct address.
ECbmModuleId GetSystemId(int32_t address)
Get system Id (should be ECbmModuleId::kSts)
constexpr uint32_t kCurrentVersion
XPU_D int32_t PackDigiAddress(int32_t address)
Strip address to contain only unit, (half)ladder and module.
uint32_t GetElementId(int32_t address, int32_t level)
Get the index of an element.
constexpr int32_t kVersionShift
std::string ToString(int32_t address)
String output.
XPU_D int32_t UnpackDigiAddress(int32_t digiAddress)
Add version and system to compressed address that's stored in a digi.