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