]>
Commit | Line | Data |
---|---|---|
3240bb4a | 1 | #include "TObjArray.h" |
2 | #include "AliLog.h" | |
3 | #include "AliCDBRunRange.h" | |
4 | #include "AliCDBManager.h" | |
5 | #include "AliCDBMetaData.h" | |
6 | #include "AliCDBStorage.h" | |
7 | #include "AliTRDcalibDB.h" | |
8 | #include "AliTRDtrendingManager.h" | |
9 | ||
10 | ClassImp(AliTRDtrendingManager) | |
11 | ||
12 | AliTRDtrendingManager* AliTRDtrendingManager::fgInstance=NULL; | |
13 | Bool_t AliTRDtrendingManager::fgTerminated = kFALSE; | |
14 | ||
15 | //____________________________________________ | |
16 | AliTRDtrendingManager* AliTRDtrendingManager::Instance() | |
17 | { | |
18 | // | |
19 | // Singleton implementation | |
20 | // Returns an instance of this class, it is created if neccessary | |
21 | // | |
22 | if (fgTerminated != kFALSE) return NULL; | |
23 | ||
24 | if (!fgInstance) { | |
25 | fgInstance = new AliTRDtrendingManager(); | |
26 | AliTRDcalibDB *trd(AliTRDcalibDB::Instance()); | |
27 | if(!trd){ | |
28 | AliWarningGeneral("AliTRDtrendingManager", "TRD OCDB manager not initialized. No trending DB available."); | |
29 | } else { | |
addaf7de | 30 | const TObjArray *trendMap(NULL/*trd->GetTrendMap()*/); |
3240bb4a | 31 | if(!trendMap){ |
32 | AliWarningGeneral("AliTRDtrendingManager", "No TRD trending DB available for TRD."); | |
33 | } else fgInstance->fEntries=(TObjArray*)trendMap->Clone(); | |
34 | } | |
35 | } | |
36 | ||
37 | return fgInstance; | |
38 | } | |
39 | ||
40 | //____________________________________________ | |
41 | void AliTRDtrendingManager::Terminate() | |
42 | { | |
43 | // | |
44 | // Singleton implementation | |
45 | // Deletes the instance of this class and sets the terminated flag, | |
46 | // instances cannot be requested anymore | |
47 | // This function can be called several times. | |
48 | // | |
49 | ||
50 | fgTerminated = kTRUE; | |
51 | ||
52 | if (fgInstance != NULL) { | |
53 | delete fgInstance; | |
54 | fgInstance = NULL; | |
55 | } | |
56 | } | |
57 | ||
58 | //____________________________________________ | |
59 | AliTRDtrendingManager::AliTRDtrendingManager() | |
60 | : TObject() | |
61 | ,fEntries(NULL) | |
62 | ,fValue(NULL) | |
63 | { | |
64 | fRunRange[0] = 0; fRunRange[1] = AliCDBRunRange::Infinity(); | |
65 | } | |
66 | ||
67 | //____________________________________________ | |
68 | AliTRDtrendingManager::~AliTRDtrendingManager() | |
69 | { | |
70 | if(fValue) delete fValue; | |
71 | if(fEntries) delete fEntries; | |
72 | } | |
73 | ||
74 | //____________________________________________ | |
75 | void AliTRDtrendingManager::AddValue( | |
76 | Char_t *class_name | |
77 | ,Char_t *name | |
78 | ,Char_t *title | |
79 | ,Double_t limits[2*(AliTRDtrendValue::kNlevels+1)] | |
80 | ,Char_t *messages[AliTRDtrendValue::kNlevels] | |
81 | ,Char_t *responsible | |
82 | ,Char_t *notifiables | |
83 | ) | |
84 | { | |
85 | // Expert Function !!! | |
86 | // Add a trend value to the map already loaded | |
87 | // If no map loaded create a new one from scratch | |
88 | // | |
89 | // class_name : name of the performance task | |
90 | // name : name of the value to be trended | |
91 | // title : description of the value to be trended | |
92 | // limits : array of acceptance limits for this value. The array is organized as follows : | |
93 | // - field 0 and 1 normal limits | |
94 | // - field 2 and 3 first level of alarm | |
95 | // - .... | |
96 | // - field 8 and 9 fourth level of alarm | |
97 | // messages : array of alarm messages for each alarm level | |
98 | // responsible: name and email of the responsible person. Format "name/email" | |
99 | // notifiables: name and email of the notifiable persons. Format "name1/email1, name2/email2, etc" | |
100 | // | |
101 | AliWarning("*** EXPERT FUNCTION *** This function is adding one trending value to the current DB. Continue if you know what yout do!"); | |
102 | ||
103 | // create new trending value` | |
104 | if(!fValue) fValue = new AliTRDtrendValue(Form("%s_%s", class_name, name), title); | |
105 | else new(fValue) AliTRDtrendValue(Form("%s_%s", class_name, name), title); | |
106 | fValue->SetLimits(limits); | |
107 | for(Int_t ilevel(AliTRDtrendValue::kNlevels); ilevel--;) fValue->SetAlarm(ilevel, messages[ilevel]); | |
108 | TString s(responsible); | |
109 | TObjArray *r=s.Tokenize("/"); | |
110 | if(r->GetEntriesFast()!=2){ | |
111 | AliWarning("Responsible name/email incorrectly formated."); | |
112 | } else { | |
113 | fValue->SetResponsible(((TObjString*)r->At(0))->String().Data(), ((TObjString*)r->At(1))->String().Data()); | |
114 | } | |
115 | if(notifiables){ | |
116 | s=notifiables; | |
117 | TObjArray *n=s.Tokenize(","); | |
118 | for(Int_t in(0); in<TMath::Min(AliTRDtrendValue::kNnotifiable, n->GetEntriesFast()); in++){ | |
119 | TString ss(((TObjString*)n->At(in))->String()); | |
120 | r=ss.Tokenize("/"); | |
121 | if(r->GetEntriesFast()!=2){ | |
122 | AliWarning(Form("Notifiable person name/email incorrectly formated for [%s].", ss.Data())); | |
123 | } else { | |
124 | fValue->SetNotifiable(((TObjString*)r->At(0))->String().Data(), ((TObjString*)r->At(1))->String().Data()); | |
125 | } | |
126 | } | |
127 | } | |
128 | // if no trending map defined create one | |
129 | if(!fEntries){ | |
130 | AliInfo("No trending map loaded. Create one from scratch."); | |
131 | fEntries = new TObjArray(50); | |
132 | fEntries->SetOwner(); | |
133 | } | |
134 | ||
135 | fEntries->AddLast(new AliTRDtrendValue(*fValue)); | |
136 | } | |
137 | ||
138 | //____________________________________________ | |
139 | AliTRDtrendValue* AliTRDtrendingManager::GetValue(Char_t *class_name, Char_t *value_name) | |
140 | { | |
141 | if(!fEntries){ | |
142 | AliError("No trending map defined."); | |
143 | return NULL; | |
144 | } | |
145 | AliTRDtrendValue *val((AliTRDtrendValue*)fEntries->FindObject(Form("%s_%s", class_name, value_name))); | |
146 | if(!val){ | |
147 | AliError(Form("Missing trending value %s [%s]", value_name, class_name)); | |
148 | fEntries->ls(); | |
149 | } | |
150 | return val; | |
151 | } | |
152 | ||
153 | //____________________________________________ | |
154 | Bool_t AliTRDtrendingManager::ModifyValue( | |
155 | Char_t *class_name | |
156 | ,Char_t *name | |
157 | ,Char_t *title | |
158 | ,Double_t *limits | |
159 | ,Char_t **messages | |
160 | ,Char_t *responsible | |
161 | ,Char_t *notifiables | |
162 | ) | |
163 | { | |
164 | // Expert Function !!! | |
165 | // Modify a trend value in the map already loaded | |
166 | // see function AddValue() for explanation of input format. | |
167 | ||
168 | if(!fEntries){ | |
169 | AliError("No trending map loaded."); | |
170 | return kFALSE; | |
171 | } | |
172 | AliWarning("*** EXPERT FUNCTION *** This function is modifying one trending value to the current DB. Continue if you know what yout do!"); | |
173 | ||
174 | AliTRDtrendValue *val((AliTRDtrendValue*)fEntries->FindObject(Form("%s_%s", class_name, name))); | |
175 | if(!val){ | |
176 | AliError(Form("Missing trending value %s [%s]", name, class_name)); | |
177 | return kFALSE; | |
178 | } | |
179 | ||
180 | val->SetTitle(title); | |
181 | if(limits) val->SetLimits(limits); | |
182 | if(messages){ | |
183 | for(Int_t ilevel(AliTRDtrendValue::kNlevels); ilevel--;) val->SetAlarm(ilevel, messages[ilevel]); | |
184 | } | |
185 | TString s; | |
186 | TObjArray *r(NULL); | |
187 | if(responsible){ | |
188 | s=responsible; | |
189 | r=s.Tokenize("/"); | |
190 | if(r->GetEntriesFast()!=2){ | |
191 | AliWarning("Responsible name/email incorrectly formated."); | |
192 | } else { | |
193 | val->SetResponsible(((TObjString*)r->At(0))->String().Data(), ((TObjString*)r->At(1))->String().Data()); | |
194 | } | |
195 | } | |
196 | if(notifiables){ | |
197 | s=notifiables; | |
198 | TObjArray *n=s.Tokenize(","); | |
199 | for(Int_t in(0); in<TMath::Min(AliTRDtrendValue::kNnotifiable, n->GetEntriesFast()); in++){ | |
200 | TString ss(((TObjString*)n->At(in))->String()); | |
201 | r=ss.Tokenize("/"); | |
202 | if(r->GetEntriesFast()!=2){ | |
203 | AliWarning(Form("Notifiable person name/email incorrectly formated for [%s].", ss.Data())); | |
204 | } else { | |
205 | val->SetNotifiable(((TObjString*)r->At(0))->String().Data(), ((TObjString*)r->At(1))->String().Data()); | |
206 | } | |
207 | } | |
208 | } | |
209 | return kTRUE; | |
210 | } | |
211 | ||
212 | //____________________________________________ | |
213 | void AliTRDtrendingManager::Print(Option_t *o) const | |
214 | { | |
215 | if(!fEntries){ | |
216 | AliError("No trending map available."); | |
217 | return; | |
218 | } | |
219 | ||
220 | for(Int_t iv(0); iv<fEntries->GetEntriesFast(); iv++){ | |
221 | ((AliTRDtrendValue*)fEntries->At(iv))->Print(o); | |
222 | } | |
223 | } | |
224 | ||
225 | //____________________________________________ | |
226 | void AliTRDtrendingManager::Save() | |
227 | { | |
228 | // Saving TRD trending DB to $ALICE_ROOT/OCDB. | |
229 | ||
230 | AliWarning("Saving TRD trending DB to $ALICE_ROOT/OCDB."); | |
231 | ||
232 | AliCDBMetaData *metaData= new AliCDBMetaData(); | |
233 | metaData->SetObjectClassName("TObjArray"); | |
234 | metaData->SetResponsible("Alexander Wilk"); | |
235 | metaData->SetBeamPeriod(1); | |
236 | metaData->SetAliRootVersion("05-21-01"); //root version | |
237 | metaData->SetComment("TRD trending "); | |
238 | ||
239 | AliCDBId id("TRD/Calib/Trend", fRunRange[0], fRunRange[1]); | |
240 | AliCDBManager *man = AliCDBManager::Instance(); | |
241 | AliCDBStorage *gStorLoc = man->GetStorage("local://$ALICE_ROOT/OCDB"); | |
242 | if (!gStorLoc) { | |
243 | return; | |
244 | } | |
245 | gStorLoc->Put(fEntries, id, metaData); | |
246 | } |