1 |
//============================================================================ |
//============================================================================ |
2 |
// $Id: PacketUser.cpp,v 1.11 2009/12/30 10:46:33 mocchiut 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" |
650 |
if (!single_connection) { |
if (!single_connection) { |
651 |
CloseDBConnection(); |
CloseDBConnection(); |
652 |
} |
} |
653 |
return; |
// return; // commented here... |
654 |
|
|
655 |
}; |
}; |
656 |
} |
} |
657 |
|
|
658 |
if ( real_time_init || real_time_last) { |
if ( real_time_init || real_time_last) { |
659 |
//saves info in DB in table Table_ROOT |
//saves info in DB in table Table_ROOT |
660 |
if (boot_number == 0) |
if (boot_number == 0) |
661 |
boot_number = boot_number_prevvalue; |
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.str() = ""; |
|
|
oss << "Saved information regarding file: " << filename << " in table " << Table_ROOT_Good << " id= " << my_id; |
|
|
msg = oss.str(); |
|
|
mainLogUtil->logInfo(msg); |
|
662 |
|
|
663 |
if (tryMerge) { |
if (saveROOT_DB( |
664 |
merge_ROOTfiles(); |
Table_ROOT_Good, |
665 |
} |
outDir, // here outDir is good, no expand EMI |
666 |
} else { |
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() = ""; |
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 |
// if dbinfo is not empty than |
686 |
if ( obt_time_sync && last_time_sync_info && arsize > 0 ){ |
if ( arsize > 0 ){ |
|
|
|
687 |
|
|
688 |
// if(!m_dbinfos.empty()){ |
if ( !obt_time_sync || !last_time_sync_info ){ |
689 |
// while(!m_dbinfos.empty()){ |
TString *nomino=new TString(rootfilename); |
690 |
// dbinfo *app = m_dbinfos.back(); |
nomino->Remove(15); |
691 |
// m_dbinfos.pop_back(); |
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 |
Int_t ez=0; |
// |
693 |
while ( ez < arsize ){ |
oss.str() = ""; |
694 |
Int_t eid = idtorecover->At(ez); |
oss << "(EM) Trying to find obt_time_sync and last_time_sync_info from DB, query is: " << qu.Data(); |
695 |
if ( eid > -1 ){ |
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); |
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()); |
TSQLResult *result = sqlServer->Query(qu.Data()); |
723 |
TSQLRow *row = result->Next(); |
TSQLRow *row = result->Next(); |
724 |
|
|
725 |
TString efolder_name=""; |
TString efolder_name=""; |
726 |
TString efile_name=""; |
TString efile_name=""; |
727 |
unsigned long int epkt_number_in=0ULL; |
unsigned long int epkt_number_in=0ULL; |
728 |
unsigned long int epkt_number_fin=0ULL; |
unsigned long int epkt_number_fin=0ULL; |
729 |
unsigned long int eobt_in=0ULL; |
unsigned long int eobt_in=0ULL; |
730 |
unsigned long int eobt_fin=0ULL; |
unsigned long int eobt_fin=0ULL; |
731 |
unsigned long int emboot_num=0ULL; |
unsigned long int emboot_num=0ULL; |
732 |
unsigned long int etime_offset=0ULL; |
unsigned long int etime_offset=0ULL; |
733 |
int ebad_pkt=0; |
int ebad_pkt=0; |
734 |
int ebad_pkt_read=0; |
int ebad_pkt_read=0; |
735 |
int ebad_pkt_CalRead=0; |
int ebad_pkt_CalRead=0; |
736 |
int enum_PKT_Saved=0; |
int enum_PKT_Saved=0; |
737 |
TString enome_input=""; |
TString enome_input=""; |
738 |
bool e_time_is_estimated=false; |
bool e_time_is_estimated=false; |
739 |
|
|
740 |
if ( row ){ |
if ( row ){ |
741 |
efolder_name = (TString)row->GetField(0); |
efolder_name = (TString)row->GetField(0); |
742 |
efile_name = (TString)row->GetField(1); |
efile_name = (TString)row->GetField(1); |
743 |
epkt_number_in = (unsigned long int)atoll(row->GetField(2)); |
epkt_number_in = (unsigned long int)atoll(row->GetField(2)); |
744 |
epkt_number_fin = (unsigned long int)atoll(row->GetField(3)); |
epkt_number_fin = (unsigned long int)atoll(row->GetField(3)); |
745 |
eobt_in = (unsigned long int)atoll(row->GetField(4)); |
eobt_in = (unsigned long int)atoll(row->GetField(4)); |
746 |
eobt_fin = (unsigned long int)atoll(row->GetField(5)); |
eobt_fin = (unsigned long int)atoll(row->GetField(5)); |
747 |
emboot_num = (unsigned long int)atoll(row->GetField(6)); |
emboot_num = (unsigned long int)atoll(row->GetField(6)); |
748 |
etime_offset = (unsigned long int)atoll(row->GetField(7)); |
etime_offset = (unsigned long int)atoll(row->GetField(7)); |
749 |
ebad_pkt = (int)atoi(row->GetField(8)); |
ebad_pkt = (int)atoi(row->GetField(8)); |
750 |
ebad_pkt_read = (int)atoi(row->GetField(9)); |
ebad_pkt_read = (int)atoi(row->GetField(9)); |
751 |
ebad_pkt_CalRead = (int)atoi(row->GetField(10)); |
ebad_pkt_CalRead = (int)atoi(row->GetField(10)); |
752 |
enum_PKT_Saved = (int)atoi(row->GetField(11)); |
enum_PKT_Saved = (int)atoi(row->GetField(11)); |
753 |
enome_input = (TString)row->GetField(12); |
enome_input = (TString)row->GetField(12); |
754 |
e_time_is_estimated = (bool)atoi(row->GetField(13)); |
e_time_is_estimated = (bool)atoi(row->GetField(13)); |
755 |
}; |
}; |
756 |
delete result; |
delete result; |
757 |
|
|
758 |
setReal_TimeRECOVERY( |
setReal_TimeRECOVERY( |
759 |
real_time_init, |
real_time_init, |
760 |
real_time_last, |
real_time_last, |
761 |
eobt_in, |
eobt_in, |
762 |
eobt_fin |
eobt_fin |
763 |
); |
); |
764 |
// |
// |
765 |
|
|
766 |
if (saveROOT_DB( |
if (saveROOT_DB( |
767 |
Table_ROOT_Good, |
Table_ROOT_Good, |
768 |
efolder_name.Data(), |
efolder_name.Data(), |
769 |
efile_name.Data(), |
efile_name.Data(), |
770 |
epkt_number_in, |
epkt_number_in, |
771 |
epkt_number_fin, eobt_in, eobt_fin, obt_time_sync, last_time_sync_info, |
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, |
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) { |
enum_PKT_Saved, enome_input.Data(), e_time_is_estimated) == true) { |
774 |
oss.str() = ""; |
oss.str() = ""; |
775 |
oss << "\nTAG(tassa): RECOVERED!!!! Saved information regarding file: " << efile_name << " in table " << Table_ROOT_Good << " id= " << my_id; |
oss << "\nTAG(tassa): RECOVERED!!!! Saved information regarding file: " << efile_name << " in table " << Table_ROOT_Good << " id= " << my_id; |
776 |
msg = oss.str(); |
msg = oss.str(); |
777 |
mainLogUtil->logInfo(msg); |
mainLogUtil->logInfo(msg); |
778 |
/*merging we use global variable. we haveto set with current value*/ |
/*merging we use global variable. we haveto set with current value*/ |
779 |
|
|
780 |
strcpy(outDir,efolder_name.Data() ); |
strcpy(outDir,efolder_name.Data() ); |
781 |
// outDir=efolder_name.Data(); |
// outDir=efolder_name.Data(); |
782 |
strcpy(filename,efile_name.Data() ); |
strcpy(filename,efile_name.Data() ); |
783 |
// filename=efile_name.Data(); |
// filename=efile_name.Data(); |
784 |
pkt_number_init=epkt_number_in; |
pkt_number_init=epkt_number_in; |
785 |
pkt_number_last=epkt_number_fin; |
pkt_number_last=epkt_number_fin; |
786 |
obt_init=eobt_in; |
obt_init=eobt_in; |
787 |
obt_last=eobt_fin; |
obt_last=eobt_fin; |
788 |
boot_number=emboot_num; |
boot_number=emboot_num; |
789 |
timeOffset=etime_offset; |
timeOffset=etime_offset; |
790 |
bad_pkt=ebad_pkt; |
bad_pkt=ebad_pkt; |
791 |
bad_pkt_EventReader=ebad_pkt_read; |
bad_pkt_EventReader=ebad_pkt_read; |
792 |
bad_pkt_CalibReader=ebad_pkt_CalRead; |
bad_pkt_CalibReader=ebad_pkt_CalRead; |
793 |
numPKTSaved=enum_PKT_Saved; |
numPKTSaved=enum_PKT_Saved; |
794 |
strcpy(fni,enome_input.Data() ); |
strcpy(fni,enome_input.Data() ); |
795 |
// fni=enome_input.Data(); |
// fni=enome_input.Data(); |
796 |
time_is_estimated=e_time_is_estimated; |
time_is_estimated=e_time_is_estimated; |
797 |
|
|
798 |
if (tryMerge) { |
if (tryMerge) { |
799 |
merge_ROOTfiles(); |
merge_ROOTfiles(); |
800 |
} |
} |
801 |
|
|
802 |
TString qu2 = Form("update ROOT_TABLE_BAD set ON_DISK='MVD' where ID_N=%i;",eid); |
TString qu2 = Form("update ROOT_TABLE_BAD set ON_DISK='MVD' where ID_N=%i;",eid); |
803 |
sqlServer->Query(qu2.Data()); |
sqlServer->Query(qu2.Data()); |
804 |
|
|
805 |
|
|
806 |
} |
} |
807 |
else { |
else { |
808 |
oss.str() = ""; |
oss.str() = ""; |
809 |
oss << "Problem storing information in DB regarding file: " << filename; |
oss << "Problem storing information in DB regarding file: " << filename; |
810 |
msg = oss.str(); |
msg = oss.str(); |
811 |
mainLogUtil->logError(msg); |
mainLogUtil->logError(msg); |
812 |
} |
} |
813 |
|
|
814 |
|
|
815 |
}; |
}; |
816 |
ez++; |
ez++; |
817 |
} |
} |
818 |
// |
// |
819 |
idtorecover->Reset(); |
idtorecover->Reset(); |
820 |
delete idtorecover; |
delete idtorecover; |
821 |
idtorecover = new TArrayI(100); |
idtorecover = new TArrayI(100); |
822 |
arsize = 0; |
arsize = 0; |
823 |
// delete app; |
// delete app; |
824 |
} |
}; |
825 |
|
}; |
826 |
|
|
827 |
CleanDisk(); |
CleanDisk(); |
828 |
if (!single_connection) { |
if (!single_connection) { |