]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDDataDCS.cxx
fix for the corrupt data
[u/mrichter/AliRoot.git] / TRD / AliTRDDataDCS.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17
18 ////////////////////////////////////////////////////////////////////////////
19 //                                                                        //
20 // This class collects the DCS information and does an AliSplineFit       //
21 //                                                                        //
22 // Typical use :                                                          //
23 //                                                                        //
24 //   AliTRDDataDCS dataDcs;                                               //
25 //   dataDcs.ExtractDCS(dcs);                                             //
26 //   ->call a storeRef function                                           //
27 //   dataDcs.PerformFit();                                                //                        
28 //   dataDcs.ClearGraphs();                                               //
29 //   ->call a store function                                              //
30 //   dataDcs.ClearFits();                                                 //
31 //                                                                        //
32 // Author:                                                                //
33 //   W. Monange   (wilfried.monange@free.fr)                              //
34 //                                                                        //
35 ////////////////////////////////////////////////////////////////////////////
36
37 #include <TGraph.h>
38 #include <TObjArray.h>
39 #include <AliCDBMetaData.h>
40 #include <TMap.h>
41
42 #include "AliDCSValue.h"
43 #include "AliDCSValue.h"
44 #include "AliLog.h"
45 #include "AliTRDDataDCS.h"
46 #include "AliSplineFit.h"
47
48 ClassImp(AliTRDDataDCS)
49
50 //_____________________________________________________________________________
51 AliTRDDataDCS::AliTRDDataDCS() 
52   :TNamed()       
53   ,fGraphsAreIni(kFALSE)
54   ,fFitsAreIni(kFALSE)
55   ,fNAlias(22)
56 {
57   //
58   // Default constructor
59   //
60
61   Init ();
62
63 }
64
65 //_____________________________________________________________________________
66 AliTRDDataDCS::~AliTRDDataDCS()
67 {
68   //
69   // Destructor
70   //
71
72   ClearFits();
73   ClearGraphs();
74
75 }
76
77 //_____________________________________________________________________________
78 void AliTRDDataDCS::Init()
79 {
80   //
81   // Initialization
82   //
83
84   SetConf(kChamberByteStatus, "trd_chamberByteStatus%03d",'c', 540, kTRUE,kFALSE,       10,10,0,2); 
85   SetConf(kPreTrigger,        "trd_preTrigger",           'c',   1, kTRUE, kTRUE,       10,10,0,2);
86   SetConf(kGoofyHv,           "trd_goofyHv",              'f',   1, kTRUE, kTRUE,       10,10,0,2);
87   SetConf(kGoofyPeakPos,      "trd_goofyPeakPos%02d",     'f',   2, kTRUE, kTRUE,       10,10,0,2);
88   SetConf(kGoofyPeakArea,     "trd_goofyPeakArea%02d",    'f',   2, kTRUE, kTRUE,       10,10,0,2);
89   SetConf(kGoofyTemp,         "trd_goofyTemp%02d",        'f',   2, kTRUE, kTRUE,       10,10,0,2);
90   SetConf(kGoofyPressure,     "trd_goofyPressure",        'f',   1, kTRUE, kTRUE,       10,10,0,2);
91   SetConf(kGoofyVelocity,     "trd_goofyVelocity",        'f',   1, kTRUE, kTRUE,       10,10,0,2);
92   SetConf(kGoofyGain,         "trd_goofyGain%02d",        'f',   2, kTRUE, kTRUE,       10,10,0,2);
93   SetConf(kGoofyCO2,          "trd_goofyCO2",             'f',   1, kTRUE, kTRUE,       10,10,0,2);
94   SetConf(kGoofyN2,           "trd_goofyN2",              'f',   1, kTRUE, kTRUE,       10,10,0,2);
95   SetConf(kGasO2,             "trd_gasO2",                'f',   1, kTRUE, kTRUE,       10,10,0,2);
96   SetConf(kGasOverpressure,   "trd_gasOverpressure",      'f',   1, kTRUE, kTRUE,       10,10,0,2);
97   SetConf(kEnvTemp,           "trd_envTemp%03d",          'f', 540, kTRUE, kTRUE,       10,10,0,2);
98   SetConf(kHvAnodeImon,       "trd_hvAnodeImon%03d",      'f', 540, kTRUE, kTRUE,       10,10,0,2);
99   SetConf(kHvDriftImon,       "trd_hvDriftImon%03d",      'f', 540, kTRUE, kTRUE,       10,10,0,2);
100   SetConf(kHvAnodeUmon,       "trd_hvAnodeUmon%03d",      'f', 540, kTRUE, kTRUE,       10,10,0,2);
101   SetConf(kHvDriftUmon,       "trd_hvDriftUmon%03d",      'f', 540, kTRUE, kTRUE,       10,10,0,2);
102   SetConf(kAdcClkPhase,       "trd_adcClkPhase",          'f',   1, kTRUE, kTRUE,       10,10,0,2);
103   SetConf(kAtmPressure,       "trd_atmPressure",          'f',   1, kTRUE, kTRUE,       10,10,0,2);
104   SetConf(kLuminosity,        "trd_luminosity",           'f',   1, kTRUE, kTRUE,       10,10,0,2);
105   SetConf(kMagneticField,     "trd_magneticField",        'f',   1, kTRUE, kTRUE,       10,10,0,2);             
106   
107   for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++) {
108     fDatas[iAlias].GetGraph().SetOwner(1);
109     fDatas[iAlias].GetFit().SetOwner(1);
110   }
111
112 }
113
114 //_____________________________________________________________________________
115 void AliTRDDataDCS::SetConf(UInt_t iAlias, const char *amanda, 
116                              char dataType, UInt_t nChannel, 
117                              Bool_t enableGraph, Bool_t enableFit, Int_t minPoints, 
118                              Int_t iter, Double_t maxDelta, Int_t fitReq)
119 {
120   //
121   // Configure a DCS alias
122   //
123
124   if (iAlias >= fNAlias) {
125     AliWarning (Form("Alias %d is not correct", iAlias));
126     return;
127   }
128   
129   fConfs[iAlias].SetAmanda(amanda);
130   fConfs[iAlias].SetDataType(dataType);
131   fConfs[iAlias].SetNChannel(nChannel);
132   fConfs[iAlias].SetEnableGraph(enableGraph);
133   fConfs[iAlias].SetEnableFit(enableFit);
134   fConfs[iAlias].SetMinPoints(minPoints);
135   fConfs[iAlias].SetIter(iter);
136   fConfs[iAlias].SetMaxDelta(maxDelta);
137   fConfs[iAlias].SetFitReq(fitReq);
138   
139 }
140
141 //_____________________________________________________________________________
142 void AliTRDDataDCS::InitFits()
143 {
144   //
145   // Initialize the fits
146   //
147
148   if (fFitsAreIni)
149     return;
150   
151   UInt_t nChannel;
152   for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++) {
153     nChannel = fConfs[iAlias].GetEnableFit() ? fConfs[iAlias].GetNChannel() : 0;
154     fDatas[iAlias].GetFit().Expand(nChannel);   
155   }
156   
157   fFitsAreIni = kTRUE;
158 }
159
160 //_____________________________________________________________________________
161 void AliTRDDataDCS::InitGraphs()
162 {
163   //
164   // Initialize the graphs
165   //
166
167   if (fGraphsAreIni)
168     return;
169   
170   UInt_t nChannel;      
171   for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++) {
172     nChannel = fConfs[iAlias].GetEnableGraph() ? fConfs[iAlias].GetNChannel() : 0;       
173     fDatas[iAlias].GetGraph().Expand(nChannel);
174   }
175   
176   fGraphsAreIni = kTRUE;
177 }
178
179 //_____________________________________________________________________________
180 void AliTRDDataDCS::ClearFits()
181 {
182   //
183   // Clear the fits
184   //
185
186   for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++) {
187     fDatas[iAlias].GetFit().Clear();
188     fDatas[iAlias].GetFit().Expand(0);
189   }
190   
191   fFitsAreIni = kFALSE;
192 }
193
194 //_____________________________________________________________________________
195 void AliTRDDataDCS::ClearGraphs()
196 {
197   //
198   // Clear the grpahs
199   //
200
201   for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++) {
202     fDatas[iAlias].GetGraph().Clear();
203     fDatas[iAlias].GetGraph().Expand(0);
204   }
205   
206   fGraphsAreIni = kFALSE;
207 }
208
209 //_____________________________________________________________________________
210 Bool_t AliTRDDataDCS::ExtractDCS (TMap *dcsAlias)
211 {
212   //
213   // Extract the DCS information
214   //
215
216   if (dcsAlias == 0x0) {
217     AliWarning ("No DCS Map");
218     return kFALSE;
219   }
220   
221   ClearGraphs();
222   InitGraphs();
223   
224   TGraph *graphTemp;
225   UInt_t nChannel;
226   
227   for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++){
228     
229     // extract dcs only when it is needed
230     nChannel = fDatas[iAlias].GetGraph().GetSize();
231     
232     for (UInt_t iSensor=0; iSensor < nChannel; iSensor++) {
233       
234       graphTemp = FindAndMakeGraph(dcsAlias, 
235                                    Form(fConfs[iAlias].GetAmanda().Data(), iSensor), 
236                                    fConfs[iAlias].GetDataType()); 
237       
238       fDatas[iAlias].GetGraph().AddAt(graphTemp, iSensor);
239     }
240   }
241   
242   return kTRUE;
243 }
244
245 //_____________________________________________________________________________
246 TGraph *AliTRDDataDCS::FindAndMakeGraph (TMap *dcsMap, const char *amandaStr, 
247                                           char dataType)
248 {
249   //
250   // Create the graphs
251   //
252
253   TGraph *graph;
254   
255   TPair *pair = (TPair *) dcsMap->FindObject(amandaStr);
256   if (pair == 0x0) {
257     AliWarning (Form("Can't find %s in dcsMap", amandaStr));
258     return 0x0;
259   }
260   
261   TObjArray *valueSet = (TObjArray *) pair->Value();
262   
263   //
264   // Make graph of values read from DCS map
265   //   (spline fit parameters will subsequently be obtained from this graph) 
266   //
267   
268   Int_t nEntries = valueSet->GetEntriesFast();
269   if (nEntries == 0) {
270     AliWarning (Form("Entry %s in dcsMap contain no datas", amandaStr));
271     return 0x0;
272   }
273   
274   Float_t * x = new Float_t[nEntries];
275   Float_t * y = new Float_t[nEntries];
276   
277   Bool_t ok = kTRUE;
278   Int_t time0 = 0;
279   Int_t iEntries;
280   for (iEntries = 0;  iEntries< nEntries; iEntries++) {
281     
282     AliDCSValue *val = (AliDCSValue *) valueSet->At(iEntries);
283     
284     if (val == 0x0) { 
285       ok = false;
286       AliError(Form("Entry %s at %d contain no datas", amandaStr, iEntries));
287       break;
288     }
289     
290     if (time0 == 0) 
291       time0 = val->GetTimeStamp();
292     
293     
294     x[iEntries] = (val->GetTimeStamp() - time0)/3600.0; // give times in fractions of hours 
295     
296     switch (dataType) {
297     case 'f' :
298       y[iEntries] = val->GetFloat();
299       break;
300       
301     case 'c' :
302       y[iEntries] = (Float_t) val->GetChar();
303       break;
304       
305     default :
306       ok = false;
307       AliError(Form("Bad type for entry %s", amandaStr));
308       break;
309     }
310   }
311   
312   if (ok)
313     graph = new TGraph(iEntries, x, y);
314   else
315     graph = 0x0;
316   
317   delete [] x;
318   delete [] y;
319   
320   return graph;
321 }
322
323 //_____________________________________________________________________________
324 Bool_t AliTRDDataDCS::PerformFit()
325 {
326   //
327   // Do the fit
328   //
329
330   AliSplineFit *fitTemp;
331   
332   ClearFits();
333   InitFits();
334   
335   UInt_t nChannel;
336   
337   for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++){
338     
339     // perform fit only when it is needed
340     nChannel = fDatas[iAlias].GetFit().GetSize();
341     
342     for (UInt_t iSensor=0; iSensor < nChannel; iSensor++) {
343       
344       fitTemp = Fit((TGraph*)fDatas[iAlias].GetGraph(iSensor),
345                      fConfs[iAlias].GetMinPoints(),
346                      fConfs[iAlias].GetIter(),
347                      fConfs[iAlias].GetMaxDelta(),
348                      fConfs[iAlias].GetFitReq()); 
349       
350       if (fitTemp == 0x0)
351         AliInfo(Form("Can't fit %s", Form(fConfs[iAlias].GetAmanda().Data(), iSensor)));
352       
353       fDatas[iAlias].GetFit().AddAt(fitTemp, iSensor);
354     }
355   }
356   
357   return kTRUE;
358   
359 }
360
361 //_____________________________________________________________________________
362 AliSplineFit *AliTRDDataDCS::Fit(TGraph *graph, 
363                                  Int_t  minPoints, Int_t  iter, 
364                                  Double_t  maxDelta, Int_t  fitReq)
365 {
366   //
367   // Do the spline fit
368   //
369
370   if (graph == 0x0) {
371     AliError("No graph for fit");
372     return 0x0;
373   }
374   
375   AliSplineFit *spline = new AliSplineFit();
376   spline->InitKnots(new TGraph (*graph), minPoints, iter, maxDelta);
377   spline->SplineFit(fitReq);
378   spline->Cleanup();   // delete also new TGraph (*graph)
379   
380   return spline;
381 }
382
383 //_____________________________________________________________________________
384 void AliTRDDataDCS::Print(Option_t* option) const
385 {
386   //
387   // Print function
388   //
389
390   if (option[0]=='g' || option[0]=='\0'){
391     
392     if (fGraphsAreIni){
393       
394       for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++){
395         
396         for (Int_t iSensor = 0; iSensor < fDatas[iAlias].GetGraph().GetSize(); iSensor++) {
397           
398           if (fDatas[iAlias].GetGraph(iSensor) != 0x0)
399             AliInfo(Form("Graph %s contain %d point(s)", 
400                           Form(fConfs[iAlias].GetAmanda(), iSensor), 
401                           ((TGraph*)(fDatas[iAlias].GetGraph(iSensor)))->GetN()));
402         }
403       }
404     }
405     else{
406       AliInfo("Graphs don't exist");
407     }
408   }
409   
410   
411   if (option[0] == 'f' || option[0]=='\0'){
412     
413     AliInfo("no print for fit");
414     
415   }
416   
417 }
418
419 //_____________________________________________________________________________
420 TGraph *AliTRDDataDCS::GetGraph(UInt_t iAlias, UInt_t iChannel) const
421 {
422   //
423   // Get a graph
424   //
425
426   if (iAlias >= fNAlias) {
427     AliWarning(Form("Alias %d is not correct", iAlias));
428     return 0x0;
429   }
430   
431   if (iChannel >= (UInt_t) fDatas[iAlias].GetGraph().GetSize()) {
432     AliWarning(Form("Alias %s is not correct", 
433                      Form(fConfs[iAlias].GetAmanda().Data(), iChannel)));
434     return 0x0;
435   }
436   
437   return (TGraph *)fDatas[iAlias].GetGraph(iChannel);
438 }
439
440 //_____________________________________________________________________________
441 AliSplineFit *AliTRDDataDCS::GetFit(UInt_t iAlias, UInt_t iChannel) const
442 {
443   //
444   // Get the spline fit
445   //
446
447   if (iAlias >= fNAlias) {
448     AliWarning (Form("Alias %d is not correct", iAlias));
449     return 0x0;
450   }
451   
452   if (iChannel >= (UInt_t) fDatas[iAlias].GetFit().GetSize()) {
453     AliWarning(Form("Alias %s is not correct", 
454                      Form(fConfs[iAlias].GetAmanda().Data(), iChannel)));
455     return 0x0;
456   }
457   
458   return (AliSplineFit *) fDatas[iAlias].GetFit(iChannel);
459 }
460
461 //_____________________________________________________________________________
462 TString AliTRDDataDCS::GetAmandaStr (UInt_t iAlias) const 
463 {
464   //
465   // Return the AMANDA string
466   //
467
468   if (iAlias < fNAlias)
469     return fConfs[iAlias].GetAmanda();
470   else return TString ();
471 }
472
473 //_____________________________________________________________________________
474 UInt_t AliTRDDataDCS::GetNChannel (UInt_t iAlias) const 
475 {
476   //
477   // Get the channel number
478   //
479
480   if (iAlias < fNAlias)
481     return fConfs[iAlias].GetNChannel();
482   else return 0;
483 }