#include "TString.h"
#include "TObjString.h"
#include "TObjArray.h"
#include "AliLog.h"
#include "AliTRDtrendValue.h"
ClassImp(AliTRDtrendValue)
AliTRDtrendValue::AliTRDtrendValue()
: TNamed("none", "none")
,fValue(0.)
,fSigma(1.)
,fResponsible(NULL)
{
memset(fNotifiable, 0, kNnotifiable*sizeof(TNamed*));
}
AliTRDtrendValue::AliTRDtrendValue(const Char_t *n, const Char_t *t)
: TNamed("none", t)
,fValue(0.)
,fSigma(1.)
,fResponsible(NULL)
{
if(strchr(GetName(),'_')!=strrchr(GetName(), '_')){
AliError(Form("Wrong trend value name format. Trend value name should be of the form \"trendClass_trendValue\" with only one \"_\" character."));
} else SetName(n);
memset(fNotifiable, 0, kNnotifiable*sizeof(TNamed*));
}
AliTRDtrendValue::AliTRDtrendValue(const AliTRDtrendValue &ref)
: TNamed(ref)
,fValue(ref.fValue)
,fSigma(ref.fSigma)
,fResponsible(NULL)
{
if(ref.fResponsible) fResponsible = new TNamed(*ref.fResponsible);
memset(fNotifiable, 0, kNnotifiable*sizeof(TNamed*));
Int_t in(0);
while(ref.fNotifiable[in]){
fNotifiable[in] = new TNamed(*(ref.fNotifiable[in]));
in++;
}
}
AliTRDtrendValue::~AliTRDtrendValue()
{
if(fResponsible) delete fResponsible;
for(Int_t in(0); in<kNnotifiable; in++)
if(fNotifiable[in]) delete fNotifiable[in];
}
AliTRDtrendValue& AliTRDtrendValue::operator/=(const AliTRDtrendValue &n)
{
fValue-=n.fValue;
if(n.fSigma>0.) fValue/=n.fSigma;
return *this;
}
const char* AliTRDtrendValue::GetAlarmMessage(Int_t ns) const
{
if(ns<0 || ns>kNlevels) return NULL;
else return "not defined";
}
const char* AliTRDtrendValue::GetResponsible() const
{
if(!fResponsible) return NULL;
return Form("%s <%s>", fResponsible->GetName(), fResponsible->GetTitle());
}
const char* AliTRDtrendValue::GetNotifiable(Int_t in) const
{
if(in<0||in>=kNnotifiable) return NULL;
if(!fNotifiable[in]) return NULL;
return Form("%s <%s>", fNotifiable[in]->GetName(), fNotifiable[in]->GetTitle());
}
void AliTRDtrendValue::SetAlarm(Int_t level, Char_t *)
{
if(level<0||level>=kNlevels){
AliWarning(Form("Alarm level[%d] out of range [0 %d]", level, kNlevels-1));
return;
}
}
void AliTRDtrendValue::SetNotifiable(const Char_t *name, const Char_t *mail)
{
Int_t n(0); while(GetNotifiable(n)) n++;
if(n>=kNnotifiable-1){
AliWarning(Form("Could not add %s for notification. There are already %d persons registered for notification.", name, kNnotifiable-1));
return;
}
fNotifiable[n] = new TNamed(name, mail);
}
void AliTRDtrendValue::SetResponsible(const Char_t *name, const Char_t *mail, Option_t *opt)
{
if(fResponsible){
if(strcmp(opt, "u")!=0){
AliWarning(Form("Responsible already set %s <%s>", fResponsible->GetName(), fResponsible->GetTitle()));
return;
}else{
AliWarning(Form("Old responsible %s <%s> replaced by %s <%s>", fResponsible->GetName(), fResponsible->GetTitle(), name, mail));
new(fResponsible) TNamed(name, mail);
}
} else fResponsible = new TNamed(name, mail);
}
void AliTRDtrendValue::Print(Option_t *) const
{
const char* vn = strchr(GetName(), '_')+1;
Int_t cnLength = vn-GetName();
char *cn = new char[cnLength]; memcpy(cn, GetName(), (cnLength-1)*sizeof(char)); cn[cnLength-1]=0;
printf(" %s [%s] - %s\n", vn, cn, GetTitle());
printf("*** %f +- %f\n", fValue, fSigma);
printf("*** Responsible %s <%s>\n", fResponsible?fResponsible->GetName():"", fResponsible?fResponsible->GetTitle():"");
printf("*** Notifiable person(s) ***\n");
Int_t in(0);
while(fNotifiable[in]){
printf(" %s <%s>\n", fNotifiable[in]->GetName(), fNotifiable[in]->GetTitle());
in++;
}
delete [] cn;
}