Belle II Software development
ChannelMapper Class Reference

Provides mapping between electronic channels and pixels. More...

#include <ChannelMapper.h>

Public Types

enum  {
  c_numBoardstacks = 4 ,
  c_numCarrierBoards = 4 ,
  c_numAsics = 4 ,
  c_numChannels = 8 ,
  c_numRows = 2 ,
  c_numColumns = 16 ,
  c_numPixelRows = c_numRows * c_numCarrierBoards ,
  c_numPixelColumns = c_numColumns * c_numBoardstacks ,
  c_numPixels = c_numPixelRows * c_numPixelColumns ,
  c_invalidChannel = c_numPixels ,
  c_invalidPixelID = 0
}
 Enum for the number of different quantities etc. More...
 
enum  EType {
  c_unknown = 0 ,
  c_default = 1 ,
  c_IRS3B = 2 ,
  c_IRSX = 3
}
 Enum for electornic types. More...
 

Public Member Functions

 ChannelMapper ()
 constructor
 
void initialize (const GearDir &channelMapping)
 Initialize from Gearbox (XML)
 
void initialize ()
 Initialize from database.
 
bool isValid () const
 Checks if mapping is available.
 
void importPayload (const IntervalOfValidity &iov) const
 import mappings to database
 
EType getType () const
 Return electornic type (see enum)
 
const std::string & getName () const
 Return electornic name.
 
unsigned getChannel (int pixel) const
 Converts pixel to hardware channel number (0-based)
 
int getPixelID (unsigned channel) const
 Converts hardware channel number to pixel ID (1-based)
 
void print () const
 Print mappings to terminal screen.
 
void test () const
 test that the conversion and inverse of it gives identity, if not B2ERROR
 

Static Public Member Functions

static bool isPixelIDValid (int pixel)
 Checks validity of pixel ID.
 
static bool isChannelValid (unsigned channel)
 Checks validity of hardware channel number.
 
static unsigned getChannel (unsigned boardstack, unsigned carrier, unsigned asic, unsigned chan)
 Returns hardware channel number (0-based)
 
static void splitChannelNumber (unsigned channel, unsigned &boardstack, unsigned &carrier, unsigned &asic, unsigned &chan)
 Splits hardware channel number into boardstack, carrier, asic and asic channel.
 
static int getPmtID (int pixel)
 Returns PMT ID (1-based)
 

Private Member Functions

void clear ()
 Clear.
 
void update ()
 re-do conversion arrays when DBArray has changed
 

Private Attributes

EType m_type = c_unknown
 electornic type
 
std::string m_typeName
 electronic type name
 
std::vector< TOPChannelMapm_mapping
 mappings from gearbox
 
DBArray< TOPChannelMapm_mappingDB
 mappings from database
 
bool m_valid = false
 true if mapping available
 
bool m_fromDB = false
 true, if from database
 
const TOPChannelMapm_channels [c_numRows][c_numColumns] = {{0}}
 conversion array
 
const TOPChannelMapm_pixels [c_numAsics][c_numChannels] = {{0}}
 conversion array
 

Detailed Description

Provides mapping between electronic channels and pixels.

Definition at line 27 of file ChannelMapper.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

Enum for the number of different quantities etc.

Enumerator
c_numBoardstacks 

number of boardstacks per TOP module

c_numCarrierBoards 

number of carrier boards per boardstack

c_numAsics 

number of ASIC's per carrier board

c_numChannels 

number of channels per ASIC

c_numRows 

number of pixel rows per carrier board

c_numColumns 

number of pixel columns per carrier board

c_numPixelRows 

per module

c_numPixelColumns 

per module

c_numPixels 

per module

c_invalidChannel 

value of invalid channel number

c_invalidPixelID 

value of invalid pixel ID

Definition at line 33 of file ChannelMapper.h.

33 {c_numBoardstacks = 4,
34 c_numCarrierBoards = 4,
35 c_numAsics = 4,
36 c_numChannels = 8,
37 c_numRows = 2,
38 c_numColumns = 16,
39 c_numPixelRows = c_numRows * c_numCarrierBoards,
40 c_numPixelColumns = c_numColumns * c_numBoardstacks,
41 c_numPixels = c_numPixelRows * c_numPixelColumns,
42 c_invalidChannel = c_numPixels,
43 c_invalidPixelID = 0
44 };

◆ EType

enum EType

Enum for electornic types.

Definition at line 49 of file ChannelMapper.h.

49 {c_unknown = 0,
50 c_default = 1,
51 c_IRS3B = 2,
52 c_IRSX = 3
53 };

Constructor & Destructor Documentation

◆ ChannelMapper()

constructor

Definition at line 24 of file ChannelMapper.cc.

25 {
26 static_assert(c_numRows * c_numColumns == c_numAsics * c_numChannels,
27 "TOP::ChannelMapper: bug in coding (enum) - "
28 "number of channels and number of pixels disagree");
29
30 for (auto& channels : m_channels) {
31 for (auto& channel : channels) channel = 0;
32 }
33 for (auto& pixels : m_pixels) {
34 for (auto& pixel : pixels) pixel = 0;
35 }
36 }

Member Function Documentation

◆ clear()

void clear ( )
private

Clear.

Definition at line 324 of file ChannelMapper.cc.

325 {
326 m_mapping.clear();
327 for (auto& channels : m_channels) {
328 for (auto& channel : channels) channel = 0;
329 }
330 for (auto& pixels : m_pixels) {
331 for (auto& pixel : pixels) pixel = 0;
332 }
333 m_valid = false;
334 m_fromDB = false;
335 }

◆ getChannel() [1/2]

unsigned getChannel ( int pixel) const

Converts pixel to hardware channel number (0-based)

Parameters
pixelpixel ID (1-based)
Returns
channel number (or c_invalidChannel for invalid pixel)

Definition at line 198 of file ChannelMapper.cc.

199 {
200 if (!isPixelIDValid(pixel)) return c_invalidChannel; // cppcheck-suppress knownConditionTrueFalse
201
202 unsigned pix = pixel - 1;
203 unsigned pixRow = pix / c_numPixelColumns;
204 unsigned pixCol = pix % c_numPixelColumns;
205
206 unsigned carrier = pixRow / c_numRows;
207 unsigned row = pixRow % c_numRows;
208 unsigned boardstack = pixCol / c_numColumns;
209 unsigned col = pixCol % c_numColumns;
210
211 const auto& map = m_channels[row][col];
212 if (!map) {
213 B2WARNING("TOP::ChannelMapper: no channel mapped to pixel. Return invalid channel."
214 << LogVar("pixelID", pixel));
215 return c_invalidChannel;
216 }
217 unsigned asic = map->getASICNumber();
218 unsigned chan = map->getASICChannel();
219
220 return getChannel(boardstack, carrier, asic, chan);
221 }

◆ getChannel() [2/2]

static unsigned getChannel ( unsigned boardstack,
unsigned carrier,
unsigned asic,
unsigned chan )
inlinestatic

Returns hardware channel number (0-based)

Parameters
boardstackboardstack number (0-based)
carriercarrier board number (0-based)
asicASIC number (0-based)
chanASIC channel number (0-based)
Returns
channel number (or c_invalidChannel for invalid pixel)

Definition at line 131 of file ChannelMapper.h.

135 {
136 return chan + c_numChannels * (asic + c_numAsics *
137 (carrier + c_numCarrierBoards * boardstack));
138 }

◆ getName()

const std::string & getName ( ) const
inline

Return electornic name.

Returns
name

Definition at line 93 of file ChannelMapper.h.

93{return m_typeName;}

◆ getPixelID()

int getPixelID ( unsigned channel) const

Converts hardware channel number to pixel ID (1-based)

Parameters
channelhardware channel number (0-based)
Returns
pixel ID (or c_invalidPixelID for invalid channel number)

Definition at line 239 of file ChannelMapper.cc.

240 {
241
242 if (!isChannelValid(channel)) return c_invalidPixelID;
243
244 unsigned boardstack = 0;
245 unsigned carrier = 0;
246 unsigned asic = 0;
247 unsigned chan = 0;
248 splitChannelNumber(channel, boardstack, carrier, asic, chan);
249
250 const auto& map = m_pixels[asic][chan];
251 if (!map) {
252 B2ERROR("TOP::ChannelMapper: no pixel mapped to channel. Return invalid pixel."
253 << LogVar("channel", channel));
254 return c_invalidPixelID;
255 }
256 unsigned row = map->getRow();
257 unsigned col = map->getColumn();
258 unsigned pixRow = row + carrier * c_numRows;
259 unsigned pixCol = col + boardstack * c_numColumns;
260
261 return pixCol + pixRow * c_numPixelColumns + 1;
262
263 }

◆ getPmtID()

int getPmtID ( int pixel)
static

Returns PMT ID (1-based)

Parameters
pixelpixelID (1-based)
Returns
PMT ID (or 0 for invalid pixel)

Definition at line 265 of file ChannelMapper.cc.

266 {
267 if (not isPixelIDValid(pixel)) return 0; // cppcheck-suppress knownConditionTrueFalse
268 pixel--;
269 int pmtRow = pixel / 256;
270 int pmtCol = (pixel % 64) / 4;
271 return pmtRow * 16 + pmtCol + 1;
272 }

◆ getType()

EType getType ( ) const
inline

Return electornic type (see enum)

Returns
type

Definition at line 87 of file ChannelMapper.h.

87{return m_type;}

◆ importPayload()

void importPayload ( const IntervalOfValidity & iov) const

import mappings to database

Parameters
iovInterval of validity.

Definition at line 188 of file ChannelMapper.cc.

189 {
190 DBImportArray<TOPChannelMap> array;
191 for (const auto& map : m_mapping) {
192 array.appendNew(map);
193 }
194 array.import(iov);
195 }

◆ initialize() [1/2]

void initialize ( )

Initialize from database.

Definition at line 168 of file ChannelMapper.cc.

169 {
170 m_type = c_default;
171
172 if (!m_mappingDB.isValid()) {
173 clear();
174 return;
175 }
176 update();
177
178 m_mappingDB.addCallback(this, &ChannelMapper::update);
179
180 const auto& logSystem = LogSystem::Instance();
181 if (logSystem.isLevelEnabled(LogConfig::c_Debug, 100, "top")) {
182 print();
183 }
184
185 }

◆ initialize() [2/2]

void initialize ( const GearDir & channelMapping)

Initialize from Gearbox (XML)

Parameters
channelMappingXML data directory

Definition at line 39 of file ChannelMapper.cc.

40 {
41 clear();
42
43 string path = channelMapping.getPath();
44 auto i1 = path.rfind("type='") + 6;
45 auto i2 = path.rfind("']");
46 m_typeName = path.substr(i1, i2 - i1);
47
48 if (m_typeName == "IRS3B") {
49 m_type = c_IRS3B;
50 } else if (m_typeName == "IRSX") {
51 m_type = c_IRSX;
52 } else {
53 B2ERROR("TOP::ChannelMapper: unknown electronic type."
54 << LogVar("type", m_typeName));
55 }
56
57 // get parameters from Gearbox
58 for (const GearDir& map : channelMapping.getNodes("map")) {
59 std::vector<double> data = map.getArray("");
60 unsigned row = int(data[0]) - 1;
61 unsigned col = int(data[1]) - 1;
62 unsigned asic = int(data[2]);
63 unsigned chan = int(data[3]);
64 m_mapping.push_back(TOPChannelMap(row, col, asic, chan));
65 }
66 if (m_mapping.empty()) {
67 B2ERROR("TOP::ChannelMapper: mapping is not available in Gearbox");
68 return;
69 }
70
71 // check the size of the mapping
72 if (m_mapping.size() != c_numAsics * c_numChannels)
73 B2FATAL("TOP::ChannelMapper: got incorrect map size from xml file for '"
74 << m_typeName << "' - expect " << c_numAsics * c_numChannels
75 << ", got " << m_mapping.size());
76
77 // check the mapping for consistency
78 bool ok = true;
79 unordered_set<unsigned> pixels;
80 unordered_set<unsigned> channels;
81 for (unsigned ii = 0; ii < m_mapping.size(); ii++) {
82 const auto& map = m_mapping[ii];
83 unsigned row = map.getRow();
84 unsigned col = map.getColumn();
85 unsigned asic = map.getASICNumber();
86 unsigned chan = map.getASICChannel();
87 if (row >= c_numRows) {
88 B2ERROR("TOP::ChannelMapper: pixel row out of range."
89 << LogVar("node", ii)
90 << LogVar("row", row)
91 << LogVar("column", col)
92 << LogVar("ASIC", asic)
93 << LogVar("channel", chan));
94 ok = false;
95 }
96 if (col >= c_numColumns) {
97 B2ERROR("TOP::ChannelMapper: pixel column out of range."
98 << LogVar("node", ii)
99 << LogVar("row", row)
100 << LogVar("column", col)
101 << LogVar("ASIC", asic)
102 << LogVar("channel", chan));
103 ok = false;
104 }
105 if (asic >= c_numAsics) {
106 B2ERROR("TOP::ChannelMapper: ASIC number out of range."
107 << LogVar("node", ii)
108 << LogVar("row", row)
109 << LogVar("column", col)
110 << LogVar("ASIC", asic)
111 << LogVar("channel", chan));
112 ok = false;
113 }
114 if (chan >= c_numChannels) {
115 B2ERROR("TOP::ChannelMapper: ASIC channel number out of range."
116 << LogVar("node", ii)
117 << LogVar("row", row)
118 << LogVar("column", col)
119 << LogVar("ASIC", asic)
120 << LogVar("channel", chan));
121 ok = false;
122 }
123 if (!pixels.insert(col + row * c_numColumns).second) {
124 B2ERROR("TOP::ChannelMapper: pixel already mapped."
125 << LogVar("node", ii)
126 << LogVar("row", row)
127 << LogVar("column", col)
128 << LogVar("ASIC", asic)
129 << LogVar("channel", chan));
130 ok = false;
131 }
132 if (!channels.insert(chan + asic * c_numChannels).second) {
133 B2ERROR("TOP::ChannelMapper: channel already mapped."
134 << LogVar("node", ii)
135 << LogVar("row", row)
136 << LogVar("column", col)
137 << LogVar("ASIC", asic)
138 << LogVar("channel", chan));
139 ok = false;
140 }
141 }
142 if (!ok) {
143 B2FATAL("TOP::ChannelMapper: errors detected in xml file for '"
144 << m_typeName << "'");
145 return;
146 }
147
148 // prepare conversion arrays
149 for (const auto& map : m_mapping) {
150 m_channels[map.getRow()][map.getColumn()] = &map;
151 m_pixels[map.getASICNumber()][map.getASICChannel()] = &map;
152 }
153 m_valid = true;
154
155 B2INFO("TOP::ChannelMapper: " << m_mapping.size() <<
156 " channels of carrier board of type '" << m_typeName
157 << "' mapped to pixels.");
158
159 // print mappings if debug level for package 'top' is set to 100 or larger
160 const auto& logSystem = LogSystem::Instance();
161 if (logSystem.isLevelEnabled(LogConfig::c_Debug, 100, "top")) {
162 print();
163 }
164
165 }

◆ isChannelValid()

static bool isChannelValid ( unsigned channel)
inlinestatic

Checks validity of hardware channel number.

Parameters
channelhardware channel number (0-based)
Returns
true for valid ID

Definition at line 111 of file ChannelMapper.h.

112 {
113 return channel < c_numPixels;
114 }

◆ isPixelIDValid()

static bool isPixelIDValid ( int pixel)
inlinestatic

Checks validity of pixel ID.

Parameters
pixelpixel ID (1-based)
Returns
true for valid ID

Definition at line 100 of file ChannelMapper.h.

101 {
102 unsigned pix = pixel - 1;
103 return pix < c_numPixels; // cppcheck-suppress knownConditionTrueFalse
104 }

◆ isValid()

bool isValid ( ) const
inline

Checks if mapping is available.

Returns
true if available

Definition at line 75 of file ChannelMapper.h.

75{return m_valid;}

◆ print()

void print ( ) const

Print mappings to terminal screen.

Definition at line 274 of file ChannelMapper.cc.

275 {
276 std::vector<std::string> what;
277 what.push_back(string("Boardstack numbers (view from the back):"));
278 what.push_back(string("Carrier board numbers (view from the back):"));
279 what.push_back(string("ASIC numbers (view from the back):"));
280 what.push_back(string("ASIC channel numbers (view from the back):"));
281 unsigned value[4] = {0, 0, 0, 0};
282
283 std::string xaxis("+------phi--------->");
284 std::string yaxis("|ohr|||^");
285
286 cout << endl;
287 cout << " Mapping of TOP electronic channels to pixels";
288 if (!m_typeName.empty()) cout << " for " << m_typeName;
289 cout << endl << endl;
290
291 for (int i = 0; i < 4; i++) {
292 cout << " " << what[i] << endl << endl;
293 for (int row = c_numPixelRows - 1; row >= 0; row--) {
294 cout << " " << yaxis[row] << " ";
295 for (int col = 0; col < c_numPixelColumns; col++) {
296 int pixel = col + c_numPixelColumns * row + 1;
297 auto channel = getChannel(pixel);
298 if (channel != c_invalidChannel) {
299 splitChannelNumber(channel, value[0], value[1], value[2], value[3]);
300 cout << value[i];
301 } else {
302 cout << "?";
303 }
304 }
305 cout << endl;
306 }
307 cout << " " << xaxis << endl << endl;
308 }
309
310 }

◆ splitChannelNumber()

void splitChannelNumber ( unsigned channel,
unsigned & boardstack,
unsigned & carrier,
unsigned & asic,
unsigned & chan )
static

Splits hardware channel number into boardstack, carrier, asic and asic channel.

Parameters
channelhardware channel number (0-based) [input]
boardstackboardstack number (0-based) [output]
carriercarrier board number (0-based) [output]
asicASIC number (0-based) [output]
chanASIC channel number (0-based) [output]

Definition at line 224 of file ChannelMapper.cc.

229 {
230 chan = channel % c_numChannels;
231 channel /= c_numChannels;
232 asic = channel % c_numAsics;
233 channel /= c_numAsics;
234 carrier = channel % c_numCarrierBoards;
235 boardstack = channel / c_numCarrierBoards;
236 }

◆ test()

void test ( ) const

test that the conversion and inverse of it gives identity, if not B2ERROR

Definition at line 312 of file ChannelMapper.cc.

313 {
314 for (int pixel = 1; pixel <= c_numPixels; pixel++)
315 if (pixel != getPixelID(getChannel(pixel)))
316 B2ERROR("TOP::ChannelMapper: bug, getPixelID is not inverse of getChannel");
317
318 for (unsigned channel = 0; channel < c_numPixels; channel++)
319 if (channel != getChannel(getPixelID(channel)))
320 B2ERROR("TOP::ChannelMapper: bug, getChannel is not inverse of getPixelID");
321 }

◆ update()

void update ( )
private

re-do conversion arrays when DBArray has changed

Definition at line 338 of file ChannelMapper.cc.

339 {
340 clear();
341 if (!m_mappingDB.isValid()) return;
342
343 for (const auto& map : m_mappingDB) {
344 m_channels[map.getRow()][map.getColumn()] = &map;
345 m_pixels[map.getASICNumber()][map.getASICChannel()] = &map;
346 }
347 m_valid = true;
348 m_fromDB = true;
349 }

Member Data Documentation

◆ m_channels

const TOPChannelMap* m_channels[c_numRows][c_numColumns] = {{0}}
private

conversion array

Definition at line 197 of file ChannelMapper.h.

197{{0}};

◆ m_fromDB

bool m_fromDB = false
private

true, if from database

Definition at line 195 of file ChannelMapper.h.

◆ m_mapping

std::vector<TOPChannelMap> m_mapping
private

mappings from gearbox

Definition at line 192 of file ChannelMapper.h.

◆ m_mappingDB

DBArray<TOPChannelMap> m_mappingDB
private

mappings from database

Definition at line 193 of file ChannelMapper.h.

◆ m_pixels

const TOPChannelMap* m_pixels[c_numAsics][c_numChannels] = {{0}}
private

conversion array

Definition at line 198 of file ChannelMapper.h.

198{{0}};

◆ m_type

EType m_type = c_unknown
private

electornic type

Definition at line 190 of file ChannelMapper.h.

◆ m_typeName

std::string m_typeName
private

electronic type name

Definition at line 191 of file ChannelMapper.h.

◆ m_valid

bool m_valid = false
private

true if mapping available

Definition at line 194 of file ChannelMapper.h.


The documentation for this class was generated from the following files: