19#ifndef O2_MCH_DATADECODER_H_
20#define O2_MCH_DATADECODER_H_
23#include <unordered_set>
24#include <unordered_map>
47 return std::hash<uint64_t>{}(info.get());
51void dumpOrbits(
const std::unordered_set<OrbitInfo, OrbitInfoHash>& mOrbits);
82 uint64_t
time = 0x0000000000000000;
105 }
else if (
time < rhs.time) {
119 bool update(uint32_t
orbit, uint32_t bunchCrossing,
bool verbose =
false);
120 bool check(int32_t
orbit, uint32_t
bc, int32_t orbitRef, uint32_t bcRef,
bool verbose =
false);
152 std::string mapCRUfile, std::string mapFECfile,
155 uint32_t nofOrbitsPerTF = 32);
160 void setOrbitsInTF(uint32_t nofOrbitsPerTF) { mOrbitsInTF = nofOrbitsPerTF; }
176 static uint64_t
getChipId(uint32_t solar, uint32_t
ds, uint32_t chip);
178 static int32_t
getDigitTimeHBPackets(uint32_t orbitTF, uint32_t bcTF, uint32_t orbitDigit, uint32_t bcDigit);
181 int32_t
getDigitTimeBCRst(uint32_t orbitTF, uint32_t bcTF, uint32_t orbitDigit, uint32_t bcDigit);
189 const std::unordered_set<OrbitInfo, OrbitInfoHash>&
getOrbits()
const {
return mOrbits; }
191 const std::vector<o2::mch::DecoderError>&
getErrors()
const {
return mErrors; }
193 const std::vector<o2::mch::HeartBeatPacket>&
getHBPackets()
const {
return mHBPackets; }
201 void initElec2DetMapper(std::string
filename);
202 void initFee2SolarMapper(std::string
filename);
204 void decodePage(gsl::span<const std::byte> page);
208 bool getTimeFrameStartRecord(
const RawDigit& digit, uint32_t&
orbit, uint32_t&
bc);
211 void updateMergerRecord(uint32_t mergerChannelId, uint32_t mergerBoardId, uint64_t mergerChannelBitmask, uint32_t digitId);
212 bool mergeDigits(uint32_t mergerChannelId, uint32_t mergerBoardId, uint64_t mergerChannelBitmask,
o2::mch::raw::SampaCluster& sc);
216 struct MergerChannelRecord {
217 MergerChannelRecord() =
default;
218 uint32_t digitId{0xFFFF};
219 uint32_t bcEnd{0xFFFF};
222 static constexpr uint32_t sMaxSolarId = 200 * 8 - 1;
223 static constexpr uint32_t sReadoutBoardsNum = (sMaxSolarId + 1) * 40;
224 static constexpr uint32_t sReadoutChipsNum = sReadoutBoardsNum * 2;
225 static constexpr uint32_t sReadoutChannelsNum = sReadoutChipsNum * 32;
227 std::vector<TimeFrameStartRecord> mTimeFrameStartRecords;
232 std::vector<MergerChannelRecord> mMergerRecords;
233 std::vector<uint64_t> mMergerRecordsReady;
237 std::string mMapFECfile;
238 std::string mMapCRUfile;
243 std::unordered_set<OrbitInfo, OrbitInfoHash> mOrbits;
244 std::vector<o2::mch::DecoderError> mErrors;
245 std::vector<o2::mch::HeartBeatPacket> mHBPackets;
247 uint32_t mOrbitsInTF;
249 uint32_t mFirstOrbitInTF;
250 uint32_t mSampaTimeOffset{0};
257 bool mDs2manu{
false};
259 bool mUseDummyElecMap{
false};
260 std::map<std::string, uint64_t> mErrorMap;
263bool operator<(
const DataDecoder::RawDigit& d1,
const DataDecoder::RawDigit& d2);
265std::ostream&
operator<<(std::ostream& os,
const DataDecoder::RawDigit& d);
267std::string
asString(
const DataDecoder::RawDigit& d);
MCH digit implementation.
MCH orbit info implementation.
std::vector< RawDigit > RawDigitVector
void logErrorMap(int tfcount) const
send all messages from our error map to the infologger
void setOrbitsInTF(uint32_t nofOrbitsPerTF)
void computeDigitsTimeBCRst()
Compute the time of all the digits that have been decoded in the current TimeFrame.
void computeDigitsTimeHBPackets()
Compute the time of all the digits that have been decoded in the current TimeFrame.
static constexpr int32_t tfTimeInvalid
static int32_t getDigitTimeHBPackets(uint32_t orbitTF, uint32_t bcTF, uint32_t orbitDigit, uint32_t bcDigit)
Helper function for computing the digit time relative to the beginning of the TimeFrame.
static constexpr int32_t tfTimeMax
const std::vector< o2::mch::HeartBeatPacket > & getHBPackets() const
Get the list of heart-beat packets that have been found in the current TimeFrame.
const std::vector< o2::mch::DecoderError > & getErrors() const
Get the list of decoding errors that have been found in the current TimeFrame.
void setFirstOrbitInTF(uint32_t orbit)
int32_t getDigitTimeBCRst(uint32_t orbitTF, uint32_t bcTF, uint32_t orbitDigit, uint32_t bcDigit)
static uint64_t getChipId(uint32_t solar, uint32_t ds, uint32_t chip)
Convert a Solar/Ds/Chip triplet into an unique chip index.
void setDigits(const RawDigitVector &digits)
Initialize the digits from an external vector. To be only used for unit tests.
void updateTimeFrameStartRecord(uint64_t chipId, uint32_t mFirstOrbitInTF, uint32_t bcTF)
For a given SAMPA chip, update the information about the BC counter value at the beginning of the Tim...
const RawDigitVector & getDigits() const
Get the vector of digits that have been decoded in the current TimeFrame.
const std::unordered_set< OrbitInfo, OrbitInfoHash > & getOrbits() const
Get the list of orbits that have been found in the current TimeFrame for each CRU link.
bool decodeBuffer(gsl::span< const std::byte > buf)
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLenum GLuint GLenum GLsizei const GLchar * buf
std::function< void(o2::header::RDHAny *)> RdhHandler
std::function< std::optional< DsDetId >(DsElecId)> Elec2DetMapper
std::function< void(Page buffer)> PageDecoder
void dumpOrbits(const std::unordered_set< OrbitInfo, OrbitInfoHash > &mOrbits)
std::function< void(DsElecId dsId, DualSampaChannelId channel, SampaCluster)> SampaChannelHandler
uint6_t DualSampaChannelId
std::function< std::optional< uint16_t >(FeeLinkId id)> FeeLink2SolarMapper
From (feeId,linkId) to solarId.
std::string asString(const SampaCluster &sc)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
bool operator<(const observer_ptr< W1 > &p1, const observer_ptr< W2 > &p2)
std::ostream & operator<<(std::ostream &stream, o2::InteractionRecord const &ir)
auto getSampaTime() const
bool operator==(const RawDigit &) const
auto getBunchCrossing() const
Structure storing the raw SAMPA information.
bool operator<(const SampaInfo &rhs) const
bool operator==(const SampaInfo &) const
uint32_t bunchCrossing
bit 0 to 9: sampa time
uint32_t getBXTime() const
uint32_t reserved
bit 10 to 29: bunch crossing counter
uint32_t orbit
bit 30 to 31: reserved
bool check(int32_t orbit, uint32_t bc, int32_t orbitRef, uint32_t bcRef, bool verbose=false)
TimeFrameStartRecord()=default
bool update(uint32_t orbit, uint32_t bunchCrossing, bool verbose=false)
store the new orbit/bc pair, and copy the existing one in the "*Prev" data members
int64_t mBunchCrossingPrev
std::size_t operator()(const OrbitInfo &info) const noexcept
Piece of data for one Sampa channel.
const bool useDummyElecMap
DataDecoder::RawDigitVector RawDigitVector
std::vector< Digit > digits