BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
TestDbAlg.cxx
Go to the documentation of this file.
1#include "GaudiKernel/MsgStream.h"
2#include "GaudiKernel/SmartDataPtr.h"
3
4#include "Database/DatabaseRecord.h"
5#include "Database/TestDbAlg.h"
6#include "DatabaseSvc/IDatabaseSvc.h"
7
8#include "TBufferFile.h"
9#include "TTree.h"
10#include <iostream>
11
12using namespace std;
13
14/////////////////////////////////////////////////////////////////////////////
15
16TestDbAlg::TestDbAlg( const std::string& name, ISvcLocator* pSvcLocator )
17 : Algorithm( name, pSvcLocator ) {}
18
19// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
20
22 MsgStream log( msgSvc(), name() );
23
24 IDatabaseSvc* m_dbsvc;
25 StatusCode sc = serviceLocator()->service( "DatabaseSvc", m_dbsvc, true );
26 if ( sc.isFailure() )
27 {
28 log << MSG::ERROR << "Unable to find DatabaseSvc " << endmsg;
29 return sc;
30 }
31
32 std::cout << "*************************************************************" << std::endl;
33 std::cout << "Test 1: Numbers" << std::endl;
34 std::cout << "*************************************************************" << std::endl;
35
36 char stmt[255];
37 sprintf( stmt, "select Vx, Vy, Vz, SigmaVx, SigmaVy, SigmaVz,RunNo from BeamPar where RunNo "
38 "> 9950 and RunNo < 9980 and SftVer='6.5.1'" );
39
41 int row_no;
42 row_no = m_dbsvc->query( "offlinedb", stmt, res );
43 if ( row_no < 0 )
44 {
45 std::cerr << "Query \"" << stmt << "\" failed" << std::endl;
46 return StatusCode::FAILURE;
47 }
48
49 int row;
50 double vx, svx;
51 vx = 0;
52 svx = 0;
53
54 for ( row = 0; row < row_no; row++ )
55 {
56 DatabaseRecord& records = *res[row];
57 sscanf( records["Vx"], "%lf", &vx );
58 sscanf( records["SigmaVx"], "%lf", &svx );
59 cout << "Read from DB: RunNo " << records["RunNo"] << " Vx= " << vx << " SigmaVx= " << svx
60 << endl;
61 cout << " " << records.GetLong( "RunNo" )
62 << " Vx= " << records.GetDouble( "Vx" )
63 << " SigmaVx= " << records.GetDouble( "SigmaVx" ) << endl;
64 }
65
66 // Check BLOBs
67 std::cout << "*************************************************************" << std::endl;
68 std::cout << "Test 2: BLOBs" << std::endl;
69 std::cout << "*************************************************************" << std::endl;
70
71 res.clear();
72 sprintf( stmt, "select EndTofPar,BarTofPar from TofCalConst where RunFrom <= 11000 and "
73 "RunTo >= 11000 and SftVer='6.5.1'" );
74 row_no = m_dbsvc->query( "offlinedb", stmt, res );
75 if ( row_no < 0 )
76 {
77 std::cerr << "Query \"" << stmt << "\" failed" << std::endl;
78 return StatusCode::FAILURE;
79 }
80 for ( row = 0; row < row_no; row++ )
81 {
82 DatabaseRecord& records = *res[row];
83 // TBuffer *buf1 = new TBuffer(TBuffer::kRead);
84 TBufferFile* buf1 = new TBufferFile( TBuffer::kRead );
85 buf1->SetBuffer( records["EndTofPar"], 32768, kFALSE );
86 TTree* curvetree = new TTree();
87 curvetree->Streamer( *buf1 );
88 double cnvAtten[8];
89 curvetree->SetBranchAddress( "Atten0", &cnvAtten[0] );
90 curvetree->SetBranchAddress( "Atten1", &cnvAtten[1] );
91 curvetree->SetBranchAddress( "Atten2", &cnvAtten[2] );
92 curvetree->SetBranchAddress( "Atten3", &cnvAtten[3] );
93 curvetree->SetBranchAddress( "Atten4", &cnvAtten[4] );
94 int entries = curvetree->GetEntries();
95 if ( entries > 10 ) entries = 10;
96 for ( int iiii = 0; iiii < entries; iiii++ )
97 {
98 curvetree->GetEntry( iiii );
99 for ( int jjj = 0; jjj < 5; jjj++ )
100 { std::cout << "cnvAtten[" << jjj << "]=" << cnvAtten[jjj] << " "; }
101 std::cout << std::endl;
102 }
103 }
104
105 // sleep(600);
106 // Test strings
107 std::cout << "*************************************************************" << std::endl;
108 std::cout << "Test 3: Strings" << std::endl;
109 std::cout << "*************************************************************" << std::endl;
110
111 res.clear();
112 sprintf( stmt, "select XtTree,QtTree,T0Tree,SdTree,RunFrom,RunTo,CalParVer,FileName from "
113 "MdcCalConst where SftVer = '6.5.3'" );
114 row_no = m_dbsvc->query( "offlinedb", stmt, res );
115 if ( row_no < 0 )
116 {
117 std::cerr << "Query \"" << stmt << "\" failed" << std::endl;
118 return StatusCode::FAILURE;
119 }
120
121 for ( row = 0; row < row_no; row++ )
122 {
123 DatabaseRecord& records = *res[row];
124 cout << "Read from DB: Runs " << records["RunFrom"] << " " << records["RunTo"]
125 << " FileName = " << records["FileName"] << endl;
126 }
127
128 return StatusCode::SUCCESS;
129}
130
131// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
132StatusCode TestDbAlg::execute() {
133 MsgStream log( msgSvc(), name() );
134
135 log << "TestDbAlg execute()" << endl;
136
137 return StatusCode::SUCCESS;
138}
139
140// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
141
142StatusCode TestDbAlg::finalize() { return StatusCode::SUCCESS; }
sprintf(cut, "kal_costheta0_em>-0.93&&kal_costheta0_em<0.93&&kal_pxy0_em>=0.05+%d*0.1&&kal_" "pxy0_em<0.15+%d*0.1&&NGch>=2", j, j)
IMessageSvc * msgSvc()
virtual int query(const std::string &dbName, const std::string &sql, DatabaseRecordVector &res)=0
StatusCode execute()
TestDbAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition TestDbAlg.cxx:16
StatusCode initialize()
Definition TestDbAlg.cxx:21
StatusCode finalize()