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
19
21{
22
23 // --- Constructor ------------------------------------------------------------------
25
26 // ------------------------------------------------------------------------------------
27
28
29 // --- Destructor -----------------------------------------------------------------
31 // ------------------------------------------------------------------------------------
32
33
34 // --- Equipment IDs --------------------------------------------------------------
35 std::vector<uint16_t> ReadoutConfig::GetEquipmentIds()
36 {
37 std::vector<uint16_t> result;
38 for (auto& entry : fReadoutMap)
39 result.push_back(entry.first);
40 return result;
41 }
42 // ------------------------------------------------------------------------------------
43
44
45 // --- Number of Asics for a component / equipment -------------------------------
46 size_t ReadoutConfig::GetNumAsics(uint16_t equipmentId)
47 {
48 size_t result = 0;
49 auto it = fChannelMap.find(equipmentId);
50 if (it != fChannelMap.end()) result = fChannelMap[equipmentId].size();
51 return result;
52 }
53 // ------------------------------------------------------------------------------------
54
55 // --- List of ASICs registered to the ROB ---------------------
56 std::vector<uint8_t> ReadoutConfig::GetAsicList(uint16_t equipmentId)
57 {
58 std::vector<uint8_t> result;
59 for (auto& entry : fChannelMap[equipmentId])
60 result.push_back(entry.first);
61 return result;
62 }
63 // ------------------------------------------------------------------------------------
64
65
66 // --- Number of Channels for a component / equipment, asic pair ---------------------
67 size_t ReadoutConfig::GetNumChans(uint16_t equipmentId, uint16_t asicId)
68 {
69 size_t result = 0;
70 auto it = fChannelMap.find(equipmentId);
71 if (it != fChannelMap.end()) {
72 auto fiberMap = fChannelMap[equipmentId];
73 auto jt = fiberMap.find(asicId);
74 if (jt != fiberMap.end()) {
75 result = fiberMap[asicId].size();
76 }
77 }
78 return result;
79 }
80 // ------------------------------------------------------------------------------------
81
82 // --- Initialise the component mapping structure ----------------------------------
83 void ReadoutConfig::InitComponentMap(const std::map<uint32_t, std::vector<uint16_t>>& map)
84 {
85 // Receive map (moduleId, crobId) -> (equipId)
86 // Invert to obtain component map (equipId) -> (module iq, crob id)
87 for (auto& entry : map) {
88 uint16_t mod_id = entry.first;
89 //for (uint8_t eq_id = 0; eq_id < NROBMOD * NELINKROB; eq_id++) {
90 uint8_t eq_id = 0;
91 for (const auto& eq_add : entry.second) {
92 //uint16_t eq_id = entry.second[elink_id];
93 fReadoutMap[eq_add] = {mod_id, eq_id++};
94 }
95 }
96 }
97 // ------------------------------------------------------------------------------------
98
99 // --- Initialise the mapping structure --------------------------------------------
101 const std::map<size_t, std::map<size_t, std::map<size_t, std::tuple<int32_t, bool, uint8_t, uint16_t>>>>&
102 channelMap)
103 {
104 // Constructing the map (equipId, asicId, chanId) -> (pad address, mask flag, daq offset)
105 for (auto compMap : channelMap) {
106 uint16_t equipmentId = compMap.first;
107 // uint16_t numAsics = compMap.second.size();
108 for (auto asicMap : compMap.second) {
109 uint16_t asicId = asicMap.first;
110 // uint16_t numChans = asicMap.second.size();
111 fChannelMap[equipmentId][asicId].resize(16);
112 for (auto chanMap : asicMap.second) {
113 uint16_t chanId = chanMap.first;
114 std::tuple<int32_t, bool, uint8_t, uint16_t> chanPars = chanMap.second;
115 const ChanMapping entry = {std::get<0>(chanPars), std::get<1>(chanPars), std::get<2>(chanPars),
116 std::get<3>(chanPars)};
117 fChannelMap[equipmentId][asicId][chanId] = entry;
118 }
119 }
120 }
121 }
122 // ------------------------------------------------------------------------------------
123
124
125 // --- Mapping (equimentId, asicId, channel) -> (pad address, mask flag, daq offset) -----
126 ReadoutConfig::ChanMapping ReadoutConfig::ChanMap(uint16_t equipId, uint16_t asicId, uint16_t chanId)
127 {
128 ChanMapping result = {-1, false, 0, 0};
129 auto it = fChannelMap.find(equipId);
130 if (it != fChannelMap.end()) {
131 auto fiberMap = fChannelMap[equipId];
132 auto jt = fiberMap.find(asicId);
133 if (jt != fiberMap.end()) {
134 auto asic = fiberMap[asicId];
135 if (chanId < asic.size()) {
136 result = asic[chanId];
137 }
138 }
139 }
140 return result;
141 }
142 // ------------------------------------------------------------------------------------
143
144
145 // --- Mapping (equimentId) -> (module id, crob id) ---------------------------------
147 {
148 CompMapping result = {};
149 auto equipIter = fReadoutMap.find(equipId);
150 if (equipIter != fReadoutMap.end()) {
151 result = equipIter->second;
152 }
153 return result;
154 }
155 // ------------------------------------------------------------------------------------
156
157
158 // ----- Print readout map ------------------------------------------------
160 {
161 std::stringstream ss;
162 for (auto comp : fReadoutMap) {
163 uint16_t equipmentId = comp.first;
164 auto value = comp.second;
165 uint16_t moduleId = value.moduleId;
166 uint16_t fiberId = value.fiberId;
167 ss << "Equipment 0x" << std::hex << (int) equipmentId << " Module " << moduleId << " fiberId " << fiberId << "\n";
168 }
169 ss << "\n";
170
171 for (auto asicMap : fChannelMap) {
172 uint16_t equipmentId = asicMap.first;
173 uint16_t numAsics = asicMap.second.size();
174 ss << "\n Equipment 0x" << std::hex << (int) equipmentId << " nAsics " << numAsics;
175
176 int asicCnt(0);
177 auto asics = asicMap.second;
178 for (auto asic : asics) {
179 int asicId = asic.first;
180 auto asicChs = asic.second;
181 uint16_t numChans = asicChs.size();
182 ss << "\n " << asicCnt << " AsicId " << asicId << " nChans " << numChans;
183 for (size_t chanId = 0; chanId < numChans; chanId++) {
184 auto entry = asicChs.at(chanId);
185 int32_t address = entry.padAddress;
186 bool isMasked = entry.maskFlag;
187 uint8_t tOffset = entry.tOffset;
188 uint16_t thres = entry.lThreshold;
189 ss << "\n chanID " << chanId << " {pad " << address << " mask " << isMasked << " time offset[clk] "
190 << (int) tOffset << " threshold[" << (thres > 0 ? "on" : "off") << "]}";
191 }
192 asicCnt++;
193 }
194 }
195 ss << "\n";
196 return ss.str();
197 }
198 // ----------------------------------------------------------------------------
199
200
201} // namespace cbm::algo::trd2d
#define CBM_YAML_INSTANTIATE(type)
Explicitly instantiate the Read and Dump functions for a type.
Definition Yaml.h:305
Provides the hardware-to-software address mapping for the CBM-TRD2D.
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,...
size_t GetNumAsics(uint16_t equipmentId)
Number of ASICS of a component.
std::string PrintReadoutMap()
Debug output of readout map.
size_t GetNumChans(uint16_t equipmentId, uint16_t asicId)
Number of channels of a component - ASIC pair.
void InitComponentMap(const std::map< uint32_t, std::vector< uint16_t > > &map)
Initialisation of readout map.
std::vector< uint8_t > GetAsicList(uint16_t equipmentId)
Number of ASICS of a component.
std::vector< uint16_t > GetEquipmentIds()
Equipment in the configuration.
void InitChannelMap(const std::map< size_t, std::map< size_t, std::map< size_t, std::tuple< int32_t, bool, uint8_t, uint16_t > > > > &channelMap)
Initialisation of channel map.
std::map< uint16_t, CompMapping > fReadoutMap
std::map< uint16_t, std::map< uint8_t, std::vector< ChanMapping > > > fChannelMap
CompMapping CompMap(uint16_t equipId)
API: Mapping from component to pair (module id, crob id)