25 #include "RelationalAccess/ISchema.h"
26 #include "RelationalAccess/ITable.h"
27 #include "RelationalAccess/ICursor.h"
28 #include "RelationalAccess/IQuery.h"
29 #include "RelationalAccess/TableDescription.h"
30 #include "RelationalAccess/ITableDataEditor.h"
31 #include "CoralBase/AttributeList.h"
32 #include "CoralBase/AttributeSpecification.h"
33 #include "CoralBase/Attribute.h"
34 #include "CoralBase/TimeStamp.h"
50 : dataTag(ps.getParameter<std::
string>(
"tag")),
51 onlineConnect(ps.getParameter<std::
string>(
"onlineDB")),
52 utilConnect(ps.getParameter<std::
string>(
"utilDB")),
53 onlineAuthentication(ps.getParameter<std::
string>(
"onlineAuthentication")),
54 bufferConnect(ps.getParameter<std::
string>(
"bufferDB")),
55 ySince(ps.getParameter<int>(
"sinceYear")),
56 mSince(ps.getParameter<int>(
"sinceMonth")),
57 dSince(ps.getParameter<int>(
"sinceDay")),
58 hSince(ps.getParameter<int>(
"sinceHour")),
59 pSince(ps.getParameter<int>(
"sinceMinute")),
60 sSince(ps.getParameter<int>(
"sinceSecond")),
61 yUntil(ps.getParameter<int>(
"untilYear")),
62 mUntil(ps.getParameter<int>(
"untilMonth")),
63 dUntil(ps.getParameter<int>(
"untilDay")),
64 hUntil(ps.getParameter<int>(
"untilHour")),
65 pUntil(ps.getParameter<int>(
"untilMinute")),
66 sUntil(ps.getParameter<int>(
"untilSecond")),
67 dumpAtStart(ps.getParameter<bool>(
"dumpAtStart")),
68 dumpAtEnd(ps.getParameter<bool>(
"dumpAtEnd")),
69 bwdTime(ps.getParameter<long long int>(
"bwdTime")),
70 fwdTime(ps.getParameter<long long int>(
"fwdTime")),
71 minTime(ps.getParameter<long long int>(
"minTime")),
75 mapVersion(ps.getParameter<std::
string>(
"mapVersion")),
76 splitVersion(ps.getParameter<std::
string>(
"splitVersion")) {
91 std::cout <<
"get new objects..." << std::endl;
94 std::cout <<
"configure omds DbConnection" << std::endl;
99 std::cout <<
"create omds DbSession" << std::endl;
101 std::cout <<
"start omds transaction" << std::endl;
106 std::cout <<
"create util DbSession" << std::endl;
108 std::cout <<
"startutil transaction" << std::endl;
113 std::cout <<
"create buffer DbSession" << std::endl;
115 std::cout <<
"start buffer transaction" << std::endl;
123 std::cout <<
"latest DCS data (HV) already copied until: " << last << std::endl;
139 std::cout <<
"no old data... " << last << std::endl;
144 while (paylIter != paylIend) {
145 const std::pair<DTHVStatusId, DTHVStatusData>&
entry = *paylIter++;
152 coral::TimeStamp coralLast =
coralTime(last);
157 std::cout <<
"Required time interval in the future: " << std::endl
159 <<
" current time " << coralProc.year() <<
" " << coralProc.month() <<
" " << coralProc.day()
169 std::cout <<
"Required time interval already copied: " << std::endl
171 <<
" data until " << coralLast.year() <<
" " << coralLast.month() <<
" " << coralLast.day()
175 std::cout <<
"Required time interval not contiguous with copied data: " << std::endl
176 <<
" data until " << coralLast.year() <<
" " << coralLast.month() <<
" " << coralLast.day() << std::endl
205 std::set<std::string>::const_iterator omds_iter = omds_lt.begin();
206 std::set<std::string>::const_iterator omds_iend = omds_lt.end();
207 while (omds_iter != omds_iend) {
209 std::cout <<
"TABLE: " << istr << std::endl;
213 std::set<std::string>::const_iterator util_iter = util_lt.begin();
214 std::set<std::string>::const_iterator util_iend = util_lt.end();
215 while (util_iter != util_iend) {
217 std::cout <<
"TABLE: " << istr << std::endl;
224 std::cout <<
"open buffer db..." << std::endl;
239 std::cout <<
"retrieve aliases table..." << std::endl;
241 std::unique_ptr<coral::IQuery> hvalQuery(hvalTable.newQuery());
242 hvalQuery->addToOutputList(
"DETID");
243 hvalQuery->addToOutputList(
"DPID");
244 coral::ICursor& hvalCursor = hvalQuery->execute();
247 while (hvalCursor.next()) {
248 chId = hvalCursor.currentRow()[
"DETID"].data<
int>();
249 dpId = hvalCursor.currentRow()[
"DPID"].data<
int>();
250 aliasMap.insert(std::pair<int, int>(dpId, chId));
251 layerMap.insert(std::pair<int, int>(chId, dpId));
259 std::cout <<
"retrieve layer split table..." << std::endl;
269 std::cout <<
" layer split table got..." << std::endl;
270 std::unique_ptr<coral::IQuery> lsplQuery(lsplTable.newQuery());
271 coral::AttributeList versionBindVariableList;
272 versionBindVariableList.extend(
"version",
typeid(
std::string));
274 lsplQuery->setCondition(
"VERSION=:version", versionBindVariableList);
275 lsplQuery->addToOutputList(
"WHEEL");
276 lsplQuery->addToOutputList(
"SECTOR");
277 lsplQuery->addToOutputList(
"STATION");
278 lsplQuery->addToOutputList(
"SUPERLAYER");
279 lsplQuery->addToOutputList(
"LAYER");
280 lsplQuery->addToOutputList(
"PART");
281 lsplQuery->addToOutputList(
"FIRST_CELL");
282 lsplQuery->addToOutputList(
"LAST_CELL");
283 coral::ICursor& lsplCursor = lsplQuery->execute();
284 while (lsplCursor.next()) {
285 whe = lsplCursor.currentRow()[
"WHEEL"].data<
int>();
286 sec = lsplCursor.currentRow()[
"SECTOR"].data<
int>();
287 sta = lsplCursor.currentRow()[
"STATION"].data<
int>();
288 qua = lsplCursor.currentRow()[
"SUPERLAYER"].data<
int>();
289 lay = lsplCursor.currentRow()[
"LAYER"].data<
int>();
290 l_p = lsplCursor.currentRow()[
"PART"].data<
int>();
291 f_c = lsplCursor.currentRow()[
"FIRST_CELL"].data<
int>();
292 l_c = lsplCursor.currentRow()[
"LAST_CELL"].data<
int>();
293 DTWireId wireId(whe, sta, sec, qua, lay, 10 + l_p);
294 laySplit.insert(std::pair<int, int>(wireId.rawId(), (f_c * 10000) + l_c));
296 std::cout <<
"channel split table retrieved" << std::endl;
301 std::cout <<
"retrieve channel split table..." << std::endl;
315 std::unique_ptr<coral::IQuery> csplQuery(csplTable.newQuery());
316 coral::AttributeList versionBindVariableList;
317 versionBindVariableList.extend(
"version",
typeid(
std::string));
319 csplQuery->setCondition(
"VERSION=:version", versionBindVariableList);
320 csplQuery->addToOutputList(
"P_WHEEL");
321 csplQuery->addToOutputList(
"P_SECTOR");
322 csplQuery->addToOutputList(
"P_STATION");
323 csplQuery->addToOutputList(
"P_SUPERLAYER");
324 csplQuery->addToOutputList(
"P_LAYER");
325 csplQuery->addToOutputList(
"P_PART");
326 csplQuery->addToOutputList(
"S_NUMBER");
327 csplQuery->addToOutputList(
"S_WHEEL");
328 csplQuery->addToOutputList(
"S_SECTOR");
329 csplQuery->addToOutputList(
"S_STATION");
330 csplQuery->addToOutputList(
"S_SUPERLAYER");
331 csplQuery->addToOutputList(
"S_LAYER");
332 csplQuery->addToOutputList(
"S_PART");
333 coral::ICursor& csplCursor = csplQuery->execute();
334 while (csplCursor.next()) {
335 pwhe = csplCursor.currentRow()[
"P_WHEEL"].data<
int>();
336 psec = csplCursor.currentRow()[
"P_SECTOR"].data<
int>();
337 psta = csplCursor.currentRow()[
"P_STATION"].data<
int>();
338 pqua = csplCursor.currentRow()[
"P_SUPERLAYER"].data<
int>();
339 play = csplCursor.currentRow()[
"P_LAYER"].data<
int>();
340 pl_p = csplCursor.currentRow()[
"P_PART"].data<
int>();
341 csplCursor.currentRow()[
"S_NUMBER"].data<
int>();
342 swhe = csplCursor.currentRow()[
"S_WHEEL"].data<
int>();
343 ssec = csplCursor.currentRow()[
"S_SECTOR"].data<
int>();
344 ssta = csplCursor.currentRow()[
"S_STATION"].data<
int>();
345 squa = csplCursor.currentRow()[
"S_SUPERLAYER"].data<
int>();
346 slay = csplCursor.currentRow()[
"S_LAYER"].data<
int>();
347 sl_p = csplCursor.currentRow()[
"S_PART"].data<
int>();
348 DTWireId pId(pwhe, psta, psec, pqua, play, 10 + pl_p);
349 DTWireId sId(swhe, ssta, ssec, squa, slay, 10 + sl_p);
350 int pRaw = pId.rawId();
351 int sRaw = sId.
rawId();
353 std::map<int, std::vector<int>*>::iterator iter =
channelSplit.find(pRaw);
354 std::map<int, std::vector<int>*>::iterator iend =
channelSplit.end();
356 channelSplit.insert(std::pair<
int, std::vector<int>*>(pRaw, splitList =
new std::vector<int>));
358 splitList = iter->second;
360 splitList->push_back(sRaw);
366 std::cout <<
"DTHVStatusHandler::dumpHVAliases - begin" << std::endl;
368 std::cout <<
"create aliases description..." << std::endl;
369 coral::TableDescription hvalDesc;
370 hvalDesc.setName(
"HVALIASES");
371 hvalDesc.insertColumn(
"DETID", coral::AttributeSpecification::typeNameForId(
typeid(
int)));
372 hvalDesc.insertColumn(
"DPID", coral::AttributeSpecification::typeNameForId(
typeid(
int)));
373 std::cout <<
"create aliases table..." << std::endl;
376 std::cout <<
"open DPNAME table..." << std::endl;
377 std::map<int, std::string> idMap;
379 std::unique_ptr<coral::IQuery> dpidQuery(dpidTable.newQuery());
380 dpidQuery->addToOutputList(
"ID");
381 dpidQuery->addToOutputList(
"DPNAME");
382 coral::ICursor& dpidCursor = dpidQuery->execute();
383 while (dpidCursor.next()) {
384 const coral::AttributeList& row = dpidCursor.currentRow();
385 int id =
static_cast<int>(0.01 + row[
"ID"].data<
float>());
387 idMap.insert(std::pair<int, std::string>(
id, dp));
389 std::cout <<
"DPNAME table read... " << idMap.size() << std::endl;
391 std::cout <<
"open ALIASES table..." << std::endl;
392 std::map<std::string, std::string> cnMap;
394 std::unique_ptr<coral::IQuery> nameQuery(nameTable.newQuery());
395 nameQuery->addToOutputList(
"DPE_NAME");
396 nameQuery->addToOutputList(
"ALIAS");
397 coral::ICursor& nameCursor = nameQuery->execute();
398 while (nameCursor.next()) {
399 const coral::AttributeList& row = nameCursor.currentRow();
402 if (an.length() < 20)
404 cnMap.insert(std::pair<std::string, std::string>(dp, an));
406 std::cout <<
"ALIASES table read... " << cnMap.size() << std::endl;
408 std::map<int, std::string>::const_iterator idIter = idMap.begin();
409 std::map<int, std::string>::const_iterator idIend = idMap.end();
411 while (idIter != idIend) {
412 const std::pair<int, std::string>& ientry = *idIter++;
413 int dpId = ientry.first;
415 int ldp = dp.length();
420 if (subChk != outChk)
423 chName +=
".actual.OvC";
424 int chCode = subOut.c_str()[16] -
'0';
425 std::map<std::string, std::string>::const_iterator jter = cnMap.find(chName);
426 if (jter == cnMap.end())
428 const std::pair<std::string, std::string>& jentry = *jter;
429 std::cout << dp << std::endl << chName <<
" " << chCode << std::endl;
431 int al = an.length();
432 int iofw = 7 + an.find(
"DT_HV_W", 0);
433 int iofc = 3 + an.find(
"_MB", 0);
434 int iofs = 2 + an.find(
"_S", 0);
435 int iofq = 3 + an.find(
"_SL", 0);
436 int iofl = 2 + an.find(
"_L", 0);
437 if ((iofw == al) || (iofc == al) || (iofs == al) || (iofq == al) || (iofl == al)) {
440 int ioew = an.find(
'_', iofw);
441 int ioec = an.find(
'_', iofc);
442 int ioes = an.find(
'_', iofs);
443 int ioeq = an.find(
'_', iofq);
444 int ioel = an.find(
'_', iofl);
446 const char* cwhe = swhe.c_str();
447 int whe = cwhe[1] -
'0';
452 const char* ccha = scha.c_str();
453 int cha = *ccha -
'0';
456 const char* csec = ssec.c_str();
457 int sec = ((*csec -
'0') * 10) + (csec[1] -
'0');
458 if ((csec[2] ==
'R') && (sec == 10))
460 if ((csec[2] ==
'L') && (sec == 4))
464 const char* cqua = squa.c_str();
465 int qua = *cqua -
'0';
468 const char* clay = slay.c_str();
469 int lay = *clay -
'0';
471 DTWireId wireId(whe, cha, sec, qua, lay, 10 + chCode);
472 int chId = wireId.
rawId();
473 coral::AttributeList newChan;
474 newChan.extend(
"DETID",
typeid(
int));
475 newChan.extend(
"DPID",
typeid(
int));
476 newChan[
"DETID"].data<
int>() = chId;
477 newChan[
"DPID"].data<
int>() = dpId;
478 hvalTable.dataEditor().insertRow(newChan);
479 aliasMap.insert(std::pair<int, int>(dpId, chId));
480 layerMap.insert(std::pair<int, int>(chId, dpId));
483 std::cout <<
"DTHVStatusHandler::dumpHVAliases - end" << std::endl;
488 std::cout <<
"create snapshot description..." << std::endl;
489 coral::TableDescription hvssDesc;
490 hvssDesc.setName(
"HVSNAPSHOT");
491 hvssDesc.insertColumn(
"TIME", coral::AttributeSpecification::typeNameForId(
typeid(coral::TimeStamp)));
492 hvssDesc.insertColumn(
"WHEEL", coral::AttributeSpecification::typeNameForId(
typeid(
int)));
493 hvssDesc.insertColumn(
"STATION", coral::AttributeSpecification::typeNameForId(
typeid(
int)));
494 hvssDesc.insertColumn(
"SECTOR", coral::AttributeSpecification::typeNameForId(
typeid(
int)));
495 hvssDesc.insertColumn(
"SUPERLAYER", coral::AttributeSpecification::typeNameForId(
typeid(
int)));
496 hvssDesc.insertColumn(
"LAYER", coral::AttributeSpecification::typeNameForId(
typeid(
int)));
497 hvssDesc.insertColumn(
"CHAN", coral::AttributeSpecification::typeNameForId(
typeid(
int)));
498 hvssDesc.insertColumn(
"TYPE", coral::AttributeSpecification::typeNameForId(
typeid(
int)));
499 hvssDesc.insertColumn(
"VALUE", coral::AttributeSpecification::typeNameForId(
typeid(
float)));
500 std::cout <<
"create snapshot table..." << std::endl;
503 coral::AttributeList newMeas;
504 newMeas.extend(
"TIME",
typeid(coral::TimeStamp));
505 newMeas.extend(
"WHEEL",
typeid(
int));
506 newMeas.extend(
"STATION",
typeid(
int));
507 newMeas.extend(
"SECTOR",
typeid(
int));
508 newMeas.extend(
"SUPERLAYER",
typeid(
int));
509 newMeas.extend(
"LAYER",
typeid(
int));
510 newMeas.extend(
"CHAN",
typeid(
int));
511 newMeas.extend(
"TYPE",
typeid(
int));
512 newMeas.extend(
"VALUE",
typeid(
float));
514 long long int zeroTime = 0LL;
515 newMeas[
"TIME"].data<coral::TimeStamp>() = coral::TimeStamp(zeroTime);
516 newMeas[
"VALUE"].data<
float>() = -999999.0;
518 std::map<int, int>::const_iterator iter =
aliasMap.begin();
519 std::map<int, int>::const_iterator iend =
aliasMap.end();
520 while (iter != iend) {
521 const std::pair<int, int>&
entry = *iter++;
522 int detId = entry.second;
524 newMeas[
"WHEEL"].data<
int>() = chlId.
wheel();
525 newMeas[
"STATION"].data<
int>() = chlId.
station();
526 newMeas[
"SECTOR"].data<
int>() = chlId.
sector();
527 newMeas[
"SUPERLAYER"].data<
int>() = chlId.
superLayer();
528 newMeas[
"LAYER"].data<
int>() = chlId.
layer();
529 newMeas[
"CHAN"].data<
int>() = chlId.
wire() - 10;
531 for (itype = 1; itype <= 2; itype++) {
532 newMeas[
"TYPE"].data<
int>() = itype;
533 bufferTable.dataEditor().insertRow(newMeas);
537 std::cout <<
"create logging info..." << std::endl;
540 coral::TableDescription infoDesc;
541 infoDesc.setName(
"LOG");
542 infoDesc.insertColumn(
"EXECTIME", coral::AttributeSpecification::typeNameForId(
typeid(coral::TimeStamp)));
543 infoDesc.insertColumn(
"SNAPSHOT", coral::AttributeSpecification::typeNameForId(
typeid(coral::TimeStamp)));
545 coral::AttributeList newInfo;
546 newInfo.extend(
"EXECTIME",
typeid(coral::TimeStamp));
547 newInfo.extend(
"SNAPSHOT",
typeid(coral::TimeStamp));
548 newInfo[
"EXECTIME"].data<coral::TimeStamp>() = coral::TimeStamp(zeroTime);
549 newInfo[
"SNAPSHOT"].data<coral::TimeStamp>() = coral::TimeStamp(zeroTime);
551 infoTable.dataEditor().insertRow(newInfo);
559 std::cout <<
" snapshot at " << snapshotTime <<
" ( " <<
coralTime(snapshotTime).total_nanoseconds() <<
" ) "
562 coral::TimeStamp coralSnap =
coralTime(snapshotTime);
563 std::cout <<
"too recent snapshot: " << std::endl
564 <<
" snapshot at " << coralSnap.year() <<
" " << coralSnap.month() <<
" " << coralSnap.day() << std::endl
573 while (missingChannels) {
574 std::cout <<
"back iteration: " << condSince <<
" ( " <<
coralTime(condSince).total_nanoseconds() <<
" ) -> "
575 << condUntil <<
" ( " <<
coralTime(condUntil).total_nanoseconds() <<
" ) " << std::endl;
576 if (condSince <= snapshotTime)
577 condSince = snapshotTime;
578 std::cout <<
"corrected since: " << condSince <<
" ( " <<
coralTime(condSince).total_nanoseconds() <<
" ) "
580 if (condSince >= condUntil)
582 std::cout <<
"missing... " << missingChannels << std::endl;
584 condUntil = condSince;
585 condSince = condUntil - dTime;
600 int missingChannels = 0;
601 std::map<int, int>::const_iterator layIter =
layerMap.begin();
602 std::map<int, int>::const_iterator layIend =
layerMap.end();
603 std::cout <<
"retrieve snapshot table..." << std::endl;
605 std::unique_ptr<coral::IQuery> hvssQuery(hvssTable.newQuery());
606 hvssQuery->addToOutputList(
"TIME");
607 hvssQuery->addToOutputList(
"WHEEL");
608 hvssQuery->addToOutputList(
"STATION");
609 hvssQuery->addToOutputList(
"SECTOR");
610 hvssQuery->addToOutputList(
"SUPERLAYER");
611 hvssQuery->addToOutputList(
"LAYER");
612 hvssQuery->addToOutputList(
"CHAN");
613 hvssQuery->addToOutputList(
"TYPE");
614 hvssQuery->addToOutputList(
"VALUE");
615 coral::ICursor& hvssCursor = hvssQuery->execute();
616 while (hvssCursor.next()) {
617 coral::TimeStamp time = hvssCursor.currentRow()[
"TIME"].data<coral::TimeStamp>();
618 int whe = hvssCursor.currentRow()[
"WHEEL"].data<
int>();
619 int sta = hvssCursor.currentRow()[
"STATION"].data<
int>();
620 int sec = hvssCursor.currentRow()[
"SECTOR"].data<
int>();
621 int qua = hvssCursor.currentRow()[
"SUPERLAYER"].data<
int>();
622 int lay = hvssCursor.currentRow()[
"LAYER"].data<
int>();
623 int l_p = hvssCursor.currentRow()[
"CHAN"].data<
int>();
624 int mty = hvssCursor.currentRow()[
"TYPE"].data<
int>();
625 float value = hvssCursor.currentRow()[
"VALUE"].data<
float>();
628 DTWireId wireId(whe, sta, sec, qua, lay, 10 + l_p);
630 if (layIter == layIend) {
633 int dpId = (layIter->second * 10) + mty;
637 return missingChannels;
641 long long int lastTime = 0LL;
642 long long int chanTime = 0LL;
643 std::map<int, timedMeasurement>::iterator mapIter =
snapshotValues.begin();
644 std::map<int, timedMeasurement>::iterator mapIend =
snapshotValues.end();
645 while (mapIter != mapIend) {
646 const std::pair<int, timedMeasurement>&
entry = *mapIter++;
647 chanTime = entry.second.first;
648 if (lastTime < chanTime)
667 std::cout <<
"dump snapshot to buffer db..." << std::endl;
669 coral::AttributeList emptyBindVariableList;
670 std::map<int, int>::const_iterator mapIter =
aliasMap.begin();
671 std::map<int, int>::const_iterator mapIend =
aliasMap.end();
673 coral::ITableDataEditor& hvssEditor(hvssTable.dataEditor());
674 long nRows = hvssEditor.deleteRows(emptyCondition, emptyBindVariableList);
675 std::cout << nRows <<
" rows deleted" << std::endl;
677 coral::AttributeList newMeas;
678 newMeas.extend(
"TIME",
typeid(coral::TimeStamp));
679 newMeas.extend(
"WHEEL",
typeid(
int));
680 newMeas.extend(
"STATION",
typeid(
int));
681 newMeas.extend(
"SECTOR",
typeid(
int));
682 newMeas.extend(
"SUPERLAYER",
typeid(
int));
683 newMeas.extend(
"LAYER",
typeid(
int));
684 newMeas.extend(
"CHAN",
typeid(
int));
685 newMeas.extend(
"TYPE",
typeid(
int));
686 newMeas.extend(
"VALUE",
typeid(
float));
689 std::map<int, timedMeasurement>::const_iterator ssvIter =
snapshotValues.begin();
690 std::map<int, timedMeasurement>::const_iterator ssvIend =
snapshotValues.end();
691 while (ssvIter != ssvIend) {
692 const std::pair<int, timedMeasurement>&
entry = *ssvIter++;
693 int dpty = entry.first;
694 int dpId = dpty / 10;
695 int type = dpty % 10;
697 if (mapIter == mapIend)
701 long long int newTime = tMeas.first;
702 newMeas[
"TIME"].data<coral::TimeStamp>() = coral::TimeStamp(newTime);
703 newMeas[
"WHEEL"].data<
int>() = chlId.
wheel();
704 newMeas[
"STATION"].data<
int>() = chlId.
station();
705 newMeas[
"SECTOR"].data<
int>() = chlId.
sector();
706 newMeas[
"SUPERLAYER"].data<
int>() = chlId.
superLayer();
707 newMeas[
"LAYER"].data<
int>() = chlId.
layer();
708 newMeas[
"CHAN"].data<
int>() = chlId.
wire() - 10;
709 newMeas[
"TYPE"].data<
int>() = type;
710 newMeas[
"VALUE"].data<
float>() = tMeas.second;
711 hvssEditor.insertRow(newMeas);
714 std::cout << nRows <<
" rows updated" << std::endl;
716 std::cout <<
"create logging info..." << std::endl;
719 coral::TableDescription infoDesc;
720 infoDesc.setName(
"LOG");
721 infoDesc.insertColumn(
"EXECTIME", coral::AttributeSpecification::typeNameForId(
typeid(coral::TimeStamp)));
722 infoDesc.insertColumn(
"SNAPSHOT", coral::AttributeSpecification::typeNameForId(
typeid(coral::TimeStamp)));
724 coral::AttributeList newInfo;
725 newInfo.extend(
"EXECTIME",
typeid(coral::TimeStamp));
726 newInfo.extend(
"SNAPSHOT",
typeid(coral::TimeStamp));
728 newInfo[
"SNAPSHOT"].data<coral::TimeStamp>() = time;
730 infoTable.dataEditor().insertRow(newInfo);
737 int& missingChannels,
739 std::map<int, timedMeasurement>::iterator mapIter =
snapshotValues.begin();
740 std::map<int, timedMeasurement>::iterator mapIend =
snapshotValues.end();
742 std::map<long long int, channelValue> periodBuffer;
745 std::unique_ptr<coral::IQuery> fwccQuery(fwccTable.newQuery());
746 fwccQuery->addToOutputList(
"DPID");
747 fwccQuery->addToOutputList(
"CHANGE_DATE");
748 fwccQuery->addToOutputList(
"ACTUAL_VMON");
749 fwccQuery->addToOutputList(
"ACTUAL_IMON");
750 fwccQuery->addToOutputList(
"ACTUAL_ISON");
751 fwccQuery->addToOutputList(
"ACTUAL_STATUS");
752 fwccQuery->addToOutputList(
"ACTUAL_OVC");
753 coral::AttributeList timeBindVariableList;
754 timeBindVariableList.extend(
"since",
typeid(coral::TimeStamp));
755 timeBindVariableList.extend(
"until",
typeid(coral::TimeStamp));
756 coral::TimeStamp coralSince =
coralTime(condSince);
757 coral::TimeStamp coralUntil =
coralTime(condUntil);
758 std::cout <<
"look for data since " << coralSince.year() <<
" " << coralSince.month() <<
" " << coralSince.day()
759 <<
" " << coralSince.hour() <<
":" << coralSince.minute() <<
":" << coralSince.second() <<
" until "
760 << coralUntil.year() <<
" " << coralUntil.month() <<
" " << coralUntil.day() <<
" " << coralUntil.hour()
761 <<
":" << coralUntil.minute() <<
":" << coralUntil.second() << std::endl;
762 timeBindVariableList[
"since"].data<coral::TimeStamp>() =
coralTime(condSince);
763 timeBindVariableList[
"until"].data<coral::TimeStamp>() =
coralTime(condUntil);
764 fwccQuery->setCondition(
"CHANGE_DATE>:since and CHANGE_DATE<:until", timeBindVariableList);
765 fwccQuery->addToOrderList(
"CHANGE_DATE");
766 coral::ICursor& fwccCursor = fwccQuery->execute();
768 while (fwccCursor.next()) {
770 const coral::Attribute& dp = fwccCursor.currentRow()[
"DPID"];
771 const coral::Attribute& vmon = fwccCursor.currentRow()[
"ACTUAL_VMON"];
772 const coral::Attribute& imon = fwccCursor.currentRow()[
"ACTUAL_IMON"];
773 coral::TimeStamp changeTime = fwccCursor.currentRow()[
"CHANGE_DATE"].data<coral::TimeStamp>();
774 long long int cTimeValue = changeTime.total_nanoseconds();
776 cTimeValue = -cTimeValue;
778 std::cout <<
"------- " << nrows << std::endl;
781 int dpId = 10 *
static_cast<int>(0.01 + fwccCursor.currentRow()[
"DPID"].data<
float>());
782 if (!(vmon.isNull())) {
783 while (periodBuffer.find(cTimeValue) != periodBuffer.end())
786 periodBuffer.insert(std::pair<long long int, channelValue>(cTimeValue,
channelValue(chan, vmon.data<
float>())));
788 if (!(imon.isNull())) {
789 while (periodBuffer.find(cTimeValue) != periodBuffer.end())
792 periodBuffer.insert(std::pair<long long int, channelValue>(cTimeValue,
channelValue(chan, imon.data<
float>())));
798 std::cout <<
"data found in period: " << periodBuffer.size() << std::endl;
799 std::map<long long int, channelValue>::const_iterator bufIter = periodBuffer.begin();
800 std::map<long long int, channelValue>::const_iterator bufIend = periodBuffer.end();
802 bool changedStatus =
false;
803 while (bufIter != bufIend) {
804 const std::pair<long long int, channelValue>&
entry = *bufIter++;
805 long long int mTime = entry.first;
809 int chan = cValue.first;
810 float cont = cValue.second;
812 if ((mapIter != mapIend) && (mapIter->second.first < mTime)) {
819 changedStatus =
false;
822 std::cout <<
"max payload number reached" << std::endl;
827 if (copyOffline && !changedStatus &&
checkStatusChange(chan, mapIter->second.second, cont)) {
829 changedStatus =
true;
852 while (condSince < condUntil) {
854 condSince = condUntil;
855 condUntil = condSince + dTime;
859 std::cout <<
"call filterData " << std::endl;
879 std::map<int, int>::const_iterator layerIter =
layerMap.begin();
880 std::map<int, int>::const_iterator layerIend =
layerMap.end();
881 while (layerIter != layerIend) {
882 const std::pair<int, int>& chanEntry = *layerIter++;
883 int rawId = chanEntry.first;
885 int whe = chlId.
wheel();
889 int lay = chlId.
layer();
890 int l_p = chlId.
wire();
893 for (type = 1; type <= 2; type++) {
895 for (l_p = 0; l_p <= 1; l_p++) {
912 if (!flag.
a && !flag.
c && !flag.
s)
915 std::map<int, std::vector<int>*>::const_iterator m_iter =
channelSplit.find(rPart);
916 std::map<int, std::vector<int>*>::const_iterator m_iend =
channelSplit.end();
917 if (m_iter != m_iend) {
918 std::vector<int>* cList = m_iter->second;
919 std::vector<int>::const_iterator l_iter = cList->begin();
920 std::vector<int>::const_iterator l_iend = cList->end();
921 while (l_iter != l_iend) {
923 int wh2 = chlId.
wheel();
927 int la2 = chlId.
layer();
928 int lp2 = chlId.
wire() - 10;
944 valueL = valueR = valueS = valueC = 0.0;
946 std::map<int, timedMeasurement>::const_iterator snapIter =
snapshotValues.begin();
947 std::map<int, timedMeasurement>::const_iterator snapIend =
snapshotValues.end();
952 std::map<int, int>::const_iterator layerIter;
953 std::map<int, int>::const_iterator layerIend =
layerMap.end();
954 if ((layerIter =
layerMap.find(rawL)) != layerIend) {
955 const std::pair<int, int>& layerEntry = *layerIter;
956 int dpId = layerEntry.second;
958 if (snapIter != snapIend) {
959 const std::pair<int, timedMeasurement>& snapEntry = *snapIter;
960 valueL = snapEntry.second.second;
962 std::cout <<
"snapR not found" << std::endl;
964 std::cout <<
"rawR not found" << std::endl;
965 if ((layerIter =
layerMap.find(rawR)) != layerIend) {
966 const std::pair<int, int>& layerEntry = *layerIter;
967 int dpId = layerEntry.second;
969 if (snapIter != snapIend) {
970 const std::pair<int, timedMeasurement>& snapEntry = *snapIter;
971 valueR = snapEntry.second.second;
973 std::cout <<
"snapL not found" << std::endl;
975 std::cout <<
"rawL not found" << std::endl;
976 if ((layerIter =
layerMap.find(rawS)) != layerIend) {
977 const std::pair<int, int>& layerEntry = *layerIter;
978 int dpId = layerEntry.second;
980 if (snapIter != snapIend) {
981 const std::pair<int, timedMeasurement>& snapEntry = *snapIter;
982 valueS = snapEntry.second.second;
984 std::cout <<
"snapS not found" << std::endl;
986 std::cout <<
"rawS not found" << std::endl;
987 if ((layerIter =
layerMap.find(rawC)) != layerIend) {
988 const std::pair<int, int>& layerEntry = *layerIter;
989 int dpId = layerEntry.second;
991 if (snapIter != snapIend) {
992 const std::pair<int, timedMeasurement>& snapEntry = *snapIter;
993 valueC = snapEntry.second.second;
995 std::cout <<
"snapC not found" << std::endl;
997 std::cout <<
"rawC not found" << std::endl;
1012 int searchStatus = hv->
get(whe, sta, sec, qua, lay, l_p, fCell, lCell, flagA, flagC, flagS);
1014 DTWireId wireId(whe, sta, sec, qua, lay, 10 + l_p);
1015 std::map<int, int>::const_iterator splitIter =
laySplit.find(wireId.
rawId());
1016 std::map<int, int>::const_iterator splitIend =
laySplit.end();
1017 if (splitIter != splitIend) {
1018 int code = splitIter->second;
1019 fCell = code / 10000;
1020 lCell = code % 10000;
1026 hv->
set(whe, sta, sec, qua, lay, l_p, fCell, lCell, flagA, flagC, flagS);
1031 int dpId = chan / 10;
1032 int type = chan % 10;
1033 std::map<int, int>::const_iterator aliasIter =
aliasMap.find(dpId);
1034 std::map<int, int>::const_iterator aliasIend =
aliasMap.end();
1035 if (aliasIter == aliasIend)
1037 int rawId = aliasIter->second;
1039 int l_p = chlId.
wire();
1055 if (valueL != oldValue)
1056 std::cout <<
"*** INCONSISTENT DATA!!!!! " << type <<
" " << l_p <<
" " << oldValue <<
" " << valueL <<
" "
1061 if (valueR != oldValue)
1062 std::cout <<
"*** INCONSISTENT DATA!!!!! " << type <<
" " << l_p <<
" " << oldValue <<
" " << valueR <<
" "
1067 if (valueS != oldValue)
1068 std::cout <<
"*** INCONSISTENT DATA!!!!! " << type <<
" " << l_p <<
" " << oldValue <<
" " << valueS <<
" "
1073 if (valueC != oldValue)
1074 std::cout <<
"*** INCONSISTENT DATA!!!!! " << type <<
" " << l_p <<
" " << oldValue <<
" " << valueC <<
" "
1088 std::cout <<
"changed status: " << chan <<
" from " << oldValue <<
" to " << newValue << std::endl;
1104 std::vector<std::pair<DTHVStatus*, cond::Time_t> >::const_iterator iter =
tmpContainer.begin();
1105 std::vector<std::pair<DTHVStatus*, cond::Time_t> >::const_iterator iend =
tmpContainer.end();
1106 std::vector<std::pair<DTHVStatus*, cond::Time_t> >::const_iterator prev;
1107 std::vector<std::pair<DTHVStatus*, cond::Time_t> >::const_iterator
next;
1109 while (iter != iend) {
1121 int dtot = nSize - pSize;
1123 while (++next != iend) {
1128 int diff = nSize - pSize;
1129 iTime =
static_cast<int>((iter->second >> 32) & 0xffffffff);
1130 pTime =
static_cast<int>((prev->second >> 32) & 0xffffffff);
1131 nTime =
static_cast<int>((next->second >> 32) & 0xffffffff);
1132 if ((nTime - pTime) > maxTime)
1134 if ((nTime - iTime) > maxTtot)
1136 if ((dtot * diff) < 0)
1143 dtot = pSize - iSize;
1144 int dist = pTime - iTime;
1145 if ((dtot < -minDiff) && (dist < maxTtot)) {
1146 std::cout <<
" ******** SWITCH ON " <<
std::distance(iter, prev) <<
" " << iTime <<
" " << pTime <<
" " << iSize
1147 <<
" " << pSize << std::endl;
1148 m_to_transfer.push_back(std::make_pair(prev->first, prev->second));
1149 while (iter != prev)
1150 delete (iter++->first);
1152 if ((dtot > minDiff) && (dist < maxTtot)) {
1153 std::cout <<
" ******** SWITCH OFF " <<
std::distance(iter, prev) <<
" " << iTime <<
" " << pTime <<
" " << iSize
1154 <<
" " << pSize << std::endl;
1155 m_to_transfer.push_back(std::make_pair(prev->first, iter->second));
1157 while (iter != prev)
1158 delete (iter++->first);
1160 if (((dtot >= -minDiff) && (dtot <= minDiff)) || (dist >= maxTtot)) {
1161 while (iter != next) {
1162 const std::pair<DTHVStatus*, cond::Time_t>&
entry = *iter++;
1163 m_to_transfer.push_back(std::make_pair(entry.first, entry.second));
1172 int whe = chlId.
wheel();
1174 int sec = chlId.
sector();
1176 int lay = chlId.
layer();
1177 DTWireId chl(whe, sta, sec, qua, lay, 10 + l_p);
1182 long long int iTime = ((((time >> 32) & 0xFFFFFFFF) * 1000000000) + ((time & 0xFFFFFFFF) * 1000));
1183 coral::TimeStamp cTime(iTime);
1189 ((time.total_nanoseconds() / 1000000000) << 32) + ((time.total_nanoseconds() % 1000000000) / 1000);
1194 cond::Time_t cTime = ((time / 1000000000) << 32) + ((time % 1000000000) / 1000);
int get(int wheelId, int stationId, int sectorId, int slId, int layerId, int partId, int &fCell, int &lCell, int &flagA, int &flagC, int &flagS) const
get content
tuple cont
load Luminosity info ##
DTHVAbstractCheck::timedMeasurement timedMeasurement
cond::persistency::Session omds_session
void start(bool readOnly=true)
tuple chan
lumi = TPaveText(lowX+0.38, lowY+0.061, lowX+0.45, lowY+0.161, "NDC") lumi.SetBorderSize( 0 ) lumi...
constexpr uint32_t rawId() const
get the raw id
void getLayerValues(int rawId, int type, float &valueL, float &valueR, float &valueS, float &valueC)
cond::persistency::Session buff_session
std::string onlineConnect
std::map< int, int > laySplit
static DTWireId layerId(int rawId, int l_p)
int layer() const
Return the layer number.
virtual void setStatus(int rawId, int flagA, int flagC, int flagS, const std::map< int, timedMeasurement > &snapshotValues, const std::map< int, int > &aliasMap, const std::map< int, int > &layerMap)
Transaction & transaction()
DTHVStatusHandler(const edm::ParameterSet &ps)
cond::persistency::Session util_session
DTHVStatus * offlineList()
cond::Time_t recoverLastTime()
virtual DTHVAbstractCheck::flag checkCurrentStatus(int rawId, int type, float valueA, float valueC, float valueS, const std::map< int, timedMeasurement > &snapshotValues, const std::map< int, int > &aliasMap, const std::map< int, int > &layerMap)=0
static coral::TimeStamp coralTime(const cond::Time_t &time)
std::vector< std::pair< DTHVStatus *, cond::Time_t > > tmpContainer
int checkStatusChange(int type, float oldValue, float newValue)
std::map< int, int > layerMap
static bool compare(const DTHVAbstractCheck::flag &fl, const DTHVAbstractCheck::flag &fr)
unsigned long long Time_t
void dumpSnapshot(const coral::TimeStamp &time)
static cond::Time_t condTime(const coral::TimeStamp &time)
std::vector< std::pair< DTHVStatus *, Time_t > > m_to_transfer
coral::ISchema & nominalSchema()
int superLayer() const
Return the superlayer number.
Session createSession(const std::string &connectionString, bool writeCapable=false)
void getNewObjects() override
int checkForPeriod(cond::Time_t condSince, cond::Time_t condUntil, int &missingChannels, bool copyOffline)
static DTHVAbstractCheck * getInstance()
check HV status
void setChannelFlag(DTHVStatus *hv, int whe, int sta, int sec, int qua, int lay, int l_p, const DTHVAbstractCheck::flag &flag)
int wire() const
Return the wire number.
std::vector< std::pair< DTHVStatusId, DTHVStatusData > >::const_iterator const_iterator
Access methods to data.
std::string onlineAuthentication
std::map< int, int > aliasMap
int set(int wheelId, int stationId, int sectorId, int slId, int layerId, int partId, int fCell, int lCell, int flagA, int flagC, int flagS)
std::pair< int, float > channelValue
std::unique_ptr< DTHVStatus > Ref
char data[epos_bytes_allocation]
~DTHVStatusHandler() override
const_iterator end() const
DTHVAbstractCheck * hvChecker
std::string id() const override
std::string bufferConnect
const_iterator begin() const
int station() const
Return the station number.
std::map< int, timedMeasurement > snapshotValues
int wheel() const
Return the wheel number.
void setAuthenticationPath(const std::string &p)
std::map< int, std::vector< int > * > channelSplit
cond::TagInfo_t const & tagInfo() const