28 #include "RelationalAccess/ISchema.h"
29 #include "RelationalAccess/ITable.h"
30 #include "RelationalAccess/ICursor.h"
31 #include "RelationalAccess/IQuery.h"
32 #include "RelationalAccess/TableDescription.h"
33 #include "RelationalAccess/ITableDataEditor.h"
34 #include "CoralBase/AttributeList.h"
35 #include "CoralBase/AttributeSpecification.h"
36 #include "CoralBase/Attribute.h"
37 #include "CoralBase/TimeStamp.h"
54 dataTag( ps.getParameter<std::
string> (
"tag" ) ),
55 onlineConnect( ps.getParameter<std::
string> (
"onlineDB" ) ),
56 utilConnect( ps.getParameter<std::
string> (
"utilDB" ) ),
57 onlineAuthentication( ps.getParameter<std::
string> (
58 "onlineAuthentication" ) ),
59 bufferConnect( ps.getParameter<std::
string> (
"bufferDB" ) ),
60 ySince( ps.getParameter<int> (
"sinceYear" ) ),
61 mSince( ps.getParameter<int> (
"sinceMonth" ) ),
62 dSince( ps.getParameter<int> (
"sinceDay" ) ),
63 hSince( ps.getParameter<int> (
"sinceHour" ) ),
64 pSince( ps.getParameter<int> (
"sinceMinute" ) ),
65 sSince( ps.getParameter<int> (
"sinceSecond" ) ),
66 yUntil( ps.getParameter<int> (
"untilYear" ) ),
67 mUntil( ps.getParameter<int> (
"untilMonth" ) ),
68 dUntil( ps.getParameter<int> (
"untilDay" ) ),
69 hUntil( ps.getParameter<int> (
"untilHour" ) ),
70 pUntil( ps.getParameter<int> (
"untilMinute" ) ),
71 sUntil( ps.getParameter<int> (
"untilSecond" ) ),
72 dumpAtStart( ps.getParameter<bool>(
"dumpAtStart" ) ),
73 dumpAtEnd( ps.getParameter<bool>(
"dumpAtEnd" ) ),
74 bwdTime( ps.getParameter<long long int> (
"bwdTime" ) ),
75 fwdTime( ps.getParameter<long long int> (
"fwdTime" ) ),
76 minTime( ps.getParameter<long long int> (
"minTime" ) ),
83 mapVersion( ps.getParameter<std::
string> (
"mapVersion" ) ),
84 splitVersion( ps.getParameter<std::
string> (
"splitVersion" ) ) {
85 std::cout <<
" PopCon application for DT HV data export "
103 std::cout <<
"get new objects..." << std::endl;
106 std::cout <<
"configure omds DbConnection" << std::endl;
110 std::cout <<
"create omds DbSession" << std::endl;
112 std::cout <<
"open omds session" << std::endl;
114 std::cout <<
"start omds transaction" << std::endl;
119 std::cout <<
"configure util DbConnection" << std::endl;
123 std::cout <<
"create util DbSession" << std::endl;
125 std::cout <<
"open util session" << std::endl;
127 std::cout <<
"startutil transaction" << std::endl;
132 std::cout <<
"configure buffer DbConnection" << std::endl;
135 std::cout <<
"create buffer DbSession" << std::endl;
137 std::cout <<
"open buffer session" << std::endl;
139 std::cout <<
"start buffer transaction" << std::endl;
147 std::cout <<
"latest DCS data (HV) already copied until: "
148 << last << std::endl;
164 m_to_transfer.push_back( std::make_pair( dummyStatus, snc ) );
166 std::cout <<
"no old data... " << last << std::endl;
172 while ( paylIter != paylIend ) {
173 const std::pair<DTHVStatusId,DTHVStatusData>& entry = *paylIter++;
177 chan. slId, chan.
layerId, chan. partId + 10 );
184 coral::TimeStamp coralLast =
coralTime( last );
189 std::cout <<
"Required time interval in the future: "
191 <<
" copy since " <<
ySince <<
" "
194 <<
" ( " <<
procSince <<
" )" << std::endl
195 <<
" current time " << coralProc.year( ) <<
" "
196 << coralProc.month() <<
" "
197 << coralProc.day( ) << std::endl;
206 std::cout <<
"Required time interval already copied: "
208 <<
" copy until " <<
yUntil <<
" "
211 <<
" ( " <<
procUntil <<
" )" << std::endl
212 <<
" data until " << coralLast.year( ) <<
" "
213 << coralLast.month() <<
" "
214 << coralLast.day( ) << std::endl;
218 std::cout <<
"Required time interval not contiguous with copied data: "
220 <<
" data until " << coralLast.year( ) <<
" "
221 << coralLast.month() <<
" "
222 << coralLast.day( ) << std::endl
223 <<
" copy since " <<
ySince <<
" "
226 <<
" ( " <<
procSince <<
" )" << std::endl;
267 std::set<std::string>::const_iterator omds_iter = omds_lt.begin();
268 std::set<std::string>::const_iterator omds_iend = omds_lt.end();
269 while ( omds_iter != omds_iend ) {
271 std::cout <<
"TABLE: " << istr << std::endl;
275 std::set<std::string>::const_iterator util_iter = util_lt.begin();
276 std::set<std::string>::const_iterator util_iend = util_lt.end();
277 while ( util_iter != util_iend ) {
279 std::cout <<
"TABLE: " << istr << std::endl;
286 std::cout <<
"open buffer db..." << std::endl;
297 return "DTHVStatusHandler";
307 std::cout <<
"retrieve aliases table..." << std::endl;
308 coral::ITable& hvalTable =
310 std::auto_ptr<coral::IQuery> hvalQuery( hvalTable.newQuery() );
311 hvalQuery->addToOutputList(
"DETID" );
312 hvalQuery->addToOutputList(
"DPID" );
313 coral::ICursor& hvalCursor = hvalQuery->execute();
316 while ( hvalCursor.next() ) {
317 chId = hvalCursor.currentRow()[
"DETID"].data<
int>();
318 dpId = hvalCursor.currentRow()[
"DPID"].data<
int>();
319 aliasMap.insert( std::pair<int,int>( dpId, chId ) );
320 layerMap.insert( std::pair<int,int>( chId, dpId ) );
330 std::cout <<
"retrieve layer split table..." << std::endl;
339 coral::ITable& lsplTable =
341 std::cout <<
" layer split table got..." << std::endl;
342 std::auto_ptr<coral::IQuery> lsplQuery( lsplTable.newQuery() );
343 coral::AttributeList versionBindVariableList;
344 versionBindVariableList.extend(
"version",
typeid(
std::string) );
346 lsplQuery->setCondition(
"VERSION=:version", versionBindVariableList );
347 lsplQuery->addToOutputList(
"WHEEL" );
348 lsplQuery->addToOutputList(
"SECTOR" );
349 lsplQuery->addToOutputList(
"STATION" );
350 lsplQuery->addToOutputList(
"SUPERLAYER" );
351 lsplQuery->addToOutputList(
"LAYER" );
352 lsplQuery->addToOutputList(
"PART" );
353 lsplQuery->addToOutputList(
"FIRST_CELL" );
354 lsplQuery->addToOutputList(
"LAST_CELL" );
355 coral::ICursor& lsplCursor = lsplQuery->execute();
356 while ( lsplCursor.next() ) {
357 whe = lsplCursor.currentRow()[
"WHEEL" ].data<
int>();
358 sec = lsplCursor.currentRow()[
"SECTOR" ].data<
int>();
359 sta = lsplCursor.currentRow()[
"STATION" ].data<
int>();
360 qua = lsplCursor.currentRow()[
"SUPERLAYER"].data<
int>();
361 lay = lsplCursor.currentRow()[
"LAYER" ].data<
int>();
362 l_p = lsplCursor.currentRow()[
"PART" ].data<
int>();
363 f_c = lsplCursor.currentRow()[
"FIRST_CELL"].data<
int>();
364 l_c = lsplCursor.currentRow()[
"LAST_CELL"].data<
int>();
365 DTWireId wireId( whe, sta, sec, qua, lay, 10 + l_p );
366 laySplit.insert( std::pair<int,int>( wireId.rawId(),
367 ( f_c * 10000 ) + l_c ) );
369 std::cout <<
"channel split table retrieved" << std::endl;
375 std::cout <<
"retrieve channel split table..." << std::endl;
388 coral::ITable& csplTable =
390 std::auto_ptr<coral::IQuery> csplQuery( csplTable.newQuery() );
391 coral::AttributeList versionBindVariableList;
392 versionBindVariableList.extend(
"version",
typeid(
std::string) );
394 csplQuery->setCondition(
"VERSION=:version", versionBindVariableList );
395 csplQuery->addToOutputList(
"P_WHEEL" );
396 csplQuery->addToOutputList(
"P_SECTOR" );
397 csplQuery->addToOutputList(
"P_STATION" );
398 csplQuery->addToOutputList(
"P_SUPERLAYER" );
399 csplQuery->addToOutputList(
"P_LAYER" );
400 csplQuery->addToOutputList(
"P_PART" );
401 csplQuery->addToOutputList(
"S_NUMBER" );
402 csplQuery->addToOutputList(
"S_WHEEL" );
403 csplQuery->addToOutputList(
"S_SECTOR" );
404 csplQuery->addToOutputList(
"S_STATION" );
405 csplQuery->addToOutputList(
"S_SUPERLAYER" );
406 csplQuery->addToOutputList(
"S_LAYER" );
407 csplQuery->addToOutputList(
"S_PART" );
408 coral::ICursor& csplCursor = csplQuery->execute();
409 while ( csplCursor.next() ) {
410 pwhe = csplCursor.currentRow()[
"P_WHEEL" ].data<
int>();
411 psec = csplCursor.currentRow()[
"P_SECTOR" ].data<
int>();
412 psta = csplCursor.currentRow()[
"P_STATION" ].data<
int>();
413 pqua = csplCursor.currentRow()[
"P_SUPERLAYER"].data<
int>();
414 play = csplCursor.currentRow()[
"P_LAYER" ].data<
int>();
415 pl_p = csplCursor.currentRow()[
"P_PART" ].data<
int>();
416 csplCursor.currentRow()[
"S_NUMBER" ].data<
int>();
417 swhe = csplCursor.currentRow()[
"S_WHEEL" ].data<
int>();
418 ssec = csplCursor.currentRow()[
"S_SECTOR" ].data<
int>();
419 ssta = csplCursor.currentRow()[
"S_STATION" ].data<
int>();
420 squa = csplCursor.currentRow()[
"S_SUPERLAYER"].data<
int>();
421 slay = csplCursor.currentRow()[
"S_LAYER" ].data<
int>();
422 sl_p = csplCursor.currentRow()[
"S_PART" ].data<
int>();
423 DTWireId pId( pwhe, psta, psec, pqua, play, 10 + pl_p );
424 DTWireId sId( swhe, ssta, ssec, squa, slay, 10 + sl_p );
425 int pRaw = pId.rawId();
426 int sRaw = sId.
rawId();
427 std::vector<int>* splitList = 0;
428 std::map< int,std::vector<int>* >::iterator
iter =
430 std::map< int,std::vector<int>* >::iterator iend =
432 if ( iter == iend ) {
434 std::vector<int>* >( pRaw, splitList =
435 new std::vector<int> ) );
438 splitList = iter->second;
440 splitList->push_back( sRaw );
448 std::cout <<
"DTHVStatusHandler::dumpHVAliases - begin" << std::endl;
450 std::cout <<
"create aliases description..." << std::endl;
451 coral::TableDescription hvalDesc;
452 hvalDesc.setName(
"HVALIASES" );
453 hvalDesc.insertColumn(
"DETID",
454 coral::AttributeSpecification::typeNameForId(
456 hvalDesc.insertColumn(
"DPID",
457 coral::AttributeSpecification::typeNameForId(
459 std::cout <<
"create aliases table..." << std::endl;
460 coral::ITable& hvalTable =
463 std::cout <<
"open DPNAME table..." << std::endl;
464 std::map<int,std::string> idMap;
465 coral::ITable& dpidTable =
467 std::auto_ptr<coral::IQuery> dpidQuery( dpidTable.newQuery() );
468 dpidQuery->addToOutputList(
"ID" );
469 dpidQuery->addToOutputList(
"DPNAME" );
470 coral::ICursor& dpidCursor = dpidQuery->execute();
471 while( dpidCursor.next() ) {
472 const coral::AttributeList& row = dpidCursor.currentRow();
473 int id =
static_cast<int>( 0.01 +
474 row[
"ID" ].data<
float>() );
476 idMap.insert( std::pair<int,std::string>(
id, dp ) );
478 std::cout <<
"DPNAME table read... " << idMap.size() << std::endl;
480 std::cout <<
"open ALIASES table..." << std::endl;
481 std::map<std::string,std::string> cnMap;
482 coral::ITable& nameTable =
484 std::auto_ptr<coral::IQuery> nameQuery( nameTable.newQuery() );
485 nameQuery->addToOutputList(
"DPE_NAME" );
486 nameQuery->addToOutputList(
"ALIAS" );
487 coral::ICursor& nameCursor = nameQuery->execute();
488 while( nameCursor.next() ) {
489 const coral::AttributeList& row = nameCursor.currentRow();
492 if ( an.length() < 20 )
continue;
493 cnMap.insert( std::pair<std::string,std::string>( dp, an ) );
495 std::cout <<
"ALIASES table read... " << cnMap.size() << std::endl;
497 std::map<int,std::string>::const_iterator idIter = idMap.begin();
498 std::map<int,std::string>::const_iterator idIend = idMap.end();
500 while ( idIter != idIend ) {
501 const std::pair<int,std::string>& ientry = *idIter++;
502 int dpId = ientry.first;
504 int ldp = dp.length();
505 if ( ldp < 20 )
continue;
508 if ( subChk != outChk )
continue;
510 chName +=
".actual.OvC";
511 int chCode = subOut.c_str()[16] -
'0';
512 std::map<std::string,std::string>::const_iterator jter =
513 cnMap.find( chName );
514 if ( jter == cnMap.end() )
continue;
515 const std::pair<std::string,std::string>& jentry = *jter;
516 std::cout << dp << std::endl << chName <<
" " << chCode << std::endl;
518 int al = an.length();
519 int iofw = 7 + an.find(
"DT_HV_W", 0 );
520 int iofc = 3 + an.find(
"_MB", 0 );
521 int iofs = 2 + an.find(
"_S" , 0 );
522 int iofq = 3 + an.find(
"_SL", 0 );
523 int iofl = 2 + an.find(
"_L" , 0 );
524 if ( ( iofw == al ) ||
531 int ioew = an.find(
"_", iofw );
532 int ioec = an.find(
"_", iofc );
533 int ioes = an.find(
"_", iofs );
534 int ioeq = an.find(
"_", iofq );
535 int ioel = an.find(
"_", iofl );
536 std::string swhe( an.substr( iofw, ioew - iofw ) );
537 const char* cwhe = swhe.c_str();
538 int whe = cwhe[1] -
'0';
539 if ( *cwhe !=
'P' ) whe = -whe;
541 std::string scha( an.substr( iofc, ioec - iofc ) );
542 const char* ccha = scha.c_str();
543 int cha = *ccha -
'0';
545 std::string ssec( an.substr( iofs, ioes - iofs ) );
546 const char* csec = ssec.c_str();
547 int sec = ( ( *csec -
'0' ) * 10 ) + ( csec[1] -
'0' );
548 if ( ( csec[2] ==
'R' ) && ( sec == 10 ) ) sec = 14;
549 if ( ( csec[2] ==
'L' ) && ( sec == 4 ) ) sec = 13;
551 std::string squa( an.substr( iofq, ioeq - iofq ) );
552 const char* cqua = squa.c_str();
553 int qua = *cqua -
'0';
555 std::string slay( an.substr( iofl, ioel - iofl ) );
556 const char* clay = slay.c_str();
557 int lay = *clay -
'0';
559 DTWireId wireId( whe, cha, sec, qua, lay, 10 + chCode );
560 int chId = wireId.
rawId();
561 coral::AttributeList newChan;
562 newChan.extend(
"DETID",
typeid(
int) );
563 newChan.extend(
"DPID",
typeid(
int) );
564 newChan[
"DETID"].data<
int>() = chId;
565 newChan[
"DPID"].data<
int>() = dpId;
566 hvalTable.dataEditor().insertRow( newChan );
567 aliasMap.insert( std::pair<int,int>( dpId, chId ) );
568 layerMap.insert( std::pair<int,int>( chId, dpId ) );
571 std::cout <<
"DTHVStatusHandler::dumpHVAliases - end" << std::endl;
577 std::cout <<
"create snapshot description..." << std::endl;
578 coral::TableDescription hvssDesc;
579 hvssDesc.setName(
"HVSNAPSHOT" );
580 hvssDesc.insertColumn(
"TIME",
581 coral::AttributeSpecification::typeNameForId(
582 typeid(coral::TimeStamp) ) );
583 hvssDesc.insertColumn(
"WHEEL",
584 coral::AttributeSpecification::typeNameForId(
586 hvssDesc.insertColumn(
"STATION",
587 coral::AttributeSpecification::typeNameForId(
589 hvssDesc.insertColumn(
"SECTOR",
590 coral::AttributeSpecification::typeNameForId(
592 hvssDesc.insertColumn(
"SUPERLAYER",
593 coral::AttributeSpecification::typeNameForId(
595 hvssDesc.insertColumn(
"LAYER",
596 coral::AttributeSpecification::typeNameForId(
598 hvssDesc.insertColumn(
"CHAN",
599 coral::AttributeSpecification::typeNameForId(
601 hvssDesc.insertColumn(
"TYPE",
602 coral::AttributeSpecification::typeNameForId(
604 hvssDesc.insertColumn(
"VALUE",
605 coral::AttributeSpecification::typeNameForId(
607 std::cout <<
"create snapshot table..." << std::endl;
609 coral::ITable& bufferTable =
611 coral::AttributeList newMeas;
612 newMeas.extend(
"TIME",
typeid(coral::TimeStamp) );
613 newMeas.extend(
"WHEEL",
typeid(
int) );
614 newMeas.extend(
"STATION",
typeid(
int) );
615 newMeas.extend(
"SECTOR",
typeid(
int) );
616 newMeas.extend(
"SUPERLAYER",
typeid(
int) );
617 newMeas.extend(
"LAYER",
typeid(
int) );
618 newMeas.extend(
"CHAN",
typeid(
int) );
619 newMeas.extend(
"TYPE",
typeid(
int) );
620 newMeas.extend(
"VALUE",
typeid(
float) );
622 long long int zeroTime = 0LL;
623 newMeas[
"TIME" ].data<coral::TimeStamp>() =
624 coral::TimeStamp( zeroTime );
625 newMeas[
"VALUE" ].data<
float>() = -999999.0;
627 std::map<int,int>::const_iterator
iter =
aliasMap.begin();
628 std::map<int,int>::const_iterator iend =
aliasMap.end();
629 while ( iter != iend ) {
630 const std::pair<int,int>& entry= *iter++;
631 int detId = entry.second;
633 newMeas[
"WHEEL" ].data<
int>() = chlId.
wheel ();
634 newMeas[
"STATION" ].data<
int>() = chlId.
station ();
635 newMeas[
"SECTOR" ].data<
int>() = chlId.
sector ();
636 newMeas[
"SUPERLAYER"].data<
int>() = chlId.
superLayer();
637 newMeas[
"LAYER" ].data<
int>() = chlId.
layer ();
638 newMeas[
"CHAN" ].data<
int>() = chlId.
wire () - 10;
640 for ( itype = 1; itype <= 2; itype++ ) {
641 newMeas[
"TYPE" ].data<
int>() = itype;
642 bufferTable.dataEditor().insertRow( newMeas );
646 std::cout <<
"create logging info..." << std::endl;
649 coral::TableDescription infoDesc;
650 infoDesc.setName(
"LOG" );
651 infoDesc.insertColumn(
"EXECTIME",
652 coral::AttributeSpecification::typeNameForId(
653 typeid(coral::TimeStamp) ) );
654 infoDesc.insertColumn(
"SNAPSHOT",
655 coral::AttributeSpecification::typeNameForId(
656 typeid(coral::TimeStamp) ) );
658 coral::AttributeList newInfo;
659 newInfo.extend(
"EXECTIME",
typeid(coral::TimeStamp) );
660 newInfo.extend(
"SNAPSHOT",
typeid(coral::TimeStamp) );
661 newInfo[
"EXECTIME"].data<coral::TimeStamp>() =
662 coral::TimeStamp( zeroTime );
663 newInfo[
"SNAPSHOT"].data<coral::TimeStamp>() =
664 coral::TimeStamp( zeroTime );
665 coral::ITable& infoTable =
667 infoTable.dataEditor().insertRow( newInfo );
677 std::cout <<
" snapshot at " << snapshotTime <<
" ( "
679 .total_nanoseconds() <<
" ) "
682 coral::TimeStamp coralSnap =
coralTime( snapshotTime );
683 std::cout <<
"too recent snapshot: " << std::endl
684 <<
" snapshot at " << coralSnap.year( ) <<
" "
685 << coralSnap.month() <<
" "
686 << coralSnap.day( ) << std::endl
687 <<
" copy since " <<
ySince <<
" "
690 <<
" ( " <<
procSince <<
" )" << std::endl;
698 while ( missingChannels ) {
700 << condSince <<
" ( " <<
coralTime( condSince )
701 .total_nanoseconds() <<
" ) -> "
702 << condUntil <<
" ( " <<
coralTime( condUntil )
703 .total_nanoseconds() <<
" ) "
705 if ( condSince <= snapshotTime ) condSince = snapshotTime;
707 << condSince <<
" ( " <<
coralTime( condSince )
708 .total_nanoseconds() <<
" ) "
710 if ( condSince >= condUntil )
break;
711 std::cout <<
"missing... " << missingChannels << std::endl;
713 condUntil = condSince;
714 condSince = condUntil - dTime;
728 int missingChannels = 0;
729 std::map<int,int>::const_iterator layIter =
layerMap.begin();
730 std::map<int,int>::const_iterator layIend =
layerMap.end();
731 std::cout <<
"retrieve snapshot table..." << std::endl;
732 coral::ITable& hvssTable =
734 std::auto_ptr<coral::IQuery> hvssQuery( hvssTable.newQuery() );
735 hvssQuery->addToOutputList(
"TIME" );
736 hvssQuery->addToOutputList(
"WHEEL" );
737 hvssQuery->addToOutputList(
"STATION" );
738 hvssQuery->addToOutputList(
"SECTOR" );
739 hvssQuery->addToOutputList(
"SUPERLAYER" );
740 hvssQuery->addToOutputList(
"LAYER" );
741 hvssQuery->addToOutputList(
"CHAN" );
742 hvssQuery->addToOutputList(
"TYPE" );
743 hvssQuery->addToOutputList(
"VALUE" );
744 coral::ICursor& hvssCursor = hvssQuery->execute();
745 while ( hvssCursor.next() ) {
746 coral::TimeStamp
time =
747 hvssCursor.currentRow()[
"TIME"].data<coral::TimeStamp>();
748 int whe = hvssCursor.currentRow()[
"WHEEL" ].data<
int>();
749 int sta = hvssCursor.currentRow()[
"STATION" ].data<
int>();
750 int sec = hvssCursor.currentRow()[
"SECTOR" ].data<
int>();
751 int qua = hvssCursor.currentRow()[
"SUPERLAYER"].data<
int>();
752 int lay = hvssCursor.currentRow()[
"LAYER" ].data<
int>();
753 int l_p = hvssCursor.currentRow()[
"CHAN" ].data<
int>();
754 int mty = hvssCursor.currentRow()[
"TYPE" ].data<
int>();
755 float value = hvssCursor.currentRow()[
"VALUE" ].data<
float>();
756 if ( mty > 2 )
continue;
757 DTWireId wireId( whe, sta, sec, qua, lay, 10 + l_p );
759 if ( layIter == layIend ) {
762 int dpId = ( layIter->second * 10 ) + mty;
765 time.total_nanoseconds(),
value ) ) );
768 return missingChannels;
773 long long int lastTime = 0LL;
774 long long int chanTime = 0LL;
775 std::map<int,timedMeasurement>::iterator mapIter =
snapshotValues.begin();
776 std::map<int,timedMeasurement>::iterator mapIend =
snapshotValues.end();
777 while ( mapIter != mapIend ) {
778 const std::pair<int,timedMeasurement>& entry = *mapIter++;
779 chanTime = entry.second.first;
780 if ( lastTime < chanTime ) lastTime = chanTime;
800 std::cout <<
"dump snapshot to buffer db..." << std::endl;
802 coral::AttributeList emptyBindVariableList;
803 std::map<int,int>::const_iterator mapIter =
aliasMap.begin();
804 std::map<int,int>::const_iterator mapIend =
aliasMap.end();
805 coral::ITable& hvssTable =
807 coral::ITableDataEditor& hvssEditor( hvssTable.dataEditor() );
808 long nRows = hvssEditor.deleteRows( emptyCondition, emptyBindVariableList );
809 std::cout << nRows <<
" rows deleted" << std::endl;
811 coral::AttributeList newMeas;
812 newMeas.extend(
"TIME",
typeid(coral::TimeStamp) );
813 newMeas.extend(
"WHEEL",
typeid(
int) );
814 newMeas.extend(
"STATION",
typeid(
int) );
815 newMeas.extend(
"SECTOR",
typeid(
int) );
816 newMeas.extend(
"SUPERLAYER",
typeid(
int) );
817 newMeas.extend(
"LAYER",
typeid(
int) );
818 newMeas.extend(
"CHAN",
typeid(
int) );
819 newMeas.extend(
"TYPE",
typeid(
int) );
820 newMeas.extend(
"VALUE",
typeid(
float) );
823 std::map<int,timedMeasurement>::const_iterator ssvIter =
825 std::map<int,timedMeasurement>::const_iterator ssvIend =
827 while ( ssvIter != ssvIend ) {
828 const std::pair<int,timedMeasurement>& entry = *ssvIter++;
829 int dpty = entry.first;
830 int dpId = dpty / 10;
831 int type = dpty % 10;
833 if ( mapIter == mapIend )
continue;
836 long long int newTime = tMeas.first;
837 newMeas[
"TIME" ].data<coral::TimeStamp>() =
838 coral::TimeStamp( newTime );
839 newMeas[
"WHEEL" ].data<
int>() = chlId.
wheel ();
840 newMeas[
"STATION" ].data<
int>() = chlId.
station ();
841 newMeas[
"SECTOR" ].data<
int>() = chlId.
sector ();
842 newMeas[
"SUPERLAYER"].data<
int>() = chlId.
superLayer();
843 newMeas[
"LAYER" ].data<
int>() = chlId.
layer ();
844 newMeas[
"CHAN" ].data<
int>() = chlId.
wire () - 10;
845 newMeas[
"TYPE" ].data<
int>() = type;
846 newMeas[
"VALUE" ].data<
float>() = tMeas.second;
847 hvssEditor.insertRow( newMeas );
850 std::cout << nRows <<
" rows updated" << std::endl;
852 std::cout <<
"create logging info..." << std::endl;
855 coral::TableDescription infoDesc;
856 infoDesc.setName(
"LOG" );
857 infoDesc.insertColumn(
"EXECTIME",
858 coral::AttributeSpecification::typeNameForId(
859 typeid(coral::TimeStamp) ) );
860 infoDesc.insertColumn(
"SNAPSHOT",
861 coral::AttributeSpecification::typeNameForId(
862 typeid(coral::TimeStamp) ) );
864 coral::AttributeList newInfo;
865 newInfo.extend(
"EXECTIME",
typeid(coral::TimeStamp) );
866 newInfo.extend(
"SNAPSHOT",
typeid(coral::TimeStamp) );
868 newInfo[
"SNAPSHOT"].data<coral::TimeStamp>() = time;
869 coral::ITable& infoTable =
871 infoTable.dataEditor().insertRow( newInfo );
880 int& missingChannels,
883 std::map<int,timedMeasurement>::iterator mapIter =
snapshotValues.begin();
884 std::map<int,timedMeasurement>::iterator mapIend =
snapshotValues.end();
886 std::map<long long int,channelValue> periodBuffer;
888 coral::ITable& fwccTable =
890 std::auto_ptr<coral::IQuery> fwccQuery( fwccTable.newQuery() );
891 fwccQuery->addToOutputList(
"DPID" );
892 fwccQuery->addToOutputList(
"CHANGE_DATE" );
893 fwccQuery->addToOutputList(
"ACTUAL_VMON" );
894 fwccQuery->addToOutputList(
"ACTUAL_IMON" );
895 fwccQuery->addToOutputList(
"ACTUAL_ISON" );
896 fwccQuery->addToOutputList(
"ACTUAL_STATUS" );
897 fwccQuery->addToOutputList(
"ACTUAL_OVC" );
898 coral::AttributeList timeBindVariableList;
899 timeBindVariableList.extend(
"since",
typeid(coral::TimeStamp) );
900 timeBindVariableList.extend(
"until",
typeid(coral::TimeStamp) );
901 coral::TimeStamp coralSince =
coralTime( condSince );
902 coral::TimeStamp coralUntil =
coralTime( condUntil );
904 << coralSince.year( ) <<
" "
905 << coralSince.month( ) <<
" "
906 << coralSince.day( ) <<
" "
907 << coralSince.hour( ) <<
":"
908 << coralSince.minute() <<
":"
909 << coralSince.second() <<
" until "
910 << coralUntil.year( ) <<
" "
911 << coralUntil.month( ) <<
" "
912 << coralUntil.day( ) <<
" "
913 << coralUntil.hour( ) <<
":"
914 << coralUntil.minute() <<
":"
915 << coralUntil.second() << std::endl;
916 timeBindVariableList[
"since"].data<coral::TimeStamp>() =
918 timeBindVariableList[
"until"].data<coral::TimeStamp>() =
920 fwccQuery->setCondition(
"CHANGE_DATE>:since and CHANGE_DATE<:until",
921 timeBindVariableList );
922 fwccQuery->addToOrderList(
"CHANGE_DATE" );
923 coral::ICursor& fwccCursor = fwccQuery->execute();
925 while ( fwccCursor.next() ) {
927 const coral::Attribute& dp = fwccCursor.currentRow()[
"DPID" ];
928 const coral::Attribute& vmon = fwccCursor.currentRow()[
"ACTUAL_VMON" ];
929 const coral::Attribute& imon = fwccCursor.currentRow()[
"ACTUAL_IMON" ];
930 coral::TimeStamp changeTime =
931 fwccCursor.currentRow()[
"CHANGE_DATE"].data<coral::TimeStamp>();
932 long long int cTimeValue = changeTime.total_nanoseconds();
933 if ( !copyOffline ) cTimeValue = -cTimeValue;
935 std::cout <<
"------- " << nrows << std::endl;
938 int dpId = 10 *
static_cast<int>( 0.01 +
939 fwccCursor.currentRow()[
"DPID"].data<
float>() );
940 if ( !( vmon.isNull() ) ) {
941 while ( periodBuffer.find( cTimeValue ) !=
942 periodBuffer.end() ) cTimeValue++;
944 periodBuffer.insert( std::pair<long long int,channelValue> (
946 vmon.data<
float>() ) ) );
948 if ( !( imon.isNull() ) ) {
949 while ( periodBuffer.find( cTimeValue ) !=
950 periodBuffer.end() ) cTimeValue++;
952 periodBuffer.insert( std::pair<long long int,channelValue> (
954 imon.data<
float>() ) ) );
960 std::cout <<
"data found in period: " << periodBuffer.size() << std::endl;
961 std::map<long long int,channelValue>::const_iterator bufIter =
962 periodBuffer.begin();
963 std::map<long long int,channelValue>::const_iterator bufIend =
966 bool changedStatus =
false;
967 while ( bufIter != bufIend ) {
968 const std::pair<long long int,channelValue>& entry = *bufIter++;
969 long long int mTime = entry.first;
970 if ( !copyOffline ) mTime = -mTime;
972 int chan = cValue.first;
973 float cont = cValue.second;
975 if ( ( mapIter != mapIend ) &&
976 ( mapIter->second.first < mTime ) ) {
978 if ( changedStatus ) {
982 << hvStatus->
end() - hvStatus->
begin() << std::endl;
984 changedStatus =
false;
987 std::cout <<
"max payload number reached" << std::endl;
992 if ( copyOffline && !changedStatus &&
995 changedStatus =
true;
1010 long long int dTime =
fwdTime;
1019 while ( condSince < condUntil ) {
1021 condSince = condUntil;
1022 condUntil = condSince + dTime;
1025 std::cout <<
"call filterData " << std::endl;
1049 std::map<int,int>::const_iterator layerIter =
layerMap.begin();
1050 std::map<int,int>::const_iterator layerIend =
layerMap.end();
1051 while ( layerIter != layerIend ) {
1052 const std::pair<int,int>& chanEntry = *layerIter++;
1053 int rawId = chanEntry.first;
1055 int whe = chlId.
wheel ();
1057 int sec = chlId.
sector ();
1059 int lay = chlId.
layer ();
1060 int l_p = chlId.
wire();
1061 if ( l_p != 10 )
continue;
1062 for ( type = 1; type <= 2; type++ ) {
1064 for ( l_p = 0; l_p <= 1; l_p++ ) {
1081 valueA, valueC, valueS,
1084 if ( !flag.
a && !flag.
c && !flag.
s )
continue;
1086 std::map< int,std::vector<int>* >::const_iterator m_iter =
1088 std::map< int,std::vector<int>* >::const_iterator m_iend =
1090 if ( m_iter != m_iend ) {
1091 std::vector<int>* cList = m_iter->second;
1092 std::vector<int>::const_iterator l_iter = cList->begin();
1093 std::vector<int>::const_iterator l_iend = cList->end();
1094 while ( l_iter != l_iend ) {
1096 int wh2 = chlId.
wheel ();
1098 int se2 = chlId.
sector ();
1100 int la2 = chlId.
layer ();
1101 int lp2 = chlId.
wire() - 10;
1118 float& valueL,
float& valueR,
1119 float& valueS,
float& valueC ) {
1125 std::map<int,timedMeasurement>::const_iterator snapIter =
1127 std::map<int,timedMeasurement>::const_iterator snapIend =
1133 std::map<int,int>::const_iterator layerIter;
1134 std::map<int,int>::const_iterator layerIend =
layerMap.end();
1135 if ( ( layerIter =
layerMap.find( rawL ) ) != layerIend ) {
1136 const std::pair<int,int>& layerEntry = *layerIter;
1137 int dpId = layerEntry.second;
1139 if ( snapIter != snapIend ) {
1140 const std::pair<int,timedMeasurement>& snapEntry = *snapIter;
1141 valueL = snapEntry.second.second;
1143 else std::cout <<
"snapR not found" << std::endl;
1145 else std::cout <<
"rawR not found" << std::endl;
1146 if ( ( layerIter =
layerMap.find( rawR ) ) != layerIend ) {
1147 const std::pair<int,int>& layerEntry = *layerIter;
1148 int dpId = layerEntry.second;
1150 if ( snapIter != snapIend ) {
1151 const std::pair<int,timedMeasurement>& snapEntry = *snapIter;
1152 valueR = snapEntry.second.second;
1154 else std::cout <<
"snapL not found" << std::endl;
1156 else std::cout <<
"rawL not found" << std::endl;
1157 if ( ( layerIter =
layerMap.find( rawS ) ) != layerIend ) {
1158 const std::pair<int,int>& layerEntry = *layerIter;
1159 int dpId = layerEntry.second;
1161 if ( snapIter != snapIend ) {
1162 const std::pair<int,timedMeasurement>& snapEntry = *snapIter;
1163 valueS = snapEntry.second.second;
1165 else std::cout <<
"snapS not found" << std::endl;
1167 else std::cout <<
"rawS not found" << std::endl;
1168 if ( ( layerIter =
layerMap.find( rawC ) ) != layerIend ) {
1169 const std::pair<int,int>& layerEntry = *layerIter;
1170 int dpId = layerEntry.second;
1172 if ( snapIter != snapIend ) {
1173 const std::pair<int,timedMeasurement>& snapEntry = *snapIter;
1174 valueC = snapEntry.second.second;
1176 else std::cout <<
"snapC not found" << std::endl;
1178 else std::cout <<
"rawC not found" << std::endl;
1188 int whe,
int sta,
int sec,
1189 int qua,
int lay,
int l_p,
1196 int searchStatus = hv->
get( whe, sta, sec, qua, lay, l_p,
1197 fCell, lCell, flagA, flagC, flagS );
1198 if ( searchStatus ) {
1199 DTWireId wireId( whe, sta, sec, qua, lay, 10 + l_p );
1200 std::map<int,int>::const_iterator splitIter =
1202 std::map<int,int>::const_iterator splitIend =
1204 if ( splitIter != splitIend ) {
1205 int code = splitIter->second;
1206 fCell = code / 10000;
1207 lCell = code % 10000;
1213 hv->
set( whe, sta, sec, qua, lay, l_p,
1214 fCell, lCell, flagA, flagC, flagS );
1220 float oldValue,
float newValue ) {
1221 int dpId = chan / 10;
1222 int type = chan % 10;
1223 std::map<int,int>::const_iterator aliasIter =
aliasMap.find( dpId );
1224 std::map<int,int>::const_iterator aliasIend =
aliasMap.end();
1225 if ( aliasIter == aliasIend )
return false;
1226 int rawId = aliasIter->second;
1228 int l_p = chlId.
wire();
1241 valueL, valueC, valueS,
1247 valueR, valueC, valueS,
1252 if ( valueL != oldValue )
std::cout <<
"*** INCONSISTENT DATA!!!!! "
1253 << type <<
" " << l_p <<
" "
1254 << oldValue <<
" " << valueL <<
" "
1259 if ( valueR != oldValue )
std::cout <<
"*** INCONSISTENT DATA!!!!! "
1260 << type <<
" " << l_p <<
" "
1261 << oldValue <<
" " << valueR <<
" "
1266 if ( valueS != oldValue )
std::cout <<
"*** INCONSISTENT DATA!!!!! "
1267 << type <<
" " << l_p <<
" "
1268 << oldValue <<
" " << valueS <<
" "
1273 if ( valueC != oldValue )
std::cout <<
"*** INCONSISTENT DATA!!!!! "
1274 << type <<
" " << l_p <<
" "
1275 << oldValue <<
" " << valueC <<
" "
1285 valueL, valueC, valueS,
1291 valueR, valueC, valueS,
1297 std::cout <<
"changed status: " << chan <<
" from "
1298 << oldValue <<
" to " << newValue << std::endl;
1316 std::vector< std::pair<DTHVStatus*, cond::Time_t> >::const_iterator
iter =
1318 std::vector< std::pair<DTHVStatus*, cond::Time_t> >::const_iterator iend =
1320 std::vector< std::pair<DTHVStatus*, cond::Time_t> >::const_iterator prev;
1321 std::vector< std::pair<DTHVStatus*, cond::Time_t> >::const_iterator
next;
1323 while ( iter != iend ) {
1327 if ( next == iend ) next = prev;
1331 iSize = std::distance( iPtr->
begin(), iPtr->
end() );
1332 pSize = std::distance( pPtr->
begin(), pPtr->
end() );
1333 nSize = std::distance( nPtr->
begin(), nPtr->
end() );
1334 int dtot = nSize - pSize;
1336 while ( ++next != iend ) {
1339 pSize = std::distance( pPtr->
begin(), pPtr->
end() );
1340 nSize = std::distance( nPtr->
begin(), nPtr->
end() );
1341 int diff = nSize - pSize;
1342 iTime =
static_cast<int>( ( iter->second >> 32 ) & 0xffffffff );
1343 pTime =
static_cast<int>( ( prev->second >> 32 ) & 0xffffffff );
1344 nTime =
static_cast<int>( ( next->second >> 32 ) & 0xffffffff );
1345 if ( ( nTime - pTime ) > maxTime )
break;
1346 if ( ( nTime - iTime ) > maxTtot )
break;
1347 if ( ( dtot * diff ) < 0 )
break;
1351 iSize = std::distance( iPtr->
begin(), iPtr->
end() );
1352 pSize = std::distance( pPtr->
begin(), pPtr->
end() );
1353 dtot = pSize - iSize;
1354 int dist = pTime - iTime;
1355 if ( ( dtot < -minDiff ) &&
1356 ( dist < maxTtot ) ) {
1358 << std::distance( iter, prev ) <<
" "
1359 << iTime <<
" " << pTime <<
" "
1360 << iSize <<
" " << pSize << std::endl;
1361 m_to_transfer.push_back( std::make_pair( prev->first, prev->second ) );
1362 while ( iter != prev )
delete ( iter++->first );
1364 if ( ( dtot > minDiff ) &&
1365 ( dist < maxTtot ) ) {
1367 << std::distance( iter, prev ) <<
" "
1368 << iTime <<
" " << pTime <<
" "
1369 << iSize <<
" " << pSize << std::endl;
1370 m_to_transfer.push_back( std::make_pair( prev->first, iter->second ) );
1372 while ( iter != prev )
delete ( iter++->first );
1374 if ( ( ( dtot >= -minDiff ) && ( dtot <= minDiff ) ) ||
1375 ( dist >= maxTtot ) ) {
1376 while ( iter != next ) {
1377 const std::pair<DTHVStatus*, cond::Time_t>& entry = *iter++;
1378 m_to_transfer.push_back( std::make_pair( entry.first, entry.second ) );
1389 int whe = chlId.
wheel ();
1391 int sec = chlId.
sector ();
1393 int lay = chlId.
layer ();
1394 DTWireId chl( whe, sta, sec, qua, lay, 10 + l_p );
1400 long long int iTime = ( ( ( ( time >> 32 ) & 0xFFFFFFFF ) * 1000000000 ) +
1401 ( ( time & 0xFFFFFFFF ) * 1000 ) );
1402 coral::TimeStamp cTime( iTime );
1408 cond::Time_t cTime = ( ( time.total_nanoseconds() / 1000000000 ) << 32 ) +
1409 ( ( time.total_nanoseconds() % 1000000000 ) / 1000 );
1416 ( ( 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