Removing useless flag.
[u/mrichter/AliRoot.git] / TRD / AliTRDDataDCS.cxx
CommitLineData
67b87932 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// //
54d68e69 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// //
67b87932 32// Author: //
33// W. Monange (wilfried.monange@free.fr) //
34// //
35////////////////////////////////////////////////////////////////////////////
a5e1169e 36
a5e1169e 37#include <TGraph.h>
38#include <TObjArray.h>
a5e1169e 39#include <TMap.h>
40
41#include "AliDCSValue.h"
42#include "AliDCSValue.h"
43#include "AliLog.h"
a5e1169e 44#include "AliSplineFit.h"
45
c893147d 46#include "AliTRDDataDCS.h"
47
a5e1169e 48ClassImp(AliTRDDataDCS)
49
a5e1169e 50//_____________________________________________________________________________
54d68e69 51AliTRDDataDCS::AliTRDDataDCS()
52 :TNamed()
53 ,fGraphsAreIni(kFALSE)
54 ,fFitsAreIni(kFALSE)
55 ,fNAlias(22)
a5e1169e 56{
54d68e69 57 //
58 // Default constructor
59 //
60
a5e1169e 61 Init ();
54d68e69 62
a5e1169e 63}
64
65//_____________________________________________________________________________
54d68e69 66AliTRDDataDCS::~AliTRDDataDCS()
a5e1169e 67{
54d68e69 68 //
69 // Destructor
70 //
71
72 ClearFits();
73 ClearGraphs();
74
a5e1169e 75}
76
77//_____________________________________________________________________________
54d68e69 78void AliTRDDataDCS::Init()
a5e1169e 79{
54d68e69 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);
a5e1169e 106
107 for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++) {
54d68e69 108 fDatas[iAlias].GetGraph().SetOwner(1);
109 fDatas[iAlias].GetFit().SetOwner(1);
a5e1169e 110 }
54d68e69 111
a5e1169e 112}
113
114//_____________________________________________________________________________
54d68e69 115void AliTRDDataDCS::SetConf(UInt_t iAlias, const char *amanda,
a5e1169e 116 char dataType, UInt_t nChannel,
54d68e69 117 Bool_t enableGraph, Bool_t enableFit, Int_t minPoints,
118 Int_t iter, Double_t maxDelta, Int_t fitReq)
a5e1169e 119{
54d68e69 120 //
121 // Configure a DCS alias
122 //
123
a5e1169e 124 if (iAlias >= fNAlias) {
125 AliWarning (Form("Alias %d is not correct", iAlias));
126 return;
127 }
128
54d68e69 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);
a5e1169e 138
139}
140
141//_____________________________________________________________________________
54d68e69 142void AliTRDDataDCS::InitFits()
a5e1169e 143{
54d68e69 144 //
145 // Initialize the fits
146 //
147
148 if (fFitsAreIni)
a5e1169e 149 return;
150
151 UInt_t nChannel;
152 for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++) {
54d68e69 153 nChannel = fConfs[iAlias].GetEnableFit() ? fConfs[iAlias].GetNChannel() : 0;
154 fDatas[iAlias].GetFit().Expand(nChannel);
a5e1169e 155 }
156
54d68e69 157 fFitsAreIni = kTRUE;
a5e1169e 158}
159
160//_____________________________________________________________________________
54d68e69 161void AliTRDDataDCS::InitGraphs()
a5e1169e 162{
54d68e69 163 //
164 // Initialize the graphs
165 //
166
167 if (fGraphsAreIni)
a5e1169e 168 return;
169
170 UInt_t nChannel;
171 for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++) {
54d68e69 172 nChannel = fConfs[iAlias].GetEnableGraph() ? fConfs[iAlias].GetNChannel() : 0;
173 fDatas[iAlias].GetGraph().Expand(nChannel);
a5e1169e 174 }
175
54d68e69 176 fGraphsAreIni = kTRUE;
a5e1169e 177}
178
179//_____________________________________________________________________________
54d68e69 180void AliTRDDataDCS::ClearFits()
a5e1169e 181{
54d68e69 182 //
183 // Clear the fits
184 //
185
a5e1169e 186 for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++) {
54d68e69 187 fDatas[iAlias].GetFit().Clear();
188 fDatas[iAlias].GetFit().Expand(0);
a5e1169e 189 }
190
54d68e69 191 fFitsAreIni = kFALSE;
a5e1169e 192}
193
194//_____________________________________________________________________________
54d68e69 195void AliTRDDataDCS::ClearGraphs()
196{
197 //
198 // Clear the grpahs
199 //
200
a5e1169e 201 for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++) {
54d68e69 202 fDatas[iAlias].GetGraph().Clear();
203 fDatas[iAlias].GetGraph().Expand(0);
a5e1169e 204 }
205
54d68e69 206 fGraphsAreIni = kFALSE;
a5e1169e 207}
208
a5e1169e 209//_____________________________________________________________________________
54d68e69 210Bool_t AliTRDDataDCS::ExtractDCS (TMap *dcsAlias)
a5e1169e 211{
54d68e69 212 //
213 // Extract the DCS information
214 //
215
a5e1169e 216 if (dcsAlias == 0x0) {
217 AliWarning ("No DCS Map");
218 return kFALSE;
219 }
220
54d68e69 221 ClearGraphs();
222 InitGraphs();
a5e1169e 223
54d68e69 224 TGraph *graphTemp;
a5e1169e 225 UInt_t nChannel;
226
227 for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++){
228
229 // extract dcs only when it is needed
54d68e69 230 nChannel = fDatas[iAlias].GetGraph().GetSize();
a5e1169e 231
232 for (UInt_t iSensor=0; iSensor < nChannel; iSensor++) {
233
54d68e69 234 graphTemp = FindAndMakeGraph(dcsAlias,
235 Form(fConfs[iAlias].GetAmanda().Data(), iSensor),
236 fConfs[iAlias].GetDataType());
a5e1169e 237
54d68e69 238 fDatas[iAlias].GetGraph().AddAt(graphTemp, iSensor);
a5e1169e 239 }
240 }
241
242 return kTRUE;
243}
244
245//_____________________________________________________________________________
c893147d 246TGraph *AliTRDDataDCS::FindAndMakeGraph (TMap * const dcsMap
247 , const char *amandaStr
248 , char dataType)
a5e1169e 249{
54d68e69 250 //
251 // Create the graphs
252 //
253
254 TGraph *graph;
a5e1169e 255
54d68e69 256 TPair *pair = (TPair *) dcsMap->FindObject(amandaStr);
a5e1169e 257 if (pair == 0x0) {
258 AliWarning (Form("Can't find %s in dcsMap", amandaStr));
259 return 0x0;
260 }
261
54d68e69 262 TObjArray *valueSet = (TObjArray *) pair->Value();
a5e1169e 263
264 //
265 // Make graph of values read from DCS map
266 // (spline fit parameters will subsequently be obtained from this graph)
267 //
268
269 Int_t nEntries = valueSet->GetEntriesFast();
270 if (nEntries == 0) {
271 AliWarning (Form("Entry %s in dcsMap contain no datas", amandaStr));
272 return 0x0;
273 }
274
54d68e69 275 Float_t * x = new Float_t[nEntries];
276 Float_t * y = new Float_t[nEntries];
a5e1169e 277
54d68e69 278 Bool_t ok = kTRUE;
a5e1169e 279 Int_t time0 = 0;
280 Int_t iEntries;
281 for (iEntries = 0; iEntries< nEntries; iEntries++) {
282
54d68e69 283 AliDCSValue *val = (AliDCSValue *) valueSet->At(iEntries);
a5e1169e 284
285 if (val == 0x0) {
286 ok = false;
54d68e69 287 AliError(Form("Entry %s at %d contain no datas", amandaStr, iEntries));
a5e1169e 288 break;
289 }
290
291 if (time0 == 0)
292 time0 = val->GetTimeStamp();
293
294
295 x[iEntries] = (val->GetTimeStamp() - time0)/3600.0; // give times in fractions of hours
296
297 switch (dataType) {
298 case 'f' :
299 y[iEntries] = val->GetFloat();
300 break;
301
302 case 'c' :
303 y[iEntries] = (Float_t) val->GetChar();
304 break;
305
306 default :
307 ok = false;
54d68e69 308 AliError(Form("Bad type for entry %s", amandaStr));
a5e1169e 309 break;
310 }
311 }
312
313 if (ok)
54d68e69 314 graph = new TGraph(iEntries, x, y);
a5e1169e 315 else
316 graph = 0x0;
317
318 delete [] x;
319 delete [] y;
320
321 return graph;
322}
323
a5e1169e 324//_____________________________________________________________________________
54d68e69 325Bool_t AliTRDDataDCS::PerformFit()
a5e1169e 326{
54d68e69 327 //
328 // Do the fit
329 //
330
331 AliSplineFit *fitTemp;
a5e1169e 332
54d68e69 333 ClearFits();
334 InitFits();
a5e1169e 335
336 UInt_t nChannel;
337
338 for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++){
339
340 // perform fit only when it is needed
54d68e69 341 nChannel = fDatas[iAlias].GetFit().GetSize();
a5e1169e 342
343 for (UInt_t iSensor=0; iSensor < nChannel; iSensor++) {
344
54d68e69 345 fitTemp = Fit((TGraph*)fDatas[iAlias].GetGraph(iSensor),
346 fConfs[iAlias].GetMinPoints(),
347 fConfs[iAlias].GetIter(),
348 fConfs[iAlias].GetMaxDelta(),
349 fConfs[iAlias].GetFitReq());
a5e1169e 350
351 if (fitTemp == 0x0)
54d68e69 352 AliInfo(Form("Can't fit %s", Form(fConfs[iAlias].GetAmanda().Data(), iSensor)));
a5e1169e 353
54d68e69 354 fDatas[iAlias].GetFit().AddAt(fitTemp, iSensor);
a5e1169e 355 }
356 }
357
358 return kTRUE;
359
360}
361
362//_____________________________________________________________________________
c893147d 363AliSplineFit *AliTRDDataDCS::Fit(const TGraph * const graph,
54d68e69 364 Int_t minPoints, Int_t iter,
365 Double_t maxDelta, Int_t fitReq)
a5e1169e 366{
acc49af9 367 //
368 // Do the spline fit
369 //
370
a5e1169e 371 if (graph == 0x0) {
54d68e69 372 AliError("No graph for fit");
a5e1169e 373 return 0x0;
374 }
375
54d68e69 376 AliSplineFit *spline = new AliSplineFit();
377 spline->InitKnots(new TGraph (*graph), minPoints, iter, maxDelta);
378 spline->SplineFit(fitReq);
a5e1169e 379 spline->Cleanup(); // delete also new TGraph (*graph)
380
381 return spline;
382}
383
a5e1169e 384//_____________________________________________________________________________
c893147d 385void AliTRDDataDCS::Print(const Option_t * const option) const
a5e1169e 386{
54d68e69 387 //
388 // Print function
389 //
390
a5e1169e 391 if (option[0]=='g' || option[0]=='\0'){
392
54d68e69 393 if (fGraphsAreIni){
a5e1169e 394
395 for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++){
396
54d68e69 397 for (Int_t iSensor = 0; iSensor < fDatas[iAlias].GetGraph().GetSize(); iSensor++) {
a5e1169e 398
54d68e69 399 if (fDatas[iAlias].GetGraph(iSensor) != 0x0)
400 AliInfo(Form("Graph %s contain %d point(s)",
401 Form(fConfs[iAlias].GetAmanda(), iSensor),
402 ((TGraph*)(fDatas[iAlias].GetGraph(iSensor)))->GetN()));
a5e1169e 403 }
404 }
54d68e69 405 }
406 else{
407 AliInfo("Graphs don't exist");
a5e1169e 408 }
409 }
410
411
412 if (option[0] == 'f' || option[0]=='\0'){
413
54d68e69 414 AliInfo("no print for fit");
a5e1169e 415
416 }
417
418}
419
420//_____________________________________________________________________________
54d68e69 421TGraph *AliTRDDataDCS::GetGraph(UInt_t iAlias, UInt_t iChannel) const
a5e1169e 422{
54d68e69 423 //
424 // Get a graph
425 //
426
a5e1169e 427 if (iAlias >= fNAlias) {
54d68e69 428 AliWarning(Form("Alias %d is not correct", iAlias));
a5e1169e 429 return 0x0;
430 }
431
54d68e69 432 if (iChannel >= (UInt_t) fDatas[iAlias].GetGraph().GetSize()) {
433 AliWarning(Form("Alias %s is not correct",
434 Form(fConfs[iAlias].GetAmanda().Data(), iChannel)));
a5e1169e 435 return 0x0;
436 }
437
54d68e69 438 return (TGraph *)fDatas[iAlias].GetGraph(iChannel);
a5e1169e 439}
440
441//_____________________________________________________________________________
54d68e69 442AliSplineFit *AliTRDDataDCS::GetFit(UInt_t iAlias, UInt_t iChannel) const
a5e1169e 443{
54d68e69 444 //
445 // Get the spline fit
446 //
447
a5e1169e 448 if (iAlias >= fNAlias) {
449 AliWarning (Form("Alias %d is not correct", iAlias));
450 return 0x0;
451 }
452
54d68e69 453 if (iChannel >= (UInt_t) fDatas[iAlias].GetFit().GetSize()) {
454 AliWarning(Form("Alias %s is not correct",
455 Form(fConfs[iAlias].GetAmanda().Data(), iChannel)));
a5e1169e 456 return 0x0;
457 }
458
54d68e69 459 return (AliSplineFit *) fDatas[iAlias].GetFit(iChannel);
a5e1169e 460}
461
462//_____________________________________________________________________________
463TString AliTRDDataDCS::GetAmandaStr (UInt_t iAlias) const
464{
54d68e69 465 //
466 // Return the AMANDA string
467 //
468
a5e1169e 469 if (iAlias < fNAlias)
54d68e69 470 return fConfs[iAlias].GetAmanda();
a5e1169e 471 else return TString ();
472}
473
474//_____________________________________________________________________________
475UInt_t AliTRDDataDCS::GetNChannel (UInt_t iAlias) const
476{
54d68e69 477 //
478 // Get the channel number
479 //
480
a5e1169e 481 if (iAlias < fNAlias)
54d68e69 482 return fConfs[iAlias].GetNChannel();
a5e1169e 483 else return 0;
484}