00001
00002
00003
00004 #ifndef FROOT_TFndDB
00005 #define FROOT_TFndDB
00006
00008
00009
00010
00011
00012
00014
00015 #include "TObject.h"
00016 #include "TSQLServer.h"
00017 #include "TTreeSQL.h"
00018 #include "TSQLResult.h"
00019 #include "TSQLRow.h"
00020
00021
00022
00023
00024 #include "FROOT.h"
00025 using namespace FROOT;
00026
00027 class TFndDB: public TObject{
00028
00029 static const Int_t K_N_DbTables = 6;
00030
00031 private:
00032 Int_t fDebug;
00033 TSQLServer *fDBServ;
00034 TTreeSQL *fSqlTree[K_N_DbTables];
00035 TSQLResult *fCurRes;
00036 TSQLRow *fCurRow;
00037
00038 Bool_t fIsThere;
00039
00040 Int_t fTofAdcSlab[K_N_Tof_AdcMod][K_N_Tof_AdcCha];
00041 Int_t fTofAdcSide[K_N_Tof_AdcMod][K_N_Tof_AdcCha];
00042 Int_t fTofTdcSlab[K_N_Tof_TdcMod][K_N_Tof_TdcCha];
00043 Int_t fTofTdcSide[K_N_Tof_TdcMod][K_N_Tof_TdcCha];
00044 Int_t fTofMtSlab[K_N_Tof_TdcMod][K_N_Tof_TdcCha];
00045
00046
00047 private:
00048
00049 Int_t FetchTofRunInfo(Bool_t verbose,const Int_t &run_time);
00050 Int_t FetchSilRunInfo(Bool_t verbose,Int_t run_time);
00051 Int_t FetchLmdRunInfo(Bool_t verbose,Int_t run_time);
00052 Int_t FetchStbRunInfo(Bool_t verbose,Int_t run_time);
00053
00054 Int_t FetchTofCalibInfo(const Bool_t &verbose);
00055 Int_t FetchLmdCalibInfo(const Bool_t &verbose);
00056 Int_t FetchStbCalibInfo(const Bool_t &verbose);
00057
00058 void PrintCurRow(Int_t row_num,Int_t print_mode);
00059
00060 public:
00061 enum EFndDbTables {DBTAB_TOF_FEE = 0, DBTAB_TOF_CALIB, DBTAB_TOF_OFFSET, DBTAB_SIL_FEE, DBTAB_LMD_FEE, DBTAB_STB_FEE };
00062 enum EFndQueryPrintMode { Q_SILENT = 0, Q_GENINFO, Q_COMPACT, Q_DETAILED, Q_MYSQL_STYLE };
00063
00064 TFndDB();
00065 ~TFndDB();
00066
00067 Int_t ConnectToHost(const TString &server,TString user="finuda",TString passwd="",Int_t timeout = 3,Int_t n_trials = 10);
00068 void DisconnectFromHost();
00069 Bool_t IsConnected(){ return fDBServ->IsConnected(); }
00070 Bool_t IsThere() {return fIsThere;}
00071
00072 TSQLServer *GetDBServer() { return fDBServ; }
00073 TTreeSQL *GetSqlTree(Int_t table) { return fSqlTree[table];}
00074
00075 Int_t FetchRunInfo(Bool_t verbose,UInt_t run_time=0,Bool_t also_calib=kTRUE);
00076 Int_t LoadAllInfo(Bool_t verbose,TString TofDB_str="TofDB2");
00077 Int_t UnloadAllInfo();
00078
00079 TSQLResult* Query(TString DB_name,TString QueryStr,Int_t print_mode=(Int_t)(Q_SILENT));
00080
00081
00082 static void Tof_ChNum_To_DetChan(const Int_t &ch,Int_t &layer,Int_t &slab){
00083
00084 slab = ch % 100;
00085 layer = 1 + ((ch - slab) / 100);
00086 }
00087
00088 static Int_t Tof_ChannelToDBNumbering(const Int_t &layer,const Int_t &slab){
00089
00090
00091 return (Int_t)( ((layer-1) * 100) + slab );
00092 }
00093
00094 static void Lmd_ChNum_To_DetChan(const Int_t &ch,Int_t &lay,Int_t &dch_num,Int_t &wire_num,Int_t &wirenode){
00095
00096
00097 Int_t tmp_val = ch;
00098 lay = (ch - (ch%1000))/1000;
00099 tmp_val -= 1000*lay;
00100 dch_num = (tmp_val - (tmp_val%100))/100;
00101 tmp_val -= -(100*dch_num);
00102 wire_num = tmp_val%100;
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113 wirenode = wire_num-1;
00114 wirenode = wirenode + (Int_t)(wire_num/2);
00115
00116 wirenode -= (1- (Int_t)(wire_num%2));
00117 }
00118
00119 static Int_t Lmd_ChannelToDBNumbering(const Int_t &lay,const Int_t &ch,const Int_t &wire){
00120
00121
00122
00123
00124
00125 Int_t channel = -1;
00126 channel = (Int_t)(
00127 lay * 1000 +
00128 ch * 100 +
00129 wire
00130 );
00131 return channel;
00132 }
00133
00134 static Int_t Lmd_ChannelToDBNumbering(const Int_t &cham,const Int_t &wire){
00135
00136
00137
00138
00139 Int_t ch = cham % 10;
00140 Int_t lay = (cham - ch) / 10;
00141 Int_t channel = -1;
00142 channel = (Int_t)(
00143 lay * 1000 +
00144 ch * 100 +
00145 wire
00146 );
00147 return channel;
00148 }
00149
00150 static void Stb_ChNum_To_DetChan(const Int_t &ch,Int_t &crown,Int_t &tube,Int_t &wirenode){
00151
00152
00153 Int_t tmp_val = ch;
00154 crown = (ch - (ch%1000))/1000;
00155 tmp_val -= 1000*crown;
00156 tube = tmp_val;
00157
00158 wirenode = (tube *2) - (1 + crown%2);
00159 if(crown>=5) wirenode+= (2* K_N_STB_TUBES);
00160 }
00161
00162 static Int_t Stb_ChannelToDBNumbering(const Int_t &crown,const Int_t &tube){
00163
00164
00165 return (Int_t)( crown * 1000 + tube );
00166 }
00167
00168
00169 ClassDef(TFndDB,1)
00170 };
00171 #endif // FROOT_TFndDB