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();
227 delete Queryalgoview;
234 coral::IQuery* Querytechview = gtmonschemaHandle.newQuery();
235 Querytechview->addToTableList(techviewname);
236 coral::AttributeList qtechOutput;
237 qtechOutput.extend(
"COUNT_BX",
typeid(
unsigned int));
238 qtechOutput.extend(
"LUMI_SECTION",
typeid(
unsigned int));
239 qtechOutput.extend(
"SCALER_INDEX",
typeid(
unsigned int));
240 Querytechview->addToOutputList(
"COUNT_BX");
241 Querytechview->addToOutputList(
"LUMI_SECTION");
242 Querytechview->addToOutputList(
"SCALER_INDEX");
243 Querytechview->setCondition(
"RUN_NUMBER=:runnumber", bindVariableList);
244 Querytechview->addToOrderList(
"LUMI_SECTION");
245 Querytechview->addToOrderList(
"SCALER_INDEX");
246 Querytechview->defineOutput(qtechOutput);
247 coral::ICursor& techcursor = Querytechview->execute();
249 while (techcursor.next()) {
250 const coral::AttributeList& row = techcursor.currentRow();
252 unsigned int lsnr = row[
"LUMI_SECTION"].data<
unsigned int>();
253 unsigned int count = row[
"COUNT_BX"].data<
unsigned int>();
254 unsigned int techbit = row[
"SCALER_INDEX"].data<
unsigned int>();
255 mybitcount_tech.push_back(
count);
259 std::cout <<
"TECH COUNT alert: found hole in LS range " <<
s << std::endl;
260 std::cout <<
" fill all techcount with 0 for LS " <<
s << std::endl;
262 techcount.push_back(tmpzero);
265 techcount.push_back(mybitcount_tech);
266 mybitcount_tech.clear();
271 delete Querytechview;
272 transaction.commit();
277 delete Querytechview;
284 coral::IQuery* Querydeadview = gtmonschemaHandle.newQuery();
285 Querydeadview->addToTableList(deadviewname);
286 coral::AttributeList qdeadOutput;
287 qdeadOutput.extend(
"FRACTION",
typeid(
float));
288 qdeadOutput.extend(
"LUMI_SECTION",
typeid(
unsigned int));
289 qdeadOutput.extend(
"COUNT_BX",
typeid(
unsigned int));
290 Querydeadview->addToOutputList(
"FRACTION");
291 Querydeadview->addToOutputList(
"LUMI_SECTION");
292 Querydeadview->addToOutputList(
"COUNT_BX");
293 coral::AttributeList bindVariablesDead;
294 bindVariablesDead.extend(
"runnumber",
typeid(
int));
295 bindVariablesDead.extend(
"scalername",
typeid(
std::string));
296 bindVariablesDead[
"runnumber"].data<
int>() =
runnumber;
298 Querydeadview->setCondition(
"RUN_NUMBER=:runnumber AND SCALER_NAME=:scalername", bindVariablesDead);
299 Querydeadview->addToOrderList(
"LUMI_SECTION");
300 Querydeadview->defineOutput(qdeadOutput);
301 coral::ICursor& deadcursor = Querydeadview->execute();
303 while (deadcursor.next()) {
304 const coral::AttributeList& row = deadcursor.currentRow();
307 unsigned int lsnr = row[
"LUMI_SECTION"].data<
unsigned int>();
309 unsigned int count = 0;
311 std::cout <<
"DEADTIME alert: found hole in LS range" <<
s << std::endl;
312 std::cout <<
" fill deadtimefraction 0%, deadtimebeamactive 0 for LS " <<
s << std::endl;
313 deadfracresult.push_back(dfrac);
314 deadtimeresult.push_back(
count);
317 if (!row[
"FRACTION"].isNull()) {
318 dfrac = row[
"FRACTION"].data<
float>();
320 std::cout <<
"DEADTIME fraction alert: undefined fraction , assume 100% , LS " << lsnr << std::endl;
323 std::cout <<
"DEADTIME fraction alert: overflow dead fraction , force to 100% , LS " << lsnr << std::endl;
326 deadfracresult.push_back(dfrac);
327 count = row[
"COUNT_BX"].data<
unsigned int>();
328 deadtimeresult.push_back(
count);
332 delete Querydeadview;
333 transaction.commit();
339 delete Querydeadview;
344 std::vector<int> prescidx;
345 coral::IQuery* allpsidxQuery = gtmonschemaHandle.newQuery();
346 allpsidxQuery->addToTableList(lstablename);
347 coral::AttributeList allpsidxOutput;
348 allpsidxOutput.extend(
"psidx",
typeid(
int));
349 allpsidxQuery->addToOutputList(
"distinct(PRESCALE_INDEX)",
"psidx");
350 coral::AttributeList bindVariablesAllpsidx;
351 bindVariablesAllpsidx.extend(
"runnumber",
typeid(
int));
352 bindVariablesAllpsidx[
"runnumber"].data<
int>() =
runnumber;
353 allpsidxQuery->setCondition(
"RUN_NUMBER =:runnumber", bindVariablesAllpsidx);
354 allpsidxQuery->defineOutput(allpsidxOutput);
355 coral::ICursor& allpsidxCursor = allpsidxQuery->execute();
356 while (allpsidxCursor.next()) {
357 const coral::AttributeList& row = allpsidxCursor.currentRow();
358 int psidx = row[
"psidx"].data<
int>();
359 prescidx.push_back(psidx);
361 delete allpsidxQuery;
362 std::map<int, std::vector<unsigned int> > algoprescMap;
363 std::map<int, std::vector<unsigned int> > techprescMap;
364 std::vector<int>::iterator prescidxIt;
365 std::vector<int>::iterator prescidxItBeg = prescidx.begin();
366 std::vector<int>::iterator prescidxItEnd = prescidx.end();
367 for (prescidxIt = prescidxItBeg; prescidxIt != prescidxItEnd; ++prescidxIt) {
368 std::vector<unsigned int> algopres;
370 std::vector<unsigned int> techpres;
372 algoprescMap.insert(std::make_pair(*prescidxIt, algopres));
373 techprescMap.insert(std::make_pair(*prescidxIt, techpres));
379 std::map<unsigned int, int> lsprescmap;
380 coral::IQuery* lstoprescQuery = gtmonschemaHandle.newQuery();
381 lstoprescQuery->addToTableList(lstablename);
382 coral::AttributeList lstoprescOutput;
383 lstoprescOutput.extend(
"lumisection",
typeid(
unsigned int));
384 lstoprescOutput.extend(
"psidx",
typeid(
int));
385 lstoprescQuery->addToOutputList(
"LUMI_SECTION",
"lumisection");
386 lstoprescQuery->addToOutputList(
"PRESCALE_INDEX",
"psidx");
387 coral::AttributeList bindVariablesLstopresc;
388 bindVariablesLstopresc.extend(
"runnumber",
typeid(
int));
389 bindVariablesLstopresc[
"runnumber"].data<
int>() =
runnumber;
390 lstoprescQuery->setCondition(
"RUN_NUMBER =:runnumber", bindVariablesLstopresc);
391 lstoprescQuery->defineOutput(lstoprescOutput);
392 unsigned int lsprescount = 0;
393 unsigned int lastpresc = 0;
394 coral::ICursor& lstoprescCursor = lstoprescQuery->execute();
395 while (lstoprescCursor.next()) {
397 const coral::AttributeList& row = lstoprescCursor.currentRow();
398 unsigned int lumisection = row[
"lumisection"].data<
unsigned int>();
399 while (lsprescount != lumisection) {
400 std::cout <<
"PRESCALE_INDEX COUNT alert: found hole in LS range " << lsprescount << std::endl;
401 std::cout <<
" fill this prescale from last availabl prescale " << lastpresc << std::endl;
402 unsigned int guesspsidx = lastpresc;
403 lsprescmap.insert(std::make_pair(lsprescount, guesspsidx));
406 int psidx = row[
"psidx"].data<
int>();
407 lsprescmap.insert(std::make_pair(lumisection, psidx));
410 if (lsprescount == 0) {
411 lstoprescCursor.close();
412 delete lstoprescQuery;
413 transaction.commit();
419 delete lstoprescQuery;
421 for (prescidxIt = prescidxItBeg; prescidxIt != prescidxItEnd; ++prescidxIt) {
422 std::vector<unsigned int> algopres;
424 std::vector<unsigned int> techpres;
426 algoprescMap.insert(std::make_pair(*prescidxIt, algopres));
427 techprescMap.insert(std::make_pair(*prescidxIt, techpres));
435 coral::ISchema& gtschemaHandle = trgsession->schema(gtschema);
436 if (!gtschemaHandle.existsView(runtechviewname)) {
439 if (!gtschemaHandle.existsView(runalgoviewname)) {
442 if (!gtschemaHandle.existsView(runprescalgoviewname)) {
445 if (!gtschemaHandle.existsView(runpresctechviewname)) {
451 std::map<unsigned int, std::string> triggernamemap;
452 coral::IQuery* QueryName = gtschemaHandle.newQuery();
453 QueryName->addToTableList(runalgoviewname);
454 coral::AttributeList qAlgoNameOutput;
455 qAlgoNameOutput.extend(
"ALGO_INDEX",
typeid(
unsigned int));
456 qAlgoNameOutput.extend(
"ALIAS",
typeid(
std::string));
457 QueryName->addToOutputList(
"ALGO_INDEX");
458 QueryName->addToOutputList(
"ALIAS");
459 QueryName->setCondition(
"RUNNUMBER=:runnumber", bindVariableList);
461 QueryName->defineOutput(qAlgoNameOutput);
462 coral::ICursor& algonamecursor = QueryName->execute();
463 while (algonamecursor.next()) {
464 const coral::AttributeList& row = algonamecursor.currentRow();
466 unsigned int algo_index = row[
"ALGO_INDEX"].data<
unsigned int>();
468 triggernamemap.insert(std::make_pair(algo_index,
algo_name));
475 std::map<unsigned int, std::string> techtriggernamemap;
476 coral::IQuery* QueryTechName = gtschemaHandle.newQuery();
477 QueryTechName->addToTableList(runtechviewname);
478 coral::AttributeList qTechNameOutput;
479 qTechNameOutput.extend(
"TECHTRIG_INDEX",
typeid(
unsigned int));
480 qTechNameOutput.extend(
"NAME",
typeid(
std::string));
481 QueryTechName->addToOutputList(
"TECHTRIG_INDEX");
482 QueryTechName->addToOutputList(
"NAME");
483 QueryTechName->setCondition(
"RUNNUMBER=:runnumber", bindVariableList);
485 QueryTechName->defineOutput(qTechNameOutput);
486 coral::ICursor& technamecursor = QueryTechName->execute();
487 while (technamecursor.next()) {
488 const coral::AttributeList& row = technamecursor.currentRow();
490 unsigned int tech_index = row[
"TECHTRIG_INDEX"].data<
unsigned int>();
492 techtriggernamemap.insert(std::make_pair(tech_index, tech_name));
494 delete QueryTechName;
501 std::vector<int>::iterator presIt;
502 std::vector<int>::iterator presItBeg = prescidx.begin();
503 std::vector<int>::iterator presItEnd = prescidx.end();
504 for (presIt = presItBeg; presIt != presItEnd; ++presIt) {
505 coral::IQuery* QueryAlgoPresc = gtschemaHandle.newQuery();
506 QueryAlgoPresc->addToTableList(runprescalgoviewname);
507 coral::AttributeList qAlgoPrescOutput;
508 std::string algoprescBase(
"PRESCALE_FACTOR_ALGO_");
511 qAlgoPrescOutput.extend(algopresc,
typeid(
unsigned int));
515 QueryAlgoPresc->addToOutputList(algopresc);
517 coral::AttributeList PrescbindVariable;
518 PrescbindVariable.extend(
"runnumber",
typeid(
int));
519 PrescbindVariable.extend(
"prescaleindex",
typeid(
int));
520 PrescbindVariable[
"runnumber"].data<
int>() =
runnumber;
521 PrescbindVariable[
"prescaleindex"].data<
int>() = *presIt;
522 QueryAlgoPresc->setCondition(
"RUNNR=:runnumber AND PRESCALE_INDEX=:prescaleindex", PrescbindVariable);
523 QueryAlgoPresc->defineOutput(qAlgoPrescOutput);
524 coral::ICursor& algopresccursor = QueryAlgoPresc->execute();
525 while (algopresccursor.next()) {
526 const coral::AttributeList& row = algopresccursor.currentRow();
529 algoprescMap[*presIt].push_back(row[algopresc].data<unsigned int>());
532 delete QueryAlgoPresc;
537 for (presIt = presItBeg; presIt != presItEnd; ++presIt) {
538 coral::IQuery* QueryTechPresc = gtschemaHandle.newQuery();
539 QueryTechPresc->addToTableList(runpresctechviewname);
540 coral::AttributeList qTechPrescOutput;
544 qTechPrescOutput.extend(techpresc,
typeid(
unsigned int));
548 QueryTechPresc->addToOutputList(techpresc);
550 coral::AttributeList TechPrescbindVariable;
551 TechPrescbindVariable.extend(
"runnumber",
typeid(
int));
552 TechPrescbindVariable.extend(
"prescaleindex",
typeid(
int));
553 TechPrescbindVariable[
"runnumber"].data<
int>() =
runnumber;
554 TechPrescbindVariable[
"prescaleindex"].data<
int>() = *presIt;
555 QueryTechPresc->setCondition(
"RUNNR=:runnumber AND PRESCALE_INDEX=:prescaleindex", TechPrescbindVariable);
556 QueryTechPresc->defineOutput(qTechPrescOutput);
557 coral::ICursor& techpresccursor = QueryTechPresc->execute();
558 while (techpresccursor.next()) {
559 const coral::AttributeList& row = techpresccursor.currentRow();
563 techprescMap[*presIt].push_back(row[techpresc].data<unsigned int>());
566 delete QueryTechPresc;
568 transaction.commit();
571 std::map<unsigned int, int>::iterator lsprescmapIt;
572 std::map<unsigned int, int>::iterator lsprescmapItBeg = lsprescmap.begin();
573 std::map<unsigned int, int>::iterator lsprescmapItEnd = lsprescmap.end();
574 for (lsprescmapIt = lsprescmapItBeg; lsprescmapIt != lsprescmapItEnd; ++lsprescmapIt) {
575 unsigned int ls = lsprescmapIt->first;
576 int preidx = lsprescmapIt->second;
577 algoprescale.insert(std::make_pair(
ls, algoprescMap[preidx]));
578 techprescale.insert(std::make_pair(
ls, techprescMap[preidx]));
580 algoprescMap.clear();
581 techprescMap.clear();
586 std::map<unsigned int, std::string>::iterator
pos = triggernamemap.find(algoidx);
587 if (
pos != triggernamemap.end()) {
588 algonames.push_back(
pos->second);
590 algonames.push_back(
"False");
596 std::stringstream
ss;
599 technames.push_back(
ss.str());
606 throw lumi::Exception(
"wrong number of bits",
"retrieveData",
"TRG2DB");
611 if (deadtimeresult.size() != deadfracresult.size() || deadtimeresult.size() != algocount.size() ||
612 deadtimeresult.size() != techcount.size() || deadtimeresult.size() != algoprescale.size() ||
613 deadtimeresult.size() != techprescale.size()) {
616 <<
"[WARNING] inconsistent number of LS of deadtimecounter,deadfrac,algo,tech,prescalealgo,prescaletech "
617 << deadtimeresult.size() <<
" " << deadfracresult.size() <<
" " << algocount.size() <<
" " << techcount.size()
618 <<
" " << algoprescale.size() <<
" " << techprescale.size() << std::endl;
619 TRGScalers2DB::TriggerDeadCountResult::iterator dIt;
620 TRGScalers2DB::TriggerDeadCountResult::iterator dBeg = deadtimeresult.begin();
621 TRGScalers2DB::TriggerDeadCountResult::iterator dEnd = deadtimeresult.end();
622 unsigned int dcnt = 0;
623 for (dIt = dBeg; dIt != dEnd; ++dIt) {
625 deadfracresult.at(dcnt);
626 }
catch (std::out_of_range& er) {
627 std::cout <<
"[WARNING] filling FAKE deadfrac=0.0 at LS " << dcnt << std::endl;
628 deadfracresult[dcnt] = 0.0;
632 }
catch (std::out_of_range& er) {
634 std::cout <<
"[WARNING] filling FAKE algocount at LS " << dcnt << std::endl;
635 algocount[dcnt] = tmpzero;
639 }
catch (std::out_of_range& er) {
641 std::cout <<
"[WARNING] filling FAKE techcount at LS " << dcnt << std::endl;
642 techcount[dcnt] = tmpzero;
644 if (algoprescale.find(dcnt + 1) == algoprescale.end()) {
646 std::cout <<
"[WARNING] filling FAKE 1 algoprescale at LS " << dcnt + 1 << std::endl;
647 algoprescale[dcnt + 1] = tmpzero;
649 if (techprescale.find(dcnt + 1) == techprescale.end()) {
651 std::cout <<
"[WARNING] filling FAKE 1 techprescale at LS " << dcnt + 1 << std::endl;
652 techprescale[dcnt + 1] = tmpzero;
660 unsigned long long trgdataid = 0;
661 coral::ISessionProxy* lumisession = svc->connect(
m_dest, coral::Update);
662 coral::ITypeConverter& lumitpc = lumisession->typeConverter();
663 lumitpc.setCppTypeForSqlType(
"unsigned int",
"NUMBER(7)");
664 lumitpc.setCppTypeForSqlType(
"unsigned int",
"NUMBER(10)");
665 lumitpc.setCppTypeForSqlType(
"unsigned long long",
"NUMBER(20)");
667 if (
m_mode ==
"loadoldschema") {
668 std::cout <<
"writing trg data to old trg table " << std::endl;
672 deadtimeresult.begin(),
673 deadtimeresult.end(),
684 std::cout <<
"writing trg data to new lstrg table " << std::endl;
688 deadtimeresult.begin(),
689 deadtimeresult.end(),
702 std::cout <<
"database error " << er.what() << std::endl;
703 lumisession->transaction().rollback();