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