#ifndef ALISPDUTILS_CXX
#define ALISPDUTILS_CXX
#include <TString.h>
#include "AliSPDUtils.h"
ClassImp(AliSPDUtils)
const Int_t AliSPDUtils::fgkDDLModuleMap[20][12] = {
{ 4, 5, 0, 1, 80, 81, 84, 85, 88, 89, 92, 93},
{12,13, 8, 9, 96, 97,100,101,104,105,108,109},
{20,21,16,17,112,113,116,117,120,121,124,125},
{28,29,24,25,128,129,132,133,136,137,140,141},
{36,37,32,33,144,145,148,149,152,153,156,157},
{44,45,40,41,160,161,164,165,168,169,172,173},
{52,53,48,49,176,177,180,181,184,185,188,189},
{60,61,56,57,192,193,196,197,200,201,204,205},
{68,69,64,65,208,209,212,213,216,217,220,221},
{76,77,72,73,224,225,228,229,232,233,236,237},
{ 7, 6, 3, 2, 83, 82, 87, 86, 91, 90, 95, 94},
{15,14,11,10, 99, 98,103,102,107,106,111,110},
{23,22,19,18,115,114,119,118,123,122,127,126},
{31,30,27,26,131,130,135,134,139,138,143,142},
{39,38,35,34,147,146,151,150,155,154,159,158},
{47,46,43,42,163,162,167,166,171,170,175,174},
{55,54,51,50,179,178,183,182,187,186,191,190},
{63,62,59,58,195,194,199,198,203,202,207,206},
{71,70,67,66,211,210,215,214,219,218,223,222},
{79,78,75,74,227,226,231,230,235,234,239,238}
};
AliSPDUtils::~AliSPDUtils() {
}
Bool_t AliSPDUtils::OfflineToOnline(UInt_t module, UInt_t colM, UInt_t rowM, UInt_t& eq, UInt_t& hs, UInt_t& chip, UInt_t& col, UInt_t& row) {
eq = GetOnlineEqIdFromOffline(module);
hs = GetOnlineHSFromOffline(module);
chip = GetOnlineChipFromOffline(module,colM);
col = GetOnlineColFromOffline(module,colM);
row = GetOnlineRowFromOffline(module,rowM);
if (eq>=20 || hs>=6 || chip>=10 || col>=32 || row>=256) return kFALSE;
else return kTRUE;
}
Bool_t AliSPDUtils::OnlineToOffline(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t col, UInt_t row, UInt_t& module, UInt_t& colM, UInt_t& rowM) {
module = GetOfflineModuleFromOnline(eq,hs,chip);
colM = GetOfflineColFromOnline(eq,hs,chip,col);
rowM = GetOfflineRowFromOnline(eq,hs,chip,row);
if (module>=240 || colM>=160 || rowM>=256) return kFALSE;
else return kTRUE;
}
Bool_t AliSPDUtils::GetOfflineFromOfflineChipKey(UInt_t chipkey,UInt_t& module, UInt_t& chip){
if (chipkey>=1200) {
TString errMess = Form("%d is not a valid Chip Key number",chipkey);
printf(" ERROR : %s\n", errMess.Data());
return 0;
}
module = chipkey/5;
chip=chipkey%20%5;
return 1;
}
UInt_t AliSPDUtils::GetOfflineModuleFromOnline(UInt_t eqId, UInt_t hs, UInt_t chip) {
if (eqId<20 && hs<6 && chip<10) return fgkDDLModuleMap[eqId][hs*2+chip/5];
else return 240;
}
UInt_t AliSPDUtils::GetOfflineChipKeyFromOnline(UInt_t eqId, UInt_t hs, UInt_t chip) {
if (eqId<20 && hs<6 && chip<10) {
UInt_t module = GetOfflineModuleFromOnline(eqId,hs,chip);
UInt_t chipInModule = ( chip>4 ? chip-5 : chip );
if(eqId>9) chipInModule = 4 - chipInModule;
return (module*5 + chipInModule);
} else return 1200;
}
UInt_t AliSPDUtils::GetOnlineEqIdFromOffline(UInt_t module) {
for (UInt_t eqId=0; eqId<20; eqId++) {
for (UInt_t iModule=0; iModule<12; iModule++) {
if (GetModuleNumber(eqId,iModule)==(Int_t)module) return eqId;
}
}
return 20;
}
UInt_t AliSPDUtils::GetOnlineHSFromOffline(UInt_t module) {
for (UInt_t eqId=0; eqId<20; eqId++) {
for (UInt_t iModule=0; iModule<12; iModule++) {
if (GetModuleNumber(eqId,iModule)==(Int_t)module) return iModule/2;
}
}
return 6;
}
UInt_t AliSPDUtils::GetOnlineChipFromOffline(UInt_t module, UInt_t colM) {
for (UInt_t eq=0; eq<20; eq++) {
for (UInt_t iModule=0; iModule<12; iModule++) {
if (GetModuleNumber(eq,iModule)==(Int_t)module) {
if (module<80) {
if (eq<10) {
return (159-colM)/32 + 5*(iModule%2);
}
else {
return colM/32 + 5*(iModule%2);
}
}
else if (module<240) {
if (eq<10) {
return colM/32 + 5*(iModule%2);
}
else {
return (159-colM)/32 + 5*(iModule%2);
}
}
}
}
}
return 10;
}
Int_t AliSPDUtils::GetModuleNumber(UInt_t iDDL, UInt_t iModule) {
if (iDDL<20 && iModule<12) return fgkDDLModuleMap[iDDL][iModule];
else return 240;
}
UInt_t AliSPDUtils::GetOnlineColFromOffline(UInt_t module, UInt_t colM) {
if (module<80) {
return colM%32;
}
else if (module<240) {
return colM%32;
}
return 32;
}
UInt_t AliSPDUtils::GetOnlineRowFromOffline(UInt_t module, UInt_t rowM) {
if (module<80) {
return (255-rowM);
}
else if (module<240) {
return (255-rowM);
}
return 256;
}
UInt_t AliSPDUtils::GetOfflineColFromOnline(UInt_t eqId, UInt_t hs, UInt_t chip, UInt_t col) {
if (eqId>=20 || hs>=6 || chip>=10 || col>=32) return 160;
UInt_t offset = 32 * (chip % 5);
if (hs<2) {
if (eqId<10) {
return 159 - (31-col + offset);
}
else {
return col + offset;
}
}
else {
if (eqId<10) {
return (col + offset);
}
else {
return 159 - (31-col + offset);
}
}
}
UInt_t AliSPDUtils::GetOfflineRowFromOnline(UInt_t eqId, UInt_t hs, UInt_t chip, UInt_t row) {
if (eqId>=20 || hs>=6 || chip>=10 || row>=256) return 256;
return 255-row;
}
Bool_t AliSPDUtils::GetOnlineFromOfflineChipKey(UInt_t chipkey,UInt_t& eq, UInt_t& hs, UInt_t& chip){
if (chipkey>=1200) {
TString errMess = Form("%d is not a valid Chip Key number",chipkey);
printf("ERROR : %s \n", errMess.Data());
return 0;
}
eq = GetOnlineEqIdFromOffline(chipkey/5);
hs = GetOnlineHSFromOffline(chipkey/5);
chip=chipkey%20;
if(chip>9) chip=19-chip;
return 1;
}
#endif