1 /**************************************************************************
2 * Copyright(c) 2006-07, 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 **************************************************************************/
17 ////////////////////////////////////////////////////////////////////////////////
19 // Class describing time dependent values read from DCS sensors //
20 // (including pointers to graphs/fits) //
21 // Authors: Marian Ivanov, Haavard Helstrup and Martin Siska //
23 ////////////////////////////////////////////////////////////////////////////////
26 #include "AliDCSSensor.h"
29 ClassImp(AliDCSSensor)
31 const Double_t kSecInHour = 3600.; // seconds in one hour
35 AliDCSSensor::AliDCSSensor():
48 // Standard constructor
52 AliDCSSensor::AliDCSSensor(const AliDCSSensor& source) :
55 fIdDCS(source.fIdDCS),
56 fStringID(source.fStringID),
57 fStartTime(source.fStartTime),
58 fEndTime(source.fEndTime),
68 if (source.fGraph) fGraph = (TGraph*)source.fGraph->Clone();
69 if (source.fFit) fFit = (AliSplineFit*)source.fFit->Clone();
72 AliDCSSensor& AliDCSSensor::operator=(const AliDCSSensor& source){
74 // assignment operator
76 if (&source == this) return *this;
77 new (this) AliDCSSensor(source);
83 void AliDCSSensor::Print(const Option_t* option) const{
87 TString opt = option; opt.ToLower();
88 printf("%s:%s\n",GetTitle(), GetName());
89 printf("%s\n",fStringID.Data());
93 void AliDCSSensor::Draw(Option_t* option) {
95 // draw function - to viusalize sensor
96 // Unfortuantelly - it make a memory leak as function Draw does not return the object pointer
98 TCanvas * canvas = new TCanvas((fStringID+option).Data(), (fStringID+option).Data());
100 // transform points to time in s
101 Int_t npoints = fGraph->GetN();
102 for (Int_t i=0; i<npoints; i++){
103 fGraph->GetX()[i]=fGraph->GetX()[i]*3600+fStartTime;
109 TGraph * graph = MakeGraph(100); // memory leak - we can not modify the content - const method
110 graph->Draw(option); //
116 //_____________________________________________________________________________
117 Double_t AliDCSSensor::GetValue(UInt_t timeSec)
120 // Get DCS value for actual sensor
121 // timeSec given as offset from start-of-map measured in seconds
122 // *NOTE* In the current TPC setup, start-of-map is defined as the
123 // first measured point for each sensor. This will be different
124 // for each sensor in the array. If you want to get a value at the
125 // same absolute time, use AliDCSSensor::GetValue(TTimeStamp time)
126 // or AliDCSSensorArray::GetValue (UInt_t timeSec, Int_t sensor)
127 // which measure offsets with respect to the (global) start-of-run
130 return Eval(TTimeStamp((time_t)(fStartTime+timeSec),0),inside);
132 //_____________________________________________________________________________
133 Double_t AliDCSSensor::GetValue(TTimeStamp time)
135 // Get DCS value for actual sensor
136 // time given as absolute TTimeStamp
139 return Eval(time, inside);
142 //_____________________________________________________________________________
144 Double_t AliDCSSensor::Eval(const TTimeStamp& time, Bool_t& inside) const
147 // Return DCS value at given time
148 // The value is calculated from the AliSplineFit, if a fit is not available
149 // the most recent reading from the Graph of DCS points is returned (if
150 // the graph is present)
151 // If time < start of map return value at start of map, inside = false
152 // If time > end of map return value at end of map, inside = false
154 UInt_t timeSec = time.GetSec();
155 UInt_t diff = timeSec-fStartTime;
158 if ( timeSec < fStartTime ) {
162 if ( timeSec > fEndTime ) {
164 diff = fEndTime-fStartTime;
167 Double_t timeHour = diff/kSecInHour;
169 return fFit->Eval(timeHour);
172 return EvalGraph(timeHour);
178 //_____________________________________________________________________________
180 Double_t AliDCSSensor::EvalGraph(const TTimeStamp& time, Bool_t& inside) const
183 // Return DCS value from graph of DCS points (i.e return last reading before
184 // the time specified by TTimeStamp
185 // If time < start of map return value at start of map, inside = false
186 // If time > end of map return value at end of map, inside = false
188 UInt_t timeSec = time.GetSec();
189 UInt_t diff = timeSec-fStartTime;
192 if ( timeSec < fStartTime ) {
196 if ( timeSec > fEndTime ) {
198 diff = fEndTime-fStartTime;
201 Double_t timeHour = diff/kSecInHour;
203 return EvalGraph(timeHour);
208 //_____________________________________________________________________________
209 Double_t AliDCSSensor::EvalGraph(const Double_t& timeHour) const
212 // Extract last value in graph observed before time given by timeHour
215 // return -99 if point specified is before beginning of graph
216 Double_t x=0; Double_t y=0;
217 fGraph->GetPoint(0,x,y);
218 if ( timeHour < x ) return -99;
220 // return previous point when first time > timeHour is observed
222 Int_t npoints = fGraph->GetN();
223 for (Int_t i=1; i<npoints; i++) {
224 fGraph->GetPoint(i,x,y);
225 if ( timeHour < x ) {
226 fGraph->GetPoint(i-1,x,y);
231 // return last point if all times are < timeHour
236 //_____________________________________________________________________________
237 TGraph* AliDCSSensor::MakeGraph(Int_t nPoints, Bool_t debug) const
240 // Make graph from start time to end time of DCS values
245 UInt_t stepTime = (fEndTime-fStartTime)/nPoints;
248 printf ("Start time %d, End time %d, step time %d\n",
249 fStartTime,fEndTime,stepTime);
250 TTimeStamp t((time_t)fStartTime,0); t.Print();
251 TTimeStamp t2((time_t)fEndTime,0); t2.Print();
254 if ( !fFit ) return 0;
256 Double_t *x = new Double_t[nPoints+1];
257 Double_t *y = new Double_t[nPoints+1];
258 for (Int_t ip=0; ip<nPoints; ip++) {
259 x[ip] = (time_t)(fStartTime+ip*stepTime);
260 y[ip] = fFit->Eval(ip*stepTime/kSecInHour);
262 TTimeStamp t3((time_t)x[ip],0);
263 printf ("x=%f, y=%f ",x[ip],y[ip]);
268 TGraph *graph = new TGraph(nPoints,x,y);
272 graph->GetXaxis()->SetTimeDisplay(1);
273 graph->GetXaxis()->SetLabelOffset(0.02);
274 graph->GetXaxis()->SetTimeFormat("#splitline{%d/%m}{%H:%M}");
279 //_____________________________________________________________________________
281 TClonesArray * AliDCSSensor::ReadTree(TTree* tree) {
283 // read values from ascii file
286 Int_t nentries = tree->GetEntries();
295 tree->SetBranchAddress("StringID",&stringId);
296 tree->SetBranchAddress("IdDCS",&idDCS);
297 tree->SetBranchAddress("Num",&num);
298 tree->SetBranchAddress("X",&x);
299 tree->SetBranchAddress("Y",&y);
300 tree->SetBranchAddress("Z",&z);
302 // firstSensor = (Int_t)tree->GetMinimum("ECha");
303 // lastSensor = (Int_t)tree->GetMaximum("ECha");
305 TClonesArray * array = new TClonesArray("AliDCSSensor",nentries);
306 printf ("nentries = %d\n",nentries);
308 for (Int_t isensor=0; isensor<nentries; isensor++){
309 AliDCSSensor * sens = new ((*array)[isensor])AliDCSSensor;
310 tree->GetEntry(isensor);
311 sens->SetId(isensor);
312 sens->SetIdDCS(idDCS);
313 sens->SetStringID(TString(stringId));