1 |
//============================================================================ |
//============================================================================ |
2 |
// $Id: PacketUser.cpp,v 1.3 2008/12/18 12:58:37 mocchiut Exp $ |
// $Id: PacketUser.cpp,v 1.10 2009/12/24 10:31:12 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]; |
|
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().c_str(); |
oss << "In download: " << download << " timeOffset: " << timeOffset << " obt_time_sync: " << obt_time_sync |
356 |
string msg = oss.str(); |
<< " last_time_sync_info: " << last_time_sync_info << " using Packet Type: " << type->GetName(); |
357 |
mainLogUtil->logAll(msg); |
// 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 |
|
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 |
string msg = oss.str(); |
// oss<<"In download: "<<download<<" boot_number: "<<boot_number<<" using Packet Type: "<<type->GetName().c_str(); |
385 |
mainLogUtil->logAll(msg); |
oss << "In download: " << download << " boot_number: " << boot_number << " using Packet Type: " << type->GetName(); |
386 |
return; |
string msg = oss.str(); |
387 |
} |
mainLogUtil->logAll(msg); |
388 |
else |
return; |
389 |
{ |
} |
390 |
return; |
else { |
391 |
} |
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 << " 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 |
|
if (!do_cont_check) |
557 |
|
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; |
654 |
|
|
655 |
|
}; |
656 |
|
} |
657 |
|
|
658 |
|
if ( real_time_init || real_time_last) { |
659 |
|
//saves info in DB in table Table_ROOT |
660 |
|
if (boot_number == 0) |
661 |
|
boot_number = boot_number_prevvalue; |
662 |
|
|
663 |
|
if (saveROOT_DB( |
664 |
|
Table_ROOT_Good, |
665 |
|
outDir, // here outDir is good, no expand EMI |
666 |
|
filename, pkt_number_init, pkt_number_last, obt_init, obt_last, obt_time_sync, last_time_sync_info, |
667 |
|
real_time_init, real_time_last, boot_number, timeOffset, bad_pkt, bad_pkt_EventReader, bad_pkt_CalibReader, |
668 |
|
numPKTSaved, fni, time_is_estimated) == true) { |
669 |
|
oss.str() = ""; |
670 |
|
oss << "Saved information regarding file: " << filename << " in table " << Table_ROOT_Good << " id= " << my_id; |
671 |
|
msg = oss.str(); |
672 |
|
mainLogUtil->logInfo(msg); |
673 |
|
|
674 |
|
if (tryMerge) { |
675 |
|
merge_ROOTfiles(); |
676 |
|
} |
677 |
|
} else { |
678 |
|
oss.str() = ""; |
679 |
|
oss << "Problem storing information in DB regarding file: " << filename; |
680 |
|
msg = oss.str(); |
681 |
|
mainLogUtil->logError(msg); |
682 |
|
} |
683 |
|
}; |
684 |
|
|
685 |
// se non faccio proprio controlli su continuita' neanche salvo su DB |
// if dbinfo is not empty than |
686 |
if(!do_cont_check) return; |
if ( obt_time_sync && last_time_sync_info && arsize > 0 ){ |
687 |
|
|
|
stringstream oss; |
|
|
oss.str()=""; |
|
|
|
|
|
//TODO: check when I don't want to log in DB informations |
|
|
// se non ho salvato nessun pacchetto |
|
|
if(numPKTSaved==0){ |
|
|
stringstream err; |
|
|
err.str()=""; |
|
|
err<<"NO PACKET SAVED in file: "<< rootfilename <<" The group is empty: you can remove this file."; |
|
|
msg = err.str(); |
|
|
mainLogUtil->logError(msg); |
|
|
return; |
|
|
} |
|
|
|
|
|
//se non ho salvato nessun pacchetto buono |
|
|
if((numPKTSaved-bad_pkt_EventReader-bad_pkt_CalibReader-bad_pkt)==0){ |
|
|
stringstream err; |
|
|
err.str()=""; |
|
|
err<<"NO GOOD PACKET SAVED in file: "<< rootfilename <<" The group is BAD: you may want to remove this file."; |
|
|
msg = err.str(); |
|
|
mainLogUtil->logInfo(msg); |
|
|
// mainLogUtil->logError(msg); |
|
|
// return; //TODO: decidi se nn vuoi affatto usarlo o addirittura salvarlo tra i BAD??? |
|
|
} |
|
|
|
|
|
if(!single_connection){ |
|
|
OpenDBConnection(NULL);//Nota qui ho deciso di lockare tutte le tabelle |
|
|
} |
|
|
|
|
|
//don't save in Table_ROOT_Good and don't search for ROOT files in the same temporal range |
|
|
if((!real_time_init)&&(!real_time_last)) |
|
|
{ |
|
|
//saved in another table for future study |
|
|
if(saveROOT_DB(Table_ROOT_Bad, outDir,// here outDir is good, no expand EMI |
|
|
filename, |
|
|
pkt_number_init, pkt_number_last, |
|
|
obt_init, obt_last, |
|
|
obt_time_sync, last_time_sync_info, |
|
|
real_time_init, real_time_last, |
|
|
boot_number, |
|
|
timeOffset, |
|
|
bad_pkt, bad_pkt_EventReader, bad_pkt_CalibReader, numPKTSaved, |
|
|
fni,time_is_estimated)==true) |
|
|
{ |
|
|
oss.str()=""; |
|
|
oss<<"Saved information regarding file: "<<filename<<" in table "<<Table_ROOT_Bad; |
|
|
msg = oss.str(); |
|
|
mainLogUtil->logInfo(msg); |
|
|
} |
|
|
else |
|
|
{ |
|
|
oss.str()=""; |
|
|
oss<<"Problem storing information in DB regarding file: "<<filename; |
|
|
msg = oss.str(); |
|
|
mainLogUtil->logError(msg); |
|
|
} |
|
|
|
|
|
if(!single_connection){ |
|
|
CloseDBConnection(); |
|
|
} |
|
|
|
|
|
return; |
|
|
} |
|
|
|
|
|
//saves info in DB in table Table_ROOT_Good |
|
|
if(boot_number==0) |
|
|
boot_number=boot_number_prevvalue; |
|
|
|
|
|
if(saveROOT_DB(Table_ROOT_Good, outDir, // here outDir is good, no expand EMI |
|
|
filename, |
|
|
pkt_number_init, pkt_number_last, |
|
|
obt_init, obt_last, |
|
|
obt_time_sync, last_time_sync_info, |
|
|
real_time_init, real_time_last, |
|
|
boot_number, |
|
|
timeOffset, |
|
|
bad_pkt, bad_pkt_EventReader, bad_pkt_CalibReader, numPKTSaved, |
|
|
fni,time_is_estimated)==true) |
|
|
{ |
|
|
oss<<"Saved information regarding file: "<<filename<<" in table "<<Table_ROOT_Good<< " id= "<<my_id; |
|
|
msg = oss.str(); |
|
|
mainLogUtil->logInfo(msg); |
|
|
|
|
|
if(tryMerge){ |
|
|
merge_ROOTfiles(); |
|
|
} |
|
|
} |
|
|
else |
|
|
{ |
|
|
oss<<"Problem storing information in DB regarding file: "<<filename; |
|
|
msg = oss.str(); |
|
|
mainLogUtil->logError(msg); |
|
|
} |
|
|
|
|
|
if(!single_connection){ |
|
|
CloseDBConnection(); |
|
|
} |
|
688 |
|
|
689 |
}//pRun |
// if(!m_dbinfos.empty()){ |
690 |
|
// while(!m_dbinfos.empty()){ |
691 |
|
// dbinfo *app = m_dbinfos.back(); |
692 |
|
// m_dbinfos.pop_back(); |
693 |
|
Int_t ez=0; |
694 |
|
while ( ez < arsize ){ |
695 |
|
Int_t eid = idtorecover->At(ez); |
696 |
|
if ( eid > -1 ){ |
697 |
|
|
698 |
|
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); |
699 |
|
TSQLResult *result = sqlServer->Query(qu.Data()); |
700 |
|
TSQLRow *row = result->Next(); |
701 |
|
|
702 |
|
TString efolder_name=""; |
703 |
|
TString efile_name=""; |
704 |
|
unsigned long int epkt_number_in=0ULL; |
705 |
|
unsigned long int epkt_number_fin=0ULL; |
706 |
|
unsigned long int eobt_in=0ULL; |
707 |
|
unsigned long int eobt_fin=0ULL; |
708 |
|
unsigned long int emboot_num=0ULL; |
709 |
|
unsigned long int etime_offset=0ULL; |
710 |
|
int ebad_pkt=0; |
711 |
|
int ebad_pkt_read=0; |
712 |
|
int ebad_pkt_CalRead=0; |
713 |
|
int enum_PKT_Saved=0; |
714 |
|
TString enome_input=""; |
715 |
|
bool e_time_is_estimated=false; |
716 |
|
|
717 |
|
if ( row ){ |
718 |
|
efolder_name = (TString)row->GetField(0); |
719 |
|
efile_name = (TString)row->GetField(1); |
720 |
|
epkt_number_in = (unsigned long int)atoll(row->GetField(2)); |
721 |
|
epkt_number_fin = (unsigned long int)atoll(row->GetField(3)); |
722 |
|
eobt_in = (unsigned long int)atoll(row->GetField(4)); |
723 |
|
eobt_fin = (unsigned long int)atoll(row->GetField(5)); |
724 |
|
emboot_num = (unsigned long int)atoll(row->GetField(6)); |
725 |
|
etime_offset = (unsigned long int)atoll(row->GetField(7)); |
726 |
|
ebad_pkt = (int)atoi(row->GetField(8)); |
727 |
|
ebad_pkt_read = (int)atoi(row->GetField(9)); |
728 |
|
ebad_pkt_CalRead = (int)atoi(row->GetField(10)); |
729 |
|
enum_PKT_Saved = (int)atoi(row->GetField(11)); |
730 |
|
enome_input = (TString)row->GetField(12); |
731 |
|
e_time_is_estimated = (bool)atoi(row->GetField(13)); |
732 |
|
}; |
733 |
|
delete result; |
734 |
|
|
735 |
|
setReal_TimeRECOVERY( |
736 |
|
real_time_init, |
737 |
|
real_time_last, |
738 |
|
eobt_in, |
739 |
|
eobt_fin |
740 |
|
); |
741 |
|
// |
742 |
|
|
743 |
|
if (saveROOT_DB( |
744 |
|
Table_ROOT_Good, |
745 |
|
efolder_name.Data(), |
746 |
|
efile_name.Data(), |
747 |
|
epkt_number_in, |
748 |
|
epkt_number_fin, eobt_in, eobt_fin, obt_time_sync, last_time_sync_info, |
749 |
|
real_time_init, real_time_last, emboot_num, etime_offset, ebad_pkt, ebad_pkt_read, ebad_pkt_CalRead, |
750 |
|
enum_PKT_Saved, enome_input.Data(), e_time_is_estimated) == true) { |
751 |
|
oss.str() = ""; |
752 |
|
oss << "\nTAG(tassa): RECOVERED!!!! Saved information regarding file: " << efile_name << " in table " << Table_ROOT_Good << " id= " << my_id; |
753 |
|
msg = oss.str(); |
754 |
|
mainLogUtil->logInfo(msg); |
755 |
|
/*merging we use global variable. we haveto set with current value*/ |
756 |
|
|
757 |
|
strcpy(outDir,efolder_name.Data() ); |
758 |
|
// outDir=efolder_name.Data(); |
759 |
|
strcpy(filename,efile_name.Data() ); |
760 |
|
// filename=efile_name.Data(); |
761 |
|
pkt_number_init=epkt_number_in; |
762 |
|
pkt_number_last=epkt_number_fin; |
763 |
|
obt_init=eobt_in; |
764 |
|
obt_last=eobt_fin; |
765 |
|
boot_number=emboot_num; |
766 |
|
timeOffset=etime_offset; |
767 |
|
bad_pkt=ebad_pkt; |
768 |
|
bad_pkt_EventReader=ebad_pkt_read; |
769 |
|
bad_pkt_CalibReader=ebad_pkt_CalRead; |
770 |
|
numPKTSaved=enum_PKT_Saved; |
771 |
|
strcpy(fni,enome_input.Data() ); |
772 |
|
// fni=enome_input.Data(); |
773 |
|
time_is_estimated=e_time_is_estimated; |
774 |
|
|
775 |
|
if (tryMerge) { |
776 |
|
merge_ROOTfiles(); |
777 |
|
} |
778 |
|
|
779 |
|
TString qu2 = Form("update ROOT_TABLE_BAD set ON_DISK='MVD' where ID_N=%i;",eid); |
780 |
|
sqlServer->Query(qu2.Data()); |
781 |
|
|
782 |
|
|
783 |
|
} |
784 |
|
else { |
785 |
|
oss.str() = ""; |
786 |
|
oss << "Problem storing information in DB regarding file: " << filename; |
787 |
|
msg = oss.str(); |
788 |
|
mainLogUtil->logError(msg); |
789 |
|
} |
790 |
|
|
791 |
|
|
792 |
|
}; |
793 |
|
ez++; |
794 |
|
} |
795 |
|
// |
796 |
|
idtorecover->Reset(); |
797 |
|
delete idtorecover; |
798 |
|
idtorecover = new TArrayI(100); |
799 |
|
arsize = 0; |
800 |
|
// delete app; |
801 |
|
} |
802 |
|
|
803 |
|
CleanDisk(); |
804 |
|
if (!single_connection) { |
805 |
|
CloseDBConnection(); |
806 |
|
} |
807 |
|
|
808 |
|
}//pRun |
809 |
} |
} |
810 |
|
|
811 |
|
|
812 |
|
void PacketUser::CleanDisk(){ |
813 |
|
if ( !candelete ) return; |
814 |
|
// |
815 |
|
// delete small files present in root_table_bad from disk: |
816 |
|
// |
817 |
|
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); |
818 |
|
TSQLResult *result = sqlServer->Query(qu.Data()); |
819 |
|
TSQLRow *row = result->Next(); |
820 |
|
while ( row ){ |
821 |
|
TString tbdel = (TString)gSystem->ExpandPathName(row->GetField(0))+"/"+ (TString)row->GetField(1); |
822 |
|
stringstream err; |
823 |
|
string msg; |
824 |
|
err.str() = ""; |
825 |
|
err << " Deleting file " << tbdel.Data() << " from disk! "; |
826 |
|
msg = err.str(); |
827 |
|
mainLogUtil->logInfo(msg); |
828 |
|
gSystem->Unlink(tbdel.Data()); |
829 |
|
// printf("ciccio %s \n",tbdel.Data()); |
830 |
|
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); |
831 |
|
// printf("pluto %s \n",q2u.Data()); |
832 |
|
sqlServer->Query(q2u.Data()); |
833 |
|
// printf("paperoga \n"); |
834 |
|
row=result->Next(); |
835 |
|
// |
836 |
|
}; |
837 |
|
|
838 |
|
} |
839 |
|
|
840 |
//save in Table_ROOT_Good or in Table_ROOT_Bad |
//save in Table_ROOT_Good or in Table_ROOT_Bad |
841 |
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, |
842 |
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, |
843 |
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, |
844 |
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, |
845 |
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) { |
846 |
unsigned long int mboot_num, |
//TODO: forse far ritornare ID della cosa appena inserita se e' andatato tutto ok invece che true false? |
847 |
unsigned long int time_offset, |
stringstream oss; |
848 |
int bad_pkt, int bad_pkt_read, int bad_pkt_CalRead, int num_PKT_Saved, |
oss.str(""); |
849 |
char* nome_input, bool _time_is_estimated){ |
oss << "INSERT INTO " << table_name |
850 |
//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)" |
851 |
stringstream oss; |
<< " VALUES ('" << 0 << "','" << folder_name << "','" << file_name << "','" << pkt_number_in << "','" |
852 |
oss.str(""); |
<< pkt_number_fin << "','" << obt_in << "','" << obt_fin << "','" << oT_sync << "','" << lT_sync_info << "','" |
853 |
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 << "','" |
854 |
<< " 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," |
855 |
<< oT_sync << "','" << lT_sync_info << "','" |
<< _time_is_estimated << ",'" << tag_value << "'" << ");"; |
856 |
<< mtime_init << "','" << mtime_last << "','" |
string msg = oss.str(); |
857 |
<< 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; |
|
|
} |
|
858 |
|
|
859 |
//the ID of the current ROOT file in table Table_ROOT_Good |
stringstream oss1; |
860 |
my_id = select_maxIDN_DB(table_name); |
oss1.str() = ""; |
861 |
if(!boot_number){ |
string msg1; |
862 |
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; |
|
|
} |
|
863 |
|
|
864 |
|
TSQLResult* res = NULL; |
865 |
|
|
866 |
void PacketUser::recover_boot_number(){ |
query = oss.str(); |
867 |
|
msg1 = "SaveROOT_DB query: "; |
868 |
|
msg1 += query; |
869 |
|
mainLogUtil->logInfo(msg1); |
870 |
|
|
871 |
|
res = sqlServer->Query(query.c_str()); |
872 |
|
if (!res) { |
873 |
|
oss1 << "DBError UNABLE to: " << oss.str().c_str() << endl; |
874 |
|
msg1 = oss1.str(); |
875 |
|
mainLogUtil->logError(msg1); |
876 |
|
return false; |
877 |
|
} |
878 |
|
|
879 |
|
|
880 |
|
if(!strcmp(table_name,Table_ROOT_Good)) { |
881 |
|
//the ID of the current ROOT file in table Table_ROOT_Good |
882 |
|
my_id = select_maxIDN_DB(table_name); |
883 |
|
if (!boot_number) { |
884 |
|
if (id_to_recover_index < 1000) |
885 |
|
id_to_recover[id_to_recover_index++] = my_id; |
886 |
|
} |
887 |
|
else if (boot_number && id_to_recover_index && !is_new_route) { |
888 |
|
recover_boot_number(); |
889 |
|
} |
890 |
|
} |
891 |
|
// cout<<"DBG: my_id = "<<my_id<<endl; |
892 |
|
if (res) { |
893 |
|
delete res; |
894 |
|
res = NULL; |
895 |
|
} |
896 |
|
return true; |
897 |
|
} |
898 |
|
|
899 |
|
void PacketUser::recover_boot_number() { |
900 |
string msg1; |
string msg1; |
901 |
stringstream oss1; |
stringstream oss1; |
902 |
stringstream oss; |
stringstream oss; |
903 |
oss.str(""); |
oss.str(""); |
904 |
string query=""; |
string query = ""; |
905 |
TSQLResult* res=NULL; |
TSQLResult* res = NULL; |
906 |
if(!boot_number || !id_to_recover_index) |
if (!boot_number || !id_to_recover_index) |
907 |
return; |
return; |
908 |
|
|
909 |
for (int i = 0; i<id_to_recover_index;i++){ |
for (int i = 0; i < id_to_recover_index; i++) { |
910 |
oss << "UPDATE "<< Table_ROOT_Good << " SET BOOT_NUMBER=" << boot_number << " WHERE ID_N=" << id_to_recover[i]; |
oss.str(""); |
911 |
query = oss.str(); |
oss << "UPDATE " << Table_ROOT_Good << " SET BOOT_NUMBER=" << boot_number << " WHERE ID_N=" << id_to_recover[i] |
912 |
res= sqlServer->Query(query.c_str()); |
<< ";"; |
913 |
if(!res) |
query = oss.str(); |
914 |
{ |
res = sqlServer->Query(query.c_str()); |
915 |
oss1<<"DBError UNABLE to: "<<query.c_str()<<endl; |
if (!res) { |
916 |
msg1=oss1.str(); |
oss1 << "DBError UNABLE to: " << query.c_str() << endl; |
917 |
mainLogUtil->logError(msg1); |
msg1 = oss1.str(); |
918 |
return ; |
mainLogUtil->logError(msg1); |
919 |
} |
return; |
920 |
|
} |
921 |
} |
} |
922 |
|
|
923 |
for (int i = 0; i<id_to_recover_index;i++){ |
for (int i = 0; i < id_to_recover_index; i++) { |
924 |
oss << "UPDATE " << Table_ROOT_Merging << " SET BOOT_NUMBER=" << boot_number << " WHERE ROOT_ID_N=" << id_to_recover[i]; |
oss.str(""); |
925 |
query=oss.str(); |
oss << "UPDATE " << Table_ROOT_Merging << " SET BOOT_NUMBER=" << boot_number << " WHERE ROOT_ID_N=" |
926 |
res= sqlServer->Query(query.c_str()); |
<< id_to_recover[i] << ";"; |
927 |
if(!res) |
query = oss.str(); |
928 |
{ |
res = sqlServer->Query(query.c_str()); |
929 |
oss1<<"DBError UNABLE to: "<<query.c_str()<<endl; |
if (!res) { |
930 |
msg1=oss1.str(); |
oss1 << "DBError UNABLE to: " << query.c_str() << endl; |
931 |
mainLogUtil->logError(msg1); |
msg1 = oss1.str(); |
932 |
return ; |
mainLogUtil->logError(msg1); |
933 |
} |
return; |
934 |
|
} |
935 |
} |
} |
936 |
|
|
937 |
id_to_recover_index=0; |
id_to_recover_index = 0; |
938 |
} |
} |
939 |
|
|
|
|
|
|
|
|
940 |
/**********************************************************************************************/ |
/**********************************************************************************************/ |
941 |
/*###########################################################################################################*/ |
/*###########################################################################################################*/ |
942 |
/********************************** MERGING *************************************************/ |
/********************************** MERGING *************************************************/ |
945 |
// 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 |
946 |
/**********************************************************************************************/ |
/**********************************************************************************************/ |
947 |
//try to merge current ROOT file with files in DB |
//try to merge current ROOT file with files in DB |
948 |
bool PacketUser::merge_ROOTfiles() |
bool PacketUser::merge_ROOTfiles() { |
949 |
{ |
stringstream log; |
950 |
stringstream log; |
log.str(""); |
951 |
log.str(""); |
string slog; |
|
string slog; |
|
952 |
|
|
953 |
mainLogUtil->logInfo("Trying merging ROOT files"); |
mainLogUtil->logInfo("Trying merging ROOT files"); |
954 |
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; |
|
955 |
|
|
956 |
|
TSQLResult* res = NULL; |
957 |
|
TSQLRow* row = NULL; |
958 |
|
//numero di ROOT files trovati sul DB che hanno relaz di tipo dato |
959 |
|
unsigned int num_rows = 0; |
960 |
|
|
961 |
|
//Record su DB: |
962 |
|
unsigned int idN = 0; |
963 |
|
unsigned int root_id_db = 0; |
964 |
|
unsigned long int pkt_num_in_db = 0; |
965 |
|
unsigned long int pkt_num_fin_db = 0; |
966 |
|
unsigned long int pkt_obt_in_db = 0; |
967 |
|
unsigned long int pkt_obt_fin_db = 0; |
968 |
|
unsigned long int time_in_db = 0; |
969 |
|
unsigned long int time_fin_db = 0; |
970 |
|
unsigned int boot_num_db = 0; |
971 |
|
double perc = 0; |
972 |
|
|
973 |
//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 |
974 |
//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 |
975 |
for(int relaz=AFTER; relaz<=BIGGER; relaz++) |
for (int relaz = AFTER; relaz <= BIGGER; relaz++) { |
976 |
{ |
//marco_new: esci se sono arrivato a zero |
977 |
//marco_new: esci se sono arrivato a zero |
if (real_time_last == real_time_init) { |
978 |
if(real_time_last==real_time_init) |
log.str(""); |
979 |
{ |
log << "Current File Lenght=0; real_time_last=real_time_init= " << real_time_last; |
980 |
log.str(""); |
slog = log.str(); |
981 |
log<<"Current File Lenght=0; real_time_last=real_time_init= "<<real_time_last; |
mainLogUtil->logAll(slog); |
982 |
slog=log.str(); |
mainLogUtil->logInfo("Finish merging ROOT files"); |
983 |
mainLogUtil->logAll(slog); |
if (res) { |
984 |
mainLogUtil->logInfo("Finish merging ROOT files"); |
delete res; |
985 |
if(res){delete res; res = NULL;} |
res = NULL; |
986 |
if(row){delete row; row = NULL;} |
} |
987 |
return true; |
if (row) { |
988 |
} |
delete row; |
989 |
|
row = NULL; |
990 |
num_rows=0; |
} |
991 |
res = Select_merging(Table_ROOT_Merging, real_time_init, real_time_last, (type_Rel_ROOT)relaz); |
return true; |
992 |
|
} |
993 |
if (!res) |
|
994 |
{ |
num_rows = 0; |
995 |
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); |
996 |
return false; |
|
997 |
} |
if (!res) { |
998 |
|
mainLogUtil->logError("DB_ERROR: Unable to find ROOT files to be merged RES=null"); |
999 |
num_rows=res->GetRowCount(); |
return false; |
1000 |
log.str(""); |
} |
1001 |
log<<"Found "<<num_rows<<" ROOT file in DB with relation of kind = "<<relaz; |
|
1002 |
slog=log.str(); |
num_rows = res->GetRowCount(); |
1003 |
mainLogUtil->logAll(slog); |
log.str(""); |
1004 |
|
log << "Found " << num_rows << " ROOT file in DB with relation of kind = " << relaz; |
1005 |
if(num_rows>0) |
slog = log.str(); |
1006 |
{ |
mainLogUtil->logAll(slog); |
1007 |
for(unsigned int i=0; i<num_rows; i++) |
|
1008 |
{ |
if (num_rows > 0) { |
1009 |
row=res->Next(); |
for (unsigned int i = 0; i < num_rows; i++) { |
1010 |
if (!row) |
row = res->Next(); |
1011 |
{ |
if (!row) { |
1012 |
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"); |
1013 |
if(res){delete res; res = NULL;} |
if (res) { |
1014 |
return false; |
delete res; |
1015 |
} |
res = NULL; |
1016 |
|
} |
1017 |
//Leggi Record dal DB: |
return false; |
1018 |
idN=atoll(row->GetField(0)); |
} |
1019 |
root_id_db=atoll(row->GetField(1)); |
|
1020 |
pkt_num_in_db=atoll(row->GetField(2)); |
//Leggi Record dal DB: |
1021 |
pkt_num_fin_db=atoll(row->GetField(3)); |
idN = atoll(row->GetField(0)); |
1022 |
pkt_obt_in_db=atoll(row->GetField(4)); |
root_id_db = atoll(row->GetField(1)); |
1023 |
pkt_obt_fin_db=atoll(row->GetField(5)); |
pkt_num_in_db = atoll(row->GetField(2)); |
1024 |
time_in_db=atoll(row->GetField(6)); |
pkt_num_fin_db = atoll(row->GetField(3)); |
1025 |
time_fin_db=atoll(row->GetField(7)); |
pkt_obt_in_db = atoll(row->GetField(4)); |
1026 |
boot_num_db=atoll(row->GetField(8)); |
pkt_obt_fin_db = atoll(row->GetField(5)); |
1027 |
perc=atof(row->GetField(9)); |
time_in_db = atoll(row->GetField(6)); |
1028 |
|
time_fin_db = atoll(row->GetField(7)); |
1029 |
log.str(""); |
boot_num_db = atoll(row->GetField(8)); |
1030 |
log<<"*** ROOT file found in DB has idN= "<<idN<<" root_id_db= "<<root_id_db; |
perc = atof(row->GetField(9)); |
1031 |
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; |
|
1032 |
log<<" time_in_db= "<<time_in_db<<" time_fin_db= "<<time_fin_db<<" boot_num_db= "<<boot_num_db<<" perc= "<<perc<<" ***"; |
log.str(""); |
1033 |
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; |
1034 |
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= " |
1035 |
slog=log.str(); |
<< pkt_obt_in_db << " pkt_obt_fin_db= " << pkt_obt_fin_db; |
1036 |
mainLogUtil->logAll(slog); |
log << " time_in_db= " << time_in_db << " time_fin_db= " << time_fin_db << " boot_num_db= " << boot_num_db |
1037 |
if(perc>percentage) |
<< " perc= " << perc << " ***"; |
1038 |
{ |
log << "\n*** Current ROOT file has pkt_number_init= " << pkt_number_init << " obt_init= " << obt_init |
1039 |
mainLogUtil->logInfo("Current ROOT file is better than the one in DB"); |
<< " real_time_init= " << real_time_init; |
1040 |
//modifica DB |
log << " pkt_number_last= " << pkt_number_last << " obt_last= " << obt_last << " real_time_last= " |
1041 |
updateMergeROOT_DB(Table_ROOT_Merging, |
<< real_time_last << " ***"; |
1042 |
root_id_db, |
slog = log.str(); |
1043 |
pkt_num_in_db, pkt_num_fin_db, |
mainLogUtil->logAll(slog); |
1044 |
pkt_obt_in_db, pkt_obt_fin_db, |
if (perc > percentage) { |
1045 |
time_in_db, time_fin_db, |
mainLogUtil->logInfo("Current ROOT file is better than the one in DB"); |
1046 |
boot_num_db, |
//modifica DB |
1047 |
perc, |
updateMergeROOT_DB(Table_ROOT_Merging, root_id_db, pkt_num_in_db, pkt_num_fin_db, pkt_obt_in_db, |
1048 |
idN,(type_Rel_ROOT)relaz); |
pkt_obt_fin_db, time_in_db, time_fin_db, boot_num_db, perc, idN, (type_Rel_ROOT) relaz); |
1049 |
} |
} |
1050 |
else |
else { |
1051 |
{ |
mainLogUtil->logInfo("Found ROOT file in DB is better than current ROOT file"); |
1052 |
mainLogUtil->logInfo("Found ROOT file in DB is better than current ROOT file"); |
if (relaz == AFTER) { |
1053 |
if(relaz == AFTER) |
mainLogUtil->logInfo("Relaz:AFTER = Changing Init values of the Current ROOT file"); |
1054 |
{ |
pkt_number_init = (pkt_num_fin_db + 1); |
1055 |
mainLogUtil->logInfo("Relaz:AFTER = Changing Init values of the Current ROOT file"); |
obt_init = pkt_obt_fin_db; |
1056 |
pkt_number_init = (pkt_num_fin_db+1); |
real_time_init = time_fin_db; |
1057 |
obt_init = pkt_obt_fin_db; |
log.str(""); |
1058 |
real_time_init = time_fin_db; |
log << "\n*** Current ROOT file becomes: pkt_number_init= " << pkt_number_init << " obt_init= " |
1059 |
log.str(""); |
<< obt_init << " real_time_init= " << real_time_init; |
1060 |
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= " |
1061 |
log<<" pkt_number_last= "<<pkt_number_last<<" obt_last= "<<obt_last<<" real_time_last= "<<real_time_last<<" ***"; |
<< real_time_last << " ***"; |
1062 |
slog=log.str(); |
slog = log.str(); |
1063 |
mainLogUtil->logAll(slog); |
mainLogUtil->logAll(slog); |
1064 |
} |
} |
1065 |
else if(relaz == BEFORE) |
else if (relaz == BEFORE) { |
1066 |
{ |
mainLogUtil->logInfo("Relaz:BEFORE = Changing Last values of the Current ROOT file"); |
1067 |
mainLogUtil->logInfo("Relaz:BEFORE = Changing Last values of the Current ROOT file"); |
pkt_number_last = (pkt_num_in_db - 1); |
1068 |
pkt_number_last = (pkt_num_in_db-1); |
obt_last = pkt_obt_in_db; |
1069 |
obt_last = pkt_obt_in_db; |
real_time_last = time_in_db; |
1070 |
real_time_last = time_in_db; |
|
1071 |
|
log.str(""); |
1072 |
log.str(""); |
log << "\n*** Current ROOT file becomes: pkt_number_init= " << pkt_number_init << " obt_init= " |
1073 |
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; |
1074 |
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= " |
1075 |
slog=log.str(); |
<< real_time_last << " ***"; |
1076 |
mainLogUtil->logAll(slog); |
slog = log.str(); |
1077 |
} |
mainLogUtil->logAll(slog); |
1078 |
else if(relaz == SMALLER) |
} |
1079 |
{ |
else if (relaz == SMALLER) { |
1080 |
//non devo proprio salvarlo ed esco ... |
//non devo proprio salvarlo ed esco ... |
1081 |
mainLogUtil->logInfo("Relaz:SMALLER = Nothing to save"); |
mainLogUtil->logInfo("Relaz:SMALLER = Nothing to save"); |
1082 |
mainLogUtil->logInfo("\nFinish merging ROOT files"); |
mainLogUtil->logInfo("\nFinish merging ROOT files"); |
1083 |
if(res){delete res; res = NULL;} |
if (res) { |
1084 |
if(row){delete row; row = NULL;} |
delete res; |
1085 |
return true; |
res = NULL; |
1086 |
} |
} |
1087 |
else if(relaz == BIGGER)//spezzettamento |
if (row) { |
1088 |
{ |
delete row; |
1089 |
mainLogUtil->logInfo("Relaz:BIGGER = (1st part) Saving the first part of the Current ROOT file"); |
row = NULL; |
1090 |
saveMergeROOT_DB(Table_ROOT_Merging, my_id, |
} |
1091 |
pkt_number_init, (pkt_num_in_db-1), |
return true; |
1092 |
obt_init, pkt_obt_in_db, |
} |
1093 |
real_time_init, time_in_db, |
else if (relaz == BIGGER)//spezzettamento |
1094 |
boot_number, |
{ |
1095 |
percentage); |
mainLogUtil->logInfo("Relaz:BIGGER = (1st part) Saving the first part of the Current ROOT file"); |
1096 |
|
saveMergeROOT_DB(Table_ROOT_Merging, my_id, pkt_number_init, (pkt_num_in_db - 1), obt_init, pkt_obt_in_db, |
1097 |
mainLogUtil->logInfo("Relaz:BIGGER = (2nd part)Changing Init values of the Current ROOT file"); |
real_time_init, time_in_db, boot_number, percentage); |
1098 |
pkt_number_init = (pkt_num_fin_db+1); |
|
1099 |
obt_init= pkt_obt_fin_db; |
mainLogUtil->logInfo("Relaz:BIGGER = (2nd part)Changing Init values of the Current ROOT file"); |
1100 |
real_time_init= time_fin_db; |
pkt_number_init = (pkt_num_fin_db + 1); |
1101 |
|
obt_init = pkt_obt_fin_db; |
1102 |
log.str(""); |
real_time_init = time_fin_db; |
1103 |
log<<"\n*** Current ROOT file becomes: pkt_number_init= "<<pkt_number_init<<" obt_init= "<<obt_init<<" real_time_init= "<<real_time_init; |
|
1104 |
log<<" pkt_number_last= "<<pkt_number_last<<" obt_last= "<<obt_last<<" real_time_last= "<<real_time_last<<" ***"; |
log.str(""); |
1105 |
slog=log.str(); |
log << "\n*** Current ROOT file becomes: pkt_number_init= " << pkt_number_init << " obt_init= " |
1106 |
mainLogUtil->logAll(slog); |
<< obt_init << " real_time_init= " << real_time_init; |
1107 |
}//if relaz |
log << " pkt_number_last= " << pkt_number_last << " obt_last= " << obt_last << " real_time_last= " |
1108 |
}//if perc |
<< real_time_last << " ***"; |
1109 |
}//for num_rows |
slog = log.str(); |
1110 |
}//if num_rows |
mainLogUtil->logAll(slog); |
1111 |
|
}//if relaz |
1112 |
|
}//if perc |
1113 |
|
}//for num_rows |
1114 |
|
}//if num_rows |
1115 |
|
|
1116 |
|
if (res) { |
1117 |
|
delete res; |
1118 |
|
res = NULL; |
1119 |
|
} |
1120 |
|
if (row) { |
1121 |
|
delete row; |
1122 |
|
row = NULL; |
1123 |
|
} |
1124 |
|
|
1125 |
|
}//for relaz |
1126 |
|
|
1127 |
|
mainLogUtil->logInfo("Saving Current ROOT file"); |
1128 |
|
saveMergeROOT_DB(Table_ROOT_Merging, my_id, pkt_number_init, pkt_number_last, obt_init, obt_last, real_time_init, |
1129 |
|
real_time_last, boot_number, percentage); |
1130 |
|
|
1131 |
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"); |
|
1132 |
return true; |
return true; |
1133 |
|
|
1134 |
} |
} |
1135 |
|
|
1136 |
//unsigned int root_id, percentage non le devo modificare |
//unsigned int root_id, percentage non le devo modificare |
1137 |
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, |
1138 |
unsigned int root_id, |
unsigned long int pkt_number_fin, unsigned long int obt_in, unsigned long int obt_fin, |
1139 |
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, |
1140 |
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(""); |
|
1141 |
|
|
1142 |
if(type_rel == AFTER){ |
stringstream oss; |
1143 |
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; |
|
1144 |
|
|
1145 |
string msg = oss.str(); |
if (type_rel == AFTER) { |
1146 |
mainLogUtil->logInfo(msg); |
mainLogUtil->logInfo("Relaz:AFTER = Updating Last values of the DB ROOT file"); |
1147 |
|
//marco_new:tolti tutti gli apici che qui non devono essere |
1148 |
stringstream oss1; |
|
1149 |
oss1.str()=""; |
int good = 1; |
1150 |
string msg1; |
if ( pkt_number_in >= (pkt_number_init - 1) && abs((int)(pkt_number_in-(pkt_number_init-1)))<10 ) good = 0; |
1151 |
|
|
1152 |
TSQLResult* res=NULL; |
oss << "UPDATE " << table_name << " SET PKT_NUMBER_FINAL =" << (pkt_number_init - 1) << ", PKT_OBT_FINAL =" |
1153 |
res= sqlServer->Query(oss.str().c_str()); |
<< obt_init << ", REAL_TIME_LAST =" << real_time_init << ", GOOD="<< good << " WHERE ID_N =" << ID_record << ";"; |
1154 |
if(!res) |
|
1155 |
{ |
} |
1156 |
oss1<<"DBError UNABLE to: "<<oss.str().c_str()<<endl; |
else if (type_rel == BEFORE) { |
1157 |
msg1=oss1.str(); |
mainLogUtil->logInfo("Relaz:BEFORE = Updating Init values of the DB ROOT file"); |
1158 |
mainLogUtil->logError(msg1); |
|
1159 |
return false; |
int good = 1; |
1160 |
} |
if ( (pkt_number_last+1) >= pkt_number_fin && abs((int)((pkt_number_last+1)-pkt_number_fin))<10 ) good = 0; |
1161 |
if(res){delete res; res = NULL;} |
|
1162 |
return true; |
oss << "UPDATE " << table_name << " SET PKT_NUMBER_INIT =" << (pkt_number_last + 1) << ", PKT_OBT_INIT =" |
1163 |
|
<< obt_last << ", REAL_TIME_INIT =" << real_time_last << ", GOOD="<< good << " WHERE ID_N =" << ID_record << ";"; |
1164 |
|
} |
1165 |
|
else if (type_rel == SMALLER) { |
1166 |
|
//spezzettamentento |
1167 |
|
mainLogUtil->logInfo("Relaz:SMALLER = (1st part) Updating Last values of the DB ROOT file"); |
1168 |
|
|
1169 |
|
int good = 1; |
1170 |
|
if ( pkt_number_in >= (pkt_number_init - 1) && abs((int)(pkt_number_in-(pkt_number_init-1)))<10 ) good = 0; |
1171 |
|
|
1172 |
|
oss << "UPDATE " << table_name << " SET PKT_NUMBER_FINAL=" << (pkt_number_init - 1) << ", PKT_OBT_FINAL =" |
1173 |
|
<< obt_init << ", REAL_TIME_LAST =" << real_time_init << ", GOOD="<< good << " WHERE ID_N =" << ID_record << ";"; |
1174 |
|
|
1175 |
|
mainLogUtil->logInfo("Relaz:SMALLER = (2nd part) Saving the second part of the DB ROOT file"); |
1176 |
|
|
1177 |
|
saveMergeROOT_DB(table_name, root_id, (pkt_number_last + 1), pkt_number_fin, obt_last, obt_fin, real_time_last, |
1178 |
|
mtime_last, mboot_num, bad_perc); |
1179 |
|
} |
1180 |
|
else if (type_rel == BIGGER) { |
1181 |
|
//marco_new: ok anche se coincidenti etc |
1182 |
|
// oss << "DELETE FROM "<< table_name <<" WHERE ID_N ="<< ID_record<<";"; // EMILIANO |
1183 |
|
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 |
1184 |
|
mainLogUtil->logInfo("Record deleted from merging table"); |
1185 |
|
} |
1186 |
|
else |
1187 |
|
return false; |
1188 |
|
|
1189 |
|
string msg = oss.str(); |
1190 |
|
mainLogUtil->logInfo(msg); |
1191 |
|
|
1192 |
|
stringstream oss1; |
1193 |
|
oss1.str() = ""; |
1194 |
|
string msg1; |
1195 |
|
|
1196 |
|
TSQLResult* res = NULL; |
1197 |
|
res = sqlServer->Query(oss.str().c_str()); |
1198 |
|
if (!res) { |
1199 |
|
oss1 << "DBError UNABLE to: " << oss.str().c_str() << endl; |
1200 |
|
msg1 = oss1.str(); |
1201 |
|
mainLogUtil->logError(msg1); |
1202 |
|
return false; |
1203 |
|
} |
1204 |
|
if (res) { |
1205 |
|
delete res; |
1206 |
|
res = NULL; |
1207 |
|
} |
1208 |
|
return true; |
1209 |
} |
} |
1210 |
|
|
1211 |
//cerca eventuali ROOT files in DB che possono venire mergiati |
//cerca eventuali ROOT files in DB che possono venire mergiati |
1212 |
//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 |
1213 |
//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 |
1214 |
//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 |
1215 |
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, |
1216 |
{ |
type_Rel_ROOT type_rel) { |
1217 |
TSQLResult* res=NULL; |
TSQLResult* res = NULL; |
1218 |
stringstream query; |
stringstream query; |
1219 |
query.str(""); |
query.str(""); |
1220 |
|
|
1221 |
if(type_rel == AFTER) |
if (type_rel == AFTER) |
1222 |
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 |
1223 |
else if(type_rel == BEFORE) |
<< " and REAL_TIME_LAST <= " << mtime_last << " and REAL_TIME_INIT < " << mtime_init; // EMI |
1224 |
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) |
1225 |
else if(type_rel == SMALLER) |
query << "select * from " << table_name << " where GOOD=1 and REAL_TIME_INIT >= " << mtime_init |
1226 |
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 |
1227 |
else if(type_rel == BIGGER) |
else if (type_rel == SMALLER) |
1228 |
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 |
1229 |
else |
<< " and REAL_TIME_LAST > " << mtime_last; // EMI |
1230 |
return 0; |
else if (type_rel == BIGGER) |
1231 |
|
query << "select * from " << table_name << " where GOOD=1 and REAL_TIME_INIT >= " << mtime_init |
1232 |
query<< " order by REAL_TIME_INIT ASC";//marco_new: inutile |
<< " and REAL_TIME_LAST <= " << mtime_last; // EMI |
1233 |
//se volessi mettere un filtro sulla qualita' |
else |
1234 |
// query<<" and NUM_PKT_SAVED - BAD_PKT_CALREAD - BAD_PKT_READ - BAD_PKT >= 2" ; |
return 0; |
1235 |
string msg = query.str(); |
|
1236 |
mainLogUtil->logAll(msg); |
query << " order by REAL_TIME_INIT ASC;";//marco_new: inutile |
1237 |
res= sqlServer->Query(query.str().c_str()); |
//se volessi mettere un filtro sulla qualita' |
1238 |
stringstream oss1; |
// query<<" and NUM_PKT_SAVED - BAD_PKT_CALREAD - BAD_PKT_READ - BAD_PKT >= 2" ; |
1239 |
oss1.str()=""; |
string msg = query.str(); |
1240 |
string msg1; |
mainLogUtil->logAll(msg); |
1241 |
|
res = sqlServer->Query(query.str().c_str()); |
1242 |
if (!res) |
stringstream oss1; |
1243 |
{ |
oss1.str() = ""; |
1244 |
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<<"'" |
|
|
<< ")"; |
|
1245 |
|
|
1246 |
string msg = oss.str(); |
if (!res) { |
1247 |
mainLogUtil->logAll(msg); |
oss1 << "DBError UNABLE to: " << query.str().c_str() << endl; |
1248 |
|
msg1 = oss1.str(); |
1249 |
//marco_new: controlla |
mainLogUtil->logError(msg1); |
1250 |
//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; |
|
|
} |
|
1251 |
|
|
1252 |
stringstream oss1; |
return res; |
1253 |
oss1.str()=""; |
} |
1254 |
string msg1; |
|
1255 |
|
bool PacketUser::saveMergeROOT_DB(const char* table_name, unsigned int root_id, unsigned long int pkt_number_in, |
1256 |
TSQLResult* res=NULL; |
unsigned long int pkt_number_fin, unsigned long int obt_in, unsigned long int obt_fin, |
1257 |
res= sqlServer->Query(oss.str().c_str()); |
unsigned long int mtime_init, unsigned long int mtime_last, unsigned long int mboot_num, double percentage) { |
1258 |
if(!res) |
|
1259 |
{ |
int good = 1; |
1260 |
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; |
1261 |
msg1=oss1.str(); |
|
1262 |
mainLogUtil->logError(msg1); |
stringstream oss; |
1263 |
return false; |
oss.str(""); |
1264 |
} |
oss << "INSERT INTO " << table_name |
1265 |
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)" |
1266 |
return true; |
<< " VALUES ('" << 0 << "','" << root_id << "','" << pkt_number_in << "','" << pkt_number_fin << "','" << obt_in |
1267 |
|
<< "','" << obt_fin << "','" << mtime_init << "','" << mtime_last << "','" << mboot_num << "','" << percentage |
1268 |
|
<< "'," << "NULL" << ",'" << tag_value << "','" << good <<"');"; |
1269 |
|
|
1270 |
|
string msg = oss.str(); |
1271 |
|
mainLogUtil->logAll(msg); |
1272 |
|
|
1273 |
|
//marco_new: controlla |
1274 |
|
//marco_new: esci se sono arrivato a zero |
1275 |
|
// if(real_time_last==real_time_init){ |
1276 |
|
if (mtime_init == mtime_last) { |
1277 |
|
mainLogUtil->logAll("Nothing to be saved"); |
1278 |
|
|
1279 |
|
// if(res){delete res; res = NULL;} |
1280 |
|
// if(row){delete row; row = NULL;} |
1281 |
|
return true; |
1282 |
|
} |
1283 |
|
|
1284 |
|
stringstream oss1; |
1285 |
|
oss1.str() = ""; |
1286 |
|
string msg1; |
1287 |
|
|
1288 |
|
TSQLResult* res = NULL; |
1289 |
|
res = sqlServer->Query(oss.str().c_str()); |
1290 |
|
if (!res) { |
1291 |
|
oss1 << "DBError UNABLE to: " << oss.str().c_str() << endl; |
1292 |
|
msg1 = oss1.str(); |
1293 |
|
mainLogUtil->logError(msg1); |
1294 |
|
return false; |
1295 |
|
} |
1296 |
|
if (res) { |
1297 |
|
delete res; |
1298 |
|
res = NULL; |
1299 |
|
} |
1300 |
|
return true; |
1301 |
} |
} |
1302 |
|
|
1303 |
//Utility: return max(IDN) |
//Utility: return max(IDN) |
1304 |
unsigned int PacketUser::select_maxIDN_DB(char* table_name) |
unsigned int PacketUser::select_maxIDN_DB(const char* table_name) { |
|
{ |
|
1305 |
|
|
1306 |
if (!strcmp(table_name,Table_ROOT_Bad)) |
if (!strcmp(table_name, Table_ROOT_Bad)) { |
1307 |
{ |
return 0; |
1308 |
return 0; |
} |
1309 |
} |
unsigned int idN = 0; |
1310 |
unsigned int idN=0; |
TSQLResult* res = NULL; |
1311 |
TSQLResult* res=NULL; |
stringstream oss; |
1312 |
stringstream oss; |
oss.str(""); |
1313 |
oss.str(""); |
oss << "select max(ID_N) from " << table_name; |
1314 |
oss<<"select max(ID_N) from "<<table_name; |
// string msg = oss.str(); |
1315 |
// string msg = oss.str(); |
// mainLogUtil->logAll(msg); |
1316 |
// mainLogUtil->logAll(msg); |
res = sqlServer->Query(oss.str().c_str()); |
1317 |
res= sqlServer->Query(oss.str().c_str()); |
|
1318 |
|
stringstream oss1; |
1319 |
stringstream oss1; |
oss1.str() = ""; |
1320 |
oss1.str()=""; |
string msg1; |
1321 |
string msg1; |
|
1322 |
|
if (!res) { |
1323 |
if(!res) |
oss1 << "DBError UNABLE to: " << oss.str().c_str() << endl; |
1324 |
{ |
msg1 = oss1.str(); |
1325 |
oss1<<"DBError UNABLE to: "<<oss.str().c_str()<<endl; |
mainLogUtil->logError(msg1); |
1326 |
msg1=oss1.str(); |
return 0; |
1327 |
mainLogUtil->logError(msg1); |
} |
1328 |
return 0; |
|
1329 |
} |
TSQLRow* row = NULL; |
1330 |
|
row = res->Next(); |
1331 |
TSQLRow* row=NULL; |
if (!row) { |
1332 |
row=res->Next(); |
oss1 << "DBError UNABLE to: " << oss.str().c_str() << endl; |
1333 |
if (!row ) |
msg1 = oss1.str(); |
1334 |
{ |
mainLogUtil->logError(msg1); |
1335 |
oss1<<"DBError UNABLE to: "<<oss.str().c_str()<<endl; |
return 0; |
1336 |
msg1=oss1.str(); |
} |
1337 |
mainLogUtil->logError(msg1); |
|
1338 |
return 0; |
idN = atoi(row->GetField(0)); |
1339 |
} |
if (row) { |
1340 |
|
delete row; |
1341 |
idN=atoi(row->GetField(0)); |
row = NULL; |
1342 |
if(row){delete row; row = NULL;} |
} |
1343 |
if(res){delete res; res = NULL;} |
if (res) { |
1344 |
|
delete res; |
1345 |
oss<<". idN = "<<idN; |
res = NULL; |
1346 |
string msg = oss.str(); |
} |
1347 |
mainLogUtil->logAll(msg); |
|
1348 |
|
oss << ". idN = " << idN; |
1349 |
|
string msg = oss.str(); |
1350 |
|
mainLogUtil->logAll(msg); |
1351 |
|
|
1352 |
return idN; |
return idN; |
1353 |
} |
} |
1354 |
|
|
1355 |
/** |
/** |
1356 |
* Lock par=table, if par=null lock all tables |
* Lock par=table, if par=null lock all tables |
1357 |
*/ |
*/ |
1358 |
int PacketUser::LockTables(char* tableTobeLocked) |
int PacketUser::LockTables(const char* tableTobeLocked) { |
1359 |
{ |
//se non ho il DB :) |
1360 |
//se non ho il DB :) |
if (!do_cont_check) |
1361 |
if(!do_cont_check) return 999; |
return 999; |
1362 |
|
|
1363 |
TSQLResult* res=NULL; |
TSQLResult* res = NULL; |
1364 |
stringstream oss; |
stringstream oss; |
1365 |
oss.str(""); |
oss.str(""); |
1366 |
if(!tableTobeLocked) |
if (!tableTobeLocked) |
1367 |
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 |
1368 |
else |
<< " write, " << Table_ROOT_Merging << " write;"; |
1369 |
oss << "lock table "<<tableTobeLocked<<" write; "; |
else |
1370 |
|
oss << "lock table " << tableTobeLocked << " write; "; |
1371 |
string msg = oss.str(); |
|
1372 |
mainLogUtil->logAll(msg); |
string msg = oss.str(); |
1373 |
|
mainLogUtil->logAll(msg); |
1374 |
res= sqlServer->Query(oss.str().c_str()); |
|
1375 |
|
res = sqlServer->Query(oss.str().c_str()); |
1376 |
stringstream oss1; |
|
1377 |
oss1.str()=""; |
stringstream oss1; |
1378 |
string msg1; |
oss1.str() = ""; |
1379 |
|
string msg1; |
1380 |
if(!res) |
|
1381 |
{ |
if (!res) { |
1382 |
oss1<<"DBError UNABLE to: "<<oss.str().c_str()<<endl; |
oss1 << "DBError UNABLE to: " << oss.str().c_str() << endl; |
1383 |
msg1=oss1.str(); |
msg1 = oss1.str(); |
1384 |
mainLogUtil->logError(msg1); |
mainLogUtil->logError(msg1); |
1385 |
return 1; |
return 1; |
1386 |
} |
} |
1387 |
|
|
1388 |
if(res){delete res; res = NULL;} |
if (res) { |
1389 |
mainLogUtil->logAll("TABLES LOCKED"); |
delete res; |
1390 |
return 0; |
res = NULL; |
1391 |
|
} |
1392 |
|
mainLogUtil->logAll("TABLES LOCKED"); |
1393 |
|
return 0; |
1394 |
} |
} |
1395 |
|
|
1396 |
/** |
/** |
1397 |
* UNLock tables |
* UNLock tables |
1398 |
*/ |
*/ |
1399 |
int PacketUser::UnLockTables(){ |
int PacketUser::UnLockTables() { |
1400 |
//se non ho il DB :) |
//se non ho il DB :) |
1401 |
if(!do_cont_check) return 999; |
if (!do_cont_check) |
1402 |
|
return 999; |
1403 |
|
|
1404 |
TSQLResult* res=NULL; |
TSQLResult* res = NULL; |
1405 |
stringstream oss; |
stringstream oss; |
1406 |
oss.str(""); |
oss.str(""); |
1407 |
oss << "unlock tables;"; |
oss << "unlock tables;"; |
1408 |
|
|
1409 |
string msg = oss.str(); |
string msg = oss.str(); |
1410 |
mainLogUtil->logAll(msg); |
mainLogUtil->logAll(msg); |
1411 |
|
|
1412 |
res= sqlServer->Query(oss.str().c_str()); |
res = sqlServer->Query(oss.str().c_str()); |
1413 |
|
|
1414 |
stringstream oss1; |
stringstream oss1; |
1415 |
oss1.str()=""; |
oss1.str() = ""; |
1416 |
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"); |
|
1417 |
|
|
1418 |
return 0; |
if (!res) { |
1419 |
|
oss1 << "DBError UNABLE to: " << oss.str().c_str() << endl; |
1420 |
|
msg1 = oss1.str(); |
1421 |
|
mainLogUtil->logError(msg1); |
1422 |
|
return 1; |
1423 |
|
} |
1424 |
|
|
1425 |
|
if (res) { |
1426 |
|
delete res; |
1427 |
|
res = NULL; |
1428 |
|
} |
1429 |
|
mainLogUtil->logAll("TABLES UNLOCKED"); |
1430 |
|
|
1431 |
|
return 0; |
1432 |
} |
} |
1433 |
|
|
1434 |
/*********************************************************/ |
/*********************************************************/ |
1435 |
//marco_new_31 |
//marco_new_31 |
1436 |
void PacketUser::OpenDBConnection(char* tableTobeLocked){ |
void PacketUser::OpenDBConnection(const char* tableTobeLocked) { |
1437 |
if(do_cont_check){ |
if (do_cont_check) { |
1438 |
//controllo che non sia gia' aperta |
//controllo che non sia gia' aperta |
1439 |
if(!sqlServer){ |
if (!sqlServer) { |
1440 |
sqlServer = TSQLServer::Connect(connection,db_user,db_pwd); |
sqlServer = TSQLServer::Connect(connection, db_user, db_pwd); |
1441 |
if ((!sqlServer)||(!(sqlServer->IsConnected()))){cout<<"Can not connect with MYSQL sever"<<endl;} |
if ((!sqlServer) || (!(sqlServer->IsConnected()))) { |
1442 |
mainLogUtil->logAll("Connected to DB"); |
cout << "Can not connect with MYSQL sever" << endl; |
1443 |
//blocca le tabelle |
} |
1444 |
LockTables(tableTobeLocked); |
mainLogUtil->logAll("Connected to DB"); |
1445 |
} |
stringstream myquery; |
1446 |
} |
myquery.str(""); |
1447 |
|
myquery << "SET time_zone='+0:00'"; |
1448 |
|
sqlServer->Query(myquery.str().c_str()); |
1449 |
|
//blocca le tabelle |
1450 |
|
LockTables(tableTobeLocked); |
1451 |
|
} |
1452 |
|
} |
1453 |
|
|
1454 |
} |
} |
1455 |
|
|
1456 |
//marco_new_31 |
//marco_new_31 |
1457 |
void PacketUser::CloseDBConnection(){ |
void PacketUser::CloseDBConnection() { |
1458 |
if(do_cont_check){ |
if (do_cont_check) { |
1459 |
//controllo che ce ne sia una aperta |
//controllo che ce ne sia una aperta |
1460 |
if(sqlServer && sqlServer->IsConnected()){ |
if (sqlServer && sqlServer->IsConnected()) { |
1461 |
//marco_new: sblocca tutte le tabelle |
//marco_new: sblocca tutte le tabelle |
1462 |
UnLockTables(); |
UnLockTables(); |
1463 |
sqlServer->Close(); |
sqlServer->Close(); |
1464 |
delete sqlServer; |
delete sqlServer; |
1465 |
sqlServer=NULL; |
sqlServer = NULL; |
1466 |
mainLogUtil->logAll("Closed Connection to DB"); |
mainLogUtil->logAll("Closed Connection to DB"); |
1467 |
} |
} |
1468 |
} |
} |
1469 |
} |
} |
1470 |
|
|
|
|
|
|
|
|
1471 |
/***********************************************************************************************************************/ |
/***********************************************************************************************************************/ |
1472 |
/*#################################################### HIC SUNT LEONES ################################################*/ |
/*#################################################### HIC SUNT LEONES ################################################*/ |
1473 |
/***********************************************************************************************************************/ |
/***********************************************************************************************************************/ |
1474 |
//UNUSED: dbg functions... |
//UNUSED: dbg functions... |
1475 |
|
|
1476 |
//Return the system time in ms |
//Return the system time in ms |
1477 |
unsigned long long PacketUser::Record_Time(){ |
unsigned long long PacketUser::Record_Time() { |
1478 |
timeval tv; |
timeval tv; |
1479 |
gettimeofday(&tv,NULL); |
gettimeofday(&tv, NULL); |
1480 |
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; |
1481 |
return timems; |
return timems; |
1482 |
} |
} |
1483 |
|
|
1484 |
//dbg_functions: |
//dbg_functions: |
1485 |
|
|
1486 |
//UNUSED. save a packet in a file |
//UNUSED. save a packet in a file |
1487 |
void PacketUser::savePKT_file(char* headerPkt, |
void PacketUser::savePKT_file(char* headerPkt, char* pamPkt, long int length, bool append, char* nomefile) { |
1488 |
char* pamPkt, |
char fno[80] = ""; |
1489 |
long int length, |
ofstream fout; |
1490 |
bool append, |
sprintf(fno, "%s/pkt%d_of_%s.pkt", gSystem->ExpandPathName(outDir), numPKTSaved, nomefile); // EMI |
1491 |
char* nomefile) |
|
1492 |
{ |
if (append == true) |
1493 |
char fno[80]=""; |
fout.open(fno, ios::binary | ios::app); |
1494 |
ofstream fout; |
else |
1495 |
sprintf(fno,"%s/pkt%d_of_%s.pkt", gSystem->ExpandPathName(outDir), numPKTSaved, nomefile); // EMI |
fout.open(fno, ios::binary); |
1496 |
|
|
1497 |
if(append==true) |
if (!fout) { |
1498 |
fout.open(fno, ios::binary | ios::app); |
cout << "can not open output file " << fno << endl; |
1499 |
else |
return; |
1500 |
fout.open(fno, ios::binary); |
} |
1501 |
|
fout.write(headerPkt, LENGTH_HEADER_PKT); |
1502 |
if (!fout) {cout<<"can not open output file "<<fno<<endl; return;} |
fout.write(pamPkt, length); |
1503 |
fout.write(headerPkt,LENGTH_HEADER_PKT); |
fout.close(); |
|
fout.write(pamPkt,length); |
|
|
fout.close(); |
|
1504 |
} |
} |
1505 |
|
|
1506 |
//UNUSED |
//UNUSED |
1507 |
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) { |
1508 |
{ |
char fno[80] = ""; |
1509 |
char fno[80]=""; |
ofstream fout; |
1510 |
ofstream fout; |
if (append == true) { |
1511 |
if(append==true) |
sprintf(fno, "%s/packets.pkt", gSystem->ExpandPathName(outDir)); // EMI |
1512 |
{ |
fout.open(fno, ios::binary | ios::app); |
1513 |
sprintf(fno,"%s/packets.pkt", gSystem->ExpandPathName(outDir)); // EMI |
} |
1514 |
fout.open(fno, ios::binary | ios::app); |
else { |
1515 |
} |
sprintf(fno, "%s/packet%d.pkt", gSystem->ExpandPathName(outDir), numPKT); // EMI |
1516 |
else{ |
fout.open(fno, ios::binary); |
1517 |
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(); |
|
|
} |
|
1518 |
|
|
1519 |
|
if (!fout) { |
1520 |
|
cout << "can not open output file " << fno << endl; |
1521 |
|
return; |
1522 |
|
} |
1523 |
|
fout.write(headerPkt, LENGTH_HEADER_PKT); |
1524 |
|
fout.write(pamPkt, length); |
1525 |
|
fout.close(); |
1526 |
|
} |
1527 |
|
|
1528 |
} |
} |