]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliDCSSensorArray.cxx
AOD includes added.
[u/mrichter/AliRoot.git] / STEER / AliDCSSensorArray.cxx
CommitLineData
7264822f 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
17///////////////////////////////////////////////////////////////////////////////
18// //
19// Calibration class for DCS sensors //
20// Authors: Marian Ivanov and Haavard Helstrup //
21// //
22///////////////////////////////////////////////////////////////////////////////
23
24#include "AliDCSSensorArray.h"
25
26ClassImp(AliDCSSensorArray)
27
8cb8848e 28const Double_t kSecInHour = 3600.; // seconds in one hour
7264822f 29
30//_____________________________________________________________________________
7c76a767 31AliDCSSensorArray::AliDCSSensorArray():TNamed(),
e5250086 32 fMinGraph(10),
33 fMinPoints(10),
34 fIter(10),
35 fMaxDelta(0.0),
36 fFitReq(2),
37 fValCut(9999999),
38 fDiffCut(9999999),
7c76a767 39 fStartTime (2000,1,1,0,0,0),
40 fEndTime (2000,1,1,0,0,0),
41 fSensors(0)
7264822f 42{
43 //
44 // AliDCSSensorArray default constructor
45 //
7264822f 46
47}
48//_____________________________________________________________________________
7c76a767 49AliDCSSensorArray::AliDCSSensorArray(Int_t prevRun, const char* dbEntry) :
50 TNamed(),
e5250086 51 fMinGraph(10),
52 fMinPoints(10),
53 fIter(10),
54 fMaxDelta(0.0),
55 fFitReq(2),
56 fValCut(9999999),
57 fDiffCut(9999999),
7c76a767 58 fStartTime (2000,1,1,0,0,0),
59 fEndTime (2000,1,1,0,0,0),
60 fSensors(0)
7264822f 61{
62 //
63 // Read positions etc. from data base entry for previous run
64 // Delete all fits and graphs
65 //
66 AliDCSSensorArray *temp=0;
67 AliCDBEntry* entry =
68 AliCDBManager::Instance()->Get(dbEntry,prevRun);
69 if (entry){
70 entry->SetOwner(kTRUE);
71 temp = (AliDCSSensorArray*)entry->GetObject();
72 }
73
74 TGraph *gr;
75 AliSplineFit* fit;
76
77// Delete previous values
78
79 Int_t nsensors = temp->fSensors->GetEntries();
80 for ( Int_t isensor=0; isensor<nsensors; isensor++) {
81 AliDCSSensor *entry = (AliDCSSensor*)temp->fSensors->At(isensor);
82 gr = entry->GetGraph();
83 if ( gr != 0 ) {
84 delete gr;
85 gr = 0;
86 }
87 fit = entry->GetFit();
88 if ( fit != 0 ) {
89 delete fit;
90 fit = 0;
91 }
92 }
93
94 new (this) AliDCSSensorArray(*temp);
95 delete temp;
96}
97
98
99
100//_____________________________________________________________________________
7c76a767 101AliDCSSensorArray::AliDCSSensorArray(const AliDCSSensorArray &c):TNamed(c),
e5250086 102 fMinGraph(c.fMinGraph),
103 fMinPoints(c.fMinPoints),
104 fIter(c.fIter),
105 fMaxDelta(c.fMaxDelta),
106 fFitReq(c.fFitReq),
107 fValCut(c.fValCut),
108 fDiffCut(c.fDiffCut),
7c76a767 109 fStartTime (c.fStartTime),
110 fEndTime (c.fEndTime),
111 fSensors(0)
112
7264822f 113{
114 //
115 // AliDCSSensorArray copy constructor
116 //
117
118 ((AliDCSSensorArray &) c).Copy(*this);
119
120}
121
122///_____________________________________________________________________________
123AliDCSSensorArray::~AliDCSSensorArray()
124{
125 //
126 // AliDCSSensorArray destructor
127 //
128 fSensors->Delete();
129 delete fSensors;
130
131}
132
133//_____________________________________________________________________________
134AliDCSSensorArray &AliDCSSensorArray::operator=(const AliDCSSensorArray &c)
135{
136 //
137 // Assignment operator
138 //
139
140 if (this != &c) ((AliDCSSensorArray &) c).Copy(*this);
141 return *this;
142
143}
144
145//_____________________________________________________________________________
146void AliDCSSensorArray::Copy(TObject &c) const
147{
148 //
149 // Copy function
150 //
151
152 TObject::Copy(c);
153}
154//_____________________________________________________________________________
155void AliDCSSensorArray::SetGraph(TMap *map, const char *amandaString)
156{
157 //
158 // Read graphs from DCS maps
159 //
160 char dname[100];
161 Int_t nsensors = fSensors->GetEntries();
162 for ( Int_t isensor=0; isensor<nsensors; isensor++) {
163 AliDCSSensor *entry = (AliDCSSensor*)fSensors->At(isensor);
164 Int_t dcsSensor=entry->GetIdDCS();
165 sprintf(dname,amandaString,dcsSensor);
166 TGraph *gr = (TGraph*)map->GetValue(dname);
167 entry->SetGraph(gr);
168 }
169}
170//_____________________________________________________________________________
8cb8848e 171void AliDCSSensorArray::MakeSplineFit(TMap *map, const char *amandaString,
172 Bool_t keepMap)
7264822f 173{
174 //
175 // Make spline fits from DCS maps
176 //
177 char dname[100];
178 Int_t nsensors = fSensors->GetEntries();
179 for ( Int_t isensor=0; isensor<nsensors; isensor++) {
180 AliDCSSensor *entry = (AliDCSSensor*)fSensors->At(isensor);
181 Int_t dcsSensor=entry->GetIdDCS();
182 sprintf(dname,amandaString,dcsSensor);
183 TGraph *gr = (TGraph*)map->GetValue(dname);
e5250086 184 if (gr->GetN() < fMinGraph ) continue;
7264822f 185 AliSplineFit *fit = new AliSplineFit();
e5250086 186 fit->InitKnots(gr,fMinPoints,fIter,fMaxDelta);
187 fit->SplineFit(fFitReq);
7264822f 188 entry->SetStartTime(fStartTime);
8cb8848e 189 entry->SetEndTime(fEndTime);
7264822f 190 fit->Cleanup();
191 entry->SetFit(fit);
8cb8848e 192 if (keepMap) entry->SetGraph(gr);
7264822f 193 }
194}
195
196//_____________________________________________________________________________
197Double_t AliDCSSensorArray::GetValue(UInt_t timeSec, Int_t sensor)
198{
199 //
200 // Return sensor value at time timeSec (obtained from fitted function)
201 // timeSec = time in seconds from start of run
202 //
203 AliDCSSensor *entry = (AliDCSSensor*)fSensors->At(sensor);
204 return entry->GetValue(timeSec);
205}
206
207
208//_____________________________________________________________________________
209TMap* AliDCSSensorArray::ExtractDCS(TMap *dcsMap, const char *amandaString)
210{
211 //
212 // Extract temperature graphs from DCS maps
213 //
214 TMap *values = new TMap;
215 TObjArray * valueSet;
7c76a767 216 Int_t nsensors = fSensors->GetEntries();
217 for ( Int_t isensor=0; isensor<nsensors; isensor++) {
218 AliDCSSensor *entry = (AliDCSSensor*)fSensors->At(isensor);
219 Int_t dcsSensor=entry->GetIdDCS();
7264822f 220 TString DPname = Form (amandaString,dcsSensor);
7c76a767 221 TPair *pair = (TPair*)dcsMap->FindObject(DPname.Data());
222 valueSet = (TObjArray*)pair->Value();
7264822f 223 TGraph *graph = MakeGraph(valueSet);
224 values->Add(new TObjString(DPname.Data()),graph);
225 }
226 return values;
227}
228
229//_____________________________________________________________________________
230TGraph* AliDCSSensorArray::MakeGraph(TObjArray* valueSet){
231 //
232 // Make graph of temperature values read from DCS map
233 // (spline fit parameters will subsequently be obtained from this graph)
234 //
235 Int_t nentries = valueSet->GetEntriesFast();
236 Float_t *x = new Float_t[nentries];
237 Float_t *y = new Float_t[nentries];
238 Int_t time0=0;
239 Int_t out=0;
240 Int_t skipped=0;
e5250086 241 AliDCSValue *val = (AliDCSValue *)valueSet->At(0);
242 AliDCSValue::Type type = val->GetType();
243 if ( type == AliDCSValue::kInvalid || type == AliDCSValue::kBool ) return 0;
244 Float_t value;
7264822f 245 for (Int_t i=0; i<nentries; i++){
e5250086 246 val = (AliDCSValue *)valueSet->At(i);
7264822f 247 if (!val) continue;
248 if (time0==0){
249 time0=val->GetTimeStamp();
250 }
e5250086 251 switch ( type )
252 {
253 case AliDCSValue::kFloat:
254 value = val->GetFloat();
255 break;
256 case AliDCSValue::kChar:
257 value = val->GetChar();
258 break;
259 case AliDCSValue::kInt:
260 value = val->GetInt();
261 break;
262 case AliDCSValue::kUInt:
263 value = val->GetUInt();
264 break;
265 default:
266 continue;
267 }
268 if (TMath::Abs(value)>fValCut) continue; // refuse values greater than cut
269 if ( out>0 && skipped<10 && TMath::Abs(value-y[out-1])>fDiffCut) {
270 skipped++; // refuse values changing
271 continue; // by > cut in one time step
7264822f 272 }
273 skipped=0;
274 if (val->GetTimeStamp()-time0>1000000) continue;
8cb8848e 275 x[out] = (val->GetTimeStamp()-time0)/kSecInHour; // give times in fractions of hours
7264822f 276 y[out] = val->GetFloat();
277 out++;
278
279 }
280 TGraph * graph = new TGraph(out,x,y);
281 delete [] x;
282 delete [] y;
283 return graph;
284}
285
286//_____________________________________________________________________________
287AliDCSSensor* AliDCSSensorArray::GetSensor(Int_t IdDCS)
288{
289 //
290 // Return sensor information for sensor specified by IdDCS
291 //
292 Int_t nsensors = fSensors->GetEntries();
293 for (Int_t isensor=0; isensor<nsensors; isensor++) {
294 AliDCSSensor *entry = (AliDCSSensor*)fSensors->At(isensor);
295 if (entry->GetIdDCS() == IdDCS) return entry;
296 }
297 return 0;
298}
299//_____________________________________________________________________________
300AliDCSSensor* AliDCSSensorArray::GetSensor(Double_t x, Double_t y, Double_t z)
301{
302 //
303 // Return sensor closest to given position
304 //
305 Int_t nsensors = fSensors->GetEntries();
306 Double_t dist2min=1e99;
307 Double_t xs,ys,zs,dist2;
308 Int_t ind=-1;
309 for (Int_t isensor=0; isensor<nsensors; isensor++) {
310 AliDCSSensor *entry = (AliDCSSensor*)fSensors->At(isensor);
311 xs = entry->GetX();
312 ys = entry->GetY();
313 zs = entry->GetZ();
314 dist2 = (x-xs)*(x-xs) + (y-ys)*(y-ys) + (z-zs)*(z-zs);
315 if (dist2 < dist2min) {
316 ind=isensor;
317 dist2min = dist2;
318 }
319 }
320 if ( ind >= 0 ) {
321 return (AliDCSSensor*)fSensors->At(ind);
322 } else {
323 return 0;
324 }
325}
8cb8848e 326
327AliDCSSensor* AliDCSSensorArray::GetSensorNum(Int_t ind)
328{
329 //
330 // Return sensor given by array index
331 //
332 return (AliDCSSensor*)fSensors->At(ind);
333}
334
335Int_t AliDCSSensorArray::GetFirstIdDCS() const
336{
337 //
338 // Return DCS Id of first sensor
339 //
340 if ( fSensors != 0 ) {
341 return ((AliDCSSensor*)fSensors->At(0))->GetIdDCS();
342 } else {
343 return 0;
344 }
345}
346
347Int_t AliDCSSensorArray::GetLastIdDCS() const
348{
349 //
350 // Return DCS Id of last sensor
351 //
352 if ( fSensors != 0 ) {
353 Int_t last = fSensors->GetEntries();
354 return ((AliDCSSensor*)fSensors->At(last-1))->GetIdDCS();
355 } else {
356 return 0;
357 }
358}