1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ////////////////////////////////////////////////////////////////////////////
20 // This class collects the DCS information and does an AliSplineFit //
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(); //
33 // W. Monange (wilfried.monange@free.fr) //
35 ////////////////////////////////////////////////////////////////////////////
38 #include <TObjArray.h>
39 #include <AliCDBMetaData.h>
42 #include "AliDCSValue.h"
43 #include "AliDCSValue.h"
45 #include "AliTRDDataDCS.h"
46 #include "AliSplineFit.h"
48 ClassImp(AliTRDDataDCS)
50 //_____________________________________________________________________________
51 AliTRDDataDCS::AliTRDDataDCS()
53 ,fGraphsAreIni(kFALSE)
58 // Default constructor
65 //_____________________________________________________________________________
66 AliTRDDataDCS::~AliTRDDataDCS()
77 //_____________________________________________________________________________
78 void AliTRDDataDCS::Init()
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);
107 for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++) {
108 fDatas[iAlias].GetGraph().SetOwner(1);
109 fDatas[iAlias].GetFit().SetOwner(1);
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)
121 // Configure a DCS alias
124 if (iAlias >= fNAlias) {
125 AliWarning (Form("Alias %d is not correct", iAlias));
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);
141 //_____________________________________________________________________________
142 void AliTRDDataDCS::InitFits()
145 // Initialize the fits
152 for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++) {
153 nChannel = fConfs[iAlias].GetEnableFit() ? fConfs[iAlias].GetNChannel() : 0;
154 fDatas[iAlias].GetFit().Expand(nChannel);
160 //_____________________________________________________________________________
161 void AliTRDDataDCS::InitGraphs()
164 // Initialize the graphs
171 for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++) {
172 nChannel = fConfs[iAlias].GetEnableGraph() ? fConfs[iAlias].GetNChannel() : 0;
173 fDatas[iAlias].GetGraph().Expand(nChannel);
176 fGraphsAreIni = kTRUE;
179 //_____________________________________________________________________________
180 void AliTRDDataDCS::ClearFits()
186 for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++) {
187 fDatas[iAlias].GetFit().Clear();
188 fDatas[iAlias].GetFit().Expand(0);
191 fFitsAreIni = kFALSE;
194 //_____________________________________________________________________________
195 void AliTRDDataDCS::ClearGraphs()
201 for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++) {
202 fDatas[iAlias].GetGraph().Clear();
203 fDatas[iAlias].GetGraph().Expand(0);
206 fGraphsAreIni = kFALSE;
209 //_____________________________________________________________________________
210 Bool_t AliTRDDataDCS::ExtractDCS (TMap *dcsAlias)
213 // Extract the DCS information
216 if (dcsAlias == 0x0) {
217 AliWarning ("No DCS Map");
227 for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++){
229 // extract dcs only when it is needed
230 nChannel = fDatas[iAlias].GetGraph().GetSize();
232 for (UInt_t iSensor=0; iSensor < nChannel; iSensor++) {
234 graphTemp = FindAndMakeGraph(dcsAlias,
235 Form(fConfs[iAlias].GetAmanda().Data(), iSensor),
236 fConfs[iAlias].GetDataType());
238 fDatas[iAlias].GetGraph().AddAt(graphTemp, iSensor);
245 //_____________________________________________________________________________
246 TGraph *AliTRDDataDCS::FindAndMakeGraph (TMap *dcsMap, const char *amandaStr,
255 TPair *pair = (TPair *) dcsMap->FindObject(amandaStr);
257 AliWarning (Form("Can't find %s in dcsMap", amandaStr));
261 TObjArray *valueSet = (TObjArray *) pair->Value();
264 // Make graph of values read from DCS map
265 // (spline fit parameters will subsequently be obtained from this graph)
268 Int_t nEntries = valueSet->GetEntriesFast();
270 AliWarning (Form("Entry %s in dcsMap contain no datas", amandaStr));
274 Float_t * x = new Float_t[nEntries];
275 Float_t * y = new Float_t[nEntries];
280 for (iEntries = 0; iEntries< nEntries; iEntries++) {
282 AliDCSValue *val = (AliDCSValue *) valueSet->At(iEntries);
286 AliError(Form("Entry %s at %d contain no datas", amandaStr, iEntries));
291 time0 = val->GetTimeStamp();
294 x[iEntries] = (val->GetTimeStamp() - time0)/3600.0; // give times in fractions of hours
298 y[iEntries] = val->GetFloat();
302 y[iEntries] = (Float_t) val->GetChar();
307 AliError(Form("Bad type for entry %s", amandaStr));
313 graph = new TGraph(iEntries, x, y);
323 //_____________________________________________________________________________
324 Bool_t AliTRDDataDCS::PerformFit()
330 AliSplineFit *fitTemp;
337 for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++){
339 // perform fit only when it is needed
340 nChannel = fDatas[iAlias].GetFit().GetSize();
342 for (UInt_t iSensor=0; iSensor < nChannel; iSensor++) {
344 fitTemp = Fit((TGraph*)fDatas[iAlias].GetGraph(iSensor),
345 fConfs[iAlias].GetMinPoints(),
346 fConfs[iAlias].GetIter(),
347 fConfs[iAlias].GetMaxDelta(),
348 fConfs[iAlias].GetFitReq());
351 AliInfo(Form("Can't fit %s", Form(fConfs[iAlias].GetAmanda().Data(), iSensor)));
353 fDatas[iAlias].GetFit().AddAt(fitTemp, iSensor);
361 //_____________________________________________________________________________
362 AliSplineFit *AliTRDDataDCS::Fit(TGraph *graph,
363 Int_t minPoints, Int_t iter,
364 Double_t maxDelta, Int_t fitReq)
371 AliError("No graph for fit");
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)
383 //_____________________________________________________________________________
384 void AliTRDDataDCS::Print(Option_t* option) const
390 if (option[0]=='g' || option[0]=='\0'){
394 for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++){
396 for (Int_t iSensor = 0; iSensor < fDatas[iAlias].GetGraph().GetSize(); iSensor++) {
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()));
406 AliInfo("Graphs don't exist");
411 if (option[0] == 'f' || option[0]=='\0'){
413 AliInfo("no print for fit");
419 //_____________________________________________________________________________
420 TGraph *AliTRDDataDCS::GetGraph(UInt_t iAlias, UInt_t iChannel) const
426 if (iAlias >= fNAlias) {
427 AliWarning(Form("Alias %d is not correct", iAlias));
431 if (iChannel >= (UInt_t) fDatas[iAlias].GetGraph().GetSize()) {
432 AliWarning(Form("Alias %s is not correct",
433 Form(fConfs[iAlias].GetAmanda().Data(), iChannel)));
437 return (TGraph *)fDatas[iAlias].GetGraph(iChannel);
440 //_____________________________________________________________________________
441 AliSplineFit *AliTRDDataDCS::GetFit(UInt_t iAlias, UInt_t iChannel) const
444 // Get the spline fit
447 if (iAlias >= fNAlias) {
448 AliWarning (Form("Alias %d is not correct", iAlias));
452 if (iChannel >= (UInt_t) fDatas[iAlias].GetFit().GetSize()) {
453 AliWarning(Form("Alias %s is not correct",
454 Form(fConfs[iAlias].GetAmanda().Data(), iChannel)));
458 return (AliSplineFit *) fDatas[iAlias].GetFit(iChannel);
461 //_____________________________________________________________________________
462 TString AliTRDDataDCS::GetAmandaStr (UInt_t iAlias) const
465 // Return the AMANDA string
468 if (iAlias < fNAlias)
469 return fConfs[iAlias].GetAmanda();
470 else return TString ();
473 //_____________________________________________________________________________
474 UInt_t AliTRDDataDCS::GetNChannel (UInt_t iAlias) const
477 // Get the channel number
480 if (iAlias < fNAlias)
481 return fConfs[iAlias].GetNChannel();