29 #include "RelationalAccess/ISchema.h"
30 #include "RelationalAccess/ITable.h"
31 #include "RelationalAccess/ICursor.h"
32 #include "RelationalAccess/IQuery.h"
33 #include "RelationalAccess/TableDescription.h"
34 #include "RelationalAccess/ITableDataEditor.h"
35 #include "CoralBase/AttributeList.h"
36 #include "CoralBase/AttributeSpecification.h"
37 #include "CoralBase/Attribute.h"
38 #include "CoralBase/TimeStamp.h"
55 dataTag( ps.getParameter<std::
string> (
"tag" ) ),
56 onlineConnect( ps.getParameter<std::
string> (
"onlineDB" ) ),
57 utilConnect( ps.getParameter<std::
string> (
"utilDB" ) ),
58 onlineAuthentication( ps.getParameter<std::
string> (
59 "onlineAuthentication" ) ),
60 bufferConnect( ps.getParameter<std::
string> (
"bufferDB" ) ),
61 ySince( ps.getParameter<int> (
"sinceYear" ) ),
62 mSince( ps.getParameter<int> (
"sinceMonth" ) ),
63 dSince( ps.getParameter<int> (
"sinceDay" ) ),
64 hSince( ps.getParameter<int> (
"sinceHour" ) ),
65 pSince( ps.getParameter<int> (
"sinceMinute" ) ),
66 sSince( ps.getParameter<int> (
"sinceSecond" ) ),
67 yUntil( ps.getParameter<int> (
"untilYear" ) ),
68 mUntil( ps.getParameter<int> (
"untilMonth" ) ),
69 dUntil( ps.getParameter<int> (
"untilDay" ) ),
70 hUntil( ps.getParameter<int> (
"untilHour" ) ),
71 pUntil( ps.getParameter<int> (
"untilMinute" ) ),
72 sUntil( ps.getParameter<int> (
"untilSecond" ) ),
73 dumpAtStart( ps.getParameter<bool>(
"dumpAtStart" ) ),
74 dumpAtEnd( ps.getParameter<bool>(
"dumpAtEnd" ) ),
75 bwdTime( ps.getParameter<long long int> (
"bwdTime" ) ),
76 fwdTime( ps.getParameter<long long int> (
"fwdTime" ) ),
77 minTime( ps.getParameter<long long int> (
"minTime" ) ),
84 mapVersion( ps.getParameter<std::
string> (
"mapVersion" ) ),
85 splitVersion( ps.getParameter<std::
string> (
"splitVersion" ) ) {
86 std::cout <<
" PopCon application for DT HV data export "
104 std::cout <<
"get new objects..." << std::endl;
107 std::cout <<
"configure omds DbConnection" << std::endl;
111 std::cout <<
"create omds DbSession" << std::endl;
113 std::cout <<
"open omds session" << std::endl;
115 std::cout <<
"start omds transaction" << std::endl;
120 std::cout <<
"configure util DbConnection" << std::endl;
124 std::cout <<
"create util DbSession" << std::endl;
126 std::cout <<
"open util session" << std::endl;
128 std::cout <<
"startutil transaction" << std::endl;
133 std::cout <<
"configure buffer DbConnection" << std::endl;
136 std::cout <<
"create buffer DbSession" << std::endl;
138 std::cout <<
"open buffer session" << std::endl;
140 std::cout <<
"start buffer transaction" << std::endl;
148 std::cout <<
"latest DCS data (HV) already copied until: "
149 << last << std::endl;
165 m_to_transfer.push_back( std::make_pair( dummyStatus, snc ) );
167 std::cout <<
"no old data... " << last << std::endl;
173 while ( paylIter != paylIend ) {
174 const std::pair<DTHVStatusId,DTHVStatusData>& entry = *paylIter++;
178 chan. slId, chan.
layerId, chan. partId + 10 );
185 coral::TimeStamp coralLast =
coralTime( last );
190 std::cout <<
"Required time interval in the future: "
192 <<
" copy since " <<
ySince <<
" "
195 <<
" ( " <<
procSince <<
" )" << std::endl
196 <<
" current time " << coralProc.year( ) <<
" "
197 << coralProc.month() <<
" "
198 << coralProc.day( ) << std::endl;
207 std::cout <<
"Required time interval already copied: "
209 <<
" copy until " <<
yUntil <<
" "
212 <<
" ( " <<
procUntil <<
" )" << std::endl
213 <<
" data until " << coralLast.year( ) <<
" "
214 << coralLast.month() <<
" "
215 << coralLast.day( ) << std::endl;
219 std::cout <<
"Required time interval not contiguous with copied data: "
221 <<
" data until " << coralLast.year( ) <<
" "
222 << coralLast.month() <<
" "
223 << coralLast.day( ) << std::endl
224 <<
" copy since " <<
ySince <<
" "
227 <<
" ( " <<
procSince <<
" )" << std::endl;
268 std::set<std::string>::const_iterator omds_iter = omds_lt.begin();
269 std::set<std::string>::const_iterator omds_iend = omds_lt.end();
270 while ( omds_iter != omds_iend ) {
272 std::cout <<
"TABLE: " << istr << std::endl;
276 std::set<std::string>::const_iterator util_iter = util_lt.begin();
277 std::set<std::string>::const_iterator util_iend = util_lt.end();
278 while ( util_iter != util_iend ) {
280 std::cout <<
"TABLE: " << istr << std::endl;
287 std::cout <<
"open buffer db..." << std::endl;
298 return "DTHVStatusHandler";
308 std::cout <<
"retrieve aliases table..." << std::endl;
309 coral::ITable& hvalTable =
311 std::auto_ptr<coral::IQuery> hvalQuery( hvalTable.newQuery() );
312 hvalQuery->addToOutputList(
"DETID" );
313 hvalQuery->addToOutputList(
"DPID" );
314 coral::ICursor& hvalCursor = hvalQuery->execute();
317 while ( hvalCursor.next() ) {
318 chId = hvalCursor.currentRow()[
"DETID"].data<
int>();
319 dpId = hvalCursor.currentRow()[
"DPID"].data<
int>();
320 aliasMap.insert( std::pair<int,int>( dpId, chId ) );
321 layerMap.insert( std::pair<int,int>( chId, dpId ) );
331 std::cout <<
"retrieve layer split table..." << std::endl;
340 coral::ITable& lsplTable =
342 std::cout <<
" layer split table got..." << std::endl;
343 std::auto_ptr<coral::IQuery> lsplQuery( lsplTable.newQuery() );
344 coral::AttributeList versionBindVariableList;
345 versionBindVariableList.extend(
"version",
typeid(
std::string) );
347 lsplQuery->setCondition(
"VERSION=:version", versionBindVariableList );
348 lsplQuery->addToOutputList(
"WHEEL" );
349 lsplQuery->addToOutputList(
"SECTOR" );
350 lsplQuery->addToOutputList(
"STATION" );
351 lsplQuery->addToOutputList(
"SUPERLAYER" );
352 lsplQuery->addToOutputList(
"LAYER" );
353 lsplQuery->addToOutputList(
"PART" );
354 lsplQuery->addToOutputList(
"FIRST_CELL" );
355 lsplQuery->addToOutputList(
"LAST_CELL" );
356 coral::ICursor& lsplCursor = lsplQuery->execute();
357 while ( lsplCursor.next() ) {
358 whe = lsplCursor.currentRow()[
"WHEEL" ].data<
int>();
359 sec = lsplCursor.currentRow()[
"SECTOR" ].data<
int>();
360 sta = lsplCursor.currentRow()[
"STATION" ].data<
int>();
361 qua = lsplCursor.currentRow()[
"SUPERLAYER"].data<
int>();
362 lay = lsplCursor.currentRow()[
"LAYER" ].data<
int>();
363 l_p = lsplCursor.currentRow()[
"PART" ].data<
int>();
364 f_c = lsplCursor.currentRow()[
"FIRST_CELL"].data<
int>();
365 l_c = lsplCursor.currentRow()[
"LAST_CELL"].data<
int>();
366 DTWireId wireId( whe, sta, sec, qua, lay, 10 + l_p );
367 laySplit.insert( std::pair<int,int>( wireId.rawId(),
368 ( f_c * 10000 ) + l_c ) );
370 std::cout <<
"channel split table retrieved" << std::endl;
376 std::cout <<
"retrieve channel split table..." << std::endl;
389 coral::ITable& csplTable =
391 std::auto_ptr<coral::IQuery> csplQuery( csplTable.newQuery() );
392 coral::AttributeList versionBindVariableList;
393 versionBindVariableList.extend(
"version",
typeid(
std::string) );
395 csplQuery->setCondition(
"VERSION=:version", versionBindVariableList );
396 csplQuery->addToOutputList(
"P_WHEEL" );
397 csplQuery->addToOutputList(
"P_SECTOR" );
398 csplQuery->addToOutputList(
"P_STATION" );
399 csplQuery->addToOutputList(
"P_SUPERLAYER" );
400 csplQuery->addToOutputList(
"P_LAYER" );
401 csplQuery->addToOutputList(
"P_PART" );
402 csplQuery->addToOutputList(
"S_NUMBER" );
403 csplQuery->addToOutputList(
"S_WHEEL" );
404 csplQuery->addToOutputList(
"S_SECTOR" );
405 csplQuery->addToOutputList(
"S_STATION" );
406 csplQuery->addToOutputList(
"S_SUPERLAYER" );
407 csplQuery->addToOutputList(
"S_LAYER" );
408 csplQuery->addToOutputList(
"S_PART" );
409 coral::ICursor& csplCursor = csplQuery->execute();
410 while ( csplCursor.next() ) {
411 pwhe = csplCursor.currentRow()[
"P_WHEEL" ].data<
int>();
412 psec = csplCursor.currentRow()[
"P_SECTOR" ].data<
int>();
413 psta = csplCursor.currentRow()[
"P_STATION" ].data<
int>();
414 pqua = csplCursor.currentRow()[
"P_SUPERLAYER"].data<
int>();
415 play = csplCursor.currentRow()[
"P_LAYER" ].data<
int>();
416 pl_p = csplCursor.currentRow()[
"P_PART" ].data<
int>();
417 csplCursor.currentRow()[
"S_NUMBER" ].data<
int>();
418 swhe = csplCursor.currentRow()[
"S_WHEEL" ].data<
int>();
419 ssec = csplCursor.currentRow()[
"S_SECTOR" ].data<
int>();
420 ssta = csplCursor.currentRow()[
"S_STATION" ].data<
int>();
421 squa = csplCursor.currentRow()[
"S_SUPERLAYER"].data<
int>();
422 slay = csplCursor.currentRow()[
"S_LAYER" ].data<
int>();
423 sl_p = csplCursor.currentRow()[
"S_PART" ].data<
int>();
424 DTWireId pId( pwhe, psta, psec, pqua, play, 10 + pl_p );
425 DTWireId sId( swhe, ssta, ssec, squa, slay, 10 + sl_p );
426 int pRaw = pId.rawId();
427 int sRaw = sId.
rawId();
428 std::vector<int>* splitList = 0;
429 std::map< int,std::vector<int>* >::iterator iter =
431 std::map< int,std::vector<int>* >::iterator iend =
433 if ( iter == iend ) {
435 std::vector<int>* >( pRaw, splitList =
436 new std::vector<int> ) );
439 splitList = iter->second;
441 splitList->push_back( sRaw );
449 std::cout <<
"DTHVStatusHandler::dumpHVAliases - begin" << std::endl;
451 std::cout <<
"create aliases description..." << std::endl;
452 coral::TableDescription hvalDesc;
453 hvalDesc.setName(
"HVALIASES" );
454 hvalDesc.insertColumn(
"DETID",
455 coral::AttributeSpecification::typeNameForId(
457 hvalDesc.insertColumn(
"DPID",
458 coral::AttributeSpecification::typeNameForId(
460 std::cout <<
"create aliases table..." << std::endl;
461 coral::ITable& hvalTable =
464 std::cout <<
"open DPNAME table..." << std::endl;
465 std::map<int,std::string> idMap;
466 coral::ITable& dpidTable =
468 std::auto_ptr<coral::IQuery> dpidQuery( dpidTable.newQuery() );
469 dpidQuery->addToOutputList(
"ID" );
470 dpidQuery->addToOutputList(
"DPNAME" );
471 coral::ICursor& dpidCursor = dpidQuery->execute();
472 while( dpidCursor.next() ) {
473 const coral::AttributeList& row = dpidCursor.currentRow();
474 int id =
static_cast<int>( 0.01 +
475 row[
"ID" ].data<
float>() );
477 idMap.insert( std::pair<int,std::string>(
id, dp ) );
479 std::cout <<
"DPNAME table read... " << idMap.size() << std::endl;
481 std::cout <<
"open ALIASES table..." << std::endl;
482 std::map<std::string,std::string> cnMap;
483 coral::ITable& nameTable =
485 std::auto_ptr<coral::IQuery> nameQuery( nameTable.newQuery() );
486 nameQuery->addToOutputList(
"DPE_NAME" );
487 nameQuery->addToOutputList(
"ALIAS" );
488 coral::ICursor& nameCursor = nameQuery->execute();
489 while( nameCursor.next() ) {
490 const coral::AttributeList& row = nameCursor.currentRow();
493 if ( an.length() < 20 )
continue;
494 cnMap.insert( std::pair<std::string,std::string>( dp, an ) );
496 std::cout <<
"ALIASES table read... " << cnMap.size() << std::endl;
498 std::map<int,std::string>::const_iterator idIter = idMap.begin();
499 std::map<int,std::string>::const_iterator idIend = idMap.end();
501 while ( idIter != idIend ) {
502 const std::pair<int,std::string>& ientry = *idIter++;
503 int dpId = ientry.first;
505 int ldp = dp.length();
506 if ( ldp < 20 )
continue;
509 if ( subChk != outChk )
continue;
511 chName +=
".actual.OvC";
512 int chCode = subOut.c_str()[16] -
'0';
513 std::map<std::string,std::string>::const_iterator jter =
514 cnMap.find( chName );
515 if ( jter == cnMap.end() )
continue;
516 const std::pair<std::string,std::string>& jentry = *jter;
517 std::cout << dp << std::endl << chName <<
" " << chCode << std::endl;
519 int al = an.length();
520 int iofw = 7 + an.find(
"DT_HV_W", 0 );
521 int iofc = 3 + an.find(
"_MB", 0 );
522 int iofs = 2 + an.find(
"_S" , 0 );
523 int iofq = 3 + an.find(
"_SL", 0 );
524 int iofl = 2 + an.find(
"_L" , 0 );
525 if ( ( iofw == al ) ||
532 int ioew = an.find(
"_", iofw );
533 int ioec = an.find(
"_", iofc );
534 int ioes = an.find(
"_", iofs );
535 int ioeq = an.find(
"_", iofq );
536 int ioel = an.find(
"_", iofl );
537 std::string swhe( an.substr( iofw, ioew - iofw ) );
538 const char* cwhe = swhe.c_str();
539 int whe = cwhe[1] -
'0';
540 if ( *cwhe !=
'P' ) whe = -whe;
542 std::string scha( an.substr( iofc, ioec - iofc ) );
543 const char* ccha = scha.c_str();
544 int cha = *ccha -
'0';
546 std::string ssec( an.substr( iofs, ioes - iofs ) );
547 const char* csec = ssec.c_str();
548 int sec = ( ( *csec -
'0' ) * 10 ) + ( csec[1] -
'0' );
549 if ( ( csec[2] ==
'R' ) && ( sec == 10 ) ) sec = 14;
550 if ( ( csec[2] ==
'L' ) && ( sec == 4 ) ) sec = 13;
552 std::string squa( an.substr( iofq, ioeq - iofq ) );
553 const char* cqua = squa.c_str();
554 int qua = *cqua -
'0';
556 std::string slay( an.substr( iofl, ioel - iofl ) );
557 const char* clay = slay.c_str();
558 int lay = *clay -
'0';
560 DTWireId wireId( whe, cha, sec, qua, lay, 10 + chCode );
561 int chId = wireId.
rawId();
562 coral::AttributeList newChan;
563 newChan.extend(
"DETID",
typeid(
int) );
564 newChan.extend(
"DPID",
typeid(
int) );
565 newChan[
"DETID"].data<
int>() = chId;
566 newChan[
"DPID"].data<
int>() = dpId;
567 hvalTable.dataEditor().insertRow( newChan );
568 aliasMap.insert( std::pair<int,int>( dpId, chId ) );
569 layerMap.insert( std::pair<int,int>( chId, dpId ) );
572 std::cout <<
"DTHVStatusHandler::dumpHVAliases - end" << std::endl;
578 std::cout <<
"create snapshot description..." << std::endl;
579 coral::TableDescription hvssDesc;
580 hvssDesc.setName(
"HVSNAPSHOT" );
581 hvssDesc.insertColumn(
"TIME",
582 coral::AttributeSpecification::typeNameForId(
583 typeid(coral::TimeStamp) ) );
584 hvssDesc.insertColumn(
"WHEEL",
585 coral::AttributeSpecification::typeNameForId(
587 hvssDesc.insertColumn(
"STATION",
588 coral::AttributeSpecification::typeNameForId(
590 hvssDesc.insertColumn(
"SECTOR",
591 coral::AttributeSpecification::typeNameForId(
593 hvssDesc.insertColumn(
"SUPERLAYER",
594 coral::AttributeSpecification::typeNameForId(
596 hvssDesc.insertColumn(
"LAYER",
597 coral::AttributeSpecification::typeNameForId(
599 hvssDesc.insertColumn(
"CHAN",
600 coral::AttributeSpecification::typeNameForId(
602 hvssDesc.insertColumn(
"TYPE",
603 coral::AttributeSpecification::typeNameForId(
605 hvssDesc.insertColumn(
"VALUE",
606 coral::AttributeSpecification::typeNameForId(
608 std::cout <<
"create snapshot table..." << std::endl;
610 coral::ITable& bufferTable =
612 coral::AttributeList newMeas;
613 newMeas.extend(
"TIME",
typeid(coral::TimeStamp) );
614 newMeas.extend(
"WHEEL",
typeid(
int) );
615 newMeas.extend(
"STATION",
typeid(
int) );
616 newMeas.extend(
"SECTOR",
typeid(
int) );
617 newMeas.extend(
"SUPERLAYER",
typeid(
int) );
618 newMeas.extend(
"LAYER",
typeid(
int) );
619 newMeas.extend(
"CHAN",
typeid(
int) );
620 newMeas.extend(
"TYPE",
typeid(
int) );
621 newMeas.extend(
"VALUE",
typeid(
float) );
623 long long int zeroTime = 0LL;
624 newMeas[
"TIME" ].data<coral::TimeStamp>() =
625 coral::TimeStamp( zeroTime );
626 newMeas[
"VALUE" ].data<
float>() = -999999.0;
628 std::map<int,int>::const_iterator iter =
aliasMap.begin();
629 std::map<int,int>::const_iterator iend =
aliasMap.end();
630 while ( iter != iend ) {
631 const std::pair<int,int>& entry= *iter++;
632 int detId = entry.second;
634 newMeas[
"WHEEL" ].data<
int>() = chlId.
wheel ();
635 newMeas[
"STATION" ].data<
int>() = chlId.
station ();
636 newMeas[
"SECTOR" ].data<
int>() = chlId.
sector ();
637 newMeas[
"SUPERLAYER"].data<
int>() = chlId.
superLayer();
638 newMeas[
"LAYER" ].data<
int>() = chlId.
layer ();
639 newMeas[
"CHAN" ].data<
int>() = chlId.
wire () - 10;
641 for ( itype = 1; itype <= 2; itype++ ) {
642 newMeas[
"TYPE" ].data<
int>() = itype;
643 bufferTable.dataEditor().insertRow( newMeas );
647 std::cout <<
"create logging info..." << std::endl;
650 coral::TableDescription infoDesc;
651 infoDesc.setName(
"LOG" );
652 infoDesc.insertColumn(
"EXECTIME",
653 coral::AttributeSpecification::typeNameForId(
654 typeid(coral::TimeStamp) ) );
655 infoDesc.insertColumn(
"SNAPSHOT",
656 coral::AttributeSpecification::typeNameForId(
657 typeid(coral::TimeStamp) ) );
659 coral::AttributeList newInfo;
660 newInfo.extend(
"EXECTIME",
typeid(coral::TimeStamp) );
661 newInfo.extend(
"SNAPSHOT",
typeid(coral::TimeStamp) );
662 newInfo[
"EXECTIME"].data<coral::TimeStamp>() =
663 coral::TimeStamp( zeroTime );
664 newInfo[
"SNAPSHOT"].data<coral::TimeStamp>() =
665 coral::TimeStamp( zeroTime );
666 coral::ITable& infoTable =
668 infoTable.dataEditor().insertRow( newInfo );
678 std::cout <<
" snapshot at " << snapshotTime <<
" ( "
680 .total_nanoseconds() <<
" ) "
683 coral::TimeStamp coralSnap =
coralTime( snapshotTime );
684 std::cout <<
"too recent snapshot: " << std::endl
685 <<
" snapshot at " << coralSnap.year( ) <<
" "
686 << coralSnap.month() <<
" "
687 << coralSnap.day( ) << std::endl
688 <<
" copy since " <<
ySince <<
" "
691 <<
" ( " <<
procSince <<
" )" << std::endl;
699 while ( missingChannels ) {
701 << condSince <<
" ( " <<
coralTime( condSince )
702 .total_nanoseconds() <<
" ) -> "
703 << condUntil <<
" ( " <<
coralTime( condUntil )
704 .total_nanoseconds() <<
" ) "
706 if ( condSince <= snapshotTime ) condSince = snapshotTime;
708 << condSince <<
" ( " <<
coralTime( condSince )
709 .total_nanoseconds() <<
" ) "
711 if ( condSince >= condUntil )
break;
712 std::cout <<
"missing... " << missingChannels << std::endl;
714 condUntil = condSince;
715 condSince = condUntil - dTime;
729 int missingChannels = 0;
730 std::map<int,int>::const_iterator layIter =
layerMap.begin();
731 std::map<int,int>::const_iterator layIend =
layerMap.end();
732 std::cout <<
"retrieve snapshot table..." << std::endl;
733 coral::ITable& hvssTable =
735 std::auto_ptr<coral::IQuery> hvssQuery( hvssTable.newQuery() );
736 hvssQuery->addToOutputList(
"TIME" );
737 hvssQuery->addToOutputList(
"WHEEL" );
738 hvssQuery->addToOutputList(
"STATION" );
739 hvssQuery->addToOutputList(
"SECTOR" );
740 hvssQuery->addToOutputList(
"SUPERLAYER" );
741 hvssQuery->addToOutputList(
"LAYER" );
742 hvssQuery->addToOutputList(
"CHAN" );
743 hvssQuery->addToOutputList(
"TYPE" );
744 hvssQuery->addToOutputList(
"VALUE" );
745 coral::ICursor& hvssCursor = hvssQuery->execute();
746 while ( hvssCursor.next() ) {
747 coral::TimeStamp
time =
748 hvssCursor.currentRow()[
"TIME"].data<coral::TimeStamp>();
749 int whe = hvssCursor.currentRow()[
"WHEEL" ].data<
int>();
750 int sta = hvssCursor.currentRow()[
"STATION" ].data<
int>();
751 int sec = hvssCursor.currentRow()[
"SECTOR" ].data<
int>();
752 int qua = hvssCursor.currentRow()[
"SUPERLAYER"].data<
int>();
753 int lay = hvssCursor.currentRow()[
"LAYER" ].data<
int>();
754 int l_p = hvssCursor.currentRow()[
"CHAN" ].data<
int>();
755 int mty = hvssCursor.currentRow()[
"TYPE" ].data<
int>();
756 float value = hvssCursor.currentRow()[
"VALUE" ].data<
float>();
757 if ( mty > 2 )
continue;
758 DTWireId wireId( whe, sta, sec, qua, lay, 10 + l_p );
760 if ( layIter == layIend ) {
763 int dpId = ( layIter->second * 10 ) + mty;
766 time.total_nanoseconds(),
value ) ) );
769 return missingChannels;
774 long long int lastTime = 0LL;
775 long long int chanTime = 0LL;
776 std::map<int,timedMeasurement>::iterator mapIter =
snapshotValues.begin();
777 std::map<int,timedMeasurement>::iterator mapIend =
snapshotValues.end();
778 while ( mapIter != mapIend ) {
779 const std::pair<int,timedMeasurement>& entry = *mapIter++;
780 chanTime = entry.second.first;
781 if ( lastTime < chanTime ) lastTime = chanTime;
801 std::cout <<
"dump snapshot to buffer db..." << std::endl;
803 coral::AttributeList emptyBindVariableList;
804 std::map<int,int>::const_iterator mapIter =
aliasMap.begin();
805 std::map<int,int>::const_iterator mapIend =
aliasMap.end();
806 coral::ITable& hvssTable =
808 coral::ITableDataEditor& hvssEditor( hvssTable.dataEditor() );
809 long nRows = hvssEditor.deleteRows( emptyCondition, emptyBindVariableList );
810 std::cout << nRows <<
" rows deleted" << std::endl;
812 coral::AttributeList newMeas;
813 newMeas.extend(
"TIME",
typeid(coral::TimeStamp) );
814 newMeas.extend(
"WHEEL",
typeid(
int) );
815 newMeas.extend(
"STATION",
typeid(
int) );
816 newMeas.extend(
"SECTOR",
typeid(
int) );
817 newMeas.extend(
"SUPERLAYER",
typeid(
int) );
818 newMeas.extend(
"LAYER",
typeid(
int) );
819 newMeas.extend(
"CHAN",
typeid(
int) );
820 newMeas.extend(
"TYPE",
typeid(
int) );
821 newMeas.extend(
"VALUE",
typeid(
float) );
824 std::map<int,timedMeasurement>::const_iterator ssvIter =
826 std::map<int,timedMeasurement>::const_iterator ssvIend =
828 while ( ssvIter != ssvIend ) {
829 const std::pair<int,timedMeasurement>& entry = *ssvIter++;
830 int dpty = entry.first;
831 int dpId = dpty / 10;
832 int type = dpty % 10;
834 if ( mapIter == mapIend )
continue;
837 long long int newTime = tMeas.first;
838 newMeas[
"TIME" ].data<coral::TimeStamp>() =
839 coral::TimeStamp( newTime );
840 newMeas[
"WHEEL" ].data<
int>() = chlId.
wheel ();
841 newMeas[
"STATION" ].data<
int>() = chlId.
station ();
842 newMeas[
"SECTOR" ].data<
int>() = chlId.
sector ();
843 newMeas[
"SUPERLAYER"].data<
int>() = chlId.
superLayer();
844 newMeas[
"LAYER" ].data<
int>() = chlId.
layer ();
845 newMeas[
"CHAN" ].data<
int>() = chlId.
wire () - 10;
846 newMeas[
"TYPE" ].data<
int>() = type;
847 newMeas[
"VALUE" ].data<
float>() = tMeas.second;
848 hvssEditor.insertRow( newMeas );
851 std::cout << nRows <<
" rows updated" << std::endl;
853 std::cout <<
"create logging info..." << std::endl;
856 coral::TableDescription infoDesc;
857 infoDesc.setName(
"LOG" );
858 infoDesc.insertColumn(
"EXECTIME",
859 coral::AttributeSpecification::typeNameForId(
860 typeid(coral::TimeStamp) ) );
861 infoDesc.insertColumn(
"SNAPSHOT",
862 coral::AttributeSpecification::typeNameForId(
863 typeid(coral::TimeStamp) ) );
865 coral::AttributeList newInfo;
866 newInfo.extend(
"EXECTIME",
typeid(coral::TimeStamp) );
867 newInfo.extend(
"SNAPSHOT",
typeid(coral::TimeStamp) );
869 newInfo[
"SNAPSHOT"].data<coral::TimeStamp>() = time;
870 coral::ITable& infoTable =
872 infoTable.dataEditor().insertRow( newInfo );
881 int& missingChannels,
884 std::map<int,timedMeasurement>::iterator mapIter =
snapshotValues.begin();
885 std::map<int,timedMeasurement>::iterator mapIend =
snapshotValues.end();
887 std::map<long long int,channelValue> periodBuffer;
889 coral::ITable& fwccTable =
891 std::auto_ptr<coral::IQuery> fwccQuery( fwccTable.newQuery() );
892 fwccQuery->addToOutputList(
"DPID" );
893 fwccQuery->addToOutputList(
"CHANGE_DATE" );
894 fwccQuery->addToOutputList(
"ACTUAL_VMON" );
895 fwccQuery->addToOutputList(
"ACTUAL_IMON" );
896 fwccQuery->addToOutputList(
"ACTUAL_ISON" );
897 fwccQuery->addToOutputList(
"ACTUAL_STATUS" );
898 fwccQuery->addToOutputList(
"ACTUAL_OVC" );
899 coral::AttributeList timeBindVariableList;
900 timeBindVariableList.extend(
"since",
typeid(coral::TimeStamp) );
901 timeBindVariableList.extend(
"until",
typeid(coral::TimeStamp) );
902 coral::TimeStamp coralSince =
coralTime( condSince );
903 coral::TimeStamp coralUntil =
coralTime( condUntil );
905 << coralSince.year( ) <<
" "
906 << coralSince.month( ) <<
" "
907 << coralSince.day( ) <<
" "
908 << coralSince.hour( ) <<
":"
909 << coralSince.minute() <<
":"
910 << coralSince.second() <<
" until "
911 << coralUntil.year( ) <<
" "
912 << coralUntil.month( ) <<
" "
913 << coralUntil.day( ) <<
" "
914 << coralUntil.hour( ) <<
":"
915 << coralUntil.minute() <<
":"
916 << coralUntil.second() << std::endl;
917 timeBindVariableList[
"since"].data<coral::TimeStamp>() =
919 timeBindVariableList[
"until"].data<coral::TimeStamp>() =
921 fwccQuery->setCondition(
"CHANGE_DATE>:since and CHANGE_DATE<:until",
922 timeBindVariableList );
923 fwccQuery->addToOrderList(
"CHANGE_DATE" );
924 coral::ICursor& fwccCursor = fwccQuery->execute();
926 while ( fwccCursor.next() ) {
928 const coral::Attribute&
dp = fwccCursor.currentRow()[
"DPID" ];
929 const coral::Attribute& vmon = fwccCursor.currentRow()[
"ACTUAL_VMON" ];
930 const coral::Attribute& imon = fwccCursor.currentRow()[
"ACTUAL_IMON" ];
931 coral::TimeStamp changeTime =
932 fwccCursor.currentRow()[
"CHANGE_DATE"].data<coral::TimeStamp>();
933 long long int cTimeValue = changeTime.total_nanoseconds();
934 if ( !copyOffline ) cTimeValue = -cTimeValue;
936 std::cout <<
"------- " << nrows << std::endl;
939 int dpId = 10 *
static_cast<int>( 0.01 +
940 fwccCursor.currentRow()[
"DPID"].data<
float>() );
941 if ( !( vmon.isNull() ) ) {
942 while ( periodBuffer.find( cTimeValue ) !=
943 periodBuffer.end() ) cTimeValue++;
945 periodBuffer.insert( std::pair<long long int,channelValue> (
947 vmon.data<
float>() ) ) );
949 if ( !( imon.isNull() ) ) {
950 while ( periodBuffer.find( cTimeValue ) !=
951 periodBuffer.end() ) cTimeValue++;
953 periodBuffer.insert( std::pair<long long int,channelValue> (
955 imon.data<
float>() ) ) );
961 std::cout <<
"data found in period: " << periodBuffer.size() << std::endl;
962 std::map<long long int,channelValue>::const_iterator bufIter =
963 periodBuffer.begin();
964 std::map<long long int,channelValue>::const_iterator bufIend =
967 bool changedStatus =
false;
968 while ( bufIter != bufIend ) {
969 const std::pair<long long int,channelValue>& entry = *bufIter++;
970 long long int mTime = entry.first;
971 if ( !copyOffline ) mTime = -mTime;
973 int chan = cValue.first;
974 float cont = cValue.second;
976 if ( ( mapIter != mapIend ) &&
977 ( mapIter->second.first < mTime ) ) {
979 if ( changedStatus ) {
983 << hvStatus->
end() - hvStatus->
begin() << std::endl;
985 changedStatus =
false;
988 std::cout <<
"max payload number reached" << std::endl;
993 if ( copyOffline && !changedStatus &&
996 changedStatus =
true;
1011 long long int dTime =
fwdTime;
1020 while ( condSince < condUntil ) {
1022 condSince = condUntil;
1023 condUntil = condSince + dTime;
1026 std::cout <<
"call filterData " << std::endl;
1050 std::map<int,int>::const_iterator layerIter =
layerMap.begin();
1051 std::map<int,int>::const_iterator layerIend =
layerMap.end();
1052 while ( layerIter != layerIend ) {
1053 const std::pair<int,int>& chanEntry = *layerIter++;
1054 int rawId = chanEntry.first;
1056 int whe = chlId.
wheel ();
1058 int sec = chlId.
sector ();
1060 int lay = chlId.
layer ();
1061 int l_p = chlId.
wire();
1062 if ( l_p != 10 )
continue;
1063 for ( type = 1; type <= 2; type++ ) {
1065 for ( l_p = 0; l_p <= 1; l_p++ ) {
1082 valueA, valueC, valueS,
1085 if ( !flag.
a && !flag.
c && !flag.
s )
continue;
1087 std::map< int,std::vector<int>* >::const_iterator m_iter =
1089 std::map< int,std::vector<int>* >::const_iterator m_iend =
1091 if ( m_iter != m_iend ) {
1092 std::vector<int>* cList = m_iter->second;
1093 std::vector<int>::const_iterator l_iter = cList->begin();
1094 std::vector<int>::const_iterator l_iend = cList->end();
1095 while ( l_iter != l_iend ) {
1097 int wh2 = chlId.
wheel ();
1099 int se2 = chlId.
sector ();
1101 int la2 = chlId.
layer ();
1102 int lp2 = chlId.
wire() - 10;
1119 float& valueL,
float& valueR,
1120 float& valueS,
float& valueC ) {
1126 std::map<int,timedMeasurement>::const_iterator snapIter =
1128 std::map<int,timedMeasurement>::const_iterator snapIend =
1134 std::map<int,int>::const_iterator layerIter;
1135 std::map<int,int>::const_iterator layerIend =
layerMap.end();
1136 if ( ( layerIter =
layerMap.find( rawL ) ) != layerIend ) {
1137 const std::pair<int,int>& layerEntry = *layerIter;
1138 int dpId = layerEntry.second;
1140 if ( snapIter != snapIend ) {
1141 const std::pair<int,timedMeasurement>& snapEntry = *snapIter;
1142 valueL = snapEntry.second.second;
1144 else std::cout <<
"snapR not found" << std::endl;
1146 else std::cout <<
"rawR not found" << std::endl;
1147 if ( ( layerIter =
layerMap.find( rawR ) ) != layerIend ) {
1148 const std::pair<int,int>& layerEntry = *layerIter;
1149 int dpId = layerEntry.second;
1151 if ( snapIter != snapIend ) {
1152 const std::pair<int,timedMeasurement>& snapEntry = *snapIter;
1153 valueR = snapEntry.second.second;
1155 else std::cout <<
"snapL not found" << std::endl;
1157 else std::cout <<
"rawL not found" << std::endl;
1158 if ( ( layerIter =
layerMap.find( rawS ) ) != layerIend ) {
1159 const std::pair<int,int>& layerEntry = *layerIter;
1160 int dpId = layerEntry.second;
1162 if ( snapIter != snapIend ) {
1163 const std::pair<int,timedMeasurement>& snapEntry = *snapIter;
1164 valueS = snapEntry.second.second;
1166 else std::cout <<
"snapS not found" << std::endl;
1168 else std::cout <<
"rawS not found" << std::endl;
1169 if ( ( layerIter =
layerMap.find( rawC ) ) != layerIend ) {
1170 const std::pair<int,int>& layerEntry = *layerIter;
1171 int dpId = layerEntry.second;
1173 if ( snapIter != snapIend ) {
1174 const std::pair<int,timedMeasurement>& snapEntry = *snapIter;
1175 valueC = snapEntry.second.second;
1177 else std::cout <<
"snapC not found" << std::endl;
1179 else std::cout <<
"rawC not found" << std::endl;
1189 int whe,
int sta,
int sec,
1190 int qua,
int lay,
int l_p,
1197 int searchStatus = hv->
get( whe, sta, sec, qua, lay, l_p,
1198 fCell, lCell, flagA, flagC, flagS );
1199 if ( searchStatus ) {
1200 DTWireId wireId( whe, sta, sec, qua, lay, 10 + l_p );
1201 std::map<int,int>::const_iterator splitIter =
1203 std::map<int,int>::const_iterator splitIend =
1205 if ( splitIter != splitIend ) {
1206 int code = splitIter->second;
1207 fCell = code / 10000;
1208 lCell = code % 10000;
1214 hv->
set( whe, sta, sec, qua, lay, l_p,
1215 fCell, lCell, flagA, flagC, flagS );
1221 float oldValue,
float newValue ) {
1222 int dpId = chan / 10;
1223 int type = chan % 10;
1224 std::map<int,int>::const_iterator aliasIter =
aliasMap.find( dpId );
1225 std::map<int,int>::const_iterator aliasIend =
aliasMap.end();
1226 if ( aliasIter == aliasIend )
return false;
1227 int rawId = aliasIter->second;
1229 int l_p = chlId.
wire();
1242 valueL, valueC, valueS,
1248 valueR, valueC, valueS,
1253 if ( valueL != oldValue )
std::cout <<
"*** INCONSISTENT DATA!!!!! "
1254 << type <<
" " << l_p <<
" "
1255 << oldValue <<
" " << valueL <<
" "
1260 if ( valueR != oldValue )
std::cout <<
"*** INCONSISTENT DATA!!!!! "
1261 << type <<
" " << l_p <<
" "
1262 << oldValue <<
" " << valueR <<
" "
1267 if ( valueS != oldValue )
std::cout <<
"*** INCONSISTENT DATA!!!!! "
1268 << type <<
" " << l_p <<
" "
1269 << oldValue <<
" " << valueS <<
" "
1274 if ( valueC != oldValue )
std::cout <<
"*** INCONSISTENT DATA!!!!! "
1275 << type <<
" " << l_p <<
" "
1276 << oldValue <<
" " << valueC <<
" "
1286 valueL, valueC, valueS,
1292 valueR, valueC, valueS,
1298 std::cout <<
"changed status: " << chan <<
" from "
1299 << oldValue <<
" to " << newValue << std::endl;
1317 std::vector< std::pair<DTHVStatus*, cond::Time_t> >::const_iterator iter =
1319 std::vector< std::pair<DTHVStatus*, cond::Time_t> >::const_iterator iend =
1321 std::vector< std::pair<DTHVStatus*, cond::Time_t> >::const_iterator prev;
1322 std::vector< std::pair<DTHVStatus*, cond::Time_t> >::const_iterator
next;
1324 while ( iter != iend ) {
1328 if ( next == iend ) next = prev;
1332 iSize = std::distance( iPtr->
begin(), iPtr->
end() );
1333 pSize = std::distance( pPtr->
begin(), pPtr->
end() );
1334 nSize = std::distance( nPtr->
begin(), nPtr->
end() );
1335 int dtot = nSize - pSize;
1337 while ( ++next != iend ) {
1340 pSize = std::distance( pPtr->
begin(), pPtr->
end() );
1341 nSize = std::distance( nPtr->
begin(), nPtr->
end() );
1342 int diff = nSize - pSize;
1343 iTime =
static_cast<int>( ( iter->second >> 32 ) & 0xffffffff );
1344 pTime =
static_cast<int>( ( prev->second >> 32 ) & 0xffffffff );
1345 nTime =
static_cast<int>( ( next->second >> 32 ) & 0xffffffff );
1346 if ( ( nTime - pTime ) > maxTime )
break;
1347 if ( ( nTime - iTime ) > maxTtot )
break;
1348 if ( ( dtot * diff ) < 0 )
break;
1352 iSize = std::distance( iPtr->
begin(), iPtr->
end() );
1353 pSize = std::distance( pPtr->
begin(), pPtr->
end() );
1354 dtot = pSize - iSize;
1355 int dist = pTime - iTime;
1356 if ( ( dtot < -minDiff ) &&
1357 ( dist < maxTtot ) ) {
1359 << std::distance( iter, prev ) <<
" "
1360 << iTime <<
" " << pTime <<
" "
1361 << iSize <<
" " << pSize << std::endl;
1362 m_to_transfer.push_back( std::make_pair( prev->first, prev->second ) );
1363 while ( iter != prev )
delete ( iter++->first );
1365 if ( ( dtot > minDiff ) &&
1366 ( dist < maxTtot ) ) {
1368 << std::distance( iter, prev ) <<
" "
1369 << iTime <<
" " << pTime <<
" "
1370 << iSize <<
" " << pSize << std::endl;
1371 m_to_transfer.push_back( std::make_pair( prev->first, iter->second ) );
1373 while ( iter != prev )
delete ( iter++->first );
1375 if ( ( ( dtot >= -minDiff ) && ( dtot <= minDiff ) ) ||
1376 ( dist >= maxTtot ) ) {
1377 while ( iter != next ) {
1378 const std::pair<DTHVStatus*, cond::Time_t>& entry = *iter++;
1379 m_to_transfer.push_back( std::make_pair( entry.first, entry.second ) );
1390 int whe = chlId.
wheel ();
1392 int sec = chlId.
sector ();
1394 int lay = chlId.
layer ();
1395 DTWireId chl( whe, sta, sec, qua, lay, 10 + l_p );
1401 long long int iTime = ( ( ( ( time >> 32 ) & 0xFFFFFFFF ) * 1000000000 ) +
1402 ( ( time & 0xFFFFFFFF ) * 1000 ) );
1403 coral::TimeStamp cTime( iTime );
1409 cond::Time_t cTime = ( ( time.total_nanoseconds() / 1000000000 ) << 32 ) +
1410 ( ( time.total_nanoseconds() % 1000000000 ) / 1000 );
1417 ( ( 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
edm::Ref< Container > Ref
std::map< int, int > aliasMap
DTHVAbstractCheck::timedMeasurement timedMeasurement
DbTransaction & transaction()
void open(const std::string &connectionString, bool readOnly=false)
int commit()
commit transaction.
DbConnectionConfiguration & configuration()
void getLayerValues(int rawId, int type, float &valueL, float &valueR, float &valueS, float &valueC)
std::string onlineConnect
cond::DbSession buff_session
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)
std::map< int, std::vector< int > * > channelSplit
DTHVStatusHandler(const edm::ParameterSet &ps)
DTHVStatus * offlineList()
OldContainer m_to_transfer
std::vector< std::pair< DTHVStatus *, cond::Time_t > > tmpContainer
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
uint32_t rawId() const
get the raw id
cond::DbConnection buff_conn
static coral::TimeStamp coralTime(const cond::Time_t &time)
int checkStatusChange(int type, float oldValue, float newValue)
cond::ValidityInterval lastInterval
int start(bool readOnly=false)
start transaction
static bool compare(const DTHVAbstractCheck::flag &fl, const DTHVAbstractCheck::flag &fr)
std::map< int, int > laySplit
unsigned long long Time_t
void dumpSnapshot(const coral::TimeStamp &time)
static cond::Time_t condTime(const coral::TimeStamp &time)
std::map< int, timedMeasurement > snapshotValues
int superLayer() const
Return the superlayer number.
std::map< int, int > layerMap
int checkForPeriod(cond::Time_t condSince, cond::Time_t condUntil, int &missingChannels, bool copyOffline)
static DTHVAbstractCheck * getInstance()
check HV status
std::vector< std::pair< DTHVStatusId, DTHVStatusData > >::const_iterator const_iterator
Access methods to data.
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.
cond::DbConnection util_conn
std::string onlineAuthentication
DbSession createSession() const
int set(int wheelId, int stationId, int sectorId, int slId, int layerId, int partId, int fCell, int lCell, int flagA, int flagC, int flagS)
coral::ISchema & nominalSchema()
cond::DbSession util_session
std::pair< int, float > channelValue
void setAuthenticationPath(const std::string &p)
char data[epos_bytes_allocation]
cond::DbSession omds_session
const_iterator end() const
DTHVAbstractCheck * hvChecker
std::string bufferConnect
const_iterator begin() const
int station() const
Return the station number.
int wheel() const
Return the wheel number.
virtual ~DTHVStatusHandler()
cond::DbConnection omds_conn
cond::TagInfo_t const & tagInfo() const