Project
Loading...
Searching...
No Matches
CMV.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
15
20
21#ifndef ALICEO2_DATAFORMATSTPC_CMV_H
22#define ALICEO2_DATAFORMATSTPC_CMV_H
23
24#include <cstdint>
25#include <cmath>
26
27namespace o2::tpc::cmv
28{
29
30static constexpr uint32_t NTimeBinsPerPacket = 3564;
31static constexpr uint32_t NPacketsPerTFPerCRU = 4;
32static constexpr uint32_t NTimeBinsPerTF = NTimeBinsPerPacket * NPacketsPerTFPerCRU;
33
35static constexpr uint32_t DataSizeBytes = NTimeBinsPerPacket * sizeof(uint16_t);
36static constexpr uint32_t DataPaddingBytes = (32 - (DataSizeBytes % 32)) % 32;
37
39struct Header {
40 static constexpr uint8_t MagicWord = 0xDC;
41 union {
42 uint64_t word0 = 0;
43 struct {
44 uint8_t version : 8;
45 uint8_t packetID : 8;
46 uint8_t errorCode : 8;
47 uint8_t magicWord : 8;
48 uint32_t heartbeatOrbit : 32;
49 };
50 };
51 union {
52 uint64_t word1 = 0;
53 struct {
54 uint16_t heartbeatBC : 16;
55 uint16_t unused1 : 16;
56 uint32_t unused2 : 32;
57 };
58 };
59 union {
60 uint64_t word3 = 0;
61 struct {
62 uint64_t unused3 : 64;
63 };
64 };
65 union {
66 uint64_t word4 = 0;
67 struct {
68 uint64_t unused4 : 64;
69 };
70 };
71};
72
74struct Data {
75 uint16_t cmv{0};
76
77 uint16_t getCMV() const { return cmv; }
78 void setCMV(uint16_t value) { cmv = value; }
79
80 // Decode to float: sign-magnitude with 7 fractional bits, range ±255.992
81 float getCMVFloat() const
82 {
83 const bool positive = (cmv >> 15) & 1; // bit 15: sign (1=positive, 0=negative)
84 const float magnitude = (cmv & 0x7FFF) / 128.f; // lower 15 bits, shift right by 7 (divide by 2^7)
85 return positive ? magnitude : -magnitude;
86 }
87
88 // Encode from float: clamps magnitude to 15 bits, range ±255.992
89 void setCMVFloat(float value)
90 {
91 const bool positive = (value >= 0.f);
92 const uint16_t magnitude = static_cast<uint16_t>(std::abs(value) * 128.f + 0.5f) & 0x7FFF;
93 cmv = (positive ? 0x8000 : 0x0000) | magnitude;
94 }
95};
96
100struct Container {
102 Data data[NTimeBinsPerPacket];
103 uint8_t padding[DataPaddingBytes]{};
104
105 // Header and data accessors
106 const Header& getHeader() const { return header; }
107 Header& getHeader() { return header; }
108
109 const Data* getData() const { return data; }
110 Data* getData() { return data; }
111
112 // Per timebin CMV accessors
113 uint16_t getCMV(uint32_t timeBin) const { return data[timeBin].getCMV(); }
114 void setCMV(uint32_t timeBin, uint16_t value) { data[timeBin].setCMV(value); }
115
116 float getCMVFloat(uint32_t timeBin) const { return data[timeBin].getCMVFloat(); }
117 void setCMVFloat(uint32_t timeBin, float value) { data[timeBin].setCMVFloat(value); }
118};
119
120} // namespace o2::tpc::cmv
121
122#endif
GLsizei const GLfloat * value
Definition glcorearb.h:819
GLboolean * data
Definition glcorearb.h:298
uint8_t padding[DataPaddingBytes]
trailing padding to align data to 32-byte boundary
Definition CMV.h:103
void setCMV(uint32_t timeBin, uint16_t value)
Definition CMV.h:114
float getCMVFloat(uint32_t timeBin) const
Definition CMV.h:116
Header & getHeader()
Definition CMV.h:107
Data data[NTimeBinsPerPacket]
data values
Definition CMV.h:102
const Header & getHeader() const
Definition CMV.h:106
uint16_t getCMV(uint32_t timeBin) const
Definition CMV.h:113
const Data * getData() const
Definition CMV.h:109
void setCMVFloat(uint32_t timeBin, float value)
Definition CMV.h:117
Header header
CMV data header.
Definition CMV.h:101
CMV single data container.
Definition CMV.h:74
uint16_t getCMV() const
raw 16-bit integer representation
Definition CMV.h:77
float getCMVFloat() const
Definition CMV.h:81
void setCMVFloat(float value)
Definition CMV.h:89
void setCMV(uint16_t value)
set raw 16-bit integer representation
Definition CMV.h:78
uint16_t cmv
16-bit signed fixed point value: bit 15 = sign (1=positive, 0=negative), bits 14-0 = I8F7 magnitude
Definition CMV.h:75
Header definition of the CMVs.
Definition CMV.h:39
static constexpr uint8_t MagicWord
Definition CMV.h:40
uint64_t word4
bits 192 - 255
Definition CMV.h:66
uint64_t unused4
reserved
Definition CMV.h:68
uint64_t unused3
reserved
Definition CMV.h:62
uint8_t version
version
Definition CMV.h:44
uint64_t word0
bits 0 - 63
Definition CMV.h:42
uint64_t word1
bits 64 - 127
Definition CMV.h:52
uint16_t unused1
reserved
Definition CMV.h:55
uint16_t heartbeatBC
first BC id of the package
Definition CMV.h:54
uint8_t magicWord
magic word
Definition CMV.h:47
uint32_t heartbeatOrbit
first heart beat timing of the package
Definition CMV.h:48
uint32_t unused2
reserved
Definition CMV.h:56
uint8_t errorCode
errors
Definition CMV.h:46
uint64_t word3
bits 128 - 191
Definition CMV.h:60
uint8_t packetID
packet id
Definition CMV.h:45