/[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.17 by mocchiut, Thu Nov 9 12:02:54 2006 UTC revision 1.21 by mocchiut, Tue Jan 23 17:04:11 2007 UTC
# Line 161  GL_TIMESYNC::GL_TIMESYNC(){ Line 161  GL_TIMESYNC::GL_TIMESYNC(){
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 1309  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr Line 1306  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr
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 1332  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 1347  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr Line 1341  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr
1341      };      };
1342    };    };
1343    //    //
1344    //      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);
   TDatime ti = TDatime(Row->GetField(0));  
   TTimeStamp tu = TTimeStamp((UInt_t)ti.GetYear(),(UInt_t)ti.GetMonth(),(UInt_t)ti.GetDay(),(UInt_t)ti.GetHour(),(UInt_t)ti.GetMinute(),(UInt_t)ti.GetSecond(),0,true,0);  
1345    T0 = (UInt_t)tu.GetSec();    T0 = (UInt_t)tu.GetSec();
1346    //    //
1347    // look for the correct timesync entry    // look for the correct timesync entry
# Line 1391  UInt_t GL_TIMESYNC::DBabsTime(UInt_t OBT Line 1383  UInt_t GL_TIMESYNC::DBabsTime(UInt_t OBT
1383   */   */
1384  UInt_t GL_TIMESYNC::ResursTime(UInt_t OBT){    UInt_t GL_TIMESYNC::ResursTime(UInt_t OBT){  
1385    //    //
1386    return(((UInt_t)((this->DBobt(OBT)-this->DBobt(OBT0))/1000)+TIMESYNC));    return(((UInt_t)((Int_t)(this->DBobt(OBT)-this->DBobt(OBT0))/1000)+TIMESYNC));
1387    //    //
1388  };  };
1389    
1390    
1391  ULong64_t GL_TIMESYNC::DBobt(UInt_t obt){    /**
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 1545  TString GL_TIMESYNC::UnConvertTime(TStri Line 1570  TString GL_TIMESYNC::UnConvertTime(TStri
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 Query_GL_TLE_go(myquery.str(), dbc);    return DoQuery(myquery.str().c_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 Query_GL_TLE_go(myquery.str(), dbc);    return DoQuery(myquery.str().c_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    row = result->Next();    delete row;
1659    tle1 = row->GetField(0);    delete result;
   tle2 = row->GetField(1);  
   tle3 = row->GetField(2);  
1660    
1661    tle = new cTle(tle1, tle2, tle3);    return 0;
1662    }
1663    
   delete result;  
   delete row;  
1664    
1665    return tle;  //
1666    // 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 thistle;
1680  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.23