9#include <top/geometry/ChannelMapper.h>
10#include <framework/database/DBImportArray.h>
11#include <unordered_set>
12#include <framework/logging/LogSystem.h>
27 "TOP::ChannelMapper: bug in coding (enum) - "
28 "number of channels and number of pixels disagree");
31 for (
auto& channel : channels) channel = 0;
34 for (
auto& pixel : pixels) pixel = 0;
43 string path = channelMapping.
getPath();
44 auto i1 = path.rfind(
"type='") + 6;
45 auto i2 = path.rfind(
"']");
53 B2ERROR(
"TOP::ChannelMapper: unknown electronic type."
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]);
67 B2ERROR(
"TOP::ChannelMapper: mapping is not available in Gearbox");
73 B2FATAL(
"TOP::ChannelMapper: got incorrect map size from xml file for '"
79 unordered_set<unsigned> pixels;
80 unordered_set<unsigned> channels;
81 for (
unsigned ii = 0; ii <
m_mapping.size(); ii++) {
83 unsigned row = map.getRow();
84 unsigned col = map.getColumn();
85 unsigned asic = map.getASICNumber();
86 unsigned chan = map.getASICChannel();
88 B2ERROR(
"TOP::ChannelMapper: pixel row out of range."
93 <<
LogVar(
"channel", chan));
97 B2ERROR(
"TOP::ChannelMapper: pixel column out of range."
102 <<
LogVar(
"channel", chan));
106 B2ERROR(
"TOP::ChannelMapper: ASIC number out of range."
111 <<
LogVar(
"channel", chan));
115 B2ERROR(
"TOP::ChannelMapper: ASIC channel number out of range."
120 <<
LogVar(
"channel", chan));
124 B2ERROR(
"TOP::ChannelMapper: pixel already mapped."
129 <<
LogVar(
"channel", chan));
133 B2ERROR(
"TOP::ChannelMapper: channel already mapped."
138 <<
LogVar(
"channel", chan));
143 B2FATAL(
"TOP::ChannelMapper: errors detected in xml file for '"
150 m_channels[map.getRow()][map.getColumn()] = ↦
151 m_pixels[map.getASICNumber()][map.getASICChannel()] = ↦
155 B2INFO(
"TOP::ChannelMapper: " <<
m_mapping.size() <<
156 " channels of carrier board of type '" <<
m_typeName
157 <<
"' mapped to pixels.");
192 array.appendNew(map);
202 unsigned pix = pixel - 1;
213 B2WARNING(
"TOP::ChannelMapper: no channel mapped to pixel. Return invalid channel."
214 <<
LogVar(
"pixelID", pixel));
217 unsigned asic = map->getASICNumber();
218 unsigned chan = map->getASICChannel();
220 return getChannel(boardstack, carrier, asic, chan);
225 unsigned& boardstack,
244 unsigned boardstack = 0;
245 unsigned carrier = 0;
250 const auto& map =
m_pixels[asic][chan];
252 B2ERROR(
"TOP::ChannelMapper: no pixel mapped to channel. Return invalid pixel."
253 <<
LogVar(
"channel", channel));
256 unsigned row = map->getRow();
257 unsigned col = map->getColumn();
258 unsigned pixRow = row + carrier *
c_numRows;
269 int pmtRow = pixel / 256;
270 int pmtCol = (pixel % 64) / 4;
271 return pmtRow * 16 + pmtCol + 1;
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};
283 std::string xaxis(
"+------phi--------->");
284 std::string yaxis(
"|ohr|||^");
287 cout <<
" Mapping of TOP electronic channels to pixels";
289 cout << endl << endl;
291 for (
int i = 0; i < 4; i++) {
292 cout <<
" " << what[i] << endl << endl;
294 cout <<
" " << yaxis[row] <<
" ";
307 cout <<
" " << xaxis << endl << endl;
316 B2ERROR(
"TOP::ChannelMapper: bug, getPixelID is not inverse of getChannel");
318 for (
unsigned channel = 0; channel <
c_numPixels; channel++)
320 B2ERROR(
"TOP::ChannelMapper: bug, getChannel is not inverse of getPixelID");
328 for (
auto& channel : channels) channel = 0;
331 for (
auto& pixel : pixels) pixel = 0;
344 m_channels[map.getRow()][map.getColumn()] = ↦
345 m_pixels[map.getASICNumber()][map.getASICChannel()] = ↦
Class for importing array of objects to the database.
bool import(const IntervalOfValidity &iov)
Import the object to database.
GearDir is the basic class used for accessing the parameter store.
A class that describes the interval of experiments/runs for which an object in the database is valid.
@ c_Debug
Debug: for code development.
static LogSystem & Instance()
Static method to get a reference to the LogSystem instance.
Map of pixels and channels within the carrier board.
EType m_type
electornic type
void test() const
test that the conversion and inverse of it gives identity, if not B2ERROR
void initialize()
Initialize from database.
bool m_fromDB
true, if from database
std::vector< TOPChannelMap > m_mapping
mappings from gearbox
static bool isChannelValid(unsigned channel)
Checks validity of hardware channel number.
DBArray< TOPChannelMap > m_mappingDB
mappings from database
const TOPChannelMap * m_pixels[c_numAsics][c_numChannels]
conversion array
@ c_numCarrierBoards
number of carrier boards per boardstack
@ c_numColumns
number of pixel columns per carrier board
@ c_numChannels
number of channels per ASIC
@ c_numRows
number of pixel rows per carrier board
@ c_invalidChannel
value of invalid channel number
@ c_invalidPixelID
value of invalid pixel ID
@ c_numAsics
number of ASIC's per carrier board
@ c_numPixelColumns
per module
@ c_numPixelRows
per module
static void splitChannelNumber(unsigned channel, unsigned &boardstack, unsigned &carrier, unsigned &asic, unsigned &chan)
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)
static int getPmtID(int pixel)
Returns PMT ID (1-based)
bool m_valid
true if mapping available
ChannelMapper()
constructor
void update()
re-do conversion arrays when DBArray has changed
void importPayload(const IntervalOfValidity &iov) const
import mappings to database
void print() const
Print mappings to terminal screen.
static bool isPixelIDValid(int pixel)
Checks validity of pixel ID.
const TOPChannelMap * m_channels[c_numRows][c_numColumns]
conversion array
unsigned getChannel(int pixel) const
Converts pixel to hardware channel number (0-based)
std::string m_typeName
electronic type name
std::string getPath() const
Return path of the current interface.
std::vector< GearDir > getNodes(const std::string &path="") const
Get vector of GearDirs which point to all the nodes the given path evaluates to.
Class to store variables with their name which were sent to the logging service.
Abstract base class for different kinds of events.