emcCalibrationData.C

Go to the documentation of this file.
00001 #include "emcCalibrationData.h"
00002 #include <iostream>
00003 #include <string>
00004 
00005 using namespace std;
00006 
00007 const float emcCalibrationData::fgInvalidFloat = -99999.9999;
00008 
00009 //_____________________________________________________________________________
00010 emcCalibrationData::emcCalibrationData(EType type, size_t number, size_t size)
00011   : fStart(0), fEnd(0), fType(type), fNumber(number),
00012     fValues(0), fErrors(0), fSize(size), fDimension(0)
00013 {
00014   SetTypeAndSize(fType, fSize);
00015 }
00016 
00017 //_____________________________________________________________________________
00018 emcCalibrationData::~emcCalibrationData()
00019 {
00020   Reset();
00021 }
00022 
00023 //_____________________________________________________________________________
00024 const char*
00025 emcCalibrationData::GetCategory(void) const
00026 {
00027   string cat;
00028 
00029   switch (fType)
00030     {
00031     case kUnknown:
00032       cat = "UNKNOWN";
00033       break;
00034     case kIniCal:
00035       cat = "generic.IniCal";
00036       break;   
00037     case kTofSectorOffset:
00038       cat = "tof.sector.offsets";
00039       break;
00040     default:
00041       return "???";
00042       break;
00043     }
00044   return cat.c_str();
00045 }
00046 
00047 //_____________________________________________________________________________
00048 float
00049 emcCalibrationData::GetError(size_t index, size_t dim) const
00050 {
00051   float rv = fgInvalidFloat;
00052 
00053   if ( index < fSize &&
00054        dim < fDimension )
00055     {
00056       rv = fErrors[index][dim];
00057     }
00058   return rv;
00059 }
00060 
00061 //_____________________________________________________________________________
00062 const char*
00063 emcCalibrationData::GetTypeName(EType type)
00064 {
00065   // Type name should not contain blanks and should be short,
00066   // as it is used to infer the DB name.
00067 
00068   switch (type)
00069     {
00070     case kUnknown:
00071       return "UNKNOWN";
00072       break;   
00073     case kIniCal:
00074       return "IniCal";
00075       break;
00076     case kTofSectorOffset:
00077       return "TofSectorOffset";
00078       break;
00079     default:
00080       return "???";
00081       break;
00082     }
00083 }
00084 
00085 //_____________________________________________________________________________
00086 float
00087 emcCalibrationData::GetValue(size_t index, size_t dim) const
00088 {
00089   float rv = fgInvalidFloat;
00090 
00091   if ( index < fSize &&
00092        dim < fDimension )
00093     {
00094       rv = fValues[index][dim];
00095     }
00096   return rv;
00097 }
00098 
00099 //_____________________________________________________________________________
00100 bool
00101 emcCalibrationData::IsValid(const PHTimeStamp& cwhen) const
00102 {
00103   PHTimeStamp& when = const_cast<PHTimeStamp&>(cwhen);
00104   if (when.isInRange(fStart, fEnd))
00105     return true;
00106   return false;
00107 }
00108 
00109 //_____________________________________________________________________________
00110 void
00111 emcCalibrationData::Print(int level) const
00112 {
00113   cout << "Calibration type " << static_cast<int>(fType)
00114        << " (\"" << GetTypeName() << "\")"
00115        << " number " << fNumber
00116        << " has " << fSize << " entries." << endl;
00117   cout << " - is valid from " << fStart << " until "
00118        << fEnd << endl;
00119   if (level)
00120     {
00121       size_t i;
00122       for (i = 0;i < fSize;i++)
00123         {
00124           cout << i << " ";
00125           size_t j;
00126           for (j = 0;j < fDimension;j++)
00127             {
00128               if (j)
00129                 cout << " , ";
00130               cout << GetValue(i, j) << " +- " << GetError(i, j);
00131             }
00132           cout << endl;
00133         }
00134     }
00135 }
00136 
00137 //_____________________________________________________________________________
00138 void
00139 emcCalibrationData::Reset(void)
00140 {
00141   if (!fValues || !fErrors)
00142     return ;
00143 
00144   size_t i;
00145 
00146   for ( i = 0; i < fSize; i++ )
00147     {
00148       delete[] fValues[i];
00149       fValues[i] = 0;
00150       delete[] fErrors[i];
00151       fErrors[i] = 0;
00152     }
00153 
00154   delete[] fValues;
00155   delete[] fErrors;
00156 
00157   fValues = 0;
00158   fErrors = 0;
00159   fDimension = 0;
00160   fSize = 0;
00161   fStart.setTics(0);
00162   fEnd.setTics(0);
00163 }
00164 
00165 //_____________________________________________________________________________
00166 bool
00167 emcCalibrationData::Set(size_t index, float value, float error, size_t dim)
00168 {
00169   bool rv = false;
00170 
00171   if ( index < fSize &&
00172        dim < fDimension )
00173     {
00174       fValues[index][dim] = value;
00175       fErrors[index][dim] = error;
00176       rv = true;
00177     }
00178   return rv;
00179 }
00180 
00181 //_____________________________________________________________________________
00182 void
00183 emcCalibrationData::SetTypeAndSize(EType type, size_t size)
00184 {
00185   Reset();
00186 
00187   fType = type;
00188   fSize = size;
00189 
00190   fRange = 1;
00191   fDimension = 1;
00192 
00193   if (fType == kIniCal)
00194     {
00195       fDimension = 3;
00196       fRange = 8;
00197     }
00198   else if (fType == kTofSectorOffset)
00199     {
00200       fDimension = 5;
00201       // dim 0 = run,number of events
00202       // dim 1 = peak, width
00203       // dim 2 = gaus peak, gaus width
00204       // dim 3 = bbcT0, bbcT0rms
00205       // dim 4 = toft0, tofT0rms
00206       fRange = 8;
00207     }
00208 
00209   if (fSize)
00210     {
00211 
00212       fValues = new float * [fSize];
00213       fErrors = new float * [fSize];
00214 
00215       size_t i;
00216       size_t j;
00217 
00218       for ( i = 0; i < fSize; i++ )
00219         {
00220           fValues[i] = new float[fDimension];
00221           fErrors[i] = new float[fDimension];
00222           for ( j = 0; j < fDimension; j++ )
00223             {
00224               fValues[i][j] = fErrors[i][j] = 0.0;
00225             }
00226         }
00227     }
00228 }
00229 
00230 
00231 
00232 
00233