|
| 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 MID/Filtering/src/ColumnDataMaskToROMask.cxx |
| 13 | +/// \brief Converts ColumnData masks into local board masks |
| 14 | +/// \author Diego Stocco <Diego.Stocco at cern.ch> |
| 15 | +/// \date 12 October 2021 |
| 16 | + |
| 17 | +#include "MIDFiltering/ColumnDataMaskToROMask.h" |
| 18 | + |
| 19 | +#include <fstream> |
| 20 | +#include "fmt/format.h" |
| 21 | +#include "MIDFiltering/MaskMaker.h" |
| 22 | +#include "MIDFiltering/ChannelMasksHandler.h" |
| 23 | + |
| 24 | +namespace o2 |
| 25 | +{ |
| 26 | +namespace mid |
| 27 | +{ |
| 28 | +ColumnDataMaskToROMask::ColumnDataMaskToROMask() |
| 29 | +{ |
| 30 | + // Default ctr |
| 31 | + mDefaultMasks = makeDefaultMasks(); |
| 32 | + mColToBoard.setDebugMode(true); |
| 33 | +} |
| 34 | + |
| 35 | +bool ColumnDataMaskToROMask::needsMask(const ROBoard& mask, bool hasDirectInputY) const |
| 36 | +{ |
| 37 | + /// Returns true if the local board is masked |
| 38 | + if (!hasDirectInputY) { |
| 39 | + return true; |
| 40 | + } |
| 41 | + |
| 42 | + for (int ich = 0; ich < 4; ++ich) { |
| 43 | + if (mask.patternsBP[ich] != 0xFFFF || mask.patternsNBP[ich] != 0xFFFF) { |
| 44 | + return true; |
| 45 | + } |
| 46 | + } |
| 47 | + return false; |
| 48 | +} |
| 49 | + |
| 50 | +uint32_t ColumnDataMaskToROMask::makeConfigWord(const ROBoard& mask) const |
| 51 | +{ |
| 52 | + /// Computes the configuration word for the local board |
| 53 | + auto cfgWord = sTxDataMask; |
| 54 | + bool hasDirectInputY = mCrateMapper.hasDirectInputY(mask.boardId); |
| 55 | + bool isMasked = needsMask(mask, hasDirectInputY); |
| 56 | + if (isMasked) { |
| 57 | + cfgWord |= sMonmoff; |
| 58 | + } |
| 59 | + if (!hasDirectInputY) { |
| 60 | + cfgWord |= sXorY; |
| 61 | + } |
| 62 | + return cfgWord; |
| 63 | +} |
| 64 | + |
| 65 | +std::vector<ROBoard> ColumnDataMaskToROMask::convert(gsl::span<const ColumnData> colDataMasks) |
| 66 | +{ |
| 67 | + /// Converts ColumnData masks into local board masks |
| 68 | + mColToBoard.process(colDataMasks); |
| 69 | + |
| 70 | + std::vector<ROBoard> roMasks; |
| 71 | + for (auto& mapIt : mColToBoard.getData()) { |
| 72 | + for (auto& board : mapIt.second) { |
| 73 | + roMasks.emplace_back(board); |
| 74 | + } |
| 75 | + } |
| 76 | + return roMasks; |
| 77 | +} |
| 78 | + |
| 79 | +void ColumnDataMaskToROMask::write(gsl::span<const ColumnData> colDataMasks, const char* outFilename) |
| 80 | +{ |
| 81 | + /// Writes the mask to file |
| 82 | + |
| 83 | + // FIXME: currently, the masks are written to a file that is then read by WinCC |
| 84 | + // In the future, this should be moved to ccdb |
| 85 | + |
| 86 | + auto roMasks = convert(colDataMasks); |
| 87 | + |
| 88 | + // We order the masks for easier reading from humans |
| 89 | + std::sort(roMasks.begin(), roMasks.end(), [](const ROBoard& loc1, const ROBoard& loc2) { return loc1.boardId < loc2.boardId; }); |
| 90 | + |
| 91 | + std::ofstream outFile(outFilename); |
| 92 | + for (auto& mask : roMasks) { |
| 93 | + auto cfgWord = makeConfigWord(mask); |
| 94 | + outFile << fmt::format("{:02x} {:08x}", mask.boardId, cfgWord); |
| 95 | + |
| 96 | + bool isMasked = cfgWord & sMonmoff; |
| 97 | + |
| 98 | + for (int ich = 0; ich < 4; ++ich) { |
| 99 | + uint16_t valBP = isMasked ? mask.patternsBP[ich] : 0; |
| 100 | + uint16_t valNBP = (isMasked && (cfgWord & sXorY) == 0) ? mask.patternsNBP[ich] : 0; |
| 101 | + outFile << fmt::format(" {:04x}{:04x}", valBP, valNBP); |
| 102 | + } |
| 103 | + outFile << std::endl; |
| 104 | + } |
| 105 | +} |
| 106 | +} // namespace mid |
| 107 | +} // namespace o2 |
0 commit comments