+//__________________________________________________________________________
+void AliITSRawStreamSPD::CheckHeaderAndTrailerCount(Int_t ddlID) {
+ // Checks that the number of header and trailers found for the ddl are as expected
+ if (fEqPLChipHeadersRead != fExpectedHeaderTrailerCount) {
+ TString errMess = Form("Chip header count inconsistent %d != %d (expected) for ddl %d",
+ fEqPLChipHeadersRead,fExpectedHeaderTrailerCount,ddlID);
+ AliError(errMess.Data());
+ fRawReader->AddMajorErrorLog(kHeaderCountErr,errMess.Data());
+ if (fAdvancedErrorLog) fAdvLogger->ProcessError(kHeaderCountErr,ddlID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
+ }
+ if (fEqPLChipTrailersRead != fExpectedHeaderTrailerCount) {
+ TString errMess = Form("Chip trailer count inconsistent %d != %d (expected) for ddl %d",
+ fEqPLChipTrailersRead,fExpectedHeaderTrailerCount,ddlID);
+ AliError(errMess.Data());
+ fRawReader->AddMajorErrorLog(kHeaderCountErr,errMess.Data());
+ if (fAdvancedErrorLog) fAdvLogger->ProcessError(kHeaderCountErr,ddlID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data());
+ }
+}
+//__________________________________________________________________________
+void AliITSRawStreamSPD::ActivateAdvancedErrorLog(Bool_t activate, AliITSRawStreamSPDErrorLog* advLogger) {
+ // Activate the advanced error logging.
+ // Logger object has to be created elsewhere and a pointer sent here.
+ fAdvancedErrorLog=activate;
+ if (activate && advLogger!=NULL) {
+ fAdvLogger = advLogger;
+ }
+ if (fAdvLogger==NULL) {
+ fAdvancedErrorLog=kFALSE;
+ }
+}
+//__________________________________________________________________________
+const Char_t* AliITSRawStreamSPD::GetErrorName(UInt_t errorCode) {
+ // Returns a string for each error code
+ if (errorCode==kTotal) return "All Errors";
+ else if (errorCode==kHeaderMissingErr) return "Header Missing";
+ else if (errorCode==kTrailerMissingErr) return "Trailer Missing";
+ else if (errorCode==kTrailerWithoutHeaderErr) return "Trailer Unexpected";
+ else if (errorCode==kHeaderCountErr) return "Header Count Wrong";
+ else if (errorCode==kTrailerCountErr) return "Trailer Count Wrong";
+ else if (errorCode==kFillUnexpectErr) return "Fill Unexpected";
+ else if (errorCode==kFillMissingErr) return "Fill Missing";
+ else if (errorCode==kWrongFillWordErr) return "Fill Word Wrong";
+ else if (errorCode==kNumberHitsErr) return "Hit Count Wrong";
+ else if (errorCode==kEventCounterErr) return "Event Counter Error";
+ else if (errorCode==kDDLNumberErr) return "DDL Number Error";
+ else if (errorCode==kHSNumberErr) return "HS Number Error";
+ else if (errorCode==kChipAddrErr) return "Chip Address Error";
+ else if (errorCode==kCalHeaderLengthErr) return "Calib Header Length Error";
+ else if (errorCode==kAdvEventCounterErr) return "Event Counter Error (Adv)";
+ else if (errorCode==kAdvEventCounterOrderErr) return "Event Counter Jump Error (Adv)";
+ else if (errorCode==kTrailerErrorBitErr) return "Trailer Error Bit Set";
+ else if (errorCode==kLinkRxDetectorFatalErr) return "LinkRx/Detector Fatal Error Bit Set";
+ else if (errorCode==kTSMtriggerErr) return "TSM Trigger Error Bit Set";
+ else if (errorCode==kHighMultiplicityFlag) return "High Multiplicity Event Flag Set";
+ else return "";
+}
+//__________________________________________________________________________
+Bool_t AliITSRawStreamSPD::GetFastOrSignal(UInt_t eq, UInt_t hs, UInt_t chip) {
+ // returns if there was a fastor signal from this chip
+ if (eq>=20 || hs>=6 || chip>=10) {
+ TString errMess = Form("eq,hs,chip = %d,%d,%d out of bounds. Return kFALSE.",eq,hs,chip);
+ AliError(errMess.Data());
+ return kFALSE;
+ }
+ return fFastOrSignal[eq][hs][chip];
+}
+//__________________________________________________________________________
+Bool_t AliITSRawStreamSPD::IsActiveEq(UInt_t eq) const {
+ // returns if the eq is active (seen in data)
+ if (eq>=20) {
+ TString errMess = Form("eq = %d out of bounds. Return kFALSE.",eq);
+ AliError(errMess.Data());
+ return kFALSE;
+ }
+ return fActiveEq[eq];
+}
+//__________________________________________________________________________
+Bool_t AliITSRawStreamSPD::IsActiveHS(UInt_t eq, UInt_t hs) const {
+ // returns if the hs is active (info from block attr)
+ if (eq>=20 || hs>=6) {
+ TString errMess = Form("eq,hs = %d,%d out of bounds. Return kFALSE.",eq,hs);
+ AliError(errMess.Data());
+ return kFALSE;
+ }
+ return fActiveHS[eq][hs];
+}
+//__________________________________________________________________________
+Bool_t AliITSRawStreamSPD::IsActiveChip(UInt_t eq, UInt_t hs, UInt_t chip) const {
+ // returns if the chip is active (seen in data)
+ if (eq>=20 || hs>=6 || chip>=10) {
+ TString errMess = Form("eq,hs,chip = %d,%d,%d out of bounds. Return kFALSE.",eq,hs,chip);
+ AliError(errMess.Data());
+ return kFALSE;
+ }
+ return fActiveChip[eq][hs][chip];
+}
+//__________________________________________________________________________
+Bool_t AliITSRawStreamSPD::GetHalfStavePresent(UInt_t hs) {
+ // Reads the half stave present status from the block attributes
+ // This is not really needed anymore (kept for now in case it is still used somewhere).
+ // The same information can be reached through the "IsActiveHS" method instead.
+ Int_t ddlID = fRawReader->GetDDLID();
+ if (ddlID==-1) {
+ AliWarning("DDL ID = -1. Cannot read block attributes. Return kFALSE.");
+ return kFALSE;
+ }
+ else {
+ if (hs>=6) {
+ AliWarning(Form("HS >= 6 requested (%d). Return kFALSE.",hs));
+ return kFALSE;
+ }
+ UChar_t attr = fRawReader->GetBlockAttributes();
+ if (((attr>>hs) & 0x01) == 0x01) { // bit set means not present
+ return kFALSE;
+ }
+ else {
+ return kTRUE;
+ }
+ }
+}
+//__________________________________________________________________________
+Bool_t AliITSRawStreamSPD::IsEventCounterFullConsistent() const {
+ // checks if the event counter values are consistent within the event
+ Short_t reference = -1;
+ for (UInt_t eq=0; eq<20; eq++) {
+ if (IsActiveEq(eq)) {
+ for (UInt_t hs=0; hs<6; hs++) {
+ if (IsActiveHS(eq,hs)) {
+ for (UInt_t chip=0; chip<10; chip++) {
+ if (fEventCounterFull[eq][hs][chip]!=-1) {
+ if (reference==-1) reference = fEventCounterFull[eq][hs][chip];
+ if (fEventCounterFull[eq][hs][chip] != reference) return kFALSE;
+ }
+ }
+ }
+ }
+ }
+ }
+ return kTRUE;
+}
+//__________________________________________________________________________
+Short_t AliITSRawStreamSPD::GetEventCounterFullEq(UInt_t eq) const {
+ // if the eq is active; returns the event counter value
+ if (eq>=20) {
+ TString errMess = Form("eq (%d) out of bounds",eq);
+ AliError(errMess.Data());
+ return -1;
+ }
+ if (IsActiveEq(eq)) {
+ for (UInt_t hs=0; hs<6; hs++) {
+ if (IsActiveHS(eq,hs)) {
+ for (UInt_t chip=0; chip<10; chip++) {
+ if (fEventCounterFull[eq][hs][chip]!=-1) {
+ return fEventCounterFull[eq][hs][chip];
+ }
+ }
+ }
+ }
+ }
+ return -1;
+}
+//__________________________________________________________________________
+Short_t AliITSRawStreamSPD::GetEventCounterFullHS(UInt_t eq, UInt_t hs) const {
+ // if the eq,hs is active; returns the event counter value
+ if (eq>=20 || hs>=6) {
+ TString errMess = Form("eq,hs (%d,%d) out of bounds",eq,hs);
+ AliError(errMess.Data());
+ return -1;
+ }
+ if (IsActiveEq(eq)) {
+ if (IsActiveHS(eq,hs)) {
+ for (UInt_t chip=0; chip<10; chip++) {
+ if (fEventCounterFull[eq][hs][chip]!=-1) {
+ return fEventCounterFull[eq][hs][chip];
+ }
+ }
+ }
+ }
+ return -1;
+}
+//__________________________________________________________________________
+Short_t AliITSRawStreamSPD::GetEventCounterFullChip(UInt_t eq, UInt_t hs, UInt_t chip) const {
+ // if the eq,hs,chip is active; returns the event counter value
+ if (eq>=20 || hs>=6 || chip>=10) {
+ TString errMess = Form("eq,hs,chip (%d,%d,%d) out of bounds",eq,hs,chip);
+ AliError(errMess.Data());
+ return -1;
+ }
+ if (IsActiveEq(eq)) {
+ if (IsActiveHS(eq,hs)) {
+ if (IsActiveChip(eq,hs,chip)) {
+ return fEventCounterFull[eq][hs][chip];
+ }
+ }
+ }
+ return -1;
+}
+//__________________________________________________________________________
+Int_t AliITSRawStreamSPD::GetHword(UInt_t index) {
+ if (index<kCalHeadLenMax) return fCalHeadWord[index];
+ else return 0;
+}
+Bool_t AliITSRawStreamSPD::GetHhalfStaveScanned(UInt_t hs) const {
+ if (hs<6) return (Bool_t)((fCalHeadWord[0]>>(6+hs)) & (0x00000001));
+ else return kFALSE;
+}
+Bool_t AliITSRawStreamSPD::GetHchipPresent(UInt_t hs, UInt_t chip) const {
+ if (hs<6 && chip<10) return ((( fCalHeadWord[hs/3+3]>>((hs%3)*10+chip)) & 0x00000001) == 1);
+ else return kFALSE;
+}
+UInt_t AliITSRawStreamSPD::GetHdacHigh(UInt_t hs) const {
+ if (hs<6) return (fCalHeadWord[hs/2+7]>>(24-16*(hs%2)) & 0x000000ff);
+ else return 0;
+}
+UInt_t AliITSRawStreamSPD::GetHdacLow(UInt_t hs) const {
+ if (hs<6) return (fCalHeadWord[hs/2+7]>>(16-16*(hs%2)) & 0x000000ff);
+ else return 0;
+}
+UInt_t AliITSRawStreamSPD::GetHTPAmp(UInt_t hs) const {
+ if (hs<6) return fCalHeadWord[hs+10];
+ else return 0;
+}
+Bool_t AliITSRawStreamSPD::GetHminTHchipPresent(UInt_t chip) const {
+ if (chip<10) return ((( fCalHeadWord[7]>>(16+chip)) & 0x00000001) == 1);
+ else return kFALSE;
+}
+UInt_t AliITSRawStreamSPD::GetFOHnumDacs() const {
+ return (fCalHeadLen-37)/2;
+}
+UInt_t AliITSRawStreamSPD::GetFOHdacIndex(UInt_t index) const {
+ if (index>=GetFOHnumDacs()) {
+ TString errMess = Form("Only %d DACs in this run, returning 0",GetFOHnumDacs());
+ AliError(errMess.Data());
+ return 0;
+ }
+ return fCalHeadWord[7+index*2];
+}
+UInt_t AliITSRawStreamSPD::GetFOHdacValue(UInt_t index) const {
+ if (index>=GetFOHnumDacs()) {
+ TString errMess = Form("Only %d DACs in this run, returning 0",GetFOHnumDacs());
+ AliError(errMess.Data());
+ return 0;
+ }
+ return fCalHeadWord[7+1+index*2];
+}
+UInt_t AliITSRawStreamSPD::GetFOHchipCount(UInt_t hs, UInt_t chip) const {
+ if (hs<6 && chip<10) {
+ if (chip%2==0) {
+ return ((fCalHeadWord[7 + GetFOHnumDacs()*2 + (hs*10 + chip)/2] >> 16) & 0x0000ffff);
+ }
+ else {
+ return (fCalHeadWord[7 + GetFOHnumDacs()*2 + (hs*10 + chip)/2] & 0x0000ffff);
+ }
+ }
+ else return 0;
+}
+//__________________________________________________________________________
+Int_t AliITSRawStreamSPD::GetModuleNumber(UInt_t iDDL, UInt_t iModule) {
+ if (iDDL<20 && iModule<12) return fgkDDLModuleMap[iDDL][iModule];
+ else return 240;
+}
+//__________________________________________________________________________
+Bool_t AliITSRawStreamSPD::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) {
+ // converts offline coordinates to online
+ 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 AliITSRawStreamSPD::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) {
+ // converts online coordinates to offline
+ 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;
+}
+//__________________________________________________________________________
+UInt_t AliITSRawStreamSPD::GetOnlineEqIdFromOffline(UInt_t module) {
+ // offline->online (eq)
+ 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; // error
+}
+//__________________________________________________________________________
+UInt_t AliITSRawStreamSPD::GetOnlineHSFromOffline(UInt_t module) {
+ // offline->online (hs)
+ 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; // error
+}
+//__________________________________________________________________________
+UInt_t AliITSRawStreamSPD::GetOnlineChipFromOffline(UInt_t module, UInt_t colM) {
+ // offline->online (chip)
+ 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) { // side A
+ return (159-colM)/32 + 5*(iModule%2);
+ }
+ else { // side C
+ return colM/32 + 5*(iModule%2);
+ }
+ }
+ else if (module<240) {
+ if (eq<10) { // side A
+ return colM/32 + 5*(iModule%2);
+ }
+ else { // side C
+ return (159-colM)/32 + 5*(iModule%2);
+ }
+ }
+ }
+ }
+ }
+ return 10; // error
+}
+//__________________________________________________________________________
+UInt_t AliITSRawStreamSPD::GetOnlineColFromOffline(UInt_t module, UInt_t colM) {
+ // offline->online (col)
+ if (module<80) { // inner layer
+ return colM%32;
+ }
+ else if (module<240) { // outer layer
+ return colM%32;
+ }
+ return 32; // error
+}
+//__________________________________________________________________________
+UInt_t AliITSRawStreamSPD::GetOnlineRowFromOffline(UInt_t module, UInt_t rowM) {
+ // offline->online (row)
+ if (module<80) { // inner layer
+ return (255-rowM);
+ }
+ else if (module<240) { // outer layer
+ return (255-rowM);
+ }
+ return 256; // error
+}
+//__________________________________________________________________________
+UInt_t AliITSRawStreamSPD::GetOfflineModuleFromOnline(UInt_t eqId, UInt_t hs, UInt_t chip) {
+ // online->offline (module)
+ if (eqId<20 && hs<6 && chip<10) return fgkDDLModuleMap[eqId][hs*2+chip/5];
+ else return 240;
+}
+//__________________________________________________________________________
+UInt_t AliITSRawStreamSPD::GetOfflineChipKeyFromOnline(UInt_t eqId, UInt_t hs, UInt_t chip) {
+ // online->offline (chip key: 0-1199)
+ 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; // side C only
+ return (module*5 + chipInModule);
+ } else return 1200;
+}
+//__________________________________________________________________________
+UInt_t AliITSRawStreamSPD::GetOfflineColFromOnline(UInt_t eqId, UInt_t hs, UInt_t chip, UInt_t col) {
+ // online->offline (col)
+ if (eqId>=20 || hs>=6 || chip>=10 || col>=32) return 160; // error
+ UInt_t offset = 32 * (chip % 5);
+ if (hs<2) {
+ if (eqId<10) {
+ return 159 - (31-col + offset); // inner layer, side A
+ }
+ else {
+ return col + offset; // inner layer, side C
+ }
+ }
+ else {
+ if (eqId<10) {
+ return (col + offset); // outer layer, side A
+ }
+ else {
+ return 159 - (31-col + offset); // outer layer, side C
+ }
+ }
+}
+//__________________________________________________________________________
+UInt_t AliITSRawStreamSPD::GetOfflineRowFromOnline(UInt_t eqId, UInt_t hs, UInt_t chip, UInt_t row) {
+ // online->offline (row)
+ if (eqId>=20 || hs>=6 || chip>=10 || row>=256) return 256; // error
+ return 255-row;
+}
+