CbmRoot
Loading...
Searching...
No Matches
trd/ReadoutConfig.cxx
Go to the documentation of this file.
1/* Copyright (C) 2022 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Volker Friese [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
19namespace cbm::algo::trd
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 Crobs for a component / equipment -------------------------------
45 size_t ReadoutConfig::GetNumCrobs(uint16_t equipmentId)
46 {
47 size_t result = 0;
48 auto it = fReadoutMap.find(equipmentId);
49 if (it != fReadoutMap.end()) result = fReadoutMap[equipmentId].size();
50 return result;
51 }
52 // ------------------------------------------------------------------------------------
53
54
55 // --- Number of Elinks for a component / equipment, crob pair ---------------------
56 size_t ReadoutConfig::GetNumElinks(uint16_t equipmentId, uint16_t crobId)
57 {
58 size_t result = 0;
59 if (crobId < GetNumCrobs(equipmentId)) result = fReadoutMap[equipmentId][crobId].size();
60 return result;
61 }
62 // ------------------------------------------------------------------------------------
63
64
65 // --- Initialise the mapping structure --------------------------------------------
66 void ReadoutConfig::Init(const std::map<size_t, std::map<size_t, std::map<size_t, size_t>>>& addressMap,
67 std::map<size_t, std::map<size_t, std::map<size_t, std::map<size_t, size_t>>>>& channelMap)
68 {
69 // Constructing the map (equipmentId, crobId, eLink) -> (ASIC address)
70 for (auto compMap : addressMap) {
71 uint16_t equipmentId = compMap.first;
72 uint16_t numCrobs = compMap.second.size();
73 fReadoutMap[equipmentId].resize(numCrobs);
74
75 for (auto crobMap : compMap.second) {
76 uint16_t crobId = crobMap.first;
77 uint16_t numElinks = crobMap.second.size();
78 fReadoutMap[equipmentId][crobId].resize(numElinks);
79
80 for (auto elinkMap : crobMap.second) {
81 uint16_t elinkId = elinkMap.first;
82 uint16_t address = elinkMap.second;
83 fReadoutMap[equipmentId][crobId][elinkId] = address;
84 }
85 }
86 }
87
88 // Constructing the map (equipmentId, crobId, eLink, chan) -> (chan address)
89 for (auto compMap : channelMap) {
90 uint16_t equipmentId = compMap.first;
91 uint16_t numCrobs = compMap.second.size();
92 fChannelMap[equipmentId].resize(numCrobs);
93
94 for (auto crobMap : compMap.second) {
95 uint16_t crobId = crobMap.first;
96 uint16_t numElinks = crobMap.second.size();
97 fChannelMap[equipmentId][crobId].resize(numElinks);
98
99 for (auto elinkMap : crobMap.second) {
100 uint16_t elinkId = elinkMap.first;
101 uint16_t numChans = elinkMap.second.size();
102 fChannelMap[equipmentId][crobId][elinkId].resize(numChans);
103
104 for (auto chanMap : elinkMap.second) {
105 uint16_t chanId = chanMap.first;
106 uint32_t address = chanMap.second;
107 fChannelMap[equipmentId][crobId][elinkId][chanId] = address;
108 }
109 }
110 }
111 }
112 }
113 // ------------------------------------------------------------------------------------
114
115
116 // --- Mapping (equimentId, crobId, elink) -> (ASIC address, channel addresses) -----
117 std::pair<int32_t, std::vector<uint32_t>> ReadoutConfig::Map(uint16_t equipmentId, uint16_t crobId, uint16_t elinkId)
118 {
119 std::pair<int32_t, std::vector<uint32_t>> result;
120 result.first = -1;
121 auto it = fChannelMap.find(equipmentId);
122 if (it != fChannelMap.end()) {
123 if (crobId < fChannelMap[equipmentId].size()) {
124 if (elinkId < fChannelMap[equipmentId][crobId].size()) {
125 result.first = fReadoutMap[equipmentId][crobId][elinkId];
126 result.second = fChannelMap[equipmentId][crobId][elinkId];
127 }
128 }
129 }
130 return result;
131 }
132 // ------------------------------------------------------------------------------------
133
134 void ReadoutConfig::SetElinkTimeOffset(uint32_t criid, uint8_t elinkid, int32_t offsetNs)
135 {
136 // create vector for criid if not yet existing
137 if (fElinkTimeOffsetMap.find(criid) == fElinkTimeOffsetMap.end()) {
138 //vector has fixed size of 256 (max elinkid) and is initialized to 0
139 fElinkTimeOffsetMap.insert(std::make_pair(criid, std::vector<int32_t>(256, 0)));
140 }
141
142 fElinkTimeOffsetMap[criid][elinkid] = offsetNs;
143 }
144
145 int32_t ReadoutConfig::GetElinkTimeOffset(uint32_t criid, uint8_t elinkid)
146 {
147 auto it = fElinkTimeOffsetMap.find(criid);
148 if (it == fElinkTimeOffsetMap.end()) {
149 return 0;
150 }
151
152 const auto& elinks = it->second;
153 return elinks.at(elinkid);
154 }
155
156
157 // ----- Print readout map ------------------------------------------------
159 {
160 std::stringstream ss;
161 for (auto compMap : fReadoutMap) {
162
163 uint16_t equipmentId = compMap.first;
164 uint16_t numCrobs = compMap.second.size();
165 ss << "\n Equipment " << equipmentId << " nCrobs " << numCrobs;
166 for (size_t crobId = 0; crobId < numCrobs; crobId++) {
167
168 uint16_t numElinks = compMap.second.at(crobId).size();
169 ss << "\n Equipment " << equipmentId << " CrobId " << crobId << " nElinks " << numElinks;
170 for (size_t elinkId = 0; elinkId < numElinks; elinkId++) {
171
172 uint16_t address = compMap.second.at(crobId).at(elinkId);
173 ss << "\n Equipment " << equipmentId << " CrobId " << crobId << " elinkID " << elinkId << " address "
174 << address;
175
176 //Now output channel addresses
177 ss << "\n Channels ";
178 auto vec = fChannelMap[equipmentId][crobId][elinkId];
179 std::copy(vec.begin(), vec.end() - 1, std::ostream_iterator<uint32_t>(ss, " "));
180 ss << vec.back();
181 }
182 }
183 }
184 ss << "\n";
185 return ss.str();
186 }
187 // ----------------------------------------------------------------------------
188
189
190} // namespace cbm::algo::trd
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-TRD.
std::vector< uint16_t > GetEquipmentIds()
Equipment in the configuration.
void Init(const std::map< size_t, std::map< size_t, std::map< size_t, size_t > > > &addressMap, std::map< size_t, std::map< size_t, std::map< size_t, std::map< size_t, size_t > > > > &channelMap)
Initialisation of readout map.
void SetElinkTimeOffset(uint32_t criid, uint8_t elinkid, int32_t offsetNs)
Register a time offeset to be substracted from the digis which come from a specific CRI.
std::pair< int32_t, std::vector< uint32_t > > Map(uint16_t equipId, uint16_t crob, uint16_t elink)
API: Mapping from component, crob and elink to pair (ASIC address, channel addresses)
int32_t GetElinkTimeOffset(uint32_t criid, uint8_t elinkid)
Get the time offeset to be substracted from the digis which come from a specific CRI.
size_t GetNumCrobs(uint16_t equipmentId)
Number of CROBS of a component.
std::string PrintReadoutMap()
Debug output of readout map.
std::map< uint32_t, std::vector< int32_t > > fElinkTimeOffsetMap
Map to store time offsets for each CRI&Elink combination.
std::map< uint16_t, std::vector< std::vector< std::vector< uint32_t > > > > fChannelMap
size_t GetNumElinks(uint16_t equipmentId, uint16_t crobId)
Number of elinks of a component - CROB pair.
std::map< uint16_t, std::vector< std::vector< uint16_t > > > fReadoutMap