1 ////////////////////////////////////////////////////////////////////////////
3 // Trend Value Manager //
5 // Mediates interaction with DB (OCDB ?!) // // //
7 // Alexandru Bercuci <A.Bercuci@gsi.de> //
9 ////////////////////////////////////////////////////////////////////////////
13 #include "TObjArray.h"
21 #include "AliTRDtrendingManager.h"
23 ClassImp(AliTRDtrendingManager)
25 AliTRDtrendingManager* AliTRDtrendingManager::fgInstance=NULL;
26 Bool_t AliTRDtrendingManager::fgTerminated = kFALSE;
28 //____________________________________________
29 AliTRDtrendingManager* AliTRDtrendingManager::Instance()
32 // Singleton implementation
33 // Returns an instance of this class, it is created if neccessary
35 if (fgTerminated != kFALSE) return NULL;
37 if (!fgInstance) fgInstance = new AliTRDtrendingManager();
42 //____________________________________________
43 void AliTRDtrendingManager::Terminate()
46 // Singleton implementation
47 // Deletes the instance of this class and sets the terminated flag,
48 // instances cannot be requested anymore
49 // This function can be called several times.
54 if (fgInstance != NULL) {
55 if(TFile::Open("TRD.Trend.root", "RECREATE")){
59 delete fgInstance; fgInstance = NULL;
63 //____________________________________________
64 AliTRDtrendingManager::AliTRDtrendingManager()
70 // fRunRange[0] = 0; fRunRange[1] = AliCDBRunRange::Infinity();
73 //____________________________________________
74 AliTRDtrendingManager::~AliTRDtrendingManager()
77 if(fValue) delete fValue;
78 if(fEntries) delete fEntries;
81 //____________________________________________
82 void AliTRDtrendingManager::AddValue(
84 ,Double_t mean,Double_t sigm
86 ,const Char_t *responsible
87 ,const Char_t *notifiables
91 // Expert Function !!!
92 // Add a trend value to the map already loaded
93 // If no map loaded create a new one from scratch
95 // class_name : name of the performance task
96 // name : name of the value to be trended
97 // title : description of the value to be trended
98 // messages : array of alarm messages for each alarm level
99 // responsible: name and email of the responsible person. Format "name/email"
100 // notifiables: name and email of the notifiable persons. Format "name1/email1, name2/email2, etc"
103 if(!fEntries){ // if no trending map defined create one
104 AliDebug(1, "No trending map loaded. Create one from scratch.");
105 fEntries = new TObjArray(50);
106 fEntries->SetOwner();
107 fEntries->SetName("values");
110 if(!(fValue = GetValue(name))){
111 // create new trending value`
112 fValue = new AliTRDtrendValue(name, title?title:"");
113 fValue->Set(mean, sigm);
114 if(messages) for(Int_t ilevel(AliTRDtrendValue::kNlevels); ilevel--;) if(messages[ilevel]) fValue->SetAlarm(ilevel, messages[ilevel]);
117 TString s(responsible);
119 if(r->GetEntriesFast()!=2){
120 AliWarning("Responsible name/email incorrectly formated.");
122 fValue->SetResponsible(((TObjString*)r->At(0))->String().Data(), ((TObjString*)r->At(1))->String().Data());
126 TString s(notifiables);
127 TObjArray *n=s.Tokenize(",");
128 for(Int_t in(0); in<TMath::Min(AliTRDtrendValue::kNnotifiable, n->GetEntriesFast()); in++){
129 TString ss(((TObjString*)n->At(in))->String());
131 if(r->GetEntriesFast()!=2){
132 AliWarning(Form("Notifiable person name/email incorrectly formated for [%s].", ss.Data()));
134 fValue->SetNotifiable(((TObjString*)r->At(0))->String().Data(), ((TObjString*)r->At(1))->String().Data());
140 fEntries->AddLast(new AliTRDtrendValue(*fValue));
143 //____________________________________________
144 AliTRDtrendValue* AliTRDtrendingManager::GetValue(const Char_t *name)
146 // Search trend value list by value "name" formatted according to "class_name"
148 AliError("No trending map defined.");
151 fValue = (AliTRDtrendValue*)fEntries->FindObject(name);
155 //____________________________________________
156 Bool_t AliTRDtrendingManager::MakeTrends(const char *fileList)
158 // Make trends with reference to DB for all trend files in "fileList".
159 // The DB should be loaded
161 AliWarning("Trending map undefined");
164 Int_t ntv(fEntries->GetEntries());
167 if(!(fp= fopen(fileList, "rt"))){
168 AliWarning(Form("Can not open file list \"%s\"", fileList));
172 TGraph **g = new TGraph*[ntv]; memset(g, 0, ntv*sizeof(TGraph*));
173 AliTRDtrendValue *TV(NULL), *tv(NULL);
174 TString sfp; Int_t run[10000], nr(0);
176 // guess run no from path. Do we need a more robust approach ?
177 TObjArray *afp=sfp.Tokenize("/");
178 Int_t idx = afp->GetEntries()-2;
179 Int_t rno = ((TObjString*)(*afp)[idx])->GetString().Atoi();
181 if(!TFile::Open(sfp.Data())) continue;
183 for(Int_t it(0); it<ntv; it++){
184 if(!(TV = (AliTRDtrendValue*)fEntries->At(it))) continue;
185 if(!(tv = (AliTRDtrendValue*)gFile->Get(TV->GetName()))) {
186 AliWarning(Form("Missing %09d.%s", rno, TV->GetName()));
191 g[it] = new TGraph();
192 g[it]->SetNameTitle(TV->GetName(), TV->GetTitle());
193 g[it]->SetMarkerStyle(4);g[it]->SetMarkerSize(0.8);
195 g[it]->SetPoint(g[it]->GetN(), nr, tv->GetVal());
201 TH1 *hT = new TH1F("hT", ";#bf{RUN};", nr, -0.5, nr-0.5);
202 TAxis *ax = hT->GetXaxis(); ax->SetTitleOffset(2.6);ax->CenterTitle(); ax->SetBit(TAxis::kLabelsVert);
203 TAxis *ay = hT->GetYaxis(); ay->SetTitleOffset(0.4);ay->CenterTitle(); ay->SetAxisColor(kRed); ay->SetRangeUser(-5, 5);
204 for(Int_t ir(0); ir<nr; ir++) ax->SetBinLabel(ir+1, Form("%09d", run[ir]));
206 TCanvas *c = new TCanvas("c", "TRD Trend", 1, 1, 1200, 500);
207 c->SetLeftMargin(0.03666361);
208 c->SetRightMargin(0.005499542);
209 c->SetTopMargin(0.02542373);
210 c->SetBottomMargin(0.1758475);
211 for(Int_t it(0); it<ntv; it++){
213 ay->SetTitle(Form("#bf{%s [#sigmau]}", g[it]->GetTitle())); hT->Draw("p");
215 c->Modified(); c->Update(); c->SaveAs(Form("Trend_%s.gif", g[it]->GetName()));
222 //____________________________________________
223 Bool_t AliTRDtrendingManager::ModifyValue(
226 ,Double_t mean, Double_t sgm
228 ,const Char_t *responsible
229 ,const Char_t *notifiables
232 // Expert Function !!!
233 // Modify a trend value in the map already loaded
234 // see function AddValue() for explanation of input format.
237 AliError("No trending map loaded.");
240 AliWarning("*** EXPERT FUNCTION *** This function is modifying one trending value to the current DB. Continue if you know what yout do!");
243 AliError(Form("Missing trending value %s", name));
247 fValue->SetTitle(title);
248 fValue->Set(mean, sgm);
250 for(Int_t ilevel(AliTRDtrendValue::kNlevels); ilevel--;) fValue->SetAlarm(ilevel, messages[ilevel]);
257 if(r->GetEntriesFast()!=2){
258 AliWarning("Responsible name/email incorrectly formated.");
260 fValue->SetResponsible(((TObjString*)r->At(0))->String().Data(), ((TObjString*)r->At(1))->String().Data());
265 TObjArray *n=s.Tokenize(",");
266 for(Int_t in(0); in<TMath::Min(AliTRDtrendValue::kNnotifiable, n->GetEntriesFast()); in++){
267 TString ss(((TObjString*)n->At(in))->String());
269 if(r->GetEntriesFast()!=2){
270 AliWarning(Form("Notifiable person name/email incorrectly formated for [%s].", ss.Data()));
272 fValue->SetNotifiable(((TObjString*)r->At(0))->String().Data(), ((TObjString*)r->At(1))->String().Data());
279 //____________________________________________
280 void AliTRDtrendingManager::Print(Option_t *o) const
282 // Dump trend value list
284 AliError("No trending map available.");
288 for(Int_t iv(0); iv<fEntries->GetEntriesFast(); iv++){
289 ((AliTRDtrendValue*)fEntries->At(iv))->Print(o);
293 //____________________________________________
294 void AliTRDtrendingManager::Load(const char *fn)
296 // Load TRD trending DB from $ALICE_ROOT/PWGPP/TRD/data.
298 AliDebug(1, "Loading TRD trending ...");
299 if(!TFile::Open(fn)) return;
301 TList *tvList = gFile->GetListOfKeys(); TIterator *iter(tvList->MakeIterator()); AliTRDtrendValue *tv(NULL);
302 fEntries = new TObjArray(tvList->GetEntries());
303 fEntries->SetOwner();
305 while((ktv = (TKey*)iter->Next())){
306 tv = (AliTRDtrendValue*)gFile->Get(ktv->GetName());
307 fEntries->AddLast(new AliTRDtrendValue(*tv));