27 #include "RelationalAccess/ISchema.h"
28 #include "RelationalAccess/ITable.h"
29 #include "RelationalAccess/ICursor.h"
30 #include "RelationalAccess/IQuery.h"
31 #include "RelationalAccess/TableDescription.h"
32 #include "RelationalAccess/ITableDataEditor.h"
33 #include "CoralBase/AttributeList.h"
34 #include "CoralBase/AttributeSpecification.h"
35 #include "CoralBase/Attribute.h"
36 #include "CoralBase/TimeStamp.h"
53 dataTag( ps.getParameter<std::
string> (
"tag" ) ),
54 onlineConnect( ps.getParameter<std::
string> (
"onlineDB" ) ),
55 utilConnect( ps.getParameter<std::
string> (
"utilDB" ) ),
56 onlineAuthentication( ps.getParameter<std::
string> (
57 "onlineAuthentication" ) ),
58 bufferConnect( ps.getParameter<std::
string> (
"bufferDB" ) ),
59 ySince( ps.getParameter<int> (
"sinceYear" ) ),
60 mSince( ps.getParameter<int> (
"sinceMonth" ) ),
61 dSince( ps.getParameter<int> (
"sinceDay" ) ),
62 hSince( ps.getParameter<int> (
"sinceHour" ) ),
63 pSince( ps.getParameter<int> (
"sinceMinute" ) ),
64 sSince( ps.getParameter<int> (
"sinceSecond" ) ),
65 yUntil( ps.getParameter<int> (
"untilYear" ) ),
66 mUntil( ps.getParameter<int> (
"untilMonth" ) ),
67 dUntil( ps.getParameter<int> (
"untilDay" ) ),
68 hUntil( ps.getParameter<int> (
"untilHour" ) ),
69 pUntil( ps.getParameter<int> (
"untilMinute" ) ),
70 sUntil( ps.getParameter<int> (
"untilSecond" ) ),
71 dumpAtStart( ps.getParameter<bool>(
"dumpAtStart" ) ),
72 dumpAtEnd( ps.getParameter<bool>(
"dumpAtEnd" ) ),
73 bwdTime( ps.getParameter<long long int> (
"bwdTime" ) ),
74 fwdTime( ps.getParameter<long long int> (
"fwdTime" ) ),
75 minTime( ps.getParameter<long long int> (
"minTime" ) ),
79 mapVersion( ps.getParameter<std::
string> (
"mapVersion" ) ),
80 splitVersion( ps.getParameter<std::
string> (
"splitVersion" ) ) {
81 std::cout <<
" PopCon application for DT HV data export "
99 std::cout <<
"get new objects..." << std::endl;
102 std::cout <<
"configure omds DbConnection" << std::endl;
107 std::cout <<
"create omds DbSession" << std::endl;
109 std::cout <<
"start omds transaction" << std::endl;
114 std::cout <<
"create util DbSession" << std::endl;
116 std::cout <<
"startutil transaction" << std::endl;
121 std::cout <<
"create buffer DbSession" << std::endl;
123 std::cout <<
"start buffer transaction" << std::endl;
131 std::cout <<
"latest DCS data (HV) already copied until: "
132 << last << std::endl;
148 m_to_transfer.push_back( std::make_pair( dummyStatus, snc ) );
150 std::cout <<
"no old data... " << last << std::endl;
156 while ( paylIter != paylIend ) {
157 const std::pair<DTHVStatusId,DTHVStatusData>& entry = *paylIter++;
161 chan. slId, chan.
layerId, chan. partId + 10 );
168 coral::TimeStamp coralLast =
coralTime( last );
173 std::cout <<
"Required time interval in the future: "
175 <<
" copy since " <<
ySince <<
" "
178 <<
" ( " <<
procSince <<
" )" << std::endl
179 <<
" current time " << coralProc.year( ) <<
" "
180 << coralProc.month() <<
" "
181 << coralProc.day( ) << std::endl;
190 std::cout <<
"Required time interval already copied: "
192 <<
" copy until " <<
yUntil <<
" "
195 <<
" ( " <<
procUntil <<
" )" << std::endl
196 <<
" data until " << coralLast.year( ) <<
" "
197 << coralLast.month() <<
" "
198 << coralLast.day( ) << std::endl;
202 std::cout <<
"Required time interval not contiguous with copied data: "
204 <<
" data until " << coralLast.year( ) <<
" "
205 << coralLast.month() <<
" "
206 << coralLast.day( ) << std::endl
207 <<
" copy since " <<
ySince <<
" "
210 <<
" ( " <<
procSince <<
" )" << std::endl;
251 std::set<std::string>::const_iterator omds_iter = omds_lt.begin();
252 std::set<std::string>::const_iterator omds_iend = omds_lt.end();
253 while ( omds_iter != omds_iend ) {
255 std::cout <<
"TABLE: " << istr << std::endl;
259 std::set<std::string>::const_iterator util_iter = util_lt.begin();
260 std::set<std::string>::const_iterator util_iend = util_lt.end();
261 while ( util_iter != util_iend ) {
263 std::cout <<
"TABLE: " << istr << std::endl;
270 std::cout <<
"open buffer db..." << std::endl;
281 return "DTHVStatusHandler";
291 std::cout <<
"retrieve aliases table..." << std::endl;
292 coral::ITable& hvalTable =
294 std::auto_ptr<coral::IQuery> hvalQuery( hvalTable.newQuery() );
295 hvalQuery->addToOutputList(
"DETID" );
296 hvalQuery->addToOutputList(
"DPID" );
297 coral::ICursor& hvalCursor = hvalQuery->execute();
300 while ( hvalCursor.next() ) {
301 chId = hvalCursor.currentRow()[
"DETID"].data<
int>();
302 dpId = hvalCursor.currentRow()[
"DPID"].data<
int>();
303 aliasMap.insert( std::pair<int,int>( dpId, chId ) );
304 layerMap.insert( std::pair<int,int>( chId, dpId ) );
314 std::cout <<
"retrieve layer split table..." << std::endl;
323 coral::ITable& lsplTable =
325 std::cout <<
" layer split table got..." << std::endl;
326 std::auto_ptr<coral::IQuery> lsplQuery( lsplTable.newQuery() );
327 coral::AttributeList versionBindVariableList;
328 versionBindVariableList.extend(
"version",
typeid(
std::string) );
330 lsplQuery->setCondition(
"VERSION=:version", versionBindVariableList );
331 lsplQuery->addToOutputList(
"WHEEL" );
332 lsplQuery->addToOutputList(
"SECTOR" );
333 lsplQuery->addToOutputList(
"STATION" );
334 lsplQuery->addToOutputList(
"SUPERLAYER" );
335 lsplQuery->addToOutputList(
"LAYER" );
336 lsplQuery->addToOutputList(
"PART" );
337 lsplQuery->addToOutputList(
"FIRST_CELL" );
338 lsplQuery->addToOutputList(
"LAST_CELL" );
339 coral::ICursor& lsplCursor = lsplQuery->execute();
340 while ( lsplCursor.next() ) {
341 whe = lsplCursor.currentRow()[
"WHEEL" ].data<
int>();
342 sec = lsplCursor.currentRow()[
"SECTOR" ].data<
int>();
343 sta = lsplCursor.currentRow()[
"STATION" ].data<
int>();
344 qua = lsplCursor.currentRow()[
"SUPERLAYER"].data<
int>();
345 lay = lsplCursor.currentRow()[
"LAYER" ].data<
int>();
346 l_p = lsplCursor.currentRow()[
"PART" ].data<
int>();
347 f_c = lsplCursor.currentRow()[
"FIRST_CELL"].data<
int>();
348 l_c = lsplCursor.currentRow()[
"LAST_CELL"].data<
int>();
349 DTWireId wireId( whe, sta, sec, qua, lay, 10 + l_p );
350 laySplit.insert( std::pair<int,int>( wireId.rawId(),
351 ( f_c * 10000 ) + l_c ) );
353 std::cout <<
"channel split table retrieved" << std::endl;
359 std::cout <<
"retrieve channel split table..." << std::endl;
372 coral::ITable& csplTable =
374 std::auto_ptr<coral::IQuery> csplQuery( csplTable.newQuery() );
375 coral::AttributeList versionBindVariableList;
376 versionBindVariableList.extend(
"version",
typeid(
std::string) );
378 csplQuery->setCondition(
"VERSION=:version", versionBindVariableList );
379 csplQuery->addToOutputList(
"P_WHEEL" );
380 csplQuery->addToOutputList(
"P_SECTOR" );
381 csplQuery->addToOutputList(
"P_STATION" );
382 csplQuery->addToOutputList(
"P_SUPERLAYER" );
383 csplQuery->addToOutputList(
"P_LAYER" );
384 csplQuery->addToOutputList(
"P_PART" );
385 csplQuery->addToOutputList(
"S_NUMBER" );
386 csplQuery->addToOutputList(
"S_WHEEL" );
387 csplQuery->addToOutputList(
"S_SECTOR" );
388 csplQuery->addToOutputList(
"S_STATION" );
389 csplQuery->addToOutputList(
"S_SUPERLAYER" );
390 csplQuery->addToOutputList(
"S_LAYER" );
391 csplQuery->addToOutputList(
"S_PART" );
392 coral::ICursor& csplCursor = csplQuery->execute();
393 while ( csplCursor.next() ) {
394 pwhe = csplCursor.currentRow()[
"P_WHEEL" ].data<
int>();
395 psec = csplCursor.currentRow()[
"P_SECTOR" ].data<
int>();
396 psta = csplCursor.currentRow()[
"P_STATION" ].data<
int>();
397 pqua = csplCursor.currentRow()[
"P_SUPERLAYER"].data<
int>();
398 play = csplCursor.currentRow()[
"P_LAYER" ].data<
int>();
399 pl_p = csplCursor.currentRow()[
"P_PART" ].data<
int>();
400 csplCursor.currentRow()[
"S_NUMBER" ].data<
int>();
401 swhe = csplCursor.currentRow()[
"S_WHEEL" ].data<
int>();
402 ssec = csplCursor.currentRow()[
"S_SECTOR" ].data<
int>();
403 ssta = csplCursor.currentRow()[
"S_STATION" ].data<
int>();
404 squa = csplCursor.currentRow()[
"S_SUPERLAYER"].data<
int>();
405 slay = csplCursor.currentRow()[
"S_LAYER" ].data<
int>();
406 sl_p = csplCursor.currentRow()[
"S_PART" ].data<
int>();
407 DTWireId pId( pwhe, psta, psec, pqua, play, 10 + pl_p );
408 DTWireId sId( swhe, ssta, ssec, squa, slay, 10 + sl_p );
409 int pRaw = pId.rawId();
410 int sRaw = sId.
rawId();
411 std::vector<int>* splitList = 0;
412 std::map< int,std::vector<int>* >::iterator iter =
414 std::map< int,std::vector<int>* >::iterator iend =
416 if ( iter == iend ) {
418 std::vector<int>* >( pRaw, splitList =
419 new std::vector<int> ) );
422 splitList = iter->second;
424 splitList->push_back( sRaw );
432 std::cout <<
"DTHVStatusHandler::dumpHVAliases - begin" << std::endl;
434 std::cout <<
"create aliases description..." << std::endl;
435 coral::TableDescription hvalDesc;
436 hvalDesc.setName(
"HVALIASES" );
437 hvalDesc.insertColumn(
"DETID",
438 coral::AttributeSpecification::typeNameForId(
440 hvalDesc.insertColumn(
"DPID",
441 coral::AttributeSpecification::typeNameForId(
443 std::cout <<
"create aliases table..." << std::endl;
444 coral::ITable& hvalTable =
447 std::cout <<
"open DPNAME table..." << std::endl;
448 std::map<int,std::string> idMap;
449 coral::ITable& dpidTable =
451 std::auto_ptr<coral::IQuery> dpidQuery( dpidTable.newQuery() );
452 dpidQuery->addToOutputList(
"ID" );
453 dpidQuery->addToOutputList(
"DPNAME" );
454 coral::ICursor& dpidCursor = dpidQuery->execute();
455 while( dpidCursor.next() ) {
456 const coral::AttributeList& row = dpidCursor.currentRow();
457 int id =
static_cast<int>( 0.01 +
458 row[
"ID" ].data<
float>() );
460 idMap.insert( std::pair<int,std::string>(
id, dp ) );
462 std::cout <<
"DPNAME table read... " << idMap.size() << std::endl;
464 std::cout <<
"open ALIASES table..." << std::endl;
465 std::map<std::string,std::string> cnMap;
466 coral::ITable& nameTable =
468 std::auto_ptr<coral::IQuery> nameQuery( nameTable.newQuery() );
469 nameQuery->addToOutputList(
"DPE_NAME" );
470 nameQuery->addToOutputList(
"ALIAS" );
471 coral::ICursor& nameCursor = nameQuery->execute();
472 while( nameCursor.next() ) {
473 const coral::AttributeList& row = nameCursor.currentRow();
476 if ( an.length() < 20 )
continue;
477 cnMap.insert( std::pair<std::string,std::string>( dp, an ) );
479 std::cout <<
"ALIASES table read... " << cnMap.size() << std::endl;
481 std::map<int,std::string>::const_iterator idIter = idMap.begin();
482 std::map<int,std::string>::const_iterator idIend = idMap.end();
484 while ( idIter != idIend ) {
485 const std::pair<int,std::string>& ientry = *idIter++;
486 int dpId = ientry.first;
488 int ldp = dp.length();
489 if ( ldp < 20 )
continue;
492 if ( subChk != outChk )
continue;
494 chName +=
".actual.OvC";
495 int chCode = subOut.c_str()[16] -
'0';
496 std::map<std::string,std::string>::const_iterator jter =
497 cnMap.find( chName );
498 if ( jter == cnMap.end() )
continue;
499 const std::pair<std::string,std::string>& jentry = *jter;
500 std::cout << dp << std::endl << chName <<
" " << chCode << std::endl;
502 int al = an.length();
503 int iofw = 7 + an.find(
"DT_HV_W", 0 );
504 int iofc = 3 + an.find(
"_MB", 0 );
505 int iofs = 2 + an.find(
"_S" , 0 );
506 int iofq = 3 + an.find(
"_SL", 0 );
507 int iofl = 2 + an.find(
"_L" , 0 );
508 if ( ( iofw == al ) ||
515 int ioew = an.find(
"_", iofw );
516 int ioec = an.find(
"_", iofc );
517 int ioes = an.find(
"_", iofs );
518 int ioeq = an.find(
"_", iofq );
519 int ioel = an.find(
"_", iofl );
520 std::string swhe( an.substr( iofw, ioew - iofw ) );
521 const char* cwhe = swhe.c_str();
522 int whe = cwhe[1] -
'0';
523 if ( *cwhe !=
'P' ) whe = -whe;
525 std::string scha( an.substr( iofc, ioec - iofc ) );
526 const char* ccha = scha.c_str();
527 int cha = *ccha -
'0';
529 std::string ssec( an.substr( iofs, ioes - iofs ) );
530 const char* csec = ssec.c_str();
531 int sec = ( ( *csec -
'0' ) * 10 ) + ( csec[1] -
'0' );
532 if ( ( csec[2] ==
'R' ) && ( sec == 10 ) ) sec = 14;
533 if ( ( csec[2] ==
'L' ) && ( sec == 4 ) ) sec = 13;
535 std::string squa( an.substr( iofq, ioeq - iofq ) );
536 const char* cqua = squa.c_str();
537 int qua = *cqua -
'0';
539 std::string slay( an.substr( iofl, ioel - iofl ) );
540 const char* clay = slay.c_str();
541 int lay = *clay -
'0';
543 DTWireId wireId( whe, cha, sec, qua, lay, 10 + chCode );
544 int chId = wireId.
rawId();
545 coral::AttributeList newChan;
546 newChan.extend(
"DETID",
typeid(
int) );
547 newChan.extend(
"DPID",
typeid(
int) );
548 newChan[
"DETID"].data<
int>() = chId;
549 newChan[
"DPID"].data<
int>() = dpId;
550 hvalTable.dataEditor().insertRow( newChan );
551 aliasMap.insert( std::pair<int,int>( dpId, chId ) );
552 layerMap.insert( std::pair<int,int>( chId, dpId ) );
555 std::cout <<
"DTHVStatusHandler::dumpHVAliases - end" << std::endl;
561 std::cout <<
"create snapshot description..." << std::endl;
562 coral::TableDescription hvssDesc;
563 hvssDesc.setName(
"HVSNAPSHOT" );
564 hvssDesc.insertColumn(
"TIME",
565 coral::AttributeSpecification::typeNameForId(
566 typeid(coral::TimeStamp) ) );
567 hvssDesc.insertColumn(
"WHEEL",
568 coral::AttributeSpecification::typeNameForId(
570 hvssDesc.insertColumn(
"STATION",
571 coral::AttributeSpecification::typeNameForId(
573 hvssDesc.insertColumn(
"SECTOR",
574 coral::AttributeSpecification::typeNameForId(
576 hvssDesc.insertColumn(
"SUPERLAYER",
577 coral::AttributeSpecification::typeNameForId(
579 hvssDesc.insertColumn(
"LAYER",
580 coral::AttributeSpecification::typeNameForId(
582 hvssDesc.insertColumn(
"CHAN",
583 coral::AttributeSpecification::typeNameForId(
585 hvssDesc.insertColumn(
"TYPE",
586 coral::AttributeSpecification::typeNameForId(
588 hvssDesc.insertColumn(
"VALUE",
589 coral::AttributeSpecification::typeNameForId(
591 std::cout <<
"create snapshot table..." << std::endl;
593 coral::ITable& bufferTable =
595 coral::AttributeList newMeas;
596 newMeas.extend(
"TIME",
typeid(coral::TimeStamp) );
597 newMeas.extend(
"WHEEL",
typeid(
int) );
598 newMeas.extend(
"STATION",
typeid(
int) );
599 newMeas.extend(
"SECTOR",
typeid(
int) );
600 newMeas.extend(
"SUPERLAYER",
typeid(
int) );
601 newMeas.extend(
"LAYER",
typeid(
int) );
602 newMeas.extend(
"CHAN",
typeid(
int) );
603 newMeas.extend(
"TYPE",
typeid(
int) );
604 newMeas.extend(
"VALUE",
typeid(
float) );
606 long long int zeroTime = 0LL;
607 newMeas[
"TIME" ].data<coral::TimeStamp>() =
608 coral::TimeStamp( zeroTime );
609 newMeas[
"VALUE" ].data<
float>() = -999999.0;
611 std::map<int,int>::const_iterator iter =
aliasMap.begin();
612 std::map<int,int>::const_iterator iend =
aliasMap.end();
613 while ( iter != iend ) {
614 const std::pair<int,int>& entry= *iter++;
615 int detId = entry.second;
617 newMeas[
"WHEEL" ].data<
int>() = chlId.
wheel ();
618 newMeas[
"STATION" ].data<
int>() = chlId.
station ();
619 newMeas[
"SECTOR" ].data<
int>() = chlId.
sector ();
620 newMeas[
"SUPERLAYER"].data<
int>() = chlId.
superLayer();
621 newMeas[
"LAYER" ].data<
int>() = chlId.
layer ();
622 newMeas[
"CHAN" ].data<
int>() = chlId.
wire () - 10;
624 for ( itype = 1; itype <= 2; itype++ ) {
625 newMeas[
"TYPE" ].data<
int>() = itype;
626 bufferTable.dataEditor().insertRow( newMeas );
630 std::cout <<
"create logging info..." << std::endl;
633 coral::TableDescription infoDesc;
634 infoDesc.setName(
"LOG" );
635 infoDesc.insertColumn(
"EXECTIME",
636 coral::AttributeSpecification::typeNameForId(
637 typeid(coral::TimeStamp) ) );
638 infoDesc.insertColumn(
"SNAPSHOT",
639 coral::AttributeSpecification::typeNameForId(
640 typeid(coral::TimeStamp) ) );
642 coral::AttributeList newInfo;
643 newInfo.extend(
"EXECTIME",
typeid(coral::TimeStamp) );
644 newInfo.extend(
"SNAPSHOT",
typeid(coral::TimeStamp) );
645 newInfo[
"EXECTIME"].data<coral::TimeStamp>() =
646 coral::TimeStamp( zeroTime );
647 newInfo[
"SNAPSHOT"].data<coral::TimeStamp>() =
648 coral::TimeStamp( zeroTime );
649 coral::ITable& infoTable =
651 infoTable.dataEditor().insertRow( newInfo );
661 std::cout <<
" snapshot at " << snapshotTime <<
" ( "
663 .total_nanoseconds() <<
" ) "
666 coral::TimeStamp coralSnap =
coralTime( snapshotTime );
667 std::cout <<
"too recent snapshot: " << std::endl
668 <<
" snapshot at " << coralSnap.year( ) <<
" "
669 << coralSnap.month() <<
" "
670 << coralSnap.day( ) << std::endl
671 <<
" copy since " <<
ySince <<
" "
674 <<
" ( " <<
procSince <<
" )" << std::endl;
682 while ( missingChannels ) {
684 << condSince <<
" ( " <<
coralTime( condSince )
685 .total_nanoseconds() <<
" ) -> "
686 << condUntil <<
" ( " <<
coralTime( condUntil )
687 .total_nanoseconds() <<
" ) "
689 if ( condSince <= snapshotTime ) condSince = snapshotTime;
691 << condSince <<
" ( " <<
coralTime( condSince )
692 .total_nanoseconds() <<
" ) "
694 if ( condSince >= condUntil )
break;
695 std::cout <<
"missing... " << missingChannels << std::endl;
697 condUntil = condSince;
698 condSince = condUntil - dTime;
712 int missingChannels = 0;
713 std::map<int,int>::const_iterator layIter =
layerMap.begin();
714 std::map<int,int>::const_iterator layIend =
layerMap.end();
715 std::cout <<
"retrieve snapshot table..." << std::endl;
716 coral::ITable& hvssTable =
718 std::auto_ptr<coral::IQuery> hvssQuery( hvssTable.newQuery() );
719 hvssQuery->addToOutputList(
"TIME" );
720 hvssQuery->addToOutputList(
"WHEEL" );
721 hvssQuery->addToOutputList(
"STATION" );
722 hvssQuery->addToOutputList(
"SECTOR" );
723 hvssQuery->addToOutputList(
"SUPERLAYER" );
724 hvssQuery->addToOutputList(
"LAYER" );
725 hvssQuery->addToOutputList(
"CHAN" );
726 hvssQuery->addToOutputList(
"TYPE" );
727 hvssQuery->addToOutputList(
"VALUE" );
728 coral::ICursor& hvssCursor = hvssQuery->execute();
729 while ( hvssCursor.next() ) {
730 coral::TimeStamp time =
731 hvssCursor.currentRow()[
"TIME"].data<coral::TimeStamp>();
732 int whe = hvssCursor.currentRow()[
"WHEEL" ].data<
int>();
733 int sta = hvssCursor.currentRow()[
"STATION" ].data<
int>();
734 int sec = hvssCursor.currentRow()[
"SECTOR" ].data<
int>();
735 int qua = hvssCursor.currentRow()[
"SUPERLAYER"].data<
int>();
736 int lay = hvssCursor.currentRow()[
"LAYER" ].data<
int>();
737 int l_p = hvssCursor.currentRow()[
"CHAN" ].data<
int>();
738 int mty = hvssCursor.currentRow()[
"TYPE" ].data<
int>();
739 float value = hvssCursor.currentRow()[
"VALUE" ].data<
float>();
740 if ( mty > 2 )
continue;
741 DTWireId wireId( whe, sta, sec, qua, lay, 10 + l_p );
743 if ( layIter == layIend ) {
746 int dpId = ( layIter->second * 10 ) + mty;
749 time.total_nanoseconds(),
value ) ) );
752 return missingChannels;
757 long long int lastTime = 0LL;
758 long long int chanTime = 0LL;
759 std::map<int,timedMeasurement>::iterator mapIter =
snapshotValues.begin();
760 std::map<int,timedMeasurement>::iterator mapIend =
snapshotValues.end();
761 while ( mapIter != mapIend ) {
762 const std::pair<int,timedMeasurement>& entry = *mapIter++;
763 chanTime = entry.second.first;
764 if ( lastTime < chanTime ) lastTime = chanTime;
784 std::cout <<
"dump snapshot to buffer db..." << std::endl;
786 coral::AttributeList emptyBindVariableList;
787 std::map<int,int>::const_iterator mapIter =
aliasMap.begin();
788 std::map<int,int>::const_iterator mapIend =
aliasMap.end();
789 coral::ITable& hvssTable =
791 coral::ITableDataEditor& hvssEditor( hvssTable.dataEditor() );
792 long nRows = hvssEditor.deleteRows( emptyCondition, emptyBindVariableList );
793 std::cout << nRows <<
" rows deleted" << std::endl;
795 coral::AttributeList newMeas;
796 newMeas.extend(
"TIME",
typeid(coral::TimeStamp) );
797 newMeas.extend(
"WHEEL",
typeid(
int) );
798 newMeas.extend(
"STATION",
typeid(
int) );
799 newMeas.extend(
"SECTOR",
typeid(
int) );
800 newMeas.extend(
"SUPERLAYER",
typeid(
int) );
801 newMeas.extend(
"LAYER",
typeid(
int) );
802 newMeas.extend(
"CHAN",
typeid(
int) );
803 newMeas.extend(
"TYPE",
typeid(
int) );
804 newMeas.extend(
"VALUE",
typeid(
float) );
807 std::map<int,timedMeasurement>::const_iterator ssvIter =
809 std::map<int,timedMeasurement>::const_iterator ssvIend =
811 while ( ssvIter != ssvIend ) {
812 const std::pair<int,timedMeasurement>& entry = *ssvIter++;
813 int dpty = entry.first;
814 int dpId = dpty / 10;
815 int type = dpty % 10;
817 if ( mapIter == mapIend )
continue;
820 long long int newTime = tMeas.first;
821 newMeas[
"TIME" ].data<coral::TimeStamp>() =
822 coral::TimeStamp( newTime );
823 newMeas[
"WHEEL" ].data<
int>() = chlId.
wheel ();
824 newMeas[
"STATION" ].data<
int>() = chlId.
station ();
825 newMeas[
"SECTOR" ].data<
int>() = chlId.
sector ();
826 newMeas[
"SUPERLAYER"].data<
int>() = chlId.
superLayer();
827 newMeas[
"LAYER" ].data<
int>() = chlId.
layer ();
828 newMeas[
"CHAN" ].data<
int>() = chlId.
wire () - 10;
829 newMeas[
"TYPE" ].data<
int>() = type;
830 newMeas[
"VALUE" ].data<
float>() = tMeas.second;
831 hvssEditor.insertRow( newMeas );
834 std::cout << nRows <<
" rows updated" << std::endl;
836 std::cout <<
"create logging info..." << std::endl;
839 coral::TableDescription infoDesc;
840 infoDesc.setName(
"LOG" );
841 infoDesc.insertColumn(
"EXECTIME",
842 coral::AttributeSpecification::typeNameForId(
843 typeid(coral::TimeStamp) ) );
844 infoDesc.insertColumn(
"SNAPSHOT",
845 coral::AttributeSpecification::typeNameForId(
846 typeid(coral::TimeStamp) ) );
848 coral::AttributeList newInfo;
849 newInfo.extend(
"EXECTIME",
typeid(coral::TimeStamp) );
850 newInfo.extend(
"SNAPSHOT",
typeid(coral::TimeStamp) );
852 newInfo[
"SNAPSHOT"].data<coral::TimeStamp>() = time;
853 coral::ITable& infoTable =
855 infoTable.dataEditor().insertRow( newInfo );
864 int& missingChannels,
867 std::map<int,timedMeasurement>::iterator mapIter =
snapshotValues.begin();
868 std::map<int,timedMeasurement>::iterator mapIend =
snapshotValues.end();
870 std::map<long long int,channelValue> periodBuffer;
872 coral::ITable& fwccTable =
874 std::auto_ptr<coral::IQuery> fwccQuery( fwccTable.newQuery() );
875 fwccQuery->addToOutputList(
"DPID" );
876 fwccQuery->addToOutputList(
"CHANGE_DATE" );
877 fwccQuery->addToOutputList(
"ACTUAL_VMON" );
878 fwccQuery->addToOutputList(
"ACTUAL_IMON" );
879 fwccQuery->addToOutputList(
"ACTUAL_ISON" );
880 fwccQuery->addToOutputList(
"ACTUAL_STATUS" );
881 fwccQuery->addToOutputList(
"ACTUAL_OVC" );
882 coral::AttributeList timeBindVariableList;
883 timeBindVariableList.extend(
"since",
typeid(coral::TimeStamp) );
884 timeBindVariableList.extend(
"until",
typeid(coral::TimeStamp) );
885 coral::TimeStamp coralSince =
coralTime( condSince );
886 coral::TimeStamp coralUntil =
coralTime( condUntil );
888 << coralSince.year( ) <<
" "
889 << coralSince.month( ) <<
" "
890 << coralSince.day( ) <<
" "
891 << coralSince.hour( ) <<
":"
892 << coralSince.minute() <<
":"
893 << coralSince.second() <<
" until "
894 << coralUntil.year( ) <<
" "
895 << coralUntil.month( ) <<
" "
896 << coralUntil.day( ) <<
" "
897 << coralUntil.hour( ) <<
":"
898 << coralUntil.minute() <<
":"
899 << coralUntil.second() << std::endl;
900 timeBindVariableList[
"since"].data<coral::TimeStamp>() =
902 timeBindVariableList[
"until"].data<coral::TimeStamp>() =
904 fwccQuery->setCondition(
"CHANGE_DATE>:since and CHANGE_DATE<:until",
905 timeBindVariableList );
906 fwccQuery->addToOrderList(
"CHANGE_DATE" );
907 coral::ICursor& fwccCursor = fwccQuery->execute();
909 while ( fwccCursor.next() ) {
911 const coral::Attribute&
dp = fwccCursor.currentRow()[
"DPID" ];
912 const coral::Attribute& vmon = fwccCursor.currentRow()[
"ACTUAL_VMON" ];
913 const coral::Attribute& imon = fwccCursor.currentRow()[
"ACTUAL_IMON" ];
914 coral::TimeStamp changeTime =
915 fwccCursor.currentRow()[
"CHANGE_DATE"].data<coral::TimeStamp>();
916 long long int cTimeValue = changeTime.total_nanoseconds();
917 if ( !copyOffline ) cTimeValue = -cTimeValue;
919 std::cout <<
"------- " << nrows << std::endl;
922 int dpId = 10 *
static_cast<int>( 0.01 +
923 fwccCursor.currentRow()[
"DPID"].data<
float>() );
924 if ( !( vmon.isNull() ) ) {
925 while ( periodBuffer.find( cTimeValue ) !=
926 periodBuffer.end() ) cTimeValue++;
928 periodBuffer.insert( std::pair<long long int,channelValue> (
930 vmon.data<
float>() ) ) );
932 if ( !( imon.isNull() ) ) {
933 while ( periodBuffer.find( cTimeValue ) !=
934 periodBuffer.end() ) cTimeValue++;
936 periodBuffer.insert( std::pair<long long int,channelValue> (
938 imon.data<
float>() ) ) );
944 std::cout <<
"data found in period: " << periodBuffer.size() << std::endl;
945 std::map<long long int,channelValue>::const_iterator bufIter =
946 periodBuffer.begin();
947 std::map<long long int,channelValue>::const_iterator bufIend =
950 bool changedStatus =
false;
951 while ( bufIter != bufIend ) {
952 const std::pair<long long int,channelValue>& entry = *bufIter++;
953 long long int mTime = entry.first;
954 if ( !copyOffline ) mTime = -mTime;
956 int chan = cValue.first;
957 float cont = cValue.second;
959 if ( ( mapIter != mapIend ) &&
960 ( mapIter->second.first < mTime ) ) {
962 if ( changedStatus ) {
966 << hvStatus->
end() - hvStatus->
begin() << std::endl;
968 changedStatus =
false;
971 std::cout <<
"max payload number reached" << std::endl;
976 if ( copyOffline && !changedStatus &&
979 changedStatus =
true;
1003 while ( condSince < condUntil ) {
1005 condSince = condUntil;
1006 condUntil = condSince + dTime;
1009 std::cout <<
"call filterData " << std::endl;
1033 std::map<int,int>::const_iterator layerIter =
layerMap.begin();
1034 std::map<int,int>::const_iterator layerIend =
layerMap.end();
1035 while ( layerIter != layerIend ) {
1036 const std::pair<int,int>& chanEntry = *layerIter++;
1037 int rawId = chanEntry.first;
1039 int whe = chlId.
wheel ();
1041 int sec = chlId.
sector ();
1043 int lay = chlId.
layer ();
1044 int l_p = chlId.
wire();
1045 if ( l_p != 10 )
continue;
1046 for ( type = 1; type <= 2; type++ ) {
1048 for ( l_p = 0; l_p <= 1; l_p++ ) {
1065 valueA, valueC, valueS,
1068 if ( !flag.
a && !flag.
c && !flag.
s )
continue;
1070 std::map< int,std::vector<int>* >::const_iterator m_iter =
1072 std::map< int,std::vector<int>* >::const_iterator m_iend =
1074 if ( m_iter != m_iend ) {
1075 std::vector<int>* cList = m_iter->second;
1076 std::vector<int>::const_iterator l_iter = cList->begin();
1077 std::vector<int>::const_iterator l_iend = cList->end();
1078 while ( l_iter != l_iend ) {
1080 int wh2 = chlId.
wheel ();
1082 int se2 = chlId.
sector ();
1084 int la2 = chlId.
layer ();
1085 int lp2 = chlId.
wire() - 10;
1102 float& valueL,
float& valueR,
1103 float& valueS,
float& valueC ) {
1109 std::map<int,timedMeasurement>::const_iterator snapIter =
1111 std::map<int,timedMeasurement>::const_iterator snapIend =
1117 std::map<int,int>::const_iterator layerIter;
1118 std::map<int,int>::const_iterator layerIend =
layerMap.end();
1119 if ( ( layerIter =
layerMap.find( rawL ) ) != layerIend ) {
1120 const std::pair<int,int>& layerEntry = *layerIter;
1121 int dpId = layerEntry.second;
1123 if ( snapIter != snapIend ) {
1124 const std::pair<int,timedMeasurement>& snapEntry = *snapIter;
1125 valueL = snapEntry.second.second;
1127 else std::cout <<
"snapR not found" << std::endl;
1129 else std::cout <<
"rawR not found" << std::endl;
1130 if ( ( layerIter =
layerMap.find( rawR ) ) != layerIend ) {
1131 const std::pair<int,int>& layerEntry = *layerIter;
1132 int dpId = layerEntry.second;
1134 if ( snapIter != snapIend ) {
1135 const std::pair<int,timedMeasurement>& snapEntry = *snapIter;
1136 valueR = snapEntry.second.second;
1138 else std::cout <<
"snapL not found" << std::endl;
1140 else std::cout <<
"rawL not found" << std::endl;
1141 if ( ( layerIter =
layerMap.find( rawS ) ) != layerIend ) {
1142 const std::pair<int,int>& layerEntry = *layerIter;
1143 int dpId = layerEntry.second;
1145 if ( snapIter != snapIend ) {
1146 const std::pair<int,timedMeasurement>& snapEntry = *snapIter;
1147 valueS = snapEntry.second.second;
1149 else std::cout <<
"snapS not found" << std::endl;
1151 else std::cout <<
"rawS not found" << std::endl;
1152 if ( ( layerIter =
layerMap.find( rawC ) ) != layerIend ) {
1153 const std::pair<int,int>& layerEntry = *layerIter;
1154 int dpId = layerEntry.second;
1156 if ( snapIter != snapIend ) {
1157 const std::pair<int,timedMeasurement>& snapEntry = *snapIter;
1158 valueC = snapEntry.second.second;
1160 else std::cout <<
"snapC not found" << std::endl;
1162 else std::cout <<
"rawC not found" << std::endl;
1172 int whe,
int sta,
int sec,
1173 int qua,
int lay,
int l_p,
1180 int searchStatus = hv->
get( whe, sta, sec, qua, lay, l_p,
1181 fCell, lCell, flagA, flagC, flagS );
1182 if ( searchStatus ) {
1183 DTWireId wireId( whe, sta, sec, qua, lay, 10 + l_p );
1184 std::map<int,int>::const_iterator splitIter =
1186 std::map<int,int>::const_iterator splitIend =
1188 if ( splitIter != splitIend ) {
1189 int code = splitIter->second;
1190 fCell = code / 10000;
1191 lCell = code % 10000;
1197 hv->
set( whe, sta, sec, qua, lay, l_p,
1198 fCell, lCell, flagA, flagC, flagS );
1204 float oldValue,
float newValue ) {
1205 int dpId = chan / 10;
1206 int type = chan % 10;
1207 std::map<int,int>::const_iterator aliasIter =
aliasMap.find( dpId );
1208 std::map<int,int>::const_iterator aliasIend =
aliasMap.end();
1209 if ( aliasIter == aliasIend )
return false;
1210 int rawId = aliasIter->second;
1212 int l_p = chlId.
wire();
1225 valueL, valueC, valueS,
1231 valueR, valueC, valueS,
1236 if ( valueL != oldValue )
std::cout <<
"*** INCONSISTENT DATA!!!!! "
1237 << type <<
" " << l_p <<
" "
1238 << oldValue <<
" " << valueL <<
" "
1243 if ( valueR != oldValue )
std::cout <<
"*** INCONSISTENT DATA!!!!! "
1244 << type <<
" " << l_p <<
" "
1245 << oldValue <<
" " << valueR <<
" "
1250 if ( valueS != oldValue )
std::cout <<
"*** INCONSISTENT DATA!!!!! "
1251 << type <<
" " << l_p <<
" "
1252 << oldValue <<
" " << valueS <<
" "
1257 if ( valueC != oldValue )
std::cout <<
"*** INCONSISTENT DATA!!!!! "
1258 << type <<
" " << l_p <<
" "
1259 << oldValue <<
" " << valueC <<
" "
1269 valueL, valueC, valueS,
1275 valueR, valueC, valueS,
1281 std::cout <<
"changed status: " << chan <<
" from "
1282 << oldValue <<
" to " << newValue << std::endl;
1300 std::vector< std::pair<DTHVStatus*, cond::Time_t> >::const_iterator iter =
1302 std::vector< std::pair<DTHVStatus*, cond::Time_t> >::const_iterator iend =
1304 std::vector< std::pair<DTHVStatus*, cond::Time_t> >::const_iterator prev;
1305 std::vector< std::pair<DTHVStatus*, cond::Time_t> >::const_iterator
next;
1307 while ( iter != iend ) {
1311 if ( next == iend ) next = prev;
1318 int dtot = nSize - pSize;
1320 while ( ++next != iend ) {
1325 int diff = nSize - pSize;
1326 iTime =
static_cast<int>( ( iter->second >> 32 ) & 0xffffffff );
1327 pTime =
static_cast<int>( ( prev->second >> 32 ) & 0xffffffff );
1328 nTime =
static_cast<int>( ( next->second >> 32 ) & 0xffffffff );
1329 if ( ( nTime - pTime ) > maxTime )
break;
1330 if ( ( nTime - iTime ) > maxTtot )
break;
1331 if ( ( dtot * diff ) < 0 )
break;
1337 dtot = pSize - iSize;
1338 int dist = pTime - iTime;
1339 if ( ( dtot < -minDiff ) &&
1340 ( dist < maxTtot ) ) {
1343 << iTime <<
" " << pTime <<
" "
1344 << iSize <<
" " << pSize << std::endl;
1345 m_to_transfer.push_back( std::make_pair( prev->first, prev->second ) );
1346 while ( iter != prev )
delete ( iter++->first );
1348 if ( ( dtot > minDiff ) &&
1349 ( dist < maxTtot ) ) {
1352 << iTime <<
" " << pTime <<
" "
1353 << iSize <<
" " << pSize << std::endl;
1354 m_to_transfer.push_back( std::make_pair( prev->first, iter->second ) );
1356 while ( iter != prev )
delete ( iter++->first );
1358 if ( ( ( dtot >= -minDiff ) && ( dtot <= minDiff ) ) ||
1359 ( dist >= maxTtot ) ) {
1360 while ( iter != next ) {
1361 const std::pair<DTHVStatus*, cond::Time_t>& entry = *iter++;
1362 m_to_transfer.push_back( std::make_pair( entry.first, entry.second ) );
1373 int whe = chlId.
wheel ();
1375 int sec = chlId.
sector ();
1377 int lay = chlId.
layer ();
1378 DTWireId chl( whe, sta, sec, qua, lay, 10 + l_p );
1384 long long int iTime = ( ( ( ( time >> 32 ) & 0xFFFFFFFF ) * 1000000000 ) +
1385 ( ( time & 0xFFFFFFFF ) * 1000 ) );
1386 coral::TimeStamp cTime( iTime );
1392 cond::Time_t cTime = ( ( time.total_nanoseconds() / 1000000000 ) << 32 ) +
1393 ( ( time.total_nanoseconds() % 1000000000 ) / 1000 );
1400 ( ( 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
tuple cont
load Luminosity info ##
DTHVAbstractCheck::timedMeasurement timedMeasurement
cond::persistency::Session omds_session
void start(bool readOnly=true)
void getLayerValues(int rawId, int type, float &valueL, float &valueR, float &valueS, float &valueC)
cond::persistency::Session buff_session
std::string onlineConnect
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
Transaction & transaction()
DTHVStatusHandler(const edm::ParameterSet &ps)
cond::persistency::Session util_session
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
static coral::TimeStamp coralTime(const cond::Time_t &time)
int checkStatusChange(int type, float oldValue, float newValue)
cond::ValidityInterval lastInterval
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)
coral::ISchema & nominalSchema()
std::map< int, timedMeasurement > snapshotValues
int superLayer() const
Return the superlayer number.
std::map< int, int > layerMap
Session createSession(const std::string &connectionString, bool writeCapable=false)
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.
std::string onlineAuthentication
int set(int wheelId, int stationId, int sectorId, int slId, int layerId, int partId, int fCell, int lCell, int flagA, int flagC, int flagS)
std::pair< int, float > channelValue
char data[epos_bytes_allocation]
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.
void setAuthenticationPath(const std::string &p)
virtual ~DTHVStatusHandler()
cond::TagInfo_t const & tagInfo() const