|
|
|
| 1 |
//============================================================================ |
//============================================================================ |
| 2 |
// $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 $ |
| 3 |
// Description : |
// Description : |
| 4 |
//============================================================================ |
//============================================================================ |
| 5 |
#include "PacketUser.h" |
#include "PacketUser.h" |
| 35 |
//per tenere conto reset obt |
//per tenere conto reset obt |
| 36 |
extern unsigned long int max_pkt_obt; |
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 |
|
|
| 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]; // Emiliano: che si vuole fare con questa riga? cosi` non fa nulla... |
| 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 |
|
|
| 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, gSystem->ExpandPathName(outDir), multiFile, compression); // EMI |
| 247 |
strcat(rootfilename,".root"); |
strcat(rootfilename,".root"); |
| 248 |
reader->Init(pRun); |
reader->Init(pRun); |
| 249 |
stringstream oss; |
stringstream oss; |
| 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 |
| 325 |
|
|
| 326 |
stringstream oss; |
stringstream oss; |
| 327 |
oss.str()=""; |
oss.str()=""; |
| 328 |
oss<<"In download: "<<download<<" timeOffset: "<<timeOffset<<" obt_time_sync: "<<obt_time_sync<<" last_time_sync_info: "<<last_time_sync_info<<" using Packet Type: "<<type->GetName().c_str(); |
oss<<"In download: "<<download<<" timeOffset: "<<timeOffset<<" obt_time_sync: "<<obt_time_sync<<" last_time_sync_info: "<<last_time_sync_info<<" using Packet Type: "<<type->GetName(); |
| 329 |
|
// oss<<"In download: "<<download<<" timeOffset: "<<timeOffset<<" obt_time_sync: "<<obt_time_sync<<" last_time_sync_info: "<<last_time_sync_info<<" using Packet Type: "<<type->GetName().c_str(); |
| 330 |
string msg = oss.str(); |
string msg = oss.str(); |
| 331 |
mainLogUtil->logAll(msg); |
mainLogUtil->logAll(msg); |
| 332 |
} |
} |
| 352 |
*/ |
*/ |
| 353 |
stringstream oss; |
stringstream oss; |
| 354 |
oss.str()=""; |
oss.str()=""; |
| 355 |
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(); |
| 356 |
|
oss<<"In download: "<<download<<" boot_number: "<<boot_number<<" using Packet Type: "<<type->GetName(); |
| 357 |
string msg = oss.str(); |
string msg = oss.str(); |
| 358 |
mainLogUtil->logAll(msg); |
mainLogUtil->logAll(msg); |
| 359 |
return; |
return; |
| 367 |
//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 |
| 368 |
void PacketUser::setReal_Time() |
void PacketUser::setReal_Time() |
| 369 |
{ |
{ |
| 370 |
if((obt_time_sync)||(last_time_sync_info)) |
|
| 371 |
|
if(!obt_time_sync && !last_time_sync_info && numPKTSaved > 1000 ) |
| 372 |
{ |
{ |
| 373 |
|
time_is_estimated=true; |
| 374 |
real_time_init=(obt_init/1000-obt_time_sync)+last_time_sync_info; |
obt_time_sync=obt_time_sync_prevvalue; |
| 375 |
|
last_time_sync_info=last_time_sync_info_prevvalue; |
| 376 |
|
} |
| 377 |
|
if(obt_time_sync || last_time_sync_info) |
| 378 |
|
{ |
| 379 |
|
real_time_init=(obt_init/1000-obt_time_sync)+last_time_sync_info; |
| 380 |
//se obt si e' resettato |
//se obt si e' resettato |
| 381 |
if(obt_last<obt_init) |
if(obt_last<obt_init) |
| 382 |
{ |
{ |
| 391 |
real_time_last=(obt_last/1000-obt_time_sync)+last_time_sync_info; |
real_time_last=(obt_last/1000-obt_time_sync)+last_time_sync_info; |
| 392 |
real_time_init+=timeOffset; |
real_time_init+=timeOffset; |
| 393 |
real_time_last+=timeOffset; |
real_time_last+=timeOffset; |
|
|
|
|
|
|
| 394 |
} |
} |
| 395 |
} |
} |
| 396 |
|
|
| 431 |
|
|
| 432 |
oss.str(""); |
oss.str(""); |
| 433 |
oss << "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE),ID FROM "<< table <<" WHERE FROM_ORBIT < " |
oss << "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE),ID FROM "<< table <<" WHERE FROM_ORBIT < " |
| 434 |
<< orbit_number << " order by FROM_ORBIT desc limit 1;"; |
<< orbit_number << " AND SPECIAL_FILE='' order by FROM_ORBIT desc limit 1;"; |
| 435 |
|
|
| 436 |
string msg2 = oss.str(); |
string msg2 = oss.str(); |
| 437 |
mainLogUtil->logAll(msg2); |
mainLogUtil->logAll(msg2); |
| 526 |
if((!real_time_init)&&(!real_time_last)) |
if((!real_time_init)&&(!real_time_last)) |
| 527 |
{ |
{ |
| 528 |
//saved in another table for future study |
//saved in another table for future study |
| 529 |
if(saveROOT_DB(Table_ROOT_Bad, outDir, |
if(saveROOT_DB(Table_ROOT_Bad, outDir,// here outDir is good, no expand EMI |
| 530 |
filename, |
filename, |
| 531 |
pkt_number_init, pkt_number_last, |
pkt_number_init, pkt_number_last, |
| 532 |
obt_init, obt_last, |
obt_init, obt_last, |
| 535 |
boot_number, |
boot_number, |
| 536 |
timeOffset, |
timeOffset, |
| 537 |
bad_pkt, bad_pkt_EventReader, bad_pkt_CalibReader, numPKTSaved, |
bad_pkt, bad_pkt_EventReader, bad_pkt_CalibReader, numPKTSaved, |
| 538 |
fni)==true) |
fni,time_is_estimated)==true) |
| 539 |
{ |
{ |
| 540 |
oss.str()=""; |
oss.str()=""; |
| 541 |
oss<<"Saved information regarding file: "<<filename<<" in table "<<Table_ROOT_Bad; |
oss<<"Saved information regarding file: "<<filename<<" in table "<<Table_ROOT_Bad; |
| 558 |
} |
} |
| 559 |
|
|
| 560 |
//saves info in DB in table Table_ROOT_Good |
//saves info in DB in table Table_ROOT_Good |
| 561 |
if(saveROOT_DB(Table_ROOT_Good, outDir, |
if(boot_number==0) |
| 562 |
|
boot_number=boot_number_prevvalue; |
| 563 |
|
|
| 564 |
|
if(saveROOT_DB(Table_ROOT_Good, outDir, // here outDir is good, no expand EMI |
| 565 |
filename, |
filename, |
| 566 |
pkt_number_init, pkt_number_last, |
pkt_number_init, pkt_number_last, |
| 567 |
obt_init, obt_last, |
obt_init, obt_last, |
| 570 |
boot_number, |
boot_number, |
| 571 |
timeOffset, |
timeOffset, |
| 572 |
bad_pkt, bad_pkt_EventReader, bad_pkt_CalibReader, numPKTSaved, |
bad_pkt, bad_pkt_EventReader, bad_pkt_CalibReader, numPKTSaved, |
| 573 |
fni)==true) |
fni,time_is_estimated)==true) |
| 574 |
{ |
{ |
| 575 |
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; |
| 576 |
msg = oss.str(); |
msg = oss.str(); |
| 603 |
unsigned long int mboot_num, |
unsigned long int mboot_num, |
| 604 |
unsigned long int time_offset, |
unsigned long int time_offset, |
| 605 |
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, |
| 606 |
char* nome_input){ |
char* nome_input, bool _time_is_estimated){ |
| 607 |
//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? |
| 608 |
stringstream oss; |
stringstream oss; |
| 609 |
oss.str(""); |
oss.str(""); |
| 610 |
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)" |
| 611 |
<< " 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<< "','" |
| 612 |
<< oT_sync << "','" << lT_sync_info << "','" |
<< oT_sync << "','" << lT_sync_info << "','" |
| 613 |
<< mtime_init << "','" << mtime_last << "','" |
<< mtime_init << "','" << mtime_last << "','" |
| 615 |
<< time_offset << "','" |
<< time_offset << "','" |
| 616 |
<< bad_pkt <<"','" << bad_pkt_read <<"','"<< bad_pkt_CalRead <<"','"<< num_PKT_Saved<<"','" |
<< bad_pkt <<"','" << bad_pkt_read <<"','"<< bad_pkt_CalRead <<"','"<< num_PKT_Saved<<"','" |
| 617 |
<< nome_input <<"'," |
<< nome_input <<"'," |
| 618 |
<<"NULL"<< |
<<"NULL,"<<_time_is_estimated<< |
| 619 |
")"; |
");"; |
| 620 |
string msg = oss.str(); |
string msg = oss.str(); |
| 621 |
mainLogUtil->logAll(msg); |
mainLogUtil->logAll(msg); |
| 622 |
|
|
| 623 |
stringstream oss1; |
stringstream oss1; |
| 624 |
oss1.str()=""; |
oss1.str()=""; |
| 625 |
string msg1; |
string msg1; |
| 626 |
|
string query; |
| 627 |
|
|
| 628 |
TSQLResult* res=NULL; |
TSQLResult* res=NULL; |
| 629 |
res= sqlServer->Query(oss.str().c_str()); |
|
| 630 |
|
query=oss.str(); |
| 631 |
|
msg1="SaveROOT_DB query: "; |
| 632 |
|
msg1 += query; |
| 633 |
|
mainLogUtil->logInfo(msg1); |
| 634 |
|
|
| 635 |
|
res= sqlServer->Query(query.c_str()); |
| 636 |
if(!res) |
if(!res) |
| 637 |
{ |
{ |
| 638 |
oss1<<"DBError UNABLE to: "<<oss.str().c_str()<<endl; |
oss1<<"DBError UNABLE to: "<<oss.str().c_str()<<endl; |
| 643 |
|
|
| 644 |
//the ID of the current ROOT file in table Table_ROOT_Good |
//the ID of the current ROOT file in table Table_ROOT_Good |
| 645 |
my_id = select_maxIDN_DB(table_name); |
my_id = select_maxIDN_DB(table_name); |
| 646 |
|
if(!boot_number){ |
| 647 |
|
if(id_to_recover_index<1000) |
| 648 |
|
id_to_recover[id_to_recover_index++]=my_id; |
| 649 |
|
}else if (boot_number && id_to_recover_index && !is_new_route){ |
| 650 |
|
recover_boot_number(); |
| 651 |
|
} |
| 652 |
// cout<<"DBG: my_id = "<<my_id<<endl; |
// cout<<"DBG: my_id = "<<my_id<<endl; |
| 653 |
if(res){delete res; res = NULL;} |
if(res){delete res; res = NULL;} |
| 654 |
return true; |
return true; |
| 655 |
} |
} |
| 656 |
|
|
| 657 |
|
|
| 658 |
|
void PacketUser::recover_boot_number(){ |
| 659 |
|
string msg1; |
| 660 |
|
stringstream oss1; |
| 661 |
|
stringstream oss; |
| 662 |
|
oss.str(""); |
| 663 |
|
string query=""; |
| 664 |
|
TSQLResult* res=NULL; |
| 665 |
|
if(!boot_number || !id_to_recover_index) |
| 666 |
|
return; |
| 667 |
|
|
| 668 |
|
for (int i = 0; i<id_to_recover_index;i++){ |
| 669 |
|
oss.str(""); |
| 670 |
|
oss << "UPDATE "<< Table_ROOT_Good << " SET BOOT_NUMBER=" << boot_number << " WHERE ID_N=" << id_to_recover[i] << ";"; |
| 671 |
|
query = oss.str(); |
| 672 |
|
res= sqlServer->Query(query.c_str()); |
| 673 |
|
if(!res) |
| 674 |
|
{ |
| 675 |
|
oss1<<"DBError UNABLE to: "<<query.c_str()<<endl; |
| 676 |
|
msg1=oss1.str(); |
| 677 |
|
mainLogUtil->logError(msg1); |
| 678 |
|
return ; |
| 679 |
|
} |
| 680 |
|
} |
| 681 |
|
|
| 682 |
|
for (int i = 0; i<id_to_recover_index;i++){ |
| 683 |
|
oss.str(""); |
| 684 |
|
oss << "UPDATE " << Table_ROOT_Merging << " SET BOOT_NUMBER=" << boot_number << " WHERE ROOT_ID_N=" << id_to_recover[i] << ";"; |
| 685 |
|
query=oss.str(); |
| 686 |
|
res= sqlServer->Query(query.c_str()); |
| 687 |
|
if(!res) |
| 688 |
|
{ |
| 689 |
|
oss1<<"DBError UNABLE to: "<<query.c_str()<<endl; |
| 690 |
|
msg1=oss1.str(); |
| 691 |
|
mainLogUtil->logError(msg1); |
| 692 |
|
return ; |
| 693 |
|
} |
| 694 |
|
} |
| 695 |
|
|
| 696 |
|
id_to_recover_index=0; |
| 697 |
|
} |
| 698 |
|
|
| 699 |
|
|
| 700 |
|
|
| 701 |
/**********************************************************************************************/ |
/**********************************************************************************************/ |
| 702 |
/*###########################################################################################################*/ |
/*###########################################################################################################*/ |
| 703 |
/********************************** MERGING *************************************************/ |
/********************************** MERGING *************************************************/ |
| 704 |
/*###########################################################################################################*/ |
/*###########################################################################################################*/ |
| 705 |
// Merge ROOT files: find other ROOT files in the same temporal ranges |
// Merge ROT files: find other ROOT files in the same temporal ranges |
| 706 |
// 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 |
| 707 |
/**********************************************************************************************/ |
/**********************************************************************************************/ |
| 708 |
//try to merge current ROOT file with files in DB |
//try to merge current ROOT file with files in DB |
| 816 |
if(relaz == AFTER) |
if(relaz == AFTER) |
| 817 |
{ |
{ |
| 818 |
mainLogUtil->logInfo("Relaz:AFTER = Changing Init values of the Current ROOT file"); |
mainLogUtil->logInfo("Relaz:AFTER = Changing Init values of the Current ROOT file"); |
| 819 |
pkt_number_init = pkt_num_fin_db; |
pkt_number_init = (pkt_num_fin_db+1); |
| 820 |
obt_init = pkt_obt_fin_db; |
obt_init = pkt_obt_fin_db; |
| 821 |
real_time_init = time_fin_db; |
real_time_init = time_fin_db; |
| 822 |
log.str(""); |
log.str(""); |
| 828 |
else if(relaz == BEFORE) |
else if(relaz == BEFORE) |
| 829 |
{ |
{ |
| 830 |
mainLogUtil->logInfo("Relaz:BEFORE = Changing Last values of the Current ROOT file"); |
mainLogUtil->logInfo("Relaz:BEFORE = Changing Last values of the Current ROOT file"); |
| 831 |
pkt_number_last = pkt_num_in_db; |
pkt_number_last = (pkt_num_in_db-1); |
| 832 |
obt_last = pkt_obt_in_db; |
obt_last = pkt_obt_in_db; |
| 833 |
real_time_last = time_in_db; |
real_time_last = time_in_db; |
| 834 |
|
|
| 851 |
{ |
{ |
| 852 |
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"); |
| 853 |
saveMergeROOT_DB(Table_ROOT_Merging, my_id, |
saveMergeROOT_DB(Table_ROOT_Merging, my_id, |
| 854 |
pkt_number_init, pkt_num_in_db, |
pkt_number_init, (pkt_num_in_db-1), |
| 855 |
obt_init, pkt_obt_in_db, |
obt_init, pkt_obt_in_db, |
| 856 |
real_time_init, time_in_db, |
real_time_init, time_in_db, |
| 857 |
boot_number, |
boot_number, |
| 858 |
percentage); |
percentage); |
| 859 |
|
|
| 860 |
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"); |
| 861 |
pkt_number_init = pkt_num_fin_db; |
pkt_number_init = (pkt_num_fin_db+1); |
| 862 |
obt_init= pkt_obt_fin_db; |
obt_init= pkt_obt_fin_db; |
| 863 |
real_time_init= time_fin_db; |
real_time_init= time_fin_db; |
| 864 |
|
|
| 907 |
mainLogUtil->logInfo("Relaz:AFTER = Updating Last values of the DB ROOT file"); |
mainLogUtil->logInfo("Relaz:AFTER = Updating Last values of the DB ROOT file"); |
| 908 |
//marco_new:tolti tutti gli apici che qui non devono essere |
//marco_new:tolti tutti gli apici che qui non devono essere |
| 909 |
oss << "UPDATE "<< table_name |
oss << "UPDATE "<< table_name |
| 910 |
<< " SET PKT_NUMBER_FINAL ="<< pkt_number_init |
<< " SET PKT_NUMBER_FINAL ="<< (pkt_number_init - 1) |
| 911 |
<<", PKT_OBT_FINAL ="<< obt_init |
<<", PKT_OBT_FINAL ="<< obt_init |
| 912 |
<<", REAL_TIME_LAST ="<< real_time_init<<" WHERE ID_N ="<< ID_record <<";"; |
<<", REAL_TIME_LAST ="<< real_time_init<<" WHERE ID_N ="<< ID_record <<";"; |
| 913 |
|
|
| 915 |
else if(type_rel == BEFORE){ |
else if(type_rel == BEFORE){ |
| 916 |
mainLogUtil->logInfo("Relaz:BEFORE = Updating Init values of the DB ROOT file"); |
mainLogUtil->logInfo("Relaz:BEFORE = Updating Init values of the DB ROOT file"); |
| 917 |
oss << "UPDATE "<< table_name |
oss << "UPDATE "<< table_name |
| 918 |
<< " SET PKT_NUMBER_INIT ="<< pkt_number_last |
<< " SET PKT_NUMBER_INIT ="<< (pkt_number_last+1) |
| 919 |
<<", PKT_OBT_INIT ="<< obt_last |
<<", PKT_OBT_INIT ="<< obt_last |
| 920 |
<<", REAL_TIME_INIT ="<< real_time_last<<" WHERE ID_N ="<< ID_record<<";"; |
<<", REAL_TIME_INIT ="<< real_time_last<<" WHERE ID_N ="<< ID_record<<";"; |
| 921 |
} |
} |
| 924 |
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"); |
| 925 |
|
|
| 926 |
oss << "UPDATE "<< table_name |
oss << "UPDATE "<< table_name |
| 927 |
<< " SET PKT_NUMBER_FINAL="<< pkt_number_init |
<< " SET PKT_NUMBER_FINAL="<< (pkt_number_init-1) |
| 928 |
<<", PKT_OBT_FINAL ="<< obt_init |
<<", PKT_OBT_FINAL ="<< obt_init |
| 929 |
<<", REAL_TIME_LAST ="<< real_time_init<<" WHERE ID_N ="<< ID_record<<";"; |
<<", REAL_TIME_LAST ="<< real_time_init<<" WHERE ID_N ="<< ID_record<<";"; |
| 930 |
|
|
| 931 |
mainLogUtil->logInfo("Relaz:SMALLER = (2nd part) Saving the second part of the DB ROOT file"); |
mainLogUtil->logInfo("Relaz:SMALLER = (2nd part) Saving the second part of the DB ROOT file"); |
| 932 |
|
|
| 933 |
saveMergeROOT_DB(table_name, root_id, |
saveMergeROOT_DB(table_name, root_id, |
| 934 |
pkt_number_last, pkt_number_fin, |
(pkt_number_last+1), pkt_number_fin, |
| 935 |
obt_last, obt_fin, |
obt_last, obt_fin, |
| 936 |
real_time_last, mtime_last, |
real_time_last, mtime_last, |
| 937 |
mboot_num, |
mboot_num, |
| 939 |
} |
} |
| 940 |
else if(type_rel == BIGGER){ |
else if(type_rel == BIGGER){ |
| 941 |
//marco_new: ok anche se coincidenti etc |
//marco_new: ok anche se coincidenti etc |
| 942 |
oss << "DELETE FROM "<< table_name <<" WHERE ID_N ="<< ID_record<<";"; |
// oss << "DELETE FROM "<< table_name <<" WHERE ID_N ="<< ID_record<<";"; // EMILIANO |
| 943 |
|
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 |
| 944 |
mainLogUtil->logInfo("Record deleted from merging table"); |
mainLogUtil->logInfo("Record deleted from merging table"); |
| 945 |
} |
} |
| 946 |
else |
else |
| 977 |
query.str(""); |
query.str(""); |
| 978 |
|
|
| 979 |
if(type_rel == AFTER) |
if(type_rel == AFTER) |
| 980 |
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 GOOD=1 and REAL_TIME_LAST > "<< mtime_init <<" and REAL_TIME_LAST <= "<< mtime_last <<" and REAL_TIME_INIT < "<< mtime_init; // EMI |
| 981 |
else if(type_rel == BEFORE) |
else if(type_rel == BEFORE) |
| 982 |
query<<"select * from "<<table_name<<" where REAL_TIME_INIT >= "<< mtime_init <<" and REAL_TIME_INIT < "<< mtime_last <<" and REAL_TIME_LAST > "<< mtime_last; |
query<<"select * from "<<table_name<<" where GOOD=1 and REAL_TIME_INIT >= "<< mtime_init <<" and REAL_TIME_INIT < "<< mtime_last <<" and REAL_TIME_LAST > "<< mtime_last; // EMI |
| 983 |
else if(type_rel == SMALLER) |
else if(type_rel == SMALLER) |
| 984 |
query<<"select * from "<<table_name<<" where REAL_TIME_INIT < "<< mtime_init <<" and REAL_TIME_LAST > "<< mtime_last; |
query<<"select * from "<<table_name<<" where GOOD=1 and REAL_TIME_INIT < "<< mtime_init <<" and REAL_TIME_LAST > "<< mtime_last; // EMI |
| 985 |
else if(type_rel == BIGGER) |
else if(type_rel == BIGGER) |
| 986 |
query<<"select * from "<<table_name<<" where REAL_TIME_INIT >= "<< mtime_init <<" and REAL_TIME_LAST <= "<< mtime_last; |
query<<"select * from "<<table_name<<" where GOOD=1 and REAL_TIME_INIT >= "<< mtime_init <<" and REAL_TIME_LAST <= "<< mtime_last; // EMI |
| 987 |
else |
else |
| 988 |
return 0; |
return 0; |
| 989 |
|
|
| 1017 |
|
|
| 1018 |
stringstream oss; |
stringstream oss; |
| 1019 |
oss.str(""); |
oss.str(""); |
| 1020 |
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)" |
| 1021 |
<< " 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<< "','" |
| 1022 |
<< mtime_init << "','" << mtime_last << "','" |
<< mtime_init << "','" << mtime_last << "','" |
| 1023 |
<< mboot_num <<"','" |
<< mboot_num <<"','" |
| 1024 |
<< percentage <<"'," |
<< percentage <<"'," |
| 1025 |
<<"NULL"<< |
<<"NULL"<<",'" |
| 1026 |
")"; |
<< tag_value<<"'" |
| 1027 |
|
<< ")"; |
| 1028 |
|
|
| 1029 |
string msg = oss.str(); |
string msg = oss.str(); |
| 1030 |
mainLogUtil->logAll(msg); |
mainLogUtil->logAll(msg); |
| 1031 |
|
|
|
|
|
| 1032 |
//marco_new: controlla |
//marco_new: controlla |
| 1033 |
//marco_new: esci se sono arrivato a zero |
//marco_new: esci se sono arrivato a zero |
| 1034 |
// if(real_time_last==real_time_init){ |
// if(real_time_last==real_time_init){ |
| 1237 |
{ |
{ |
| 1238 |
char fno[80]=""; |
char fno[80]=""; |
| 1239 |
ofstream fout; |
ofstream fout; |
| 1240 |
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 |
| 1241 |
|
|
| 1242 |
if(append==true) |
if(append==true) |
| 1243 |
fout.open(fno, ios::binary | ios::app); |
fout.open(fno, ios::binary | ios::app); |
| 1257 |
ofstream fout; |
ofstream fout; |
| 1258 |
if(append==true) |
if(append==true) |
| 1259 |
{ |
{ |
| 1260 |
sprintf(fno,"%s/packets.pkt", outDir); |
sprintf(fno,"%s/packets.pkt", gSystem->ExpandPathName(outDir)); // EMI |
| 1261 |
fout.open(fno, ios::binary | ios::app); |
fout.open(fno, ios::binary | ios::app); |
| 1262 |
} |
} |
| 1263 |
else{ |
else{ |
| 1264 |
sprintf(fno,"%s/packet%d.pkt", outDir, numPKT ); |
sprintf(fno,"%s/packet%d.pkt", gSystem->ExpandPathName(outDir), numPKT ); // EMI |
| 1265 |
fout.open(fno, ios::binary); |
fout.open(fno, ios::binary); |
| 1266 |
} |
} |
| 1267 |
|
|