]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDDataDCS.cxx
New interface of a VStore to hold hits (Laurent)
[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 // Author:                                                                //
23 //   W. Monange   (wilfried.monange@free.fr)                              //
24 //                                                                        //
25 ////////////////////////////////////////////////////////////////////////////
26
27
28 #include <TGraph.h>
29 #include <TObjArray.h>
30 #include <AliCDBMetaData.h>
31 #include <TMap.h>
32
33 #include "AliDCSValue.h"
34 #include "AliDCSValue.h"
35 #include "AliLog.h"
36 #include "AliTRDDataDCS.h"
37 #include "AliSplineFit.h"
38
39 ClassImp(AliTRDDataDCS)
40
41 /*
42 Typical use :
43
44 AliTRDDataDCS dataDcs;
45 dataDcs.ExtractDCS (dcs);
46 ->call a storeRef function
47 dataDcs.PerformFit ();
48 dataDcs.ClearGraphs ();
49 ->call a store function
50 dataDcs.ClearFits ();
51
52 */
53
54 //_____________________________________________________________________________
55 AliTRDDataDCS::AliTRDDataDCS () 
56   :  chamberByteStatus  (0),
57      preTrigger         (1),
58      goofyHv            (2),
59      goofyPeakPos       (3),
60      goofyPeakArea      (4),
61      goofyTemp          (5),
62      goofyPressure      (6),
63      goofyVelocity      (7),
64      goofyGain          (8),
65      goofyCO2           (9),
66      goofyN2            (10),
67      gasO2              (11),
68      gasOverpressure    (12),
69      envTemp            (13),
70      hvAnodeImon        (14),
71      hvDriftImon        (15),
72      hvAnodeUmon        (16),
73      hvDriftUmon        (17),
74      adcClkPhase        (18),
75      atmPressure        (19),
76      luminosity         (20),
77      magneticField      (21),
78      fNAlias            (22),
79      graphsAreIni       (false),
80      fitsAreIni         (false)
81 {
82   Init ();
83 }
84
85 //_____________________________________________________________________________
86 AliTRDDataDCS::~AliTRDDataDCS ()
87 {
88   ClearFits ();
89   ClearGraphs ();
90 }
91
92 //_____________________________________________________________________________
93 void AliTRDDataDCS::Init ()
94 {
95   SetConf (chamberByteStatus, "trd_chamberByteStatus%03d", 'c', 540, true, false, 10,10,0,2); 
96   SetConf (preTrigger,          "trd_preTrigger",               'c', 1, true, true,     10,10,0,2);
97   SetConf (goofyHv,                     "trd_goofyHv",                  'f', 1, true, true,     10,10,0,2);
98   SetConf (goofyPeakPos,                "trd_goofyPeakPos%02d", 'f', 2, true, true,     10,10,0,2);
99   SetConf (goofyPeakArea,       "trd_goofyPeakArea%02d",'f', 2, true, true,     10,10,0,2);
100   SetConf (goofyTemp,           "trd_goofyTemp%02d",    'f', 2, true, true,     10,10,0,2);
101   SetConf (goofyPressure,       "trd_goofyPressure",    'f', 1, true, true,     10,10,0,2);
102   SetConf (goofyVelocity,       "trd_goofyVelocity",    'f', 1, true, true,     10,10,0,2);
103   SetConf (goofyGain,           "trd_goofyGain%02d",    'f', 2, true, true,     10,10,0,2);
104   SetConf (goofyCO2,                    "trd_goofyCO2",                 'f', 1, true, true,     10,10,0,2);
105   SetConf (goofyN2,                     "trd_goofyN2",                  'f', 1, true, true,     10,10,0,2);
106   SetConf (gasO2,                       "trd_gasO2",                    'f', 1, true, true,     10,10,0,2);
107   SetConf (gasOverpressure,     "trd_gasOverpressure",  'f', 1, true, true,     10,10,0,2);
108   SetConf (envTemp,                     "trd_envTemp%03d",              'f', 540, true, true,   10,10,0,2);
109   SetConf (hvAnodeImon,                 "trd_hvAnodeImon%03d",  'f', 540, true, true,   10,10,0,2);
110   SetConf (hvDriftImon,                 "trd_hvDriftImon%03d",  'f', 540, true, true,   10,10,0,2);
111   SetConf (hvAnodeUmon,                 "trd_hvAnodeUmon%03d",  'f', 540, true, true,   10,10,0,2);
112   SetConf (hvDriftUmon,                 "trd_hvDriftUmon%03d",  'f', 540, true, true,   10,10,0,2);
113   SetConf (adcClkPhase,                 "trd_adcClkPhase",              'f', 1, true, true,     10,10,0,2);
114   SetConf (atmPressure,                 "trd_atmPressure",              'f', 1, true, true,     10,10,0,2);
115   SetConf (luminosity,          "trd_luminosity",               'f', 1, true, true,     10,10,0,2);
116   SetConf (magneticField,       "trd_magneticField",    'f', 1, true, true,     10,10,0,2);             
117   
118   for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++) {
119     fDatas[iAlias].graph.SetOwner (1);
120     fDatas[iAlias].fit.SetOwner (1);
121   }
122 }
123
124 //_____________________________________________________________________________
125 void AliTRDDataDCS::SetConf (UInt_t iAlias, const char * amanda, 
126                              char dataType, UInt_t nChannel, 
127                              Bool_t enableGraph, Bool_t enableFit, Int_t kMinPoints, 
128                              Int_t kIter, Double_t kMaxDelta, Int_t kFitReq)
129 {
130   if (iAlias >= fNAlias) {
131     AliWarning (Form("Alias %d is not correct", iAlias));
132     return;
133   }
134   
135   fConfs[iAlias].amanda = amanda;
136   fConfs[iAlias].dataType = dataType;
137   fConfs[iAlias].nChannel = nChannel;
138   fConfs[iAlias].enableGraph = enableGraph;
139   fConfs[iAlias].enableFit = enableFit;
140   fConfs[iAlias].kMinPoints = kMinPoints;
141   fConfs[iAlias].kIter = kIter;
142   fConfs[iAlias].kMaxDelta = kMaxDelta;
143   fConfs[iAlias].kFitReq = kFitReq;
144   
145 }
146
147 //_____________________________________________________________________________
148 void AliTRDDataDCS::InitFits ()
149 {
150   if (fitsAreIni)
151     return;
152   
153   UInt_t nChannel;
154   for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++) {
155     nChannel = fConfs[iAlias].enableFit ? fConfs[iAlias].nChannel : 0;
156     fDatas[iAlias].fit.Expand (nChannel);       
157   }
158   
159   fitsAreIni = true;
160 }
161
162 //_____________________________________________________________________________
163 void AliTRDDataDCS::InitGraphs ()
164 {
165   if (graphsAreIni)
166     return;
167   
168   UInt_t nChannel;      
169   for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++) {
170     nChannel = fConfs[iAlias].enableGraph ? fConfs[iAlias].nChannel : 0;         
171     fDatas[iAlias].graph.Expand (nChannel);
172   }
173   
174   graphsAreIni = true;
175 }
176
177 //_____________________________________________________________________________
178 void AliTRDDataDCS::ClearFits ()
179 {
180   for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++) {
181     fDatas[iAlias].fit.Clear ();
182     fDatas[iAlias].fit.Expand (0);
183   }
184   
185   fitsAreIni = false;
186 }
187
188 //_____________________________________________________________________________
189 void AliTRDDataDCS::ClearGraphs ()
190 {       
191   for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++) {
192     fDatas[iAlias].graph.Clear ();
193     fDatas[iAlias].graph.Expand (0);
194   }
195   
196   graphsAreIni = false;
197 }
198
199 //_____________________________________________________________________________
200 void AliTRDDataDCS::Streamer(TBuffer &R__b) {
201   
202   if (R__b.IsReading()) {
203     
204     R__b.ReadBool (graphsAreIni);
205     R__b.ReadBool (fitsAreIni);
206     
207     
208     for (UInt_t iAlias=0; iAlias<fNAlias; iAlias++) {
209       TString::ReadString (R__b, TString::Class());
210       R__b.ReadChar (fConfs[iAlias].dataType);
211       R__b.ReadUInt (fConfs[iAlias].nChannel);
212       R__b.ReadBool (fConfs[iAlias].enableGraph);
213       R__b.ReadBool (fConfs[iAlias].enableFit);
214       R__b.ReadInt  (fConfs[iAlias].kMinPoints);
215       R__b.ReadInt  (fConfs[iAlias].kIter);
216       R__b.ReadDouble  (fConfs[iAlias].kMaxDelta);
217       R__b.ReadInt  (fConfs[iAlias].kFitReq);
218     }
219     
220     
221     if (graphsAreIni) {
222       for (UInt_t iAlias=0; iAlias<fNAlias; iAlias++)
223         fDatas[iAlias].graph = *(TObjArray*)R__b.ReadObject (TObjArray::Class());
224     }
225     
226     if (fitsAreIni) {
227       for (UInt_t iAlias=0; iAlias<fNAlias; iAlias++)
228         fDatas[iAlias].fit = *(TObjArray*)R__b.ReadObject (TObjArray::Class());
229     }
230     
231     AliInfo (Form("Read %d octets to the stream (%d Ko)", R__b.Length(), R__b.Length()/1024));
232     
233   } else {
234     R__b.WriteBool (graphsAreIni);
235     R__b.WriteBool (fitsAreIni);
236     
237     for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++) {
238       TString::WriteString (R__b, &fConfs[iAlias].amanda);
239       R__b.WriteChar (fConfs[iAlias].dataType);
240       R__b.WriteUInt (fConfs[iAlias].nChannel);
241       R__b.WriteBool (fConfs[iAlias].enableGraph);
242       R__b.WriteBool (fConfs[iAlias].enableFit);
243       R__b.WriteInt  (fConfs[iAlias].kMinPoints);
244       R__b.WriteInt  (fConfs[iAlias].kIter);
245       R__b.WriteDouble  (fConfs[iAlias].kMaxDelta);
246       R__b.WriteInt  (fConfs[iAlias].kFitReq);
247     }
248     
249     if (graphsAreIni) {
250       for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++) 
251         R__b.WriteObject ((TObject*)&fDatas[iAlias].graph);
252     }
253     
254     if (fitsAreIni) {
255       for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++) 
256         R__b.WriteObject ((TObject*)&fDatas[iAlias].fit);
257     }
258     
259     AliInfo (Form("Write %d octets to the stream (%d Ko)", R__b.Length(), R__b.Length()/1024));
260   }
261 }
262
263 //_____________________________________________________________________________
264 Bool_t AliTRDDataDCS::ExtractDCS (TMap * dcsAlias)
265 {
266   if (dcsAlias == 0x0) {
267     AliWarning ("No DCS Map");
268     return kFALSE;
269   }
270   
271   ClearGraphs ();
272   InitGraphs ();
273   
274   TGraph * graphTemp;
275   UInt_t nChannel;
276   
277   for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++){
278     
279     // extract dcs only when it is needed
280     nChannel = fDatas[iAlias].graph.GetSize ();
281     
282     for (UInt_t iSensor=0; iSensor < nChannel; iSensor++) {
283       
284       graphTemp = FindAndMakeGraph (dcsAlias, 
285                                     Form (fConfs[iAlias].amanda.Data(), iSensor), 
286                                     fConfs[iAlias].dataType); 
287       
288       fDatas[iAlias].graph.AddAt (graphTemp, iSensor);
289     }
290   }
291   
292   return kTRUE;
293 }
294
295 //_____________________________________________________________________________
296 TGraph * AliTRDDataDCS::FindAndMakeGraph (TMap * dcsMap, const char * amandaStr, 
297                                           char dataType)
298 {
299   TGraph * graph;
300   
301   TPair * pair = (TPair*)dcsMap->FindObject(amandaStr);
302   if (pair == 0x0) {
303     AliWarning (Form("Can't find %s in dcsMap", amandaStr));
304     return 0x0;
305   }
306   
307   TObjArray * valueSet = (TObjArray*)pair->Value();
308   
309   //
310   // Make graph of values read from DCS map
311   //   (spline fit parameters will subsequently be obtained from this graph) 
312   //
313   
314   Int_t nEntries = valueSet->GetEntriesFast();
315   if (nEntries == 0) {
316     AliWarning (Form("Entry %s in dcsMap contain no datas", amandaStr));
317     return 0x0;
318   }
319   
320   Float_t * x = new Float_t [nEntries];
321   Float_t * y = new Float_t [nEntries];
322   
323   Bool_t ok = true;
324   Int_t time0 = 0;
325   Int_t iEntries;
326   for (iEntries = 0;  iEntries< nEntries; iEntries++) {
327     
328     AliDCSValue * val = (AliDCSValue *)valueSet->At(iEntries);
329     
330     if (val == 0x0) { 
331       ok = false;
332       AliError (Form("Entry %s at %d contain no datas", amandaStr, iEntries));
333       break;
334     }
335     
336     if (time0 == 0) 
337       time0 = val->GetTimeStamp();
338     
339     
340     x[iEntries] = (val->GetTimeStamp() - time0)/3600.0; // give times in fractions of hours 
341     
342     switch (dataType) {
343     case 'f' :
344       y[iEntries] = val->GetFloat();
345       break;
346       
347     case 'c' :
348       y[iEntries] = (Float_t) val->GetChar();
349       break;
350       
351     default :
352       ok = false;
353       AliError (Form("Bad type for entry %s", amandaStr));
354       break;
355     }
356   }
357   
358   if (ok)
359     graph = new TGraph (iEntries, x, y);
360   else
361     graph = 0x0;
362   
363   delete [] x;
364   delete [] y;
365   
366   return graph;
367 }
368
369
370 //_____________________________________________________________________________
371 Bool_t AliTRDDataDCS::PerformFit ()
372 {
373   AliSplineFit * fitTemp;
374   
375   ClearFits ();
376   InitFits ();
377   
378   UInt_t nChannel;
379   
380   for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++){
381     
382     // perform fit only when it is needed
383     nChannel = fDatas[iAlias].fit.GetSize ();
384     
385     for (UInt_t iSensor=0; iSensor < nChannel; iSensor++) {
386       
387       fitTemp = Fit ((TGraph*)fDatas[iAlias].graph[iSensor],
388                      fConfs[iAlias].kMinPoints,
389                      fConfs[iAlias].kIter,
390                      fConfs[iAlias].kMaxDelta,
391                      fConfs[iAlias].kFitReq); 
392       
393       if (fitTemp == 0x0)
394         AliInfo (Form ("Can't fit %s", Form (fConfs[iAlias].amanda.Data(), iSensor)));
395       
396       fDatas[iAlias].fit.AddAt (fitTemp, iSensor);
397     }
398   }
399   
400   return kTRUE;
401   
402 }
403
404 //_____________________________________________________________________________
405 AliSplineFit * AliTRDDataDCS::Fit (TGraph * graph, 
406                                    Int_t  kMinPoints, Int_t  kIter, 
407                                    Double_t  kMaxDelta, Int_t  kFitReq)
408 {
409   if (graph == 0x0) {
410     AliError ("No graph for fit");
411     return 0x0;
412   }
413   
414   AliSplineFit * spline = new AliSplineFit ();
415   spline->InitKnots (new TGraph (*graph), kMinPoints, kIter, kMaxDelta);
416   spline->SplineFit (kFitReq);
417   spline->Cleanup();   // delete also new TGraph (*graph)
418   
419   return spline;
420 }
421
422
423 //_____________________________________________________________________________
424 void AliTRDDataDCS::Print (Option_t* option) const
425 {
426   if (option[0]=='g' || option[0]=='\0'){
427     
428     if (graphsAreIni){
429       
430       for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++){
431         
432         for (Int_t iSensor = 0; iSensor < fDatas[iAlias].graph.GetSize(); iSensor++) {
433           
434           if (fDatas[iAlias].graph[iSensor] != 0x0)
435             AliInfo (Form("Graph %s contain %d point(s)", 
436                           Form(fConfs[iAlias].amanda, iSensor), 
437                           ((TGraph*)(fDatas[iAlias].graph[iSensor]))->GetN ()));
438         }
439       }
440     }else{
441       AliInfo ("Graphs don't exist");
442     }
443   }
444   
445   
446   if (option[0] == 'f' || option[0]=='\0'){
447     
448     AliInfo ("no print for fit");
449     
450   }
451   
452 }
453
454 //_____________________________________________________________________________
455 TGraph * AliTRDDataDCS::GetGraph (UInt_t iAlias, UInt_t iChannel) const
456 {
457   if (iAlias >= fNAlias) {
458     AliWarning (Form("Alias %d is not correct", iAlias));
459     return 0x0;
460   }
461   
462   if (iChannel >= (UInt_t)fDatas[iAlias].graph.GetSize()) {
463     AliWarning (Form("Alias %s is not correct", 
464                      Form(fConfs[iAlias].amanda.Data(), iChannel)));
465     return 0x0;
466   }
467   
468   return (TGraph *)fDatas[iAlias].graph[iChannel];
469 }
470
471 //_____________________________________________________________________________
472 AliSplineFit * AliTRDDataDCS::GetFit (UInt_t iAlias, UInt_t iChannel) const
473 {
474   if (iAlias >= fNAlias) {
475     AliWarning (Form("Alias %d is not correct", iAlias));
476     return 0x0;
477   }
478   
479   if (iChannel >= (UInt_t)fDatas[iAlias].fit.GetSize()) {
480     AliWarning (Form("Alias %s is not correct", 
481                      Form(fConfs[iAlias].amanda.Data(), iChannel)));
482     return 0x0;
483   }
484   
485   return (AliSplineFit *)fDatas[iAlias].fit[iChannel];
486 }
487
488 //_____________________________________________________________________________
489 TString AliTRDDataDCS::GetAmandaStr (UInt_t iAlias) const 
490 {
491   if (iAlias < fNAlias)
492     return fConfs[iAlias].amanda;
493   else return TString ();
494 }
495
496 //_____________________________________________________________________________
497 UInt_t AliTRDDataDCS::GetNChannel (UInt_t iAlias) const 
498 {
499   if (iAlias < fNAlias)
500     return fConfs[iAlias].nChannel;
501   else return 0;
502 }