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 TPC temperature sensors (including pointers to graphs/fits//
20 // Authors: Marian Ivanov, Haavard Helstrup and Martin Siska //
22 ////////////////////////////////////////////////////////////////////////////////
25 #include "AliDCSSensor.h"
26 ClassImp(AliDCSSensor)
28 const Double_t kSecInHour = 3600.; // seconds in one hour
32 AliDCSSensor::AliDCSSensor():
45 // Standard constructor
49 AliDCSSensor::AliDCSSensor(const AliDCSSensor& source) :
52 fIdDCS(source.fIdDCS),
53 fStringID(source.fStringID),
54 fStartTime(source.fStartTime),
55 fEndTime(source.fEndTime),
56 fGraph(source.fGraph),
66 AliDCSSensor& AliDCSSensor::operator=(const AliDCSSensor& source){
68 // assignment operator
70 if (&source == this) return *this;
71 new (this) AliDCSSensor(source);
76 //_____________________________________________________________________________
77 Double_t AliDCSSensor::GetValue(UInt_t timeSec)
80 // Get temperature value for actual sensor
81 // timeSec given as offset from start-of-run measured in seconds
84 return Eval(TTimeStamp((time_t)(fStartTime+timeSec),0),inside);
86 //_____________________________________________________________________________
87 Double_t AliDCSSensor::GetValue(TTimeStamp time)
89 // Get temperature value for actual sensor
90 // time given as absolute TTimeStamp
93 return Eval(time, inside);
96 //_____________________________________________________________________________
98 Double_t AliDCSSensor::Eval(const TTimeStamp& time, Bool_t inside) const
101 // Return temperature at given time
102 // If time < start of map return value at start of map, inside = false
103 // If time > end of map return value at end of map, inside = false
105 UInt_t timeSec = time.GetSec();
106 UInt_t diff = timeSec-fStartTime;
109 if ( timeSec < fStartTime ) {
113 if ( timeSec > fEndTime ) {
115 diff = fEndTime-fStartTime;
118 Double_t timeHour = diff/kSecInHour;
120 return fFit->Eval(timeHour);
123 return EvalGraph(timeHour);
129 //_____________________________________________________________________________
130 Double_t AliDCSSensor::EvalGraph(const Double_t& timeHour) const
133 // Extract last value in graph observed before time given by timeHour
136 // return -99 if point specified is before beginning of graph
137 Double_t x=0; Double_t y=0;
138 fGraph->GetPoint(0,x,y);
139 if ( timeHour < x ) return -99;
141 // return previous point when first time > timeHour is observed
143 Int_t npoints = fGraph->GetN();
144 for (Int_t i=1; i<npoints; i++) {
145 fGraph->GetPoint(i,x,y);
146 if ( timeHour < x ) {
147 fGraph->GetPoint(i-1,x,y);
152 // return last point if all times are < timeHour
157 //_____________________________________________________________________________
158 TGraph* AliDCSSensor::MakeGraph(Int_t nPoints) const
161 // Make graph from start time to end time of DCS values
164 UInt_t stepTime = (fEndTime-fStartTime)/nPoints;
166 if ( !fFit ) return 0;
168 Double_t *x = new Double_t[nPoints+1];
169 Double_t *y = new Double_t[nPoints+1];
170 for (Int_t ip=0; ip<nPoints; ip++) {
171 x[ip] = fStartTime+ip*stepTime;
172 y[ip] = fFit->Eval(ip*stepTime/kSecInHour);
175 TGraph *graph = new TGraph(nPoints,x,y);
179 graph->GetXaxis()->SetTimeDisplay(1);
180 graph->GetXaxis()->SetLabelOffset(0.02);
181 graph->GetXaxis()->SetTimeFormat("#splitline{%d/%m}{%H:%M}");
186 //_____________________________________________________________________________
188 TClonesArray * AliDCSSensor::ReadTree(TTree* tree) {
190 // read values from ascii file
193 Int_t nentries = tree->GetEntries();
202 tree->SetBranchAddress("StringID",&stringId);
203 tree->SetBranchAddress("IdDCS",&idDCS);
204 tree->SetBranchAddress("Num",&num);
205 tree->SetBranchAddress("X",&x);
206 tree->SetBranchAddress("Y",&y);
207 tree->SetBranchAddress("Z",&z);
209 // firstSensor = (Int_t)tree->GetMinimum("ECha");
210 // lastSensor = (Int_t)tree->GetMaximum("ECha");
212 TClonesArray * array = new TClonesArray("AliDCSSensor",nentries);
213 printf ("nentries = %d\n",nentries);
215 for (Int_t isensor=0; isensor<nentries; isensor++){
216 AliDCSSensor * sens = new ((*array)[isensor])AliDCSSensor;
217 tree->GetEntry(isensor);
218 sens->SetId(isensor);
219 sens->SetIdDCS(idDCS);
220 sens->SetStringID(TString(stringId));