--- chewbacca/YodaProfiler/src/PamelaDBOperations.cpp 2008/10/31 11:21:44 1.4 +++ chewbacca/YodaProfiler/src/PamelaDBOperations.cpp 2008/11/04 09:44:49 1.5 @@ -58,7 +58,7 @@ * @param debug debug flag. * @param tlefilename ascii file with TLE 3 line elements. */ -PamelaDBOperations::PamelaDBOperations(TString host, TString user, TString password, TString filerawname, TString filerootname, UInt_t boot, UInt_t tsync, UInt_t obt0, Bool_t debug, TString tlefilename, UInt_t dwinput, Bool_t staticp, Bool_t gpamela){ +PamelaDBOperations::PamelaDBOperations(TString host, TString user, TString password, TString filerawname, TString filerootname, UInt_t boot, UInt_t tsync, UInt_t obt0, Bool_t debug, TString tlefilename, UInt_t dwinput, Bool_t staticp, Bool_t gpamela, Bool_t keepenv){ // chewbacca = false; chminentry = 0; @@ -76,6 +76,8 @@ // }; // + KEEPENV = false; + if ( keepenv ) KEEPENV=true; STATIC=false; if ( staticp ) STATIC=true; // @@ -138,7 +140,7 @@ TString chfile; UInt_t ridn = 0; qu.str(""); - qu << "SELECT ROOT_ID_N,PKT_NUMBER_INIT,PKT_NUMBER_FINAL,PKT_OBT_INIT,PKT_OBT_FINAL from ROOT_TABLE_MERGING where ID_N=" << chID << ";"; + qu << "SELECT ROOT_ID_N,PKT_NUMBER_INIT,PKT_NUMBER_FINAL,PKT_OBT_INIT,PKT_OBT_FINAL,INSERTED_BY from ROOT_TABLE_MERGING where ID_N=" << chID << ";"; if ( debug ) printf(" chewbacca: query is %s \n",qu.str().c_str()); result = conn->Query(qu.str().c_str()); if ( result ){ @@ -149,6 +151,7 @@ chpktmax = (UInt_t)atoll(row->GetField(2)); chobtmin = (UInt_t)atoll(row->GetField(3)); chobtmax = (UInt_t)atoll(row->GetField(4)); + chiby = (TString)(row->GetField(5)); } else { throw -84; }; @@ -163,7 +166,11 @@ if ( result2 ){ row2 = result2->Next(); if ( row2 ){ - chpath = (TString)gSystem->ExpandPathName(row2->GetField(0))+'/'; + if ( KEEPENV ){ + chpath = (TString)(row2->GetField(0))+'/'; + } else { + chpath = (TString)gSystem->ExpandPathName(row2->GetField(0))+'/'; + }; chfile = (TString)(row2->GetField(1)); chobtts = (UInt_t)atoll(row2->GetField(2)); chlastts = (UInt_t)atoll(row2->GetField(3)); @@ -435,9 +442,13 @@ TString PamelaDBOperations::GetRootPath(){ if ( STATIC ){ - return((TString)gSystem->DirName(filerootname.Data())+'/'); - } else { - return((TString)gSystem->ExpandPathName("$PAM_L0")+'/'); + return((TString)gSystem->DirName(this->GetRootName().Data())+'/'); + } else { + if ( KEEPENV ){ + return((TString)gSystem->ExpandPathName(gSystem->DirName(filerootname.Data()))+'/'); + } else { + return((TString)gSystem->ExpandPathName("$PAM_L0")+'/'); + }; }; }; @@ -1125,7 +1136,15 @@ stringstream oss; // oss.str(""); - oss << "INSERT INTO _RUNID_GEN VALUES (NULL);"; + if ( chewbacca ){// if chewbacca and tag=none then use chewbacca tag (chiby = chewbacca inserted by), if chewbacca and tag!=none then use tag, if not chewbacca use tag. + if ( !strcmp(tag.Data(),"NONE") ){ + oss << "INSERT INTO _RUNID_GEN VALUES (NULL,'"<< chiby.Data() <<"');"; + } else { + oss << "INSERT INTO _RUNID_GEN VALUES (NULL,'"<< tag.Data() <<"');"; + }; + } else { + oss << "INSERT INTO _RUNID_GEN VALUES (NULL,'"<< tag.Data() <<"');"; + }; result = conn->Query(oss.str().c_str()); if ( !result ) throw -10; oss.str(""); @@ -1464,30 +1483,6 @@ // PUBLIC FUNCTIONS // -// /** -// * Insert a new row into GL_RAW table. -// */ -// Int_t PamelaDBOperations::insertPamelaRawFile(){ -// // -// stringstream oss; -// // -// Bool_t idr = this->SetID_RAW(); -// if ( idr ) return(1); -// // -// oss.str(""); -// if ( STATIC ){ -// oss << "INSERT INTO GL_RAW (PATH, NAME) VALUES ('" -// << this->GetRawPath().Data() << "', '" << this->GetRawFile().Data() << "')"; -// } else { -// oss << "INSERT INTO GL_RAW (PATH, NAME) VALUES ('$PAM_RAW', '" << this->GetRawFile().Data() << "')"; -// }; -// if ( conn->Query(oss.str().c_str()) == 0 ) throw -4; -// // -// idr = this->SetID_RAW(); -// if ( !idr ) throw -11; -// // -// return(0); -// } /** * Insert a new row into GL_RAW table. */ @@ -1501,7 +1496,8 @@ glraw.PATH = GetRawPath(); glraw.NAME = GetRawFile(); - glraw.BOOT_NUMBER = 0;//??? + // glraw.BOOT_NUMBER = 0;//??? + glraw.BOOT_NUMBER = this->GetBOOTnumber(); if( insertPamelaRawFile(&glraw) )return(1); // @@ -1515,7 +1511,7 @@ */ Int_t PamelaDBOperations::insertPamelaRawFile(GL_RAW *glraw){ // - if(!glraw)return(1);//?? + if(!glraw)return(1);//?? ok I think // stringstream oss; // @@ -1852,104 +1848,6 @@ return(signal); } -// /** -// * Insert all the new rows into GL_ROOT. -// * The raw file indicates in the parameters should be already been stored in the database. -// */ -// Int_t PamelaDBOperations::insertPamelaRootFile(){ -// stringstream oss; -// TSQLResult *result = 0; -// TSQLRow *row = 0; -// UInt_t idtimesync = 0; -// // -// // -// if ( chewbacca ){ -// oss.str(""); -// oss << " SELECT ID FROM GL_TIMESYNC where TIMESYNC="<Query(oss.str().c_str()); -// // -// if ( !result ) throw -3; -// // -// row = result->Next(); -// // -// if ( !row ) throw -3; -// idtimesync = (UInt_t)atoll(row->GetField(0)); -// } else { -// oss.str(""); -// if ( STATIC ){ -// oss << " SELECT COUNT(GL_ROOT.ID_RAW),GL_RAW.ID,GL_ROOT.ID FROM GL_RAW " -// << " LEFT JOIN GL_ROOT " -// << " ON GL_RAW.ID = GL_ROOT.ID_RAW " -// << " WHERE GL_RAW.PATH = '" << this->GetRawPath().Data() << "' AND " -// << " GL_RAW.NAME = '" << this->GetRawFile().Data() << "' GROUP BY GL_RAW.ID "; -// } else { -// oss << " SELECT COUNT(GL_ROOT.ID_RAW),GL_RAW.ID,GL_ROOT.ID FROM GL_RAW " -// << " LEFT JOIN GL_ROOT " -// << " ON GL_RAW.ID = GL_ROOT.ID_RAW " -// << " WHERE GL_RAW.PATH = '$PAM_RAW' AND " -// << " GL_RAW.NAME = '" << this->GetRawFile().Data() << "' GROUP BY GL_RAW.ID "; -// }; -// result = conn->Query(oss.str().c_str()); -// // -// if ( !result ) throw -12; -// // -// row = result->Next(); -// // -// if ( !row ) throw -10; -// if ( row != NULL && (UInt_t)atoll(row->GetField(0))>0 ){ -// idroot = (UInt_t)atoll(row->GetField(2)); -// return(1); -// }; -// // -// // determine which timesync has to be used -// // -// oss.str(""); -// oss << "SELECT GL_TIMESYNC.ID FROM GL_TIMESYNC LEFT JOIN GL_RAW ON GL_RAW.ID = GL_TIMESYNC.ID_RAW ORDER BY GL_TIMESYNC.ID DESC LIMIT 1;"; -// result = conn->Query(oss.str().c_str()); -// // -// if ( !result ) throw -3; -// // -// row = result->Next(); -// // -// if ( !row ) throw -3; -// idtimesync = (UInt_t)atoll(row->GetField(0)); -// }; -// // -// oss.str(""); -// if ( STATIC ){ -// oss << "INSERT INTO GL_ROOT (ID_RAW, ID_TIMESYNC,PATH, NAME) VALUES ('" -// << this->GetID_RAW() << "', '" << idtimesync << "', '" << this->GetRootPath().Data() << "', '" << this->GetRootFile().Data() << "')"; -// } else { -// oss << "INSERT INTO GL_ROOT (ID_RAW, ID_TIMESYNC,PATH, NAME) VALUES ('" -// << this->GetID_RAW() << "', '" << idtimesync << "', '$PAM_L0', '" << this->GetRootFile().Data() << "')"; -// }; -// // -// if ( debug ) printf(" query is %s \n",oss.str().c_str()); -// if (conn->Query(oss.str().c_str()) == 0) throw -4; -// // -// delete result; -// // -// oss.str(""); -// // oss << "SELECT ID FROM GL_ROOT WHERE ID_RAW=" << this->GetID_RAW() << ";"; -// if ( STATIC ){ -// oss << "SELECT ID FROM GL_ROOT WHERE PATH='" << this->GetRootPath().Data() << "' and NAME='"<< this->GetRootFile().Data() <<"';"; -// } else { -// oss << "SELECT ID FROM GL_ROOT WHERE PATH='$PAM_L0' and NAME='"<< this->GetRootFile().Data() <<"';"; -// }; -// // -// if ( debug ) printf(" query is %s \n",oss.str().c_str()); -// result = conn->Query(oss.str().c_str()); -// if ( !result ) throw -12; -// row = result->Next(); -// if ( !row ) throw -3; -// this->SetID_ROOT((UInt_t)atoll(row->GetField(0))); -// if ( debug ) printf(" The ID of the ROOT file is %u \n",this->GetID_ROOT()); -// // -// delete result; -// // -// return(0); -// } /** * Insert all the new rows into GL_ROOT. * The raw file indicates in the parameters should be already been stored in the database. @@ -1959,7 +1857,7 @@ stringstream oss; TSQLResult *result = 0; TSQLRow *row = 0; - // + // // ---------------------- // determine the timesync // ---------------------- @@ -2031,8 +1929,16 @@ glroot.ID_RAW = GetID_RAW(); glroot.ID_TIMESYNC = idtimesync; - glroot.PATH = GetRootPath(); - glroot.NAME = GetRootFile(); + if ( STATIC ){ + glroot.PATH = GetRootPath(); + } else { + if ( KEEPENV ){ + glroot.PATH = gSystem->DirName(filerootname.Data()); + } else { + glroot.PATH = "$PAM_L0"; + }; + }; + // glroot.NAME = GetRootFile(); if ( insertPamelaRootFile(&glroot) )return 1; @@ -2046,22 +1952,14 @@ * The raw file indicates in the parameters should be already been stored in the database. */ Int_t PamelaDBOperations::insertPamelaRootFile(GL_ROOT *glroot){ - - - stringstream oss; TSQLResult *result = 0; TSQLRow *row = 0; // // oss.str(""); - if ( STATIC ){ - oss << "INSERT INTO GL_ROOT (ID_RAW, ID_TIMESYNC,PATH, NAME) VALUES ('" - << glroot->ID_RAW << "', '" << glroot->ID_TIMESYNC << "', '" << glroot->PATH << "', '" << glroot->NAME << "')"; - } else { - oss << "INSERT INTO GL_ROOT (ID_RAW, ID_TIMESYNC,PATH, NAME) VALUES ('" - << glroot->ID_RAW << "', '" << glroot->ID_TIMESYNC << "', '$PAM_L0', '" << glroot->NAME << "')"; - }; + oss << "INSERT INTO GL_ROOT (ID_RAW, ID_TIMESYNC,PATH, NAME) VALUES ('" + << glroot->ID_RAW << "', '" << glroot->ID_TIMESYNC << "', '" << glroot->PATH << "', '" << glroot->NAME << "')"; // if ( debug ) printf("%s \n",oss.str().c_str()); if (conn->Query(oss.str().c_str()) == 0) throw -4; @@ -2070,11 +1968,7 @@ // oss.str(""); // oss << "SELECT ID FROM GL_ROOT WHERE ID_RAW=" << this->GetID_RAW() << ";"; - if ( STATIC ){ - oss << "SELECT ID FROM GL_ROOT WHERE PATH='" << glroot->PATH << "' and NAME='"<< glroot->NAME <<"';"; - } else { - oss << "SELECT ID FROM GL_ROOT WHERE PATH='$PAM_L0' and NAME='"<< glroot->NAME <<"';"; - }; + oss << "SELECT ID FROM GL_ROOT WHERE PATH='" << glroot->PATH << "' and NAME='"<< glroot->NAME <<"';"; // if ( debug ) printf("%s \n",oss.str().c_str()); result = conn->Query(oss.str().c_str()); @@ -3449,18 +3343,6 @@ // this->HandleRunFragments(true,mistrail,firstentry,lastentry); // cannot call it here since it enters a loop which will destroy the already stored variables if we arrive here from HandleRunFragments // - - - - - - - - - - - - mishead = true; @@ -3780,37 +3662,6 @@ }; // EEE - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - } else { if ( !IsRunAlreadyInserted() ){ glrun->SetID(this->AssignRunID()); @@ -4641,152 +4492,6 @@ return(0); }; -// /** -// * Fill the GL_TRK_CALIB table -// */ -// void PamelaDBOperations::HandleTRK_CALIB(Bool_t pk1, Bool_t pk2){ -// // -// TSQLResult *result = 0; -// TSQLRow *row = 0; -// // -// stringstream oss; -// oss.str(""); -// // -// UInt_t totime = 0; -// // -// if ( !pk1 && !pk2 ){ -// if ( IsDebug() ) printf(" Cannot handle trk calibration with both packet missing!\n"); -// return; -// }; -// // -// // check if the calibration has already been inserted -// // -// oss.str(""); -// oss << " SELECT ID FROM GL_TRK_CALIB WHERE " -// << " BOOT_NUMBER = "<< this->GetBOOTnumber(); // -// oss << " AND ( ( "; -// if ( pk1 ){ -// oss << " OBT1 = "<< obt1 << " AND " -// << " PKT1 = "<< pkt1 -// << " ) OR ( "; -// } else { -// oss << " PKT1 = "<< pkt2-1 -// << " ) OR ( "; -// }; -// if ( pk2 ){ -// oss << " OBT2 = "<< obt2 << " AND " -// << " PKT2 = "<< pkt2; -// } else { -// oss << " PKT2 = "<< pkt1+1; -// }; -// oss << " ) );"; -// // -// if ( IsDebug() ) printf(" Check if the trk calibration has already 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 ){ -// // -// if ( IsDebug() ) printf(" Trk calibration already inserted in the DB\n"); -// if ( PEDANTIC ) throw -80; -// // -// } else { -// // -// // we have to insert a new calibration, check where to place it -// // -// oss.str(""); -// oss << " SELECT ID,TO_TIME FROM GL_TRK_CALIB WHERE " -// << " FROM_TIME < "<< fromtime << " AND " -// << " TO_TIME > "<< fromtime << ";"; -// // -// if ( IsDebug() ) printf(" Check where to place the trk calibration: 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 calibrations in the db contain our calibration -// // -// if ( IsDebug() ) printf(" Calibration with fromtime lower than others to be inserted in the DB\n"); -// if ( fromtime < 1150871000 ) fromtime = 0; // the first flight calibration was taken at about 1150863300 s, this line allows to analyze first runs in raw mode -// // -// oss.str(""); -// oss << " SELECT FROM_TIME FROM GL_TRK_CALIB WHERE " -// << " FROM_TIME > "<< fromtime << " ORDER BY FROM_TIME ASC LIMIT 1;"; -// // -// if ( IsDebug() ) printf(" Check the upper limit for calibration: 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 ){ -// totime = numeric_limits::max(); -// } else { -// totime = (UInt_t)atoll(row->GetField(0)); -// }; -// // -// } else { -// // -// // determine upper and lower limits and make space for the new calibration -// // -// totime = (UInt_t)atoll(row->GetField(1)); -// // -// oss.str(""); -// oss << " UPDATE GL_TRK_CALIB SET " -// << " TO_TIME = "<< fromtime << " WHERE " // NOTICE: to_time is equal to from_time of the calibration before, so the interval is: [from_time,to_time[ -// << " ID = "<< row->GetField(0) << ";"; -// // -// if ( IsDebug() ) printf(" Make space for the new trk calibration: query is \n %s \n",oss.str().c_str()); -// result = conn->Query(oss.str().c_str()); -// // -// if ( !result ) throw -4; -// // -// }; -// // -// oss.str(""); -// oss << " INSERT INTO GL_TRK_CALIB (ID,ID_ROOT_L0,EV_ROOT_CALIBTRK1,EV_ROOT_CALIBTRK2,FROM_TIME,TO_TIME,OBT1,PKT1,OBT2,PKT2,BOOT_NUMBER,VALIDATION) " -// << " VALUES (NULL,' " -// << idroot << "',"; -// // -// if ( !pk1 ){ -// oss << "NULL,"; -// } else { -// oss << "'" -// << t1 << "',"; -// }; -// // -// if ( !pk2 ){ -// oss << "NULL,'"; -// } else { -// oss << "'" -// << t2 << "','"; -// }; -// // -// oss << fromtime << "','" -// << totime << "','" -// << obt1 << "','" -// << pkt1 << "','" -// << obt2 << "','" -// << pkt2 << "','" -// << this->GetBOOTnumber() << "','" -// << valid << "');"; -// // -// if ( IsDebug() ) printf(" Insert the new trk calibration: query is \n %s \n",oss.str().c_str()); -// // -// result = conn->Query(oss.str().c_str()); -// // -// if ( !result ) throw -4; -// // -// }; -// // -// }; /** * Fill the GL_TRK_CALIB table */ @@ -5416,16 +5121,16 @@ if ( IsDebug() ) cout << "- - - - - - - - - - -" <ExpandPathName(path)+"/"+name); // EM, path could be symbolic and we must expand it if(!file)throw -100; if(file->IsZombie())throw -100; // @@ -5495,32 +5200,32 @@ // // check if the raw file already exist // - UInt_t id_raw = 0; - oss.str(""); - oss << "SELECT ID FROM GL_RAW where NAME=\"" << gSystem->BaseName(raw.Data()) <<"\";"; - if ( IsDebug() ) cout << oss.str().c_str() << endl; + UInt_t id_raw = 0; // EM GL_RAW is there only for backward compatibility so we do not need to fill it when in "chewbacca" mode +// oss.str(""); +// oss << "SELECT ID FROM GL_RAW where NAME=\"" << gSystem->BaseName(raw.Data()) <<"\";"; +// if ( IsDebug() ) cout << oss.str().c_str() << endl; - result = conn->Query(oss.str().c_str()); - if ( !result ) throw -4;; - if ( IsDebug() ) cout <<"Rows: "<GetRowCount()<GetRowCount() == 0){ - if ( IsDebug() ) cout << " << Insert new RAW file >> "<DirName(raw.Data()); - glraw.NAME = gSystem->BaseName(raw.Data()); - glraw.BOOT_NUMBER = boot_number; - // - insertPamelaRawFile( &glraw ); - // - id_raw = glraw.ID; - }else{ - row = result->Next(); - id_raw = (UInt_t)atoll(row->GetField(0)); - } - if ( IsDebug() ) cout << "ID_RAW = "<Query(oss.str().c_str()); +// if ( !result ) throw -4;; +// if ( IsDebug() ) cout <<"Rows: "<GetRowCount()<GetRowCount() == 0){ +// if ( IsDebug() ) cout << " << Insert new RAW file >> "<DirName(raw.Data()); +// glraw.NAME = gSystem->BaseName(raw.Data()); +// glraw.BOOT_NUMBER = boot_number; +// // +// insertPamelaRawFile( &glraw ); +// // +// id_raw = glraw.ID; +// }else{ +// row = result->Next(); +// id_raw = (UInt_t)atoll(row->GetField(0)); +// } +// if ( IsDebug() ) cout << "ID_RAW = "<ExpandPathName(path); + } else { + if ( KEEPENV ){ + glroot.PATH = path; + } else { + glroot.PATH = "$PAM_L0"; + }; + }; + // glroot.PATH = path; glroot.NAME = name; // insertPamelaRootFile( &glroot );