Project
Loading...
Searching...
No Matches
ROBoardConfigHandler.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
18
19#include <algorithm>
20#include <fstream>
21#include <iostream>
22#include <sstream>
23#include <string>
24#include "fmt/format.h"
25#include "MIDRaw/CrateMapper.h"
26
27namespace o2
28{
29namespace mid
30{
31
36
41
43{
44 load(in);
45}
46
47ROBoardConfigHandler::ROBoardConfigHandler(const std::vector<ROBoardConfig>& configurations)
48{
49 set(configurations);
50}
51
52const ROBoardConfig ROBoardConfigHandler::getConfig(uint8_t uniqueLocId) const
53{
54 auto cfgIt = mROBoardConfigs.find(uniqueLocId);
55 if (cfgIt == mROBoardConfigs.end()) {
56 throw std::runtime_error(fmt::format("Cannot find local board {:02x}", uniqueLocId));
57 }
58 return cfgIt->second;
59}
60
61void ROBoardConfigHandler::load(std::istream& in)
62{
63 std::vector<ROBoardConfig> configurations;
64 std::string line, token;
65 while (std::getline(in, line)) {
66 if (std::count(line.begin(), line.end(), ' ') < 5) {
67 continue;
68 }
69 if (line.find('#') < line.find(' ')) {
70 continue;
71 }
72 ROBoardConfig cfg;
73 std::stringstream ss;
74 ss << line;
75 std::getline(ss, token, ' ');
76 cfg.boardId = static_cast<uint8_t>(std::strtol(token.c_str(), nullptr, 16));
77 std::getline(ss, token, ' ');
78 cfg.configWord = static_cast<uint32_t>(std::strtol(token.c_str(), nullptr, 16));
79 for (int ich = 0; ich < 4; ++ich) {
80 std::getline(ss, token, ' ');
81 auto mask = static_cast<uint32_t>(std::strtol(token.c_str(), nullptr, 16));
82 cfg.masksBP[ich] = (mask >> 16) & 0xFFFF;
83 cfg.masksNBP[ich] = (mask & 0xFFFF);
84 }
85 configurations.emplace_back(cfg);
86 }
87 set(configurations);
88}
89
90bool ROBoardConfigHandler::load(const char* filename)
91{
92 std::ifstream inFile(filename);
93 if (!inFile.is_open()) {
94 return false;
95 }
96 load(inFile);
97 return true;
98}
99
100void ROBoardConfigHandler::write(std::ostream& out) const
101{
102 std::vector<ROBoardConfig> configs;
103 for (auto& cfgIt : mROBoardConfigs) {
104 configs.emplace_back(cfgIt.second);
105 }
106
107 std::sort(configs.begin(), configs.end(), [](const ROBoardConfig& cfg1, const ROBoardConfig& cfg2) { return cfg1.boardId < cfg2.boardId; });
108
109 for (auto& cfg : configs) {
110 out << cfg << "\n";
111 }
112}
113
115{
116 std::ofstream outFile(filename);
117 write(outFile);
118 outFile.close();
119}
120
121void ROBoardConfigHandler::set(const std::vector<ROBoardConfig>& configurations)
122{
123 mROBoardConfigs.clear();
124 for (auto& cfg : configurations) {
125 mROBoardConfigs.emplace(cfg.boardId, cfg);
126 }
127}
128
129void ROBoardConfigHandler::updateMasks(const std::vector<ROBoard>& masks)
130{
131 for (auto& mask : masks) {
132 auto cfgIt = mROBoardConfigs.find(mask.boardId);
133
134 bool isMasked = false;
135 for (int ich = 0; ich < 4; ++ich) {
136 if (mask.patternsBP[ich] != 0xFFFF || mask.patternsNBP[ich] != 0xFFFF) {
137 isMasked = true;
138 }
139 }
140
141 if (isMasked) {
142 cfgIt->second.configWord |= crateconfig::sMonmoff;
143 cfgIt->second.masksBP = mask.patternsBP;
144 cfgIt->second.masksNBP = mask.patternsNBP;
145 }
146 }
147}
148
149std::vector<ROBoardConfig> makeZSROBoardConfig(uint16_t gbtUniqueId)
150{
151 // In this configuration, data from one local board
152 // (reading the output from 4 detection planes)
153 // is transmitted if at least one strip in X AND Y are fired on the same detection plane.
154 std::vector<ROBoardConfig> configurations;
155 CrateMapper crateMapper;
156 auto locIds = crateMapper.getROBoardIds(gbtUniqueId);
157 for (auto& locId : locIds) {
158 ROBoardConfig cfg;
159 cfg.configWord = crateconfig::sTxDataMask;
160 cfg.boardId = locId;
161 configurations.emplace_back(cfg);
162 }
163 return configurations;
164}
165
166std::vector<ROBoardConfig> makeNoZSROBoardConfig(uint16_t gbtUniqueId)
167{
168 // In this configuration, no zero suppression is performed.
169 // Data from one local board are transmitted as soon as one strip in X OR Y is fired.
170 auto configurations = makeZSROBoardConfig(gbtUniqueId);
171 for (auto& cfg : configurations) {
172 cfg.configWord |= crateconfig::sXorY;
173 }
174 return configurations;
175}
176
177std::vector<ROBoardConfig> makeDefaultROBoardConfig(uint16_t gbtUniqueId)
178{
179 // Originally, the electronics was configured to apply the zero suppression as explained in makeZSROBoardConfig.
180 // However, this logic implies that, when a Y strip covers several local boards,
181 // the signal is copied to all local boards.
182 // This is not the case in the current electronics setup: when an Y strip covers several local boards
183 // the signal is sent to the first board only and no copy of the signal is sent to the others.
184 // If we try to apply zero suppression with this setup, we have a bias.
185 // Indeed, when a board without direct Y signal is fired, we have that:
186 // - the board only transmits its X signal
187 // - the neighbour board with Y signal has no X signal. If we require X AND Y we lose the Y signal.
188 // If we do not change the setup, we are therefore obliged to release the zero suppression.
189 return makeNoZSROBoardConfig(gbtUniqueId);
190}
191
192} // namespace mid
193} // namespace o2
Mapper to convert the RO Ids to a format suitable for O2.
std::vector< uint8_t > getROBoardIds(uint16_t gbtUniqueId=0xFFFF) const
Returns the list of local board IDs (RO convention)
const ROBoardConfig getConfig(uint8_t uniqueLocId) const
void write(const char *filename) const
void updateMasks(const std::vector< ROBoard > &masks)
void set(const std::vector< ROBoardConfig > &configurations)
ROBoardConfigHandler()
Default constructor.
GLint GLuint mask
Definition glcorearb.h:291
std::vector< ROBoardConfig > makeNoZSROBoardConfig(uint16_t gbtUniqueId=0xFFFF)
std::vector< ROBoardConfig > makeDefaultROBoardConfig(uint16_t gbtUniqueId=0xFFFF)
std::vector< ROBoardConfig > makeZSROBoardConfig(uint16_t gbtUniqueId=0xFFFF)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::string filename()