Correct formula for phi, in case of current local X <0, in GetLocalXat and GetPhiZat
[u/mrichter/AliRoot.git] / ITS / AliITSDCSDataSDD.cxx
CommitLineData
cfaccd71 1/**************************************************************************
2 * Copyright(c) 2007-2009, 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/* $Id$ */
17
18///////////////////////////////////////////////////////////////////
cfaccd71 19// Implementation of the class containing SDD DCS data //
20// Origin: F.Prino, Torino, prino@to.infn.it //
e22bf775 21// V. Pospisil, CTU Praguem gdermog@seznam.cz //
cfaccd71 22///////////////////////////////////////////////////////////////////
23
24#include "AliITSDCSDataSDD.h"
25#include "AliLog.h"
26
e22bf775 27#define AUTORESIZE 50
28
cfaccd71 29ClassImp(AliITSDCSDataSDD)
30
dc5eacf8 31const Float_t AliITSDCSDataSDD::fgkTPrec = 100.0;
32const Float_t AliITSDCSDataSDD::fgkMVPrec = 1000.0;
33
e22bf775 34//---------------------------------------------------------------------------
35AliITSDCSDataSDD::AliITSDCSDataSDD(): TObject(),
36fTempLeft(0),
37fTempLeftTimeStamp(0),
38fTempLeftMaxPoints(0),
39fTempLeftSetPoints(0),
40fTempRight(0),
41fTempRightTimeStamp(0),
42fTempRightMaxPoints(0),
43fTempRightSetPoints(0),
44fHV(0),
45fHVTimeStamp(0),
46fHVMaxPoints(0),
47fHVSetPoints(0),
48fMV(0),
49fMVTimeStamp(0),
50fMVMaxPoints(0),
51fMVSetPoints(0),
52fStatus(0),
53fStatusTimeStamp(0),
54fStatusMaxPoints(0),
55fStatusSetPoints(0)
cfaccd71 56{
e22bf775 57// default constructor
58} /*AliITSDCSDataSDD::AliITSDCSDataSDD*/
59
60//---------------------------------------------------------------------------
61
62void AliITSDCSDataSDD::SetNPointsTempLeft( Int_t npts )
cfaccd71 63{
e22bf775 64 //
65 if( npts < fTempLeftSetPoints)
66 { // Cannot resize arrays - some elements would be lost
67 AliWarning("Attemp to reduce size of full array (SDD DCS _TEMP_L)");
cfaccd71 68 return;
e22bf775 69 } /*if*/
70
71 fTempLeft.Set( npts );
72 fTempLeftTimeStamp.Set( npts );
73 // Both temperature and tme stamp arrays are resized
74
75 fTempLeftMaxPoints = npts;
76 // New size is stored
77} /*AliITSDCSDataSDD::SetNPointsTempLeft*/
78
79//---------------------------------------------------------------------------
80
81void AliITSDCSDataSDD::SetNPointsTempRight( Int_t npts )
82{
83 //
84 if( npts < fTempRightSetPoints)
85 { // Cannot resize arrays - some elements would be lost
86 AliWarning("Attemp to reduce size of full array (SDD DCS _TEMP_R)");
87 return;
88 } /*if*/
89
90 fTempRight.Set( npts );
91 fTempRightTimeStamp.Set( npts );
92 // Both temperature and tme stamp arrays are resized
93
94 fTempRightMaxPoints = npts;
95 // New size is stored
96} /*AliITSDCSDataSDD::SetNPointsTempRight*/
97
98//---------------------------------------------------------------------------
99
100void AliITSDCSDataSDD::SetNPointsHV( Int_t npts )
101{
102 //
103 if( npts < fHVSetPoints)
104 { // Cannot resize arrays - some elements would be lost
105 AliWarning("Attemp to reduce size of full array (SDD DCS _HV)");
106 return;
107 } /*if*/
108
109 fHV.Set( npts );
110 fHVTimeStamp.Set( npts );
111 // Both temperature and tme stamp arrays are resized
112
113 fHVMaxPoints = npts; // New size is stored
114
115}/*AliITSDCSDataSDD::SetNPointsHV*/
116
117//---------------------------------------------------------------------------
118
119void AliITSDCSDataSDD::SetNPointsMV( Int_t npts )
120{
121 //
122 if( npts < fMVSetPoints)
123 { // Cannot resize arrays - some elements would be lost
124 AliWarning("Attemp to reduce size of full array (SDD DCS _MV)");
125 return;
126 } /*if*/
127
128 fMV.Set( npts );
129 fMVTimeStamp.Set( npts );
130 // Both temperature and tme stamp arrays are resized
131
132 fMVMaxPoints = npts; // New size is stored
133
134} /*AliITSDCSDataSDD::SetNPointsMV*/
135
136//---------------------------------------------------------------------------
137
138void AliITSDCSDataSDD::SetNPointsStatus( Int_t npts )
139{
140 //
141 if( npts < fStatusSetPoints)
142 { // Cannot resize arrays - some elements would be lost
143 AliWarning("Attemp to reduce size of full array (SDD DCS Status)");
144 return;
145 } /*if*/
146
147 fStatus.Set( npts );
148 fStatusTimeStamp.Set( npts );
149 // Both temperature and tme stamp arrays are resized
150
151 fStatusMaxPoints = npts;
152 // New size is stored
153
154} /*AliITSDCSDataSDD::SetNPointsMV*/
155
156//---------------------------------------------------------------------------
157void AliITSDCSDataSDD::SetValueTempLeft(Int_t time, Float_t temperature )
158{
159 //
160 if( fTempLeftMaxPoints == fTempLeftSetPoints )
161 SetNPointsTempLeft( fTempLeftMaxPoints + AUTORESIZE );
162 // Enlarges arrays if necessary
163
164 Int_t i = FindIndex( time, fTempLeftTimeStamp, fTempLeftSetPoints );
165 // Finds place where the new value have to be inserted
166
167 if( i < 0 )
168 i = 0; // New value have to be inserted before the first one in the array
169 else
170 i++; // New value will be put somewhere in the middle of the array
171 // or at the end
172
173 if( i < fTempLeftSetPoints )
174 {
dc5eacf8 175 Short_t *fromPtrF = fTempLeft.GetArray() + i;
e22bf775 176 // Sets pointer to cell which have to be filled by new value
dc5eacf8 177 Short_t *toPtrF = fromPtrF + 1;
e22bf775 178 // Sets pointer to cell where the array content have to be shifted
179
dc5eacf8 180 memmove( toPtrF, fromPtrF, (fTempLeftSetPoints - i)*sizeof(Short_t) );
e22bf775 181 // Shifts array content. Now there is vacant place for new value to be inserted
182
183 Int_t *fromPtrI = fTempLeftTimeStamp.GetArray() + i;
184 Int_t *toPtrI = fromPtrI + 1;
185 memmove( toPtrI, fromPtrI, (fTempLeftSetPoints - i)*sizeof(Int_t) );
186 // Do the same for time stamp array
187 } /*if*/
188
dc5eacf8 189 UShort_t val = (UShort_t)( temperature * fgkTPrec );
190 // Float value of temperature is stored as UShort_t with given precision
191
192 fTempLeft.AddAt( (Short_t)val, i );
e22bf775 193 fTempLeftTimeStamp.AddAt( time, i );
194 fTempLeftSetPoints++;
195 // New values are inserted
196} /*AliITSDCSDataSDD::SetValueTempLeft*/
197
198//---------------------------------------------------------------------------
199
200void AliITSDCSDataSDD::SetValueTempRight(Int_t time, Float_t temperature )
201{
202 //
203 if( fTempRightMaxPoints == fTempRightSetPoints )
204 SetNPointsTempRight( fTempRightMaxPoints + AUTORESIZE );
205 // Enlarges arrays if necessary
206
207 Int_t i = FindIndex( time, fTempRightTimeStamp, fTempRightSetPoints );
208 // Finds place where the new value have to be inserted
209
210 if( i < 0 )
211 i = 0; // New value have to be inserted before the first one in the array
212 else
213 i++; // New value will be put somewhere in the middle of the array
214 // or at the end
215
216 if( i < fTempRightSetPoints )
217 { // Some values have to be moved
dc5eacf8 218 Short_t *fromPtrF = fTempRight.GetArray() + i;
e22bf775 219 // Sets pointer to cell which have to be filled by new value
dc5eacf8 220 Short_t *toPtrF = fromPtrF + 1;
e22bf775 221 // Sets pointer to cell where the array content have to be shifted
222
dc5eacf8 223 memmove( toPtrF, fromPtrF, (fTempRightSetPoints - i)*sizeof(Short_t) );
e22bf775 224 // Shifts array content. Now there is vacant place for new value to be inserted
225
226 Int_t *fromPtrI = fTempRightTimeStamp.GetArray() + i;
227 Int_t *toPtrI = fromPtrI + 1;
228 memmove( toPtrI, fromPtrI, (fTempRightSetPoints - i)*sizeof(Int_t) );
229 // Do the same for time stamp array
230 } /*if*/
231
dc5eacf8 232 UShort_t val = (UShort_t)( temperature * fgkTPrec );
233 // Float value of temperature is stored as UShort_t with given precision
234
235 fTempRight.AddAt( (Short_t)val, i );
e22bf775 236 fTempRightTimeStamp.AddAt( time, i );
237 fTempRightSetPoints++;
238 // New values are inserted
239} /*AliITSDCSDataSDD::SetValueTempRight*/
240
241//---------------------------------------------------------------------------
242
243void AliITSDCSDataSDD::SetValueHV(Int_t time, Float_t voltage )
244{
245 //
246 if( fHVMaxPoints == fHVSetPoints )
247 SetNPointsHV( fHVMaxPoints + AUTORESIZE );
248 // Enlarges arrays if necessary
249
250 Int_t i = FindIndex( time, fHVTimeStamp, fHVSetPoints );
251 // Finds place where the new value have to be inserted
252
253 if( i < 0 )
254 i = 0; // New value have to be inserted before the first one in the array
255 else
256 i++; // New value will be put somewhere in the middle of the array
257 // or at the end
258
259 if( i < fHVSetPoints )
260 {
261 Float_t *fromPtrF = fHV.GetArray() + i;
262 // Sets pointer to cell which have to be filled by new value
263 Float_t *toPtrF = fromPtrF + 1;
264 // Sets pointer to cell where the array content have to be shifted
265
266 memmove( toPtrF, fromPtrF, (fHVSetPoints - i)*sizeof(Float_t) );
267 // Shifts array content. Now there is vacant place for new value to be inserted
268
269 Int_t *fromPtrI = fHVTimeStamp.GetArray() + i;
270 Int_t *toPtrI = fromPtrI + 1;
271 memmove( toPtrI, fromPtrI, (fHVSetPoints - i)*sizeof(Int_t) );
272 // Do the same for time stamp array
273 } /*if*/
274
275 fHV.AddAt( voltage, i );
276 fHVTimeStamp.AddAt( time, i );
277 fHVSetPoints++;
278 // New values are inserted
279} /*AliITSDCSDataSDD::SetValueHV*/
280
281//---------------------------------------------------------------------------
282
283void AliITSDCSDataSDD::SetValueMV(Int_t time, Float_t voltage )
284{
285 //
286 if( fMVMaxPoints == fMVSetPoints )
287 SetNPointsMV( fMVMaxPoints + AUTORESIZE );
288 // Enlarges arrays if necessary
289
290 Int_t i = FindIndex( time, fMVTimeStamp, fMVSetPoints );
291 // Finds place where the new value have to be inserted
292
293 if( i < 0 )
294 i = 0; // New value have to be inserted before the first one in the array
295 else
296 i++; // New value will be put somewhere in the middle of the array
297 // or at the end
298
299 if( i < fMVSetPoints )
300 {
dc5eacf8 301 Short_t *fromPtrF = fMV.GetArray() + i;
e22bf775 302 // Sets pointer to cell which have to be filled by new value
dc5eacf8 303 Short_t *toPtrF = fromPtrF + 1;
e22bf775 304 // Sets pointer to cell where the array content have to be shifted
305
dc5eacf8 306 memmove( toPtrF, fromPtrF, (fMVSetPoints - i)*sizeof(Short_t) );
e22bf775 307 // Shifts array content. Now there is vacant place for new value to be inserted
308
309 Int_t *fromPtrI = fMVTimeStamp.GetArray() + i;
310 Int_t *toPtrI = fromPtrI + 1;
311 memmove( toPtrI, fromPtrI, (fMVSetPoints - i)*sizeof(Int_t) );
312 // Do the same for time stamp array
313 } /*if*/
314
dc5eacf8 315 UShort_t val = (UShort_t)( voltage * fgkMVPrec );
316 // Float value of temperature is stored as UShort_t with given precision
317
318 fMV.AddAt( (Short_t)val, i );
e22bf775 319 fMVTimeStamp.AddAt( time, i );
320 fMVSetPoints++;
321 // New values are inserted
322} /*AliITSDCSDataSDD::SetValueMV*/
323
324//---------------------------------------------------------------------------
325
326void AliITSDCSDataSDD::SetValueStatus(Int_t time, Char_t status )
327{
328 //
329 if( fStatusMaxPoints == fStatusSetPoints )
330 SetNPointsStatus( fStatusMaxPoints + AUTORESIZE );
331 // Enlarges arrays if necessary
332
333 Int_t i = FindIndex( time, fStatusTimeStamp, fStatusSetPoints );
334 // Finds place where the new value have to be inserted
335
336 if( i < 0 )
337 i = 0; // New value have to be inserted before the first one in the array
338 else
339 i++; // New value will be put somewhere in the middle of the array
340 // or at the end
341
342 if( i < fStatusSetPoints )
343 {
344 Char_t *fromPtrF = fStatus.GetArray() + i;
345 // Sets pointer to cell which have to be filled by new value
346 Char_t *toPtrF = fromPtrF + 1;
347 // Sets pointer to cell where the array content have to be shifted
348
349 memmove( toPtrF, fromPtrF, (fStatusSetPoints - i)*sizeof(Char_t) );
350 // Shifts array content. Now there is vacant place for new value to be inserted
351
352 Int_t *fromPtrI = fStatusTimeStamp.GetArray() + i;
353 Int_t *toPtrI = fromPtrI + 1;
354 memmove( toPtrI, fromPtrI, (fStatusSetPoints - i)*sizeof(Int_t) );
355 // Do the same for time stamp array
356 } /*if*/
357
358 fStatus.AddAt( status, i );
359 fStatusTimeStamp.AddAt( time, i );
360 fStatusSetPoints++;
361 // New values are inserted
362
363} /*AliITSDCSDataSDD::SetValueStatus*/
364
365
366//---------------------------------------------------------------------------
367
e22bf775 368void AliITSDCSDataSDD::Compress()
369{
dc5eacf8 370// Minimize array sizes
e22bf775 371
372 SetNPointsTempLeft( fTempLeftSetPoints );
373 SetNPointsTempRight( fTempRightSetPoints );
374 SetNPointsHV( fHVSetPoints );
375 SetNPointsMV( fMVSetPoints );
376 SetNPointsStatus( fStatusSetPoints );
377
378} /*AliITSDCSDataSDD::Compress*/
379
380//---------------------------------------------------------------------------
381
dc5eacf8 382Float_t AliITSDCSDataSDD::GetDriftField( Int_t timeStamp ) const
383{
e22bf775 384// Returns drift field counted for specific time
385
386 Int_t cathodesNumber = 291;
387 Float_t cathodesPitch = 0.0120;
388
389 Float_t hv = GetHV( timeStamp );
390 Float_t mv = GetMV( timeStamp );
391
392 if( hv < 0.0 || mv < 0.0 ) return -1.0;
393 // HV or MV is unknown at this time
394
395 return ( hv - mv ) / ( cathodesNumber * cathodesPitch );
396
397} /*AliITSDCSDataSDD::GetDriftField*/
398
399//---------------------------------------------------------------------------
400
401
402Float_t AliITSDCSDataSDD::GetDriftSpeed( Int_t /*timeStamp*/ ) const
dc5eacf8 403{
404// Returns drift speed counted for specific time. Calculation is based on temerature
405// taken from DCS. This metod is not dedicated for normal usage, it should be used
406// only in cases that the injectors for given module fails.
407//
408// Presently only a prototype, returns -1.0.
e22bf775 409
410 /* PROTOTYPE */
411
412 return -1.0;
413
414} /*AliITSDCSDataSDD::*/
415
416//---------------------------------------------------------------------------
417
418
419void AliITSDCSDataSDD:: PrintValues( FILE *output ) const
dc5eacf8 420{
e22bf775 421// Prints array contents
422
423 Int_t nTLEntries = GetTempLeftRecords();
424 Int_t nTREntries = GetTempRightRecords();
425 Int_t nHVEntries = GetHVRecords() ;
426 Int_t nMVEntries = GetMVRecords();
427 Int_t nStatEntries = GetStatusRecords();
428
dc5eacf8 429 fprintf( output, "+------------------------------------------------------------------------------------------------------------+\n");
430 fprintf( output, "| DCS content |\n" );
431 fprintf( output, "+----------------------+-----------------------+---------------------+---------------------+-----------------+\n");
432 fprintf( output, "| %05i records | %05i records | %05i records | %05i records | %05i records |\n",
e22bf775 433 nHVEntries, nMVEntries, nTLEntries, nTREntries, nStatEntries );
dc5eacf8 434 fprintf( output, "| time (s) HV | time (s) MV | time (s) TL | time (s) TR | time (s) Stat |\n" );
435 fprintf( output, "+----------------------+-----------------------+---------------------+---------------------+-----------------+\n");
e22bf775 436
437 Int_t a = (nHVEntries > nMVEntries ) ? nHVEntries : nMVEntries;
438 Int_t b = (nTLEntries > nTREntries ) ? nTLEntries : nTREntries;
439 if( a < b ) a = b;
440 Int_t loopMax = ( a > nStatEntries ) ? a : nStatEntries ;
441 // Finds maximal entry number
442
443 for( Int_t entryLoop = 0; entryLoop < loopMax; entryLoop++ )
444 {
445
446 if( entryLoop < nHVEntries )
447 fprintf( output, "| %12i %4.2f | ", GetHVTimeIdx(entryLoop), GetHVIdx(entryLoop) );
448 else
449 fprintf( output, "| | ");
450
451 if( entryLoop < nMVEntries )
dc5eacf8 452 fprintf( output, " %12i %2.3f | ", GetMVTimeIdx(entryLoop), GetMVIdx(entryLoop) );
e22bf775 453 else
dc5eacf8 454 fprintf( output, " | ");
e22bf775 455
456 if( entryLoop < nTLEntries )
457 fprintf( output, "%12i %2.2f | ", GetTempLeftTimeIdx(entryLoop), GetTempLeftIdx(entryLoop) );
458 else
459 fprintf( output, " | ");
460
461 if( entryLoop < nTREntries )
462 fprintf( output, "%12i %2.2f | ", GetTempRightTimeIdx(entryLoop), GetTempRightIdx(entryLoop) );
463 else
464 fprintf( output, " | ");
465
466 if( entryLoop < nStatEntries )
467 fprintf( output, "%12i %i |\n", GetStatusTimeIdx(entryLoop), GetStatusIdx(entryLoop) );
468 else
469 fprintf( output, " |\n");
470
471 } /*for( entryLoop )*/
472
473
474} /*AliITSDCSDataSDD::PrintValues()*/
475
476//---------------------------------------------------------------------------
477
dc5eacf8 478Int_t AliITSDCSDataSDD::FindIndex( Int_t timeStamp, const TArrayI &timeStampArray, Int_t n ) const
479{
480// Provides binary search in the time array. Returns index in the array of time
481// stamps by selected value. Returns -1 if the time is less than time stamp in
482// the timeArray[0]
e22bf775 483
484 if( n < 1 ) return -1;// Empty array or wrong value of array size
485
dc5eacf8 486 if( timeStamp >= timeStampArray.At(n-1) ) return n-1;
e22bf775 487 // Time is larger than last timestamp - last value in the array have
488 // to be used. This is the most frequent case, so it have sense
489 // to check it and avoid searching.
490
dc5eacf8 491 if( timeStamp < timeStampArray.At(0) ) return -1;
e22bf775 492 // Time is less than all time stamp stored in the array
493
494 Int_t left = 0;
495 Int_t right = n-1;
496 Int_t middle = (left + right)/2;
497
498 while( !( middle == left || middle == right) )
499 { // Binary search in the time stamp array
500
dc5eacf8 501 if( timeStampArray.At(middle) < timeStamp )
e22bf775 502 left = middle;
503 else
504 right = middle;
505 middle = (left + right)/2;
506 } /*while*/
507
dc5eacf8 508 if( timeStamp >= timeStampArray.At(right) )
e22bf775 509 return right;
510 else
511 return left;
512
513} /*AliITSDCSDataSDD::FindIndexByTimeStamp*/
514
515//---------------------------------------------------------------------------