]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDDataDCS.cxx
AliDCSClient "multiSplit" option added in the DCS configuration
[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 // void AliTRDDataDCS::Streamer(TBuffer &R__b) 
211 // {
212 //   //
213 //   // Custom streamer
214 //   //
215   
216 //   if (R__b.IsReading()) {
217     
218 //     R__b.ReadBool (fGraphsAreIni);
219 //     R__b.ReadBool (fFitsAreIni);
220     
221     
222 //     for (UInt_t iAlias=0; iAlias<fNAlias; iAlias++) {
223 //       TString::ReadString (R__b, TString::Class());
224 //       R__b.ReadChar (fConfs[iAlias].fDataType);
225 //       R__b.ReadUInt (fConfs[iAlias].fNChannel);
226 //       R__b.ReadBool (fConfs[iAlias].fEnableGraph);
227 //       R__b.ReadBool (fConfs[iAlias].fEnableFit);
228 //       R__b.ReadInt  (fConfs[iAlias].fMinPoints);
229 //       R__b.ReadInt  (fConfs[iAlias].fIter);
230 //       R__b.ReadDouble  (fConfs[iAlias].fMaxDelta);
231 //       R__b.ReadInt  (fConfs[iAlias].fFitReq);
232 //     }
233     
234     
235 //     if (fGraphsAreIni) {
236 //       for (UInt_t iAlias=0; iAlias<fNAlias; iAlias++)
237 //      fDatas[iAlias].GetGraph() = *(TObjArray*)R__b.ReadObject (TObjArray::Class());
238 //     }
239     
240 //     if (fFitsAreIni) {
241 //       for (UInt_t iAlias=0; iAlias<fNAlias; iAlias++)
242 //      fDatas[iAlias].GetFit() = *(TObjArray*)R__b.ReadObject (TObjArray::Class());
243 //     }
244     
245 //     AliInfo (Form("Read %d octets to the stream (%d Ko)", R__b.Length(), R__b.Length()/1024));
246     
247 //   } else {
248 //     R__b.WriteBool (fGraphsAreIni);
249 //     R__b.WriteBool (fFitsAreIni);
250     
251 //     for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++) {
252 //       TString::WriteString (R__b, &fConfs[iAlias].fAmanda);
253 //       R__b.WriteChar (fConfs[iAlias].fDataType);
254 //       R__b.WriteUInt (fConfs[iAlias].fNChannel);
255 //       R__b.WriteBool (fConfs[iAlias].fEnableGraph);
256 //       R__b.WriteBool (fConfs[iAlias].fEnableFit);
257 //       R__b.WriteInt  (fConfs[iAlias].fMinPoints);
258 //       R__b.WriteInt  (fConfs[iAlias].fIter);
259 //       R__b.WriteDouble  (fConfs[iAlias].fMaxDelta);
260 //       R__b.WriteInt  (fConfs[iAlias].fFitReq);
261 //     }
262     
263 //     if (fGraphsAreIni) {
264 //       for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++) 
265 //      R__b.WriteObject ((TObject*)&fDatas[iAlias].GetGraph());
266 //     }
267     
268 //     if (fFitsAreIni) {
269 //       for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++) 
270 //      R__b.WriteObject ((TObject*)&fDatas[iAlias].GetFit());
271 //     }
272     
273 //     AliInfo (Form("Write %d octets to the stream (%d Ko)", R__b.Length(), R__b.Length()/1024));
274 //   }
275 // }
276
277 //_____________________________________________________________________________
278 Bool_t AliTRDDataDCS::ExtractDCS (TMap *dcsAlias)
279 {
280   //
281   // Extract the DCS information
282   //
283
284   if (dcsAlias == 0x0) {
285     AliWarning ("No DCS Map");
286     return kFALSE;
287   }
288   
289   ClearGraphs();
290   InitGraphs();
291   
292   TGraph *graphTemp;
293   UInt_t nChannel;
294   
295   for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++){
296     
297     // extract dcs only when it is needed
298     nChannel = fDatas[iAlias].GetGraph().GetSize();
299     
300     for (UInt_t iSensor=0; iSensor < nChannel; iSensor++) {
301       
302       graphTemp = FindAndMakeGraph(dcsAlias, 
303                                    Form(fConfs[iAlias].GetAmanda().Data(), iSensor), 
304                                    fConfs[iAlias].GetDataType()); 
305       
306       fDatas[iAlias].GetGraph().AddAt(graphTemp, iSensor);
307     }
308   }
309   
310   return kTRUE;
311 }
312
313 //_____________________________________________________________________________
314 TGraph *AliTRDDataDCS::FindAndMakeGraph (TMap *dcsMap, const char *amandaStr, 
315                                           char dataType)
316 {
317   //
318   // Create the graphs
319   //
320
321   TGraph *graph;
322   
323   TPair *pair = (TPair *) dcsMap->FindObject(amandaStr);
324   if (pair == 0x0) {
325     AliWarning (Form("Can't find %s in dcsMap", amandaStr));
326     return 0x0;
327   }
328   
329   TObjArray *valueSet = (TObjArray *) pair->Value();
330   
331   //
332   // Make graph of values read from DCS map
333   //   (spline fit parameters will subsequently be obtained from this graph) 
334   //
335   
336   Int_t nEntries = valueSet->GetEntriesFast();
337   if (nEntries == 0) {
338     AliWarning (Form("Entry %s in dcsMap contain no datas", amandaStr));
339     return 0x0;
340   }
341   
342   Float_t * x = new Float_t[nEntries];
343   Float_t * y = new Float_t[nEntries];
344   
345   Bool_t ok = kTRUE;
346   Int_t time0 = 0;
347   Int_t iEntries;
348   for (iEntries = 0;  iEntries< nEntries; iEntries++) {
349     
350     AliDCSValue *val = (AliDCSValue *) valueSet->At(iEntries);
351     
352     if (val == 0x0) { 
353       ok = false;
354       AliError(Form("Entry %s at %d contain no datas", amandaStr, iEntries));
355       break;
356     }
357     
358     if (time0 == 0) 
359       time0 = val->GetTimeStamp();
360     
361     
362     x[iEntries] = (val->GetTimeStamp() - time0)/3600.0; // give times in fractions of hours 
363     
364     switch (dataType) {
365     case 'f' :
366       y[iEntries] = val->GetFloat();
367       break;
368       
369     case 'c' :
370       y[iEntries] = (Float_t) val->GetChar();
371       break;
372       
373     default :
374       ok = false;
375       AliError(Form("Bad type for entry %s", amandaStr));
376       break;
377     }
378   }
379   
380   if (ok)
381     graph = new TGraph(iEntries, x, y);
382   else
383     graph = 0x0;
384   
385   delete [] x;
386   delete [] y;
387   
388   return graph;
389 }
390
391 //_____________________________________________________________________________
392 Bool_t AliTRDDataDCS::PerformFit()
393 {
394   //
395   // Do the fit
396   //
397
398   AliSplineFit *fitTemp;
399   
400   ClearFits();
401   InitFits();
402   
403   UInt_t nChannel;
404   
405   for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++){
406     
407     // perform fit only when it is needed
408     nChannel = fDatas[iAlias].GetFit().GetSize();
409     
410     for (UInt_t iSensor=0; iSensor < nChannel; iSensor++) {
411       
412       fitTemp = Fit((TGraph*)fDatas[iAlias].GetGraph(iSensor),
413                      fConfs[iAlias].GetMinPoints(),
414                      fConfs[iAlias].GetIter(),
415                      fConfs[iAlias].GetMaxDelta(),
416                      fConfs[iAlias].GetFitReq()); 
417       
418       if (fitTemp == 0x0)
419         AliInfo(Form("Can't fit %s", Form(fConfs[iAlias].GetAmanda().Data(), iSensor)));
420       
421       fDatas[iAlias].GetFit().AddAt(fitTemp, iSensor);
422     }
423   }
424   
425   return kTRUE;
426   
427 }
428
429 //_____________________________________________________________________________
430 AliSplineFit *AliTRDDataDCS::Fit(TGraph *graph, 
431                                  Int_t  minPoints, Int_t  iter, 
432                                  Double_t  maxDelta, Int_t  fitReq)
433 {
434   if (graph == 0x0) {
435     AliError("No graph for fit");
436     return 0x0;
437   }
438   
439   AliSplineFit *spline = new AliSplineFit();
440   spline->InitKnots(new TGraph (*graph), minPoints, iter, maxDelta);
441   spline->SplineFit(fitReq);
442   spline->Cleanup();   // delete also new TGraph (*graph)
443   
444   return spline;
445 }
446
447 //_____________________________________________________________________________
448 void AliTRDDataDCS::Print(Option_t* option) const
449 {
450   //
451   // Print function
452   //
453
454   if (option[0]=='g' || option[0]=='\0'){
455     
456     if (fGraphsAreIni){
457       
458       for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++){
459         
460         for (Int_t iSensor = 0; iSensor < fDatas[iAlias].GetGraph().GetSize(); iSensor++) {
461           
462           if (fDatas[iAlias].GetGraph(iSensor) != 0x0)
463             AliInfo(Form("Graph %s contain %d point(s)", 
464                           Form(fConfs[iAlias].GetAmanda(), iSensor), 
465                           ((TGraph*)(fDatas[iAlias].GetGraph(iSensor)))->GetN()));
466         }
467       }
468     }
469     else{
470       AliInfo("Graphs don't exist");
471     }
472   }
473   
474   
475   if (option[0] == 'f' || option[0]=='\0'){
476     
477     AliInfo("no print for fit");
478     
479   }
480   
481 }
482
483 //_____________________________________________________________________________
484 TGraph *AliTRDDataDCS::GetGraph(UInt_t iAlias, UInt_t iChannel) const
485 {
486   //
487   // Get a graph
488   //
489
490   if (iAlias >= fNAlias) {
491     AliWarning(Form("Alias %d is not correct", iAlias));
492     return 0x0;
493   }
494   
495   if (iChannel >= (UInt_t) fDatas[iAlias].GetGraph().GetSize()) {
496     AliWarning(Form("Alias %s is not correct", 
497                      Form(fConfs[iAlias].GetAmanda().Data(), iChannel)));
498     return 0x0;
499   }
500   
501   return (TGraph *)fDatas[iAlias].GetGraph(iChannel);
502 }
503
504 //_____________________________________________________________________________
505 AliSplineFit *AliTRDDataDCS::GetFit(UInt_t iAlias, UInt_t iChannel) const
506 {
507   //
508   // Get the spline fit
509   //
510
511   if (iAlias >= fNAlias) {
512     AliWarning (Form("Alias %d is not correct", iAlias));
513     return 0x0;
514   }
515   
516   if (iChannel >= (UInt_t) fDatas[iAlias].GetFit().GetSize()) {
517     AliWarning(Form("Alias %s is not correct", 
518                      Form(fConfs[iAlias].GetAmanda().Data(), iChannel)));
519     return 0x0;
520   }
521   
522   return (AliSplineFit *) fDatas[iAlias].GetFit(iChannel);
523 }
524
525 //_____________________________________________________________________________
526 TString AliTRDDataDCS::GetAmandaStr (UInt_t iAlias) const 
527 {
528   //
529   // Return the AMANDA string
530   //
531
532   if (iAlias < fNAlias)
533     return fConfs[iAlias].GetAmanda();
534   else return TString ();
535 }
536
537 //_____________________________________________________________________________
538 UInt_t AliTRDDataDCS::GetNChannel (UInt_t iAlias) const 
539 {
540   //
541   // Get the channel number
542   //
543
544   if (iAlias < fNAlias)
545     return fConfs[iAlias].GetNChannel();
546   else return 0;
547 }