]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGPP/TRD/info/AliTRDtrendValue.cxx
various extensions
[u/mrichter/AliRoot.git] / PWGPP / TRD / info / AliTRDtrendValue.cxx
CommitLineData
61f6b45e 1////////////////////////////////////////////////////////////////////////////
2// //
3// Trend Value Incapsulation //
4// //
5// Authors: //
6// Alexandru Bercuci <A.Bercuci@gsi.de> //
7// //
8////////////////////////////////////////////////////////////////////////////
9
3240bb4a 10#include "TString.h"
11#include "TObjString.h"
12#include "TObjArray.h"
13
14#include "AliLog.h"
15#include "AliTRDtrendValue.h"
16
17ClassImp(AliTRDtrendValue)
18
19
20//____________________________________________
21AliTRDtrendValue::AliTRDtrendValue()
22 : TNamed("none", "none")
3240bb4a 23 ,fValue(0.)
847569f2 24 ,fSigma(1.)
25 ,fResponsible(NULL)
3240bb4a 26{
61f6b45e 27// Constructor. Reset all fields.
847569f2 28 //memset(fAlarmMessage, 0, kNlevels*sizeof(Char_t*));
29 memset(fNotifiable, 0, kNnotifiable*sizeof(TNamed*));
3240bb4a 30}
31
32//____________________________________________
847569f2 33AliTRDtrendValue::AliTRDtrendValue(const Char_t *n, const Char_t *t)
3240bb4a 34 : TNamed("none", t)
3240bb4a 35 ,fValue(0.)
847569f2 36 ,fSigma(1.)
37 ,fResponsible(NULL)
3240bb4a 38{
61f6b45e 39// Constructor. Define name and title for trend variable.
95d47440 40 if(strchr(GetName(),'_')!=strrchr(GetName(), '_')){
3240bb4a 41 AliError(Form("Wrong trend value name format. Trend value name should be of the form \"trendClass_trendValue\" with only one \"_\" character."));
42 } else SetName(n);
43
847569f2 44 //memset(fAlarmMessage, 0, kNlevels*sizeof(Char_t*));
45 memset(fNotifiable, 0, kNnotifiable*sizeof(TNamed*));
3240bb4a 46}
47
48//____________________________________________
847569f2 49AliTRDtrendValue::AliTRDtrendValue(const AliTRDtrendValue &ref)
50 : TNamed(ref)
51 ,fValue(ref.fValue)
52 ,fSigma(ref.fSigma)
53 ,fResponsible(NULL)
3240bb4a 54{
f036f7ec 55// Copy constructor
56
847569f2 57 if(ref.fResponsible) fResponsible = new TNamed(*ref.fResponsible);
58 //memset(fAlarmMessage, 0, kNlevels*sizeof(Char_t*));
59 //for(Int_t ia(0); ia<kNlevels; ia++) SetAlarm(ia, ref.fAlarmMessage[ia]);
60 memset(fNotifiable, 0, kNnotifiable*sizeof(TNamed*));
61 Int_t in(0);
62 while(ref.fNotifiable[in]){
63 fNotifiable[in] = new TNamed(*(ref.fNotifiable[in]));
64 in++;
65 }
66}
3240bb4a 67
95d47440 68//____________________________________________
69AliTRDtrendValue::~AliTRDtrendValue()
70{
71// destructor
72 if(fResponsible) delete fResponsible;
73 for(Int_t in(0); in<kNnotifiable; in++)
74 if(fNotifiable[in]) delete fNotifiable[in];
75}
76
847569f2 77//____________________________________________
78AliTRDtrendValue& AliTRDtrendValue::operator/=(const AliTRDtrendValue &n)
79{
80 fValue-=n.fValue;
81 if(n.fSigma>0.) fValue/=n.fSigma;
82 return *this;
3240bb4a 83}
84
85//____________________________________________
847569f2 86const char* AliTRDtrendValue::GetAlarmMessage(Int_t ns) const
3240bb4a 87{
61f6b45e 88// Check if value triggered alarm
847569f2 89 if(ns<0 || ns>kNlevels) return NULL;
90 else return "not defined";//fAlarmMessage[ns];
3240bb4a 91}
92
3240bb4a 93//____________________________________________
847569f2 94const char* AliTRDtrendValue::GetResponsible() const
3240bb4a 95{
61f6b45e 96// Get responsible with name and mail
847569f2 97 if(!fResponsible) return NULL;
98 return Form("%s <%s>", fResponsible->GetName(), fResponsible->GetTitle());
3240bb4a 99}
100
101//____________________________________________
847569f2 102const char* AliTRDtrendValue::GetNotifiable(Int_t in) const
3240bb4a 103{
61f6b45e 104// Get noticible person "in" with name and mail
60dd7ffe 105 if(in<0||in>=kNnotifiable) return NULL;
847569f2 106 if(!fNotifiable[in]) return NULL;
107 return Form("%s <%s>", fNotifiable[in]->GetName(), fNotifiable[in]->GetTitle());
108}
109
110//____________________________________________
111void AliTRDtrendValue::SetAlarm(Int_t level, Char_t */*m*/)
112{
113// define alarm message for "level"
114 if(level<0||level>=kNlevels){
115 AliWarning(Form("Alarm level[%d] out of range [0 %d]", level, kNlevels-1));
116 return;
117 }
118 //fAlarmMessage[level] = StrDup(m);
3240bb4a 119}
120
121//____________________________________________
122void AliTRDtrendValue::SetNotifiable(const Char_t *name, const Char_t *mail)
123{
61f6b45e 124// add noticible person to DB
847569f2 125 Int_t n(0); while(GetNotifiable(n)) n++;
126 if(n>=kNnotifiable-1){
127 AliWarning(Form("Could not add %s for notification. There are already %d persons registered for notification.", name, kNnotifiable-1));
3240bb4a 128 return;
129 }
847569f2 130 fNotifiable[n] = new TNamed(name, mail);
3240bb4a 131}
132
133//____________________________________________
847569f2 134void AliTRDtrendValue::SetResponsible(const Char_t *name, const Char_t *mail, Option_t *opt)
3240bb4a 135{
61f6b45e 136// set responsible person for trend
847569f2 137 if(fResponsible){
138 if(strcmp(opt, "u")!=0){
139 AliWarning(Form("Responsible already set %s <%s>", fResponsible->GetName(), fResponsible->GetTitle()));
140 return;
141 }else{
142 AliWarning(Form("Old responsible %s <%s> replaced by %s <%s>", fResponsible->GetName(), fResponsible->GetTitle(), name, mail));
143 new(fResponsible) TNamed(name, mail);
144 }
145 } else fResponsible = new TNamed(name, mail);
3240bb4a 146}
147
148//____________________________________________
149void AliTRDtrendValue::Print(Option_t */*o*/) const
150{
151// name - title
152// value - limits
153// alarm level, message
154// responsible
155
95d47440 156 const char* vn = strchr(GetName(), '_')+1;
157 Int_t cnLength = vn-GetName();
158 char *cn = new char[cnLength]; memcpy(cn, GetName(), (cnLength-1)*sizeof(char)); cn[cnLength-1]=0;
159 printf(" %s [%s] - %s\n", vn, cn, GetTitle());
847569f2 160 printf("*** %f +- %f\n", fValue, fSigma);
161 printf("*** Responsible %s <%s>\n", fResponsible?fResponsible->GetName():"", fResponsible?fResponsible->GetTitle():"");
162 printf("*** Notifiable person(s) ***\n");
163 Int_t in(0);
164 while(fNotifiable[in]){
165 printf(" %s <%s>\n", fNotifiable[in]->GetName(), fNotifiable[in]->GetTitle());
166 in++;
3240bb4a 167 }
847569f2 168/* printf("*** Alarm messages \n");
169 for(in=0; in<kNlevels; in++) printf("*** Alarm [%d] : %s\n", in, fAlarmMessage[in]?fAlarmMessage[in]:"not defined");*/
95d47440 170 delete [] cn;
3240bb4a 171}