CbmRoot
Loading...
Searching...
No Matches
CbmRichAddress.h
Go to the documentation of this file.
1/* Copyright (C) 2024 Justus-Liebig-Universitaet Giessen, Giessen
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Martin Beyer [committer] */
4
10
11#pragma once
12
13#include <cstdint>
14#include <string>
15
34namespace CbmRichAddress
35{
47
48 inline constexpr uint32_t kCurrentVersion = 0;
49
50 // --- These values are not to be changed if backward compatibility
51 // --- shall be maintained.
52 inline constexpr int32_t kVersionSize = 4; // Bits for version number
53 inline constexpr int32_t kVersionShift = 28; // First bit for version number
54 inline constexpr int32_t kVersionMask = (1 << kVersionSize) - 1;
55
56 namespace Detail
57 {
58 // ----- Definition of address bit field ------------------------------
59 inline constexpr uint16_t kBits[kCurrentVersion + 1][static_cast<uint32_t>(RichElementLevel::kNumLevels)] = {
60
61 // Version 0
62 {
63 4, // system
64 1, // camera
65 4, // strip
66 3, // backplane
67 3, // pmt
68 6 // pixel
69 }};
70 // -------------------------------------------------------------------------
71
72 // ----- Bit shifts -----------------------------------------------------
73 inline constexpr int32_t kShift[kCurrentVersion + 1][static_cast<uint32_t>(RichElementLevel::kNumLevels)] = {
74 {0, kShift[0][0] + kBits[0][0], kShift[0][1] + kBits[0][1], kShift[0][2] + kBits[0][2],
75 kShift[0][3] + kBits[0][3], kShift[0][4] + kBits[0][4]}};
76 // -------------------------------------------------------------------------
77
78 // ----- Bit masks -----------------------------------------------------
79 inline constexpr int32_t kMask[kCurrentVersion + 1][static_cast<uint32_t>(RichElementLevel::kNumLevels)] = {
80 {(1 << kBits[0][0]) - 1, (1 << kBits[0][1]) - 1, (1 << kBits[0][2]) - 1, (1 << kBits[0][3]) - 1,
81 (1 << kBits[0][4]) - 1, (1 << kBits[0][5]) - 1}};
82 // -------------------------------------------------------------------------
83
84
85 } // namespace Detail
86
96 int32_t GetAddress(uint32_t camera = 0, uint32_t strip = 0, uint32_t backplane = 0, uint32_t pmt = 0,
97 uint32_t pixel = 0, uint32_t version = kCurrentVersion);
98
108 int32_t GetMotherAddress(int32_t address, int32_t level);
109
115 uint32_t GetElementId(int32_t address, int32_t level);
116
120 uint32_t GetSystemId(int32_t address);
121
129 uint32_t GetVersion(int32_t address);
130
138 int32_t SetElementId(int32_t address, int32_t level, uint32_t newId);
139
144 std::string ToString(int32_t address);
145
146} // namespace CbmRichAddress
constexpr int32_t kMask[kCurrentVersion+1][static_cast< uint32_t >(RichElementLevel::kNumLevels)]
constexpr int32_t kShift[kCurrentVersion+1][static_cast< uint32_t >(RichElementLevel::kNumLevels)]
constexpr uint16_t kBits[kCurrentVersion+1][static_cast< uint32_t >(RichElementLevel::kNumLevels)]
Functions to encode or decode the address field of RICH data.
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.
uint32_t GetVersion(int32_t address)
Extract version number.
constexpr int32_t kVersionMask
constexpr uint32_t kCurrentVersion
uint32_t GetSystemId(int32_t address)
Get system Id (should be integer value of ECbmModuleId::kRich)
constexpr int32_t kVersionSize
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.
int32_t GetAddress(uint32_t camera=0, uint32_t strip=0, uint32_t backplane=0, uint32_t pmt=0, uint32_t pixel=0, uint32_t version=kCurrentVersion)
Construct address.