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;
75 std::string gtmonschema(
"CMS_GT_MON");
76 std::string algoviewname(
"GT_MON_TRIG_ALGO_VIEW");
77 std::string techviewname(
"GT_MON_TRIG_TECH_VIEW");
78 std::string deadviewname(
"GT_MON_TRIG_DEAD_VIEW");
79 std::string celltablename(
"GT_CELL_LUMISEG");
81 std::string gtschema(
"CMS_GT");
82 std::string runtechviewname(
"GT_RUN_TECH_VIEW");
83 std::string runalgoviewname(
"GT_RUN_ALGO_VIEW");
84 std::string runprescalgoviewname(
"GT_RUN_PRESC_ALGO_VIEW");
85 std::string runpresctechviewname(
"GT_RUN_PRESC_TECH_VIEW");
101 algocount.reserve(400);
103 techcount.reserve(400);
105 deadtimeresult.reserve(400);
106 coral::ITransaction&
transaction=trgsession->transaction();
107 transaction.start(
true);
130 coral::ISchema& gtmonschemaHandle=trgsession->schema(gtmonschema);
131 if(!gtmonschemaHandle.existsView(algoviewname)){
132 throw lumi::Exception(std::string(
"non-existing view ")+algoviewname,
"retrieveData",
"TRG2DB");
134 if(!gtmonschemaHandle.existsView(techviewname)){
135 throw lumi::Exception(std::string(
"non-existing view ")+techviewname,
"retrieveData",
"TRG2DB");
137 if(!gtmonschemaHandle.existsView(deadviewname)){
138 throw lumi::Exception(std::string(
"non-existing view ")+deadviewname,
"retrieveData",
"TRG2DB");
140 if(!gtmonschemaHandle.existsTable(celltablename)){
141 throw lumi::Exception(std::string(
"non-existing table ")+celltablename,
"retrieveData",
"TRG2DB");
148 coral::IQuery* Queryalgoview=gtmonschemaHandle.newQuery();
149 Queryalgoview->addToTableList(algoviewname);
150 coral::AttributeList qalgoOutput;
151 qalgoOutput.extend(
"counts",
typeid(
unsigned int));
152 qalgoOutput.extend(
"lsnr",
typeid(
unsigned int));
153 qalgoOutput.extend(
"algobit",
typeid(
unsigned int));
154 Queryalgoview->addToOutputList(
"counts");
155 Queryalgoview->addToOutputList(
"lsnr");
156 Queryalgoview->addToOutputList(
"algobit");
157 Queryalgoview->setCondition(
"RUNNR =:runnumber",bindVariableList);
158 Queryalgoview->addToOrderList(
"lsnr");
159 Queryalgoview->addToOrderList(
"algobit");
160 Queryalgoview->defineOutput(qalgoOutput);
161 coral::ICursor&
c=Queryalgoview->execute();
165 const coral::AttributeList& row = c.currentRow();
167 unsigned int lsnr=row[
"lsnr"].data<
unsigned int>();
168 unsigned int count=row[
"counts"].data<
unsigned int>();
169 unsigned int algobit=row[
"algobit"].data<
unsigned int>();
170 mybitcount_algo.push_back(count);
174 std::cout<<
"ALGO COUNT alert: found hole in LS range"<<std::endl;
175 std::cout<<
" fill all algocount 0 for LS "<<s<<std::endl;
177 algocount.push_back(tmpzero);
180 algocount.push_back(mybitcount_algo);
181 mybitcount_algo.clear();
186 delete Queryalgoview;
187 transaction.commit();
188 throw lumi::Exception(std::string(
"requested run ")+runnumberstr+std::string(
" doesn't exist for algocounts"),
"retrieveData",
"TRG2DB");
190 delete Queryalgoview;
196 coral::IQuery* Querytechview=gtmonschemaHandle.newQuery();
197 Querytechview->addToTableList(techviewname);
198 coral::AttributeList qtechOutput;
199 qtechOutput.extend(
"counts",
typeid(
unsigned int));
200 qtechOutput.extend(
"lsnr",
typeid(
unsigned int));
201 qtechOutput.extend(
"techbit",
typeid(
unsigned int));
202 Querytechview->addToOutputList(
"counts");
203 Querytechview->addToOutputList(
"lsnr");
204 Querytechview->addToOutputList(
"techbit");
205 Querytechview->setCondition(
"RUNNR =:runnumber",bindVariableList);
206 Querytechview->addToOrderList(
"lsnr");
207 Querytechview->addToOrderList(
"techbit");
208 Querytechview->defineOutput(qtechOutput);
209 coral::ICursor& techcursor=Querytechview->execute();
212 while( techcursor.next() ){
213 const coral::AttributeList& row = techcursor.currentRow();
215 unsigned int lsnr=row[
"lsnr"].data<
unsigned int>();
216 unsigned int count=row[
"counts"].data<
unsigned int>();
217 unsigned int techbit=row[
"techbit"].data<
unsigned int>();
218 mybitcount_tech.push_back(count);
222 std::cout<<
"TECH COUNT alert: found hole in LS range"<<std::endl;
223 std::cout<<
" fill all techcount with 0 for LS "<<s<<std::endl;
225 techcount.push_back(tmpzero);
228 techcount.push_back(mybitcount_tech);
229 mybitcount_tech.clear();
234 delete Querytechview;
235 transaction.commit();
236 throw lumi::Exception(std::string(
"requested run ")+runnumberstr+std::string(
" doesn't exist for techcounts"),
"retrieveData",
"TRG2DB");
238 delete Querytechview;
244 coral::IQuery* Querydeadview=gtmonschemaHandle.newQuery();
245 Querydeadview->addToTableList(deadviewname);
246 coral::AttributeList qdeadOutput;
247 qdeadOutput.extend(
"counts",
typeid(
unsigned int));
248 qdeadOutput.extend(
"lsnr",
typeid(
unsigned int));
249 Querydeadview->addToOutputList(
"counts");
250 Querydeadview->addToOutputList(
"lsnr");
251 coral::AttributeList bindVariablesDead;
252 bindVariablesDead.extend(
"runnumber",
typeid(
int));
253 bindVariablesDead.extend(
"countername",
typeid(std::string));
254 bindVariablesDead[
"runnumber"].data<
int>()=
runnumber;
255 bindVariablesDead[
"countername"].data<std::string>()=std::string(
"DeadtimeBeamActive");
256 Querydeadview->setCondition(
"RUNNR =:runnumber AND DEADCOUNTER =:countername",bindVariablesDead);
257 Querydeadview->addToOrderList(
"lsnr");
258 Querydeadview->defineOutput(qdeadOutput);
259 coral::ICursor& deadcursor=Querydeadview->execute();
261 while( deadcursor.next() ){
262 const coral::AttributeList& row = deadcursor.currentRow();
265 unsigned int lsnr=row[
"lsnr"].data<
unsigned int>();
267 std::cout<<
"DEADTIME alert: found hole in LS range"<<std::endl;
268 std::cout<<
" fill deadtimebeamactive 0 for LS "<<s<<std::endl;
269 deadtimeresult.push_back(0);
272 unsigned int count=row[
"counts"].data<
unsigned int>();
273 deadtimeresult.push_back(count);
277 delete Querydeadview;
278 transaction.commit();
279 throw lumi::Exception(std::string(
"requested run ")+runnumberstr+std::string(
" doesn't exist for deadcounts"),
"retrieveData",
"TRG2DB");
282 delete Querydeadview;
288 coral::ISchema& gtschemaHandle=trgsession->schema(gtschema);
289 if(!gtschemaHandle.existsView(runtechviewname)){
290 throw lumi::Exception(std::string(
"non-existing view ")+runtechviewname,
"str2int",
"TRG2DB");
292 if(!gtschemaHandle.existsView(runalgoviewname)){
293 throw lumi::Exception(std::string(
"non-existing view ")+runalgoviewname,
"str2int",
"TRG2DB");
295 if(!gtschemaHandle.existsView(runprescalgoviewname)){
296 throw lumi::Exception(std::string(
"non-existing view ")+runprescalgoviewname,
"str2int",
"TRG2DB");
298 if(!gtschemaHandle.existsView(runpresctechviewname)){
299 throw lumi::Exception(std::string(
"non-existing view ")+runpresctechviewname,
"str2int",
"TRG2DB");
304 std::map<unsigned int,std::string> triggernamemap;
305 coral::IQuery* QueryName=gtschemaHandle.newQuery();
306 QueryName->addToTableList(runalgoviewname);
307 coral::AttributeList qAlgoNameOutput;
308 qAlgoNameOutput.extend(
"algo_index",
typeid(
unsigned int));
309 qAlgoNameOutput.extend(
"alias",
typeid(std::string));
310 QueryName->addToOutputList(
"algo_index");
311 QueryName->addToOutputList(
"alias");
312 QueryName->setCondition(
"runnumber =:runnumber",bindVariableList);
313 QueryName->addToOrderList(
"algo_index");
314 QueryName->defineOutput(qAlgoNameOutput);
315 coral::ICursor& algonamecursor=QueryName->execute();
316 while( algonamecursor.next() ){
317 const coral::AttributeList& row = algonamecursor.currentRow();
319 unsigned int algo_index=row[
"algo_index"].data<
unsigned int>();
320 std::string
algo_name=row[
"alias"].data<std::string>();
321 triggernamemap.insert(std::make_pair(algo_index,algo_name));
327 std::map<unsigned int,std::string> techtriggernamemap;
328 coral::IQuery* QueryTechName=gtschemaHandle.newQuery();
329 QueryTechName->addToTableList(runtechviewname);
330 coral::AttributeList qTechNameOutput;
331 qTechNameOutput.extend(
"techtrig_index",
typeid(
unsigned int));
332 qTechNameOutput.extend(
"name",
typeid(std::string));
333 QueryTechName->addToOutputList(
"techtrig_index");
334 QueryTechName->addToOutputList(
"name");
335 QueryTechName->setCondition(
"runnumber =:runnumber",bindVariableList);
336 QueryTechName->addToOrderList(
"techtrig_index");
337 QueryTechName->defineOutput(qTechNameOutput);
338 coral::ICursor& technamecursor=QueryTechName->execute();
339 while( technamecursor.next() ){
340 const coral::AttributeList& row = technamecursor.currentRow();
342 unsigned int tech_index=row[
"techtrig_index"].data<
unsigned int>();
343 std::string tech_name=row[
"name"].data<std::string>();
344 techtriggernamemap.insert(std::make_pair(tech_index,tech_name));
346 delete QueryTechName;
350 coral::IQuery* QueryAlgoPresc=gtschemaHandle.newQuery();
351 QueryAlgoPresc->addToTableList(runprescalgoviewname);
352 coral::AttributeList qAlgoPrescOutput;
353 std::string algoprescBase(
"PRESCALE_FACTOR_ALGO_");
355 std::string algopresc=algoprescBase+
int2str(bitidx,3);
356 qAlgoPrescOutput.extend(algopresc,
typeid(
unsigned int));
359 std::string algopresc=algoprescBase+
int2str(bitidx,3);
360 QueryAlgoPresc->addToOutputList(algopresc);
362 coral::AttributeList PrescbindVariable;
363 PrescbindVariable.extend(
"runnumber",
typeid(
int));
364 PrescbindVariable.extend(
"prescaleindex",
typeid(
int));
365 PrescbindVariable[
"runnumber"].data<
int>()=
runnumber;
366 PrescbindVariable[
"prescaleindex"].data<
int>()=0;
367 QueryAlgoPresc->setCondition(
"runnr =:runnumber AND prescale_index =:prescaleindex",PrescbindVariable);
368 QueryAlgoPresc->defineOutput(qAlgoPrescOutput);
369 coral::ICursor& algopresccursor=QueryAlgoPresc->execute();
370 while( algopresccursor.next() ){
371 const coral::AttributeList& row = algopresccursor.currentRow();
373 for(
unsigned int bitidx=0;bitidx<128;++bitidx){
374 std::string algopresc=algoprescBase+
int2str(bitidx,3);
375 algoprescale.push_back(row[algopresc].data<unsigned int>());
378 delete QueryAlgoPresc;
382 coral::IQuery* QueryTechPresc=gtschemaHandle.newQuery();
383 QueryTechPresc->addToTableList(runpresctechviewname);
384 coral::AttributeList qTechPrescOutput;
385 std::string techprescBase(
"PRESCALE_FACTOR_TT_");
387 std::string techpresc=techprescBase+this->
int2str(bitidx,3);
388 qTechPrescOutput.extend(techpresc,
typeid(
unsigned int));
391 std::string techpresc=techprescBase+
int2str(bitidx,3);
392 QueryTechPresc->addToOutputList(techpresc);
394 coral::AttributeList TechPrescbindVariable;
395 TechPrescbindVariable.extend(
"runnumber",
typeid(
int));
396 TechPrescbindVariable.extend(
"prescaleindex",
typeid(
int));
397 TechPrescbindVariable[
"runnumber"].data<
int>()=
runnumber;
398 TechPrescbindVariable[
"prescaleindex"].data<
int>()=0;
399 QueryTechPresc->setCondition(
"runnr =:runnumber AND prescale_index =:prescaleindex",TechPrescbindVariable);
400 QueryTechPresc->defineOutput(qTechPrescOutput);
401 coral::ICursor& techpresccursor=QueryTechPresc->execute();
402 while( techpresccursor.next() ){
403 const coral::AttributeList& row = techpresccursor.currentRow();
406 std::string techpresc=techprescBase+
int2str(bitidx,3);
407 techprescale.push_back(row[techpresc].data<unsigned int>());
410 delete QueryTechPresc;
411 transaction.commit();
417 std::map<unsigned int,std::string>::iterator
pos=triggernamemap.find(algoidx);
418 if(pos!=triggernamemap.end()){
419 algonames.push_back(pos->second);
421 algonames.push_back(
"False");
427 std::stringstream ss;
429 std::map<unsigned int,std::string>::iterator pos=techtriggernamemap.find(techidx);
431 technames.push_back(ss.str());
440 if(algoprescale.size()!=lumi::N_TRGALGOBIT || techprescale.size()!=
lumi::N_TRGTECHBIT){
441 throw lumi::Exception(
"wrong number of prescale",
"retrieveData",
"TRG2DB");
443 if(deadtimeresult.size()!=algocount.size() || deadtimeresult.size()!=techcount.size()){
444 throw lumi::Exception(
"inconsistent number of LS",
"retrieveData",
"TRG2DB");
449 coral::ISessionProxy* lumisession=svc->connect(
m_dest,coral::Update);
450 coral::ITypeConverter& lumitpc=lumisession->typeConverter();
451 lumitpc.setCppTypeForSqlType(
"unsigned int",
"NUMBER(7)");
452 lumitpc.setCppTypeForSqlType(
"unsigned int",
"NUMBER(10)");
453 lumitpc.setCppTypeForSqlType(
"unsigned long long",
"NUMBER(20)");
455 TriggerDeadCountResult::const_iterator deadIt;
456 TriggerDeadCountResult::const_iterator deadBeg=deadtimeresult.begin();
457 TriggerDeadCountResult::const_iterator deadEnd=deadtimeresult.end();
459 unsigned int totalcmsls=deadtimeresult.size();
460 std::cout<<
"inserting totalcmsls "<<totalcmsls<<std::endl;
461 std::map< unsigned long long, std::vector<unsigned long long> > idallocationtable;
464 lumisession->transaction().start(
false);
467 lumisession->transaction().commit();
468 unsigned int trglscount=0;
469 for(deadIt=deadBeg;deadIt!=deadEnd;++deadIt,++trglscount){
470 std::vector<unsigned long long> bitvec;
471 bitvec.reserve(lumi::N_TRGBIT);
472 BITCOUNT& algoinbits=algocount[trglscount];
473 BITCOUNT& techinbits=techcount[trglscount];
474 BITCOUNT::const_iterator algoBitIt;
475 BITCOUNT::const_iterator algoBitBeg=algoinbits.begin();
476 BITCOUNT::const_iterator algoBitEnd=algoinbits.end();
477 for(algoBitIt=algoBitBeg;algoBitIt!=algoBitEnd;++algoBitIt,++trgID){
478 bitvec.push_back(trgID);
480 BITCOUNT::const_iterator techBitIt;
481 BITCOUNT::const_iterator techBitBeg=techinbits.begin();
482 BITCOUNT::const_iterator techBitEnd=techinbits.end();
483 for(techBitIt=techBitBeg;techBitIt!=techBitEnd;++techBitIt,++trgID){
484 bitvec.push_back(trgID);
486 idallocationtable.insert(std::make_pair(trglscount,bitvec));
488 std::cout<<
"\t all ids allocated"<<std::endl;
489 coral::AttributeList trgData;
490 trgData.extend<
unsigned long long>(
"TRG_ID");
491 trgData.extend<
unsigned int>(
"RUNNUM");
492 trgData.extend<
unsigned int>(
"CMSLSNUM");
493 trgData.extend<
unsigned int>(
"BITNUM");
494 trgData.extend<std::string>(
"BITNAME");
495 trgData.extend<
unsigned int>(
"TRGCOUNT");
496 trgData.extend<
unsigned long long>(
"DEADTIME");
497 trgData.extend<
unsigned int>(
"PRESCALE");
499 unsigned long long& trg_id=trgData[
"TRG_ID"].data<
unsigned long long>();
500 unsigned int& trgrunnum=trgData[
"RUNNUM"].data<
unsigned int>();
501 unsigned int& cmslsnum=trgData[
"CMSLSNUM"].data<
unsigned int>();
502 unsigned int& bitnum=trgData[
"BITNUM"].data<
unsigned int>();
503 std::string& bitname=trgData[
"BITNAME"].data<std::string>();
504 unsigned int& count=trgData[
"TRGCOUNT"].data<
unsigned int>();
505 unsigned long long& deadtime=trgData[
"DEADTIME"].data<
unsigned long long>();
506 unsigned int& prescale=trgData[
"PRESCALE"].data<
unsigned int>();
509 coral::IBulkOperation* trgInserter=0;
510 unsigned int comittedls=0;
511 for(deadIt=deadBeg;deadIt!=deadEnd;++deadIt,++trglscount ){
512 unsigned int cmslscount=trglscount+1;
513 BITCOUNT& algoinbits=algocount[trglscount];
514 BITCOUNT& techinbits=techcount[trglscount];
515 unsigned int trgbitcount=0;
516 BITCOUNT::const_iterator algoBitIt;
517 BITCOUNT::const_iterator algoBitBeg=algoinbits.begin();
518 BITCOUNT::const_iterator algoBitEnd=algoinbits.end();
519 if(!lumisession->transaction().isActive()){
520 lumisession->transaction().start(
false);
522 trgInserter=trgtable.dataEditor().bulkInsert(trgData,2048);
524 for(algoBitIt=algoBitBeg;algoBitIt!=algoBitEnd;++algoBitIt,++trgbitcount){
525 trg_id = idallocationtable[trglscount].at(trgbitcount);
528 cmslsnum = cmslscount;
530 bitname=algonames[trgbitcount];
532 prescale=algoprescale[trgbitcount];
533 trgInserter->processNextIteration();
535 BITCOUNT::const_iterator techBitIt;
536 BITCOUNT::const_iterator techBitBeg=techinbits.begin();
537 BITCOUNT::const_iterator techBitEnd=techinbits.end();
538 for(techBitIt=techBitBeg;techBitIt!=techBitEnd;++techBitIt,++trgbitcount){
539 trg_id = idallocationtable[trglscount].at(trgbitcount);
542 cmslsnum = cmslscount;
547 trgInserter->processNextIteration();
549 trgInserter->flush();
552 std::cout<<
"\t committing in LS chunck "<<comittedls<<std::endl;
553 delete trgInserter; trgInserter=0;
554 lumisession->transaction().commit();
557 }
else if( trglscount==( totalcmsls-1) ){
558 std::cout<<
"\t committing at the end"<<std::endl;
559 delete trgInserter; trgInserter=0;
560 lumisession->transaction().commit();
565 lumisession->transaction().rollback();
571 lumisession->transaction().commit();
std::vector< std::string > TriggerNameResult_Algo
static const std::string trgTableName()
std::vector< BITCOUNT > TriggerCountResult_Algo
std::vector< unsigned int > PrescaleResult_Tech
std::vector< unsigned int > PrescaleResult_Algo
std::vector< BITCOUNT > TriggerCountResult_Tech
std::vector< unsigned int > BITCOUNT
std::vector< DEADCOUNT > TriggerDeadCountResult
std::string int2str(unsigned int t, unsigned int width)
const unsigned int N_TRGTECHBIT
static const unsigned int COMMITLSINTERVAL
std::vector< std::string > TriggerNameResult_Tech
unsigned long long generateNextIDForTable(const std::string &tableName, unsigned int interval=1)
const unsigned int N_TRGALGOBIT
const unsigned int N_TRGBIT