537 |
myquery << ",VALIDATION"; |
myquery << ",VALIDATION"; |
538 |
myquery << " from GL_RUN where ID=" << run << ";"; |
myquery << " from GL_RUN where ID=" << run << ";"; |
539 |
// |
// |
540 |
|
// printf(" myquery is %s \n",myquery.str().c_str()); |
541 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
542 |
if(!pResult->GetRowCount())return(-50); |
// |
543 |
|
// printf(" getrowcount %i \n",pResult->GetRowCount()); |
544 |
|
// |
545 |
|
if( !pResult->GetRowCount() ) return(-50); |
546 |
|
// |
547 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
548 |
Row = pResult->Next(); |
Row = pResult->Next(); |
549 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
578 |
if (t==27) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t)); |
if (t==27) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t)); |
579 |
if (t==28) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); |
if (t==28) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); |
580 |
if (t==29) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
if (t==29) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
|
|
|
|
|
|
581 |
}; |
}; |
582 |
}; |
}; |
583 |
delete pResult; |
// delete pResult; |
584 |
|
return(0); |
|
return 0; |
|
|
|
|
585 |
}; |
}; |
586 |
|
|
587 |
/** |
/** |
772 |
* \param run starting time |
* \param run starting time |
773 |
* \return struct of type GL_CALO_CALIB_data, which stores the query result |
* \return struct of type GL_CALO_CALIB_data, which stores the query result |
774 |
*/ |
*/ |
775 |
Int_t GL_CALO_CALIB::Query_GL_CALO_CALIB(UInt_t time, UInt_t section, TSQLServer *dbc){ |
Int_t GL_CALO_CALIB::Query_GL_CALO_CALIB(UInt_t time, UInt_t &uptime, UInt_t section, TSQLServer *dbc){ |
776 |
// MySQL variables |
// MySQL variables |
777 |
TSQLResult *pResult; |
TSQLResult *pResult; |
778 |
TSQLRow *Row; |
TSQLRow *Row; |
779 |
int t; |
int t; |
780 |
stringstream myquery; |
stringstream myquery; |
781 |
|
uptime = 0; |
782 |
// |
// |
783 |
// select the correct calibration |
// select the correct calibration |
784 |
// |
// |
786 |
myquery << "select ID_ROOT_L0, FROM_TIME, TO_TIME, EV_ROOT,VALIDATION from GL_CALO_CALIB where SECTION=" << section; |
myquery << "select ID_ROOT_L0, FROM_TIME, TO_TIME, EV_ROOT,VALIDATION from GL_CALO_CALIB where SECTION=" << section; |
787 |
myquery << " and FROM_TIME <= " << time; |
myquery << " and FROM_TIME <= " << time; |
788 |
myquery << " and TO_TIME > " << time; |
myquery << " and TO_TIME > " << time; |
789 |
myquery << " and VALIDATION=1;"; |
myquery << " ;"; |
790 |
|
//myquery << " and VALIDATION=1;"; |
791 |
// |
// |
792 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
793 |
|
// printf(" mysquery is %s\n",myquery.str().c_str()); |
794 |
|
// |
795 |
|
if( !pResult->GetRowCount() ) return(-54); |
796 |
|
Row = pResult->Next(); |
797 |
|
if( Row == NULL ) return (-54); |
798 |
|
// |
799 |
|
uptime = (UInt_t)atoll(Row->GetField(2)); |
800 |
// |
// |
801 |
// if it is corrupted validation is 0 and we have no results from the query... |
// if it is corrupted validation is 0 and we have no results from the query... |
802 |
// |
// |
803 |
if( !pResult->GetRowCount() ){ |
if( atoi(Row->GetField(4)) == 0 ){ // if validation = 0 |
|
// pResult->Delete(); |
|
804 |
// |
// |
805 |
// in this case take relax the conditions and take the valid calibration that preceed the correct one |
// in this case take relax the conditions and take the valid calibration that preceed the correct one |
806 |
// |
// |
809 |
myquery << " and FROM_TIME <= " << time; |
myquery << " and FROM_TIME <= " << time; |
810 |
myquery << " and VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;"; |
myquery << " and VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;"; |
811 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
812 |
|
// printf(" mysquery is %s\n",myquery.str().c_str()); |
813 |
// |
// |
814 |
// if no results yet quit with error |
// if no results yet quit with error |
815 |
// |
// |
816 |
if( !pResult->GetRowCount() ) return (-54); |
if( !pResult->GetRowCount() ) return (-54); |
817 |
|
// |
818 |
|
Row = pResult->Next(); |
819 |
|
// |
820 |
}; |
}; |
821 |
// |
// |
822 |
// store infos and exit |
// store infos and exit |
823 |
// |
// |
|
Row = pResult->Next(); |
|
824 |
if( Row == NULL ) return (-54); |
if( Row == NULL ) return (-54); |
825 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
826 |
if (t==0) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
if (t==0) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
848 |
// ---------------- |
// ---------------- |
849 |
myquery.str(""); |
myquery.str(""); |
850 |
myquery << "select * from GL_S4_CALIB where FROM_TIME <= "<< time; |
myquery << "select * from GL_S4_CALIB where FROM_TIME <= "<< time; |
851 |
myquery << " AND VALIDATION = 1 ORDER BY FROM_TIME DESC LIMIT 1;"; |
myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
852 |
// myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
// myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
853 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
854 |
if(!pResult->GetRowCount())return (-55);//throw -55; |
if(!pResult->GetRowCount())return (-55);//throw -55; |
1061 |
return(pkt_num); |
return(pkt_num); |
1062 |
// |
// |
1063 |
}; |
}; |
1064 |
|
|
1065 |
|
/* |
1066 |
|
* |
1067 |
|
* Convert the time in the DB from UInt_t to a string |
1068 |
|
* |
1069 |
|
* @param dbt time in the DB |
1070 |
|
* @param tzone Time Zone, can be UTC,GMT,CET,CEST,MSD default is MSK |
1071 |
|
* |
1072 |
|
*/ |
1073 |
|
TString GL_TIMESYNC::ConvertTime(TString tzone, UInt_t dbt){ |
1074 |
|
// |
1075 |
|
TDatime *time = new TDatime(); |
1076 |
|
TString rtime; |
1077 |
|
// |
1078 |
|
time->Set(dbt,false); // MSK = Moscow Winter Time |
1079 |
|
// |
1080 |
|
if ( !strcmp(tzone.Data(),"UTC") || !strcmp(tzone.Data(),"GMT") ){ |
1081 |
|
// |
1082 |
|
UInt_t timeUTC = time->Convert() - 60*60*3; // UTC (Coordinated Universal Time) = Moscow Winter Time - 3 hs |
1083 |
|
time->Set(timeUTC,false); |
1084 |
|
// |
1085 |
|
}; |
1086 |
|
// |
1087 |
|
if ( !strcmp(tzone.Data(),"CET") ){ |
1088 |
|
// |
1089 |
|
UInt_t timeCET = time->Convert() - 60*60*2; // CET (Central European Time) = Moscow Winter Time - 2 hs |
1090 |
|
time->Set(timeCET,false); |
1091 |
|
// |
1092 |
|
}; |
1093 |
|
// |
1094 |
|
if ( !strcmp(tzone.Data(),"CEST") ){ |
1095 |
|
// |
1096 |
|
UInt_t timeCEST = time->Convert() - 60*60*1; // CEST (Central European Summer Time) = Moscow Winter Time - 1 h |
1097 |
|
time->Set(timeCEST,false); |
1098 |
|
// |
1099 |
|
}; |
1100 |
|
// |
1101 |
|
if ( !strcmp(tzone.Data(),"MSD") ){ |
1102 |
|
// |
1103 |
|
UInt_t timeMSD = time->Convert() + 60*60*1; // MSD (Moscow Summer Time) = Moscow Winter Time + 1 h |
1104 |
|
time->Set(timeMSD,false); |
1105 |
|
// |
1106 |
|
}; |
1107 |
|
// |
1108 |
|
rtime = time->AsSQLString(); |
1109 |
|
// |
1110 |
|
return(rtime); |
1111 |
|
} |
1112 |
|
|
1113 |
|
/* |
1114 |
|
* |
1115 |
|
* Convert the time in the DB from UInt_t to a string |
1116 |
|
* |
1117 |
|
* @param dbt time in the DB |
1118 |
|
* @param tzone Time Zone, can be UTC,GMT,CET,CEST,MSD default is MSK |
1119 |
|
* |
1120 |
|
*/ |
1121 |
|
TString GL_TIMESYNC::UnConvertTime(TString tzone, UInt_t dbt){ |
1122 |
|
// |
1123 |
|
TDatime *time = new TDatime(); |
1124 |
|
TString rtime; |
1125 |
|
// |
1126 |
|
time->Set(dbt,false); // MSK = Moscow Winter Time |
1127 |
|
// |
1128 |
|
if ( !strcmp(tzone.Data(),"UTC") || !strcmp(tzone.Data(),"GMT") ){ |
1129 |
|
// |
1130 |
|
UInt_t timeUTC = time->Convert() + 60*60*3; // UTC (Coordinated Universal Time) +3 hs = Moscow Winter Time |
1131 |
|
time->Set(timeUTC,false); |
1132 |
|
// |
1133 |
|
}; |
1134 |
|
// |
1135 |
|
if ( !strcmp(tzone.Data(),"CET") ){ |
1136 |
|
// |
1137 |
|
UInt_t timeCET = time->Convert() + 60*60*2; // CET (Central European Time) + 2 hs = Moscow Winter Time |
1138 |
|
time->Set(timeCET,false); |
1139 |
|
// |
1140 |
|
}; |
1141 |
|
// |
1142 |
|
if ( !strcmp(tzone.Data(),"CEST") ){ |
1143 |
|
// |
1144 |
|
UInt_t timeCEST = time->Convert() + 60*60*1; // CEST (Central European Summer Time) + 1 h = Moscow Winter Time |
1145 |
|
time->Set(timeCEST,false); |
1146 |
|
// |
1147 |
|
}; |
1148 |
|
// |
1149 |
|
if ( !strcmp(tzone.Data(),"MSD") ){ |
1150 |
|
// |
1151 |
|
UInt_t timeMSD = time->Convert() - 60*60*1; // MSD (Moscow Summer Time) - 1 h = Moscow Winter Time |
1152 |
|
time->Set(timeMSD,false); |
1153 |
|
// |
1154 |
|
}; |
1155 |
|
// |
1156 |
|
rtime = time->AsSQLString(); |
1157 |
|
// |
1158 |
|
return(rtime); |
1159 |
|
} |