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 //
23 // W. Monange (wilfried.monange@free.fr) //
25 ////////////////////////////////////////////////////////////////////////////
29 #include <TObjArray.h>
30 #include <AliCDBMetaData.h>
33 #include "AliDCSValue.h"
34 #include "AliDCSValue.h"
36 #include "AliTRDDataDCS.h"
37 #include "AliSplineFit.h"
39 ClassImp(AliTRDDataDCS)
44 AliTRDDataDCS dataDcs;
45 dataDcs.ExtractDCS (dcs);
46 ->call a storeRef function
47 dataDcs.PerformFit ();
48 dataDcs.ClearGraphs ();
49 ->call a store function
54 //_____________________________________________________________________________
55 AliTRDDataDCS::AliTRDDataDCS ()
56 : chamberByteStatus (0),
85 //_____________________________________________________________________________
86 AliTRDDataDCS::~AliTRDDataDCS ()
92 //_____________________________________________________________________________
93 void AliTRDDataDCS::Init ()
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);
118 for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++) {
119 fDatas[iAlias].graph.SetOwner (1);
120 fDatas[iAlias].fit.SetOwner (1);
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)
130 if (iAlias >= fNAlias) {
131 AliWarning (Form("Alias %d is not correct", iAlias));
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;
147 //_____________________________________________________________________________
148 void AliTRDDataDCS::InitFits ()
154 for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++) {
155 nChannel = fConfs[iAlias].enableFit ? fConfs[iAlias].nChannel : 0;
156 fDatas[iAlias].fit.Expand (nChannel);
162 //_____________________________________________________________________________
163 void AliTRDDataDCS::InitGraphs ()
169 for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++) {
170 nChannel = fConfs[iAlias].enableGraph ? fConfs[iAlias].nChannel : 0;
171 fDatas[iAlias].graph.Expand (nChannel);
177 //_____________________________________________________________________________
178 void AliTRDDataDCS::ClearFits ()
180 for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++) {
181 fDatas[iAlias].fit.Clear ();
182 fDatas[iAlias].fit.Expand (0);
188 //_____________________________________________________________________________
189 void AliTRDDataDCS::ClearGraphs ()
191 for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++) {
192 fDatas[iAlias].graph.Clear ();
193 fDatas[iAlias].graph.Expand (0);
196 graphsAreIni = false;
199 //_____________________________________________________________________________
200 void AliTRDDataDCS::Streamer(TBuffer &R__b) {
202 if (R__b.IsReading()) {
204 R__b.ReadBool (graphsAreIni);
205 R__b.ReadBool (fitsAreIni);
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);
222 for (UInt_t iAlias=0; iAlias<fNAlias; iAlias++)
223 fDatas[iAlias].graph = *(TObjArray*)R__b.ReadObject (TObjArray::Class());
227 for (UInt_t iAlias=0; iAlias<fNAlias; iAlias++)
228 fDatas[iAlias].fit = *(TObjArray*)R__b.ReadObject (TObjArray::Class());
231 AliInfo (Form("Read %d octets to the stream (%d Ko)", R__b.Length(), R__b.Length()/1024));
234 R__b.WriteBool (graphsAreIni);
235 R__b.WriteBool (fitsAreIni);
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);
250 for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++)
251 R__b.WriteObject ((TObject*)&fDatas[iAlias].graph);
255 for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++)
256 R__b.WriteObject ((TObject*)&fDatas[iAlias].fit);
259 AliInfo (Form("Write %d octets to the stream (%d Ko)", R__b.Length(), R__b.Length()/1024));
263 //_____________________________________________________________________________
264 Bool_t AliTRDDataDCS::ExtractDCS (TMap * dcsAlias)
266 if (dcsAlias == 0x0) {
267 AliWarning ("No DCS Map");
277 for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++){
279 // extract dcs only when it is needed
280 nChannel = fDatas[iAlias].graph.GetSize ();
282 for (UInt_t iSensor=0; iSensor < nChannel; iSensor++) {
284 graphTemp = FindAndMakeGraph (dcsAlias,
285 Form (fConfs[iAlias].amanda.Data(), iSensor),
286 fConfs[iAlias].dataType);
288 fDatas[iAlias].graph.AddAt (graphTemp, iSensor);
295 //_____________________________________________________________________________
296 TGraph * AliTRDDataDCS::FindAndMakeGraph (TMap * dcsMap, const char * amandaStr,
301 TPair * pair = (TPair*)dcsMap->FindObject(amandaStr);
303 AliWarning (Form("Can't find %s in dcsMap", amandaStr));
307 TObjArray * valueSet = (TObjArray*)pair->Value();
310 // Make graph of values read from DCS map
311 // (spline fit parameters will subsequently be obtained from this graph)
314 Int_t nEntries = valueSet->GetEntriesFast();
316 AliWarning (Form("Entry %s in dcsMap contain no datas", amandaStr));
320 Float_t * x = new Float_t [nEntries];
321 Float_t * y = new Float_t [nEntries];
326 for (iEntries = 0; iEntries< nEntries; iEntries++) {
328 AliDCSValue * val = (AliDCSValue *)valueSet->At(iEntries);
332 AliError (Form("Entry %s at %d contain no datas", amandaStr, iEntries));
337 time0 = val->GetTimeStamp();
340 x[iEntries] = (val->GetTimeStamp() - time0)/3600.0; // give times in fractions of hours
344 y[iEntries] = val->GetFloat();
348 y[iEntries] = (Float_t) val->GetChar();
353 AliError (Form("Bad type for entry %s", amandaStr));
359 graph = new TGraph (iEntries, x, y);
370 //_____________________________________________________________________________
371 Bool_t AliTRDDataDCS::PerformFit ()
373 AliSplineFit * fitTemp;
380 for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++){
382 // perform fit only when it is needed
383 nChannel = fDatas[iAlias].fit.GetSize ();
385 for (UInt_t iSensor=0; iSensor < nChannel; iSensor++) {
387 fitTemp = Fit ((TGraph*)fDatas[iAlias].graph[iSensor],
388 fConfs[iAlias].kMinPoints,
389 fConfs[iAlias].kIter,
390 fConfs[iAlias].kMaxDelta,
391 fConfs[iAlias].kFitReq);
394 AliInfo (Form ("Can't fit %s", Form (fConfs[iAlias].amanda.Data(), iSensor)));
396 fDatas[iAlias].fit.AddAt (fitTemp, iSensor);
404 //_____________________________________________________________________________
405 AliSplineFit * AliTRDDataDCS::Fit (TGraph * graph,
406 Int_t kMinPoints, Int_t kIter,
407 Double_t kMaxDelta, Int_t kFitReq)
410 AliError ("No graph for fit");
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)
423 //_____________________________________________________________________________
424 void AliTRDDataDCS::Print (Option_t* option) const
426 if (option[0]=='g' || option[0]=='\0'){
430 for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++){
432 for (Int_t iSensor = 0; iSensor < fDatas[iAlias].graph.GetSize(); iSensor++) {
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 ()));
441 AliInfo ("Graphs don't exist");
446 if (option[0] == 'f' || option[0]=='\0'){
448 AliInfo ("no print for fit");
454 //_____________________________________________________________________________
455 TGraph * AliTRDDataDCS::GetGraph (UInt_t iAlias, UInt_t iChannel) const
457 if (iAlias >= fNAlias) {
458 AliWarning (Form("Alias %d is not correct", iAlias));
462 if (iChannel >= (UInt_t)fDatas[iAlias].graph.GetSize()) {
463 AliWarning (Form("Alias %s is not correct",
464 Form(fConfs[iAlias].amanda.Data(), iChannel)));
468 return (TGraph *)fDatas[iAlias].graph[iChannel];
471 //_____________________________________________________________________________
472 AliSplineFit * AliTRDDataDCS::GetFit (UInt_t iAlias, UInt_t iChannel) const
474 if (iAlias >= fNAlias) {
475 AliWarning (Form("Alias %d is not correct", iAlias));
479 if (iChannel >= (UInt_t)fDatas[iAlias].fit.GetSize()) {
480 AliWarning (Form("Alias %s is not correct",
481 Form(fConfs[iAlias].amanda.Data(), iChannel)));
485 return (AliSplineFit *)fDatas[iAlias].fit[iChannel];
488 //_____________________________________________________________________________
489 TString AliTRDDataDCS::GetAmandaStr (UInt_t iAlias) const
491 if (iAlias < fNAlias)
492 return fConfs[iAlias].amanda;
493 else return TString ();
496 //_____________________________________________________________________________
497 UInt_t AliTRDDataDCS::GetNChannel (UInt_t iAlias) const
499 if (iAlias < fNAlias)
500 return fConfs[iAlias].nChannel;