CbmRoot
Loading...
Searching...
No Matches
trd2d/ReadoutConfig.cxx
Go to the documentation of this file.
1/* Copyright (C) 2023 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Volker Friese, Dominik Smith [committer] */
4
5#include "ReadoutConfig.h"
6
7//#include "CbmTrdAddress.h"
8
9#include <cassert>
10#include <iomanip>
11#include <iostream>
12#include <iterator>
13
14using std::pair;
15using std::setw;
16
18
20{
21
22 // --- Constructor ------------------------------------------------------------------
24
25 // ------------------------------------------------------------------------------------
26
27
28 // --- Destructor -----------------------------------------------------------------
30 // ------------------------------------------------------------------------------------
31
32
33 // --- Equipment IDs --------------------------------------------------------------
34 std::vector<uint16_t> ReadoutConfig::GetEquipmentIds()
35 {
36 std::vector<uint16_t> result;
37 for (auto& entry : fReadoutMap)
38 result.push_back(entry.first);
39 return result;
40 }
41 // ------------------------------------------------------------------------------------
42
43
44 // --- Number of Asics for a component / equipment -------------------------------
45 size_t ReadoutConfig::GetNumAsics(uint16_t equipmentId)
46 {
47 size_t result = 0;
48 auto it = fChannelMap.find(equipmentId);
49 if (it != fChannelMap.end()) result = fChannelMap[equipmentId].size();
50 return result;
51 }
52 // ------------------------------------------------------------------------------------
53
54
55 // --- Number of Channels for a component / equipment, asic pair ---------------------
56 size_t ReadoutConfig::GetNumChans(uint16_t equipmentId, uint16_t asicId)
57 {
58 size_t result = 0;
59 auto it = fChannelMap.find(equipmentId);
60 if (it != fChannelMap.end()) {
61 if (asicId < fChannelMap[equipmentId].size()) {
62 result = fChannelMap[equipmentId][asicId].size();
63 }
64 }
65 return result;
66 }
67 // ------------------------------------------------------------------------------------
68
69 // --- Initialise the component mapping structure ----------------------------------
70 void ReadoutConfig::InitComponentMap(const std::map<uint32_t, uint16_t[NCROBMOD]>& map)
71 {
72 // Receive map (moduleId, crobId) -> (equipId)
73 // Invert to obtain component map (equipId) -> (module iq, crob id)
74 for (auto& entry : map) {
75 uint16_t mod_id = entry.first;
76 for (uint8_t crob_id = 0; crob_id < NCROBMOD; crob_id++) {
77 uint16_t eq_id = entry.second[crob_id];
78 if (!eq_id) continue;
79 fReadoutMap[eq_id] = {mod_id, crob_id};
80 }
81 }
82 }
83 // ------------------------------------------------------------------------------------
84
85 // --- Initialise the mapping structure --------------------------------------------
87 const std::map<size_t, std::map<size_t, std::map<size_t, std::tuple<int32_t, bool, uint64_t>>>>& channelMap)
88 {
89 // Constructing the map (equipId, asicId, chanId) -> (pad address, mask flag, daq offset)
90 for (auto compMap : channelMap) {
91 uint16_t equipmentId = compMap.first;
92 uint16_t numAsics = compMap.second.size();
93 fChannelMap[equipmentId].resize(numAsics);
94
95 for (auto asicMap : compMap.second) {
96 uint16_t asicId = asicMap.first;
97 uint16_t numChans = asicMap.second.size();
98 fChannelMap[equipmentId][asicId].resize(numChans);
99 for (auto chanMap : asicMap.second) {
100 uint16_t chanId = chanMap.first;
101 std::tuple<int32_t, bool, uint64_t> chanPars = chanMap.second;
102 ChanMapping entry = {std::get<0>(chanPars), std::get<1>(chanPars), std::get<2>(chanPars)};
103 fChannelMap[equipmentId][asicId][chanId] = entry;
104 }
105 }
106 }
107 }
108 // ------------------------------------------------------------------------------------
109
110
111 // --- Mapping (equimentId, asicId, channel) -> (pad address, mask flag, daq offset) -----
112 ReadoutConfig::ChanMapping ReadoutConfig::ChanMap(uint16_t equipId, uint16_t asic, uint16_t chan)
113 {
114 ChanMapping result = {-1, false, 0};
115 auto it = fChannelMap.find(equipId);
116 if (it != fChannelMap.end()) {
117 if (asic < fChannelMap[equipId].size()) {
118 if (chan < fChannelMap[equipId][asic].size()) {
119 result = fChannelMap[equipId][asic][chan];
120 }
121 }
122 }
123 return result;
124 }
125 // ------------------------------------------------------------------------------------
126
127
128 // --- Mapping (equimentId) -> (module id, crob id) ---------------------------------
130 {
131 CompMapping result = {};
132 auto equipIter = fReadoutMap.find(equipId);
133 if (equipIter != fReadoutMap.end()) {
134 result = equipIter->second;
135 }
136 return result;
137 }
138 // ------------------------------------------------------------------------------------
139
140
141 // ----- Print readout map ------------------------------------------------
143 {
144 std::stringstream ss;
145 for (auto comp : fReadoutMap) {
146 uint16_t equipmentId = comp.first;
147 auto value = comp.second;
148 uint16_t moduleId = value.moduleId;
149 uint16_t crobId = value.crobId;
150 ss << "Equipment " << equipmentId << " Module " << moduleId << " Crob " << crobId << "\n";
151 }
152 ss << "\n";
153
154 for (auto asicMap : fChannelMap) {
155 uint16_t equipmentId = asicMap.first;
156 uint16_t numAsics = asicMap.second.size();
157 ss << "\n Equipment " << equipmentId << " nAsics " << numAsics;
158 for (size_t asicId = 0; asicId < numAsics; asicId++) {
159
160 uint16_t numChans = asicMap.second.at(asicId).size();
161 ss << "\n Equipment " << equipmentId << " AsicId " << asicId << " nChans " << numChans;
162 for (size_t chanId = 0; chanId < numChans; chanId++) {
163 auto entry = asicMap.second.at(asicId).at(chanId);
164 int32_t address = entry.padAddress;
165 bool isMasked = entry.rPairingFlag;
166 uint64_t daqOffset = entry.daqOffset;
167 ss << "\n Equipment " << equipmentId << " AsicId " << asicId << " chanID " << chanId << " pad address "
168 << address << " mask " << isMasked << " daq offset " << daqOffset;
169 }
170 }
171 }
172 ss << "\n";
173 return ss.str();
174 }
175 // ----------------------------------------------------------------------------
176
177
178} // namespace cbm::algo::trd2d
static constexpr size_t size()
Definition KfSimdPseudo.h:2
#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 InitChannelMap(const std::map< size_t, std::map< size_t, std::map< size_t, std::tuple< int32_t, bool, uint64_t > > > > &channelMap)
Initialisation of channel map.
std::vector< uint16_t > GetEquipmentIds()
Equipment in the configuration.
void InitComponentMap(const std::map< uint32_t, uint16_t[NCROBMOD]> &crob_map)
Initialisation of readout map.
std::map< uint16_t, std::vector< std::vector< ChanMapping > > > fChannelMap
std::map< uint16_t, CompMapping > fReadoutMap
CompMapping CompMap(uint16_t equipId)
API: Mapping from component to pair (module id, crob id)
#define NCROBMOD