1 /**************************************************************************
2 * Copyright(c) 2007-2009, 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 **************************************************************************/
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 ///////////////////////////////////////////////////////////////////
24 #include "AliITSDCSDataSDD.h"
29 ClassImp(AliITSDCSDataSDD)
31 const Float_t AliITSDCSDataSDD::fgkTPrec = 100.0;
32 const Float_t AliITSDCSDataSDD::fgkMVPrec = 1000.0;
34 //---------------------------------------------------------------------------
35 AliITSDCSDataSDD::AliITSDCSDataSDD(): TObject(),
37 fTempLeftTimeStamp(0),
38 fTempLeftMaxPoints(0),
39 fTempLeftSetPoints(0),
41 fTempRightTimeStamp(0),
42 fTempRightMaxPoints(0),
43 fTempRightSetPoints(0),
57 // default constructor
58 } /*AliITSDCSDataSDD::AliITSDCSDataSDD*/
60 //---------------------------------------------------------------------------
62 void AliITSDCSDataSDD::SetNPointsTempLeft( Int_t npts )
64 // dimension arrays with left side temperatures
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)");
73 fTempLeft.Set( npts );
74 fTempLeftTimeStamp.Set( npts );
75 // Both temperature and tme stamp arrays are resized
77 fTempLeftMaxPoints = npts;
79 } /*AliITSDCSDataSDD::SetNPointsTempLeft*/
81 //---------------------------------------------------------------------------
83 void AliITSDCSDataSDD::SetNPointsTempRight( Int_t npts )
85 // dimension arrays with right side temperatures
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)");
94 fTempRight.Set( npts );
95 fTempRightTimeStamp.Set( npts );
96 // Both temperature and tme stamp arrays are resized
98 fTempRightMaxPoints = npts;
100 } /*AliITSDCSDataSDD::SetNPointsTempRight*/
102 //---------------------------------------------------------------------------
104 void AliITSDCSDataSDD::SetNPointsHV( Int_t npts )
106 // dimension arrays with HV values
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)");
116 fHVTimeStamp.Set( npts );
117 // Both temperature and tme stamp arrays are resized
119 fHVMaxPoints = npts; // New size is stored
121 }/*AliITSDCSDataSDD::SetNPointsHV*/
123 //---------------------------------------------------------------------------
125 void AliITSDCSDataSDD::SetNPointsMV( Int_t npts )
127 // dimension arrays with MV values
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)");
137 fMVTimeStamp.Set( npts );
138 // Both temperature and tme stamp arrays are resized
140 fMVMaxPoints = npts; // New size is stored
142 } /*AliITSDCSDataSDD::SetNPointsMV*/
144 //---------------------------------------------------------------------------
146 void AliITSDCSDataSDD::SetNPointsStatus( Int_t npts )
148 // dimension arrays withn DCS channel status
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)");
158 fStatusTimeStamp.Set( npts );
159 // Both temperature and tme stamp arrays are resized
161 fStatusMaxPoints = npts;
162 // New size is stored
164 } /*AliITSDCSDataSDD::SetNPointsMV*/
166 //---------------------------------------------------------------------------
167 void AliITSDCSDataSDD::SetValueTempLeft(Int_t time, Float_t temperature )
169 // insert a value for left temperature data point
172 if( fTempLeftMaxPoints == fTempLeftSetPoints )
173 SetNPointsTempLeft( fTempLeftMaxPoints + AUTORESIZE );
174 // Enlarges arrays if necessary
176 Int_t i = FindIndex( time, fTempLeftTimeStamp, fTempLeftSetPoints );
177 // Finds place where the new value have to be inserted
180 i = 0; // New value have to be inserted before the first one in the array
182 i++; // New value will be put somewhere in the middle of the array
185 if( i < fTempLeftSetPoints )
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
192 memmove( toPtrF, fromPtrF, (fTempLeftSetPoints - i)*sizeof(Short_t) );
193 // Shifts array content. Now there is vacant place for new value to be inserted
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
201 UShort_t val = (UShort_t)( temperature * fgkTPrec );
202 // Float value of temperature is stored as UShort_t with given precision
204 fTempLeft.AddAt( (Short_t)val, i );
205 fTempLeftTimeStamp.AddAt( time, i );
206 fTempLeftSetPoints++;
207 // New values are inserted
208 } /*AliITSDCSDataSDD::SetValueTempLeft*/
210 //---------------------------------------------------------------------------
212 void AliITSDCSDataSDD::SetValueTempRight(Int_t time, Float_t temperature )
214 // insert a value for right temperature data point
217 if( fTempRightMaxPoints == fTempRightSetPoints )
218 SetNPointsTempRight( fTempRightMaxPoints + AUTORESIZE );
219 // Enlarges arrays if necessary
221 Int_t i = FindIndex( time, fTempRightTimeStamp, fTempRightSetPoints );
222 // Finds place where the new value have to be inserted
225 i = 0; // New value have to be inserted before the first one in the array
227 i++; // New value will be put somewhere in the middle of the array
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
237 memmove( toPtrF, fromPtrF, (fTempRightSetPoints - i)*sizeof(Short_t) );
238 // Shifts array content. Now there is vacant place for new value to be inserted
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
246 UShort_t val = (UShort_t)( temperature * fgkTPrec );
247 // Float value of temperature is stored as UShort_t with given precision
249 fTempRight.AddAt( (Short_t)val, i );
250 fTempRightTimeStamp.AddAt( time, i );
251 fTempRightSetPoints++;
252 // New values are inserted
253 } /*AliITSDCSDataSDD::SetValueTempRight*/
255 //---------------------------------------------------------------------------
257 void AliITSDCSDataSDD::SetValueHV(Int_t time, Float_t voltage )
259 // insert a value for HV data point
262 if( fHVMaxPoints == fHVSetPoints )
263 SetNPointsHV( fHVMaxPoints + AUTORESIZE );
264 // Enlarges arrays if necessary
266 Int_t i = FindIndex( time, fHVTimeStamp, fHVSetPoints );
267 // Finds place where the new value have to be inserted
270 i = 0; // New value have to be inserted before the first one in the array
272 i++; // New value will be put somewhere in the middle of the array
275 if( i < fHVSetPoints )
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
282 memmove( toPtrF, fromPtrF, (fHVSetPoints - i)*sizeof(Float_t) );
283 // Shifts array content. Now there is vacant place for new value to be inserted
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
291 fHV.AddAt( voltage, i );
292 fHVTimeStamp.AddAt( time, i );
294 // New values are inserted
295 } /*AliITSDCSDataSDD::SetValueHV*/
297 //---------------------------------------------------------------------------
299 void AliITSDCSDataSDD::SetValueMV(Int_t time, Float_t voltage )
301 // insert a value for MV data point
304 if( fMVMaxPoints == fMVSetPoints )
305 SetNPointsMV( fMVMaxPoints + AUTORESIZE );
306 // Enlarges arrays if necessary
308 Int_t i = FindIndex( time, fMVTimeStamp, fMVSetPoints );
309 // Finds place where the new value have to be inserted
312 i = 0; // New value have to be inserted before the first one in the array
314 i++; // New value will be put somewhere in the middle of the array
317 if( i < fMVSetPoints )
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
324 memmove( toPtrF, fromPtrF, (fMVSetPoints - i)*sizeof(Short_t) );
325 // Shifts array content. Now there is vacant place for new value to be inserted
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
333 UShort_t val = (UShort_t)( voltage * fgkMVPrec );
334 // Float value of temperature is stored as UShort_t with given precision
336 fMV.AddAt( (Short_t)val, i );
337 fMVTimeStamp.AddAt( time, i );
339 // New values are inserted
340 } /*AliITSDCSDataSDD::SetValueMV*/
342 //---------------------------------------------------------------------------
344 void AliITSDCSDataSDD::SetValueStatus(Int_t time, Char_t status )
346 // insert a value for channel status
349 if( fStatusMaxPoints == fStatusSetPoints )
350 SetNPointsStatus( fStatusMaxPoints + AUTORESIZE );
351 // Enlarges arrays if necessary
353 Int_t i = FindIndex( time, fStatusTimeStamp, fStatusSetPoints );
354 // Finds place where the new value have to be inserted
357 i = 0; // New value have to be inserted before the first one in the array
359 i++; // New value will be put somewhere in the middle of the array
362 if( i < fStatusSetPoints )
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
369 memmove( toPtrF, fromPtrF, (fStatusSetPoints - i)*sizeof(Char_t) );
370 // Shifts array content. Now there is vacant place for new value to be inserted
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
378 fStatus.AddAt( status, i );
379 fStatusTimeStamp.AddAt( time, i );
381 // New values are inserted
383 } /*AliITSDCSDataSDD::SetValueStatus*/
386 //---------------------------------------------------------------------------
388 void AliITSDCSDataSDD::Compress()
390 // Minimize array sizes
392 SetNPointsTempLeft( fTempLeftSetPoints );
393 SetNPointsTempRight( fTempRightSetPoints );
394 SetNPointsHV( fHVSetPoints );
395 SetNPointsMV( fMVSetPoints );
396 SetNPointsStatus( fStatusSetPoints );
398 } /*AliITSDCSDataSDD::Compress*/
400 //---------------------------------------------------------------------------
402 Float_t AliITSDCSDataSDD::GetDriftField( Int_t timeStamp ) const
404 // Returns drift field counted for specific time
406 Int_t cathodesNumber = 291;
407 Float_t cathodesPitch = 0.0120;
409 Float_t hv = GetHV( timeStamp );
410 Float_t mv = GetMV( timeStamp );
412 if( hv < 0.0 || mv < 0.0 ) return -1.0;
413 // HV or MV is unknown at this time
415 return ( hv - mv ) / ( cathodesNumber * cathodesPitch );
417 } /*AliITSDCSDataSDD::GetDriftField*/
419 //---------------------------------------------------------------------------
422 Float_t AliITSDCSDataSDD::GetDriftSpeed( Int_t /*timeStamp*/ ) const
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.
428 // Presently only a prototype, returns -1.0.
434 } /*AliITSDCSDataSDD::*/
436 //---------------------------------------------------------------------------
439 void AliITSDCSDataSDD:: PrintValues( FILE *output ) const
441 // Prints array contents
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();
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");
457 Int_t a = (nHVEntries > nMVEntries ) ? nHVEntries : nMVEntries;
458 Int_t b = (nTLEntries > nTREntries ) ? nTLEntries : nTREntries;
460 Int_t loopMax = ( a > nStatEntries ) ? a : nStatEntries ;
461 // Finds maximal entry number
463 for( Int_t entryLoop = 0; entryLoop < loopMax; entryLoop++ )
466 if( entryLoop < nHVEntries )
467 fprintf( output, "| %12i %4.2f | ", GetHVTimeIdx(entryLoop), GetHVIdx(entryLoop) );
469 fprintf( output, "| | ");
471 if( entryLoop < nMVEntries )
472 fprintf( output, " %12i %2.3f | ", GetMVTimeIdx(entryLoop), GetMVIdx(entryLoop) );
474 fprintf( output, " | ");
476 if( entryLoop < nTLEntries )
477 fprintf( output, "%12i %2.2f | ", GetTempLeftTimeIdx(entryLoop), GetTempLeftIdx(entryLoop) );
479 fprintf( output, " | ");
481 if( entryLoop < nTREntries )
482 fprintf( output, "%12i %2.2f | ", GetTempRightTimeIdx(entryLoop), GetTempRightIdx(entryLoop) );
484 fprintf( output, " | ");
486 if( entryLoop < nStatEntries )
487 fprintf( output, "%12i %i |\n", GetStatusTimeIdx(entryLoop), GetStatusIdx(entryLoop) );
489 fprintf( output, " |\n");
491 } /*for( entryLoop )*/
494 } /*AliITSDCSDataSDD::PrintValues()*/
496 //---------------------------------------------------------------------------
498 Int_t AliITSDCSDataSDD::FindIndex( Int_t timeStamp, const TArrayI &timeStampArray, Int_t n ) const
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
504 if( n < 1 ) return -1;// Empty array or wrong value of array size
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.
511 if( timeStamp < timeStampArray.At(0) ) return -1;
512 // Time is less than all time stamp stored in the array
516 Int_t middle = (left + right)/2;
518 while( !( middle == left || middle == right) )
519 { // Binary search in the time stamp array
521 if( timeStampArray.At(middle) < timeStamp )
525 middle = (left + right)/2;
528 if( timeStamp >= timeStampArray.At(right) )
533 } /*AliITSDCSDataSDD::FindIndexByTimeStamp*/
535 //---------------------------------------------------------------------------