// 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 "AliAltroMapping.h"
rowNumber,secNumber);
}
- Short_t hwAdress = fMapping->GetHWAdress(rowNumber,padNumber,secNumber);
- if (hwAdress == -1)
+ Short_t hwAddress = fMapping->GetHWAddress(rowNumber,padNumber,secNumber);
+ if (hwAddress == -1)
AliFatal(Form("No hardware (ALTRO) adress found for these pad-row (%d) and pad (%d) indeces !",rowNumber,padNumber));
- WriteTrailer(wordsNumber,hwAdress);
+ WriteTrailer(wordsNumber,hwAddress);
}
//_____________________________________________________________________________
-void AliAltroBuffer::WriteTrailer(Int_t wordsNumber, Short_t hwAdress)
+void AliAltroBuffer::WriteTrailer(Int_t wordsNumber, Short_t hwAddress)
{
//Writes a trailer of 40 bits using
//a given hardware adress
FillBuffer(0x2AA);
}//end for
Int_t temp;
- temp = 0x2AA;
- FillBuffer(temp);
- temp = 0xA << 6;
- temp |= ((wordsNumber & 0x3FF) >> 4);
+ temp = hwAddress & 0x3FF;
FillBuffer(temp);
+
temp = (wordsNumber << 6) & 0x3FF;
temp |= (0xA << 2);
+ temp |= ((hwAddress >> 10) & 0x3);
+ FillBuffer(temp);
- temp |= (hwAdress >> 10) & 0x3;
+ temp = 0xA << 6;
+ temp |= ((wordsNumber & 0x3FF) >> 4);
FillBuffer(temp);
- temp = hwAdress & 0x3FF;
+
+ temp = 0x2AA;
FillBuffer(temp);
}
rowNumber,secNumber);
}
- Short_t hwAdress;
- if (!ReadTrailer(wordsNumber,hwAdress)) return kFALSE;
- rowNumber = fMapping->GetPadRow(hwAdress);
- padNumber = fMapping->GetPad(hwAdress);
- secNumber = fMapping->GetSector(hwAdress);
+ Short_t hwAddress;
+ if (!ReadTrailer(wordsNumber,hwAddress)) return kFALSE;
+ rowNumber = fMapping->GetPadRow(hwAddress);
+ padNumber = fMapping->GetPad(hwAddress);
+ secNumber = fMapping->GetSector(hwAddress);
return kTRUE;
}
//_____________________________________________________________________________
-Bool_t AliAltroBuffer::ReadTrailer(Int_t& wordsNumber, Short_t& hwAdress)
+Bool_t AliAltroBuffer::ReadTrailer(Int_t& wordsNumber, Short_t& hwAddress)
{
//Read a trailer of 40 bits in the forward reading mode
Int_t temp = GetNext();
- if (temp != 0x2AA)
- AliFatal(Form("Incorrect trailer found ! Expecting 0x2AA but found %x !",temp));
+ hwAddress = temp;
temp = GetNext();
- if ((temp >> 6) != 0xA)
- AliFatal(Form("Incorrect trailer found ! Expecting 0xA but found %x !",temp >> 6));
- wordsNumber = (temp << 4) & 0x3FF;
-
- temp = GetNext();
- wordsNumber |= (temp >> 6);
+ wordsNumber = ((temp & 0x3FF) >> 6);
if (((temp >> 2) & 0xF) != 0xA)
AliFatal(Form("Incorrect trailer found ! Expecting second 0xA but found %x !",temp >> 6));
- hwAdress = (temp & 0x3) << 10;
+ hwAddress |= (temp & 0x3) << 10;
+
+ temp = GetNext();
+ if ((temp >> 6) != 0xA)
+ AliFatal(Form("Incorrect trailer found ! Expecting 0xA but found %x !",temp >> 6));
+ wordsNumber |= (temp << 4) & 0x3FF;
temp = GetNext();
- hwAdress |= temp;
+ if (temp != 0x2AA)
+ AliFatal(Form("Incorrect trailer found ! Expecting 0x2AA but found %x !",temp));
return kTRUE;
}
rowNumber,secNumber);
}
- Short_t hwAdress;
- if (!ReadTrailerBackward(wordsNumber,hwAdress)) return kFALSE;
- rowNumber = fMapping->GetPadRow(hwAdress);
- padNumber = fMapping->GetPad(hwAdress);
- secNumber = fMapping->GetSector(hwAdress);
+ Short_t hwAddress;
+ if (!ReadTrailerBackward(wordsNumber,hwAddress)) return kFALSE;
+ rowNumber = fMapping->GetPadRow(hwAddress);
+ padNumber = fMapping->GetPad(hwAddress);
+ secNumber = fMapping->GetSector(hwAddress);
return kTRUE;
}
//_____________________________________________________________________________
-Bool_t AliAltroBuffer::ReadTrailerBackward(Int_t& wordsNumber, Short_t& hwAdress)
+Bool_t AliAltroBuffer::ReadTrailerBackward(Int_t& wordsNumber, Short_t& hwAddress)
{
//Read a trailer of 40 bits in the backward reading mode
Int_t temp;
fEndingFillWords = 0;
- do {
- temp = GetNextBackWord();
+ while ((temp = GetNextBackWord()) == 0x2AA) {
fEndingFillWords++;
if (temp == -1) return kFALSE;
- } while (temp == 0x2AA);
+ };
+ if (fEndingFillWords == 0)
+ AliFatal("Incorrect trailer found ! Expected 0x2AA not found !");
fEndingFillWords--;
- hwAdress = temp;
+ wordsNumber = (temp << 4) & 0x3FF;
+ if ((temp >> 6) != 0xA)
+ AliFatal(Form("Incorrect trailer found ! Expecting 0xA but found %x !",temp >> 6));
temp = GetNextBackWord();
- hwAdress |= (temp & 0x3) << 10;
+ hwAddress = (temp & 0x3) << 10;
if (((temp >> 2) & 0xF) != 0xA)
- AliFatal(Form("Incorrect trailer found ! Expecting second 0xA but found %x !",temp >> 6));
- wordsNumber = (temp >> 6);
+ AliFatal(Form("Incorrect trailer found ! Expecting second 0xA but found %x !",(temp >> 2) & 0xF));
+ wordsNumber |= ((temp & 0x3FF) >> 6);
temp = GetNextBackWord();
- wordsNumber |= (temp << 4) & 0x3FF;
- if ((temp >> 6) != 0xA)
- AliFatal(Form("Incorrect trailer found ! Expecting 0xA but found %x !",temp >> 6));
-
- temp = GetNextBackWord();
- if (temp != 0x2AA)
- AliFatal(Form("Incorrect trailer found ! Expecting 0x2AA but found %x !",temp));
+ hwAddress |= temp;
return kTRUE;
}
Int_t nTimeBins, const Int_t* adcValues,
Int_t threshold)
{
-//Write all ADC values and the trailer of a channel
+ //Write all ADC values and the trailer of a channel
+ Int_t nWords = WriteBunch(nTimeBins,adcValues,threshold);
+ // write the trailer
+ WriteTrailer(nWords, padNumber, rowNumber, secNumber);
+}
+
+//_____________________________________________________________________________
+void AliAltroBuffer::WriteChannel(Short_t hwAddress,
+ Int_t nTimeBins, const Int_t* adcValues,
+ Int_t threshold)
+{
+ //Write all ADC values and the trailer of a channel
+ Int_t nWords = WriteBunch(nTimeBins,adcValues,threshold);
+ // write the trailer
+ WriteTrailer(nWords, hwAddress);
+}
+
+//_____________________________________________________________________________
+Int_t AliAltroBuffer::WriteBunch(Int_t nTimeBins, const Int_t* adcValues,
+ Int_t threshold)
+{
+ //Write all ADC values
+ //Return number of words written
Int_t nWords = 0;
Int_t timeBin = -1;
nWords += 2;
}
- // write the trailer
- WriteTrailer(nWords, padNumber, rowNumber, secNumber);
+ return nWords;
}
//_____________________________________________________________________________
-void AliAltroBuffer::ReadChannel(Int_t padNumber, Int_t rowNumber,
- Int_t secNumber,
- Int_t& nTimeBins, Int_t* adcValues)
+void AliAltroBuffer::ReadChannelBackward(Int_t& padNumber, Int_t& rowNumber,
+ Int_t& secNumber,
+ Int_t& nTimeBins, Int_t* adcValues)
{
-//Read all ADC values and the trailer of a channel
+//Read all ADC values and the trailer of a channel (in backward order)
Int_t wordsNumber;
- if (!ReadTrailer(wordsNumber,padNumber,
- rowNumber,secNumber)) return;
+ if (!ReadTrailerBackward(wordsNumber,padNumber,
+ rowNumber,secNumber)) return;
+ return ReadBunchBackward(wordsNumber,nTimeBins,adcValues);
+}
+//_____________________________________________________________________________
+void AliAltroBuffer::ReadChannelBackward(Short_t& hwAddress,
+ Int_t& nTimeBins, Int_t* adcValues)
+{
+//Read all ADC values and the trailer of a channel (in backward order)
+
+ Int_t wordsNumber;
+ if (!ReadTrailerBackward(wordsNumber,
+ hwAddress)) return;
+ return ReadBunchBackward(wordsNumber,nTimeBins,adcValues);
+}
+
+//_____________________________________________________________________________
+void AliAltroBuffer::ReadBunchBackward(Int_t wordsNumber,
+ Int_t& nTimeBins, Int_t* adcValues)
+{
if (wordsNumber < 0) return;
// Number of fill words
Int_t nFillWords;
nFillWords = 4 - wordsNumber % 4;
// Read the fill words
for (Int_t i = 0; i < nFillWords; i++) {
- Int_t temp = GetNext();
+ Int_t temp = GetNextBackWord();
if (temp != 0x2AA)
AliFatal(Form("Invalid fill word, expected 0x2AA, but got %X", temp));
}
Int_t lastWord = wordsNumber;
nTimeBins = -1;
while (lastWord > 0) {
- Int_t l = GetNext();
+ Int_t l = GetNextBackWord();
if (l < 0) AliFatal(Form("Bad bunch length (%d) !", l));
- Int_t t = GetNext();
+ Int_t t = GetNextBackWord();
if (t < 0) AliFatal(Form("Bad bunch time (%d) !", t));
lastWord -= 2;
if (nTimeBins == -1) nTimeBins = t + 1;
for (Int_t i = 2; i < l; i++) {
- Int_t amp = GetNext();
+ Int_t amp = GetNextBackWord();
if (amp < 0) AliFatal(Form("Bad adc value (%X) !", amp));
adcValues[t - (i-2)] = amp;
lastWord--;
void WriteTrailer(Int_t wordsNumber, Int_t padNumber,
Int_t rowNumber, Int_t secNumber);
//this method is used to write the trailer
- void WriteTrailer(Int_t wordsNumber, Short_t hwAdress);
+ void WriteTrailer(Int_t wordsNumber, Short_t hwAddress);
//this method is used to write the trailer
void WriteDummyTrailer(Int_t wordsNumber, Int_t padNumber,
Int_t rowNumber, Int_t secNumber);
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 ReadTrailer(Int_t& wordsNumber, Short_t& hwAdress);
+ Bool_t ReadTrailer(Int_t& wordsNumber, Short_t& hwAddress);
//this method is used to read the trailer when the file is read forward
Bool_t ReadDummyTrailer(Int_t& wordsNumber, Int_t& padNumber,
Int_t& rowNumber, Int_t &secNumber);
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
- Bool_t ReadTrailerBackward(Int_t& wordsNumber, Short_t& hwAdress);
+ Bool_t ReadTrailerBackward(Int_t& wordsNumber, Short_t& hwAddress);
//this method is used to read the trailer when the file is read backward
Bool_t ReadDummyTrailerBackward(Int_t& wordsNumber, 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 ReadChannel(Int_t padNumber, Int_t rowNumber, Int_t secNumber,
- Int_t& nTimeBins, Int_t* adcValues);
+ void WriteChannel(Short_t hwAddress,
+ 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
+ Int_t WriteBunch(Int_t nTimeBins, const Int_t* adcValues,
+ Int_t threshold = 0);
+ //this method is used to write all ADC values
+ void ReadChannelBackward(Int_t& padNumber, Int_t& rowNumber, Int_t& secNumber,
+ Int_t& nTimeBins, Int_t* adcValues);
+ //this method is used to read all ADC values and the trailer of a channel
+ void ReadChannelBackward(Short_t& hwAddress,
+ Int_t& nTimeBins, Int_t* adcValues);
//this method is used to read all ADC values and the trailer of a channel
+ void ReadBunchBackward(Int_t wordsNumber,
+ Int_t& nTimeBins, Int_t* adcValues);
+ //this method is used to read all ADC values
void WriteDataHeader(Bool_t dummy, Bool_t compressed);
//this method is used to write the data header
///
///////////////////////////////////////////////////////////////////////////////
+#include <TSystem.h>
+
#include "AliTPCRawStream.h"
#include "AliTPCHNode.h"
#include "AliRawReader.h"
+#include "AliLog.h"
+#include "AliTPCAltroMapping.h"
ClassImp(AliTPCRawStream)
}
fSector = fPrevSector = fRow = fPrevRow = fPad = fPrevPad = fTime = fSignal = -1;
+
+ 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());
+ }
}
AliTPCRawStream::AliTPCRawStream(const AliTPCRawStream& stream) :
// clean up
delete[] fData;
+
+ for(Int_t i = 0; i < 6; i++) delete fMapping[i];
}
void AliTPCRawStream::Reset()
fDataSize = 0;
Int_t pos = (fRawReader->GetDataSize() * 8) / 10;
while (Get10BitWord(data, pos-1) == 0x2AA) pos--;
+ pos++;
while (pos > 0) {
for (Int_t i = 0; i < 4; i++) { // copy trailer
fData[fDataSize++] = Get10BitWord(data, pos-4+i);
}
pos -= 4;
- Int_t count = fData[fDataSize-4];
+
+ Int_t count = (fData[fDataSize-2] << 4) & 0x3FF;
+ count |= ((fData[fDataSize-3] & 0x3FF) >> 6);
+ // Int_t count = fData[fDataSize-4];
pos -= (4 - (count % 4)) % 4; // skip fill words
while (count > 0) {
Error("Next", "could not read trailer");
return kFALSE;
}
- fCount = fData[fPosition++];
- fPad = fData[fPosition++];
- fRow = fData[fPosition++];
- fSector = fData[fPosition++];
+
+ Short_t temp = fData[fPosition++];
+ Short_t hwAdress = temp & 0x3FF;
+
+ temp = fData[fPosition++];
+ hwAdress |= (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);
+
+ temp = fData[fPosition++];
+ fCount |= (temp << 4) & 0x3FF;
+ if ((temp >> 6) != 0xA)
+ AliFatal(Form("Incorrect trailer found ! Expecting 0xA but found %x !",temp >> 6));
+
+ temp = fData[fPosition++];
+ if (temp != 0x2AA)
+ AliFatal(Form("Incorrect trailer found ! Expecting 0x2AA but found %x !",temp));
+
+ Int_t ddlNumber = fRawReader->GetDDLID();
+ Int_t patchIndex;
+ if (ddlNumber < 72) {
+ fSector = ddlNumber / 2;
+ patchIndex = ddlNumber % 2;
+ }
+ else {
+ fSector = (ddlNumber - 72) / 4 + 36;
+ patchIndex = (ddlNumber - 72) % 4 + 2;
+ }
+ fPad = fMapping[patchIndex]->GetPad(hwAdress);
+ fRow = fMapping[patchIndex]->GetPadRow(hwAdress);
+
fBunchLength = 0;
}