/[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.20 by mocchiut, Mon Nov 27 14:25:34 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 1573  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      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.20  
changed lines
  Added in v.1.21

  ViewVC Help
Powered by ViewVC 1.1.23