Project
Loading...
Searching...
No Matches
ELinkManager.cxx
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
16
17#include "MIDRaw/ELinkManager.h"
18
19#include "fmt/format.h"
20#include "Framework/Logger.h"
22
23namespace o2
24{
25namespace mid
26{
27void ELinkManager::init(uint16_t feeId, bool isDebugMode, bool isBare, const ElectronicsDelay& electronicsDelay, const FEEIdConfig& feeIdConfig)
28{
30 auto gbtUniqueIds = isBare ? std::vector<uint16_t>{feeId} : feeIdConfig.getGBTUniqueIdsInLink(feeId);
31 mFeeId = feeId;
32
33 for (auto& gbtUniqueId : gbtUniqueIds) {
34 auto crateId = crateparams::getCrateIdFromGBTUniqueId(gbtUniqueId);
35 uint8_t offset = crateparams::getGBTIdInCrate(gbtUniqueId) * 8;
36 for (int ilink = 0; ilink < 10; ++ilink) {
37 bool isLoc = ilink < 8;
38 auto uniqueId = raw::makeUniqueLocID(crateId, ilink % 8 + offset);
39 ELinkDataShaper shaper(isDebugMode, isLoc, uniqueId, electronicsDelay);
40#if defined(MID_RAW_VECTORS)
41 mDataShapers.emplace_back(shaper);
42#else
43 auto uniqueRegLocId = makeUniqueId(isLoc, uniqueId);
44 mDataShapers.emplace(uniqueRegLocId, shaper);
45#endif
46
47 if (isBare) {
48 ELinkDecoder decoder;
49 decoder.setBareDecoder(true);
50#if defined(MID_RAW_VECTORS)
51 mDecoders.emplace_back(decoder);
52#else
53 mDecoders.emplace(uniqueRegLocId, decoder);
54#endif
55 }
56 }
57 }
58
59#if defined(MID_RAW_VECTORS)
60 if (isBare) {
61 mIndex = [](uint8_t, uint8_t locId, bool isLoc) { return 8 * (1 - static_cast<size_t>(isLoc)) + (locId % 8); };
62 } else {
63 mIndex = [](uint8_t crateId, uint8_t locId, bool isLoc) { return 10 * (2 * (crateId % 4) + (locId / 8)) + 8 * (1 - static_cast<size_t>(isLoc)) + (locId % 8); };
64 }
65#endif
66}
67
68void ELinkManager::onDone(const ELinkDecoder& decoder, uint8_t crateId, uint8_t locId, std::vector<ROBoard>& data, std::vector<ROFRecord>& rofs)
69{
70 auto uniqueId = makeUniqueId(raw::isLoc(decoder.getStatusWord()), raw::makeUniqueLocID(crateId, locId));
71 auto ds = mDataShapers.find(uniqueId);
72 if (ds == mDataShapers.end()) {
73 // There is something wrong: we are receiving data from a local board that is not expected to be there.
74 // This usually happens when some local boards are not properly configured
75 // and the crate or board ID that they return is not correct.
76 // We keep track of this for debugging.
77 // However, when a board is faulty it keeps sending messages.
78 // To avoid flooding the logs, we warn only the first time we see it.
79 auto& err = mErrors[uniqueId];
80 ++err;
81 static unsigned int nTotalErr = 0;
82 if (err == 1 && nTotalErr++ < 3) {
83 // This is the first time we see this faulty board, so we report it.
84 ROBoard board{decoder.getStatusWord(), decoder.getTriggerWord(), raw::makeUniqueLocID(crateId, locId), decoder.getInputs()};
85 for (int ich = 0; ich < 4; ++ich) {
86 board.patternsBP[ich] = decoder.getPattern(0, ich);
87 board.patternsNBP[ich] = decoder.getPattern(1, ich);
88 }
89 LOG(alarm) << "FEEId: " << mFeeId << " board not found: " << board;
90 }
91 return;
92 }
93 return ds->second.onDone(decoder, data, rofs);
94}
95
96void ELinkManager::set(uint32_t orbit, uint32_t trigger)
97{
99 for (auto& shaper : mDataShapers) {
100#if defined(MID_RAW_VECTORS)
101 shaper.set(orbit, trigger);
102#else
103 shaper.second.set(orbit, trigger);
104#endif
105 }
106}
107
108} // namespace mid
109} // namespace o2
MID RO crate parameters.
MID e-link data shaper manager.
uint64_t orbit
Definition RawEventData.h:6
uint8_t getInputs() const
Gets the inputs.
uint8_t getStatusWord() const
Gets the status word.
uint16_t getPattern(int cathode, int chamber) const
uint8_t getTriggerWord() const
Gets the trigger word.
void setBareDecoder(bool isBare)
void init(uint16_t feeId, bool isDebugMode, bool isBare=false, const ElectronicsDelay &electronicsDelay=ElectronicsDelay(), const FEEIdConfig &feeIdConfig=FEEIdConfig())
void onDone(const ELinkDecoder &decoder, uint8_t boardUniqueId, std::vector< ROBoard > &data, std::vector< ROFRecord > &rofs)
Main function to be executed when decoding is done.
void set(uint32_t orbit, uint32_t trigger)
const std::vector< uint16_t > & getGBTUniqueIdsInLink(uint16_t feeId) const
Definition FEEIdConfig.h:36
GLboolean * data
Definition glcorearb.h:298
GLintptr offset
Definition glcorearb.h:660
uint8_t getCrateIdFromGBTUniqueId(uint16_t gbtUniqueId)
Gets the crate ID from the GBT unique ID.
uint8_t getGBTIdInCrate(uint16_t gbtUniqueId)
Gets the link ID in crate from the RO ID.
uint8_t makeUniqueLocID(uint8_t crateId, uint8_t locId)
Definition ROBoard.h:86
bool isLoc(uint8_t statusWord)
Definition ROBoard.h:65
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
o2::mch::DsIndex ds
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"