STEER/TFndDB.h

00001 // @(#)fROOT/STEER:$Name:  $:$Id: TFndDB.h,v 1.13 2007/09/05 16:34:21 Diego_Faso Exp $
00002 // Author: Diego Faso <mailto:faso@to.infn.it>, 2006/07/05
00003 
00004 #ifndef FROOT_TFndDB
00005 #define FROOT_TFndDB
00006 
00008 //                                                                         //
00009 //                               TFndFeeDB                                 //
00010 //                                                                         //
00011 // Interface to the FINUDA official database.                              //
00012 //                                                                         //
00014 
00015 #include "TObject.h"
00016 #include "TSQLServer.h"
00017 #include "TTreeSQL.h"
00018 #include "TSQLResult.h"
00019 #include "TSQLRow.h"
00020 
00021 //#define FndDB_TofDB2StartTime 1145138400 // Sun Apr 16 00:00:00 2006
00022 //#define FndDB_Lmd_NewTdcsTime 1045868400 // Sat Feb 22 00:00:00 2003
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]; // TOF-ADC: Slab number
00041   Int_t fTofAdcSide[K_N_Tof_AdcMod][K_N_Tof_AdcCha]; // TOF-ADC: side flag (0:p-side ; 1:e-side)
00042   Int_t fTofTdcSlab[K_N_Tof_TdcMod][K_N_Tof_TdcCha]; // TOF-TDC: Slab number
00043   Int_t fTofTdcSide[K_N_Tof_TdcMod][K_N_Tof_TdcCha]; // TOF-TDC: side flag (0:p-side ; 1:e-side)
00044   Int_t fTofMtSlab[K_N_Tof_TdcMod][K_N_Tof_TdcCha];  // Slab Number
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;}     // Is there a database link?
00071 
00072   TSQLServer *GetDBServer() { return fDBServ; }
00073   TTreeSQL *GetSqlTree(Int_t table) { return fSqlTree[table];} // see the EFndDbTables
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   // static methods for channel/numbering comversions
00082   static void Tof_ChNum_To_DetChan(const Int_t &ch,Int_t &layer,Int_t &slab){
00083     // according to official DB numbering
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     // layer:  [1;2]
00090     // slab:   [1,12] [1,72] (TOFINO TOFONE)
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     // according to official DB numbering
00096     // wirenode is needed by the geometry manager
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     // --- before fROOT-9.0
00106     /*     wirenode = wire_num-1; */
00107     /*     wirenode = wirenode + (Int_t)(wire_num/2); */
00108     /*     wirenode = wirenode *2; */
00109     /*     wirenode -= 2* (1- (Int_t)(wire_num%2)); */
00110     //
00111     //
00112     // --- after fROOT-9.0 (gcc-4/gfortran used for re-rceating geometry from fidarc 603)
00113     wirenode = wire_num-1;
00114     wirenode = wirenode + (Int_t)(wire_num/2);
00115     //    wirenode = wirenode ;
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     // lay:  [1;2]
00121     // ch:   [1,8]
00122     // wire: [1,12] (inner) ; [1,22] (outer)
00123     // wire == 0 is used by the external node
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     // ch:   [11,18];[21,28] ===> inner;outer
00136     // wire: [1,12] (inner) ; [1,22] (outer)
00137     // wire == 0 is used by the external node
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     // according to official DB numbering
00152     // wirenode is needed by the geometry manager
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     // crown:  [1;6]
00164     // tube:   [1,404]
00165     return (Int_t)( crown * 1000 + tube );
00166   }
00167   
00168   
00169   ClassDef(TFndDB,1)
00170 };
00171 #endif // FROOT_TFndDB

Generated on Tue Oct 16 15:40:48 2007 by  doxygen 1.5.2