CbmRoot
Loading...
Searching...
No Matches
CbmPsdAddress.h
Go to the documentation of this file.
1/* Copyright (C) 2019-2020 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Nikolay Karpushkin, David Emschermann [committer] */
4
27#ifndef CBMPSDADDRESS_H
28#define CBMPSDADDRESS_H 1
29
30#include "CbmDefs.h" // for ECbmModuleId::kPsd
31
32#include <cassert> // for assert
33#include <cstdint>
34
36public:
43 static uint32_t GetAddress(int32_t moduleId, int32_t sectionId)
44 {
45 assert(!(moduleId < 0 || moduleId > fgkModuleIdLength || sectionId < 0 || sectionId > fgkSectionIdLength));
47 | (sectionId << fgkSectionIdShift);
48 }
49
55 static uint32_t GetSystemId(uint32_t address)
56 {
57 return (address & (fgkSystemIdLength << fgkSystemIdShift)) >> fgkSystemIdShift;
58 }
59
65 static uint32_t GetModuleId(uint32_t address)
66 {
67 return (address & (fgkModuleIdLength << fgkModuleIdShift)) >> fgkModuleIdShift;
68 }
69
75 static uint32_t GetSectionId(uint32_t address)
76 {
78 }
79
86 static uint32_t SetModuleId(uint32_t address, int32_t newModuleId)
87 {
88 assert(!(newModuleId < 0 || newModuleId > fgkModuleIdLength));
89 return GetAddress(newModuleId, GetSectionId(address));
90 }
91
98 static uint32_t SetSectionId(uint32_t address, int32_t newSectionId)
99 {
100 assert(!(newSectionId < 0 || newSectionId > fgkSectionIdLength));
101 return GetAddress(GetModuleId(address), newSectionId);
102 }
103
104
105private:
106 // Length of the index of the corresponding volume
107 static const int32_t fgkSystemIdLength = 15; // 2^4 - 1
108 static const int32_t fgkModuleIdLength = 63; // 2^6 - 1
109 static const int32_t fgkSectionIdLength = 31; // 2^5 - 1
110
111 // Number of a start bit for each volume
112 static const int32_t fgkSystemIdShift = 0;
113 static const int32_t fgkModuleIdShift = 4;
114 static const int32_t fgkSectionIdShift = 10;
115};
116
117#endif
XPU_D constexpr auto ToIntegralType(T enumerator) -> typename std::underlying_type< T >::type
Definition CbmDefs.h:29
@ kPsd
Projectile spectator detector.
CBM PSD interface class to the unique address.
static const int32_t fgkSectionIdShift
static const int32_t fgkSystemIdLength
static uint32_t SetModuleId(uint32_t address, int32_t newModuleId)
Set new module ID for address.
static uint32_t GetSystemId(uint32_t address)
Return System identifier from address.
static uint32_t GetAddress(int32_t moduleId, int32_t sectionId)
Return address from system ID, module, Section.
static uint32_t SetSectionId(uint32_t address, int32_t newSectionId)
Set new section ID for address.
static const int32_t fgkSectionIdLength
static const int32_t fgkModuleIdShift
static const int32_t fgkModuleIdLength
static const int32_t fgkSystemIdShift
static uint32_t GetSectionId(uint32_t address)
Return sector ID from address.
static uint32_t GetModuleId(uint32_t address)
Return module ID from address.