--- /dev/null
+/**************************************************************************
+ * 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. *
+ **************************************************************************/
+
+/* $Id$ */
+
+// Interface to the Altro format
+// to read and write digits
+// To be used in Alice Data Challenges
+// and in the compression of the RAW data
+// Author: D.Favretto
+
+#include "AliAltroBuffer.h"
+#include "AliRawDataHeader.h"
+#include <Riostream.h>
+#include <stdlib.h>
+
+
+ClassImp(AliAltroBuffer)
+
+
+//_____________________________________________________________________________
+AliAltroBuffer::AliAltroBuffer(const char* fileName, Int_t flag):
+ fShift(0),
+ fCurrentCell(0),
+ fFreeCellBuffer(0),
+ fFlag(flag),
+ fVerbose(0),
+ fFile(NULL),
+ fMaskBackward(0xFF),
+ fFilePosition(0),
+ fFileEnd(0),
+ fDataHeaderPos(0),
+ fEndingFillWords(0)
+{
+//if flag = 1 the actual object is used in the write mode
+//if flag = 0 the actual object is used in the read mode
+
+ //the buffer is cleaned
+ for (Int_t i = 0; i < 5; i++) fBuffer[i] = 0;
+
+ if (flag) {
+ fFreeCellBuffer = 16;
+ fShift = 32;
+ //open the output file
+#ifndef __DECCXX
+ fFile = new fstream(fileName, ios::binary|ios::out);
+#else
+ fFile = new fstream(fileName, ios::out);
+#endif
+ } else {
+ //open the input file
+#ifndef __DECCXX
+ fFile = new fstream(fileName, ios::binary|ios::in);
+#else
+ fFile = new fstream(fileName, ios::in);
+#endif
+ if (!fFile) {
+ Error("AliAltroBuffer", "File doesn't exist: %s", fileName);
+ return;
+ }
+ fShift = 0;
+ //To get the file dimension (position of the last element in term of bytes)
+ fFile->seekg(0, ios::end);
+ fFilePosition = fFile->tellg();
+ fFileEnd = fFilePosition;
+ fFile->seekg(0);
+ }
+}
+
+//_____________________________________________________________________________
+AliAltroBuffer::~AliAltroBuffer()
+{
+// destructor
+
+ if (fFlag) {
+ //Flush out the Buffer content at the end only if Buffer wasn't completely filled
+ Flush();
+ if (fVerbose) Info("~AliAltroBuffer", "File Created");
+ }//end if
+ fFile->close();
+ delete fFile;
+}
+
+//_____________________________________________________________________________
+AliAltroBuffer::AliAltroBuffer(const AliAltroBuffer& source):
+ TObject(source),
+ fShift(source.fShift),
+ fCurrentCell(source.fCurrentCell),
+ fFreeCellBuffer(source.fFreeCellBuffer),
+ fFlag(source.fFlag),
+ fVerbose(source.fVerbose),
+ fFile(NULL),
+ fMaskBackward(source.fMaskBackward),
+ fFilePosition(source.fFilePosition),
+ fFileEnd(source.fFileEnd),
+ fDataHeaderPos(source.fDataHeaderPos),
+ fEndingFillWords(source.fEndingFillWords)
+{
+// Copy Constructor
+
+ Fatal("AliAltroBuffer", "copy constructor not implemented");
+}
+
+//_____________________________________________________________________________
+AliAltroBuffer& AliAltroBuffer::operator = (const AliAltroBuffer& /*source*/)
+{
+//Assigment operator
+
+ Fatal("operator =", "assignment operator not implemented");
+ return *this;
+}
+
+
+//_____________________________________________________________________________
+Int_t AliAltroBuffer::GetNext()
+{
+//It reads a 10 bits word in forward dicection from the Buffer.
+//A new Buffer is read from the file only when Buffer is empty.
+//If there aren't elements anymore -1 is returned otherwise
+//the next element is returned
+
+ UInt_t mask = 0xFFC00000;
+ UInt_t temp;
+ UInt_t value;
+ if (!fShift) {
+ if (fFile->tellg() >= (Int_t)fFileEnd) return -1;
+ if (fFile->read((char*)fBuffer, sizeof(UInt_t)*5)) {
+ fCurrentCell = 0;
+ fShift = 22;
+ value = fBuffer[fCurrentCell] & mask;
+ value = value >> 22;
+ fBuffer[fCurrentCell] = fBuffer[fCurrentCell] << 10;
+ return value;
+ } else {
+ return -1;
+ }
+ } else {
+ if (fShift >= 10) {
+ value = fBuffer[fCurrentCell] & mask;
+ value = value >> 22;
+ fShift -= 10;
+ fBuffer[fCurrentCell] = fBuffer[fCurrentCell] << 10;
+ } else {
+ value = fBuffer[fCurrentCell] & mask;
+ fCurrentCell++;
+ temp = fBuffer[fCurrentCell];
+ temp = temp >> fShift;
+ temp = temp & mask;
+ value = value | temp;
+ value = value >> 22;
+ fBuffer[fCurrentCell] = fBuffer[fCurrentCell] << (10-fShift);
+ fShift += 22;
+ }
+ return value;
+ }//end else
+}
+
+//_____________________________________________________________________________
+Int_t AliAltroBuffer::GetNextBackWord()
+{
+//It reads a 10 bits word in backward dicection from the Buffer.
+//A new Buffer is read from the file only when Buffer is empty.
+//If there aren't elements anymore -1 is returned otherwise
+//the next element is returned
+
+ UInt_t mask = 0x3FF;
+ UInt_t temp;
+ UInt_t value;
+ if (!fShift) {
+ if (fFilePosition > fDataHeaderPos){
+ fFilePosition -= sizeof(UInt_t)*5;
+ fFile->seekg(fFilePosition);
+ fFile->read((char*)fBuffer, sizeof(UInt_t)*5);
+
+ fCurrentCell = 4;
+ fShift = 22;
+ fMaskBackward = 0xFF;
+ value = fBuffer[fCurrentCell] & mask;
+ fBuffer[fCurrentCell] = fBuffer[fCurrentCell] >> 10;
+ return value;
+ } else {
+ fFile->seekg(fDataHeaderPos);
+ return -1;
+ }
+ } else {
+ if (fShift >= 10) {
+ value = fBuffer[fCurrentCell] & mask;
+ fShift -= 10;
+ fBuffer[fCurrentCell] = fBuffer[fCurrentCell] >> 10;
+ } else {
+ value = fBuffer[fCurrentCell];
+ fCurrentCell--;
+ temp = fBuffer[fCurrentCell] & mask;
+ temp = temp & fMaskBackward;
+ fMaskBackward = fMaskBackward >> 2;
+ temp = temp << fShift;
+ value = value | temp;
+ fBuffer[fCurrentCell] = fBuffer[fCurrentCell] >> (10-fShift);
+ fShift = 22 + fShift;
+ }
+ return value;
+ }//end else
+}
+
+//_____________________________________________________________________________
+void AliAltroBuffer::Flush()
+{
+// Flushes the Buffer content
+ if (fFreeCellBuffer != 16) {
+ Int_t temp = fFreeCellBuffer;
+ for (Int_t i = 0; i < temp; i++){
+ FillBuffer(0x2AA);
+ }//end for
+ }//end if
+}
+
+//_____________________________________________________________________________
+void AliAltroBuffer::FillBuffer(Int_t val)
+{
+//Fills the Buffer with 16 ten bits words and write into a file
+
+ fFreeCellBuffer--;
+ if (fShift < 10) {
+ Int_t temp = val;
+ val = val >> (10-fShift);
+ fBuffer[fCurrentCell] |= val;
+ fCurrentCell++;
+ fShift += 32;
+ val = temp;
+ }
+ fShift -= 10;
+ val = val << fShift;
+ fBuffer[fCurrentCell] |= val;
+ if (!fShift) {
+ //Buffer is written into a file
+ fFile->write((char*)fBuffer, sizeof(UInt_t)*5);
+ //Buffer is empty
+ for (Int_t j = 0; j < 5; j++) fBuffer[j] = 0;
+ fShift = 32;
+ fCurrentCell = 0;
+ fFreeCellBuffer = 16;
+ }
+}
+
+
+//_____________________________________________________________________________
+void AliAltroBuffer::WriteTrailer(Int_t wordsNumber, Int_t padNumber,
+ Int_t rowNumber, Int_t secNumber)
+{
+//Writes a trailer of 40 bits
+
+ Int_t num = fFreeCellBuffer % 4;
+ for(Int_t i = 0; i < num; i++) {
+ FillBuffer(0x2AA);
+ }//end for
+ FillBuffer(wordsNumber);
+ FillBuffer(padNumber);
+ FillBuffer(rowNumber);
+ FillBuffer(secNumber);
+}
+
+//_____________________________________________________________________________
+Bool_t AliAltroBuffer::ReadTrailer(Int_t& wordsNumber, Int_t& padNumber,
+ Int_t& rowNumber, Int_t& secNumber)
+{
+//Read a trailer of 40 bits in the forward reading mode
+
+ wordsNumber = GetNext();
+ if (wordsNumber == -1) return kFALSE;
+ padNumber = GetNext();
+ if (padNumber == -1) return kFALSE;
+ rowNumber = GetNext();
+ if (rowNumber == -1) return kFALSE;
+ secNumber = GetNext();
+ if (secNumber == -1) return kFALSE;
+ return kTRUE;
+}
+
+//_____________________________________________________________________________
+Bool_t AliAltroBuffer::ReadTrailerBackward(Int_t& wordsNumber,
+ Int_t& padNumber,
+ Int_t& rowNumber, Int_t& secNumber)
+{
+//Read a trailer of 40 bits in the backward reading mode
+
+ Int_t temp;
+ fEndingFillWords = 0;
+ do {
+ temp = GetNextBackWord();
+ fEndingFillWords++;
+ if (temp == -1) return kFALSE;
+ } while (temp == 0x2AA);
+ fEndingFillWords--;
+ secNumber = temp;
+ rowNumber = GetNextBackWord();
+ if (rowNumber == -1) return kFALSE;
+ padNumber = GetNextBackWord();
+ if (padNumber == -1) return kFALSE;
+ wordsNumber = GetNextBackWord();
+ if (wordsNumber == -1) return kFALSE;
+ return kTRUE;
+}
+
+
+//_____________________________________________________________________________
+void AliAltroBuffer::WriteChannel(Int_t padNumber, Int_t rowNumber,
+ Int_t secNumber,
+ Int_t nTimeBins, const Int_t* adcValues,
+ Int_t threshold)
+{
+//Write all ADC values and the trailer of a channel
+
+ Int_t nWords = 0;
+ Int_t timeBin = -1;
+ Int_t bunchLength = 0;
+
+ // loop over time bins
+ for (Int_t iTime = 0; iTime < nTimeBins; iTime++) {
+ if (adcValues[iTime] >= threshold) { // ADC value above threshold
+ FillBuffer(adcValues[iTime]);
+ nWords++;
+ timeBin = iTime;
+ bunchLength++;
+
+ } else if (timeBin >= 0) { // end of bunch
+ FillBuffer(timeBin);
+ FillBuffer(bunchLength + 2);
+ nWords += 2;
+ timeBin = -1;
+ bunchLength = 0;
+ }
+ }
+
+ if (timeBin >= 0) { // end of bunch
+ FillBuffer(timeBin);
+ FillBuffer(bunchLength + 2);
+ nWords += 2;
+ }
+
+ // write the trailer
+ WriteTrailer(nWords, padNumber, rowNumber, secNumber);
+}
+
+
+//_____________________________________________________________________________
+void AliAltroBuffer::WriteDataHeader(Bool_t dummy, Bool_t compressed)
+{
+//Write a (dummy or real) DDL data header,
+//set the compression bit if compressed
+
+ AliRawDataHeader header;
+ if (dummy) {
+ //if size=0 it means that this data header is a dummy data header
+ fDataHeaderPos = fFile->tellp();
+ fFile->write((char*)(&header), sizeof(header));
+ } else {
+ UInt_t currentFilePos = fFile->tellp();
+ fFile->seekp(fDataHeaderPos);
+ header.fSize = currentFilePos-fDataHeaderPos;
+ header.SetAttribute(0); // valid data
+ if (compressed) header.SetAttribute(1);
+ fFile->write((char*)(&header), sizeof(header));
+ fFile->seekp(currentFilePos);
+ }
+}
--- /dev/null
+/* Copyright(c) 1998-2003, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice */
+
+/////////////////////////////////////////////////////
+// Class used for read-write the ALTRO data format //
+/////////////////////////////////////////////////////
+
+/*This class is an interface between the altro format file and the
+ user, and can be used in write or read mode
+ In the write mode a new altro file is created and filled using the method FillBuffer().
+ The name of the file is specified as parameter in the constructor as well as the type mode.
+ In the Read mode the specified file is open and the values can be read using the
+ methods GetNext() and GetNextBackWord().
+ The first method is used to read the file forward while the second is used to read backward
+*/
+
+#ifndef AliALTROBUFFER_H
+#define AliALTROBUFFER_H
+
+#include <TObject.h>
+#ifdef __CINT__
+class fstream;
+#else
+#include "Riostream.h"
+#endif
+
+
+class AliAltroBuffer: public TObject {
+ public:
+ AliAltroBuffer(const char* fileName, Int_t flag);
+ virtual ~AliAltroBuffer();
+
+ void FillBuffer(Int_t val);
+ //this method stores a word into the buffer
+ Int_t GetFreeCellNumber()const {return fFreeCellBuffer;}
+ //this method returns the number of free cells of the internal buffer
+ Int_t GetNextBackWord();
+ //this method returns the next word of 10 bit (reading the file backward) if it exists -1 otherwise
+ Int_t GetNext();
+ //this method returns the next word of 10 bit (reading the file forward) if it exists -1 otherwise
+
+ void WriteTrailer(Int_t wordsNumber, Int_t padNumber,
+ Int_t rowNumber, Int_t secNumber);
+ //this method is used to write the trailer
+ Bool_t ReadTrailer(Int_t& wordsNumber, Int_t& padNumber,
+ Int_t& rowNumber, Int_t &secNumber);
+ //this method is used to read the trailer when the file is read forward
+ Bool_t ReadTrailerBackward(Int_t& wordsNumber, Int_t& padNumber,
+ Int_t& rowNumber, Int_t& secNumber);
+ //this method is used to read the trailer when the file is read backward
+
+ void WriteChannel(Int_t padNumber, Int_t rowNumber, Int_t secNumber,
+ Int_t nTimeBins, const Int_t* adcValues,
+ Int_t threshold = 0);
+ //this method is used to write all ADC values and the trailer of a channel
+
+ void WriteDataHeader(Bool_t dummy, Bool_t compressed);
+ //this method is used to write the data header
+ void SetVerbose(Int_t val) {fVerbose = val;}
+ //this method is used to set the verbose level
+ //level 0 no output messages
+ //level !=0 some messages are displayed during the run
+ void Flush();
+ //this method is used to fill the buffer with 2AA hexadecimal value and save it into the output file
+ Int_t GetFillWordsNum() const {return fEndingFillWords;}
+
+ private:
+ AliAltroBuffer(const AliAltroBuffer& source);
+ AliAltroBuffer& operator = (const AliAltroBuffer& source);
+
+ UInt_t fBuffer[5]; //Buffer dimension is 32*5=160 bits and it contains 16 values
+ //A value is never splitted in two Buffer
+
+
+ Int_t fShift; //This variable contains the number of free bits in the current cell of
+ //the Buffer after that the value Val is been inserted.
+ //size of Int_t is 32 bit that is the same size of a cell of Buffer so
+ //the shift operation are performed only on value Val.
+ Int_t fCurrentCell; //This variable contains the cell number of the cell currently used
+ Int_t fFreeCellBuffer;//number of free cells of the buffer
+ Int_t fFlag; //0 read 1 write
+ Int_t fVerbose; //verbose level
+ fstream* fFile; //logical name of the I/O file
+ Int_t fMaskBackward; //bit mask for backward reading of a file
+ UInt_t fFilePosition;//'pointer' to the actual position in the file
+ UInt_t fFileEnd; //position of the last element of the file (File dimension)
+ UInt_t fDataHeaderPos;//Data header position
+ Int_t fEndingFillWords;//Few words at the end of the stream
+
+ ClassDef(AliAltroBuffer,0) // Interface to the Altro format
+};
+
+#endif
--- /dev/null
+/**************************************************************************
+ * 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. *
+ **************************************************************************/
+
+/* $Id$ */
+
+///////////////////////////////////////////////////////////////////////////////
+///
+/// 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 "AliAltroRawStream.h"
+#include "AliRawReader.h"
+
+ClassImp(AliAltroRawStream)
+
+
+//_____________________________________________________________________________
+AliAltroRawStream::AliAltroRawStream(AliRawReader* rawReader) :
+ fSector(-1),
+ fPrevSector(-1),
+ fRow(-1),
+ fPrevRow(-1),
+ fPad(-1),
+ fPrevPad(-1),
+ fTime(-1),
+ fSignal(-1),
+ fRawReader(rawReader),
+ fData(NULL),
+ fPosition(0),
+ fCount(0),
+ fBunchLength(0)
+{
+// create an object to read Altro raw digits
+
+}
+
+//_____________________________________________________________________________
+AliAltroRawStream::AliAltroRawStream(const AliAltroRawStream& stream) :
+ TObject(stream),
+ fSector(-1),
+ fPrevSector(-1),
+ fRow(-1),
+ fPrevRow(-1),
+ fPad(-1),
+ fPrevPad(-1),
+ fTime(-1),
+ fSignal(-1),
+ fRawReader(NULL),
+ fData(NULL),
+ fPosition(0),
+ fCount(0),
+ fBunchLength(0)
+{
+ Fatal("AliAltroRawStream", "copy constructor not implemented");
+}
+
+//_____________________________________________________________________________
+AliAltroRawStream& AliAltroRawStream::operator = (const AliAltroRawStream&
+ /* stream */)
+{
+ Fatal("operator =", "assignment operator not implemented");
+ return *this;
+}
+
+//_____________________________________________________________________________
+AliAltroRawStream::~AliAltroRawStream()
+{
+// clean up
+
+}
+
+
+//_____________________________________________________________________________
+Bool_t AliAltroRawStream::Next()
+{
+// read the next raw digit
+// returns kFALSE if there is no digit left
+
+ fPrevSector = fSector;
+ fPrevRow = fRow;
+ fPrevPad = fPad;
+
+ while (fCount == 0) { // next trailer
+ if (fPosition <= 0) { // next payload
+ do {
+ if (!fRawReader->ReadNextData(fData)) return kFALSE;
+ } while (fRawReader->GetDataSize() == 0);
+
+ fPosition = (fRawReader->GetDataSize() * 8) / 10;
+ while (Get10BitWord(fData, fPosition-1) == 0x2AA) fPosition--;
+ }
+
+ if (fPosition > 0) {
+ // read the trailer
+ if (fPosition <= 4) {
+ Error("Next", "could not read trailer");
+ return kFALSE;
+ }
+ fSector = Get10BitWord(fData, --fPosition);
+ fRow = Get10BitWord(fData, --fPosition);
+ fPad = Get10BitWord(fData, --fPosition);
+ fCount = Get10BitWord(fData, --fPosition);
+
+ fPosition -= (4 - (fCount % 4)) % 4; // skip fill words
+ fBunchLength = 0;
+ }
+ }
+
+ if (fBunchLength == 0) {
+ if (fPosition <= 0) {
+ Error("Next", "could not read bunch length");
+ return kFALSE;
+ }
+ fBunchLength = Get10BitWord(fData, --fPosition) - 2;
+ fCount--;
+
+ if (fPosition <= 0) {
+ Error("Next", "could not read time bin");
+ return kFALSE;
+ }
+ fTime = Get10BitWord(fData, --fPosition);
+ fCount--;
+ } else {
+ fTime--;
+ }
+
+ if (fPosition <= 0) {
+ Error("Next", "could not read sample amplitude");
+ return kFALSE;
+ }
+ fSignal = Get10BitWord(fData, --fPosition);
+ fCount--;
+ fBunchLength--;
+
+ return kTRUE;
+}
+
+
+//_____________________________________________________________________________
+UShort_t AliAltroRawStream::Get10BitWord(UChar_t* buffer, Int_t position) const
+{
+// return a word in a 10 bit array as an UShort_t
+
+ Int_t iBit = position * 10;
+ Int_t iByte = iBit / 8;
+ Int_t shift = iBit % 8;
+// return ((buffer[iByte+1] * 256 + buffer[iByte]) >> shift) & 0x03FF;
+
+ // recalculate the byte numbers and the shift because
+ // the raw data is written as integers where the high bits are filled first
+ // -> little endian is assumed here !
+ Int_t iByteHigh = 4 * (iByte / 4) + 3 - (iByte % 4);
+ iByte++;
+ Int_t iByteLow = 4 * (iByte / 4) + 3 - (iByte % 4);
+ shift = 6 - shift;
+ return ((buffer[iByteHigh] * 256 + buffer[iByteLow]) >> shift) & 0x03FF;
+}
--- /dev/null
+#ifndef ALIALTRORAWSTREAM_H
+#define ALIALTRORAWSTREAM_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice */
+
+/* $Id$ */
+
+///////////////////////////////////////////////////////////////////////////////
+///
+/// This is a base class for reading raw data digits in Altro format
+///
+///////////////////////////////////////////////////////////////////////////////
+
+#include <TObject.h>
+
+class AliRawReader;
+
+
+class AliAltroRawStream: public TObject {
+ public :
+ AliAltroRawStream(AliRawReader* rawReader);
+ virtual ~AliAltroRawStream();
+
+ virtual Bool_t Next();
+
+ protected:
+ 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
+ Int_t fTime; // index of current time bin
+ Int_t fSignal; // signal in ADC counts
+
+ AliRawReader* fRawReader; // object for reading the raw data
+
+ private :
+ AliAltroRawStream(const AliAltroRawStream& stream);
+ AliAltroRawStream& operator = (const AliAltroRawStream& stream);
+
+ UShort_t Get10BitWord(UChar_t* buffer, Int_t position) const;
+
+ 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(AliAltroRawStream, 0) // base class for reading Altro raw digits
+};
+
+#endif
--- /dev/null
+/**************************************************************************
+ * 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. *
+ **************************************************************************/
+
+/* $Id$ */
+
+///////////////////////////////////////////////////////////////////////////////
+///
+/// This is a service class for packing and unpacking bits in a 32 bit word.
+///
+///////////////////////////////////////////////////////////////////////////////
+
+#include <TError.h>
+
+#include "AliBitPacking.h"
+
+
+ClassImp(AliBitPacking)
+
+
+//_____________________________________________________________________________
+Bool_t AliBitPacking::PackWord(UInt_t data, UInt_t &word,
+ Int_t startBit, Int_t stopBit)
+{
+// Packs data into the word buffer from startBit bit up to stopBit bit
+
+ // check that startBit and stopBit are reasonable
+ if (startBit > stopBit) {
+ ::Error("AliBitPacking::PackWord",
+ "startBit is larger than stopBit");
+ return kFALSE;
+ }
+ if (stopBit > 31) {
+ ::Error("AliBitPacking::PackWord",
+ "stopBit exceeds valid range of 32 bits");
+ return kFALSE;
+ }
+
+ // create a word with the bits 0 to (stopBit-startBit) set
+ UInt_t bits = 0xFFFFFFFF;
+ if (stopBit-startBit < 31) bits = (1 << (stopBit-startBit+1)) - 1;
+
+ // check that the data fits into the given bit range
+ if (data > bits){
+ ::Error("AliBitPacking::PackWord",
+ "Word to be filled is not within desired length");
+ return kFALSE;
+ }
+
+ // clear the bits from startBit to stopBit
+ word &= (0xFFFFFFFF ^ (bits << startBit));
+
+ // fill in the data bits
+ word |= (data << startBit);
+
+ return kTRUE;
+}
+
+//_____________________________________________________________________________
+UInt_t AliBitPacking::UnpackWord(UInt_t word, Int_t startBit, Int_t stopBit)
+{
+// Unpacks data of stopBit-startBit+1 bits from word buffer starting from
+// the position indicated by startBit
+
+ // check that startBit and stopBit are reasonable
+ if (startBit > stopBit) {
+ ::Error("AliBitPacking::UnpackWord",
+ "startBit is larger than stopBit");
+ return 0xFFFFFFFF;
+ }
+ if (stopBit > 31) {
+ ::Error("AliBitPacking::UnpackWord",
+ "stopBit exceeds valid range of 32 bits");
+ return 0xFFFFFFFF;
+ }
+
+ // create a word with the bits 0 to (stopBit-startBit) set
+ UInt_t bits = 0xFFFFFFFF;
+ if (stopBit-startBit < 31) bits = (1 << (stopBit-startBit+1)) - 1;
+
+ // pick out the requested bits
+ return ((word >> startBit) & bits);
+}
--- /dev/null
+#ifndef ALIBITPACKING_H
+#define ALIBITPACKING_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice */
+
+/* $Id$ */
+
+///////////////////////////////////////////////////////////////////////////////
+///
+/// This is a service class for packing and unpacking bits in a 32 bit word.
+///
+///////////////////////////////////////////////////////////////////////////////
+
+#include <TObject.h>
+
+
+class AliBitPacking: public TObject {
+ public :
+ static Bool_t PackWord(UInt_t data, UInt_t &word,
+ Int_t startBit, Int_t stopBit);
+ static UInt_t UnpackWord(UInt_t word, Int_t startBit, Int_t stopBit);
+
+ ClassDef(AliBitPacking, 0) // class for packing and unpacking bits
+};
+
+#endif
#include <Riostream.h>
#include <TMath.h>
#include <TSystem.h>
-#include "AliTPCBuffer160.h"
+#include "AliAltroBuffer.h"
#include "AliTPCHNode.h"
#include "AliTPCHTable.h"
#include "AliTPCCompression.h"
Int_t AliTPCCompression::FillTables(const char* fSource,AliTPCHTable* table[],Int_t /*NumTables*/){
//This method is used to compute the frequencies of the symbols in the source file
- AliTPCBuffer160 buff(fSource,0);
+ AliAltroBuffer buff(fSource,0);
UInt_t countWords=0;
UInt_t countTrailer=0;
Int_t numWords,padNum,rowNum,secNum=0;
UInt_t stat[5]={0,0,0,0,0};
Int_t endFill=0;
Int_t end=1;
- while(buff.ReadTrailerBackward(numWords,padNum,rowNum,secNum) !=-1 ){
+ while(buff.ReadTrailerBackward(numWords,padNum,rowNum,secNum)){
if(end){
endFill=buff.GetFillWordsNum();
end=0;
f.open(fDest,ios::out);
#endif
// Source file is open
- AliTPCBuffer160 buff(fSource,0);
+ AliAltroBuffer buff(fSource,0);
//coded words are written into a file
Int_t numWords,padNum,rowNum,secNum=0;
UInt_t storedWords=0;
fStat<<endl;
fStat<<"-------------------COMPRESSION STATISTICS----------"<<endl;
Int_t end=1;
- while(buff.ReadTrailerBackward(numWords,padNum,rowNum,secNum) !=-1 ){
+ while(buff.ReadTrailerBackward(numWords,padNum,rowNum,secNum)){
if(end){
fillWords=buff.GetFillWordsNum();
end=0;
if(fVerbose){
cout<<"Number of Packect: "<<packetNumber<<endl;
}
- AliTPCBuffer160 bufferFile(fDest,1);
+ AliAltroBuffer bufferFile(fDest,1);
UInt_t k=0;
UInt_t wordsRead=0; //number of read coded words
while(k<packetNumber){
//Time bin of the last amplitude sample in the bunch, amplitude values)
//It is used mainly for debugging
ofstream ftxt(fileOut);
- AliTPCBuffer160 buff(fileIn,0);
+ AliAltroBuffer buff(fileIn,0);
Int_t numWords,padNum,rowNum,secNum=0;
Int_t value=0;
if (fVerbose) cout<<"Creating a txt file from an Altro Format file"<<endl;
- while(buff.ReadTrailerBackward(numWords,padNum,rowNum,secNum) !=-1 ){
+ while(buff.ReadTrailerBackward(numWords,padNum,rowNum,secNum)){
ftxt<<"S:"<<secNum<<" R:"<<rowNum<<" P:"<<padNum<<" W:"<<numWords<<endl;
if (numWords%4){
for(Int_t j=0;j<(4-numWords%4);j++){
#include <TObjArray.h>
#include <TMath.h>
-#include "AliTPCBuffer160.h"
+#include "AliAltroBuffer.h"
#include "AliTPCHNode.h"
#include "AliTPCHTable.h"
Int_t AliTPCHTable::GetFrequencies(const char *fname){
//It fills the "fCode" array with the frequencies of the symbols read from the file
- AliTPCBuffer160 buff(fname,0);
+ AliAltroBuffer buff(fname,0);
UInt_t numberOfWords=0;
Int_t val;
while((val=buff.GetNext())!=-1){
#pragma link C++ class AliRawReaderFile+;
#pragma link C++ class AliRawReaderRoot+;
#pragma link C++ class AliRawReaderDate+;
+#pragma link C++ class AliBitPacking+;
+#pragma link C++ class AliAltroBuffer+;
#pragma link C++ class AliTPCBuffer160+;
#pragma link C++ class AliTPCCompression+;
#pragma link C++ class AliTPCHNode+;
#pragma link C++ class AliTPCHTable+;
+#pragma link C++ class AliAltroRawStream+;
#pragma link C++ class AliTPCRawStream+;
#pragma link C++ class AliITSRawStream+;
#pragma link C++ class AliITSRawStreamSPD+;
AliRunDB.cxx AliMDC.cxx \
AliRawReader.cxx AliRawReaderFile.cxx AliRawReaderRoot.cxx \
AliRawReaderDate.cxx \
+ AliBitPacking.cxx AliAltroBuffer.cxx \
AliTPCBuffer160.cxx AliTPCCompression.cxx \
AliTPCHNode.cxx AliTPCHTable.cxx \
- AliTPCRawStream.cxx \
+ AliAltroRawStream.cxx AliTPCRawStream.cxx \
AliITSRawStream.cxx AliITSRawStreamSPD.cxx \
AliITSRawStreamSDD.cxx AliITSRawStreamSSD.cxx \
AliITSRawStreamSDDv2.cxx AliVMERawStream.cxx
EHDRS:=$(ROOTSYS)/include/TH1F.h
+EDEFINE:= -DUSE_RDM
+
DHDR:= LinkDef.h
ifdef DATE_ROOT