BOSS 7.0.6
BESIII Offline Software System
Loading...
Searching...
No Matches
ConnectionProvider.cxx
Go to the documentation of this file.
1#include "GaudiKernel/MsgStream.h"
2#include "GaudiKernel/SvcFactory.h"
3#include "GaudiKernel/ISvcLocator.h"
4#include "GaudiKernel/SmartDataPtr.h"
5#include "GaudiKernel/Bootstrap.h"
6
8#include "GaudiKernel/MsgStream.h"
9#include "GaudiKernel/SvcFactory.h"
10#include "GaudiKernel/ISvcLocator.h"
11#include "GaudiKernel/Bootstrap.h"
13#include "facilities/Util.h"
14#include <iostream>
15#include <cstdio>
16#include <boost/lexical_cast.hpp>
17#include <cstdlib>
18
19using namespace std;
20
21namespace RealDBUtil {
22
23 #define _T(str) ("\'"+str+"\'")
24 typedef basic_string<char>::size_type S_T;
25 static const S_T npos = -1;
26
27 std::vector<std::string> ConnectionProvider::split(const std::string& src, std::string delimit, std::string null_subst)
28 {
29 if( src.empty() || delimit.empty() ) throw "split: empty string\0";
30 vector<string> v;
31 S_T deli_len = delimit.size();
32 long index = npos, last_search_position = 0;
33 while( (index=src.find(delimit, last_search_position))!=npos )
34 {
35 if(index==last_search_position)
36 v.push_back(null_subst);
37 else
38 v.push_back( src.substr(last_search_position, index-
39 last_search_position) );
40 last_search_position = index + deli_len;
41 }
42 string last_one = src.substr(last_search_position);
43 v.push_back( last_one.empty()? null_subst:last_one );
44 return v;
45 }
46
47 bool ConnectionProvider::getcal(int runNo, std::string ids){
48
49 //Read Luminosity information
50 char stmt1[1024];
51 int run_No =std::abs(runNo);
52 sprintf(stmt1,"select EQM_fileid,EMCGain from RunParams where run_number = %d",run_No);
53
55 results.clear();
56 int rowNumber = m_dbsvc->query("run",stmt1,results);
57 if(rowNumber <= 0){
58 std::cout << "ERROR Read EQM_fileid from the Database, exit." << endreq;
59 exit(1);
60 }
61
62 int fileid = std::atoi((*results[0])["EQM_fileid"]);
63
64 string gainnum((*results[0])["EMCGain"]);
65
66 sprintf(stmt1, "select OID,Position,Channel1,Channel2,Channel3,Channel4,Channel5,Channel6,Channel7,Channel8,Channel9,Channel10,Channel11,Channel12,Channel13,Channel14,Channel15,Channel16,Channel17,Channel18,Channel19,Channel20,Channel21,Channel22,Channel23,Channel24,Channel25,Channel26,Channel27,Channel28,Channel29,Channel30,Channel31,Channel32 from EQM where FileId=%d", fileid);
67
68 results.clear();
69 rowNumber = m_dbsvc->query("run",stmt1,results);
70 if(rowNumber <= 0){
71 std::cout << "ERROR Read EQM from the Database, exit." << endreq;
72 exit(1);
73 }
74
75 std::map<std::string, std::vector<std::string> > map_EQM;
76 map_EQM.clear();
77 for(int i=0;i<rowNumber;i++)
78 { for(int j=2;j<34;j++)
79 {
80 std::vector<std::string> vec_tmp;
81 vec_tmp.clear();
82 vec_tmp.push_back(toString<int>(j-1));
83 vec_tmp.push_back((*results[i])["OID"]);
84 vec_tmp.push_back((*results[i])["Position"]);
85 typedef pair<std::string, std::vector<std::string> > vpair;
86 map_EQM.insert(vpair((*results[i])["Channel"+toString<int>(j-1)], vec_tmp));
87
88 }
89 }
90
91 vector<string> id = split(ids, ",", "<null>");
92 id_num=id.size();
93
94 for(unsigned int m=0;m<id.size();m++){
95 if(id[m] == "0") { std::cout << " error: No." << m+1 << " id=0,please delete it! " << std::endl; break; }
96 if(id[m] == "NULL") { std::cout << " end of loop! " << std::endl; break; }
97 string channelnum,oid,modu;
98 bool if_found = false;
99 for(std::map<std::string,std::vector<std::string> >::iterator iter = map_EQM.begin(); iter != map_EQM.end(); iter++)
100 {
101 if(iter->first == id[m]) {
102 if_found = true;
103 channelnum = iter->second[0];
104 oid = iter->second[1];
105 modu = iter->second[2];
106 }
107 }
108
109 if(!if_found) { std::cout << "can not find id " << id[m] << " in EQM, exit." << std::endl; exit(1); }
110
111 string b="AAAA";
112 string trgcratenum;
113 for(int i=0;i<4;i++){
114 b[i] =oid[i+4];
115 }
116
117 //change oid to cratenum
118 string a[16][2]={{"E3_1","96"},{"E2_0","97"},{"E2_1","98"},{"E1_0","99"},{"E1_1","100"},{"E3_0","101"},{"E2_2","102"},{"E3_2","103"},{"W3_1","112"},{"W2_0","113"},{"W2_1","114"},{"W1_0","115"},{"W1_1","116"},{"W3_0","117"},{"W2_2","118"},{"W3_2","119"}};
119 string trgCrate[16]={"0x60","0x61","0x62","0x63","0x64","0x65","0x66","0x67","0x70","0x71","0x72","0x73","0x74","0x75","0x76","0x77"};
120
121 for(int i=0;i<16;i++){
122 if(b.compare(a[i][0])) continue;
123 else {
124 trgcratenum = trgCrate[i];
125 }
126 }
127
128 std::string query_name = "select gain from EMC_Gain where run_id="+gainnum+" and ppc_id=\""+trgcratenum+"\" and Qmodule_no="+modu+" and Qchannel_no="+channelnum;
129 results.clear();
130 rowNumber = m_dbsvc->query("run",query_name.c_str(),results);
131 if(rowNumber <= 0){
132 std::cout << "ERROR Read gain from EMC_Gain Database, exit." << endreq;
133 exit(1);
134 }
135
136 //std::cout << "run_id: " << gainnum << " ppc_id: " << trgcratenum << " Qmodule_no: " << modu << " Qchannel_no: " << channelnum << " m: " << m << std::endl;
137
138 trgGain[m] = new std::string((*results[0])["gain"]);
139 //std::cout << "gain: " << *trgGain[m] << std::endl;
140 }
141 return true;
142 }
143
145 StatusCode sc = Gaudi::svcLocator()->service("DatabaseSvc", m_dbsvc, true);
146 if (sc .isFailure() ) {
147 std::cout << "ERROR: In ConnectionProvider()--> Unable to find DatabaseSvc " << std::endl;
148 }
149 m_trgTpye = -1;
150 m_tfee_fileid = -1;
151 }
152
154 }
155
156ConnectionProvider::eRet ConnectionProvider::getReadLumInfo(std::string& Lum, int runNo, std::string SftVer, std::string ParVer, std::string BossRelease) {
157 //Read Luminosity information
158 char stmt1[200];
159 int run_No =std::abs(runNo);
160
161
162 if(SftVer == "default") {
163 if(BossRelease == "default") {
164 std::cout << "ERROR BossRelease must be set! Current value is " << BossRelease << "." << endreq;
165 exit(1);
166 }
167 else {
168 sprintf(stmt1, "select SftVer, ParVer from CalVtxLumVer where BossRelease = '%s' and RunFrom <= %d and RunTo >= %d and DataType = 'LumVtx'", BossRelease.c_str(), run_No, run_No);
169
170 DatabaseRecordVector records;
171 int rowNo = m_dbsvc->query("offlinedb",stmt1,records);
172 if(rowNo == 0) {
173 std::cout << "ERROR: can not find records for run = " << run_No << " and BossRelease = " << BossRelease << endreq;
174 exit(1);
175 }
176 DatabaseRecord* recordst = records[0];
177 SftVer = recordst->GetString("SftVer");
178 ParVer = recordst->GetString("ParVer");
179 std::cout << "Using the new SftVer and ParVer (" << SftVer << ", " << ParVer << ") for run " << run_No << ". " << endreq;
180 }
181 }
182
183
184 sprintf(stmt1,"select OfflineTwoGam,SftVer,ParVer from OfflineLum where RunNo = %d",run_No);
185/*
186 if(std::atoi(ParVer.c_str()) == 0) {
187 sprintf(stmt1,"select OfflineTwoGam,ParVer from OfflineLum where RunNo = %d && SftVer = \"%s\"",run_No,SftVer.c_str());
188 }
189 else {
190 sprintf(stmt1,"select OfflineTwoGam from OfflineLum where RunNo = %d && SftVer = \"%s\" && ParVer = \"%s\"",run_No,SftVer.c_str(),ParVer.c_str());
191 }
192*/
193 DatabaseRecordVector results;
194 results.clear();
195 int status = m_dbsvc->query("offlinedb",stmt1,results);
196 if(status<0){
197 std::cout << "ERROR Read the luminosity from the Database" << endreq;
198 exit(1);
199 }
200
201 int RowNumber = results.size();
202 if(RowNumber == 0){
203 std::cout<<"WARNING: No Luminosity Data in this run, return 0."<<std::endl;
204 Lum = "0";
205 return RETOk;
206 }
207
208 int ParVerID = 0;
209 int RecordNo = 0;
210 if(std::atoi(ParVer.c_str()) == 0) {
211 for(int i = 0; i < RowNumber; i++) {
212 if((std::atoi((*results[i])["ParVer"]) > ParVerID)&&((*results[i])["SftVer"]==SftVer)) { Lum = (*results[i])["OfflineTwoGam"]; ParVerID = std::atoi((*results[i])["ParVer"]); RecordNo++;}
213 }
214 }
215 else {
216 RecordNo = 0;
217 for(int i = 0; i < RowNumber; i++) {
218 if((std::atoi((*results[i])["ParVer"]) == std::atoi(ParVer.c_str()))&&((*results[i])["SftVer"]==SftVer)) { Lum = (*results[i])["OfflineTwoGam"]; ParVerID = std::atoi((*results[i])["ParVer"]); RecordNo++;}
219 }
220 }
221
222 if(RecordNo == 0) {
223 //std::cout<<"ERROR: No Luminosity infor. found by your selection criteria, please check it (SftVer, ParVer)"<<std::endl;
224 //std::abort();
225 std::cout<<"WARNING: No Luminosity infor. found by your selection criteria, please check it (<<SftVer, <<ParVer)"<<std::endl;
226 Lum = "0";
227 return RETOk;
228
229 }
230
231 if(RecordNo >= 2 && std::atoi(ParVer.c_str()) != 0) {
232 std::cout<<"ERROR: More than two Lum. records found by your selection criteria, please check it (SftVer, ParVer)"<<std::endl;
233 exit(1);
234 }
235
236 return RETOk;
237}
238
239 ConnectionProvider::eRet ConnectionProvider::getLumCurvePar(std::string& runTotalTime, std::string& tau_value, int runNo, std::string SftVer, std::string ParVer, std::string BossRelease) {
240 //Read Luminosity curve parameters
241 char stmt1[200];
242 int run_No =std::abs(runNo);
243
244 if(SftVer == "default") {
245 if(BossRelease == "default") {
246 std::cout << "ERROR BossRelease must be set! Current value is " << BossRelease << "." << endreq;
247 exit(1);
248 }
249 else {
250 sprintf(stmt1, "select SftVer, ParVer from CalVtxLumVer where BossRelease = '%s' and RunFrom <= %d and RunTo >= %d and DataType = 'LumVtx'", BossRelease.c_str(), run_No, run_No);
251
252 DatabaseRecordVector records;
253 int rowNo = m_dbsvc->query("offlinedb",stmt1,records);
254 if(rowNo == 0) {
255 std::cout << "ERROR: can not find records for run = " << run_No << " and BossRelease = " << BossRelease << endreq;
256 exit(1);
257 }
258 DatabaseRecord* recordst = records[0];
259 SftVer = recordst->GetString("SftVer");
260 ParVer = recordst->GetString("ParVer");
261 std::cout << "Using the new SftVer and ParVer (" << SftVer << ", " << ParVer << ") for run " << run_No << ". " << endreq;
262 }
263 }
264
265 sprintf(stmt1,"select runTime,Tau_Value,SftVer,ParVer from OfflineLum where RunNo = %d",run_No);
266
267 DatabaseRecordVector results;
268 results.clear();
269 int status = m_dbsvc->query("offlinedb",stmt1,results);
270 if(status<0){
271 std::cout << "ERROR Read the luminosity curve parameters from the Database" << endreq;
272 exit(1);
273 }
274
275 int RowNumber = results.size();
276 if(RowNumber == 0){
277 std::cout<<"ERROR: No Luminosity curve parameters in this run, aborted."<<std::endl;
278 exit(1);
279 }
280
281 int ParVerID = 0;
282 int RecordNo = 0;
283 if(std::atoi(ParVer.c_str()) == 0) {
284 for(int i = 0; i < RowNumber; i++) {
285 if((std::atoi((*results[i])["ParVer"]) > ParVerID)&&((*results[i])["SftVer"]==SftVer)) {
286 runTotalTime = (*results[i])["runTime"];
287 tau_value = (*results[i])["Tau_Value"];
288 ParVerID = std::atoi((*results[i])["ParVer"]);
289 RecordNo++;
290 }
291 }
292 }
293 else {
294 RecordNo = 0;
295 for(int i = 0; i < RowNumber; i++) {
296 if((std::atoi((*results[i])["ParVer"]) == std::atoi(ParVer.c_str()))&&((*results[i])["SftVer"]==SftVer)) {
297 runTotalTime = (*results[i])["runTime"];
298 tau_value = (*results[i])["Tau_Value"];
299 ParVerID = std::atoi((*results[i])["ParVer"]);
300 RecordNo++;
301 }
302 }
303 }
304 if(RecordNo == 0) {
305 std::cout<<"ERROR: No Luminosity curve parameters found by your selection criteria, please check it (SftVer, ParVer)"<<std::endl;
306 exit(1);
307 }
308
309 if(RecordNo >= 2 && std::atoi(ParVer.c_str()) != 0) {
310 std::cout<<"ERROR: More than two Lum. curve parameters records found by your selection criteria, please check it (SftVer, ParVer)"<<std::endl;
311 exit(1);
312 }
313
314 return RETOk;
315 }
316
317 ConnectionProvider::eRet ConnectionProvider::getReadBunchInfo(std::vector<std::string>& bunch, int runNo, std::string SftVer, std::string ParVer, std::string BossRelease) {
318 //Read bunch size information
319 char stmt1[200];
320 int run_No =std::abs(runNo);
321
322 if(SftVer == "default") {
323 if(BossRelease == "default") {
324 std::cout << "ERROR BossRelease must be set! Current value is " << BossRelease << "." << endreq;
325 exit(1);
326 }
327 else {
328 sprintf(stmt1, "select SftVer, ParVer from CalVtxLumVer where BossRelease = '%s' and RunFrom <= %d and RunTo >= %d and DataType = 'LumVtx'", BossRelease.c_str(), run_No, run_No);
329
330 DatabaseRecordVector records;
331 int rowNo = m_dbsvc->query("offlinedb",stmt1,records);
332 if(rowNo == 0) {
333 std::cout << "ERROR: can not find records for run = " << run_No << " and BossRelease = " << BossRelease << endreq;
334 exit(1);
335 }
336 DatabaseRecord* recordst = records[0];
337 SftVer = recordst->GetString("SftVer");
338 ParVer = recordst->GetString("ParVer");
339 std::cout << "Using the new SftVer and ParVer (" << SftVer << ", " << ParVer << ") for run " << run_No << ". " << endreq;
340 }
341 }
342
343 sprintf(stmt1,"select Vx,Vy,Vz,AcSigmaVx,AcSigmaVy,SigmaVz,SftVer,ParVer from BeamPar where runNo = %d",run_No);
344/*
345 if(std::atoi(ParVer.c_str()) == 0) {
346 sprintf(stmt1,"select Vx,Vy,Vz,AcSigmaVx,AcSigmaVy,SigmaVz,ParVer from BeamPar where runNo = %d && SftVer = \"%s\"",run_No,SftVer.c_str());
347 }
348 else {
349 sprintf(stmt1,"select Vx,Vy,Vz,AcSigmaVx,AcSigmaVy,SigmaVz from BeamPar where runNo = %d && SftVer = \"%s\" && ParVer = \"%s\"",run_No,SftVer.c_str(),ParVer.c_str());
350 }
351*/
352
353 DatabaseRecordVector results;
354 results.clear();
355 int status = m_dbsvc->query("offlinedb",stmt1,results);
356 if(status<0){
357 std::cout << "ERROR Read the bunch from the Database" << endreq;
358 exit(1);
359 }
360
361 int RowNumber = results.size();
362 if(RowNumber == 0){
363 std::cout<<"WARNING: No bunch Data in this run! Please check your selection criteria (runNo, SftVer, ParVer)"<<std::endl;
364 return RETNoSchemaMatch;
365 }
366
367 int ParVerID = 0;
368 int RecordNo = 0;
369 if(std::atoi(ParVer.c_str()) == 0) {
370 for(int i = 0; i < RowNumber; i++) {
371 if((std::atoi((*results[i])["ParVer"]) > ParVerID)&&((*results[i])["SftVer"]==SftVer)) {
372 bunch.clear();
373 bunch.push_back((*results[i])["Vx"]);
374 bunch.push_back((*results[i])["Vy"]);
375 bunch.push_back((*results[i])["Vz"]);
376 bunch.push_back((*results[i])["AcSigmaVx"]);
377 bunch.push_back((*results[i])["AcSigmaVy"]);
378 bunch.push_back((*results[i])["SigmaVz"]);
379 ParVerID = std::atoi((*results[i])["ParVer"]);
380 RecordNo++;
381 }
382 }
383 }
384 else {
385 RecordNo = 0;
386 for(int i = 0; i < RowNumber; i++) {
387 if((std::atoi((*results[i])["ParVer"]) == std::atoi(ParVer.c_str()))&&((*results[i])["SftVer"]==SftVer)) {
388 bunch.clear();
389 bunch.push_back((*results[i])["Vx"]);
390 bunch.push_back((*results[i])["Vy"]);
391 bunch.push_back((*results[i])["Vz"]);
392 bunch.push_back((*results[i])["AcSigmaVx"]);
393 bunch.push_back((*results[i])["AcSigmaVy"]);
394 bunch.push_back((*results[i])["SigmaVz"]);
395 RecordNo++;
396 }
397 }
398 }
399
400 if(RecordNo == 0) {
401 std::cout<<"WARNING: No bunch infor. found in this run, it will use other run's"<<std::endl;
402 return RETNoSchemaMatch;
403 }
404
405 if(RecordNo >= 2 && std::atoi(ParVer.c_str()) != 0) {
406 std::cout<<"ERROR: More than two bunch records found by your selection criteria, please check it (SftVer, ParVer)"<<std::endl;
407 exit(1);
408 }
409
410 return RETOk;
411 }
412
414 //Read trigger table used in trigger simulation
415 char stmt1[200];
416 int run_No =std::abs(runNo);
417
418 sprintf(stmt1,"select trgtable_id from RunParams where run_number = %d ",run_No);
419
420 DatabaseRecordVector results;
421 results.clear();
422 int status = m_dbsvc->query("run",stmt1,results);
423 if(status<0){
424 std::cout << "ERROR Read the trigger table from the Database" << endreq;
425 exit(1);
426 }
427
428 int RowNumber = results.size();
429 if(RowNumber!=1){
430 std::cout<<"ERROR:error searching Trigger Type Data in the database, check your selection criteria"<<std::endl;
431 return RETMySQLError;
432 }
433 int i_trgTpye = std::atoi((*results[0])["trgtable_id"]);
434 std::cout<<"Obj_id is "<<i_trgTpye<<std::endl;
435 results.clear();
436
437 if(i_trgTpye == m_trgTpye) {
438 std::cout<<"Don't need to update trigger table, it is same with the last run!"<<std::endl;
439 }
440 else {
441 m_trgTpye = i_trgTpye;
442 m_trgTable.clear();
443 //retrieve EventChannelEnableRegister from database
444 sprintf(stmt1,"select EventChannelEnableRegister from TrgTable where Obj_id = %d ", i_trgTpye);
445 int status1 = m_dbsvc->query("run",stmt1,results);
446 if(status1<0){
447 std::cout << "ERROR Read the trigger table from the Database 1" << endreq;
448 exit(1);
449 }
450 RowNumber = results.size();
451 if(RowNumber!=1){
452 std::cout<<"ERROR:error searching Trigger Type Data in the database, check your selection criterions"<<std::endl;
453 return RETMySQLError;
454 }
455 m_trgTable.push_back((*results[0])["EventChannelEnableRegister"]);
456 results.clear();
457
458 //retrieve TrgTable_Channel from database
459 for(int i = 1; i < 17; i++)
460 for(int j = 1; j < 5; j++) {
461 if(i < 10) sprintf(stmt1,"select TrgTable_CH0%d_%d from TrgTable where Obj_id = %d ", i, j, i_trgTpye);
462 else sprintf(stmt1,"select TrgTable_CH%d_%d from TrgTable where Obj_id = %d ", i, j, i_trgTpye);
463 int status2 = m_dbsvc->query("run",stmt1,results);
464 if(status2<0){
465 std::cout << "ERROR Read the trigger table from the Database 2" << endreq;
466 exit(1);
467 }
468 RowNumber = results.size();
469 if(RowNumber!=1){
470 std::cout<<"ERROR:error searching TrgTable Data in the database, check your selection criterions"<<std::endl;
471 return RETMySQLError;
472 }
473 if(i<10) sprintf(stmt1,"TrgTable_CH0%d_%d", i, j);
474 else sprintf(stmt1,"TrgTable_CH%d_%d", i, j);
475 m_trgTable.push_back((*results[0])[stmt1]);
476 results.clear();
477 }
478 }
479 trgTable = m_trgTable;
480
481 return RETOk;
482 }
483
485 // Get EmcCalibConstSvc.
486 IEmcCalibConstSvc *emcCalibConstSvc;
487 ISvcLocator* svcLocator = Gaudi::svcLocator();
488 StatusCode sc = svcLocator->service("EmcCalibConstSvc",emcCalibConstSvc);
489 if(sc!=StatusCode::SUCCESS) {
490 cout << "ConnectionProvider Error: Can't get EmcCalibConstSvc." << endl;
491 }
492
493 string ids="128005";
494
495 ostringstream str;
496 int idBegin=0;
497 int idEnd=6240;
498
499 for(int i=idBegin;i<idEnd;i++) {
500 unsigned int npart = emcCalibConstSvc->getPartID(i);
501 unsigned int ntheta = emcCalibConstSvc->getThetaIndex(i);
502 unsigned int nphi = emcCalibConstSvc->getPhiIndex(i);
503
504 int triPart,triTheta,triPhi;
505 if(npart==0) {
506 triPart=0;
507 triTheta=23+ntheta;
508 } else if(npart==1&&ntheta<22) {
509 triPart=0;
510 triTheta=22-ntheta;
511 } else if(npart==1&&ntheta>=22) {
512 triPart=1;
513 triTheta=ntheta-21;
514 } else { //npart==2
515 triPart=1;
516 triTheta=23+ntheta;
517 }
518 triPhi=nphi+1;
519
520 ostringstream ssTheta;
521 if(triPart==1&&triTheta<10) {
522 ssTheta<<"0"<<triTheta;
523 } else {
524 ssTheta<<triTheta;
525 }
526
527 ostringstream ssPhi;
528 if(triPhi<10) {
529 ssPhi<<"00"<<triPhi;
530 } else if(triPhi<100) {
531 ssPhi<<"0"<<triPhi;
532 } else {
533 ssPhi<<triPhi;
534 }
535
536 if(triPart==0) {
537 str<<ssTheta.str()<<ssPhi.str();
538 } else {
539 str<<triPart<<ssTheta.str()<<ssPhi.str();
540 }
541 if(i!=idEnd-1) {
542 str<<",";
543 }
544
545 //cout<<npart<<"\t"<<ntheta<<"\t"<<nphi<<endl;
546
547 }
548
549 ids=str.str();
550 //cout<<ids<<endl;
551
552 getcal( runNo, ids);
553
554 emcGain.clear();
555 for(int i=0;i<id_num;i++) {
556 istringstream isin(*trgGain[i]);
557 double value;
558 isin>>value;
559 value = ((50./255.)*(value)/60.)*5*0.5;
560 emcGain.push_back(value);
561 delete trgGain[i];
562 }
563
564 return RETOk;
565 }
566
567
569 //Read trigger configure information
570 char stmt1[1024];
571 int run_No =std::abs(runNo);
572
573 sprintf(stmt1,"select Trg_fileid from RunParams where run_number = %d ",run_No);
574
575 DatabaseRecordVector results;
576 results.clear();
577 int rowNumber = m_dbsvc->query("run",stmt1,results);
578 if( rowNumber <= 0){
579 std::cout << "ERROR: Read the Trg_fileid from RunParams, exit." << endl;
580 exit(1);
581 }
582
583 if(rowNumber > 1){
584 std::cout<<"WARNNING: there are more than one record for Trg_fileid in run " << runNo << ", the first one will be selected."<<std::endl;
585 }
586 int trg_fileid = std::atoi((*results[0])["Trg_fileid"]);
587
588 sprintf(stmt1,"select EtotDataSteps,VthBEtotH,VthEEtotH,VthEtotL,VthEtotM,VthBLZ,VthDiffB,VthDiffE,VthBalBLK,VthBalEEMC,VthDiffMin from Trg_EACC where FileId = %d ", trg_fileid);
589
590 results.clear();
591 rowNumber = m_dbsvc->query("run",stmt1,results);
592 if( rowNumber <= 0){
593 std::cout << "ERROR: Read the EACC config infor. from Trg_EACC, exit." << endl;
594 exit(1);
595 }
596
597 if(rowNumber > 1){
598 std::cout<<"WARNNING: there are more than one record for EACC in run " << runNo << ", the first one will be selected."<<std::endl;
599 }
600
601 m_EtotDataSteps = std::atoi((*results[0])["EtotDataSteps"]);
602 m_VthBEtotH = std::atoi((*results[0])["VthBEtotH"]);
603 m_VthEEtotH = std::atoi((*results[0])["VthEEtotH"]);
604 m_VthEtotL = std::atoi((*results[0])["VthEtotL"]);
605 m_VthEtotM = std::atoi((*results[0])["VthEtotM"]);
606 m_VthBLZ = std::atoi((*results[0])["VthBLZ"]);
607 m_VthDiffB = std::atoi((*results[0])["VthDiffB"]);
608 m_VthDiffE = std::atoi((*results[0])["VthDiffE"]);
609 m_VthBalBLK = std::atoi((*results[0])["VthBalBLK"]);
610 m_VthBalEEMC = std::atoi((*results[0])["VthBalEEMC"]);
611 m_VthDiffMin = std::atoi((*results[0])["VthDiffMin"]);
612
613 return RETOk;
614 }
615
616
617 //ConnectionProvider::eRet ConnectionProvider::getReadBackgroundInfo(std::vector<std::string>& fileInfor, std::vector<int>& vRanTrgEvtNum, int runNo) {
619 //Read background file
620 char stmt1[200];
621 int run_No =std::abs(runNo);
622
623 //sprintf(stmt1,"select FilePath,FileName,NumEvent from RanTrgData where RunNo = %d ",run_No);
624 sprintf(stmt1,"select FilePath,FileName from RanTrgData where RunNo = %d ",run_No);
625
626 DatabaseRecordVector results;
627 results.clear();
628 int status = m_dbsvc->query("offlinedb",stmt1,results);
629 if(status<0){
630 std::cout << "ERROR Read the background file from the Database" << endreq;
631 exit(1);
632 }
633
634 int RowNumber = results.size();
635 if(RowNumber == 0){
636 std::cout<<"WARNING: No Bg infor. in this run!"<<std::endl;
637 return RETNoSchemaMatch;
638 }
639 //vRanTrgEvtNum.clear();
640 fileInfor.clear();
641 for(int i = 0; i < RowNumber; i++) {
642 //int RanTrgEvtNum = 0;
643 //RanTrgEvtNum = std::atoi((*results[i])["NumEvent"]);
644 //if(RanTrgEvtNum != 0) vRanTrgEvtNum.push_back(RanTrgEvtNum);
645 //if(RanTrgEvtNum != 0) {
646 fileInfor.push_back((*results[i])["FilePath"]);
647 fileInfor.push_back((*results[i])["FileName"]);
648 //}
649 }
650
651 if(fileInfor.size() == 0) {
652 std::cout<<"WARNING: the total bg event number in run " << runNo << " is zero, it will use other run's bg" << std::endl;
653 return RETNoSchemaMatch;
654 }
655
656 return RETOk;
657 }
658
659 //ConnectionProvider::eRet ConnectionProvider::getReadBackgroundInfo( std::vector<std::string>& fileInfor, std::vector<int>& vRanTrgEvtNum, std::string stmt1) {
660 ConnectionProvider::eRet ConnectionProvider::getReadBackgroundInfo( std::vector<std::string>& fileInfor, std::string stmt1) {
661 //Read background file
662 //char stmt1[200];
663 //int run_No =runNo;
664
665 //sprintf(stmt1,"select FilePath,FileName from RanTrgData where RunNo = %d ",run_No);
666
667 DatabaseRecordVector results;
668 results.clear();
669 int status = m_dbsvc->query("offlinedb",stmt1,results);
670 if(status<0){
671 std::cout << "ERROR Read the background file from the Database" << endreq;
672 exit(1);
673 }
674 int RowNumber = results.size();
675 if(RowNumber == 0){
676 std::cout<<"ERROR:error searching background Data in the database, check your selection criterions"<<std::endl;
677 return RETMySQLError;
678 }
679 //vRanTrgEvtNum.clear();
680 fileInfor.clear();
681 for(int i = 0; i < RowNumber; i++) {
682 //int RanTrgEvtNum = 0;
683 //RanTrgEvtNum = std::atoi((*results[i])["NumEvent"]);
684 //if(RanTrgEvtNum != 0) vRanTrgEvtNum.push_back(RanTrgEvtNum);
685 //if(RanTrgEvtNum != 0) {
686 fileInfor.push_back((*results[i])["FilePath"]);
687 fileInfor.push_back((*results[i])["FileName"]);
688 //}
689 }
690
691 if(fileInfor.size() == 0) {
692 std::cout<<"WARNING: the total bg event number in your selected bg files is zero, it will abort after error message" << std::endl;
693 return RETNoSchemaMatch;
694 }
695
696 return RETOk;
697 }
698
700 //Read tof FEE threshold
701 char stmt1[200];
702 int run_No =std::abs(runNo);
703
704 sprintf(stmt1,"select TFEE_fileid from RunParams where run_number = %d ",run_No);
705
706 DatabaseRecordVector results;
707 results.clear();
708 int status = m_dbsvc->query("run",stmt1,results);
709 if(status<0){
710 std::cout << "ERROR Read the Tof threshold from the Database" << endreq;
711 exit(1);
712 }
713 int RowNumber = results.size();
714 if(RowNumber!=1){
715 std::cout<<"ERROR:error searching TFEE_fileid Data in the database, check your selection criterions"<<std::endl;
716 return RETMySQLError;
717 }
718 int i_tfee_fileid = std::atoi((*results[0])["TFEE_fileid"]);
719 std::cout<<"TFEE file id is "<<i_tfee_fileid<<std::endl;
720 results.clear();
721
722 if(i_tfee_fileid == m_tfee_fileid) {
723 std::cout<<"Don't need to update TOF FEE threshold, it is same with the last run!"<<std::endl;
724 }
725 else {
726 m_tfee_fileid = i_tfee_fileid;
727 m_tofThresh.clear();
728
729 sprintf(stmt1,"select PhysAddress,BarrelEnd,HighThreshold,LowThreshold from TFEE where FileId = %d ",i_tfee_fileid);
730 int status1 = m_dbsvc->query("run",stmt1,results);
731 if(status1<0){
732 std::cout << "ERROR Read the Tof threshold from the Database 1" << endreq;
733 exit(1);
734 }
735 int RowNumber = results.size();
736 if(RowNumber == 0){
737 std::cout<<"WARNING: No TFEE infor. in this run!"<<std::endl;
738 return RETNoSchemaMatch;
739 }
740 for(int i = 0; i < RowNumber; i++) {
741 m_tofThresh.push_back((*results[i])["PhysAddress"]);
742 m_tofThresh.push_back((*results[i])["BarrelEnd"]);
743 m_tofThresh.push_back((*results[i])["HighThreshold"]);
744 m_tofThresh.push_back((*results[i])["LowThreshold"]);
745 }
746 results.clear();
747 }
748
749 tofThresh = m_tofThresh;
750
751 return RETOk;
752 }
753
754 ConnectionProvider::eRet ConnectionProvider::getRunInfo(std::vector<std::string>& runInfo, int runNo) {
755 //Read run information
756 char stmt1[500];
757 int run_No =std::abs(runNo);
758
759 sprintf(stmt1,"select R_TM_BPR_PatNum,R_TM_BER_PatNum,S_R3O_BI_DCCT_current,E_R3O_BI_DCCT_current,AV_R3O_BI_DCCT_current,S_R4O_BI_DCCT_current,E_R4O_BI_DCCT_current,AV_R4O_BI_DCCT_current,S_BPR_LIFE,E_BPR_LIFE,AV_BPR_LIFE,S_BER_LIFE,E_BER_LIFE,AV_BER_LIFE from RunParams where run_number = %d ",run_No);
760
761 DatabaseRecordVector results;
762 results.clear();
763 int status = m_dbsvc->query("run",stmt1,results);
764 if(status<0){
765 std::cout << "ERROR Read the run information from the Database" << endreq;
766 exit(1);
767 }
768 int RowNumber = results.size();
769 if(RowNumber == 0){
770 std::cout<<"WARNING: No run information in this run!"<<std::endl;
771 return RETNoSchemaMatch;
772 }
773
774 for(int i = 0; i < RowNumber; i++) {
775 for(std::map<std::string,char*>::iterator iter = (*results[i]).begin(); iter != (*results[i]).end(); iter++) {
776 runInfo.push_back(iter->second);
777 }
778 }
779
780 return RETOk;
781 }
782
783}
char * SftVer
Definition: DQA_TO_DB.cxx:18
int runNo
Definition: DQA_TO_DB.cxx:12
char * ParVer
Definition: DQA_TO_DB.cxx:19
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
**********Class see also m_nmax DOUBLE PRECISION m_amel DOUBLE PRECISION m_x2 DOUBLE PRECISION m_alfinv DOUBLE PRECISION m_Xenph INTEGER m_KeyWtm INTEGER m_idyfs DOUBLE PRECISION m_zini DOUBLE PRECISION m_q2 DOUBLE PRECISION m_Wt_KF DOUBLE PRECISION m_WtCut INTEGER m_KFfin *COMMON c_KarLud $ !Input CMS energy[GeV] $ !CMS energy after beam spread beam strahlung[GeV] $ !Beam energy spread[GeV] $ !z boost due to beam spread $ !electron beam mass *ff pair spectrum $ !minimum v
Definition: KarLud.h:35
std::string GetString(std::string key)
virtual int query(const std::string &dbName, const std::string &sql, DatabaseRecordVector &res)=0
virtual unsigned int getPartID(int Index) const =0
virtual unsigned int getPhiIndex(int Index) const =0
virtual unsigned int getThetaIndex(int Index) const =0
ConnectionProvider::eRet getRunInfo(std::vector< std::string > &runInfo, int runNo)
std::vector< std::string > split(const std::string &src, std::string delimit, std::string null_subst="")
ConnectionProvider()
Constructor keeps track of table of interest.
ConnectionProvider::eRet getReadBunchInfo(std::vector< std::string > &bunch, int runNo, std::string SftVer, std::string ParVer, std::string BossRelease)
ConnectionProvider::eRet getLumCurvePar(std::string &runTotalTime, std::string &tau_value, int runNo, std::string SftVer, std::string ParVer, std::string BossRelease)
ConnectionProvider::eRet getTrgConfigInfo(int runNo)
ConnectionProvider::eRet getReadLumInfo(std::string &Lum, int runNo, std::string SftVer, std::string ParVer, std::string BossRelease)
ConnectionProvider::eRet getEmcGain(std::vector< double > &emcGain, int runNo)
ConnectionProvider::eRet getReadTrgTableInfo(std::vector< std::string > &trgTable, int runNo)
bool getcal(int runNo, std::string ids)
ConnectionProvider::eRet getReadBackgroundInfo(std::vector< std::string > &fileInfor, int runNo)
ConnectionProvider::eRet getReadTofThreshInfo(std::vector< std::string > &tofThresh, int runNo)
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)
basic_string< char >::size_type S_T
const double b
Definition: slope.cxx:9