--- chewbacca/PamOffLineSW/PacketUser.cpp 2008/09/23 07:20:12 1.1.1.1 +++ chewbacca/PamOffLineSW/PacketUser.cpp 2008/12/18 12:58:37 1.3 @@ -1,5 +1,5 @@ //============================================================================ -// $Id: PacketUser.cpp,v 1.67 2008-09-05 14:33:48 messineo Exp $ +// $Id: PacketUser.cpp,v 1.69 2008-10-27 10:41:27 messineo Exp $ // Description : //============================================================================ #include "PacketUser.h" @@ -32,6 +32,12 @@ extern char* db_pwd; extern char* connection; +//per tenere conto reset obt +extern unsigned long int max_pkt_obt; + +#define TAGVALUELEN 4 +extern char tag_value[TAGVALUELEN]; + PacketUser PacketUser::instance; int PacketUser::numDiscontinity=1; @@ -55,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; @@ -70,6 +83,12 @@ // good_pkt_Calib=0; my_id=0; boot_number=0; + //(tassa) + boot_number_prevvalue=0; + + //(tassa) + id_to_recover[1000]; + id_to_recover_index=0; } PacketUser::~PacketUser() @@ -84,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; @@ -92,41 +115,20 @@ // good_pkt_Calib=0; my_id=0; boot_number=0; + boot_number_prevvalue=0; } + //Put the packet in a root file. Create a new ROOT file for each group of packets void PacketUser::usePKT(char*& headerPkt, char*& pamPkt, long int length, bool isCons, bool isPKTGood, const PacketType* type, unsigned long int counter, unsigned long int obt) { //If the packet type was not recognised before if(!type){return;} - - -/* //zzzzzz marco per debug mi salvo il pacchetto vardump - if(type==PacketType::VarDump) - { - long int dataLength = length - 2; //the block of data - int b_offset = 4; - while (b_offset < dataLength){ - boot_number = (((UINT32)pamPkt[1+b_offset]<<24)&0xFF000000) + (((UINT32)pamPkt[2+b_offset]<<16)&0x00FF0000) + (((UINT32)pamPkt[3+b_offset]<<8)&0x0000FF00) + (((UINT32)pamPkt[4+b_offset])&0x000000FF); - cout<<"IN "<=0)//I want to use only accepted packet { - setTimeSync(pamPkt, length, type);//marco_new: here I retrieve also the boot_number if packet type is vardump + setTimeSync(pamPkt, length, type);//here I retrieve also the boot_number if packet type is vardump } //just to be sure ... if(pamPkt){delete[] pamPkt; pamPkt = NULL;} - //just to be sure ... if(headerPkt){delete[] headerPkt; headerPkt = NULL;} numPKT++; @@ -230,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 } @@ -238,8 +243,7 @@ //starts a new root file void PacketUser::StartGroup() { - pRun = new PamelaRun(rootfilename, outDir , multiFile, compression); - //marco_new: aggiunta estensione .root + pRun = new PamelaRun(rootfilename, outDir, multiFile, compression); strcat(rootfilename,".root"); reader->Init(pRun); stringstream oss; @@ -258,7 +262,7 @@ -//retrieve obt_time_sync and last_time_sync_info from packet if type has special values +//retrieve obt_time_sync and last_time_sync_info from packet if type has special values and BOOT_NUMBER void PacketUser::setTimeSync(char* packet, long int pktLength, const PacketType* type) { //do nothing @@ -269,18 +273,21 @@ } //TODO: usare anche MCMD ... NOTA: questo da sempre errore ret != 0 -//In RunHeader e RunTrailer sono in secondi(?), controllare se aggiungo altri tipi di paccheti se invece sono in secondi - - - // devo ricalcolare tutto non per ogni gruppetto (ROOT file) ma solo se cambia download - - //When I found a new download I need to reset all values +//In RunHeader e RunTrailer sono in secondi(?), controllare se aggiungo altri tipi di paccheti se invece sono in secondi +// devo ricalcolare tutto non per ogni gruppetto (ROOT file) ma solo se cambia download +//When I found a new download I need to reset all values if(is_new_route) - { - //reset + { + //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 @@ -326,18 +333,22 @@ //Boot Number void PacketUser::setBootNumber(char* packet, long int pktLength, const PacketType* type) { - //se gia calcolato esco: lo calcolo una volta per download e per continuit� + //se gia calcolato esco: lo calcolo una volta per download e per continuita' if(boot_number) return; -//todo: controlla se algo giusto: preso da VarDumpReader.cpp -//mmm e' sbagliatissimo cambiare !!! + if(type==PacketType::VarDump) - { + { + int b_offset = 34;//4+5*6 + boot_number = (((UINT32)packet[1+b_offset]<<24)&0xFF000000) + (((UINT32)packet[2+b_offset]<<16)&0x00FF0000) + (((UINT32)packet[3+b_offset]<<8)&0x0000FF00) + (((UINT32)packet[4+b_offset])&0x000000FF); + +/* long int dataLength = pktLength - 2; //the block of data - int b_offset = 4; + int b_offset = 4; while (b_offset < dataLength){ boot_number = (((UINT32)packet[1+b_offset]<<24)&0xFF000000) + (((UINT32)packet[2+b_offset]<<16)&0x00FF0000) + (((UINT32)packet[3+b_offset]<<8)&0x0000FF00) + (((UINT32)packet[4+b_offset])&0x000000FF); b_offset = b_offset + 5; } +*/ stringstream oss; oss.str()=""; oss<<"In download: "<GetName().c_str(); @@ -354,13 +365,31 @@ //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)) - { - real_time_init=(obt_init/1000-obt_time_sync)+last_time_sync_info; - real_time_last=(obt_last/1000-obt_time_sync)+last_time_sync_info; + + if(!obt_time_sync && !last_time_sync_info && numPKTSaved > 1000 ) + { + 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_lastlogWarning(msg); + } + else + real_time_last=(obt_last/1000-obt_time_sync)+last_time_sync_info; real_time_init+=timeOffset; - real_time_last+=timeOffset; - } + real_time_last+=timeOffset; + } } //timeOffset @@ -371,14 +400,11 @@ //if(!table){table=Table_GL_RESURS_OFFSET} - //marco_new_31:metto qui se voglio aprire e chiudere Connessione solo quando serve - //marco_new_01 if(!single_connection){ OpenDBConnection(table);//Nota qui ho deciso di lockare solo questa tabella e non tutte } - UInt_t t0 = 0; //toffset - + UInt_t t0 = 0;//toffset stringstream oss; oss.str(""); oss << "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE),ID FROM "<< table <<" WHERE SPECIAL_FILE='" @@ -429,8 +455,6 @@ if(res){delete res; res = NULL;} if(row){delete row; row = NULL;} - //marco_new_31:metto qui se voglio aprire e chiudere Connessione solo quando serve - //marco_new_01 if(!single_connection){ CloseDBConnection(); } @@ -444,9 +468,6 @@ setReal_Time(); FinishGroup(rootfilename); mainLogUtil->logAll("######################### Closed the last group ############################"); - - //marco_new_31:metto qui se voglio avere come in origine apertura Connessione all'inizio e chiusura alla fine - //marco_new_01 if(single_connection){ CloseDBConnection(); } @@ -474,7 +495,6 @@ oss.str()=""; //TODO: check when I don't want to log in DB informations - // se non ho salvato nessun pacchetto if(numPKTSaved==0){ stringstream err; @@ -496,8 +516,6 @@ // return; //TODO: decidi se nn vuoi affatto usarlo o addirittura salvarlo tra i BAD??? } - //marco_new_31:metto qui se voglio aprire e chiudere Connessione solo quando serve - //marco_new_01 if(!single_connection){ OpenDBConnection(NULL);//Nota qui ho deciso di lockare tutte le tabelle } @@ -515,7 +533,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: "<logError(msg); } - - //marco_new_31:metto qui se voglio aprire e chiudere Connessione solo quando serve - //marco_new_01 + if(!single_connection){ CloseDBConnection(); } @@ -540,7 +556,10 @@ } //saves info in DB in table Table_ROOT_Good - if(saveROOT_DB(Table_ROOT_Good, outDir, + if(boot_number==0) + boot_number=boot_number_prevvalue; + + if(saveROOT_DB(Table_ROOT_Good, outDir, filename, pkt_number_init, pkt_number_last, obt_init, obt_last, @@ -549,13 +568,12 @@ boot_number, timeOffset, bad_pkt, bad_pkt_EventReader, bad_pkt_CalibReader, numPKTSaved, - fni)==true) + fni,time_is_estimated)==true) { oss<<"Saved information regarding file: "<logAll(msg); @@ -606,9 +621,16 @@ 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: "<logError(msg1); + return ; + } + } + +for (int i = 0; ilogError(msg1); + return ; + } + } + + id_to_recover_index=0; +} + + + /**********************************************************************************************/ /*###########################################################################################################*/ /********************************** MERGING *************************************************/ /*###########################################################################################################*/ -// Merge ROOT files: found 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 bool PacketUser::merge_ROOTfiles() { - mainLogUtil->logInfo("Trying merging ROOT files"); + stringstream log; + log.str(""); + string slog; - //marco_new: controlla + mainLogUtil->logInfo("Trying merging ROOT files"); double percentage=(double)(bad_pkt+bad_pkt_EventReader+bad_pkt_CalibReader)/numPKTSaved; TSQLResult* res=NULL; TSQLRow* row =NULL; +//numero di ROOT files trovati sul DB che hanno relaz di tipo dato + unsigned int num_rows=0; + + //Record su DB: + unsigned int idN = 0; + unsigned int root_id_db=0; + unsigned long int pkt_num_in_db=0; + unsigned long int pkt_num_fin_db=0; + unsigned long int pkt_obt_in_db=0; + unsigned long int pkt_obt_fin_db=0; + unsigned long int time_in_db=0; + unsigned long int time_fin_db=0; + unsigned int boot_num_db=0; + double perc=0; + - //marco_new: non considero mai caso di continuit�(mio finale=DB iniz o viceversa), non mi interessa + //marco_new: non considero mai caso di continuita'(mio finale=DB iniz o viceversa), non mi interessa //marco_new: after e before contengono anche smaller ma con un bordo comune for(int relaz=AFTER; relaz<=BIGGER; relaz++) - { - //marco_new: controlla tutto + { //marco_new: esci se sono arrivato a zero - if(real_time_last==real_time_init){ + if(real_time_last==real_time_init) + { + log.str(""); + log<<"Current File Lenght=0; real_time_last=real_time_init= "<logAll(slog); mainLogUtil->logInfo("Finish merging ROOT files"); if(res){delete res; res = NULL;} if(row){delete row; row = NULL;} return true; } - res = Select_merging(Table_ROOT_Merging, real_time_init, real_time_last, (type_Rel_ROOT)relaz); + num_rows=0; + res = Select_merging(Table_ROOT_Merging, real_time_init, real_time_last, (type_Rel_ROOT)relaz); - unsigned int num_rows=0; if (!res) { mainLogUtil->logError("DB_ERROR: Unable to find ROOT files to be merged RES=null"); @@ -666,92 +756,122 @@ } num_rows=res->GetRowCount(); -// cout<<"MMMMM trovati num_rows "<< num_rows<< " per relaz= "<logError("DB_ERROR: Unable to find ROOT files to be merged. ROW=null"); if(res){delete res; res = NULL;} return false; } - - //TODO ricavare tutte le info che servono - unsigned int idN = 0; - idN=atoi(row->GetField(0)); - - double perc =0; - //marco_new: + //Leggi Record dal DB: + idN=atoll(row->GetField(0)); + root_id_db=atoll(row->GetField(1)); + pkt_num_in_db=atoll(row->GetField(2)); + pkt_num_fin_db=atoll(row->GetField(3)); + pkt_obt_in_db=atoll(row->GetField(4)); + pkt_obt_fin_db=atoll(row->GetField(5)); + time_in_db=atoll(row->GetField(6)); + time_fin_db=atoll(row->GetField(7)); + boot_num_db=atoll(row->GetField(8)); perc=atof(row->GetField(9)); - //unsigned long int M_pkt_number_in, M_pkt_number_fin, M_obt_in, M_obt_fin, M_mtime_init, M_mtime_last; - if(perc>percentage){ + + log.str(""); + log<<"*** ROOT file found in DB has idN= "<logAll(slog); + if(perc>percentage) + { mainLogUtil->logInfo("Current ROOT file is better than the one in DB"); //modifica DB updateMergeROOT_DB(Table_ROOT_Merging, - atoi(row->GetField(1)), atoi(row->GetField(2)), - atoi(row->GetField(3)), atoi(row->GetField(4)), - atoi(row->GetField(5)), atoi(row->GetField(6)), - atoi(row->GetField(7)), atoi(row->GetField(8)), - perc, - idN,(type_Rel_ROOT)relaz); + root_id_db, + pkt_num_in_db, pkt_num_fin_db, + pkt_obt_in_db, pkt_obt_fin_db, + time_in_db, time_fin_db, + boot_num_db, + perc, + idN,(type_Rel_ROOT)relaz); } - else{ - mainLogUtil->logInfo("Found ROOT files in DB better than current ROOT file"); - - if(relaz == AFTER){ + else + { + mainLogUtil->logInfo("Found ROOT file in DB is better than current ROOT file"); + if(relaz == AFTER) + { mainLogUtil->logInfo("Relaz:AFTER = Changing Init values of the Current ROOT file"); - pkt_number_init= atoi(row->GetField(3)); - obt_init= atoi(row->GetField(5)); - real_time_init= atoi(row->GetField(7)); + pkt_number_init = (pkt_num_fin_db+1); + obt_init = pkt_obt_fin_db; + real_time_init = time_fin_db; + log.str(""); + log<<"\n*** Current ROOT file becomes: pkt_number_init= "<logAll(slog); } - else if(relaz == BEFORE){ - mainLogUtil->logInfo("Relaz:BEFORE = Changing Last values of the Current ROOT file"); - pkt_number_last= atoi(row->GetField(2)); - obt_last= atoi(row->GetField(4)); - real_time_last= atoi(row->GetField(6)); + else if(relaz == BEFORE) + { + mainLogUtil->logInfo("Relaz:BEFORE = Changing Last values of the Current ROOT file"); + pkt_number_last = (pkt_num_in_db-1); + obt_last = pkt_obt_in_db; + real_time_last = time_in_db; + + log.str(""); + log<<"\n*** Current ROOT file becomes: pkt_number_init= "<logAll(slog); } else if(relaz == SMALLER) { //non devo proprio salvarlo ed esco ... mainLogUtil->logInfo("Relaz:SMALLER = Nothing to save"); - mainLogUtil->logInfo("Finish merging ROOT files"); + mainLogUtil->logInfo("\nFinish merging ROOT files"); if(res){delete res; res = NULL;} - if(row){delete row; row = NULL;} + if(row){delete row; row = NULL;} return true; } else if(relaz == BIGGER)//spezzettamento { 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, atoi(row->GetField(2)), - obt_init, atoi(row->GetField(4)), - real_time_init, atoi(row->GetField(6)), + 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= atoi(row->GetField(3)); - obt_init= atoi(row->GetField(5)); - real_time_init= atoi(row->GetField(7)); - } - } + pkt_number_init = (pkt_num_fin_db+1); + obt_init= pkt_obt_fin_db; + real_time_init= time_fin_db; + + log.str(""); + log<<"\n*** Current ROOT file becomes: pkt_number_init= "<logAll(slog); + }//if relaz + }//if perc }//for num_rows - } - else{ - //marco_new: - mainLogUtil->logInfo("Found 0 ROOT files in DB that can be merged with current ROOT file"); - - } + }//if num_rows - //marco_new:??? if(res){delete res; res = NULL;} if(row){delete row; row = NULL;} -}//for + +}//for relaz mainLogUtil->logInfo("Saving Current ROOT file"); saveMergeROOT_DB(Table_ROOT_Merging, my_id, @@ -761,9 +881,9 @@ boot_number, percentage); - mainLogUtil->logInfo("Finish merging ROOT files"); return true; + } //unsigned int root_id, percentage non le devo modificare @@ -775,21 +895,23 @@ unsigned long int mboot_num, double bad_perc, unsigned int ID_record, type_Rel_ROOT type_rel){ - stringstream oss; - oss.str(""); + stringstream oss; + oss.str(""); + if(type_rel == AFTER){ 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 <<";"; + } else if(type_rel == BEFORE){ - mainLogUtil->logInfo("Relaz:BEFORE = Updating Init values of the DB ROOT file"); + 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<<";"; } @@ -798,29 +920,27 @@ 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, - obt_last, obt_fin, - real_time_last, mtime_last, - mboot_num, - bad_perc); + mainLogUtil->logInfo("Relaz:SMALLER = (2nd part) Saving the second part of the DB ROOT file"); + + saveMergeROOT_DB(table_name, root_id, + (pkt_number_last+1), pkt_number_fin, + obt_last, obt_fin, + real_time_last, mtime_last, + mboot_num, + bad_perc); } else if(type_rel == BIGGER){ //marco_new: ok anche se coincidenti etc oss << "DELETE FROM "<< table_name <<" WHERE ID_N ="<< ID_record<<";"; - mainLogUtil->logInfo("Rimosso record in Tabella merging"); + mainLogUtil->logInfo("Record deleted from merging table"); } else return false; - - string msg = oss.str(); mainLogUtil->logInfo(msg); @@ -841,18 +961,16 @@ return true; } -//marco_new: check here +//cerca eventuali ROOT files in DB che possono venire mergiati +//marco_new bordi: messo in after a before casi in cui smaller con un bordo in comune +//marco_new bordi: messo in bigger casi con bordi in comune; tra questi anche caso particolare di coincidente +//marco_new bordi: smaller resta solo caso in cui DB e' piu largo sia a dx che a sx TSQLResult* PacketUser::Select_merging(char* table_name, unsigned long int mtime_init, unsigned long int mtime_last, type_Rel_ROOT type_rel) { - -// unsigned int idN=0; TSQLResult* res=NULL; stringstream query; query.str(""); - //marco_new bordi: messo in after a before casi in cui smaller con un bordo in comune - //marco_new bordi: messo in bigger casi con bordi in comune; tra questi anche caso particolare di coincidente - //marco_new bordi: smaller resta solo caso in cui DB � piu largo sia a dx che a sx if(type_rel == AFTER) query<<"select * from "< "<< mtime_init <<" and REAL_TIME_LAST <= "<< mtime_last <<" and REAL_TIME_INIT < "<< mtime_init; else if(type_rel == BEFORE) @@ -865,17 +983,14 @@ return 0; query<< " order by REAL_TIME_INIT ASC";//marco_new: inutile + //se volessi mettere un filtro sulla qualita' // query<<" and NUM_PKT_SAVED - BAD_PKT_CALREAD - BAD_PKT_READ - BAD_PKT >= 2" ; - - string msg = query.str(); mainLogUtil->logAll(msg); - - res= sqlServer->Query(query.str().c_str()); - + res= sqlServer->Query(query.str().c_str()); stringstream oss1; - oss1.str()=""; - string msg1; + oss1.str()=""; + string msg1; if (!res) { @@ -897,17 +1012,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){ @@ -919,7 +1035,6 @@ return true; } - stringstream oss1; oss1.str()=""; string msg1; @@ -950,8 +1065,8 @@ stringstream oss; oss.str(""); oss<<"select max(ID_N) from "<logAll(msg); +// string msg = oss.str(); +// mainLogUtil->logAll(msg); res= sqlServer->Query(oss.str().c_str()); stringstream oss1; @@ -979,6 +1094,11 @@ idN=atoi(row->GetField(0)); if(row){delete row; row = NULL;} if(res){delete res; res = NULL;} + + oss<<". idN = "<logAll(msg); + return idN; } @@ -1016,7 +1136,7 @@ } if(res){delete res; res = NULL;} - mainLogUtil->logAll("######################### TABLES LOCKED ############################"); + mainLogUtil->logAll("TABLES LOCKED"); return 0; } @@ -1050,7 +1170,7 @@ } if(res){delete res; res = NULL;} - mainLogUtil->logAll("######################### TABLES UNLOCKED ############################"); + mainLogUtil->logAll("TABLES UNLOCKED"); return 0; } @@ -1058,16 +1178,14 @@ /*********************************************************/ //marco_new_31 void PacketUser::OpenDBConnection(char* tableTobeLocked){ - mainLogUtil->logAll("######################### OpenDBConnection ############################"); if(do_cont_check){ - //controllo che non sia gi� aperta + //controllo che non sia gia' aperta if(!sqlServer){ sqlServer = TSQLServer::Connect(connection,db_user,db_pwd); if ((!sqlServer)||(!(sqlServer->IsConnected()))){cout<<"Can not connect with MYSQL sever"<logAll("######################### OpenDBConnection OK ############################"); + mainLogUtil->logAll("Connected to DB"); + //blocca le tabelle + LockTables(tableTobeLocked); } } @@ -1075,19 +1193,15 @@ //marco_new_31 void PacketUser::CloseDBConnection(){ - mainLogUtil->logAll("######################### CloseDBConnection ############################"); if(do_cont_check){ //controllo che ce ne sia una aperta if(sqlServer && sqlServer->IsConnected()){ //marco_new: sblocca tutte le tabelle UnLockTables(); sqlServer->Close(); - - //marco_new_01: ?? - delete sqlServer; - + delete sqlServer; sqlServer=NULL; - mainLogUtil->logAll("######################### CloseDBConnection OK ############################"); + mainLogUtil->logAll("Closed Connection to DB"); } } }