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
 
 ~ChannelMapper ()
 destructor
 
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)
 
std::string getName () const
 Return electornic name.
 
bool isPixelIDValid (int pixel) const
 Checks validity of pixel ID.
 
bool isChannelValid (unsigned channel) const
 Checks validity of hardware channel number.
 
unsigned getChannel (int pixel) const
 Converts pixel to hardware channel number (0-based)
 
unsigned getChannel (unsigned boardstack, unsigned carrier, unsigned asic, unsigned chan) const
 Returns hardware channel number (0-based)
 
void splitChannelNumber (unsigned channel, unsigned &boardstack, unsigned &carrier, unsigned &asic, unsigned &chan) const
 Splits hardware channel number into boardstack, carrier, asic and asic channel.
 
int getPixelID (unsigned channel) const
 Converts hardware channel number to pixel ID (1-based)
 
int getPmtID (int pixel) const
 Returns PMT 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
 

Private Member Functions

 ChannelMapper (const ChannelMapper &)
 Copy constructor.
 
ChannelMapperoperator= (const ChannelMapper &)
 Assignment operator.
 
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< TOPChannelMap > * m_mappingDB = 0
 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,
35 c_numAsics = 4,
36 c_numChannels = 8,
37 c_numRows = 2,
38 c_numColumns = 16,
44 };
@ c_numCarrierBoards
number of carrier boards per boardstack
Definition: ChannelMapper.h:34
@ c_numColumns
number of pixel columns per carrier board
Definition: ChannelMapper.h:38
@ c_numChannels
number of channels per ASIC
Definition: ChannelMapper.h:36
@ c_numRows
number of pixel rows per carrier board
Definition: ChannelMapper.h:37
@ c_numBoardstacks
number of boardstacks per TOP module
Definition: ChannelMapper.h:33
@ c_invalidChannel
value of invalid channel number
Definition: ChannelMapper.h:42
@ c_invalidPixelID
value of invalid pixel ID
Definition: ChannelMapper.h:43
@ c_numAsics
number of ASIC's per carrier board
Definition: ChannelMapper.h:35

◆ 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() [1/2]

constructor

Definition at line 24 of file ChannelMapper.cc.

25 {
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 }
const TOPChannelMap * m_pixels[c_numAsics][c_numChannels]
conversion array
const TOPChannelMap * m_channels[c_numRows][c_numColumns]
conversion array

◆ ~ChannelMapper()

destructor

Definition at line 39 of file ChannelMapper.cc.

40 {
41 if (m_mappingDB) delete m_mappingDB;
42 }
DBArray< TOPChannelMap > * m_mappingDB
mappings from database

◆ ChannelMapper() [2/2]

ChannelMapper ( const ChannelMapper )
inlineprivate

Copy constructor.

Definition at line 188 of file ChannelMapper.h.

189 {}

Member Function Documentation

◆ clear()

void clear ( )
private

Clear.

Definition at line 333 of file ChannelMapper.cc.

334 {
335 m_mapping.clear();
336 for (auto& channels : m_channels) {
337 for (auto& channel : channels) channel = 0;
338 }
339 for (auto& pixels : m_pixels) {
340 for (auto& pixel : pixels) pixel = 0;
341 }
342 m_valid = false;
343 m_fromDB = false;
344 }
bool m_fromDB
true, if from database
std::vector< TOPChannelMap > m_mapping
mappings from gearbox
bool m_valid
true if mapping available

◆ 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 207 of file ChannelMapper.cc.

208 {
209 if (!isPixelIDValid(pixel)) return c_invalidChannel;
210
211 unsigned pix = pixel - 1;
212 unsigned pixRow = pix / c_numPixelColumns;
213 unsigned pixCol = pix % c_numPixelColumns;
214
215 unsigned carrier = pixRow / c_numRows;
216 unsigned row = pixRow % c_numRows;
217 unsigned boardstack = pixCol / c_numColumns;
218 unsigned col = pixCol % c_numColumns;
219
220 const auto& map = m_channels[row][col];
221 if (!map) {
222 B2WARNING("TOP::ChannelMapper: no channel mapped to pixel. Return invalid channel."
223 << LogVar("pixelID", pixel));
224 return c_invalidChannel;
225 }
226 unsigned asic = map->getASICNumber();
227 unsigned chan = map->getASICChannel();
228
229 return getChannel(boardstack, carrier, asic, chan);
230 }
bool isPixelIDValid(int pixel) const
Checks validity of pixel ID.
unsigned getChannel(int pixel) const
Converts pixel to hardware channel number (0-based)
Class to store variables with their name which were sent to the logging service.

◆ getChannel() [2/2]

unsigned getChannel ( unsigned  boardstack,
unsigned  carrier,
unsigned  asic,
unsigned  chan 
) const
inline

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 136 of file ChannelMapper.h.

140 {
141 return chan + c_numChannels * (asic + c_numAsics *
142 (carrier + c_numCarrierBoards * boardstack));
143 }

◆ getName()

std::string getName ( ) const
inline

Return electornic name.

Returns
name

Definition at line 98 of file ChannelMapper.h.

98{return m_typeName;}
std::string m_typeName
electronic type name

◆ 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 248 of file ChannelMapper.cc.

249 {
250
251 if (!isChannelValid(channel)) return c_invalidPixelID;
252
253 unsigned boardstack = 0;
254 unsigned carrier = 0;
255 unsigned asic = 0;
256 unsigned chan = 0;
257 splitChannelNumber(channel, boardstack, carrier, asic, chan);
258
259 const auto& map = m_pixels[asic][chan];
260 if (!map) {
261 B2ERROR("TOP::ChannelMapper: no pixel mapped to channel. Return invalid pixel."
262 << LogVar("channel", channel));
263 return c_invalidPixelID;
264 }
265 unsigned row = map->getRow();
266 unsigned col = map->getColumn();
267 unsigned pixRow = row + carrier * c_numRows;
268 unsigned pixCol = col + boardstack * c_numColumns;
269
270 return pixCol + pixRow * c_numPixelColumns + 1;
271
272 }
void splitChannelNumber(unsigned channel, unsigned &boardstack, unsigned &carrier, unsigned &asic, unsigned &chan) const
Splits hardware channel number into boardstack, carrier, asic and asic channel.
bool isChannelValid(unsigned channel) const
Checks validity of hardware channel number.

◆ getPmtID()

int getPmtID ( int  pixel) const

Returns PMT ID (1-based)

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

Definition at line 274 of file ChannelMapper.cc.

275 {
276 if (not isPixelIDValid(pixel)) return 0;
277 pixel--;
278 int pmtRow = pixel / 256;
279 int pmtCol = (pixel % 64) / 4;
280 return pmtRow * 16 + pmtCol + 1;
281 }

◆ getType()

EType getType ( ) const
inline

Return electornic type (see enum)

Returns
type

Definition at line 92 of file ChannelMapper.h.

92{return m_type;}
EType m_type
electornic type

◆ importPayload()

void importPayload ( const IntervalOfValidity iov) const

import mappings to database

Parameters
iovInterval of validity.

Definition at line 197 of file ChannelMapper.cc.

198 {
199 DBImportArray<TOPChannelMap> array;
200 for (const auto& map : m_mapping) {
201 array.appendNew(map);
202 }
203 array.import(iov);
204 }

◆ initialize() [1/2]

void initialize ( )

Initialize from database.

Definition at line 174 of file ChannelMapper.cc.

175 {
176 m_type = c_default;
177
178 if (m_mappingDB) delete m_mappingDB;
179 m_mappingDB = new DBArray<TOPChannelMap>();
180
181 if (!m_mappingDB->isValid()) {
182 clear();
183 return;
184 }
185 update();
186
187 m_mappingDB->addCallback(this, &ChannelMapper::update);
188
189 const auto& logSystem = LogSystem::Instance();
190 if (logSystem.isLevelEnabled(LogConfig::c_Debug, 100, "top")) {
191 print();
192 }
193
194 }
@ c_Debug
Debug: for code development.
Definition: LogConfig.h:26
static LogSystem & Instance()
Static method to get a reference to the LogSystem instance.
Definition: LogSystem.cc:31
void update()
re-do conversion arrays when DBArray has changed
void print() const
Print mappings to terminal screen.

◆ initialize() [2/2]

void initialize ( const GearDir channelMapping)

Initialize from Gearbox (XML)

Parameters
channelMappingXML data directory

Definition at line 44 of file ChannelMapper.cc.

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

◆ isChannelValid()

bool isChannelValid ( unsigned  channel) const
inline

Checks validity of hardware channel number.

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

Definition at line 116 of file ChannelMapper.h.

117 {
118 return channel < c_numPixels;
119 }

◆ isPixelIDValid()

bool isPixelIDValid ( int  pixel) const
inline

Checks validity of pixel ID.

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

Definition at line 105 of file ChannelMapper.h.

106 {
107 unsigned pix = pixel - 1;
108 return pix < c_numPixels;
109 }

◆ isValid()

bool isValid ( ) const
inline

Checks if mapping is available.

Returns
true if available

Definition at line 80 of file ChannelMapper.h.

80{return m_valid;}

◆ operator=()

ChannelMapper & operator= ( const ChannelMapper )
inlineprivate

Assignment operator.

Definition at line 194 of file ChannelMapper.h.

195 {return *this;}

◆ print()

void print ( ) const

Print mappings to terminal screen.

Definition at line 283 of file ChannelMapper.cc.

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

◆ splitChannelNumber()

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

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 233 of file ChannelMapper.cc.

238 {
239 chan = channel % c_numChannels;
240 channel /= c_numChannels;
241 asic = channel % c_numAsics;
242 channel /= c_numAsics;
243 carrier = channel % c_numCarrierBoards;
244 boardstack = channel / c_numCarrierBoards;
245 }

◆ test()

void test ( ) const

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

Definition at line 321 of file ChannelMapper.cc.

322 {
323 for (int pixel = 1; pixel <= c_numPixels; pixel++)
324 if (pixel != getPixelID(getChannel(pixel)))
325 B2ERROR("TOP::ChannelMapper: bug, getPixelID is not inverse of getChannel");
326
327 for (unsigned channel = 0; channel < c_numPixels; channel++)
328 if (channel != getChannel(getPixelID(channel)))
329 B2ERROR("TOP::ChannelMapper: bug, getChannel is not inverse of getPixelID");
330 }
int getPixelID(unsigned channel) const
Converts hardware channel number to pixel ID (1-based)

◆ update()

void update ( )
private

re-do conversion arrays when DBArray has changed

Definition at line 347 of file ChannelMapper.cc.

348 {
349 clear();
350 if (!m_mappingDB->isValid()) return;
351
352 for (const auto& map : *m_mappingDB) {
353 m_channels[map.getRow()][map.getColumn()] = &map;
354 m_pixels[map.getASICNumber()][map.getASICChannel()] = &map;
355 }
356 m_valid = true;
357 m_fromDB = true;
358 }

Member Data Documentation

◆ m_channels

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

conversion array

Definition at line 215 of file ChannelMapper.h.

◆ m_fromDB

bool m_fromDB = false
private

true, if from database

Definition at line 213 of file ChannelMapper.h.

◆ m_mapping

std::vector<TOPChannelMap> m_mapping
private

mappings from gearbox

Definition at line 210 of file ChannelMapper.h.

◆ m_mappingDB

DBArray<TOPChannelMap>* m_mappingDB = 0
private

mappings from database

Definition at line 211 of file ChannelMapper.h.

◆ m_pixels

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

conversion array

Definition at line 216 of file ChannelMapper.h.

◆ m_type

EType m_type = c_unknown
private

electornic type

Definition at line 208 of file ChannelMapper.h.

◆ m_typeName

std::string m_typeName
private

electronic type name

Definition at line 209 of file ChannelMapper.h.

◆ m_valid

bool m_valid = false
private

true if mapping available

Definition at line 212 of file ChannelMapper.h.


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