| 1 |
//============================================================================ |
//============================================================================ |
| 2 |
// $Id: PacketUser.cpp,v 1.6 2008/12/23 20:43:08 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" |
| 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; |
| 11 |
extern short compression ; |
extern short compression; |
| 12 |
extern char *outDir; |
extern char *outDir; |
| 13 |
extern TSQLServer *sqlServer; |
extern TSQLServer *sqlServer; |
| 14 |
extern bool multiFile; |
extern bool multiFile; |
| 15 |
extern char* fni; |
extern char* fni; |
| 17 |
extern bool is_new_route; |
extern bool is_new_route; |
| 18 |
extern unsigned int download; |
extern unsigned int download; |
| 19 |
|
|
| 20 |
extern unsigned int mmm_number; |
extern unsigned int mmm_number; |
| 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 |
|
|
| 29 |
extern bool do_cont_check; |
extern bool do_cont_check; |
| 30 |
|
|
| 31 |
//marco_new_31: |
//marco_new_31: |
| 32 |
extern char* db_user; |
extern char* db_user; |
| 33 |
extern char* db_pwd; |
extern char* db_pwd; |
| 34 |
extern char* connection; |
extern char* connection; |
| 35 |
|
|
| 36 |
//per tenere conto reset obt |
//per tenere conto reset obt |
| 37 |
extern unsigned long int max_pkt_obt; |
extern unsigned long int max_pkt_obt; |
| 38 |
|
|
| 39 |
#define TAGVALUELEN 4 |
#define TAGVALUELEN 4 |
| 40 |
extern char tag_value[TAGVALUELEN]; |
extern char tag_value[TAGVALUELEN]; |
| 41 |
|
|
| 42 |
PacketUser PacketUser::instance; |
PacketUser PacketUser::instance; |
|
|
|
|
int PacketUser::numDiscontinity=1; |
|
|
int PacketUser::numPKT=0; |
|
|
int PacketUser::numPKTSaved=0; |
|
|
|
|
|
PacketUser& PacketUser::getInstance() |
|
|
{ |
|
|
return instance; |
|
|
} |
|
|
|
|
|
PacketUser::PacketUser() |
|
|
{ |
|
|
gROOT->SetBatch(kTRUE); |
|
|
numDiscontinity=1; |
|
|
numPKTSaved=0; |
|
|
numPKT=0; |
|
|
pkt_number_init=0; |
|
|
obt_init=0; |
|
|
pkt_number_last=0; |
|
|
obt_last=0; |
|
|
obt_time_sync=0; |
|
|
last_time_sync_info=0; |
|
|
|
|
|
//(tassa) |
|
|
obt_time_sync_prevvalue=0; |
|
|
last_time_sync_info_prevvalue=0; |
|
|
time_is_estimated=false; |
|
|
|
|
| 43 |
|
|
| 44 |
real_time_init=0; |
int PacketUser::numDiscontinity = 1; |
| 45 |
real_time_last=0; |
int PacketUser::numPKT = 0; |
| 46 |
bad_pkt=0; |
int PacketUser::numPKTSaved = 0; |
| 47 |
bad_pkt_EventReader=0; |
|
| 48 |
bad_pkt_CalibReader=0; |
PacketUser& PacketUser::getInstance() { |
| 49 |
reader= NULL; |
return instance; |
| 50 |
pRun=NULL; |
} |
| 51 |
reader=new pamela::techmodel::EventReader(); |
|
| 52 |
Table_ROOT_Good="ROOT_TABLE"; |
PacketUser::PacketUser() { |
| 53 |
Table_ROOT_Bad="ROOT_TABLE_BAD"; |
gROOT->SetBatch(kTRUE); |
| 54 |
Table_GL_RESURS_OFFSET="GL_RESURS_OFFSET"; |
numDiscontinity = 1; |
| 55 |
Table_ROOT_Merging="ROOT_TABLE_MERGING"; |
numPKTSaved = 0; |
| 56 |
// good_pkt_Calib=0; |
numPKT = 0; |
| 57 |
my_id=0; |
pkt_number_init = 0; |
| 58 |
boot_number=0; |
obt_init = 0; |
| 59 |
//(tassa) |
pkt_number_last = 0; |
| 60 |
boot_number_prevvalue=0; |
obt_last = 0; |
| 61 |
|
obt_time_sync = 0; |
| 62 |
//(tassa) |
last_time_sync_info = 0; |
| 63 |
// id_to_recover[1000]; // Emiliano: che si vuole fare con questa riga? cosi` non fa nulla... |
|
| 64 |
id_to_recover_index=0; |
//(tassa) |
| 65 |
} |
obt_time_sync_prevvalue = 0; |
| 66 |
|
last_time_sync_info_prevvalue = 0; |
| 67 |
PacketUser::~PacketUser() |
time_is_estimated = false; |
| 68 |
{ |
|
| 69 |
if(reader){delete reader; reader = NULL;} |
//EM |
| 70 |
numDiscontinity=1; |
recoverlimit = 400; |
| 71 |
numPKTSaved=0; |
idtorecover = new TArrayI(100); |
| 72 |
numPKT=0; |
arsize = 0; |
| 73 |
pkt_number_init=0; |
|
| 74 |
obt_init=0; |
real_time_init = 0; |
| 75 |
pkt_number_last=0; |
real_time_last = 0; |
| 76 |
obt_last=0; |
bad_pkt = 0; |
| 77 |
obt_time_sync = 0; |
bad_pkt_EventReader = 0; |
| 78 |
last_time_sync_info = 0; |
bad_pkt_CalibReader = 0; |
| 79 |
obt_time_sync_prevvalue=0; |
reader = NULL; |
| 80 |
last_time_sync_info_prevvalue=0; |
pRun = NULL; |
| 81 |
time_is_estimated=false; |
reader = new pamela::techmodel::EventReader(); |
| 82 |
|
Table_ROOT_Good = "ROOT_TABLE"; |
| 83 |
real_time_init=0; |
Table_ROOT_Bad = "ROOT_TABLE_BAD"; |
| 84 |
real_time_last=0; |
Table_GL_RESURS_OFFSET = "GL_RESURS_OFFSET"; |
| 85 |
bad_pkt=0; |
Table_ROOT_Merging = "ROOT_TABLE_MERGING"; |
| 86 |
bad_pkt_EventReader=0; |
// good_pkt_Calib=0; |
| 87 |
bad_pkt_CalibReader=0; |
my_id = 0; |
| 88 |
// good_pkt_Calib=0; |
boot_number = 0; |
| 89 |
my_id=0; |
//(tassa) |
| 90 |
boot_number=0; |
boot_number_prevvalue = 0; |
| 91 |
boot_number_prevvalue=0; |
|
| 92 |
} |
//(tassa) |
| 93 |
|
// id_to_recover[1000]; // Emiliano: che si vuole fare con questa riga? cosi` non fa nulla... |
| 94 |
|
id_to_recover_index = 0; |
| 95 |
//Put the packet in a root file. Create a new ROOT file for each group of packets |
} |
| 96 |
void PacketUser::usePKT(char*& headerPkt, char*& pamPkt, long int length, bool isCons, bool isPKTGood, const PacketType* type, |
|
| 97 |
unsigned long int counter, unsigned long int obt) |
PacketUser::~PacketUser() { |
| 98 |
{ |
if (reader) { |
| 99 |
//If the packet type was not recognised before |
delete reader; |
| 100 |
if(!type){return;} |
reader = NULL; |
| 101 |
|
} |
| 102 |
//in order to start ... |
numDiscontinity = 1; |
| 103 |
if(numPKT==0) |
numPKTSaved = 0; |
| 104 |
{ |
numPKT = 0; |
| 105 |
if(single_connection){ |
pkt_number_init = 0; |
| 106 |
OpenDBConnection(NULL); |
obt_init = 0; |
| 107 |
} |
pkt_number_last = 0; |
| 108 |
|
obt_last = 0; |
| 109 |
|
obt_time_sync = 0; |
| 110 |
|
last_time_sync_info = 0; |
| 111 |
|
obt_time_sync_prevvalue = 0; |
| 112 |
|
last_time_sync_info_prevvalue = 0; |
| 113 |
|
time_is_estimated = false; |
| 114 |
|
|
| 115 |
|
real_time_init = 0; |
| 116 |
|
real_time_last = 0; |
| 117 |
|
bad_pkt = 0; |
| 118 |
|
bad_pkt_EventReader = 0; |
| 119 |
|
bad_pkt_CalibReader = 0; |
| 120 |
|
// good_pkt_Calib=0; |
| 121 |
|
my_id = 0; |
| 122 |
|
boot_number = 0; |
| 123 |
|
boot_number_prevvalue = 0; |
| 124 |
|
} |
| 125 |
|
|
| 126 |
|
//Put the packet in a root file. Create a new ROOT file for each group of packets |
| 127 |
|
void PacketUser::usePKT(char*& headerPkt, char*& pamPkt, long int length, bool isCons, bool isPKTGood, |
| 128 |
|
const PacketType* type, unsigned long int counter, unsigned long int obt) { |
| 129 |
|
//If the packet type was not recognised before |
| 130 |
|
if (!type) { |
| 131 |
|
return; |
| 132 |
|
} |
| 133 |
|
|
| 134 |
setInit(counter,obt); |
//in order to start ... |
| 135 |
StartGroup(); |
if (numPKT == 0) { |
| 136 |
} |
if (single_connection) { |
| 137 |
|
OpenDBConnection(NULL); |
| 138 |
//here we know if the incoming packet can be considered consecutive to the previuos one |
} |
|
if((!isCons)&&(numPKT!=0)) |
|
|
{ |
|
|
setReal_Time(); |
|
|
//closing the group in file rootfilename |
|
|
FinishGroup(rootfilename); |
|
|
|
|
|
//se gia' e' cambiato download non cambio numdisco |
|
|
if(!is_new_route){numDiscontinity++;} |
|
|
|
|
|
//the current pkt will be placed in a new group: rootfilename |
|
|
setInit(counter,obt); |
|
|
StartGroup(); |
|
|
} |
|
|
|
|
|
//add current packet to the group and calculate bad_pkt_EventReader and bad_pkt_CalibReader |
|
|
int ret= |
|
|
reader->PKT_RunEvent(headerPkt, pamPkt, length, type); |
|
|
/* |
|
|
ret |
|
|
0 packet good |
|
|
1 exception but used //never happen |
|
|
2 CRC exception but used |
|
|
3 CALIBRATION PACKET with error but used |
|
|
-1 CRC exception packet DISCARDED |
|
|
-2 FATAL exception packet DISCARDED //never happen |
|
|
-3 No way to read events of this type. packet DISCARDED( es OLD CalibCal) |
|
|
ret = 10 if the packet is good but comes from a cadre with VRL problems |
|
|
*/ |
|
|
|
|
|
//here we also know if the packet comes from one or more corrupted cadres |
|
|
if((!isPKTGood)&&(!ret)){ret=10;} |
|
|
switch (ret) |
|
|
{ |
|
|
case 0: {numPKTSaved++; break;} |
|
|
case 1: {bad_pkt_EventReader++; numPKTSaved++; break;} |
|
|
case 2: {bad_pkt_EventReader++;numPKTSaved++; break;} |
|
|
case 3: {bad_pkt_CalibReader++; numPKTSaved++; break;} |
|
|
case 10: {bad_pkt++; numPKTSaved++; break;} |
|
|
default:{ |
|
|
stringstream oss; |
|
|
oss.str()=""; |
|
|
oss<<"Packet DISCARDED, reason = "<<ret; |
|
|
string msg = oss.str(); |
|
|
mainLogUtil->logAll(msg); |
|
|
break; |
|
|
} |
|
|
} |
|
| 139 |
|
|
| 140 |
/* |
setInit(counter, obt); |
| 141 |
if ((ret==0)&&((type==PacketType::CalibTrk1)||(type==PacketType::CalibTrk2)|| (type==PacketType::CalibCalPed))) |
StartGroup(); |
| 142 |
{ |
} |
| 143 |
good_pkt_Calib++;//maybe I will remove this in future |
|
| 144 |
} |
//here we know if the incoming packet can be considered consecutive to the previuos one |
| 145 |
*/ |
if ((!isCons) && (numPKT != 0)) { |
| 146 |
|
setReal_Time(); |
| 147 |
if(ret>=0)// only the packet not discarded of course |
//closing the group in file rootfilename |
| 148 |
setLast(counter,obt); |
FinishGroup(rootfilename); |
| 149 |
|
|
| 150 |
//TODO: decide what kind of packet I can use here |
//se gia' e' cambiato download non cambio numdisco |
| 151 |
// if((ret==0)||(ret==10))//I want to use only good packet |
if (!is_new_route) { |
| 152 |
if(ret>=0)//I want to use only accepted packet |
numDiscontinity++; |
| 153 |
{ |
} |
| 154 |
setTimeSync(pamPkt, length, type);//here I retrieve also the boot_number if packet type is vardump |
|
| 155 |
} |
//the current pkt will be placed in a new group: rootfilename |
| 156 |
|
setInit(counter, obt); |
| 157 |
|
StartGroup(); |
| 158 |
|
} |
| 159 |
|
|
| 160 |
|
//add current packet to the group and calculate bad_pkt_EventReader and bad_pkt_CalibReader |
| 161 |
|
int ret = reader->PKT_RunEvent(headerPkt, pamPkt, length, type); |
| 162 |
|
/* |
| 163 |
|
ret |
| 164 |
|
0 packet good |
| 165 |
|
1 exception but used //never happen |
| 166 |
|
2 CRC exception but used |
| 167 |
|
3 CALIBRATION PACKET with error but used |
| 168 |
|
-1 CRC exception packet DISCARDED |
| 169 |
|
-2 FATAL exception packet DISCARDED //never happen |
| 170 |
|
-3 No way to read events of this type. packet DISCARDED( es OLD CalibCal) |
| 171 |
|
ret = 10 if the packet is good but comes from a cadre with VRL problems |
| 172 |
|
*/ |
| 173 |
|
|
| 174 |
|
//here we also know if the packet comes from one or more corrupted cadres |
| 175 |
|
if ((!isPKTGood) && (!ret)) { |
| 176 |
|
ret = 10; |
| 177 |
|
} |
| 178 |
|
switch (ret) { |
| 179 |
|
case 0: { |
| 180 |
|
numPKTSaved++; |
| 181 |
|
break; |
| 182 |
|
} |
| 183 |
|
case 1: { |
| 184 |
|
bad_pkt_EventReader++; |
| 185 |
|
numPKTSaved++; |
| 186 |
|
break; |
| 187 |
|
} |
| 188 |
|
case 2: { |
| 189 |
|
bad_pkt_EventReader++; |
| 190 |
|
numPKTSaved++; |
| 191 |
|
break; |
| 192 |
|
} |
| 193 |
|
case 3: { |
| 194 |
|
bad_pkt_CalibReader++; |
| 195 |
|
numPKTSaved++; |
| 196 |
|
break; |
| 197 |
|
} |
| 198 |
|
case 10: { |
| 199 |
|
bad_pkt++; |
| 200 |
|
numPKTSaved++; |
| 201 |
|
break; |
| 202 |
|
} |
| 203 |
|
default: { |
| 204 |
|
stringstream oss; |
| 205 |
|
oss.str() = ""; |
| 206 |
|
oss << "Packet DISCARDED, reason = " << ret; |
| 207 |
|
string msg = oss.str(); |
| 208 |
|
mainLogUtil->logAll(msg); |
| 209 |
|
break; |
| 210 |
|
} |
| 211 |
|
} |
| 212 |
|
|
| 213 |
|
/* |
| 214 |
|
if ((ret==0)&&((type==PacketType::CalibTrk1)||(type==PacketType::CalibTrk2)|| (type==PacketType::CalibCalPed))) |
| 215 |
|
{ |
| 216 |
|
good_pkt_Calib++;//maybe I will remove this in future |
| 217 |
|
} |
| 218 |
|
*/ |
| 219 |
|
|
| 220 |
//just to be sure ... |
if (ret >= 0)// only the packet not discarded of course |
| 221 |
if(pamPkt){delete[] pamPkt; pamPkt = NULL;} |
setLast(counter, obt); |
|
if(headerPkt){delete[] headerPkt; headerPkt = NULL;} |
|
| 222 |
|
|
| 223 |
numPKT++; |
//TODO: decide what kind of packet I can use here |
| 224 |
|
// if((ret==0)||(ret==10))//I want to use only good packet |
| 225 |
|
if (ret >= 0)//I want to use only accepted packet |
| 226 |
|
{ |
| 227 |
|
setTimeSync(pamPkt, length, type);//here I retrieve also the boot_number if packet type is vardump |
| 228 |
|
} |
| 229 |
|
|
| 230 |
|
//just to be sure ... |
| 231 |
|
if (pamPkt) { |
| 232 |
|
delete[] pamPkt; |
| 233 |
|
pamPkt = NULL; |
| 234 |
|
} |
| 235 |
|
if (headerPkt) { |
| 236 |
|
delete[] headerPkt; |
| 237 |
|
headerPkt = NULL; |
| 238 |
|
} |
| 239 |
|
|
| 240 |
|
numPKT++; |
| 241 |
} |
} |
| 242 |
|
|
| 243 |
//set the value of the counter and obt of the first packet of the group |
//set the value of the counter and obt of the first packet of the group |
| 244 |
void PacketUser::setInit(unsigned long int counter, unsigned long int obt) |
void PacketUser::setInit(unsigned long int counter, unsigned long int obt) { |
| 245 |
{ |
sprintf(nnnn_mmm_ppp, "%05d_%03d_%03d", orbit_number, mmm_number, download); |
| 246 |
sprintf(nnnn_mmm_ppp,"%05d_%03d_%03d", orbit_number, mmm_number, download); |
sprintf(rootfilename, "%s_%s_%d", nome_output, nnnn_mmm_ppp, numDiscontinity); |
| 247 |
sprintf(rootfilename,"%s_%s_%d", nome_output, nnnn_mmm_ppp, numDiscontinity); |
pkt_number_init = counter; |
| 248 |
pkt_number_init=counter; |
obt_init = obt; |
| 249 |
obt_init=obt; |
pkt_number_last = 0; |
| 250 |
pkt_number_last=0; |
obt_last = 0; |
| 251 |
obt_last=0; |
real_time_init = 0; |
| 252 |
real_time_init=0; |
real_time_last = 0; |
| 253 |
real_time_last=0; |
bad_pkt = 0; |
| 254 |
bad_pkt=0; |
numPKTSaved = 0; |
| 255 |
numPKTSaved=0; |
bad_pkt_EventReader = 0; |
| 256 |
bad_pkt_EventReader=0; bad_pkt_CalibReader=0; |
bad_pkt_CalibReader = 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 |
|
if ( obt_time_sync ) obt_time_sync_prevvalue = obt_time_sync; // save the last NOT NULL obt_time_sync! EM |
| 263 |
|
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; |
| 265 |
|
obt_time_sync = 0; |
| 266 |
|
last_time_sync_info = 0; |
| 267 |
|
boot_number_prevvalue = boot_number; |
| 268 |
|
boot_number = 0; |
| 269 |
|
|
| 270 |
obt_time_sync_prevvalue=obt_time_sync; |
// NB: se ho discontinuita in genere non so a che download appartiene potrebbe proprio essere sbagliato tenere i vecchi valori |
|
last_time_sync_info_prevvalue=last_time_sync_info; |
|
|
time_is_estimated=false; |
|
|
obt_time_sync=0; last_time_sync_info=0; |
|
|
boot_number_prevvalue=boot_number; |
|
|
boot_number=0; |
|
|
|
|
|
// NB: se ho discontinuita in genere non so a che download appartiene potrebbe proprio essere sbagliato tenere i vecchi valori |
|
| 271 |
|
|
| 272 |
} |
} |
| 273 |
|
|
| 274 |
//starts a new root file |
//starts a new root file |
| 275 |
void PacketUser::StartGroup() |
void PacketUser::StartGroup() { |
| 276 |
{ |
pRun = new PamelaRun(rootfilename, gSystem->ExpandPathName(outDir), multiFile, compression); // EMI |
| 277 |
pRun = new PamelaRun(rootfilename, gSystem->ExpandPathName(outDir), multiFile, compression); // EMI |
strcat(rootfilename, ".root"); |
| 278 |
strcat(rootfilename,".root"); |
reader->Init(pRun); |
| 279 |
reader->Init(pRun); |
stringstream oss; |
| 280 |
stringstream oss; |
oss.str() = ""; |
| 281 |
oss.str()=""; |
oss << "######################### Start a new group in file: " << rootfilename << " ############################"; |
| 282 |
oss<<"######################### Start a new group in file: "<< rootfilename <<" ############################"; |
string msg = oss.str(); |
| 283 |
string msg = oss.str(); |
mainLogUtil->logInfo(msg); |
|
mainLogUtil->logInfo(msg); |
|
| 284 |
} |
} |
| 285 |
|
|
| 286 |
//set the value of the counter and obt of the last packet of the group |
//set the value of the counter and obt of the last packet of the group |
| 287 |
void PacketUser::setLast(unsigned long int counter, unsigned long int obt) |
void PacketUser::setLast(unsigned long int counter, unsigned long int obt) { |
| 288 |
{ |
pkt_number_last = counter; |
| 289 |
pkt_number_last=counter; |
obt_last = obt; |
|
obt_last=obt; |
|
| 290 |
} |
} |
| 291 |
|
|
| 292 |
|
//retrieve obt_time_sync and last_time_sync_info from packet if type has special values and BOOT_NUMBER |
| 293 |
|
void PacketUser::setTimeSync(char* packet, long int pktLength, const PacketType* type) { |
| 294 |
|
//do nothing |
| 295 |
|
if (!do_cont_check) { |
| 296 |
|
if (is_new_route) |
| 297 |
|
is_new_route = false; |
| 298 |
|
return; |
| 299 |
|
} |
| 300 |
|
|
| 301 |
|
//TODO: usare anche MCMD ... NOTA: questo da sempre errore ret != 0 |
| 302 |
|
//In RunHeader e RunTrailer sono in secondi(?), controllare se aggiungo altri tipi di paccheti se invece sono in secondi |
| 303 |
|
// devo ricalcolare tutto non per ogni gruppetto (ROOT file) ma solo se cambia download |
| 304 |
|
//When I found a new download I need to reset all values |
| 305 |
|
if (is_new_route) { |
| 306 |
|
//reset |
| 307 |
|
is_new_route = false; |
| 308 |
|
//(tassa) ci ho ripensato se stiamo in un secondo download non prendiamo i bootnumber e timesync del precedente! |
| 309 |
|
obt_time_sync_prevvalue = 0;//obt_time_sync; |
| 310 |
|
last_time_sync_info_prevvalue = 0;//last_time_sync_info; |
| 311 |
|
|
| 312 |
|
obt_time_sync = 0; |
| 313 |
|
last_time_sync_info = 0; |
| 314 |
|
boot_number_prevvalue = 0;//boot_number; |
| 315 |
|
boot_number = 0; |
| 316 |
|
time_is_estimated = false; |
| 317 |
|
if (time_Offset) |
| 318 |
|
timeOffset = time_Offset; |
| 319 |
|
else |
| 320 |
|
timeOffset = retrieveTimeOffset(Table_GL_RESURS_OFFSET); |
| 321 |
|
} |
| 322 |
|
|
| 323 |
//retrieve obt_time_sync and last_time_sync_info from packet if type has special values and BOOT_NUMBER |
//retrieve boot number if possible |
| 324 |
void PacketUser::setTimeSync(char* packet, long int pktLength, const PacketType* type) |
setBootNumber(packet, pktLength, type); |
|
{ |
|
|
//do nothing |
|
|
if(!do_cont_check) { |
|
|
if(is_new_route) |
|
|
is_new_route=false; |
|
|
return; |
|
|
} |
|
|
|
|
|
//TODO: usare anche MCMD ... NOTA: questo da sempre errore ret != 0 |
|
|
//In RunHeader e RunTrailer sono in secondi(?), controllare se aggiungo altri tipi di paccheti se invece sono in secondi |
|
|
// devo ricalcolare tutto non per ogni gruppetto (ROOT file) ma solo se cambia download |
|
|
//When I found a new download I need to reset all values |
|
|
if(is_new_route) |
|
|
{ |
|
|
//reset |
|
|
is_new_route=false; |
|
|
//(tassa) ci ho ripensato se stiamo in un secondo download non prendiamo i bootnumber e timesync del precedente! |
|
|
obt_time_sync_prevvalue=0;//obt_time_sync; |
|
|
last_time_sync_info_prevvalue=0;//last_time_sync_info; |
|
|
|
|
|
obt_time_sync=0; last_time_sync_info=0; |
|
|
boot_number_prevvalue=0;//boot_number; |
|
|
boot_number=0; |
|
|
time_is_estimated=false; |
|
|
if(time_Offset) |
|
|
timeOffset=time_Offset; |
|
|
else |
|
|
timeOffset=retrieveTimeOffset(Table_GL_RESURS_OFFSET); |
|
|
} |
|
|
|
|
|
//retrieve boot number if possible |
|
|
setBootNumber(packet,pktLength,type); |
|
| 325 |
|
|
| 326 |
//Retrieve if possible obt_time_sync and last_time_sync_info |
//Retrieve if possible obt_time_sync and last_time_sync_info |
| 327 |
int offset=0; |
int offset = 0; |
| 328 |
if(type==PacketType::RunHeader) |
if (type == PacketType::RunHeader) { |
| 329 |
{ |
offset = 0; |
| 330 |
offset=0; |
} |
| 331 |
} |
else if (type == PacketType::RunTrailer) { |
| 332 |
else if(type==PacketType::RunTrailer) |
offset = 3; |
| 333 |
{ |
} |
| 334 |
offset=3; |
else if (type == PacketType::Mcmd) { |
| 335 |
} |
// mainLogUtil->logAll("TODO: Packet Mcmd now is not used to retrieve Absolute time. This may cause problems somewhere."); |
| 336 |
else if(type==PacketType::Mcmd) |
return; |
| 337 |
{ |
} |
| 338 |
// mainLogUtil->logAll("TODO: Packet Mcmd now is not used to retrieve Absolute time. This may cause problems somewhere."); |
else { |
| 339 |
return; |
return; |
| 340 |
} |
} |
|
else |
|
|
{ |
|
|
return; |
|
|
} |
|
|
|
|
|
//I don't need to retrieve them again if they are good |
|
|
if((obt_time_sync)||(last_time_sync_info)) return; |
|
| 341 |
|
|
| 342 |
obt_time_sync = (((UINT32)packet[5+offset]<<24)&0xFF000000) + (((UINT32)packet[6+offset]<<16)&0x00FF0000) + (((UINT32)packet[7+offset]<<8)&0x0000FF00) + (((UINT32)packet[8+offset])&0x000000FF); |
//I don't need to retrieve them again if they are good |
| 343 |
last_time_sync_info = (((UINT32)packet[9+offset]<<24)&0xFF000000) + (((UINT32)packet[10+offset]<<16)&0x00FF0000) + (((UINT32)packet[11+offset]<<8)&0x0000FF00) + (((UINT32)packet[12+offset])&0x000000FF); |
// if ((obt_time_sync) || (last_time_sync_info)) |
| 344 |
|
// 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) |
| 348 |
|
& 0x00FF0000) + (((UINT32) packet[7 + offset] << 8) & 0x0000FF00) + (((UINT32) packet[8 + offset]) & 0x000000FF); |
| 349 |
|
last_time_sync_info = (((UINT32) packet[9 + offset] << 24) & 0xFF000000) + (((UINT32) packet[10 + offset] << 16) |
| 350 |
|
& 0x00FF0000) + (((UINT32) packet[11 + offset] << 8) & 0x0000FF00) |
| 351 |
|
+ (((UINT32) packet[12 + offset]) & 0x000000FF); |
| 352 |
|
|
| 353 |
stringstream oss; |
stringstream oss; |
| 354 |
oss.str()=""; |
oss.str() = ""; |
| 355 |
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(); |
oss << "In download: " << download << " timeOffset: " << timeOffset << " obt_time_sync: " << obt_time_sync |
| 356 |
// 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(); |
<< " last_time_sync_info: " << last_time_sync_info << " using Packet Type: " << type->GetName(); |
| 357 |
string msg = oss.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().c_str(); |
| 358 |
mainLogUtil->logAll(msg); |
string msg = oss.str(); |
| 359 |
|
mainLogUtil->logAll(msg); |
| 360 |
} |
} |
| 361 |
|
|
| 362 |
//Boot Number |
//Boot Number |
| 363 |
void PacketUser::setBootNumber(char* packet, long int pktLength, const PacketType* type) |
void PacketUser::setBootNumber(char* packet, long int pktLength, const PacketType* type) { |
| 364 |
{ |
//se gia calcolato esco: lo calcolo una volta per download e per continuita' |
| 365 |
//se gia calcolato esco: lo calcolo una volta per download e per continuita' |
if (boot_number) |
| 366 |
if(boot_number) return; |
return; |
| 367 |
|
|
| 368 |
if(type==PacketType::VarDump) |
if (type == PacketType::VarDump) { |
| 369 |
{ |
int b_offset = 34;//4+5*6 |
| 370 |
int b_offset = 34;//4+5*6 |
boot_number = (((UINT32) packet[1 + b_offset] << 24) & 0xFF000000) + (((UINT32) packet[2 + b_offset] << 16) |
| 371 |
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); |
& 0x00FF0000) + (((UINT32) packet[3 + b_offset] << 8) & 0x0000FF00) + (((UINT32) packet[4 + b_offset]) |
| 372 |
|
& 0x000000FF); |
| 373 |
/* |
|
| 374 |
long int dataLength = pktLength - 2; //the block of data |
/* |
| 375 |
int b_offset = 4; |
long int dataLength = pktLength - 2; //the block of data |
| 376 |
while (b_offset < dataLength){ |
int b_offset = 4; |
| 377 |
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); |
while (b_offset < dataLength){ |
| 378 |
b_offset = b_offset + 5; |
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); |
| 379 |
} |
b_offset = b_offset + 5; |
| 380 |
*/ |
} |
| 381 |
stringstream oss; |
*/ |
| 382 |
oss.str()=""; |
stringstream oss; |
| 383 |
// oss<<"In download: "<<download<<" boot_number: "<<boot_number<<" using Packet Type: "<<type->GetName().c_str(); |
oss.str() = ""; |
| 384 |
oss<<"In download: "<<download<<" boot_number: "<<boot_number<<" using Packet Type: "<<type->GetName(); |
// oss<<"In download: "<<download<<" boot_number: "<<boot_number<<" using Packet Type: "<<type->GetName().c_str(); |
| 385 |
string msg = oss.str(); |
oss << "In download: " << download << " boot_number: " << boot_number << " using Packet Type: " << type->GetName(); |
| 386 |
mainLogUtil->logAll(msg); |
string msg = oss.str(); |
| 387 |
return; |
mainLogUtil->logAll(msg); |
| 388 |
} |
return; |
| 389 |
else |
} |
| 390 |
{ |
else { |
| 391 |
return; |
return; |
| 392 |
} |
} |
| 393 |
|
|
| 394 |
} |
} |
| 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; |
| 400 |
time_is_estimated=true; |
obt_time_sync = obt_time_sync_prevvalue; |
| 401 |
obt_time_sync=obt_time_sync_prevvalue; |
last_time_sync_info = last_time_sync_info_prevvalue; |
| 402 |
last_time_sync_info=last_time_sync_info_prevvalue; |
} |
| 403 |
} |
if (obt_time_sync || last_time_sync_info) { |
| 404 |
if(obt_time_sync || last_time_sync_info) |
real_time_init = (obt_init / 1000 - obt_time_sync) + last_time_sync_info; |
| 405 |
{ |
//se obt si e' resettato |
| 406 |
real_time_init=(obt_init/1000-obt_time_sync)+last_time_sync_info; |
if (obt_last < obt_init) { |
| 407 |
//se obt si e' resettato |
real_time_last = (max_pkt_obt / 1000 + obt_last / 1000 - obt_time_sync) + last_time_sync_info; |
| 408 |
if(obt_last<obt_init) |
stringstream oss; |
| 409 |
{ |
oss.str() = ""; |
| 410 |
real_time_last=(max_pkt_obt/1000+ obt_last/1000-obt_time_sync)+last_time_sync_info; |
oss << "obt_last(" << obt_last << ") < obt_init(" << obt_init |
| 411 |
stringstream oss; |
<< "). It is due to Pamela Reset. Adding max_pkt_obt(" << max_pkt_obt |
| 412 |
oss.str()=""; |
<< ") to obt_last in order to compute real_time_last"; |
| 413 |
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"; |
string msg = oss.str(); |
| 414 |
string msg = oss.str(); |
mainLogUtil->logWarning(msg); |
| 415 |
mainLogUtil->logWarning(msg); |
} |
| 416 |
} |
else |
| 417 |
else |
real_time_last = (obt_last / 1000 - obt_time_sync) + last_time_sync_info; |
| 418 |
real_time_last=(obt_last/1000-obt_time_sync)+last_time_sync_info; |
real_time_init += timeOffset; |
| 419 |
real_time_init+=timeOffset; |
real_time_last += timeOffset; |
| 420 |
real_time_last+=timeOffset; |
} |
|
} |
|
| 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(char * table) |
unsigned long int PacketUser::retrieveTimeOffset(const char * table) { |
| 454 |
{ |
if (!do_cont_check) |
| 455 |
if(!do_cont_check) return 0; |
return 0; |
|
|
|
|
//if(!table){table=Table_GL_RESURS_OFFSET} |
|
| 456 |
|
|
| 457 |
if(!single_connection){ |
//if(!table){table=Table_GL_RESURS_OFFSET} |
|
OpenDBConnection(table);//Nota qui ho deciso di lockare solo questa tabella e non tutte |
|
|
} |
|
| 458 |
|
|
| 459 |
UInt_t t0 = 0;//toffset |
if (!single_connection) { |
| 460 |
stringstream oss; |
OpenDBConnection(table);//Nota qui ho deciso di lockare solo questa tabella e non tutte |
| 461 |
oss.str(""); |
} |
|
oss << "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE),ID FROM "<< table <<" WHERE SPECIAL_FILE='" |
|
|
<< nnnn_mmm_ppp << "';"; |
|
|
|
|
|
string msg = oss.str(); |
|
|
mainLogUtil->logAll(msg); |
|
|
|
|
|
TSQLResult* res=NULL; |
|
|
TSQLRow* row=NULL; |
|
|
res= sqlServer->Query(oss.str().c_str()); |
|
|
if(!res) |
|
|
{ |
|
|
mainLogUtil->logError("DBError retrieveTimeOffset 1"); |
|
|
return 0; |
|
|
} |
|
|
|
|
|
row=res->Next(); |
|
|
if (!row ) |
|
|
{ |
|
|
if(res){delete res; res = NULL;} |
|
|
|
|
|
oss.str(""); |
|
|
oss << "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE),ID FROM "<< table <<" WHERE FROM_ORBIT < " |
|
|
<< orbit_number << " AND SPECIAL_FILE='' order by FROM_ORBIT desc limit 1;"; |
|
|
|
|
|
string msg2 = oss.str(); |
|
|
mainLogUtil->logAll(msg2); |
|
|
|
|
|
res= sqlServer->Query(oss.str().c_str()); |
|
|
if(!res) |
|
|
{ |
|
|
mainLogUtil->logError("DBError retrieveTimeOffset 2"); |
|
|
return 0; |
|
|
} |
|
|
row=res->Next(); |
|
|
if (!row) |
|
|
{ |
|
|
mainLogUtil->logError("DBError retrieveTimeOffset 3"); |
|
|
return 0; |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
TTimeStamp tu = TTimeStamp((UInt_t)atoi(row->GetField(0)),(UInt_t)atoi(row->GetField(1)),(UInt_t)atoi(row->GetField(2)),(UInt_t)atoi(row->GetField(3)),(UInt_t)atoi(row->GetField(4)),(UInt_t)atoi(row->GetField(5)),0,true,0); |
|
|
t0 = (UInt_t)tu.GetSec(); |
|
|
|
|
|
if(res){delete res; res = NULL;} |
|
|
if(row){delete row; row = NULL;} |
|
| 462 |
|
|
| 463 |
if(!single_connection){ |
UInt_t t0 = 0;//toffset |
| 464 |
CloseDBConnection(); |
stringstream oss; |
| 465 |
} |
oss.str(""); |
| 466 |
return t0; |
oss |
| 467 |
|
<< "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE),ID FROM " |
| 468 |
|
<< table << " WHERE SPECIAL_FILE='" << nnnn_mmm_ppp << "';"; |
| 469 |
|
|
| 470 |
|
string msg = oss.str(); |
| 471 |
|
mainLogUtil->logAll(msg); |
| 472 |
|
|
| 473 |
|
TSQLResult* res = NULL; |
| 474 |
|
TSQLRow* row = NULL; |
| 475 |
|
res = sqlServer->Query(oss.str().c_str()); |
| 476 |
|
if (!res) { |
| 477 |
|
mainLogUtil->logError("DBError retrieveTimeOffset 1"); |
| 478 |
|
return 0; |
| 479 |
|
} |
| 480 |
|
|
| 481 |
|
row = res->Next(); |
| 482 |
|
if (!row) { |
| 483 |
|
if (res) { |
| 484 |
|
delete res; |
| 485 |
|
res = NULL; |
| 486 |
|
} |
| 487 |
|
|
| 488 |
|
oss.str(""); |
| 489 |
|
oss |
| 490 |
|
<< "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE),ID FROM " |
| 491 |
|
<< table << " WHERE FROM_ORBIT < " << orbit_number << " AND SPECIAL_FILE='' order by FROM_ORBIT desc limit 1;"; |
| 492 |
|
|
| 493 |
|
string msg2 = oss.str(); |
| 494 |
|
mainLogUtil->logAll(msg2); |
| 495 |
|
|
| 496 |
|
res = sqlServer->Query(oss.str().c_str()); |
| 497 |
|
if (!res) { |
| 498 |
|
mainLogUtil->logError("DBError retrieveTimeOffset 2"); |
| 499 |
|
return 0; |
| 500 |
|
} |
| 501 |
|
row = res->Next(); |
| 502 |
|
if (!row) { |
| 503 |
|
mainLogUtil->logError("DBError retrieveTimeOffset 3"); |
| 504 |
|
return 0; |
| 505 |
|
} |
| 506 |
|
|
| 507 |
|
} |
| 508 |
|
|
| 509 |
|
TTimeStamp tu = TTimeStamp((UInt_t) atoi(row->GetField(0)), (UInt_t) atoi(row->GetField(1)), (UInt_t) atoi( |
| 510 |
|
row->GetField(2)), (UInt_t) atoi(row->GetField(3)), (UInt_t) atoi(row->GetField(4)), (UInt_t) atoi(row->GetField( |
| 511 |
|
5)), 0, true, 0); |
| 512 |
|
t0 = (UInt_t) tu.GetSec(); |
| 513 |
|
|
| 514 |
|
if (res) { |
| 515 |
|
delete res; |
| 516 |
|
res = NULL; |
| 517 |
|
} |
| 518 |
|
if (row) { |
| 519 |
|
delete row; |
| 520 |
|
row = NULL; |
| 521 |
|
} |
| 522 |
|
|
| 523 |
|
if (!single_connection) { |
| 524 |
|
CloseDBConnection(); |
| 525 |
|
} |
| 526 |
|
return t0; |
| 527 |
} |
} |
| 528 |
|
|
| 529 |
//this is public and can be called from the main at the end of the game |
//this is public and can be called from the main at the end of the game |
| 530 |
void PacketUser::FinishLastGroup() |
void PacketUser::FinishLastGroup() { |
| 531 |
{ |
mainLogUtil->logAll("######################### Closing the last group ############################"); |
| 532 |
mainLogUtil->logAll("######################### Closing the last group ############################"); |
setReal_Time(); |
| 533 |
setReal_Time(); |
FinishGroup(rootfilename); |
| 534 |
FinishGroup(rootfilename); |
mainLogUtil->logAll("######################### Closed the last group ############################"); |
| 535 |
mainLogUtil->logAll("######################### Closed the last group ############################"); |
// |
| 536 |
if(single_connection){ |
if (single_connection) { |
| 537 |
CloseDBConnection(); |
CloseDBConnection(); |
| 538 |
} |
} |
| 539 |
} |
} |
| 540 |
|
|
| 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) { |
| 544 |
if(pRun) |
if ( !( !real_time_init && !real_time_last && numPKTSaved <= recoverlimit ) || !candelete ) pRun->WriteFiles(); |
| 545 |
{ |
delete pRun; |
| 546 |
pRun->WriteFiles(); |
pRun = NULL; |
| 547 |
delete pRun; pRun = NULL; |
stringstream close; |
| 548 |
stringstream close; |
close.str() = ""; |
| 549 |
close.str()=""; |
string msg; |
| 550 |
string msg; |
|
| 551 |
|
close << "TAG XX ######################### Close group in file: " << rootfilename << " ############################"; |
| 552 |
close<<"######################### Close group in file: "<< rootfilename <<" ############################"; |
msg = close.str(); |
| 553 |
msg = close.str(); |
mainLogUtil->logInfo(msg); |
| 554 |
mainLogUtil->logInfo(msg); |
|
| 555 |
|
// se non faccio proprio controlli su continuita' neanche salvo su DB |
| 556 |
// se non faccio proprio controlli su continuita' neanche salvo su DB |
if (!do_cont_check) |
| 557 |
if(!do_cont_check) return; |
return; |
| 558 |
|
|
| 559 |
|
stringstream oss; |
| 560 |
|
oss.str() = ""; |
| 561 |
|
|
| 562 |
|
//TODO: check when I don't want to log in DB informations |
| 563 |
|
// se non ho salvato nessun pacchetto |
| 564 |
|
if (numPKTSaved == 0) { |
| 565 |
|
stringstream err; |
| 566 |
|
err.str() = ""; |
| 567 |
|
err << "NO PACKET SAVED in file: " << rootfilename << " The group is empty: you can remove this file."; |
| 568 |
|
msg = err.str(); |
| 569 |
|
mainLogUtil->logError(msg); |
| 570 |
|
// return; |
| 571 |
|
} |
| 572 |
|
|
| 573 |
|
//se non ho salvato nessun pacchetto buono |
| 574 |
|
if ((numPKTSaved - bad_pkt_EventReader - bad_pkt_CalibReader - bad_pkt) == 0) { |
| 575 |
|
stringstream err; |
| 576 |
|
err.str() = ""; |
| 577 |
|
err << "NO GOOD PACKET SAVED in file: " << rootfilename << " The group is BAD: you may want to remove this file."; |
| 578 |
|
msg = err.str(); |
| 579 |
|
mainLogUtil->logInfo(msg); |
| 580 |
|
// mainLogUtil->logError(msg); |
| 581 |
|
// return; //TODO: decidi se nn vuoi affatto usarlo o addirittura salvarlo tra i BAD??? |
| 582 |
|
} |
| 583 |
|
|
| 584 |
|
if (!single_connection) { |
| 585 |
|
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 |
| 590 |
|
if ((!real_time_init) && (!real_time_last)) { |
| 591 |
|
//saved in another table for future study |
| 592 |
|
if (saveROOT_DB( |
| 593 |
|
Table_ROOT_Bad, |
| 594 |
|
outDir,// here outDir is good, no expand EMI |
| 595 |
|
filename, pkt_number_init, pkt_number_last, obt_init, obt_last, obt_time_sync, last_time_sync_info, |
| 596 |
|
real_time_init, real_time_last, boot_number, timeOffset, bad_pkt, bad_pkt_EventReader, bad_pkt_CalibReader, |
| 597 |
|
numPKTSaved, fni, time_is_estimated) == true) { |
| 598 |
|
oss.str() = ""; |
| 599 |
|
oss << "Saved information regarding file: " << filename << " in table " << Table_ROOT_Bad; |
| 600 |
|
msg = oss.str(); |
| 601 |
|
mainLogUtil->logInfo(msg); |
| 602 |
|
} |
| 603 |
|
else { |
| 604 |
|
oss.str() = ""; |
| 605 |
|
oss << "Problem storing information in DB regarding file: " << filename; |
| 606 |
|
msg = oss.str(); |
| 607 |
|
mainLogUtil->logError(msg); |
| 608 |
|
} |
| 609 |
|
|
| 610 |
|
|
| 611 |
|
|
| 612 |
|
if ( numPKTSaved > recoverlimit){ // EM |
| 613 |
|
// |
| 614 |
|
if ( obt_time_sync && last_time_sync_info ){ |
| 615 |
|
stringstream err; |
| 616 |
|
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 |
stringstream oss; |
if (tryMerge) { |
| 675 |
oss.str()=""; |
merge_ROOTfiles(); |
| 676 |
|
} |
| 677 |
//TODO: check when I don't want to log in DB informations |
} else { |
| 678 |
// se non ho salvato nessun pacchetto |
oss.str() = ""; |
| 679 |
if(numPKTSaved==0){ |
oss << "Problem storing information in DB regarding file: " << filename; |
| 680 |
stringstream err; |
msg = oss.str(); |
| 681 |
err.str()=""; |
mainLogUtil->logError(msg); |
| 682 |
err<<"NO PACKET SAVED in file: "<< rootfilename <<" The group is empty: you can remove this file."; |
} |
| 683 |
msg = err.str(); |
}; |
| 684 |
mainLogUtil->logError(msg); |
|
| 685 |
return; |
// if dbinfo is not empty than |
| 686 |
} |
if ( arsize > 0 ){ |
| 687 |
|
|
| 688 |
//se non ho salvato nessun pacchetto buono |
if ( !obt_time_sync || !last_time_sync_info ){ |
| 689 |
if((numPKTSaved-bad_pkt_EventReader-bad_pkt_CalibReader-bad_pkt)==0){ |
TString *nomino=new TString(rootfilename); |
| 690 |
stringstream err; |
nomino->Remove(15); |
| 691 |
err.str()=""; |
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 |
err<<"NO GOOD PACKET SAVED in file: "<< rootfilename <<" The group is BAD: you may want to remove this file."; |
// |
| 693 |
msg = err.str(); |
oss.str() = ""; |
| 694 |
mainLogUtil->logInfo(msg); |
oss << "(EM) Trying to find obt_time_sync and last_time_sync_info from DB, query is: " << qu.Data(); |
| 695 |
// mainLogUtil->logError(msg); |
msg = oss.str(); |
| 696 |
// return; //TODO: decidi se nn vuoi affatto usarlo o addirittura salvarlo tra i BAD??? |
mainLogUtil->logInfo(msg); |
| 697 |
} |
// |
| 698 |
|
TSQLResult *result = sqlServer->Query(qu.Data()); |
| 699 |
if(!single_connection){ |
TSQLRow *row = result->Next(); |
| 700 |
OpenDBConnection(NULL);//Nota qui ho deciso di lockare tutte le tabelle |
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 |
//don't save in Table_ROOT_Good and don't search for ROOT files in the same temporal range |
oss.str() = ""; |
| 704 |
if((!real_time_init)&&(!real_time_last)) |
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 |
//saved in another table for future study |
mainLogUtil->logInfo(msg); |
| 707 |
if(saveROOT_DB(Table_ROOT_Bad, outDir,// here outDir is good, no expand EMI |
}; |
| 708 |
filename, |
delete nomino; |
| 709 |
pkt_number_init, pkt_number_last, |
}; |
| 710 |
obt_init, obt_last, |
|
| 711 |
obt_time_sync, last_time_sync_info, |
if ( obt_time_sync && last_time_sync_info ){ |
| 712 |
real_time_init, real_time_last, |
// if(!m_dbinfos.empty()){ |
| 713 |
boot_number, |
// while(!m_dbinfos.empty()){ |
| 714 |
timeOffset, |
// dbinfo *app = m_dbinfos.back(); |
| 715 |
bad_pkt, bad_pkt_EventReader, bad_pkt_CalibReader, numPKTSaved, |
// m_dbinfos.pop_back(); |
| 716 |
fni,time_is_estimated)==true) |
Int_t ez=0; |
| 717 |
{ |
while ( ez < arsize ){ |
| 718 |
oss.str()=""; |
Int_t eid = idtorecover->At(ez); |
| 719 |
oss<<"Saved information regarding file: "<<filename<<" in table "<<Table_ROOT_Bad; |
if ( eid > -1 ){ |
| 720 |
msg = oss.str(); |
|
| 721 |
mainLogUtil->logInfo(msg); |
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 |
else |
TSQLRow *row = result->Next(); |
| 724 |
{ |
|
| 725 |
oss.str()=""; |
TString efolder_name=""; |
| 726 |
oss<<"Problem storing information in DB regarding file: "<<filename; |
TString efile_name=""; |
| 727 |
msg = oss.str(); |
unsigned long int epkt_number_in=0ULL; |
| 728 |
mainLogUtil->logError(msg); |
unsigned long int epkt_number_fin=0ULL; |
| 729 |
} |
unsigned long int eobt_in=0ULL; |
| 730 |
|
unsigned long int eobt_fin=0ULL; |
| 731 |
if(!single_connection){ |
unsigned long int emboot_num=0ULL; |
| 732 |
CloseDBConnection(); |
unsigned long int etime_offset=0ULL; |
| 733 |
} |
int ebad_pkt=0; |
| 734 |
|
int ebad_pkt_read=0; |
| 735 |
return; |
int ebad_pkt_CalRead=0; |
| 736 |
} |
int enum_PKT_Saved=0; |
| 737 |
|
TString enome_input=""; |
| 738 |
//saves info in DB in table Table_ROOT_Good |
bool e_time_is_estimated=false; |
| 739 |
if(boot_number==0) |
|
| 740 |
boot_number=boot_number_prevvalue; |
if ( row ){ |
| 741 |
|
efolder_name = (TString)row->GetField(0); |
| 742 |
if(saveROOT_DB(Table_ROOT_Good, outDir, // here outDir is good, no expand EMI |
efile_name = (TString)row->GetField(1); |
| 743 |
filename, |
epkt_number_in = (unsigned long int)atoll(row->GetField(2)); |
| 744 |
pkt_number_init, pkt_number_last, |
epkt_number_fin = (unsigned long int)atoll(row->GetField(3)); |
| 745 |
obt_init, obt_last, |
eobt_in = (unsigned long int)atoll(row->GetField(4)); |
| 746 |
obt_time_sync, last_time_sync_info, |
eobt_fin = (unsigned long int)atoll(row->GetField(5)); |
| 747 |
real_time_init, real_time_last, |
emboot_num = (unsigned long int)atoll(row->GetField(6)); |
| 748 |
boot_number, |
etime_offset = (unsigned long int)atoll(row->GetField(7)); |
| 749 |
timeOffset, |
ebad_pkt = (int)atoi(row->GetField(8)); |
| 750 |
bad_pkt, bad_pkt_EventReader, bad_pkt_CalibReader, numPKTSaved, |
ebad_pkt_read = (int)atoi(row->GetField(9)); |
| 751 |
fni,time_is_estimated)==true) |
ebad_pkt_CalRead = (int)atoi(row->GetField(10)); |
| 752 |
{ |
enum_PKT_Saved = (int)atoi(row->GetField(11)); |
| 753 |
oss<<"Saved information regarding file: "<<filename<<" in table "<<Table_ROOT_Good<< " id= "<<my_id; |
enome_input = (TString)row->GetField(12); |
| 754 |
msg = oss.str(); |
e_time_is_estimated = (bool)atoi(row->GetField(13)); |
| 755 |
mainLogUtil->logInfo(msg); |
}; |
| 756 |
|
delete result; |
| 757 |
if(tryMerge){ |
|
| 758 |
merge_ROOTfiles(); |
setReal_TimeRECOVERY( |
| 759 |
} |
real_time_init, |
| 760 |
} |
real_time_last, |
| 761 |
else |
eobt_in, |
| 762 |
{ |
eobt_fin |
| 763 |
oss<<"Problem storing information in DB regarding file: "<<filename; |
); |
| 764 |
msg = oss.str(); |
// |
| 765 |
mainLogUtil->logError(msg); |
|
| 766 |
} |
if (saveROOT_DB( |
| 767 |
|
Table_ROOT_Good, |
| 768 |
if(!single_connection){ |
efolder_name.Data(), |
| 769 |
CloseDBConnection(); |
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) { |
| 829 |
|
CloseDBConnection(); |
| 830 |
|
} |
| 831 |
|
|
| 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(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 pkt_number_in, unsigned long int pkt_number_fin, unsigned long int obt_in, |
| 867 |
unsigned long int obt_in, unsigned long int obt_fin, |
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 oT_sync, unsigned long int lT_sync_info, |
unsigned long int mtime_last, unsigned long int mboot_num, unsigned long int time_offset, int bad_pkt, |
| 869 |
unsigned long int mtime_init, unsigned long int mtime_last, |
int bad_pkt_read, int bad_pkt_CalRead, int num_PKT_Saved, const char* nome_input, bool _time_is_estimated) { |
| 870 |
unsigned long int mboot_num, |
//TODO: forse far ritornare ID della cosa appena inserita se e' andatato tutto ok invece che true false? |
| 871 |
unsigned long int time_offset, |
stringstream oss; |
| 872 |
int bad_pkt, int bad_pkt_read, int bad_pkt_CalRead, int num_PKT_Saved, |
oss.str(""); |
| 873 |
char* nome_input, bool _time_is_estimated){ |
oss << "INSERT INTO " << table_name |
| 874 |
//TODO: forse far ritornare ID della cosa appena inserita se e' andatato tutto ok invece che true false? |
<< " (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 |
stringstream oss; |
<< " VALUES ('" << 0 << "','" << folder_name << "','" << file_name << "','" << pkt_number_in << "','" |
| 876 |
oss.str(""); |
<< pkt_number_fin << "','" << obt_in << "','" << obt_fin << "','" << oT_sync << "','" << lT_sync_info << "','" |
| 877 |
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)" |
<< mtime_init << "','" << mtime_last << "','" << mboot_num << "','" << time_offset << "','" << bad_pkt << "','" |
| 878 |
<< " VALUES ('"<<0<< "','" <<folder_name<<"','" <<file_name<< "','" << pkt_number_in <<"','"<< pkt_number_fin << "','"<< obt_in <<"','"<< obt_fin<< "','" |
<< bad_pkt_read << "','" << bad_pkt_CalRead << "','" << num_PKT_Saved << "','" << nome_input << "'," << "NULL," |
| 879 |
<< oT_sync << "','" << lT_sync_info << "','" |
<< _time_is_estimated << ",'" << tag_value << "'" << ");"; |
| 880 |
<< mtime_init << "','" << mtime_last << "','" |
string msg = oss.str(); |
| 881 |
<< mboot_num << "','" |
mainLogUtil->logAll(msg); |
|
<< time_offset << "','" |
|
|
<< bad_pkt <<"','" << bad_pkt_read <<"','"<< bad_pkt_CalRead <<"','"<< num_PKT_Saved<<"','" |
|
|
<< nome_input <<"'," |
|
|
<<"NULL,"<<_time_is_estimated<< |
|
|
");"; |
|
|
string msg = oss.str(); |
|
|
mainLogUtil->logAll(msg); |
|
|
|
|
|
stringstream oss1; |
|
|
oss1.str()=""; |
|
|
string msg1; |
|
|
string query; |
|
|
|
|
|
TSQLResult* res=NULL; |
|
|
|
|
|
query=oss.str(); |
|
|
msg1="SaveROOT_DB query: "; |
|
|
msg1 += query; |
|
|
mainLogUtil->logInfo(msg1); |
|
|
|
|
|
res= sqlServer->Query(query.c_str()); |
|
|
if(!res) |
|
|
{ |
|
|
oss1<<"DBError UNABLE to: "<<oss.str().c_str()<<endl; |
|
|
msg1=oss1.str(); |
|
|
mainLogUtil->logError(msg1); |
|
|
return false; |
|
|
} |
|
| 882 |
|
|
| 883 |
//the ID of the current ROOT file in table Table_ROOT_Good |
stringstream oss1; |
| 884 |
my_id = select_maxIDN_DB(table_name); |
oss1.str() = ""; |
| 885 |
if(!boot_number){ |
string msg1; |
| 886 |
if(id_to_recover_index<1000) |
string query; |
|
id_to_recover[id_to_recover_index++]=my_id; |
|
|
}else if (boot_number && id_to_recover_index && !is_new_route){ |
|
|
recover_boot_number(); |
|
|
} |
|
|
// cout<<"DBG: my_id = "<<my_id<<endl; |
|
|
if(res){delete res; res = NULL;} |
|
|
return true; |
|
|
} |
|
| 887 |
|
|
| 888 |
|
TSQLResult* res = NULL; |
| 889 |
|
|
| 890 |
|
query = oss.str(); |
| 891 |
|
msg1 = "SaveROOT_DB query: "; |
| 892 |
|
msg1 += query; |
| 893 |
|
mainLogUtil->logInfo(msg1); |
| 894 |
|
|
| 895 |
|
res = sqlServer->Query(query.c_str()); |
| 896 |
|
if (!res) { |
| 897 |
|
oss1 << "DBError UNABLE to: " << oss.str().c_str() << endl; |
| 898 |
|
msg1 = oss1.str(); |
| 899 |
|
mainLogUtil->logError(msg1); |
| 900 |
|
return false; |
| 901 |
|
} |
| 902 |
|
|
| 903 |
void PacketUser::recover_boot_number(){ |
|
| 904 |
|
if(!strcmp(table_name,Table_ROOT_Good)) { |
| 905 |
|
//the ID of the current ROOT file in table Table_ROOT_Good |
| 906 |
|
my_id = select_maxIDN_DB(table_name); |
| 907 |
|
if (!boot_number) { |
| 908 |
|
if (id_to_recover_index < 1000) |
| 909 |
|
id_to_recover[id_to_recover_index++] = my_id; |
| 910 |
|
} |
| 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; |
| 916 |
|
if (res) { |
| 917 |
|
delete res; |
| 918 |
|
res = NULL; |
| 919 |
|
} |
| 920 |
|
return true; |
| 921 |
|
} |
| 922 |
|
|
| 923 |
|
void PacketUser::recover_boot_number() { |
| 924 |
string msg1; |
string msg1; |
| 925 |
stringstream oss1; |
stringstream oss1; |
| 926 |
stringstream oss; |
stringstream oss; |
| 927 |
oss.str(""); |
oss.str(""); |
| 928 |
string query=""; |
string query = ""; |
| 929 |
TSQLResult* res=NULL; |
TSQLResult* res = NULL; |
| 930 |
if(!boot_number || !id_to_recover_index) |
if (!boot_number || !id_to_recover_index) |
| 931 |
return; |
return; |
| 932 |
|
|
| 933 |
for (int i = 0; i<id_to_recover_index;i++){ |
for (int i = 0; i < id_to_recover_index; i++) { |
| 934 |
oss.str(""); |
oss.str(""); |
| 935 |
oss << "UPDATE "<< Table_ROOT_Good << " SET BOOT_NUMBER=" << boot_number << " WHERE ID_N=" << id_to_recover[i] << ";"; |
oss << "UPDATE " << Table_ROOT_Good << " SET BOOT_NUMBER=" << boot_number << " WHERE ID_N=" << id_to_recover[i] |
| 936 |
query = oss.str(); |
<< ";"; |
| 937 |
res= sqlServer->Query(query.c_str()); |
query = oss.str(); |
| 938 |
if(!res) |
res = sqlServer->Query(query.c_str()); |
| 939 |
{ |
if (!res) { |
| 940 |
oss1<<"DBError UNABLE to: "<<query.c_str()<<endl; |
oss1 << "DBError UNABLE to: " << query.c_str() << endl; |
| 941 |
msg1=oss1.str(); |
msg1 = oss1.str(); |
| 942 |
mainLogUtil->logError(msg1); |
mainLogUtil->logError(msg1); |
| 943 |
return ; |
return; |
| 944 |
} |
} |
| 945 |
} |
} |
| 946 |
|
|
| 947 |
for (int i = 0; i<id_to_recover_index;i++){ |
for (int i = 0; i < id_to_recover_index; i++) { |
| 948 |
oss.str(""); |
oss.str(""); |
| 949 |
oss << "UPDATE " << Table_ROOT_Merging << " SET BOOT_NUMBER=" << boot_number << " WHERE ROOT_ID_N=" << id_to_recover[i] << ";"; |
oss << "UPDATE " << Table_ROOT_Merging << " SET BOOT_NUMBER=" << boot_number << " WHERE ROOT_ID_N=" |
| 950 |
query=oss.str(); |
<< id_to_recover[i] << ";"; |
| 951 |
res= sqlServer->Query(query.c_str()); |
query = oss.str(); |
| 952 |
if(!res) |
res = sqlServer->Query(query.c_str()); |
| 953 |
{ |
if (!res) { |
| 954 |
oss1<<"DBError UNABLE to: "<<query.c_str()<<endl; |
oss1 << "DBError UNABLE to: " << query.c_str() << endl; |
| 955 |
msg1=oss1.str(); |
msg1 = oss1.str(); |
| 956 |
mainLogUtil->logError(msg1); |
mainLogUtil->logError(msg1); |
| 957 |
return ; |
return; |
| 958 |
} |
} |
| 959 |
} |
} |
| 960 |
|
|
| 961 |
id_to_recover_index=0; |
id_to_recover_index = 0; |
| 962 |
} |
} |
| 963 |
|
|
|
|
|
|
|
|
| 964 |
/**********************************************************************************************/ |
/**********************************************************************************************/ |
| 965 |
/*###########################################################################################################*/ |
/*###########################################################################################################*/ |
| 966 |
/********************************** MERGING *************************************************/ |
/********************************** MERGING *************************************************/ |
| 969 |
// 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 |
| 970 |
/**********************************************************************************************/ |
/**********************************************************************************************/ |
| 971 |
//try to merge current ROOT file with files in DB |
//try to merge current ROOT file with files in DB |
| 972 |
bool PacketUser::merge_ROOTfiles() |
bool PacketUser::merge_ROOTfiles() { |
| 973 |
{ |
stringstream log; |
| 974 |
stringstream log; |
log.str(""); |
| 975 |
log.str(""); |
string slog; |
|
string slog; |
|
| 976 |
|
|
| 977 |
mainLogUtil->logInfo("Trying merging ROOT files"); |
mainLogUtil->logInfo("Trying merging ROOT files"); |
| 978 |
double percentage=(double)(bad_pkt+bad_pkt_EventReader+bad_pkt_CalibReader)/numPKTSaved; |
double percentage = (double) (bad_pkt + bad_pkt_EventReader + bad_pkt_CalibReader) / numPKTSaved; |
|
|
|
|
TSQLResult* res=NULL; |
|
|
TSQLRow* row =NULL; |
|
|
//numero di ROOT files trovati sul DB che hanno relaz di tipo dato |
|
|
unsigned int num_rows=0; |
|
|
|
|
|
//Record su DB: |
|
|
unsigned int idN = 0; |
|
|
unsigned int root_id_db=0; |
|
|
unsigned long int pkt_num_in_db=0; |
|
|
unsigned long int pkt_num_fin_db=0; |
|
|
unsigned long int pkt_obt_in_db=0; |
|
|
unsigned long int pkt_obt_fin_db=0; |
|
|
unsigned long int time_in_db=0; |
|
|
unsigned long int time_fin_db=0; |
|
|
unsigned int boot_num_db=0; |
|
|
double perc=0; |
|
| 979 |
|
|
| 980 |
|
TSQLResult* res = NULL; |
| 981 |
|
TSQLRow* row = NULL; |
| 982 |
|
//numero di ROOT files trovati sul DB che hanno relaz di tipo dato |
| 983 |
|
unsigned int num_rows = 0; |
| 984 |
|
|
| 985 |
|
//Record su DB: |
| 986 |
|
unsigned int idN = 0; |
| 987 |
|
unsigned int root_id_db = 0; |
| 988 |
|
unsigned long int pkt_num_in_db = 0; |
| 989 |
|
unsigned long int pkt_num_fin_db = 0; |
| 990 |
|
unsigned long int pkt_obt_in_db = 0; |
| 991 |
|
unsigned long int pkt_obt_fin_db = 0; |
| 992 |
|
unsigned long int time_in_db = 0; |
| 993 |
|
unsigned long int time_fin_db = 0; |
| 994 |
|
unsigned int boot_num_db = 0; |
| 995 |
|
double perc = 0; |
| 996 |
|
|
| 997 |
//marco_new: non considero mai caso di continuita'(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 |
| 998 |
//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 |
| 999 |
for(int relaz=AFTER; relaz<=BIGGER; relaz++) |
for (int relaz = AFTER; relaz <= BIGGER; relaz++) { |
| 1000 |
{ |
//marco_new: esci se sono arrivato a zero |
| 1001 |
//marco_new: esci se sono arrivato a zero |
if (real_time_last == real_time_init) { |
| 1002 |
if(real_time_last==real_time_init) |
log.str(""); |
| 1003 |
{ |
log << "Current File Lenght=0; real_time_last=real_time_init= " << real_time_last; |
| 1004 |
log.str(""); |
slog = log.str(); |
| 1005 |
log<<"Current File Lenght=0; real_time_last=real_time_init= "<<real_time_last; |
mainLogUtil->logAll(slog); |
| 1006 |
slog=log.str(); |
mainLogUtil->logInfo("Finish merging ROOT files"); |
| 1007 |
mainLogUtil->logAll(slog); |
if (res) { |
| 1008 |
mainLogUtil->logInfo("Finish merging ROOT files"); |
delete res; |
| 1009 |
if(res){delete res; res = NULL;} |
res = NULL; |
| 1010 |
if(row){delete row; row = NULL;} |
} |
| 1011 |
return true; |
if (row) { |
| 1012 |
} |
delete row; |
| 1013 |
|
row = NULL; |
| 1014 |
num_rows=0; |
} |
| 1015 |
res = Select_merging(Table_ROOT_Merging, real_time_init, real_time_last, (type_Rel_ROOT)relaz); |
return true; |
| 1016 |
|
} |
| 1017 |
if (!res) |
|
| 1018 |
{ |
num_rows = 0; |
| 1019 |
mainLogUtil->logError("DB_ERROR: Unable to find ROOT files to be merged RES=null"); |
res = Select_merging(Table_ROOT_Merging, real_time_init, real_time_last, (type_Rel_ROOT) relaz); |
| 1020 |
return false; |
|
| 1021 |
} |
if (!res) { |
| 1022 |
|
mainLogUtil->logError("DB_ERROR: Unable to find ROOT files to be merged RES=null"); |
| 1023 |
num_rows=res->GetRowCount(); |
return false; |
| 1024 |
log.str(""); |
} |
| 1025 |
log<<"Found "<<num_rows<<" ROOT file in DB with relation of kind = "<<relaz; |
|
| 1026 |
slog=log.str(); |
num_rows = res->GetRowCount(); |
| 1027 |
mainLogUtil->logAll(slog); |
log.str(""); |
| 1028 |
|
log << "Found " << num_rows << " ROOT file in DB with relation of kind = " << relaz; |
| 1029 |
if(num_rows>0) |
slog = log.str(); |
| 1030 |
{ |
mainLogUtil->logAll(slog); |
| 1031 |
for(unsigned int i=0; i<num_rows; i++) |
|
| 1032 |
{ |
if (num_rows > 0) { |
| 1033 |
row=res->Next(); |
for (unsigned int i = 0; i < num_rows; i++) { |
| 1034 |
if (!row) |
row = res->Next(); |
| 1035 |
{ |
if (!row) { |
| 1036 |
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"); |
| 1037 |
if(res){delete res; res = NULL;} |
if (res) { |
| 1038 |
return false; |
delete res; |
| 1039 |
} |
res = NULL; |
| 1040 |
|
} |
| 1041 |
//Leggi Record dal DB: |
return false; |
| 1042 |
idN=atoll(row->GetField(0)); |
} |
| 1043 |
root_id_db=atoll(row->GetField(1)); |
|
| 1044 |
pkt_num_in_db=atoll(row->GetField(2)); |
//Leggi Record dal DB: |
| 1045 |
pkt_num_fin_db=atoll(row->GetField(3)); |
idN = atoll(row->GetField(0)); |
| 1046 |
pkt_obt_in_db=atoll(row->GetField(4)); |
root_id_db = atoll(row->GetField(1)); |
| 1047 |
pkt_obt_fin_db=atoll(row->GetField(5)); |
pkt_num_in_db = atoll(row->GetField(2)); |
| 1048 |
time_in_db=atoll(row->GetField(6)); |
pkt_num_fin_db = atoll(row->GetField(3)); |
| 1049 |
time_fin_db=atoll(row->GetField(7)); |
pkt_obt_in_db = atoll(row->GetField(4)); |
| 1050 |
boot_num_db=atoll(row->GetField(8)); |
pkt_obt_fin_db = atoll(row->GetField(5)); |
| 1051 |
perc=atof(row->GetField(9)); |
time_in_db = atoll(row->GetField(6)); |
| 1052 |
|
time_fin_db = atoll(row->GetField(7)); |
| 1053 |
log.str(""); |
boot_num_db = atoll(row->GetField(8)); |
| 1054 |
log<<"*** ROOT file found in DB has idN= "<<idN<<" root_id_db= "<<root_id_db; |
perc = atof(row->GetField(9)); |
| 1055 |
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; |
|
| 1056 |
log<<" time_in_db= "<<time_in_db<<" time_fin_db= "<<time_fin_db<<" boot_num_db= "<<boot_num_db<<" perc= "<<perc<<" ***"; |
log.str(""); |
| 1057 |
log<<"\n*** Current ROOT file has pkt_number_init= "<<pkt_number_init<<" obt_init= "<<obt_init<<" real_time_init= "<<real_time_init; |
log << "*** ROOT file found in DB has idN= " << idN << " root_id_db= " << root_id_db; |
| 1058 |
log<<" pkt_number_last= "<<pkt_number_last<<" obt_last= "<<obt_last<<" real_time_last= "<<real_time_last<<" ***"; |
log << " pkt_num_in_db= " << pkt_num_in_db << " pkt_num_fin_db= " << pkt_num_fin_db << " pkt_obt_in_db= " |
| 1059 |
slog=log.str(); |
<< pkt_obt_in_db << " pkt_obt_fin_db= " << pkt_obt_fin_db; |
| 1060 |
mainLogUtil->logAll(slog); |
log << " time_in_db= " << time_in_db << " time_fin_db= " << time_fin_db << " boot_num_db= " << boot_num_db |
| 1061 |
if(perc>percentage) |
<< " perc= " << perc << " ***"; |
| 1062 |
{ |
log << "\n*** Current ROOT file has pkt_number_init= " << pkt_number_init << " obt_init= " << obt_init |
| 1063 |
mainLogUtil->logInfo("Current ROOT file is better than the one in DB"); |
<< " real_time_init= " << real_time_init; |
| 1064 |
//modifica DB |
log << " pkt_number_last= " << pkt_number_last << " obt_last= " << obt_last << " real_time_last= " |
| 1065 |
updateMergeROOT_DB(Table_ROOT_Merging, |
<< real_time_last << " ***"; |
| 1066 |
root_id_db, |
slog = log.str(); |
| 1067 |
pkt_num_in_db, pkt_num_fin_db, |
mainLogUtil->logAll(slog); |
| 1068 |
pkt_obt_in_db, pkt_obt_fin_db, |
if (perc > percentage) { |
| 1069 |
time_in_db, time_fin_db, |
mainLogUtil->logInfo("Current ROOT file is better than the one in DB"); |
| 1070 |
boot_num_db, |
//modifica DB |
| 1071 |
perc, |
updateMergeROOT_DB(Table_ROOT_Merging, root_id_db, pkt_num_in_db, pkt_num_fin_db, pkt_obt_in_db, |
| 1072 |
idN,(type_Rel_ROOT)relaz); |
pkt_obt_fin_db, time_in_db, time_fin_db, boot_num_db, perc, idN, (type_Rel_ROOT) relaz); |
| 1073 |
} |
} |
| 1074 |
else |
else { |
| 1075 |
{ |
mainLogUtil->logInfo("Found ROOT file in DB is better than current ROOT file"); |
| 1076 |
mainLogUtil->logInfo("Found ROOT file in DB is better than current ROOT file"); |
if (relaz == AFTER) { |
| 1077 |
if(relaz == AFTER) |
mainLogUtil->logInfo("Relaz:AFTER = Changing Init values of the Current ROOT file"); |
| 1078 |
{ |
pkt_number_init = (pkt_num_fin_db + 1); |
| 1079 |
mainLogUtil->logInfo("Relaz:AFTER = Changing Init values of the Current ROOT file"); |
obt_init = pkt_obt_fin_db; |
| 1080 |
pkt_number_init = (pkt_num_fin_db+1); |
real_time_init = time_fin_db; |
| 1081 |
obt_init = pkt_obt_fin_db; |
log.str(""); |
| 1082 |
real_time_init = time_fin_db; |
log << "\n*** Current ROOT file becomes: pkt_number_init= " << pkt_number_init << " obt_init= " |
| 1083 |
log.str(""); |
<< obt_init << " real_time_init= " << real_time_init; |
| 1084 |
log<<"\n*** Current ROOT file becomes: pkt_number_init= "<<pkt_number_init<<" obt_init= "<<obt_init<<" real_time_init= "<<real_time_init; |
log << " pkt_number_last= " << pkt_number_last << " obt_last= " << obt_last << " real_time_last= " |
| 1085 |
log<<" pkt_number_last= "<<pkt_number_last<<" obt_last= "<<obt_last<<" real_time_last= "<<real_time_last<<" ***"; |
<< real_time_last << " ***"; |
| 1086 |
slog=log.str(); |
slog = log.str(); |
| 1087 |
mainLogUtil->logAll(slog); |
mainLogUtil->logAll(slog); |
| 1088 |
} |
} |
| 1089 |
else if(relaz == BEFORE) |
else if (relaz == BEFORE) { |
| 1090 |
{ |
mainLogUtil->logInfo("Relaz:BEFORE = Changing Last values of the Current ROOT file"); |
| 1091 |
mainLogUtil->logInfo("Relaz:BEFORE = Changing Last values of the Current ROOT file"); |
pkt_number_last = (pkt_num_in_db - 1); |
| 1092 |
pkt_number_last = (pkt_num_in_db-1); |
obt_last = pkt_obt_in_db; |
| 1093 |
obt_last = pkt_obt_in_db; |
real_time_last = time_in_db; |
| 1094 |
real_time_last = time_in_db; |
|
| 1095 |
|
log.str(""); |
| 1096 |
log.str(""); |
log << "\n*** Current ROOT file becomes: pkt_number_init= " << pkt_number_init << " obt_init= " |
| 1097 |
log<<"\n*** Current ROOT file becomes: pkt_number_init= "<<pkt_number_init<<" obt_init= "<<obt_init<<" real_time_init= "<<real_time_init; |
<< obt_init << " real_time_init= " << real_time_init; |
| 1098 |
log<<" pkt_number_last= "<<pkt_number_last<<" obt_last= "<<obt_last<<" real_time_last= "<<real_time_last<<" ***"; |
log << " pkt_number_last= " << pkt_number_last << " obt_last= " << obt_last << " real_time_last= " |
| 1099 |
slog=log.str(); |
<< real_time_last << " ***"; |
| 1100 |
mainLogUtil->logAll(slog); |
slog = log.str(); |
| 1101 |
} |
mainLogUtil->logAll(slog); |
| 1102 |
else if(relaz == SMALLER) |
} |
| 1103 |
{ |
else if (relaz == SMALLER) { |
| 1104 |
//non devo proprio salvarlo ed esco ... |
//non devo proprio salvarlo ed esco ... |
| 1105 |
mainLogUtil->logInfo("Relaz:SMALLER = Nothing to save"); |
mainLogUtil->logInfo("Relaz:SMALLER = Nothing to save"); |
| 1106 |
mainLogUtil->logInfo("\nFinish merging ROOT files"); |
mainLogUtil->logInfo("\nFinish merging ROOT files"); |
| 1107 |
if(res){delete res; res = NULL;} |
if (res) { |
| 1108 |
if(row){delete row; row = NULL;} |
delete res; |
| 1109 |
return true; |
res = NULL; |
| 1110 |
} |
} |
| 1111 |
else if(relaz == BIGGER)//spezzettamento |
if (row) { |
| 1112 |
{ |
delete row; |
| 1113 |
mainLogUtil->logInfo("Relaz:BIGGER = (1st part) Saving the first part of the Current ROOT file"); |
row = NULL; |
| 1114 |
saveMergeROOT_DB(Table_ROOT_Merging, my_id, |
} |
| 1115 |
pkt_number_init, (pkt_num_in_db-1), |
return true; |
| 1116 |
obt_init, pkt_obt_in_db, |
} |
| 1117 |
real_time_init, time_in_db, |
else if (relaz == BIGGER)//spezzettamento |
| 1118 |
boot_number, |
{ |
| 1119 |
percentage); |
mainLogUtil->logInfo("Relaz:BIGGER = (1st part) Saving the first part of the Current ROOT file"); |
| 1120 |
|
saveMergeROOT_DB(Table_ROOT_Merging, my_id, pkt_number_init, (pkt_num_in_db - 1), obt_init, pkt_obt_in_db, |
| 1121 |
mainLogUtil->logInfo("Relaz:BIGGER = (2nd part)Changing Init values of the Current ROOT file"); |
real_time_init, time_in_db, boot_number, percentage); |
| 1122 |
pkt_number_init = (pkt_num_fin_db+1); |
|
| 1123 |
obt_init= pkt_obt_fin_db; |
mainLogUtil->logInfo("Relaz:BIGGER = (2nd part)Changing Init values of the Current ROOT file"); |
| 1124 |
real_time_init= time_fin_db; |
pkt_number_init = (pkt_num_fin_db + 1); |
| 1125 |
|
obt_init = pkt_obt_fin_db; |
| 1126 |
log.str(""); |
real_time_init = time_fin_db; |
| 1127 |
log<<"\n*** Current ROOT file becomes: pkt_number_init= "<<pkt_number_init<<" obt_init= "<<obt_init<<" real_time_init= "<<real_time_init; |
|
| 1128 |
log<<" pkt_number_last= "<<pkt_number_last<<" obt_last= "<<obt_last<<" real_time_last= "<<real_time_last<<" ***"; |
log.str(""); |
| 1129 |
slog=log.str(); |
log << "\n*** Current ROOT file becomes: pkt_number_init= " << pkt_number_init << " obt_init= " |
| 1130 |
mainLogUtil->logAll(slog); |
<< obt_init << " real_time_init= " << real_time_init; |
| 1131 |
}//if relaz |
log << " pkt_number_last= " << pkt_number_last << " obt_last= " << obt_last << " real_time_last= " |
| 1132 |
}//if perc |
<< real_time_last << " ***"; |
| 1133 |
}//for num_rows |
slog = log.str(); |
| 1134 |
}//if num_rows |
mainLogUtil->logAll(slog); |
| 1135 |
|
}//if relaz |
| 1136 |
|
}//if perc |
| 1137 |
|
}//for num_rows |
| 1138 |
|
}//if num_rows |
| 1139 |
|
|
| 1140 |
|
if (res) { |
| 1141 |
|
delete res; |
| 1142 |
|
res = NULL; |
| 1143 |
|
} |
| 1144 |
|
if (row) { |
| 1145 |
|
delete row; |
| 1146 |
|
row = NULL; |
| 1147 |
|
} |
| 1148 |
|
|
| 1149 |
|
}//for relaz |
| 1150 |
|
|
| 1151 |
|
mainLogUtil->logInfo("Saving Current ROOT file"); |
| 1152 |
|
saveMergeROOT_DB(Table_ROOT_Merging, my_id, pkt_number_init, pkt_number_last, obt_init, obt_last, real_time_init, |
| 1153 |
|
real_time_last, boot_number, percentage); |
| 1154 |
|
|
| 1155 |
if(res){delete res; res = NULL;} |
mainLogUtil->logInfo("Finish merging ROOT files"); |
|
if(row){delete row; row = NULL;} |
|
|
|
|
|
}//for relaz |
|
|
|
|
|
mainLogUtil->logInfo("Saving Current ROOT file"); |
|
|
saveMergeROOT_DB(Table_ROOT_Merging, my_id, |
|
|
pkt_number_init, pkt_number_last, |
|
|
obt_init, obt_last, |
|
|
real_time_init, real_time_last, |
|
|
boot_number, |
|
|
percentage); |
|
|
|
|
|
mainLogUtil->logInfo("Finish merging ROOT files"); |
|
| 1156 |
return true; |
return true; |
| 1157 |
|
|
| 1158 |
} |
} |
| 1159 |
|
|
| 1160 |
//unsigned int root_id, percentage non le devo modificare |
//unsigned int root_id, percentage non le devo modificare |
| 1161 |
bool PacketUser::updateMergeROOT_DB(char* table_name, |
bool PacketUser::updateMergeROOT_DB(const char* table_name, unsigned int root_id, unsigned long int pkt_number_in, |
| 1162 |
unsigned int root_id, |
unsigned long int pkt_number_fin, unsigned long int obt_in, unsigned long int obt_fin, |
| 1163 |
unsigned long int pkt_number_in, unsigned long int pkt_number_fin, |
unsigned long int mtime_init, unsigned long int mtime_last, unsigned long int mboot_num, double bad_perc, |
| 1164 |
unsigned long int obt_in, unsigned long int obt_fin, |
unsigned int ID_record, type_Rel_ROOT type_rel) { |
|
unsigned long int mtime_init, unsigned long int mtime_last, |
|
|
unsigned long int mboot_num, |
|
|
double bad_perc, |
|
|
unsigned int ID_record, type_Rel_ROOT type_rel){ |
|
|
|
|
|
stringstream oss; |
|
|
oss.str(""); |
|
| 1165 |
|
|
| 1166 |
if(type_rel == AFTER){ |
stringstream oss; |
| 1167 |
mainLogUtil->logInfo("Relaz:AFTER = Updating Last values of the DB ROOT file"); |
oss.str(""); |
|
//marco_new:tolti tutti gli apici che qui non devono essere |
|
|
oss << "UPDATE "<< table_name |
|
|
<< " SET PKT_NUMBER_FINAL ="<< (pkt_number_init - 1) |
|
|
<<", PKT_OBT_FINAL ="<< obt_init |
|
|
<<", REAL_TIME_LAST ="<< real_time_init<<" WHERE ID_N ="<< ID_record <<";"; |
|
|
|
|
|
} |
|
|
else if(type_rel == BEFORE){ |
|
|
mainLogUtil->logInfo("Relaz:BEFORE = Updating Init values of the DB ROOT file"); |
|
|
oss << "UPDATE "<< table_name |
|
|
<< " SET PKT_NUMBER_INIT ="<< (pkt_number_last+1) |
|
|
<<", PKT_OBT_INIT ="<< obt_last |
|
|
<<", REAL_TIME_INIT ="<< real_time_last<<" WHERE ID_N ="<< ID_record<<";"; |
|
|
} |
|
|
else if(type_rel == SMALLER){ |
|
|
//spezzettamentento |
|
|
mainLogUtil->logInfo("Relaz:SMALLER = (1st part) Updating Last values of the DB ROOT file"); |
|
|
|
|
|
oss << "UPDATE "<< table_name |
|
|
<< " SET PKT_NUMBER_FINAL="<< (pkt_number_init-1) |
|
|
<<", PKT_OBT_FINAL ="<< obt_init |
|
|
<<", REAL_TIME_LAST ="<< real_time_init<<" WHERE ID_N ="<< ID_record<<";"; |
|
|
|
|
|
mainLogUtil->logInfo("Relaz:SMALLER = (2nd part) Saving the second part of the DB ROOT file"); |
|
|
|
|
|
saveMergeROOT_DB(table_name, root_id, |
|
|
(pkt_number_last+1), pkt_number_fin, |
|
|
obt_last, obt_fin, |
|
|
real_time_last, mtime_last, |
|
|
mboot_num, |
|
|
bad_perc); |
|
|
} |
|
|
else if(type_rel == BIGGER){ |
|
|
//marco_new: ok anche se coincidenti etc |
|
|
// oss << "DELETE FROM "<< table_name <<" WHERE ID_N ="<< ID_record<<";"; // EMILIANO |
|
|
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 |
|
|
mainLogUtil->logInfo("Record deleted from merging table"); |
|
|
} |
|
|
else |
|
|
return false; |
|
| 1168 |
|
|
| 1169 |
string msg = oss.str(); |
if (type_rel == AFTER) { |
| 1170 |
mainLogUtil->logInfo(msg); |
mainLogUtil->logInfo("Relaz:AFTER = Updating Last values of the DB ROOT file"); |
| 1171 |
|
//marco_new:tolti tutti gli apici che qui non devono essere |
| 1172 |
stringstream oss1; |
|
| 1173 |
oss1.str()=""; |
int good = 1; |
| 1174 |
string msg1; |
if ( pkt_number_in >= (pkt_number_init - 1) && abs((int)(pkt_number_in-(pkt_number_init-1)))<10 ) good = 0; |
| 1175 |
|
|
| 1176 |
TSQLResult* res=NULL; |
oss << "UPDATE " << table_name << " SET PKT_NUMBER_FINAL =" << (pkt_number_init - 1) << ", PKT_OBT_FINAL =" |
| 1177 |
res= sqlServer->Query(oss.str().c_str()); |
<< obt_init << ", REAL_TIME_LAST =" << real_time_init << ", GOOD="<< good << " WHERE ID_N =" << ID_record << ";"; |
| 1178 |
if(!res) |
|
| 1179 |
{ |
} |
| 1180 |
oss1<<"DBError UNABLE to: "<<oss.str().c_str()<<endl; |
else if (type_rel == BEFORE) { |
| 1181 |
msg1=oss1.str(); |
mainLogUtil->logInfo("Relaz:BEFORE = Updating Init values of the DB ROOT file"); |
| 1182 |
mainLogUtil->logError(msg1); |
|
| 1183 |
return false; |
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 |
if(res){delete res; res = NULL;} |
|
| 1186 |
return true; |
oss << "UPDATE " << table_name << " SET PKT_NUMBER_INIT =" << (pkt_number_last + 1) << ", PKT_OBT_INIT =" |
| 1187 |
|
<< obt_last << ", REAL_TIME_INIT =" << real_time_last << ", GOOD="<< good << " WHERE ID_N =" << ID_record << ";"; |
| 1188 |
|
} |
| 1189 |
|
else if (type_rel == SMALLER) { |
| 1190 |
|
//spezzettamentento |
| 1191 |
|
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 =" |
| 1197 |
|
<< 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"); |
| 1200 |
|
|
| 1201 |
|
saveMergeROOT_DB(table_name, root_id, (pkt_number_last + 1), pkt_number_fin, obt_last, obt_fin, real_time_last, |
| 1202 |
|
mtime_last, mboot_num, bad_perc); |
| 1203 |
|
} |
| 1204 |
|
else if (type_rel == BIGGER) { |
| 1205 |
|
//marco_new: ok anche se coincidenti etc |
| 1206 |
|
// oss << "DELETE FROM "<< table_name <<" WHERE ID_N ="<< ID_record<<";"; // EMILIANO |
| 1207 |
|
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 |
| 1208 |
|
mainLogUtil->logInfo("Record deleted from merging table"); |
| 1209 |
|
} |
| 1210 |
|
else |
| 1211 |
|
return false; |
| 1212 |
|
|
| 1213 |
|
string msg = oss.str(); |
| 1214 |
|
mainLogUtil->logInfo(msg); |
| 1215 |
|
|
| 1216 |
|
stringstream oss1; |
| 1217 |
|
oss1.str() = ""; |
| 1218 |
|
string msg1; |
| 1219 |
|
|
| 1220 |
|
TSQLResult* res = NULL; |
| 1221 |
|
res = sqlServer->Query(oss.str().c_str()); |
| 1222 |
|
if (!res) { |
| 1223 |
|
oss1 << "DBError UNABLE to: " << oss.str().c_str() << endl; |
| 1224 |
|
msg1 = oss1.str(); |
| 1225 |
|
mainLogUtil->logError(msg1); |
| 1226 |
|
return false; |
| 1227 |
|
} |
| 1228 |
|
if (res) { |
| 1229 |
|
delete res; |
| 1230 |
|
res = NULL; |
| 1231 |
|
} |
| 1232 |
|
return true; |
| 1233 |
} |
} |
| 1234 |
|
|
| 1235 |
//cerca eventuali ROOT files in DB che possono venire mergiati |
//cerca eventuali ROOT files in DB che possono venire mergiati |
| 1236 |
//marco_new bordi: messo in after a before casi in cui smaller con un bordo in comune |
//marco_new bordi: messo in after a before casi in cui smaller con un bordo in comune |
| 1237 |
//marco_new bordi: messo in bigger casi con bordi in comune; tra questi anche caso particolare di coincidente |
//marco_new bordi: messo in bigger casi con bordi in comune; tra questi anche caso particolare di coincidente |
| 1238 |
//marco_new bordi: smaller resta solo caso in cui DB e' piu largo sia a dx che a sx |
//marco_new bordi: smaller resta solo caso in cui DB e' piu largo sia a dx che a sx |
| 1239 |
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(const char* table_name, unsigned long int mtime_init, unsigned long int mtime_last, |
| 1240 |
{ |
type_Rel_ROOT type_rel) { |
| 1241 |
TSQLResult* res=NULL; |
TSQLResult* res = NULL; |
| 1242 |
stringstream query; |
stringstream query; |
| 1243 |
query.str(""); |
query.str(""); |
| 1244 |
|
|
| 1245 |
if(type_rel == AFTER) |
if (type_rel == AFTER) |
| 1246 |
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 |
query << "select * from " << table_name << " where GOOD=1 and REAL_TIME_LAST > " << mtime_init |
| 1247 |
else if(type_rel == BEFORE) |
<< " and REAL_TIME_LAST <= " << mtime_last << " and REAL_TIME_INIT < " << mtime_init; // EMI |
| 1248 |
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 |
else if (type_rel == BEFORE) |
| 1249 |
else if(type_rel == SMALLER) |
query << "select * from " << table_name << " where GOOD=1 and REAL_TIME_INIT >= " << mtime_init |
| 1250 |
query<<"select * from "<<table_name<<" where GOOD=1 and REAL_TIME_INIT < "<< mtime_init <<" and REAL_TIME_LAST > "<< mtime_last; // EMI |
<< " and REAL_TIME_INIT < " << mtime_last << " and REAL_TIME_LAST > " << mtime_last; // EMI |
| 1251 |
else if(type_rel == BIGGER) |
else if (type_rel == SMALLER) |
| 1252 |
query<<"select * from "<<table_name<<" where GOOD=1 and REAL_TIME_INIT >= "<< mtime_init <<" and REAL_TIME_LAST <= "<< mtime_last; // EMI |
query << "select * from " << table_name << " where GOOD=1 and REAL_TIME_INIT < " << mtime_init |
| 1253 |
else |
<< " and REAL_TIME_LAST > " << mtime_last; // EMI |
| 1254 |
return 0; |
else if (type_rel == BIGGER) |
| 1255 |
|
query << "select * from " << table_name << " where GOOD=1 and REAL_TIME_INIT >= " << mtime_init |
| 1256 |
query<< " order by REAL_TIME_INIT ASC";//marco_new: inutile |
<< " and REAL_TIME_LAST <= " << mtime_last; // EMI |
| 1257 |
//se volessi mettere un filtro sulla qualita' |
else |
| 1258 |
// query<<" and NUM_PKT_SAVED - BAD_PKT_CALREAD - BAD_PKT_READ - BAD_PKT >= 2" ; |
return 0; |
| 1259 |
string msg = query.str(); |
|
| 1260 |
mainLogUtil->logAll(msg); |
query << " order by REAL_TIME_INIT ASC;";//marco_new: inutile |
| 1261 |
res= sqlServer->Query(query.str().c_str()); |
//se volessi mettere un filtro sulla qualita' |
| 1262 |
stringstream oss1; |
// query<<" and NUM_PKT_SAVED - BAD_PKT_CALREAD - BAD_PKT_READ - BAD_PKT >= 2" ; |
| 1263 |
oss1.str()=""; |
string msg = query.str(); |
| 1264 |
string msg1; |
mainLogUtil->logAll(msg); |
| 1265 |
|
res = sqlServer->Query(query.str().c_str()); |
| 1266 |
if (!res) |
stringstream oss1; |
| 1267 |
{ |
oss1.str() = ""; |
| 1268 |
oss1<<"DBError UNABLE to: "<<query.str().c_str()<<endl; |
string msg1; |
|
msg1=oss1.str(); |
|
|
mainLogUtil->logError(msg1); |
|
|
} |
|
|
|
|
|
return res; |
|
|
} |
|
|
|
|
|
bool PacketUser::saveMergeROOT_DB(char* table_name, unsigned int root_id, |
|
|
unsigned long int pkt_number_in, unsigned long int pkt_number_fin, |
|
|
unsigned long int obt_in, unsigned long int obt_fin, |
|
|
unsigned long int mtime_init, unsigned long int mtime_last, |
|
|
unsigned long int mboot_num, |
|
|
double percentage) |
|
|
{ |
|
|
|
|
|
stringstream oss; |
|
|
oss.str(""); |
|
|
oss << "INSERT INTO "<< table_name <<" (ID_N, ROOT_ID_N, PKT_NUMBER_INIT, PKT_NUMBER_FINAL, PKT_OBT_INIT, PKT_OBT_FINAL, REAL_TIME_INIT, REAL_TIME_LAST, BOOT_NUMBER, BAD_PKT_PERCENTAGE, INSERT_TIME, INSERTED_BY)" |
|
|
<< " VALUES ('"<<0<< "','" <<root_id<<"','"<< pkt_number_in <<"','"<< pkt_number_fin << "','"<< obt_in <<"','"<< obt_fin<< "','" |
|
|
<< mtime_init << "','" << mtime_last << "','" |
|
|
<< mboot_num <<"','" |
|
|
<< percentage <<"'," |
|
|
<<"NULL"<<",'" |
|
|
<< tag_value<<"'" |
|
|
<< ")"; |
|
| 1269 |
|
|
| 1270 |
string msg = oss.str(); |
if (!res) { |
| 1271 |
mainLogUtil->logAll(msg); |
oss1 << "DBError UNABLE to: " << query.str().c_str() << endl; |
| 1272 |
|
msg1 = oss1.str(); |
| 1273 |
//marco_new: controlla |
mainLogUtil->logError(msg1); |
| 1274 |
//marco_new: esci se sono arrivato a zero |
} |
|
// if(real_time_last==real_time_init){ |
|
|
if(mtime_init==mtime_last){ |
|
|
mainLogUtil->logAll("Nothing to be saved"); |
|
|
|
|
|
// if(res){delete res; res = NULL;} |
|
|
// if(row){delete row; row = NULL;} |
|
|
return true; |
|
|
} |
|
| 1275 |
|
|
| 1276 |
stringstream oss1; |
return res; |
| 1277 |
oss1.str()=""; |
} |
| 1278 |
string msg1; |
|
| 1279 |
|
bool PacketUser::saveMergeROOT_DB(const char* table_name, unsigned int root_id, unsigned long int pkt_number_in, |
| 1280 |
TSQLResult* res=NULL; |
unsigned long int pkt_number_fin, unsigned long int obt_in, unsigned long int obt_fin, |
| 1281 |
res= sqlServer->Query(oss.str().c_str()); |
unsigned long int mtime_init, unsigned long int mtime_last, unsigned long int mboot_num, double percentage) { |
| 1282 |
if(!res) |
|
| 1283 |
{ |
int good = 1; |
| 1284 |
oss1<<"DBError UNABLE to: "<<oss.str().c_str()<<endl; |
if ( pkt_number_in >= pkt_number_fin && abs((int)(pkt_number_fin-pkt_number_in))<10 ) good = 0; |
| 1285 |
msg1=oss1.str(); |
|
| 1286 |
mainLogUtil->logError(msg1); |
stringstream oss; |
| 1287 |
return false; |
oss.str(""); |
| 1288 |
} |
oss << "INSERT INTO " << table_name |
| 1289 |
if(res){delete res; res = NULL;} |
<< " (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 |
return true; |
<< " VALUES ('" << 0 << "','" << root_id << "','" << pkt_number_in << "','" << pkt_number_fin << "','" << obt_in |
| 1291 |
|
<< "','" << obt_fin << "','" << mtime_init << "','" << mtime_last << "','" << mboot_num << "','" << percentage |
| 1292 |
|
<< "'," << "NULL" << ",'" << tag_value << "','" << good <<"');"; |
| 1293 |
|
|
| 1294 |
|
string msg = oss.str(); |
| 1295 |
|
mainLogUtil->logAll(msg); |
| 1296 |
|
|
| 1297 |
|
//marco_new: controlla |
| 1298 |
|
//marco_new: esci se sono arrivato a zero |
| 1299 |
|
// if(real_time_last==real_time_init){ |
| 1300 |
|
if (mtime_init == mtime_last) { |
| 1301 |
|
mainLogUtil->logAll("Nothing to be saved"); |
| 1302 |
|
|
| 1303 |
|
// if(res){delete res; res = NULL;} |
| 1304 |
|
// if(row){delete row; row = NULL;} |
| 1305 |
|
return true; |
| 1306 |
|
} |
| 1307 |
|
|
| 1308 |
|
stringstream oss1; |
| 1309 |
|
oss1.str() = ""; |
| 1310 |
|
string msg1; |
| 1311 |
|
|
| 1312 |
|
TSQLResult* res = NULL; |
| 1313 |
|
res = sqlServer->Query(oss.str().c_str()); |
| 1314 |
|
if (!res) { |
| 1315 |
|
oss1 << "DBError UNABLE to: " << oss.str().c_str() << endl; |
| 1316 |
|
msg1 = oss1.str(); |
| 1317 |
|
mainLogUtil->logError(msg1); |
| 1318 |
|
return false; |
| 1319 |
|
} |
| 1320 |
|
if (res) { |
| 1321 |
|
delete res; |
| 1322 |
|
res = NULL; |
| 1323 |
|
} |
| 1324 |
|
return true; |
| 1325 |
} |
} |
| 1326 |
|
|
| 1327 |
//Utility: return max(IDN) |
//Utility: return max(IDN) |
| 1328 |
unsigned int PacketUser::select_maxIDN_DB(char* table_name) |
unsigned int PacketUser::select_maxIDN_DB(const char* table_name) { |
|
{ |
|
| 1329 |
|
|
| 1330 |
if (!strcmp(table_name,Table_ROOT_Bad)) |
if (!strcmp(table_name, Table_ROOT_Bad)) { |
| 1331 |
{ |
return 0; |
| 1332 |
return 0; |
} |
| 1333 |
} |
unsigned int idN = 0; |
| 1334 |
unsigned int idN=0; |
TSQLResult* res = NULL; |
| 1335 |
TSQLResult* res=NULL; |
stringstream oss; |
| 1336 |
stringstream oss; |
oss.str(""); |
| 1337 |
oss.str(""); |
oss << "select max(ID_N) from " << table_name; |
| 1338 |
oss<<"select max(ID_N) from "<<table_name; |
// string msg = oss.str(); |
| 1339 |
// string msg = oss.str(); |
// mainLogUtil->logAll(msg); |
| 1340 |
// mainLogUtil->logAll(msg); |
res = sqlServer->Query(oss.str().c_str()); |
| 1341 |
res= sqlServer->Query(oss.str().c_str()); |
|
| 1342 |
|
stringstream oss1; |
| 1343 |
stringstream oss1; |
oss1.str() = ""; |
| 1344 |
oss1.str()=""; |
string msg1; |
| 1345 |
string msg1; |
|
| 1346 |
|
if (!res) { |
| 1347 |
if(!res) |
oss1 << "DBError UNABLE to: " << oss.str().c_str() << endl; |
| 1348 |
{ |
msg1 = oss1.str(); |
| 1349 |
oss1<<"DBError UNABLE to: "<<oss.str().c_str()<<endl; |
mainLogUtil->logError(msg1); |
| 1350 |
msg1=oss1.str(); |
return 0; |
| 1351 |
mainLogUtil->logError(msg1); |
} |
| 1352 |
return 0; |
|
| 1353 |
} |
TSQLRow* row = NULL; |
| 1354 |
|
row = res->Next(); |
| 1355 |
TSQLRow* row=NULL; |
if (!row) { |
| 1356 |
row=res->Next(); |
oss1 << "DBError UNABLE to: " << oss.str().c_str() << endl; |
| 1357 |
if (!row ) |
msg1 = oss1.str(); |
| 1358 |
{ |
mainLogUtil->logError(msg1); |
| 1359 |
oss1<<"DBError UNABLE to: "<<oss.str().c_str()<<endl; |
return 0; |
| 1360 |
msg1=oss1.str(); |
} |
| 1361 |
mainLogUtil->logError(msg1); |
|
| 1362 |
return 0; |
idN = atoi(row->GetField(0)); |
| 1363 |
} |
if (row) { |
| 1364 |
|
delete row; |
| 1365 |
idN=atoi(row->GetField(0)); |
row = NULL; |
| 1366 |
if(row){delete row; row = NULL;} |
} |
| 1367 |
if(res){delete res; res = NULL;} |
if (res) { |
| 1368 |
|
delete res; |
| 1369 |
oss<<". idN = "<<idN; |
res = NULL; |
| 1370 |
string msg = oss.str(); |
} |
| 1371 |
mainLogUtil->logAll(msg); |
|
| 1372 |
|
oss << ". idN = " << idN; |
| 1373 |
|
string msg = oss.str(); |
| 1374 |
|
mainLogUtil->logAll(msg); |
| 1375 |
|
|
| 1376 |
return idN; |
return idN; |
| 1377 |
} |
} |
| 1378 |
|
|
| 1379 |
/** |
/** |
| 1380 |
* Lock par=table, if par=null lock all tables |
* Lock par=table, if par=null lock all tables |
| 1381 |
*/ |
*/ |
| 1382 |
int PacketUser::LockTables(char* tableTobeLocked) |
int PacketUser::LockTables(const char* tableTobeLocked) { |
| 1383 |
{ |
//se non ho il DB :) |
| 1384 |
//se non ho il DB :) |
if (!do_cont_check) |
| 1385 |
if(!do_cont_check) return 999; |
return 999; |
| 1386 |
|
|
| 1387 |
TSQLResult* res=NULL; |
TSQLResult* res = NULL; |
| 1388 |
stringstream oss; |
stringstream oss; |
| 1389 |
oss.str(""); |
oss.str(""); |
| 1390 |
if(!tableTobeLocked) |
if (!tableTobeLocked) |
| 1391 |
oss << "lock table "<<Table_ROOT_Good<<" write, "<<Table_ROOT_Bad<<" write, "<<Table_GL_RESURS_OFFSET<<" write, "<<Table_ROOT_Merging<<" write;"; |
oss << "lock table " << Table_ROOT_Good << " write, " << Table_ROOT_Bad << " write, " << Table_GL_RESURS_OFFSET |
| 1392 |
else |
<< " write, " << Table_ROOT_Merging << " write;"; |
| 1393 |
oss << "lock table "<<tableTobeLocked<<" write; "; |
else |
| 1394 |
|
oss << "lock table " << tableTobeLocked << " write; "; |
| 1395 |
string msg = oss.str(); |
|
| 1396 |
mainLogUtil->logAll(msg); |
string msg = oss.str(); |
| 1397 |
|
mainLogUtil->logAll(msg); |
| 1398 |
res= sqlServer->Query(oss.str().c_str()); |
|
| 1399 |
|
res = sqlServer->Query(oss.str().c_str()); |
| 1400 |
stringstream oss1; |
|
| 1401 |
oss1.str()=""; |
stringstream oss1; |
| 1402 |
string msg1; |
oss1.str() = ""; |
| 1403 |
|
string msg1; |
| 1404 |
if(!res) |
|
| 1405 |
{ |
if (!res) { |
| 1406 |
oss1<<"DBError UNABLE to: "<<oss.str().c_str()<<endl; |
oss1 << "DBError UNABLE to: " << oss.str().c_str() << endl; |
| 1407 |
msg1=oss1.str(); |
msg1 = oss1.str(); |
| 1408 |
mainLogUtil->logError(msg1); |
mainLogUtil->logError(msg1); |
| 1409 |
return 1; |
return 1; |
| 1410 |
} |
} |
| 1411 |
|
|
| 1412 |
if(res){delete res; res = NULL;} |
if (res) { |
| 1413 |
mainLogUtil->logAll("TABLES LOCKED"); |
delete res; |
| 1414 |
return 0; |
res = NULL; |
| 1415 |
|
} |
| 1416 |
|
mainLogUtil->logAll("TABLES LOCKED"); |
| 1417 |
|
return 0; |
| 1418 |
} |
} |
| 1419 |
|
|
| 1420 |
/** |
/** |
| 1421 |
* UNLock tables |
* UNLock tables |
| 1422 |
*/ |
*/ |
| 1423 |
int PacketUser::UnLockTables(){ |
int PacketUser::UnLockTables() { |
| 1424 |
//se non ho il DB :) |
//se non ho il DB :) |
| 1425 |
if(!do_cont_check) return 999; |
if (!do_cont_check) |
| 1426 |
|
return 999; |
| 1427 |
|
|
| 1428 |
TSQLResult* res=NULL; |
TSQLResult* res = NULL; |
| 1429 |
stringstream oss; |
stringstream oss; |
| 1430 |
oss.str(""); |
oss.str(""); |
| 1431 |
oss << "unlock tables;"; |
oss << "unlock tables;"; |
| 1432 |
|
|
| 1433 |
string msg = oss.str(); |
string msg = oss.str(); |
| 1434 |
mainLogUtil->logAll(msg); |
mainLogUtil->logAll(msg); |
| 1435 |
|
|
| 1436 |
res= sqlServer->Query(oss.str().c_str()); |
res = sqlServer->Query(oss.str().c_str()); |
| 1437 |
|
|
| 1438 |
stringstream oss1; |
stringstream oss1; |
| 1439 |
oss1.str()=""; |
oss1.str() = ""; |
| 1440 |
string msg1; |
string msg1; |
|
|
|
|
if(!res) |
|
|
{ |
|
|
oss1<<"DBError UNABLE to: "<<oss.str().c_str()<<endl; |
|
|
msg1=oss1.str(); |
|
|
mainLogUtil->logError(msg1); |
|
|
return 1; |
|
|
} |
|
|
|
|
|
if(res){delete res; res = NULL;} |
|
|
mainLogUtil->logAll("TABLES UNLOCKED"); |
|
| 1441 |
|
|
| 1442 |
return 0; |
if (!res) { |
| 1443 |
|
oss1 << "DBError UNABLE to: " << oss.str().c_str() << endl; |
| 1444 |
|
msg1 = oss1.str(); |
| 1445 |
|
mainLogUtil->logError(msg1); |
| 1446 |
|
return 1; |
| 1447 |
|
} |
| 1448 |
|
|
| 1449 |
|
if (res) { |
| 1450 |
|
delete res; |
| 1451 |
|
res = NULL; |
| 1452 |
|
} |
| 1453 |
|
mainLogUtil->logAll("TABLES UNLOCKED"); |
| 1454 |
|
|
| 1455 |
|
return 0; |
| 1456 |
} |
} |
| 1457 |
|
|
| 1458 |
/*********************************************************/ |
/*********************************************************/ |
| 1459 |
//marco_new_31 |
//marco_new_31 |
| 1460 |
void PacketUser::OpenDBConnection(char* tableTobeLocked){ |
void PacketUser::OpenDBConnection(const char* tableTobeLocked) { |
| 1461 |
if(do_cont_check){ |
if (do_cont_check) { |
| 1462 |
//controllo che non sia gia' aperta |
//controllo che non sia gia' aperta |
| 1463 |
if(!sqlServer){ |
if (!sqlServer) { |
| 1464 |
sqlServer = TSQLServer::Connect(connection,db_user,db_pwd); |
sqlServer = TSQLServer::Connect(connection, db_user, db_pwd); |
| 1465 |
if ((!sqlServer)||(!(sqlServer->IsConnected()))){cout<<"Can not connect with MYSQL sever"<<endl;} |
if ((!sqlServer) || (!(sqlServer->IsConnected()))) { |
| 1466 |
mainLogUtil->logAll("Connected to DB"); |
cout << "Can not connect with MYSQL sever" << endl; |
| 1467 |
//blocca le tabelle |
} |
| 1468 |
LockTables(tableTobeLocked); |
mainLogUtil->logAll("Connected to DB"); |
| 1469 |
} |
stringstream myquery; |
| 1470 |
} |
myquery.str(""); |
| 1471 |
|
myquery << "SET time_zone='+0:00'"; |
| 1472 |
|
sqlServer->Query(myquery.str().c_str()); |
| 1473 |
|
//blocca le tabelle |
| 1474 |
|
LockTables(tableTobeLocked); |
| 1475 |
|
} |
| 1476 |
|
} |
| 1477 |
|
|
| 1478 |
} |
} |
| 1479 |
|
|
| 1480 |
//marco_new_31 |
//marco_new_31 |
| 1481 |
void PacketUser::CloseDBConnection(){ |
void PacketUser::CloseDBConnection() { |
| 1482 |
if(do_cont_check){ |
if (do_cont_check) { |
| 1483 |
//controllo che ce ne sia una aperta |
//controllo che ce ne sia una aperta |
| 1484 |
if(sqlServer && sqlServer->IsConnected()){ |
if (sqlServer && sqlServer->IsConnected()) { |
| 1485 |
//marco_new: sblocca tutte le tabelle |
//marco_new: sblocca tutte le tabelle |
| 1486 |
UnLockTables(); |
UnLockTables(); |
| 1487 |
sqlServer->Close(); |
sqlServer->Close(); |
| 1488 |
delete sqlServer; |
delete sqlServer; |
| 1489 |
sqlServer=NULL; |
sqlServer = NULL; |
| 1490 |
mainLogUtil->logAll("Closed Connection to DB"); |
mainLogUtil->logAll("Closed Connection to DB"); |
| 1491 |
} |
} |
| 1492 |
} |
} |
| 1493 |
} |
} |
| 1494 |
|
|
|
|
|
|
|
|
| 1495 |
/***********************************************************************************************************************/ |
/***********************************************************************************************************************/ |
| 1496 |
/*#################################################### HIC SUNT LEONES ################################################*/ |
/*#################################################### HIC SUNT LEONES ################################################*/ |
| 1497 |
/***********************************************************************************************************************/ |
/***********************************************************************************************************************/ |
| 1498 |
//UNUSED: dbg functions... |
//UNUSED: dbg functions... |
| 1499 |
|
|
| 1500 |
//Return the system time in ms |
//Return the system time in ms |
| 1501 |
unsigned long long PacketUser::Record_Time(){ |
unsigned long long PacketUser::Record_Time() { |
| 1502 |
timeval tv; |
timeval tv; |
| 1503 |
gettimeofday(&tv,NULL); |
gettimeofday(&tv, NULL); |
| 1504 |
unsigned long long timems = (unsigned long long)tv.tv_sec * (unsigned long long)1000 + tv.tv_usec / 1000; |
unsigned long long timems = (unsigned long long) tv.tv_sec * (unsigned long long) 1000 + tv.tv_usec / 1000; |
| 1505 |
return timems; |
return timems; |
| 1506 |
} |
} |
| 1507 |
|
|
| 1508 |
//dbg_functions: |
//dbg_functions: |
| 1509 |
|
|
| 1510 |
//UNUSED. save a packet in a file |
//UNUSED. save a packet in a file |
| 1511 |
void PacketUser::savePKT_file(char* headerPkt, |
void PacketUser::savePKT_file(char* headerPkt, char* pamPkt, long int length, bool append, char* nomefile) { |
| 1512 |
char* pamPkt, |
char fno[80] = ""; |
| 1513 |
long int length, |
ofstream fout; |
| 1514 |
bool append, |
sprintf(fno, "%s/pkt%d_of_%s.pkt", gSystem->ExpandPathName(outDir), numPKTSaved, nomefile); // EMI |
| 1515 |
char* nomefile) |
|
| 1516 |
{ |
if (append == true) |
| 1517 |
char fno[80]=""; |
fout.open(fno, ios::binary | ios::app); |
| 1518 |
ofstream fout; |
else |
| 1519 |
sprintf(fno,"%s/pkt%d_of_%s.pkt", gSystem->ExpandPathName(outDir), numPKTSaved, nomefile); // EMI |
fout.open(fno, ios::binary); |
| 1520 |
|
|
| 1521 |
if(append==true) |
if (!fout) { |
| 1522 |
fout.open(fno, ios::binary | ios::app); |
cout << "can not open output file " << fno << endl; |
| 1523 |
else |
return; |
| 1524 |
fout.open(fno, ios::binary); |
} |
| 1525 |
|
fout.write(headerPkt, LENGTH_HEADER_PKT); |
| 1526 |
if (!fout) {cout<<"can not open output file "<<fno<<endl; return;} |
fout.write(pamPkt, length); |
| 1527 |
fout.write(headerPkt,LENGTH_HEADER_PKT); |
fout.close(); |
|
fout.write(pamPkt,length); |
|
|
fout.close(); |
|
| 1528 |
} |
} |
| 1529 |
|
|
| 1530 |
//UNUSED |
//UNUSED |
| 1531 |
void PacketUser::saveALL_PKT(char* headerPkt, char* pamPkt, long int length, bool append) |
void PacketUser::saveALL_PKT(char* headerPkt, char* pamPkt, long int length, bool append) { |
| 1532 |
{ |
char fno[80] = ""; |
| 1533 |
char fno[80]=""; |
ofstream fout; |
| 1534 |
ofstream fout; |
if (append == true) { |
| 1535 |
if(append==true) |
sprintf(fno, "%s/packets.pkt", gSystem->ExpandPathName(outDir)); // EMI |
| 1536 |
{ |
fout.open(fno, ios::binary | ios::app); |
| 1537 |
sprintf(fno,"%s/packets.pkt", gSystem->ExpandPathName(outDir)); // EMI |
} |
| 1538 |
fout.open(fno, ios::binary | ios::app); |
else { |
| 1539 |
} |
sprintf(fno, "%s/packet%d.pkt", gSystem->ExpandPathName(outDir), numPKT); // EMI |
| 1540 |
else{ |
fout.open(fno, ios::binary); |
| 1541 |
sprintf(fno,"%s/packet%d.pkt", gSystem->ExpandPathName(outDir), numPKT ); // EMI |
} |
|
fout.open(fno, ios::binary); |
|
|
} |
|
|
|
|
|
if (!fout) {cout<<"can not open output file "<<fno<<endl; return;} |
|
|
fout.write(headerPkt,LENGTH_HEADER_PKT); |
|
|
fout.write(pamPkt,length); |
|
|
fout.close(); |
|
|
} |
|
| 1542 |
|
|
| 1543 |
|
if (!fout) { |
| 1544 |
|
cout << "can not open output file " << fno << endl; |
| 1545 |
|
return; |
| 1546 |
|
} |
| 1547 |
|
fout.write(headerPkt, LENGTH_HEADER_PKT); |
| 1548 |
|
fout.write(pamPkt, length); |
| 1549 |
|
fout.close(); |
| 1550 |
|
} |
| 1551 |
|
|
| 1552 |
} |
} |