#include "AliDCSValue.h"
#include "AliLog.h"
#include "TTimeStamp.h"
#include <TString.h>
ClassImp(AliDCSValue)
AliDCSValue::AliDCSValue() :
TObject(),
fType(kInvalid),
fBool(kFALSE),
fChar(0),
fInt(0),
fUInt(0),
fFloat(0),
fTimeStamp(0)
{
}
AliDCSValue::AliDCSValue(Bool_t value, UInt_t timeStamp) :
TObject(),
fType(kBool),
fBool(value),
fChar(0),
fInt(0),
fUInt(0),
fFloat(0),
fTimeStamp(timeStamp)
{
}
AliDCSValue::AliDCSValue(Char_t value, UInt_t timeStamp) :
TObject(),
fType(kChar),
fBool(kFALSE),
fChar(value),
fInt(0),
fUInt(0),
fFloat(0),
fTimeStamp(timeStamp)
{
}
AliDCSValue::AliDCSValue(Int_t value, UInt_t timeStamp) :
TObject(),
fType(kInt),
fBool(kFALSE),
fChar(0),
fInt(value),
fUInt(0),
fFloat(0),
fTimeStamp(timeStamp)
{
}
AliDCSValue::AliDCSValue(UInt_t value, UInt_t timeStamp) :
TObject(),
fType(kUInt),
fBool(kFALSE),
fChar(0),
fInt(0),
fUInt(value),
fFloat(0),
fTimeStamp(timeStamp)
{
}
AliDCSValue::AliDCSValue(Float_t value, UInt_t timeStamp) :
TObject(),
fType(kFloat),
fBool(kFALSE),
fChar(0),
fInt(0),
fUInt(0),
fFloat(value),
fTimeStamp(timeStamp)
{
Init();
fTimeStamp = timeStamp;
fType = kFloat;
fFloat = value;
}
AliDCSValue::AliDCSValue(const AliDCSValue& c) :
TObject(c),
fType(c.fType),
fBool(c.fBool),
fChar(c.fChar),
fInt(c.fInt),
fUInt(c.fUInt),
fFloat(c.fFloat),
fTimeStamp(c.fTimeStamp)
{
}
void AliDCSValue::Init()
{
fType = kInvalid;
fBool = kFALSE;
fChar = 0;
fInt = 0;
fUInt = 0;
fFloat = 0;
fTimeStamp = 0;
}
AliDCSValue::~AliDCSValue()
{
}
AliDCSValue &AliDCSValue::operator=(const AliDCSValue &c)
{
if (this != &c)
((AliDCSValue &) c).Copy(*this);
return *this;
}
void AliDCSValue::Copy(TObject& c) const
{
AliDCSValue& target = (AliDCSValue &) c;
target.Init();
target.fType = fType;
target.fBool = fBool;
target.fChar = fChar;
target.fInt = fInt;
target.fUInt = fUInt;
target.fFloat = fFloat;
target.fTimeStamp = fTimeStamp;
}
Int_t AliDCSValue::GetSize() const
{
Int_t size = sizeof(fTimeStamp);
switch (fType)
{
case kBool: size += sizeof(Bool_t); break;
case kChar: size += sizeof(Char_t); break;
case kInt: size += sizeof(Int_t); break;
case kUInt: size += sizeof(UInt_t); break;
case kFloat: size += sizeof(Float_t); break;
case kInvalid: break;
}
return size;
}
const Char_t* AliDCSValue::ToString() const
{
TString str;
switch (fType)
{
case kBool: str = (fBool == kFALSE) ? "FALSE" : "TRUE"; break;
case kChar: str.Form("%d", fChar); break;
case kInt: str.Form("%d", fInt); break;
case kUInt: str.Form("%d", fUInt); break;
case kFloat: str.Form("%f", fFloat); break;
case kInvalid: break;
}
return Form("%s Timestamp: %s (%d)", str.Data(), TTimeStamp(fTimeStamp).AsString(), fTimeStamp);
}
void AliDCSValue::Print(Option_t* ) const
{
printf("%s\n", ToString());
}
Bool_t AliDCSValue::GetBool() const
{
if (fType!=kBool) AliError(Form("invalid request, object is not of type kBool (%d) but %d", kBool, fType));
return fBool;
}
Char_t AliDCSValue::GetChar() const
{
if (fType!=kChar) AliError(Form("invalid request, object is not of type kChar (%d) but %d", kChar, fType));
return fChar;
}
Int_t AliDCSValue::GetInt() const
{
if (fType!=kInt) AliError(Form("invalid request, object is not of type kInt (%d) but %d", kInt, fType));
return fInt;
}
UInt_t AliDCSValue::GetUInt() const
{
if (fType!=kUInt) AliError(Form("invalid request, object is not of type kUInt (%d) but %d", kUInt, fType));
return fUInt;
}
Float_t AliDCSValue::GetFloat() const
{
if (fType!=kFloat) AliError(Form("invalid request, object is not of type kFloat (%d) but %d", kFloat, fType));
return fFloat;
}