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 {
43 struct {
49 };
50 };
51 union {
53 struct {
57 };
58 };
59 union {
61 struct {
63 };
64 };
65 union {
67 struct {
69 };
70 };
71};
72
74struct Data {
76
77 uint16_t getCMV() const { return cmv; }
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: truncates 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>(
93 std::lround(std::abs(value) * 128.f)) &
94 0x7FFF;
95 cmv = (positive ? 0x8000 : 0x0000) | magnitude;
96 }
97};
98
102struct Container {
104 Data data[NTimeBinsPerPacket];
105 uint8_t padding[DataPaddingBytes]{};
106
107 // Header and data accessors
108 const Header& getHeader() const { return header; }
109 Header& getHeader() { return header; }
110
111 const Data* getData() const { return data; }
112 Data* getData() { return data; }
113
114 // Per timebin CMV accessors
115 uint16_t getCMV(uint32_t timeBin) const { return data[timeBin].getCMV(); }
116 void setCMV(uint32_t timeBin, uint16_t value) { data[timeBin].setCMV(value); }
117
118 float getCMVFloat(uint32_t timeBin) const { return data[timeBin].getCMVFloat(); }
119 void setCMVFloat(uint32_t timeBin, float value) { data[timeBin].setCMVFloat(value); }
120};
121
122} // namespace o2::tpc::cmv
123
124#endif
unsigned short int uint16_t
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char Directory with events to Events directory is and not inside events Show standalone event Run event generator maximum time bin of continuous for triggered for automatic continuous for automatic continuous triggered uint64_t
GLsizei const GLfloat * value
Definition glcorearb.h:819
uint8_t padding[DataPaddingBytes]
trailing padding to align data to 32-byte boundary
Definition CMV.h:105
void setCMV(uint32_t timeBin, uint16_t value)
Definition CMV.h:116
float getCMVFloat(uint32_t timeBin) const
Definition CMV.h:118
Header & getHeader()
Definition CMV.h:109
Data data[NTimeBinsPerPacket]
data values
Definition CMV.h:104
const Header & getHeader() const
Definition CMV.h:108
uint16_t getCMV(uint32_t timeBin) const
Definition CMV.h:115
const Data * getData() const
Definition CMV.h:111
void setCMVFloat(uint32_t timeBin, float value)
Definition CMV.h:119
Header header
CMV data header.
Definition CMV.h:103
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