--- chewbacca/PamOffLineSW/PacketUser.cpp 2008/11/04 09:44:31 1.2 +++ chewbacca/PamOffLineSW/PacketUser.cpp 2009/07/24 13:53:38 1.7 @@ -1,6 +1,5 @@ - //============================================================================ -// $Id: PacketUser.cpp,v 1.69 2008-10-27 10:41:27 messineo Exp $ +// $Id: PacketUser.cpp,v 1.6 2008/12/23 20:43:08 mocchiut Exp $ // Description : //============================================================================ #include "PacketUser.h" @@ -36,6 +35,8 @@ //per tenere conto reset obt extern unsigned long int max_pkt_obt; +#define TAGVALUELEN 4 +extern char tag_value[TAGVALUELEN]; PacketUser PacketUser::instance; @@ -60,6 +61,13 @@ obt_last=0; obt_time_sync=0; last_time_sync_info=0; + + //(tassa) + obt_time_sync_prevvalue=0; + last_time_sync_info_prevvalue=0; + time_is_estimated=false; + + real_time_init=0; real_time_last=0; bad_pkt=0; @@ -75,6 +83,12 @@ // good_pkt_Calib=0; my_id=0; boot_number=0; + //(tassa) + boot_number_prevvalue=0; + + //(tassa) + // id_to_recover[1000]; // Emiliano: che si vuole fare con questa riga? cosi` non fa nulla... + id_to_recover_index=0; } PacketUser::~PacketUser() @@ -89,6 +103,10 @@ obt_last=0; obt_time_sync = 0; last_time_sync_info = 0; + obt_time_sync_prevvalue=0; + last_time_sync_info_prevvalue=0; + time_is_estimated=false; + real_time_init=0; real_time_last=0; bad_pkt=0; @@ -97,6 +115,7 @@ // good_pkt_Calib=0; my_id=0; boot_number=0; + boot_number_prevvalue=0; } @@ -209,7 +228,14 @@ //marco_NB: //ogni volta che trovo una discontinuit� resetto come se mi trovassi in un nuovo download oppure uso i vecchi valori se esistono? - obt_time_sync=0; last_time_sync_info=0; boot_number=0; + + obt_time_sync_prevvalue=obt_time_sync; + last_time_sync_info_prevvalue=last_time_sync_info; + time_is_estimated=false; + obt_time_sync=0; last_time_sync_info=0; + boot_number_prevvalue=boot_number; + boot_number=0; + // NB: se ho discontinuita in genere non so a che download appartiene potrebbe proprio essere sbagliato tenere i vecchi valori } @@ -217,7 +243,7 @@ //starts a new root file void PacketUser::StartGroup() { - pRun = new PamelaRun(rootfilename, outDir, multiFile, compression); + pRun = new PamelaRun(rootfilename, gSystem->ExpandPathName(outDir), multiFile, compression); // EMI strcat(rootfilename,".root"); reader->Init(pRun); stringstream oss; @@ -254,8 +280,14 @@ { //reset is_new_route=false; + //(tassa) ci ho ripensato se stiamo in un secondo download non prendiamo i bootnumber e timesync del precedente! + obt_time_sync_prevvalue=0;//obt_time_sync; + last_time_sync_info_prevvalue=0;//last_time_sync_info; + obt_time_sync=0; last_time_sync_info=0; + boot_number_prevvalue=0;//boot_number; boot_number=0; + time_is_estimated=false; if(time_Offset) timeOffset=time_Offset; else @@ -293,7 +325,8 @@ stringstream oss; oss.str()=""; - oss<<"In download: "<GetName().c_str(); + oss<<"In download: "<GetName(); + // oss<<"In download: "<GetName().c_str(); string msg = oss.str(); mainLogUtil->logAll(msg); } @@ -319,7 +352,8 @@ */ stringstream oss; oss.str()=""; - oss<<"In download: "<GetName().c_str(); + // oss<<"In download: "<GetName().c_str(); + oss<<"In download: "<GetName(); string msg = oss.str(); mainLogUtil->logAll(msg); return; @@ -333,10 +367,16 @@ //set the real time of the first packet and the last packet oif a group of packet if possible void PacketUser::setReal_Time() { - if((obt_time_sync)||(last_time_sync_info)) + + if(!obt_time_sync && !last_time_sync_info && numPKTSaved > 1000 ) { - - real_time_init=(obt_init/1000-obt_time_sync)+last_time_sync_info; + time_is_estimated=true; + obt_time_sync=obt_time_sync_prevvalue; + last_time_sync_info=last_time_sync_info_prevvalue; + } + if(obt_time_sync || last_time_sync_info) + { + real_time_init=(obt_init/1000-obt_time_sync)+last_time_sync_info; //se obt si e' resettato if(obt_lastlogAll(msg2); @@ -488,7 +526,7 @@ if((!real_time_init)&&(!real_time_last)) { //saved in another table for future study - if(saveROOT_DB(Table_ROOT_Bad, outDir, + if(saveROOT_DB(Table_ROOT_Bad, outDir,// here outDir is good, no expand EMI filename, pkt_number_init, pkt_number_last, obt_init, obt_last, @@ -497,7 +535,7 @@ boot_number, timeOffset, bad_pkt, bad_pkt_EventReader, bad_pkt_CalibReader, numPKTSaved, - fni)==true) + fni,time_is_estimated)==true) { oss.str()=""; oss<<"Saved information regarding file: "<logAll(msg); stringstream oss1; oss1.str()=""; string msg1; + string query; - TSQLResult* res=NULL; - res= sqlServer->Query(oss.str().c_str()); + TSQLResult* res=NULL; + + query=oss.str(); + msg1="SaveROOT_DB query: "; + msg1 += query; + mainLogUtil->logInfo(msg1); + + res= sqlServer->Query(query.c_str()); if(!res) { oss1<<"DBError UNABLE to: "<Query(query.c_str()); + if(!res) + { + oss1<<"DBError UNABLE to: "<logError(msg1); + return ; + } + } + + for (int i = 0; iQuery(query.c_str()); + if(!res) + { + oss1<<"DBError UNABLE to: "<logError(msg1); + return ; + } + } + + id_to_recover_index=0; +} + + + /**********************************************************************************************/ /*###########################################################################################################*/ /********************************** MERGING *************************************************/ /*###########################################################################################################*/ -// Merge ROOT files: find other ROOT files in the same temporal ranges +// Merge ROT files: find other ROOT files in the same temporal ranges // it finds ROOT files that covers particular temporal range of interest and save this info in DB /**********************************************************************************************/ //try to merge current ROOT file with files in DB @@ -718,7 +816,7 @@ if(relaz == AFTER) { mainLogUtil->logInfo("Relaz:AFTER = Changing Init values of the Current ROOT file"); - pkt_number_init = pkt_num_fin_db; + pkt_number_init = (pkt_num_fin_db+1); obt_init = pkt_obt_fin_db; real_time_init = time_fin_db; log.str(""); @@ -730,7 +828,7 @@ else if(relaz == BEFORE) { mainLogUtil->logInfo("Relaz:BEFORE = Changing Last values of the Current ROOT file"); - pkt_number_last = pkt_num_in_db; + pkt_number_last = (pkt_num_in_db-1); obt_last = pkt_obt_in_db; real_time_last = time_in_db; @@ -753,14 +851,14 @@ { mainLogUtil->logInfo("Relaz:BIGGER = (1st part) Saving the first part of the Current ROOT file"); saveMergeROOT_DB(Table_ROOT_Merging, my_id, - pkt_number_init, pkt_num_in_db, + pkt_number_init, (pkt_num_in_db-1), obt_init, pkt_obt_in_db, real_time_init, time_in_db, boot_number, percentage); mainLogUtil->logInfo("Relaz:BIGGER = (2nd part)Changing Init values of the Current ROOT file"); - pkt_number_init = pkt_num_fin_db; + pkt_number_init = (pkt_num_fin_db+1); obt_init= pkt_obt_fin_db; real_time_init= time_fin_db; @@ -809,7 +907,7 @@ mainLogUtil->logInfo("Relaz:AFTER = Updating Last values of the DB ROOT file"); //marco_new:tolti tutti gli apici che qui non devono essere oss << "UPDATE "<< table_name - << " SET PKT_NUMBER_FINAL ="<< pkt_number_init + << " SET PKT_NUMBER_FINAL ="<< (pkt_number_init - 1) <<", PKT_OBT_FINAL ="<< obt_init <<", REAL_TIME_LAST ="<< real_time_init<<" WHERE ID_N ="<< ID_record <<";"; @@ -817,7 +915,7 @@ else if(type_rel == BEFORE){ mainLogUtil->logInfo("Relaz:BEFORE = Updating Init values of the DB ROOT file"); oss << "UPDATE "<< table_name - << " SET PKT_NUMBER_INIT ="<< pkt_number_last + << " SET PKT_NUMBER_INIT ="<< (pkt_number_last+1) <<", PKT_OBT_INIT ="<< obt_last <<", REAL_TIME_INIT ="<< real_time_last<<" WHERE ID_N ="<< ID_record<<";"; } @@ -826,14 +924,14 @@ mainLogUtil->logInfo("Relaz:SMALLER = (1st part) Updating Last values of the DB ROOT file"); oss << "UPDATE "<< table_name - << " SET PKT_NUMBER_FINAL="<< pkt_number_init + << " SET PKT_NUMBER_FINAL="<< (pkt_number_init-1) <<", PKT_OBT_FINAL ="<< obt_init <<", REAL_TIME_LAST ="<< real_time_init<<" WHERE ID_N ="<< ID_record<<";"; mainLogUtil->logInfo("Relaz:SMALLER = (2nd part) Saving the second part of the DB ROOT file"); saveMergeROOT_DB(table_name, root_id, - pkt_number_last, pkt_number_fin, + (pkt_number_last+1), pkt_number_fin, obt_last, obt_fin, real_time_last, mtime_last, mboot_num, @@ -841,7 +939,8 @@ } else if(type_rel == BIGGER){ //marco_new: ok anche se coincidenti etc - oss << "DELETE FROM "<< table_name <<" WHERE ID_N ="<< ID_record<<";"; + // oss << "DELETE FROM "<< table_name <<" WHERE ID_N ="<< ID_record<<";"; // EMILIANO + oss << "UPDATE "<< table_name <<" SET GOOD=0 WHERE ID_N ="<< ID_record<<";"; // EMILIANO DO NOT DELETE FROM ROOT_TABLE_MERGING JUST SET GOOD FLAG TO ZERO mainLogUtil->logInfo("Record deleted from merging table"); } else @@ -878,13 +977,13 @@ query.str(""); if(type_rel == AFTER) - query<<"select * from "< "<< mtime_init <<" and REAL_TIME_LAST <= "<< mtime_last <<" and REAL_TIME_INIT < "<< mtime_init; + query<<"select * from "< "<< mtime_init <<" and REAL_TIME_LAST <= "<< mtime_last <<" and REAL_TIME_INIT < "<< mtime_init; // EMI else if(type_rel == BEFORE) - query<<"select * from "<= "<< mtime_init <<" and REAL_TIME_INIT < "<< mtime_last <<" and REAL_TIME_LAST > "<< mtime_last; + query<<"select * from "<= "<< mtime_init <<" and REAL_TIME_INIT < "<< mtime_last <<" and REAL_TIME_LAST > "<< mtime_last; // EMI else if(type_rel == SMALLER) - query<<"select * from "< "<< mtime_last; + query<<"select * from "< "<< mtime_last; // EMI else if(type_rel == BIGGER) - query<<"select * from "<= "<< mtime_init <<" and REAL_TIME_LAST <= "<< mtime_last; + query<<"select * from "<= "<< mtime_init <<" and REAL_TIME_LAST <= "<< mtime_last; // EMI else return 0; @@ -918,18 +1017,18 @@ stringstream oss; oss.str(""); - oss << "INSERT INTO "<< table_name <<" (ID_N, ROOT_ID_N, PKT_NUMBER_INIT, PKT_NUMBER_FINAL, PKT_OBT_INIT, PKT_OBT_FINAL, REAL_TIME_INIT, REAL_TIME_LAST, BOOT_NUMBER, BAD_PKT_PERCENTAGE, INSERT_TIME)" + oss << "INSERT INTO "<< table_name <<" (ID_N, ROOT_ID_N, PKT_NUMBER_INIT, PKT_NUMBER_FINAL, PKT_OBT_INIT, PKT_OBT_FINAL, REAL_TIME_INIT, REAL_TIME_LAST, BOOT_NUMBER, BAD_PKT_PERCENTAGE, INSERT_TIME, INSERTED_BY)" << " VALUES ('"<<0<< "','" <logAll(msg); - //marco_new: controlla //marco_new: esci se sono arrivato a zero // if(real_time_last==real_time_init){ @@ -1138,7 +1237,7 @@ { char fno[80]=""; ofstream fout; - sprintf(fno,"%s/pkt%d_of_%s.pkt", outDir, numPKTSaved, nomefile); + sprintf(fno,"%s/pkt%d_of_%s.pkt", gSystem->ExpandPathName(outDir), numPKTSaved, nomefile); // EMI if(append==true) fout.open(fno, ios::binary | ios::app); @@ -1158,11 +1257,11 @@ ofstream fout; if(append==true) { - sprintf(fno,"%s/packets.pkt", outDir); + sprintf(fno,"%s/packets.pkt", gSystem->ExpandPathName(outDir)); // EMI fout.open(fno, ios::binary | ios::app); } else{ - sprintf(fno,"%s/packet%d.pkt", outDir, numPKT ); + sprintf(fno,"%s/packet%d.pkt", gSystem->ExpandPathName(outDir), numPKT ); // EMI fout.open(fno, ios::binary); }