20 {
21 MsgStream log(messageService(), name());
22
24 StatusCode sc = serviceLocator()->service("DatabaseSvc",m_dbsvc,true);
25 if (sc .isFailure() ) {
26 log << MSG::ERROR << "Unable to find DatabaseSvc " << endreq;
27 return sc;
28 }
29
30 std::cout << "*************************************************************" << std::endl;
31 std::cout << "Test 1: Numbers" << std::endl;
32 std::cout << "*************************************************************" << std::endl;
33
34 char stmt[255];
35 sprintf(stmt,"select Vx, Vy, Vz, SigmaVx, SigmaVy, SigmaVz,RunNo from BeamPar where RunNo > 9950 and RunNo < 9980 and SftVer='6.5.1'");
36
38 int row_no;
39 row_no = m_dbsvc->
query(
"offlinedb",stmt,res);
40 if(row_no<0){
41 std::cerr << "Query \"" << stmt << "\" failed" << std::endl;
42 return StatusCode::FAILURE;
43 }
44
45 int row;
46 double vx, svx;
47 vx = 0;
48 svx = 0;
49
50 for (row=0;row<row_no;row++){
52 sscanf(records["Vx"], "%lf", &vx);
53 sscanf(records["SigmaVx"], "%lf", &svx);
54 cout << "Read from DB: RunNo " << records["RunNo"] << " Vx= " << vx << " SigmaVx= " << svx << endl;
55 cout <<
" " << records.
GetLong(
"RunNo") <<
" Vx= " << records.
GetDouble(
"Vx") <<
" SigmaVx= " << records.
GetDouble(
"SigmaVx") << endl;
56 }
57
58
59 std::cout << "*************************************************************" << std::endl;
60 std::cout << "Test 2: BLOBs" << std::endl;
61 std::cout << "*************************************************************" << std::endl;
62
64 sprintf(stmt,"select EndTofPar,BarTofPar from TofCalConst where RunFrom <= 11000 and RunTo >= 11000 and SftVer='6.5.1'");
65 row_no = m_dbsvc->
query(
"offlinedb", stmt, res);
66 if(row_no<0){
67 std::cerr << "Query \"" << stmt << "\" failed" << std::endl;
68 return StatusCode::FAILURE;
69 }
70 for (row=0;row<row_no;row++)
71 {
73
74 TBufferFile *buf1 = new TBufferFile(TBuffer::kRead);
75 buf1->SetBuffer(records["EndTofPar"],32768,kFALSE);
76 TTree* curvetree = new TTree();
77 curvetree->Streamer(*buf1);
78 double cnvAtten[8];
84 int entries=curvetree->GetEntries();
85 if(entries>10) entries = 10;
86 for(int iiii=0; iiii<entries;iiii++)
87 {
88 curvetree->GetEntry(iiii);
89 for(int jjj=0;jjj<5;jjj++){
90 std::cout<<"cnvAtten["<<jjj<<"]="<<cnvAtten[jjj]<<" ";
91 }
92 std::cout<<std::endl;
93 }
94 }
95
96
97
98 std::cout << "*************************************************************" << std::endl;
99 std::cout << "Test 3: Strings" << std::endl;
100 std::cout << "*************************************************************" << std::endl;
101
103 sprintf(stmt,"select XtTree,QtTree,T0Tree,SdTree,RunFrom,RunTo,CalParVer,FileName from MdcCalConst where SftVer = '6.5.3'");
104 row_no = m_dbsvc->
query(
"offlinedb",stmt,res);
105 if(row_no<0){
106 std::cerr << "Query \"" << stmt << "\" failed" << std::endl;
107 return StatusCode::FAILURE;
108 }
109
110 for (row=0;row<row_no;row++){
112 cout << "Read from DB: Runs " << records["RunFrom"] << " " << records["RunTo"] << " FileName = " << records["FileName"] << endl;
113 }
114
115
116 return StatusCode::SUCCESS;
117}
data SetBranchAddress("time",&time)
double GetDouble(std::string key)
long GetLong(std::string key)
virtual int query(const std::string &dbName, const std::string &sql, DatabaseRecordVector &res)=0