9 #include <top/geometry/FrontEndMapper.h>
10 #include <framework/database/DBImportArray.h>
11 #include <framework/logging/LogSystem.h>
24 FrontEndMapper::FrontEndMapper()
26 for (
unsigned i = 0; i < c_numModules; i++) {
27 for (
unsigned k = 0; k < c_numColumns; k++) {
28 m_fromModule[i][k] = 0;
34 FrontEndMapper::~FrontEndMapper()
36 if (m_mappingDB)
delete m_mappingDB;
40 void FrontEndMapper::initialize(
const GearDir& frontEndMapping)
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");
108 m_copperIDs.insert(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,
121 m_mapping.push_back(feemap);
124 if (moduleMapped) numModules++;
129 for (
const auto& feemap : m_mapping) {
130 m_fromModule[feemap.getModuleID() - 1][feemap.getBoardstackNumber()] = &feemap;
131 m_fromScrod[feemap.getScrodID()] = &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)");
140 const auto& logSystem = LogSystem::Instance();
141 if (logSystem.isLevelEnabled(LogConfig::c_Debug, 100,
"top")) {
148 void FrontEndMapper::initialize()
151 if (m_mappingDB)
delete m_mappingDB;
154 if (!m_mappingDB->isValid()) {
160 m_mappingDB->addCallback(
this, &FrontEndMapper::update);
162 const auto& logSystem = LogSystem::Instance();
163 if (logSystem.isLevelEnabled(LogConfig::c_Debug, 100,
"top")) {
173 for (
const auto& map : m_mapping) {
180 void FrontEndMapper::clear()
185 m_fromCopper.clear();
186 for (
unsigned i = 0; i < c_numModules; i++) {
187 for (
unsigned k = 0; k < c_numColumns; k++) {
188 m_fromModule[i][k] = 0;
196 void FrontEndMapper::update()
199 if (!m_mappingDB->isValid())
return;
201 for (
const auto& feemap : *m_mappingDB) {
202 m_copperIDs.insert(feemap.getCopperID());
203 m_fromModule[feemap.getModuleID() - 1][feemap.getBoardstackNumber()] = &feemap;
204 m_fromScrod[feemap.getScrodID()] = &feemap;
205 m_fromCopper[feemap.getCopperID() * 4 + feemap.getFinesseSlot()] = &feemap;
212 void FrontEndMapper::print()
const
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
221 <<
" (module " << getModuleCNumber(moduleID) <<
"):" << endl;
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.
Mapping of a boardstack number within a module to SCROD and COPPER/Finesse.
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.