| 1 |
//============================================================================ |
//============================================================================ |
| 2 |
// $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 $ |
| 3 |
// Description : |
// Description : |
| 4 |
//============================================================================ |
//============================================================================ |
| 5 |
#include "PacketUser.h" |
#include "PacketUser.h" |
| 32 |
extern char* db_pwd; |
extern char* db_pwd; |
| 33 |
extern char* connection; |
extern char* connection; |
| 34 |
|
|
| 35 |
|
//per tenere conto reset obt |
| 36 |
|
extern unsigned long int max_pkt_obt; |
| 37 |
|
|
| 38 |
|
#define TAGVALUELEN 4 |
| 39 |
|
extern char tag_value[TAGVALUELEN]; |
| 40 |
|
|
| 41 |
PacketUser PacketUser::instance; |
PacketUser PacketUser::instance; |
| 42 |
|
|
| 43 |
int PacketUser::numDiscontinity=1; |
int PacketUser::numDiscontinity=1; |
| 61 |
obt_last=0; |
obt_last=0; |
| 62 |
obt_time_sync=0; |
obt_time_sync=0; |
| 63 |
last_time_sync_info=0; |
last_time_sync_info=0; |
| 64 |
|
|
| 65 |
|
//(tassa) |
| 66 |
|
obt_time_sync_prevvalue=0; |
| 67 |
|
last_time_sync_info_prevvalue=0; |
| 68 |
|
time_is_estimated=false; |
| 69 |
|
|
| 70 |
|
|
| 71 |
real_time_init=0; |
real_time_init=0; |
| 72 |
real_time_last=0; |
real_time_last=0; |
| 73 |
bad_pkt=0; |
bad_pkt=0; |
| 83 |
// good_pkt_Calib=0; |
// good_pkt_Calib=0; |
| 84 |
my_id=0; |
my_id=0; |
| 85 |
boot_number=0; |
boot_number=0; |
| 86 |
|
//(tassa) |
| 87 |
|
boot_number_prevvalue=0; |
| 88 |
|
|
| 89 |
|
//(tassa) |
| 90 |
|
id_to_recover[1000]; |
| 91 |
|
id_to_recover_index=0; |
| 92 |
} |
} |
| 93 |
|
|
| 94 |
PacketUser::~PacketUser() |
PacketUser::~PacketUser() |
| 103 |
obt_last=0; |
obt_last=0; |
| 104 |
obt_time_sync = 0; |
obt_time_sync = 0; |
| 105 |
last_time_sync_info = 0; |
last_time_sync_info = 0; |
| 106 |
|
obt_time_sync_prevvalue=0; |
| 107 |
|
last_time_sync_info_prevvalue=0; |
| 108 |
|
time_is_estimated=false; |
| 109 |
|
|
| 110 |
real_time_init=0; |
real_time_init=0; |
| 111 |
real_time_last=0; |
real_time_last=0; |
| 112 |
bad_pkt=0; |
bad_pkt=0; |
| 115 |
// good_pkt_Calib=0; |
// good_pkt_Calib=0; |
| 116 |
my_id=0; |
my_id=0; |
| 117 |
boot_number=0; |
boot_number=0; |
| 118 |
|
boot_number_prevvalue=0; |
| 119 |
} |
} |
| 120 |
|
|
| 121 |
|
|
| 122 |
//Put the packet in a root file. Create a new ROOT file for each group of packets |
//Put the packet in a root file. Create a new ROOT file for each group of packets |
| 123 |
void PacketUser::usePKT(char*& headerPkt, char*& pamPkt, long int length, bool isCons, bool isPKTGood, const PacketType* type, |
void PacketUser::usePKT(char*& headerPkt, char*& pamPkt, long int length, bool isCons, bool isPKTGood, const PacketType* type, |
| 124 |
unsigned long int counter, unsigned long int obt) |
unsigned long int counter, unsigned long int obt) |
| 125 |
{ |
{ |
| 126 |
//If the packet type was not recognised before |
//If the packet type was not recognised before |
| 127 |
if(!type){return;} |
if(!type){return;} |
| 128 |
|
|
|
|
|
|
/* //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 "<<numPKTSaved<<" boot_number "<<boot_number<<" al b_offset "<<b_offset<<" di "<<dataLength<<endl; |
|
|
|
|
|
b_offset = b_offset + 5; |
|
|
} |
|
|
|
|
|
cout<<"IN "<<numPKTSaved<<" FINAL boot_number "<<boot_number<<endl; |
|
|
savePKT_file(headerPkt,pamPkt,length,false,"vardump"); |
|
|
numPKTSaved++; |
|
|
} |
|
|
return; |
|
|
*/ |
|
|
|
|
|
|
|
| 129 |
//in order to start ... |
//in order to start ... |
| 130 |
if(numPKT==0) |
if(numPKT==0) |
| 131 |
{ |
{ |
|
//marco_new_31: metto qui se voglio avere come in origine apertura Connessione all'inizio e chiusura alla fine |
|
|
//marco_new_01 |
|
| 132 |
if(single_connection){ |
if(single_connection){ |
| 133 |
OpenDBConnection(NULL); |
OpenDBConnection(NULL); |
| 134 |
} |
} |
| 141 |
if((!isCons)&&(numPKT!=0)) |
if((!isCons)&&(numPKT!=0)) |
| 142 |
{ |
{ |
| 143 |
setReal_Time(); |
setReal_Time(); |
| 144 |
//closing the group in file rootfilename |
//closing the group in file rootfilename |
| 145 |
FinishGroup(rootfilename); |
FinishGroup(rootfilename); |
| 146 |
|
|
| 147 |
//numDiscontinity++; |
//se gia' e' cambiato download non cambio numdisco |
| 148 |
//se gia' e' cambiato download nn cambio numdisco |
if(!is_new_route){numDiscontinity++;} |
| 149 |
if(!is_new_route) numDiscontinity++; |
|
|
|
|
| 150 |
//the current pkt will be placed in a new group: rootfilename |
//the current pkt will be placed in a new group: rootfilename |
| 151 |
setInit(counter,obt); |
setInit(counter,obt); |
| 152 |
StartGroup(); |
StartGroup(); |
| 167 |
ret = 10 if the packet is good but comes from a cadre with VRL problems |
ret = 10 if the packet is good but comes from a cadre with VRL problems |
| 168 |
*/ |
*/ |
| 169 |
|
|
| 170 |
//here we know if the packet comes from one or more corrupted cadres |
//here we also know if the packet comes from one or more corrupted cadres |
|
//if(!isPKTGood){bad_pkt++;} |
|
| 171 |
if((!isPKTGood)&&(!ret)){ret=10;} |
if((!isPKTGood)&&(!ret)){ret=10;} |
|
|
|
| 172 |
switch (ret) |
switch (ret) |
| 173 |
{ |
{ |
| 174 |
case 0: {numPKTSaved++; break;} |
case 0: {numPKTSaved++; break;} |
| 200 |
// if((ret==0)||(ret==10))//I want to use only good packet |
// if((ret==0)||(ret==10))//I want to use only good packet |
| 201 |
if(ret>=0)//I want to use only accepted packet |
if(ret>=0)//I want to use only accepted packet |
| 202 |
{ |
{ |
| 203 |
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 |
| 204 |
} |
} |
| 205 |
|
|
| 206 |
//just to be sure ... |
//just to be sure ... |
| 207 |
if(pamPkt){delete[] pamPkt; pamPkt = NULL;} |
if(pamPkt){delete[] pamPkt; pamPkt = NULL;} |
|
//just to be sure ... |
|
| 208 |
if(headerPkt){delete[] headerPkt; headerPkt = NULL;} |
if(headerPkt){delete[] headerPkt; headerPkt = NULL;} |
| 209 |
|
|
| 210 |
numPKT++; |
numPKT++; |
| 228 |
|
|
| 229 |
//marco_NB: |
//marco_NB: |
| 230 |
//ogni volta che trovo una discontinuit� resetto come se mi trovassi in un nuovo download oppure uso i vecchi valori se esistono? |
//ogni volta che trovo una discontinuit� resetto come se mi trovassi in un nuovo download oppure uso i vecchi valori se esistono? |
| 231 |
obt_time_sync=0; last_time_sync_info=0; boot_number=0; |
|
| 232 |
|
obt_time_sync_prevvalue=obt_time_sync; |
| 233 |
|
last_time_sync_info_prevvalue=last_time_sync_info; |
| 234 |
|
time_is_estimated=false; |
| 235 |
|
obt_time_sync=0; last_time_sync_info=0; |
| 236 |
|
boot_number_prevvalue=boot_number; |
| 237 |
|
boot_number=0; |
| 238 |
|
|
| 239 |
// NB: se ho discontinuita in genere non so a che download appartiene potrebbe proprio essere sbagliato tenere i vecchi valori |
// NB: se ho discontinuita in genere non so a che download appartiene potrebbe proprio essere sbagliato tenere i vecchi valori |
| 240 |
|
|
| 241 |
} |
} |
| 243 |
//starts a new root file |
//starts a new root file |
| 244 |
void PacketUser::StartGroup() |
void PacketUser::StartGroup() |
| 245 |
{ |
{ |
| 246 |
pRun = new PamelaRun(rootfilename, outDir , multiFile, compression); |
pRun = new PamelaRun(rootfilename, outDir, multiFile, compression); |
|
//marco_new: aggiunta estensione .root |
|
| 247 |
strcat(rootfilename,".root"); |
strcat(rootfilename,".root"); |
| 248 |
reader->Init(pRun); |
reader->Init(pRun); |
| 249 |
stringstream oss; |
stringstream oss; |
| 262 |
|
|
| 263 |
|
|
| 264 |
|
|
| 265 |
//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 |
| 266 |
void PacketUser::setTimeSync(char* packet, long int pktLength, const PacketType* type) |
void PacketUser::setTimeSync(char* packet, long int pktLength, const PacketType* type) |
| 267 |
{ |
{ |
| 268 |
//do nothing |
//do nothing |
| 273 |
} |
} |
| 274 |
|
|
| 275 |
//TODO: usare anche MCMD ... NOTA: questo da sempre errore ret != 0 |
//TODO: usare anche MCMD ... NOTA: questo da sempre errore ret != 0 |
| 276 |
//In RunHeader e RunTrailer sono in secondi(?), controllare se aggiungo altri tipi di paccheti se invece sono in secondi |
//In RunHeader e RunTrailer sono in secondi(?), controllare se aggiungo altri tipi di paccheti se invece sono in secondi |
| 277 |
|
// devo ricalcolare tutto non per ogni gruppetto (ROOT file) ma solo se cambia download |
| 278 |
|
//When I found a new download I need to reset all values |
|
// 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 |
|
| 279 |
if(is_new_route) |
if(is_new_route) |
| 280 |
{ |
{ |
| 281 |
//reset |
//reset |
| 282 |
is_new_route=false; |
is_new_route=false; |
| 283 |
|
//(tassa) ci ho ripensato se stiamo in un secondo download non prendiamo i bootnumber e timesync del precedente! |
| 284 |
|
obt_time_sync_prevvalue=0;//obt_time_sync; |
| 285 |
|
last_time_sync_info_prevvalue=0;//last_time_sync_info; |
| 286 |
|
|
| 287 |
obt_time_sync=0; last_time_sync_info=0; |
obt_time_sync=0; last_time_sync_info=0; |
| 288 |
|
boot_number_prevvalue=0;//boot_number; |
| 289 |
boot_number=0; |
boot_number=0; |
| 290 |
|
time_is_estimated=false; |
| 291 |
if(time_Offset) |
if(time_Offset) |
| 292 |
timeOffset=time_Offset; |
timeOffset=time_Offset; |
| 293 |
else |
else |
| 333 |
//Boot Number |
//Boot Number |
| 334 |
void PacketUser::setBootNumber(char* packet, long int pktLength, const PacketType* type) |
void PacketUser::setBootNumber(char* packet, long int pktLength, const PacketType* type) |
| 335 |
{ |
{ |
| 336 |
//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' |
| 337 |
if(boot_number) return; |
if(boot_number) return; |
| 338 |
//todo: controlla se algo giusto: preso da VarDumpReader.cpp |
|
|
//mmm e' sbagliatissimo cambiare !!! |
|
| 339 |
if(type==PacketType::VarDump) |
if(type==PacketType::VarDump) |
| 340 |
{ |
{ |
| 341 |
|
int b_offset = 34;//4+5*6 |
| 342 |
|
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); |
| 343 |
|
|
| 344 |
|
/* |
| 345 |
long int dataLength = pktLength - 2; //the block of data |
long int dataLength = pktLength - 2; //the block of data |
| 346 |
int b_offset = 4; |
int b_offset = 4; |
| 347 |
while (b_offset < dataLength){ |
while (b_offset < dataLength){ |
| 348 |
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); |
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); |
| 349 |
b_offset = b_offset + 5; |
b_offset = b_offset + 5; |
| 350 |
} |
} |
| 351 |
|
*/ |
| 352 |
stringstream oss; |
stringstream oss; |
| 353 |
oss.str()=""; |
oss.str()=""; |
| 354 |
oss<<"In download: "<<download<<" boot_number: "<<boot_number<<" using Packet Type: "<<type->GetName().c_str(); |
oss<<"In download: "<<download<<" boot_number: "<<boot_number<<" using Packet Type: "<<type->GetName().c_str(); |
| 365 |
//set the real time of the first packet and the last packet oif a group of packet if possible |
//set the real time of the first packet and the last packet oif a group of packet if possible |
| 366 |
void PacketUser::setReal_Time() |
void PacketUser::setReal_Time() |
| 367 |
{ |
{ |
| 368 |
if((obt_time_sync)||(last_time_sync_info)) |
|
| 369 |
{ |
if(!obt_time_sync && !last_time_sync_info && numPKTSaved > 1000 ) |
| 370 |
real_time_init=(obt_init/1000-obt_time_sync)+last_time_sync_info; |
{ |
| 371 |
real_time_last=(obt_last/1000-obt_time_sync)+last_time_sync_info; |
time_is_estimated=true; |
| 372 |
|
obt_time_sync=obt_time_sync_prevvalue; |
| 373 |
|
last_time_sync_info=last_time_sync_info_prevvalue; |
| 374 |
|
} |
| 375 |
|
if(obt_time_sync || last_time_sync_info) |
| 376 |
|
{ |
| 377 |
|
real_time_init=(obt_init/1000-obt_time_sync)+last_time_sync_info; |
| 378 |
|
//se obt si e' resettato |
| 379 |
|
if(obt_last<obt_init) |
| 380 |
|
{ |
| 381 |
|
real_time_last=(max_pkt_obt/1000+ obt_last/1000-obt_time_sync)+last_time_sync_info; |
| 382 |
|
stringstream oss; |
| 383 |
|
oss.str()=""; |
| 384 |
|
oss<<"obt_last("<<obt_last<<") < obt_init("<<obt_init<<"). It is due to Pamela Reset. Adding max_pkt_obt("<<max_pkt_obt<<") to obt_last in order to compute real_time_last"; |
| 385 |
|
string msg = oss.str(); |
| 386 |
|
mainLogUtil->logWarning(msg); |
| 387 |
|
} |
| 388 |
|
else |
| 389 |
|
real_time_last=(obt_last/1000-obt_time_sync)+last_time_sync_info; |
| 390 |
real_time_init+=timeOffset; |
real_time_init+=timeOffset; |
| 391 |
real_time_last+=timeOffset; |
real_time_last+=timeOffset; |
| 392 |
} |
} |
| 393 |
} |
} |
| 394 |
|
|
| 395 |
//timeOffset |
//timeOffset |
| 400 |
|
|
| 401 |
//if(!table){table=Table_GL_RESURS_OFFSET} |
//if(!table){table=Table_GL_RESURS_OFFSET} |
| 402 |
|
|
|
//marco_new_31:metto qui se voglio aprire e chiudere Connessione solo quando serve |
|
|
//marco_new_01 |
|
| 403 |
if(!single_connection){ |
if(!single_connection){ |
| 404 |
OpenDBConnection(table);//Nota qui ho deciso di lockare solo questa tabella e non tutte |
OpenDBConnection(table);//Nota qui ho deciso di lockare solo questa tabella e non tutte |
| 405 |
} |
} |
| 406 |
|
|
| 407 |
UInt_t t0 = 0; //toffset |
UInt_t t0 = 0;//toffset |
|
|
|
| 408 |
stringstream oss; |
stringstream oss; |
| 409 |
oss.str(""); |
oss.str(""); |
| 410 |
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='" |
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='" |
| 455 |
if(res){delete res; res = NULL;} |
if(res){delete res; res = NULL;} |
| 456 |
if(row){delete row; row = NULL;} |
if(row){delete row; row = NULL;} |
| 457 |
|
|
|
//marco_new_31:metto qui se voglio aprire e chiudere Connessione solo quando serve |
|
|
//marco_new_01 |
|
| 458 |
if(!single_connection){ |
if(!single_connection){ |
| 459 |
CloseDBConnection(); |
CloseDBConnection(); |
| 460 |
} |
} |
| 468 |
setReal_Time(); |
setReal_Time(); |
| 469 |
FinishGroup(rootfilename); |
FinishGroup(rootfilename); |
| 470 |
mainLogUtil->logAll("######################### Closed the last group ############################"); |
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 |
|
| 471 |
if(single_connection){ |
if(single_connection){ |
| 472 |
CloseDBConnection(); |
CloseDBConnection(); |
| 473 |
} |
} |
| 495 |
oss.str()=""; |
oss.str()=""; |
| 496 |
|
|
| 497 |
//TODO: check when I don't want to log in DB informations |
//TODO: check when I don't want to log in DB informations |
|
|
|
| 498 |
// se non ho salvato nessun pacchetto |
// se non ho salvato nessun pacchetto |
| 499 |
if(numPKTSaved==0){ |
if(numPKTSaved==0){ |
| 500 |
stringstream err; |
stringstream err; |
| 516 |
// return; //TODO: decidi se nn vuoi affatto usarlo o addirittura salvarlo tra i BAD??? |
// return; //TODO: decidi se nn vuoi affatto usarlo o addirittura salvarlo tra i BAD??? |
| 517 |
} |
} |
| 518 |
|
|
|
//marco_new_31:metto qui se voglio aprire e chiudere Connessione solo quando serve |
|
|
//marco_new_01 |
|
| 519 |
if(!single_connection){ |
if(!single_connection){ |
| 520 |
OpenDBConnection(NULL);//Nota qui ho deciso di lockare tutte le tabelle |
OpenDBConnection(NULL);//Nota qui ho deciso di lockare tutte le tabelle |
| 521 |
} |
} |
| 533 |
boot_number, |
boot_number, |
| 534 |
timeOffset, |
timeOffset, |
| 535 |
bad_pkt, bad_pkt_EventReader, bad_pkt_CalibReader, numPKTSaved, |
bad_pkt, bad_pkt_EventReader, bad_pkt_CalibReader, numPKTSaved, |
| 536 |
fni)==true) |
fni,time_is_estimated)==true) |
| 537 |
{ |
{ |
| 538 |
oss.str()=""; |
oss.str()=""; |
| 539 |
oss<<"Saved information regarding file: "<<filename<<" in table "<<Table_ROOT_Bad; |
oss<<"Saved information regarding file: "<<filename<<" in table "<<Table_ROOT_Bad; |
| 547 |
msg = oss.str(); |
msg = oss.str(); |
| 548 |
mainLogUtil->logError(msg); |
mainLogUtil->logError(msg); |
| 549 |
} |
} |
| 550 |
|
|
|
//marco_new_31:metto qui se voglio aprire e chiudere Connessione solo quando serve |
|
|
//marco_new_01 |
|
| 551 |
if(!single_connection){ |
if(!single_connection){ |
| 552 |
CloseDBConnection(); |
CloseDBConnection(); |
| 553 |
} |
} |
| 556 |
} |
} |
| 557 |
|
|
| 558 |
//saves info in DB in table Table_ROOT_Good |
//saves info in DB in table Table_ROOT_Good |
| 559 |
if(saveROOT_DB(Table_ROOT_Good, outDir, |
if(boot_number==0) |
| 560 |
|
boot_number=boot_number_prevvalue; |
| 561 |
|
|
| 562 |
|
if(saveROOT_DB(Table_ROOT_Good, outDir, |
| 563 |
filename, |
filename, |
| 564 |
pkt_number_init, pkt_number_last, |
pkt_number_init, pkt_number_last, |
| 565 |
obt_init, obt_last, |
obt_init, obt_last, |
| 568 |
boot_number, |
boot_number, |
| 569 |
timeOffset, |
timeOffset, |
| 570 |
bad_pkt, bad_pkt_EventReader, bad_pkt_CalibReader, numPKTSaved, |
bad_pkt, bad_pkt_EventReader, bad_pkt_CalibReader, numPKTSaved, |
| 571 |
fni)==true) |
fni,time_is_estimated)==true) |
| 572 |
{ |
{ |
| 573 |
oss<<"Saved information regarding file: "<<filename<<" in table "<<Table_ROOT_Good<< " id= "<<my_id; |
oss<<"Saved information regarding file: "<<filename<<" in table "<<Table_ROOT_Good<< " id= "<<my_id; |
| 574 |
msg = oss.str(); |
msg = oss.str(); |
| 575 |
mainLogUtil->logInfo(msg); |
mainLogUtil->logInfo(msg); |
| 576 |
|
|
|
//TODO : work on this .... |
|
| 577 |
if(tryMerge){ |
if(tryMerge){ |
| 578 |
merge_ROOTfiles(); |
merge_ROOTfiles(); |
| 579 |
} |
} |
| 585 |
mainLogUtil->logError(msg); |
mainLogUtil->logError(msg); |
| 586 |
} |
} |
| 587 |
|
|
|
//marco_new_31:metto qui se voglio apriree chiudere Connessione solo quando serve |
|
|
//marco_new_01 |
|
| 588 |
if(!single_connection){ |
if(!single_connection){ |
| 589 |
CloseDBConnection(); |
CloseDBConnection(); |
| 590 |
} |
} |
| 592 |
}//pRun |
}//pRun |
| 593 |
} |
} |
| 594 |
|
|
|
|
|
| 595 |
//save in Table_ROOT_Good or in Table_ROOT_Bad |
//save in Table_ROOT_Good or in Table_ROOT_Bad |
| 596 |
bool PacketUser::saveROOT_DB(char* table_name, char* folder_name, char* file_name, |
bool PacketUser::saveROOT_DB(char* table_name, char* folder_name, char* file_name, |
| 597 |
unsigned long int pkt_number_in, unsigned long int pkt_number_fin, |
unsigned long int pkt_number_in, unsigned long int pkt_number_fin, |
| 601 |
unsigned long int mboot_num, |
unsigned long int mboot_num, |
| 602 |
unsigned long int time_offset, |
unsigned long int time_offset, |
| 603 |
int bad_pkt, int bad_pkt_read, int bad_pkt_CalRead, int num_PKT_Saved, |
int bad_pkt, int bad_pkt_read, int bad_pkt_CalRead, int num_PKT_Saved, |
| 604 |
char* nome_input){ |
char* nome_input, bool _time_is_estimated){ |
| 605 |
//TODO: forse far ritornare ID della cosa appena inserita se e' andatato tutto ok invece che true false? |
//TODO: forse far ritornare ID della cosa appena inserita se e' andatato tutto ok invece che true false? |
| 606 |
stringstream oss; |
stringstream oss; |
| 607 |
oss.str(""); |
oss.str(""); |
| 608 |
oss << "INSERT INTO "<< table_name <<" (ID_N, FOLDER_NAME, FILE_NAME, PKT_NUMBER_INIT, PKT_NUMBER_FINAL, PKT_OBT_INIT, PKT_OBT_FINAL, OBT_TIME_SYNC, LAST_TIME_SYNC_INFO, REAL_TIME_INIT, REAL_TIME_LAST, BOOT_NUMBER, TIME_OFFSET,BAD_PKT,BAD_PKT_READ,BAD_PKT_CALREAD,NUM_PKT_SAVED,INPUT_NAME,INSERT_TIME)" |
oss << "INSERT INTO "<< table_name <<" (ID_N, FOLDER_NAME, FILE_NAME, PKT_NUMBER_INIT, PKT_NUMBER_FINAL, PKT_OBT_INIT, PKT_OBT_FINAL, OBT_TIME_SYNC, LAST_TIME_SYNC_INFO, REAL_TIME_INIT, REAL_TIME_LAST, BOOT_NUMBER, TIME_OFFSET,BAD_PKT,BAD_PKT_READ,BAD_PKT_CALREAD,NUM_PKT_SAVED,INPUT_NAME,INSERT_TIME,TIME_IS_ESTIMATED)" |
| 609 |
<< " VALUES ('"<<0<< "','" <<folder_name<<"','" <<file_name<< "','" << pkt_number_in <<"','"<< pkt_number_fin << "','"<< obt_in <<"','"<< obt_fin<< "','" |
<< " VALUES ('"<<0<< "','" <<folder_name<<"','" <<file_name<< "','" << pkt_number_in <<"','"<< pkt_number_fin << "','"<< obt_in <<"','"<< obt_fin<< "','" |
| 610 |
<< oT_sync << "','" << lT_sync_info << "','" |
<< oT_sync << "','" << lT_sync_info << "','" |
| 611 |
<< mtime_init << "','" << mtime_last << "','" |
<< mtime_init << "','" << mtime_last << "','" |
| 612 |
<< mboot_num << "','" |
<< mboot_num << "','" |
| 613 |
<< time_offset << "','" |
<< time_offset << "','" |
| 614 |
<< bad_pkt <<"','" << bad_pkt_read <<"','"<< bad_pkt_CalRead <<"','"<< numPKTSaved<<"','" |
<< bad_pkt <<"','" << bad_pkt_read <<"','"<< bad_pkt_CalRead <<"','"<< num_PKT_Saved<<"','" |
| 615 |
<< nome_input <<"'," |
<< nome_input <<"'," |
| 616 |
<<"NULL"<< |
<<"NULL,"<<_time_is_estimated<< |
| 617 |
")"; |
")"; |
| 618 |
string msg = oss.str(); |
string msg = oss.str(); |
| 619 |
mainLogUtil->logAll(msg); |
mainLogUtil->logAll(msg); |
| 621 |
stringstream oss1; |
stringstream oss1; |
| 622 |
oss1.str()=""; |
oss1.str()=""; |
| 623 |
string msg1; |
string msg1; |
| 624 |
|
string query; |
| 625 |
|
|
| 626 |
TSQLResult* res=NULL; |
TSQLResult* res=NULL; |
| 627 |
res= sqlServer->Query(oss.str().c_str()); |
|
| 628 |
|
query=oss.str(); |
| 629 |
|
msg1="SaveROOT_DB query: "; |
| 630 |
|
msg1 += query; |
| 631 |
|
mainLogUtil->logInfo(msg1); |
| 632 |
|
|
| 633 |
|
res= sqlServer->Query(query.c_str()); |
| 634 |
if(!res) |
if(!res) |
| 635 |
{ |
{ |
| 636 |
oss1<<"DBError UNABLE to: "<<oss.str().c_str()<<endl; |
oss1<<"DBError UNABLE to: "<<oss.str().c_str()<<endl; |
| 639 |
return false; |
return false; |
| 640 |
} |
} |
| 641 |
|
|
|
//marco_new: si pu� ottimizzare ... |
|
| 642 |
//the ID of the current ROOT file in table Table_ROOT_Good |
//the ID of the current ROOT file in table Table_ROOT_Good |
| 643 |
my_id = select_maxIDN_DB(table_name); |
my_id = select_maxIDN_DB(table_name); |
| 644 |
|
if(!boot_number){ |
| 645 |
|
if(id_to_recover_index<1000) |
| 646 |
|
id_to_recover[id_to_recover_index++]=my_id; |
| 647 |
|
}else if (boot_number && id_to_recover_index && !is_new_route){ |
| 648 |
|
recover_boot_number(); |
| 649 |
|
} |
| 650 |
// cout<<"DBG: my_id = "<<my_id<<endl; |
// cout<<"DBG: my_id = "<<my_id<<endl; |
| 651 |
if(res){delete res; res = NULL;} |
if(res){delete res; res = NULL;} |
| 652 |
return true; |
return true; |
| 653 |
} |
} |
| 654 |
|
|
| 655 |
|
|
| 656 |
|
void PacketUser::recover_boot_number(){ |
| 657 |
|
string msg1; |
| 658 |
|
stringstream oss1; |
| 659 |
|
stringstream oss; |
| 660 |
|
oss.str(""); |
| 661 |
|
string query=""; |
| 662 |
|
TSQLResult* res=NULL; |
| 663 |
|
if(!boot_number || !id_to_recover_index) |
| 664 |
|
return; |
| 665 |
|
|
| 666 |
|
for (int i = 0; i<id_to_recover_index;i++){ |
| 667 |
|
oss << "UPDATE "<< Table_ROOT_Good << " SET BOOT_NUMBER=" << boot_number << " WHERE ID_N=" << id_to_recover[i]; |
| 668 |
|
query = oss.str(); |
| 669 |
|
res= sqlServer->Query(query.c_str()); |
| 670 |
|
if(!res) |
| 671 |
|
{ |
| 672 |
|
oss1<<"DBError UNABLE to: "<<query.c_str()<<endl; |
| 673 |
|
msg1=oss1.str(); |
| 674 |
|
mainLogUtil->logError(msg1); |
| 675 |
|
return ; |
| 676 |
|
} |
| 677 |
|
} |
| 678 |
|
|
| 679 |
|
for (int i = 0; i<id_to_recover_index;i++){ |
| 680 |
|
oss << "UPDATE " << Table_ROOT_Merging << " SET BOOT_NUMBER=" << boot_number << " WHERE ROOT_ID_N=" << id_to_recover[i]; |
| 681 |
|
query=oss.str(); |
| 682 |
|
res= sqlServer->Query(query.c_str()); |
| 683 |
|
if(!res) |
| 684 |
|
{ |
| 685 |
|
oss1<<"DBError UNABLE to: "<<query.c_str()<<endl; |
| 686 |
|
msg1=oss1.str(); |
| 687 |
|
mainLogUtil->logError(msg1); |
| 688 |
|
return ; |
| 689 |
|
} |
| 690 |
|
} |
| 691 |
|
|
| 692 |
|
id_to_recover_index=0; |
| 693 |
|
} |
| 694 |
|
|
| 695 |
|
|
| 696 |
|
|
| 697 |
/**********************************************************************************************/ |
/**********************************************************************************************/ |
| 698 |
/*###########################################################################################################*/ |
/*###########################################################################################################*/ |
| 699 |
/********************************** MERGING *************************************************/ |
/********************************** MERGING *************************************************/ |
| 700 |
/*###########################################################################################################*/ |
/*###########################################################################################################*/ |
| 701 |
// Merge ROOT files: found other ROOT files in the same temporal ranges |
// Merge ROT files: find other ROOT files in the same temporal ranges |
| 702 |
// it finds ROOT files that covers particular temporal range of interest and save this info in DB |
// it finds ROOT files that covers particular temporal range of interest and save this info in DB |
| 703 |
/**********************************************************************************************/ |
/**********************************************************************************************/ |
| 704 |
//try to merge current ROOT file with files in DB |
//try to merge current ROOT file with files in DB |
| 705 |
bool PacketUser::merge_ROOTfiles() |
bool PacketUser::merge_ROOTfiles() |
| 706 |
{ |
{ |
| 707 |
mainLogUtil->logInfo("Trying merging ROOT files"); |
stringstream log; |
| 708 |
|
log.str(""); |
| 709 |
|
string slog; |
| 710 |
|
|
| 711 |
//marco_new: controlla |
mainLogUtil->logInfo("Trying merging ROOT files"); |
| 712 |
double percentage=(double)(bad_pkt+bad_pkt_EventReader+bad_pkt_CalibReader)/numPKTSaved; |
double percentage=(double)(bad_pkt+bad_pkt_EventReader+bad_pkt_CalibReader)/numPKTSaved; |
| 713 |
|
|
| 714 |
TSQLResult* res=NULL; |
TSQLResult* res=NULL; |
| 715 |
TSQLRow* row =NULL; |
TSQLRow* row =NULL; |
| 716 |
|
//numero di ROOT files trovati sul DB che hanno relaz di tipo dato |
| 717 |
|
unsigned int num_rows=0; |
| 718 |
|
|
| 719 |
|
//Record su DB: |
| 720 |
|
unsigned int idN = 0; |
| 721 |
|
unsigned int root_id_db=0; |
| 722 |
|
unsigned long int pkt_num_in_db=0; |
| 723 |
|
unsigned long int pkt_num_fin_db=0; |
| 724 |
|
unsigned long int pkt_obt_in_db=0; |
| 725 |
|
unsigned long int pkt_obt_fin_db=0; |
| 726 |
|
unsigned long int time_in_db=0; |
| 727 |
|
unsigned long int time_fin_db=0; |
| 728 |
|
unsigned int boot_num_db=0; |
| 729 |
|
double perc=0; |
| 730 |
|
|
| 731 |
|
|
| 732 |
//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 |
| 733 |
//marco_new: after e before contengono anche smaller ma con un bordo comune |
//marco_new: after e before contengono anche smaller ma con un bordo comune |
| 734 |
for(int relaz=AFTER; relaz<=BIGGER; relaz++) |
for(int relaz=AFTER; relaz<=BIGGER; relaz++) |
| 735 |
{ |
{ |
|
//marco_new: controlla tutto |
|
| 736 |
//marco_new: esci se sono arrivato a zero |
//marco_new: esci se sono arrivato a zero |
| 737 |
if(real_time_last==real_time_init){ |
if(real_time_last==real_time_init) |
| 738 |
|
{ |
| 739 |
|
log.str(""); |
| 740 |
|
log<<"Current File Lenght=0; real_time_last=real_time_init= "<<real_time_last; |
| 741 |
|
slog=log.str(); |
| 742 |
|
mainLogUtil->logAll(slog); |
| 743 |
mainLogUtil->logInfo("Finish merging ROOT files"); |
mainLogUtil->logInfo("Finish merging ROOT files"); |
| 744 |
if(res){delete res; res = NULL;} |
if(res){delete res; res = NULL;} |
| 745 |
if(row){delete row; row = NULL;} |
if(row){delete row; row = NULL;} |
| 746 |
return true; |
return true; |
| 747 |
} |
} |
| 748 |
|
|
| 749 |
res = Select_merging(Table_ROOT_Merging, real_time_init, real_time_last, (type_Rel_ROOT)relaz); |
num_rows=0; |
| 750 |
|
res = Select_merging(Table_ROOT_Merging, real_time_init, real_time_last, (type_Rel_ROOT)relaz); |
| 751 |
|
|
|
unsigned int num_rows=0; |
|
| 752 |
if (!res) |
if (!res) |
| 753 |
{ |
{ |
| 754 |
mainLogUtil->logError("DB_ERROR: Unable to find ROOT files to be merged RES=null"); |
mainLogUtil->logError("DB_ERROR: Unable to find ROOT files to be merged RES=null"); |
| 756 |
} |
} |
| 757 |
|
|
| 758 |
num_rows=res->GetRowCount(); |
num_rows=res->GetRowCount(); |
| 759 |
// cout<<"MMMMM trovati num_rows "<< num_rows<< " per relaz= "<<relaz; |
log.str(""); |
| 760 |
|
log<<"Found "<<num_rows<<" ROOT file in DB with relation of kind = "<<relaz; |
| 761 |
|
slog=log.str(); |
| 762 |
|
mainLogUtil->logAll(slog); |
| 763 |
|
|
| 764 |
if(num_rows>0) |
if(num_rows>0) |
| 765 |
{ |
{ |
| 766 |
for(unsigned int i=0; i<num_rows; i++) |
for(unsigned int i=0; i<num_rows; i++) |
| 767 |
{ |
{ |
| 768 |
row=res->Next(); |
row=res->Next(); |
| 769 |
if (!row) |
if (!row) |
| 770 |
{ |
{ |
| 771 |
mainLogUtil->logError("DB_ERROR: Unable to find ROOT files to be merged. ROW=null"); |
mainLogUtil->logError("DB_ERROR: Unable to find ROOT files to be merged. ROW=null"); |
| 772 |
if(res){delete res; res = NULL;} |
if(res){delete res; res = NULL;} |
| 773 |
return false; |
return false; |
| 774 |
} |
} |
| 775 |
|
|
| 776 |
|
//Leggi Record dal DB: |
| 777 |
//TODO ricavare tutte le info che servono |
idN=atoll(row->GetField(0)); |
| 778 |
unsigned int idN = 0; |
root_id_db=atoll(row->GetField(1)); |
| 779 |
idN=atoi(row->GetField(0)); |
pkt_num_in_db=atoll(row->GetField(2)); |
| 780 |
|
pkt_num_fin_db=atoll(row->GetField(3)); |
| 781 |
double perc =0; |
pkt_obt_in_db=atoll(row->GetField(4)); |
| 782 |
//marco_new: |
pkt_obt_fin_db=atoll(row->GetField(5)); |
| 783 |
|
time_in_db=atoll(row->GetField(6)); |
| 784 |
|
time_fin_db=atoll(row->GetField(7)); |
| 785 |
|
boot_num_db=atoll(row->GetField(8)); |
| 786 |
perc=atof(row->GetField(9)); |
perc=atof(row->GetField(9)); |
| 787 |
//unsigned long int M_pkt_number_in, M_pkt_number_fin, M_obt_in, M_obt_fin, M_mtime_init, M_mtime_last; |
|
| 788 |
if(perc>percentage){ |
log.str(""); |
| 789 |
|
log<<"*** ROOT file found in DB has idN= "<<idN<<" root_id_db= "<<root_id_db; |
| 790 |
|
log<<" pkt_num_in_db= "<<pkt_num_in_db<<" pkt_num_fin_db= "<<pkt_num_fin_db<<" pkt_obt_in_db= "<<pkt_obt_in_db<<" pkt_obt_fin_db= "<<pkt_obt_fin_db; |
| 791 |
|
log<<" time_in_db= "<<time_in_db<<" time_fin_db= "<<time_fin_db<<" boot_num_db= "<<boot_num_db<<" perc= "<<perc<<" ***"; |
| 792 |
|
log<<"\n*** Current ROOT file has pkt_number_init= "<<pkt_number_init<<" obt_init= "<<obt_init<<" real_time_init= "<<real_time_init; |
| 793 |
|
log<<" pkt_number_last= "<<pkt_number_last<<" obt_last= "<<obt_last<<" real_time_last= "<<real_time_last<<" ***"; |
| 794 |
|
slog=log.str(); |
| 795 |
|
mainLogUtil->logAll(slog); |
| 796 |
|
if(perc>percentage) |
| 797 |
|
{ |
| 798 |
mainLogUtil->logInfo("Current ROOT file is better than the one in DB"); |
mainLogUtil->logInfo("Current ROOT file is better than the one in DB"); |
| 799 |
//modifica DB |
//modifica DB |
| 800 |
updateMergeROOT_DB(Table_ROOT_Merging, |
updateMergeROOT_DB(Table_ROOT_Merging, |
| 801 |
atoi(row->GetField(1)), atoi(row->GetField(2)), |
root_id_db, |
| 802 |
atoi(row->GetField(3)), atoi(row->GetField(4)), |
pkt_num_in_db, pkt_num_fin_db, |
| 803 |
atoi(row->GetField(5)), atoi(row->GetField(6)), |
pkt_obt_in_db, pkt_obt_fin_db, |
| 804 |
atoi(row->GetField(7)), atoi(row->GetField(8)), |
time_in_db, time_fin_db, |
| 805 |
perc, |
boot_num_db, |
| 806 |
idN,(type_Rel_ROOT)relaz); |
perc, |
| 807 |
|
idN,(type_Rel_ROOT)relaz); |
| 808 |
} |
} |
| 809 |
else{ |
else |
| 810 |
mainLogUtil->logInfo("Found ROOT files in DB better than current ROOT file"); |
{ |
| 811 |
|
mainLogUtil->logInfo("Found ROOT file in DB is better than current ROOT file"); |
| 812 |
if(relaz == AFTER){ |
if(relaz == AFTER) |
| 813 |
|
{ |
| 814 |
mainLogUtil->logInfo("Relaz:AFTER = Changing Init values of the Current ROOT file"); |
mainLogUtil->logInfo("Relaz:AFTER = Changing Init values of the Current ROOT file"); |
| 815 |
pkt_number_init= atoi(row->GetField(3)); |
pkt_number_init = (pkt_num_fin_db+1); |
| 816 |
obt_init= atoi(row->GetField(5)); |
obt_init = pkt_obt_fin_db; |
| 817 |
real_time_init= atoi(row->GetField(7)); |
real_time_init = time_fin_db; |
| 818 |
|
log.str(""); |
| 819 |
|
log<<"\n*** Current ROOT file becomes: pkt_number_init= "<<pkt_number_init<<" obt_init= "<<obt_init<<" real_time_init= "<<real_time_init; |
| 820 |
|
log<<" pkt_number_last= "<<pkt_number_last<<" obt_last= "<<obt_last<<" real_time_last= "<<real_time_last<<" ***"; |
| 821 |
|
slog=log.str(); |
| 822 |
|
mainLogUtil->logAll(slog); |
| 823 |
} |
} |
| 824 |
else if(relaz == BEFORE){ |
else if(relaz == BEFORE) |
| 825 |
mainLogUtil->logInfo("Relaz:BEFORE = Changing Last values of the Current ROOT file"); |
{ |
| 826 |
pkt_number_last= atoi(row->GetField(2)); |
mainLogUtil->logInfo("Relaz:BEFORE = Changing Last values of the Current ROOT file"); |
| 827 |
obt_last= atoi(row->GetField(4)); |
pkt_number_last = (pkt_num_in_db-1); |
| 828 |
real_time_last= atoi(row->GetField(6)); |
obt_last = pkt_obt_in_db; |
| 829 |
|
real_time_last = time_in_db; |
| 830 |
|
|
| 831 |
|
log.str(""); |
| 832 |
|
log<<"\n*** Current ROOT file becomes: pkt_number_init= "<<pkt_number_init<<" obt_init= "<<obt_init<<" real_time_init= "<<real_time_init; |
| 833 |
|
log<<" pkt_number_last= "<<pkt_number_last<<" obt_last= "<<obt_last<<" real_time_last= "<<real_time_last<<" ***"; |
| 834 |
|
slog=log.str(); |
| 835 |
|
mainLogUtil->logAll(slog); |
| 836 |
} |
} |
| 837 |
else if(relaz == SMALLER) |
else if(relaz == SMALLER) |
| 838 |
{ |
{ |
| 839 |
//non devo proprio salvarlo ed esco ... |
//non devo proprio salvarlo ed esco ... |
| 840 |
mainLogUtil->logInfo("Relaz:SMALLER = Nothing to save"); |
mainLogUtil->logInfo("Relaz:SMALLER = Nothing to save"); |
| 841 |
mainLogUtil->logInfo("Finish merging ROOT files"); |
mainLogUtil->logInfo("\nFinish merging ROOT files"); |
| 842 |
if(res){delete res; res = NULL;} |
if(res){delete res; res = NULL;} |
| 843 |
if(row){delete row; row = NULL;} |
if(row){delete row; row = NULL;} |
| 844 |
return true; |
return true; |
| 845 |
} |
} |
| 846 |
else if(relaz == BIGGER)//spezzettamento |
else if(relaz == BIGGER)//spezzettamento |
| 847 |
{ |
{ |
| 848 |
mainLogUtil->logInfo("Relaz:BIGGER = (1st part) Saving the first part of the Current ROOT file"); |
mainLogUtil->logInfo("Relaz:BIGGER = (1st part) Saving the first part of the Current ROOT file"); |
| 849 |
saveMergeROOT_DB(Table_ROOT_Merging, my_id, |
saveMergeROOT_DB(Table_ROOT_Merging, my_id, |
| 850 |
pkt_number_init, atoi(row->GetField(2)), |
pkt_number_init, (pkt_num_in_db-1), |
| 851 |
obt_init, atoi(row->GetField(4)), |
obt_init, pkt_obt_in_db, |
| 852 |
real_time_init, atoi(row->GetField(6)), |
real_time_init, time_in_db, |
| 853 |
boot_number, |
boot_number, |
| 854 |
percentage); |
percentage); |
| 855 |
|
|
| 856 |
mainLogUtil->logInfo("Relaz:BIGGER = (2nd part)Changing Init values of the Current ROOT file"); |
mainLogUtil->logInfo("Relaz:BIGGER = (2nd part)Changing Init values of the Current ROOT file"); |
| 857 |
pkt_number_init= atoi(row->GetField(3)); |
pkt_number_init = (pkt_num_fin_db+1); |
| 858 |
obt_init= atoi(row->GetField(5)); |
obt_init= pkt_obt_fin_db; |
| 859 |
real_time_init= atoi(row->GetField(7)); |
real_time_init= time_fin_db; |
| 860 |
} |
|
| 861 |
} |
log.str(""); |
| 862 |
|
log<<"\n*** Current ROOT file becomes: pkt_number_init= "<<pkt_number_init<<" obt_init= "<<obt_init<<" real_time_init= "<<real_time_init; |
| 863 |
|
log<<" pkt_number_last= "<<pkt_number_last<<" obt_last= "<<obt_last<<" real_time_last= "<<real_time_last<<" ***"; |
| 864 |
|
slog=log.str(); |
| 865 |
|
mainLogUtil->logAll(slog); |
| 866 |
|
}//if relaz |
| 867 |
|
}//if perc |
| 868 |
}//for num_rows |
}//for num_rows |
| 869 |
} |
}//if num_rows |
|
else{ |
|
|
//marco_new: |
|
|
mainLogUtil->logInfo("Found 0 ROOT files in DB that can be merged with current ROOT file"); |
|
|
|
|
|
} |
|
| 870 |
|
|
|
//marco_new:??? |
|
| 871 |
if(res){delete res; res = NULL;} |
if(res){delete res; res = NULL;} |
| 872 |
if(row){delete row; row = NULL;} |
if(row){delete row; row = NULL;} |
| 873 |
}//for |
|
| 874 |
|
}//for relaz |
| 875 |
|
|
| 876 |
mainLogUtil->logInfo("Saving Current ROOT file"); |
mainLogUtil->logInfo("Saving Current ROOT file"); |
| 877 |
saveMergeROOT_DB(Table_ROOT_Merging, my_id, |
saveMergeROOT_DB(Table_ROOT_Merging, my_id, |
| 881 |
boot_number, |
boot_number, |
| 882 |
percentage); |
percentage); |
| 883 |
|
|
|
|
|
| 884 |
mainLogUtil->logInfo("Finish merging ROOT files"); |
mainLogUtil->logInfo("Finish merging ROOT files"); |
| 885 |
return true; |
return true; |
| 886 |
|
|
| 887 |
} |
} |
| 888 |
|
|
| 889 |
//unsigned int root_id, percentage non le devo modificare |
//unsigned int root_id, percentage non le devo modificare |
| 895 |
unsigned long int mboot_num, |
unsigned long int mboot_num, |
| 896 |
double bad_perc, |
double bad_perc, |
| 897 |
unsigned int ID_record, type_Rel_ROOT type_rel){ |
unsigned int ID_record, type_Rel_ROOT type_rel){ |
|
stringstream oss; |
|
|
oss.str(""); |
|
| 898 |
|
|
| 899 |
|
stringstream oss; |
| 900 |
|
oss.str(""); |
| 901 |
|
|
| 902 |
if(type_rel == AFTER){ |
if(type_rel == AFTER){ |
| 903 |
mainLogUtil->logInfo("Relaz:AFTER = Updating Last values of the DB ROOT file"); |
mainLogUtil->logInfo("Relaz:AFTER = Updating Last values of the DB ROOT file"); |
| 904 |
//marco_new:tolti tutti gli apici che qui non devono essere |
//marco_new:tolti tutti gli apici che qui non devono essere |
| 905 |
oss << "UPDATE "<< table_name |
oss << "UPDATE "<< table_name |
| 906 |
<< " SET PKT_NUMBER_FINAL ="<< pkt_number_init |
<< " SET PKT_NUMBER_FINAL ="<< (pkt_number_init - 1) |
| 907 |
<<", PKT_OBT_FINAL ="<< obt_init |
<<", PKT_OBT_FINAL ="<< obt_init |
| 908 |
<<", REAL_TIME_LAST ="<< real_time_init<<" WHERE ID_N ="<< ID_record <<";"; |
<<", REAL_TIME_LAST ="<< real_time_init<<" WHERE ID_N ="<< ID_record <<";"; |
| 909 |
|
|
| 910 |
} |
} |
| 911 |
else if(type_rel == BEFORE){ |
else if(type_rel == BEFORE){ |
| 912 |
mainLogUtil->logInfo("Relaz:BEFORE = Updating Init values of the DB ROOT file"); |
mainLogUtil->logInfo("Relaz:BEFORE = Updating Init values of the DB ROOT file"); |
| 913 |
oss << "UPDATE "<< table_name |
oss << "UPDATE "<< table_name |
| 914 |
<< " SET PKT_NUMBER_INIT ="<< pkt_number_last |
<< " SET PKT_NUMBER_INIT ="<< (pkt_number_last+1) |
| 915 |
<<", PKT_OBT_INIT ="<< obt_last |
<<", PKT_OBT_INIT ="<< obt_last |
| 916 |
<<", REAL_TIME_INIT ="<< real_time_last<<" WHERE ID_N ="<< ID_record<<";"; |
<<", REAL_TIME_INIT ="<< real_time_last<<" WHERE ID_N ="<< ID_record<<";"; |
| 917 |
} |
} |
| 920 |
mainLogUtil->logInfo("Relaz:SMALLER = (1st part) Updating Last values of the DB ROOT file"); |
mainLogUtil->logInfo("Relaz:SMALLER = (1st part) Updating Last values of the DB ROOT file"); |
| 921 |
|
|
| 922 |
oss << "UPDATE "<< table_name |
oss << "UPDATE "<< table_name |
| 923 |
<< " SET PKT_NUMBER_FINAL="<< pkt_number_init |
<< " SET PKT_NUMBER_FINAL="<< (pkt_number_init-1) |
| 924 |
<<", PKT_OBT_FINAL ="<< obt_init |
<<", PKT_OBT_FINAL ="<< obt_init |
| 925 |
<<", REAL_TIME_LAST ="<< real_time_init<<" WHERE ID_N ="<< ID_record<<";"; |
<<", 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"); |
|
| 926 |
|
|
| 927 |
saveMergeROOT_DB(table_name, root_id, |
mainLogUtil->logInfo("Relaz:SMALLER = (2nd part) Saving the second part of the DB ROOT file"); |
| 928 |
pkt_number_last, pkt_number_fin, |
|
| 929 |
obt_last, obt_fin, |
saveMergeROOT_DB(table_name, root_id, |
| 930 |
real_time_last, mtime_last, |
(pkt_number_last+1), pkt_number_fin, |
| 931 |
mboot_num, |
obt_last, obt_fin, |
| 932 |
bad_perc); |
real_time_last, mtime_last, |
| 933 |
|
mboot_num, |
| 934 |
|
bad_perc); |
| 935 |
} |
} |
| 936 |
else if(type_rel == BIGGER){ |
else if(type_rel == BIGGER){ |
| 937 |
//marco_new: ok anche se coincidenti etc |
//marco_new: ok anche se coincidenti etc |
| 938 |
oss << "DELETE FROM "<< table_name <<" WHERE ID_N ="<< ID_record<<";"; |
oss << "DELETE FROM "<< table_name <<" WHERE ID_N ="<< ID_record<<";"; |
| 939 |
mainLogUtil->logInfo("Rimosso record in Tabella merging"); |
mainLogUtil->logInfo("Record deleted from merging table"); |
| 940 |
} |
} |
| 941 |
else |
else |
| 942 |
return false; |
return false; |
| 943 |
|
|
|
|
|
|
|
|
| 944 |
string msg = oss.str(); |
string msg = oss.str(); |
| 945 |
mainLogUtil->logInfo(msg); |
mainLogUtil->logInfo(msg); |
| 946 |
|
|
| 961 |
return true; |
return true; |
| 962 |
} |
} |
| 963 |
|
|
| 964 |
//marco_new: check here |
//cerca eventuali ROOT files in DB che possono venire mergiati |
| 965 |
|
//marco_new bordi: messo in after a before casi in cui smaller con un bordo in comune |
| 966 |
|
//marco_new bordi: messo in bigger casi con bordi in comune; tra questi anche caso particolare di coincidente |
| 967 |
|
//marco_new bordi: smaller resta solo caso in cui DB e' piu largo sia a dx che a sx |
| 968 |
TSQLResult* PacketUser::Select_merging(char* table_name, unsigned long int mtime_init, unsigned long int mtime_last, type_Rel_ROOT type_rel) |
TSQLResult* PacketUser::Select_merging(char* table_name, unsigned long int mtime_init, unsigned long int mtime_last, type_Rel_ROOT type_rel) |
| 969 |
{ |
{ |
|
|
|
|
// unsigned int idN=0; |
|
| 970 |
TSQLResult* res=NULL; |
TSQLResult* res=NULL; |
| 971 |
stringstream query; |
stringstream query; |
| 972 |
query.str(""); |
query.str(""); |
| 973 |
|
|
|
//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 |
|
| 974 |
if(type_rel == AFTER) |
if(type_rel == AFTER) |
| 975 |
query<<"select * from "<<table_name<<" where REAL_TIME_LAST > "<< mtime_init <<" and REAL_TIME_LAST <= "<< mtime_last <<" and REAL_TIME_INIT < "<< mtime_init; |
query<<"select * from "<<table_name<<" where REAL_TIME_LAST > "<< mtime_init <<" and REAL_TIME_LAST <= "<< mtime_last <<" and REAL_TIME_INIT < "<< mtime_init; |
| 976 |
else if(type_rel == BEFORE) |
else if(type_rel == BEFORE) |
| 983 |
return 0; |
return 0; |
| 984 |
|
|
| 985 |
query<< " order by REAL_TIME_INIT ASC";//marco_new: inutile |
query<< " order by REAL_TIME_INIT ASC";//marco_new: inutile |
| 986 |
|
//se volessi mettere un filtro sulla qualita' |
| 987 |
// query<<" and NUM_PKT_SAVED - BAD_PKT_CALREAD - BAD_PKT_READ - BAD_PKT >= 2" ; |
// query<<" and NUM_PKT_SAVED - BAD_PKT_CALREAD - BAD_PKT_READ - BAD_PKT >= 2" ; |
|
|
|
|
|
|
| 988 |
string msg = query.str(); |
string msg = query.str(); |
| 989 |
mainLogUtil->logAll(msg); |
mainLogUtil->logAll(msg); |
| 990 |
|
res= sqlServer->Query(query.str().c_str()); |
|
res= sqlServer->Query(query.str().c_str()); |
|
|
|
|
| 991 |
stringstream oss1; |
stringstream oss1; |
| 992 |
oss1.str()=""; |
oss1.str()=""; |
| 993 |
string msg1; |
string msg1; |
| 994 |
|
|
| 995 |
if (!res) |
if (!res) |
| 996 |
{ |
{ |
| 1012 |
|
|
| 1013 |
stringstream oss; |
stringstream oss; |
| 1014 |
oss.str(""); |
oss.str(""); |
| 1015 |
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)" |
| 1016 |
<< " VALUES ('"<<0<< "','" <<root_id<<"','"<< pkt_number_in <<"','"<< pkt_number_fin << "','"<< obt_in <<"','"<< obt_fin<< "','" |
<< " VALUES ('"<<0<< "','" <<root_id<<"','"<< pkt_number_in <<"','"<< pkt_number_fin << "','"<< obt_in <<"','"<< obt_fin<< "','" |
| 1017 |
<< mtime_init << "','" << mtime_last << "','" |
<< mtime_init << "','" << mtime_last << "','" |
| 1018 |
<< mboot_num <<"','" |
<< mboot_num <<"','" |
| 1019 |
<< percentage <<"'," |
<< percentage <<"'," |
| 1020 |
<<"NULL"<< |
<<"NULL"<<",'" |
| 1021 |
")"; |
<< tag_value<<"'" |
| 1022 |
|
<< ")"; |
| 1023 |
|
|
| 1024 |
string msg = oss.str(); |
string msg = oss.str(); |
| 1025 |
mainLogUtil->logAll(msg); |
mainLogUtil->logAll(msg); |
| 1026 |
|
|
| 1027 |
//marco_new: controlla |
//marco_new: controlla |
| 1028 |
//marco_new: esci se sono arrivato a zero |
//marco_new: esci se sono arrivato a zero |
| 1029 |
// if(real_time_last==real_time_init){ |
// if(real_time_last==real_time_init){ |
| 1035 |
return true; |
return true; |
| 1036 |
} |
} |
| 1037 |
|
|
|
|
|
| 1038 |
stringstream oss1; |
stringstream oss1; |
| 1039 |
oss1.str()=""; |
oss1.str()=""; |
| 1040 |
string msg1; |
string msg1; |
| 1065 |
stringstream oss; |
stringstream oss; |
| 1066 |
oss.str(""); |
oss.str(""); |
| 1067 |
oss<<"select max(ID_N) from "<<table_name; |
oss<<"select max(ID_N) from "<<table_name; |
| 1068 |
string msg = oss.str(); |
// string msg = oss.str(); |
| 1069 |
mainLogUtil->logAll(msg); |
// mainLogUtil->logAll(msg); |
| 1070 |
res= sqlServer->Query(oss.str().c_str()); |
res= sqlServer->Query(oss.str().c_str()); |
| 1071 |
|
|
| 1072 |
stringstream oss1; |
stringstream oss1; |
| 1094 |
idN=atoi(row->GetField(0)); |
idN=atoi(row->GetField(0)); |
| 1095 |
if(row){delete row; row = NULL;} |
if(row){delete row; row = NULL;} |
| 1096 |
if(res){delete res; res = NULL;} |
if(res){delete res; res = NULL;} |
| 1097 |
|
|
| 1098 |
|
oss<<". idN = "<<idN; |
| 1099 |
|
string msg = oss.str(); |
| 1100 |
|
mainLogUtil->logAll(msg); |
| 1101 |
|
|
| 1102 |
return idN; |
return idN; |
| 1103 |
} |
} |
| 1104 |
|
|
| 1136 |
} |
} |
| 1137 |
|
|
| 1138 |
if(res){delete res; res = NULL;} |
if(res){delete res; res = NULL;} |
| 1139 |
mainLogUtil->logAll("######################### TABLES LOCKED ############################"); |
mainLogUtil->logAll("TABLES LOCKED"); |
| 1140 |
return 0; |
return 0; |
| 1141 |
} |
} |
| 1142 |
|
|
| 1170 |
} |
} |
| 1171 |
|
|
| 1172 |
if(res){delete res; res = NULL;} |
if(res){delete res; res = NULL;} |
| 1173 |
mainLogUtil->logAll("######################### TABLES UNLOCKED ############################"); |
mainLogUtil->logAll("TABLES UNLOCKED"); |
| 1174 |
|
|
| 1175 |
return 0; |
return 0; |
| 1176 |
} |
} |
| 1178 |
/*********************************************************/ |
/*********************************************************/ |
| 1179 |
//marco_new_31 |
//marco_new_31 |
| 1180 |
void PacketUser::OpenDBConnection(char* tableTobeLocked){ |
void PacketUser::OpenDBConnection(char* tableTobeLocked){ |
|
mainLogUtil->logAll("######################### OpenDBConnection ############################"); |
|
| 1181 |
if(do_cont_check){ |
if(do_cont_check){ |
| 1182 |
//controllo che non sia gi� aperta |
//controllo che non sia gia' aperta |
| 1183 |
if(!sqlServer){ |
if(!sqlServer){ |
| 1184 |
sqlServer = TSQLServer::Connect(connection,db_user,db_pwd); |
sqlServer = TSQLServer::Connect(connection,db_user,db_pwd); |
| 1185 |
if ((!sqlServer)||(!(sqlServer->IsConnected()))){cout<<"Can not connect with MYSQL sever"<<endl;} |
if ((!sqlServer)||(!(sqlServer->IsConnected()))){cout<<"Can not connect with MYSQL sever"<<endl;} |
| 1186 |
|
mainLogUtil->logAll("Connected to DB"); |
| 1187 |
//marco_new: blocca tutte le tabelle |
//blocca le tabelle |
| 1188 |
LockTables(tableTobeLocked); |
LockTables(tableTobeLocked); |
|
mainLogUtil->logAll("######################### OpenDBConnection OK ############################"); |
|
| 1189 |
} |
} |
| 1190 |
} |
} |
| 1191 |
|
|
| 1193 |
|
|
| 1194 |
//marco_new_31 |
//marco_new_31 |
| 1195 |
void PacketUser::CloseDBConnection(){ |
void PacketUser::CloseDBConnection(){ |
|
mainLogUtil->logAll("######################### CloseDBConnection ############################"); |
|
| 1196 |
if(do_cont_check){ |
if(do_cont_check){ |
| 1197 |
//controllo che ce ne sia una aperta |
//controllo che ce ne sia una aperta |
| 1198 |
if(sqlServer && sqlServer->IsConnected()){ |
if(sqlServer && sqlServer->IsConnected()){ |
| 1199 |
//marco_new: sblocca tutte le tabelle |
//marco_new: sblocca tutte le tabelle |
| 1200 |
UnLockTables(); |
UnLockTables(); |
| 1201 |
sqlServer->Close(); |
sqlServer->Close(); |
| 1202 |
|
delete sqlServer; |
|
//marco_new_01: ?? |
|
|
delete sqlServer; |
|
|
|
|
| 1203 |
sqlServer=NULL; |
sqlServer=NULL; |
| 1204 |
mainLogUtil->logAll("######################### CloseDBConnection OK ############################"); |
mainLogUtil->logAll("Closed Connection to DB"); |
| 1205 |
} |
} |
| 1206 |
} |
} |
| 1207 |
} |
} |