CbmRoot
Loading...
Searching...
No Matches
CbmMustAddress.cxx
Go to the documentation of this file.
1/* Copyright (C) 2025 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Radoslaw Karabowicz [committer] */
4
5#include "CbmMustAddress.h"
6
7#include "AlgoFairloggerCompat.h" // for Logger, LOG
8#include "CbmDefs.h" // for kMust
9
10#include <iomanip> // for setw, __iom_t6
11#include <ios> // for right
12
13
14// ----- Definition of the address field -------------------------------
15const int32_t CbmMustAddress::fgkBits[] = {fgkSystemBits, // system = kMUST
16 4, // station
17 4, // layer
18 8, // module
19 10}; // tube
20// -------------------------------------------------------------------------
21
22// ----- Initialisation of bit shifts -----------------------------------
23const int32_t CbmMustAddress::fgkShift[] = {
26// -------------------------------------------------------------------------
27
28
29// ----- Initialisation of bit masks -----------------------------------
30const int32_t CbmMustAddress::fgkMask[] = {(1 << fgkBits[0]) - 1, (1 << fgkBits[1]) - 1, (1 << fgkBits[2]) - 1,
31 (1 << fgkBits[3]) - 1, (1 << fgkBits[4]) - 1};
32// -------------------------------------------------------------------------
33
34
35// ----- Unique element address -----------------------------------------
36uint32_t CbmMustAddress::GetAddress(int32_t station, int32_t layer, int32_t module, int32_t tube)
37{
38
39 // Catch overrunning of allowed ranges
40 if (station >= (1 << fgkBits[kMustStation])) {
41 LOG(error) << "Station Id " << station << " exceeds maximum (" << (1 << fgkBits[kMustStation]) - 1 << ")";
42 return 0;
43 }
44 if (layer >= (1 << fgkBits[kMustLayer])) {
45 LOG(error) << "Layer Id " << layer << " exceeds maximum (" << (1 << fgkBits[kMustLayer]) - 1 << ")";
46 return 0;
47 }
48 if (module >= (1 << fgkBits[kMustModule])) {
49 LOG(error) << "Module Id " << module << " exceeds maximum (" << (1 << fgkBits[kMustModule]) - 1 << ")";
50 return 0;
51 }
52 if (tube >= (1 << fgkBits[kMustTube])) {
53 LOG(error) << "Tube Id " << tube << " exceeds maximum (" << (1 << fgkBits[kMustTube]) - 1 << ")";
54 return 0;
55 }
56
58 | layer << fgkShift[kMustLayer] | module << fgkShift[kMustModule] | tube << fgkShift[kMustTube];
59}
60// -------------------------------------------------------------------------
61
62
63// ----- Unique element address -----------------------------------------
64uint32_t CbmMustAddress::GetAddress(int32_t* elementId)
65{
66
68 for (int32_t level = 1; level < kMustNofLevels; level++) {
69 if (elementId[level] >= (1 << fgkBits[level])) {
70 LOG(error) << "Id " << elementId[level] << " for MuST level " << level << " exceeds maximum ("
71 << (1 << fgkBits[level]) - 1 << ")";
72 return 0;
73 }
74 address = address | (elementId[level] << fgkShift[level]);
75 }
76
77 return address;
78}
79// -------------------------------------------------------------------------
80
81
82// ----- Print info ----------------------------------------------------
84{
85 LOG(info) << "Number of MuST levels is " << kMustNofLevels;
86 for (int32_t level = 0; level < kMustNofLevels; level++)
87 LOG(info) << "Level " << std::setw(2) << std::right << level << ": bits " << std::setw(2) << fgkBits[level]
88 << ", max. range " << std::setw(6) << fgkMask[level];
89}
90// -------------------------------------------------------------------------
91
92
93// -------------------------------------------------------------------------
94uint32_t CbmMustAddress::SetElementId(uint32_t address, int32_t level, int32_t newId)
95{
96 if (level < 0 || level >= kMustNofLevels) return address;
97 if (newId >= (1 << fgkBits[level])) {
98 LOG(error) << "Id " << newId << " for MuST level " << level << " exceeds maximum (" << (1 << fgkBits[level]) - 1
99 << ")";
100 return 0;
101 }
102 return (address & (~(fgkMask[level] << fgkShift[level]))) | (newId << fgkShift[level]);
103}
104// -------------------------------------------------------------------------
105
106#ifndef NO_ROOT
108#endif
ClassImp(CbmConverterManager)
XPU_D constexpr auto ToIntegralType(T enumerator) -> typename std::underlying_type< T >::type
Converts an element of enum class to its underlying integral type.
Definition CbmDefs.h:33
@ kMust
MuSt detection system.
Definition CbmDefs.h:53
@ kMustStation
Station.
@ kMustSystem
System = MuST.
@ kMustModule
Module.
@ kMustTube
Tube.
@ kMustLayer
Layer.
@ kMustNofLevels
Number of MuST levels.
Interface class to unique address for the MuST.
static uint32_t SetElementId(uint32_t address, int32_t level, int32_t newId)
static uint32_t GetAddress(int32_t station=0, int32_t layer=0, int32_t module=0, int32_t tube=0)
static const int32_t fgkMask[kMustNofLevels]
static const int32_t fgkBits[kMustNofLevels]
static const int32_t fgkShift[kMustNofLevels]
static void Print()