#include "AliAltroBufferV3.h"
#include "AliRawDataHeaderSim.h"
#include "AliLog.h"
#include "AliFstream.h"
ClassImp(AliAltroBufferV3)
AliAltroBufferV3::AliAltroBufferV3(const char* fileName, AliAltroMapping *mapping):
AliAltroBuffer(fileName,mapping),
fN(0),
fFECERRA(0),
fFECERRB(0),
fERRREG2(0),
fERRREG3(0),
fActiveFECsA(0xffff),
fActiveFECsB(0xffff),
fALTROCFG1(0),
fALTROCFG2(0),
fTSample(0),
fL1Phase(0)
{
memset(fArray, 0, kMaxWords*sizeof(UShort_t));
}
AliAltroBufferV3::~AliAltroBufferV3()
{
}
AliAltroBufferV3::AliAltroBufferV3(const AliAltroBufferV3& source):
AliAltroBuffer(source),
fN(source.fN),
fFECERRA(source.fFECERRA),
fFECERRB(source.fFECERRB),
fERRREG2(source.fERRREG2),
fERRREG3(source.fERRREG3),
fActiveFECsA(source.fActiveFECsA),
fActiveFECsB(source.fActiveFECsB),
fALTROCFG1(source.fALTROCFG1),
fALTROCFG2(source.fALTROCFG2),
fTSample(source.fTSample),
fL1Phase(source.fL1Phase)
{
Fatal("AliAltroBufferV3", "copy constructor not implemented");
}
AliAltroBufferV3& AliAltroBufferV3::operator = (const AliAltroBufferV3& )
{
#if 0
fFECERRA = source.fFECERRA;
fFECERRB = source.fFECERRB;
fERRREG2 = source.fERRREG2;
fERRREG3 = source.fERRREG3;
fActiveFECsA = source.fActiveFECsA;
fActiveFECsB = source.fActiveFECsB;
fALTROCFG1 = source.fALTROCFG1;
fALTROCFG2 = source.fALTROCFG2;
fTSample = source.fTSample;
fL1Phase = source.fL1Phase;
#endif
Fatal("operator =", "assignment operator not implemented");
return *this;
}
void AliAltroBufferV3::FillBuffer(Int_t val)
{
if ((val > 0x3FF) || (val < 0)) {
Error("FillBuffer", "Value out of range (10 bits): %d", val);
val = 0x3FF;
}
if (fN >= (kMaxWords-1)) {
Error("FillBuffer","Altro channel can't have more than 1024 10-bit words!");
return;
}
fArray[fN++] = val;
}
void AliAltroBufferV3::WriteTrailer(Int_t wordsNumber, Short_t hwAddress)
{
UInt_t temp = hwAddress & 0xFFF;
temp |= ((wordsNumber & 0x3FF) << 16);
temp |= (0x1U << 30);
fFile->WriteBuffer((char *)(&temp),sizeof(UInt_t));
ReverseAndWrite();
}
UInt_t AliAltroBufferV3::SetField(UInt_t& input, UShort_t start, UInt_t mask, UInt_t val) const
{
UInt_t out = (mask << start);
UInt_t fld = (val << start) & out;
input &= ~out;
input |= fld;
return input;
}
void AliAltroBufferV3::ReverseAndWrite()
{
UInt_t temp = 0;
Int_t shift = 20;
for(Int_t i = (fN-1); i >= 0; i--) {
temp |= (fArray[i] << shift);
shift -= 10;
if (shift < 0) {
fFile->WriteBuffer((char *)(&temp),sizeof(UInt_t));
temp = 0;
shift = 20;
}
}
if (shift != 20) {
fFile->WriteBuffer((char *)(&temp),sizeof(UInt_t));
}
fN = 0;
}
UChar_t AliAltroBufferV3::WriteRCUTrailer(Int_t rcuId)
{
UInt_t currentFilePos = fFile->Tellp();
UInt_t size = currentFilePos-fDataHeaderPos;
size -= sizeof(AliRawDataHeaderV3);
size /= 4;
if (size > 0x3FFFFFF) {
AliFatal(Form("The current raw data payload size of %d is bigger than the max possible one ! Can not write the RCU trailer !",size));
return 2;
}
size |= (1U << 31);
fFile->WriteBuffer((char *)(&size),sizeof(UInt_t));
UInt_t buffer;
buffer = (0x1U << 26);
buffer |= (0x1U << 31);
fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
buffer = (fERRREG2 & 0x3FFFFFF);
buffer |= (0x2U << 26);
buffer |= (0x1U << 31);
fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
buffer = (fERRREG3 & 0x3FFFFFF);
buffer |= (0x3U << 26);
buffer |= (0x1U << 31);
fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
buffer = (fActiveFECsA & 0x3FFFFFF);
buffer |= (0x4U << 26);
buffer |= (0x1U << 31);
fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
buffer = (fActiveFECsB & 0x3FFFFFF);
buffer |= (0x5U << 26);
buffer |= (0x1U << 31);
fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
buffer = (fALTROCFG1 & 0x3FFFFFF);
buffer |= (0x6U << 26);
buffer |= (0x1U << 31);
fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
buffer = (fALTROCFG2 & 0x3FFFFFF);
buffer |= (0x7U << 26);
buffer |= (0x1U << 31);
fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
buffer = (9 & 0x7F);
buffer |= ((rcuId & 0x1FF) << 7);
buffer |= (0x2U << 16);
buffer |= (0x8U << 26);
buffer |= (0x3U << 30);
fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
return 2;
}