9#include <top/geometry/FrontEndMapper.h>
10#include <framework/database/DBImportArray.h>
11#include <framework/logging/LogSystem.h>
26 for (
unsigned i = 0; i < c_numModules; i++) {
27 for (
unsigned k = 0; k < c_numColumns; k++) {
47 unordered_set<unsigned short> scrodIDs;
48 unordered_set<string> coppers;
49 unordered_set<int> modules;
53 for (
const GearDir& topModule : frontEndMapping.
getNodes(
"TOPModule")) {
55 int moduleCNumber = topModule.getInt(
"@CNumber");
56 int moduleID = topModule.getInt(
"moduleID");
57 if (moduleID == 0)
continue;
58 if (moduleID < 0 or moduleID > c_numModules) {
59 B2ERROR(
"TOP::FrontEndMapper: invalid moduleID in xml file"
60 <<
LogVar(
"moduleID", moduleID)
61 <<
LogVar(
"path", topModule.getPath()));
65 bool moduleMapped =
false;
68 int col = boardstack.getInt(
"@col");
69 if (col < 0 or col >= c_numColumns) {
70 B2ERROR(
"TOP::FrontEndMapper: invalid boardstack number in xml file"
71 <<
LogVar(
"moduleID", moduleID)
72 <<
LogVar(
"boardstack", col)
73 <<
LogVar(
"path", boardstack.getPath()));
76 if (!modules.insert(moduleID * c_numColumns + col).second) {
77 B2ERROR(
"TOP::FrontEndMapper: this boardstack is already mapped."
78 <<
LogVar(
"moduleID", moduleID)
79 <<
LogVar(
"boardstack", col)
80 <<
LogVar(
"path", boardstack.getPath()));
84 unsigned short scrodID = (
unsigned short) boardstack.getInt(
"SCRODid");
85 if (!scrodIDs.insert(scrodID).second) {
86 B2ERROR(
"TOP::FrontEndMapper: this SCROD ID is already used."
87 <<
LogVar(
"moduleID", moduleID)
88 <<
LogVar(
"boardstack", col)
89 <<
LogVar(
"scrod", scrodID)
90 <<
LogVar(
"path", boardstack.getPath() +
"/SCRODid"));
94 string finesseSlot = boardstack.getString(
"FinesseSlot");
96 if (finesseSlot ==
"A") {finesse = 0;}
97 else if (finesseSlot ==
"B") {finesse = 1;}
98 else if (finesseSlot ==
"C") {finesse = 2;}
99 else if (finesseSlot ==
"D") {finesse = 3;}
101 B2ERROR(
"TOP::FrontEndMapper: invalid finesse slot (valid are A, B, C, D)."
102 <<
LogVar(
"FinesseSlot", finesseSlot)
103 <<
LogVar(
"path", boardstack.getPath() +
"/FinesseSlot"));
107 unsigned copperID = (unsigned) boardstack.getInt(
"COPPERid");
109 string copper = boardstack.getString(
"COPPERid") +
" " + finesseSlot;
110 if (!coppers.insert(copper).second) {
111 B2ERROR(
"TOP::FrontEndMapper: this COPPER ID is already used."
112 <<
LogVar(
"moduleID", moduleID)
113 <<
LogVar(
"boardstack", col)
114 <<
LogVar(
"copperID", copper)
115 <<
LogVar(
"path", boardstack.getPath() +
"/COPPERid"));
119 TOPFrontEndMap feemap(moduleID, moduleCNumber, col, scrodID, copperID, finesse,
124 if (moduleMapped) numModules++;
130 m_fromModule[feemap.getModuleID() - 1][feemap.getBoardstackNumber()] = &feemap;
132 m_fromCopper[feemap.getCopperID() * 4 + feemap.getFinesseSlot()] = &feemap;
136 B2INFO(
"TOP::FrontEndMapper: " <<
m_mapping.size() <<
" SCROD's mapped to "
137 << numModules <<
" TOP module(s)");
186 for (
unsigned i = 0; i < c_numModules; i++) {
187 for (
unsigned k = 0; k < c_numColumns; k++) {
203 m_fromModule[feemap.getModuleID() - 1][feemap.getBoardstackNumber()] = &feemap;
205 m_fromCopper[feemap.getCopperID() * 4 + feemap.getFinesseSlot()] = &feemap;
215 cout <<
" Mapping of TOP front-end electronics" << endl << endl;
217 const char label[5] =
"ABCD";
218 for (
int i = 0; i < c_numModules; i++) {
219 int moduleID = i + 1;
220 cout <<
" slot " << moduleID
222 for (
int bs = 0; bs < c_numColumns; bs++) {
223 const auto* map =
getMap(moduleID, bs);
226 cout <<
" scrod " << map->getScrodID();
227 if (map->getScrodID() < 10) cout <<
" ";
228 if (map->getScrodID() < 100) cout <<
" ";
229 cout <<
" copper " << map->getCopperID();
230 cout <<
" " << label[map->getFinesseSlot()];
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.
Mapping of a boardstack number within a module to SCROD and COPPER/Finesse.
void initialize()
Initialize from database.
bool m_fromDB
true, if from database
const TOPFrontEndMap * m_fromModule[c_numModules][c_numColumns]
conversion
const TOPFrontEndMap * getMap(int moduleID, int bs) const
Return map from TOP module side.
FrontEndMapper()
constructor
DBArray< TOPFrontEndMap > * m_mappingDB
mappings from database
bool m_valid
true, if mapping available
~FrontEndMapper()
destructor
std::unordered_set< unsigned int > m_copperIDs
COPPER ID's.
std::map< unsigned int, const TOPFrontEndMap * > m_fromCopper
conversion
std::map< unsigned short, const TOPFrontEndMap * > m_fromScrod
conversion
int getModuleCNumber(int moduleID) const
Returns module construction number.
void update()
re-do conversion maps when DBArray has changed
void importPayload(const IntervalOfValidity &iov) const
import mappings to database
void print() const
Print mappings to terminal screen.
std::vector< TOPFrontEndMap > m_mapping
mappings from gearbox
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.