Line data Source code
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 <TMap.h>
40 :
41 : #include "AliDCSValue.h"
42 : #include "AliDCSValue.h"
43 : #include "AliLog.h"
44 : #include "AliSplineFit.h"
45 :
46 : #include "AliTRDDataDCS.h"
47 :
48 48 : ClassImp(AliTRDDataDCS)
49 :
50 : //_____________________________________________________________________________
51 0 : AliTRDDataDCS::AliTRDDataDCS()
52 0 : :TNamed()
53 0 : ,fGraphsAreIni(kFALSE)
54 0 : ,fFitsAreIni(kFALSE)
55 0 : ,fNAlias(22)
56 0 : {
57 : //
58 : // Default constructor
59 : //
60 :
61 0 : Init ();
62 :
63 0 : }
64 :
65 : //_____________________________________________________________________________
66 : AliTRDDataDCS::~AliTRDDataDCS()
67 0 : {
68 : //
69 : // Destructor
70 : //
71 :
72 0 : ClearFits();
73 0 : ClearGraphs();
74 :
75 0 : }
76 :
77 : //_____________________________________________________________________________
78 : void AliTRDDataDCS::Init()
79 : {
80 : //
81 : // Initialization
82 : //
83 :
84 0 : SetConf(kChamberByteStatus, "trd_chamberByteStatus%03d",'c', 540, kTRUE,kFALSE, 10,10,0,2);
85 0 : SetConf(kPreTrigger, "trd_preTrigger", 'c', 1, kTRUE, kTRUE, 10,10,0,2);
86 0 : SetConf(kGoofyHv, "trd_goofyHv", 'f', 1, kTRUE, kTRUE, 10,10,0,2);
87 0 : SetConf(kGoofyPeakPos, "trd_goofyPeakPos%02d", 'f', 2, kTRUE, kTRUE, 10,10,0,2);
88 0 : SetConf(kGoofyPeakArea, "trd_goofyPeakArea%02d", 'f', 2, kTRUE, kTRUE, 10,10,0,2);
89 0 : SetConf(kGoofyTemp, "trd_goofyTemp%02d", 'f', 2, kTRUE, kTRUE, 10,10,0,2);
90 0 : SetConf(kGoofyPressure, "trd_goofyPressure", 'f', 1, kTRUE, kTRUE, 10,10,0,2);
91 0 : SetConf(kGoofyVelocity, "trd_goofyVelocity", 'f', 1, kTRUE, kTRUE, 10,10,0,2);
92 0 : SetConf(kGoofyGain, "trd_goofyGain%02d", 'f', 2, kTRUE, kTRUE, 10,10,0,2);
93 0 : SetConf(kGoofyCO2, "trd_goofyCO2", 'f', 1, kTRUE, kTRUE, 10,10,0,2);
94 0 : SetConf(kGoofyN2, "trd_goofyN2", 'f', 1, kTRUE, kTRUE, 10,10,0,2);
95 0 : SetConf(kGasO2, "trd_gasO2", 'f', 1, kTRUE, kTRUE, 10,10,0,2);
96 0 : SetConf(kGasOverpressure, "trd_gasOverpressure", 'f', 1, kTRUE, kTRUE, 10,10,0,2);
97 0 : SetConf(kEnvTemp, "trd_envTemp%03d", 'f', 540, kTRUE, kTRUE, 10,10,0,2);
98 0 : SetConf(kHvAnodeImon, "trd_hvAnodeImon%03d", 'f', 540, kTRUE, kTRUE, 10,10,0,2);
99 0 : SetConf(kHvDriftImon, "trd_hvDriftImon%03d", 'f', 540, kTRUE, kTRUE, 10,10,0,2);
100 0 : SetConf(kHvAnodeUmon, "trd_hvAnodeUmon%03d", 'f', 540, kTRUE, kTRUE, 10,10,0,2);
101 0 : SetConf(kHvDriftUmon, "trd_hvDriftUmon%03d", 'f', 540, kTRUE, kTRUE, 10,10,0,2);
102 0 : SetConf(kAdcClkPhase, "trd_adcClkPhase", 'f', 1, kTRUE, kTRUE, 10,10,0,2);
103 0 : SetConf(kAtmPressure, "trd_atmPressure", 'f', 1, kTRUE, kTRUE, 10,10,0,2);
104 0 : SetConf(kLuminosity, "trd_luminosity", 'f', 1, kTRUE, kTRUE, 10,10,0,2);
105 0 : SetConf(kMagneticField, "trd_magneticField", 'f', 1, kTRUE, kTRUE, 10,10,0,2);
106 :
107 0 : for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++) {
108 0 : fDatas[iAlias].GetGraph().SetOwner(1);
109 0 : fDatas[iAlias].GetFit().SetOwner(1);
110 : }
111 :
112 0 : }
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 0 : if (iAlias >= fNAlias) {
125 0 : AliWarning (Form("Alias %d is not correct", iAlias));
126 0 : return;
127 : }
128 :
129 0 : fConfs[iAlias].SetAmanda(amanda);
130 0 : fConfs[iAlias].SetDataType(dataType);
131 0 : fConfs[iAlias].SetNChannel(nChannel);
132 0 : fConfs[iAlias].SetEnableGraph(enableGraph);
133 0 : fConfs[iAlias].SetEnableFit(enableFit);
134 0 : fConfs[iAlias].SetMinPoints(minPoints);
135 0 : fConfs[iAlias].SetIter(iter);
136 0 : fConfs[iAlias].SetMaxDelta(maxDelta);
137 0 : fConfs[iAlias].SetFitReq(fitReq);
138 :
139 0 : }
140 :
141 : //_____________________________________________________________________________
142 : void AliTRDDataDCS::InitFits()
143 : {
144 : //
145 : // Initialize the fits
146 : //
147 :
148 0 : if (fFitsAreIni)
149 : return;
150 :
151 : UInt_t nChannel;
152 0 : for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++) {
153 0 : nChannel = fConfs[iAlias].GetEnableFit() ? fConfs[iAlias].GetNChannel() : 0;
154 0 : fDatas[iAlias].GetFit().Expand(nChannel);
155 : }
156 :
157 0 : fFitsAreIni = kTRUE;
158 0 : }
159 :
160 : //_____________________________________________________________________________
161 : void AliTRDDataDCS::InitGraphs()
162 : {
163 : //
164 : // Initialize the graphs
165 : //
166 :
167 0 : if (fGraphsAreIni)
168 : return;
169 :
170 : UInt_t nChannel;
171 0 : for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++) {
172 0 : nChannel = fConfs[iAlias].GetEnableGraph() ? fConfs[iAlias].GetNChannel() : 0;
173 0 : fDatas[iAlias].GetGraph().Expand(nChannel);
174 : }
175 :
176 0 : fGraphsAreIni = kTRUE;
177 0 : }
178 :
179 : //_____________________________________________________________________________
180 : void AliTRDDataDCS::ClearFits()
181 : {
182 : //
183 : // Clear the fits
184 : //
185 :
186 0 : for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++) {
187 0 : fDatas[iAlias].GetFit().Clear();
188 0 : fDatas[iAlias].GetFit().Expand(0);
189 : }
190 :
191 0 : fFitsAreIni = kFALSE;
192 0 : }
193 :
194 : //_____________________________________________________________________________
195 : void AliTRDDataDCS::ClearGraphs()
196 : {
197 : //
198 : // Clear the grpahs
199 : //
200 :
201 0 : for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++) {
202 0 : fDatas[iAlias].GetGraph().Clear();
203 0 : fDatas[iAlias].GetGraph().Expand(0);
204 : }
205 :
206 0 : fGraphsAreIni = kFALSE;
207 0 : }
208 :
209 : //_____________________________________________________________________________
210 : Bool_t AliTRDDataDCS::ExtractDCS (TMap *dcsAlias)
211 : {
212 : //
213 : // Extract the DCS information
214 : //
215 :
216 0 : if (dcsAlias == 0x0) {
217 0 : AliWarning ("No DCS Map");
218 0 : return kFALSE;
219 : }
220 :
221 0 : ClearGraphs();
222 0 : InitGraphs();
223 :
224 : TGraph *graphTemp;
225 : UInt_t nChannel;
226 :
227 0 : for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++){
228 :
229 : // extract dcs only when it is needed
230 0 : nChannel = fDatas[iAlias].GetGraph().GetSize();
231 :
232 0 : for (UInt_t iSensor=0; iSensor < nChannel; iSensor++) {
233 :
234 0 : graphTemp = FindAndMakeGraph(dcsAlias,
235 0 : Form(fConfs[iAlias].GetAmanda().Data(), iSensor),
236 0 : fConfs[iAlias].GetDataType());
237 :
238 0 : fDatas[iAlias].GetGraph().AddAt(graphTemp, iSensor);
239 : }
240 : }
241 :
242 : return kTRUE;
243 0 : }
244 :
245 : //_____________________________________________________________________________
246 : TGraph *AliTRDDataDCS::FindAndMakeGraph (TMap * const dcsMap
247 : , const char *amandaStr
248 : , char dataType)
249 : {
250 : //
251 : // Create the graphs
252 : //
253 :
254 : TGraph *graph;
255 :
256 0 : TPair *pair = (TPair *) dcsMap->FindObject(amandaStr);
257 0 : if (pair == 0x0) {
258 0 : AliWarning (Form("Can't find %s in dcsMap", amandaStr));
259 0 : return 0x0;
260 : }
261 :
262 0 : TObjArray *valueSet = (TObjArray *) pair->Value();
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 0 : Int_t nEntries = valueSet->GetEntriesFast();
270 0 : if (nEntries == 0) {
271 0 : AliWarning (Form("Entry %s in dcsMap contain no datas", amandaStr));
272 0 : return 0x0;
273 : }
274 :
275 0 : Float_t * x = new Float_t[nEntries];
276 0 : Float_t * y = new Float_t[nEntries];
277 :
278 : Bool_t ok = kTRUE;
279 : Int_t time0 = 0;
280 : Int_t iEntries;
281 0 : for (iEntries = 0; iEntries< nEntries; iEntries++) {
282 :
283 0 : AliDCSValue *val = (AliDCSValue *) valueSet->At(iEntries);
284 :
285 0 : if (val == 0x0) {
286 : ok = false;
287 0 : AliError(Form("Entry %s at %d contain no datas", amandaStr, iEntries));
288 0 : break;
289 : }
290 :
291 0 : if (time0 == 0)
292 0 : time0 = val->GetTimeStamp();
293 :
294 :
295 0 : x[iEntries] = (val->GetTimeStamp() - time0)/3600.0; // give times in fractions of hours
296 :
297 0 : switch (dataType) {
298 : case 'f' :
299 0 : y[iEntries] = val->GetFloat();
300 0 : break;
301 :
302 : case 'c' :
303 0 : y[iEntries] = (Float_t) val->GetChar();
304 0 : break;
305 :
306 : default :
307 : ok = false;
308 0 : AliError(Form("Bad type for entry %s", amandaStr));
309 0 : break;
310 : }
311 0 : }
312 :
313 0 : if (ok)
314 0 : graph = new TGraph(iEntries, x, y);
315 : else
316 : graph = 0x0;
317 :
318 0 : delete [] x;
319 0 : delete [] y;
320 :
321 : return graph;
322 0 : }
323 :
324 : //_____________________________________________________________________________
325 : Bool_t AliTRDDataDCS::PerformFit()
326 : {
327 : //
328 : // Do the fit
329 : //
330 :
331 : AliSplineFit *fitTemp;
332 :
333 0 : ClearFits();
334 0 : InitFits();
335 :
336 : UInt_t nChannel;
337 :
338 0 : for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++){
339 :
340 : // perform fit only when it is needed
341 0 : nChannel = fDatas[iAlias].GetFit().GetSize();
342 :
343 0 : for (UInt_t iSensor=0; iSensor < nChannel; iSensor++) {
344 :
345 0 : fitTemp = Fit((TGraph*)fDatas[iAlias].GetGraph(iSensor),
346 0 : fConfs[iAlias].GetMinPoints(),
347 0 : fConfs[iAlias].GetIter(),
348 0 : fConfs[iAlias].GetMaxDelta(),
349 0 : fConfs[iAlias].GetFitReq());
350 :
351 0 : if (fitTemp == 0x0)
352 0 : AliInfo(Form("Can't fit %s", Form(fConfs[iAlias].GetAmanda().Data(), iSensor)));
353 :
354 0 : fDatas[iAlias].GetFit().AddAt(fitTemp, iSensor);
355 : }
356 : }
357 :
358 0 : return kTRUE;
359 :
360 0 : }
361 :
362 : //_____________________________________________________________________________
363 : AliSplineFit *AliTRDDataDCS::Fit(const TGraph * const graph,
364 : Int_t minPoints, Int_t iter,
365 : Double_t maxDelta, Int_t fitReq)
366 : {
367 : //
368 : // Do the spline fit
369 : //
370 :
371 0 : if (graph == 0x0) {
372 0 : AliError("No graph for fit");
373 0 : return 0x0;
374 : }
375 :
376 0 : AliSplineFit *spline = new AliSplineFit();
377 0 : spline->InitKnots(new TGraph (*graph), minPoints, iter, maxDelta);
378 0 : spline->SplineFit(fitReq);
379 0 : spline->Cleanup(); // delete also new TGraph (*graph)
380 :
381 : return spline;
382 0 : }
383 :
384 : //_____________________________________________________________________________
385 : void AliTRDDataDCS::Print(const Option_t * const option) const
386 : {
387 : //
388 : // Print function
389 : //
390 :
391 0 : if (option[0]=='g' || option[0]=='\0'){
392 :
393 0 : if (fGraphsAreIni){
394 :
395 0 : for (UInt_t iAlias = 0; iAlias < fNAlias; iAlias++){
396 :
397 0 : for (Int_t iSensor = 0; iSensor < fDatas[iAlias].GetGraph().GetSize(); iSensor++) {
398 :
399 0 : if (fDatas[iAlias].GetGraph(iSensor) != 0x0)
400 0 : AliInfo(Form("Graph %s contain %d point(s)",
401 : Form(fConfs[iAlias].GetAmanda(), iSensor),
402 : ((TGraph*)(fDatas[iAlias].GetGraph(iSensor)))->GetN()));
403 : }
404 : }
405 0 : }
406 : else{
407 0 : AliInfo("Graphs don't exist");
408 : }
409 : }
410 :
411 :
412 0 : if (option[0] == 'f' || option[0]=='\0'){
413 :
414 0 : AliInfo("no print for fit");
415 :
416 0 : }
417 :
418 0 : }
419 :
420 : //_____________________________________________________________________________
421 : TGraph *AliTRDDataDCS::GetGraph(UInt_t iAlias, UInt_t iChannel) const
422 : {
423 : //
424 : // Get a graph
425 : //
426 :
427 0 : if (iAlias >= fNAlias) {
428 0 : AliWarning(Form("Alias %d is not correct", iAlias));
429 0 : return 0x0;
430 : }
431 :
432 0 : if (iChannel >= (UInt_t) fDatas[iAlias].GetGraph().GetSize()) {
433 0 : AliWarning(Form("Alias %s is not correct",
434 : Form(fConfs[iAlias].GetAmanda().Data(), iChannel)));
435 0 : return 0x0;
436 : }
437 :
438 0 : return (TGraph *)fDatas[iAlias].GetGraph(iChannel);
439 0 : }
440 :
441 : //_____________________________________________________________________________
442 : AliSplineFit *AliTRDDataDCS::GetFit(UInt_t iAlias, UInt_t iChannel) const
443 : {
444 : //
445 : // Get the spline fit
446 : //
447 :
448 0 : if (iAlias >= fNAlias) {
449 0 : AliWarning (Form("Alias %d is not correct", iAlias));
450 0 : return 0x0;
451 : }
452 :
453 0 : if (iChannel >= (UInt_t) fDatas[iAlias].GetFit().GetSize()) {
454 0 : AliWarning(Form("Alias %s is not correct",
455 : Form(fConfs[iAlias].GetAmanda().Data(), iChannel)));
456 0 : return 0x0;
457 : }
458 :
459 0 : return (AliSplineFit *) fDatas[iAlias].GetFit(iChannel);
460 0 : }
461 :
462 : //_____________________________________________________________________________
463 : TString AliTRDDataDCS::GetAmandaStr (UInt_t iAlias) const
464 : {
465 : //
466 : // Return the AMANDA string
467 : //
468 :
469 0 : if (iAlias < fNAlias)
470 0 : return fConfs[iAlias].GetAmanda();
471 0 : else return TString ();
472 0 : }
473 :
474 : //_____________________________________________________________________________
475 : UInt_t AliTRDDataDCS::GetNChannel (UInt_t iAlias) const
476 : {
477 : //
478 : // Get the channel number
479 : //
480 :
481 0 : if (iAlias < fNAlias)
482 0 : return fConfs[iAlias].GetNChannel();
483 0 : else return 0;
484 0 : }
|