9 #include <ecl/utility/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());
46 B2WARNING(
"Reading possibly outdated ECLChannelMap from " << eclMapFileName);
48 ifstream mapFile(eclMapFileName);
49 if (mapFile.is_open()) {
51 float iCrate, iShaper, iChannel, thetaID, phiID, cellID;
54 while (mapFile.good()) {
57 char ch = mapFile.get();
59 mapFile.ignore(256,
'\n');
61 }
else if (ch ==
'\n') {
67 mapFile >> iCrate >> iShaper >> iChannel >> thetaID >> phiID >> cellID;
69 if (cellID > ECL_TOTAL_CHANNELS) {
70 B2ERROR(
"ECLChannelMapper:: wrong cellID in the init file " << eclMapFileName);
75 convertArrayInv[(int)cellID - 1][0] = (
int)iCrate;
76 convertArrayInv[(int)cellID - 1][1] = (
int)iShaper;
77 convertArrayInv[(int)cellID - 1][2] = (
int)iChannel;
81 if (iCrate >= 1 && iCrate <= 36) {
82 arrayIndex = arrayCount;
83 convertArrayBarrel[arrayIndex] = (int)cellID;
87 if (iCrate > 36 && iCrate < 45) {
88 arrayIndex = arrayCount - 36 * 12 * 16;
90 if (arrayIndex >= 0 && arrayIndex < ECL_FWD_CRATES * ECL_FWD_SHAPERS_IN_CRATE * ECL_CHANNELS_IN_SHAPER)
91 convertArrayFWD[arrayIndex] = (int)cellID;
96 arrayIndex = arrayCount - 36 * 12 * 16 - 8 * 10 * 16;
97 if (arrayIndex >= 0 && arrayIndex < ECL_BKW_CRATES * ECL_BKW_SHAPERS_IN_CRATE * ECL_CHANNELS_IN_SHAPER)
98 convertArrayBKW[arrayIndex] = (int)cellID;
103 B2ERROR(
"ERROR:: file " << eclMapFileName <<
" doesn't found");
107 isInitialized =
true;
116 if (isInitialized && !channelMap.
hasChanged()) {
121 B2FATAL(
"ECLChannelMapper:: Could not get ECLChannelMap from the database.");
124 B2INFO(
"ECLChannelMapper:: loaded ECLChannelMap from the database"
133 int iCrate = 1, iShaper = 1, iChannel = 1;
136 int iMaxShapers = ECL_BARREL_SHAPERS_IN_CRATE;
138 while (iCrate <= ECL_CRATES) {
139 if (iCrate <= ECL_BARREL_CRATES) {
141 cellID = mappingBAR[arrayIndex];
142 convertArrayBarrel[arrayIndex] = cellID;
143 }
else if (iCrate <= ECL_BARREL_CRATES + ECL_FWD_CRATES) {
145 cellID = mappingFWD[arrayIndex];
146 convertArrayFWD[arrayIndex] = cellID;
149 cellID = mappingBWD[arrayIndex];
150 convertArrayBKW[arrayIndex] = cellID;
153 if (cellID > ECL_TOTAL_CHANNELS) {
154 B2FATAL(
"ECLChannelMapper:: wrong cellID (" << cellID <<
") in the database payload");
159 convertArrayInv[cellID - 1][0] = iCrate;
160 convertArrayInv[cellID - 1][1] = iShaper;
161 convertArrayInv[cellID - 1][2] = iChannel;
168 if (iChannel > ECL_CHANNELS_IN_SHAPER) {
171 if (iShaper > iMaxShapers) {
173 if (iCrate == ECL_BARREL_CRATES) {
175 iMaxShapers = getNShapersInCrate(iCrate + 1);
176 }
else if (iCrate == ECL_BARREL_CRATES + ECL_FWD_CRATES) {
178 iMaxShapers = getNShapersInCrate(iCrate + 1);
185 isInitialized =
true;
194 if (!isInitialized) {
195 B2FATAL(
"ECLChannelMapper:: Tried to generate dbobject before initialization");
198 int mappingBAR_size = ECL_BARREL_CRATES * ECL_BARREL_SHAPERS_IN_CRATE * ECL_CHANNELS_IN_SHAPER;
199 int mappingFWD_size = ECL_FWD_CRATES * ECL_FWD_SHAPERS_IN_CRATE * ECL_CHANNELS_IN_SHAPER;
200 int mappingBWD_size = ECL_BKW_CRATES * ECL_BKW_SHAPERS_IN_CRATE * ECL_CHANNELS_IN_SHAPER;
202 std::vector<int> mappingBAR(mappingBAR_size);
203 std::vector<int> mappingFWD(mappingFWD_size);
204 std::vector<int> mappingBWD(mappingBWD_size);
206 for (
int i = 0; i < mappingBAR_size; i++)
207 mappingBAR[i] = convertArrayBarrel[i];
208 for (
int i = 0; i < mappingFWD_size; i++)
209 mappingFWD[i] = convertArrayFWD[i];
210 for (
int i = 0; i < mappingBWD_size; i++)
211 mappingBWD[i] = convertArrayBKW[i];
222 if (iFINESSE > ECL_FINESSES_IN_COPPER - 1) {
223 B2ERROR(
"ECLChannelMapper::ERROR:: wrong FINESSE " << iFINESSE);
227 if ((iCOPPERNode & BECL_ID) == BECL_ID) {
229 iCrate = (iCOPPERNode - BECL_ID - 1) * ECL_FINESSES_IN_COPPER + iFINESSE + 1;
231 }
else if ((iCOPPERNode & EECL_ID) == EECL_ID) {
233 iCrate = ECL_BARREL_CRATES + iFINESSE * ECL_FWD_CRATES + (iCOPPERNode - EECL_ID - 1) + 1;
237 B2ERROR(
"ECLChannelMapper::ERROR:: wrong COPPER NodeID 0x" << std::hex << iCOPPERNode <<
" BECL_ID 0x" << BECL_ID <<
" EECL_ID 0x"
242 if (iCrate > ECL_CRATES || iCrate < 1) {
243 B2ERROR(
"ECLChannelMapper::getCrateID::ERROR:: wrong crate number " << iCrate <<
" return -1");
259 if (iCrate < 1 || iCrate > 52)
return -1;
260 if (iShaper < 1 || iShaper > 12)
return -1;
261 if (iChannel < 1 || iChannel > 16)
return -1;
263 if (iCrate >= 1 && iCrate <= 36) {
268 arrayIndex = (iCrate - 1) * ECL_BARREL_SHAPERS_IN_CRATE * ECL_CHANNELS_IN_SHAPER
269 + (iShaper - 1) * ECL_CHANNELS_IN_SHAPER + (iChannel - 1);
270 cellID = convertArrayBarrel[arrayIndex];
274 if (iCrate > 36 && iCrate < 45) {
275 arrayIndex = (iCrate - 37) * ECL_FWD_SHAPERS_IN_CRATE * ECL_CHANNELS_IN_SHAPER
276 + (iShaper - 1) * ECL_CHANNELS_IN_SHAPER + (iChannel - 1);
277 cellID = convertArrayFWD[arrayIndex];
281 arrayIndex = (iCrate - 45) * ECL_BKW_SHAPERS_IN_CRATE * ECL_CHANNELS_IN_SHAPER
282 + (iShaper - 1) * ECL_CHANNELS_IN_SHAPER + (iChannel - 1);
283 cellID = convertArrayBKW[arrayIndex];
291 if (cellID > 0 && cellID <= ECL_TOTAL_CHANNELS) {
292 return convertArrayInv[cellID - 1 ][0];
298 if (cellID > 0 && cellID <= ECL_TOTAL_CHANNELS) {
299 return convertArrayInv[cellID - 1][1];
305 if (cellID > 0 && cellID <= ECL_TOTAL_CHANNELS) {
306 return convertArrayInv[cellID - 1][2];
312 int systemID, iNode, iCOPPERNode;
314 if (iCrate < 1 || iCrate > ECL_CRATES)
return -1;
315 systemID = (iCrate <= ECL_BARREL_CRATES) * BECL_ID + (iCrate > ECL_BARREL_CRATES) * EECL_ID;
316 iNode = (iCrate <= ECL_BARREL_CRATES) ? (iCrate - 1) / 2 : (iCrate - ECL_BARREL_CRATES - 1) % 8;
317 iCOPPERNode = systemID + iNode + 1;
324 if (iCrate < 1 || iCrate > ECL_CRATES)
return -1;
326 return (iCrate <= ECL_BARREL_CRATES) ? (iCrate - 1) % 2 : (iCrate - ECL_BARREL_CRATES - 1) / 8;
331 if (iCrate <= ECL_BARREL_CRATES)
return 0;
332 if (ECL_BARREL_CRATES < iCrate && iCrate <= ECL_BARREL_CRATES + ECL_FWD_CRATES)
334 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.
int getSubSystem(int iCrate)
get ECL subsystem ID by given crate number: 0 – barrel, 1 – forward. 2 – backward endcap
bool initFromDB()
Initialize channel mapper from the conditions database.
ECLChannelMap getDBObject()
Convert internal data to ECLChannelMap database object.
int getCrateID(int iCOPPERNode, int iFINESSE)
get crate number by given COPPER node number and FINESSE number
bool initFromFile()
Initialize channel mapper using data stored in default location.
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 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.