#include "AliMUONBusStruct.h"
#include "AliLog.h"
#include <Riostream.h>
#include <string.h>
using std::cout;
using std::endl;
ClassImp(AliMUONBusStruct)
const Int_t AliMUONBusStruct::fgkHeaderLength = 4;
const UInt_t AliMUONBusStruct::fgkDefaultDataKey = 0xB000000B;
const Int_t AliMUONBusStruct::fgkManuNofChannels(64);
AliMUONBusStruct::AliMUONBusStruct()
: TObject(),
fDataKey(0),
fTotalLength(0),
fLength(0),
fBusPatchId(0),
fBufSize(43*fgkManuNofChannels),
fData(new UInt_t[fBufSize]),
fDspId(0),
fBlkId(0)
{
}
AliMUONBusStruct::~AliMUONBusStruct()
{
delete[] fData;
}
void AliMUONBusStruct::SetAlloc(Int_t size)
{
if (size < fBufSize)
return;
else
ResizeData(size);
}
void AliMUONBusStruct::AddData(UInt_t data)
{
if (fLength == fBufSize)
ResizeData();
fData[fLength++] = data;
fTotalLength = fLength + fgkHeaderLength;
}
void AliMUONBusStruct::ResizeData(Int_t size)
{
if (size == 0)
fBufSize *= 2;
else
fBufSize = size;
UInt_t* newData = new UInt_t[fBufSize];
for (Int_t i = 0; i < fLength; i++)
newData[i] = fData[i];
delete[] fData;
fData = newData;
}
AliMUONBusStruct::
AliMUONBusStruct(const AliMUONBusStruct& event)
: TObject(event),
fDataKey(event.fDataKey),
fTotalLength(event.fTotalLength),
fLength(event.fLength),
fBusPatchId(event.fBusPatchId),
fBufSize(event.fBufSize),
fData(new UInt_t[event.fBufSize]),
fDspId(event.fDspId),
fBlkId(event.fBlkId)
{
for (int i = 0; i < event.fBufSize; i++)
fData[i] = event.fData[i];
}
AliMUONBusStruct&
AliMUONBusStruct::operator=(const AliMUONBusStruct& event)
{
if (this == &event) return *this;
fDataKey = event.fDataKey;
fTotalLength = event.fTotalLength;
fLength = event.fLength;
fBusPatchId = event.fBusPatchId;
fBufSize = event.fBufSize;
fBlkId = event.fBlkId;
fDspId = event.fDspId;
delete [] fData;
fData = new UInt_t[event.fBufSize];
for (int i = 0; i < event.fLength; i++)
fData[i] = event.fData[i];
return *this;
}
Int_t AliMUONBusStruct::Compare(const TObject *obj) const
{
AliMUONBusStruct* event = (AliMUONBusStruct*) obj;
return (fBusPatchId > event->GetBusPatchId()) ? 1 : -1;
}
void AliMUONBusStruct::Clear(Option_t *)
{
delete[] fData;
}
UInt_t AliMUONBusStruct::GetData(Int_t n) const
{
if ( n>=0 && n<fLength ) return fData[n];
AliError("Index outside limits.");
return 0;
}
Char_t AliMUONBusStruct::GetParity(Int_t n) const
{
if ( n>=0 && n<fLength ) return (Char_t)(fData[n] >> 31) & 0x1;
AliError("Index outside limits.");
return 0;
}
UShort_t AliMUONBusStruct::GetManuId(Int_t n) const
{
if ( n>=0 && n<fLength ) return (UShort_t)(fData[n] >> 18) & 0x7FF;
AliError("Index outside limits.");
return 0;
}
UChar_t AliMUONBusStruct::GetChannelId(Int_t n) const
{
if ( n>=0 && n<fLength ) return (Char_t)(fData[n] >> 12) & 0x3F;
AliError("Index outside limits.");
return 0;
}
UShort_t AliMUONBusStruct::GetCharge(Int_t n) const
{
if ( n>=0 && n<fLength ) return (UShort_t)(fData[n] & 0xFFF);
AliError("Index outside limits.");
return 0;
}
void AliMUONBusStruct::Print(Option_t* opt) const
{
cout << "Bus patch info" << endl;
cout << "DataKey: " << fDataKey << endl;
cout << "fTotalLength: " << fTotalLength << endl;
cout << "fLength: " << fLength << endl;
cout << "fBusPatchId: " << fBusPatchId << endl;
cout << "fBufSize: " << fBufSize << endl;
if (strstr(opt, "all")) {
for (Int_t i = 0; i <fLength; ++i)
cout << "Data["<< i << "] = " << fData[i] << endl;
}
}