00001 #ifndef St_starMagOnlC_h
00002 #define St_starMagOnlC_h
00003
00004 #include "TChair.h"
00005 #include "TMath.h"
00006 #include "tables/St_starMagOnl_Table.h"
00007
00008 enum StMagnetPolarity {eUnknownMField, eFullMFieldPolB, eHalfMFieldPolB,
00009 eZeroMField, eHalfMFieldPolA, eFullMFieldPolA};
00010
00011 class St_starMagOnlC : public TChair {
00012 public:
00013 static St_starMagOnlC* instance();
00014 starMagOnl_st*Struct(Int_t i = 0) {return ((St_starMagOnl*) Table())->GetTable()+i;}
00015 UInt_t getNumRows() {return GetNRows();}
00016 UInt_t runNumber(Int_t i = 0) {return Struct(i)->runNumber;}
00017 UInt_t time(Int_t i = 0) {return Struct(i)->time;}
00018 Double_t current(Int_t i = 0) {return Struct(i)->current;}
00019 Double_t getScaleFactor(UInt_t time=0) {return currentToScaleFactor(getMagnetCurrent(time));}
00020 Double_t getMagnetCurrent(UInt_t time=0) {
00021 if (! instance()) return 0;
00022 if (getNumRows() == 1 || time == 0) return current();
00023 Double_t tempCurrent = -9999;
00024 for (UInt_t i = 0; i < getNumRows()-1; i++)
00025 if( time >= getTimeEntry(i) && time <= getTimeEntry(i+1) )
00026 if( TMath::Abs(getMagnetCurrentEntry(i) - getMagnetCurrentEntry(i+1)) < 50 )
00027 tempCurrent = getMagnetCurrentEntry(i);
00028 return tempCurrent;
00029 }
00030 StMagnetPolarity getMagneticField(UInt_t time=0) {
00031 StMagnetPolarity value = eUnknownMField;
00032 if (! instance()) return value;
00033 Double_t scaleFactor = getScaleFactor(time);
00034 if(scaleFactor == 1.0) value = eFullMFieldPolA;
00035 if(scaleFactor == 0.5) value = eHalfMFieldPolA;
00036 if(scaleFactor == 0.0) value = eZeroMField;
00037 if(scaleFactor == -0.5) value = eHalfMFieldPolB;
00038 if(scaleFactor == -1.0) value = eFullMFieldPolB;
00039 return value;
00040 }
00041 UInt_t getRunNumber() {return runNumber();}
00042 UInt_t getTimeEntry(UInt_t i=0) {return time(i);}
00043 Double_t getMagnetCurrentEntry(UInt_t i=0) {return current(i);}
00044 static Double_t currentToScaleFactor(Double_t current) {
00045 Double_t value = -9999;
00046 if (! instance()) return value;
00047 if (current < -4450 && current > -4550) value = -1.0;
00048 else if(current < -2200 && current > -2300) value = -0.5;
00049 else if(current > -50 && current < 50) value = 0.0;
00050 else if(current > 2200 && current < 2300) value = 0.5;
00051 else if(current > 4450 && current < 4550) value = 1.0;
00052 return value;
00053 }
00054 protected:
00055 St_starMagOnlC(St_starMagOnl *table=0) : TChair(table) {}
00056 virtual ~St_starMagOnlC() {fgInstance = 0;}
00057 private:
00058 static St_starMagOnlC* fgInstance;
00059 ClassDefChair(St_starMagOnl, starMagOnl_st )
00060 ClassDef(St_starMagOnlC,1)
00061 };
00062 #endif