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