From 44443c72139756133609ca40d69afe4aea3de81e Mon Sep 17 00:00:00 2001 From: cvetan Date: Wed, 1 Oct 2008 16:08:40 +0000 Subject: [PATCH 1/1] Update of the fast altro decoder (Per Thomas) --- RAW/AliAltroBunch.cxx | 5 ++- RAW/AliAltroBunch.h | 50 ++++++++++++++++++-------- RAW/AliAltroData.cxx | 58 +++++++++++++++++++++++------- RAW/AliAltroData.h | 12 +++++-- RAW/AliAltroDecoder.cxx | 80 ++++++++++++++++++++++++----------------- RAW/AliAltroDecoder.h | 11 +++--- 6 files changed, 148 insertions(+), 68 deletions(-) diff --git a/RAW/AliAltroBunch.cxx b/RAW/AliAltroBunch.cxx index a0b57d1c66f..1235e068b95 100644 --- a/RAW/AliAltroBunch.cxx +++ b/RAW/AliAltroBunch.cxx @@ -21,7 +21,10 @@ AliAltroBunch::AliAltroBunch() : fData(NULL), fBunchSize(-1), fEndTimeBin(0), - fStartTimeBin(999) + fStartTimeBin(999), + fPrewBunchSize(0), + fPrevEndTimeBin(0) +// fIsFirstBunch(true) { // Default constructor } diff --git a/RAW/AliAltroBunch.h b/RAW/AliAltroBunch.h index 008f2a44b74..5ca9c8aec6d 100644 --- a/RAW/AliAltroBunch.h +++ b/RAW/AliAltroBunch.h @@ -5,34 +5,54 @@ #include +#define DECODERERROR -3 + class AliAltroBunch: public TObject { public: AliAltroBunch(); ~ AliAltroBunch(); - - const UInt_t* GetData() const { return fData; } - void SetData(UInt_t *data) { fData = data; } - Int_t GetBunchSize() const { return fBunchSize; } - void SetBunchSize(Int_t size) { fBunchSize = size; } - UInt_t GetEndTimeBin() const { return fEndTimeBin; } - void SetEndTimeBin(UInt_t bin) { fEndTimeBin = bin; } - UInt_t GetStartTimeBin() const - { - return (fEndTimeBin - (fBunchSize -1)); - } - - void SetStartTimeBin(UInt_t bin) { fStartTimeBin = bin; } + inline const UInt_t* GetData() const { return fData; } + + inline void SetData(UInt_t *data) + { + fData = data; + } + + inline Int_t GetBunchSize() const { return fBunchSize; } + inline void SetBunchSize(Int_t size) + { + fPrewBunchSize = fBunchSize; fBunchSize = size; + } + + inline int CheckConsistency() + { + if( (fPrevEndTimeBin - fPrewBunchSize ) <= fEndTimeBin ) + { + // printf("%s:%d, ERROR conistency check failed\n", __FILE__ , __LINE__ ); + return DECODERERROR; + } + else + { + return kTRUE; + } + } + + inline UInt_t GetEndTimeBin() const { return fEndTimeBin; } + inline void SetEndTimeBin(UInt_t bin) {fPrevEndTimeBin = fEndTimeBin; fEndTimeBin = bin; } + inline UInt_t GetStartTimeBin() const { return (fEndTimeBin - (fBunchSize -1)); } + inline void SetStartTimeBin(UInt_t bin) { fStartTimeBin = bin; } private: - AliAltroBunch& operator = (const AliAltroBunch& bunch); AliAltroBunch(const AliAltroBunch& bunch); - UInt_t *fData; // pointer to data of current bunch Int_t fBunchSize; // total size of current bunch including timestamp and the size indicator (i.e a bunch with just one sample will have size 3) UInt_t fEndTimeBin; // Time stamp of the last sample in the bunch in entities of sample indexes UInt_t fStartTimeBin; // Time index of the first bin in the bunch + Int_t fPrewBunchSize; + Int_t fPrevEndTimeBin; + // bool fIsFirstBunch; ClassDef(AliAltroBunch,0) // container class for Altro bunches }; diff --git a/RAW/AliAltroData.cxx b/RAW/AliAltroData.cxx index a240c8e0d45..91580fad1cd 100644 --- a/RAW/AliAltroData.cxx +++ b/RAW/AliAltroData.cxx @@ -19,13 +19,14 @@ ClassImp(AliAltroData) AliAltroData::AliAltroData(): fData(0), - fBunchData(0), - fDataSize(0), - fWc(0), - fHadd(-1), - fPrevHadd(-1), - fBunchCounter(0), - fIsComplete(0) + fBunchData(0), + fDataSize(0), + fWc(0), + fHadd(-1), + fPrevHadd(-1), + fBunchCounter(0), + fIsComplete(0), + fBufferLeft(0) { @@ -92,12 +93,12 @@ AliAltroData::NextBunch(AliAltroBunch *altroBunch) -Bool_t AliAltroData::NextBunch(AliAltroBunch *altroBunch) + //Bool_t AliAltroData::NextBunch(AliAltroBunch *altroBunch) +int AliAltroData::NextBunch(AliAltroBunch *altroBunch) { if(fIsComplete == kTRUE) { - if(fBunchCounter == 0) { fBunchData = &fData[fDataSize - 1]; @@ -108,9 +109,43 @@ Bool_t AliAltroData::NextBunch(AliAltroBunch *altroBunch) if(*fBunchData == 0){ fWc += 1;}; fWc += *fBunchData; altroBunch->SetData(fData + fDataSize - fWc); - altroBunch->SetBunchSize(*fBunchData -2); + + int tmpsize = *fBunchData -2; + + // altroBunch->SetBunchSize( *fBunchData -2 ); + altroBunch->SetBunchSize( tmpsize ); + + + fBufferLeft -= *fBunchData; + // printf("%s:%d, bufferleft = %d \n", __FILE__, __LINE__ , fBufferLeft); fBunchData --; altroBunch->SetEndTimeBin( *fBunchData ); + + // if( (fBufferLeft <= 7 ) || ( fBufferLeft - tmpsize) <= 7) + if( fBufferLeft - tmpsize <= 7) + { + // printf("%s:%d, ERROR, attempt too access buffer outside allowed range\n", __FILE__ , __LINE__ ); + return kFALSE; + } + + + if(fBunchCounter >0) + { + int tmpret = altroBunch->CheckConsistency(); + + if(tmpret != kTRUE) + { + return tmpret; + } + + /* + if( altroBunch->CheckConsistency() == kFALSE) + { + return kFALSE; + } + */ + } + // altroBunch->SetStartTimeBin(*fBunchData - fBunchSize); fBunchData -= (altroBunch->GetBunchSize() +1); @@ -122,7 +157,6 @@ Bool_t AliAltroData::NextBunch(AliAltroBunch *altroBunch) return kFALSE; } - fBunchCounter ++; return kTRUE; } @@ -136,7 +170,7 @@ Bool_t AliAltroData::NextBunch(AliAltroBunch *altroBunch) else { // printf("\nAliAltroData::NextBunch: WARNING, dataset is not complet. 2AAA endmarker is missing "); - // printf("\nfor branch %d, card %d, chip %d, channel %d\n", GetBranch(), GetCard(), GetChip(), GetChannel()); + // printf("\nfor branch %d, card %d, chip %d, channel %d\n", GetBranch(), GetCard(), GetChip(), GetChannel()); return kFALSE; } diff --git a/RAW/AliAltroData.h b/RAW/AliAltroData.h index c8d13e94200..a7da48fea85 100644 --- a/RAW/AliAltroData.h +++ b/RAW/AliAltroData.h @@ -3,6 +3,8 @@ /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * * See cxx source for full Copyright notice */ +#define DECODERERROR -3 + #include class AliAltroBunch; @@ -12,7 +14,9 @@ public: AliAltroData(); ~ AliAltroData(); - Bool_t NextBunch(AliAltroBunch *altrobunch); + + // Bool_t NextBunch(AliAltroBunch *altrobunch); + int NextBunch(AliAltroBunch *altrobunch); Int_t GetChannel() const; Int_t GetChip() const; @@ -25,7 +29,9 @@ public: Int_t GetHadd() const { return fHadd; } Int_t GetPrevHadd() const { return fPrevHadd; } Bool_t IsNewHadd() const { return (fHadd != fPrevHadd); } - void SetHadd(Int_t add) { fPrevHadd = fHadd; fHadd = add; } + // void SetHadd(Int_t add) { fPrevHadd = fHadd; fHadd = add; } + void SetHadd(Int_t add, Int_t bufferleft) { fPrevHadd = fHadd; fHadd = add; fBufferLeft = bufferleft ; } + const UInt_t* GetData() const { return fData; } void SetData(UInt_t *data) { fData = data; } // UInt_t* GetData() const { return fData; } @@ -46,6 +52,8 @@ private: Int_t fBunchCounter; Bool_t fIsComplete; + // Int_t fMaxBunchSize; + Int_t fBufferLeft; ClassDef(AliAltroData, 0) // container class for Altro payload diff --git a/RAW/AliAltroDecoder.cxx b/RAW/AliAltroDecoder.cxx index cc757e1baf4..9a52267f9a8 100644 --- a/RAW/AliAltroDecoder.cxx +++ b/RAW/AliAltroDecoder.cxx @@ -61,7 +61,8 @@ AliAltroDecoder::AliAltroDecoder() : f32DtaPtr(0), fInComplete(0), fDecodeIfCorruptedTrailer(kTRUE), fIsDecoded(kFALSE), - fIsFatalCorruptedTrailer(kTRUE) + fIsFatalCorruptedTrailer(kTRUE) + // fIsFirstChannelOfPayload(kTRUE) { // Default constructor } @@ -91,11 +92,6 @@ Bool_t AliAltroDecoder::CheckPayloadTrailer() const Bool_t AliAltroDecoder::Decode() { - // Decodes the RCU payload (all altro channels in one go) from the DDL/Altro - // format to PC readable format. - // The 10 bit words of the 40/10 bit Altro format are transformed to separated - // integers. - if( fIsFatalCorruptedTrailer == kTRUE) { // printf("\n AliAltroDecoder::Decode(), WARNING, attempt to decode badly corrupted data\n"); @@ -131,7 +127,6 @@ Bool_t AliAltroDecoder::Decode() if( ((CheckPayloadTrailer() == kTRUE) || fDecodeIfCorruptedTrailer == kTRUE ) && (fSize > 32) ) { - // fDDLBlockCnt = 0; fOutBufferIndex = 0; for(Int_t i = 0; i < fNDDLBlocks; i++) @@ -141,9 +136,6 @@ Bool_t AliAltroDecoder::Decode() DecodeLastDDLBlock(); fOutBufferIndex = fN40AltroWords*4 - 1; - - // DumpData(fOutBuffer, 400,4); - fIsDecoded = kTRUE; return kTRUE; } @@ -161,17 +153,12 @@ Bool_t AliAltroDecoder::Decode() } + + Bool_t AliAltroDecoder::NextChannel(AliAltroData *altroDataPtr) { - // Reads the next altro channel in the RCU payload after the RCU payload - // has been decoded. The channels are read starting from the end (backlinked list) - // Returns kTRUE as long as ther are unread channels in the payload - // Returns kFALSE when all the channels have been read. - if(fIsFatalCorruptedTrailer == kTRUE) { - // printf("\n AliAltroDecoder::NextChannel(), WARNING, attempt to decode badly corrupted data\n"); - // printf("\n AliAltroDecoder::NextChannel(), Please check on the return value (-1 if fataly corrupted) of the SetMemory() function\n"); return kFALSE; } @@ -180,14 +167,9 @@ Bool_t AliAltroDecoder::NextChannel(AliAltroData *altroDataPtr) if(fIsDecoded != kTRUE) { - // cout <<"AliAltroDecoder::NextChanne, WARNING, buffer was not decoded, decoding now.. "<< endl; Decode(); } - // an altro block must constist of at least 2 40bit words: - // - 40bit Altro trailer - // - at least 3 10bit words (bunch length, time bin, signal) padded to 40 bit - // we are reading backwards, so the index is already 1 inside the block if(fOutBufferIndex >= 7) { if((fOutBuffer[fOutBufferIndex] << 4 ) | ((fOutBuffer[fOutBufferIndex-1] & 0x3c0) >> 6) == 0x2aaa) @@ -204,7 +186,7 @@ Bool_t AliAltroDecoder::NextChannel(AliAltroData *altroDataPtr) fOutBufferIndex --; fNAltro10bitWords = ( (fOutBuffer[fOutBufferIndex] & 0x3f) << 4 ) | ((fOutBuffer[fOutBufferIndex -1] & (0xF << 6)) >> 6) ; fOutBufferIndex --; - altroDataPtr->SetHadd( ((fOutBuffer[fOutBufferIndex] & 0x3)) << 10 | ( fOutBuffer[fOutBufferIndex-1] ) ); + altroDataPtr->SetHadd( ((fOutBuffer[fOutBufferIndex] & 0x3)) << 10 | ( fOutBuffer[fOutBufferIndex-1] ), fOutBufferIndex); fOutBufferIndex --; @@ -216,13 +198,9 @@ Bool_t AliAltroDecoder::NextChannel(AliAltroData *altroDataPtr) { fOutBufferIndex = fOutBufferIndex - fNAltro10bitWords -(4 - fNAltro10bitWords%4); } - if(fOutBufferIndex >= 0) { - - //cout << " AliAltroDecoder::NextChannel fOutBufferIndex =" << fOutBufferIndex << endl; - // printf( "AliAltroDecoder::NextChannel fOutBufferIndex = %d", fOutBufferIndex); altroDataPtr->SetData( &fOutBuffer[fOutBufferIndex] ); if(fOutBufferIndex > 0) fOutBufferIndex --; altroDataPtr->SetDataSize( fNAltro10bitWords ); @@ -234,7 +212,6 @@ Bool_t AliAltroDecoder::NextChannel(AliAltroData *altroDataPtr) return kFALSE; } - } else { @@ -288,6 +265,7 @@ Float_t AliAltroDecoder::GetFailureRate() } + void AliAltroDecoder::PrintInfo(AliAltroData &altrodata, Int_t n, Int_t nPerLine) { // prints data and address information contained in altrodata @@ -313,17 +291,19 @@ int AliAltroDecoder::SetMemory(UChar_t *dtaPtr, UInt_t size) // Sets the pointer to the memory block that should be decoded // Returns a negative value if an inconsistency in the data is detected + // fIsFirstChannelOfPayload = kTRUE; + if(dtaPtr == 0) { - printf("\nAliAltroDecoder::SetMemory(UChar_t *dtaPtr, UInt_t size) FATAL ERROR, dtaPtr = ZERO !!!!!!!!!!!!\n"); - printf("Please check your code that you don't give a zero pointer to the decoder \n"); + // printf("\nAliAltroDecoder::SetMemory(UChar_t *dtaPtr, UInt_t size) FATAL ERROR, dtaPtr = ZERO !!!!!!!!!!!!\n"); + // printf("Please check your code that you don't give a zero pointer to the decoder \n"); return -99; } if (size #include @@ -86,10 +88,6 @@ class AliAltroDecoder: public TObject { * @return kTRUE if trailer available; */ Bool_t GetRCUTrailerData(UChar_t*& data) const; - - /** - * Provide size of RCU trailer. - */ Int_t GetRCUTrailerSize() const; private: @@ -117,7 +115,10 @@ class AliAltroDecoder: public TObject { Int_t fInComplete; // Number of altro channels that is read out properly Bool_t fDecodeIfCorruptedTrailer; // Wether or not to try to decode the data if the RCU trailer is incorrect (will succseed in most cases) Bool_t fIsDecoded; // Wether or not the buffer set last by the "SetMemory()" function has been decoded - Bool_t fIsFatalCorruptedTrailer; // If trailer is fataly corrupted, not possible in any way to recover, then it is not allowed to decode the DDL payload. + Bool_t fIsFatalCorruptedTrailer; // If trailer is fataly corrupted, not possible in any way to recover, then it is not allowed to decode the DDL payload. + + // Bool_t fIsFirstChannelOfPayload; + ClassDef(AliAltroDecoder, 0) // class for decoding Altro payload }; -- 2.39.3