1 |
//============================================================================ |
//============================================================================ |
2 |
// $Id: PacketUser.cpp,v 1.8 2009/08/05 18:48:42 pam-fi Exp $ |
// $Id: PacketUser.cpp,v 1.13 2010/01/08 13:36:14 mocchiut Exp $ |
3 |
// Description : |
// Description : |
4 |
//============================================================================ |
//============================================================================ |
5 |
#include "PacketUser.h" |
#include "PacketUser.h" |
6 |
#include <sys/time.h> |
#include <sys/time.h> |
7 |
|
#include <iostream> |
8 |
|
|
9 |
namespace PamOffLineSW { |
namespace PamOffLineSW { |
10 |
extern LogUtil* mainLogUtil; |
extern LogUtil* mainLogUtil; |
21 |
extern unsigned int orbit_number; |
extern unsigned int orbit_number; |
22 |
extern unsigned long int time_Offset; |
extern unsigned long int time_Offset; |
23 |
extern bool tryMerge; |
extern bool tryMerge; |
24 |
|
extern bool candelete; // EM |
25 |
//marco_new_01 |
//marco_new_01 |
26 |
extern bool single_connection; |
extern bool single_connection; |
27 |
|
|
66 |
last_time_sync_info_prevvalue = 0; |
last_time_sync_info_prevvalue = 0; |
67 |
time_is_estimated = false; |
time_is_estimated = false; |
68 |
|
|
69 |
|
//EM |
70 |
|
recoverlimit = 400; |
71 |
|
idtorecover = new TArrayI(100); |
72 |
|
arsize = 0; |
73 |
|
|
74 |
real_time_init = 0; |
real_time_init = 0; |
75 |
real_time_last = 0; |
real_time_last = 0; |
76 |
bad_pkt = 0; |
bad_pkt = 0; |
257 |
//good_pkt_Calib=0; |
//good_pkt_Calib=0; |
258 |
|
|
259 |
//marco_NB: |
//marco_NB: |
260 |
//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 discontinuita` resetto come se mi trovassi in un nuovo download oppure uso i vecchi valori se esistono? |
261 |
|
|
262 |
obt_time_sync_prevvalue = obt_time_sync; |
if ( obt_time_sync ) obt_time_sync_prevvalue = obt_time_sync; // save the last NOT NULL obt_time_sync! EM |
263 |
last_time_sync_info_prevvalue = last_time_sync_info; |
if ( last_time_sync_info ) last_time_sync_info_prevvalue = last_time_sync_info; // save the last NOT NULL last_time_sync |
264 |
time_is_estimated = false; |
time_is_estimated = false; |
265 |
obt_time_sync = 0; |
obt_time_sync = 0; |
266 |
last_time_sync_info = 0; |
last_time_sync_info = 0; |
340 |
} |
} |
341 |
|
|
342 |
//I don't need to retrieve them again if they are good |
//I don't need to retrieve them again if they are good |
343 |
if ((obt_time_sync) || (last_time_sync_info)) |
// if ((obt_time_sync) || (last_time_sync_info)) |
344 |
return; |
// return; |
345 |
|
// no, do it, since there is a (small indeed) time drift due to different clock of PAMELA CPU and RESURS CPU... |
346 |
|
|
347 |
obt_time_sync = (((UINT32) packet[5 + offset] << 24) & 0xFF000000) + (((UINT32) packet[6 + offset] << 16) |
obt_time_sync = (((UINT32) packet[5 + offset] << 24) & 0xFF000000) + (((UINT32) packet[6 + offset] << 16) |
348 |
& 0x00FF0000) + (((UINT32) packet[7 + offset] << 8) & 0x0000FF00) + (((UINT32) packet[8 + offset]) & 0x000000FF); |
& 0x00FF0000) + (((UINT32) packet[7 + offset] << 8) & 0x0000FF00) + (((UINT32) packet[8 + offset]) & 0x000000FF); |
395 |
//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 |
396 |
void PacketUser::setReal_Time() { |
void PacketUser::setReal_Time() { |
397 |
|
|
398 |
if (!obt_time_sync && !last_time_sync_info && numPKTSaved > 1000) { |
if (!obt_time_sync && !last_time_sync_info && numPKTSaved > recoverlimit) { |
399 |
time_is_estimated = true; |
time_is_estimated = true; |
400 |
obt_time_sync = obt_time_sync_prevvalue; |
obt_time_sync = obt_time_sync_prevvalue; |
401 |
last_time_sync_info = last_time_sync_info_prevvalue; |
last_time_sync_info = last_time_sync_info_prevvalue; |
420 |
} |
} |
421 |
} |
} |
422 |
|
|
423 |
|
void PacketUser::setReal_TimeRECOVERY( |
424 |
|
unsigned long int & _real_time_init, |
425 |
|
unsigned long int & _real_time_last, |
426 |
|
unsigned long int _obt_init, |
427 |
|
unsigned long int _obt_last |
428 |
|
) { |
429 |
|
|
430 |
|
if (obt_time_sync || last_time_sync_info) { |
431 |
|
_real_time_init = (_obt_init / 1000 - obt_time_sync) + last_time_sync_info; |
432 |
|
//se obt si e' resettato |
433 |
|
if (_obt_last < _obt_init) { |
434 |
|
_real_time_last = (max_pkt_obt / 1000 + _obt_last / 1000 - obt_time_sync) + last_time_sync_info; |
435 |
|
stringstream oss; |
436 |
|
oss.str() = ""; |
437 |
|
oss << "obt_last(" << obt_last << ") < obt_init(" << obt_init |
438 |
|
<< "). It is due to Pamela Reset. Adding max_pkt_obt(" << max_pkt_obt |
439 |
|
<< ") to obt_last in order to compute real_time_last"; |
440 |
|
string msg = oss.str(); |
441 |
|
mainLogUtil->logWarning(msg); |
442 |
|
} |
443 |
|
else |
444 |
|
_real_time_last = (_obt_last / 1000 - obt_time_sync) + last_time_sync_info; |
445 |
|
_real_time_init += timeOffset; |
446 |
|
_real_time_last += timeOffset; |
447 |
|
} |
448 |
|
} |
449 |
|
|
450 |
|
|
451 |
//timeOffset |
//timeOffset |
452 |
//retrieve from table Table_GL_RESURS_OFFSET timeOffset |
//retrieve from table Table_GL_RESURS_OFFSET timeOffset |
453 |
unsigned long int PacketUser::retrieveTimeOffset(const char * table) { |
unsigned long int PacketUser::retrieveTimeOffset(const char * table) { |
532 |
setReal_Time(); |
setReal_Time(); |
533 |
FinishGroup(rootfilename); |
FinishGroup(rootfilename); |
534 |
mainLogUtil->logAll("######################### Closed the last group ############################"); |
mainLogUtil->logAll("######################### Closed the last group ############################"); |
535 |
|
// |
536 |
if (single_connection) { |
if (single_connection) { |
537 |
CloseDBConnection(); |
CloseDBConnection(); |
538 |
} |
} |
541 |
//Finish the old root file |
//Finish the old root file |
542 |
void PacketUser::FinishGroup(char * filename) { |
void PacketUser::FinishGroup(char * filename) { |
543 |
if (pRun) { |
if (pRun) { |
544 |
pRun->WriteFiles(); |
if ( !( !real_time_init && !real_time_last && numPKTSaved <= recoverlimit ) || !candelete ) pRun->WriteFiles(); |
545 |
delete pRun; |
delete pRun; |
546 |
pRun = NULL; |
pRun = NULL; |
547 |
stringstream close; |
stringstream close; |
548 |
close.str() = ""; |
close.str() = ""; |
549 |
string msg; |
string msg; |
550 |
|
|
551 |
close << "######################### Close group in file: " << rootfilename << " ############################"; |
close << "TAG XX ######################### Close group in file: " << rootfilename << " ############################"; |
552 |
msg = close.str(); |
msg = close.str(); |
553 |
mainLogUtil->logInfo(msg); |
mainLogUtil->logInfo(msg); |
554 |
|
|
567 |
err << "NO PACKET SAVED in file: " << rootfilename << " The group is empty: you can remove this file."; |
err << "NO PACKET SAVED in file: " << rootfilename << " The group is empty: you can remove this file."; |
568 |
msg = err.str(); |
msg = err.str(); |
569 |
mainLogUtil->logError(msg); |
mainLogUtil->logError(msg); |
570 |
return; |
// return; |
571 |
} |
} |
572 |
|
|
573 |
//se non ho salvato nessun pacchetto buono |
//se non ho salvato nessun pacchetto buono |
585 |
OpenDBConnection(NULL);//Nota qui ho deciso di lockare tutte le tabelle |
OpenDBConnection(NULL);//Nota qui ho deciso di lockare tutte le tabelle |
586 |
} |
} |
587 |
|
|
588 |
|
|
589 |
//don't save in Table_ROOT_Good and don't search for ROOT files in the same temporal range |
//don't save in Table_ROOT_Good and don't search for ROOT files in the same temporal range |
590 |
if ((!real_time_init) && (!real_time_last)) { |
if ((!real_time_init) && (!real_time_last)) { |
591 |
//saved in another table for future study |
//saved in another table for future study |
607 |
mainLogUtil->logError(msg); |
mainLogUtil->logError(msg); |
608 |
} |
} |
609 |
|
|
|
if (!single_connection) { |
|
|
CloseDBConnection(); |
|
|
} |
|
|
|
|
|
return; |
|
|
} |
|
610 |
|
|
|
//saves info in DB in table Table_ROOT_Good |
|
|
if (boot_number == 0) |
|
|
boot_number = boot_number_prevvalue; |
|
|
|
|
|
if (saveROOT_DB( |
|
|
Table_ROOT_Good, |
|
|
outDir, // here outDir is good, no expand EMI |
|
|
filename, pkt_number_init, pkt_number_last, obt_init, obt_last, obt_time_sync, last_time_sync_info, |
|
|
real_time_init, real_time_last, boot_number, timeOffset, bad_pkt, bad_pkt_EventReader, bad_pkt_CalibReader, |
|
|
numPKTSaved, fni, time_is_estimated) == true) { |
|
|
oss << "Saved information regarding file: " << filename << " in table " << Table_ROOT_Good << " id= " << my_id; |
|
|
msg = oss.str(); |
|
|
mainLogUtil->logInfo(msg); |
|
611 |
|
|
612 |
if (tryMerge) { |
if ( numPKTSaved > recoverlimit){ // EM |
613 |
merge_ROOTfiles(); |
// |
614 |
} |
if ( obt_time_sync && last_time_sync_info ){ |
615 |
} |
stringstream err; |
616 |
else { |
err.str() = ""; |
617 |
|
err << "(EM): -- RECOVERING WHEN NUMPACKET > "<< recoverlimit <<"!! -- file=<" << filename << ">. We have a previous time sync, immediate recovery!\n"; |
618 |
|
msg = err.str(); |
619 |
|
mainLogUtil->logInfo(msg); |
620 |
|
// |
621 |
|
setReal_TimeRECOVERY( |
622 |
|
real_time_init, |
623 |
|
real_time_last, |
624 |
|
obt_init, |
625 |
|
obt_last |
626 |
|
); |
627 |
|
// |
628 |
|
} else { |
629 |
|
stringstream err; |
630 |
|
err.str() = ""; |
631 |
|
err << "TAG(tassa): -- RECOVERING WHEN NUMPACKET > "<< recoverlimit <<"!! -- file=<" << filename << ">. Saving in a queue to try alfer to recover it!\n"; |
632 |
|
msg = err.str(); |
633 |
|
mainLogUtil->logInfo(msg); |
634 |
|
|
635 |
|
TString qu = Form("select ID_N from ROOT_TABLE_BAD order by INSERT_TIME desc limit 1;"); |
636 |
|
TSQLResult *result = sqlServer->Query(qu.Data()); |
637 |
|
TSQLRow *row = result->Next(); |
638 |
|
Int_t eid = -1; |
639 |
|
if ( row ) eid = (Int_t)atoi(row->GetField(0)); |
640 |
|
idtorecover->AddAt(eid,arsize); |
641 |
|
arsize++; |
642 |
|
if ( arsize > 100 ) idtorecover->Set(arsize); |
643 |
|
// dbinfo *app = new dbinfo( outDir, |
644 |
|
// filename, pkt_number_init, pkt_number_last, obt_init, obt_last, boot_number, timeOffset, bad_pkt, bad_pkt_EventReader, bad_pkt_CalibReader, |
645 |
|
// numPKTSaved, fni, time_is_estimated); |
646 |
|
// m_dbinfos.push_back(app); |
647 |
|
} |
648 |
|
|
649 |
|
CleanDisk(); |
650 |
|
if (!single_connection) { |
651 |
|
CloseDBConnection(); |
652 |
|
} |
653 |
|
// return; // commented here... |
654 |
|
|
655 |
|
}; |
656 |
|
} |
657 |
|
|
658 |
|
if ( real_time_init || real_time_last) { |
659 |
|
//saves info in DB in table Table_ROOT |
660 |
|
if (boot_number == 0) |
661 |
|
boot_number = boot_number_prevvalue; |
662 |
|
|
663 |
|
if (saveROOT_DB( |
664 |
|
Table_ROOT_Good, |
665 |
|
outDir, // here outDir is good, no expand EMI |
666 |
|
filename, pkt_number_init, pkt_number_last, obt_init, obt_last, obt_time_sync, last_time_sync_info, |
667 |
|
real_time_init, real_time_last, boot_number, timeOffset, bad_pkt, bad_pkt_EventReader, bad_pkt_CalibReader, |
668 |
|
numPKTSaved, fni, time_is_estimated) == true) { |
669 |
|
oss.str() = ""; |
670 |
|
oss << "Saved information regarding file: " << filename << " in table " << Table_ROOT_Good << " id= " << my_id; |
671 |
|
msg = oss.str(); |
672 |
|
mainLogUtil->logInfo(msg); |
673 |
|
|
674 |
|
if (tryMerge) { |
675 |
|
merge_ROOTfiles(); |
676 |
|
} |
677 |
|
} else { |
678 |
|
oss.str() = ""; |
679 |
oss << "Problem storing information in DB regarding file: " << filename; |
oss << "Problem storing information in DB regarding file: " << filename; |
680 |
msg = oss.str(); |
msg = oss.str(); |
681 |
mainLogUtil->logError(msg); |
mainLogUtil->logError(msg); |
682 |
} |
} |
683 |
|
}; |
684 |
|
|
685 |
|
// if dbinfo is not empty than |
686 |
|
if ( arsize > 0 ){ |
687 |
|
|
688 |
|
if ( !obt_time_sync || !last_time_sync_info ){ |
689 |
|
TString *nomino=new TString(rootfilename); |
690 |
|
nomino->Remove(15); |
691 |
|
TString qu = Form("select OBT_TIME_SYNC,LAST_TIME_SYNC_INFO from ROOT_TABLE where FILE_NAME like '%s_%%' and (abs(PKT_NUMBER_INIT-%lu)<50000 or abs(PKT_OBT_INIT-%lu)<3000000) limit 1;",nomino->Data(),pkt_number_init,obt_init); |
692 |
|
// |
693 |
|
oss.str() = ""; |
694 |
|
oss << "(EM) Trying to find obt_time_sync and last_time_sync_info from DB, query is: " << qu.Data(); |
695 |
|
msg = oss.str(); |
696 |
|
mainLogUtil->logInfo(msg); |
697 |
|
// |
698 |
|
TSQLResult *result = sqlServer->Query(qu.Data()); |
699 |
|
TSQLRow *row = result->Next(); |
700 |
|
if ( row && result->GetRowCount() == 1 ){ |
701 |
|
obt_time_sync = (unsigned long int)atoll(row->GetField(0)); |
702 |
|
last_time_sync_info = (unsigned long int)atoll(row->GetField(1)); |
703 |
|
oss.str() = ""; |
704 |
|
oss << "(EM) found obt_time_sync and last_time_sync_info from DB! obt_time_sync = " <<obt_time_sync <<" last_time_sync_info = " << last_time_sync_info; |
705 |
|
msg = oss.str(); |
706 |
|
mainLogUtil->logInfo(msg); |
707 |
|
}; |
708 |
|
delete nomino; |
709 |
|
}; |
710 |
|
|
711 |
|
if ( obt_time_sync && last_time_sync_info ){ |
712 |
|
// if(!m_dbinfos.empty()){ |
713 |
|
// while(!m_dbinfos.empty()){ |
714 |
|
// dbinfo *app = m_dbinfos.back(); |
715 |
|
// m_dbinfos.pop_back(); |
716 |
|
Int_t ez=0; |
717 |
|
while ( ez < arsize ){ |
718 |
|
Int_t eid = idtorecover->At(ez); |
719 |
|
if ( eid > -1 ){ |
720 |
|
|
721 |
|
TString qu = Form("select FOLDER_NAME,FILE_NAME,PKT_NUMBER_INIT,PKT_NUMBER_FINAL,PKT_OBT_INIT,PKT_OBT_FINAL,BOOT_NUMBER,TIME_OFFSET,BAD_PKT,BAD_PKT_READ,BAD_PKT_CALREAD,NUM_PKT_SAVED,INPUT_NAME,TIME_IS_ESTIMATED from ROOT_TABLE_BAD where ID_N=%i;",eid); |
722 |
|
TSQLResult *result = sqlServer->Query(qu.Data()); |
723 |
|
TSQLRow *row = result->Next(); |
724 |
|
|
725 |
|
TString efolder_name=""; |
726 |
|
TString efile_name=""; |
727 |
|
unsigned long int epkt_number_in=0ULL; |
728 |
|
unsigned long int epkt_number_fin=0ULL; |
729 |
|
unsigned long int eobt_in=0ULL; |
730 |
|
unsigned long int eobt_fin=0ULL; |
731 |
|
unsigned long int emboot_num=0ULL; |
732 |
|
unsigned long int etime_offset=0ULL; |
733 |
|
int ebad_pkt=0; |
734 |
|
int ebad_pkt_read=0; |
735 |
|
int ebad_pkt_CalRead=0; |
736 |
|
int enum_PKT_Saved=0; |
737 |
|
TString enome_input=""; |
738 |
|
bool e_time_is_estimated=false; |
739 |
|
|
740 |
|
if ( row ){ |
741 |
|
efolder_name = (TString)row->GetField(0); |
742 |
|
efile_name = (TString)row->GetField(1); |
743 |
|
epkt_number_in = (unsigned long int)atoll(row->GetField(2)); |
744 |
|
epkt_number_fin = (unsigned long int)atoll(row->GetField(3)); |
745 |
|
eobt_in = (unsigned long int)atoll(row->GetField(4)); |
746 |
|
eobt_fin = (unsigned long int)atoll(row->GetField(5)); |
747 |
|
emboot_num = (unsigned long int)atoll(row->GetField(6)); |
748 |
|
etime_offset = (unsigned long int)atoll(row->GetField(7)); |
749 |
|
ebad_pkt = (int)atoi(row->GetField(8)); |
750 |
|
ebad_pkt_read = (int)atoi(row->GetField(9)); |
751 |
|
ebad_pkt_CalRead = (int)atoi(row->GetField(10)); |
752 |
|
enum_PKT_Saved = (int)atoi(row->GetField(11)); |
753 |
|
enome_input = (TString)row->GetField(12); |
754 |
|
e_time_is_estimated = (bool)atoi(row->GetField(13)); |
755 |
|
}; |
756 |
|
delete result; |
757 |
|
|
758 |
|
setReal_TimeRECOVERY( |
759 |
|
real_time_init, |
760 |
|
real_time_last, |
761 |
|
eobt_in, |
762 |
|
eobt_fin |
763 |
|
); |
764 |
|
// |
765 |
|
|
766 |
|
if (saveROOT_DB( |
767 |
|
Table_ROOT_Good, |
768 |
|
efolder_name.Data(), |
769 |
|
efile_name.Data(), |
770 |
|
epkt_number_in, |
771 |
|
epkt_number_fin, eobt_in, eobt_fin, obt_time_sync, last_time_sync_info, |
772 |
|
real_time_init, real_time_last, emboot_num, etime_offset, ebad_pkt, ebad_pkt_read, ebad_pkt_CalRead, |
773 |
|
enum_PKT_Saved, enome_input.Data(), e_time_is_estimated) == true) { |
774 |
|
oss.str() = ""; |
775 |
|
oss << "\nTAG(tassa): RECOVERED!!!! Saved information regarding file: " << efile_name << " in table " << Table_ROOT_Good << " id= " << my_id; |
776 |
|
msg = oss.str(); |
777 |
|
mainLogUtil->logInfo(msg); |
778 |
|
/*merging we use global variable. we haveto set with current value*/ |
779 |
|
|
780 |
|
strcpy(outDir,efolder_name.Data() ); |
781 |
|
// outDir=efolder_name.Data(); |
782 |
|
strcpy(filename,efile_name.Data() ); |
783 |
|
// filename=efile_name.Data(); |
784 |
|
pkt_number_init=epkt_number_in; |
785 |
|
pkt_number_last=epkt_number_fin; |
786 |
|
obt_init=eobt_in; |
787 |
|
obt_last=eobt_fin; |
788 |
|
boot_number=emboot_num; |
789 |
|
timeOffset=etime_offset; |
790 |
|
bad_pkt=ebad_pkt; |
791 |
|
bad_pkt_EventReader=ebad_pkt_read; |
792 |
|
bad_pkt_CalibReader=ebad_pkt_CalRead; |
793 |
|
numPKTSaved=enum_PKT_Saved; |
794 |
|
strcpy(fni,enome_input.Data() ); |
795 |
|
// fni=enome_input.Data(); |
796 |
|
time_is_estimated=e_time_is_estimated; |
797 |
|
|
798 |
|
if (tryMerge) { |
799 |
|
merge_ROOTfiles(); |
800 |
|
} |
801 |
|
|
802 |
|
TString qu2 = Form("update ROOT_TABLE_BAD set ON_DISK='MVD' where ID_N=%i;",eid); |
803 |
|
sqlServer->Query(qu2.Data()); |
804 |
|
|
805 |
|
|
806 |
|
} |
807 |
|
else { |
808 |
|
oss.str() = ""; |
809 |
|
oss << "Problem storing information in DB regarding file: " << filename; |
810 |
|
msg = oss.str(); |
811 |
|
mainLogUtil->logError(msg); |
812 |
|
} |
813 |
|
|
814 |
|
|
815 |
|
}; |
816 |
|
ez++; |
817 |
|
} |
818 |
|
// |
819 |
|
idtorecover->Reset(); |
820 |
|
delete idtorecover; |
821 |
|
idtorecover = new TArrayI(100); |
822 |
|
arsize = 0; |
823 |
|
// delete app; |
824 |
|
}; |
825 |
|
}; |
826 |
|
|
827 |
|
CleanDisk(); |
828 |
if (!single_connection) { |
if (!single_connection) { |
829 |
CloseDBConnection(); |
CloseDBConnection(); |
830 |
} |
} |
832 |
}//pRun |
}//pRun |
833 |
} |
} |
834 |
|
|
835 |
|
|
836 |
|
void PacketUser::CleanDisk(){ |
837 |
|
if ( !candelete ) return; |
838 |
|
// |
839 |
|
// delete small files present in root_table_bad from disk: |
840 |
|
// |
841 |
|
TString qu = Form("select FOLDER_NAME,FILE_NAME from ROOT_TABLE_BAD where NUM_PKT_SAVED<=%i and INSERTED_BY='%s' and ON_DISK='YES';",recoverlimit,tag_value); |
842 |
|
TSQLResult *result = sqlServer->Query(qu.Data()); |
843 |
|
TSQLRow *row = result->Next(); |
844 |
|
while ( row ){ |
845 |
|
TString tbdel = (TString)gSystem->ExpandPathName(row->GetField(0))+"/"+ (TString)row->GetField(1); |
846 |
|
stringstream err; |
847 |
|
string msg; |
848 |
|
err.str() = ""; |
849 |
|
err << " Deleting file " << tbdel.Data() << " from disk! "; |
850 |
|
msg = err.str(); |
851 |
|
mainLogUtil->logInfo(msg); |
852 |
|
gSystem->Unlink(tbdel.Data()); |
853 |
|
// printf("ciccio %s \n",tbdel.Data()); |
854 |
|
TString q2u = Form("UPDATE ROOT_TABLE_BAD set ON_DISK='NO' where FOLDER_NAME='%s' and FILE_NAME='%s' and NUM_PKT_SAVED<=%i and INSERTED_BY='%s';",row->GetField(0),row->GetField(1),recoverlimit,tag_value); |
855 |
|
// printf("pluto %s \n",q2u.Data()); |
856 |
|
sqlServer->Query(q2u.Data()); |
857 |
|
// printf("paperoga \n"); |
858 |
|
row=result->Next(); |
859 |
|
// |
860 |
|
}; |
861 |
|
|
862 |
|
} |
863 |
|
|
864 |
//save in Table_ROOT_Good or in Table_ROOT_Bad |
//save in Table_ROOT_Good or in Table_ROOT_Bad |
865 |
bool PacketUser::saveROOT_DB(const char* table_name, char* folder_name, char* file_name, |
bool PacketUser::saveROOT_DB(const char* table_name, const char* folder_name, const char* file_name, |
866 |
unsigned long int pkt_number_in, unsigned long int pkt_number_fin, unsigned long int obt_in, |
unsigned long int pkt_number_in, unsigned long int pkt_number_fin, unsigned long int obt_in, |
867 |
unsigned long int obt_fin, unsigned long int oT_sync, unsigned long int lT_sync_info, unsigned long int mtime_init, |
unsigned long int obt_fin, unsigned long int oT_sync, unsigned long int lT_sync_info, unsigned long int mtime_init, |
868 |
unsigned long int mtime_last, unsigned long int mboot_num, unsigned long int time_offset, int bad_pkt, |
unsigned long int mtime_last, unsigned long int mboot_num, unsigned long int time_offset, int bad_pkt, |
869 |
int bad_pkt_read, int bad_pkt_CalRead, int num_PKT_Saved, char* nome_input, bool _time_is_estimated) { |
int bad_pkt_read, int bad_pkt_CalRead, int num_PKT_Saved, const char* nome_input, bool _time_is_estimated) { |
870 |
//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? |
871 |
stringstream oss; |
stringstream oss; |
872 |
oss.str(""); |
oss.str(""); |
873 |
oss << "INSERT INTO " << table_name |
oss << "INSERT INTO " << table_name |
874 |
<< " (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)" |
<< " (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,INSERTED_BY)" |
875 |
<< " VALUES ('" << 0 << "','" << folder_name << "','" << file_name << "','" << pkt_number_in << "','" |
<< " VALUES ('" << 0 << "','" << folder_name << "','" << file_name << "','" << pkt_number_in << "','" |
876 |
<< pkt_number_fin << "','" << obt_in << "','" << obt_fin << "','" << oT_sync << "','" << lT_sync_info << "','" |
<< pkt_number_fin << "','" << obt_in << "','" << obt_fin << "','" << oT_sync << "','" << lT_sync_info << "','" |
877 |
<< mtime_init << "','" << mtime_last << "','" << mboot_num << "','" << time_offset << "','" << bad_pkt << "','" |
<< mtime_init << "','" << mtime_last << "','" << mboot_num << "','" << time_offset << "','" << bad_pkt << "','" |
878 |
<< bad_pkt_read << "','" << bad_pkt_CalRead << "','" << num_PKT_Saved << "','" << nome_input << "'," << "NULL," |
<< bad_pkt_read << "','" << bad_pkt_CalRead << "','" << num_PKT_Saved << "','" << nome_input << "'," << "NULL," |
879 |
<< _time_is_estimated << ");"; |
<< _time_is_estimated << ",'" << tag_value << "'" << ");"; |
880 |
string msg = oss.str(); |
string msg = oss.str(); |
881 |
mainLogUtil->logAll(msg); |
mainLogUtil->logAll(msg); |
882 |
|
|
900 |
return false; |
return false; |
901 |
} |
} |
902 |
|
|
903 |
//the ID of the current ROOT file in table Table_ROOT_Good |
|
904 |
my_id = select_maxIDN_DB(table_name); |
if(!strcmp(table_name,Table_ROOT_Good)) { |
905 |
if (!boot_number) { |
//the ID of the current ROOT file in table Table_ROOT_Good |
906 |
if (id_to_recover_index < 1000) |
my_id = select_maxIDN_DB(table_name); |
907 |
id_to_recover[id_to_recover_index++] = my_id; |
if (!boot_number) { |
908 |
} |
if (id_to_recover_index < 1000) |
909 |
else if (boot_number && id_to_recover_index && !is_new_route) { |
id_to_recover[id_to_recover_index++] = my_id; |
910 |
recover_boot_number(); |
} |
911 |
|
else if (boot_number && id_to_recover_index && !is_new_route) { |
912 |
|
recover_boot_number(); |
913 |
|
} |
914 |
} |
} |
915 |
// cout<<"DBG: my_id = "<<my_id<<endl; |
// cout<<"DBG: my_id = "<<my_id<<endl; |
916 |
if (res) { |
if (res) { |
1169 |
if (type_rel == AFTER) { |
if (type_rel == AFTER) { |
1170 |
mainLogUtil->logInfo("Relaz:AFTER = Updating Last values of the DB ROOT file"); |
mainLogUtil->logInfo("Relaz:AFTER = Updating Last values of the DB ROOT file"); |
1171 |
//marco_new:tolti tutti gli apici che qui non devono essere |
//marco_new:tolti tutti gli apici che qui non devono essere |
1172 |
|
|
1173 |
|
int good = 1; |
1174 |
|
if ( pkt_number_in >= (pkt_number_init - 1) && abs((int)(pkt_number_in-(pkt_number_init-1)))<10 ) good = 0; |
1175 |
|
|
1176 |
oss << "UPDATE " << table_name << " SET PKT_NUMBER_FINAL =" << (pkt_number_init - 1) << ", PKT_OBT_FINAL =" |
oss << "UPDATE " << table_name << " SET PKT_NUMBER_FINAL =" << (pkt_number_init - 1) << ", PKT_OBT_FINAL =" |
1177 |
<< obt_init << ", REAL_TIME_LAST =" << real_time_init << " WHERE ID_N =" << ID_record << ";"; |
<< obt_init << ", REAL_TIME_LAST =" << real_time_init << ", GOOD="<< good << " WHERE ID_N =" << ID_record << ";"; |
1178 |
|
|
1179 |
} |
} |
1180 |
else if (type_rel == BEFORE) { |
else if (type_rel == BEFORE) { |
1181 |
mainLogUtil->logInfo("Relaz:BEFORE = Updating Init values of the DB ROOT file"); |
mainLogUtil->logInfo("Relaz:BEFORE = Updating Init values of the DB ROOT file"); |
1182 |
|
|
1183 |
|
int good = 1; |
1184 |
|
if ( (pkt_number_last+1) >= pkt_number_fin && abs((int)((pkt_number_last+1)-pkt_number_fin))<10 ) good = 0; |
1185 |
|
|
1186 |
oss << "UPDATE " << table_name << " SET PKT_NUMBER_INIT =" << (pkt_number_last + 1) << ", PKT_OBT_INIT =" |
oss << "UPDATE " << table_name << " SET PKT_NUMBER_INIT =" << (pkt_number_last + 1) << ", PKT_OBT_INIT =" |
1187 |
<< obt_last << ", REAL_TIME_INIT =" << real_time_last << " WHERE ID_N =" << ID_record << ";"; |
<< obt_last << ", REAL_TIME_INIT =" << real_time_last << ", GOOD="<< good << " WHERE ID_N =" << ID_record << ";"; |
1188 |
} |
} |
1189 |
else if (type_rel == SMALLER) { |
else if (type_rel == SMALLER) { |
1190 |
//spezzettamentento |
//spezzettamentento |
1191 |
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"); |
1192 |
|
|
1193 |
|
int good = 1; |
1194 |
|
if ( pkt_number_in >= (pkt_number_init - 1) && abs((int)(pkt_number_in-(pkt_number_init-1)))<10 ) good = 0; |
1195 |
|
|
1196 |
oss << "UPDATE " << table_name << " SET PKT_NUMBER_FINAL=" << (pkt_number_init - 1) << ", PKT_OBT_FINAL =" |
oss << "UPDATE " << table_name << " SET PKT_NUMBER_FINAL=" << (pkt_number_init - 1) << ", PKT_OBT_FINAL =" |
1197 |
<< obt_init << ", REAL_TIME_LAST =" << real_time_init << " WHERE ID_N =" << ID_record << ";"; |
<< obt_init << ", REAL_TIME_LAST =" << real_time_init << ", GOOD="<< good << " WHERE ID_N =" << ID_record << ";"; |
1198 |
|
|
1199 |
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"); |
1200 |
|
|
1257 |
else |
else |
1258 |
return 0; |
return 0; |
1259 |
|
|
1260 |
query << " order by REAL_TIME_INIT ASC";//marco_new: inutile |
query << " order by REAL_TIME_INIT ASC;";//marco_new: inutile |
1261 |
//se volessi mettere un filtro sulla qualita' |
//se volessi mettere un filtro sulla qualita' |
1262 |
// 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" ; |
1263 |
string msg = query.str(); |
string msg = query.str(); |
1280 |
unsigned long int pkt_number_fin, unsigned long int obt_in, unsigned long int obt_fin, |
unsigned long int pkt_number_fin, unsigned long int obt_in, unsigned long int obt_fin, |
1281 |
unsigned long int mtime_init, unsigned long int mtime_last, unsigned long int mboot_num, double percentage) { |
unsigned long int mtime_init, unsigned long int mtime_last, unsigned long int mboot_num, double percentage) { |
1282 |
|
|
1283 |
|
int good = 1; |
1284 |
|
if ( pkt_number_in >= pkt_number_fin && abs((int)(pkt_number_fin-pkt_number_in))<10 ) good = 0; |
1285 |
|
|
1286 |
stringstream oss; |
stringstream oss; |
1287 |
oss.str(""); |
oss.str(""); |
1288 |
oss << "INSERT INTO " << table_name |
oss << "INSERT INTO " << table_name |
1289 |
<< " (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)" |
<< " (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,GOOD)" |
1290 |
<< " VALUES ('" << 0 << "','" << root_id << "','" << pkt_number_in << "','" << pkt_number_fin << "','" << obt_in |
<< " VALUES ('" << 0 << "','" << root_id << "','" << pkt_number_in << "','" << pkt_number_fin << "','" << obt_in |
1291 |
<< "','" << obt_fin << "','" << mtime_init << "','" << mtime_last << "','" << mboot_num << "','" << percentage |
<< "','" << obt_fin << "','" << mtime_init << "','" << mtime_last << "','" << mboot_num << "','" << percentage |
1292 |
<< "'," << "NULL" << ",'" << tag_value << "'" << ")"; |
<< "'," << "NULL" << ",'" << tag_value << "','" << good <<"');"; |
1293 |
|
|
1294 |
string msg = oss.str(); |
string msg = oss.str(); |
1295 |
mainLogUtil->logAll(msg); |
mainLogUtil->logAll(msg); |