From 5bbd01a6fb5a962035ffd6e616270bd0523d5231 Mon Sep 17 00:00:00 2001 From: cvetan Date: Tue, 18 Apr 2006 14:39:41 +0000 Subject: [PATCH] Classes for reading of the old RCU TPC raw data --- RAW/AliAltroRawStreamOld.cxx | 292 +++++++++++++++++++++++++++++++++++ RAW/AliAltroRawStreamOld.h | 80 ++++++++++ RAW/RAWLinkDef.h | 1 + RAW/libRAWData.pkg | 1 + TPC/AliTPCRawStreamOld.cxx | 144 +++++++++++++++++ TPC/AliTPCRawStreamOld.h | 53 +++++++ TPC/TPCbaseLinkDef.h | 1 + TPC/libTPCbase.pkg | 2 +- 8 files changed, 573 insertions(+), 1 deletion(-) create mode 100644 RAW/AliAltroRawStreamOld.cxx create mode 100644 RAW/AliAltroRawStreamOld.h create mode 100644 TPC/AliTPCRawStreamOld.cxx create mode 100644 TPC/AliTPCRawStreamOld.h diff --git a/RAW/AliAltroRawStreamOld.cxx b/RAW/AliAltroRawStreamOld.cxx new file mode 100644 index 00000000000..6bd9721726b --- /dev/null +++ b/RAW/AliAltroRawStreamOld.cxx @@ -0,0 +1,292 @@ +/************************************************************************** + * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * * + * Author: The ALICE Off-line Project. * + * Contributors are mentioned in the code where appropriate. * + * * + * Permission to use, copy, modify and distribute this software and its * + * documentation strictly for non-commercial purposes is hereby granted * + * without fee, provided that the above copyright notice appears in all * + * copies and that both the copyright notice and this permission notice * + * appear in the supporting documentation. The authors make no claims * + * about the suitability of this software for any purpose. It is * + * provided "as is" without express or implied warranty. * + **************************************************************************/ + +/////////////////////////////////////////////////////////////////////////////// +/// +/// This class provides access to Altro digits in raw data. +/// +/// It loops over all Altro digits in the raw data given by the AliRawReader. +/// The Next method goes to the next digit. If there are no digits left +/// it returns kFALSE. +/// Several getters provide information about the current digit. +/// +/////////////////////////////////////////////////////////////////////////////// + +#include "AliAltroRawStreamOld.h" +#include "AliRawReader.h" +#include "AliLog.h" + +ClassImp(AliAltroRawStreamOld) + + +//_____________________________________________________________________________ +AliAltroRawStreamOld::AliAltroRawStreamOld(AliRawReader* rawReader) : + fNoAltroMapping(kTRUE), + fDDLNumber(-1), + fPrevDDLNumber(-1), + fHWAddress(-1), + fPrevHWAddress(-1), + fTime(-1), + fPrevTime(-1), + fSignal(-1), + fTimeBunch(-1), + fRawReader(rawReader), + fData(NULL), + fPosition(0), + fCount(0), + fBunchLength(0) +{ +// create an object to read Altro raw digits + fSegmentation[0] = fSegmentation[1] = fSegmentation[2] = -1; +} + +//_____________________________________________________________________________ +AliAltroRawStreamOld::AliAltroRawStreamOld(const AliAltroRawStreamOld& stream) : + TObject(stream), + fNoAltroMapping(kTRUE), + fDDLNumber(-1), + fPrevDDLNumber(-1), + fHWAddress(-1), + fPrevHWAddress(-1), + fTime(-1), + fPrevTime(-1), + fSignal(-1), + fTimeBunch(-1), + fRawReader(NULL), + fData(NULL), + fPosition(0), + fCount(0), + fBunchLength(0) +{ + Fatal("AliAltroRawStreamOld", "copy constructor not implemented"); +} + +//_____________________________________________________________________________ +AliAltroRawStreamOld& AliAltroRawStreamOld::operator = (const AliAltroRawStreamOld& + /* stream */) +{ + Fatal("operator =", "assignment operator not implemented"); + return *this; +} + +//_____________________________________________________________________________ +AliAltroRawStreamOld::~AliAltroRawStreamOld() +{ +// clean up + +} + +//_____________________________________________________________________________ +void AliAltroRawStreamOld::Reset() +{ +// reset altro raw stream params + + fPosition = fCount = fBunchLength = 0; + + fDDLNumber = fPrevDDLNumber = fHWAddress = fPrevHWAddress = fTime = fPrevTime = fSignal = fTimeBunch = -1; + + if (fRawReader) fRawReader->Reset(); + + fSegmentation[0] = fSegmentation[1] = fSegmentation[2] = -1; +} + +//_____________________________________________________________________________ +Bool_t AliAltroRawStreamOld::Next() +{ +// read the next raw digit +// returns kFALSE if there is no digit left + + fPrevDDLNumber = fDDLNumber; + fPrevHWAddress = fHWAddress; + fPrevTime = fTime; + + while (fCount == 0) { // next trailer + if (fPosition <= 0) { // next payload + do { + if (!fRawReader->ReadNextData(fData)) return kFALSE; + } while (fRawReader->GetDataSize() == 0); + + fDDLNumber = fRawReader->GetDDLID(); + + fPosition = GetPosition(); + } + + if (!ReadTrailer()) + AliFatal("Incorrect trailer information !"); + + fBunchLength = 0; + } + + if (fBunchLength == 0) ReadBunch(); + else fTime--; + + ReadAmplitude(); + + return kTRUE; +} + +//_____________________________________________________________________________ +void AliAltroRawStreamOld::SelectRawData(Int_t detId) +{ + // Select the raw data for specific + // detector id + AliDebug(1,Form("Selecting raw data for detector %d",detId)); + fRawReader->Select(detId); +} + +//_____________________________________________________________________________ +UShort_t AliAltroRawStreamOld::GetNextWord() +{ + // Read the next 10 bit word in backward direction + // The input stream access is given by fData and fPosition + + fPosition--; + + Int_t iBit = fPosition * 10; + Int_t iByte = iBit / 8; + Int_t shift = iBit % 8; + + // the raw data is written as integers where the low bits are filled first + // -> little endian is assumed here ! + Int_t iByteLow = iByte; + iByte++; + Int_t iByteHigh = iByte; + return ((fData[iByteHigh] * 256 + fData[iByteLow]) >> shift) & 0x03FF; +} + +//_____________________________________________________________________________ +Bool_t AliAltroRawStreamOld::ReadTrailer() +{ + //Read a trailer of 40 bits in the backward reading mode + //In case of no mapping is provided, read a dummy trailer + if (fNoAltroMapping) { + AliError("No ALTRO mapping information is loaded! Reading a dummy trailer!"); + return ReadDummyTrailer(); + } + + //First reading filling words + UShort_t temp; + Int_t nFillWords = 0; + while ((temp = GetNextWord()) == 0x2AA) nFillWords++; + if (nFillWords == 0) + AliFatal("Incorrect trailer found ! Expected 0x2AA not found !"); + + //Then read the trailer + if (fPosition <= 4) + AliFatal(Form("Incorrect raw data size ! Expected at lest 4 words but found %d !",fPosition)); + + fCount = (temp << 4) & 0x3FF; + if ((temp >> 6) != 0xA) + AliFatal(Form("Incorrect trailer found ! Expecting 0xA but found %x !",temp >> 6)); + + temp = GetNextWord(); + fHWAddress = (temp & 0x3) << 10; + if (((temp >> 2) & 0xF) != 0xA) + AliFatal(Form("Incorrect trailer found ! Expecting second 0xA but found %x !",(temp >> 2) & 0xF)); + fCount |= ((temp & 0x3FF) >> 6); + if (fCount == 0) return kFALSE; + + temp = GetNextWord(); + fHWAddress |= temp; + + fPosition -= (4 - (fCount % 4)) % 4; // skip fill words + + return kTRUE; +} + +//_____________________________________________________________________________ +Bool_t AliAltroRawStreamOld::ReadDummyTrailer() +{ + //Read a trailer of 40 bits in the backward reading mode + //In case of no mapping is provided, read a dummy trailer + UShort_t temp; + while ((temp = GetNextWord()) == 0x2AA); + + fSegmentation[0] = temp; + fSegmentation[1] = GetNextWord(); + fSegmentation[2] = GetNextWord(); + fCount = GetNextWord(); + if (fCount == 0) return kFALSE; + fHWAddress = -1; + + fPosition -= (4 - (fCount % 4)) % 4; // skip fill words + + return kTRUE; +} + +//_____________________________________________________________________________ +void AliAltroRawStreamOld::ReadBunch() +{ + // Read altro payload in + // backward direction + if (fPosition <= 0) + AliFatal("Could not read bunch length !"); + + fBunchLength = GetNextWord() - 2; + fTimeBunch = fBunchLength; + fCount--; + + if (fPosition <= 0) + AliFatal("Could not read time bin !"); + + fTime = GetNextWord(); + fCount--; + + return; +} + +//_____________________________________________________________________________ +void AliAltroRawStreamOld::ReadAmplitude() +{ + // Read next time bin amplitude + if (fPosition <= 0) + AliFatal("Could not read sample amplitude !"); + + fSignal = GetNextWord(); + fCount--; + fBunchLength--; + + return; +} + +//_____________________________________________________________________________ +Int_t AliAltroRawStreamOld::GetPosition() +{ + // Sets the position in the + // input stream + + // Get the payload size from the RCU trailer + // The trailer is actually one 32-bit word + Int_t position = (fData[fRawReader->GetDataSize()-1]) << 24; + position |= (fData[fRawReader->GetDataSize()-2]) << 16; + position |= (fData[fRawReader->GetDataSize()-3]) << 8; + position |= (fData[fRawReader->GetDataSize()-4]); + // The size is specified in a number of 40bits + // Therefore we need to transform it to number of bytes + position *= 5; + + // Check the consistency of the header and trailer + if ((fRawReader->GetDataSize() - 32) != position) + AliFatal(Form("Inconsistent raw data size ! Expected %d bytes (from the header), found %d words (in the RCU trailer)!", + fRawReader->GetDataSize()-32, + position)); + + // Skip the Common Data Header which contains + // only 7 (!) words + fData += 28; + + // Return the position in units of 10-bit words + return position*8/10; +} diff --git a/RAW/AliAltroRawStreamOld.h b/RAW/AliAltroRawStreamOld.h new file mode 100644 index 00000000000..0b7b4ca41b6 --- /dev/null +++ b/RAW/AliAltroRawStreamOld.h @@ -0,0 +1,80 @@ +#ifndef ALIALTRORAWSTREAMOLD_H +#define ALIALTRORAWSTREAMOLD_H +/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * See cxx source for full Copyright notice */ + +/////////////////////////////////////////////////////////////////////////////// +/// +/// This is a class for reading raw data digits in Altro format +/// OLD RCU version +/// The RCU trailer is just one 32-bit word +/// The Common Data Header is 7 32-bit words and is skipped during +/// the raw data reading. +/// The raw data payload is little endian. +/// +/////////////////////////////////////////////////////////////////////////////// + +#include + +class AliRawReader; + +class AliAltroRawStreamOld: public TObject { + public : + AliAltroRawStreamOld(AliRawReader* rawReader); + virtual ~AliAltroRawStreamOld(); + + virtual void Reset(); + virtual Bool_t Next(); + + inline Int_t GetDDLNumber() const { return fDDLNumber; } // Provide current DDL number + inline Int_t GetPrevDDLNumber() const { return fPrevDDLNumber; }// Provide previous DDL number + inline Bool_t IsNewDDLNumber() const {return (fDDLNumber != fPrevDDLNumber);}; + inline Int_t GetHWAddress() const { return fHWAddress; } // Provide current hardware address + inline Int_t GetPrevHWAddress() const { return fPrevHWAddress; } // Provide previous hardware address + inline Bool_t IsNewHWAddress() const {return (fHWAddress != fPrevHWAddress) || IsNewDDLNumber();}; + inline Int_t GetTime() const { return fTime; } // Provide index of current time bin + inline Int_t GetPrevTime() const { return fPrevTime; } // Provide index of previous time bin + inline Bool_t IsNewTime() const {return (fTime != fPrevTime) || IsNewHWAddress();}; + inline Int_t GetSignal() const { return fSignal; } // Provide signal in ADC counts + inline Int_t GetTimeLength() const { return fTimeBunch; } // Provide total length of current time bunch + + void SelectRawData(Int_t detId); // Select raw data for specific detector id + + protected: + AliAltroRawStreamOld(const AliAltroRawStreamOld& stream); + AliAltroRawStreamOld& operator = (const AliAltroRawStreamOld& stream); + + Bool_t fNoAltroMapping; // temporary flag in case of no altro mapping is provided + Short_t fSegmentation[3]; // temporary container for the dummy trailer, to be removed + + private : + + UShort_t GetNextWord(); + Bool_t ReadTrailer(); + Bool_t ReadDummyTrailer(); + void ReadBunch(); + void ReadAmplitude(); + Int_t GetPosition(); + + Int_t fDDLNumber; // index of current DDL number + Int_t fPrevDDLNumber;// index of current DDL number + Short_t fHWAddress; // current hardware address + Short_t fPrevHWAddress;// previous hardware address + Int_t fTime; // index of current time bin + Int_t fPrevTime; // index of previous time bin + Int_t fSignal; // signal in ADC counts + Int_t fTimeBunch; // total length of the current time bunch + + AliRawReader* fRawReader; // object for reading the raw data + + + UChar_t* fData; // raw data + + Int_t fPosition; // current (10 bit) position in fData + Int_t fCount; // counter of words to be read for current trailer + Int_t fBunchLength; // remaining number of signal bins in the current bunch + + ClassDef(AliAltroRawStreamOld, 0) // base class for reading Altro raw digits +}; + +#endif diff --git a/RAW/RAWLinkDef.h b/RAW/RAWLinkDef.h index b1074526e69..cdc861a83b9 100644 --- a/RAW/RAWLinkDef.h +++ b/RAW/RAWLinkDef.h @@ -22,6 +22,7 @@ #pragma link C++ class AliAltroBuffer+; #pragma link C++ class AliAltroMapping+; #pragma link C++ class AliAltroRawStream+; +#pragma link C++ class AliAltroRawStreamOld+; #pragma link C++ class AliVMERawStream+; #endif diff --git a/RAW/libRAWData.pkg b/RAW/libRAWData.pkg index 11ecffd9d75..ea914e4a561 100644 --- a/RAW/libRAWData.pkg +++ b/RAW/libRAWData.pkg @@ -15,6 +15,7 @@ SRCS:= AliRawEventHeaderBase.cxx AliRawEquipmentHeader.cxx \ AliRawReaderMemory.cxx \ AliBitPacking.cxx AliAltroBuffer.cxx AliAltroMapping.cxx \ AliAltroRawStream.cxx \ + AliAltroRawStreamOld.cxx \ AliVMERawStream.cxx HDRS:= $(SRCS:.cxx=.h) diff --git a/TPC/AliTPCRawStreamOld.cxx b/TPC/AliTPCRawStreamOld.cxx new file mode 100644 index 00000000000..a82276d4010 --- /dev/null +++ b/TPC/AliTPCRawStreamOld.cxx @@ -0,0 +1,144 @@ +/************************************************************************** + * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * * + * Author: The ALICE Off-line Project. * + * Contributors are mentioned in the code where appropriate. * + * * + * Permission to use, copy, modify and distribute this software and its * + * documentation strictly for non-commercial purposes is hereby granted * + * without fee, provided that the above copyright notice appears in all * + * copies and that both the copyright notice and this permission notice * + * appear in the supporting documentation. The authors make no claims * + * about the suitability of this software for any purpose. It is * + * provided "as is" without express or implied warranty. * + **************************************************************************/ + +/////////////////////////////////////////////////////////////////////////////// +/// +/// This class provides access to TPC digits in raw data. +/// +/// It loops over all TPC digits in the raw data given by the AliRawReader. +/// The Next method goes to the next digit. If there are no digits left +/// it returns kFALSE. +/// Several getters provide information about the current digit. +/// +/////////////////////////////////////////////////////////////////////////////// + +#include + +#include "AliTPCRawStreamOld.h" +#include "AliRawReader.h" +#include "AliLog.h" +#include "AliTPCAltroMapping.h" + +ClassImp(AliTPCRawStreamOld) + +//_____________________________________________________________________________ +AliTPCRawStreamOld::AliTPCRawStreamOld(AliRawReader* rawReader) : + AliAltroRawStreamOld(rawReader), + fSector(-1), + fPrevSector(-1), + fRow(-1), + fPrevRow(-1), + fPad(-1), + fPrevPad(-1) +{ + // create an object to read TPC raw digits + + // Do not select on the equipment Id, since the Id + // is wrong (it starts from 228 or so...) + // SelectRawData(0); + // Skip the Common Data Header, since it is only 7 + // 32-bit words + rawReader->RequireHeader(kFALSE); + + TString path = gSystem->Getenv("ALICE_ROOT"); + path += "/TPC/mapping/Patch"; + TString path2; + for(Int_t i = 0; i < 6; i++) { + path2 = path; + path2 += i; + path2 += ".data"; + fMapping[i] = new AliTPCAltroMapping(path2.Data()); + } + + fNoAltroMapping = kFALSE; +} + +//_____________________________________________________________________________ +AliTPCRawStreamOld::AliTPCRawStreamOld(const AliTPCRawStreamOld& stream) : + AliAltroRawStreamOld(stream), + fSector(-1), + fPrevSector(-1), + fRow(-1), + fPrevRow(-1), + fPad(-1), + fPrevPad(-1) +{ + Fatal("AliTPCRawStreamOld", "copy constructor not implemented"); +} + +//_____________________________________________________________________________ +AliTPCRawStreamOld& AliTPCRawStreamOld::operator = (const AliTPCRawStreamOld& + /* stream */) +{ + Fatal("operator =", "assignment operator not implemented"); + return *this; +} + +//_____________________________________________________________________________ +AliTPCRawStreamOld::~AliTPCRawStreamOld() +{ +// destructor + + for(Int_t i = 0; i < 6; i++) delete fMapping[i]; +} + +//_____________________________________________________________________________ +void AliTPCRawStreamOld::Reset() +{ + // reset tpc raw stream params + AliAltroRawStreamOld::Reset(); + fSector = fPrevSector = fRow = fPrevRow = fPad = fPrevPad = -1; +} + +//_____________________________________________________________________________ +Bool_t AliTPCRawStreamOld::Next() +{ + // Read next TPC signal + // Apply the TPC altro mapping to get + // the sector,pad-row and pad indeces + fPrevSector = fSector; + fPrevRow = fRow; + fPrevPad = fPad; + if (AliAltroRawStreamOld::Next()) { + if (IsNewHWAddress()) + ApplyAltroMapping(); + return kTRUE; + } + else + return kFALSE; +} + +//_____________________________________________________________________________ +void AliTPCRawStreamOld::ApplyAltroMapping() +{ + // Take the DDL index, load + // the corresponding altro mapping + // object and fill the sector,row and pad indeces + Int_t ddlNumber = GetDDLNumber()-228; + Int_t patchIndex; + if (ddlNumber < 72) { + fSector = ddlNumber / 2; + patchIndex = ddlNumber % 2; + } + else { + fSector = (ddlNumber - 72) / 4 + 36; + patchIndex = (ddlNumber - 72) % 4 + 2; + } + + Short_t hwAddress = GetHWAddress(); + fRow = fMapping[patchIndex]->GetPadRow(hwAddress); + fPad = fMapping[patchIndex]->GetPad(hwAddress); + +} diff --git a/TPC/AliTPCRawStreamOld.h b/TPC/AliTPCRawStreamOld.h new file mode 100644 index 00000000000..d71e054eec5 --- /dev/null +++ b/TPC/AliTPCRawStreamOld.h @@ -0,0 +1,53 @@ +#ifndef ALITPCRAWSTREAMOLD_H +#define ALITPCRAWSTREAMOLD_H +/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * See cxx source for full Copyright notice */ + +/////////////////////////////////////////////////////////////////////////////// +/// +/// This class provides access to TPC digits in raw data. +/// +/////////////////////////////////////////////////////////////////////////////// + +#include "AliAltroRawStreamOld.h" + +class AliRawReader; +class AliAltroMapping; + +class AliTPCRawStreamOld: public AliAltroRawStreamOld { + public : + AliTPCRawStreamOld(AliRawReader* rawReader); + virtual ~AliTPCRawStreamOld(); + + virtual void Reset(); + virtual Bool_t Next(); + + inline Int_t GetSector() const { return fSector; } // Provide index of current sector + inline Int_t GetPrevSector() const { return fPrevSector; } // Provide index of previous sector + inline Bool_t IsNewSector() const {return fSector != fPrevSector;}; + inline Int_t GetRow() const { return fRow; } // Provide index of current row + inline Int_t GetPrevRow() const { return fPrevRow; } // Provide index of previous row + inline Bool_t IsNewRow() const {return (fRow != fPrevRow) || IsNewSector();}; + inline Int_t GetPad() const { return fPad; } // Provide index of current pad + inline Int_t GetPrevPad() const { return fPrevPad; } // Provide index of previous pad + inline Bool_t IsNewPad() const {return (fPad != fPrevPad) || IsNewRow();}; + + protected : + AliTPCRawStreamOld(const AliTPCRawStreamOld& stream); + AliTPCRawStreamOld& operator = (const AliTPCRawStreamOld& stream); + + virtual void ApplyAltroMapping(); + + Int_t fSector; // index of current sector + Int_t fPrevSector; // index of previous sector + Int_t fRow; // index of current row + Int_t fPrevRow; // index of previous row + Int_t fPad; // index of current pad + Int_t fPrevPad; // index of previous pad + + AliAltroMapping *fMapping[6]; // Pointers to ALTRO mapping + + ClassDef(AliTPCRawStreamOld, 0) // base class for reading TPC raw digits +}; + +#endif diff --git a/TPC/TPCbaseLinkDef.h b/TPC/TPCbaseLinkDef.h index a9d4fdd647c..525feb68555 100644 --- a/TPC/TPCbaseLinkDef.h +++ b/TPC/TPCbaseLinkDef.h @@ -37,6 +37,7 @@ #pragma link C++ class AliTPCAltroMapping+; #pragma link C++ class AliTPCRawStream+; +#pragma link C++ class AliTPCRawStreamOld+; #endif diff --git a/TPC/libTPCbase.pkg b/TPC/libTPCbase.pkg index 4fa1be1aff8..f2db82ca448 100644 --- a/TPC/libTPCbase.pkg +++ b/TPC/libTPCbase.pkg @@ -6,7 +6,7 @@ SRCS:= AliSegmentID.cxx AliSegmentArray.cxx AliDigits.cxx AliH2F.cxx \ AliSimDigits.cxx AliDigitsArray.cxx AliTPCDigitsArray.cxx \ AliTPCROC.cxx AliTPCCalROC.cxx AliTPCCalPad.cxx AliTPCCalDet.cxx \ AliTPCcalibDB.cxx \ - AliTPCAltroMapping.cxx AliTPCRawStream.cxx + AliTPCAltroMapping.cxx AliTPCRawStream.cxx AliTPCRawStreamOld.cxx -- 2.39.3