]>
Commit | Line | Data |
---|---|---|
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 | ||
17 | ClassImp(AliTRDtrendValue) | |
18 | ||
19 | ||
20 | //____________________________________________ | |
21 | AliTRDtrendValue::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 | 33 | AliTRDtrendValue::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. |
3240bb4a | 40 | TString s(n); |
41 | TObjArray *names(s.Tokenize("_")); | |
42 | if(names->GetEntriesFast()!=2){ | |
43 | AliError(Form("Wrong trend value name format. Trend value name should be of the form \"trendClass_trendValue\" with only one \"_\" character.")); | |
44 | } else SetName(n); | |
45 | ||
847569f2 | 46 | //memset(fAlarmMessage, 0, kNlevels*sizeof(Char_t*)); |
47 | memset(fNotifiable, 0, kNnotifiable*sizeof(TNamed*)); | |
3240bb4a | 48 | } |
49 | ||
50 | //____________________________________________ | |
847569f2 | 51 | AliTRDtrendValue::AliTRDtrendValue(const AliTRDtrendValue &ref) |
52 | : TNamed(ref) | |
53 | ,fValue(ref.fValue) | |
54 | ,fSigma(ref.fSigma) | |
55 | ,fResponsible(NULL) | |
3240bb4a | 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 | |
847569f2 | 68 | //____________________________________________ |
69 | AliTRDtrendValue& AliTRDtrendValue::operator/=(const AliTRDtrendValue &n) | |
70 | { | |
71 | fValue-=n.fValue; | |
72 | if(n.fSigma>0.) fValue/=n.fSigma; | |
73 | return *this; | |
3240bb4a | 74 | } |
75 | ||
76 | //____________________________________________ | |
847569f2 | 77 | const char* AliTRDtrendValue::GetAlarmMessage(Int_t ns) const |
3240bb4a | 78 | { |
61f6b45e | 79 | // Check if value triggered alarm |
847569f2 | 80 | if(ns<0 || ns>kNlevels) return NULL; |
81 | else return "not defined";//fAlarmMessage[ns]; | |
3240bb4a | 82 | } |
83 | ||
84 | //____________________________________________ | |
85 | const char* AliTRDtrendValue::GetClassName() const | |
86 | { | |
61f6b45e | 87 | // Check task to which value belong |
3240bb4a | 88 | TString s(TNamed::GetName()); |
89 | TObjArray *names(s.Tokenize("_")); | |
90 | if(names->GetEntriesFast()!=2){ | |
91 | AliError(Form("Wrong trend value name format.")); | |
92 | return NULL; | |
93 | } | |
94 | ||
95 | return ((TObjString*)names->At(0))->String().Data(); | |
96 | } | |
97 | ||
98 | //____________________________________________ | |
99 | const char* AliTRDtrendValue::GetValueName() const | |
100 | { | |
61f6b45e | 101 | // value name |
3240bb4a | 102 | TString s(TNamed::GetName()); |
103 | TObjArray *names(s.Tokenize("_")); | |
104 | if(names->GetEntriesFast()!=2){ | |
105 | AliError(Form("Wrong trend value name format.")); | |
106 | return NULL; | |
107 | } | |
108 | return ((TObjString*)names->At(1))->String().Data(); | |
109 | } | |
110 | ||
111 | //____________________________________________ | |
847569f2 | 112 | const char* AliTRDtrendValue::GetResponsible() const |
3240bb4a | 113 | { |
61f6b45e | 114 | // Get responsible with name and mail |
847569f2 | 115 | if(!fResponsible) return NULL; |
116 | return Form("%s <%s>", fResponsible->GetName(), fResponsible->GetTitle()); | |
3240bb4a | 117 | } |
118 | ||
119 | //____________________________________________ | |
847569f2 | 120 | const char* AliTRDtrendValue::GetNotifiable(Int_t in) const |
3240bb4a | 121 | { |
61f6b45e | 122 | // Get noticible person "in" with name and mail |
847569f2 | 123 | if(in<0||in>kNnotifiable) return NULL; |
124 | if(!fNotifiable[in]) return NULL; | |
125 | return Form("%s <%s>", fNotifiable[in]->GetName(), fNotifiable[in]->GetTitle()); | |
126 | } | |
127 | ||
128 | //____________________________________________ | |
129 | void AliTRDtrendValue::SetAlarm(Int_t level, Char_t */*m*/) | |
130 | { | |
131 | // define alarm message for "level" | |
132 | if(level<0||level>=kNlevels){ | |
133 | AliWarning(Form("Alarm level[%d] out of range [0 %d]", level, kNlevels-1)); | |
134 | return; | |
135 | } | |
136 | //fAlarmMessage[level] = StrDup(m); | |
3240bb4a | 137 | } |
138 | ||
139 | //____________________________________________ | |
140 | void AliTRDtrendValue::SetNotifiable(const Char_t *name, const Char_t *mail) | |
141 | { | |
61f6b45e | 142 | // add noticible person to DB |
847569f2 | 143 | Int_t n(0); while(GetNotifiable(n)) n++; |
144 | if(n>=kNnotifiable-1){ | |
145 | AliWarning(Form("Could not add %s for notification. There are already %d persons registered for notification.", name, kNnotifiable-1)); | |
3240bb4a | 146 | return; |
147 | } | |
847569f2 | 148 | fNotifiable[n] = new TNamed(name, mail); |
3240bb4a | 149 | } |
150 | ||
151 | //____________________________________________ | |
847569f2 | 152 | void AliTRDtrendValue::SetResponsible(const Char_t *name, const Char_t *mail, Option_t *opt) |
3240bb4a | 153 | { |
61f6b45e | 154 | // set responsible person for trend |
847569f2 | 155 | if(fResponsible){ |
156 | if(strcmp(opt, "u")!=0){ | |
157 | AliWarning(Form("Responsible already set %s <%s>", fResponsible->GetName(), fResponsible->GetTitle())); | |
158 | return; | |
159 | }else{ | |
160 | AliWarning(Form("Old responsible %s <%s> replaced by %s <%s>", fResponsible->GetName(), fResponsible->GetTitle(), name, mail)); | |
161 | new(fResponsible) TNamed(name, mail); | |
162 | } | |
163 | } else fResponsible = new TNamed(name, mail); | |
3240bb4a | 164 | } |
165 | ||
166 | //____________________________________________ | |
167 | void AliTRDtrendValue::Print(Option_t */*o*/) const | |
168 | { | |
169 | // name - title | |
170 | // value - limits | |
171 | // alarm level, message | |
172 | // responsible | |
173 | ||
174 | printf(" %s [%s] - %s\n", GetValueName(), GetClassName(), GetTitle()); | |
847569f2 | 175 | printf("*** %f +- %f\n", fValue, fSigma); |
176 | printf("*** Responsible %s <%s>\n", fResponsible?fResponsible->GetName():"", fResponsible?fResponsible->GetTitle():""); | |
177 | printf("*** Notifiable person(s) ***\n"); | |
178 | Int_t in(0); | |
179 | while(fNotifiable[in]){ | |
180 | printf(" %s <%s>\n", fNotifiable[in]->GetName(), fNotifiable[in]->GetTitle()); | |
181 | in++; | |
3240bb4a | 182 | } |
847569f2 | 183 | /* printf("*** Alarm messages \n"); |
184 | for(in=0; in<kNlevels; in++) printf("*** Alarm [%d] : %s\n", in, fAlarmMessage[in]?fAlarmMessage[in]:"not defined");*/ | |
3240bb4a | 185 | } |