#include "AliITSDCSDataSDD.h"
#include "AliLog.h"
#define AUTORESIZE 50
ClassImp(AliITSDCSDataSDD)
const Float_t AliITSDCSDataSDD::fgkTPrec = 100.0;
const Float_t AliITSDCSDataSDD::fgkMVPrec = 1000.0;
AliITSDCSDataSDD::AliITSDCSDataSDD(): TObject(),
fTempLeft(0),
fTempLeftTimeStamp(0),
fTempLeftMaxPoints(0),
fTempLeftSetPoints(0),
fTempRight(0),
fTempRightTimeStamp(0),
fTempRightMaxPoints(0),
fTempRightSetPoints(0),
fHV(0),
fHVTimeStamp(0),
fHVMaxPoints(0),
fHVSetPoints(0),
fMV(0),
fMVTimeStamp(0),
fMVMaxPoints(0),
fMVSetPoints(0),
fStatus(0),
fStatusTimeStamp(0),
fStatusMaxPoints(0),
fStatusSetPoints(0)
{
}
void AliITSDCSDataSDD::SetNPointsTempLeft( Int_t npts )
{
if( npts < fTempLeftSetPoints)
{
AliWarning("Attemp to reduce size of full array (SDD DCS _TEMP_L)");
return;
}
fTempLeft.Set( npts );
fTempLeftTimeStamp.Set( npts );
fTempLeftMaxPoints = npts;
}
void AliITSDCSDataSDD::SetNPointsTempRight( Int_t npts )
{
if( npts < fTempRightSetPoints)
{
AliWarning("Attemp to reduce size of full array (SDD DCS _TEMP_R)");
return;
}
fTempRight.Set( npts );
fTempRightTimeStamp.Set( npts );
fTempRightMaxPoints = npts;
}
void AliITSDCSDataSDD::SetNPointsHV( Int_t npts )
{
if( npts < fHVSetPoints)
{
AliWarning("Attemp to reduce size of full array (SDD DCS _HV)");
return;
}
fHV.Set( npts );
fHVTimeStamp.Set( npts );
fHVMaxPoints = npts;
}
void AliITSDCSDataSDD::SetNPointsMV( Int_t npts )
{
if( npts < fMVSetPoints)
{
AliWarning("Attemp to reduce size of full array (SDD DCS _MV)");
return;
}
fMV.Set( npts );
fMVTimeStamp.Set( npts );
fMVMaxPoints = npts;
}
void AliITSDCSDataSDD::SetNPointsStatus( Int_t npts )
{
if( npts < fStatusSetPoints)
{
AliWarning("Attemp to reduce size of full array (SDD DCS Status)");
return;
}
fStatus.Set( npts );
fStatusTimeStamp.Set( npts );
fStatusMaxPoints = npts;
}
void AliITSDCSDataSDD::SetValueTempLeft(Int_t time, Float_t temperature )
{
if( fTempLeftMaxPoints == fTempLeftSetPoints )
SetNPointsTempLeft( fTempLeftMaxPoints + AUTORESIZE );
Int_t i = FindIndex( time, fTempLeftTimeStamp, fTempLeftSetPoints );
if( i < 0 )
i = 0;
else
i++;
if( i < fTempLeftSetPoints )
{
Short_t *fromPtrF = fTempLeft.GetArray() + i;
Short_t *toPtrF = fromPtrF + 1;
memmove( toPtrF, fromPtrF, (fTempLeftSetPoints - i)*sizeof(Short_t) );
Int_t *fromPtrI = fTempLeftTimeStamp.GetArray() + i;
Int_t *toPtrI = fromPtrI + 1;
memmove( toPtrI, fromPtrI, (fTempLeftSetPoints - i)*sizeof(Int_t) );
}
UShort_t val = (UShort_t)( temperature * fgkTPrec );
fTempLeft.AddAt( (Short_t)val, i );
fTempLeftTimeStamp.AddAt( time, i );
fTempLeftSetPoints++;
}
void AliITSDCSDataSDD::SetValueTempRight(Int_t time, Float_t temperature )
{
if( fTempRightMaxPoints == fTempRightSetPoints )
SetNPointsTempRight( fTempRightMaxPoints + AUTORESIZE );
Int_t i = FindIndex( time, fTempRightTimeStamp, fTempRightSetPoints );
if( i < 0 )
i = 0;
else
i++;
if( i < fTempRightSetPoints )
{
Short_t *fromPtrF = fTempRight.GetArray() + i;
Short_t *toPtrF = fromPtrF + 1;
memmove( toPtrF, fromPtrF, (fTempRightSetPoints - i)*sizeof(Short_t) );
Int_t *fromPtrI = fTempRightTimeStamp.GetArray() + i;
Int_t *toPtrI = fromPtrI + 1;
memmove( toPtrI, fromPtrI, (fTempRightSetPoints - i)*sizeof(Int_t) );
}
UShort_t val = (UShort_t)( temperature * fgkTPrec );
fTempRight.AddAt( (Short_t)val, i );
fTempRightTimeStamp.AddAt( time, i );
fTempRightSetPoints++;
}
void AliITSDCSDataSDD::SetValueHV(Int_t time, Float_t voltage )
{
if( fHVMaxPoints == fHVSetPoints )
SetNPointsHV( fHVMaxPoints + AUTORESIZE );
Int_t i = FindIndex( time, fHVTimeStamp, fHVSetPoints );
if( i < 0 )
i = 0;
else
i++;
if( i < fHVSetPoints )
{
Float_t *fromPtrF = fHV.GetArray() + i;
Float_t *toPtrF = fromPtrF + 1;
memmove( toPtrF, fromPtrF, (fHVSetPoints - i)*sizeof(Float_t) );
Int_t *fromPtrI = fHVTimeStamp.GetArray() + i;
Int_t *toPtrI = fromPtrI + 1;
memmove( toPtrI, fromPtrI, (fHVSetPoints - i)*sizeof(Int_t) );
}
fHV.AddAt( voltage, i );
fHVTimeStamp.AddAt( time, i );
fHVSetPoints++;
}
void AliITSDCSDataSDD::SetValueMV(Int_t time, Float_t voltage )
{
if( fMVMaxPoints == fMVSetPoints )
SetNPointsMV( fMVMaxPoints + AUTORESIZE );
Int_t i = FindIndex( time, fMVTimeStamp, fMVSetPoints );
if( i < 0 )
i = 0;
else
i++;
if( i < fMVSetPoints )
{
Short_t *fromPtrF = fMV.GetArray() + i;
Short_t *toPtrF = fromPtrF + 1;
memmove( toPtrF, fromPtrF, (fMVSetPoints - i)*sizeof(Short_t) );
Int_t *fromPtrI = fMVTimeStamp.GetArray() + i;
Int_t *toPtrI = fromPtrI + 1;
memmove( toPtrI, fromPtrI, (fMVSetPoints - i)*sizeof(Int_t) );
}
UShort_t val = (UShort_t)( voltage * fgkMVPrec );
fMV.AddAt( (Short_t)val, i );
fMVTimeStamp.AddAt( time, i );
fMVSetPoints++;
}
void AliITSDCSDataSDD::SetValueStatus(Int_t time, Char_t status )
{
if( fStatusMaxPoints == fStatusSetPoints )
SetNPointsStatus( fStatusMaxPoints + AUTORESIZE );
Int_t i = FindIndex( time, fStatusTimeStamp, fStatusSetPoints );
if( i < 0 )
i = 0;
else
i++;
if( i < fStatusSetPoints )
{
Char_t *fromPtrF = fStatus.GetArray() + i;
Char_t *toPtrF = fromPtrF + 1;
memmove( toPtrF, fromPtrF, (fStatusSetPoints - i)*sizeof(Char_t) );
Int_t *fromPtrI = fStatusTimeStamp.GetArray() + i;
Int_t *toPtrI = fromPtrI + 1;
memmove( toPtrI, fromPtrI, (fStatusSetPoints - i)*sizeof(Int_t) );
}
fStatus.AddAt( status, i );
fStatusTimeStamp.AddAt( time, i );
fStatusSetPoints++;
}
void AliITSDCSDataSDD::Compress()
{
SetNPointsTempLeft( fTempLeftSetPoints );
SetNPointsTempRight( fTempRightSetPoints );
SetNPointsHV( fHVSetPoints );
SetNPointsMV( fMVSetPoints );
SetNPointsStatus( fStatusSetPoints );
}
Float_t AliITSDCSDataSDD::GetDriftField( Int_t timeStamp ) const
{
Int_t cathodesNumber = 291;
Float_t cathodesPitch = 0.0120;
Float_t hv = GetHV( timeStamp );
Float_t mv = GetMV( timeStamp );
if( hv < 0.0 || mv < 0.0 ) return -1.0;
return ( hv - mv ) / ( cathodesNumber * cathodesPitch );
}
Float_t AliITSDCSDataSDD::GetDriftSpeed( Int_t ) const
{
return -1.0;
}
void AliITSDCSDataSDD:: PrintValues( FILE *output ) const
{
Int_t nTLEntries = GetTempLeftRecords();
Int_t nTREntries = GetTempRightRecords();
Int_t nHVEntries = GetHVRecords() ;
Int_t nMVEntries = GetMVRecords();
Int_t nStatEntries = GetStatusRecords();
fprintf( output, "+------------------------------------------------------------------------------------------------------------+\n");
fprintf( output, "| DCS content |\n" );
fprintf( output, "+----------------------+-----------------------+---------------------+---------------------+-----------------+\n");
fprintf( output, "| %05i records | %05i records | %05i records | %05i records | %05i records |\n",
nHVEntries, nMVEntries, nTLEntries, nTREntries, nStatEntries );
fprintf( output, "| time (s) HV | time (s) MV | time (s) TL | time (s) TR | time (s) Stat |\n" );
fprintf( output, "+----------------------+-----------------------+---------------------+---------------------+-----------------+\n");
Int_t a = (nHVEntries > nMVEntries ) ? nHVEntries : nMVEntries;
Int_t b = (nTLEntries > nTREntries ) ? nTLEntries : nTREntries;
if( a < b ) a = b;
Int_t loopMax = ( a > nStatEntries ) ? a : nStatEntries ;
for( Int_t entryLoop = 0; entryLoop < loopMax; entryLoop++ )
{
if( entryLoop < nHVEntries )
fprintf( output, "| %12i %4.2f | ", GetHVTimeIdx(entryLoop), GetHVIdx(entryLoop) );
else
fprintf( output, "| | ");
if( entryLoop < nMVEntries )
fprintf( output, " %12i %2.3f | ", GetMVTimeIdx(entryLoop), GetMVIdx(entryLoop) );
else
fprintf( output, " | ");
if( entryLoop < nTLEntries )
fprintf( output, "%12i %2.2f | ", GetTempLeftTimeIdx(entryLoop), GetTempLeftIdx(entryLoop) );
else
fprintf( output, " | ");
if( entryLoop < nTREntries )
fprintf( output, "%12i %2.2f | ", GetTempRightTimeIdx(entryLoop), GetTempRightIdx(entryLoop) );
else
fprintf( output, " | ");
if( entryLoop < nStatEntries )
fprintf( output, "%12i %i |\n", GetStatusTimeIdx(entryLoop), GetStatusIdx(entryLoop) );
else
fprintf( output, " |\n");
}
}
Int_t AliITSDCSDataSDD::FindIndex( Int_t timeStamp, const TArrayI &timeStampArray, Int_t n ) const
{
if( n < 1 ) return -1;
if( timeStamp >= timeStampArray.At(n-1) ) return n-1;
if( timeStamp < timeStampArray.At(0) ) return -1;
Int_t left = 0;
Int_t right = n-1;
Int_t middle = (left + right)/2;
while( !( middle == left || middle == right) )
{
if( timeStampArray.At(middle) < timeStamp )
left = middle;
else
right = middle;
middle = (left + right)/2;
}
if( timeStamp >= timeStampArray.At(right) )
return right;
else
return left;
}