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