CbmRoot
Loading...
Searching...
No Matches
CbmFsdAddress.h
Go to the documentation of this file.
1/* Copyright (C) 2023 Physikalisches Institut, Eberhard Karls Universitaet Tuebingen, Tuebingen
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Volker Friese, Andrey Lebedev, Lukas Chlad [committer] */
4
13#ifndef CBMFSDADDRESS_H
14#define CBMFSDADDRESS_H 1
15
16#include "CbmDefs.h" // for ECbmModuleId
17
18#include <cassert> // for assert
19#include <cstdint> // for uint32_t
20#include <sstream> // for string
21
38{
40 enum class Level
41 {
42 System,
43 Unit,
44 Module,
47 };
48
49 inline constexpr uint32_t kCurrentVersion = 0;
50
51 // --- These values are not to be changed if backward compatibility
52 // --- shall be maintained.
53 inline constexpr int32_t kVersionSize = 4; // Bits for version number
54 inline constexpr int32_t kVersionShift = 28; // First bit for version number
55 inline constexpr int32_t kVersionMask = (1 << kVersionSize) - 1;
56
57 namespace Detail
58 {
59 // clang-format off
60 // ----- Definition of address bit field ------------------------------
61 inline constexpr uint16_t kBits[kCurrentVersion + 1][static_cast<uint32_t>(CbmFsdAddress::Level::NumLevels)] = {
62
63 // Version 0
64 {
65 4, // system
66 4, // unit
67 15, // module
68 2 // photodet
69 }
70
71 };
72 // -------------------------------------------------------------------------
73
74 // ----- Bit shifts -----------------------------------------------------
75 inline constexpr int32_t kShift[kCurrentVersion + 1][static_cast<uint32_t>(CbmFsdAddress::Level::NumLevels)] = {
76 {0, kShift[0][0] + kBits[0][0], kShift[0][1] + kBits[0][1], kShift[0][2] + kBits[0][2]}
77 };
78 // -------------------------------------------------------------------------
79
80 // ----- Bit masks -----------------------------------------------------
81 inline constexpr int32_t kMask[kCurrentVersion + 1][static_cast<uint32_t>(CbmFsdAddress::Level::NumLevels)] = {
82 {(1 << kBits[0][0]) - 1, (1 << kBits[0][1]) - 1, (1 << kBits[0][2]) - 1, (1 << kBits[0][3]) - 1}
83 };
84 // -------------------------------------------------------------------------
85 // clang-format on
86 } // Namespace Detail
87
88
95 int32_t GetAddress(uint32_t Unit = 0, uint32_t Module = 0, uint32_t PhotoDet = 0, uint32_t Version = kCurrentVersion);
96
97
107 int32_t GetMotherAddress(int32_t address, int32_t level);
108
109
115 uint32_t GetElementId(int32_t address, int32_t level);
116
117
121 uint32_t GetSystemId(int32_t address);
122
123
131 uint32_t GetVersion(int32_t address);
132
133
141 int32_t SetElementId(int32_t address, int32_t level, uint32_t newId);
142
146 std::string ToString(int32_t address);
147
148} // Namespace CbmFsdAddress
149
150
151#endif // CBMFSDADDRESS_H
constexpr uint16_t kBits[kCurrentVersion+1][static_cast< uint32_t >(CbmFsdAddress::Level::NumLevels)]
constexpr int32_t kShift[kCurrentVersion+1][static_cast< uint32_t >(CbmFsdAddress::Level::NumLevels)]
constexpr int32_t kMask[kCurrentVersion+1][static_cast< uint32_t >(CbmFsdAddress::Level::NumLevels)]
Functions to encode or decode the address field of FSD data.
uint32_t GetSystemId(int32_t address)
Get system Id (should be integer value of ECbmModuleId::kFsd)
constexpr int32_t kVersionSize
int32_t GetAddress(uint32_t Unit=0, uint32_t Module=0, uint32_t PhotoDet=0, uint32_t Version=kCurrentVersion)
Construct address.
uint32_t GetVersion(int32_t address)
Extract version number.
constexpr int32_t kVersionShift
uint32_t GetElementId(int32_t address, int32_t level)
Get the index of an 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.
int32_t GetMotherAddress(int32_t address, int32_t level)
Construct the address of an element from the address of a descendant element.
constexpr uint32_t kCurrentVersion
constexpr int32_t kVersionMask
std::string ToString(int32_t address)
String output.