STEER/CDB: Missing delete in AliDCSSensor dtor
[u/mrichter/AliRoot.git] / STEER / CDB / AliDCSSensor.cxx
CommitLineData
7264822f 1/**************************************************************************
2 * Copyright(c) 2006-07, 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
17////////////////////////////////////////////////////////////////////////////////
18// //
1bc2e138 19// Class describing time dependent values read from DCS sensors //
20// (including pointers to graphs/fits) //
7264822f 21// Authors: Marian Ivanov, Haavard Helstrup and Martin Siska //
22// //
23////////////////////////////////////////////////////////////////////////////////
24
25
7264822f 26#include "AliDCSSensor.h"
6ec4e3e3 27#include "TDatime.h"
ceb67868 28#include "TCanvas.h"
e27404da 29ClassImp(AliDCSSensor)
8cb8848e 30
8cb8848e 31const Double_t kSecInHour = 3600.; // seconds in one hour
32
7264822f 33
34
35AliDCSSensor::AliDCSSensor():
36 fId(),
37 fIdDCS(0),
24cd438b 38 fStringID(),
7264822f 39 fStartTime(0),
8cb8848e 40 fEndTime(0),
7264822f 41 fGraph(0),
42 fFit(0),
43 fX(0),
44 fY(0),
45 fZ(0)
46{
47 //
48 // Standard constructor
49 //
50}
51
52AliDCSSensor::AliDCSSensor(const AliDCSSensor& source) :
53 TNamed(source),
54 fId(source.fId),
55 fIdDCS(source.fIdDCS),
24cd438b 56 fStringID(source.fStringID),
7264822f 57 fStartTime(source.fStartTime),
8cb8848e 58 fEndTime(source.fEndTime),
9663477d 59 fGraph(0),
60 fFit(0),
7264822f 61 fX(source.fX),
62 fY(source.fY),
63 fZ(source.fZ)
64//
65// Copy constructor
66//
9663477d 67{
68 if (source.fGraph) fGraph = (TGraph*)source.fGraph->Clone();
69 if (source.fFit) fFit = (AliSplineFit*)source.fFit->Clone();
70}
7264822f 71
422b2142 72AliDCSSensor::~AliDCSSensor(){
73 //
74 // Destructor
75 //
76 if(fGraph)
77 delete fGraph;
78 fGraph=0;
79
80}
81
7264822f 82AliDCSSensor& AliDCSSensor::operator=(const AliDCSSensor& source){
83//
84// assignment operator
85//
86 if (&source == this) return *this;
87 new (this) AliDCSSensor(source);
dc0184e7 88
89 return *this;
7264822f 90}
91
3dc6d65a 92
ceb67868 93void AliDCSSensor::Print(const Option_t* option) const{
3dc6d65a 94 //
ceb67868 95 // print function
3dc6d65a 96 //
97 TString opt = option; opt.ToLower();
98 printf("%s:%s\n",GetTitle(), GetName());
ceb67868 99 printf("%s\n",fStringID.Data());
100
101}
102
e94b22cc 103void AliDCSSensor::Draw(Option_t* option) {
ceb67868 104 //
105 // draw function - to viusalize sensor
106 // Unfortuantelly - it make a memory leak as function Draw does not return the object pointer
107 //
e94b22cc 108 TCanvas * canvas = new TCanvas((fStringID+option).Data(), (fStringID+option).Data());
ceb67868 109 if (fGraph){
110 // transform points to time in s
111 Int_t npoints = fGraph->GetN();
112 for (Int_t i=0; i<npoints; i++){
113 fGraph->GetX()[i]=fGraph->GetX()[i]*3600+fStartTime;
114 }
e94b22cc 115 fGraph->Draw("alp");
ceb67868 116 return;
3dc6d65a 117 }
e94b22cc 118 canvas->cd();
ceb67868 119 TGraph * graph = MakeGraph(100); // memory leak - we can not modify the content - const method
120 graph->Draw(option); //
121 //
3dc6d65a 122}
123
ceb67868 124
125
7264822f 126//_____________________________________________________________________________
dc0184e7 127Double_t AliDCSSensor::GetValue(UInt_t timeSec)
7264822f 128{
3dc6d65a 129 //
1bc2e138 130 // Get DCS value for actual sensor
6ec4e3e3 131 // timeSec given as offset from start-of-map measured in seconds
132 // *NOTE* In the current TPC setup, start-of-map is defined as the
133 // first measured point for each sensor. This will be different
134 // for each sensor in the array. If you want to get a value at the
135 // same absolute time, use AliDCSSensor::GetValue(TTimeStamp time)
136 // or AliDCSSensorArray::GetValue (UInt_t timeSec, Int_t sensor)
137 // which measure offsets with respect to the (global) start-of-run
7264822f 138 //
2972d4eb 139 Bool_t inside=kTRUE;
008ef66a 140 return Eval(TTimeStamp((time_t)(fStartTime+timeSec),0),inside);
7264822f 141}
142//_____________________________________________________________________________
143Double_t AliDCSSensor::GetValue(TTimeStamp time)
144{
1bc2e138 145 // Get DCS value for actual sensor
7264822f 146 // time given as absolute TTimeStamp
147 //
2972d4eb 148 Bool_t inside=kTRUE;
67a165ed 149 return Eval(time, inside);
8cb8848e 150}
151
152//_____________________________________________________________________________
153
1bc2e138 154Double_t AliDCSSensor::Eval(const TTimeStamp& time, Bool_t& inside) const
8cb8848e 155{
156 //
1bc2e138 157 // Return DCS value at given time
158 // The value is calculated from the AliSplineFit, if a fit is not available
159 // the most recent reading from the Graph of DCS points is returned (if
160 // the graph is present)
67a165ed 161 // If time < start of map return value at start of map, inside = false
162 // If time > end of map return value at end of map, inside = false
8cb8848e 163
164 UInt_t timeSec = time.GetSec();
165 UInt_t diff = timeSec-fStartTime;
67a165ed 166 inside = true;
8cb8848e 167
67a165ed 168 if ( timeSec < fStartTime ) {
169 inside=false;
170 diff=0;
171 }
172 if ( timeSec > fEndTime ) {
173 inside=false;
174 diff = fEndTime-fStartTime;
175 }
8cb8848e 176
177 Double_t timeHour = diff/kSecInHour;
178 if ( fFit ) {
179 return fFit->Eval(timeHour);
180 } else {
e7097603 181 if ( fGraph ) {
182 return EvalGraph(timeHour);
183 } else {
184 return -99;
185 }
8cb8848e 186 }
187}
e7097603 188//_____________________________________________________________________________
1bc2e138 189
190Double_t AliDCSSensor::EvalGraph(const TTimeStamp& time, Bool_t& inside) const
191{
192 //
193 // Return DCS value from graph of DCS points (i.e return last reading before
194 // the time specified by TTimeStamp
195 // If time < start of map return value at start of map, inside = false
196 // If time > end of map return value at end of map, inside = false
197
198 UInt_t timeSec = time.GetSec();
199 UInt_t diff = timeSec-fStartTime;
200 inside = true;
201
202 if ( timeSec < fStartTime ) {
203 inside=false;
204 diff=0;
205 }
206 if ( timeSec > fEndTime ) {
207 inside=false;
208 diff = fEndTime-fStartTime;
209 }
210
211 Double_t timeHour = diff/kSecInHour;
212 if ( fGraph ) {
213 return EvalGraph(timeHour);
214 } else {
215 return -99;
216 }
217}
218//_____________________________________________________________________________
e7097603 219Double_t AliDCSSensor::EvalGraph(const Double_t& timeHour) const
220{
221 //
222 // Extract last value in graph observed before time given by timeHour
223 //
224
225 // return -99 if point specified is before beginning of graph
226 Double_t x=0; Double_t y=0;
227 fGraph->GetPoint(0,x,y);
228 if ( timeHour < x ) return -99;
229
230 // return previous point when first time > timeHour is observed
231
232 Int_t npoints = fGraph->GetN();
233 for (Int_t i=1; i<npoints; i++) {
234 fGraph->GetPoint(i,x,y);
235 if ( timeHour < x ) {
236 fGraph->GetPoint(i-1,x,y);
237 return y;
238 }
239 }
240
241 // return last point if all times are < timeHour
242 return y;
243}
244
8cb8848e 245
e7097603 246//_____________________________________________________________________________
6ec4e3e3 247TGraph* AliDCSSensor::MakeGraph(Int_t nPoints, Bool_t debug) const
8cb8848e 248{
249 //
250 // Make graph from start time to end time of DCS values
251 //
252
6ec4e3e3 253
254
8cb8848e 255 UInt_t stepTime = (fEndTime-fStartTime)/nPoints;
256
6ec4e3e3 257 if (debug==kTRUE) {
258 printf ("Start time %d, End time %d, step time %d\n",
259 fStartTime,fEndTime,stepTime);
260 TTimeStamp t((time_t)fStartTime,0); t.Print();
261 TTimeStamp t2((time_t)fEndTime,0); t2.Print();
262 }
263
8cb8848e 264 if ( !fFit ) return 0;
265
266 Double_t *x = new Double_t[nPoints+1];
267 Double_t *y = new Double_t[nPoints+1];
268 for (Int_t ip=0; ip<nPoints; ip++) {
6ec4e3e3 269 x[ip] = (time_t)(fStartTime+ip*stepTime);
8cb8848e 270 y[ip] = fFit->Eval(ip*stepTime/kSecInHour);
6ec4e3e3 271 if (debug==kTRUE) {
272 TTimeStamp t3((time_t)x[ip],0);
273 printf ("x=%f, y=%f ",x[ip],y[ip]);
274 t3.Print();
275 }
8cb8848e 276 }
277
278 TGraph *graph = new TGraph(nPoints,x,y);
279 delete [] x;
280 delete [] y;
281
282 graph->GetXaxis()->SetTimeDisplay(1);
283 graph->GetXaxis()->SetLabelOffset(0.02);
284 graph->GetXaxis()->SetTimeFormat("#splitline{%d/%m}{%H:%M}");
82dfb6c8 285
8cb8848e 286 return graph;
7264822f 287}
288
24cd438b 289//_____________________________________________________________________________
290
291TClonesArray * AliDCSSensor::ReadTree(TTree* tree) {
292 //
293 // read values from ascii file
294 //
82dfb6c8 295
24cd438b 296 Int_t nentries = tree->GetEntries();
82dfb6c8 297
24cd438b 298 char stringId[100];
299 Int_t num=0;
300 Int_t idDCS=0;
301 Double_t x=0;
302 Double_t y=0;
303 Double_t z=0;
304
305 tree->SetBranchAddress("StringID",&stringId);
306 tree->SetBranchAddress("IdDCS",&idDCS);
307 tree->SetBranchAddress("Num",&num);
308 tree->SetBranchAddress("X",&x);
309 tree->SetBranchAddress("Y",&y);
310 tree->SetBranchAddress("Z",&z);
311
312 // firstSensor = (Int_t)tree->GetMinimum("ECha");
313 // lastSensor = (Int_t)tree->GetMaximum("ECha");
314
315 TClonesArray * array = new TClonesArray("AliDCSSensor",nentries);
316 printf ("nentries = %d\n",nentries);
317
318 for (Int_t isensor=0; isensor<nentries; isensor++){
319 AliDCSSensor * sens = new ((*array)[isensor])AliDCSSensor;
320 tree->GetEntry(isensor);
321 sens->SetId(isensor);
322 sens->SetIdDCS(idDCS);
323 sens->SetStringID(TString(stringId));
324 sens->SetX(x);
325 sens->SetY(y);
326 sens->SetZ(z);
327
328 }
329 return array;
330}
7264822f 331