Belle II Software development
FrontEndMapper Class Reference

Provides mapping between electronics module position within a TOP module and SCROD ID, COPPER and Finesse slot. More...

#include <FrontEndMapper.h>

Public Member Functions

 FrontEndMapper ()
 constructor
 
void initialize (const GearDir &frontEndMapping)
 Initialize from Gearbox (XML)
 
void initialize ()
 Initialize from database.
 
bool isValid () const
 check if the mapping is available
 
void importPayload (const IntervalOfValidity &iov) const
 import mappings to database
 
const TOPFrontEndMapgetMap (int moduleID, int bs) const
 Return map from TOP module side.
 
const TOPFrontEndMapgetMap (unsigned short scrodID) const
 Return map from SCROD side.
 
const TOPFrontEndMapgetMapFromCopper (unsigned copperID, int finesse) const
 Return map from COPPER/Finesse side.
 
int getMapSize () const
 Return size of the map.
 
const std::unordered_set< unsigned int > & getCopperIDs () const
 Return a set of copper ID's.
 
int getModuleCNumber (int moduleID) const
 Returns module construction number.
 
void print () const
 Print mappings to terminal screen.
 

Private Types

enum  {
  c_numModules = 16 ,
  c_numColumns = 4
}
 Number of TOP modules (number of physical ones can be less), number of electronic modules (SCROD's) per TOP module. More...
 

Private Member Functions

void clear ()
 Clear.
 
void update ()
 re-do conversion maps when DBArray has changed
 

Private Attributes

std::vector< TOPFrontEndMapm_mapping
 mappings from gearbox
 
DBArray< TOPFrontEndMapm_mappingDB
 mappings from database
 
bool m_valid = false
 true, if mapping available
 
bool m_fromDB = false
 true, if from database
 
std::unordered_set< unsigned int > m_copperIDs
 COPPER ID's.
 
const TOPFrontEndMapm_fromModule [c_numModules][c_numColumns] = {{0}}
 conversion
 
std::map< unsigned short, const TOPFrontEndMap * > m_fromScrod
 conversion
 
std::map< unsigned int, const TOPFrontEndMap * > m_fromCopper
 conversion
 

Detailed Description

Provides mapping between electronics module position within a TOP module and SCROD ID, COPPER and Finesse slot.

Definition at line 31 of file FrontEndMapper.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private

Number of TOP modules (number of physical ones can be less), number of electronic modules (SCROD's) per TOP module.

Definition at line 151 of file FrontEndMapper.h.

151{c_numModules = 16, c_numColumns = 4};

Constructor & Destructor Documentation

◆ FrontEndMapper()

constructor

Definition at line 24 of file FrontEndMapper.cc.

25 {
26 for (unsigned i = 0; i < c_numModules; i++) {
27 for (unsigned k = 0; k < c_numColumns; k++) {
28 m_fromModule[i][k] = 0;
29 }
30 }
31 }

Member Function Documentation

◆ clear()

void clear ( )
private

Clear.

Definition at line 170 of file FrontEndMapper.cc.

171 {
172 m_mapping.clear();
173 m_copperIDs.clear();
174 m_fromScrod.clear();
175 m_fromCopper.clear();
176 for (unsigned i = 0; i < c_numModules; i++) {
177 for (unsigned k = 0; k < c_numColumns; k++) {
178 m_fromModule[i][k] = 0;
179 }
180 }
181 m_valid = false;
182 m_fromDB = false;
183 }

◆ getCopperIDs()

const std::unordered_set< unsigned int > & getCopperIDs ( ) const
inline

Return a set of copper ID's.

Returns
copper ID's

Definition at line 121 of file FrontEndMapper.h.

122 {
123 return m_copperIDs;
124 }

◆ getMap() [1/2]

const TOPFrontEndMap * getMap ( int moduleID,
int bs ) const
inline

Return map from TOP module side.

Parameters
moduleIDTOP module ID
bsboardstack number
Returns
pointer to map element or NULL

Definition at line 69 of file FrontEndMapper.h.

70 {
71 moduleID--;
72 if (moduleID >= 0 and moduleID < c_numModules and bs >= 0 and bs < c_numColumns)
73 return m_fromModule[moduleID][bs];
74 return 0;
75 }

◆ getMap() [2/2]

const TOPFrontEndMap * getMap ( unsigned short scrodID) const
inline

Return map from SCROD side.

Parameters
scrodIDSCROD ID
Returns
pointer to map element or NULL

Definition at line 82 of file FrontEndMapper.h.

83 {
84 std::map<unsigned short, const TOPFrontEndMap*>::const_iterator it =
85 m_fromScrod.find(scrodID);
86 if (it == m_fromScrod.end()) return 0;
87 return it->second;
88 }

◆ getMapFromCopper()

const TOPFrontEndMap * getMapFromCopper ( unsigned copperID,
int finesse ) const
inline

Return map from COPPER/Finesse side.

Parameters
copperIDCOPPER ID
finesseFinesse slot number
Returns
pointer to map element or NULL

Definition at line 96 of file FrontEndMapper.h.

97 {
98 std::map<unsigned int, const TOPFrontEndMap*>::const_iterator it =
99 m_fromCopper.find(copperID * 4 + finesse);
100 if (it == m_fromCopper.end()) return 0;
101 return it->second;
102 }

◆ getMapSize()

int getMapSize ( ) const
inline

Return size of the map.

Returns
size

Definition at line 108 of file FrontEndMapper.h.

109 {
110 if (m_fromDB) {
111 return m_mappingDB.getEntries();
112 } else {
113 return m_mapping.size();
114 }
115 }

◆ getModuleCNumber()

int getModuleCNumber ( int moduleID) const
inline

Returns module construction number.

Parameters
moduleIDmodule ID (slot number)
Returns
module construction number

Definition at line 131 of file FrontEndMapper.h.

132 {
133 for (int bs = 0; bs < c_numColumns; bs++) {
134 const auto* map = getMap(moduleID, bs);
135 if (map) return map->getModuleCNumber();
136 }
137 return 0;
138 }

◆ importPayload()

void importPayload ( const IntervalOfValidity & iov) const

import mappings to database

Parameters
iovInterval of validity.

Definition at line 160 of file FrontEndMapper.cc.

161 {
162 DBImportArray<TOPFrontEndMap> array;
163 for (const auto& map : m_mapping) {
164 array.appendNew(map);
165 }
166 array.import(iov);
167 }

◆ initialize() [1/2]

void initialize ( )

Initialize from database.

Definition at line 142 of file FrontEndMapper.cc.

143 {
144 if (!m_mappingDB.isValid()) {
145 clear();
146 return;
147 }
148 update();
149
150 m_mappingDB.addCallback(this, &FrontEndMapper::update);
151
152 const auto& logSystem = LogSystem::Instance();
153 if (logSystem.isLevelEnabled(LogConfig::c_Debug, 100, "top")) {
154 print();
155 }
156
157 }

◆ initialize() [2/2]

void initialize ( const GearDir & frontEndMapping)

Initialize from Gearbox (XML)

Parameters
frontEndMappingXML data directory

Definition at line 34 of file FrontEndMapper.cc.

35 {
36
37 clear();
38
39 // unordered sets used to check that ...
40
41 unordered_set<unsigned short> scrodIDs; // all SCROD ID's are different
42 unordered_set<string> coppers; // COPPER inputs are used only once
43 unordered_set<int> modules; // (moduleID, col) mapped only once
44
45 // read parameters from gerabox
46 int numModules = 0; // counter of mapped modules
47 for (const GearDir& topModule : frontEndMapping.getNodes("TOPModule")) {
48
49 int moduleCNumber = topModule.getInt("@CNumber");
50 int moduleID = topModule.getInt("moduleID");
51 if (moduleID == 0) continue; // module is not installed into barrel
52 if (moduleID < 0 or moduleID > c_numModules) {
53 B2ERROR("TOP::FrontEndMapper: invalid moduleID in xml file"
54 << LogVar("moduleID", moduleID)
55 << LogVar("path", topModule.getPath()));
56 return;
57 }
58
59 bool moduleMapped = false; // to count mapped modules
60 for (const GearDir& boardstack : topModule.getNodes("Boardstack")) {
61
62 int col = boardstack.getInt("@col");
63 if (col < 0 or col >= c_numColumns) {
64 B2ERROR("TOP::FrontEndMapper: invalid boardstack number in xml file"
65 << LogVar("moduleID", moduleID)
66 << LogVar("boardstack", col)
67 << LogVar("path", boardstack.getPath()));
68 return;
69 }
70 if (!modules.insert(moduleID * c_numColumns + col).second) {
71 B2ERROR("TOP::FrontEndMapper: this boardstack is already mapped."
72 << LogVar("moduleID", moduleID)
73 << LogVar("boardstack", col)
74 << LogVar("path", boardstack.getPath()));
75 return;
76 }
77
78 unsigned short scrodID = (unsigned short) boardstack.getInt("SCRODid");
79 if (!scrodIDs.insert(scrodID).second) {
80 B2ERROR("TOP::FrontEndMapper: this SCROD ID is already used."
81 << LogVar("moduleID", moduleID)
82 << LogVar("boardstack", col)
83 << LogVar("scrod", scrodID)
84 << LogVar("path", boardstack.getPath() + "/SCRODid"));
85 return;
86 }
87
88 string finesseSlot = boardstack.getString("FinesseSlot");
89 int finesse = 0;
90 if (finesseSlot == "A") {finesse = 0;}
91 else if (finesseSlot == "B") {finesse = 1;}
92 else if (finesseSlot == "C") {finesse = 2;}
93 else if (finesseSlot == "D") {finesse = 3;}
94 else {
95 B2ERROR("TOP::FrontEndMapper: invalid finesse slot (valid are A, B, C, D)."
96 << LogVar("FinesseSlot", finesseSlot)
97 << LogVar("path", boardstack.getPath() + "/FinesseSlot"));
98 return;
99 }
100
101 unsigned copperID = (unsigned) boardstack.getInt("COPPERid");
102 m_copperIDs.insert(copperID);
103 string copper = boardstack.getString("COPPERid") + " " + finesseSlot;
104 if (!coppers.insert(copper).second) {
105 B2ERROR("TOP::FrontEndMapper: this COPPER ID is already used."
106 << LogVar("moduleID", moduleID)
107 << LogVar("boardstack", col)
108 << LogVar("copperID", copper)
109 << LogVar("path", boardstack.getPath() + "/COPPERid"));
110 return;
111 }
112
113 TOPFrontEndMap feemap(moduleID, moduleCNumber, col, scrodID, copperID, finesse,
114 m_mapping.size());
115 m_mapping.push_back(feemap);
116 moduleMapped = true;
117 }
118 if (moduleMapped) numModules++;
119 }
120
121 // set conversion objects
122
123 for (const auto& feemap : m_mapping) {
124 m_fromModule[feemap.getModuleID() - 1][feemap.getBoardstackNumber()] = &feemap;
125 m_fromScrod[feemap.getScrodID()] = &feemap;
126 m_fromCopper[feemap.getCopperID() * 4 + feemap.getFinesseSlot()] = &feemap;
127 }
128 m_valid = true;
129
130 B2INFO("TOP::FrontEndMapper: " << m_mapping.size() << " SCROD's mapped to "
131 << numModules << " TOP module(s)");
132
133 // print mappings if debug level for package 'top' is set to 100 or larger
134 const auto& logSystem = LogSystem::Instance();
135 if (logSystem.isLevelEnabled(LogConfig::c_Debug, 100, "top")) {
136 print();
137 }
138
139 }

◆ isValid()

bool isValid ( ) const
inline

check if the mapping is available

Returns
true if available

Definition at line 55 of file FrontEndMapper.h.

55{return m_valid;}

◆ print()

void print ( ) const

Print mappings to terminal screen.

Definition at line 202 of file FrontEndMapper.cc.

203 {
204 cout << endl;
205 cout << " Mapping of TOP front-end electronics" << endl << endl;
206
207 const char label[5] = "ABCD";
208 for (int i = 0; i < c_numModules; i++) {
209 int moduleID = i + 1;
210 cout << " slot " << moduleID
211 << " (module " << getModuleCNumber(moduleID) << "):" << endl;
212 for (int bs = 0; bs < c_numColumns; bs++) {
213 const auto* map = getMap(moduleID, bs);
214 if (!map) continue;
215 cout << " BS" << bs;
216 cout << " scrod " << map->getScrodID();
217 if (map->getScrodID() < 10) cout << " ";
218 if (map->getScrodID() < 100) cout << " ";
219 cout << " copper " << map->getCopperID();
220 cout << " " << label[map->getFinesseSlot()];
221 cout << endl;
222 }
223 }
224 cout << endl;
225
226 }

◆ update()

void update ( )
private

re-do conversion maps when DBArray has changed

Definition at line 186 of file FrontEndMapper.cc.

187 {
188 clear();
189 if (!m_mappingDB.isValid()) return;
190
191 for (const auto& feemap : m_mappingDB) {
192 m_copperIDs.insert(feemap.getCopperID());
193 m_fromModule[feemap.getModuleID() - 1][feemap.getBoardstackNumber()] = &feemap;
194 m_fromScrod[feemap.getScrodID()] = &feemap;
195 m_fromCopper[feemap.getCopperID() * 4 + feemap.getFinesseSlot()] = &feemap;
196 }
197 m_valid = true;
198 m_fromDB = true;
199 }

Member Data Documentation

◆ m_copperIDs

std::unordered_set<unsigned int> m_copperIDs
private

COPPER ID's.

Definition at line 168 of file FrontEndMapper.h.

◆ m_fromCopper

std::map<unsigned int, const TOPFrontEndMap*> m_fromCopper
private

conversion

Definition at line 171 of file FrontEndMapper.h.

◆ m_fromDB

bool m_fromDB = false
private

true, if from database

Definition at line 166 of file FrontEndMapper.h.

◆ m_fromModule

const TOPFrontEndMap* m_fromModule[c_numModules][c_numColumns] = {{0}}
private

conversion

Definition at line 169 of file FrontEndMapper.h.

169{{0}};

◆ m_fromScrod

std::map<unsigned short, const TOPFrontEndMap*> m_fromScrod
private

conversion

Definition at line 170 of file FrontEndMapper.h.

◆ m_mapping

std::vector<TOPFrontEndMap> m_mapping
private

mappings from gearbox

Definition at line 163 of file FrontEndMapper.h.

◆ m_mappingDB

DBArray<TOPFrontEndMap> m_mappingDB
private

mappings from database

Definition at line 164 of file FrontEndMapper.h.

◆ m_valid

bool m_valid = false
private

true, if mapping available

Definition at line 165 of file FrontEndMapper.h.


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