]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG1/TRD/info/AliTRDtrendValue.cxx
fix coverity
[u/mrichter/AliRoot.git] / PWG1 / TRD / info / AliTRDtrendValue.cxx
1 ////////////////////////////////////////////////////////////////////////////
2 //                                                                        //
3 //  Trend Value Incapsulation                                             //
4 //                                                                        //
5 //  Authors:                                                              //
6 //    Alexandru Bercuci <A.Bercuci@gsi.de>                                //
7 //                                                                        //
8 ////////////////////////////////////////////////////////////////////////////
9
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")
23   ,fAlarmLevel(0)
24   ,fValue(0.)
25   ,fResponsible()
26   ,fNnotifiable(0)
27 {
28 //  Constructor. Reset all fields.
29   memset(fLimits, 0, 2*(kNlevels+1)*sizeof(Double_t));
30   for(Int_t ilevel(kNlevels); ilevel--; ) snprintf(fAlarmMessage[ilevel], 1024, " ");
31 }
32
33 //____________________________________________
34 AliTRDtrendValue::AliTRDtrendValue(Char_t *n, Char_t *t) 
35   : TNamed("none", t)
36   ,fAlarmLevel(0)
37   ,fValue(0.)
38   ,fResponsible()
39   ,fNnotifiable(0)
40 {
41 //  Constructor. Define name and title for trend variable.
42   TString s(n);
43   TObjArray *names(s.Tokenize("_"));
44   if(names->GetEntriesFast()!=2){
45     AliError(Form("Wrong trend value name format. Trend value name should be of the form \"trendClass_trendValue\" with only one \"_\" character."));
46   } else SetName(n);
47
48   memset(fLimits, 0, 2*(kNlevels+1)*sizeof(Double_t));
49   for(Int_t ilevel(kNlevels); ilevel--; ) snprintf(fAlarmMessage[ilevel], 1024, " ");
50 }
51
52 //____________________________________________
53 Int_t AliTRDtrendValue::GetAlarmLevel()
54 {
55   // check value against limits and do some more work
56   fAlarmLevel=kNlevels-1;
57   for(Int_t ilevel(0); ilevel<kNlevels+1; ilevel++)
58     if(fValue<fLimits[2*ilevel+1] &&
59        fValue>=fLimits[2*ilevel]){ 
60       fAlarmLevel = ilevel;
61       break;
62     }
63
64   return fAlarmLevel;
65 }
66
67 //____________________________________________
68 const char* AliTRDtrendValue::GetAlarmMessage() const
69 {
70 // Check if value triggered alarm
71   if(!fAlarmLevel) return "OK";
72   else return fAlarmMessage[fAlarmLevel-1];
73 }
74
75 //____________________________________________
76 const char* AliTRDtrendValue::GetClassName() const
77 {
78 // Check task to which value belong
79   TString s(TNamed::GetName());
80   TObjArray *names(s.Tokenize("_"));
81   if(names->GetEntriesFast()!=2){
82     AliError(Form("Wrong trend value name format."));
83     return NULL;
84   }
85
86   return ((TObjString*)names->At(0))->String().Data();
87 }
88
89 //____________________________________________
90 const char* AliTRDtrendValue::GetValueName() const
91 {
92 // value name
93   TString s(TNamed::GetName());
94   TObjArray *names(s.Tokenize("_"));
95   if(names->GetEntriesFast()!=2){
96     AliError(Form("Wrong trend value name format."));
97     return NULL;
98   }
99   return ((TObjString*)names->At(1))->String().Data();
100 }
101
102 //____________________________________________
103 const char* AliTRDtrendValue::GetResponsible(Char_t *n, Char_t *mail) const
104 {
105 // Get responsible with name and mail
106   if(n) snprintf(n, 100, "%s", fResponsible.fNameR);
107   if(mail) snprintf(mail, 200, "%s", fResponsible.fMail);
108   return Form("%s <%s>", fResponsible.fNameR, fResponsible.fMail);
109 }
110
111 //____________________________________________
112 const char* AliTRDtrendValue::GetNotifiable(Int_t in, Char_t *n, Char_t *mail) const
113 {
114 // Get noticible person "in" with name and mail
115   if(in<0||in>=fNnotifiable) return NULL;
116   if(n) snprintf(n, 100, "%s", fNotifiable[in].fNameR);
117   if(mail) snprintf(mail, 200, "%s", fNotifiable[in].fMail);
118   return Form("%s <%s>", fNotifiable[in].fNameR, fNotifiable[in].fMail);
119 }
120
121 //____________________________________________
122 void AliTRDtrendValue::SetNotifiable(const Char_t *name, const Char_t *mail)
123 {
124 // add noticible person to DB
125   if(fNnotifiable==kNnotifiable){
126     AliWarning(Form("Could not add %s for notification. Only %d persons can be registered for notification.", name, kNnotifiable));
127     return;
128   }
129   snprintf(fNotifiable[fNnotifiable].fNameR, 100, "%s", name);
130   snprintf(fNotifiable[fNnotifiable].fMail, 200, "%s", mail);
131   fNnotifiable++;
132 }
133
134 //____________________________________________
135 void AliTRDtrendValue::SetResponsible(const Char_t *name, const Char_t *mail) 
136 {
137 // set responsible person for trend
138   snprintf(fResponsible.fNameR, 100, "%s", name);
139   snprintf(fResponsible.fMail, 200, "%s", mail);
140 }
141
142 //____________________________________________
143 void AliTRDtrendValue::Print(Option_t */*o*/) const
144 {
145 //   name - title
146 //   value - limits
147 //   alarm level, message
148 //   responsible
149
150   printf("    %s [%s] - %s\n", GetValueName(), GetClassName(), GetTitle());
151   printf("*** %f limits[%f %f]\n", fValue, fLimits[0], fLimits[1]);
152   if(fAlarmLevel){
153     printf("*** Alarm level   : %d limits[%f %f]\n", fAlarmLevel, fLimits[2*fAlarmLevel], fLimits[2*fAlarmLevel+1]);
154     printf("*** Alarm message : %s\n", GetAlarmMessage());
155   }
156   printf("*** Responsible %s <%s>\n", fResponsible.fNameR, fResponsible.fMail);
157   if(fNnotifiable){
158     printf("*** Notifiable person(s) ***\n");
159     for(Int_t i(0); i<fNnotifiable; i++)
160       printf("        %s <%s>\n", fNotifiable[i].fNameR, fNotifiable[i].fMail);
161   }
162 }
163
164 //____________________________________________
165 AliTRDtrendValue::AliTRDtrendValueResponsible::AliTRDtrendValueResponsible(Char_t *n, Char_t *m) 
166 {
167 // define person with mail and mail
168   if(n) snprintf(fNameR, 100, "%s", n); else snprintf(fNameR, 100, " ");
169   if(m) snprintf(fMail, 200, "%s", m); else snprintf(fMail, 200, " ");
170 }