10#include <ecl/mapper/ECLChannelMapper.h>
13#include <framework/database/DBObjPtr.h>
14#include <framework/utilities/FileSystem.h>
15#include <rawdata/dataobjects/RawCOPPERFormat.h>
28 for (i = 0; i < ECL_BARREL_CRATES * ECL_BARREL_SHAPERS_IN_CRATE * ECL_CHANNELS_IN_SHAPER; i++)
30 for (i = 0; i < ECL_FWD_CRATES * ECL_FWD_SHAPERS_IN_CRATE * ECL_CHANNELS_IN_SHAPER; i++)
32 for (i = 0; i < ECL_BKW_CRATES * ECL_BKW_SHAPERS_IN_CRATE * ECL_CHANNELS_IN_SHAPER; i++)
34 for (i = 0; i < ECL_TOTAL_CHANNELS; i++)
35 for (
int j = 0; j < 3; j++)
61 B2WARNING(
"Reading possibly outdated ECLChannelMap from " << eclMapFileName);
63 ifstream mapFile(eclMapFileName);
64 if (mapFile.is_open()) {
66 float iCrate, iShaper, iChannel, thetaID, phiID, cellID;
69 while (mapFile.good()) {
72 char ch = mapFile.get();
74 mapFile.ignore(256,
'\n');
76 }
else if (ch ==
'\n') {
82 mapFile >> iCrate >> iShaper >> iChannel >> thetaID >> phiID >> cellID;
84 if (cellID >
static_cast<float>(ECL_TOTAL_CHANNELS)) {
85 B2ERROR(
"ECLChannelMapper:: wrong cellID in the init file " << eclMapFileName);
96 if (iCrate >= 1 && iCrate <= 36) {
97 arrayIndex = arrayCount;
102 if (iCrate > 36 && iCrate < 45) {
103 arrayIndex = arrayCount - 36 * 12 * 16;
105 if (arrayIndex >= 0 && arrayIndex < ECL_FWD_CRATES * ECL_FWD_SHAPERS_IN_CRATE * ECL_CHANNELS_IN_SHAPER)
111 arrayIndex = arrayCount - 36 * 12 * 16 - 8 * 10 * 16;
112 if (arrayIndex >= 0 && arrayIndex < ECL_BKW_CRATES * ECL_BKW_SHAPERS_IN_CRATE * ECL_CHANNELS_IN_SHAPER)
118 B2ERROR(
"ERROR:: file " << eclMapFileName <<
" doesn't found");
136 B2FATAL(
"ECLChannelMapper:: Could not get ECLChannelMap from the database.");
139 B2INFO(
"ECLChannelMapper:: loaded ECLChannelMap from the database"
142 const auto& mappingBAR = channelMap->getMappingBAR();
143 const auto& mappingFWD = channelMap->getMappingFWD();
144 const auto& mappingBWD = channelMap->getMappingBWD();
148 int iCrate = 1, iShaper = 1, iChannel = 1;
151 int iMaxShapers = ECL_BARREL_SHAPERS_IN_CRATE;
153 while (iCrate <= ECL_CRATES) {
154 if (iCrate <= ECL_BARREL_CRATES) {
156 cellID = mappingBAR[arrayIndex];
158 }
else if (iCrate <= ECL_BARREL_CRATES + ECL_FWD_CRATES) {
160 cellID = mappingFWD[arrayIndex];
164 cellID = mappingBWD[arrayIndex];
168 if (cellID > ECL_TOTAL_CHANNELS) {
169 B2FATAL(
"ECLChannelMapper:: wrong cellID (" << cellID <<
") in the database payload");
183 if (iChannel > ECL_CHANNELS_IN_SHAPER) {
186 if (iShaper > iMaxShapers) {
188 if (iCrate == ECL_BARREL_CRATES) {
191 }
else if (iCrate == ECL_BARREL_CRATES + ECL_FWD_CRATES) {
210 B2FATAL(
"ECLChannelMapper:: Tried to generate dbobject before initialization");
213 int mappingBAR_size = ECL_BARREL_CRATES * ECL_BARREL_SHAPERS_IN_CRATE * ECL_CHANNELS_IN_SHAPER;
214 int mappingFWD_size = ECL_FWD_CRATES * ECL_FWD_SHAPERS_IN_CRATE * ECL_CHANNELS_IN_SHAPER;
215 int mappingBWD_size = ECL_BKW_CRATES * ECL_BKW_SHAPERS_IN_CRATE * ECL_CHANNELS_IN_SHAPER;
217 std::vector<int> mappingBAR(mappingBAR_size);
218 std::vector<int> mappingFWD(mappingFWD_size);
219 std::vector<int> mappingBWD(mappingBWD_size);
221 for (
int i = 0; i < mappingBAR_size; i++)
223 for (
int i = 0; i < mappingFWD_size; i++)
225 for (
int i = 0; i < mappingBWD_size; i++)
239 if (iFINESSE > ECL_FINESSES_IN_COPPER - 1) {
240 B2ERROR(
"ECLChannelMapper::ERROR:: wrong FINESSE " << iFINESSE);
244 if ((iCOPPERNode & BECL_ID) == BECL_ID) {
245 iCrate = (iCOPPERNode - BECL_ID - 1) * ECL_FINESSES_IN_COPPER + iFINESSE + 1;
246 }
else if ((iCOPPERNode & EECL_ID) == EECL_ID) {
247 iCrate = ECL_BARREL_CRATES + iFINESSE * ECL_FWD_CRATES + (iCOPPERNode - EECL_ID - 1) + 1;
249 B2ERROR(
"ECLChannelMapper::ERROR:: wrong COPPER NodeID 0x" << std::hex << iCOPPERNode <<
" BECL_ID 0x" << BECL_ID <<
" EECL_ID 0x"
255 const int ECL_BARREL_FEE_IN_PCIE40 = 18;
256 const int ECL_ENDCAP_FEE_IN_PCIE40 = 16;
262 if (iCOPPERNode == BECL_ID + 1 || iCOPPERNode == BECL_ID + 2) {
264 iCrate = (iCOPPERNode - BECL_ID - 1) * ECL_BARREL_FEE_IN_PCIE40 + iFINESSE + 1;
265 if (iFINESSE >= ECL_BARREL_FEE_IN_PCIE40) {
266 B2ERROR(
"ECLChannelMapper:: slot id must be less than 18, got slot id " << iFINESSE);
269 }
else if (iCOPPERNode == BECL_ID + 3) {
271 iCrate = 2 * ECL_BARREL_FEE_IN_PCIE40 + (iFINESSE % 2) * 8 + iFINESSE / 2 + 1;
272 if (iFINESSE >= ECL_ENDCAP_FEE_IN_PCIE40) {
273 B2ERROR(
"ECLChannelMapper:: slot id must be less than 16, got slot id " << iFINESSE);
277 B2ERROR(
"ECLChannelMapper:: wrong COPPER NodeID 0x" << std::hex << iCOPPERNode <<
" expected BECL_ID 0x" << BECL_ID);
282 if (iCrate > ECL_CRATES || iCrate < 1) {
283 B2ERROR(
"ECLChannelMapper::getCrateID::ERROR:: wrong crate number " << iCrate <<
" return -1");
298 if (iCrate < 1 || iCrate > 52)
return -1;
299 if (iShaper < 1 || iShaper > 12)
return -1;
300 if (iChannel < 1 || iChannel > 16)
return -1;
302 if (iCrate >= 1 && iCrate <= 36) {
307 arrayIndex = (iCrate - 1) * ECL_BARREL_SHAPERS_IN_CRATE * ECL_CHANNELS_IN_SHAPER
308 + (iShaper - 1) * ECL_CHANNELS_IN_SHAPER + (iChannel - 1);
313 if (iCrate > 36 && iCrate < 45) {
314 arrayIndex = (iCrate - 37) * ECL_FWD_SHAPERS_IN_CRATE * ECL_CHANNELS_IN_SHAPER
315 + (iShaper - 1) * ECL_CHANNELS_IN_SHAPER + (iChannel - 1);
320 arrayIndex = (iCrate - 45) * ECL_BKW_SHAPERS_IN_CRATE * ECL_CHANNELS_IN_SHAPER
321 + (iShaper - 1) * ECL_CHANNELS_IN_SHAPER + (iChannel - 1);
330 if (cellID > 0 && cellID <= ECL_TOTAL_CHANNELS) {
337 if (cellID > 0 && cellID <= ECL_TOTAL_CHANNELS) {
344 if (cellID > 0 && cellID <= ECL_TOTAL_CHANNELS) {
351 if (cellID < 1 || cellID > ECL_TOTAL_CHANNELS)
return -1;
359 const int bar_eid_count = ECL_BARREL_CRATES * ECL_BARREL_SHAPERS_IN_CRATE * ECL_CHANNELS_IN_SHAPER;
361 const int fwd_eid_count = ECL_FWD_CRATES * ECL_FWD_SHAPERS_IN_CRATE * ECL_CHANNELS_IN_SHAPER;
364 arrayIndex += (crate - 1) * ECL_BARREL_SHAPERS_IN_CRATE * ECL_CHANNELS_IN_SHAPER
365 + (shaper - 1) * ECL_CHANNELS_IN_SHAPER + (channel - 1);
366 }
else if (crate <= 44) {
367 arrayIndex += bar_eid_count;
368 arrayIndex += (crate - 37) * ECL_FWD_SHAPERS_IN_CRATE * ECL_CHANNELS_IN_SHAPER
369 + (shaper - 1) * ECL_CHANNELS_IN_SHAPER + (channel - 1);
371 arrayIndex += bar_eid_count + fwd_eid_count;
372 arrayIndex += (crate - 45) * ECL_BKW_SHAPERS_IN_CRATE * ECL_CHANNELS_IN_SHAPER
373 + (shaper - 1) * ECL_CHANNELS_IN_SHAPER + (channel - 1);
381 int systemID, iNode, iCOPPERNode;
383 if (iCrate < 1 || iCrate > ECL_CRATES)
return -1;
384 systemID = (iCrate <= ECL_BARREL_CRATES) * BECL_ID + (iCrate > ECL_BARREL_CRATES) * EECL_ID;
385 iNode = (iCrate <= ECL_BARREL_CRATES) ? (iCrate - 1) / 2 : (iCrate - ECL_BARREL_CRATES - 1) % 8;
386 iCOPPERNode = systemID + iNode + 1;
393 if (iCrate < 1 || iCrate > ECL_CRATES)
return -1;
395 return (iCrate <= ECL_BARREL_CRATES) ? (iCrate - 1) % 2 : (iCrate - ECL_BARREL_CRATES - 1) / 8;
400 if (iCrate <= ECL_BARREL_CRATES)
return 0;
401 if (ECL_BARREL_CRATES < iCrate && iCrate <= ECL_BARREL_CRATES + ECL_FWD_CRATES)
403 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).
Class for accessing objects in the database.
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.
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.
bool isInitialized
initialization flag
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 convertArrayFWD[ECL_FWD_CRATES *ECL_FWD_SHAPERS_IN_CRATE *ECL_CHANNELS_IN_SHAPER]
convert (iCrate, iShaper, iChannel) to CellId for Forward endcap
int getFINESSE(int iCrate)
Get number of FINESSE (0/1) in COPPER by given crate number.
ECLChannelMapper()
Default constructor.
int getNShapersInCrate(int iCrate)
Get number of ShaperDSP modules in the given VME crate number.
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 convertArrayBKW[ECL_BKW_CRATES *ECL_BKW_SHAPERS_IN_CRATE *ECL_CHANNELS_IN_SHAPER]
convert (iCrate, iShaper, iChannel) to CellId Backward endcap
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 convertArrayInv[ECL_TOTAL_CHANNELS][3]
convert CellId to (iCrate, iShaper, iChannel)
int convertArrayBarrel[ECL_BARREL_CRATES *ECL_BARREL_SHAPERS_IN_CRATE *ECL_CHANNELS_IN_SHAPER]
convert (iCrate, iShaper, iChannel) to CellId for Barrel ECL
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.