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"
39 virtual const std::string
dataType()
const;
58 unsigned int str2int(
const std::string&
s);
62 TriggerDeadCountResult::iterator deadtimesBeg,
63 TriggerDeadCountResult::iterator deadtimesEnd,
71 unsigned int commitintv);
75 TriggerDeadCountResult::iterator deadtimesBeg,
76 TriggerDeadCountResult::iterator deadtimesEnd,
84 unsigned int commitintv);
113 std::string runnumberstr=
int2str(runnumber,6);
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)");
126 std::string gtmonschema(
"CMS_GT_MON");
127 std::string algoviewname(
"V_SCALERS_FDL_ALGO");
128 std::string techviewname(
"V_SCALERS_FDL_TECH");
129 std::string deadviewname(
"V_SCALERS_TCS_DEADTIME");
130 std::string lstablename(
"LUMI_SECTIONS");
132 std::string gtschema(
"CMS_GT");
133 std::string runtechviewname(
"GT_RUN_TECH_VIEW");
134 std::string runalgoviewname(
"GT_RUN_ALGO_VIEW");
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)){
165 throw lumi::Exception(std::string(
"non-existing view ")+algoviewname,
"retrieveData",
"TRGScalers2DB");
167 if(!gtmonschemaHandle.existsView(techviewname)){
168 throw lumi::Exception(std::string(
"non-existing view ")+techviewname,
"retrieveData",
"TRGScalers2DB");
170 if(!gtmonschemaHandle.existsView(deadviewname)){
171 throw lumi::Exception(std::string(
"non-existing view ")+deadviewname,
"retrieveData",
"TRGScalers2DB");
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();
223 throw lumi::Exception(std::string(
"requested run ")+runnumberstr+std::string(
" doesn't exist for algocounts"),
"retrieveData",
"TRGScalers2DB");
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();
271 throw lumi::Exception(std::string(
"requested run ")+runnumberstr+std::string(
" doesn't exist for techcounts"),
"retrieveData",
"TRGScalers2DB");
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;
293 bindVariablesDead[
"scalername"].data<std::string>()=std::string(
"DeadtimeBeamActive");
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();
330 throw lumi::Exception(std::string(
"requested run ")+runnumberstr+std::string(
" doesn't exist for deadcounts"),
"retrieveData",
"TRGScalers2DB");
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();
406 throw lumi::Exception(std::string(
"requested run ")+runnumberstr+std::string(
" doesn't exist for prescale_index"),
"retrieveData",
"TRG2DB");
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)){
424 throw lumi::Exception(std::string(
"non-existing view ")+runtechviewname,
"str2int",
"TRG2DB");
426 if(!gtschemaHandle.existsView(runalgoviewname)){
427 throw lumi::Exception(std::string(
"non-existing view ")+runalgoviewname,
"str2int",
"TRG2DB");
429 if(!gtschemaHandle.existsView(runprescalgoviewname)){
430 throw lumi::Exception(std::string(
"non-existing view ")+runprescalgoviewname,
"str2int",
"TRG2DB");
432 if(!gtschemaHandle.existsView(runpresctechviewname)){
433 throw lumi::Exception(std::string(
"non-existing view ")+runpresctechviewname,
"str2int",
"TRG2DB");
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>();
454 std::string algo_name=row[
"alias"].data<std::string>();
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>();
478 std::string tech_name=row[
"name"].data<std::string>();
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_");
497 std::string algopresc=algoprescBase+
int2str(bitidx,3);
498 qAlgoPrescOutput.extend(algopresc,
typeid(
unsigned int));
501 std::string algopresc=algoprescBase+
int2str(bitidx,3);
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();
515 std::string algopresc=algoprescBase+
int2str(bitidx,3);
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;
528 std::string techprescBase(
"PRESCALE_FACTOR_TT_");
530 std::string techpresc=techprescBase+this->
int2str(bitidx,3);
531 qTechPrescOutput.extend(techpresc,
typeid(
unsigned int));
534 std::string techpresc=techprescBase+
int2str(bitidx,3);
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();
549 std::string techpresc=techprescBase+
int2str(bitidx,3);
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;
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 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();
670 const std::string&
source,
671 TRGScalers2DB::TriggerDeadCountResult::iterator deadtimesBeg,TRGScalers2DB::TriggerDeadCountResult::iterator deadtimesEnd,
679 unsigned int commitintv){
680 TRGScalers2DB::TriggerDeadCountResult::iterator deadIt;
682 unsigned int totalcmsls=std::distance(deadtimesBeg,deadtimesEnd);
683 std::cout<<
"inserting totalcmsls "<<totalcmsls<<std::endl;
684 std::map< unsigned long long, std::vector<unsigned long long> > idallocationtable;
686 lumisession->transaction().start(
false);
690 unsigned int trglscount=0;
691 for(deadIt=deadtimesBeg;deadIt!=deadtimesEnd;++deadIt,++trglscount){
692 std::vector<unsigned long long> bitvec;
693 bitvec.reserve(lumi::N_TRGBIT);
694 const BITCOUNT& algoinbits=algocounts[trglscount];
695 const BITCOUNT& techinbits=techcounts[trglscount];
696 BITCOUNT::const_iterator algoBitIt;
697 BITCOUNT::const_iterator algoBitBeg=algoinbits.begin();
698 BITCOUNT::const_iterator algoBitEnd=algoinbits.end();
699 for(algoBitIt=algoBitBeg;algoBitIt!=algoBitEnd;++algoBitIt,++trgID){
700 bitvec.push_back(trgID);
702 BITCOUNT::const_iterator techBitIt;
703 BITCOUNT::const_iterator techBitBeg=techinbits.begin();
704 BITCOUNT::const_iterator techBitEnd=techinbits.end();
705 for(techBitIt=techBitBeg;techBitIt!=techBitEnd;++techBitIt,++trgID){
706 bitvec.push_back(trgID);
708 idallocationtable.insert(std::make_pair(trglscount,bitvec));
710 std::cout<<
"\t all ids allocated"<<std::endl;
711 coral::AttributeList trgData;
712 trgData.extend<
unsigned long long>(
"TRG_ID");
713 trgData.extend<
unsigned int>(
"RUNNUM");
714 trgData.extend<
unsigned int>(
"CMSLSNUM");
715 trgData.extend<
unsigned int>(
"BITNUM");
716 trgData.extend<std::string>(
"BITNAME");
717 trgData.extend<
unsigned int>(
"TRGCOUNT");
718 trgData.extend<
unsigned long long>(
"DEADTIME");
719 trgData.extend<
float>(
"DEADFRAC");
720 trgData.extend<
unsigned int>(
"PRESCALE");
722 unsigned long long& trg_id=trgData[
"TRG_ID"].data<
unsigned long long>();
723 unsigned int& trgrunnum=trgData[
"RUNNUM"].data<
unsigned int>();
724 unsigned int&
cmslsnum=trgData[
"CMSLSNUM"].data<
unsigned int>();
725 unsigned int& bitnum=trgData[
"BITNUM"].data<
unsigned int>();
726 std::string& bitname=trgData[
"BITNAME"].data<std::string>();
727 unsigned int&
count=trgData[
"TRGCOUNT"].data<
unsigned int>();
728 unsigned long long& deadtime=trgData[
"DEADTIME"].data<
unsigned long long>();
729 float& deadfrac=trgData[
"DEADFRAC"].data<
float>();
730 unsigned int& prescale=trgData[
"PRESCALE"].data<
unsigned int>();
733 coral::IBulkOperation* trgInserter=0;
734 unsigned int comittedls=0;
735 for(deadIt=deadtimesBeg;deadIt!=deadtimesEnd;++deadIt,++trglscount ){
736 unsigned int cmslscount=trglscount+1;
737 float dfra=deadfracs[trglscount];
738 const BITCOUNT& algoinbits=algocounts[trglscount];
739 const BITCOUNT& techinbits=techcounts[trglscount];
740 unsigned int trgbitcount=0;
741 BITCOUNT::const_iterator algoBitIt;
742 BITCOUNT::const_iterator algoBitBeg=algoinbits.begin();
743 BITCOUNT::const_iterator algoBitEnd=algoinbits.end();
744 if(!lumisession->transaction().isActive()){
745 lumisession->transaction().start(
false);
747 trgInserter=trgtable.dataEditor().bulkInsert(trgData,2048);
749 if(deadIt==deadtimesBeg){
751 trgInserter=trgtable.dataEditor().bulkInsert(trgData,2048);
754 for(algoBitIt=algoBitBeg;algoBitIt!=algoBitEnd;++algoBitIt,++trgbitcount){
755 trg_id = idallocationtable[trglscount].at(trgbitcount);
759 cmslsnum = cmslscount;
761 bitname=algonames[trgbitcount];
763 prescale=prescalealgo[cmslscount].at(trgbitcount);
765 trgInserter->processNextIteration();
767 BITCOUNT::const_iterator techBitIt;
768 BITCOUNT::const_iterator techBitBeg=techinbits.begin();
769 BITCOUNT::const_iterator techBitEnd=techinbits.end();
770 for(techBitIt=techBitBeg;techBitIt!=techBitEnd;++techBitIt,++trgbitcount){
771 trg_id = idallocationtable[trglscount].at(trgbitcount);
775 cmslsnum = cmslscount;
780 trgInserter->processNextIteration();
782 trgInserter->flush();
784 if(comittedls==commitintv){
785 std::cout<<
"\t committing in LS chunck "<<comittedls<<std::endl;
786 delete trgInserter; trgInserter=0;
787 lumisession->transaction().commit();
790 }
else if( trglscount==( totalcmsls-1) ){
791 std::cout<<
"\t committing at the end"<<std::endl;
792 delete trgInserter; trgInserter=0;
793 lumisession->transaction().commit();
800 unsigned int irunnumber,
801 const std::string&
source,
802 TriggerDeadCountResult::iterator deadtimesBeg,
803 TriggerDeadCountResult::iterator deadtimesEnd,
811 unsigned int commitintv){
812 TRGScalers2DB::TriggerDeadCountResult::iterator deadIt;
813 unsigned int totalcmsls=std::distance(deadtimesBeg,deadtimesEnd);
814 std::cout<<
"inserting totalcmsls "<<totalcmsls<<std::endl;
815 coral::AttributeList lstrgData;
816 lstrgData.extend<
unsigned long long>(
"DATA_ID");
817 lstrgData.extend<
unsigned int>(
"RUNNUM");
818 lstrgData.extend<
unsigned int>(
"CMSLSNUM");
819 lstrgData.extend<
unsigned long long>(
"DEADTIMECOUNT");
820 lstrgData.extend<
unsigned int>(
"BITZEROCOUNT");
821 lstrgData.extend<
unsigned int>(
"BITZEROPRESCALE");
822 lstrgData.extend<
float>(
"DEADFRAC");
823 lstrgData.extend<coral::Blob>(
"PRESCALEBLOB");
824 lstrgData.extend<coral::Blob>(
"TRGCOUNTBLOB");
826 unsigned long long& data_id=lstrgData[
"DATA_ID"].data<
unsigned long long>();
827 unsigned int& trgrunnum=lstrgData[
"RUNNUM"].data<
unsigned int>();
828 unsigned int&
cmslsnum=lstrgData[
"CMSLSNUM"].data<
unsigned int>();
829 unsigned long long& deadtime=lstrgData[
"DEADTIMECOUNT"].data<
unsigned long long>();
830 unsigned int& bitzerocount=lstrgData[
"BITZEROCOUNT"].data<
unsigned int>();
831 unsigned int& bitzeroprescale=lstrgData[
"BITZEROPRESCALE"].data<
unsigned int>();
832 float& deadfrac=lstrgData[
"DEADFRAC"].data<
float>();
833 coral::Blob& prescaleblob=lstrgData[
"PRESCALEBLOB"].data<coral::Blob>();
834 coral::Blob& trgcountblob=lstrgData[
"TRGCOUNTBLOB"].data<coral::Blob>();
836 unsigned long long branch_id=3;
837 std::string branch_name(
"DATA");
840 std::stringstream op;
842 std::string runnumberStr=op.str();
843 lumisession->transaction().start(
false);
847 std::string bitnames;
848 TriggerNameResult_Algo::iterator bitnameIt;
849 TriggerNameResult_Algo::iterator bitnameItBeg=algonames.begin();
850 TriggerNameResult_Algo::iterator bitnameItEnd=algonames.end();
851 for (bitnameIt=bitnameItBeg;bitnameIt!=bitnameItEnd;++bitnameIt){
852 if(bitnameIt!=bitnameItBeg){
853 bitnames+=std::string(
",");
855 bitnames+=*bitnameIt;
857 TriggerNameResult_Tech::iterator techbitnameIt;
858 TriggerNameResult_Tech::iterator techbitnameItBeg=technames.begin();
859 TriggerNameResult_Tech::iterator techbitnameItEnd=technames.end();
860 for(techbitnameIt=techbitnameItBeg;techbitnameIt!=techbitnameItEnd;++techbitnameIt){
861 bitnames+=std::string(
",");
862 bitnames+=*techbitnameIt;
864 std::cout<<
"\tbitnames "<<bitnames<<std::endl;
877 std::cout<<
"inserting trgrundata "<<std::endl;
879 std::cout<<
"inserting lstrg data"<<std::endl;
881 unsigned int trglscount=0;
883 coral::IBulkOperation* lstrgInserter=0;
884 unsigned int comittedls=0;
885 for(deadIt=deadtimesBeg;deadIt!=deadtimesEnd;++deadIt,++trglscount ){
886 unsigned int cmslscount=trglscount+1;
887 if(!lumisession->transaction().isActive()){
888 lumisession->transaction().start(
false);
890 lstrgInserter=lstrgtable.dataEditor().bulkInsert(lstrgData,2048);
892 if(deadIt==deadtimesBeg){
894 lstrgInserter=lstrgtable.dataEditor().bulkInsert(lstrgData,2048);
898 trgrunnum = irunnumber;
899 cmslsnum = cmslscount;
901 deadfrac = deadfracs[trglscount];
904 bitzerocount=techcounts[trglscount][4];
905 bitzeroprescale=prescaletech[
cmslsnum][4];
906 std::vector<unsigned int> fullprescales;
907 fullprescales.reserve(prescalealgo[cmslsnum].
size()+prescaletech[cmslsnum].
size());
908 fullprescales.insert(fullprescales.end(),prescalealgo[
cmslsnum].begin(),prescalealgo[
cmslsnum].end());
909 fullprescales.insert(fullprescales.end(),prescaletech[
cmslsnum].begin(),prescaletech[
cmslsnum].end());
911 prescaleblob.resize(
sizeof(
unsigned int)*(fullprescales.size()));
912 void* prescaleblob_StartAddress = prescaleblob.startingAddress();
913 std::memmove(prescaleblob_StartAddress,&fullprescales[0],
sizeof(
unsigned int)*(fullprescales.size()));
915 std::vector<unsigned int> fullcounts;
916 fullcounts.reserve(algocounts[trglscount].
size()+techcounts[trglscount].
size());
917 fullcounts.insert(fullcounts.end(),algocounts[trglscount].begin(),algocounts[trglscount].end());
918 fullcounts.insert(fullcounts.end(),techcounts[trglscount].begin(),techcounts[trglscount].end());
919 trgcountblob.resize(
sizeof(
unsigned int)*(fullcounts.size()));
920 void* trgcountblob_StartAddress = trgcountblob.startingAddress();
921 std::memmove(trgcountblob_StartAddress,&fullcounts[0],
sizeof(
unsigned int)*(fullcounts.size()));
923 lstrgInserter->processNextIteration();
924 lstrgInserter->flush();
926 if(comittedls==commitintv){
927 std::cout<<
"\t committing in LS chunck "<<comittedls<<std::endl;
928 delete lstrgInserter; lstrgInserter=0;
929 lumisession->transaction().commit();
932 }
else if( trglscount==( totalcmsls-1) ){
933 std::cout<<
"\t committing at the end"<<std::endl;
934 delete lstrgInserter; lstrgInserter=0;
935 lumisession->transaction().commit();
950 std::stringstream ss;
957 std::istringstream myStream(s);
962 throw lumi::Exception(std::string(
"str2int error"),
"str2int",
"TRGScalers2DB");
std::vector< DEADFRAC > TriggerDeadFracResult
static const std::string trgTableName()
static const std::string trgdataTableName()
static const unsigned int COMMITLSTRGINTERVAL
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
virtual void retrieveData(unsigned int runnumber)
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)
void 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)
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)