1 |
//============================================================================ |
//============================================================================ |
2 |
// $Id: PacketUser.cpp,v 1.69 2008-10-27 10:41:27 messineo Exp $ |
// $Id: PacketUser.cpp,v 1.17 2010/02/03 14:11:38 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* pelosconnection; |
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 |
{ |
} |
|
good_pkt_Calib++;//maybe I will remove this in future |
|
|
} |
|
|
*/ |
|
|
|
|
|
if(ret>=0)// only the packet not discarded of course |
|
|
setLast(counter,obt); |
|
|
|
|
|
//TODO: decide what kind of packet I can use here |
|
|
// if((ret==0)||(ret==10))//I want to use only good packet |
|
|
if(ret>=0)//I want to use only accepted packet |
|
|
{ |
|
|
setTimeSync(pamPkt, length, type);//here I retrieve also the boot_number if packet type is vardump |
|
|
} |
|
143 |
|
|
144 |
//just to be sure ... |
//here we know if the incoming packet can be considered consecutive to the previuos one |
145 |
if(pamPkt){delete[] pamPkt; pamPkt = NULL;} |
if ((!isCons) && (numPKT != 0)) { |
146 |
if(headerPkt){delete[] headerPkt; headerPkt = NULL;} |
setReal_Time(); |
147 |
|
//closing the group in file rootfilename |
148 |
|
FinishGroup(rootfilename); |
149 |
|
|
150 |
|
//se gia' e' cambiato download non cambio numdisco |
151 |
|
if (!is_new_route) { |
152 |
|
numDiscontinity++; |
153 |
|
} |
154 |
|
|
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 |
|
if (ret >= 0)// only the packet not discarded of course |
221 |
|
setLast(counter, obt); |
222 |
|
|
223 |
|
//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 |
numPKT++; |
//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, outDir, multiFile, compression); |
strcat(rootfilename, ".root"); |
278 |
strcat(rootfilename,".root"); |
//if ( !pRun ) printf(" horror! -%s- \n",rootfilename); |
279 |
reader->Init(pRun); |
reader->Init(pRun); |
280 |
stringstream oss; |
stringstream oss; |
281 |
oss.str()=""; |
oss.str() = ""; |
282 |
oss<<"######################### Start a new group in file: "<< rootfilename <<" ############################"; |
oss << "######################### Start a new group in file: " << rootfilename << " ############################"; |
283 |
string msg = oss.str(); |
string msg = oss.str(); |
284 |
mainLogUtil->logInfo(msg); |
mainLogUtil->logInfo(msg); |
285 |
} |
} |
286 |
|
|
287 |
//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 |
288 |
void PacketUser::setLast(unsigned long int counter, unsigned long int obt) |
void PacketUser::setLast(unsigned long int counter, unsigned long int obt) { |
289 |
{ |
pkt_number_last = counter; |
290 |
pkt_number_last=counter; |
obt_last = obt; |
|
obt_last=obt; |
|
291 |
} |
} |
292 |
|
|
293 |
|
//retrieve obt_time_sync and last_time_sync_info from packet if type has special values and BOOT_NUMBER |
294 |
|
void PacketUser::setTimeSync(char* packet, long int pktLength, const PacketType* type) { |
295 |
|
//do nothing |
296 |
|
if (!do_cont_check) { |
297 |
|
if (is_new_route) |
298 |
|
is_new_route = false; |
299 |
|
return; |
300 |
|
} |
301 |
|
|
302 |
|
//TODO: usare anche MCMD ... NOTA: questo da sempre errore ret != 0 |
303 |
|
//In RunHeader e RunTrailer sono in secondi(?), controllare se aggiungo altri tipi di paccheti se invece sono in secondi |
304 |
|
// devo ricalcolare tutto non per ogni gruppetto (ROOT file) ma solo se cambia download |
305 |
|
//When I found a new download I need to reset all values |
306 |
|
if (is_new_route) { |
307 |
|
//reset |
308 |
|
is_new_route = false; |
309 |
|
//(tassa) ci ho ripensato se stiamo in un secondo download non prendiamo i bootnumber e timesync del precedente! |
310 |
|
obt_time_sync_prevvalue = 0;//obt_time_sync; |
311 |
|
last_time_sync_info_prevvalue = 0;//last_time_sync_info; |
312 |
|
|
313 |
|
obt_time_sync = 0; |
314 |
|
last_time_sync_info = 0; |
315 |
|
boot_number_prevvalue = 0;//boot_number; |
316 |
|
boot_number = 0; |
317 |
|
time_is_estimated = false; |
318 |
|
if (time_Offset) |
319 |
|
timeOffset = time_Offset; |
320 |
|
else |
321 |
|
timeOffset = retrieveTimeOffset(Table_GL_RESURS_OFFSET); |
322 |
|
} |
323 |
|
|
324 |
//retrieve obt_time_sync and last_time_sync_info from packet if type has special values and BOOT_NUMBER |
//retrieve boot number if possible |
325 |
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); |
|
326 |
|
|
327 |
//Retrieve if possible obt_time_sync and last_time_sync_info |
//Retrieve if possible obt_time_sync and last_time_sync_info |
328 |
int offset=0; |
int offset = 0; |
329 |
if(type==PacketType::RunHeader) |
if (type == PacketType::RunHeader) { |
330 |
{ |
offset = 0; |
331 |
offset=0; |
} |
332 |
} |
else if (type == PacketType::RunTrailer) { |
333 |
else if(type==PacketType::RunTrailer) |
offset = 3; |
334 |
{ |
} |
335 |
offset=3; |
else if (type == PacketType::Mcmd) { |
336 |
} |
// mainLogUtil->logAll("TODO: Packet Mcmd now is not used to retrieve Absolute time. This may cause problems somewhere."); |
337 |
else if(type==PacketType::Mcmd) |
// return; |
338 |
{ |
offset = -1; |
339 |
// mainLogUtil->logAll("TODO: Packet Mcmd now is not used to retrieve Absolute time. This may cause problems somewhere."); |
} |
340 |
return; |
else { |
341 |
} |
return; |
342 |
else |
} |
343 |
{ |
|
344 |
return; |
//I don't need to retrieve them again if they are good |
345 |
} |
// if ((obt_time_sync) || (last_time_sync_info)) |
346 |
|
// return; |
347 |
//I don't need to retrieve them again if they are good |
// no, do it, since there is a (small indeed) time drift due to different clock of PAMELA CPU and RESURS CPU... |
348 |
if((obt_time_sync)||(last_time_sync_info)) return; |
// printf(" %s %lu %lu %lu %lu \n", rootfilename, pkt_number_init, pkt_number_last, obt_init, obt_last); |
349 |
|
if ( offset >= 0 ){ |
350 |
|
// use Runheader or RunTrailer |
351 |
|
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); |
352 |
|
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); |
353 |
|
// |
354 |
|
// if you arrive here and RH/RT timesync is zero try to get the correct info from DB (dangerous??) |
355 |
|
// |
356 |
|
// printf("qui\n"); |
357 |
|
if ( !obt_time_sync && !last_time_sync_info ){ |
358 |
|
// if ( true ){ |
359 |
|
stringstream os; |
360 |
|
os.str() = ""; |
361 |
|
os << " NEW (EM) AGH! NO GOOD TIMESYNC INFOS IN RH OR RT!! TRY TO LOOK IN DB"; |
362 |
|
string msg = os.str(); |
363 |
|
mainLogUtil->logAll(msg); |
364 |
|
|
365 |
|
// mysql> select ID_N,FOLDER_NAME,FILE_NAME,PKT_NUMBER_INIT,PKT_NUMBER_FINAL,BAD_PKT,NUM_PKT_SAVED,INPUT_NAME,INSERT_TIME,INSERTED_BY from ROOT_TABLE_BAD where ON_DISK='YES' order by NUM_PKT_SAVED asc; |
366 |
|
// +------+-------------+----------------------------+-----------------+------------------+---------+---------------+---------------------------------------------------------+---------------------+-------------+ |
367 |
|
// | ID_N | FOLDER_NAME | FILE_NAME | PKT_NUMBER_INIT | PKT_NUMBER_FINAL | BAD_PKT | NUM_PKT_SAVED | INPUT_NAME | INSERT_TIME | INSERTED_BY | |
368 |
|
// +------+-------------+----------------------------+-----------------+------------------+---------+---------------+---------------------------------------------------------+---------------------+-------------+ |
369 |
|
// | 6493 | $PAM_L0FIA | L0PAM_00540_002_012_4.root | 12253479 | 12254111 | 626 | 626 | /wizard/03/pamela_data/preRawreader/00540002.pam | 2010-02-03 21:50:15 | FI | |
370 |
|
// | 6463 | $PAM_L0FIA | L0PAM_00540_002_010_4.root | 12252097 | 12252730 | 627 | 627 | /wizard/03/pamela_data/preRawreader/00540002.pam | 2010-02-03 21:47:16 | FI | |
371 |
|
// | 6525 | $PAM_L0FIA | L0PAM_00540_002_014_4.root | 12254906 | 12255539 | 627 | 629 | /wizard/03/pamela_data/preRawreader/00540002.pam | 2010-02-03 21:53:24 | FI | |
372 |
|
// | 321 | $PAM_L0FIA | L0PAM_00383_001_001_2.root | 601639 | 602281 | 489 | 639 | /wizard/03/pamela_data/preRawreader/00383001.pam | 2010-02-03 16:49:55 | FI | |
373 |
|
// | 306 | $PAM_L0FIA | L0PAM_00383_002_001_2.root | 601572 | 602213 | 0 | 642 | /wizard/03/pamela_data/preRawreader/00383002.pam | 2010-02-03 16:48:55 | FI | |
374 |
|
// | 400 | $PAM_L0FIA | L0PAM_00383_001_005_2.root | 605234 | 605893 | 499 | 656 | /wizard/03/pamela_data/preRawreader/00383001.pam | 2010-02-03 16:57:08 | FI | |
375 |
|
// | 372 | $PAM_L0FIA | L0PAM_00383_001_003_2.root | 603600 | 604258 | 290 | 659 | /wizard/03/pamela_data/preRawreader/00383001.pam | 2010-02-03 16:53:44 | FI | |
376 |
|
// | 6483 | $PAM_L0FIA | L0PAM_00540_002_011_4.root | 12252731 | 12253478 | 739 | 739 | /wizard/03/pamela_data/preRawreader/00540002.pam | 2010-02-03 21:48:52 | FI | |
377 |
|
// | 6428 | $PAM_L0FIA | L0PAM_00540_002_009_4.root | 12251326 | 12252096 | 764 | 765 | /wizard/03/pamela_data/preRawreader/00540002.pam | 2010-02-03 21:45:51 | FI | |
378 |
|
// | 6507 | $PAM_L0FIA | L0PAM_00540_002_013_4.root | 12254112 | 12254905 | 781 | 781 | /wizard/03/pamela_data/preRawreader/00540002.pam | 2010-02-03 21:52:01 | FI | |
379 |
|
// | 378 | $PAM_L0FIA | L0PAM_00374_001_001_1.root | 368888 | 369754 | 0 | 867 | /wizard/03/pamela_data/preRawreader/00374001.pam | 2010-02-03 16:54:30 | FI | |
380 |
|
// | 6565 | $PAM_L0FIA | L0PAM_00540_002_015_4.root | 12255540 | 12256457 | 907 | 907 | /wizard/03/pamela_data/preRawreader/00540002.pam | 2010-02-03 21:55:22 | FI | |
381 |
|
// | 413 | $PAM_L0FIA | L0PAM_00383_001_006_2.root | 605894 | 606807 | 417 | 913 | /wizard/03/pamela_data/preRawreader/00383001.pam | 2010-02-03 16:58:52 | FI | |
382 |
|
// | 390 | $PAM_L0FIA | L0PAM_00383_001_004_2.root | 604259 | 605233 | 684 | 975 | /wizard/03/pamela_data/preRawreader/00383001.pam | 2010-02-03 16:55:45 | FI | |
383 |
|
// | 358 | $PAM_L0FIA | L0PAM_00383_001_002_2.root | 602282 | 603599 | 649 | 1316 | /wizard/03/pamela_data/preRawreader/00383001.pam | 2010-02-03 16:52:23 | FI | |
384 |
|
// | 185 | $PAM_L0NAA | L0PAM_01737_001_001_1.root | 9373563 | 9375405 | 0 | 1843 | /storage02/pamela/pamela_data/preRawreader/01737001.pam | 2010-02-03 16:24:50 | NA | |
385 |
|
// | 375 | $PAM_L0FIA | L0PAM_00383_002_002_2.root | 602214 | 608541 | 0 | 6328 | /wizard/03/pamela_data/preRawreader/00383002.pam | 2010-02-03 16:54:08 | FI | |
386 |
|
// | 1419 | $PAM_L0FIA | L0PAM_00383_001_007_2.root | 606808 | 620604 | 9086 | 13764 | /wizard/03/pamela_data/preRawreader/00383001.pam | 2010-02-03 17:26:39 | FI | |
387 |
|
// | 6118 | $PAM_L0NAA | L0PAM_02144_002_001_1.root | 0 | 123139 | 6 | 123139 | /storage02/pamela/pamela_data/preRawreader/02144002.pam | 2010-02-03 21:29:51 | NA | |
388 |
|
// | 4470 | $PAM_L0FIA | L0PAM_00614_001_001_1.root | 1409 | 130146 | 6 | 128722 | /wizard/03/pamela_data/preRawreader/00614001.pam | 2010-02-03 18:47:26 | FI | |
389 |
|
// +------+-------------+----------------------------+-----------------+------------------+---------+---------------+---------------------------------------------------------+---------------------+-------------+ |
390 |
|
// 20 rows in set (0.05 sec) |
391 |
|
// mysql> select FILE_NAME, abs(PKT_NUMBER_INIT-123139), abs(0-PKT_NUMBER_FINAL) from ROOT_TABLE where (abs(PKT_NUMBER_INIT-123139)<10000 or abs(0-PKT_NUMBER_FINAL)<10000) and FILE_NAME like "L0PAM_021%"; |
392 |
|
// +-----------------------------+-----------------------------+-------------------------+ |
393 |
|
// | FILE_NAME | abs(PKT_NUMBER_INIT-123139) | abs(0-PKT_NUMBER_FINAL) | |
394 |
|
// +-----------------------------+-----------------------------+-------------------------+ |
395 |
|
// | L0PAM_02173_001_001_11.root | 123103 | 251 | |
396 |
|
// +-----------------------------+-----------------------------+-------------------------+ |
397 |
|
// 1 row in set (0.07 sec) |
398 |
|
// |
399 |
|
TString *nomino=new TString(rootfilename); |
400 |
|
nomino->Remove(9); |
401 |
|
TString mmyy=Form("select OBT_TIME_SYNC, LAST_TIME_SYNC_INFO from ROOT_TABLE where (abs(PKT_NUMBER_INIT-%lu)<10000 or abs(%lu-PKT_NUMBER_FINAL)<10000) and FILE_NAME like '%s%%' limit 1;",pkt_number_last, pkt_number_init,nomino->Data()); |
402 |
|
delete nomino; |
403 |
|
stringstream os3; |
404 |
|
os3.str() = ""; |
405 |
|
os3 << " NEW (EM) TRY TO FIND TSYNC IN DB QUERY: " << mmyy.Data(); |
406 |
|
string msg3 = os3.str(); |
407 |
|
mainLogUtil->logAll(msg3); |
408 |
|
// |
409 |
|
TSQLResult* res = NULL; |
410 |
|
TSQLRow* row = NULL; |
411 |
|
Bool_t apro = false; |
412 |
|
if (!single_connection && !sqlServer ) { |
413 |
|
OpenDBConnection(NULL);// no, locak tutto Nota qui ho deciso di lockare solo questa tabella e non tutte |
414 |
|
apro = true; |
415 |
|
} |
416 |
|
res = sqlServer->Query(mmyy.Data()); |
417 |
|
if (!res) { |
418 |
|
mainLogUtil->logError("DBError retrieve time sync"); |
419 |
|
return; |
420 |
|
}; |
421 |
|
row = res->Next(); |
422 |
|
if ( row ){ |
423 |
|
obt_time_sync = (ULong_t)atoi(row->GetField(0)); |
424 |
|
last_time_sync_info = (ULong_t)atoi(row->GetField(1)); |
425 |
|
// |
426 |
|
stringstream os2; |
427 |
|
os2.str() = ""; |
428 |
|
os2 << " NEW (EM) FOUND TSYNC IN DB "; |
429 |
|
string msg2 = os2.str(); |
430 |
|
mainLogUtil->logAll(msg2); |
431 |
|
// |
432 |
|
}; |
433 |
|
if (res) { |
434 |
|
delete res; |
435 |
|
res = NULL; |
436 |
|
}; |
437 |
|
// |
438 |
|
if (!single_connection && apro) { |
439 |
|
CloseDBConnection(); |
440 |
|
}; |
441 |
|
}; |
442 |
|
|
443 |
|
} else { |
444 |
|
// Use Packet Mcmd now is not used to retrieve Absolute time |
445 |
|
// printf(" Pointer to Mcmd obj is %p \n",reader->GetPtr("Mcmd")); |
446 |
|
|
447 |
|
UInt_t recEntries = 0; |
448 |
|
Double_t minimum = 0.; |
449 |
|
Double_t maximum = 0.; |
450 |
|
Double_t minimum2 = 0.; |
451 |
|
Double_t maximum2 = 0.; |
452 |
|
UInt_t TSYNC = 0; |
453 |
|
UInt_t OBT = 0; |
454 |
|
Bool_t existsts = false; |
455 |
|
// |
456 |
|
pamela::McmdEvent *mc = (pamela::McmdEvent*)(((pamela::techmodel::McmdReader*)reader->GetPtr("Mcmd"))->GetMcmd()); |
457 |
|
pamela::McmdRecord *mcrc = 0; |
458 |
|
TArrayC *mcmddata = 0; |
459 |
|
// |
460 |
|
minimum = numeric_limits<Double_t>::max(); |
461 |
|
maximum = numeric_limits<Double_t>::min(); |
462 |
|
minimum2 = numeric_limits<Double_t>::max(); |
463 |
|
maximum2 = numeric_limits<Double_t>::min(); |
464 |
|
// |
465 |
|
recEntries = mc->Records->GetEntries(); |
466 |
|
// printf(" recEntries is %i \n",recEntries); |
467 |
|
|
468 |
|
for (UInt_t j = 0; j < recEntries; j++){ |
469 |
|
mcrc = (pamela::McmdRecord*)mc->Records->At(j); |
470 |
|
mcmddata = mcrc->McmdData; |
471 |
|
// |
472 |
|
if (mcrc->ID1 == 0xE0 && mcrc->Mcmd_Block_crc_ok == 1 ){ // mcmd timesync |
473 |
|
// |
474 |
|
OBT = (Int_t)(mcrc->MCMD_RECORD_OBT); |
475 |
|
// |
476 |
|
TSYNC = (((UInt_t)mcmddata->At(0)<<24)&0xFF000000) + (((UInt_t)mcmddata->At(1)<<16)&0x00FF0000) + (((UInt_t)mcmddata->At(2)<<8)&0x0000FF00) + (((UInt_t)mcmddata->At(3))&0x000000FF); |
477 |
|
// |
478 |
|
// printf("mcmd tsync tsync %u obt %u \n",TSYNC,OBT); |
479 |
|
// |
480 |
|
if ( TSYNC && OBT ){ |
481 |
|
existsts = true; |
482 |
|
stringstream os; |
483 |
|
os.str() = ""; |
484 |
|
os << " NEW (EM) FOUND TIMESYNC IN TIMESYNC MCMD"; |
485 |
|
string msg = os.str(); |
486 |
|
mainLogUtil->logAll(msg); |
487 |
|
break; |
488 |
|
}; |
489 |
|
// |
490 |
|
}; |
491 |
|
}; |
492 |
|
// |
493 |
|
if ( !existsts ){ // try with inclination mcmd |
494 |
|
// |
495 |
|
Double_t timesync = 0.; |
496 |
|
// |
497 |
|
for (UInt_t j = 0; j < recEntries; j++){ |
498 |
|
mcrc = (pamela::McmdRecord*)mc->Records->At(j); |
499 |
|
mcmddata = mcrc->McmdData; |
500 |
|
// |
501 |
|
if (mcrc->ID1 == 0xE2 && mcrc->Mcmd_Block_crc_ok == 1 ){ // mcmd inclination |
502 |
|
timesync = 0.; |
503 |
|
timesync = (Double_t)(((((UInt_t)mcmddata->At(0) << 24) & 0xFF000000) + (((UInt_t)mcmddata->At(1) << 16) & 0x00FF0000) + (((UInt_t)mcmddata->At(2) << 8) & 0x0000FF00) + ((UInt_t)mcmddata->At(3) & 0x000000FF))/128.0); |
504 |
|
// |
505 |
|
if ( timesync > maximum2){ |
506 |
|
maximum2 = timesync; |
507 |
|
OBT = (Int_t)(mcrc->MCMD_RECORD_OBT); |
508 |
|
}; |
509 |
|
}; |
510 |
|
// |
511 |
|
}; |
512 |
|
if ( maximum2 > numeric_limits<Double_t>::min() ){ |
513 |
|
TSYNC = (UInt_t)(maximum2 + 0.5); |
514 |
|
if ( TSYNC && OBT ){ |
515 |
|
existsts = true; |
516 |
|
stringstream os; |
517 |
|
os.str() = ""; |
518 |
|
os << " NEW (EM) FOUND TIMESYNC IN INCLINATION MCMD"; |
519 |
|
string msg = os.str(); |
520 |
|
mainLogUtil->logAll(msg); |
521 |
|
}; |
522 |
|
}; |
523 |
|
}; |
524 |
|
if ( !existsts ) return; |
525 |
|
|
526 |
|
// printf(" TIMESYNC FROM MCMD FOUND: TSYNC = %i OBT = %i \n",TSYNC,OBT); |
527 |
|
obt_time_sync = int(OBT/1000); |
528 |
|
last_time_sync_info = TSYNC; |
529 |
|
|
530 |
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); |
}; |
|
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); |
|
531 |
|
|
532 |
stringstream oss; |
stringstream oss; |
533 |
oss.str()=""; |
oss.str() = ""; |
534 |
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 |
535 |
string msg = oss.str(); |
<< " last_time_sync_info: " << last_time_sync_info << " using Packet Type: " << type->GetName(); |
536 |
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(); |
537 |
|
string msg = oss.str(); |
538 |
|
mainLogUtil->logAll(msg); |
539 |
} |
} |
540 |
|
|
541 |
//Boot Number |
//Boot Number |
542 |
void PacketUser::setBootNumber(char* packet, long int pktLength, const PacketType* type) |
void PacketUser::setBootNumber(char* packet, long int pktLength, const PacketType* type) { |
543 |
{ |
//se gia calcolato esco: lo calcolo una volta per download e per continuita' |
544 |
//se gia calcolato esco: lo calcolo una volta per download e per continuita' |
if (boot_number) |
545 |
if(boot_number) return; |
return; |
546 |
|
|
547 |
if(type==PacketType::VarDump) |
if (type == PacketType::VarDump) { |
548 |
{ |
int b_offset = 34;//4+5*6 |
549 |
int b_offset = 34;//4+5*6 |
boot_number = (((UINT32) packet[1 + b_offset] << 24) & 0xFF000000) + (((UINT32) packet[2 + b_offset] << 16) |
550 |
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]) |
551 |
|
& 0x000000FF); |
552 |
/* |
|
553 |
long int dataLength = pktLength - 2; //the block of data |
/* |
554 |
int b_offset = 4; |
long int dataLength = pktLength - 2; //the block of data |
555 |
while (b_offset < dataLength){ |
int b_offset = 4; |
556 |
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){ |
557 |
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); |
558 |
} |
b_offset = b_offset + 5; |
559 |
*/ |
} |
560 |
stringstream oss; |
*/ |
561 |
oss.str()=""; |
stringstream oss; |
562 |
oss<<"In download: "<<download<<" boot_number: "<<boot_number<<" using Packet Type: "<<type->GetName().c_str(); |
oss.str() = ""; |
563 |
string msg = oss.str(); |
// oss<<"In download: "<<download<<" boot_number: "<<boot_number<<" using Packet Type: "<<type->GetName().c_str(); |
564 |
mainLogUtil->logAll(msg); |
oss << "In download: " << download << " boot_number: " << boot_number << " using Packet Type: " << type->GetName(); |
565 |
return; |
string msg = oss.str(); |
566 |
} |
mainLogUtil->logAll(msg); |
567 |
else |
return; |
568 |
{ |
} |
569 |
return; |
else { |
570 |
} |
return; |
571 |
|
} |
572 |
|
|
573 |
} |
} |
574 |
//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 |
575 |
void PacketUser::setReal_Time() |
void PacketUser::setReal_Time() { |
|
{ |
|
576 |
|
|
577 |
if(!obt_time_sync && !last_time_sync_info && numPKTSaved > 1000 ) |
if (!obt_time_sync && !last_time_sync_info && numPKTSaved > recoverlimit) { |
578 |
{ |
time_is_estimated = true; |
579 |
time_is_estimated=true; |
obt_time_sync = obt_time_sync_prevvalue; |
580 |
obt_time_sync=obt_time_sync_prevvalue; |
last_time_sync_info = last_time_sync_info_prevvalue; |
581 |
last_time_sync_info=last_time_sync_info_prevvalue; |
} |
582 |
} |
if (obt_time_sync || last_time_sync_info) { |
583 |
if(obt_time_sync || last_time_sync_info) |
real_time_init = (obt_init / 1000 - obt_time_sync) + last_time_sync_info; |
584 |
{ |
//se obt si e' resettato |
585 |
real_time_init=(obt_init/1000-obt_time_sync)+last_time_sync_info; |
if (obt_last < obt_init) { |
586 |
//se obt si e' resettato |
real_time_last = (max_pkt_obt / 1000 + obt_last / 1000 - obt_time_sync) + last_time_sync_info; |
587 |
if(obt_last<obt_init) |
stringstream oss; |
588 |
{ |
oss.str() = ""; |
589 |
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 |
590 |
stringstream oss; |
<< "). It is due to Pamela Reset. Adding max_pkt_obt(" << max_pkt_obt |
591 |
oss.str()=""; |
<< ") to obt_last in order to compute real_time_last"; |
592 |
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(); |
593 |
string msg = oss.str(); |
mainLogUtil->logWarning(msg); |
594 |
mainLogUtil->logWarning(msg); |
} |
595 |
} |
else |
596 |
else |
real_time_last = (obt_last / 1000 - obt_time_sync) + last_time_sync_info; |
597 |
real_time_last=(obt_last/1000-obt_time_sync)+last_time_sync_info; |
real_time_init += timeOffset; |
598 |
real_time_init+=timeOffset; |
real_time_last += timeOffset; |
599 |
real_time_last+=timeOffset; |
} |
600 |
} |
} |
601 |
|
|
602 |
|
void PacketUser::setReal_TimeRECOVERY( |
603 |
|
unsigned long int & _real_time_init, |
604 |
|
unsigned long int & _real_time_last, |
605 |
|
unsigned long int _obt_init, |
606 |
|
unsigned long int _obt_last |
607 |
|
) { |
608 |
|
|
609 |
|
if (obt_time_sync || last_time_sync_info) { |
610 |
|
_real_time_init = (_obt_init / 1000 - obt_time_sync) + last_time_sync_info; |
611 |
|
//se obt si e' resettato |
612 |
|
if (_obt_last < _obt_init) { |
613 |
|
_real_time_last = (max_pkt_obt / 1000 + _obt_last / 1000 - obt_time_sync) + last_time_sync_info; |
614 |
|
stringstream oss; |
615 |
|
oss.str() = ""; |
616 |
|
oss << "obt_last(" << obt_last << ") < obt_init(" << obt_init |
617 |
|
<< "). It is due to Pamela Reset. Adding max_pkt_obt(" << max_pkt_obt |
618 |
|
<< ") to obt_last in order to compute real_time_last"; |
619 |
|
string msg = oss.str(); |
620 |
|
mainLogUtil->logWarning(msg); |
621 |
|
} |
622 |
|
else |
623 |
|
_real_time_last = (_obt_last / 1000 - obt_time_sync) + last_time_sync_info; |
624 |
|
_real_time_init += timeOffset; |
625 |
|
_real_time_last += timeOffset; |
626 |
|
} |
627 |
} |
} |
628 |
|
|
629 |
|
|
630 |
//timeOffset |
//timeOffset |
631 |
//retrieve from table Table_GL_RESURS_OFFSET timeOffset |
//retrieve from table Table_GL_RESURS_OFFSET timeOffset |
632 |
unsigned long int PacketUser::retrieveTimeOffset(char * table) |
unsigned long int PacketUser::retrieveTimeOffset(const char * table) { |
633 |
{ |
if (!do_cont_check) |
634 |
if(!do_cont_check) return 0; |
return 0; |
|
|
|
|
//if(!table){table=Table_GL_RESURS_OFFSET} |
|
635 |
|
|
636 |
if(!single_connection){ |
//if(!table){table=Table_GL_RESURS_OFFSET} |
|
OpenDBConnection(table);//Nota qui ho deciso di lockare solo questa tabella e non tutte |
|
|
} |
|
637 |
|
|
638 |
UInt_t t0 = 0;//toffset |
if (!single_connection) { |
639 |
stringstream oss; |
OpenDBConnection(NULL);// no, locak tutto Nota qui ho deciso di lockare solo questa tabella e non tutte |
640 |
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;} |
|
641 |
|
|
642 |
if(!single_connection){ |
UInt_t t0 = 0;//toffset |
643 |
CloseDBConnection(); |
stringstream oss; |
644 |
} |
oss.str(""); |
645 |
return t0; |
oss |
646 |
|
<< "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE),ID FROM " |
647 |
|
<< table << " WHERE SPECIAL_FILE='" << nnnn_mmm_ppp << "';"; |
648 |
|
|
649 |
|
string msg = oss.str(); |
650 |
|
mainLogUtil->logAll(msg); |
651 |
|
|
652 |
|
TSQLResult* res = NULL; |
653 |
|
TSQLRow* row = NULL; |
654 |
|
res = sqlServer->Query(oss.str().c_str()); |
655 |
|
if (!res) { |
656 |
|
mainLogUtil->logError("DBError retrieveTimeOffset 1"); |
657 |
|
return 0; |
658 |
|
} |
659 |
|
|
660 |
|
row = res->Next(); |
661 |
|
if (!row) { |
662 |
|
if (res) { |
663 |
|
delete res; |
664 |
|
res = NULL; |
665 |
|
} |
666 |
|
|
667 |
|
oss.str(""); |
668 |
|
oss |
669 |
|
<< "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE),ID FROM " |
670 |
|
<< table << " WHERE FROM_ORBIT < " << orbit_number << " AND SPECIAL_FILE='' order by FROM_ORBIT desc limit 1;"; |
671 |
|
|
672 |
|
string msg2 = oss.str(); |
673 |
|
mainLogUtil->logAll(msg2); |
674 |
|
|
675 |
|
res = sqlServer->Query(oss.str().c_str()); |
676 |
|
if (!res) { |
677 |
|
mainLogUtil->logError("DBError retrieveTimeOffset 2"); |
678 |
|
return 0; |
679 |
|
} |
680 |
|
row = res->Next(); |
681 |
|
if (!row) { |
682 |
|
mainLogUtil->logError("DBError retrieveTimeOffset 3"); |
683 |
|
return 0; |
684 |
|
} |
685 |
|
|
686 |
|
} |
687 |
|
|
688 |
|
TTimeStamp tu = TTimeStamp((UInt_t) atoi(row->GetField(0)), (UInt_t) atoi(row->GetField(1)), (UInt_t) atoi( |
689 |
|
row->GetField(2)), (UInt_t) atoi(row->GetField(3)), (UInt_t) atoi(row->GetField(4)), (UInt_t) atoi(row->GetField( |
690 |
|
5)), 0, true, 0); |
691 |
|
t0 = (UInt_t) tu.GetSec(); |
692 |
|
|
693 |
|
if (res) { |
694 |
|
delete res; |
695 |
|
res = NULL; |
696 |
|
} |
697 |
|
if (row) { |
698 |
|
delete row; |
699 |
|
row = NULL; |
700 |
|
} |
701 |
|
|
702 |
|
if (!single_connection) { |
703 |
|
CloseDBConnection(); |
704 |
|
} |
705 |
|
return t0; |
706 |
} |
} |
707 |
|
|
708 |
//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 |
709 |
void PacketUser::FinishLastGroup() |
void PacketUser::FinishLastGroup() { |
710 |
{ |
mainLogUtil->logAll("######################### Closing the last group ############################"); |
711 |
mainLogUtil->logAll("######################### Closing the last group ############################"); |
setReal_Time(); |
712 |
setReal_Time(); |
FinishGroup(rootfilename); |
713 |
FinishGroup(rootfilename); |
mainLogUtil->logAll("######################### Closed the last group ############################"); |
714 |
mainLogUtil->logAll("######################### Closed the last group ############################"); |
// |
715 |
if(single_connection){ |
if (single_connection) { |
716 |
CloseDBConnection(); |
CloseDBConnection(); |
717 |
} |
} |
718 |
} |
} |
719 |
|
|
720 |
//Finish the old root file |
//Finish the old root file |
721 |
void PacketUser::FinishGroup(char * filename) |
void PacketUser::FinishGroup(char * filename) { |
722 |
{ |
if (pRun) { |
723 |
if(pRun) |
if ( !( !real_time_init && !real_time_last && numPKTSaved <= recoverlimit ) || !candelete ) pRun->WriteFiles(); |
724 |
{ |
delete pRun; |
725 |
pRun->WriteFiles(); |
pRun = NULL; |
726 |
delete pRun; pRun = NULL; |
stringstream close; |
727 |
stringstream close; |
close.str() = ""; |
728 |
close.str()=""; |
string msg; |
729 |
string msg; |
|
730 |
|
close << "TAG XX ######################### Close group in file: " << rootfilename << " ############################"; |
731 |
close<<"######################### Close group in file: "<< rootfilename <<" ############################"; |
msg = close.str(); |
732 |
msg = close.str(); |
mainLogUtil->logInfo(msg); |
733 |
mainLogUtil->logInfo(msg); |
|
734 |
|
// se non faccio proprio controlli su continuita' neanche salvo su DB |
735 |
// se non faccio proprio controlli su continuita' neanche salvo su DB |
if (!do_cont_check) |
736 |
if(!do_cont_check) return; |
return; |
737 |
|
|
738 |
|
stringstream oss; |
739 |
|
oss.str() = ""; |
740 |
|
|
741 |
|
//TODO: check when I don't want to log in DB informations |
742 |
|
// se non ho salvato nessun pacchetto |
743 |
|
if (numPKTSaved == 0) { |
744 |
|
stringstream err; |
745 |
|
err.str() = ""; |
746 |
|
err << "NO PACKET SAVED in file: " << rootfilename << " The group is empty: you can remove this file."; |
747 |
|
msg = err.str(); |
748 |
|
mainLogUtil->logError(msg); |
749 |
|
// return; |
750 |
|
} |
751 |
|
|
752 |
|
//se non ho salvato nessun pacchetto buono |
753 |
|
if ((numPKTSaved - bad_pkt_EventReader - bad_pkt_CalibReader - bad_pkt) == 0) { |
754 |
|
stringstream err; |
755 |
|
err.str() = ""; |
756 |
|
err << "NO GOOD PACKET SAVED in file: " << rootfilename << " The group is BAD: you may want to remove this file."; |
757 |
|
msg = err.str(); |
758 |
|
mainLogUtil->logInfo(msg); |
759 |
|
// mainLogUtil->logError(msg); |
760 |
|
// return; //TODO: decidi se nn vuoi affatto usarlo o addirittura salvarlo tra i BAD??? |
761 |
|
} |
762 |
|
|
763 |
|
if (!single_connection) { |
764 |
|
OpenDBConnection(NULL);//Nota qui ho deciso di lockare tutte le tabelle |
765 |
|
} |
766 |
|
|
767 |
|
|
768 |
|
//don't save in Table_ROOT_Good and don't search for ROOT files in the same temporal range |
769 |
|
if ((!real_time_init) && (!real_time_last)) { |
770 |
|
//saved in another table for future study |
771 |
|
if (saveROOT_DB( |
772 |
|
Table_ROOT_Bad, |
773 |
|
outDir,// here outDir is good, no expand EMI |
774 |
|
filename, pkt_number_init, pkt_number_last, obt_init, obt_last, obt_time_sync, last_time_sync_info, |
775 |
|
real_time_init, real_time_last, boot_number, timeOffset, bad_pkt, bad_pkt_EventReader, bad_pkt_CalibReader, |
776 |
|
numPKTSaved, fni, time_is_estimated) == true) { |
777 |
|
oss.str() = ""; |
778 |
|
oss << "Saved information regarding file: " << filename << " in table " << Table_ROOT_Bad; |
779 |
|
msg = oss.str(); |
780 |
|
mainLogUtil->logInfo(msg); |
781 |
|
} |
782 |
|
else { |
783 |
|
oss.str() = ""; |
784 |
|
oss << "Problem storing information in DB regarding file: " << filename; |
785 |
|
msg = oss.str(); |
786 |
|
mainLogUtil->logError(msg); |
787 |
|
} |
788 |
|
|
789 |
|
|
790 |
|
|
791 |
|
if ( numPKTSaved > recoverlimit){ // EM |
792 |
|
// |
793 |
|
if ( obt_time_sync && last_time_sync_info ){ |
794 |
|
stringstream err; |
795 |
|
err.str() = ""; |
796 |
|
err << "(EM): -- RECOVERING WHEN NUMPACKET > "<< recoverlimit <<"!! -- file=<" << filename << ">. We have a previous time sync, immediate recovery!\n"; |
797 |
|
msg = err.str(); |
798 |
|
mainLogUtil->logInfo(msg); |
799 |
|
// |
800 |
|
setReal_TimeRECOVERY( |
801 |
|
real_time_init, |
802 |
|
real_time_last, |
803 |
|
obt_init, |
804 |
|
obt_last |
805 |
|
); |
806 |
|
// |
807 |
|
} else { |
808 |
|
stringstream err; |
809 |
|
err.str() = ""; |
810 |
|
err << "TAG(tassa): -- RECOVERING WHEN NUMPACKET > "<< recoverlimit <<"!! -- file=<" << filename << ">. Saving in a queue to try alfer to recover it!\n"; |
811 |
|
msg = err.str(); |
812 |
|
mainLogUtil->logInfo(msg); |
813 |
|
|
814 |
|
// TString qu = Form("select ID_N from ROOT_TABLE_BAD order by INSERT_TIME desc limit 1;"); // <========================= |
815 |
|
TString qu = Form("select ID_N from ROOT_TABLE_BAD where FILE_NAME='%s' and PKT_NUMBER_INIT=%i and INSERTED_BY='%s';",filename,pkt_number_init,tag_value); // <========================= |
816 |
|
TSQLResult *result = sqlServer->Query(qu.Data()); |
817 |
|
TSQLRow *row = result->Next(); |
818 |
|
Int_t eid = -1; |
819 |
|
if ( row ) eid = (Int_t)atoi(row->GetField(0)); |
820 |
|
idtorecover->AddAt(eid,arsize); |
821 |
|
arsize++; |
822 |
|
if ( arsize > 100 ) idtorecover->Set(arsize); |
823 |
|
// dbinfo *app = new dbinfo( outDir, |
824 |
|
// filename, pkt_number_init, pkt_number_last, obt_init, obt_last, boot_number, timeOffset, bad_pkt, bad_pkt_EventReader, bad_pkt_CalibReader, |
825 |
|
// numPKTSaved, fni, time_is_estimated); |
826 |
|
// m_dbinfos.push_back(app); |
827 |
|
} |
828 |
|
|
829 |
|
CleanDisk(); |
830 |
|
// if (!single_connection) { |
831 |
|
// CloseDBConnection(); |
832 |
|
// } |
833 |
|
// return; // commented here... |
834 |
|
|
835 |
|
}; |
836 |
|
} |
837 |
|
|
838 |
|
if ( real_time_init || real_time_last) { |
839 |
|
//saves info in DB in table Table_ROOT |
840 |
|
if (boot_number == 0) |
841 |
|
boot_number = boot_number_prevvalue; |
842 |
|
|
843 |
|
if (saveROOT_DB( |
844 |
|
Table_ROOT_Good, |
845 |
|
outDir, // here outDir is good, no expand EMI |
846 |
|
filename, pkt_number_init, pkt_number_last, obt_init, obt_last, obt_time_sync, last_time_sync_info, |
847 |
|
real_time_init, real_time_last, boot_number, timeOffset, bad_pkt, bad_pkt_EventReader, bad_pkt_CalibReader, |
848 |
|
numPKTSaved, fni, time_is_estimated) == true) { |
849 |
|
oss.str() = ""; |
850 |
|
oss << "Saved information regarding file: " << filename << " in table " << Table_ROOT_Good << " id= " << my_id; |
851 |
|
msg = oss.str(); |
852 |
|
mainLogUtil->logInfo(msg); |
853 |
|
|
854 |
stringstream oss; |
if (tryMerge) { |
855 |
oss.str()=""; |
merge_ROOTfiles(); |
856 |
|
} |
857 |
//TODO: check when I don't want to log in DB informations |
} else { |
858 |
// se non ho salvato nessun pacchetto |
oss.str() = ""; |
859 |
if(numPKTSaved==0){ |
oss << "Problem storing information in DB regarding file: " << filename; |
860 |
stringstream err; |
msg = oss.str(); |
861 |
err.str()=""; |
mainLogUtil->logError(msg); |
862 |
err<<"NO PACKET SAVED in file: "<< rootfilename <<" The group is empty: you can remove this file."; |
} |
863 |
msg = err.str(); |
}; |
864 |
mainLogUtil->logError(msg); |
|
865 |
return; |
// if dbinfo is not empty than |
866 |
} |
if ( arsize > 0 ){ |
867 |
|
|
868 |
//se non ho salvato nessun pacchetto buono |
if ( !obt_time_sync || !last_time_sync_info ){ |
869 |
if((numPKTSaved-bad_pkt_EventReader-bad_pkt_CalibReader-bad_pkt)==0){ |
TString *nomino=new TString(rootfilename); |
870 |
stringstream err; |
nomino->Remove(15); |
871 |
err.str()=""; |
TString qu = Form("select OBT_TIME_SYNC,LAST_TIME_SYNC_INFO from ROOT_TABLE where FILE_NAME like '%s_%%' and (abs(PKT_NUMBER_INIT-%lu)<50000 or abs(PKT_OBT_INIT-%lu)<3000000) limit 1;",nomino->Data(),pkt_number_init,obt_init); |
872 |
err<<"NO GOOD PACKET SAVED in file: "<< rootfilename <<" The group is BAD: you may want to remove this file."; |
// |
873 |
msg = err.str(); |
oss.str() = ""; |
874 |
mainLogUtil->logInfo(msg); |
oss << "(EM) Trying to find obt_time_sync and last_time_sync_info from DB, query is: " << qu.Data(); |
875 |
// mainLogUtil->logError(msg); |
msg = oss.str(); |
876 |
// return; //TODO: decidi se nn vuoi affatto usarlo o addirittura salvarlo tra i BAD??? |
mainLogUtil->logInfo(msg); |
877 |
} |
// |
878 |
|
TSQLResult *result = sqlServer->Query(qu.Data()); |
879 |
if(!single_connection){ |
TSQLRow *row = result->Next(); |
880 |
OpenDBConnection(NULL);//Nota qui ho deciso di lockare tutte le tabelle |
if ( row && result->GetRowCount() == 1 ){ |
881 |
} |
obt_time_sync = (unsigned long int)atoll(row->GetField(0)); |
882 |
|
last_time_sync_info = (unsigned long int)atoll(row->GetField(1)); |
883 |
//don't save in Table_ROOT_Good and don't search for ROOT files in the same temporal range |
oss.str() = ""; |
884 |
if((!real_time_init)&&(!real_time_last)) |
oss << "(EM) found obt_time_sync and last_time_sync_info from DB! obt_time_sync = " <<obt_time_sync <<" last_time_sync_info = " << last_time_sync_info; |
885 |
{ |
msg = oss.str(); |
886 |
//saved in another table for future study |
mainLogUtil->logInfo(msg); |
887 |
if(saveROOT_DB(Table_ROOT_Bad, outDir, |
}; |
888 |
filename, |
delete nomino; |
889 |
pkt_number_init, pkt_number_last, |
}; |
890 |
obt_init, obt_last, |
|
891 |
obt_time_sync, last_time_sync_info, |
if ( obt_time_sync && last_time_sync_info ){ |
892 |
real_time_init, real_time_last, |
// if(!m_dbinfos.empty()){ |
893 |
boot_number, |
// while(!m_dbinfos.empty()){ |
894 |
timeOffset, |
// dbinfo *app = m_dbinfos.back(); |
895 |
bad_pkt, bad_pkt_EventReader, bad_pkt_CalibReader, numPKTSaved, |
// m_dbinfos.pop_back(); |
896 |
fni,time_is_estimated)==true) |
Int_t ez=0; |
897 |
{ |
while ( ez < arsize ){ |
898 |
oss.str()=""; |
Int_t eid = idtorecover->At(ez); |
899 |
oss<<"Saved information regarding file: "<<filename<<" in table "<<Table_ROOT_Bad; |
if ( eid > -1 ){ |
900 |
msg = oss.str(); |
|
901 |
mainLogUtil->logInfo(msg); |
TString qu = Form("select FOLDER_NAME,FILE_NAME,PKT_NUMBER_INIT,PKT_NUMBER_FINAL,PKT_OBT_INIT,PKT_OBT_FINAL,BOOT_NUMBER,TIME_OFFSET,BAD_PKT,BAD_PKT_READ,BAD_PKT_CALREAD,NUM_PKT_SAVED,INPUT_NAME,TIME_IS_ESTIMATED from ROOT_TABLE_BAD where ID_N=%i;",eid); |
902 |
} |
TSQLResult *result = sqlServer->Query(qu.Data()); |
903 |
else |
TSQLRow *row = result->Next(); |
904 |
{ |
|
905 |
oss.str()=""; |
TString efolder_name=""; |
906 |
oss<<"Problem storing information in DB regarding file: "<<filename; |
TString efile_name=""; |
907 |
msg = oss.str(); |
unsigned long int epkt_number_in=0ULL; |
908 |
mainLogUtil->logError(msg); |
unsigned long int epkt_number_fin=0ULL; |
909 |
} |
unsigned long int eobt_in=0ULL; |
910 |
|
unsigned long int eobt_fin=0ULL; |
911 |
if(!single_connection){ |
unsigned long int emboot_num=0ULL; |
912 |
CloseDBConnection(); |
unsigned long int etime_offset=0ULL; |
913 |
} |
int ebad_pkt=0; |
914 |
|
int ebad_pkt_read=0; |
915 |
return; |
int ebad_pkt_CalRead=0; |
916 |
} |
int enum_PKT_Saved=0; |
917 |
|
TString enome_input=""; |
918 |
//saves info in DB in table Table_ROOT_Good |
bool e_time_is_estimated=false; |
919 |
if(boot_number==0) |
|
920 |
boot_number=boot_number_prevvalue; |
if ( row ){ |
921 |
|
efolder_name = (TString)row->GetField(0); |
922 |
if(saveROOT_DB(Table_ROOT_Good, outDir, |
efile_name = (TString)row->GetField(1); |
923 |
filename, |
epkt_number_in = (unsigned long int)atoll(row->GetField(2)); |
924 |
pkt_number_init, pkt_number_last, |
epkt_number_fin = (unsigned long int)atoll(row->GetField(3)); |
925 |
obt_init, obt_last, |
eobt_in = (unsigned long int)atoll(row->GetField(4)); |
926 |
obt_time_sync, last_time_sync_info, |
eobt_fin = (unsigned long int)atoll(row->GetField(5)); |
927 |
real_time_init, real_time_last, |
emboot_num = (unsigned long int)atoll(row->GetField(6)); |
928 |
boot_number, |
etime_offset = (unsigned long int)atoll(row->GetField(7)); |
929 |
timeOffset, |
ebad_pkt = (int)atoi(row->GetField(8)); |
930 |
bad_pkt, bad_pkt_EventReader, bad_pkt_CalibReader, numPKTSaved, |
ebad_pkt_read = (int)atoi(row->GetField(9)); |
931 |
fni,time_is_estimated)==true) |
ebad_pkt_CalRead = (int)atoi(row->GetField(10)); |
932 |
{ |
enum_PKT_Saved = (int)atoi(row->GetField(11)); |
933 |
oss<<"Saved information regarding file: "<<filename<<" in table "<<Table_ROOT_Good<< " id= "<<my_id; |
enome_input = (TString)row->GetField(12); |
934 |
msg = oss.str(); |
e_time_is_estimated = (bool)atoi(row->GetField(13)); |
935 |
mainLogUtil->logInfo(msg); |
}; |
936 |
|
delete result; |
937 |
if(tryMerge){ |
|
938 |
merge_ROOTfiles(); |
setReal_TimeRECOVERY( |
939 |
} |
real_time_init, |
940 |
} |
real_time_last, |
941 |
else |
eobt_in, |
942 |
{ |
eobt_fin |
943 |
oss<<"Problem storing information in DB regarding file: "<<filename; |
); |
944 |
msg = oss.str(); |
// |
945 |
mainLogUtil->logError(msg); |
|
946 |
} |
if (saveROOT_DB( |
947 |
|
Table_ROOT_Good, |
948 |
if(!single_connection){ |
efolder_name.Data(), |
949 |
CloseDBConnection(); |
efile_name.Data(), |
950 |
} |
epkt_number_in, |
951 |
|
epkt_number_fin, eobt_in, eobt_fin, obt_time_sync, last_time_sync_info, |
952 |
|
real_time_init, real_time_last, emboot_num, etime_offset, ebad_pkt, ebad_pkt_read, ebad_pkt_CalRead, |
953 |
|
enum_PKT_Saved, enome_input.Data(), e_time_is_estimated) == true) { |
954 |
|
oss.str() = ""; |
955 |
|
oss << "\nTAG(tassa): RECOVERED!!!! Saved information regarding file: " << efile_name << " in table " << Table_ROOT_Good << " id= " << my_id; |
956 |
|
msg = oss.str(); |
957 |
|
mainLogUtil->logInfo(msg); |
958 |
|
/*merging we use global variable. we haveto set with current value*/ |
959 |
|
|
960 |
|
strcpy(outDir,efolder_name.Data() ); |
961 |
|
// outDir=efolder_name.Data(); |
962 |
|
strcpy(filename,efile_name.Data() ); |
963 |
|
// filename=efile_name.Data(); |
964 |
|
pkt_number_init=epkt_number_in; |
965 |
|
pkt_number_last=epkt_number_fin; |
966 |
|
obt_init=eobt_in; |
967 |
|
obt_last=eobt_fin; |
968 |
|
boot_number=emboot_num; |
969 |
|
timeOffset=etime_offset; |
970 |
|
bad_pkt=ebad_pkt; |
971 |
|
bad_pkt_EventReader=ebad_pkt_read; |
972 |
|
bad_pkt_CalibReader=ebad_pkt_CalRead; |
973 |
|
numPKTSaved=enum_PKT_Saved; |
974 |
|
strcpy(fni,enome_input.Data() ); |
975 |
|
// fni=enome_input.Data(); |
976 |
|
time_is_estimated=e_time_is_estimated; |
977 |
|
|
978 |
|
if (tryMerge) { |
979 |
|
merge_ROOTfiles(); |
980 |
|
} |
981 |
|
|
982 |
|
TString qu2 = Form("update ROOT_TABLE_BAD set ON_DISK='MVD' where ID_N=%i;",eid); |
983 |
|
sqlServer->Query(qu2.Data()); |
984 |
|
|
985 |
|
|
986 |
|
} |
987 |
|
else { |
988 |
|
oss.str() = ""; |
989 |
|
oss << "Problem storing information in DB regarding file: " << filename; |
990 |
|
msg = oss.str(); |
991 |
|
mainLogUtil->logError(msg); |
992 |
|
} |
993 |
|
|
994 |
|
|
995 |
|
}; |
996 |
|
ez++; |
997 |
|
} |
998 |
|
// |
999 |
|
idtorecover->Reset(); |
1000 |
|
delete idtorecover; |
1001 |
|
idtorecover = new TArrayI(100); |
1002 |
|
arsize = 0; |
1003 |
|
// delete app; |
1004 |
|
}; |
1005 |
|
}; |
1006 |
|
|
1007 |
|
CleanDisk(); |
1008 |
|
if (!single_connection) { |
1009 |
|
CloseDBConnection(); |
1010 |
|
} |
1011 |
|
|
1012 |
}//pRun |
}//pRun |
1013 |
} |
} |
1014 |
|
|
1015 |
|
|
1016 |
|
void PacketUser::CleanDisk(){ |
1017 |
|
if ( !candelete ) return; |
1018 |
|
// |
1019 |
|
// delete small files present in root_table_bad from disk: |
1020 |
|
// |
1021 |
|
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); |
1022 |
|
TSQLResult *result = sqlServer->Query(qu.Data()); |
1023 |
|
TSQLRow *row = result->Next(); |
1024 |
|
while ( row ){ |
1025 |
|
TString tbdel = (TString)gSystem->ExpandPathName(row->GetField(0))+"/"+ (TString)row->GetField(1); |
1026 |
|
stringstream err; |
1027 |
|
string msg; |
1028 |
|
err.str() = ""; |
1029 |
|
err << " Deleting file " << tbdel.Data() << " from disk! "; |
1030 |
|
msg = err.str(); |
1031 |
|
mainLogUtil->logInfo(msg); |
1032 |
|
gSystem->Unlink(tbdel.Data()); |
1033 |
|
// printf("ciccio %s \n",tbdel.Data()); |
1034 |
|
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); |
1035 |
|
// printf("pluto %s \n",q2u.Data()); |
1036 |
|
sqlServer->Query(q2u.Data()); |
1037 |
|
// printf("paperoga \n"); |
1038 |
|
row=result->Next(); |
1039 |
|
// |
1040 |
|
}; |
1041 |
|
|
1042 |
|
} |
1043 |
|
|
1044 |
//save in Table_ROOT_Good or in Table_ROOT_Bad |
//save in Table_ROOT_Good or in Table_ROOT_Bad |
1045 |
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, |
1046 |
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, |
1047 |
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, |
1048 |
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, |
1049 |
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) { |
1050 |
unsigned long int mboot_num, |
//TODO: forse far ritornare ID della cosa appena inserita se e' andatato tutto ok invece che true false? |
1051 |
unsigned long int time_offset, |
|
1052 |
int bad_pkt, int bad_pkt_read, int bad_pkt_CalRead, int num_PKT_Saved, |
// EM: check is file has already been inserted, if so, update the informations (also in ROOT_TABLE_MERGING if processing ROOT_TABLE) instead of adding entries |
1053 |
char* nome_input, bool _time_is_estimated){ |
stringstream oss1; |
1054 |
//TODO: forse far ritornare ID della cosa appena inserita se e' andatato tutto ok invece che true false? |
oss1.str() = ""; |
1055 |
stringstream oss; |
string msg1; |
1056 |
oss.str(""); |
stringstream ass; |
1057 |
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)" |
ass.str(""); |
1058 |
<< " VALUES ('"<<0<< "','" <<folder_name<<"','" <<file_name<< "','" << pkt_number_in <<"','"<< pkt_number_fin << "','"<< obt_in <<"','"<< obt_fin<< "','" |
ass << "SELECT 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 FROM " << table_name << " WHERE FILE_NAME='"<< file_name <<"';"; |
1059 |
<< oT_sync << "','" << lT_sync_info << "','" |
TSQLResult* ares = NULL; |
1060 |
<< mtime_init << "','" << mtime_last << "','" |
ares = sqlServer->Query(ass.str().c_str()); |
1061 |
<< mboot_num << "','" |
if (!ares) { |
1062 |
<< time_offset << "','" |
oss1 << "DBError UNABLE to: " << ass.str().c_str() << endl; |
1063 |
<< bad_pkt <<"','" << bad_pkt_read <<"','"<< bad_pkt_CalRead <<"','"<< num_PKT_Saved<<"','" |
msg1 = oss1.str(); |
1064 |
<< nome_input <<"'," |
mainLogUtil->logError(msg1); |
1065 |
<<"NULL,"<<_time_is_estimated<< |
return false; |
1066 |
")"; |
} |
1067 |
string msg = oss.str(); |
TSQLRow *arow = ares->Next(); |
1068 |
mainLogUtil->logAll(msg); |
if ( arow ){ |
1069 |
|
TString bla=file_name; |
1070 |
stringstream oss1; |
TString *blabla=new TString(file_name); |
1071 |
oss1.str()=""; |
blabla->Remove(15); |
1072 |
string msg1; |
stringstream oss; |
1073 |
string query; |
oss.str(""); |
1074 |
|
// oss << "UPDATE " << table_name |
1075 |
TSQLResult* res=NULL; |
// << " set FOLDER_NAME='" << folder_name << "', PKT_NUMBER_INIT='" << pkt_number_in << "',PKT_NUMBER_FINAL='" << pkt_number_fin << "',PKT_OBT_INIT='" << obt_in << "',PKT_OBT_FINAL='" << obt_fin |
1076 |
|
// << "',OBT_TIME_SYNC='" << oT_sync << "',LAST_TIME_SYNC_INFO='" << lT_sync_info << "',REAL_TIME_INIT='"<< mtime_init << "',REAL_TIME_LAST='" << mtime_last << "',BOOT_NUMBER='" << mboot_num |
1077 |
query=oss.str(); |
// << "',TIME_OFFSET='" << time_offset << "',BAD_PKT='" << bad_pkt << "',BAD_PKT_READ='"<< bad_pkt_read << "',BAD_PKT_CALREAD='" << bad_pkt_CalRead << "',NUM_PKT_SAVED='" << num_PKT_Saved |
1078 |
msg1="SaveROOT_DB query: "; |
// << "',INPUT_NAME='" << nome_input << "',INSERT_TIME=NULL,TIME_IS_ESTIMATED='"<< _time_is_estimated << "',INSERTED_BY='" << tag_value << "',ON_DISK='YES' where FILE_NAME='"<<file_name<<"';"; |
1079 |
msg1 += query; |
oss << " DELETE FROM ROOT_TABLE_BAD WHERE FILE_NAME LIKE '"<<blabla->Data()<<"%';"; |
1080 |
mainLogUtil->logInfo(msg1); |
string msg = oss.str(); |
1081 |
|
mainLogUtil->logAll(msg); |
1082 |
res= sqlServer->Query(query.c_str()); |
string query; |
1083 |
if(!res) |
|
1084 |
{ |
TSQLResult* res = NULL; |
1085 |
oss1<<"DBError UNABLE to: "<<oss.str().c_str()<<endl; |
|
1086 |
msg1=oss1.str(); |
query = oss.str(); |
1087 |
mainLogUtil->logError(msg1); |
msg1 = "DeleteROOT_DB_BAD query: "; |
1088 |
return false; |
msg1 += query; |
1089 |
|
mainLogUtil->logInfo(msg1); |
1090 |
|
|
1091 |
|
res = sqlServer->Query(query.c_str()); |
1092 |
|
if (!res) { |
1093 |
|
oss1 << "DBError UNABLE to: " << oss.str().c_str() << endl; |
1094 |
|
msg1 = oss1.str(); |
1095 |
|
mainLogUtil->logError(msg1); |
1096 |
|
return false; |
1097 |
|
} |
1098 |
|
|
1099 |
|
stringstream iss; |
1100 |
|
iss.str(""); |
1101 |
|
iss << "select ROOT_TABLE_MERGING.ID_N from ROOT_TABLE_MERGING left join ROOT_TABLE on ROOT_TABLE_MERGING.ROOT_ID_N=ROOT_TABLE.ID_N where ROOT_TABLE.FILE_NAME like '"<<blabla->Data()<<"%';"; |
1102 |
|
string msg2; |
1103 |
|
string query2; |
1104 |
|
TSQLResult* res2 = NULL; |
1105 |
|
query2 = iss.str(); |
1106 |
|
msg2 = "SaveROOT_DB query: "; |
1107 |
|
msg2 += query; |
1108 |
|
mainLogUtil->logInfo(msg2); |
1109 |
|
res2 = sqlServer->Query(query2.c_str()); |
1110 |
|
if (!res2) { |
1111 |
|
oss1 << "DBError UNABLE to: " << iss.str().c_str() << endl; |
1112 |
|
msg1 = oss1.str(); |
1113 |
|
mainLogUtil->logError(msg1); |
1114 |
|
return false; |
1115 |
} |
} |
1116 |
|
TSQLRow *row2 = res2->Next(); |
1117 |
|
while ( row2 ){ |
1118 |
|
TString qq=Form("DELETE FROM ROOT_TABLE_MERGING where ID_N=%s;",row2->GetField(0)); |
1119 |
|
TSQLResult* res2b = NULL; |
1120 |
|
res2b = sqlServer->Query(qq.Data()); |
1121 |
|
delete res2b; |
1122 |
|
row2=res2->Next(); |
1123 |
|
}; |
1124 |
|
|
|
//the ID of the current ROOT file in table Table_ROOT_Good |
|
|
my_id = select_maxIDN_DB(table_name); |
|
|
if(!boot_number){ |
|
|
if(id_to_recover_index<1000) |
|
|
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; |
|
|
} |
|
1125 |
|
|
1126 |
|
|
1127 |
void PacketUser::recover_boot_number(){ |
oss.str(""); |
1128 |
|
oss << " DELETE FROM ROOT_TABLE WHERE FILE_NAME LIKE '"<<blabla->Data()<<"%';"; |
1129 |
|
string ms = oss.str(); |
1130 |
|
mainLogUtil->logAll(ms); |
1131 |
|
string quer; |
1132 |
|
TSQLResult* re = NULL; |
1133 |
|
quer = oss.str(); |
1134 |
|
msg1 = "DeleteROOT_DB query: "; |
1135 |
|
msg1 += quer; |
1136 |
|
mainLogUtil->logInfo(msg1); |
1137 |
|
|
1138 |
|
re = sqlServer->Query(quer.c_str()); |
1139 |
|
if (!re) { |
1140 |
|
oss1 << "DBError UNABLE to: " << oss.str().c_str() << endl; |
1141 |
|
msg1 = oss1.str(); |
1142 |
|
mainLogUtil->logError(msg1); |
1143 |
|
return false; |
1144 |
|
} |
1145 |
|
|
1146 |
|
delete blabla; |
1147 |
|
|
1148 |
|
} |
1149 |
|
|
1150 |
|
// } else { |
1151 |
|
if ( true ){ |
1152 |
|
stringstream oss; |
1153 |
|
oss.str(""); |
1154 |
|
oss << "INSERT INTO " << table_name |
1155 |
|
<< " (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)" |
1156 |
|
<< " VALUES ('" << 0 << "','" << folder_name << "','" << file_name << "','" << pkt_number_in << "','" |
1157 |
|
<< pkt_number_fin << "','" << obt_in << "','" << obt_fin << "','" << oT_sync << "','" << lT_sync_info << "','" |
1158 |
|
<< mtime_init << "','" << mtime_last << "','" << mboot_num << "','" << time_offset << "','" << bad_pkt << "','" |
1159 |
|
<< bad_pkt_read << "','" << bad_pkt_CalRead << "','" << num_PKT_Saved << "','" << nome_input << "'," << "NULL," |
1160 |
|
<< _time_is_estimated << ",'" << tag_value << "'" << ");"; |
1161 |
|
string msg = oss.str(); |
1162 |
|
mainLogUtil->logAll(msg); |
1163 |
|
|
1164 |
|
string query; |
1165 |
|
|
1166 |
|
TSQLResult* res = NULL; |
1167 |
|
|
1168 |
|
query = oss.str(); |
1169 |
|
msg1 = "SaveROOT_DB query: "; |
1170 |
|
msg1 += query; |
1171 |
|
mainLogUtil->logInfo(msg1); |
1172 |
|
|
1173 |
|
res = sqlServer->Query(query.c_str()); |
1174 |
|
if (!res) { |
1175 |
|
oss1 << "DBError UNABLE to: " << oss.str().c_str() << endl; |
1176 |
|
msg1 = oss1.str(); |
1177 |
|
mainLogUtil->logError(msg1); |
1178 |
|
return false; |
1179 |
|
} else { |
1180 |
|
delete res; |
1181 |
|
res = NULL; |
1182 |
|
} |
1183 |
|
} |
1184 |
|
|
1185 |
|
if(!strcmp(table_name,Table_ROOT_Good)) { |
1186 |
|
//the ID of the current ROOT file in table Table_ROOT_Good |
1187 |
|
my_id = select_maxIDN_DB(table_name,file_name); |
1188 |
|
if (!boot_number) { |
1189 |
|
if (id_to_recover_index < 1000) |
1190 |
|
id_to_recover[id_to_recover_index++] = my_id; |
1191 |
|
} |
1192 |
|
else if (boot_number && id_to_recover_index && !is_new_route) { |
1193 |
|
recover_boot_number(); |
1194 |
|
} |
1195 |
|
// cout<<"DBG: my_id = "<<my_id<<endl; |
1196 |
|
} |
1197 |
|
if (ares) { |
1198 |
|
delete ares; |
1199 |
|
ares = NULL; |
1200 |
|
} |
1201 |
|
return true; |
1202 |
|
} |
1203 |
|
|
1204 |
|
void PacketUser::recover_boot_number() { |
1205 |
string msg1; |
string msg1; |
1206 |
stringstream oss1; |
stringstream oss1; |
1207 |
stringstream oss; |
stringstream oss; |
1208 |
oss.str(""); |
oss.str(""); |
1209 |
string query=""; |
string query = ""; |
1210 |
TSQLResult* res=NULL; |
TSQLResult* res = NULL; |
1211 |
if(!boot_number || !id_to_recover_index) |
if (!boot_number || !id_to_recover_index) |
1212 |
return; |
return; |
1213 |
|
|
1214 |
for (int i = 0; i<id_to_recover_index;i++){ |
for (int i = 0; i < id_to_recover_index; i++) { |
1215 |
oss << "UPDATE "<< Table_ROOT_Good << " SET BOOT_NUMBER=" << boot_number << " WHERE ID_N=" << id_to_recover[i]; |
oss.str(""); |
1216 |
query = oss.str(); |
oss << "UPDATE " << Table_ROOT_Good << " SET BOOT_NUMBER=" << boot_number << " WHERE ID_N=" << id_to_recover[i] |
1217 |
res= sqlServer->Query(query.c_str()); |
<< ";"; |
1218 |
if(!res) |
query = oss.str(); |
1219 |
{ |
res = sqlServer->Query(query.c_str()); |
1220 |
oss1<<"DBError UNABLE to: "<<query.c_str()<<endl; |
if (!res) { |
1221 |
msg1=oss1.str(); |
oss1 << "DBError UNABLE to: " << query.c_str() << endl; |
1222 |
mainLogUtil->logError(msg1); |
msg1 = oss1.str(); |
1223 |
return ; |
mainLogUtil->logError(msg1); |
1224 |
} |
return; |
1225 |
|
} |
1226 |
} |
} |
1227 |
|
|
1228 |
for (int i = 0; i<id_to_recover_index;i++){ |
for (int i = 0; i < id_to_recover_index; i++) { |
1229 |
oss << "UPDATE " << Table_ROOT_Merging << " SET BOOT_NUMBER=" << boot_number << " WHERE ROOT_ID_N=" << id_to_recover[i]; |
oss.str(""); |
1230 |
query=oss.str(); |
oss << "UPDATE " << Table_ROOT_Merging << " SET BOOT_NUMBER=" << boot_number << " WHERE ROOT_ID_N=" |
1231 |
res= sqlServer->Query(query.c_str()); |
<< id_to_recover[i] << ";"; |
1232 |
if(!res) |
query = oss.str(); |
1233 |
{ |
res = sqlServer->Query(query.c_str()); |
1234 |
oss1<<"DBError UNABLE to: "<<query.c_str()<<endl; |
if (!res) { |
1235 |
msg1=oss1.str(); |
oss1 << "DBError UNABLE to: " << query.c_str() << endl; |
1236 |
mainLogUtil->logError(msg1); |
msg1 = oss1.str(); |
1237 |
return ; |
mainLogUtil->logError(msg1); |
1238 |
} |
return; |
1239 |
|
} |
1240 |
} |
} |
1241 |
|
|
1242 |
id_to_recover_index=0; |
id_to_recover_index = 0; |
1243 |
} |
} |
1244 |
|
|
|
|
|
|
|
|
1245 |
/**********************************************************************************************/ |
/**********************************************************************************************/ |
1246 |
/*###########################################################################################################*/ |
/*###########################################################################################################*/ |
1247 |
/********************************** MERGING *************************************************/ |
/********************************** MERGING *************************************************/ |
1250 |
// 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 |
1251 |
/**********************************************************************************************/ |
/**********************************************************************************************/ |
1252 |
//try to merge current ROOT file with files in DB |
//try to merge current ROOT file with files in DB |
1253 |
bool PacketUser::merge_ROOTfiles() |
bool PacketUser::merge_ROOTfiles() { |
1254 |
{ |
stringstream log; |
1255 |
stringstream log; |
log.str(""); |
1256 |
log.str(""); |
string slog; |
|
string slog; |
|
1257 |
|
|
1258 |
mainLogUtil->logInfo("Trying merging ROOT files"); |
mainLogUtil->logInfo("Trying merging ROOT files"); |
1259 |
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; |
|
1260 |
|
|
1261 |
|
TSQLResult* res = NULL; |
1262 |
|
TSQLRow* row = NULL; |
1263 |
|
//numero di ROOT files trovati sul DB che hanno relaz di tipo dato |
1264 |
|
unsigned int num_rows = 0; |
1265 |
|
|
1266 |
|
//Record su DB: |
1267 |
|
unsigned int idN = 0; |
1268 |
|
unsigned int root_id_db = 0; |
1269 |
|
unsigned long int pkt_num_in_db = 0; |
1270 |
|
unsigned long int pkt_num_fin_db = 0; |
1271 |
|
unsigned long int pkt_obt_in_db = 0; |
1272 |
|
unsigned long int pkt_obt_fin_db = 0; |
1273 |
|
unsigned long int time_in_db = 0; |
1274 |
|
unsigned long int time_fin_db = 0; |
1275 |
|
unsigned int boot_num_db = 0; |
1276 |
|
double perc = 0; |
1277 |
|
|
1278 |
//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 |
1279 |
//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 |
1280 |
for(int relaz=AFTER; relaz<=BIGGER; relaz++) |
for (int relaz = AFTER; relaz <= BIGGER; relaz++) { |
1281 |
{ |
//marco_new: esci se sono arrivato a zero |
1282 |
//marco_new: esci se sono arrivato a zero |
if (real_time_last == real_time_init) { |
1283 |
if(real_time_last==real_time_init) |
log.str(""); |
1284 |
{ |
log << "Current File Lenght=0; real_time_last=real_time_init= " << real_time_last; |
1285 |
log.str(""); |
slog = log.str(); |
1286 |
log<<"Current File Lenght=0; real_time_last=real_time_init= "<<real_time_last; |
mainLogUtil->logAll(slog); |
1287 |
slog=log.str(); |
mainLogUtil->logInfo("Finish merging ROOT files"); |
1288 |
mainLogUtil->logAll(slog); |
if (res) { |
1289 |
mainLogUtil->logInfo("Finish merging ROOT files"); |
delete res; |
1290 |
if(res){delete res; res = NULL;} |
res = NULL; |
1291 |
if(row){delete row; row = NULL;} |
} |
1292 |
return true; |
if (row) { |
1293 |
} |
delete row; |
1294 |
|
row = NULL; |
1295 |
num_rows=0; |
} |
1296 |
res = Select_merging(Table_ROOT_Merging, real_time_init, real_time_last, (type_Rel_ROOT)relaz); |
return true; |
1297 |
|
} |
1298 |
if (!res) |
|
1299 |
{ |
num_rows = 0; |
1300 |
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); |
1301 |
return false; |
|
1302 |
} |
if (!res) { |
1303 |
|
mainLogUtil->logError("DB_ERROR: Unable to find ROOT files to be merged RES=null"); |
1304 |
num_rows=res->GetRowCount(); |
return false; |
1305 |
log.str(""); |
} |
1306 |
log<<"Found "<<num_rows<<" ROOT file in DB with relation of kind = "<<relaz; |
|
1307 |
slog=log.str(); |
num_rows = res->GetRowCount(); |
1308 |
mainLogUtil->logAll(slog); |
log.str(""); |
1309 |
|
log << "Found " << num_rows << " ROOT file in DB with relation of kind = " << relaz; |
1310 |
if(num_rows>0) |
slog = log.str(); |
1311 |
{ |
mainLogUtil->logAll(slog); |
1312 |
for(unsigned int i=0; i<num_rows; i++) |
|
1313 |
{ |
if (num_rows > 0) { |
1314 |
row=res->Next(); |
for (unsigned int i = 0; i < num_rows; i++) { |
1315 |
if (!row) |
row = res->Next(); |
1316 |
{ |
if (!row) { |
1317 |
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"); |
1318 |
if(res){delete res; res = NULL;} |
if (res) { |
1319 |
return false; |
delete res; |
1320 |
} |
res = NULL; |
1321 |
|
} |
1322 |
//Leggi Record dal DB: |
return false; |
1323 |
idN=atoll(row->GetField(0)); |
} |
1324 |
root_id_db=atoll(row->GetField(1)); |
|
1325 |
pkt_num_in_db=atoll(row->GetField(2)); |
//Leggi Record dal DB: |
1326 |
pkt_num_fin_db=atoll(row->GetField(3)); |
idN = atoll(row->GetField(0)); |
1327 |
pkt_obt_in_db=atoll(row->GetField(4)); |
root_id_db = atoll(row->GetField(1)); |
1328 |
pkt_obt_fin_db=atoll(row->GetField(5)); |
pkt_num_in_db = atoll(row->GetField(2)); |
1329 |
time_in_db=atoll(row->GetField(6)); |
pkt_num_fin_db = atoll(row->GetField(3)); |
1330 |
time_fin_db=atoll(row->GetField(7)); |
pkt_obt_in_db = atoll(row->GetField(4)); |
1331 |
boot_num_db=atoll(row->GetField(8)); |
pkt_obt_fin_db = atoll(row->GetField(5)); |
1332 |
perc=atof(row->GetField(9)); |
time_in_db = atoll(row->GetField(6)); |
1333 |
|
time_fin_db = atoll(row->GetField(7)); |
1334 |
log.str(""); |
boot_num_db = atoll(row->GetField(8)); |
1335 |
log<<"*** ROOT file found in DB has idN= "<<idN<<" root_id_db= "<<root_id_db; |
perc = atof(row->GetField(9)); |
1336 |
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; |
|
1337 |
log<<" time_in_db= "<<time_in_db<<" time_fin_db= "<<time_fin_db<<" boot_num_db= "<<boot_num_db<<" perc= "<<perc<<" ***"; |
log.str(""); |
1338 |
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; |
1339 |
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= " |
1340 |
slog=log.str(); |
<< pkt_obt_in_db << " pkt_obt_fin_db= " << pkt_obt_fin_db; |
1341 |
mainLogUtil->logAll(slog); |
log << " time_in_db= " << time_in_db << " time_fin_db= " << time_fin_db << " boot_num_db= " << boot_num_db |
1342 |
if(perc>percentage) |
<< " perc= " << perc << " ***"; |
1343 |
{ |
log << "\n*** Current ROOT file has pkt_number_init= " << pkt_number_init << " obt_init= " << obt_init |
1344 |
mainLogUtil->logInfo("Current ROOT file is better than the one in DB"); |
<< " real_time_init= " << real_time_init; |
1345 |
//modifica DB |
log << " pkt_number_last= " << pkt_number_last << " obt_last= " << obt_last << " real_time_last= " |
1346 |
updateMergeROOT_DB(Table_ROOT_Merging, |
<< real_time_last << " ***"; |
1347 |
root_id_db, |
slog = log.str(); |
1348 |
pkt_num_in_db, pkt_num_fin_db, |
mainLogUtil->logAll(slog); |
1349 |
pkt_obt_in_db, pkt_obt_fin_db, |
if (perc > percentage) { |
1350 |
time_in_db, time_fin_db, |
mainLogUtil->logInfo("Current ROOT file is better than the one in DB"); |
1351 |
boot_num_db, |
//modifica DB |
1352 |
perc, |
updateMergeROOT_DB(Table_ROOT_Merging, root_id_db, pkt_num_in_db, pkt_num_fin_db, pkt_obt_in_db, |
1353 |
idN,(type_Rel_ROOT)relaz); |
pkt_obt_fin_db, time_in_db, time_fin_db, boot_num_db, perc, idN, (type_Rel_ROOT) relaz); |
1354 |
} |
} |
1355 |
else |
else { |
1356 |
{ |
mainLogUtil->logInfo("Found ROOT file in DB is better than current ROOT file"); |
1357 |
mainLogUtil->logInfo("Found ROOT file in DB is better than current ROOT file"); |
if (relaz == AFTER) { |
1358 |
if(relaz == AFTER) |
mainLogUtil->logInfo("Relaz:AFTER = Changing Init values of the Current ROOT file"); |
1359 |
{ |
pkt_number_init = (pkt_num_fin_db + 1); |
1360 |
mainLogUtil->logInfo("Relaz:AFTER = Changing Init values of the Current ROOT file"); |
obt_init = pkt_obt_fin_db; |
1361 |
pkt_number_init = (pkt_num_fin_db+1); |
real_time_init = time_fin_db; |
1362 |
obt_init = pkt_obt_fin_db; |
log.str(""); |
1363 |
real_time_init = time_fin_db; |
log << "\n*** Current ROOT file becomes: pkt_number_init= " << pkt_number_init << " obt_init= " |
1364 |
log.str(""); |
<< obt_init << " real_time_init= " << real_time_init; |
1365 |
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= " |
1366 |
log<<" pkt_number_last= "<<pkt_number_last<<" obt_last= "<<obt_last<<" real_time_last= "<<real_time_last<<" ***"; |
<< real_time_last << " ***"; |
1367 |
slog=log.str(); |
slog = log.str(); |
1368 |
mainLogUtil->logAll(slog); |
mainLogUtil->logAll(slog); |
1369 |
} |
} |
1370 |
else if(relaz == BEFORE) |
else if (relaz == BEFORE) { |
1371 |
{ |
mainLogUtil->logInfo("Relaz:BEFORE = Changing Last values of the Current ROOT file"); |
1372 |
mainLogUtil->logInfo("Relaz:BEFORE = Changing Last values of the Current ROOT file"); |
pkt_number_last = (pkt_num_in_db - 1); |
1373 |
pkt_number_last = (pkt_num_in_db-1); |
obt_last = pkt_obt_in_db; |
1374 |
obt_last = pkt_obt_in_db; |
real_time_last = time_in_db; |
1375 |
real_time_last = time_in_db; |
|
1376 |
|
log.str(""); |
1377 |
log.str(""); |
log << "\n*** Current ROOT file becomes: pkt_number_init= " << pkt_number_init << " obt_init= " |
1378 |
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; |
1379 |
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= " |
1380 |
slog=log.str(); |
<< real_time_last << " ***"; |
1381 |
mainLogUtil->logAll(slog); |
slog = log.str(); |
1382 |
} |
mainLogUtil->logAll(slog); |
1383 |
else if(relaz == SMALLER) |
} |
1384 |
{ |
else if (relaz == SMALLER) { |
1385 |
//non devo proprio salvarlo ed esco ... |
//non devo proprio salvarlo ed esco ... |
1386 |
mainLogUtil->logInfo("Relaz:SMALLER = Nothing to save"); |
mainLogUtil->logInfo("Relaz:SMALLER = Nothing to save"); |
1387 |
mainLogUtil->logInfo("\nFinish merging ROOT files"); |
mainLogUtil->logInfo("\nFinish merging ROOT files"); |
1388 |
if(res){delete res; res = NULL;} |
if (res) { |
1389 |
if(row){delete row; row = NULL;} |
delete res; |
1390 |
return true; |
res = NULL; |
1391 |
} |
} |
1392 |
else if(relaz == BIGGER)//spezzettamento |
if (row) { |
1393 |
{ |
delete row; |
1394 |
mainLogUtil->logInfo("Relaz:BIGGER = (1st part) Saving the first part of the Current ROOT file"); |
row = NULL; |
1395 |
saveMergeROOT_DB(Table_ROOT_Merging, my_id, |
} |
1396 |
pkt_number_init, (pkt_num_in_db-1), |
return true; |
1397 |
obt_init, pkt_obt_in_db, |
} |
1398 |
real_time_init, time_in_db, |
else if (relaz == BIGGER)//spezzettamento |
1399 |
boot_number, |
{ |
1400 |
percentage); |
mainLogUtil->logInfo("Relaz:BIGGER = (1st part) Saving the first part of the Current ROOT file"); |
1401 |
|
saveMergeROOT_DB(Table_ROOT_Merging, my_id, pkt_number_init, (pkt_num_in_db - 1), obt_init, pkt_obt_in_db, |
1402 |
mainLogUtil->logInfo("Relaz:BIGGER = (2nd part)Changing Init values of the Current ROOT file"); |
real_time_init, time_in_db, boot_number, percentage); |
1403 |
pkt_number_init = (pkt_num_fin_db+1); |
|
1404 |
obt_init= pkt_obt_fin_db; |
mainLogUtil->logInfo("Relaz:BIGGER = (2nd part)Changing Init values of the Current ROOT file"); |
1405 |
real_time_init= time_fin_db; |
pkt_number_init = (pkt_num_fin_db + 1); |
1406 |
|
obt_init = pkt_obt_fin_db; |
1407 |
log.str(""); |
real_time_init = time_fin_db; |
1408 |
log<<"\n*** Current ROOT file becomes: pkt_number_init= "<<pkt_number_init<<" obt_init= "<<obt_init<<" real_time_init= "<<real_time_init; |
|
1409 |
log<<" pkt_number_last= "<<pkt_number_last<<" obt_last= "<<obt_last<<" real_time_last= "<<real_time_last<<" ***"; |
log.str(""); |
1410 |
slog=log.str(); |
log << "\n*** Current ROOT file becomes: pkt_number_init= " << pkt_number_init << " obt_init= " |
1411 |
mainLogUtil->logAll(slog); |
<< obt_init << " real_time_init= " << real_time_init; |
1412 |
}//if relaz |
log << " pkt_number_last= " << pkt_number_last << " obt_last= " << obt_last << " real_time_last= " |
1413 |
}//if perc |
<< real_time_last << " ***"; |
1414 |
}//for num_rows |
slog = log.str(); |
1415 |
}//if num_rows |
mainLogUtil->logAll(slog); |
1416 |
|
}//if relaz |
1417 |
|
}//if perc |
1418 |
|
}//for num_rows |
1419 |
|
}//if num_rows |
1420 |
|
|
1421 |
|
if (res) { |
1422 |
|
delete res; |
1423 |
|
res = NULL; |
1424 |
|
} |
1425 |
|
if (row) { |
1426 |
|
delete row; |
1427 |
|
row = NULL; |
1428 |
|
} |
1429 |
|
|
1430 |
|
}//for relaz |
1431 |
|
|
1432 |
|
mainLogUtil->logInfo("Saving Current ROOT file"); |
1433 |
|
saveMergeROOT_DB(Table_ROOT_Merging, my_id, pkt_number_init, pkt_number_last, obt_init, obt_last, real_time_init, |
1434 |
|
real_time_last, boot_number, percentage); |
1435 |
|
|
1436 |
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"); |
|
1437 |
return true; |
return true; |
1438 |
|
|
1439 |
} |
} |
1440 |
|
|
1441 |
//unsigned int root_id, percentage non le devo modificare |
//unsigned int root_id, percentage non le devo modificare |
1442 |
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, |
1443 |
unsigned int root_id, |
unsigned long int pkt_number_fin, unsigned long int obt_in, unsigned long int obt_fin, |
1444 |
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, |
1445 |
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(""); |
|
1446 |
|
|
1447 |
if(type_rel == AFTER){ |
stringstream oss; |
1448 |
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<<";"; |
|
|
mainLogUtil->logInfo("Record deleted from merging table"); |
|
|
} |
|
|
else |
|
|
return false; |
|
1449 |
|
|
1450 |
string msg = oss.str(); |
if (type_rel == AFTER) { |
1451 |
mainLogUtil->logInfo(msg); |
mainLogUtil->logInfo("Relaz:AFTER = Updating Last values of the DB ROOT file"); |
1452 |
|
//marco_new:tolti tutti gli apici che qui non devono essere |
1453 |
stringstream oss1; |
|
1454 |
oss1.str()=""; |
int good = 1; |
1455 |
string msg1; |
if ( pkt_number_in >= (pkt_number_init - 1) && abs((int)(pkt_number_in-(pkt_number_init-1)))<10 ) good = 0; |
1456 |
|
|
1457 |
TSQLResult* res=NULL; |
oss << "UPDATE " << table_name << " SET PKT_NUMBER_FINAL =" << (pkt_number_init - 1) << ", PKT_OBT_FINAL =" |
1458 |
res= sqlServer->Query(oss.str().c_str()); |
<< obt_init << ", REAL_TIME_LAST =" << real_time_init << ", GOOD="<< good << " WHERE ID_N =" << ID_record << ";"; |
1459 |
if(!res) |
|
1460 |
{ |
} |
1461 |
oss1<<"DBError UNABLE to: "<<oss.str().c_str()<<endl; |
else if (type_rel == BEFORE) { |
1462 |
msg1=oss1.str(); |
mainLogUtil->logInfo("Relaz:BEFORE = Updating Init values of the DB ROOT file"); |
1463 |
mainLogUtil->logError(msg1); |
|
1464 |
return false; |
int good = 1; |
1465 |
} |
if ( (pkt_number_last+1) >= pkt_number_fin && abs((int)((pkt_number_last+1)-pkt_number_fin))<10 ) good = 0; |
1466 |
if(res){delete res; res = NULL;} |
|
1467 |
return true; |
oss << "UPDATE " << table_name << " SET PKT_NUMBER_INIT =" << (pkt_number_last + 1) << ", PKT_OBT_INIT =" |
1468 |
|
<< obt_last << ", REAL_TIME_INIT =" << real_time_last << ", GOOD="<< good << " WHERE ID_N =" << ID_record << ";"; |
1469 |
|
} |
1470 |
|
else if (type_rel == SMALLER) { |
1471 |
|
//spezzettamentento |
1472 |
|
mainLogUtil->logInfo("Relaz:SMALLER = (1st part) Updating Last values of the DB ROOT file"); |
1473 |
|
|
1474 |
|
int good = 1; |
1475 |
|
if ( pkt_number_in >= (pkt_number_init - 1) && abs((int)(pkt_number_in-(pkt_number_init-1)))<10 ) good = 0; |
1476 |
|
|
1477 |
|
oss << "UPDATE " << table_name << " SET PKT_NUMBER_FINAL=" << (pkt_number_init - 1) << ", PKT_OBT_FINAL =" |
1478 |
|
<< obt_init << ", REAL_TIME_LAST =" << real_time_init << ", GOOD="<< good << " WHERE ID_N =" << ID_record << ";"; |
1479 |
|
|
1480 |
|
mainLogUtil->logInfo("Relaz:SMALLER = (2nd part) Saving the second part of the DB ROOT file"); |
1481 |
|
|
1482 |
|
saveMergeROOT_DB(table_name, root_id, (pkt_number_last + 1), pkt_number_fin, obt_last, obt_fin, real_time_last, |
1483 |
|
mtime_last, mboot_num, bad_perc); |
1484 |
|
} |
1485 |
|
else if (type_rel == BIGGER) { |
1486 |
|
//marco_new: ok anche se coincidenti etc |
1487 |
|
// oss << "DELETE FROM "<< table_name <<" WHERE ID_N ="<< ID_record<<";"; // EMILIANO |
1488 |
|
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 |
1489 |
|
mainLogUtil->logInfo("Record deleted from merging table"); |
1490 |
|
} |
1491 |
|
else |
1492 |
|
return false; |
1493 |
|
|
1494 |
|
string msg = oss.str(); |
1495 |
|
mainLogUtil->logInfo(msg); |
1496 |
|
|
1497 |
|
stringstream oss1; |
1498 |
|
oss1.str() = ""; |
1499 |
|
string msg1; |
1500 |
|
|
1501 |
|
TSQLResult* res = NULL; |
1502 |
|
res = sqlServer->Query(oss.str().c_str()); |
1503 |
|
if (!res) { |
1504 |
|
oss1 << "DBError UNABLE to: " << oss.str().c_str() << endl; |
1505 |
|
msg1 = oss1.str(); |
1506 |
|
mainLogUtil->logError(msg1); |
1507 |
|
return false; |
1508 |
|
} |
1509 |
|
if (res) { |
1510 |
|
delete res; |
1511 |
|
res = NULL; |
1512 |
|
} |
1513 |
|
return true; |
1514 |
} |
} |
1515 |
|
|
1516 |
//cerca eventuali ROOT files in DB che possono venire mergiati |
//cerca eventuali ROOT files in DB che possono venire mergiati |
1517 |
//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 |
1518 |
//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 |
1519 |
//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 |
1520 |
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, |
1521 |
{ |
type_Rel_ROOT type_rel) { |
1522 |
TSQLResult* res=NULL; |
TSQLResult* res = NULL; |
1523 |
stringstream query; |
stringstream query; |
1524 |
query.str(""); |
query.str(""); |
1525 |
|
|
1526 |
if(type_rel == AFTER) |
if (type_rel == AFTER) |
1527 |
query<<"select * from "<<table_name<<" where REAL_TIME_LAST > "<< mtime_init <<" and REAL_TIME_LAST <= "<< mtime_last <<" and REAL_TIME_INIT < "<< mtime_init; |
query << "select * from " << table_name << " where GOOD=1 and REAL_TIME_LAST > " << mtime_init |
1528 |
else if(type_rel == BEFORE) |
<< " and REAL_TIME_LAST <= " << mtime_last << " and REAL_TIME_INIT < " << mtime_init; // EMI |
1529 |
query<<"select * from "<<table_name<<" where REAL_TIME_INIT >= "<< mtime_init <<" and REAL_TIME_INIT < "<< mtime_last <<" and REAL_TIME_LAST > "<< mtime_last; |
else if (type_rel == BEFORE) |
1530 |
else if(type_rel == SMALLER) |
query << "select * from " << table_name << " where GOOD=1 and REAL_TIME_INIT >= " << mtime_init |
1531 |
query<<"select * from "<<table_name<<" where REAL_TIME_INIT < "<< mtime_init <<" and REAL_TIME_LAST > "<< mtime_last; |
<< " and REAL_TIME_INIT < " << mtime_last << " and REAL_TIME_LAST > " << mtime_last; // EMI |
1532 |
else if(type_rel == BIGGER) |
else if (type_rel == SMALLER) |
1533 |
query<<"select * from "<<table_name<<" where REAL_TIME_INIT >= "<< mtime_init <<" and REAL_TIME_LAST <= "<< mtime_last; |
query << "select * from " << table_name << " where GOOD=1 and REAL_TIME_INIT < " << mtime_init |
1534 |
else |
<< " and REAL_TIME_LAST > " << mtime_last; // EMI |
1535 |
return 0; |
else if (type_rel == BIGGER) |
1536 |
|
query << "select * from " << table_name << " where GOOD=1 and REAL_TIME_INIT >= " << mtime_init |
1537 |
query<< " order by REAL_TIME_INIT ASC";//marco_new: inutile |
<< " and REAL_TIME_LAST <= " << mtime_last; // EMI |
1538 |
//se volessi mettere un filtro sulla qualita' |
else |
1539 |
// query<<" and NUM_PKT_SAVED - BAD_PKT_CALREAD - BAD_PKT_READ - BAD_PKT >= 2" ; |
return 0; |
1540 |
string msg = query.str(); |
|
1541 |
mainLogUtil->logAll(msg); |
query << " order by REAL_TIME_INIT ASC;";//marco_new: inutile |
1542 |
res= sqlServer->Query(query.str().c_str()); |
//se volessi mettere un filtro sulla qualita' |
1543 |
stringstream oss1; |
// query<<" and NUM_PKT_SAVED - BAD_PKT_CALREAD - BAD_PKT_READ - BAD_PKT >= 2" ; |
1544 |
oss1.str()=""; |
string msg = query.str(); |
1545 |
string msg1; |
mainLogUtil->logAll(msg); |
1546 |
|
res = sqlServer->Query(query.str().c_str()); |
1547 |
if (!res) |
stringstream oss1; |
1548 |
{ |
oss1.str() = ""; |
1549 |
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<<"'" |
|
|
<< ")"; |
|
1550 |
|
|
1551 |
string msg = oss.str(); |
if (!res) { |
1552 |
mainLogUtil->logAll(msg); |
oss1 << "DBError UNABLE to: " << query.str().c_str() << endl; |
1553 |
|
msg1 = oss1.str(); |
1554 |
//marco_new: controlla |
mainLogUtil->logError(msg1); |
1555 |
//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; |
|
|
} |
|
1556 |
|
|
1557 |
stringstream oss1; |
return res; |
1558 |
oss1.str()=""; |
} |
1559 |
string msg1; |
|
1560 |
|
bool PacketUser::saveMergeROOT_DB(const char* table_name, unsigned int root_id, unsigned long int pkt_number_in, |
1561 |
TSQLResult* res=NULL; |
unsigned long int pkt_number_fin, unsigned long int obt_in, unsigned long int obt_fin, |
1562 |
res= sqlServer->Query(oss.str().c_str()); |
unsigned long int mtime_init, unsigned long int mtime_last, unsigned long int mboot_num, double percentage) { |
1563 |
if(!res) |
|
1564 |
{ |
int good = 1; |
1565 |
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; |
1566 |
msg1=oss1.str(); |
|
1567 |
mainLogUtil->logError(msg1); |
stringstream oss; |
1568 |
return false; |
oss.str(""); |
1569 |
} |
oss << "INSERT INTO " << table_name |
1570 |
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)" |
1571 |
return true; |
<< " VALUES ('" << 0 << "','" << root_id << "','" << pkt_number_in << "','" << pkt_number_fin << "','" << obt_in |
1572 |
|
<< "','" << obt_fin << "','" << mtime_init << "','" << mtime_last << "','" << mboot_num << "','" << percentage |
1573 |
|
<< "'," << "NULL" << ",'" << tag_value << "','" << good <<"');"; |
1574 |
|
|
1575 |
|
string msg = oss.str(); |
1576 |
|
mainLogUtil->logAll(msg); |
1577 |
|
|
1578 |
|
//marco_new: controlla |
1579 |
|
//marco_new: esci se sono arrivato a zero |
1580 |
|
// if(real_time_last==real_time_init){ |
1581 |
|
if (mtime_init == mtime_last) { |
1582 |
|
mainLogUtil->logAll("Nothing to be saved"); |
1583 |
|
|
1584 |
|
// if(res){delete res; res = NULL;} |
1585 |
|
// if(row){delete row; row = NULL;} |
1586 |
|
return true; |
1587 |
|
} |
1588 |
|
|
1589 |
|
stringstream oss1; |
1590 |
|
oss1.str() = ""; |
1591 |
|
string msg1; |
1592 |
|
|
1593 |
|
TSQLResult* res = NULL; |
1594 |
|
res = sqlServer->Query(oss.str().c_str()); |
1595 |
|
if (!res) { |
1596 |
|
oss1 << "DBError UNABLE to: " << oss.str().c_str() << endl; |
1597 |
|
msg1 = oss1.str(); |
1598 |
|
mainLogUtil->logError(msg1); |
1599 |
|
return false; |
1600 |
|
} |
1601 |
|
if (res) { |
1602 |
|
delete res; |
1603 |
|
res = NULL; |
1604 |
|
} |
1605 |
|
return true; |
1606 |
} |
} |
1607 |
|
|
1608 |
//Utility: return max(IDN) |
//Utility: return max(IDN) |
1609 |
unsigned int PacketUser::select_maxIDN_DB(char* table_name) |
unsigned int PacketUser::select_maxIDN_DB(const char* table_name, const char* file_name) { |
|
{ |
|
1610 |
|
|
1611 |
if (!strcmp(table_name,Table_ROOT_Bad)) |
if (!strcmp(table_name, Table_ROOT_Bad)) { |
1612 |
{ |
return 0; |
1613 |
return 0; |
} |
1614 |
} |
unsigned int idN = 0; |
1615 |
unsigned int idN=0; |
TSQLResult* res = NULL; |
1616 |
TSQLResult* res=NULL; |
stringstream oss; |
1617 |
stringstream oss; |
oss.str(""); |
1618 |
oss.str(""); |
oss << "select ID_N from " << table_name << " where FILE_NAME='" << file_name <<"';"; |
1619 |
oss<<"select max(ID_N) from "<<table_name; |
// string msg = oss.str(); |
1620 |
// string msg = oss.str(); |
// mainLogUtil->logAll(msg); |
1621 |
// mainLogUtil->logAll(msg); |
res = sqlServer->Query(oss.str().c_str()); |
1622 |
res= sqlServer->Query(oss.str().c_str()); |
|
1623 |
|
stringstream oss1; |
1624 |
stringstream oss1; |
oss1.str() = ""; |
1625 |
oss1.str()=""; |
string msg1; |
1626 |
string msg1; |
|
1627 |
|
if (!res) { |
1628 |
if(!res) |
oss1 << "DBError UNABLE to: " << oss.str().c_str() << endl; |
1629 |
{ |
msg1 = oss1.str(); |
1630 |
oss1<<"DBError UNABLE to: "<<oss.str().c_str()<<endl; |
mainLogUtil->logError(msg1); |
1631 |
msg1=oss1.str(); |
return 0; |
1632 |
mainLogUtil->logError(msg1); |
} |
1633 |
return 0; |
|
1634 |
} |
TSQLRow* row = NULL; |
1635 |
|
row = res->Next(); |
1636 |
TSQLRow* row=NULL; |
if (!row) { |
1637 |
row=res->Next(); |
oss1 << "DBError UNABLE to: " << oss.str().c_str() << endl; |
1638 |
if (!row ) |
msg1 = oss1.str(); |
1639 |
{ |
mainLogUtil->logError(msg1); |
1640 |
oss1<<"DBError UNABLE to: "<<oss.str().c_str()<<endl; |
return 0; |
1641 |
msg1=oss1.str(); |
} |
1642 |
mainLogUtil->logError(msg1); |
|
1643 |
return 0; |
idN = atoi(row->GetField(0)); |
1644 |
} |
if (row) { |
1645 |
|
delete row; |
1646 |
idN=atoi(row->GetField(0)); |
row = NULL; |
1647 |
if(row){delete row; row = NULL;} |
} |
1648 |
if(res){delete res; res = NULL;} |
if (res) { |
1649 |
|
delete res; |
1650 |
oss<<". idN = "<<idN; |
res = NULL; |
1651 |
string msg = oss.str(); |
} |
|
mainLogUtil->logAll(msg); |
|
1652 |
|
|
1653 |
return idN; |
oss << ". idN = " << idN; |
1654 |
|
string msg = oss.str(); |
1655 |
|
mainLogUtil->logAll(msg); |
1656 |
|
|
1657 |
|
return idN; |
1658 |
} |
} |
1659 |
|
|
1660 |
/** |
/** |
1661 |
* Lock par=table, if par=null lock all tables |
* Lock par=table, if par=null lock all tables |
1662 |
*/ |
*/ |
1663 |
int PacketUser::LockTables(char* tableTobeLocked) |
int PacketUser::LockTables(const char* tableTobeLocked) { |
1664 |
{ |
//se non ho il DB :) |
1665 |
//se non ho il DB :) |
if (!do_cont_check) |
1666 |
if(!do_cont_check) return 999; |
return 999; |
1667 |
|
|
1668 |
TSQLResult* res=NULL; |
TSQLResult* res = NULL; |
1669 |
stringstream oss; |
stringstream oss; |
1670 |
oss.str(""); |
oss.str(""); |
1671 |
if(!tableTobeLocked) |
// if (!tableTobeLocked) |
1672 |
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 |
1673 |
else |
<< " write, " << Table_ROOT_Merging << " write;"; |
1674 |
oss << "lock table "<<tableTobeLocked<<" write; "; |
// else |
1675 |
|
// oss << "lock table " << tableTobeLocked << " write; "; |
1676 |
string msg = oss.str(); |
|
1677 |
mainLogUtil->logAll(msg); |
string msg = oss.str(); |
1678 |
|
mainLogUtil->logAll(msg); |
1679 |
res= sqlServer->Query(oss.str().c_str()); |
|
1680 |
|
res = sqlServer->Query(oss.str().c_str()); |
1681 |
stringstream oss1; |
|
1682 |
oss1.str()=""; |
stringstream oss1; |
1683 |
string msg1; |
oss1.str() = ""; |
1684 |
|
string msg1; |
1685 |
if(!res) |
|
1686 |
{ |
if (!res) { |
1687 |
oss1<<"DBError UNABLE to: "<<oss.str().c_str()<<endl; |
oss1 << "DBError UNABLE to: " << oss.str().c_str() << endl; |
1688 |
msg1=oss1.str(); |
msg1 = oss1.str(); |
1689 |
mainLogUtil->logError(msg1); |
mainLogUtil->logError(msg1); |
1690 |
return 1; |
return 1; |
1691 |
} |
} |
1692 |
|
|
1693 |
if(res){delete res; res = NULL;} |
if (res) { |
1694 |
mainLogUtil->logAll("TABLES LOCKED"); |
delete res; |
1695 |
return 0; |
res = NULL; |
1696 |
|
} |
1697 |
|
mainLogUtil->logAll("TABLES LOCKED"); |
1698 |
|
return 0; |
1699 |
} |
} |
1700 |
|
|
1701 |
/** |
/** |
1702 |
* UNLock tables |
* UNLock tables |
1703 |
*/ |
*/ |
1704 |
int PacketUser::UnLockTables(){ |
int PacketUser::UnLockTables() { |
1705 |
//se non ho il DB :) |
//se non ho il DB :) |
1706 |
if(!do_cont_check) return 999; |
if (!do_cont_check) |
1707 |
|
return 999; |
1708 |
|
|
1709 |
TSQLResult* res=NULL; |
TSQLResult* res = NULL; |
1710 |
stringstream oss; |
stringstream oss; |
1711 |
oss.str(""); |
oss.str(""); |
1712 |
oss << "unlock tables;"; |
oss << "unlock tables;"; |
1713 |
|
|
1714 |
string msg = oss.str(); |
string msg = oss.str(); |
1715 |
mainLogUtil->logAll(msg); |
mainLogUtil->logAll(msg); |
1716 |
|
|
1717 |
res= sqlServer->Query(oss.str().c_str()); |
res = sqlServer->Query(oss.str().c_str()); |
|
|
|
|
stringstream oss1; |
|
|
oss1.str()=""; |
|
|
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"); |
|
1718 |
|
|
1719 |
return 0; |
stringstream oss1; |
1720 |
|
oss1.str() = ""; |
1721 |
|
string msg1; |
1722 |
|
|
1723 |
|
if (!res) { |
1724 |
|
oss1 << "DBError UNABLE to: " << oss.str().c_str() << endl; |
1725 |
|
msg1 = oss1.str(); |
1726 |
|
mainLogUtil->logError(msg1); |
1727 |
|
return 1; |
1728 |
|
} |
1729 |
|
|
1730 |
|
if (res) { |
1731 |
|
delete res; |
1732 |
|
res = NULL; |
1733 |
|
} |
1734 |
|
mainLogUtil->logAll("TABLES UNLOCKED"); |
1735 |
|
|
1736 |
|
return 0; |
1737 |
} |
} |
1738 |
|
|
1739 |
/*********************************************************/ |
/*********************************************************/ |
1740 |
//marco_new_31 |
//marco_new_31 |
1741 |
void PacketUser::OpenDBConnection(char* tableTobeLocked){ |
void PacketUser::OpenDBConnection(const char* tableTobeLocked) { |
1742 |
if(do_cont_check){ |
if (do_cont_check) { |
1743 |
//controllo che non sia gia' aperta |
//controllo che non sia gia' aperta |
1744 |
if(!sqlServer){ |
if (!sqlServer) { |
1745 |
sqlServer = TSQLServer::Connect(connection,db_user,db_pwd); |
sqlServer = TSQLServer::Connect(pelosconnection, db_user, db_pwd); |
1746 |
if ((!sqlServer)||(!(sqlServer->IsConnected()))){cout<<"Can not connect with MYSQL sever"<<endl;} |
if ((!sqlServer) || (!(sqlServer->IsConnected()))) { |
1747 |
mainLogUtil->logAll("Connected to DB"); |
cout << "Can not connect with MYSQL sever" << endl; |
1748 |
//blocca le tabelle |
} |
1749 |
LockTables(tableTobeLocked); |
mainLogUtil->logAll("Connected to DB"); |
1750 |
} |
stringstream myquery; |
1751 |
} |
myquery.str(""); |
1752 |
|
myquery << "SET time_zone='+0:00'"; |
1753 |
|
sqlServer->Query(myquery.str().c_str()); |
1754 |
|
//blocca le tabelle |
1755 |
|
LockTables(tableTobeLocked); |
1756 |
|
} |
1757 |
|
} |
1758 |
|
|
1759 |
} |
} |
1760 |
|
|
1761 |
//marco_new_31 |
//marco_new_31 |
1762 |
void PacketUser::CloseDBConnection(){ |
void PacketUser::CloseDBConnection() { |
1763 |
if(do_cont_check){ |
if (do_cont_check) { |
1764 |
//controllo che ce ne sia una aperta |
//controllo che ce ne sia una aperta |
1765 |
if(sqlServer && sqlServer->IsConnected()){ |
if (sqlServer && sqlServer->IsConnected()) { |
1766 |
//marco_new: sblocca tutte le tabelle |
//marco_new: sblocca tutte le tabelle |
1767 |
UnLockTables(); |
UnLockTables(); |
1768 |
sqlServer->Close(); |
sqlServer->Close(); |
1769 |
delete sqlServer; |
delete sqlServer; |
1770 |
sqlServer=NULL; |
sqlServer = NULL; |
1771 |
mainLogUtil->logAll("Closed Connection to DB"); |
mainLogUtil->logAll("Closed Connection to DB"); |
1772 |
} |
} |
1773 |
} |
} |
1774 |
} |
} |
1775 |
|
|
|
|
|
|
|
|
1776 |
/***********************************************************************************************************************/ |
/***********************************************************************************************************************/ |
1777 |
/*#################################################### HIC SUNT LEONES ################################################*/ |
/*#################################################### HIC SUNT LEONES ################################################*/ |
1778 |
/***********************************************************************************************************************/ |
/***********************************************************************************************************************/ |
1779 |
//UNUSED: dbg functions... |
//UNUSED: dbg functions... |
1780 |
|
|
1781 |
//Return the system time in ms |
//Return the system time in ms |
1782 |
unsigned long long PacketUser::Record_Time(){ |
unsigned long long PacketUser::Record_Time() { |
1783 |
timeval tv; |
timeval tv; |
1784 |
gettimeofday(&tv,NULL); |
gettimeofday(&tv, NULL); |
1785 |
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; |
1786 |
return timems; |
return timems; |
1787 |
} |
} |
1788 |
|
|
1789 |
//dbg_functions: |
//dbg_functions: |
1790 |
|
|
1791 |
//UNUSED. save a packet in a file |
//UNUSED. save a packet in a file |
1792 |
void PacketUser::savePKT_file(char* headerPkt, |
void PacketUser::savePKT_file(char* headerPkt, char* pamPkt, long int length, bool append, char* nomefile) { |
1793 |
char* pamPkt, |
char fno[80] = ""; |
1794 |
long int length, |
ofstream fout; |
1795 |
bool append, |
sprintf(fno, "%s/pkt%d_of_%s.pkt", gSystem->ExpandPathName(outDir), numPKTSaved, nomefile); // EMI |
1796 |
char* nomefile) |
|
1797 |
{ |
if (append == true) |
1798 |
char fno[80]=""; |
fout.open(fno, ios::binary | ios::app); |
1799 |
ofstream fout; |
else |
1800 |
sprintf(fno,"%s/pkt%d_of_%s.pkt", outDir, numPKTSaved, nomefile); |
fout.open(fno, ios::binary); |
1801 |
|
|
1802 |
if(append==true) |
if (!fout) { |
1803 |
fout.open(fno, ios::binary | ios::app); |
cout << "can not open output file " << fno << endl; |
1804 |
else |
return; |
1805 |
fout.open(fno, ios::binary); |
} |
1806 |
|
fout.write(headerPkt, LENGTH_HEADER_PKT); |
1807 |
if (!fout) {cout<<"can not open output file "<<fno<<endl; return;} |
fout.write(pamPkt, length); |
1808 |
fout.write(headerPkt,LENGTH_HEADER_PKT); |
fout.close(); |
|
fout.write(pamPkt,length); |
|
|
fout.close(); |
|
1809 |
} |
} |
1810 |
|
|
1811 |
//UNUSED |
//UNUSED |
1812 |
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) { |
1813 |
{ |
char fno[80] = ""; |
1814 |
char fno[80]=""; |
ofstream fout; |
1815 |
ofstream fout; |
if (append == true) { |
1816 |
if(append==true) |
sprintf(fno, "%s/packets.pkt", gSystem->ExpandPathName(outDir)); // EMI |
1817 |
{ |
fout.open(fno, ios::binary | ios::app); |
1818 |
sprintf(fno,"%s/packets.pkt", outDir); |
} |
1819 |
fout.open(fno, ios::binary | ios::app); |
else { |
1820 |
} |
sprintf(fno, "%s/packet%d.pkt", gSystem->ExpandPathName(outDir), numPKT); // EMI |
1821 |
else{ |
fout.open(fno, ios::binary); |
1822 |
sprintf(fno,"%s/packet%d.pkt", outDir, numPKT ); |
} |
|
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(); |
|
|
} |
|
1823 |
|
|
1824 |
|
if (!fout) { |
1825 |
|
cout << "can not open output file " << fno << endl; |
1826 |
|
return; |
1827 |
|
} |
1828 |
|
fout.write(headerPkt, LENGTH_HEADER_PKT); |
1829 |
|
fout.write(pamPkt, length); |
1830 |
|
fout.close(); |
1831 |
|
} |
1832 |
|
|
1833 |
} |
} |