transaction.start(true); //true means readonly transaction std::cout<<"schema name "<<session->schema(gtmonschema).schemaName()<<std::endl; std::set<std::string> listofviews; listofviews=session->schema(gtmonschema).listViews(); for( std::set<std::string>::iterator it=listofviews.begin(); it!=listofviews.end();++it ){ std::cout<<"view: "<<*it<<std::endl; } std::cout<<"schema name "<<session->schema(gtschema).schemaName()<<std::endl; listofviews.clear(); listofviews=session->schema(gtschema).listViews(); for( std::set<std::string>::iterator it=listofviews.begin(); it!=listofviews.end();++it ){ std::cout<<"view: "<<*it<<std::endl; } std::cout<<"commit transaction"<<std::endl; transaction.commit();
59 coral::ConnectionService*
svc=
new coral::ConnectionService;
65 coral::ISessionProxy* trgsession=svc->connect(
m_source, coral::ReadOnly);
66 coral::ITypeConverter& tpc=trgsession->typeConverter();
68 tpc.setCppTypeForSqlType(
"unsigned int",
"NUMBER(7)");
69 tpc.setCppTypeForSqlType(
"unsigned int",
"NUMBER(10)");
70 tpc.setCppTypeForSqlType(
"unsigned long long",
"NUMBER(20)");
72 coral::AttributeList bindVariableList;
73 bindVariableList.extend(
"runnumber",
typeid(
unsigned int));
74 bindVariableList[
"runnumber"].data<
unsigned int>()=
runnumber;
76 std::string algoname(
"LEVEL1_TRIGGER_ALGO_CONDITIONS");
77 std::string techname(
"LEVEL1_TRIGGER_TECH_CONDITIONS");
83 std::string runprescalgoviewname(
"GT_RUN_PRESC_ALGO_VIEW");
84 std::string runpresctechviewname(
"GT_RUN_PRESC_TECH_VIEW");
100 algocount.reserve(400);
102 techcount.reserve(400);
104 deadtimeresult.reserve(400);
105 coral::ITransaction&
transaction=trgsession->transaction();
106 transaction.start(
true);
130 coral::ISchema& wbmschemaHandle=trgsession->schema(wbmschema);
131 if(!wbmschemaHandle.existsTable(algoname)){
134 if(!wbmschemaHandle.existsTable(techname)){
137 if(!wbmschemaHandle.existsTable(deadname)){
145 coral::IQuery* Queryalgo=wbmschemaHandle.newQuery();
146 Queryalgo->addToTableList(algoname);
147 coral::AttributeList qalgoOutput;
148 qalgoOutput.extend(
"counts",
typeid(
unsigned int));
149 qalgoOutput.extend(
"lsnr",
typeid(
unsigned int));
150 qalgoOutput.extend(
"algobit",
typeid(
unsigned int));
151 Queryalgo->addToOutputList(
"GTALGOCOUNTS",
"counts");
152 Queryalgo->addToOutputList(
"LUMISEGMENTNR",
"lsnr");
153 Queryalgo->addToOutputList(
"BIT",
"algobit");
154 Queryalgo->setCondition(
"RUNNUMBER =:runnumber",bindVariableList);
155 Queryalgo->addToOrderList(
"LUMISEGMENTNR");
156 Queryalgo->addToOrderList(
"BIT");
157 Queryalgo->defineOutput(qalgoOutput);
158 coral::ICursor&
c=Queryalgo->execute();
161 const coral::AttributeList& row = c.currentRow();
163 unsigned int lsnr=row[
"lsnr"].data<
unsigned int>();
164 unsigned int count=row[
"counts"].data<
unsigned int>();
165 mybitcount_algo.push_back(count);
166 unsigned int algobit=row[
"algobit"].data<
unsigned int>();
170 std::cout<<
"ALGO COUNT alert: found hole in LS range"<<std::endl;
171 std::cout<<
" fill all algocount 0 for LS "<<s<<std::endl;
173 algocount.push_back(tmpzero);
176 algocount.push_back(mybitcount_algo);
177 mybitcount_algo.clear();
183 transaction.commit();
187 transaction.commit();
194 transaction.start(
true);
195 coral::IQuery* Querytech=wbmschemaHandle.newQuery();
196 Querytech->addToTableList(techname);
197 coral::AttributeList qtechOutput;
198 qtechOutput.extend(
"counts",
typeid(
unsigned int));
199 qtechOutput.extend(
"lsnr",
typeid(
unsigned int));
200 qtechOutput.extend(
"techbit",
typeid(
unsigned int));
201 Querytech->addToOutputList(
"GTTECHCOUNTS",
"counts");
202 Querytech->addToOutputList(
"LUMISEGMENTNR",
"lsnr");
203 Querytech->addToOutputList(
"BIT",
"techbit");
204 Querytech->setCondition(
"RUNNUMBER=:runnumber",bindVariableList);
205 Querytech->addToOrderList(
"LUMISEGMENTNR");
206 Querytech->addToOrderList(
"BIT");
207 Querytech->defineOutput(qtechOutput);
208 coral::ICursor& techcursor=Querytech->execute();
211 while( techcursor.next() ){
212 const coral::AttributeList& row = techcursor.currentRow();
214 unsigned int lsnr=row[
"lsnr"].data<
unsigned int>();
215 unsigned int count=row[
"counts"].data<
unsigned int>();
216 unsigned int techbit=row[
"techbit"].data<
unsigned int>();
217 mybitcount_tech.push_back(count);
221 std::cout<<
"TECH COUNT alert: found hole in LS range"<<std::endl;
222 std::cout<<
" fill all techcount with 0 for LS "<<s<<std::endl;
224 techcount.push_back(tmpzero);
227 techcount.push_back(mybitcount_tech);
228 mybitcount_tech.clear();
234 transaction.commit();
238 transaction.commit();
244 transaction.start(
true);
245 coral::IQuery* Querydead=wbmschemaHandle.newQuery();
246 Querydead->addToTableList(deadname);
247 coral::AttributeList qdeadOutput;
248 qdeadOutput.extend(
"counts",
typeid(
unsigned int));
249 qdeadOutput.extend(
"lsnr",
typeid(
unsigned int));
250 Querydead->addToOutputList(
"DEADTIMEBEAMACTIVE",
"counts");
251 Querydead->addToOutputList(
"LUMISEGMENTNR",
"lsnr");
252 coral::AttributeList bindVariablesDead;
253 bindVariablesDead.extend(
"runnumber",
typeid(
int));
254 bindVariablesDead[
"runnumber"].data<
int>()=
runnumber;
255 Querydead->setCondition(
"RUNNUMBER=:runnumber",bindVariablesDead);
256 Querydead->addToOrderList(
"LUMISEGMENTNR");
257 Querydead->defineOutput(qdeadOutput);
258 coral::ICursor& deadcursor=Querydead->execute();
260 while( deadcursor.next() ){
261 const coral::AttributeList& row = deadcursor.currentRow();
264 unsigned int lsnr=row[
"lsnr"].data<
unsigned int>();
266 std::cout<<
"DEADTIME alert: found hole in LS range"<<std::endl;
267 std::cout<<
" fill deadtimebeamactive 0 for LS "<<s<<std::endl;
268 deadtimeresult.push_back(0);
271 unsigned int count=row[
"counts"].data<
unsigned int>();
272 deadtimeresult.push_back(count);
278 transaction.commit();
283 transaction.commit();
289 transaction.start(
true);
290 coral::ISchema& gtschemaHandle=trgsession->schema(gtschema);
291 if(!gtschemaHandle.existsView(runtechviewname)){
294 if(!gtschemaHandle.existsView(runalgoviewname)){
297 if(!gtschemaHandle.existsView(runprescalgoviewname)){
300 if(!gtschemaHandle.existsView(runpresctechviewname)){
306 std::map<unsigned int,std::string> triggernamemap;
307 coral::IQuery* QueryName=gtschemaHandle.newQuery();
308 QueryName->addToTableList(runalgoviewname);
309 coral::AttributeList qAlgoNameOutput;
310 qAlgoNameOutput.extend(
"algo_index",
typeid(
unsigned int));
311 qAlgoNameOutput.extend(
"alias",
typeid(
std::string));
312 QueryName->addToOutputList(
"algo_index");
313 QueryName->addToOutputList(
"alias");
314 QueryName->setCondition(
"runnumber =:runnumber",bindVariableList);
315 QueryName->addToOrderList(
"algo_index");
316 QueryName->defineOutput(qAlgoNameOutput);
317 coral::ICursor& algonamecursor=QueryName->execute();
318 while( algonamecursor.next() ){
319 const coral::AttributeList& row = algonamecursor.currentRow();
321 unsigned int algo_index=row[
"algo_index"].data<
unsigned int>();
323 triggernamemap.insert(std::make_pair(algo_index,algo_name));
327 transaction.commit();
332 transaction.start(
true);
333 std::map<unsigned int,std::string> techtriggernamemap;
334 coral::IQuery* QueryTechName=gtschemaHandle.newQuery();
335 QueryTechName->addToTableList(runtechviewname);
336 coral::AttributeList qTechNameOutput;
337 qTechNameOutput.extend(
"techtrig_index",
typeid(
unsigned int));
338 qTechNameOutput.extend(
"name",
typeid(
std::string));
339 QueryTechName->addToOutputList(
"techtrig_index");
340 QueryTechName->addToOutputList(
"name");
341 QueryTechName->setCondition(
"runnumber =:runnumber",bindVariableList);
342 QueryTechName->addToOrderList(
"techtrig_index");
343 QueryTechName->defineOutput(qTechNameOutput);
344 coral::ICursor& technamecursor=QueryTechName->execute();
345 while( technamecursor.next() ){
346 const coral::AttributeList& row = technamecursor.currentRow();
348 unsigned int tech_index=row[
"techtrig_index"].data<
unsigned int>();
350 techtriggernamemap.insert(std::make_pair(tech_index,tech_name));
352 delete QueryTechName;
353 transaction.commit();
357 transaction.start(
true);
358 coral::IQuery* QueryAlgoPresc=gtschemaHandle.newQuery();
359 QueryAlgoPresc->addToTableList(runprescalgoviewname);
360 coral::AttributeList qAlgoPrescOutput;
361 std::string algoprescBase(
"PRESCALE_FACTOR_ALGO_");
364 qAlgoPrescOutput.extend(algopresc,
typeid(
unsigned int));
368 QueryAlgoPresc->addToOutputList(algopresc);
370 coral::AttributeList PrescbindVariable;
371 PrescbindVariable.extend(
"runnumber",
typeid(
int));
372 PrescbindVariable.extend(
"prescaleindex",
typeid(
int));
373 PrescbindVariable[
"runnumber"].data<
int>()=
runnumber;
374 PrescbindVariable[
"prescaleindex"].data<
int>()=0;
375 QueryAlgoPresc->setCondition(
"runnr =:runnumber AND prescale_index =:prescaleindex",PrescbindVariable);
376 QueryAlgoPresc->defineOutput(qAlgoPrescOutput);
377 coral::ICursor& algopresccursor=QueryAlgoPresc->execute();
378 while( algopresccursor.next() ){
379 const coral::AttributeList& row = algopresccursor.currentRow();
381 for(
unsigned int bitidx=0;bitidx<128;++bitidx){
383 algoprescale.push_back(row[algopresc].data<unsigned int>());
386 delete QueryAlgoPresc;
387 transaction.commit();
392 transaction.start(
true);
393 coral::IQuery* QueryTechPresc=gtschemaHandle.newQuery();
394 QueryTechPresc->addToTableList(runpresctechviewname);
395 coral::AttributeList qTechPrescOutput;
399 qTechPrescOutput.extend(techpresc,
typeid(
unsigned int));
403 QueryTechPresc->addToOutputList(techpresc);
405 coral::AttributeList TechPrescbindVariable;
406 TechPrescbindVariable.extend(
"runnumber",
typeid(
int));
407 TechPrescbindVariable.extend(
"prescaleindex",
typeid(
int));
408 TechPrescbindVariable[
"runnumber"].data<
int>()=
runnumber;
409 TechPrescbindVariable[
"prescaleindex"].data<
int>()=0;
410 QueryTechPresc->setCondition(
"runnr =:runnumber AND prescale_index =:prescaleindex",TechPrescbindVariable);
411 QueryTechPresc->defineOutput(qTechPrescOutput);
412 coral::ICursor& techpresccursor=QueryTechPresc->execute();
413 while( techpresccursor.next() ){
414 const coral::AttributeList& row = techpresccursor.currentRow();
418 techprescale.push_back(row[techpresc].data<unsigned int>());
421 delete QueryTechPresc;
422 transaction.commit();
423 transaction.commit();
431 std::map<unsigned int,std::string>::iterator pos=triggernamemap.find(algoidx);
432 if(pos!=triggernamemap.end()){
433 algonames.push_back(pos->second);
435 algonames.push_back(
"False");
441 std::stringstream
ss;
444 technames.push_back(ss.str());
451 throw lumi::Exception(
"wrong number of bits",
"retrieveData",
"TRGWBM2DB");
453 if(algoprescale.size()!=lumi::N_TRGALGOBIT || techprescale.size()!=
lumi::N_TRGTECHBIT){
454 throw lumi::Exception(
"wrong number of prescale",
"retrieveData",
"TRGWBM2DB");
456 if(deadtimeresult.size()!=algocount.size() || deadtimeresult.size()!=techcount.size()){
457 throw lumi::Exception(
"inconsistent number of LS",
"retrieveData",
"TRGWBM2DB");
462 coral::ISessionProxy* lumisession=svc->connect(
m_dest,coral::Update);
463 coral::ITypeConverter& lumitpc=lumisession->typeConverter();
464 lumitpc.setCppTypeForSqlType(
"unsigned int",
"NUMBER(7)");
465 lumitpc.setCppTypeForSqlType(
"unsigned int",
"NUMBER(10)");
466 lumitpc.setCppTypeForSqlType(
"unsigned long long",
"NUMBER(20)");
468 TriggerDeadCountResult::const_iterator deadIt;
469 TriggerDeadCountResult::const_iterator deadBeg=deadtimeresult.begin();
470 TriggerDeadCountResult::const_iterator deadEnd=deadtimeresult.end();
472 unsigned int totalcmsls=deadtimeresult.size();
473 std::cout<<
"inserting totalcmsls "<<totalcmsls<<std::endl;
474 std::map< unsigned long long, std::vector<unsigned long long> > idallocationtable;
477 lumisession->transaction().start(
false);
480 lumisession->transaction().commit();
481 unsigned int trglscount=0;
482 for(deadIt=deadBeg;deadIt!=deadEnd;++deadIt,++trglscount){
483 std::vector<unsigned long long> bitvec;
484 bitvec.reserve(lumi::N_TRGBIT);
485 BITCOUNT& algoinbits=algocount[trglscount];
486 BITCOUNT& techinbits=techcount[trglscount];
487 BITCOUNT::const_iterator algoBitIt;
488 BITCOUNT::const_iterator algoBitBeg=algoinbits.begin();
489 BITCOUNT::const_iterator algoBitEnd=algoinbits.end();
490 for(algoBitIt=algoBitBeg;algoBitIt!=algoBitEnd;++algoBitIt,++trgID){
491 bitvec.push_back(trgID);
493 BITCOUNT::const_iterator techBitIt;
494 BITCOUNT::const_iterator techBitBeg=techinbits.begin();
495 BITCOUNT::const_iterator techBitEnd=techinbits.end();
496 for(techBitIt=techBitBeg;techBitIt!=techBitEnd;++techBitIt,++trgID){
497 bitvec.push_back(trgID);
499 idallocationtable.insert(std::make_pair(trglscount,bitvec));
501 std::cout<<
"\t all ids allocated"<<std::endl;
502 coral::AttributeList trgData;
503 trgData.extend<
unsigned long long>(
"TRG_ID");
504 trgData.extend<
unsigned int>(
"RUNNUM");
505 trgData.extend<
unsigned int>(
"CMSLSNUM");
506 trgData.extend<
unsigned int>(
"BITNUM");
508 trgData.extend<
unsigned int>(
"TRGCOUNT");
509 trgData.extend<
unsigned long long>(
"DEADTIME");
510 trgData.extend<
unsigned int>(
"PRESCALE");
512 unsigned long long& trg_id=trgData[
"TRG_ID"].data<
unsigned long long>();
513 unsigned int& trgrunnum=trgData[
"RUNNUM"].data<
unsigned int>();
514 unsigned int&
cmslsnum=trgData[
"CMSLSNUM"].data<
unsigned int>();
515 unsigned int& bitnum=trgData[
"BITNUM"].data<
unsigned int>();
517 unsigned int& count=trgData[
"TRGCOUNT"].data<
unsigned int>();
518 unsigned long long& deadtime=trgData[
"DEADTIME"].data<
unsigned long long>();
519 unsigned int& prescale=trgData[
"PRESCALE"].data<
unsigned int>();
522 coral::IBulkOperation* trgInserter=0;
523 unsigned int comittedls=0;
524 for(deadIt=deadBeg;deadIt!=deadEnd;++deadIt,++trglscount ){
525 unsigned int cmslscount=trglscount+1;
526 BITCOUNT& algoinbits=algocount[trglscount];
527 BITCOUNT& techinbits=techcount[trglscount];
528 unsigned int trgbitcount=0;
529 BITCOUNT::const_iterator algoBitIt;
530 BITCOUNT::const_iterator algoBitBeg=algoinbits.begin();
531 BITCOUNT::const_iterator algoBitEnd=algoinbits.end();
532 if(!lumisession->transaction().isActive()){
533 lumisession->transaction().start(
false);
535 trgInserter=trgtable.dataEditor().bulkInsert(trgData,2048);
537 for(algoBitIt=algoBitBeg;algoBitIt!=algoBitEnd;++algoBitIt,++trgbitcount){
538 trg_id = idallocationtable[trglscount].at(trgbitcount);
541 cmslsnum = cmslscount;
543 bitname=algonames[trgbitcount];
545 prescale=algoprescale[trgbitcount];
558 trgInserter->processNextIteration();
561 BITCOUNT::const_iterator techBitIt;
562 BITCOUNT::const_iterator techBitBeg=techinbits.begin();
563 BITCOUNT::const_iterator techBitEnd=techinbits.end();
564 for(techBitIt=techBitBeg;techBitIt!=techBitEnd;++techBitIt,++trgbitcount){
565 trg_id = idallocationtable[trglscount].at(trgbitcount);
568 cmslsnum = cmslscount;
573 trgInserter->processNextIteration();
586 trgInserter->flush();
589 std::cout<<
"\t committing in LS chunck "<<comittedls<<std::endl;
590 delete trgInserter; trgInserter=0;
591 lumisession->transaction().commit();
594 }
else if( trglscount==( totalcmsls-1) ){
595 std::cout<<
"\t committing at the end"<<std::endl;
596 delete trgInserter; trgInserter=0;
597 lumisession->transaction().commit();
602 lumisession->transaction().rollback();
std::vector< BITCOUNT > TriggerCountResult_Tech
static const std::string trgTableName()
std::vector< BITCOUNT > TriggerCountResult_Algo
const unsigned int N_TRGTECHBIT
std::string int2str(unsigned int t, unsigned int width)
std::vector< std::string > TriggerNameResult_Algo
std::vector< std::string > TriggerNameResult_Tech
std::vector< DEADCOUNT > TriggerDeadCountResult
std::vector< unsigned int > PrescaleResult_Tech
unsigned long long generateNextIDForTable(const std::string &tableName, unsigned int interval=1)
static const unsigned int COMMITLSINTERVAL
const unsigned int N_TRGALGOBIT
std::vector< unsigned int > BITCOUNT
const unsigned int N_TRGBIT
std::vector< unsigned int > PrescaleResult_Algo