#include <TestDbAlg.h>
Public Member Functions | |
TestDbAlg (const std::string &name, ISvcLocator *pSvcLocator) | |
StatusCode | initialize () |
StatusCode | execute () |
StatusCode | finalize () |
Definition at line 3 of file TestDbAlg.h.
TestDbAlg::TestDbAlg | ( | const std::string & | name, | |
ISvcLocator * | pSvcLocator | |||
) |
StatusCode TestDbAlg::execute | ( | ) |
Definition at line 120 of file TestDbAlg.cxx.
References msgSvc().
00120 { 00121 MsgStream log(msgSvc(), name()); 00122 00123 log << "TestDbAlg execute()" << endl; 00124 00125 return StatusCode::SUCCESS; 00126 }
StatusCode TestDbAlg::finalize | ( | ) |
StatusCode TestDbAlg::initialize | ( | ) |
Definition at line 20 of file TestDbAlg.cxx.
References DatabaseRecordVector::clear(), calibUtil::ERROR, and IDatabaseSvc::query().
00020 { 00021 MsgStream log(messageService(), name()); 00022 00023 IDatabaseSvc* m_dbsvc; 00024 StatusCode sc = serviceLocator()->service("DatabaseSvc",m_dbsvc,true); 00025 if (sc .isFailure() ) { 00026 log << MSG::ERROR << "Unable to find DatabaseSvc " << endreq; 00027 return sc; 00028 } 00029 00030 std::cout << "*************************************************************" << std::endl; 00031 std::cout << "Test 1: Numbers" << std::endl; 00032 std::cout << "*************************************************************" << std::endl; 00033 00034 char stmt[255]; 00035 sprintf(stmt,"select Vx, Vy, Vz, SigmaVx, SigmaVy, SigmaVz,RunNo from BeamPar where RunNo > 9950 and RunNo < 9980 and SftVer='6.5.1'"); 00036 00037 DatabaseRecordVector res; 00038 int row_no; 00039 row_no = m_dbsvc->query("offlinedb",stmt,res); 00040 if(row_no<0){ 00041 std::cerr << "Query \"" << stmt << "\" failed" << std::endl; 00042 return StatusCode::FAILURE; 00043 } 00044 00045 int row; 00046 double vx, svx; 00047 vx = 0; 00048 svx = 0; 00049 00050 for (row=0;row<row_no;row++){ 00051 DatabaseRecord& records = *res[row]; 00052 sscanf(records["Vx"], "%lf", &vx); 00053 sscanf(records["SigmaVx"], "%lf", &svx); 00054 cout << "Read from DB: RunNo " << records["RunNo"] << " Vx= " << vx << " SigmaVx= " << svx << endl; 00055 cout << " " << records.GetLong("RunNo") << " Vx= " << records.GetDouble("Vx") << " SigmaVx= " << records.GetDouble("SigmaVx") << endl; 00056 } 00057 00058 // Check BLOBs 00059 std::cout << "*************************************************************" << std::endl; 00060 std::cout << "Test 2: BLOBs" << std::endl; 00061 std::cout << "*************************************************************" << std::endl; 00062 00063 res.clear(); 00064 sprintf(stmt,"select EndTofPar,BarTofPar from TofCalConst where RunFrom <= 11000 and RunTo >= 11000 and SftVer='6.5.1'"); 00065 row_no = m_dbsvc->query("offlinedb", stmt, res); 00066 if(row_no<0){ 00067 std::cerr << "Query \"" << stmt << "\" failed" << std::endl; 00068 return StatusCode::FAILURE; 00069 } 00070 for (row=0;row<row_no;row++) 00071 { 00072 DatabaseRecord& records = *res[row]; 00073 // TBuffer *buf1 = new TBuffer(TBuffer::kRead); 00074 TBufferFile *buf1 = new TBufferFile(TBuffer::kRead); 00075 buf1->SetBuffer(records["EndTofPar"],32768,kFALSE); 00076 TTree* curvetree = new TTree(); 00077 curvetree->Streamer(*buf1); 00078 double cnvAtten[8]; 00079 curvetree -> SetBranchAddress("Atten0", &cnvAtten[0]); 00080 curvetree -> SetBranchAddress("Atten1", &cnvAtten[1]); 00081 curvetree -> SetBranchAddress("Atten2", &cnvAtten[2]); 00082 curvetree -> SetBranchAddress("Atten3", &cnvAtten[3]); 00083 curvetree -> SetBranchAddress("Atten4", &cnvAtten[4]); 00084 int entries=curvetree->GetEntries(); 00085 if(entries>10) entries = 10; 00086 for(int iiii=0; iiii<entries;iiii++) 00087 { 00088 curvetree->GetEntry(iiii); 00089 for(int jjj=0;jjj<5;jjj++){ 00090 std::cout<<"cnvAtten["<<jjj<<"]="<<cnvAtten[jjj]<<" "; 00091 } 00092 std::cout<<std::endl; 00093 } 00094 } 00095 00096 //sleep(600); 00097 // Test strings 00098 std::cout << "*************************************************************" << std::endl; 00099 std::cout << "Test 3: Strings" << std::endl; 00100 std::cout << "*************************************************************" << std::endl; 00101 00102 res.clear(); 00103 sprintf(stmt,"select XtTree,QtTree,T0Tree,SdTree,RunFrom,RunTo,CalParVer,FileName from MdcCalConst where SftVer = '6.5.3'"); 00104 row_no = m_dbsvc->query("offlinedb",stmt,res); 00105 if(row_no<0){ 00106 std::cerr << "Query \"" << stmt << "\" failed" << std::endl; 00107 return StatusCode::FAILURE; 00108 } 00109 00110 for (row=0;row<row_no;row++){ 00111 DatabaseRecord& records = *res[row]; 00112 cout << "Read from DB: Runs " << records["RunFrom"] << " " << records["RunTo"] << " FileName = " << records["FileName"] << endl; 00113 } 00114 00115 00116 return StatusCode::SUCCESS; 00117 }