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 ) {
271 const std::string& istr = *omds_iter++;
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 ) {
279 const std::string& istr = *util_iter++;
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) );
346 versionBindVariableList[
"version"].data<std::string>() =
mapVersion;
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;
390 coral::ITable& csplTable =
392 std::auto_ptr<coral::IQuery> csplQuery( csplTable.newQuery() );
393 coral::AttributeList versionBindVariableList;
394 versionBindVariableList.extend(
"version",
typeid(std::string) );
395 versionBindVariableList[
"version"].data<std::string>() =
splitVersion;
396 csplQuery->setCondition(
"VERSION=:version", versionBindVariableList );
397 csplQuery->addToOutputList(
"P_WHEEL" );
398 csplQuery->addToOutputList(
"P_SECTOR" );
399 csplQuery->addToOutputList(
"P_STATION" );
400 csplQuery->addToOutputList(
"P_SUPERLAYER" );
401 csplQuery->addToOutputList(
"P_LAYER" );
402 csplQuery->addToOutputList(
"P_PART" );
403 csplQuery->addToOutputList(
"S_NUMBER" );
404 csplQuery->addToOutputList(
"S_WHEEL" );
405 csplQuery->addToOutputList(
"S_SECTOR" );
406 csplQuery->addToOutputList(
"S_STATION" );
407 csplQuery->addToOutputList(
"S_SUPERLAYER" );
408 csplQuery->addToOutputList(
"S_LAYER" );
409 csplQuery->addToOutputList(
"S_PART" );
410 coral::ICursor& csplCursor = csplQuery->execute();
411 while ( csplCursor.next() ) {
412 pwhe = csplCursor.currentRow()[
"P_WHEEL" ].data<
int>();
413 psec = csplCursor.currentRow()[
"P_SECTOR" ].data<
int>();
414 psta = csplCursor.currentRow()[
"P_STATION" ].data<
int>();
415 pqua = csplCursor.currentRow()[
"P_SUPERLAYER"].data<
int>();
416 play = csplCursor.currentRow()[
"P_LAYER" ].data<
int>();
417 pl_p = csplCursor.currentRow()[
"P_PART" ].data<
int>();
418 snum = csplCursor.currentRow()[
"S_NUMBER" ].data<
int>();
419 swhe = csplCursor.currentRow()[
"S_WHEEL" ].data<
int>();
420 ssec = csplCursor.currentRow()[
"S_SECTOR" ].data<
int>();
421 ssta = csplCursor.currentRow()[
"S_STATION" ].data<
int>();
422 squa = csplCursor.currentRow()[
"S_SUPERLAYER"].data<
int>();
423 slay = csplCursor.currentRow()[
"S_LAYER" ].data<
int>();
424 sl_p = csplCursor.currentRow()[
"S_PART" ].data<
int>();
425 DTWireId pId( pwhe, psta, psec, pqua, play, 10 + pl_p );
426 DTWireId sId( swhe, ssta, ssec, squa, slay, 10 + sl_p );
427 int pRaw = pId.rawId();
428 int sRaw = sId.
rawId();
429 std::vector<int>* splitList = 0;
430 std::map< int,std::vector<int>* >::iterator iter =
432 std::map< int,std::vector<int>* >::iterator iend =
434 if ( iter == iend ) {
436 std::vector<int>* >( pRaw, splitList =
437 new std::vector<int> ) );
440 splitList = iter->second;
442 splitList->push_back( sRaw );
450 std::cout <<
"DTHVStatusHandler::dumpHVAliases - begin" << std::endl;
452 std::cout <<
"create aliases description..." << std::endl;
453 coral::TableDescription hvalDesc;
454 hvalDesc.setName(
"HVALIASES" );
455 hvalDesc.insertColumn(
"DETID",
456 coral::AttributeSpecification::typeNameForId(
458 hvalDesc.insertColumn(
"DPID",
459 coral::AttributeSpecification::typeNameForId(
461 std::cout <<
"create aliases table..." << std::endl;
462 coral::ITable& hvalTable =
465 std::cout <<
"open DPNAME table..." << std::endl;
466 std::map<int,std::string> idMap;
467 coral::ITable& dpidTable =
469 std::auto_ptr<coral::IQuery> dpidQuery( dpidTable.newQuery() );
470 dpidQuery->addToOutputList(
"ID" );
471 dpidQuery->addToOutputList(
"DPNAME" );
472 coral::ICursor& dpidCursor = dpidQuery->execute();
473 while( dpidCursor.next() ) {
474 const coral::AttributeList& row = dpidCursor.currentRow();
475 int id =
static_cast<int>( 0.01 +
476 row[
"ID" ].data<
float>() );
477 std::string dp = row[
"DPNAME"].data<std::string>();
478 idMap.insert( std::pair<int,std::string>(
id, dp ) );
480 std::cout <<
"DPNAME table read... " << idMap.size() << std::endl;
482 std::cout <<
"open ALIASES table..." << std::endl;
483 std::map<std::string,std::string> cnMap;
484 coral::ITable& nameTable =
486 std::auto_ptr<coral::IQuery> nameQuery( nameTable.newQuery() );
487 nameQuery->addToOutputList(
"DPE_NAME" );
488 nameQuery->addToOutputList(
"ALIAS" );
489 coral::ICursor& nameCursor = nameQuery->execute();
490 while( nameCursor.next() ) {
491 const coral::AttributeList& row = nameCursor.currentRow();
492 std::string dp = row[
"DPE_NAME"].data<std::string>();
493 std::string an = row[
"ALIAS" ].data<std::string>();
494 if ( an.length() < 20 )
continue;
495 cnMap.insert( std::pair<std::string,std::string>( dp, an ) );
497 std::cout <<
"ALIASES table read... " << cnMap.size() << std::endl;
499 std::map<int,std::string>::const_iterator idIter = idMap.begin();
500 std::map<int,std::string>::const_iterator idIend = idMap.end();
501 std::string outChk(
"/outputChannel" );
502 while ( idIter != idIend ) {
503 const std::pair<int,std::string>& ientry = *idIter++;
504 int dpId = ientry.first;
505 std::string dp = ientry.second;
506 int ldp = dp.length();
507 if ( ldp < 20 )
continue;
508 std::string subOut( dp.substr( ldp - 17, 17 ) );
509 std::string subChk( subOut.substr( 0, 14 ) );
510 if ( subChk != outChk )
continue;
511 std::string chName( dp.substr( 0, ldp - 17 ) );
512 chName +=
".actual.OvC";
513 int chCode = subOut.c_str()[16] -
'0';
514 std::map<std::string,std::string>::const_iterator jter =
515 cnMap.find( chName );
516 if ( jter == cnMap.end() )
continue;
517 const std::pair<std::string,std::string>& jentry = *jter;
518 std::cout << dp << std::endl << chName <<
" " << chCode << std::endl;
519 std::string an( jentry.second );
520 int al = an.length();
521 int iofw = 7 + an.find(
"DT_HV_W", 0 );
522 int iofc = 3 + an.find(
"_MB", 0 );
523 int iofs = 2 + an.find(
"_S" , 0 );
524 int iofq = 3 + an.find(
"_SL", 0 );
525 int iofl = 2 + an.find(
"_L" , 0 );
526 if ( ( iofw == al ) ||
533 int ioew = an.find(
"_", iofw );
534 int ioec = an.find(
"_", iofc );
535 int ioes = an.find(
"_", iofs );
536 int ioeq = an.find(
"_", iofq );
537 int ioel = an.find(
"_", iofl );
538 std::string swhe( an.substr( iofw, ioew - iofw ) );
539 const char* cwhe = swhe.c_str();
540 int whe = cwhe[1] -
'0';
541 if ( *cwhe !=
'P' ) whe = -whe;
543 std::string scha( an.substr( iofc, ioec - iofc ) );
544 const char* ccha = scha.c_str();
545 int cha = *ccha -
'0';
547 std::string ssec( an.substr( iofs, ioes - iofs ) );
548 const char* csec = ssec.c_str();
549 int sec = ( ( *csec -
'0' ) * 10 ) + ( csec[1] -
'0' );
550 if ( ( csec[2] ==
'R' ) && ( sec == 10 ) ) sec = 14;
551 if ( ( csec[2] ==
'L' ) && ( sec == 4 ) ) sec = 13;
553 std::string squa( an.substr( iofq, ioeq - iofq ) );
554 const char* cqua = squa.c_str();
555 int qua = *cqua -
'0';
557 std::string slay( an.substr( iofl, ioel - iofl ) );
558 const char* clay = slay.c_str();
559 int lay = *clay -
'0';
561 DTWireId wireId( whe, cha, sec, qua, lay, 10 + chCode );
562 int chId = wireId.
rawId();
563 coral::AttributeList newChan;
564 newChan.extend(
"DETID",
typeid(
int) );
565 newChan.extend(
"DPID",
typeid(
int) );
566 newChan[
"DETID"].data<
int>() = chId;
567 newChan[
"DPID"].data<
int>() = dpId;
568 hvalTable.dataEditor().insertRow( newChan );
569 aliasMap.insert( std::pair<int,int>( dpId, chId ) );
570 layerMap.insert( std::pair<int,int>( chId, dpId ) );
573 std::cout <<
"DTHVStatusHandler::dumpHVAliases - end" << std::endl;
579 std::cout <<
"create snapshot description..." << std::endl;
580 coral::TableDescription hvssDesc;
581 hvssDesc.setName(
"HVSNAPSHOT" );
582 hvssDesc.insertColumn(
"TIME",
583 coral::AttributeSpecification::typeNameForId(
584 typeid(coral::TimeStamp) ) );
585 hvssDesc.insertColumn(
"WHEEL",
586 coral::AttributeSpecification::typeNameForId(
588 hvssDesc.insertColumn(
"STATION",
589 coral::AttributeSpecification::typeNameForId(
591 hvssDesc.insertColumn(
"SECTOR",
592 coral::AttributeSpecification::typeNameForId(
594 hvssDesc.insertColumn(
"SUPERLAYER",
595 coral::AttributeSpecification::typeNameForId(
597 hvssDesc.insertColumn(
"LAYER",
598 coral::AttributeSpecification::typeNameForId(
600 hvssDesc.insertColumn(
"CHAN",
601 coral::AttributeSpecification::typeNameForId(
603 hvssDesc.insertColumn(
"TYPE",
604 coral::AttributeSpecification::typeNameForId(
606 hvssDesc.insertColumn(
"VALUE",
607 coral::AttributeSpecification::typeNameForId(
609 std::cout <<
"create snapshot table..." << std::endl;
611 coral::ITable& bufferTable =
613 coral::AttributeList newMeas;
614 newMeas.extend(
"TIME",
typeid(coral::TimeStamp) );
615 newMeas.extend(
"WHEEL",
typeid(
int) );
616 newMeas.extend(
"STATION",
typeid(
int) );
617 newMeas.extend(
"SECTOR",
typeid(
int) );
618 newMeas.extend(
"SUPERLAYER",
typeid(
int) );
619 newMeas.extend(
"LAYER",
typeid(
int) );
620 newMeas.extend(
"CHAN",
typeid(
int) );
621 newMeas.extend(
"TYPE",
typeid(
int) );
622 newMeas.extend(
"VALUE",
typeid(
float) );
624 long long int zeroTime = 0LL;
625 newMeas[
"TIME" ].data<coral::TimeStamp>() =
626 coral::TimeStamp( zeroTime );
627 newMeas[
"VALUE" ].data<
float>() = -999999.0;
629 std::map<int,int>::const_iterator iter =
aliasMap.begin();
630 std::map<int,int>::const_iterator iend =
aliasMap.end();
631 while ( iter != iend ) {
632 const std::pair<int,int>&
entry= *iter++;
633 int detId = entry.second;
635 newMeas[
"WHEEL" ].data<
int>() = chlId.
wheel ();
636 newMeas[
"STATION" ].data<
int>() = chlId.
station ();
637 newMeas[
"SECTOR" ].data<
int>() = chlId.
sector ();
638 newMeas[
"SUPERLAYER"].data<
int>() = chlId.
superLayer();
639 newMeas[
"LAYER" ].data<
int>() = chlId.
layer ();
640 newMeas[
"CHAN" ].data<
int>() = chlId.
wire () - 10;
642 for ( itype = 1; itype <= 2; itype++ ) {
643 newMeas[
"TYPE" ].data<
int>() = itype;
644 bufferTable.dataEditor().insertRow( newMeas );
648 std::cout <<
"create logging info..." << std::endl;
651 coral::TableDescription infoDesc;
652 infoDesc.setName(
"LOG" );
653 infoDesc.insertColumn(
"EXECTIME",
654 coral::AttributeSpecification::typeNameForId(
655 typeid(coral::TimeStamp) ) );
656 infoDesc.insertColumn(
"SNAPSHOT",
657 coral::AttributeSpecification::typeNameForId(
658 typeid(coral::TimeStamp) ) );
660 coral::AttributeList newInfo;
661 newInfo.extend(
"EXECTIME",
typeid(coral::TimeStamp) );
662 newInfo.extend(
"SNAPSHOT",
typeid(coral::TimeStamp) );
663 newInfo[
"EXECTIME"].data<coral::TimeStamp>() =
664 coral::TimeStamp( zeroTime );
665 newInfo[
"SNAPSHOT"].data<coral::TimeStamp>() =
666 coral::TimeStamp( zeroTime );
667 coral::ITable& infoTable =
669 infoTable.dataEditor().insertRow( newInfo );
679 std::cout <<
" snapshot at " << snapshotTime <<
" ( "
681 .total_nanoseconds() <<
" ) "
684 coral::TimeStamp coralSnap =
coralTime( snapshotTime );
685 std::cout <<
"too recent snapshot: " << std::endl
686 <<
" snapshot at " << coralSnap.year( ) <<
" "
687 << coralSnap.month() <<
" "
688 << coralSnap.day( ) << std::endl
689 <<
" copy since " <<
ySince <<
" "
692 <<
" ( " <<
procSince <<
" )" << std::endl;
700 while ( missingChannels ) {
702 << condSince <<
" ( " <<
coralTime( condSince )
703 .total_nanoseconds() <<
" ) -> "
704 << condUntil <<
" ( " <<
coralTime( condUntil )
705 .total_nanoseconds() <<
" ) "
707 if ( condSince <= snapshotTime ) condSince = snapshotTime;
709 << condSince <<
" ( " <<
coralTime( condSince )
710 .total_nanoseconds() <<
" ) "
712 if ( condSince >= condUntil )
break;
713 std::cout <<
"missing... " << missingChannels << std::endl;
715 condUntil = condSince;
716 condSince = condUntil - dTime;
730 int missingChannels = 0;
731 std::map<int,int>::const_iterator layIter =
layerMap.begin();
732 std::map<int,int>::const_iterator layIend =
layerMap.end();
733 std::cout <<
"retrieve snapshot table..." << std::endl;
734 coral::ITable& hvssTable =
736 std::auto_ptr<coral::IQuery> hvssQuery( hvssTable.newQuery() );
737 hvssQuery->addToOutputList(
"TIME" );
738 hvssQuery->addToOutputList(
"WHEEL" );
739 hvssQuery->addToOutputList(
"STATION" );
740 hvssQuery->addToOutputList(
"SECTOR" );
741 hvssQuery->addToOutputList(
"SUPERLAYER" );
742 hvssQuery->addToOutputList(
"LAYER" );
743 hvssQuery->addToOutputList(
"CHAN" );
744 hvssQuery->addToOutputList(
"TYPE" );
745 hvssQuery->addToOutputList(
"VALUE" );
746 coral::ICursor& hvssCursor = hvssQuery->execute();
747 while ( hvssCursor.next() ) {
748 coral::TimeStamp
time =
749 hvssCursor.currentRow()[
"TIME"].data<coral::TimeStamp>();
750 int whe = hvssCursor.currentRow()[
"WHEEL" ].data<
int>();
751 int sta = hvssCursor.currentRow()[
"STATION" ].data<
int>();
752 int sec = hvssCursor.currentRow()[
"SECTOR" ].data<
int>();
753 int qua = hvssCursor.currentRow()[
"SUPERLAYER"].data<
int>();
754 int lay = hvssCursor.currentRow()[
"LAYER" ].data<
int>();
755 int l_p = hvssCursor.currentRow()[
"CHAN" ].data<
int>();
756 int mty = hvssCursor.currentRow()[
"TYPE" ].data<
int>();
757 float value = hvssCursor.currentRow()[
"VALUE" ].data<
float>();
758 if ( mty > 2 )
continue;
759 DTWireId wireId( whe, sta, sec, qua, lay, 10 + l_p );
761 if ( layIter == layIend ) {
764 int dpId = ( layIter->second * 10 ) + mty;
767 time.total_nanoseconds(),
value ) ) );
770 return missingChannels;
775 coral::ITable& infoTable =
777 std::auto_ptr<coral::IQuery> infoQuery( infoTable.newQuery() );
778 infoQuery->addToOutputList(
"SNAPSHOT" );
779 coral::ICursor& infoCursor = infoQuery->execute();
780 coral::TimeStamp
time;
781 while ( infoCursor.next() ) {
782 time = infoCursor.currentRow()[
"SNAPSHOT"].data<coral::TimeStamp>();
790 std::cout <<
"dump snapshot to buffer db..." << std::endl;
791 std::string emptyCondition(
"" );
792 coral::AttributeList emptyBindVariableList;
793 std::map<int,int>::const_iterator mapIter =
aliasMap.begin();
794 std::map<int,int>::const_iterator mapIend =
aliasMap.end();
795 coral::ITable& hvssTable =
797 coral::ITableDataEditor& hvssEditor( hvssTable.dataEditor() );
798 long nRows = hvssEditor.deleteRows( emptyCondition, emptyBindVariableList );
799 std::cout << nRows <<
" rows deleted" << std::endl;
801 coral::AttributeList newMeas;
802 newMeas.extend(
"TIME",
typeid(coral::TimeStamp) );
803 newMeas.extend(
"WHEEL",
typeid(
int) );
804 newMeas.extend(
"STATION",
typeid(
int) );
805 newMeas.extend(
"SECTOR",
typeid(
int) );
806 newMeas.extend(
"SUPERLAYER",
typeid(
int) );
807 newMeas.extend(
"LAYER",
typeid(
int) );
808 newMeas.extend(
"CHAN",
typeid(
int) );
809 newMeas.extend(
"TYPE",
typeid(
int) );
810 newMeas.extend(
"VALUE",
typeid(
float) );
813 std::map<int,timedMeasurement>::const_iterator ssvIter =
815 std::map<int,timedMeasurement>::const_iterator ssvIend =
817 while ( ssvIter != ssvIend ) {
818 const std::pair<int,timedMeasurement>&
entry = *ssvIter++;
819 int dpty = entry.first;
820 int dpId = dpty / 10;
821 int type = dpty % 10;
823 if ( mapIter == mapIend )
continue;
826 long long int newTime = tMeas.first;
827 newMeas[
"TIME" ].data<coral::TimeStamp>() =
828 coral::TimeStamp( newTime );
829 newMeas[
"WHEEL" ].data<
int>() = chlId.
wheel ();
830 newMeas[
"STATION" ].data<
int>() = chlId.
station ();
831 newMeas[
"SECTOR" ].data<
int>() = chlId.
sector ();
832 newMeas[
"SUPERLAYER"].data<
int>() = chlId.
superLayer();
833 newMeas[
"LAYER" ].data<
int>() = chlId.
layer ();
834 newMeas[
"CHAN" ].data<
int>() = chlId.
wire () - 10;
835 newMeas[
"TYPE" ].data<
int>() = type;
836 newMeas[
"VALUE" ].data<
float>() = tMeas.second;
837 hvssEditor.insertRow( newMeas );
840 std::cout << nRows <<
" rows updated" << std::endl;
842 std::cout <<
"create logging info..." << std::endl;
845 coral::TableDescription infoDesc;
846 infoDesc.setName(
"LOG" );
847 infoDesc.insertColumn(
"EXECTIME",
848 coral::AttributeSpecification::typeNameForId(
849 typeid(coral::TimeStamp) ) );
850 infoDesc.insertColumn(
"SNAPSHOT",
851 coral::AttributeSpecification::typeNameForId(
852 typeid(coral::TimeStamp) ) );
854 coral::AttributeList newInfo;
855 newInfo.extend(
"EXECTIME",
typeid(coral::TimeStamp) );
856 newInfo.extend(
"SNAPSHOT",
typeid(coral::TimeStamp) );
858 newInfo[
"SNAPSHOT"].data<coral::TimeStamp>() = time;
859 coral::ITable& infoTable =
861 infoTable.dataEditor().insertRow( newInfo );
870 int& missingChannels,
873 std::map<int,timedMeasurement>::iterator mapIter =
snapshotValues.begin();
874 std::map<int,timedMeasurement>::iterator mapIend =
snapshotValues.end();
876 std::map<long long int,channelValue> periodBuffer;
878 coral::ITable& fwccTable =
880 std::auto_ptr<coral::IQuery> fwccQuery( fwccTable.newQuery() );
881 fwccQuery->addToOutputList(
"DPID" );
882 fwccQuery->addToOutputList(
"CHANGE_DATE" );
883 fwccQuery->addToOutputList(
"ACTUAL_VMON" );
884 fwccQuery->addToOutputList(
"ACTUAL_IMON" );
885 fwccQuery->addToOutputList(
"ACTUAL_ISON" );
886 fwccQuery->addToOutputList(
"ACTUAL_STATUS" );
887 fwccQuery->addToOutputList(
"ACTUAL_OVC" );
888 coral::AttributeList timeBindVariableList;
889 timeBindVariableList.extend(
"since",
typeid(coral::TimeStamp) );
890 timeBindVariableList.extend(
"until",
typeid(coral::TimeStamp) );
891 coral::TimeStamp coralSince =
coralTime( condSince );
892 coral::TimeStamp coralUntil =
coralTime( condUntil );
894 << coralSince.year( ) <<
" "
895 << coralSince.month( ) <<
" "
896 << coralSince.day( ) <<
" "
897 << coralSince.hour( ) <<
":"
898 << coralSince.minute() <<
":"
899 << coralSince.second() <<
" until "
900 << coralUntil.year( ) <<
" "
901 << coralUntil.month( ) <<
" "
902 << coralUntil.day( ) <<
" "
903 << coralUntil.hour( ) <<
":"
904 << coralUntil.minute() <<
":"
905 << coralUntil.second() << std::endl;
906 timeBindVariableList[
"since"].data<coral::TimeStamp>() =
908 timeBindVariableList[
"until"].data<coral::TimeStamp>() =
910 fwccQuery->setCondition(
"CHANGE_DATE>:since and CHANGE_DATE<:until",
911 timeBindVariableList );
912 fwccQuery->addToOrderList(
"CHANGE_DATE" );
913 coral::ICursor& fwccCursor = fwccQuery->execute();
915 while ( fwccCursor.next() ) {
917 const coral::Attribute& dp = fwccCursor.currentRow()[
"DPID" ];
918 const coral::Attribute& vmon = fwccCursor.currentRow()[
"ACTUAL_VMON" ];
919 const coral::Attribute& imon = fwccCursor.currentRow()[
"ACTUAL_IMON" ];
920 coral::TimeStamp changeTime =
921 fwccCursor.currentRow()[
"CHANGE_DATE"].data<coral::TimeStamp>();
922 long long int cTimeValue = changeTime.total_nanoseconds();
923 if ( !copyOffline ) cTimeValue = -cTimeValue;
925 std::cout <<
"------- " << nrows << std::endl;
928 int dpId = 10 *
static_cast<int>( 0.01 +
929 fwccCursor.currentRow()[
"DPID"].data<
float>() );
930 if ( !( vmon.isNull() ) ) {
931 while ( periodBuffer.find( cTimeValue ) !=
932 periodBuffer.end() ) cTimeValue++;
934 periodBuffer.insert( std::pair<long long int,channelValue> (
936 vmon.data<
float>() ) ) );
938 if ( !( imon.isNull() ) ) {
939 while ( periodBuffer.find( cTimeValue ) !=
940 periodBuffer.end() ) cTimeValue++;
942 periodBuffer.insert( std::pair<long long int,channelValue> (
944 imon.data<
float>() ) ) );
950 std::cout <<
"data found in period: " << periodBuffer.size() << std::endl;
951 std::map<long long int,channelValue>::const_iterator bufIter =
952 periodBuffer.begin();
953 std::map<long long int,channelValue>::const_iterator bufIend =
956 bool changedStatus =
false;
957 while ( bufIter != bufIend ) {
958 const std::pair<long long int,channelValue>&
entry = *bufIter++;
959 long long int mTime = entry.first;
960 if ( !copyOffline ) mTime = -mTime;
962 int chan = cValue.first;
963 float cont = cValue.second;
965 if ( ( mapIter != mapIend ) &&
966 ( mapIter->second.first < mTime ) ) {
968 if ( changedStatus ) {
972 << hvStatus->
end() - hvStatus->
begin() << std::endl;
974 changedStatus =
false;
977 std::cout <<
"max payload number reached" << std::endl;
982 if ( copyOffline && !changedStatus &&
985 changedStatus =
true;
1000 long long int dTime =
fwdTime;
1009 while ( condSince < condUntil ) {
1011 condSince = condUntil;
1012 condUntil = condSince + dTime;
1015 std::cout <<
"call filterData " << std::endl;
1039 std::map<int,int>::const_iterator layerIter =
layerMap.begin();
1040 std::map<int,int>::const_iterator layerIend =
layerMap.end();
1041 while ( layerIter != layerIend ) {
1042 const std::pair<int,int>& chanEntry = *layerIter++;
1043 int rawId = chanEntry.first;
1045 int whe = chlId.
wheel ();
1047 int sec = chlId.
sector ();
1049 int lay = chlId.
layer ();
1050 int l_p = chlId.
wire();
1051 if ( l_p != 10 )
continue;
1052 for ( type = 1; type <= 2; type++ ) {
1054 for ( l_p = 0; l_p <= 1; l_p++ ) {
1071 valueA, valueC, valueS,
1074 if ( !flag.
a && !flag.
c && !flag.
s )
continue;
1076 std::map< int,std::vector<int>* >::const_iterator m_iter =
1078 std::map< int,std::vector<int>* >::const_iterator m_iend =
1080 if ( m_iter != m_iend ) {
1081 std::vector<int>* cList = m_iter->second;
1082 std::vector<int>::const_iterator l_iter = cList->begin();
1083 std::vector<int>::const_iterator l_iend = cList->end();
1084 while ( l_iter != l_iend ) {
1086 int wh2 = chlId.
wheel ();
1088 int se2 = chlId.
sector ();
1090 int la2 = chlId.
layer ();
1091 int lp2 = chlId.
wire() - 10;
1108 float& valueL,
float& valueR,
1109 float& valueS,
float& valueC ) {
1115 std::map<int,timedMeasurement>::const_iterator snapIter =
1117 std::map<int,timedMeasurement>::const_iterator snapIend =
1123 std::map<int,int>::const_iterator layerIter;
1124 std::map<int,int>::const_iterator layerIend =
layerMap.end();
1125 if ( ( layerIter =
layerMap.find( rawL ) ) != layerIend ) {
1126 const std::pair<int,int>& layerEntry = *layerIter;
1127 int dpId = layerEntry.second;
1129 if ( snapIter != snapIend ) {
1130 const std::pair<int,timedMeasurement>& snapEntry = *snapIter;
1131 valueL = snapEntry.second.second;
1133 else std::cout <<
"snapR not found" << std::endl;
1135 else std::cout <<
"rawR not found" << std::endl;
1136 if ( ( layerIter =
layerMap.find( rawR ) ) != 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 valueR = snapEntry.second.second;
1144 else std::cout <<
"snapL not found" << std::endl;
1146 else std::cout <<
"rawL not found" << std::endl;
1147 if ( ( layerIter =
layerMap.find( rawS ) ) != 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 valueS = snapEntry.second.second;
1155 else std::cout <<
"snapS not found" << std::endl;
1157 else std::cout <<
"rawS not found" << std::endl;
1158 if ( ( layerIter =
layerMap.find( rawC ) ) != 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 valueC = snapEntry.second.second;
1166 else std::cout <<
"snapC not found" << std::endl;
1168 else std::cout <<
"rawC not found" << std::endl;
1178 int whe,
int sta,
int sec,
1179 int qua,
int lay,
int l_p,
1186 int searchStatus = hv->
get( whe, sta, sec, qua, lay, l_p,
1187 fCell, lCell, flagA, flagC, flagS );
1188 if ( searchStatus ) {
1189 DTWireId wireId( whe, sta, sec, qua, lay, 10 + l_p );
1190 std::map<int,int>::const_iterator splitIter =
1192 std::map<int,int>::const_iterator splitIend =
1194 if ( splitIter != splitIend ) {
1195 int code = splitIter->second;
1196 fCell = code / 10000;
1197 lCell = code % 10000;
1203 hv->
set( whe, sta, sec, qua, lay, l_p,
1204 fCell, lCell, flagA, flagC, flagS );
1210 float oldValue,
float newValue ) {
1211 int dpId = chan / 10;
1212 int type = chan % 10;
1213 std::map<int,int>::const_iterator aliasIter =
aliasMap.find( dpId );
1214 std::map<int,int>::const_iterator aliasIend =
aliasMap.end();
1215 if ( aliasIter == aliasIend )
return false;
1216 int rawId = aliasIter->second;
1218 int l_p = chlId.
wire();
1231 valueL, valueC, valueS,
1237 valueR, valueC, valueS,
1242 if ( valueL != oldValue )
std::cout <<
"*** INCONSISTENT DATA!!!!! "
1243 << type <<
" " << l_p <<
" "
1244 << oldValue <<
" " << valueL <<
" "
1249 if ( valueR != oldValue )
std::cout <<
"*** INCONSISTENT DATA!!!!! "
1250 << type <<
" " << l_p <<
" "
1251 << oldValue <<
" " << valueR <<
" "
1256 if ( valueS != oldValue )
std::cout <<
"*** INCONSISTENT DATA!!!!! "
1257 << type <<
" " << l_p <<
" "
1258 << oldValue <<
" " << valueS <<
" "
1263 if ( valueC != oldValue )
std::cout <<
"*** INCONSISTENT DATA!!!!! "
1264 << type <<
" " << l_p <<
" "
1265 << oldValue <<
" " << valueC <<
" "
1275 valueL, valueC, valueS,
1281 valueR, valueC, valueS,
1287 std::cout <<
"changed status: " << chan <<
" from "
1288 << oldValue <<
" to " << newValue << std::endl;
1306 std::vector< std::pair<DTHVStatus*, cond::Time_t> >::const_iterator iter =
1308 std::vector< std::pair<DTHVStatus*, cond::Time_t> >::const_iterator iend =
1310 std::vector< std::pair<DTHVStatus*, cond::Time_t> >::const_iterator prev;
1311 std::vector< std::pair<DTHVStatus*, cond::Time_t> >::const_iterator next;
1313 while ( iter != iend ) {
1317 if ( next == iend ) next = prev;
1321 iSize = std::distance( iPtr->
begin(), iPtr->
end() );
1322 pSize = std::distance( pPtr->
begin(), pPtr->
end() );
1323 nSize = std::distance( nPtr->
begin(), nPtr->
end() );
1324 int dtot = nSize - pSize;
1326 while ( ++next != iend ) {
1329 pSize = std::distance( pPtr->
begin(), pPtr->
end() );
1330 nSize = std::distance( nPtr->
begin(), nPtr->
end() );
1331 int diff = nSize - pSize;
1332 iTime =
static_cast<int>( ( iter->second >> 32 ) & 0xffffffff );
1333 pTime =
static_cast<int>( ( prev->second >> 32 ) & 0xffffffff );
1334 nTime =
static_cast<int>( ( next->second >> 32 ) & 0xffffffff );
1335 if ( ( nTime - pTime ) > maxTime )
break;
1336 if ( ( nTime - iTime ) > maxTtot )
break;
1337 if ( ( dtot * diff ) < 0 )
break;
1341 iSize = std::distance( iPtr->
begin(), iPtr->
end() );
1342 pSize = std::distance( pPtr->
begin(), pPtr->
end() );
1343 dtot = pSize - iSize;
1344 int dist = pTime - iTime;
1345 if ( ( dtot < -minDiff ) &&
1346 ( dist < maxTtot ) ) {
1348 << std::distance( iter, prev ) <<
" "
1349 << iTime <<
" " << pTime <<
" "
1350 << iSize <<
" " << pSize << std::endl;
1351 m_to_transfer.push_back( std::make_pair( prev->first, prev->second ) );
1352 while ( iter != prev )
delete ( iter++->first );
1354 if ( ( dtot > minDiff ) &&
1355 ( dist < maxTtot ) ) {
1357 << std::distance( iter, prev ) <<
" "
1358 << iTime <<
" " << pTime <<
" "
1359 << iSize <<
" " << pSize << std::endl;
1360 m_to_transfer.push_back( std::make_pair( prev->first, iter->second ) );
1362 while ( iter != prev )
delete ( iter++->first );
1364 if ( ( ( dtot >= -minDiff ) && ( dtot <= minDiff ) ) ||
1365 ( dist >= maxTtot ) ) {
1366 while ( iter != next ) {
1367 const std::pair<DTHVStatus*, cond::Time_t>&
entry = *iter++;
1368 m_to_transfer.push_back( std::make_pair( entry.first, entry.second ) );
1379 int whe = chlId.
wheel ();
1381 int sec = chlId.
sector ();
1383 int lay = chlId.
layer ();
1384 DTWireId chl( whe, sta, sec, qua, lay, 10 + l_p );
1390 long long int iTime = ( ( ( ( time >> 32 ) & 0xFFFFFFFF ) * 1000000000 ) +
1391 ( ( time & 0xFFFFFFFF ) * 1000 ) );
1392 coral::TimeStamp cTime( iTime );
1398 cond::Time_t cTime = ( ( time.total_nanoseconds() / 1000000000 ) << 32 ) +
1399 ( ( time.total_nanoseconds() % 1000000000 ) / 1000 );
1406 ( ( 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
cond::TagInfo const & tagInfo() const
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)
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)
std::pair< std::string, MonitorElement * > entry
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)
cond::ValidityInterval lastInterval
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