--- YodaProfiler/src/GLTables.cpp 2006/10/24 14:24:22 1.14 +++ YodaProfiler/src/GLTables.cpp 2006/10/31 15:36:04 1.15 @@ -374,8 +374,8 @@ } /** - * - * + * This method delete the run from the "FromTable" table and store it in the GL_RUN_TRASH table + * If IDRUN is 0 "this->ID" run is used. * **/ Int_t GL_RUN::DeleteRun(TSQLServer *dbc,UInt_t IDRUN,TString FromTable){ @@ -429,11 +429,28 @@ // dbc->Query(myquery.str().c_str()); // + // retrieve this ID_TRASH + // + myquery.str(""); + myquery << " SELECT ID_TRASH,ID_ROOT_L0,ID_ROOT_L2 FROM GL_RUN_TRASH ORDER BY ID_TRASH DESC LIMIT 1"; + pResult = dbc->Query(myquery.str().c_str()); + // + UInt_t idtrash = 0; + UInt_t idl0 = 0; + UInt_t idl2 = 0; + // + Row = pResult->Next(); + if( Row != NULL ){ + idtrash = (UInt_t)atoll(Row->GetField(0)); + idl0 = (UInt_t)atoll(Row->GetField(1)); + idl2 = (UInt_t)atoll(Row->GetField(2)); + }; + // TString fileL0 = ""; TString fileL2 = ""; myquery.str(""); myquery << " SELECT NAME FROM GL_ROOT WHERE ID="; - myquery << (UInt_t)ID_ROOT_L0 << ";"; + myquery << idl0 << ";"; // // printf("2myquery is %s \n",myquery.str().c_str()); // @@ -448,7 +465,7 @@ // myquery.str(""); myquery << " SELECT NAME FROM GL_ROOT WHERE ID="; - myquery << (UInt_t)ID_ROOT_L2 << ";"; + myquery << idl2 << ";"; // // printf("3myquery is %s \n",myquery.str().c_str()); // @@ -463,8 +480,8 @@ // myquery.str(""); myquery << " UPDATE GL_RUN_TRASH SET FILENAMEL0='"; - myquery << fileL0.Data() << "' where ID="; - myquery << IDRUN << ";"; + myquery << fileL0.Data() << "' where ID_TRASH="; + myquery << idtrash << ";"; // // printf("4myquery is %s \n",myquery.str().c_str()); // @@ -472,8 +489,8 @@ // myquery.str(""); myquery << " UPDATE GL_RUN_TRASH SET FILENAMEL2='"; - myquery << fileL2.Data() << "' where ID="; - myquery << IDRUN << ";"; + myquery << fileL2.Data() << "' where ID_TRASH="; + myquery << idtrash << ";"; // // printf("4myquery is %s \n",myquery.str().c_str()); // @@ -481,8 +498,8 @@ // myquery.str(""); myquery << " UPDATE GL_RUN_TRASH SET BELONGED_TO='"; - myquery << FromTable.Data() << "' where ID="; - myquery << IDRUN << ";"; + myquery << FromTable.Data() << "' where ID_TRASH="; + myquery << idtrash << ";"; // // printf("4myquery is %s \n",myquery.str().c_str()); // @@ -505,13 +522,121 @@ /** - * - * + * This method restore a run from the GL_RUN_TRASH table. + * If ID is 0 "this->ID" is used; if "ToTable" is empty BELONG_TO field of GL_RUN_TRASH is used. * **/ -Int_t GL_RUN::RestoreRun(TSQLServer *dbc,UInt_t ID,TString FromTable){ +Int_t GL_RUN::RestoreRun(TSQLServer *dbc,UInt_t IDRUN,TString ToTable){ // insert into GL_RUN_FRAGMENTS select * FROM GL_RUN where ID=11; //insert into GL_RUN_TRASH VALUES (ID , ID_RUN_FRAG , ID_ROOT_L0 , ID_ROOT_L2 , RUNHEADER_TIME , RUNTRAILER_TIME , RUNHEADER_OBT , RUNTRAILER_OBT , RUNHEADER_PKT , RUNTRAILER_PKT , BOOT_NUMBER , EV_FROM , EV_TO , NEVENTS , PKT_COUNTER , PKT_READY_COUNTER , COMPILATIONTIMESTAMP , FAV_WRK_SCHEDULE , EFF_WRK_SCHEDULE , PRH_VAR_TRG_MODE_A , PRH_VAR_TRG_MODE_B , ACQ_BUILD_INFO , ACQ_VAR_INFO , RM_ACQ_AFTER_CALIB , RM_ACQ_SETTING_MODE, TRK_CALIB_USED,CAL_DSP_MASK, LAST_TIMESYNC, OBT_TIMESYNC, VALIDATION, INSERT_TIME) select * FROM GL_RUN where ID=11; + // MySQL variables + TSQLResult *pResult; + TSQLRow *Row; + stringstream myquery; + // + if ( !IDRUN ) IDRUN = ID; + if ( !IDRUN ) return 1; + // + if ( !strcmp(ToTable.Data(),"") ){ + // + myquery.str(""); + myquery << " SELECT BELONGED_TO FROM GL_RUN_TRASH WHERE ID="; + myquery << (UInt_t)IDRUN << ";"; + // + printf(" qui? myquery is %s \n",myquery.str().c_str()); + // + pResult = dbc->Query(myquery.str().c_str()); + // + Row = pResult->Next(); + if( Row != NULL ){ + ToTable = (TString)Row->GetField(0); + } else { + return 1; + }; + }; + // ---------------- + myquery.str(""); + myquery << " INSERT INTO "; + myquery << ToTable.Data(); + myquery << " ("; + myquery << "ID"; + myquery << ",ID_RUN_FRAG"; + myquery << ",ID_ROOT_L0"; + myquery << ",ID_ROOT_L2"; + myquery << ",RUNHEADER_TIME"; + myquery << ",RUNTRAILER_TIME"; + myquery << ",RUNHEADER_OBT"; + myquery << ",RUNTRAILER_OBT"; + myquery << ",RUNHEADER_PKT"; + myquery << ",RUNTRAILER_PKT"; + myquery << ",BOOT_NUMBER"; + myquery << ",EV_FROM"; + myquery << ",EV_TO"; + myquery << ",NEVENTS"; + myquery << ",PKT_COUNTER"; + myquery << ",PKT_READY_COUNTER"; + myquery << ",COMPILATIONTIMESTAMP"; + myquery << ",FAV_WRK_SCHEDULE"; + myquery << ",EFF_WRK_SCHEDULE"; + myquery << ",PRH_VAR_TRG_MODE_A"; + myquery << ",PRH_VAR_TRG_MODE_B"; + myquery << ",ACQ_BUILD_INFO"; + myquery << ",ACQ_VAR_INFO"; + myquery << ",RM_ACQ_AFTER_CALIB"; + myquery << ",RM_ACQ_SETTING_MODE"; + myquery << ",TRK_CALIB_USED"; + myquery << ",CAL_DSP_MASK"; + myquery << ",LAST_TIMESYNC"; + myquery << ",OBT_TIMESYNC"; + myquery << ",VALIDATION"; + myquery << ",INSERT_TIME"; + myquery << ") SELECT "; + myquery << "ID"; + myquery << ",ID_RUN_FRAG"; + myquery << ",ID_ROOT_L0"; + myquery << ",ID_ROOT_L2"; + myquery << ",RUNHEADER_TIME"; + myquery << ",RUNTRAILER_TIME"; + myquery << ",RUNHEADER_OBT"; + myquery << ",RUNTRAILER_OBT"; + myquery << ",RUNHEADER_PKT"; + myquery << ",RUNTRAILER_PKT"; + myquery << ",BOOT_NUMBER"; + myquery << ",EV_FROM"; + myquery << ",EV_TO"; + myquery << ",NEVENTS"; + myquery << ",PKT_COUNTER"; + myquery << ",PKT_READY_COUNTER"; + myquery << ",COMPILATIONTIMESTAMP"; + myquery << ",FAV_WRK_SCHEDULE"; + myquery << ",EFF_WRK_SCHEDULE"; + myquery << ",PRH_VAR_TRG_MODE_A"; + myquery << ",PRH_VAR_TRG_MODE_B"; + myquery << ",ACQ_BUILD_INFO"; + myquery << ",ACQ_VAR_INFO"; + myquery << ",RM_ACQ_AFTER_CALIB"; + myquery << ",RM_ACQ_SETTING_MODE"; + myquery << ",TRK_CALIB_USED"; + myquery << ",CAL_DSP_MASK"; + myquery << ",LAST_TIMESYNC"; + myquery << ",OBT_TIMESYNC"; + myquery << ",VALIDATION"; + myquery << ",INSERT_TIME"; + myquery << " FROM GL_RUN_TRASH "; + myquery << " WHERE BELONGED_TO='GL_RUN_FRAGMENTS' AND ID="; + myquery << (UInt_t)IDRUN << ";"; + // + // printf("5myquery is %s \n",myquery.str().c_str()); + // + dbc->Query(myquery.str().c_str()); + // + // + myquery.str(""); + myquery << " DELETE FROM GL_RUN_TRASH where BELONGED_TO='GL_RUN_FRAGMENTS' AND ID="; + myquery << IDRUN << ";"; + // + dbc->Query(myquery.str().c_str()); + // return 0; };