|
| 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 | + |
| 12 | +/// @file CMV.h |
| 13 | +/// @author Tuba Gündem, tuba.gundem@cern.ch |
| 14 | +/// @brief Common mode values data format definition |
| 15 | + |
| 16 | +/// The data is sent by the CRU as 96 bit words. The CMV data layout is as follows: |
| 17 | +/// - 80-bit Header: [version:8][packetID:8][errorCode:8][magicWord:8][heartbeatOrbit:32][heartbeatBC:16] |
| 18 | +/// - 16-bit CMV value: [CMV:16] |
| 19 | + |
| 20 | +#ifndef ALICEO2_DATAFORMATSTPC_CMV_H |
| 21 | +#define ALICEO2_DATAFORMATSTPC_CMV_H |
| 22 | + |
| 23 | +#include <bitset> |
| 24 | + |
| 25 | +namespace o2::tpc::cmv |
| 26 | +{ |
| 27 | + |
| 28 | +static constexpr uint32_t NTimeBins = 3564; ///< number of time bins (spans 8 orbits) |
| 29 | +static constexpr uint32_t SignificantBits = 2; ///< number of bits used for floating point precision |
| 30 | +static constexpr float FloatConversion = 1.f / float(1 << SignificantBits); ///< conversion factor from integer representation to float |
| 31 | + |
| 32 | +/// Header definition of the CMVs |
| 33 | +struct Header { |
| 34 | + static constexpr uint8_t MagicWord = 0xDC; |
| 35 | + union { |
| 36 | + uint32_t word0 = 0; ///< bits 0 - 31 |
| 37 | + struct { |
| 38 | + uint8_t version : 8; ///< version |
| 39 | + uint8_t packetID : 8; ///< packet id |
| 40 | + uint8_t errorCode : 8; ///< errors |
| 41 | + uint8_t magicWord : 8; ///< magic word |
| 42 | + }; |
| 43 | + }; |
| 44 | + union { |
| 45 | + uint32_t word1 = 0; ///< bits 32 - 63 |
| 46 | + struct { |
| 47 | + uint32_t heartbeatOrbit : 32; ///< first heart beat timing of the package |
| 48 | + }; |
| 49 | + }; |
| 50 | + union { |
| 51 | + uint16_t word2 = 0; ///< bits 64 - 79 |
| 52 | + struct { |
| 53 | + uint16_t heartbeatBC : 16; ///< first BC id of the package |
| 54 | + }; |
| 55 | + }; |
| 56 | +}; |
| 57 | + |
| 58 | +/// CMV single data container |
| 59 | +struct Data { |
| 60 | + uint16_t CMV{0}; ///< 16bit ADC value |
| 61 | + |
| 62 | + // Raw integer accessors |
| 63 | + uint16_t getCMV() const { return CMV; } |
| 64 | + void setCMV(uint16_t value) { CMV = value; } |
| 65 | + |
| 66 | + // Float helpers using SignificantBits for fixed-point conversion |
| 67 | + float getCMVFloat() const { return static_cast<float>(CMV) * FloatConversion; } |
| 68 | + void setCMVFloat(float value) { |
| 69 | + // round to nearest representable fixed-point value |
| 70 | + setCMV(uint32_t((value + 0.5f * FloatConversion) / FloatConversion)); |
| 71 | + } |
| 72 | +}; |
| 73 | + |
| 74 | +/// CMV full data container: one packet carries NTimeBins time bins |
| 75 | +struct Container { |
| 76 | + Header header; ///< CMV data header |
| 77 | + Data data[NTimeBins]; ///< data values for given number of time bins |
| 78 | + |
| 79 | + // Header and data accessors |
| 80 | + const Header& getHeader() const { return header; } |
| 81 | + Header& getHeader() { return header; } |
| 82 | + |
| 83 | + const Data* getData() const { return data; } |
| 84 | + Data* getData() { return data; } |
| 85 | + |
| 86 | + // Per-time-bin CMV accessors |
| 87 | + uint16_t getCMV(uint32_t timeBin) const { return data[timeBin].getCMV(); } |
| 88 | + void setCMV(uint32_t timeBin, uint16_t value) { data[timeBin].setCMV(value); } |
| 89 | + |
| 90 | + float getCMVFloat(uint32_t timeBin) const { return data[timeBin].getCMVFloat(); } |
| 91 | + void setCMVFloat(uint32_t timeBin, float value) { data[timeBin].setCMVFloat(value); } |
| 92 | + |
| 93 | +}; |
| 94 | +} // namespace o2::tpc::cmv |
| 95 | + |
| 96 | +#endif |
0 commit comments