CbmRoot
Loading...
Searching...
No Matches
trd2d/ReadoutConfig.cxx
Go to the documentation of this file.
1/* Copyright (C) 2023-2025 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Volker Friese, Dominik Smith [committer], Alex Bercuci */
4
5#include "ReadoutConfig.h"
6
7//#include "CbmTrdAddress.h"
9
10#include <cassert>
11#include <iomanip>
12#include <iostream>
13#include <iterator>
14
15using std::pair;
16using std::setw;
17
20
22{
23
24 // --- Constructor ------------------------------------------------------------------
26
27 // ------------------------------------------------------------------------------------
28
29
30 // --- Destructor -----------------------------------------------------------------
32 // ------------------------------------------------------------------------------------
33
35 {
36 ChanDescriptor result;
37 if (fCalibMap.find(modId) == fCalibMap.end()) return result;
38 if (padId >= NFASPMOD * NFASPCH) return result;
39 result = fCalibMap[modId][padId];
40 return result;
41 }
42
43
44 // --- Constructor ------------------------------------------------------------------
46
47 // ------------------------------------------------------------------------------------
48
49
50 // --- Destructor -----------------------------------------------------------------
52 // ------------------------------------------------------------------------------------
53
54
55 // --- Equipment IDs --------------------------------------------------------------
56 std::vector<uint16_t> ReadoutSetup::GetEquipmentIds()
57 {
58 std::vector<uint16_t> result;
59 for (auto& entry : fReadoutMap)
60 result.push_back(entry.first);
61 return result;
62 }
63 // ------------------------------------------------------------------------------------
64
65
66 // --- Number of Asics for a component / equipment -------------------------------
67 size_t ReadoutSetup::GetNumAsics(uint16_t equipmentId)
68 {
69 size_t result = 0;
70 auto it = fChannelMap.find(equipmentId);
71 if (it != fChannelMap.end()) result = fChannelMap[equipmentId].size();
72 return result;
73 }
74 // ------------------------------------------------------------------------------------
75
76 // --- List of ASICs registered to the ROB ---------------------
77 std::vector<uint8_t> ReadoutSetup::GetAsicList(uint16_t equipmentId)
78 {
79 std::vector<uint8_t> result;
80 for (auto& entry : fChannelMap[equipmentId])
81 result.push_back(entry.first);
82 return result;
83 }
84 // ------------------------------------------------------------------------------------
85
86
87 // --- Number of Channels for a component / equipment, asic pair ---------------------
88 size_t ReadoutSetup::GetNumChans(uint16_t equipmentId, uint16_t asicId)
89 {
90 size_t result = 0;
91 auto it = fChannelMap.find(equipmentId);
92 if (it != fChannelMap.end()) {
93 auto fiberMap = fChannelMap[equipmentId];
94 auto jt = fiberMap.find(asicId);
95 if (jt != fiberMap.end()) {
96 result = fiberMap[asicId].size();
97 }
98 }
99 return result;
100 }
101 // ------------------------------------------------------------------------------------
102
103 // --- Initialise the component mapping structure ----------------------------------
104 void ReadoutSetup::InitComponentMap(const std::map<uint32_t, std::vector<uint16_t>>& map)
105 {
106 // Receive map (moduleId, crobId) -> (equipId)
107 // Invert to obtain component map (equipId) -> (module iq, crob id)
108 for (auto& entry : map) {
109 uint16_t mod_id = entry.first;
110 //for (uint8_t eq_id = 0; eq_id < NROBMOD * NELINKROB; eq_id++) {
111 uint8_t eq_id = 0;
112 for (const auto& eq_add : entry.second) {
113 //uint16_t eq_id = entry.second[elink_id];
114 fReadoutMap[eq_add] = {mod_id, eq_id++};
115 }
116 }
117 }
118 // ------------------------------------------------------------------------------------
119
120 // --- Initialise the mapping structure --------------------------------------------
122 const std::map<size_t, std::map<size_t, std::map<size_t, std::tuple<int32_t, bool, int16_t, uint16_t>>>>&
123 channelMap)
124 {
125 // Constructing the map (equipId, asicId, chanId) -> (pad address, mask flag, daq offset)
126 for (auto compMap : channelMap) {
127 uint16_t equipmentId = compMap.first;
128 // uint16_t numAsics = compMap.second.size();
129 for (auto asicMap : compMap.second) {
130 uint16_t asicId = asicMap.first;
131 // uint16_t numChans = asicMap.second.size();
132 fChannelMap[equipmentId][asicId].resize(16);
133 for (auto chanMap : asicMap.second) {
134 uint16_t chanId = chanMap.first;
135 std::tuple<int32_t, bool, int8_t, uint16_t> chanPars = chanMap.second;
136 const ChanMapping entry = {std::get<0>(chanPars), std::get<1>(chanPars), std::get<2>(chanPars),
137 std::get<3>(chanPars)};
138 fChannelMap[equipmentId][asicId][chanId] = entry;
139 }
140 }
141 }
142 }
143 // ------------------------------------------------------------------------------------
144
145
146 // --- Mapping (equimentId, asicId, channel) -> (pad address, mask flag, daq offset) -----
147 ReadoutSetup::ChanMapping ReadoutSetup::ChanMap(uint16_t equipId, uint16_t asicId, uint16_t chanId)
148 {
149 ChanMapping result = {-1, false, 0, 0};
150 auto it = fChannelMap.find(equipId);
151 if (it != fChannelMap.end()) {
152 auto fiberMap = fChannelMap[equipId];
153 auto jt = fiberMap.find(asicId);
154 if (jt != fiberMap.end()) {
155 auto asic = fiberMap[asicId];
156 if (chanId < asic.size()) {
157 result = asic[chanId];
158 }
159 }
160 }
161 return result;
162 }
163 // ------------------------------------------------------------------------------------
164
165
166 // --- Mapping (equimentId) -> (module id, crob id) ---------------------------------
168 {
169 CompMapping result = {};
170 auto equipIter = fReadoutMap.find(equipId);
171 if (equipIter != fReadoutMap.end()) {
172 result = equipIter->second;
173 }
174 return result;
175 }
176 // ------------------------------------------------------------------------------------
177
178
179 // ----- Print readout map ------------------------------------------------
181 {
182 std::stringstream ss;
183 for (auto comp : fReadoutMap) {
184 uint16_t equipmentId = comp.first;
185 auto value = comp.second;
186 uint16_t moduleId = value.moduleId;
187 uint16_t fiberId = value.fiberId;
188 ss << "Equipment 0x" << std::hex << (int) equipmentId << " Module " << moduleId << " fiberId " << fiberId << "\n";
189 }
190 ss << "\n";
191
192 for (auto asicMap : fChannelMap) {
193 uint16_t equipmentId = asicMap.first;
194 uint16_t numAsics = asicMap.second.size();
195 ss << "\n Equipment 0x" << std::hex << (int) equipmentId << " nAsics " << numAsics;
196
197 int asicCnt(0);
198 auto asics = asicMap.second;
199 for (auto asic : asics) {
200 int asicId = asic.first;
201 auto asicChs = asic.second;
202 uint16_t numChans = asicChs.size();
203 ss << "\n " << asicCnt << " AsicId " << asicId << " nChans " << numChans;
204 for (size_t chanId = 0; chanId < numChans; chanId++) {
205 auto entry = asicChs.at(chanId);
206 int32_t address = entry.padAddress;
207 bool isMasked = entry.maskFlag;
208 uint8_t tOffset = entry.tOffset;
209 uint16_t thres = entry.lThreshold;
210 ss << "\n chanID " << chanId << " {pad " << address << " mask " << isMasked << " time offset[clk] "
211 << (int) tOffset << " threshold[" << (thres > 0 ? "on" : "off") << "]}";
212 }
213 asicCnt++;
214 }
215 }
216 ss << "\n";
217 return ss.str();
218 }
219 // ----------------------------------------------------------------------------
220
221
222 // ----- Print readout map ------------------------------------------------
224 {
225 std::stringstream ss;
226 ss << "fCalibMap.size=" << fCalibMap.size() << "\n";
227 for (const auto& [mod, pars] : fCalibMap) {
228 ss << "Mod 0x" << mod << "\n";
229 int ipar(0);
230 for (auto par : pars) {
231 if (ipar % NFASPCH == 0) ss << "\t";
232 ss << " " << std::setw(4) << par.gainfee;
233 if (ipar % NFASPCH == NFASPCH - 1) ss << "\n";
234 ipar++;
235 }
236 }
237 return ss.str();
238 }
239 // ----------------------------------------------------------------------------
240
241
242} // namespace cbm::algo::trd2d
#define CBM_YAML_INSTANTIATE(type)
Explicitly instantiate the Read and Dump functions for a type.
Definition Yaml.h:305
std::string PrintCalibMap()
Debug output of readout map.
std::map< uint16_t, std::array< ChanDescriptor, NFASPMOD *NFASPCH > > fCalibMap
reference signal [ADU] to which the FEE gain is refereed
ChanDescriptor GetChannelFeeCalib(uint16_t modId, uint16_t padId)
Retrieve calibration for one channel.
std::vector< uint8_t > GetAsicList(uint16_t equipmentId)
Number of ASICS of a component.
ChanMapping ChanMap(uint16_t equipId, uint16_t asic, uint16_t chan)
API: Mapping from component, asic and channel to tuple (pad address, R pairing flag,...
std::map< uint16_t, CompMapping > fReadoutMap
std::map< uint16_t, std::map< uint8_t, std::vector< ChanMapping > > > fChannelMap
std::string PrintReadoutMap()
Debug output of readout map.
std::vector< uint16_t > GetEquipmentIds()
Equipment in the configuration.
void InitComponentMap(const std::map< uint32_t, std::vector< uint16_t > > &map)
Initialisation of readout map.
size_t GetNumAsics(uint16_t equipmentId)
Number of ASICS of a component.
void InitChannelMap(const std::map< size_t, std::map< size_t, std::map< size_t, std::tuple< int32_t, bool, int16_t, uint16_t > > > > &channelMap)
Initialisation of channel map.
size_t GetNumChans(uint16_t equipmentId, uint16_t asicId)
Number of channels of a component - ASIC pair.
CompMapping CompMap(uint16_t equipId)
API: Mapping from component to pair (module id, crob id)
#define NFASPCH
#define NFASPMOD