9 #include <ecl/mapper/ECLChannelMapper.h>
10 #include <rawdata/dataobjects/RawCOPPERFormat.h>
11 #include <framework/database/DBObjPtr.h>
12 #include <framework/utilities/FileSystem.h>
24 for (i = 0; i < ECL_BARREL_CRATES * ECL_BARREL_SHAPERS_IN_CRATE * ECL_CHANNELS_IN_SHAPER; i++)
25 convertArrayBarrel[i] = 0;
26 for (i = 0; i < ECL_FWD_CRATES * ECL_FWD_SHAPERS_IN_CRATE * ECL_CHANNELS_IN_SHAPER; i++)
27 convertArrayFWD[i] = 0;
28 for (i = 0; i < ECL_BKW_CRATES * ECL_BKW_SHAPERS_IN_CRATE * ECL_CHANNELS_IN_SHAPER; i++)
29 convertArrayBKW[i] = 0;
30 for (i = 0; i < ECL_TOTAL_CHANNELS; i++)
31 for (
int j = 0; j < 3; j++)
32 convertArrayInv[i][j] = 0;
34 isInitialized =
false;
41 return initFromFile(filePath.c_str());
49 if (use_db) instance->initFromDB();
50 else instance->initFromFile();
57 B2WARNING(
"Reading possibly outdated ECLChannelMap from " << eclMapFileName);
59 ifstream mapFile(eclMapFileName);
60 if (mapFile.is_open()) {
62 float iCrate, iShaper, iChannel, thetaID, phiID, cellID;
65 while (mapFile.good()) {
68 char ch = mapFile.get();
70 mapFile.ignore(256,
'\n');
72 }
else if (ch ==
'\n') {
78 mapFile >> iCrate >> iShaper >> iChannel >> thetaID >> phiID >> cellID;
80 if (cellID > ECL_TOTAL_CHANNELS) {
81 B2ERROR(
"ECLChannelMapper:: wrong cellID in the init file " << eclMapFileName);
86 convertArrayInv[(int)cellID - 1][0] = (
int)iCrate;
87 convertArrayInv[(int)cellID - 1][1] = (
int)iShaper;
88 convertArrayInv[(int)cellID - 1][2] = (
int)iChannel;
92 if (iCrate >= 1 && iCrate <= 36) {
93 arrayIndex = arrayCount;
94 convertArrayBarrel[arrayIndex] = (int)cellID;
98 if (iCrate > 36 && iCrate < 45) {
99 arrayIndex = arrayCount - 36 * 12 * 16;
101 if (arrayIndex >= 0 && arrayIndex < ECL_FWD_CRATES * ECL_FWD_SHAPERS_IN_CRATE * ECL_CHANNELS_IN_SHAPER)
102 convertArrayFWD[arrayIndex] = (int)cellID;
107 arrayIndex = arrayCount - 36 * 12 * 16 - 8 * 10 * 16;
108 if (arrayIndex >= 0 && arrayIndex < ECL_BKW_CRATES * ECL_BKW_SHAPERS_IN_CRATE * ECL_CHANNELS_IN_SHAPER)
109 convertArrayBKW[arrayIndex] = (int)cellID;
114 B2ERROR(
"ERROR:: file " << eclMapFileName <<
" doesn't found");
118 isInitialized =
true;
127 if (isInitialized && !channelMap.
hasChanged()) {
132 B2FATAL(
"ECLChannelMapper:: Could not get ECLChannelMap from the database.");
135 B2INFO(
"ECLChannelMapper:: loaded ECLChannelMap from the database"
144 int iCrate = 1, iShaper = 1, iChannel = 1;
147 int iMaxShapers = ECL_BARREL_SHAPERS_IN_CRATE;
149 while (iCrate <= ECL_CRATES) {
150 if (iCrate <= ECL_BARREL_CRATES) {
152 cellID = mappingBAR[arrayIndex];
153 convertArrayBarrel[arrayIndex] = cellID;
154 }
else if (iCrate <= ECL_BARREL_CRATES + ECL_FWD_CRATES) {
156 cellID = mappingFWD[arrayIndex];
157 convertArrayFWD[arrayIndex] = cellID;
160 cellID = mappingBWD[arrayIndex];
161 convertArrayBKW[arrayIndex] = cellID;
164 if (cellID > ECL_TOTAL_CHANNELS) {
165 B2FATAL(
"ECLChannelMapper:: wrong cellID (" << cellID <<
") in the database payload");
170 convertArrayInv[cellID - 1][0] = iCrate;
171 convertArrayInv[cellID - 1][1] = iShaper;
172 convertArrayInv[cellID - 1][2] = iChannel;
179 if (iChannel > ECL_CHANNELS_IN_SHAPER) {
182 if (iShaper > iMaxShapers) {
184 if (iCrate == ECL_BARREL_CRATES) {
186 iMaxShapers = getNShapersInCrate(iCrate + 1);
187 }
else if (iCrate == ECL_BARREL_CRATES + ECL_FWD_CRATES) {
189 iMaxShapers = getNShapersInCrate(iCrate + 1);
196 isInitialized =
true;
205 if (!isInitialized) {
206 B2FATAL(
"ECLChannelMapper:: Tried to generate dbobject before initialization");
209 int mappingBAR_size = ECL_BARREL_CRATES * ECL_BARREL_SHAPERS_IN_CRATE * ECL_CHANNELS_IN_SHAPER;
210 int mappingFWD_size = ECL_FWD_CRATES * ECL_FWD_SHAPERS_IN_CRATE * ECL_CHANNELS_IN_SHAPER;
211 int mappingBWD_size = ECL_BKW_CRATES * ECL_BKW_SHAPERS_IN_CRATE * ECL_CHANNELS_IN_SHAPER;
213 std::vector<int> mappingBAR(mappingBAR_size);
214 std::vector<int> mappingFWD(mappingFWD_size);
215 std::vector<int> mappingBWD(mappingBWD_size);
217 for (
int i = 0; i < mappingBAR_size; i++)
218 mappingBAR[i] = convertArrayBarrel[i];
219 for (
int i = 0; i < mappingFWD_size; i++)
220 mappingFWD[i] = convertArrayFWD[i];
221 for (
int i = 0; i < mappingBWD_size; i++)
222 mappingBWD[i] = convertArrayBKW[i];
235 if (iFINESSE > ECL_FINESSES_IN_COPPER - 1) {
236 B2ERROR(
"ECLChannelMapper::ERROR:: wrong FINESSE " << iFINESSE);
240 if ((iCOPPERNode & BECL_ID) == BECL_ID) {
241 iCrate = (iCOPPERNode - BECL_ID - 1) * ECL_FINESSES_IN_COPPER + iFINESSE + 1;
242 }
else if ((iCOPPERNode & EECL_ID) == EECL_ID) {
243 iCrate = ECL_BARREL_CRATES + iFINESSE * ECL_FWD_CRATES + (iCOPPERNode - EECL_ID - 1) + 1;
245 B2ERROR(
"ECLChannelMapper::ERROR:: wrong COPPER NodeID 0x" << std::hex << iCOPPERNode <<
" BECL_ID 0x" << BECL_ID <<
" EECL_ID 0x"
251 const int ECL_BARREL_FEE_IN_PCIE40 = 18;
252 const int ECL_ENDCAP_FEE_IN_PCIE40 = 16;
258 if (iCOPPERNode == BECL_ID + 1 || iCOPPERNode == BECL_ID + 2) {
260 iCrate = (iCOPPERNode - BECL_ID - 1) * ECL_BARREL_FEE_IN_PCIE40 + iFINESSE + 1;
261 if (iFINESSE >= ECL_BARREL_FEE_IN_PCIE40) {
262 B2ERROR(
"ECLChannelMapper:: slot id must be less than 18, got slot id " << iFINESSE);
265 }
else if (iCOPPERNode == BECL_ID + 3) {
267 iCrate = 2 * ECL_BARREL_FEE_IN_PCIE40 + (iFINESSE % 2) * 8 + iFINESSE / 2 + 1;
268 if (iFINESSE >= ECL_ENDCAP_FEE_IN_PCIE40) {
269 B2ERROR(
"ECLChannelMapper:: slot id must be less than 16, got slot id " << iFINESSE);
273 B2ERROR(
"ECLChannelMapper:: wrong COPPER NodeID 0x" << std::hex << iCOPPERNode <<
" expected BECL_ID 0x" << BECL_ID);
278 if (iCrate > ECL_CRATES || iCrate < 1) {
279 B2ERROR(
"ECLChannelMapper::getCrateID::ERROR:: wrong crate number " << iCrate <<
" return -1");
294 if (iCrate < 1 || iCrate > 52)
return -1;
295 if (iShaper < 1 || iShaper > 12)
return -1;
296 if (iChannel < 1 || iChannel > 16)
return -1;
298 if (iCrate >= 1 && iCrate <= 36) {
303 arrayIndex = (iCrate - 1) * ECL_BARREL_SHAPERS_IN_CRATE * ECL_CHANNELS_IN_SHAPER
304 + (iShaper - 1) * ECL_CHANNELS_IN_SHAPER + (iChannel - 1);
305 cellID = convertArrayBarrel[arrayIndex];
309 if (iCrate > 36 && iCrate < 45) {
310 arrayIndex = (iCrate - 37) * ECL_FWD_SHAPERS_IN_CRATE * ECL_CHANNELS_IN_SHAPER
311 + (iShaper - 1) * ECL_CHANNELS_IN_SHAPER + (iChannel - 1);
312 cellID = convertArrayFWD[arrayIndex];
316 arrayIndex = (iCrate - 45) * ECL_BKW_SHAPERS_IN_CRATE * ECL_CHANNELS_IN_SHAPER
317 + (iShaper - 1) * ECL_CHANNELS_IN_SHAPER + (iChannel - 1);
318 cellID = convertArrayBKW[arrayIndex];
326 if (cellID > 0 && cellID <= ECL_TOTAL_CHANNELS) {
327 return convertArrayInv[cellID - 1 ][0];
333 if (cellID > 0 && cellID <= ECL_TOTAL_CHANNELS) {
334 return convertArrayInv[cellID - 1][1];
340 if (cellID > 0 && cellID <= ECL_TOTAL_CHANNELS) {
341 return convertArrayInv[cellID - 1][2];
347 if (cellID < 1 || cellID > ECL_TOTAL_CHANNELS)
return -1;
349 int crate = getCrateID(cellID);
350 int shaper = getShaperPosition(cellID);
351 int channel = getShaperChannel(cellID);
355 const int bar_eid_count = ECL_BARREL_CRATES * ECL_BARREL_SHAPERS_IN_CRATE * ECL_CHANNELS_IN_SHAPER;
357 const int fwd_eid_count = ECL_FWD_CRATES * ECL_FWD_SHAPERS_IN_CRATE * ECL_CHANNELS_IN_SHAPER;
360 arrayIndex += (crate - 1) * ECL_BARREL_SHAPERS_IN_CRATE * ECL_CHANNELS_IN_SHAPER
361 + (shaper - 1) * ECL_CHANNELS_IN_SHAPER + (channel - 1);
362 }
else if (crate <= 44) {
363 arrayIndex += bar_eid_count;
364 arrayIndex += (crate - 37) * ECL_FWD_SHAPERS_IN_CRATE * ECL_CHANNELS_IN_SHAPER
365 + (shaper - 1) * ECL_CHANNELS_IN_SHAPER + (channel - 1);
367 arrayIndex += bar_eid_count + fwd_eid_count;
368 arrayIndex += (crate - 45) * ECL_BKW_SHAPERS_IN_CRATE * ECL_CHANNELS_IN_SHAPER
369 + (shaper - 1) * ECL_CHANNELS_IN_SHAPER + (channel - 1);
377 int systemID, iNode, iCOPPERNode;
379 if (iCrate < 1 || iCrate > ECL_CRATES)
return -1;
380 systemID = (iCrate <= ECL_BARREL_CRATES) * BECL_ID + (iCrate > ECL_BARREL_CRATES) * EECL_ID;
381 iNode = (iCrate <= ECL_BARREL_CRATES) ? (iCrate - 1) / 2 : (iCrate - ECL_BARREL_CRATES - 1) % 8;
382 iCOPPERNode = systemID + iNode + 1;
389 if (iCrate < 1 || iCrate > ECL_CRATES)
return -1;
391 return (iCrate <= ECL_BARREL_CRATES) ? (iCrate - 1) % 2 : (iCrate - ECL_BARREL_CRATES - 1) / 8;
396 if (iCrate <= ECL_BARREL_CRATES)
return 0;
397 if (ECL_BARREL_CRATES < iCrate && iCrate <= ECL_BARREL_CRATES + ECL_FWD_CRATES)
399 if (ECL_BARREL_CRATES + ECL_FWD_CRATES < iCrate && iCrate <= ECL_CRATES)
return 2;
bool isValid() const
Check whether a valid object was obtained from the database.
IntervalOfValidity getIoV() const
Return current IoV of the object.
bool hasChanged()
Check whether the object has changed since the last call to hasChanged of the accessor).
DB object to store correspondence table of type (Crate id, ShaperDSP id, Channel id) <-> (ECL CellID)
void setMappingVectors(const std::vector< int > &mappingBAR, const std::vector< int > &mappingFWD, const std::vector< int > &mappingBWD)
Set three vectors of map entries.
const std::vector< int > & getMappingBAR() const
Get vector of map entries for ECL barrel.
const std::vector< int > & getMappingBWD() const
Get vector of map entries for ECL backward endcap.
const std::vector< int > & getMappingFWD() const
Get vector of map entries for ECL forward endcap.
This class provides access to ECL channel map that is either a) Loaded from the database (see ecl/dbo...
int getSubSystem(int iCrate)
Get ECL subsystem ID by given crate number: 0 – barrel, 1 – forward. 2 – backward endcap.
static ECLChannelMapper * instance
Main instance of ECLChannelMapper.
bool initFromDB()
Initialize channel mapper from the conditions database.
ECLChannelMap getDBObject()
Convert internal data to ECLChannelMap database object.
bool initFromFile()
Initialize channel mapper using data stored in default location.
int getElectronicsID(int cellID)
Return channel index in ECLChannelMap.
int getFINESSE(int iCrate)
Get number of FINESSE (0/1) in COPPER by given crate number.
ECLChannelMapper()
Default constructor.
int getCellId(int iCrate, int iShaper, int iChannel)
Get CellId by given crate number, shaper position in the crate and DSP channel number in the shaper.
int getShaperChannel(int cellID)
Get number of DSP channel in the shaper by given number of CellId.
int getShaperPosition(int cellID)
Get position of the shaper in the crate by given CellId.
int getCOPPERNode(int iCrate)
Get number of COPPER node by given crate number.
static ECLChannelMapper * getInstance(bool use_db=true)
Return main instance of ECLChannelMapper.
int getCrateID(int iCOPPERNode, int iFINESSE, bool pcie40=false)
Get crate number by given COPPER node number and FINESSE number.
static std::string findFile(const std::string &path, bool silent=false)
Search for given file or directory in local or central release directory, and return absolute path if...
Class to store variables with their name which were sent to the logging service.
Abstract base class for different kinds of events.