115 coral::ConnectionService*
svc=
new coral::ConnectionService;
121 coral::ISessionProxy* trgsession=svc->connect(
m_source, coral::ReadOnly);
122 coral::ITypeConverter& tpc=trgsession->typeConverter();
123 tpc.setCppTypeForSqlType(
"unsigned int",
"NUMBER(7)");
124 tpc.setCppTypeForSqlType(
"unsigned int",
"NUMBER(10)");
125 tpc.setCppTypeForSqlType(
"unsigned long long",
"NUMBER(20)");
129 std::string deadviewname(
"V_SCALERS_TCS_DEADTIME");
135 std::string runprescalgoviewname(
"GT_RUN_PRESC_ALGO_VIEW");
136 std::string runpresctechviewname(
"GT_RUN_PRESC_TECH_VIEW");
154 deadfracresult.reserve(500);
156 deadtimeresult.reserve(500);
157 coral::ITransaction&
transaction=trgsession->transaction();
158 transaction.start(
true);
163 coral::ISchema& gtmonschemaHandle=trgsession->schema(gtmonschema);
164 if(!gtmonschemaHandle.existsView(algoviewname)){
167 if(!gtmonschemaHandle.existsView(techviewname)){
170 if(!gtmonschemaHandle.existsView(deadviewname)){
179 coral::AttributeList bindVariableList;
180 bindVariableList.extend(
"runnumber",
typeid(
unsigned int));
181 bindVariableList[
"runnumber"].data<
unsigned int>()=
runnumber;
183 coral::IQuery* Queryalgoview=gtmonschemaHandle.newQuery();
184 Queryalgoview->addToTableList(algoviewname);
185 coral::AttributeList qalgoOutput;
186 qalgoOutput.extend(
"COUNT_BX",
typeid(
unsigned int));
187 qalgoOutput.extend(
"LUMI_SECTION",
typeid(
unsigned int));
188 qalgoOutput.extend(
"SCALER_INDEX",
typeid(
unsigned int));
189 Queryalgoview->addToOutputList(
"COUNT_BX");
190 Queryalgoview->addToOutputList(
"LUMI_SECTION");
191 Queryalgoview->addToOutputList(
"SCALER_INDEX");
192 Queryalgoview->setCondition(
"RUN_NUMBER=:runnumber",bindVariableList);
193 Queryalgoview->addToOrderList(
"LUMI_SECTION");
194 Queryalgoview->addToOrderList(
"SCALER_INDEX");
195 Queryalgoview->defineOutput(qalgoOutput);
196 coral::ICursor&
c=Queryalgoview->execute();
200 const coral::AttributeList& row = c.currentRow();
202 unsigned int lsnr=row[
"LUMI_SECTION"].data<
unsigned int>();
203 unsigned int count=row[
"COUNT_BX"].data<
unsigned int>();
204 unsigned int algobit=row[
"SCALER_INDEX"].data<
unsigned int>();
205 mybitcount_algo.push_back(count);
209 std::cout<<
"ALGO COUNT alert: found hole in LS range "<<s<<std::endl;
210 std::cout<<
" fill all algocount 0 for LS "<<s<<std::endl;
212 algocount.push_back(tmpzero);
215 algocount.push_back(mybitcount_algo);
216 mybitcount_algo.clear();
221 delete Queryalgoview;
222 transaction.commit();
225 delete Queryalgoview;
232 coral::IQuery* Querytechview=gtmonschemaHandle.newQuery();
233 Querytechview->addToTableList(techviewname);
234 coral::AttributeList qtechOutput;
235 qtechOutput.extend(
"COUNT_BX",
typeid(
unsigned int));
236 qtechOutput.extend(
"LUMI_SECTION",
typeid(
unsigned int));
237 qtechOutput.extend(
"SCALER_INDEX",
typeid(
unsigned int));
238 Querytechview->addToOutputList(
"COUNT_BX");
239 Querytechview->addToOutputList(
"LUMI_SECTION");
240 Querytechview->addToOutputList(
"SCALER_INDEX");
241 Querytechview->setCondition(
"RUN_NUMBER=:runnumber",bindVariableList);
242 Querytechview->addToOrderList(
"LUMI_SECTION");
243 Querytechview->addToOrderList(
"SCALER_INDEX");
244 Querytechview->defineOutput(qtechOutput);
245 coral::ICursor& techcursor=Querytechview->execute();
247 while( techcursor.next() ){
248 const coral::AttributeList& row = techcursor.currentRow();
250 unsigned int lsnr=row[
"LUMI_SECTION"].data<
unsigned int>();
251 unsigned int count=row[
"COUNT_BX"].data<
unsigned int>();
252 unsigned int techbit=row[
"SCALER_INDEX"].data<
unsigned int>();
253 mybitcount_tech.push_back(count);
257 std::cout<<
"TECH COUNT alert: found hole in LS range "<<s<<std::endl;
258 std::cout<<
" fill all techcount with 0 for LS "<<s<<std::endl;
260 techcount.push_back(tmpzero);
263 techcount.push_back(mybitcount_tech);
264 mybitcount_tech.clear();
269 delete Querytechview;
270 transaction.commit();
273 delete Querytechview;
280 coral::IQuery* Querydeadview=gtmonschemaHandle.newQuery();
281 Querydeadview->addToTableList(deadviewname);
282 coral::AttributeList qdeadOutput;
283 qdeadOutput.extend(
"FRACTION",
typeid(
float));
284 qdeadOutput.extend(
"LUMI_SECTION",
typeid(
unsigned int));
285 qdeadOutput.extend(
"COUNT_BX",
typeid(
unsigned int));
286 Querydeadview->addToOutputList(
"FRACTION");
287 Querydeadview->addToOutputList(
"LUMI_SECTION");
288 Querydeadview->addToOutputList(
"COUNT_BX");
289 coral::AttributeList bindVariablesDead;
290 bindVariablesDead.extend(
"runnumber",
typeid(
int));
291 bindVariablesDead.extend(
"scalername",
typeid(
std::string));
292 bindVariablesDead[
"runnumber"].data<
int>()=
runnumber;
294 Querydeadview->setCondition(
"RUN_NUMBER=:runnumber AND SCALER_NAME=:scalername",bindVariablesDead);
295 Querydeadview->addToOrderList(
"LUMI_SECTION");
296 Querydeadview->defineOutput(qdeadOutput);
297 coral::ICursor& deadcursor=Querydeadview->execute();
299 while( deadcursor.next() ){
300 const coral::AttributeList& row = deadcursor.currentRow();
303 unsigned int lsnr=row[
"LUMI_SECTION"].data<
unsigned int>();
305 unsigned int count=0;
307 std::cout<<
"DEADTIME alert: found hole in LS range"<<s<<std::endl;
308 std::cout<<
" fill deadtimefraction 0%, deadtimebeamactive 0 for LS "<<s<<std::endl;
309 deadfracresult.push_back(dfrac);
310 deadtimeresult.push_back(count);
313 if(!row[
"FRACTION"].isNull()){
314 dfrac=row[
"FRACTION"].data<
float>();
316 std::cout<<
"DEADTIME fraction alert: undefined fraction , assume 100% , LS "<<lsnr<<std::endl;
319 std::cout<<
"DEADTIME fraction alert: overflow dead fraction , force to 100% , LS "<<lsnr<<std::endl;
322 deadfracresult.push_back(dfrac);
323 count=row[
"COUNT_BX"].data<
unsigned int>();
324 deadtimeresult.push_back(count);
328 delete Querydeadview;
329 transaction.commit();
333 delete Querydeadview;
338 std::vector< int > prescidx;
339 coral::IQuery* allpsidxQuery=gtmonschemaHandle.newQuery();
340 allpsidxQuery->addToTableList(lstablename);
341 coral::AttributeList allpsidxOutput;
342 allpsidxOutput.extend(
"psidx",
typeid(
int));
343 allpsidxQuery->addToOutputList(
"distinct(PRESCALE_INDEX)",
"psidx");
344 coral::AttributeList bindVariablesAllpsidx;
345 bindVariablesAllpsidx.extend(
"runnumber",
typeid(
int));
346 bindVariablesAllpsidx[
"runnumber"].data<
int>()=
runnumber;
347 allpsidxQuery->setCondition(
"RUN_NUMBER =:runnumber",bindVariablesAllpsidx);
348 allpsidxQuery->defineOutput(allpsidxOutput);
349 coral::ICursor& allpsidxCursor=allpsidxQuery->execute();
350 while( allpsidxCursor.next() ){
351 const coral::AttributeList& row = allpsidxCursor.currentRow();
352 int psidx=row[
"psidx"].data<
int>();
353 prescidx.push_back(psidx);
355 delete allpsidxQuery;
356 std::map< int, std::vector<unsigned int> > algoprescMap;
357 std::map< int, std::vector<unsigned int> > techprescMap;
358 std::vector< int >::iterator prescidxIt;
359 std::vector< int >::iterator prescidxItBeg=prescidx.begin();
360 std::vector< int >::iterator prescidxItEnd=prescidx.end();
361 for(prescidxIt=prescidxItBeg;prescidxIt!=prescidxItEnd;++prescidxIt){
364 algoprescMap.insert(std::make_pair(*prescidxIt,algopres));
365 techprescMap.insert(std::make_pair(*prescidxIt,techpres));
371 std::map< unsigned int, int > lsprescmap;
372 coral::IQuery* lstoprescQuery=gtmonschemaHandle.newQuery();
373 lstoprescQuery->addToTableList(lstablename);
374 coral::AttributeList lstoprescOutput;
375 lstoprescOutput.extend(
"lumisection",
typeid(
unsigned int));
376 lstoprescOutput.extend(
"psidx",
typeid(
int));
377 lstoprescQuery->addToOutputList(
"LUMI_SECTION",
"lumisection");
378 lstoprescQuery->addToOutputList(
"PRESCALE_INDEX",
"psidx");
379 coral::AttributeList bindVariablesLstopresc;
380 bindVariablesLstopresc.extend(
"runnumber",
typeid(
int));
381 bindVariablesLstopresc[
"runnumber"].data<
int>()=
runnumber;
382 lstoprescQuery->setCondition(
"RUN_NUMBER =:runnumber",bindVariablesLstopresc);
383 lstoprescQuery->defineOutput(lstoprescOutput);
384 unsigned int lsprescount=0;
385 unsigned int lastpresc=0;
386 coral::ICursor& lstoprescCursor=lstoprescQuery->execute();
387 while( lstoprescCursor.next() ){
389 const coral::AttributeList& row = lstoprescCursor.currentRow();
390 unsigned int lumisection=row[
"lumisection"].data<
unsigned int>();
391 while(lsprescount!=lumisection){
392 std::cout<<
"PRESCALE_INDEX COUNT alert: found hole in LS range "<<lsprescount<<std::endl;
393 std::cout<<
" fill this prescale from last availabl prescale "<<lastpresc<<std::endl;
394 unsigned int guesspsidx=lastpresc;
395 lsprescmap.insert(std::make_pair(lsprescount,guesspsidx));
398 int psidx=row[
"psidx"].data<
int>();
399 lsprescmap.insert(std::make_pair(lumisection,psidx));
403 lstoprescCursor.close();
404 delete lstoprescQuery ;
405 transaction.commit();
408 delete lstoprescQuery ;
410 for(prescidxIt=prescidxItBeg;prescidxIt!=prescidxItEnd;++prescidxIt){
413 algoprescMap.insert(std::make_pair(*prescidxIt,algopres));
414 techprescMap.insert(std::make_pair(*prescidxIt,techpres));
422 coral::ISchema& gtschemaHandle=trgsession->schema(gtschema);
423 if(!gtschemaHandle.existsView(runtechviewname)){
426 if(!gtschemaHandle.existsView(runalgoviewname)){
429 if(!gtschemaHandle.existsView(runprescalgoviewname)){
432 if(!gtschemaHandle.existsView(runpresctechviewname)){
438 std::map<unsigned int,std::string> triggernamemap;
439 coral::IQuery* QueryName=gtschemaHandle.newQuery();
440 QueryName->addToTableList(runalgoviewname);
441 coral::AttributeList qAlgoNameOutput;
442 qAlgoNameOutput.extend(
"ALGO_INDEX",
typeid(
unsigned int));
443 qAlgoNameOutput.extend(
"ALIAS",
typeid(
std::string));
444 QueryName->addToOutputList(
"ALGO_INDEX");
445 QueryName->addToOutputList(
"ALIAS");
446 QueryName->setCondition(
"RUNNUMBER=:runnumber",bindVariableList);
448 QueryName->defineOutput(qAlgoNameOutput);
449 coral::ICursor& algonamecursor=QueryName->execute();
450 while( algonamecursor.next() ){
451 const coral::AttributeList& row = algonamecursor.currentRow();
453 unsigned int algo_index=row[
"ALGO_INDEX"].data<
unsigned int>();
455 triggernamemap.insert(std::make_pair(algo_index,algo_name));
462 std::map<unsigned int,std::string> techtriggernamemap;
463 coral::IQuery* QueryTechName=gtschemaHandle.newQuery();
464 QueryTechName->addToTableList(runtechviewname);
465 coral::AttributeList qTechNameOutput;
466 qTechNameOutput.extend(
"TECHTRIG_INDEX",
typeid(
unsigned int));
467 qTechNameOutput.extend(
"NAME",
typeid(
std::string));
468 QueryTechName->addToOutputList(
"TECHTRIG_INDEX");
469 QueryTechName->addToOutputList(
"NAME");
470 QueryTechName->setCondition(
"RUNNUMBER=:runnumber",bindVariableList);
472 QueryTechName->defineOutput(qTechNameOutput);
473 coral::ICursor& technamecursor=QueryTechName->execute();
474 while( technamecursor.next() ){
475 const coral::AttributeList& row = technamecursor.currentRow();
477 unsigned int tech_index=row[
"TECHTRIG_INDEX"].data<
unsigned int>();
479 techtriggernamemap.insert(std::make_pair(tech_index,tech_name));
481 delete QueryTechName;
488 std::vector< int >::iterator presIt;
489 std::vector< int >::iterator presItBeg=prescidx.begin();
490 std::vector< int >::iterator presItEnd=prescidx.end();
491 for( presIt=presItBeg; presIt!=presItEnd; ++presIt ){
492 coral::IQuery* QueryAlgoPresc=gtschemaHandle.newQuery();
493 QueryAlgoPresc->addToTableList(runprescalgoviewname);
494 coral::AttributeList qAlgoPrescOutput;
495 std::string algoprescBase(
"PRESCALE_FACTOR_ALGO_");
498 qAlgoPrescOutput.extend(algopresc,
typeid(
unsigned int));
502 QueryAlgoPresc->addToOutputList(algopresc);
504 coral::AttributeList PrescbindVariable;
505 PrescbindVariable.extend(
"runnumber",
typeid(
int));
506 PrescbindVariable.extend(
"prescaleindex",
typeid(
int));
507 PrescbindVariable[
"runnumber"].data<
int>()=
runnumber;
508 PrescbindVariable[
"prescaleindex"].data<
int>()=*presIt;
509 QueryAlgoPresc->setCondition(
"RUNNR=:runnumber AND PRESCALE_INDEX=:prescaleindex",PrescbindVariable);
510 QueryAlgoPresc->defineOutput(qAlgoPrescOutput);
511 coral::ICursor& algopresccursor=QueryAlgoPresc->execute();
512 while( algopresccursor.next() ){
513 const coral::AttributeList& row = algopresccursor.currentRow();
516 algoprescMap[*presIt].push_back(row[algopresc].data<unsigned int>());
519 delete QueryAlgoPresc;
524 for( presIt=presItBeg; presIt!=presItEnd; ++presIt ){
525 coral::IQuery* QueryTechPresc=gtschemaHandle.newQuery();
526 QueryTechPresc->addToTableList(runpresctechviewname);
527 coral::AttributeList qTechPrescOutput;
531 qTechPrescOutput.extend(techpresc,
typeid(
unsigned int));
535 QueryTechPresc->addToOutputList(techpresc);
537 coral::AttributeList TechPrescbindVariable;
538 TechPrescbindVariable.extend(
"runnumber",
typeid(
int));
539 TechPrescbindVariable.extend(
"prescaleindex",
typeid(
int));
540 TechPrescbindVariable[
"runnumber"].data<
int>()=
runnumber;
541 TechPrescbindVariable[
"prescaleindex"].data<
int>()=*presIt;
542 QueryTechPresc->setCondition(
"RUNNR=:runnumber AND PRESCALE_INDEX=:prescaleindex",TechPrescbindVariable);
543 QueryTechPresc->defineOutput(qTechPrescOutput);
544 coral::ICursor& techpresccursor=QueryTechPresc->execute();
545 while( techpresccursor.next() ){
546 const coral::AttributeList& row = techpresccursor.currentRow();
550 techprescMap[*presIt].push_back(row[techpresc].data<unsigned int>());
553 delete QueryTechPresc;
555 transaction.commit();
558 std::map< unsigned int, int >::iterator lsprescmapIt;
559 std::map< unsigned int, int >::iterator lsprescmapItBeg=lsprescmap.begin();
560 std::map< unsigned int, int >::iterator lsprescmapItEnd=lsprescmap.end();
561 for( lsprescmapIt=lsprescmapItBeg; lsprescmapIt!=lsprescmapItEnd; ++lsprescmapIt ){
562 unsigned int ls=lsprescmapIt->first;
563 int preidx=lsprescmapIt->second;
564 algoprescale.insert(std::make_pair(ls,algoprescMap[preidx]));
565 techprescale.insert(std::make_pair(ls,techprescMap[preidx]));
567 algoprescMap.clear();
568 techprescMap.clear();
573 std::map<unsigned int,std::string>::iterator pos=triggernamemap.find(algoidx);
574 if(pos!=triggernamemap.end()){
575 algonames.push_back(pos->second);
577 algonames.push_back(
"False");
583 std::stringstream
ss;
586 technames.push_back(ss.str());
598 if(deadtimeresult.size()!=deadfracresult.size()|| deadtimeresult.size()!=algocount.size() || deadtimeresult.size()!=techcount.size() || deadtimeresult.size()!=algoprescale.size() || deadtimeresult.size()!=techprescale.size() ){
600 std::cout<<
"[WARNING] inconsistent number of LS of deadtimecounter,deadfrac,algo,tech,prescalealgo,prescaletech "<<deadtimeresult.size()<<
" "<<deadfracresult.size()<<
" "<<algocount.size()<<
" "<<techcount.size()<<
" "<<algoprescale.size()<<
" "<<techprescale.size()<<std::endl;
601 TRGScalers2DB::TriggerDeadCountResult::iterator dIt;
602 TRGScalers2DB::TriggerDeadCountResult::iterator dBeg=deadtimeresult.begin();
603 TRGScalers2DB::TriggerDeadCountResult::iterator dEnd=deadtimeresult.end();
605 for(dIt=dBeg;dIt!=dEnd;++dIt){
607 deadfracresult.at(dcnt);
608 }
catch(std::out_of_range& er){
609 std::cout<<
"[WARNING] filling FAKE deadfrac=0.0 at LS "<<dcnt<<std::endl;
610 deadfracresult[dcnt]=0.0;
614 }
catch(std::out_of_range& er){
615 std::vector<unsigned int> tmpzero(lumi::N_TRGALGOBIT,0);
616 std::cout<<
"[WARNING] filling FAKE algocount at LS "<<dcnt<<std::endl;
617 algocount[dcnt]=tmpzero;
621 }
catch(std::out_of_range& er){
622 std::vector<unsigned int> tmpzero(lumi::N_TRGTECHBIT,0);
623 std::cout<<
"[WARNING] filling FAKE techcount at LS "<<dcnt<<std::endl;
624 techcount[dcnt]=tmpzero;
626 if(algoprescale.find(dcnt+1)==algoprescale.end()){
627 std::vector<unsigned int> tmpzero(lumi::N_TRGALGOBIT,1);
628 std::cout<<
"[WARNING] filling FAKE 1 algoprescale at LS "<<dcnt+1<<std::endl;
629 algoprescale[dcnt+1]=tmpzero;
631 if(techprescale.find(dcnt+1)==techprescale.end()){
632 std::vector<unsigned int> tmpzero(lumi::N_TRGTECHBIT,1);
633 std::cout<<
"[WARNING] filling FAKE 1 techprescale at LS "<<dcnt+1<<std::endl;
634 techprescale[dcnt+1]=tmpzero;
642 unsigned long long trgdataid=0;
643 coral::ISessionProxy* lumisession=svc->connect(
m_dest,coral::Update);
644 coral::ITypeConverter& lumitpc=lumisession->typeConverter();
645 lumitpc.setCppTypeForSqlType(
"unsigned int",
"NUMBER(7)");
646 lumitpc.setCppTypeForSqlType(
"unsigned int",
"NUMBER(10)");
647 lumitpc.setCppTypeForSqlType(
"unsigned long long",
"NUMBER(20)");
649 if(
m_mode==
"loadoldschema"){
650 std::cout<<
"writing trg data to old trg table "<<std::endl;
651 writeTrgData(lumisession,
runnumber,
m_source,deadtimeresult.begin(),deadtimeresult.end(),deadfracresult,algonames,technames,algocount,techcount,algoprescale,techprescale,
COMMITLSINTERVAL);
654 std::cout<<
"writing trg data to new lstrg table "<<std::endl;
655 trgdataid=
writeTrgDataToSchema2(lumisession,
runnumber,
m_source,deadtimeresult.begin(),deadtimeresult.end(),deadfracresult,algonames,technames,algocount,techcount,algoprescale,techprescale,
COMMITLSTRGINTERVAL);
660 std::cout<<
"database error "<<er.what()<<std::endl;
661 lumisession->transaction().rollback();
std::vector< DEADFRAC > TriggerDeadFracResult
static const unsigned int COMMITLSTRGINTERVAL
std::vector< BITCOUNT > TriggerCountResult_Algo
unsigned long long writeTrgDataToSchema2(coral::ISessionProxy *session, unsigned int runnumber, const std::string &source, TriggerDeadCountResult::iterator deadtimesBeg, TriggerDeadCountResult::iterator deadtimesEnd, TRGScalers2DB::TriggerDeadFracResult &deadfracs, TriggerNameResult_Algo &algonames, TriggerNameResult_Tech &technames, TriggerCountResult_Algo &algocounts, TriggerCountResult_Tech &techcounts, PrescaleResult_Algo &prescalealgo, PrescaleResult_Tech &prescaletech, unsigned int commitintv)
std::vector< std::string > TriggerNameResult_Tech
std::vector< BITCOUNT > TriggerCountResult_Tech
std::map< unsigned int, std::vector< unsigned int > > PrescaleResult_Algo
static const unsigned int COMMITLSINTERVAL
std::vector< unsigned int > BITCOUNT
const unsigned int N_TRGTECHBIT
std::string int2str(unsigned int t, unsigned int width)
std::vector< std::string > TriggerNameResult_Algo
std::map< unsigned int, std::vector< unsigned int > > PrescaleResult_Tech
std::vector< DEADCOUNT > TriggerDeadCountResult
const unsigned int N_TRGALGOBIT
void writeTrgData(coral::ISessionProxy *session, unsigned int runnumber, const std::string &source, TriggerDeadCountResult::iterator deadtimesBeg, TriggerDeadCountResult::iterator deadtimesEnd, TRGScalers2DB::TriggerDeadFracResult &deadfracs, TriggerNameResult_Algo &algonames, TriggerNameResult_Tech &technames, TriggerCountResult_Algo &algocounts, TriggerCountResult_Tech &techcounts, PrescaleResult_Algo &prescalealgo, PrescaleResult_Tech &prescaletech, unsigned int commitintv)