/[PAMELA software]/YodaProfiler/src/GLTables.cpp
ViewVC logotype

Diff of /YodaProfiler/src/GLTables.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.15 by mocchiut, Tue Oct 31 15:36:04 2006 UTC revision 1.21 by mocchiut, Tue Jan 23 17:04:11 2007 UTC
# Line 10  Line 10 
10  //  //
11  #include <TFile.h>  #include <TFile.h>
12  #include <TTree.h>  #include <TTree.h>
13    #include <TTimeStamp.h>
14  #include <EventHeader.h>  #include <EventHeader.h>
15  #include <PscuHeader.h>  #include <PscuHeader.h>
16  //  //
# Line 153  GL_TIMESYNC::GL_TIMESYNC(){ Line 154  GL_TIMESYNC::GL_TIMESYNC(){
154    obtfirst = 0;    obtfirst = 0;
155    pktfirst = 0;    pktfirst = 0;
156    toffset  = 0;    toffset  = 0;
157    ID       = 0;    //  ID       = 0;
158    ID_RAW   = 0;    //  ID_RAW   = 0;
159    OBT0     = 0;    OBT0     = 0;
160    TIMESYNC = 0;    TIMESYNC = 0;
161    TYPE     = 0;    TYPE     = 0;
162  }  }
163    
 GL_TLE::GL_TLE(){  
 }  
   
164  // ****************************************************  // ****************************************************
165    
166  void GL_RUN::SetEV_FROM(UInt_t evfrom){  void GL_RUN::SetEV_FROM(UInt_t evfrom){
# Line 861  Int_t GL_RUN::Query_GL_RUN(UInt_t run, T Line 859  Int_t GL_RUN::Query_GL_RUN(UInt_t run, T
859        if( Row == NULL ) break;        if( Row == NULL ) break;
860  //        Set_GL_RUN(Row);  //        Set_GL_RUN(Row);
861        for( t = 0; t < pResult->GetFieldCount(); t++){        for( t = 0; t < pResult->GetFieldCount(); t++){
862                    if (t== 0) ID                = (UInt_t)atoll(Row->GetField(t));          if (t== 0) ID                = (UInt_t)atoll(Row->GetField(t));
863                    if (t== 1) ID_RUN_FRAG       = (UInt_t)atoll(Row->GetField(t));          if (t== 1) ID_RUN_FRAG       = (UInt_t)atoll(Row->GetField(t));
864                    if (t== 2) ID_ROOT_L0        = (UInt_t)atoll(Row->GetField(t));          if (t== 2) ID_ROOT_L0        = (UInt_t)atoll(Row->GetField(t));
865                    if (t== 3) ID_ROOT_L2        = (UInt_t)atoll(Row->GetField(t));          if (t== 3) ID_ROOT_L2        = (UInt_t)atoll(Row->GetField(t));
866                    if (t== 4) RUNHEADER_TIME    = (UInt_t)atoll(Row->GetField(t));          if (t== 4) RUNHEADER_TIME    = (UInt_t)atoll(Row->GetField(t));
867                    if (t== 5) RUNTRAILER_TIME   = (UInt_t)atoll(Row->GetField(t));          if (t== 5) RUNTRAILER_TIME   = (UInt_t)atoll(Row->GetField(t));
868                    if (t== 6) RUNHEADER_OBT     = (UInt_t)atoll(Row->GetField(t));          if (t== 6) RUNHEADER_OBT     = (UInt_t)atoll(Row->GetField(t));
869                    if (t== 7) RUNTRAILER_OBT    = (UInt_t)atoll(Row->GetField(t));          if (t== 7) RUNTRAILER_OBT    = (UInt_t)atoll(Row->GetField(t));
870                    if (t== 8) RUNHEADER_PKT     = (UInt_t)atoll(Row->GetField(t));          if (t== 8) RUNHEADER_PKT     = (UInt_t)atoll(Row->GetField(t));
871                    if (t== 9) RUNTRAILER_PKT    = (UInt_t)atoll(Row->GetField(t));          if (t== 9) RUNTRAILER_PKT    = (UInt_t)atoll(Row->GetField(t));
872                    if (t==10) EV_FROM           = (UInt_t)atoll(Row->GetField(t));          if (t==10) EV_FROM           = (UInt_t)atoll(Row->GetField(t));
873                    if (t==11) EV_TO             = (UInt_t)atoll(Row->GetField(t));          if (t==11) EV_TO             = (UInt_t)atoll(Row->GetField(t));
874                    if (t==12) NEVENTS           = (UInt_t)atoll(Row->GetField(t));          if (t==12) NEVENTS           = (UInt_t)atoll(Row->GetField(t));
875                    if (t==13) LAST_TIMESYNC     = (UInt_t)atoll(Row->GetField(t));          if (t==13) LAST_TIMESYNC     = (UInt_t)atoll(Row->GetField(t));
876                    if (t==14) OBT_TIMESYNC      = (UInt_t)atoll(Row->GetField(t));          if (t==14) OBT_TIMESYNC      = (UInt_t)atoll(Row->GetField(t));
877                    if (t==15) COMPILATIONTIMESTAMP = (UInt_t)atoll(Row->GetField(t));          if (t==15) COMPILATIONTIMESTAMP = (UInt_t)atoll(Row->GetField(t));
878                    if (t==16) FAV_WRK_SCHEDULE  = (UInt_t)atoll(Row->GetField(t));          if (t==16) FAV_WRK_SCHEDULE  = (UInt_t)atoll(Row->GetField(t));
879                    if (t==17) EFF_WRK_SCHEDULE  = (UInt_t)atoll(Row->GetField(t));          if (t==17) EFF_WRK_SCHEDULE  = (UInt_t)atoll(Row->GetField(t));
880                    if (t==18) PRH_VAR_TRG_MODE_A= (UInt_t)atoll(Row->GetField(t));          if (t==18) PRH_VAR_TRG_MODE_A= (UInt_t)atoll(Row->GetField(t));
881                    if (t==19) PRH_VAR_TRG_MODE_B= (UInt_t)atoll(Row->GetField(t));          if (t==19) PRH_VAR_TRG_MODE_B= (UInt_t)atoll(Row->GetField(t));
882                    if (t==20) ACQ_BUILD_INFO    = (UInt_t)atoll(Row->GetField(t));          if (t==20) ACQ_BUILD_INFO    = (UInt_t)atoll(Row->GetField(t));
883                    if (t==21) ACQ_VAR_INFO      = (UInt_t)atoll(Row->GetField(t));          if (t==21) ACQ_VAR_INFO      = (UInt_t)atoll(Row->GetField(t));
884                    if (t==22) RM_ACQ_AFTER_CALIB= (UInt_t)atoll(Row->GetField(t));          if (t==22) RM_ACQ_AFTER_CALIB= (UInt_t)atoll(Row->GetField(t));
885                    if (t==23) RM_ACQ_SETTING_MODE = (UInt_t)atoll(Row->GetField(t));          if (t==23) RM_ACQ_SETTING_MODE = (UInt_t)atoll(Row->GetField(t));
886                    if (t==24) PKT_COUNTER       = (UInt_t)atoll(Row->GetField(t));          if (t==24) PKT_COUNTER       = (UInt_t)atoll(Row->GetField(t));
887                    if (t==25) PKT_READY_COUNTER = (UInt_t)atoll(Row->GetField(t));          if (t==25) PKT_READY_COUNTER = (UInt_t)atoll(Row->GetField(t));
888                    if (t==26) TRK_CALIB_USED    = (UInt_t)atoll(Row->GetField(t));          if (t==26) TRK_CALIB_USED    = (UInt_t)atoll(Row->GetField(t));
889                    if (t==27) CAL_DSP_MASK      = (UInt_t)atoll(Row->GetField(t));          if (t==27) CAL_DSP_MASK      = (UInt_t)atoll(Row->GetField(t));
890                    if (t==28) BOOT_NUMBER       = (UInt_t)atoll(Row->GetField(t));          if (t==28) BOOT_NUMBER       = (UInt_t)atoll(Row->GetField(t));
891                    if (t==29) VALIDATION        = (UInt_t)atoll(Row->GetField(t));          if (t==29) VALIDATION        = (UInt_t)atoll(Row->GetField(t));
892        };        };
893    };    };
894    //  delete pResult;    //  delete pResult;
# Line 1303  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr Line 1301  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr
1301    //    //
1302    // look for Resurs offset    // look for Resurs offset
1303    //    //
1304    UInt_t t0 = 0;    T0 = 0;
1305    //    //
1306    //    //
1307    stringstream oss;    stringstream oss;
1308    oss.str("");    oss.str("");
1309    oss << "SELECT OFFSET_DATE FROM GL_RESURS_OFFSET WHERE SPECIAL_FILE='"    oss << "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE) FROM GL_RESURS_OFFSET WHERE SPECIAL_FILE='"
1310        << rname.str().c_str() << "';";        << rname.str().c_str() << "';";
   //  if ( IsDebug() ) printf(" %s \n",oss.str().c_str());  
1311    pResult = dbc->Query(oss.str().c_str());    pResult = dbc->Query(oss.str().c_str());
1312    Row = pResult->Next();    Row = pResult->Next();
1313    //    //
# Line 1331  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr Line 1328  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr
1328      };          };    
1329      if ( dwo.IsDigit() ) dworbit = (UInt_t)dwo.Atoi();      if ( dwo.IsDigit() ) dworbit = (UInt_t)dwo.Atoi();
1330    };    };
   // if ( IsDebug() ) printf(" Downlink orbit is %i (dwo = %s) \n",dworbit,dwo.Data());    
1331    //    //
1332    if ( !Row ){    if ( !Row ){
1333      oss.str("");      oss.str("");
1334      oss << "SELECT OFFSET_DATE FROM GL_RESURS_OFFSET WHERE FROM_ORBIT< "      oss << "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE) FROM GL_RESURS_OFFSET WHERE FROM_ORBIT< "
1335          << dworbit << " order by FROM_ORBIT desc limit 1;";          << dworbit << " order by FROM_ORBIT desc limit 1;";
     //    if ( IsDebug() ) printf(" %s \n",oss.str().c_str());  
1336      pResult = dbc->Query(oss.str().c_str());      pResult = dbc->Query(oss.str().c_str());
1337      Row = pResult->Next();      Row = pResult->Next();
1338      if ( !Row ){      if ( !Row ){
# Line 1346  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr Line 1341  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr
1341      };      };
1342    };    };
1343    //    //
1344    t0 = (UInt_t)TDatime(Row->GetField(0)).Convert();    TTimeStamp tu = TTimeStamp((UInt_t)atoi(Row->GetField(0)),(UInt_t)atoi(Row->GetField(1)),(UInt_t)atoi(Row->GetField(2)),(UInt_t)atoi(Row->GetField(3)),(UInt_t)atoi(Row->GetField(4)),(UInt_t)atoi(Row->GetField(5)),0,true,0);
1345    //    T0 = (UInt_t)tu.GetSec();
   //  myquery.str("");  
   //   myquery << "SELECT OFFSET_DATE FROM GL_RESURS_OFFSET WHERE FROM_ID_RAW<= "  
   //       << idraw << " AND TO_ID_RAW >= "  
   //       << idraw << ";";  
   //   pResult = dbc->Query(myquery.str().c_str());  
   //   if ( pResult ){  
   //     Row = pResult->Next();  
   //     if ( Row ){  
   //       //  
   //       t0 = (UInt_t)TDatime(Row->GetField(0)).Convert();  
   //       //  
   //     };  
   //   };  
   //  
1346    //    //
1347    // look for the correct timesync entry    // look for the correct timesync entry
1348    //    //
1349    myquery.str("");    myquery.str("");
1350    myquery << " SELECT OBT0,TIMESYNC FROM GL_TIMESYNC "    myquery << " SELECT OBT0,TIMESYNC,TYPE FROM GL_TIMESYNC "
1351        << " WHERE ID_RAW = " << idraw        << " WHERE ID_RAW = " << idraw
1352        << ";";        << ";";
1353    pResult = dbc->Query(myquery.str().c_str());    pResult = dbc->Query(myquery.str().c_str());
1354    if ( pResult ){    if ( pResult ){
1355      Row = pResult->Next();      Row = pResult->Next();
1356      if ( (Row != NULL) && ((UInt_t)atoll(Row->GetField(0)) > 0 ) ){      if ( (Row != NULL) && ((UInt_t)atoll(Row->GetField(0)) > 0 ) ){
1357        toffset = (UInt_t)atoll(Row->GetField(1)) - (UInt_t)(this->DBobt((UInt_t)atoll(Row->GetField(0)))/1000) + t0;        OBT0 = (UInt_t)atoll(Row->GetField(0));
1358          TIMESYNC = (UInt_t)atoll(Row->GetField(1));
1359          TYPE = (UInt_t)atoll(Row->GetField(2));
1360          toffset = (UInt_t)atoll(Row->GetField(1)) - (UInt_t)(this->DBobt((UInt_t)atoll(Row->GetField(0)))/1000) + T0;
1361      };      };
1362    };    };
1363    //    //
# Line 1392  UInt_t GL_TIMESYNC::DBabsTime(UInt_t OBT Line 1376  UInt_t GL_TIMESYNC::DBabsTime(UInt_t OBT
1376    //    //
1377  };  };
1378    
1379    /**
1380     *
1381     * Returns the Resurs time given the OBT needed to process inclination and orbital infos
1382     *
1383     */
1384    UInt_t GL_TIMESYNC::ResursTime(UInt_t OBT){  
1385      //
1386      return(((UInt_t)((Int_t)(this->DBobt(OBT)-this->DBobt(OBT0))/1000)+TIMESYNC));
1387      //
1388    };
1389    
1390  ULong64_t GL_TIMESYNC::DBobt(UInt_t obt){    
1391    /**
1392     * Return the correct packet number if we went back to zero
1393     */
1394    Long64_t GL_TIMESYNC::DBpkt(UInt_t pkt_num){  
1395    //    //
1396    if ( obt < (obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ) return((ULong64_t)(obt+numeric_limits<UInt_t>::max()));    if ( pkt_num < (pktfirst/2) && pktfirst > (16777214/2)  ){
1397        return((Long64_t)pkt_num+16777215LL);
1398      };
1399    //    //
1400    if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){    if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){
1401      if ( (obt-numeric_limits<UInt_t>::max()) < 0  ){      return((Long64_t)pkt_num-16777215LL);
       return((ULong64_t)(numeric_limits<UInt_t>::max()-obt));  
     } else {  
       return((ULong64_t)(obt-numeric_limits<UInt_t>::max()));  
     };  
1402    };    };
1403    //    //
1404    return((ULong64_t)obt);    return((Long64_t)pkt_num);
1405    //    //
1406  };  };
1407    
1408  UInt_t GL_TIMESYNC::DBpkt(UInt_t pkt_num){    /**
1409     * Return the correct On Board Time if we went back to zero
1410     */
1411    Long64_t GL_TIMESYNC::DBobt(UInt_t obt){  
1412    //    //
1413    if ( pkt_num < (pktfirst/2) && pktfirst > (16777214/2)  ) return((pkt_num+16777215));    if ( obt < (obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ) return((Long64_t)(obt+numeric_limits<UInt_t>::max()));
1414    //    //
1415    if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){    if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){
1416      if ( (pkt_num-16777215) < 0 ){      return((Long64_t)obt-(Long64_t)numeric_limits<UInt_t>::max());
       return((16777215-pkt_num));  
     } else {  
       return((pkt_num-16777215));  
     };  
1417    };    };
1418    //    //
1419    return(pkt_num);    return((Long64_t)obt);
   //  
1420  };  };
1421    
1422    
1423    
1424    // ULong64_t GL_TIMESYNC::DBobt(UInt_t obt){  
1425    //   //
1426    //   if ( obt < (obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ) return((ULong64_t)(obt+numeric_limits<UInt_t>::max()));
1427    //   //
1428    //   if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){
1429    //     if ( (obt-numeric_limits<UInt_t>::max()) < 0  ){
1430    //       return((ULong64_t)(numeric_limits<UInt_t>::max()-obt));
1431    //     } else {
1432    //       return((ULong64_t)(obt-numeric_limits<UInt_t>::max()));
1433    //     };
1434    //   };
1435    //   //
1436    //   return((ULong64_t)obt);
1437    //   //
1438    // };
1439    
1440    // UInt_t GL_TIMESYNC::DBpkt(UInt_t pkt_num){  
1441    //   //
1442    //   if ( pkt_num < (pktfirst/2) && pktfirst > (16777214/2)  ) return((pkt_num+16777215));
1443    //   //
1444    //   if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){
1445    //     if ( (pkt_num-16777215) < 0 ){
1446    //       return((16777215-pkt_num));
1447    //     } else {
1448    //       return((pkt_num-16777215));
1449    //     };
1450    //   };
1451    //   //
1452    //   return(pkt_num);
1453    //   //
1454    // };
1455    
1456  /*  /*
1457   *   *
1458   * Convert the time in the DB from UInt_t to a string   * Convert the time in the DB from UInt_t to a string
# Line 1435  UInt_t GL_TIMESYNC::DBpkt(UInt_t pkt_num Line 1463  UInt_t GL_TIMESYNC::DBpkt(UInt_t pkt_num
1463   */   */
1464  TString GL_TIMESYNC::ConvertTime(TString &tzone, UInt_t dbt){  TString GL_TIMESYNC::ConvertTime(TString &tzone, UInt_t dbt){
1465    //    //
1466    TDatime *time = new TDatime();    Int_t offset = 0;
1467    TString rtime;    TString rtime;
1468    Bool_t found = false;    Bool_t found = false;
1469    //    //
   time->Set(dbt,false); // UTC (Coordinated Universal Time)    
   //  
1470    if ( !strcmp(tzone.Data(),"MSK") || !strcmp(tzone.Data(),"MWT") ){    if ( !strcmp(tzone.Data(),"MSK") || !strcmp(tzone.Data(),"MWT") ){
1471      //      //
1472      UInt_t timeMSK = time->Convert() + 60*60*3; // UTC (Coordinated Universal Time) + 3hs = Moscow Winter Time      offset = 60*60*3; // UTC (Coordinated Universal Time) + 3hs = Moscow Winter Time
     time->Set(timeMSK,false);  
1473      found = true;      found = true;
1474      //      //
1475    };    };
1476    //    //
1477    if ( !strcmp(tzone.Data(),"CET") ){    if ( !strcmp(tzone.Data(),"CET") ){
1478      //      //
1479      UInt_t timeCET = time->Convert() + 60*60*1; // CET (Central European Time) = UTC + 1 hs      offset = 60*60*1; // CET (Central European Time) = UTC + 1 hs
     time->Set(timeCET,false);  
1480      found = true;      found = true;
1481      //      //
1482    };    };
1483    //    //
1484    if ( !strcmp(tzone.Data(),"CEST") ){    if ( !strcmp(tzone.Data(),"CEST") ){
1485      //      //
1486      UInt_t timeCEST = time->Convert() + 60*60*2; // CEST (Central European Summer Time) = UTC + 2 h      offset = 60*60*2; // CEST (Central European Summer Time) = UTC + 2 h
     time->Set(timeCEST,false);  
1487      found = true;      found = true;
1488      //      //
1489    };    };
1490    //    //
1491    if ( !strcmp(tzone.Data(),"MSD") || !strcmp(tzone.Data(),"MST")){    if ( !strcmp(tzone.Data(),"MSD") || !strcmp(tzone.Data(),"MST")){
1492      //      //
1493      UInt_t timeMSD = time->Convert() + 60*60*4; // MSD (Moscow Summer Time) = UTC + 4 h      offset = 60*60*4; // MSD (Moscow Summer Time) = UTC + 4 h
     time->Set(timeMSD,false);  
1494      found = true;      found = true;
1495      //      //
1496    };    };
# Line 1478  TString GL_TIMESYNC::ConvertTime(TString Line 1500  TString GL_TIMESYNC::ConvertTime(TString
1500      tzone = "UTC";      tzone = "UTC";
1501    };    };
1502    //    //
1503    rtime = time->AsSQLString();    dbt += offset;
1504      //
1505      TTimeStamp *time = new TTimeStamp((time_t)dbt,0);
1506      //
1507      rtime = time->AsString("s");
1508      //
1509      delete time;
1510    //    //
1511    return(rtime);    return(rtime);
1512  }  }
1513    
1514  /*  /*
1515   *   *
1516   * Convert the time in the DB from UInt_t to a string   * Convert the time from TZONE to UTC
1517   *   *
1518   * @param dbt time in the DB   * @param dbt time in the DB
1519   * @param tzone Time Zone, can be UTC,GMT,CET,CEST,MSD default is MSK   * @param tzone Time Zone, can be UTC,GMT,CET,CEST,MSD default is MSK
# Line 1493  TString GL_TIMESYNC::ConvertTime(TString Line 1521  TString GL_TIMESYNC::ConvertTime(TString
1521   */   */
1522  TString GL_TIMESYNC::UnConvertTime(TString &tzone, UInt_t dbt){  TString GL_TIMESYNC::UnConvertTime(TString &tzone, UInt_t dbt){
1523    //    //
1524    TDatime *time = new TDatime();    Int_t offset = 0;
1525    TString rtime;    TString rtime;
1526    //    //
1527    Bool_t found = false;    Bool_t found = false;
1528    //    //
   time->Set(dbt,false); // tzone  
   //  
1529    if ( !strcmp(tzone.Data(),"MSK") || !strcmp(tzone.Data(),"MWT") ){    if ( !strcmp(tzone.Data(),"MSK") || !strcmp(tzone.Data(),"MWT") ){
1530      //      //
1531      UInt_t timeUTC = time->Convert() - 60*60*3; // UTC (Coordinated Universal Time) = Moscow Winter Time - 3hs      offset = -60*60*3; // UTC (Coordinated Universal Time) = Moscow Winter Time - 3hs
     time->Set(timeUTC,false);  
1532      found = true;      found = true;
1533      //      //
1534    };    };
1535    //    //
1536    if ( !strcmp(tzone.Data(),"CET") ){    if ( !strcmp(tzone.Data(),"CET") ){
1537      //      //
1538      UInt_t timeCET = time->Convert() - 60*60*1; // CET (Central European Time) - 1 hs = UTC        offset = -60*60*1; // CET (Central European Time) - 1 hs = UTC  
     time->Set(timeCET,false);  
1539      found = true;      found = true;
1540      //      //
1541    };    };
1542    //    //
1543    if ( !strcmp(tzone.Data(),"CEST") ){    if ( !strcmp(tzone.Data(),"CEST") ){
1544      //      //
1545      UInt_t timeCEST = time->Convert() - 60*60*2; // CEST (Central European Summer Time) - 2 h = UTC      offset = -60*60*2; // CEST (Central European Summer Time) - 2 h = UTC
     time->Set(timeCEST,false);  
1546      found = true;      found = true;
1547      //      //
1548    };    };
1549    //    //
1550    if ( !strcmp(tzone.Data(),"MSD") || !strcmp(tzone.Data(),"MST") ){    if ( !strcmp(tzone.Data(),"MSD") || !strcmp(tzone.Data(),"MST") ){
1551      //      //
1552      UInt_t timeMSD = time->Convert() - 60*60*4; // MSD (Moscow Summer Time) - 4 h = UTC      offset = -60*60*4; // MSD (Moscow Summer Time) - 4 h = UTC
     time->Set(timeMSD,false);  
1553      found = true;      found = true;
1554      //      //
1555    };    };
1556    //    //
1557    if ( !found && strcmp(tzone.Data(),"UTC") && strcmp(tzone.Data(),"GMT") && strcmp(tzone.Data(),"") ){    if ( !found && strcmp(tzone.Data(),"UTC") && strcmp(tzone.Data(),"GMT") && strcmp(tzone.Data(),"") ){
1558      //      //
1559        offset = 0;
1560      printf("\n Unknown time zone %s using UTC \n",tzone.Data());      printf("\n Unknown time zone %s using UTC \n",tzone.Data());
1561      tzone = "UTC";      tzone = "UTC";
1562    };    };
1563    //    //
1564    rtime = time->AsSQLString();    dbt += offset;
1565      TTimeStamp *time = new TTimeStamp((time_t)dbt,0);
1566      //
1567      rtime = time->AsString("s");
1568    //    //
1569    return(rtime);    return(rtime);
1570  }  }
1571    
1572    
1573  // ****************************************************  //
1574  /**  // Build a query and call DoQuery.
1575   * Function to query the GL_TLE table of the DB.  //
1576   *  // date it's an SQL datetime date and dbc is the connection to be
1577   * time is the unix time for which a good tle is requested.  // used.  It will query for the tle with the nearest but previous date
1578   *  // and the immediatly next one.
1579   * Return the pointer to a cTle object that has the closest and  //
1580   * previous date compared with time.  Int_t GL_TLE::Query(TString date, TSQLServer *dbc){
  *  
  * If errors occurs it returns NULL.  
  */  
 cTle* GL_TLE::Query_GL_TLE(UInt_t time, TSQLServer *dbc){  
1581    stringstream myquery;    stringstream myquery;
1582    myquery.str("");    myquery.str("");
1583    
1584    myquery << "SELECT TLE1, TLE2, TLE3 FROM GL_TLE "    myquery << "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE "
1585            << "WHERE FROM_TIME < FROM_UNIXTIME(" << time << ") ORDER BY FROM_TIME DESC LIMIT 1;";              << "WHERE FROM_TIME <= '" << date.Data()
1586              << "' ORDER BY FROM_TIME DESC LIMIT 1) "
1587              << "UNION "
1588              << "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE "
1589              << "WHERE FROM_TIME > '" << date.Data()
1590              << "' ORDER BY FROM_TIME ASC LIMIT 1)";
1591    
1592      return DoQuery(myquery.str().c_str(), dbc);
   return Query_GL_TLE_go(myquery.str(), dbc);  
1593  }  }
1594    
1595    
1596  // ****************************************************  //
1597  /**  // Build a query and call DoQuery.
1598   * Function to query the GL_TLE table of the DB.  //
1599   *  // time is the UTC date in unix time (UTC) and dbc is the connection
1600   * date is a datetime format YYYY-MM-DD hh:mm:ss for which a good tle  // to be used.  It will query for the tle with the nearest but
1601   * is requested.  // previous date and the immediatly next one.
1602   *  //
1603   * Return the pointer to a cTle object that has the closest and  // Returns the value returned by DoQuery().
1604   * previous date compared with time.  //
1605   *  Int_t GL_TLE::Query(UInt_t time, TSQLServer *dbc){
  * If errors occurs it returns NULL.  
  */  
 cTle* GL_TLE::Query_GL_TLE(TString date, TSQLServer *dbc){  
1606    stringstream myquery;    stringstream myquery;
1607    myquery.str("");    myquery.str("");
1608    
1609    myquery << "SELECT TLE1, TLE2, TLE3 FROM GL_TLE "    myquery << "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE "
1610            << "WHERE FROM_TIME < '" << date.Data() << "' ORDER BY FROM_TIME DESC LIMIT 1;";              << "WHERE FROM_TIME <= FROM_UNIXTIME('" << time
1611              << "') ORDER BY FROM_TIME DESC LIMIT 1) "
1612              << "UNION "
1613              << "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE "
1614              << "WHERE FROM_TIME > FROM_UNIXTIME('" << time
1615              << "') ORDER BY FROM_TIME ASC LIMIT 1)";
1616    
1617      return DoQuery(myquery.str().c_str(), dbc);
   return Query_GL_TLE_go(myquery.str(), dbc);  
1618  }  }
1619    
1620    
1621  // ****************************************************  //
1622  /**  // Do the query myquery on the connectio dbc.  Initialize tle,
1623   * Private function used by Query_GL_TLE methods.  // tleFromTime and tleToTime.
1624   *  //
1625   * myquery is the query string.  // We should have two rows (unless the table is old).  From the last
1626   *  // one we only take tleToTime.
1627   * Return the pointer to a cTle object that has the closest and  //
1628   * previous date compared with time.  // Returns 0 for success, 1 for failure.
1629   *  //
1630   * If errors occurs it returns NULL.  Int_t GL_TLE::DoQuery(TString myquery, TSQLServer *dbc){
  */  
 cTle* GL_TLE::Query_GL_TLE_go(TString myquery, TSQLServer *dbc){  
   cTle *tle;  
   string tle1, tle2, tle3;  
   
   // MySQL variables  
1631    TSQLResult *result;    TSQLResult *result;
1632    TSQLRow *row;    TSQLRow *row;
1633    
1634      // Set the right time_zone (otherwise horrible things will occur! :)
1635      dbc->Query("SET time_zone = '+0:00'");
1636    
1637      // Do the query
1638    result = dbc->Query(myquery.Data());    result = dbc->Query(myquery.Data());
1639    if(! result->GetRowCount() ) return NULL;    if(! result->GetRowCount() ) {
1640        cerr << "GL_TLE: query failed: " << myquery.Data() << endl;
1641        return 1;
1642      }
1643    
1644      // Get results
1645      row = result->Next(); // first tle row
1646      tle = GiveTle(row);
1647    
1648      tleFromTime = strtol(row->GetField(4), NULL, 10);
1649    
1650      row = result->Next(); // second tle row
1651      if(row)
1652        tleToTime = strtol(row->GetField(4), NULL, 10);
1653      else {
1654        cerr << "GL_TLE: Warning: using last avaible TLE. Please update GL_TLE table!\n";
1655        tleToTime = UINT_MAX;
1656      }
1657    
1658      delete row;
1659      delete result;
1660    
1661    row = result->Next();    return 0;
1662    tle1 = row->GetField(0);  }
   tle2 = row->GetField(1);  
   tle3 = row->GetField(2);  
1663    
   tle = new cTle(tle1, tle2, tle3);  
1664    
1665    delete result;  //
1666    delete row;  // Build a cTle object from the GL_TLE row.
1667    //
1668    cTle* GL_TLE::GiveTle(TSQLRow *row) {
1669      cTle *thistle = NULL;
1670      string tle1, tle2, tle3;
1671    
1672      // Build cTle object
1673      tle1 = row->GetField(1);
1674      tle2 = row->GetField(2);
1675      tle3 = row->GetField(3);
1676    
1677      thistle = new cTle(tle1, tle2, tle3);
1678    
1679    return tle;    return thistle;
1680  }  }

Legend:
Removed from v.1.15  
changed lines
  Added in v.1.21

  ViewVC Help
Powered by ViewVC 1.1.23