]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliDCSSensor.cxx
bug fixed
[u/mrichter/AliRoot.git] / STEER / AliDCSSensor.cxx
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 //                                                                            //
19 // Class describing TPC temperature sensors (including pointers to graphs/fits//
20 // Authors: Marian Ivanov, Haavard Helstrup and Martin Siska                  //
21 //                                                                            //
22 ////////////////////////////////////////////////////////////////////////////////
23
24
25 #include "AliDCSSensor.h"
26 #include "TDatime.h"
27 ClassImp(AliDCSSensor)
28
29 const Double_t kSecInHour = 3600.; // seconds in one hour
30
31
32
33 AliDCSSensor::AliDCSSensor():
34   fId(),
35   fIdDCS(0),
36   fStringID(),
37   fStartTime(0),
38   fEndTime(0),
39   fGraph(0),
40   fFit(0),
41   fX(0),
42   fY(0),
43   fZ(0)
44 {
45   //
46   //  Standard constructor
47   //
48 }
49
50 AliDCSSensor::AliDCSSensor(const AliDCSSensor& source) :
51    TNamed(source),
52    fId(source.fId),
53    fIdDCS(source.fIdDCS),
54    fStringID(source.fStringID),
55    fStartTime(source.fStartTime),
56    fEndTime(source.fEndTime),
57    fGraph(source.fGraph),
58    fFit(source.fFit),
59    fX(source.fX),
60    fY(source.fY),
61    fZ(source.fZ)
62 //
63 //  Copy constructor
64 //
65 { }
66
67 AliDCSSensor& AliDCSSensor::operator=(const AliDCSSensor& source){
68 //
69 // assignment operator
70 //
71   if (&source == this) return *this;
72   new (this) AliDCSSensor(source);
73
74   return *this;
75 }
76
77 //_____________________________________________________________________________
78 Double_t AliDCSSensor::GetValue(UInt_t timeSec)
79 {
80  //
81  // Get temperature value for actual sensor
82  //  timeSec given as offset from start-of-map measured in seconds
83  //  *NOTE* In the current TPC setup, start-of-map is defined as the 
84  //         first measured point for each sensor. This will be different
85  //         for each sensor in the array. If you want to get a value at the 
86  //         same absolute time, use AliDCSSensor::GetValue(TTimeStamp time)
87  //         or AliDCSSensorArray::GetValue (UInt_t timeSec, Int_t sensor)
88  //         which measure offsets with respect to the (global) start-of-run
89  //
90  Bool_t inside=kTRUE;
91  return Eval(TTimeStamp((time_t)(fStartTime+timeSec),0),inside);
92 }
93 //_____________________________________________________________________________
94 Double_t AliDCSSensor::GetValue(TTimeStamp time) 
95 {
96  // Get temperature value for actual sensor
97  //  time given as absolute TTimeStamp
98  //
99  Bool_t inside=kTRUE;
100  return Eval(time, inside);
101 }
102
103 //_____________________________________________________________________________
104
105 Double_t AliDCSSensor::Eval(const TTimeStamp& time, Bool_t inside) const
106 {
107   // 
108   // Return temperature at given time
109   //  If time < start of map  return value at start of map, inside = false
110   //  If time > end of map    return value at end of map, inside = false
111   
112   UInt_t timeSec = time.GetSec();
113   UInt_t diff = timeSec-fStartTime;
114   inside = true;
115   
116   if ( timeSec < fStartTime ) { 
117      inside=false;
118      diff=0;
119   }
120   if ( timeSec > fEndTime ) {
121      inside=false;
122      diff = fEndTime-fStartTime;
123   }
124  
125   Double_t timeHour = diff/kSecInHour;
126   if ( fFit ) {
127      return fFit->Eval(timeHour); 
128   } else {
129      if ( fGraph ) {
130        return EvalGraph(timeHour);
131      } else {  
132        return -99;
133      }
134   }
135 }
136 //_____________________________________________________________________________
137 Double_t AliDCSSensor::EvalGraph(const Double_t& timeHour) const 
138 {
139   //
140   // Extract last value in graph observed before time given by timeHour
141   //
142
143   // return -99 if point specified is before beginning of graph
144   Double_t x=0; Double_t y=0;
145   fGraph->GetPoint(0,x,y);
146   if ( timeHour < x ) return -99;
147   
148   // return previous point when first time > timeHour is observed
149   
150   Int_t npoints = fGraph->GetN();
151   for (Int_t i=1; i<npoints; i++) {
152      fGraph->GetPoint(i,x,y);
153      if ( timeHour < x ) {
154        fGraph->GetPoint(i-1,x,y);
155        return y;
156      }
157   }
158   
159   // return last point if all times are < timeHour
160   return y;
161
162         
163
164 //_____________________________________________________________________________
165 TGraph* AliDCSSensor::MakeGraph(Int_t nPoints, Bool_t debug) const
166 {
167   //
168   // Make graph from start time to end time of DCS values 
169   //
170
171  
172
173   UInt_t stepTime = (fEndTime-fStartTime)/nPoints;
174   
175   if (debug==kTRUE) {
176      printf ("Start time %d, End time %d, step time %d\n",
177      fStartTime,fEndTime,stepTime);
178      TTimeStamp t((time_t)fStartTime,0); t.Print();
179      TTimeStamp t2((time_t)fEndTime,0); t2.Print();
180   }     
181   
182   if ( !fFit ) return 0;
183
184   Double_t *x = new Double_t[nPoints+1];
185   Double_t *y = new Double_t[nPoints+1];
186   for (Int_t ip=0; ip<nPoints; ip++) {
187     x[ip] = (time_t)(fStartTime+ip*stepTime);
188     y[ip] = fFit->Eval(ip*stepTime/kSecInHour);
189     if (debug==kTRUE) {
190      TTimeStamp t3((time_t)x[ip],0); 
191      printf ("x=%f, y=%f  ",x[ip],y[ip]);
192      t3.Print();
193     }
194   }
195   
196   TGraph *graph = new TGraph(nPoints,x,y);
197   delete [] x;
198   delete [] y;
199   
200   graph->GetXaxis()->SetTimeDisplay(1);
201   graph->GetXaxis()->SetLabelOffset(0.02);
202   graph->GetXaxis()->SetTimeFormat("#splitline{%d/%m}{%H:%M}");
203
204   return graph;
205 }
206
207 //_____________________________________________________________________________
208
209 TClonesArray * AliDCSSensor::ReadTree(TTree* tree) {
210   //
211   // read values from ascii file
212   //
213
214   Int_t nentries = tree->GetEntries();
215
216   char stringId[100];
217   Int_t num=0;
218   Int_t idDCS=0;
219   Double_t x=0;
220   Double_t y=0;
221   Double_t z=0;
222
223   tree->SetBranchAddress("StringID",&stringId);
224   tree->SetBranchAddress("IdDCS",&idDCS);
225   tree->SetBranchAddress("Num",&num);
226   tree->SetBranchAddress("X",&x);
227   tree->SetBranchAddress("Y",&y);
228   tree->SetBranchAddress("Z",&z);
229
230   // firstSensor = (Int_t)tree->GetMinimum("ECha");
231   // lastSensor = (Int_t)tree->GetMaximum("ECha");
232
233   TClonesArray * array = new TClonesArray("AliDCSSensor",nentries);
234    printf ("nentries = %d\n",nentries);
235
236   for (Int_t isensor=0; isensor<nentries; isensor++){
237     AliDCSSensor * sens = new ((*array)[isensor])AliDCSSensor;
238     tree->GetEntry(isensor);
239     sens->SetId(isensor);
240     sens->SetIdDCS(idDCS);
241     sens->SetStringID(TString(stringId));
242     sens->SetX(x);
243     sens->SetY(y);
244     sens->SetZ(z);
245
246   }
247   return array;
248 }
249