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

Diff of /YodaProfiler/src/PamelaDBOperations.cpp

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

revision 1.14 by mocchiut, Fri Oct 20 11:39:37 2006 UTC revision 1.16 by mocchiut, Tue Oct 31 15:36:04 2006 UTC
# Line 81  PamelaDBOperations::PamelaDBOperations(T Line 81  PamelaDBOperations::PamelaDBOperations(T
81      this->SetRootName(filerootname);      this->SetRootName(filerootname);
82      this->SetOrbitNo();      this->SetOrbitNo();
83      file = TFile::Open(this->GetRootName().Data());      file = TFile::Open(this->GetRootName().Data());
84      } else {
85        this->SetRootName("");
86    };    };
87    //    //
88    this->SetID_RAW(0);    this->SetID_RAW(0);
# Line 154  void PamelaDBOperations::SetDebugFlag(Bo Line 156  void PamelaDBOperations::SetDebugFlag(Bo
156  };  };
157    
158  /**  /**
159     * Set the nofrag flag
160     *
161     */
162    void PamelaDBOperations::SetNoFrag(Bool_t nf){
163      NOFRAG = nf;
164    };
165    
166    /**
167   * Store the BOOT number of the RAW file.   * Store the BOOT number of the RAW file.
168   * @param boot    BOOT number of the RAW file   * @param boot    BOOT number of the RAW file
169   */   */
# Line 753  void PamelaDBOperations::CheckConnection Line 763  void PamelaDBOperations::CheckConnection
763    if( !conn ) throw -1;    if( !conn ) throw -1;
764    bool connect = conn->IsConnected();    bool connect = conn->IsConnected();
765    if( !connect ) throw -1;    if( !connect ) throw -1;
766    if ( !dworbit ) throw -27;    if ( !dworbit && strcmp(this->GetRootName().Data(),"") ) throw -27;
767  };  };
768    
769  /**  /**
# Line 1556  Bool_t PamelaDBOperations::IsRunAlreadyI Line 1566  Bool_t PamelaDBOperations::IsRunAlreadyI
1566      if ( glrun->GetNEVENTS() > (UInt_t)atoll(row->GetField(1)) ){      if ( glrun->GetNEVENTS() > (UInt_t)atoll(row->GetField(1)) ){
1567        //        //
1568        if ( IsDebug() ) printf(" The new run has more events than the old one \n");        if ( IsDebug() ) printf(" The new run has more events than the old one \n");
1569        oss.str("");        glrun->DeleteRun(conn,(UInt_t)atoll(row->GetField(0)),"GL_RUN");
1570        oss << "DELETE FROM GL_RUN WHERE ID=" << row->GetField(0) <<";";  //       oss.str("");
1571        if ( IsDebug() ) printf(" delete the run entry: query is \n %s \n",oss.str().c_str());        //       oss << "DELETE FROM GL_RUN WHERE ID=" << row->GetField(0) <<";";
1572        conn->Query(oss.str().c_str());  //       if ( IsDebug() ) printf(" delete the run entry: query is \n %s \n",oss.str().c_str());      
1573    //       conn->Query(oss.str().c_str());
1574        if ( signal ) signal = false;        if ( signal ) signal = false;
1575        goto gonext;              goto gonext;      
1576        //        //
# Line 1573  Bool_t PamelaDBOperations::IsRunAlreadyI Line 1584  Bool_t PamelaDBOperations::IsRunAlreadyI
1584        //        //
1585        if ( IsDebug() ) printf(" The new run has the same number of events and the runheader the old one miss the runheader \n");        if ( IsDebug() ) printf(" The new run has the same number of events and the runheader the old one miss the runheader \n");
1586        //        //
1587        oss.str("");        glrun->DeleteRun(conn,(UInt_t)atoll(row->GetField(0)),"GL_RUN");
1588        oss << "DELETE FROM GL_RUN WHERE ID=" << row->GetField(0) <<";";  //       oss.str("");
1589        if ( IsDebug() ) printf(" delete the run entry: query is \n %s \n",oss.str().c_str());        //       oss << "DELETE FROM GL_RUN WHERE ID=" << row->GetField(0) <<";";
1590        conn->Query(oss.str().c_str());  //       if ( IsDebug() ) printf(" delete the run entry: query is \n %s \n",oss.str().c_str());      
1591    //       conn->Query(oss.str().c_str());
1592        //        //
1593        if ( signal ) signal = false;        if ( signal ) signal = false;
1594        goto gonext;        goto gonext;
# Line 1590  Bool_t PamelaDBOperations::IsRunAlreadyI Line 1602  Bool_t PamelaDBOperations::IsRunAlreadyI
1602        //        //
1603        if ( IsDebug() ) printf(" The new run has the same number of events, the runheader and the runtrailer the old one miss the runtrailer \n");        if ( IsDebug() ) printf(" The new run has the same number of events, the runheader and the runtrailer the old one miss the runtrailer \n");
1604        //        //
1605        oss.str("");        glrun->DeleteRun(conn,(UInt_t)atoll(row->GetField(0)),"GL_RUN");
1606        oss << "DELETE FROM GL_RUN WHERE ID=" << row->GetField(0) <<";";  //       oss.str("");
1607        if ( IsDebug() ) printf(" delete the run entry: query is \n %s \n",oss.str().c_str());        //       oss << "DELETE FROM GL_RUN WHERE ID=" << row->GetField(0) <<";";
1608        conn->Query(oss.str().c_str());  //       if ( IsDebug() ) printf(" delete the run entry: query is \n %s \n",oss.str().c_str());      
1609    //       conn->Query(oss.str().c_str());
1610        if ( signal ) signal = false;        if ( signal ) signal = false;
1611        //        //
1612      };      };
# Line 1656  void PamelaDBOperations::HandleRunFragme Line 1669  void PamelaDBOperations::HandleRunFragme
1669    UInt_t rhfirstev = firstev;    UInt_t rhfirstev = firstev;
1670    UInt_t rtlastev = lastev;    UInt_t rtlastev = lastev;
1671    Bool_t found = false;    Bool_t found = false;
1672      Bool_t foundinrun = false;
1673    //    //
1674    TSQLResult *result = 0;    TSQLResult *result = 0;
1675    TSQLRow    *row    = 0;    TSQLRow    *row    = 0;
# Line 1682  void PamelaDBOperations::HandleRunFragme Line 1696  void PamelaDBOperations::HandleRunFragme
1696    //    //
1697    if ( IsDebug() ) printf("The run is good, is it the other piece in the GL_RUN_FRAGMENTS table?\n");    if ( IsDebug() ) printf("The run is good, is it the other piece in the GL_RUN_FRAGMENTS table?\n");
1698    //    //
1699      // First of all insert the run in the fragment table...
1700      //
1701      oss.str("");
1702      oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE "
1703          << " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND ("
1704          << " (RUNHEADER_TIME>=" << (UInt_t)(glrun->GetRUNHEADER_TIME()-10) << " AND "
1705          << " RUNTRAILER_TIME<=" << (UInt_t)(glrun->GetRUNTRAILER_TIME()+10) << " AND ("
1706          << " RUNHEADER_OBT>=" << glrun->GetRUNHEADER_OBT() << " OR "
1707          << " RUNHEADER_PKT>=" << glrun->GetRUNHEADER_PKT() << ") AND ("
1708          << " RUNTRAILER_OBT<=" << glrun->GetRUNTRAILER_OBT() << " OR "
1709          << " RUNTRAILER_PKT<=" << glrun->GetRUNTRAILER_PKT() << ") ) OR "
1710          << " (RUNHEADER_TIME<=" << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND "
1711          << " RUNTRAILER_TIME>=" << (UInt_t)glrun->GetRUNTRAILER_TIME() <<" AND ("
1712          << " RUNHEADER_OBT<=" << glrun->GetRUNHEADER_OBT() << " OR "
1713          << " RUNHEADER_PKT<=" << glrun->GetRUNHEADER_PKT() << ") AND ("
1714          << " RUNTRAILER_OBT>=" << glrun->GetRUNTRAILER_OBT() << " OR "
1715          << " RUNTRAILER_PKT>=" << glrun->GetRUNTRAILER_PKT() << ") ));";
1716      //
1717      if ( IsDebug() ) printf(" check if run has been inserted: query is \n %s \n",oss.str().c_str());
1718      result = conn->Query(oss.str().c_str());
1719      //
1720      if ( !result ) throw -4;
1721      //
1722      row = result->Next();
1723      //
1724      if ( !row ){
1725        //
1726        // no, insert this run in the GL_RUN_FRAGMENTS table (check if exist before!)
1727        //
1728        if ( IsDebug() ) printf(" The run is new \n");
1729        if ( IsDebug() ) printf(" -> fill the GL_RUNFRAGMENTS table \n");
1730        //
1731        glrun->SetID(this->AssignRunID());
1732        glrun->SetID_RUN_FRAG(0);
1733        glrun->Fill_GL_RUN_FRAGMENTS(conn);
1734        //
1735      } else {
1736        if ( IsDebug() ) printf(" The run is already present in the fragment table \n");
1737      };
1738      //
1739      //
1740    // can we find the other piece of the run in the GL_RUN_FRAGMENTS table?    // can we find the other piece of the run in the GL_RUN_FRAGMENTS table?
1741    //        //    
1742    if ( mishead && rhfirstev == firstev ) { // look for runheader (only when at the beginning of the file, if at the end and the runh is    if ( mishead && rhfirstev == firstev ) { // look for runheader (only when at the beginning of the file, if at the end and the runh is
# Line 1690  void PamelaDBOperations::HandleRunFragme Line 1745  void PamelaDBOperations::HandleRunFragme
1745      oss.str("");      oss.str("");
1746      oss << " SELECT ID,TRK_CALIB_USED,RUNTRAILER_TIME,RUNTRAILER_OBT,RUNHEADER_PKT,RUNTRAILER_PKT FROM GL_RUN_FRAGMENTS WHERE "      oss << " SELECT ID,TRK_CALIB_USED,RUNTRAILER_TIME,RUNTRAILER_OBT,RUNHEADER_PKT,RUNTRAILER_PKT FROM GL_RUN_FRAGMENTS WHERE "
1747          << " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND "          << " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND "
1748          << " RUNHEADER_TIME <= " << (UInt_t)glrun->GetRUNHEADER_TIME()          << " RUNHEADER_TIME <= " << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND "
1749            << " ID != " << glrun->ID
1750          << " ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; // DESC NOT ASC!!          << " ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; // DESC NOT ASC!!
1751      //      //
1752      if ( IsDebug() ) printf(" look for runheader in the fragments table: query is \n %s \n",oss.str().c_str());      if ( IsDebug() ) printf(" look for runheader in the fragments table: query is \n %s \n",oss.str().c_str());
# Line 1700  void PamelaDBOperations::HandleRunFragme Line 1756  void PamelaDBOperations::HandleRunFragme
1756      //      //
1757      row = result->Next();      row = result->Next();
1758      //      //
1759        if ( !row && NoFrag() ){
1760          //
1761          oss.str("");
1762          oss << " SELECT ID,TRK_CALIB_USED,RUNTRAILER_TIME,RUNTRAILER_OBT,RUNHEADER_PKT,RUNTRAILER_PKT FROM GL_RUN WHERE "
1763              << " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND "
1764              << " RUNHEADER_TIME <= " << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND "
1765              << " ID != " << glrun->ID
1766              << " AND ID=ID_RUN_FRAG ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; // DESC NOT ASC!!
1767          //
1768          if ( IsDebug() ) printf(" look for runheader in the GL_RUN table: query is \n %s \n",oss.str().c_str());
1769          result = conn->Query(oss.str().c_str());
1770          //
1771          if ( !result ) throw -4;
1772          //
1773          foundinrun = true;
1774          //
1775          row = result->Next();
1776          //
1777        };
1778        //
1779      if ( !row ){      if ( !row ){
1780        if ( IsDebug() ) printf(" the corresponding piece has NOT been found \n");        if ( IsDebug() ) printf(" the corresponding piece has NOT been found \n");
1781        found = false;        found = false;
# Line 1774  void PamelaDBOperations::HandleRunFragme Line 1850  void PamelaDBOperations::HandleRunFragme
1850        //        //
1851        if ( IsDebug() ) printf(" now you can handle the piece of the run \n ");        if ( IsDebug() ) printf(" now you can handle the piece of the run \n ");
1852        //        //
1853          if ( foundinrun ){
1854            glrun->RestoreRun(conn,(UInt_t)atoll(row->GetField(0)),"GL_RUN_FRAGMENTS");
1855            glrun->DeleteRun(conn,(UInt_t)atoll(row->GetField(0)),"GL_RUN");
1856          };
1857          //
1858        GL_RUN *glrun1 = new GL_RUN();        GL_RUN *glrun1 = new GL_RUN();
1859        //        //
1860        UInt_t idfrag = (UInt_t)atoll(row->GetField(0));        //      UInt_t idfrag = (UInt_t)atoll(row->GetField(0));
1861        //        //
1862        oss.str("");        oss.str("");
1863        oss << " ID="<<row->GetField(0)<<";";        oss << " ID="<<row->GetField(0)<<";";
# Line 1813  void PamelaDBOperations::HandleRunFragme Line 1894  void PamelaDBOperations::HandleRunFragme
1894        //        //
1895        glrun->SetEV_FROM(firstev);        glrun->SetEV_FROM(firstev);
1896        glrun->SetNEVENTS(lastev-firstev+1);        glrun->SetNEVENTS(lastev-firstev+1);
1897          //
1898        glrun->SetRUNHEADER_TIME(glrun1->GetRUNHEADER_TIME());        glrun->SetRUNHEADER_TIME(glrun1->GetRUNHEADER_TIME());
1899        glrun->SetRUNHEADER_OBT(glrun1->GetRUNHEADER_OBT());        glrun->SetRUNHEADER_OBT(glrun1->GetRUNHEADER_OBT());
1900        glrun->SetRUNHEADER_PKT(glrun1->GetRUNHEADER_PKT());        glrun->SetRUNHEADER_PKT(glrun1->GetRUNHEADER_PKT());
# Line 1832  void PamelaDBOperations::HandleRunFragme Line 1914  void PamelaDBOperations::HandleRunFragme
1914        //        //
1915        if ( !IsRunAlreadyInserted() ){        if ( !IsRunAlreadyInserted() ){
1916          //          //
1917          glrun->SetID(this->AssignRunID());          //      glrun->SetID(this->AssignRunID());
1918          glrun->SetID_RUN_FRAG(glrun1->GetID());          glrun->SetID_RUN_FRAG(glrun1->GetID());
1919          glrun->Fill_GL_RUN(conn);          glrun->Fill_GL_RUN(conn);
1920          //          //
1921          // get id number          // set id number
         //  
 //      oss.str("");  
 //      oss << " SELECT ID FROM GL_RUN WHERE BOOT_NUMBER="<<this->GetBOOTnumber()<<" AND "  
 //          << " RUNHEADER_OBT="<<glrun->GetRUNHEADER_OBT()<<" AND "  
 //          << " RUNTRAILER_OBT="<<glrun->GetRUNTRAILER_OBT()<<";";  
 //      //  
 //      if ( IsDebug() ) printf(" search for idrun0 , query is : \n%s\n",oss.str().c_str());  
 //      //  
 //      result =  conn->Query(oss.str().c_str());  
 //      if ( !result ) throw -4;  
 //      row = result->Next();  
 //      //  
 //      UInt_t idrun0 = 0;  
 //      if ( !row ){  
 //        throw -10;  
 //      } else {  
 //        idrun0 = (UInt_t)atoll(row->GetField(0));  
 //      };  
1922          //          //
         //      glrun1->SetID_RUN_FRAG(idrun0);  
1923          glrun1->SetID_RUN_FRAG(glrun->GetID());          glrun1->SetID_RUN_FRAG(glrun->GetID());
1924          glrun1->Fill_GL_RUN(conn);          glrun1->Fill_GL_RUN(conn);
1925          //          //
 //      oss.str("");  
 //      oss << " SELECT ID FROM GL_RUN WHERE ID_RUN_FRAG="<<idrun0<<" ;";  
 //      //  
 //      if ( IsDebug() ) printf(" search for idrun1 , query is : \n%s\n",oss.str().c_str());  
 //      //  
 //      result =  conn->Query(oss.str().c_str());  
 //      if ( !result ) throw -4;  
 //      row = result->Next();  
 //      //  
 //      UInt_t idrun1 = 0;  
 //      if ( !row ){  
 //        throw -10;  
 //      } else {  
 //        idrun1 = (UInt_t)atoll(row->GetField(0));  
 //      };  
 //      //  
 //      oss.str("");  
 //      oss << " UPDATE GL_RUN SET ID_RUN_FRAG="<<idrun1<<" WHERE ID="<<idrun0<<" ;";  
 //      //  
 //      result =  conn->Query(oss.str().c_str());  
 //      if ( !result ) throw -4;  
         //  
1926        };        };
       //  
       delete glrun1;  
       //  
1927        // delete old entry in fragment table        // delete old entry in fragment table
1928        //        //
1929        oss.str("");        glrun->DeleteRun(conn,0,"GL_RUN_FRAGMENTS");
1930          glrun1->DeleteRun(conn,0,"GL_RUN_FRAGMENTS");
1931        //        //
1932        oss << " DELETE FROM GL_RUN_FRAGMENTS WHERE ID = " << idfrag << ";";        delete glrun1;
1933        //        //
       if ( IsDebug() ) printf(" Delete from frag table the old run :\n query is \n %s \n",oss.str().c_str());  
       result =  conn->Query(oss.str().c_str());  
       if ( !result ) throw -4;  
1934        //        //
1935        return;        return;
1936        //        //
# Line 1903  void PamelaDBOperations::HandleRunFragme Line 1939  void PamelaDBOperations::HandleRunFragme
1939    };    };
1940    //    //
1941    if ( mistrail && rtlastev == lastev ) { // look for runtrailer (only when at the end of the file, if at the beginning and the runh is    if ( mistrail && rtlastev == lastev ) { // look for runtrailer (only when at the end of the file, if at the beginning and the runh is
1942                                             // missing it no way we can found a piece in the frag table      // missing it no way we can found a piece in the frag table
1943      //      //
1944      oss.str("");      oss.str("");
1945      oss << " SELECT ID,PKT_COUNTER,RUNHEADER_TIME,RUNHEADER_OBT,RUNTRAILER_PKT,RUNHEADER_PKT FROM GL_RUN_FRAGMENTS WHERE "      oss << " SELECT ID,PKT_COUNTER,RUNHEADER_TIME,RUNHEADER_OBT,RUNTRAILER_PKT,RUNHEADER_PKT FROM GL_RUN_FRAGMENTS WHERE "
1946          << " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND "          << " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND "
1947          << " RUNTRAILER_TIME >= " << (UInt_t)glrun->GetRUNTRAILER_TIME()          << " RUNTRAILER_TIME >= " << (UInt_t)glrun->GetRUNTRAILER_TIME() << " AND "
1948            << " ID != " << glrun->ID
1949          << " ORDER BY RUNTRAILER_TIME ASC LIMIT 1;";          << " ORDER BY RUNTRAILER_TIME ASC LIMIT 1;";
1950      //      //
1951      if ( IsDebug() ) printf(" look for runtrailer in the fragments table: query is \n %s \n",oss.str().c_str());      if ( IsDebug() ) printf(" look for runtrailer in the fragments table: query is \n %s \n",oss.str().c_str());
# Line 1918  void PamelaDBOperations::HandleRunFragme Line 1955  void PamelaDBOperations::HandleRunFragme
1955      //      //
1956      row = result->Next();      row = result->Next();
1957      //      //
1958        if ( !row && NoFrag() ){
1959          //
1960          oss.str("");
1961          oss << " SELECT ID,PKT_COUNTER,RUNHEADER_TIME,RUNHEADER_OBT,RUNTRAILER_PKT,RUNHEADER_PKT FROM GL_RUN WHERE "
1962              << " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND "
1963              << " RUNTRAILER_TIME >= " << (UInt_t)glrun->GetRUNTRAILER_TIME() << " AND "
1964              << " ID != " << glrun->ID
1965              << " AND ID=ID_RUN_FRAG ORDER BY RUNTRAILER_TIME ASC LIMIT 1;";
1966          //
1967          if ( IsDebug() ) printf(" look for runheader in the GL_RUN table: query is \n %s \n",oss.str().c_str());
1968          result = conn->Query(oss.str().c_str());
1969          //
1970          if ( !result ) throw -4;
1971          //
1972          foundinrun = true;
1973          row = result->Next();
1974          //
1975        };
1976        //
1977      if ( !row ){      if ( !row ){
1978        if ( IsDebug() ) printf(" the corresponding piece has NOT been found \n");        if ( IsDebug() ) printf(" the corresponding piece has NOT been found \n");
1979        found = false;        found = false;
# Line 1991  void PamelaDBOperations::HandleRunFragme Line 2047  void PamelaDBOperations::HandleRunFragme
2047        //        //
2048        if ( IsDebug() ) printf(" now you can handle the piece of the run \n ");        if ( IsDebug() ) printf(" now you can handle the piece of the run \n ");
2049        //        //
2050          if ( foundinrun ){
2051            glrun->RestoreRun(conn,(UInt_t)atoll(row->GetField(0)),"GL_RUN_FRAGMENTS");
2052            glrun->DeleteRun(conn,(UInt_t)atoll(row->GetField(0)),"GL_RUN");
2053          };
2054          //
2055        GL_RUN *glrun1 = new GL_RUN();        GL_RUN *glrun1 = new GL_RUN();
2056        //        //
2057        UInt_t idfrag = (UInt_t)atoll(row->GetField(0));        //      UInt_t idfrag = (UInt_t)atoll(row->GetField(0));
2058        //        //
2059        oss.str("");        oss.str("");
2060        oss << " ID="<<row->GetField(0)<<";";        oss << " ID="<<row->GetField(0)<<";";
# Line 2049  void PamelaDBOperations::HandleRunFragme Line 2110  void PamelaDBOperations::HandleRunFragme
2110        //        //
2111        if ( !IsRunAlreadyInserted() ){        if ( !IsRunAlreadyInserted() ){
2112          //          //
2113          glrun->SetID(this->AssignRunID());          //      glrun->SetID(this->AssignRunID());
2114          //          //
2115          glrun->SetID_RUN_FRAG(glrun1->GetID());          glrun->SetID_RUN_FRAG(glrun1->GetID());
2116          glrun->Fill_GL_RUN(conn);          glrun->Fill_GL_RUN(conn);
2117          //          //
2118          // get id number          // set id number
2119          //          //
 //      oss.str("");  
 //      oss << " SELECT ID FROM GL_RUN WHERE BOOT_NUMBER="<<this->GetBOOTnumber()<<" AND "  
 //          << " RUNHEADER_OBT="<<glrun->GetRUNHEADER_OBT()<<" AND "  
 //          << " RUNTRAILER_OBT="<<glrun->GetRUNTRAILER_OBT()<<";";  
 //      //  
 //      if ( IsDebug() ) printf(" search for idrun0 , query is : \n%s\n",oss.str().c_str());  
 //      //  
 //      result =  conn->Query(oss.str().c_str());  
 //      if ( !result ) throw -4;  
 //      row = result->Next();  
 //      //  
 //      UInt_t idrun0 = 0;  
 //      if ( !row ){  
 //        throw -10;  
 //      } else {  
 //        idrun0 = (UInt_t)atoll(row->GetField(0));  
 //      };  
 //      //  
 //      glrun1->SetID_RUN_FRAG(idrun0);  
 //  
2120          glrun1->SetID_RUN_FRAG(glrun->GetID());          glrun1->SetID_RUN_FRAG(glrun->GetID());
2121          glrun1->Fill_GL_RUN(conn);          glrun1->Fill_GL_RUN(conn);
2122          //          //
 //      oss.str("");  
 //      oss << " SELECT ID FROM GL_RUN WHERE ID_RUN_FRAG="<<idrun0<<" ;";  
 //      //  
 //      if ( IsDebug() ) printf(" search for idrun1 , query is : \n%s\n",oss.str().c_str());  
 //      //  
 //      result =  conn->Query(oss.str().c_str());  
 //      if ( !result ) throw -4;  
 //      row = result->Next();  
 //      //  
 //      UInt_t idrun1 = 0;  
 //      if ( !row ){  
 //        throw -10;  
 //      } else {  
 //        idrun1 = (UInt_t)atoll(row->GetField(0));  
 //      };  
 //      //  
 //      oss.str("");  
 //      oss << " UPDATE GL_RUN SET ID_RUN_FRAG="<<idrun1<<" WHERE ID="<<idrun0<<" ;";  
 //      //  
 //      result =  conn->Query(oss.str().c_str());  
 //      if ( !result ) throw -4;  
         //  
2123        };        };
2124        //        //
2125        delete glrun1;        // delete old entries in fragment table
2126        //        //
2127        // delete old entry in fragment table        glrun->DeleteRun(conn,0,"GL_RUN_FRAGMENTS");
2128        //        glrun1->DeleteRun(conn,0,"GL_RUN_FRAGMENTS");
       oss.str("");  
       //  
       oss << " DELETE FROM GL_RUN_FRAGMENTS WHERE ID = " << idfrag << ";";  
       //  
       if ( IsDebug() ) printf(" Delete from frag table the old run :\n query is \n %s \n",oss.str().c_str());  
       result =  conn->Query(oss.str().c_str());  
       if ( !result ) throw -4;  
2129        //        //
2130          delete glrun1;
2131        //        //
2132        return;        return;
2133        //        //
# Line 2151  void PamelaDBOperations::HandleRunFragme Line 2164  void PamelaDBOperations::HandleRunFragme
2164      //      //
2165      row = result->Next();      row = result->Next();
2166      //      //
2167      if ( !row ){      if ( row ){
       //  
       oss.str("");  
       oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE "  
           << " BOOT_NUMBER=" << this->GetBOOTnumber() << " AND ("  
           << " (RUNHEADER_TIME>=" << (UInt_t)(glrun->GetRUNHEADER_TIME()-10) << " AND "  
           << " RUNTRAILER_TIME<=" << (UInt_t)(glrun->GetRUNTRAILER_TIME()+10) << " AND ("  
           << " RUNHEADER_OBT>=" << glrun->GetRUNHEADER_OBT() << " OR "  
           << " RUNHEADER_PKT>=" << glrun->GetRUNHEADER_PKT() << ") AND ("  
           << " RUNTRAILER_OBT<=" << glrun->GetRUNTRAILER_OBT() << " OR "  
           << " RUNTRAILER_PKT<=" << glrun->GetRUNTRAILER_PKT() << ") ) OR "  
           << " (RUNHEADER_TIME<=" << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND "  
           << " RUNTRAILER_TIME>=" << (UInt_t)glrun->GetRUNTRAILER_TIME() <<" AND ("  
           << " RUNHEADER_OBT<=" << glrun->GetRUNHEADER_OBT() << " OR "  
           << " RUNHEADER_PKT<=" << glrun->GetRUNHEADER_PKT() << ") AND ("  
           << " RUNTRAILER_OBT>=" << glrun->GetRUNTRAILER_OBT() << " OR "  
           << " RUNTRAILER_PKT>=" << glrun->GetRUNTRAILER_PKT() << ") ));";  
       //  
       if ( IsDebug() ) printf(" check if run has been inserted: query is \n %s \n",oss.str().c_str());  
       result = conn->Query(oss.str().c_str());  
       //  
       if ( !result ) throw -4;  
       //  
       row = result->Next();  
       //  
       if ( !row ){  
         //  
         // no, insert this run in the GL_RUN_FRAGMENTS table (check if exist before!)  
         //  
         if ( IsDebug() ) printf(" The run is new \n");  
         if ( IsDebug() ) printf(" -> fill the GL_RUNFRAGMENTS table \n");  
         //  
         glrun->SetID(this->AssignRunID());  
         glrun->SetID_RUN_FRAG(0);  
         glrun->Fill_GL_RUN_FRAGMENTS(conn);  
         //  
       } else {  
         if ( IsDebug() ) printf(" The run is already present in the fragment table \n");  
       };  
     } else {  
2168        if ( IsDebug() ) printf(" The run is already present in the GL_RUN table \n");        if ( IsDebug() ) printf(" The run is already present in the GL_RUN table \n");
2169        } else {
2170          if ( NoFrag() ){
2171            glrun->SetID_RUN_FRAG(glrun->GetID());
2172            glrun->Fill_GL_RUN(conn);      
2173            glrun->DeleteRun(conn,0,"GL_RUN_FRAGMENTS");
2174          };    
2175      };      };
2176    };    };
2177    //    //
# Line 3326  Int_t PamelaDBOperations::insertS4_CALIB Line 3306  Int_t PamelaDBOperations::insertS4_CALIB
3306   * Scan the fragment table and move old fragments to the GL_RUN table   * Scan the fragment table and move old fragments to the GL_RUN table
3307   */   */
3308  Int_t PamelaDBOperations::CleanGL_RUN_FRAGMENTS(){  Int_t PamelaDBOperations::CleanGL_RUN_FRAGMENTS(){
3309      return(this->CleanGL_RUN_FRAGMENTS(""));
3310    };
3311    
3312    /**
3313     * Scan the fragment table and move old fragments to the GL_RUN table
3314     */
3315    Int_t PamelaDBOperations::CleanGL_RUN_FRAGMENTS(TString fcleanfile){
3316    //    //
3317    TSQLResult *result = 0;    TSQLResult *result = 0;
3318    TSQLRow    *row    = 0;    TSQLRow    *row    = 0;
# Line 3333  Int_t PamelaDBOperations::CleanGL_RUN_FR Line 3320  Int_t PamelaDBOperations::CleanGL_RUN_FR
3320    TSQLRow    *row2   = 0;    TSQLRow    *row2   = 0;
3321    //    //
3322    UInt_t moved = 0;    UInt_t moved = 0;
 //  UInt_t timelim = 0;  
 //  TDatime *time = new TDatime();  
3323    //    //
3324    stringstream oss;    stringstream oss;
3325    oss.str("");    oss.str("");
3326    //    //
3327    //    if ( !strcmp(fcleanfile.Data(),"") ){
3328    // check if there are entries older than "olderthan" seconds from now      //
3329    //      // check if there are entries older than "olderthan" seconds from now
3330    oss.str("");      //
3331    oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE"      oss.str("");
3332        << " INSERT_TIME <= '" << clean_time->AsSQLString() << "';";      oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE"
3333    //          << " INSERT_TIME <= '" << clean_time->AsSQLString() << "';";
3334    if ( IsDebug() ) printf(" Select from GL_RUN_FRAGMENTS runs older than %s : query is \n %s \n",clean_time->AsSQLString(),oss.str().c_str());      //
3335    result = conn->Query(oss.str().c_str());      if ( IsDebug() ) printf(" Select from GL_RUN_FRAGMENTS runs older than %s : query is \n %s \n",clean_time->AsSQLString(),oss.str().c_str());
3336        result = conn->Query(oss.str().c_str());
3337        //
3338      } else {
3339        oss.str("");
3340        oss << " SELECT ID FROM GL_ROOT WHERE NAME='" << fcleanfile.Data() << "';";
3341        if ( IsDebug() ) printf(" Getting ID_ROOT_L0 query %s \n",oss.str().c_str());
3342        result = conn->Query(oss.str().c_str());
3343        //    
3344        if ( result ){
3345          //
3346          row = result->Next();
3347          //
3348          if ( row ){
3349            oss.str("");
3350            oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE"
3351                << " ID_ROOT_L0=" << row->GetField(0) << ";";
3352            //
3353            if ( IsDebug() ) printf(" Select from GL_RUN_FRAGMENTS for ROOT file query is \n %s \n",oss.str().c_str());
3354            result = conn->Query(oss.str().c_str());
3355            //    
3356          };
3357        } else {
3358          return(2);
3359        };
3360      };
3361    //    //
3362    if ( result ){    if ( result ){
3363      //      //
# Line 3424  Int_t PamelaDBOperations::CleanGL_RUN_FR Line 3434  Int_t PamelaDBOperations::CleanGL_RUN_FR
3434        if ( IsDebug() ) printf(" Delete run %s from the GL_RUN_FRAGMENTS table \n",row->GetField(0));              if ( IsDebug() ) printf(" Delete run %s from the GL_RUN_FRAGMENTS table \n",row->GetField(0));      
3435        //        //
3436        //        //
3437        oss.str("");        glrun->DeleteRun(conn,(UInt_t)atoll(row->GetField(0)),"GL_RUN_FRAGMENTS");
3438        oss << " DELETE from GL_RUN_FRAGMENTS where ID = " << row->GetField(0);  //      oss.str("");
3439        if ( IsDebug() ) printf(" Clean the GL_RUN_FRAGMENTS table: query is \n %s \n",oss.str().c_str());  //       oss << " DELETE from GL_RUN_FRAGMENTS where ID = " << row->GetField(0);
3440        result2 = conn->Query(oss.str().c_str());  //       if ( IsDebug() ) printf(" Clean the GL_RUN_FRAGMENTS table: query is \n %s \n",oss.str().c_str());
3441        //  //       result2 = conn->Query(oss.str().c_str());
3442        if ( !result2 ) throw -4;  //      //
3443        //  //      if ( !result2 ) throw -4;
3444    //      //
3445        row = result->Next();        row = result->Next();
3446      };      };
3447    };    };
# Line 3442  Int_t PamelaDBOperations::CleanGL_RUN_FR Line 3453  Int_t PamelaDBOperations::CleanGL_RUN_FR
3453   * Check if runs are good, i.e. if the tracker calibration is correctly associated..   * Check if runs are good, i.e. if the tracker calibration is correctly associated..
3454   */   */
3455  Int_t PamelaDBOperations::ValidateRuns(){  Int_t PamelaDBOperations::ValidateRuns(){
3456      return(this->ValidateRuns(""));
3457    };
3458    
3459    /**
3460     * Check if runs are good, i.e. if the tracker calibration is correctly associated..
3461     */
3462    Int_t PamelaDBOperations::ValidateRuns(TString valfile){
3463    //    //
3464    TSQLResult *result = 0;    TSQLResult *result = 0;
3465    TSQLRow    *row    = 0;    TSQLRow    *row    = 0;
3466    //    //
3467      UInt_t calibtime = 50;
3468      //
3469    stringstream oss;    stringstream oss;
3470    oss.str("");    oss.str("");
3471    //    //
# Line 3454  Int_t PamelaDBOperations::ValidateRuns() Line 3474  Int_t PamelaDBOperations::ValidateRuns()
3474    // =======================================================    // =======================================================
3475    UInt_t t_stop  = 0;    UInt_t t_stop  = 0;
3476    UInt_t t_start = 0;    UInt_t t_start = 0;
3477    // --------------------------------------------------------------    if ( !strcmp(valfile.Data(),"") ) {
3478    // 1) get the OBT of the last run inserted after clean-time limit      // --------------------------------------------------------------
3479    // --------------------------------------------------------------      // 1) get the OBT of the last run inserted after clean-time limit
3480    oss.str("");      // --------------------------------------------------------------
3481    oss << " SELECT * FROM GL_RUN  WHERE INSERT_TIME <= '" << clean_time->AsSQLString()      oss.str("");
3482            << "' ORDER BY RUNHEADER_TIME DESC LIMIT 1;";      oss << " SELECT * FROM GL_RUN  WHERE INSERT_TIME <= '" << clean_time->AsSQLString()
3483    if ( IsDebug() ) printf(" Get start validation-time: query is \n %s \n",oss.str().c_str());          << "' ORDER BY RUNHEADER_TIME DESC LIMIT 1;";
3484    result = conn->Query(oss.str().c_str());      if ( IsDebug() ) printf(" Get start validation-time: query is \n %s \n",oss.str().c_str());
3485    if ( !result ) throw -4;      result = conn->Query(oss.str().c_str());
3486    if ( !result->GetRowCount() ) {      if ( !result ) throw -4;
3487            printf(" No runs to validate \n");      if ( !result->GetRowCount() ) {
3488            return(1);        printf(" No runs to validate \n");
3489    }else{        return(1);
3490          row = result->Next();      }else{
3491          t_start = (UInt_t)atoll(row->GetField(4));        row = result->Next();
3492    };          t_start = (UInt_t)atoll(row->GetField(4));
3493    // --------------------------------------------------------------      };  
3494    // 2) get the OBT of the last validated run      // --------------------------------------------------------------
3495    // --------------------------------------------------------------      // 2) get the OBT of the last validated run
3496    oss.str("");      // --------------------------------------------------------------
3497    oss << " SELECT * FROM GL_RUN  WHERE VALIDATION=1 AND RUNHEADER_TIME<="<< t_start      oss.str("");
3498        <<" ORDER BY RUNHEADER_TIME DESC LIMIT 1;";      oss << " SELECT * FROM GL_RUN  WHERE VALIDATION=1 AND RUNHEADER_TIME<="<< t_start
3499    if ( IsDebug() ) printf(" Get stop validation-time: query is \n %s \n",oss.str().c_str());          <<" ORDER BY RUNHEADER_TIME DESC LIMIT 1;";
3500    result = conn->Query(oss.str().c_str());      if ( IsDebug() ) printf(" Get stop validation-time: query is \n %s \n",oss.str().c_str());
3501    if ( !result ) throw -4;      result = conn->Query(oss.str().c_str());
3502    if ( result->GetRowCount() ){      if ( !result ) throw -4;
3503            row = result->Next();      if ( result->GetRowCount() ){
3504            t_stop = (UInt_t)atoll(row->GetField(4));        row = result->Next();
3505          t_stop = (UInt_t)atoll(row->GetField(4));
3506        };
3507        if ( IsDebug() ) printf("Validation interval: from time %i - to time %i \n\n",t_stop,t_start);
3508        // --------------------------------------------------------------
3509        // now retrieves runs to be validated
3510        // --------------------------------------------------------------
3511        oss.str("");
3512        oss << " SELECT * FROM GL_RUN  WHERE  RUNHEADER_TIME <=" << t_start;
3513        oss << " AND RUNHEADER_TIME >="<< t_stop;
3514        oss << " ORDER BY RUNHEADER_TIME DESC;";
3515        if ( IsDebug() )printf(" Check runs for validation: query is \n %s \n",oss.str().c_str());
3516        result = conn->Query(oss.str().c_str());
3517      } else {
3518        //
3519        stringstream myquery;
3520        UInt_t myid = 0;
3521        myquery.str("");
3522        myquery << " SELECT ID FROM GL_ROOT where NAME='"<<valfile.Data() <<"';";
3523        //
3524        result = conn->Query(myquery.str().c_str());
3525        //
3526        row = result->Next();      
3527        if( !row ){
3528          if ( strcmp(valfile.Data(),GetRootName().Data()) ){
3529            if ( IsDebug() ) printf(" No file to be validated even if option \"-validate file\" was used!!\n");
3530            return(2);
3531          };
3532          if ( IsDebug() ) printf(" No file to be validated (force mode)! \n");
3533          return(0);
3534        };
3535        myid=(UInt_t)atoll(row->GetField(0));
3536        //
3537        myquery.str("");
3538        myquery << " SELECT MAX(RUNTRAILER_TIME),MIN(RUNHEADER_TIME) FROM GL_RUN WHERE ID_ROOT_L0="<< myid <<";";
3539        //
3540        result = conn->Query(myquery.str().c_str());
3541        //
3542        row = result->Next();      
3543        if( !row->GetField(0) || !row->GetField(1)){
3544          //
3545          if ( IsDebug() ) printf(" NO RUN ASSOCIATED TO THIS FILE! \n");
3546          //
3547          return(0);
3548          //
3549        } else {  
3550          //
3551          UInt_t runhtime = (UInt_t)atoll(row->GetField(0));
3552          UInt_t runttime = (UInt_t)atoll(row->GetField(1));
3553          UInt_t caltime = 0;
3554          //
3555          myquery.str("");
3556          myquery << " SELECT FROM_TIME FROM GL_TRK_CALIB where FROM_TIME>" <<runhtime;
3557          myquery << " order by FROM_TIME asc limit 1;";
3558          //
3559          if ( IsDebug() ) printf("  query is \n %s \n",myquery.str().c_str());
3560          //
3561          //
3562          result = conn->Query(myquery.str().c_str());
3563          //
3564          row = result->Next();      
3565          if( !row ){
3566            caltime = runhtime;
3567          } else {
3568            caltime = (UInt_t)atoll(row->GetField(0));
3569          };
3570          //
3571          myquery.str("");
3572          myquery << " SELECT * from GL_RUN where RUNHEADER_TIME>="<< runttime <<" AND RUNHEADER_TIME<=" ;
3573          myquery << caltime << " order by RUNHEADER_TIME DESC";
3574          //
3575          if ( IsDebug() ) printf("  query is \n %s \n",myquery.str().c_str());
3576          //
3577          result = conn->Query(myquery.str().c_str());
3578          //
3579        };
3580    };    };
3581    if ( IsDebug() ) printf("Validation interval: from time %i - to time %i \n\n",t_stop,t_start);    //
   // --------------------------------------------------------------  
   // now retrieves runs to be validated  
   // --------------------------------------------------------------  
   oss.str("");  
   oss << " SELECT * FROM GL_RUN  WHERE  RUNHEADER_TIME <=" << t_start;  
   oss << " AND RUNHEADER_TIME >="<< t_stop;  
   oss << " ORDER BY RUNHEADER_TIME DESC;";  
 //  if ( IsDebug() )  
   if ( IsDebug() )printf(" Check runs for validation: query is \n %s \n",oss.str().c_str());  
   result = conn->Query(oss.str().c_str());  
3582    if ( !result ) throw -4;    if ( !result ) throw -4;
3583    if ( !result->GetRowCount() ) printf(" No runs to validate \n");    if ( !result->GetRowCount() && IsDebug() ) printf(" No runs to validate \n");
3584  //  printf("------------------------------------------------------------------------------- \n");    //
     
3585    Int_t nrow = 0;    Int_t nrow = 0;
3586    GL_RUN* this_run = new GL_RUN();    GL_RUN* this_run = new GL_RUN();
3587    GL_RUN* next_run = new GL_RUN();    GL_RUN* next_run = new GL_RUN();
# Line 3511  Int_t PamelaDBOperations::ValidateRuns() Line 3595  Int_t PamelaDBOperations::ValidateRuns()
3595    UInt_t t1=0,t2=0;    UInt_t t1=0,t2=0;
3596    // ---------------------------------------------------------------------------------    // ---------------------------------------------------------------------------------
3597    // - loop over runs, back in time,    // - loop over runs, back in time,
3598    // - select sequences of runs close in time (less than 60 s apart),    // - select sequences of runs close in time (less than calibtime s apart),
3599    //   which could be preceeded by a calibration    //   which could be preceeded by a calibration
3600    // - check if there might be a missing calibration    // - check if there might be a missing calibration
3601    // ---------------------------------------------------------------------------------    // ---------------------------------------------------------------------------------
# Line 3551  Int_t PamelaDBOperations::ValidateRuns() Line 3635  Int_t PamelaDBOperations::ValidateRuns()
3635                                                        
3636                            if( this_run->ID == next_run->ID_RUN_FRAG ) interval = 0;     //=> run fragments                            if( this_run->ID == next_run->ID_RUN_FRAG ) interval = 0;     //=> run fragments
3637                                                        
3638                            if( interval >= 60 )CHECK = true;                     //more than 60 s => there might be a calibration                            if( interval >= calibtime )CHECK = true;                      //more than calibtime s => there might be a calibration
3639                                                        
3640                            if( !CHECK && this_run->VALIDATION ){                            if( !CHECK && this_run->VALIDATION ){
3641                                    for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],true);                                    for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],true);
# Line 3749  Int_t PamelaDBOperations::populateTLE()/ Line 3833  Int_t PamelaDBOperations::populateTLE()/
3833    
3834    
3835  // Insert tle in the table GL_TLE using the connection conn.  // Insert tle in the table GL_TLE using the connection conn.
3836  int PamelaDBOperations::insertTle(cTle *tle)  Int_t PamelaDBOperations::insertTle(cTle *tle)
3837  {  {
3838    stringstream oss;    stringstream oss;
3839    TSQLResult *result = 0;    TSQLResult *result = 0;
# Line 3832  string getTleDatetime(cTle *tle) Line 3916  string getTleDatetime(cTle *tle)
3916    
3917    return date.str();    return date.str();
3918  }  }
3919    
3920    /**
3921     * Remove a file from the DB, delete on cascade all entries related to that file
3922     * rearrange GL_RUN and GL_XXX_CALIB tables, turn off validation till the following
3923     * calibration
3924     **/
3925    Int_t PamelaDBOperations::removeFile(TString remfile){
3926      //
3927      // Determine ID_ROOT_L0 and ID_RAW
3928      //
3929      TSQLResult *pResult;
3930      TSQLRow *Row;
3931      stringstream myquery;
3932      //  
3933      myquery.str("");
3934      myquery << " SELECT ID, ID_RAW FROM GL_ROOT where NAME='"<<remfile.Data() <<"';";
3935      //
3936      pResult = conn->Query(myquery.str().c_str());
3937      //
3938      Row = pResult->Next();      
3939      if( !Row ){
3940        if ( strcmp(remfile.Data(),GetRootName().Data()) ){
3941          if ( IsDebug() ) printf(" No file to be removed even if option \"-remove file\" was used!!\n");
3942          return(1);
3943        };
3944        if ( IsDebug() ) printf(" No file to be removed (force mode)! \n");
3945        return(0);
3946      };
3947      //
3948      this->SetID_ROOT((UInt_t)atoll(Row->GetField(0)));
3949      this->SetID_RAW((UInt_t)atoll(Row->GetField(1)));
3950      //
3951      this->ValidationOFF();
3952      //
3953      this->RemoveCALIBS();
3954      //
3955      this->RemoveRUNS();
3956      //
3957      this->RemoveFILES();
3958      //
3959      this->SetID_ROOT(0);
3960      this->SetID_RAW(0);
3961      //
3962      return(0);
3963    };
3964    
3965    /**
3966     *
3967     * Set validation bit to zero for runs following the removing file till
3968     * 1) a run with TRK_CALIB_USED=140
3969     * 2) a run with VALIDATION = 0
3970     * 3) the next calibration
3971     *
3972     **/
3973    void PamelaDBOperations::ValidationOFF(){
3974      TSQLResult *pResult;
3975      TSQLRow *Row;
3976      stringstream myquery;
3977      Int_t unv = 0;
3978      //select ID from GL_RUN where RUNHEADER_TIME>=1152671382 AND (VALIDATION=0 OR TRK_CALIB_USED=104) order by RUNHEADER_TIME asc limit 1;
3979      myquery.str("");
3980      myquery << " SELECT MAX(RUNTRAILER_TIME) FROM GL_RUN WHERE ID_ROOT_L0="<< this->GetID_ROOT() <<";";
3981      //
3982      pResult = conn->Query(myquery.str().c_str());
3983      //
3984      Row = pResult->Next();      
3985      if( !Row->GetField(0) ){
3986        //
3987        if ( IsDebug() ) printf(" NO RUN ASSOCIATED TO THIS FILE! \n");
3988        //
3989      } else {  
3990        //
3991        UInt_t runhtime = (UInt_t)atoll(Row->GetField(0));
3992        UInt_t caltime = 0;
3993        //
3994        myquery.str("");
3995        myquery << " SELECT FROM_TIME FROM GL_TRK_CALIB where FROM_TIME>" <<runhtime;
3996        myquery << " order by FROM_TIME asc limit 1;";
3997        //
3998        if ( IsDebug() ) printf("  query is \n %s \n",myquery.str().c_str());
3999        //
4000        //
4001        delete pResult;
4002        pResult = conn->Query(myquery.str().c_str());
4003        //
4004        Row = pResult->Next();      
4005        if( !Row ){
4006          caltime = runhtime;
4007        } else {
4008          caltime = (UInt_t)atoll(Row->GetField(0));
4009        };
4010        //
4011        myquery.str("");
4012        myquery << " SELECT ID,RUNHEADER_TIME from GL_RUN where RUNHEADER_TIME>="<< runhtime <<" AND (VALIDATION=0 OR TRK_CALIB_USED=104 OR RUNHEADER_TIME>" ;
4013        myquery << caltime << ") order by RUNHEADER_TIME asc LIMIT 1";
4014        //
4015        if ( IsDebug() ) printf("  query is \n %s \n",myquery.str().c_str());
4016        //
4017        pResult = conn->Query(myquery.str().c_str());
4018        //
4019        Row = pResult->Next();      
4020        if( !Row ){
4021          //
4022          if ( IsDebug() ) printf(" NO RUN NEED TO BE UNVALIDATED \n");
4023          //
4024        } else {
4025          myquery.str("");
4026          myquery << " SELECT ID from GL_RUN where RUNHEADER_TIME<"<< Row->GetField(1) <<" AND ";
4027          myquery << " RUNHEADER_TIME>=" <<runhtime;
4028          myquery << " order by RUNHEADER_TIME asc;";
4029          //
4030          if ( IsDebug() ) printf("  query is \n %s \n",myquery.str().c_str());
4031          //
4032          pResult = conn->Query(myquery.str().c_str());
4033          //
4034          Row = pResult->Next();  
4035          while ( Row ){
4036            //      
4037            unv++;
4038            this->assignVALIDATION((UInt_t)atoll(Row->GetField(0)), false);
4039            Row = pResult->Next();  
4040            //
4041          };
4042        };
4043      };
4044      if ( IsDebug() ) printf(" %i runs have been unvalidated \n",unv);
4045    };
4046    
4047    /**
4048     *
4049     * Rearrange GL_RUN table and remove runs
4050     *
4051     **/
4052    void PamelaDBOperations::RemoveRUNS(){
4053      TSQLResult *pResult;
4054      TSQLRow *Row;
4055      stringstream myquery;
4056      UInt_t drun = 0;
4057      GL_RUN *delrun = new GL_RUN();
4058      //
4059      myquery.str("");
4060      myquery << " SELECT ID FROM GL_RUN where ID_RUN_FRAG=0 and ID_ROOT_L0=" <<this->GetID_ROOT() <<";";
4061      //
4062      if ( IsDebug() ) printf("  query is \n %s \n",myquery.str().c_str());
4063      //
4064      pResult = conn->Query(myquery.str().c_str());
4065      //
4066      Row = pResult->Next();    
4067      //
4068      //
4069      if ( !Row ){
4070        if ( IsDebug() ) printf(" No run with ID_RUN_FRAG=0 belonged to this file \n");
4071      } else {
4072        if ( IsDebug() ) printf(" Deleting run from GL_RUN table \n");    
4073        while ( Row ){
4074          delrun->DeleteRun(conn,(UInt_t)atoll(Row->GetField(0)),"GL_RUN");
4075          if ( IsDebug() ) printf(" del run %i \n",(UInt_t)atoll(Row->GetField(0)));
4076          drun++;
4077          Row = pResult->Next();    
4078        };
4079      };
4080      //
4081      //
4082      myquery.str("");
4083      myquery << " SELECT ID,ID_RUN_FRAG FROM GL_RUN where ID_RUN_FRAG!=0 and ID_ROOT_L0=" <<this->GetID_ROOT() <<";";
4084      //
4085      if ( IsDebug() ) printf("  query is \n %s \n",myquery.str().c_str());
4086      //
4087      pResult = conn->Query(myquery.str().c_str());
4088      //
4089      Row = pResult->Next();    
4090      //
4091      if ( !Row ){
4092        if ( IsDebug() ) printf(" No run with ID_RUN_FRAG!=0 belonged to this file \n");
4093      } else {
4094        if ( IsDebug() ) printf(" Deleting run fragments from GL_RUN table \n");    
4095        while ( Row ){
4096          if ( IsDebug() ) printf(" restore run %i \n",(UInt_t)atoll(Row->GetField(1)));
4097          delrun->RestoreRun(conn,(UInt_t)atoll(Row->GetField(1)),"GL_RUN_FRAGMENTS");
4098          if ( IsDebug() ) printf(" del run %i \n",(UInt_t)atoll(Row->GetField(1)));
4099          delrun->DeleteRun(conn,(UInt_t)atoll(Row->GetField(1)),"GL_RUN");
4100          if ( (UInt_t)atoll(Row->GetField(1)) != (UInt_t)atoll(Row->GetField(0)) ){
4101            if ( IsDebug() ) printf(" del run %i \n",(UInt_t)atoll(Row->GetField(0)));
4102            delrun->DeleteRun(conn,(UInt_t)atoll(Row->GetField(0)),"GL_RUN");
4103          };
4104          drun++;
4105          Row = pResult->Next();    
4106        };
4107      };
4108      //
4109      if ( IsDebug() ) printf(" Deleted %i run(s) from GL_RUN table \n",drun);    
4110      //
4111      //
4112      //
4113      drun = 0;
4114      //
4115      myquery.str("");
4116      myquery << " SELECT ID_TRASH FROM GL_RUN_TRASH where BELONGED_TO='GL_RUN_FRAGMENTS' AND ID_ROOT_L0=" <<this->GetID_ROOT() <<";";
4117      //
4118      pResult = conn->Query(myquery.str().c_str());
4119      //
4120      Row = pResult->Next();    
4121      //
4122      if ( !Row ){
4123        if ( IsDebug() ) printf(" No run from GL_RUN_FRAGMENTS table in the trash table for this file \n");
4124      } else {
4125        if ( IsDebug() ) printf(" Deleting run fragments from GL_RUN_TRASH table \n");    
4126        while ( Row ){
4127          if ( IsDebug() ) printf(" del run idtrash %i \n",(UInt_t)atoll(Row->GetField(0)));
4128          myquery.str("");
4129          myquery << " DELETE FROM GL_RUN_TRASH where ID_TRASH=" << Row->GetField(0) <<";";      
4130          conn->Query(myquery.str().c_str());
4131          drun++;
4132          Row = pResult->Next();    
4133        };
4134      };
4135      //  
4136      if ( IsDebug() ) printf(" Deleted %i run(s) from GL_RUN_TRASH table \n",drun);    
4137      //
4138      //
4139      //
4140      drun = 0;
4141      //
4142      myquery.str("");
4143      myquery << " SELECT ID FROM GL_RUN_FRAGMENTS where ID_ROOT_L0=" <<this->GetID_ROOT() <<";";
4144      //
4145      pResult = conn->Query(myquery.str().c_str());
4146      //
4147      Row = pResult->Next();    
4148      //
4149      if ( !Row ){
4150        if ( IsDebug() ) printf(" No run in the GL_RUN_FRAGMENTS table for this file \n");
4151      } else {
4152        if ( IsDebug() ) printf(" Deleting run fragments from GL_RUN_FRAGMENTS table \n");    
4153        while ( Row ){
4154          if ( IsDebug() ) printf(" del run %i \n",(UInt_t)atoll(Row->GetField(0)));
4155          myquery.str("");
4156          myquery << " DELETE FROM GL_RUN_FRAGMENTS where ID=" << Row->GetField(0) <<";";
4157          conn->Query(myquery.str().c_str());
4158          drun++;
4159          Row = pResult->Next();    
4160        };
4161      };
4162      //  
4163      if ( IsDebug() ) printf(" Deleted %i run(s) from GL_RUN_FRAGMENTS table \n",drun);    
4164      //
4165      //
4166      //
4167      delete delrun;
4168      //
4169    };
4170    
4171    
4172    /**
4173     *
4174     * Rearrange calibration tables
4175     *
4176     **/
4177    void PamelaDBOperations::RemoveFILES(){
4178      stringstream myquery;
4179      //
4180      myquery.str("");
4181      myquery << " DELETE FROM GL_RAW WHERE ID=" <<this->GetID_RAW() <<";";
4182      //
4183      if ( IsDebug() ) printf("  query is \n %s \n",myquery.str().c_str());
4184      //
4185      conn->Query(myquery.str().c_str());
4186      //
4187    };
4188    
4189    /**
4190     *
4191     * Rearrange calibration tables
4192     *
4193     **/
4194    void PamelaDBOperations::RemoveCALIBS(){
4195      TSQLResult *pResult;
4196      TSQLRow *Row;
4197      stringstream myquery;
4198      //  
4199      //
4200      // Calorimeter
4201      //
4202      for (Int_t section = 0; section < 4; section++){
4203        myquery.str("");
4204        myquery << " SELECT MIN(FROM_TIME),MAX(TO_TIME) FROM GL_CALO_CALIB WHERE ID_ROOT_L0="<< this->GetID_ROOT() <<" AND ";
4205        myquery << " SECTION=" << section << ";";
4206        //
4207        pResult = conn->Query(myquery.str().c_str());
4208        //
4209        Row = pResult->Next();      
4210        if( !Row->GetField(0) || !Row->GetField(1) ){
4211          //
4212          if ( IsDebug() ) printf(" NO CALO CALIBRATION SECTION %i ASSOCIATED TO THIS FILE! \n",section);
4213          //
4214        } else {
4215          //
4216          myquery.str("");
4217          myquery << " UPDATE GL_CALO_CALIB SET TO_TIME=" << Row->GetField(1);
4218          myquery << " WHERE TO_TIME="<< Row->GetField(0) << " AND ";
4219          myquery << " SECTION=" << section << ";";
4220          //
4221          pResult = conn->Query(myquery.str().c_str());
4222          //
4223          if( !pResult ){
4224            //
4225            if ( IsDebug() ) printf(" ERROR DELETING CALO CALIBRATIONS \n");
4226            //
4227            throw -4;
4228            //
4229          };
4230          //
4231        };
4232      };
4233      myquery.str("");
4234      myquery << " DELETE FROM GL_CALO_CALIB WHERE ID_ROOT_L0=" << this->GetID_ROOT();
4235      //
4236      pResult = conn->Query(myquery.str().c_str());
4237      //
4238      if( !pResult ){
4239        //
4240        if ( IsDebug() ) printf(" ERROR DELETING CALO CALIBRATIONS \n");
4241        //
4242        throw -4;
4243        //
4244      };
4245      //
4246      // Tracker
4247      //
4248      myquery.str("");
4249      myquery << " SELECT MIN(FROM_TIME),MAX(TO_TIME) FROM GL_TRK_CALIB WHERE ID_ROOT_L0="<< this->GetID_ROOT() <<";";
4250      //
4251      pResult = conn->Query(myquery.str().c_str());
4252      //
4253      Row = pResult->Next();      
4254      if( !Row->GetField(0) || !Row->GetField(1) ){
4255        //
4256        if ( IsDebug() ) printf(" NO TRK CALIBRATION ASSOCIATED TO THIS FILE! \n");
4257        //
4258      } else {
4259        //
4260        myquery.str("");
4261        myquery << " UPDATE GL_TRK_CALIB SET TO_TIME=" << Row->GetField(1);
4262        myquery << " WHERE TO_TIME="<< Row->GetField(0) << ";";
4263        //
4264        pResult = conn->Query(myquery.str().c_str());
4265        //
4266        if( !pResult ){
4267          //
4268          if ( IsDebug() ) printf(" ERROR DELETING TRK CALIBRATIONS \n");
4269          //
4270          throw -4;
4271          //
4272        };
4273        //
4274        myquery.str("");
4275        myquery << " DELETE FROM GL_TRK_CALIB WHERE ID_ROOT_L0=" << this->GetID_ROOT();
4276        //
4277        pResult = conn->Query(myquery.str().c_str());
4278        //
4279        if( !pResult ){
4280          //
4281          if ( IsDebug() ) printf(" ERROR DELETING TRK CALIBRATIONS \n");
4282          //
4283          throw -4;
4284          //
4285        };
4286      };
4287      //
4288      //
4289      // S4
4290      //
4291      myquery.str("");
4292      myquery << " SELECT MIN(FROM_TIME),MAX(TO_TIME) FROM GL_S4_CALIB WHERE ID_ROOT_L0="<< this->GetID_ROOT() <<";";
4293      //
4294      pResult = conn->Query(myquery.str().c_str());
4295      //
4296      Row = pResult->Next();      
4297      if( !Row->GetField(0) || !Row->GetField(1) ){
4298        //
4299        if ( IsDebug() ) printf(" NO S4 CALIBRATION ASSOCIATED TO THIS FILE! \n");
4300        //
4301      } else {
4302        //
4303        myquery.str("");
4304        myquery << " UPDATE GL_S4_CALIB SET TO_TIME=" << Row->GetField(1);
4305        myquery << " WHERE TO_TIME="<< Row->GetField(0) << ";";
4306        //
4307        pResult = conn->Query(myquery.str().c_str());
4308        //
4309        if( !pResult ){
4310          //
4311          if ( IsDebug() ) printf(" ERROR DELETING S4 CALIBRATIONS \n");
4312          //
4313          throw -4;
4314          //
4315        };
4316        //
4317        myquery.str("");
4318        myquery << " DELETE FROM GL_S4_CALIB WHERE ID_ROOT_L0=" << this->GetID_ROOT();
4319        //
4320        pResult = conn->Query(myquery.str().c_str());
4321        //
4322        if( !pResult ){
4323          //
4324          if ( IsDebug() ) printf(" ERROR DELETING S4 CALIBRATIONS \n");
4325          //
4326          throw -4;
4327          //
4328        };
4329        //
4330      };
4331    };

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.16

  ViewVC Help
Powered by ViewVC 1.1.23