1 #ifndef RecoLuminosity_LumiProducer_TRGScalers2DB_h
2 #define RecoLuminosity_LumiProducer_TRGScalers2DB_h
3 #include "CoralBase/AttributeList.h"
4 #include "CoralBase/Attribute.h"
5 #include "CoralBase/AttributeSpecification.h"
6 #include "CoralBase/Blob.h"
7 #include "CoralBase/Exception.h"
8 #include "RelationalAccess/ConnectionService.h"
9 #include "RelationalAccess/ISessionProxy.h"
10 #include "RelationalAccess/ITransaction.h"
11 #include "RelationalAccess/ITypeConverter.h"
12 #include "RelationalAccess/IQuery.h"
13 #include "RelationalAccess/ICursor.h"
14 #include "RelationalAccess/ISchema.h"
15 #include "RelationalAccess/IView.h"
16 #include "RelationalAccess/ITable.h"
17 #include "RelationalAccess/ITableDataEditor.h"
18 #include "RelationalAccess/IBulkOperation.h"
62 TriggerDeadCountResult::iterator deadtimesBeg,
63 TriggerDeadCountResult::iterator deadtimesEnd,
71 unsigned int commitintv);
75 TriggerDeadCountResult::iterator deadtimesBeg,
76 TriggerDeadCountResult::iterator deadtimesEnd,
84 unsigned int commitintv);
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();
672 TRGScalers2DB::TriggerDeadCountResult::iterator deadtimesBeg,TRGScalers2DB::TriggerDeadCountResult::iterator deadtimesEnd,
680 unsigned int commitintv){
681 TRGScalers2DB::TriggerDeadCountResult::iterator deadIt;
683 unsigned int totalcmsls=std::distance(deadtimesBeg,deadtimesEnd);
684 std::cout<<
"inserting totalcmsls "<<totalcmsls<<std::endl;
685 std::map< unsigned long long, std::vector<unsigned long long> > idallocationtable;
687 lumisession->transaction().start(
false);
691 unsigned int trglscount=0;
692 for(deadIt=deadtimesBeg;deadIt!=deadtimesEnd;++deadIt,++trglscount){
693 std::vector<unsigned long long> bitvec;
694 bitvec.reserve(lumi::N_TRGBIT);
695 const BITCOUNT& algoinbits=algocounts[trglscount];
696 const BITCOUNT& techinbits=techcounts[trglscount];
697 BITCOUNT::const_iterator algoBitIt;
698 BITCOUNT::const_iterator algoBitBeg=algoinbits.begin();
699 BITCOUNT::const_iterator algoBitEnd=algoinbits.end();
700 for(algoBitIt=algoBitBeg;algoBitIt!=algoBitEnd;++algoBitIt,++trgID){
701 bitvec.push_back(trgID);
703 BITCOUNT::const_iterator techBitIt;
704 BITCOUNT::const_iterator techBitBeg=techinbits.begin();
705 BITCOUNT::const_iterator techBitEnd=techinbits.end();
706 for(techBitIt=techBitBeg;techBitIt!=techBitEnd;++techBitIt,++trgID){
707 bitvec.push_back(trgID);
709 idallocationtable.insert(std::make_pair(trglscount,bitvec));
711 std::cout<<
"\t all ids allocated"<<std::endl;
712 coral::AttributeList trgData;
713 trgData.extend<
unsigned long long>(
"TRG_ID");
714 trgData.extend<
unsigned int>(
"RUNNUM");
715 trgData.extend<
unsigned int>(
"CMSLSNUM");
716 trgData.extend<
unsigned int>(
"BITNUM");
718 trgData.extend<
unsigned int>(
"TRGCOUNT");
719 trgData.extend<
unsigned long long>(
"DEADTIME");
720 trgData.extend<
float>(
"DEADFRAC");
721 trgData.extend<
unsigned int>(
"PRESCALE");
723 unsigned long long& trg_id=trgData[
"TRG_ID"].data<
unsigned long long>();
724 unsigned int& trgrunnum=trgData[
"RUNNUM"].data<
unsigned int>();
725 unsigned int&
cmslsnum=trgData[
"CMSLSNUM"].data<
unsigned int>();
726 unsigned int& bitnum=trgData[
"BITNUM"].data<
unsigned int>();
728 unsigned int&
count=trgData[
"TRGCOUNT"].data<
unsigned int>();
729 unsigned long long& deadtime=trgData[
"DEADTIME"].data<
unsigned long long>();
730 float& deadfrac=trgData[
"DEADFRAC"].data<
float>();
731 unsigned int& prescale=trgData[
"PRESCALE"].data<
unsigned int>();
734 coral::IBulkOperation* trgInserter=0;
735 unsigned int comittedls=0;
736 for(deadIt=deadtimesBeg;deadIt!=deadtimesEnd;++deadIt,++trglscount ){
737 unsigned int cmslscount=trglscount+1;
738 float dfra=deadfracs[trglscount];
739 const BITCOUNT& algoinbits=algocounts[trglscount];
740 const BITCOUNT& techinbits=techcounts[trglscount];
741 unsigned int trgbitcount=0;
742 BITCOUNT::const_iterator algoBitIt;
743 BITCOUNT::const_iterator algoBitBeg=algoinbits.begin();
744 BITCOUNT::const_iterator algoBitEnd=algoinbits.end();
745 if(!lumisession->transaction().isActive()){
746 lumisession->transaction().start(
false);
748 trgInserter=trgtable.dataEditor().bulkInsert(trgData,2048);
750 if(deadIt==deadtimesBeg){
752 trgInserter=trgtable.dataEditor().bulkInsert(trgData,2048);
755 for(algoBitIt=algoBitBeg;algoBitIt!=algoBitEnd;++algoBitIt,++trgbitcount){
756 trg_id = idallocationtable[trglscount].at(trgbitcount);
760 cmslsnum = cmslscount;
762 bitname=algonames[trgbitcount];
764 prescale=prescalealgo[cmslscount].at(trgbitcount);
766 trgInserter->processNextIteration();
768 BITCOUNT::const_iterator techBitIt;
769 BITCOUNT::const_iterator techBitBeg=techinbits.begin();
770 BITCOUNT::const_iterator techBitEnd=techinbits.end();
771 for(techBitIt=techBitBeg;techBitIt!=techBitEnd;++techBitIt,++trgbitcount){
772 trg_id = idallocationtable[trglscount].at(trgbitcount);
776 cmslsnum = cmslscount;
781 trgInserter->processNextIteration();
783 trgInserter->flush();
785 if(comittedls==commitintv){
786 std::cout<<
"\t committing in LS chunck "<<comittedls<<std::endl;
787 delete trgInserter; trgInserter=0;
788 lumisession->transaction().commit();
791 }
else if( trglscount==( totalcmsls-1) ){
792 std::cout<<
"\t committing at the end"<<std::endl;
793 delete trgInserter; trgInserter=0;
794 lumisession->transaction().commit();
801 unsigned int irunnumber,
803 TriggerDeadCountResult::iterator deadtimesBeg,
804 TriggerDeadCountResult::iterator deadtimesEnd,
812 unsigned int commitintv){
813 TRGScalers2DB::TriggerDeadCountResult::iterator deadIt;
814 unsigned int totalcmsls=std::distance(deadtimesBeg,deadtimesEnd);
815 std::cout<<
"inserting totalcmsls "<<totalcmsls<<std::endl;
816 coral::AttributeList lstrgData;
817 lstrgData.extend<
unsigned long long>(
"DATA_ID");
818 lstrgData.extend<
unsigned int>(
"RUNNUM");
819 lstrgData.extend<
unsigned int>(
"CMSLSNUM");
820 lstrgData.extend<
unsigned long long>(
"DEADTIMECOUNT");
821 lstrgData.extend<
unsigned int>(
"BITZEROCOUNT");
822 lstrgData.extend<
unsigned int>(
"BITZEROPRESCALE");
823 lstrgData.extend<
float>(
"DEADFRAC");
824 lstrgData.extend<coral::Blob>(
"PRESCALEBLOB");
825 lstrgData.extend<coral::Blob>(
"TRGCOUNTBLOB");
827 unsigned long long& data_id=lstrgData[
"DATA_ID"].data<
unsigned long long>();
828 unsigned int& trgrunnum=lstrgData[
"RUNNUM"].data<
unsigned int>();
829 unsigned int&
cmslsnum=lstrgData[
"CMSLSNUM"].data<
unsigned int>();
830 unsigned long long& deadtime=lstrgData[
"DEADTIMECOUNT"].data<
unsigned long long>();
831 unsigned int& bitzerocount=lstrgData[
"BITZEROCOUNT"].data<
unsigned int>();
832 unsigned int& bitzeroprescale=lstrgData[
"BITZEROPRESCALE"].data<
unsigned int>();
833 float& deadfrac=lstrgData[
"DEADFRAC"].data<
float>();
834 coral::Blob& prescaleblob=lstrgData[
"PRESCALEBLOB"].data<coral::Blob>();
835 coral::Blob& trgcountblob=lstrgData[
"TRGCOUNTBLOB"].data<coral::Blob>();
837 unsigned long long branch_id=3;
841 std::stringstream op;
844 lumisession->transaction().start(
false);
849 TriggerNameResult_Algo::iterator bitnameIt;
850 TriggerNameResult_Algo::iterator bitnameItBeg=algonames.begin();
851 TriggerNameResult_Algo::iterator bitnameItEnd=algonames.end();
852 for (bitnameIt=bitnameItBeg;bitnameIt!=bitnameItEnd;++bitnameIt){
853 if(bitnameIt!=bitnameItBeg){
856 bitnames+=*bitnameIt;
858 TriggerNameResult_Tech::iterator techbitnameIt;
859 TriggerNameResult_Tech::iterator techbitnameItBeg=technames.begin();
860 TriggerNameResult_Tech::iterator techbitnameItEnd=technames.end();
861 for(techbitnameIt=techbitnameItBeg;techbitnameIt!=techbitnameItEnd;++techbitnameIt){
863 bitnames+=*techbitnameIt;
865 std::cout<<
"\tbitnames "<<bitnames<<std::endl;
878 std::cout<<
"inserting trgrundata "<<std::endl;
880 std::cout<<
"inserting lstrg data"<<std::endl;
882 unsigned int trglscount=0;
884 coral::IBulkOperation* lstrgInserter=0;
885 unsigned int comittedls=0;
886 for(deadIt=deadtimesBeg;deadIt!=deadtimesEnd;++deadIt,++trglscount ){
887 unsigned int cmslscount=trglscount+1;
888 if(!lumisession->transaction().isActive()){
889 lumisession->transaction().start(
false);
891 lstrgInserter=lstrgtable.dataEditor().bulkInsert(lstrgData,2048);
893 if(deadIt==deadtimesBeg){
895 lstrgInserter=lstrgtable.dataEditor().bulkInsert(lstrgData,2048);
899 trgrunnum = irunnumber;
900 cmslsnum = cmslscount;
902 deadfrac = deadfracs[trglscount];
905 bitzerocount=techcounts[trglscount][4];
906 bitzeroprescale=prescaletech[
cmslsnum][4];
907 std::vector<unsigned int> fullprescales;
908 fullprescales.reserve(prescalealgo[cmslsnum].
size()+prescaletech[cmslsnum].
size());
909 fullprescales.insert(fullprescales.end(),prescalealgo[
cmslsnum].begin(),prescalealgo[
cmslsnum].end());
910 fullprescales.insert(fullprescales.end(),prescaletech[
cmslsnum].begin(),prescaletech[
cmslsnum].end());
912 prescaleblob.resize(
sizeof(
unsigned int)*(fullprescales.size()));
913 void* prescaleblob_StartAddress = prescaleblob.startingAddress();
914 std::memmove(prescaleblob_StartAddress,&fullprescales[0],
sizeof(
unsigned int)*(fullprescales.size()));
916 std::vector<unsigned int> fullcounts;
917 fullcounts.reserve(algocounts[trglscount].
size()+techcounts[trglscount].
size());
918 fullcounts.insert(fullcounts.end(),algocounts[trglscount].begin(),algocounts[trglscount].end());
919 fullcounts.insert(fullcounts.end(),techcounts[trglscount].begin(),techcounts[trglscount].end());
920 trgcountblob.resize(
sizeof(
unsigned int)*(fullcounts.size()));
921 void* trgcountblob_StartAddress = trgcountblob.startingAddress();
922 std::memmove(trgcountblob_StartAddress,&fullcounts[0],
sizeof(
unsigned int)*(fullcounts.size()));
924 lstrgInserter->processNextIteration();
925 lstrgInserter->flush();
927 if(comittedls==commitintv){
928 std::cout<<
"\t committing in LS chunck "<<comittedls<<std::endl;
929 delete lstrgInserter; lstrgInserter=0;
930 lumisession->transaction().commit();
933 }
else if( trglscount==( totalcmsls-1) ){
934 std::cout<<
"\t committing at the end"<<std::endl;
935 delete lstrgInserter; lstrgInserter=0;
936 lumisession->transaction().commit();
951 std::stringstream ss;
958 std::istringstream myStream(s);
std::vector< DEADFRAC > TriggerDeadFracResult
static const std::string trgTableName()
static const std::string trgdataTableName()
static const unsigned int COMMITLSTRGINTERVAL
virtual unsigned long long retrieveData(unsigned int runnumber)
void addEntry(coral::ISchema &schema, const std::string &datatableName, const Entry &entry, unsigned long long branch_id, const std::string &branchname)
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)
virtual const std::string sourceType() const
std::vector< std::string > TriggerNameResult_Tech
virtual const std::string dataType() const
std::vector< BITCOUNT > TriggerCountResult_Tech
static const std::string lstrgTableName()
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)
unsigned long long data_id
std::vector< std::string > TriggerNameResult_Algo
void setAuthentication(const std::string &authPath)
unsigned long long getEntryInBranchByName(coral::ISchema &schema, const std::string &datatableName, const std::string &entryname, const std::string &branchname)
std::map< unsigned int, std::vector< unsigned int > > PrescaleResult_Tech
unsigned long long revision_id
std::vector< DEADCOUNT > TriggerDeadCountResult
void insertTrgRunData(coral::ISchema &schema, const TrgEntry &trgentry)
unsigned long long entry_id
unsigned long long DEADCOUNT
void bookNewEntry(coral::ISchema &schema, const std::string &datatableName, Entry &entry)
unsigned long long generateNextIDForTable(const std::string &tableName, unsigned int interval=1)
#define DEFINE_EDM_PLUGIN(factory, type, name)
void addRevision(coral::ISchema &schema, const std::string &datatableName, const Entry &revision, unsigned long long branch_id, std::string &branchname)
const unsigned int N_TRGALGOBIT
TRGScalers2DB(const std::string &dest)
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)
const unsigned int N_TRGBIT
tuple size
Write out results.
unsigned int str2int(const std::string &s)
void bookNewRevision(coral::ISchema &schema, const std::string &datatableName, Entry &revision)