BOSS 6.6.4.p03
BESIII Offline Software System
Loading...
Searching...
No Matches
TestDbAlg Class Reference

#include <TestDbAlg.h>

+ Inheritance diagram for TestDbAlg:

Public Member Functions

 TestDbAlg (const std::string &name, ISvcLocator *pSvcLocator)
 
StatusCode initialize ()
 
StatusCode execute ()
 
StatusCode finalize ()
 

Detailed Description

Definition at line 3 of file TestDbAlg.h.

Constructor & Destructor Documentation

◆ TestDbAlg()

TestDbAlg::TestDbAlg ( const std::string &  name,
ISvcLocator *  pSvcLocator 
)

Definition at line 15 of file TestDbAlg.cxx.

15 : Algorithm(name, pSvcLocator){
16}

Member Function Documentation

◆ execute()

StatusCode TestDbAlg::execute ( )

Definition at line 120 of file TestDbAlg.cxx.

120 {
121 MsgStream log(msgSvc(), name());
122
123 log << "TestDbAlg execute()" << endl;
124
125 return StatusCode::SUCCESS;
126}
IMessageSvc * msgSvc()

◆ finalize()

StatusCode TestDbAlg::finalize ( )

Definition at line 130 of file TestDbAlg.cxx.

130 {
131 return StatusCode::SUCCESS;
132}

◆ initialize()

StatusCode TestDbAlg::initialize ( )

Definition at line 20 of file TestDbAlg.cxx.

20 {
21 MsgStream log(messageService(), name());
22
23 IDatabaseSvc* m_dbsvc;
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++){
51 DatabaseRecord& records = *res[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 // Check BLOBs
59 std::cout << "*************************************************************" << std::endl;
60 std::cout << "Test 2: BLOBs" << std::endl;
61 std::cout << "*************************************************************" << std::endl;
62
63 res.clear();
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 {
72 DatabaseRecord& records = *res[row];
73 // TBuffer *buf1 = new TBuffer(TBuffer::kRead);
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];
79 curvetree -> SetBranchAddress("Atten0", &cnvAtten[0]);
80 curvetree -> SetBranchAddress("Atten1", &cnvAtten[1]);
81 curvetree -> SetBranchAddress("Atten2", &cnvAtten[2]);
82 curvetree -> SetBranchAddress("Atten3", &cnvAtten[3]);
83 curvetree -> SetBranchAddress("Atten4", &cnvAtten[4]);
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 //sleep(600);
97 // Test strings
98 std::cout << "*************************************************************" << std::endl;
99 std::cout << "Test 3: Strings" << std::endl;
100 std::cout << "*************************************************************" << std::endl;
101
102 res.clear();
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++){
111 DatabaseRecord& records = *res[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

The documentation for this class was generated from the following files: