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;
49 string path = channelMapping.
getPath();
50 auto i1 = path.rfind(
"type='") + 6;
51 auto i2 = path.rfind(
"']");
59 B2ERROR(
"TOP::ChannelMapper: unknown electronic type."
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]);
73 B2ERROR(
"TOP::ChannelMapper: mapping is not available in Gearbox");
79 B2FATAL(
"TOP::ChannelMapper: got incorrect map size from xml file for '"
85 unordered_set<unsigned> pixels;
86 unordered_set<unsigned> channels;
87 for (
unsigned ii = 0; ii <
m_mapping.size(); ii++) {
89 unsigned row = map.getRow();
90 unsigned col = map.getColumn();
91 unsigned asic = map.getASICNumber();
92 unsigned chan = map.getASICChannel();
94 B2ERROR(
"TOP::ChannelMapper: pixel row out of range."
99 <<
LogVar(
"channel", chan));
103 B2ERROR(
"TOP::ChannelMapper: pixel column out of range."
108 <<
LogVar(
"channel", chan));
112 B2ERROR(
"TOP::ChannelMapper: ASIC number out of range."
117 <<
LogVar(
"channel", chan));
121 B2ERROR(
"TOP::ChannelMapper: ASIC channel number out of range."
126 <<
LogVar(
"channel", chan));
130 B2ERROR(
"TOP::ChannelMapper: pixel already mapped."
135 <<
LogVar(
"channel", chan));
139 B2ERROR(
"TOP::ChannelMapper: channel already mapped."
144 <<
LogVar(
"channel", chan));
149 B2FATAL(
"TOP::ChannelMapper: errors detected in xml file for '"
156 m_channels[map.getRow()][map.getColumn()] = ↦
157 m_pixels[map.getASICNumber()][map.getASICChannel()] = ↦
161 B2INFO(
"TOP::ChannelMapper: " <<
m_mapping.size() <<
162 " channels of carrier board of type '" <<
m_typeName
163 <<
"' mapped to pixels.");
211 unsigned pix = pixel - 1;
222 B2WARNING(
"TOP::ChannelMapper: no channel mapped to pixel. Return invalid channel."
223 <<
LogVar(
"pixelID", pixel));
226 unsigned asic = map->getASICNumber();
227 unsigned chan = map->getASICChannel();
229 return getChannel(boardstack, carrier, asic, chan);
234 unsigned& boardstack,
237 unsigned& chan)
const
253 unsigned boardstack = 0;
254 unsigned carrier = 0;
259 const auto& map =
m_pixels[asic][chan];
261 B2ERROR(
"TOP::ChannelMapper: no pixel mapped to channel. Return invalid pixel."
262 <<
LogVar(
"channel", channel));
265 unsigned row = map->getRow();
266 unsigned col = map->getColumn();
267 unsigned pixRow = row + carrier *
c_numRows;
278 int pmtRow = pixel / 256;
279 int pmtCol = (pixel % 64) / 4;
280 return pmtRow * 16 + pmtCol + 1;
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};
292 std::string xaxis(
"+------phi--------->");
293 std::string yaxis(
"|ohr|||^");
296 cout <<
" Mapping of TOP electronic channels to pixels";
298 cout << endl << endl;
300 for (
int i = 0; i < 4; i++) {
301 cout <<
" " << what[i] << endl << endl;
303 cout <<
" " << yaxis[row] <<
" ";
316 cout <<
" " << xaxis << endl << endl;
325 B2ERROR(
"TOP::ChannelMapper: bug, getPixelID is not inverse of getChannel");
327 for (
unsigned channel = 0; channel <
c_numPixels; channel++)
329 B2ERROR(
"TOP::ChannelMapper: bug, getChannel is not inverse of getPixelID");
337 for (
auto& channel : channels) channel = 0;
340 for (
auto& pixel : pixels) pixel = 0;
353 m_channels[map.getRow()][map.getColumn()] = ↦
354 m_pixels[map.getASICNumber()][map.getASICChannel()] = ↦
Class for accessing arrays of objects in the database.
Class for importing array of objects to the database.
T * appendNew()
Construct a new T object at the end of the array.
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
const TOPChannelMap * m_pixels[c_numAsics][c_numChannels]
conversion array
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)
bool isChannelValid(unsigned channel) const
Checks validity of hardware channel number.
@ 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
bool m_valid
true if mapping available
bool isPixelIDValid(int pixel) const
Checks validity of pixel ID.
ChannelMapper()
constructor
int getPmtID(int pixel) const
Returns PMT ID (1-based)
DBArray< TOPChannelMap > * m_mappingDB
mappings from database
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.
~ChannelMapper()
destructor
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.