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
 
 ~FrontEndMapper ()
 destructor
 
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

 FrontEndMapper (const FrontEndMapper &)
 copy constructor
 
FrontEndMapperoperator= (const FrontEndMapper &)
 assignment operator
 
void clear ()
 Clear.
 
void update ()
 re-do conversion maps when DBArray has changed
 

Private Attributes

std::vector< TOPFrontEndMapm_mapping
 mappings from gearbox
 
DBArray< TOPFrontEndMap > * m_mappingDB = 0
 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 156 of file FrontEndMapper.h.

156{c_numModules = 16, c_numColumns = 4};

Constructor & Destructor Documentation

◆ FrontEndMapper() [1/2]

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 }
const TOPFrontEndMap * m_fromModule[c_numModules][c_numColumns]
conversion

◆ ~FrontEndMapper()

destructor

Definition at line 34 of file FrontEndMapper.cc.

35 {
36 if (m_mappingDB) delete m_mappingDB;
37 }
DBArray< TOPFrontEndMap > * m_mappingDB
mappings from database

◆ FrontEndMapper() [2/2]

FrontEndMapper ( const FrontEndMapper )
inlineprivate

copy constructor

Definition at line 161 of file FrontEndMapper.h.

162 {}

Member Function Documentation

◆ clear()

void clear ( )
private

Clear.

Definition at line 180 of file FrontEndMapper.cc.

181 {
182 m_mapping.clear();
183 m_copperIDs.clear();
184 m_fromScrod.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;
189 }
190 }
191 m_valid = false;
192 m_fromDB = false;
193 }
bool m_fromDB
true, if from database
bool m_valid
true, if mapping available
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
std::vector< TOPFrontEndMap > m_mapping
mappings from gearbox

◆ getCopperIDs()

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

Return a set of copper ID's.

Returns
copper ID's

Definition at line 126 of file FrontEndMapper.h.

127 {
128 return m_copperIDs;
129 }

◆ 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 74 of file FrontEndMapper.h.

75 {
76 moduleID--;
77 if (moduleID >= 0 and moduleID < c_numModules and bs >= 0 and bs < c_numColumns)
78 return m_fromModule[moduleID][bs];
79 return 0;
80 }

◆ 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 87 of file FrontEndMapper.h.

88 {
89 std::map<unsigned short, const TOPFrontEndMap*>::const_iterator it =
90 m_fromScrod.find(scrodID);
91 if (it == m_fromScrod.end()) return 0;
92 return it->second;
93 }

◆ 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 101 of file FrontEndMapper.h.

102 {
103 std::map<unsigned int, const TOPFrontEndMap*>::const_iterator it =
104 m_fromCopper.find(copperID * 4 + finesse);
105 if (it == m_fromCopper.end()) return 0;
106 return it->second;
107 }

◆ getMapSize()

int getMapSize ( ) const
inline

Return size of the map.

Returns
size

Definition at line 113 of file FrontEndMapper.h.

114 {
115 if (m_fromDB) {
116 return m_mappingDB->getEntries();
117 } else {
118 return m_mapping.size();
119 }
120 }

◆ getModuleCNumber()

int getModuleCNumber ( int  moduleID) const
inline

Returns module construction number.

Parameters
moduleIDmodule ID (slot number)
Returns
module construction number

Definition at line 136 of file FrontEndMapper.h.

137 {
138 for (int bs = 0; bs < c_numColumns; bs++) {
139 const auto* map = getMap(moduleID, bs);
140 if (map) return map->getModuleCNumber();
141 }
142 return 0;
143 }
const TOPFrontEndMap * getMap(int moduleID, int bs) const
Return map from TOP module side.

◆ importPayload()

void importPayload ( const IntervalOfValidity iov) const

import mappings to database

Parameters
iovInterval of validity.

Definition at line 170 of file FrontEndMapper.cc.

171 {
172 DBImportArray<TOPFrontEndMap> array;
173 for (const auto& map : m_mapping) {
174 array.appendNew(map);
175 }
176 array.import(iov);
177 }

◆ initialize() [1/2]

void initialize ( )

Initialize from database.

Definition at line 148 of file FrontEndMapper.cc.

149 {
150
151 if (m_mappingDB) delete m_mappingDB;
152 m_mappingDB = new DBArray<TOPFrontEndMap>();
153
154 if (!m_mappingDB->isValid()) {
155 clear();
156 return;
157 }
158 update();
159
160 m_mappingDB->addCallback(this, &FrontEndMapper::update);
161
162 const auto& logSystem = LogSystem::Instance();
163 if (logSystem.isLevelEnabled(LogConfig::c_Debug, 100, "top")) {
164 print();
165 }
166
167 }
@ c_Debug
Debug: for code development.
Definition: LogConfig.h:26
static LogSystem & Instance()
Static method to get a reference to the LogSystem instance.
Definition: LogSystem.cc:31
void update()
re-do conversion maps when DBArray has changed
void print() const
Print mappings to terminal screen.

◆ initialize() [2/2]

void initialize ( const GearDir frontEndMapping)

Initialize from Gearbox (XML)

Parameters
frontEndMappingXML data directory

Definition at line 40 of file FrontEndMapper.cc.

41 {
42
43 clear();
44
45 // unordered sets used to check that ...
46
47 unordered_set<unsigned short> scrodIDs; // all SCROD ID's are different
48 unordered_set<string> coppers; // COPPER inputs are used only once
49 unordered_set<int> modules; // (moduleID, col) mapped only once
50
51 // read parameters from gerabox
52 int numModules = 0; // counter of mapped modules
53 for (const GearDir& topModule : frontEndMapping.getNodes("TOPModule")) {
54
55 int moduleCNumber = topModule.getInt("@CNumber");
56 int moduleID = topModule.getInt("moduleID");
57 if (moduleID == 0) continue; // module is not installed into barrel
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()));
62 return;
63 }
64
65 bool moduleMapped = false; // to count mapped modules
66 for (const GearDir& boardstack : topModule.getNodes("Boardstack")) {
67
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()));
74 return;
75 }
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()));
81 return;
82 }
83
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"));
91 return;
92 }
93
94 string finesseSlot = boardstack.getString("FinesseSlot");
95 int finesse = 0;
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;}
100 else {
101 B2ERROR("TOP::FrontEndMapper: invalid finesse slot (valid are A, B, C, D)."
102 << LogVar("FinesseSlot", finesseSlot)
103 << LogVar("path", boardstack.getPath() + "/FinesseSlot"));
104 return;
105 }
106
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"));
116 return;
117 }
118
119 TOPFrontEndMap feemap(moduleID, moduleCNumber, col, scrodID, copperID, finesse,
120 m_mapping.size());
121 m_mapping.push_back(feemap);
122 moduleMapped = true;
123 }
124 if (moduleMapped) numModules++;
125 }
126
127 // set conversion objects
128
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;
133 }
134 m_valid = true;
135
136 B2INFO("TOP::FrontEndMapper: " << m_mapping.size() << " SCROD's mapped to "
137 << numModules << " TOP module(s)");
138
139 // print mappings if debug level for package 'top' is set to 100 or larger
140 const auto& logSystem = LogSystem::Instance();
141 if (logSystem.isLevelEnabled(LogConfig::c_Debug, 100, "top")) {
142 print();
143 }
144
145 }
Class to store variables with their name which were sent to the logging service.

◆ isValid()

bool isValid ( ) const
inline

check if the mapping is available

Returns
true if available

Definition at line 60 of file FrontEndMapper.h.

60{return m_valid;}

◆ operator=()

FrontEndMapper & operator= ( const FrontEndMapper )
inlineprivate

assignment operator

Definition at line 167 of file FrontEndMapper.h.

168 {return *this;}

◆ print()

void print ( ) const

Print mappings to terminal screen.

Definition at line 212 of file FrontEndMapper.cc.

213 {
214 cout << endl;
215 cout << " Mapping of TOP front-end electronics" << endl << endl;
216
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);
224 if (!map) continue;
225 cout << " BS" << 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()];
231 cout << endl;
232 }
233 }
234 cout << endl;
235
236 }
int getModuleCNumber(int moduleID) const
Returns module construction number.

◆ update()

void update ( )
private

re-do conversion maps when DBArray has changed

Definition at line 196 of file FrontEndMapper.cc.

197 {
198 clear();
199 if (!m_mappingDB->isValid()) return;
200
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;
206 }
207 m_valid = true;
208 m_fromDB = true;
209 }

Member Data Documentation

◆ m_copperIDs

std::unordered_set<unsigned int> m_copperIDs
private

COPPER ID's.

Definition at line 185 of file FrontEndMapper.h.

◆ m_fromCopper

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

conversion

Definition at line 188 of file FrontEndMapper.h.

◆ m_fromDB

bool m_fromDB = false
private

true, if from database

Definition at line 183 of file FrontEndMapper.h.

◆ m_fromModule

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

conversion

Definition at line 186 of file FrontEndMapper.h.

◆ m_fromScrod

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

conversion

Definition at line 187 of file FrontEndMapper.h.

◆ m_mapping

std::vector<TOPFrontEndMap> m_mapping
private

mappings from gearbox

Definition at line 180 of file FrontEndMapper.h.

◆ m_mappingDB

DBArray<TOPFrontEndMap>* m_mappingDB = 0
private

mappings from database

Definition at line 181 of file FrontEndMapper.h.

◆ m_valid

bool m_valid = false
private

true, if mapping available

Definition at line 182 of file FrontEndMapper.h.


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