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 )
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)");
71 fTempLeft.Set( npts );
72 fTempLeftTimeStamp.Set( npts );
73 // Both temperature and tme stamp arrays are resized
75 fTempLeftMaxPoints = npts;
77 } /*AliITSDCSDataSDD::SetNPointsTempLeft*/
79 //---------------------------------------------------------------------------
81 void AliITSDCSDataSDD::SetNPointsTempRight( Int_t npts )
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)");
90 fTempRight.Set( npts );
91 fTempRightTimeStamp.Set( npts );
92 // Both temperature and tme stamp arrays are resized
94 fTempRightMaxPoints = npts;
96 } /*AliITSDCSDataSDD::SetNPointsTempRight*/
98 //---------------------------------------------------------------------------
100 void AliITSDCSDataSDD::SetNPointsHV( Int_t npts )
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)");
110 fHVTimeStamp.Set( npts );
111 // Both temperature and tme stamp arrays are resized
113 fHVMaxPoints = npts; // New size is stored
115 }/*AliITSDCSDataSDD::SetNPointsHV*/
117 //---------------------------------------------------------------------------
119 void AliITSDCSDataSDD::SetNPointsMV( Int_t npts )
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)");
129 fMVTimeStamp.Set( npts );
130 // Both temperature and tme stamp arrays are resized
132 fMVMaxPoints = npts; // New size is stored
134 } /*AliITSDCSDataSDD::SetNPointsMV*/
136 //---------------------------------------------------------------------------
138 void AliITSDCSDataSDD::SetNPointsStatus( Int_t npts )
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)");
148 fStatusTimeStamp.Set( npts );
149 // Both temperature and tme stamp arrays are resized
151 fStatusMaxPoints = npts;
152 // New size is stored
154 } /*AliITSDCSDataSDD::SetNPointsMV*/
156 //---------------------------------------------------------------------------
157 void AliITSDCSDataSDD::SetValueTempLeft(Int_t time, Float_t temperature )
160 if( fTempLeftMaxPoints == fTempLeftSetPoints )
161 SetNPointsTempLeft( fTempLeftMaxPoints + AUTORESIZE );
162 // Enlarges arrays if necessary
164 Int_t i = FindIndex( time, fTempLeftTimeStamp, fTempLeftSetPoints );
165 // Finds place where the new value have to be inserted
168 i = 0; // New value have to be inserted before the first one in the array
170 i++; // New value will be put somewhere in the middle of the array
173 if( i < fTempLeftSetPoints )
175 Short_t *fromPtrF = fTempLeft.GetArray() + i;
176 // Sets pointer to cell which have to be filled by new value
177 Short_t *toPtrF = fromPtrF + 1;
178 // Sets pointer to cell where the array content have to be shifted
180 memmove( toPtrF, fromPtrF, (fTempLeftSetPoints - i)*sizeof(Short_t) );
181 // Shifts array content. Now there is vacant place for new value to be inserted
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
189 UShort_t val = (UShort_t)( temperature * fgkTPrec );
190 // Float value of temperature is stored as UShort_t with given precision
192 fTempLeft.AddAt( (Short_t)val, i );
193 fTempLeftTimeStamp.AddAt( time, i );
194 fTempLeftSetPoints++;
195 // New values are inserted
196 } /*AliITSDCSDataSDD::SetValueTempLeft*/
198 //---------------------------------------------------------------------------
200 void AliITSDCSDataSDD::SetValueTempRight(Int_t time, Float_t temperature )
203 if( fTempRightMaxPoints == fTempRightSetPoints )
204 SetNPointsTempRight( fTempRightMaxPoints + AUTORESIZE );
205 // Enlarges arrays if necessary
207 Int_t i = FindIndex( time, fTempRightTimeStamp, fTempRightSetPoints );
208 // Finds place where the new value have to be inserted
211 i = 0; // New value have to be inserted before the first one in the array
213 i++; // New value will be put somewhere in the middle of the array
216 if( i < fTempRightSetPoints )
217 { // Some values have to be moved
218 Short_t *fromPtrF = fTempRight.GetArray() + i;
219 // Sets pointer to cell which have to be filled by new value
220 Short_t *toPtrF = fromPtrF + 1;
221 // Sets pointer to cell where the array content have to be shifted
223 memmove( toPtrF, fromPtrF, (fTempRightSetPoints - i)*sizeof(Short_t) );
224 // Shifts array content. Now there is vacant place for new value to be inserted
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
232 UShort_t val = (UShort_t)( temperature * fgkTPrec );
233 // Float value of temperature is stored as UShort_t with given precision
235 fTempRight.AddAt( (Short_t)val, i );
236 fTempRightTimeStamp.AddAt( time, i );
237 fTempRightSetPoints++;
238 // New values are inserted
239 } /*AliITSDCSDataSDD::SetValueTempRight*/
241 //---------------------------------------------------------------------------
243 void AliITSDCSDataSDD::SetValueHV(Int_t time, Float_t voltage )
246 if( fHVMaxPoints == fHVSetPoints )
247 SetNPointsHV( fHVMaxPoints + AUTORESIZE );
248 // Enlarges arrays if necessary
250 Int_t i = FindIndex( time, fHVTimeStamp, fHVSetPoints );
251 // Finds place where the new value have to be inserted
254 i = 0; // New value have to be inserted before the first one in the array
256 i++; // New value will be put somewhere in the middle of the array
259 if( i < fHVSetPoints )
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
266 memmove( toPtrF, fromPtrF, (fHVSetPoints - i)*sizeof(Float_t) );
267 // Shifts array content. Now there is vacant place for new value to be inserted
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
275 fHV.AddAt( voltage, i );
276 fHVTimeStamp.AddAt( time, i );
278 // New values are inserted
279 } /*AliITSDCSDataSDD::SetValueHV*/
281 //---------------------------------------------------------------------------
283 void AliITSDCSDataSDD::SetValueMV(Int_t time, Float_t voltage )
286 if( fMVMaxPoints == fMVSetPoints )
287 SetNPointsMV( fMVMaxPoints + AUTORESIZE );
288 // Enlarges arrays if necessary
290 Int_t i = FindIndex( time, fMVTimeStamp, fMVSetPoints );
291 // Finds place where the new value have to be inserted
294 i = 0; // New value have to be inserted before the first one in the array
296 i++; // New value will be put somewhere in the middle of the array
299 if( i < fMVSetPoints )
301 Short_t *fromPtrF = fMV.GetArray() + i;
302 // Sets pointer to cell which have to be filled by new value
303 Short_t *toPtrF = fromPtrF + 1;
304 // Sets pointer to cell where the array content have to be shifted
306 memmove( toPtrF, fromPtrF, (fMVSetPoints - i)*sizeof(Short_t) );
307 // Shifts array content. Now there is vacant place for new value to be inserted
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
315 UShort_t val = (UShort_t)( voltage * fgkMVPrec );
316 // Float value of temperature is stored as UShort_t with given precision
318 fMV.AddAt( (Short_t)val, i );
319 fMVTimeStamp.AddAt( time, i );
321 // New values are inserted
322 } /*AliITSDCSDataSDD::SetValueMV*/
324 //---------------------------------------------------------------------------
326 void AliITSDCSDataSDD::SetValueStatus(Int_t time, Char_t status )
329 if( fStatusMaxPoints == fStatusSetPoints )
330 SetNPointsStatus( fStatusMaxPoints + AUTORESIZE );
331 // Enlarges arrays if necessary
333 Int_t i = FindIndex( time, fStatusTimeStamp, fStatusSetPoints );
334 // Finds place where the new value have to be inserted
337 i = 0; // New value have to be inserted before the first one in the array
339 i++; // New value will be put somewhere in the middle of the array
342 if( i < fStatusSetPoints )
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
349 memmove( toPtrF, fromPtrF, (fStatusSetPoints - i)*sizeof(Char_t) );
350 // Shifts array content. Now there is vacant place for new value to be inserted
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
358 fStatus.AddAt( status, i );
359 fStatusTimeStamp.AddAt( time, i );
361 // New values are inserted
363 } /*AliITSDCSDataSDD::SetValueStatus*/
366 //---------------------------------------------------------------------------
368 void AliITSDCSDataSDD::Compress()
370 // Minimize array sizes
372 SetNPointsTempLeft( fTempLeftSetPoints );
373 SetNPointsTempRight( fTempRightSetPoints );
374 SetNPointsHV( fHVSetPoints );
375 SetNPointsMV( fMVSetPoints );
376 SetNPointsStatus( fStatusSetPoints );
378 } /*AliITSDCSDataSDD::Compress*/
380 //---------------------------------------------------------------------------
382 Float_t AliITSDCSDataSDD::GetDriftField( Int_t timeStamp ) const
384 // Returns drift field counted for specific time
386 Int_t cathodesNumber = 291;
387 Float_t cathodesPitch = 0.0120;
389 Float_t hv = GetHV( timeStamp );
390 Float_t mv = GetMV( timeStamp );
392 if( hv < 0.0 || mv < 0.0 ) return -1.0;
393 // HV or MV is unknown at this time
395 return ( hv - mv ) / ( cathodesNumber * cathodesPitch );
397 } /*AliITSDCSDataSDD::GetDriftField*/
399 //---------------------------------------------------------------------------
402 Float_t AliITSDCSDataSDD::GetDriftSpeed( Int_t /*timeStamp*/ ) const
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.
408 // Presently only a prototype, returns -1.0.
414 } /*AliITSDCSDataSDD::*/
416 //---------------------------------------------------------------------------
419 void AliITSDCSDataSDD:: PrintValues( FILE *output ) const
421 // Prints array contents
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();
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",
433 nHVEntries, nMVEntries, nTLEntries, nTREntries, nStatEntries );
434 fprintf( output, "| time (s) HV | time (s) MV | time (s) TL | time (s) TR | time (s) Stat |\n" );
435 fprintf( output, "+----------------------+-----------------------+---------------------+---------------------+-----------------+\n");
437 Int_t a = (nHVEntries > nMVEntries ) ? nHVEntries : nMVEntries;
438 Int_t b = (nTLEntries > nTREntries ) ? nTLEntries : nTREntries;
440 Int_t loopMax = ( a > nStatEntries ) ? a : nStatEntries ;
441 // Finds maximal entry number
443 for( Int_t entryLoop = 0; entryLoop < loopMax; entryLoop++ )
446 if( entryLoop < nHVEntries )
447 fprintf( output, "| %12i %4.2f | ", GetHVTimeIdx(entryLoop), GetHVIdx(entryLoop) );
449 fprintf( output, "| | ");
451 if( entryLoop < nMVEntries )
452 fprintf( output, " %12i %2.3f | ", GetMVTimeIdx(entryLoop), GetMVIdx(entryLoop) );
454 fprintf( output, " | ");
456 if( entryLoop < nTLEntries )
457 fprintf( output, "%12i %2.2f | ", GetTempLeftTimeIdx(entryLoop), GetTempLeftIdx(entryLoop) );
459 fprintf( output, " | ");
461 if( entryLoop < nTREntries )
462 fprintf( output, "%12i %2.2f | ", GetTempRightTimeIdx(entryLoop), GetTempRightIdx(entryLoop) );
464 fprintf( output, " | ");
466 if( entryLoop < nStatEntries )
467 fprintf( output, "%12i %i |\n", GetStatusTimeIdx(entryLoop), GetStatusIdx(entryLoop) );
469 fprintf( output, " |\n");
471 } /*for( entryLoop )*/
474 } /*AliITSDCSDataSDD::PrintValues()*/
476 //---------------------------------------------------------------------------
478 Int_t AliITSDCSDataSDD::FindIndex( Int_t timeStamp, const TArrayI &timeStampArray, Int_t n ) const
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
484 if( n < 1 ) return -1;// Empty array or wrong value of array size
486 if( timeStamp >= timeStampArray.At(n-1) ) return n-1;
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.
491 if( timeStamp < timeStampArray.At(0) ) return -1;
492 // Time is less than all time stamp stored in the array
496 Int_t middle = (left + right)/2;
498 while( !( middle == left || middle == right) )
499 { // Binary search in the time stamp array
501 if( timeStampArray.At(middle) < timeStamp )
505 middle = (left + right)/2;
508 if( timeStamp >= timeStampArray.At(right) )
513 } /*AliITSDCSDataSDD::FindIndexByTimeStamp*/
515 //---------------------------------------------------------------------------