CbmRoot
Loading...
Searching...
No Matches
CbmStsDigi.h
Go to the documentation of this file.
1/* Copyright (C) 2006-2020 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Volker Friese, Denis Bertini [committer], Florian Uhlig */
4
13#ifndef CBMSTSDIGI_H
14#define CBMSTSDIGI_H 1
15
16#include "CbmDefs.h" // for ECbmModuleId::kSts
17#include "CbmStsAddress.h"
18
19#include <xpu/defines.h> // for XPU_D
20
21#if !defined(NO_ROOT) && !XPU_IS_HIP_CUDA
22#include <Rtypes.h> // for ClassDef
23#endif
24
25
26#include <boost/serialization/access.hpp>
27#include <boost/serialization/base_object.hpp>
28
29#include <cassert>
30#include <string> // for string
31
41
42public: // constants
43 static constexpr int kNumAdcBits = 5;
44 static constexpr uint32_t kAdcMask = (1u << kNumAdcBits) - 1u;
45 static constexpr int kNumLowerAddrBits = 16;
46 static constexpr int kNumTimestampBits = 31;
47 static constexpr uint32_t kTimestampMask = (1u << kNumTimestampBits) - 1u;
48 static constexpr uint32_t kMaxTimestamp = kTimestampMask;
49 static constexpr uint32_t kTimeAddressBitMask = ~kTimestampMask;
50
51public:
53 CbmStsDigi() = default;
54
61 XPU_D CbmStsDigi(int32_t address, int32_t channel, uint32_t time, uint16_t charge)
62 {
63 time = ClampTime(time);
64 PackAddressAndTime(address, time);
65 PackChannelAndCharge(channel, charge);
66 }
67
69 ~CbmStsDigi() = default;
70
74 XPU_D int32_t GetAddress() const { return UnpackAddress(); }
75
76
77 XPU_D int32_t GetAddressPacked() const
78 {
79 int32_t highestBitAddr = fTime >> kNumTimestampBits;
80 int32_t packedAddress = (highestBitAddr << kNumLowerAddrBits) | int32_t(fAddress);
81 return packedAddress;
82 }
83
87 static const char* GetBranchName() { return "StsDigi"; }
88
89
93 XPU_D uint16_t GetChannel() const { return UnpackChannel(); }
94
95
99 static const char* GetClassName() { return "CbmStsDigi"; }
100
101#if XPU_IS_CPU
105 double GetCharge() const { return static_cast<double>(UnpackCharge()); }
106#endif
107
108 XPU_D uint16_t GetChargeU16() const { return UnpackCharge(); }
109
110
115
116#if XPU_IS_CPU
120 double GetTime() const { return static_cast<double>(UnpackTime()); }
121#endif
122
123 XPU_D uint32_t GetTimeU32() const { return UnpackTime(); }
124
125
126 template<class Archive>
127 void serialize(Archive& ar, const unsigned int /*version*/)
128 {
129 ar& fTime;
131 ar& fAddress;
132 }
133
134
138 XPU_D void SetTime(uint32_t dNewTime)
139 {
140 dNewTime = ClampTime(dNewTime);
141 PackTime(dNewTime);
142 }
143
144 XPU_D void SetChannel(uint16_t channel) { PackChannelAndCharge(channel, UnpackCharge()); }
145
146 XPU_D void SetCharge(uint16_t charge) { PackChannelAndCharge(UnpackChannel(), charge); }
147
148 XPU_D void SetAddress(int32_t address) { PackAddressAndTime(address, UnpackTime()); }
149
150
155 XPU_D void SetChannelAndCharge(uint16_t channel, uint16_t charge) { PackChannelAndCharge(channel, charge); }
156
161 XPU_D void SetAddressAndTime(int32_t address, uint32_t time)
162 {
163 time = ClampTime(time);
164 PackAddressAndTime(address, time);
165 }
166
167
169 std::string ToString() const;
170
171
172private:
174
175
176 uint32_t fTime;
178 uint16_t fAddress;
179
180
181 XPU_D void PackTime(uint32_t newTime) { fTime = (fTime & kTimeAddressBitMask) | (newTime & kTimestampMask); }
182 XPU_D uint32_t UnpackTime() const { return fTime & kTimestampMask; }
183
184
185 XPU_D void PackChannelAndCharge(uint16_t channel, uint16_t charge)
186 {
187 fChannelAndCharge = (channel << kNumAdcBits) | charge;
188 }
189 XPU_D uint16_t UnpackChannel() const { return fChannelAndCharge >> kNumAdcBits; }
190 XPU_D uint16_t UnpackCharge() const { return fChannelAndCharge & kAdcMask; }
191
192 XPU_D void PackAddressAndTime(int32_t newAddress, uint32_t newTime)
193 {
194 int32_t packedAddr = CbmStsAddress::PackDigiAddress(newAddress);
195
196 uint32_t highestBitAddr = packedAddr >> kNumLowerAddrBits;
197 uint32_t lowerAddr = packedAddr & ((1 << kNumLowerAddrBits) - 1);
198
199 fAddress = lowerAddr;
200 fTime = (highestBitAddr << kNumTimestampBits) | (kTimestampMask & newTime);
201 }
202
203 XPU_D int32_t UnpackAddress() const
204 {
205 int32_t packedAddress = GetAddressPacked();
206 return CbmStsAddress::UnpackDigiAddress(packedAddress);
207 }
208
209 XPU_D uint32_t ClampTime(uint32_t time) const
210 {
211 if (time > kMaxTimestamp) time = kMaxTimestamp;
212 return time;
213 }
214
215#if !defined(NO_ROOT) && !XPU_IS_HIP_CUDA
217#endif
218};
219
220#endif
ECbmModuleId
Definition CbmDefs.h:39
@ kSts
Silicon Tracking System.
Data class for a single-channel message in the STS.
Definition CbmStsDigi.h:40
ClassDefNV(CbmStsDigi, 8)
XPU_D void PackAddressAndTime(int32_t newAddress, uint32_t newTime)
Definition CbmStsDigi.h:192
CbmStsDigi()=default
XPU_D void SetAddress(int32_t address)
Definition CbmStsDigi.h:148
XPU_D void PackChannelAndCharge(uint16_t channel, uint16_t charge)
Definition CbmStsDigi.h:185
std::string ToString() const
static constexpr uint32_t kTimestampMask
Definition CbmStsDigi.h:47
XPU_D int32_t GetAddressPacked() const
Definition CbmStsDigi.h:77
XPU_D void SetAddressAndTime(int32_t address, uint32_t time)
Definition CbmStsDigi.h:161
XPU_D void SetCharge(uint16_t charge)
Definition CbmStsDigi.h:146
XPU_D void SetChannelAndCharge(uint16_t channel, uint16_t charge)
Definition CbmStsDigi.h:155
uint32_t fTime
Time [ns] in lower 31 bits, highest bit is the 17th address bit.
Definition CbmStsDigi.h:176
uint16_t fChannelAndCharge
Channel number (lower 11 bits) and charge [ADC Units] in upper 5 bits.
Definition CbmStsDigi.h:177
XPU_D void SetTime(uint32_t dNewTime)
Definition CbmStsDigi.h:138
XPU_D uint16_t UnpackChannel() const
Definition CbmStsDigi.h:189
static constexpr uint32_t kAdcMask
Definition CbmStsDigi.h:44
XPU_D uint16_t GetChannel() const
Channel number in module @value Channel number.
Definition CbmStsDigi.h:93
static constexpr int kNumAdcBits
Definition CbmStsDigi.h:43
static constexpr uint32_t kMaxTimestamp
Definition CbmStsDigi.h:48
uint16_t fAddress
Unique element address (lower 16 bits of 17)
Definition CbmStsDigi.h:178
XPU_D uint16_t UnpackCharge() const
Definition CbmStsDigi.h:190
XPU_D int32_t UnpackAddress() const
Definition CbmStsDigi.h:203
XPU_D uint32_t UnpackTime() const
Definition CbmStsDigi.h:182
static ECbmModuleId GetSystem()
Definition CbmStsDigi.h:114
XPU_D void PackTime(uint32_t newTime)
Definition CbmStsDigi.h:181
XPU_D int32_t GetAddress() const
Definition CbmStsDigi.h:74
static const char * GetBranchName()
Get the desired name of the branch for this obj in the cbm output tree (static)
Definition CbmStsDigi.h:87
XPU_D uint32_t ClampTime(uint32_t time) const
Definition CbmStsDigi.h:209
XPU_D uint16_t GetChargeU16() const
Definition CbmStsDigi.h:108
void serialize(Archive &ar, const unsigned int)
Definition CbmStsDigi.h:127
static constexpr uint32_t kTimeAddressBitMask
Definition CbmStsDigi.h:49
static constexpr int kNumTimestampBits
Definition CbmStsDigi.h:46
XPU_D uint32_t GetTimeU32() const
Definition CbmStsDigi.h:123
XPU_D void SetChannel(uint16_t channel)
Definition CbmStsDigi.h:144
static constexpr int kNumLowerAddrBits
Definition CbmStsDigi.h:45
XPU_D CbmStsDigi(int32_t address, int32_t channel, uint32_t time, uint16_t charge)
Definition CbmStsDigi.h:61
friend class boost::serialization::access
Definition CbmStsDigi.h:173
static const char * GetClassName()
Class name (static)
Definition CbmStsDigi.h:99
~CbmStsDigi()=default
XPU_D int32_t PackDigiAddress(int32_t address)
Strip address to contain only unit, (half)ladder and module.
XPU_D int32_t UnpackDigiAddress(int32_t digiAddress)
Add version and system to compressed address that's stored in a digi.