|
| 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 SAC.h |
| 13 | +/// \brief Sampled Analogue Currents (SACs) data format definitions |
| 14 | +/// @author Jens Wiechula, Jens.Wiechula@ikf.uni-frankfurt.de |
| 15 | + |
| 16 | +#ifndef ALICEO2_DATAFORMATSTPC_SAC_H |
| 17 | +#define ALICEO2_DATAFORMATSTPC_SAC_H |
| 18 | + |
| 19 | +#include <cstdint> |
| 20 | +#include <string_view> |
| 21 | + |
| 22 | +namespace o2::tpc::sac |
| 23 | +{ |
| 24 | + |
| 25 | +static constexpr uint32_t FEsPerInstance = 9; |
| 26 | + |
| 27 | +/// 256bit CRU header word of SACs |
| 28 | +struct headerDef { |
| 29 | + static constexpr uint32_t MagicWord = 0xabcd; ///< magic word |
| 30 | + |
| 31 | + union { |
| 32 | + uint64_t word0 = 0; ///< bits 0 - 63 |
| 33 | + struct { /// |
| 34 | + uint32_t version : 8; ///< header version number |
| 35 | + uint32_t instance : 4; ///< 0: TPC A (slave), 1: TPC C (master), 2/3: TRD |
| 36 | + uint32_t empty0 : 8; ///< not used |
| 37 | + uint32_t bunchCrossing : 12; ///< bunch crossing when SAC packet was received |
| 38 | + uint32_t orbit : 32; ///< orbit when SAC packet was received |
| 39 | + }; /// |
| 40 | + }; /// |
| 41 | + /// |
| 42 | + union { /// |
| 43 | + uint64_t word1 = 0; ///< bits 64 - 127 |
| 44 | + struct { ///< |
| 45 | + uint32_t pktCount : 16; ///< internal packet counter, should always increase by one |
| 46 | + uint32_t empty1_0 : 16; ///< not used |
| 47 | + uint32_t empty1_1; ///< not used |
| 48 | + }; /// |
| 49 | + }; /// |
| 50 | + /// |
| 51 | + union { /// |
| 52 | + uint64_t word2 = 0; ///< bits 128 - 191 |
| 53 | + }; /// |
| 54 | + /// |
| 55 | + union { /// |
| 56 | + uint64_t word3 = 0; ///< bits 192 - 255 |
| 57 | + struct { /// |
| 58 | + uint32_t empty3_0; ///< |
| 59 | + uint32_t empty3_1 : 16; ///< |
| 60 | + uint32_t magicWord : 16; ///< magic word should always correspond to MagicWord |
| 61 | + }; /// |
| 62 | + }; /// |
| 63 | + |
| 64 | + bool check() const { return magicWord == MagicWord; } |
| 65 | +}; |
| 66 | + |
| 67 | +struct dataDef { |
| 68 | + static constexpr uint32_t HeaderWord = 0xdeadbeef; |
| 69 | + static constexpr uint32_t TrailerWord = 0xbeefdead; |
| 70 | + static constexpr uint32_t PacketSize = 1024; |
| 71 | + static constexpr uint32_t DataSize = 1000; |
| 72 | + |
| 73 | + uint32_t header = 0; ///< header magic word, should always be HeaderWord |
| 74 | + /// |
| 75 | + union { /// |
| 76 | + uint32_t sizeFE = 0; ///< |
| 77 | + struct { /// |
| 78 | + uint32_t feid : 8; ///< front end ID (card number in rack): 1 - 9 |
| 79 | + uint32_t pktSize : 24; ///< total size of the packet in bytes, should always be 1024 |
| 80 | + }; /// |
| 81 | + }; /// |
| 82 | + /// |
| 83 | + uint32_t pktNumber = 0; ///< packet number of this front end card. Should always increase by 1 |
| 84 | + uint32_t timeStamp = 0; ///< tims stamp |
| 85 | + char dataWords[DataSize]; ///< ASCI encoded SAC data |
| 86 | + uint32_t crc32 = 0; ///< CRC32 checksum |
| 87 | + uint32_t trailer = 0; ///< trailer magic word, should always be TrailerWord |
| 88 | + |
| 89 | + bool check() const |
| 90 | + { |
| 91 | + return (header == HeaderWord) && (trailer == TrailerWord) && (pktSize == PacketSize); |
| 92 | + } |
| 93 | +}; |
| 94 | + |
| 95 | +struct packet { |
| 96 | + headerDef header; |
| 97 | + dataDef data; |
| 98 | + |
| 99 | + uint32_t getInstance() const |
| 100 | + { |
| 101 | + return header.instance; |
| 102 | + } |
| 103 | + |
| 104 | + /// return the global front end card index |
| 105 | + /// 0 - 9: A-Side |
| 106 | + /// 10 - 17: C-Side |
| 107 | + uint32_t getFEIndex() const |
| 108 | + { |
| 109 | + return data.feid - 1 + header.instance * FEsPerInstance; |
| 110 | + } |
| 111 | + |
| 112 | + std::string_view getDataWords() |
| 113 | + { |
| 114 | + return std::string_view(data.dataWords, dataDef::DataSize); |
| 115 | + } |
| 116 | + |
| 117 | + bool check() const |
| 118 | + { |
| 119 | + return header.check() && data.check(); |
| 120 | + } |
| 121 | + |
| 122 | + int getCheckMask() const |
| 123 | + { |
| 124 | + return (header.check() << 1) | data.check(); |
| 125 | + } |
| 126 | +}; |
| 127 | + |
| 128 | +} // namespace o2::tpc::sac |
| 129 | + |
| 130 | +#endif |
0 commit comments