CbmRoot
Loading...
Searching...
No Matches
CbmMuchAddress.cxx
Go to the documentation of this file.
1/* Copyright (C) 2013-2020 Petersburg Nuclear Physics Institute named by B.P.Konstantinov of National Research Centre "Kurchatov Institute", Gatchina
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Evgeny Kryshen [committer], Florian Uhlig */
4
5#include "CbmMuchAddress.h"
6
7#include "CbmDefs.h" // for kMuch
8
9#include <iomanip> // for setw, __iom_t6
10#include <ios> // for right
11
12#include "AlgoFairloggerCompat.h" // for Logger, LOG
13
14
15// ----- Definition of the address field -------------------------------
16const int32_t CbmMuchAddress::fgkBits[] = {fgkSystemBits, // system = kMUCH
17 3, // station
18 2, // layer
19 1, // layerside
20 5, // module
21 8, // sector
22 9}; // channel
23// -------------------------------------------------------------------------
24
25// ----- Initialisation of bit shifts -----------------------------------
26const int32_t CbmMuchAddress::fgkShift[] = {0,
33// -------------------------------------------------------------------------
34
35
36// ----- Initialisation of bit masks -----------------------------------
37const int32_t CbmMuchAddress::fgkMask[] = {(1 << fgkBits[0]) - 1, (1 << fgkBits[1]) - 1, (1 << fgkBits[2]) - 1,
38 (1 << fgkBits[3]) - 1, (1 << fgkBits[4]) - 1, (1 << fgkBits[5]) - 1,
39 (1 << fgkBits[6]) - 1};
40// -------------------------------------------------------------------------
41
42
43// ----- Unique element address -----------------------------------------
44uint32_t CbmMuchAddress::GetAddress(int32_t station, int32_t layer, int32_t layerside, int32_t module, int32_t sector,
45 int32_t channel)
46{
47
48 // Catch overrunning of allowed ranges
49 if (station >= (1 << fgkBits[kMuchStation])) {
50 LOG(error) << "Station Id " << station << " exceeds maximum (" << (1 << fgkBits[kMuchStation]) - 1 << ")";
51 return 0;
52 }
53 if (layer >= (1 << fgkBits[kMuchLayer])) {
54 LOG(error) << "Layer Id " << layer << " exceeds maximum (" << (1 << fgkBits[kMuchLayer]) - 1 << ")";
55 return 0;
56 }
57 if (layerside >= (1 << fgkBits[kMuchLayerSide])) {
58 LOG(error) << "LayerSide Id " << layerside << " exceeds maximum (" << (1 << fgkBits[kMuchLayerSide]) - 1 << ")";
59 return 0;
60 }
61 if (module >= (1 << fgkBits[kMuchModule])) {
62 LOG(error) << "Module Id " << module << " exceeds maximum (" << (1 << fgkBits[kMuchModule]) - 1 << ")";
63 return 0;
64 }
65 if (sector >= (1 << fgkBits[kMuchSector])) {
66 LOG(error) << "Sector Id " << sector << " exceeds maximum (" << (1 << fgkBits[kMuchSector]) - 1 << ")";
67 return 0;
68 }
69 if (channel >= (1 << fgkBits[kMuchChannel])) {
70 LOG(error) << "Channel Id " << channel << " exceeds maximum (" << (1 << fgkBits[kMuchChannel]) - 1 << ")";
71 return 0;
72 }
73
75 | layer << fgkShift[kMuchLayer] | layerside << fgkShift[kMuchLayerSide] | module << fgkShift[kMuchModule]
76 | sector << fgkShift[kMuchSector] | channel << fgkShift[kMuchChannel];
77}
78// -------------------------------------------------------------------------
79
80
81// ----- Unique element address -----------------------------------------
82uint32_t CbmMuchAddress::GetAddress(int32_t* elementId)
83{
84
86 for (int32_t level = 1; level < kMuchNofLevels; level++) {
87 if (elementId[level] >= (1 << fgkBits[level])) {
88 LOG(error) << "Id " << elementId[level] << " for MUCH level " << level << " exceeds maximum ("
89 << (1 << fgkBits[level]) - 1 << ")";
90 return 0;
91 }
92 address = address | (elementId[level] << fgkShift[level]);
93 }
94
95 return address;
96}
97// -------------------------------------------------------------------------
98
99
100// ----- Print info ----------------------------------------------------
102{
103 LOG(info) << "Number of MUCH levels is " << kMuchNofLevels;
104 for (int32_t level = 0; level < kMuchNofLevels; level++)
105 LOG(info) << "Level " << std::setw(2) << std::right << level << ": bits " << std::setw(2) << fgkBits[level]
106 << ", max. range " << std::setw(6) << fgkMask[level];
107}
108// -------------------------------------------------------------------------
109
110
111// -------------------------------------------------------------------------
112uint32_t CbmMuchAddress::SetElementId(uint32_t address, int32_t level, int32_t newId)
113{
114 if (level < 0 || level >= kMuchNofLevels) return address;
115 if (newId >= (1 << fgkBits[level])) {
116 LOG(error) << "Id " << newId << " for MUCH level " << level << " exceeds maximum (" << (1 << fgkBits[level]) - 1
117 << ")";
118 return 0;
119 }
120 return (address & (~(fgkMask[level] << fgkShift[level]))) | (newId << fgkShift[level]);
121}
122// -------------------------------------------------------------------------
123
124#ifndef NO_ROOT
126#endif
ClassImp(CbmConverterManager)
XPU_D constexpr auto ToIntegralType(T enumerator) -> typename std::underlying_type< T >::type
Definition CbmDefs.h:29
@ kMuch
Muon detection system.
@ kMuchNofLevels
Number of MUCH levels.
@ kMuchLayerSide
LayerSide.
@ kMuchStation
Station.
@ kMuchSector
Sector.
@ kMuchChannel
Channel.
@ kMuchSystem
System = MUCH.
@ kMuchModule
Module.
@ kMuchLayer
Layer.
Interface class to unique address for the MUCH.
static const int32_t fgkBits[kMuchNofLevels]
static void Print()
static uint32_t SetElementId(uint32_t address, int32_t level, int32_t newId)
static const int32_t fgkMask[kMuchNofLevels]
static const int32_t fgkShift[kMuchNofLevels]
static uint32_t GetAddress(int32_t station=0, int32_t layer=0, int32_t side=0, int32_t module=0, int32_t sector=0, int32_t channel=0)