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();
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();
713 TRGScalers2DB::TriggerDeadCountResult::iterator deadtimesBeg,
714 TRGScalers2DB::TriggerDeadCountResult::iterator deadtimesEnd,
722 unsigned int commitintv) {
723 TRGScalers2DB::TriggerDeadCountResult::iterator deadIt;
725 unsigned int totalcmsls =
std::distance(deadtimesBeg, deadtimesEnd);
726 std::cout <<
"inserting totalcmsls " << totalcmsls << std::endl;
727 std::map<unsigned long long, std::vector<unsigned long long> > idallocationtable;
729 lumisession->transaction().start(
false);
734 unsigned int trglscount = 0;
735 for (deadIt = deadtimesBeg; deadIt != deadtimesEnd; ++deadIt, ++trglscount) {
736 std::vector<unsigned long long> bitvec;
738 const BITCOUNT& algoinbits = algocounts[trglscount];
739 const BITCOUNT& techinbits = techcounts[trglscount];
740 BITCOUNT::const_iterator algoBitIt;
741 BITCOUNT::const_iterator algoBitBeg = algoinbits.begin();
742 BITCOUNT::const_iterator algoBitEnd = algoinbits.end();
743 for (algoBitIt = algoBitBeg; algoBitIt != algoBitEnd; ++algoBitIt, ++trgID) {
744 bitvec.push_back(trgID);
746 BITCOUNT::const_iterator techBitIt;
747 BITCOUNT::const_iterator techBitBeg = techinbits.begin();
748 BITCOUNT::const_iterator techBitEnd = techinbits.end();
749 for (techBitIt = techBitBeg; techBitIt != techBitEnd; ++techBitIt, ++trgID) {
750 bitvec.push_back(trgID);
752 idallocationtable.insert(std::make_pair(trglscount, bitvec));
754 std::cout <<
"\t all ids allocated" << std::endl;
755 coral::AttributeList trgData;
756 trgData.extend<
unsigned long long>(
"TRG_ID");
757 trgData.extend<
unsigned int>(
"RUNNUM");
758 trgData.extend<
unsigned int>(
"CMSLSNUM");
759 trgData.extend<
unsigned int>(
"BITNUM");
761 trgData.extend<
unsigned int>(
"TRGCOUNT");
762 trgData.extend<
unsigned long long>(
"DEADTIME");
763 trgData.extend<
float>(
"DEADFRAC");
764 trgData.extend<
unsigned int>(
"PRESCALE");
766 unsigned long long& trg_id = trgData[
"TRG_ID"].data<
unsigned long long>();
767 unsigned int& trgrunnum = trgData[
"RUNNUM"].data<
unsigned int>();
768 unsigned int& cmslsnum = trgData[
"CMSLSNUM"].data<
unsigned int>();
769 unsigned int& bitnum = trgData[
"BITNUM"].data<
unsigned int>();
771 unsigned int&
count = trgData[
"TRGCOUNT"].data<
unsigned int>();
772 unsigned long long& deadtime = trgData[
"DEADTIME"].data<
unsigned long long>();
773 float& deadfrac = trgData[
"DEADFRAC"].data<
float>();
774 unsigned int&
prescale = trgData[
"PRESCALE"].data<
unsigned int>();
777 coral::IBulkOperation* trgInserter =
nullptr;
778 unsigned int comittedls = 0;
779 for (deadIt = deadtimesBeg; deadIt != deadtimesEnd; ++deadIt, ++trglscount) {
780 unsigned int cmslscount = trglscount + 1;
781 float dfra = deadfracs[trglscount];
782 const BITCOUNT& algoinbits = algocounts[trglscount];
783 const BITCOUNT& techinbits = techcounts[trglscount];
784 unsigned int trgbitcount = 0;
785 BITCOUNT::const_iterator algoBitIt;
786 BITCOUNT::const_iterator algoBitBeg = algoinbits.begin();
787 BITCOUNT::const_iterator algoBitEnd = algoinbits.end();
788 if (!lumisession->transaction().isActive()) {
789 lumisession->transaction().start(
false);
791 trgInserter = trgtable.dataEditor().bulkInsert(trgData, 2048);
793 if (deadIt == deadtimesBeg) {
795 trgInserter = trgtable.dataEditor().bulkInsert(trgData, 2048);
798 for (algoBitIt = algoBitBeg; algoBitIt != algoBitEnd; ++algoBitIt, ++trgbitcount) {
799 trg_id = idallocationtable[trglscount].at(trgbitcount);
803 cmslsnum = cmslscount;
804 bitnum = trgbitcount;
805 bitname = algonames[trgbitcount];
807 prescale = prescalealgo[cmslscount].at(trgbitcount);
809 trgInserter->processNextIteration();
811 BITCOUNT::const_iterator techBitIt;
812 BITCOUNT::const_iterator techBitBeg = techinbits.begin();
813 BITCOUNT::const_iterator techBitEnd = techinbits.end();
814 for (techBitIt = techBitBeg; techBitIt != techBitEnd; ++techBitIt, ++trgbitcount) {
815 trg_id = idallocationtable[trglscount].at(trgbitcount);
819 cmslsnum = cmslscount;
820 bitnum = trgbitcount;
824 trgInserter->processNextIteration();
826 trgInserter->flush();
828 if (comittedls == commitintv) {
829 std::cout <<
"\t committing in LS chunck " << comittedls << std::endl;
831 trgInserter =
nullptr;
832 lumisession->transaction().commit();
834 std::cout <<
"\t committed " << std::endl;
835 }
else if (trglscount == (totalcmsls - 1)) {
836 std::cout <<
"\t committing at the end" << std::endl;
838 trgInserter =
nullptr;
839 lumisession->transaction().commit();
845 unsigned int irunnumber,
847 TriggerDeadCountResult::iterator deadtimesBeg,
848 TriggerDeadCountResult::iterator deadtimesEnd,
856 unsigned int commitintv) {
857 TRGScalers2DB::TriggerDeadCountResult::iterator deadIt;
858 unsigned int totalcmsls =
std::distance(deadtimesBeg, deadtimesEnd);
859 std::cout <<
"inserting totalcmsls " << totalcmsls << std::endl;
860 coral::AttributeList lstrgData;
861 lstrgData.extend<
unsigned long long>(
"DATA_ID");
862 lstrgData.extend<
unsigned int>(
"RUNNUM");
863 lstrgData.extend<
unsigned int>(
"CMSLSNUM");
864 lstrgData.extend<
unsigned long long>(
"DEADTIMECOUNT");
865 lstrgData.extend<
unsigned int>(
"BITZEROCOUNT");
866 lstrgData.extend<
unsigned int>(
"BITZEROPRESCALE");
867 lstrgData.extend<
float>(
"DEADFRAC");
868 lstrgData.extend<coral::Blob>(
"PRESCALEBLOB");
869 lstrgData.extend<coral::Blob>(
"TRGCOUNTBLOB");
871 unsigned long long& data_id = lstrgData[
"DATA_ID"].data<
unsigned long long>();
872 unsigned int& trgrunnum = lstrgData[
"RUNNUM"].data<
unsigned int>();
873 unsigned int& cmslsnum = lstrgData[
"CMSLSNUM"].data<
unsigned int>();
874 unsigned long long& deadtime = lstrgData[
"DEADTIMECOUNT"].data<
unsigned long long>();
875 unsigned int& bitzerocount = lstrgData[
"BITZEROCOUNT"].data<
unsigned int>();
876 unsigned int& bitzeroprescale = lstrgData[
"BITZEROPRESCALE"].data<
unsigned int>();
877 float& deadfrac = lstrgData[
"DEADFRAC"].data<
float>();
878 coral::Blob& prescaleblob = lstrgData[
"PRESCALEBLOB"].data<coral::Blob>();
879 coral::Blob& trgcountblob = lstrgData[
"TRGCOUNTBLOB"].data<coral::Blob>();
881 unsigned long long branch_id = 3;
885 std::stringstream op;
888 lumisession->transaction().start(
false);
893 TriggerNameResult_Algo::iterator bitnameIt;
894 TriggerNameResult_Algo::iterator bitnameItBeg = algonames.begin();
895 TriggerNameResult_Algo::iterator bitnameItEnd = algonames.end();
896 for (bitnameIt = bitnameItBeg; bitnameIt != bitnameItEnd; ++bitnameIt) {
897 if (bitnameIt != bitnameItBeg) {
900 bitnames += *bitnameIt;
902 TriggerNameResult_Tech::iterator techbitnameIt;
903 TriggerNameResult_Tech::iterator techbitnameItBeg = technames.begin();
904 TriggerNameResult_Tech::iterator techbitnameItEnd = technames.end();
905 for (techbitnameIt = techbitnameItBeg; techbitnameIt != techbitnameItEnd; ++techbitnameIt) {
907 bitnames += *techbitnameIt;
909 std::cout <<
"\tbitnames " << bitnames << std::endl;
917 <<
" data_id " << trgrundata.
data_id << std::endl;
923 <<
" data_id " << trgrundata.
data_id << std::endl;
927 std::cout <<
"inserting trgrundata " << std::endl;
929 std::cout <<
"inserting lstrg data" << std::endl;
931 unsigned int trglscount = 0;
933 coral::IBulkOperation* lstrgInserter =
nullptr;
934 unsigned int comittedls = 0;
935 for (deadIt = deadtimesBeg; deadIt != deadtimesEnd; ++deadIt, ++trglscount) {
936 unsigned int cmslscount = trglscount + 1;
937 if (!lumisession->transaction().isActive()) {
938 lumisession->transaction().start(
false);
940 lstrgInserter = lstrgtable.dataEditor().bulkInsert(lstrgData, 2048);
942 if (deadIt == deadtimesBeg) {
944 lstrgInserter = lstrgtable.dataEditor().bulkInsert(lstrgData, 2048);
948 trgrunnum = irunnumber;
949 cmslsnum = cmslscount;
951 deadfrac = deadfracs[trglscount];
954 bitzerocount = techcounts[trglscount][4];
955 bitzeroprescale = prescaletech[cmslsnum][4];
956 std::vector<unsigned int> fullprescales;
957 fullprescales.reserve(prescalealgo[cmslsnum].
size() + prescaletech[cmslsnum].
size());
958 fullprescales.insert(fullprescales.end(), prescalealgo[cmslsnum].begin(), prescalealgo[cmslsnum].end());
959 fullprescales.insert(fullprescales.end(), prescaletech[cmslsnum].begin(), prescaletech[cmslsnum].end());
961 prescaleblob.resize(
sizeof(
unsigned int) * (fullprescales.size()));
962 void* prescaleblob_StartAddress = prescaleblob.startingAddress();
963 std::memmove(prescaleblob_StartAddress, &fullprescales[0],
sizeof(
unsigned int) * (fullprescales.size()));
965 std::vector<unsigned int> fullcounts;
966 fullcounts.reserve(algocounts[trglscount].
size() + techcounts[trglscount].
size());
967 fullcounts.insert(fullcounts.end(), algocounts[trglscount].begin(), algocounts[trglscount].end());
968 fullcounts.insert(fullcounts.end(), techcounts[trglscount].begin(), techcounts[trglscount].end());
969 trgcountblob.resize(
sizeof(
unsigned int) * (fullcounts.size()));
970 void* trgcountblob_StartAddress = trgcountblob.startingAddress();
971 std::memmove(trgcountblob_StartAddress, &fullcounts[0],
sizeof(
unsigned int) * (fullcounts.size()));
973 lstrgInserter->processNextIteration();
974 lstrgInserter->flush();
976 if (comittedls == commitintv) {
977 std::cout <<
"\t committing in LS chunck " << comittedls << std::endl;
978 delete lstrgInserter;
979 lstrgInserter =
nullptr;
980 lumisession->transaction().commit();
982 std::cout <<
"\t committed " << std::endl;
983 }
else if (trglscount == (totalcmsls - 1)) {
984 std::cout <<
"\t committing at the end" << std::endl;
985 delete lstrgInserter;
986 lstrgInserter =
nullptr;
987 lumisession->transaction().commit();
998 std::stringstream
ss;
1005 std::istringstream myStream(
s);
1007 if (myStream >>
i) {
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
const std::string sourceType() const override
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)
std::map< unsigned int, std::vector< unsigned int > > PrescaleResult_Tech
std::vector< std::string > TriggerNameResult_Tech
std::vector< BITCOUNT > TriggerCountResult_Tech
static const std::string lstrgTableName()
static const unsigned int COMMITLSINTERVAL
~TRGScalers2DB() override
std::vector< unsigned int > BITCOUNT
const std::string dataType() const override
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
std::map< unsigned int, std::vector< unsigned int > > PrescaleResult_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)
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)
unsigned long long retrieveData(unsigned int runnumber) override
#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)
static std::string const source
const unsigned int N_TRGBIT
unsigned int str2int(const std::string &s)
void bookNewRevision(coral::ISchema &schema, const std::string &datatableName, Entry &revision)