/[PAMELA software]/chewbacca/PamOffLineSW/PacketUser.cpp_14
ViewVC logotype

Contents of /chewbacca/PamOffLineSW/PacketUser.cpp_14

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations) (download)
Thu Dec 18 14:46:58 2008 UTC (16 years, 2 months ago) by mocchiut
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +1 -1 lines
FILE REMOVED
Default values changed, symbolic path handling implemented, cleanup of backup files, do not delete files from ROOT_TABLE_MERGING

1 //============================================================================
2 // $Id: PacketUser.cpp_14,v 1.1 2008/09/23 07:20:12 mocchiut Exp $
3 // Description :
4 //============================================================================
5 #include "PacketUser.h"
6 #include <sys/time.h>
7
8 namespace PamOffLineSW
9 {
10 extern LogUtil* mainLogUtil;
11 extern short compression ;
12 extern char *outDir;
13 extern TSQLServer *sqlServer;
14 extern bool multiFile;
15 extern char* fni;
16 extern char * nome_output;
17 extern bool is_new_route;
18 extern unsigned int download;
19
20 extern unsigned int mmm_number;
21 extern unsigned int orbit_number;
22 extern unsigned long int time_Offset;
23 extern bool tryMerge;
24
25 extern bool do_cont_check;
26
27 //extern unsigned long int delta_Time;//unused ??
28
29 PacketUser PacketUser::instance;
30
31 int PacketUser::numDiscontinity=0;
32 int PacketUser::numPKT=0;
33 int PacketUser::numPKTSaved=0;
34
35 PacketUser& PacketUser::getInstance()
36 {
37 return instance;
38 }
39
40 PacketUser::PacketUser()
41 {
42 gROOT->SetBatch(kTRUE);
43 numDiscontinity=0;
44 numPKTSaved=0;
45 numPKT=0;
46 pkt_number_init=0;
47 obt_init=0;
48 pkt_number_last=0;
49 obt_last=0;
50 obt_time_sync=0;
51 last_time_sync_info=0;
52 real_time_init=0;
53 real_time_last=0;
54 bad_pkt=0;
55 bad_pkt_EventReader=0;
56 bad_pkt_CalibReader=0;
57 reader= NULL;
58 pRun=NULL;
59 reader=new pamela::techmodel::EventReader();
60 Table_ROOT_Good="ROOT_TABLE";
61 Table_ROOT_Bad="ROOT_TABLE_BAD";
62 Table_PKT_Bad= "BAD_PKT_TABLE";
63 Table_GL_RESURS_OFFSET="GL_RESURS_OFFSET";
64 Table_ROOT_Merging="ROOT_TABLE_MERGING";
65 // good_pkt_Calib=0;
66
67 }
68
69 PacketUser::~PacketUser()
70 {
71 if(reader){delete reader; reader = NULL;}
72 numDiscontinity=0;
73 numPKTSaved=0;
74 numPKT=0;
75 pkt_number_init=0;
76 obt_init=0;
77 pkt_number_last=0;
78 obt_last=0;
79 obt_time_sync = 0;
80 last_time_sync_info = 0;
81 real_time_init=0;
82 real_time_last=0;
83 bad_pkt=0;
84 bad_pkt_EventReader=0;
85 bad_pkt_CalibReader=0;
86 // good_pkt_Calib=0;
87 }
88
89 //Put the packet in a root file. Create a new ROOT file for each group of packets
90 void PacketUser::usePKT(char*& headerPkt, char*& pamPkt, long int length, bool isCons, bool isPKTGood, const PacketType* type,
91 unsigned long int counter, unsigned long int obt)
92 {
93 //If the packet type was not recognised before
94 if(!type){return;} //numPKT++;
95
96 //in order to start ...
97 if(numPKT==0)
98 {
99 setInit(counter,obt);
100 StartGroup();
101 }
102
103 //here we know if the incoming packet can be considered consecutive to the previuos one
104 if((!isCons)&&(numPKT!=0))
105 {
106 setReal_Time();
107 //closing the group in file rootfilename
108 FinishGroup(rootfilename);
109
110 //the current pkt will be placed in a new group: rootfilename
111 numDiscontinity++;
112 setInit(counter,obt);
113 StartGroup();
114 }
115
116 //add current packet to the group and calculate bad_pkt_EventReader and bad_pkt_CalibReader
117 int ret=
118 reader->PKT_RunEvent(headerPkt, pamPkt, length, type);
119 /*
120 ret
121 0 packet good
122 1 exception but used //never happen
123 2 CRC exception but used
124 3 CALIBRATION PACKET with error but used
125 -1 CRC exception packet DISCARDED
126 -2 FATAL exception packet DISCARDED //never happen
127 -3 No way to read events of this type. packet DISCARDED( es OLD CalibCal)
128 ret = 10 if the packet is good but comes from a cadre with VRL problems
129 */
130
131 //here we know if the packet comes from one or more corrupted cadres
132 //if(!isPKTGood){bad_pkt++;}
133 if((!isPKTGood)&&(!ret)){ret=10;}
134
135 switch (ret)
136 {
137 case 0: {numPKTSaved++; break;}
138 case 1: {bad_pkt_EventReader++; numPKTSaved++; break;}
139 case 2: {bad_pkt_EventReader++;numPKTSaved++; break;}
140 case 3: {bad_pkt_CalibReader++; numPKTSaved++; break;}
141 case 10: {bad_pkt++; numPKTSaved++; break;}
142 default:{
143 stringstream oss;
144 oss.str()="";
145 oss<<"Packet DISCARDED, reason = "<<ret;
146 string msg = oss.str();
147 mainLogUtil->logAll(msg);
148 break;
149 }
150 }
151 /*
152 if ((ret==0)&&((type==PacketType::CalibTrk1)||(type==PacketType::CalibTrk2)|| (type==PacketType::CalibCalPed)))
153 {
154 good_pkt_Calib++;//maybe I will remove this in future
155 }
156 */
157
158 if(ret>=0)// only the packet not discarded of course
159 setLast(counter,obt);
160
161 //TODO: decide what kind of packet I can use here
162 // if((ret==0)||(ret==10))//I want to use only good packet
163 if(ret>=0)//I want to use only accepted packet
164 setTimeSync(pamPkt, type);
165
166 //TODO: remove the following lines, I will not use BAD PKT saving
167 //if(ret>0)// if I want to save all the packets with error and the reason
168 if(ret==3)//I want to save only Calibration packets
169 {
170 /*
171 //dbg: save in file,
172 //TODO remove this later
173 //if(SaveInFile)
174 savePKT_file(headerPkt,
175 pamPkt,
176 length,
177 false,
178 rootfilename);
179 mainLogUtil->logInfo("saved bad packet in file");
180 */
181 //TODO: move the storing in DB after, when I know the ROOT_ID_N
182 // If I don't have the DB I can exit
183 if(!do_cont_check){
184 if(pamPkt){delete[] pamPkt; pamPkt = NULL;}
185 if(headerPkt){delete[] headerPkt; headerPkt = NULL;}
186 numPKT++;
187 return;
188 }
189
190 if(saveBADPKT_DB(Table_PKT_Bad,
191 outDir,
192 rootfilename,
193 counter,
194 obt,
195 fni,
196 ret,
197 999)==true)
198 {
199 stringstream oss1;
200 oss1.str()="";
201 oss1<<"Saved information regarding bad packet of file: "<<rootfilename<<" in table "<<Table_PKT_Bad;
202 string msg1 = oss1.str();
203 mainLogUtil->logInfo(msg1);
204 }
205 else
206 {
207 stringstream oss1;
208 oss1.str()="";
209 oss1<<"Problem storing information regarding bad packet of file: "<<rootfilename<<" in table "<<Table_PKT_Bad;
210 string msg1 = oss1.str();
211 mainLogUtil->logError(msg1);
212 }
213 }
214
215 //just to be sure ...
216 if(pamPkt){delete[] pamPkt; pamPkt = NULL;}
217 //just to be sure ...
218 if(headerPkt){delete[] headerPkt; headerPkt = NULL;}
219
220 numPKT++;
221 }
222
223 //set the value of the counter and obt of the first packet of the group
224 void PacketUser::setInit(unsigned long int counter, unsigned long int obt)
225 {
226 sprintf(nnnn_mmm_ppp,"%05d_%03d_%03d", orbit_number, mmm_number, download);
227 //TODO: check here, add .root
228 sprintf(rootfilename,"%s_%s_%d", nome_output, nnnn_mmm_ppp, numDiscontinity);
229 pkt_number_init=counter;
230 obt_init=obt;
231 pkt_number_last=0;
232 obt_last=0;
233 real_time_init=0;
234 real_time_last=0;
235 bad_pkt=0;
236 numPKTSaved=0;
237 bad_pkt_EventReader=0; bad_pkt_CalibReader=0;
238 //good_pkt_Calib=0;
239 }
240
241 //starts a new root file
242 void PacketUser::StartGroup()
243 {
244 pRun = new PamelaRun(rootfilename, outDir , multiFile, compression);
245 reader->Init(pRun);
246 stringstream oss;
247 oss.str()="";
248 oss<<"######################### Start a new group in file: "<< rootfilename <<" ############################";
249 string msg = oss.str();
250 mainLogUtil->logInfo(msg);
251 }
252
253 //set the value of the counter and obt of the last packet of the group
254 void PacketUser::setLast(unsigned long int counter, unsigned long int obt)
255 {
256 pkt_number_last=counter;
257 obt_last=obt;
258 }
259
260 //retrieve obt_time_sync and last_time_sync_info from packet if type has special values
261 void PacketUser::setTimeSync(char* packet, const PacketType* type)
262 {
263 //do nothing
264 if(!do_cont_check) {
265 if(is_new_route)
266 is_new_route=false;
267 return;
268 }
269
270 //TODO: usare anche MCMD ... NOTA: questo da sempre errore ret != 0
271 //In RunHeader e RunTrailer sono in secondi(?), controllare se aggiungo altri tipi di paccheti se invece sono in secondi
272
273 //When I found a new download I need to reset all values
274 if(is_new_route)
275 {
276 //reset
277 obt_time_sync=0; last_time_sync_info=0; is_new_route=false;
278 if(time_Offset)
279 timeOffset=time_Offset;
280 else
281 timeOffset=retrieveTimeOffset();
282 }
283
284 //Retrieve if possible obt_time_sync and last_time_sync_info
285 //i don't need to retrieve them again if they are good
286 if((obt_time_sync)||(last_time_sync_info)) return;
287
288 int offset=0;
289 if(type==PacketType::RunHeader)
290 {
291 offset=0;
292 }
293 else if(type==PacketType::RunTrailer)
294 {
295 offset=3;
296 }
297 else if(type==PacketType::Mcmd)
298 {
299 mainLogUtil->logAll("TODO: Packet Mcmd now is not used to retrieve Absolute time. This may cause problems somewhere.");
300 return;
301 }
302 else
303 {
304 return;
305 }
306 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);
307 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);
308
309 stringstream oss;
310 oss.str()="";
311 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();
312 string msg = oss.str();
313 mainLogUtil->logAll(msg);
314 }
315
316 //set the real time of the first packet and the last packet oif a group of packet if possible
317 void PacketUser::setReal_Time()
318 {
319 if((obt_time_sync)||(last_time_sync_info))
320 {
321 real_time_init=(obt_init/1000-obt_time_sync)+last_time_sync_info;
322 real_time_last=(obt_last/1000-obt_time_sync)+last_time_sync_info;
323 real_time_init+=timeOffset;
324 real_time_last+=timeOffset;
325 }
326 }
327
328 //timeOffset
329 //retrieve from table GL_RESURS_OFFSET timeOffset
330 unsigned long int PacketUser::retrieveTimeOffset()
331 {
332 //TODO check here ... marco
333 if(!do_cont_check) return 0;
334 UInt_t t0 = 0; //toffset
335
336 stringstream oss;
337 oss.str("");
338 oss << "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE),ID FROM GL_RESURS_OFFSET WHERE SPECIAL_FILE='"
339 << nnnn_mmm_ppp << "';";
340
341 TSQLResult* res=NULL;
342 TSQLRow* row=NULL;
343 res= sqlServer->Query(oss.str().c_str());
344 if(!res)
345 {
346 cout<<"DBError UNABLE to: "<<oss.str().c_str()<<endl;
347 return 0;
348 }
349
350 row=res->Next();
351 if (!row )
352 {
353 if(res){delete res; res = NULL;}
354
355 oss.str("");
356 oss << "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE),ID FROM GL_RESURS_OFFSET WHERE FROM_ORBIT < "
357 << orbit_number << " order by FROM_ORBIT desc limit 1;";
358 res= sqlServer->Query(oss.str().c_str());
359 if(!res)
360 {
361 cout<<"DBError UNABLE to: "<<oss.str().c_str()<<endl;
362 return 0;
363 }
364 row=res->Next();
365 if (!row)
366 {
367 cout<<"DBError UNABLE to: "<<oss.str().c_str()<<endl;
368 return 0;
369 }
370
371 }
372
373 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);
374 t0 = (UInt_t)tu.GetSec();
375
376 if(res){delete res; res = NULL;}
377 if(row){delete row; row = NULL;}
378
379 return t0;
380 }
381
382 //this is public and can be called from the main at the end of the game
383 void PacketUser::FinishLastGroup()
384 {
385 mainLogUtil->logAll("######################### Closing the last group ############################");
386 setReal_Time();
387 FinishGroup(rootfilename);
388 mainLogUtil->logAll("######################### Closed the last group ############################");
389
390 }
391
392 //finish the old root file
393 void PacketUser::FinishGroup(char * filename)
394 {
395 if(pRun)
396 {
397 pRun->WriteFiles();
398 delete pRun; pRun = NULL;
399 stringstream close;
400 close.str()="";
401 string msg;
402
403 close<<"######################### Close group in file: "<< rootfilename <<" ############################";
404 msg = close.str();
405 mainLogUtil->logInfo(msg);
406
407 //TODO: check ... se non faccio proprio controlli su continuita' neanche salvo su DB
408 // if((!step_pkt_number)&&(!step_pkt_obt)) return;
409 if(!do_cont_check) return;
410
411 stringstream oss;
412 oss.str()="";
413
414 //TODO: check when I don't want to log in DB informations
415
416 // se non ho salvato nessun pacchetto
417 if(numPKTSaved==0){
418 stringstream err;
419 err.str()="";
420 err<<"NO PACKET SAVED in file: "<< rootfilename <<" The group is empty: you can remove this file.";
421 msg = err.str();
422 mainLogUtil->logError(msg);
423 return;
424 }
425
426 //se non ho salvato nessun pacchetto buono
427 if((numPKTSaved-bad_pkt_EventReader-bad_pkt_CalibReader-bad_pkt)==0){
428 stringstream err;
429 err.str()="";
430 err<<"NO GOOD PACKET SAVED in file: "<< rootfilename <<" The group is BAD: you may want to remove this file.";
431 msg = err.str();
432 mainLogUtil->logInfo(msg);
433 // mainLogUtil->logError(msg);
434 // return; //TODO: ???
435 }
436 /*
437 //se non ho salvato nessun pacchetto buono di calibrazione
438 if(good_pkt_Calib==0){
439 stringstream err;
440 err.str()="";
441 err<<"NO GOOD CALIB PACKET SAVED in file: "<< rootfilename <<" this is strange";
442 msg = err.str();
443 mainLogUtil->logInfo(msg);
444 // mainLogUtil->logError(msg);
445 // return;
446 }
447 //TODO: I should/can use good_pkt_Calib storing this info in DB??
448 */
449
450 //don't save in Table_ROOT_Good and don't search for ROOT files in the same temporal range
451 if((!real_time_init)&&(!real_time_last))
452 {
453 //saved in another table for future study Record_Time()
454 if(saveROOT_DB(Table_ROOT_Bad, outDir,
455 filename,
456 pkt_number_init, pkt_number_last,
457 obt_init, obt_last,
458 obt_time_sync, last_time_sync_info,
459 real_time_init, real_time_last,
460 timeOffset,
461 bad_pkt, bad_pkt_EventReader, bad_pkt_CalibReader, numPKTSaved,
462 fni)==true)
463 {
464 oss.str()="";
465 oss<<"Saved information regarding file: "<<filename<<" in table "<<Table_ROOT_Bad;
466 msg = oss.str();
467 mainLogUtil->logInfo(msg);
468 }
469 else
470 {
471 oss.str()="";
472 oss<<"Problem storing information in DB regarding file: "<<filename;
473 msg = oss.str();
474 mainLogUtil->logError(msg);
475 }
476 return;
477 }
478
479 //saves info in DB in table Table_ROOT_Good
480 if(saveROOT_DB(Table_ROOT_Good, outDir,
481 filename,
482 pkt_number_init, pkt_number_last,
483 obt_init, obt_last,
484 obt_time_sync, last_time_sync_info,
485 real_time_init, real_time_last,
486 timeOffset,
487 bad_pkt, bad_pkt_EventReader, bad_pkt_CalibReader, numPKTSaved,
488 fni)==true)
489 {
490 oss<<"Saved information regarding file: "<<filename<<" in table "<<Table_ROOT_Good;
491 msg = oss.str();
492 mainLogUtil->logInfo(msg);
493
494 //TODO : work on this ....
495 if(tryMerge){
496 merge_ROOTfiles();
497 }
498 }
499 else
500 {
501 oss<<"Problem storing information in DB regarding file: "<<filename;
502 msg = oss.str();
503 mainLogUtil->logError(msg);
504 }
505 }
506 }
507
508 //inserisci in DB in apposita tabella il pkt con errore
509 bool PacketUser::saveBADPKT_DB(char* table_name,
510 char* folder_name,
511 char* file_name,
512 unsigned long int pkt_number,
513 unsigned long int pkt_obt,
514 char* nome_input,
515 int reason,
516 int rootID)
517 {
518 stringstream oss;
519 oss.str("");
520 oss << "INSERT INTO "<< table_name <<" (ID_N, FOLDER_NAME, FILE_NAME, PKT_NUMBER, PKT_OBT, INPUT_NAME, REASON, ROOT_ID_N, INSERT_TIME)"
521 << " VALUES ('"<<0<< "','" <<folder_name<<"','" <<file_name<< "','"
522 << pkt_number <<"','"
523 << pkt_obt << "','"
524 << nome_input <<"','"
525 << reason <<"','"<< rootID<< "',"
526 <<"NULL"<<
527 ")";
528 string msg = oss.str();
529 mainLogUtil->logAll(msg);
530
531 stringstream oss1;
532 oss1.str()="";
533 string msg1;
534
535 TSQLResult* res=NULL;
536 res= sqlServer->Query(oss.str().c_str());
537 if(!res)
538 {
539 oss1<<"DBError UNABLE to: "<<oss.str().c_str()<<endl;
540 msg1=oss1.str();
541 mainLogUtil->logError(msg1);
542 return false;
543 }
544 if(res){delete res; res = NULL;}
545 return true;
546 }
547
548 //save in Table_ROOT_Good or in Table_ROOT_Bad
549 bool PacketUser::saveROOT_DB(char* table_name, char* folder_name, char* file_name,
550 unsigned long int pkt_number_in, unsigned long int pkt_number_fin,
551 unsigned long int obt_in, unsigned long int obt_fin,
552 unsigned long int oT_sync, unsigned long int lT_sync_info,
553 unsigned long int mtime_init, unsigned long int mtime_last,
554 unsigned long int time_offset,
555 int bad_pkt, int bad_pkt_read, int bad_pkt_CalRead, int num_PKT_Saved,
556 char* nome_input)
557 {
558 //TODO: forse far ritornare ID della cosa appena inserita se e' andatato tutto ok invece che true false?
559 stringstream oss;
560 oss.str("");
561 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,TIME_OFFSET,BAD_PKT,BAD_PKT_READ,BAD_PKT_CALREAD,NUM_PKT_SAVED,INPUT_NAME,INSERT_TIME)"
562 << " VALUES ('"<<0<< "','" <<folder_name<<"','" <<file_name<< "','" << pkt_number_in <<"','"<< pkt_number_fin << "','"<< obt_in <<"','"<< obt_fin<< "','"
563 << oT_sync << "','" << lT_sync_info << "','"
564 << mtime_init << "','" << mtime_last << "','"
565 << time_offset << "','"
566 << bad_pkt <<"','" << bad_pkt_read <<"','"<< bad_pkt_CalRead <<"','"<< numPKTSaved<<"','"
567 << nome_input <<"',"
568 <<"NULL"<<
569 ")";
570 string msg = oss.str();
571 mainLogUtil->logAll(msg);
572
573 stringstream oss1;
574 oss1.str()="";
575 string msg1;
576
577 TSQLResult* res=NULL;
578 res= sqlServer->Query(oss.str().c_str());
579 if(!res)
580 {
581 oss1<<"DBError UNABLE to: "<<oss.str().c_str()<<endl;
582 msg1=oss1.str();
583 mainLogUtil->logError(msg1);
584 return false;
585 }
586 if(res){delete res; res = NULL;}
587 return true;
588 }
589
590 //save a packet in a file
591 void PacketUser::savePKT_file(char* headerPkt,
592 char* pamPkt,
593 long int length,
594 bool append,
595 char* nomefile)
596 {
597 char fno[80]="";
598 ofstream fout;
599 sprintf(fno,"%s/pkt%d_of_%s.pkt", outDir, numPKTSaved, nomefile);
600
601 if(append==true)
602 fout.open(fno, ios::binary | ios::app);
603 else
604 fout.open(fno, ios::binary);
605
606 if (!fout) {cout<<"can not open output file "<<fno<<endl; return;}
607 fout.write(headerPkt,LENGTH_HEADER_PKT);
608 fout.write(pamPkt,length);
609 fout.close();
610 }
611
612
613 /****************************** MERGING ***********************************************/
614
615 bool PacketUser::merge_ROOTfiles()
616 {
617 mainLogUtil->logError("MMMM merge_ROOTfiles ...");
618
619 //TODO: metti qui la corretta definizione ...
620 int percentage=(bad_pkt+bad_pkt_EventReader+bad_pkt_CalibReader);// /numPKTSaved;
621 cout<<"percentage: "<< percentage<<endl;
622
623 //TODO: cambia qui fai ritornare questo ID quando faccio la insert in save ...
624 //the ID of the current ROOT file in table Table_ROOT_Good
625 unsigned int my_id = select_maxIDN_DB(Table_ROOT_Good);
626
627 TSQLResult* res=NULL;
628 TSQLRow* row =NULL;
629 //TODO: cambiare i tipi di relaz
630 for(int relaz=AFTER; relaz<=BIGGER; relaz++)
631 {
632 res = Select_merging(Table_ROOT_Merging, real_time_init, real_time_last, (type_Rel_ROOT)relaz);
633 cout<<"MMMMM valori usati: real_time_init= "<< real_time_init<< " real_time_last= "<<real_time_last;
634
635 unsigned int num_rows=0;
636
637 if (!res)
638 {
639 mainLogUtil->logError("MMMM problem");
640 return false;
641 }
642
643 num_rows=res->GetRowCount();
644 cout<<"MMMMM trovati num_rows "<< num_rows<< " per relaz= "<<relaz;
645
646 if(num_rows>0)
647 {
648 //TODO , check: deve esserre num_rows =1 a meno che relaz bigger
649 for(unsigned int i=0; i<num_rows; i++)
650 {
651 row=res->Next();
652 if (!row)
653 {
654 //oss1<<"DBError UNABLE to: "<<query.str().c_str()<<endl;
655 //msg1=oss1.str();
656 mainLogUtil->logError("ROW=null");
657 if(res){delete res; res = NULL;}
658 return false;
659 }
660
661
662 //TODO ricavare tutte le info che servono
663 unsigned int idN = 0;
664 int perc =0;
665 idN=atoi(row->GetField(0));
666 perc=atoi(row->GetField(8));
667 //unsigned long int M_pkt_number_in, M_pkt_number_fin, M_obt_in, M_obt_fin, M_mtime_init, M_mtime_last;
668 //TODO controlla se perc=percentage
669 if(perc>percentage){
670 mainLogUtil->logError("MMMM current meglio ...");
671 //moodifica DB
672 updateMergeROOT_DB(Table_ROOT_Merging,
673 atoi(row->GetField(1)), atoi(row->GetField(2)),
674 atoi(row->GetField(3)), atoi(row->GetField(4)),
675 atoi(row->GetField(5)), atoi(row->GetField(6)),
676 atoi(row->GetField(7)), perc,
677 idN,(type_Rel_ROOT)relaz);
678 }
679 else{
680 mainLogUtil->logError("MMMM DB meglio o uguale...");
681 if(relaz == AFTER){
682 mainLogUtil->logError("MMMM AFTER: modifico i miei INIT ...");
683 pkt_number_init= atoi(row->GetField(3));
684 obt_init= atoi(row->GetField(5));
685 real_time_init= atoi(row->GetField(7));
686 }
687 else if(relaz == BEFORE){
688 mainLogUtil->logError("MMMM BEFORE: modifico i miei LAST ...");
689
690 pkt_number_last= atoi(row->GetField(2));
691 obt_last= atoi(row->GetField(4));
692 real_time_last= atoi(row->GetField(6));
693 }
694 else if(relaz == SMALLER)
695 {
696 //non devo proprio salvarlo ed esco inoltre poi non posso essere piu grande di altri ...
697 //nothing to merge
698 mainLogUtil->logError("MMMM NIENTE DA MERGIARE ESCO ...");
699
700 if(res){delete res; res = NULL;}
701 if(row){delete row; row = NULL;}
702 return false;
703 }
704 else if(relaz == BIGGER)//occhio a problemi spezzettamento
705 {
706 mainLogUtil->logError("MMMM BIGGER SALVO LA prima parte del MIO CURRENT MODIFICATO ...");
707 saveMergeROOT_DB(Table_ROOT_Merging, my_id,
708 pkt_number_init, atoi(row->GetField(2)),
709 obt_init, atoi(row->GetField(4)),
710 real_time_init, atoi(row->GetField(6)),
711 percentage);
712
713 mainLogUtil->logError("MMMM BIGGER: modifico i miei INIT per la seconda parte...");
714
715 pkt_number_init= atoi(row->GetField(3));
716 obt_init= atoi(row->GetField(5));
717 real_time_init= atoi(row->GetField(7));
718
719 }
720 }
721 }//for num_rows
722 }
723 else{
724 mainLogUtil->logError("MMMM TROVATI 0, nulla da fare ...");
725 }
726
727 if(res){delete res; res = NULL;}
728 if(row){delete row; row = NULL;}
729
730
731 }//for
732 mainLogUtil->logError("MMMM SALVO IL MIO CURRENT MODIFICATO ...");
733
734 saveMergeROOT_DB(Table_ROOT_Merging, my_id,
735 pkt_number_init, pkt_number_last,
736 obt_init, obt_last,
737 real_time_init, real_time_last,
738 percentage);
739
740
741 mainLogUtil->logInfo(" Merged ");
742 return true;
743 }
744
745 //unsigned int root_id, int percentage non le devo modificare
746 bool PacketUser::updateMergeROOT_DB(char* table_name,
747 unsigned int root_id,
748 unsigned long int pkt_number_in, unsigned long int pkt_number_fin,
749 unsigned long int obt_in, unsigned long int obt_fin,
750 unsigned long int mtime_init, unsigned long int mtime_last,
751 int bad_perc,
752 unsigned int ID_record, type_Rel_ROOT type_rel)
753 {
754 stringstream oss;
755 oss.str("");
756 //TODO: change here
757 /*
758 oss << "UPDATE "<< table_name
759 << " SET PKT_NUMBER_INIT ="<< pkt_number_in<<"',' PKT_NUMBER_FINAL ="<< pkt_number_fin
760 <<"','PKT_OBT_INIT ="<< obt_in<<"',' PKT_OBT_FINAL ="<< obt_fin
761 <<"','REAL_TIME_INIT ="<< mtime_init<<"',' REAL_TIME_LAST ="<< mtime_last<<" WHERE ID_N ="<< ID_record;
762 //<<" (ID_N, ROOT_ID_N, PKT_NUMBER_INIT, PKT_NUMBER_FINAL, PKT_OBT_INIT, PKT_OBT_FINAL, REAL_TIME_INIT,REAL_TIME_LAST,BAD_PKT_PERCENTAGE,INSERT_TIME)"
763 */
764 if(type_rel == AFTER){
765 oss << "UPDATE "<< table_name
766 << " SET 'PKT_NUMBER_FINAL ="<< pkt_number_init
767 <<"',' PKT_OBT_FINAL ="<< obt_init
768 <<"',' REAL_TIME_LAST ="<< real_time_init<<"' WHERE ID_N ="<< ID_record <<";";
769 }
770 else if(type_rel == BEFORE){
771 oss << "UPDATE "<< table_name
772 << " SET 'PKT_NUMBER_INIT ="<< pkt_number_last
773 <<"',' PKT_OBT_INIT ="<< obt_last
774 <<"',' REAL_TIME_INIT ="<< real_time_last<<"' WHERE ID_N ="<< ID_record<<";";
775 }
776 else if(type_rel == SMALLER){
777 /*
778 if(mtime_init==real_time_init){
779 mainLogUtil->logError("MMMM SMALLER ma stesso init butto quello su DB ...");
780 oss << "DELETE FROM "<< table_name <<" WHERE ID_N ="<< ID_record;
781 }
782 else{
783 mainLogUtil->logError("MMMM SMALLER perparo UPDATE PER PRIOMA PARTE SU DB, MODIFICO final VALUES...");
784 oss << "UPDATE "<< table_name
785 << " SET PKT_NUMBER_FINAL ="<< pkt_number_init
786 <<"',' PKT_OBT_FINAL ="<< obt_init
787 <<"',' REAL_TIME_LAST ="<< real_time_init<<" WHERE ID_N ="<< ID_record;
788
789 mainLogUtil->logError("MMMM SMALLER SALVO LA seconda parte di quello sul DB MODIFICATO ...");
790 saveMergeROOT_DB(table_name, root_id,
791 pkt_number_last, pkt_number_fin,
792 obt_last, obt_fin,
793 real_time_last, mtime_last,
794 bad_perc);
795
796
797 }
798
799
800 if((mtime_init==real_time_init)&&(mtime_last==real_time_last)){
801 mainLogUtil->logError("MMMM SMALLER , uguale butto quello su DB ...");
802 oss << "DELETE FROM "<< table_name <<" WHERE ID_N ="<< ID_record;
803 }else{
804 }
805
806 /**/
807 //spezzettamentento
808 mainLogUtil->logError("MMMM SMALLER perparo UPDATE PER PRIOMA PARTE SU DB, MODIFICO final VALUES...");
809 oss << "UPDATE "<< table_name
810 << " SET 'PKT_NUMBER_FINAL ="<< pkt_number_init
811 <<"',' PKT_OBT_FINAL ="<< obt_init
812 <<"',' REAL_TIME_LAST ="<< real_time_init<<"' WHERE ID_N ="<< ID_record<<";";
813
814 mainLogUtil->logError("MMMM SMALLER SALVO LA seconda parte di quello sul DB MODIFICATO ...");
815 saveMergeROOT_DB(table_name, root_id,
816 pkt_number_last, pkt_number_fin,
817 obt_last, obt_fin,
818 real_time_last, mtime_last,
819 bad_perc);
820
821
822
823
824 }
825 else if(type_rel == BIGGER){
826 //TODO: check here...
827 oss << "DELETE FROM "<< table_name <<" WHERE ID_N ="<< ID_record<<";";
828 /*
829 oss << "UPDATE "<< table_name
830 << " SET PKT_NUMBER_INIT ="<< 0<<"',' PKT_NUMBER_FINAL ="<< 0
831 <<"','PKT_OBT_INIT ="<< 0<<"',' PKT_OBT_FINAL ="<< 0
832 <<"','REAL_TIME_INIT ="<< 0<<"',' REAL_TIME_LAST ="<< 0<<" WHERE ID_N ="<< ID_record;
833 */
834 }
835 else
836 return false;
837
838
839 cout<<"$$$$$ DBG: UPDATE MERGE "<<oss.str().c_str()<<endl;
840
841 string msg = oss.str();
842 mainLogUtil->logAll(msg);
843
844 stringstream oss1;
845 oss1.str()="";
846 string msg1;
847
848 TSQLResult* res=NULL;
849 res= sqlServer->Query(oss.str().c_str());
850 if(!res)
851 {
852 oss1<<"DBError UNABLE to: "<<oss.str().c_str()<<endl;
853 msg1=oss1.str();
854 mainLogUtil->logError(msg1);
855 return false;
856 }
857 if(res){delete res; res = NULL;}
858 return true;
859
860 }
861
862
863 //TODO: ....
864 TSQLResult* PacketUser::Select_merging(char* table_name, unsigned long int mtime_init, unsigned long int mtime_last, type_Rel_ROOT type_rel)
865 {
866
867 // unsigned int idN=0;
868 TSQLResult* res=NULL;
869 stringstream query;
870 query.str("");
871
872 //TODO ... e manco poco !
873 //TODO bordi ??
874
875 if(type_rel == AFTER)
876 query<<"select * from "<<table_name<<" where REAL_TIME_LAST > "<< mtime_init <<" and REAL_TIME_LAST < "<< mtime_last <<" and REAL_TIME_INIT < "<< mtime_init;
877 else if(type_rel == BEFORE)
878 query<<"select * from "<<table_name<<" where REAL_TIME_INIT > "<< mtime_init <<" and REAL_TIME_INIT < "<< mtime_last <<" and REAL_TIME_LAST > "<< mtime_last;
879 else if(type_rel == SMALLER)
880 query<<"select * from "<<table_name<<" where REAL_TIME_INIT < "<< mtime_init <<" and REAL_TIME_LAST > "<< mtime_last;
881 else if(type_rel == BIGGER)
882 query<<"select * from "<<table_name<<" where REAL_TIME_INIT > "<< mtime_init <<" and REAL_TIME_LAST < "<< mtime_last;
883 else
884 return 0;
885 //TODO: change here ....
886 // query<<" and NUM_PKT_SAVED - BAD_PKT_CALREAD - BAD_PKT_READ - BAD_PKT >= 2" ;
887 query<< " order by REAL_TIME_INIT ASC";
888
889 cout<<"$$$$$ DBG: "<<query.str().c_str()<<endl;
890
891 res= sqlServer->Query(query.str().c_str());
892
893 stringstream oss1;
894 oss1.str()="";
895 string msg1;
896
897 if (!res)
898 {
899 oss1<<"DBError UNABLE to: "<<query.str().c_str()<<endl;
900 msg1=oss1.str();
901 mainLogUtil->logError(msg1);
902 }
903
904 return res;
905 }
906
907 bool PacketUser::saveMergeROOT_DB(char* table_name, unsigned int root_id,
908 unsigned long int pkt_number_in, unsigned long int pkt_number_fin,
909 unsigned long int obt_in, unsigned long int obt_fin,
910 unsigned long int mtime_init, unsigned long int mtime_last,
911 int percentage)
912 {
913
914 stringstream oss;
915 oss.str("");
916 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,BAD_PKT_PERCENTAGE,INSERT_TIME)"
917 << " VALUES ('"<<0<< "','" <<root_id<<"','"<< pkt_number_in <<"','"<< pkt_number_fin << "','"<< obt_in <<"','"<< obt_fin<< "','"
918 << mtime_init << "','" << mtime_last << "','"
919 << percentage <<"',"
920 <<"NULL"<<
921 ")";
922 cout<<"$$$$$ DBG: SAVE MERGE "<<oss.str().c_str()<<endl;
923
924 string msg = oss.str();
925 mainLogUtil->logAll(msg);
926
927 stringstream oss1;
928 oss1.str()="";
929 string msg1;
930
931 TSQLResult* res=NULL;
932 res= sqlServer->Query(oss.str().c_str());
933 if(!res)
934 {
935 oss1<<"DBError UNABLE to: "<<oss.str().c_str()<<endl;
936 msg1=oss1.str();
937 mainLogUtil->logError(msg1);
938 return false;
939 }
940 if(res){delete res; res = NULL;}
941 return true;
942
943 }
944
945
946 //unsigned int root_id, int percentage non le posso/devo modificare
947 bool PacketUser::OLD_updateMergeROOT_DB(char* table_name,
948 unsigned long int pkt_number_in, unsigned long int pkt_number_fin,
949 unsigned long int obt_in, unsigned long int obt_fin,
950 unsigned long int mtime_init, unsigned long int mtime_last,
951 unsigned int ID_record)
952 {
953 stringstream oss;
954 oss.str("");
955 //TODO: change here
956 oss << "UPDATE "<< table_name
957 << " SET PKT_NUMBER_INIT ="<< pkt_number_in<<"',' PKT_NUMBER_FINAL ="<< pkt_number_fin
958 <<"','PKT_OBT_INIT ="<< obt_in<<"',' PKT_OBT_FINAL ="<< obt_fin
959 <<"','REAL_TIME_INIT ="<< mtime_init<<"',' REAL_TIME_LAST ="<< mtime_last<<" WHERE ID_N ="<< ID_record;
960
961 //<<" (ID_N, ROOT_ID_N, PKT_NUMBER_INIT, PKT_NUMBER_FINAL, PKT_OBT_INIT, PKT_OBT_FINAL, REAL_TIME_INIT,REAL_TIME_LAST,BAD_PKT_PERCENTAGE,INSERT_TIME)"
962
963 cout<<"$$$$$ DBG: UPDATE MERGE "<<oss.str().c_str()<<endl;
964
965 string msg = oss.str();
966 mainLogUtil->logAll(msg);
967
968 stringstream oss1;
969 oss1.str()="";
970 string msg1;
971
972 TSQLResult* res=NULL;
973 res= sqlServer->Query(oss.str().c_str());
974 if(!res)
975 {
976 oss1<<"DBError UNABLE to: "<<oss.str().c_str()<<endl;
977 msg1=oss1.str();
978 mainLogUtil->logError(msg1);
979 return false;
980 }
981 if(res){delete res; res = NULL;}
982 return true;
983
984 }
985
986 //Utility: return max(IDN)
987 unsigned int PacketUser::select_maxIDN_DB(char* table_name)
988 {
989 unsigned int idN=0;
990 TSQLResult* res=NULL;
991 stringstream oss;
992 oss.str("");
993 oss<<"select max(ID_N) from "<<table_name;
994 res= sqlServer->Query(oss.str().c_str());
995
996 stringstream oss1;
997 oss1.str()="";
998 string msg1;
999
1000 if(!res)
1001 {
1002 oss1<<"DBError UNABLE to: "<<oss.str().c_str()<<endl;
1003 msg1=oss1.str();
1004 mainLogUtil->logError(msg1);
1005 return 0;
1006 }
1007
1008 TSQLRow* row=NULL;
1009 row=res->Next();
1010 if (!row )
1011 {
1012 oss1<<"DBError UNABLE to: "<<oss.str().c_str()<<endl;
1013 msg1=oss1.str();
1014 mainLogUtil->logError(msg1);
1015 return 0;
1016 }
1017
1018 idN=atoi(row->GetField(0));
1019 if(row){delete row; row = NULL;}
1020 if(res){delete res; res = NULL;}
1021 return idN;
1022 }
1023
1024
1025 /**********************************************************************************************/
1026 /*###########################################################################################################*/
1027 /********************************** MERGING *************************************************/
1028 /*###########################################################################################################*/
1029 // Merge ROOT files: found other ROOT files in the same temporal ranges
1030 //it finds ROOT files that covers particular temporal range of interest and save this info in DB
1031 /**********************************************************************************************/
1032 /*
1033 bool PacketUser::OLD_merge_ROOTfiles()
1034 {
1035 //do nothing....
1036 //mainLogUtil->logAlways(" Merging functionality doesn't work properly. Try to do it later !!");
1037 //cout<<"DBG: Merging functionality doesn't work properly. Try to do it later !!"<<endl;
1038 //return false;
1039
1040 //TODO: se non ho almeno due packetti buoni non uso
1041 if((numPKTSaved-bad_pkt_EventReader-bad_pkt_CalibReader-bad_pkt)<2){
1042 stringstream oss;
1043 string msg;
1044 oss.str()="";
1045 oss<<"NO ENOUGH GOOD PACKET SAVED in file: "<< rootfilename <<" The group is BAD and don't used in Merging.";
1046
1047 msg = oss.str();
1048 mainLogUtil->logError(msg);
1049 return false;
1050 }
1051
1052 //the ID of the current ROOT file in table Table_ROOT_Good
1053 unsigned int my_id = select_maxIDN_DB(Table_ROOT_Good);
1054 unsigned int n_tot_ass =0;
1055 unsigned int *idN_ass = NULL;
1056 unsigned int num_ass =0;
1057 for(int relaz=AFTER; relaz<=BIGGER; relaz++){
1058 idN_ass = Return_IDN_ASS(real_time_init, real_time_last, (type_Rel_ROOT)relaz, my_id, num_ass);
1059
1060 for(int i=0;i<num_ass;i++)
1061 saveROOT_ASS_DB("ROOT_TABLE_ASS", my_id, idN_ass[i], relaz);//change here
1062
1063 n_tot_ass += num_ass;
1064 num_ass =0;
1065 if(idN_ass){delete[] idN_ass; idN_ass=NULL;}
1066 }
1067
1068 if(n_tot_ass)
1069 {
1070 mainLogUtil->logInfo(" Merged ");
1071 return true;
1072 }
1073 else
1074 {
1075 mainLogUtil->logInfo(" Nothing to Merge ");
1076 return false;
1077 }
1078 }
1079
1080
1081 unsigned int* PacketUser::Return_IDN_ASS(unsigned long int mtime_init, unsigned long int mtime_last, type_Rel_ROOT type_rel, unsigned int my_id, unsigned int &num_ass)
1082 {
1083 unsigned int *idNass = NULL;
1084 stringstream query;
1085 query.str("");
1086
1087 //ordinare in qualche modo
1088 //TODO usare delta_Time: almeno per AFTER e BEFORE ho una certa tolleranza?
1089
1090 if(type_rel == AFTER)
1091 query<<"select ID_N from "<<Table_ROOT_Good<<" where REAL_TIME_LAST = "<< real_time_init<<" and ID_N != " <<my_id;
1092 else if(type_rel == AFTER2)
1093 query<<"select ID_N from "<<Table_ROOT_Good<<" where REAL_TIME_LAST > "<< real_time_init <<" and REAL_TIME_LAST < "<< real_time_last <<" and REAL_TIME_INIT < "<< real_time_init<<" and ID_N != " <<my_id ;
1094 else if(type_rel == BEFORE)
1095 query<<"select ID_N from "<<Table_ROOT_Good<<" where REAL_TIME_INIT = "<< real_time_last<<" and ID_N != " <<my_id ;
1096 else if(type_rel == BEFORE2)
1097 query<<"select ID_N from "<<Table_ROOT_Good<<" where REAL_TIME_INIT > "<< real_time_init <<" and REAL_TIME_INIT < "<< real_time_last <<" and REAL_TIME_LAST > "<< real_time_last <<" and ID_N != " <<my_id ;
1098 else if(type_rel == SMALLER)
1099 query<<"select ID_N from "<<Table_ROOT_Good<<" where REAL_TIME_INIT < "<< real_time_init <<" and REAL_TIME_LAST > "<< real_time_last<<" and ID_N != " <<my_id ;
1100 else if(type_rel == BIGGER)
1101 query<<"select ID_N from "<<Table_ROOT_Good<<" where REAL_TIME_INIT > "<< real_time_init <<" and REAL_TIME_LAST < "<< real_time_last<<" and ID_N != " <<my_id ;
1102 else
1103 return 0;
1104 //TODO: change here ....
1105 query<<" and NUM_PKT_SAVED - BAD_PKT_CALREAD - BAD_PKT_READ - BAD_PKT >= 2" ;
1106 ///cout<<"$$$$$ DBG: "<<query.str().c_str()<<endl;
1107
1108 TSQLResult* res=NULL;
1109 TSQLRow* row=NULL;
1110 unsigned int num_rows=0;
1111
1112 res= sqlServer->Query(query.str().c_str());
1113
1114 stringstream oss1;
1115 oss1.str()="";
1116 string msg1;
1117
1118 if (!res)
1119 {
1120 oss1<<"DBError UNABLE to: "<<query.str().c_str()<<endl;
1121 msg1=oss1.str();
1122 mainLogUtil->logError(msg1);
1123 return 0;
1124 }
1125
1126 num_rows=res->GetRowCount();
1127 if(num_rows>0)
1128 {
1129 idNass = new unsigned int[num_rows];
1130
1131 for(unsigned int i=0; i<num_rows; i++)
1132 {
1133 row=res->Next();
1134 if (!row)
1135 {
1136 oss1<<"DBError UNABLE to: "<<query.str().c_str()<<endl;
1137 msg1=oss1.str();
1138 mainLogUtil->logError(msg1);
1139 return 0;
1140 }
1141 idNass[i]=atoi(row->GetField(0));
1142 stringstream oss2;
1143 oss2.str()="";
1144 oss2<<" my_id "<<my_id<<" ha type_rel = "<<type_rel<<" rispetto: "<<idNass[i];
1145 string msg2 = oss2.str();
1146 mainLogUtil->logAll(msg2);
1147
1148 }
1149 }
1150
1151 if(res){delete res; res = NULL;}
1152 if(row){delete row; row = NULL;}
1153
1154 num_ass=num_rows;
1155 return idNass;
1156 }
1157
1158
1159 //save in Table_ROOT_ASS
1160 bool PacketUser::saveROOT_ASS_DB(char* table_name,
1161 unsigned int my_idn,
1162 unsigned int idn_ass,
1163 int type_ass)
1164 {
1165 stringstream oss;
1166 oss.str("");
1167 oss << "INSERT INTO "<< table_name <<" (ID_N, ROOT_ID_N, ID_N_ASS, TYPE_ASS, INSERT_TIME)"
1168 << " VALUES ('"<<0<< "','" <<my_idn<<"','" <<idn_ass<< "','" << type_ass <<"',"<<"NULL"<<")";
1169
1170 // cout<<"DBG: "<<oss.str().c_str()<<endl;
1171 string msg = oss.str();
1172 mainLogUtil->logAll(msg);
1173
1174 TSQLResult* res=NULL;
1175 res= sqlServer->Query(oss.str().c_str());
1176 stringstream oss1;
1177 oss1.str()="";
1178 string msg1;
1179
1180 if (!res)
1181 {
1182 oss1<<"DBError UNABLE to: "<<oss.str().c_str()<<endl;
1183 msg1=oss1.str();
1184 mainLogUtil->logError(msg1);
1185 return false;
1186 }
1187 if(res){delete res; res = NULL;}
1188 return true;
1189 }
1190
1191 */
1192 /**********************************************************************************************/
1193 //UNUSED: dbg functions...
1194
1195 //Return the system time in ms
1196 unsigned long long PacketUser::Record_Time(){
1197 timeval tv;
1198 gettimeofday(&tv,NULL);
1199 unsigned long long timems = (unsigned long long)tv.tv_sec * (unsigned long long)1000 + tv.tv_usec / 1000;
1200 return timems;
1201 }
1202
1203 //dbg_functions
1204 void PacketUser::saveALL_PKT(char* headerPkt, char* pamPkt, long int length, bool append)
1205 {
1206 char fno[80]="";
1207 ofstream fout;
1208 if(append==true)
1209 {
1210 sprintf(fno,"%s/packets.pkt", outDir);
1211 fout.open(fno, ios::binary | ios::app);
1212 }
1213 else{
1214 sprintf(fno,"%s/packet%d.pkt", outDir, numPKT );
1215 fout.open(fno, ios::binary);
1216 }
1217
1218 if (!fout) {cout<<"can not open output file "<<fno<<endl; return;}
1219 fout.write(headerPkt,LENGTH_HEADER_PKT);
1220 fout.write(pamPkt,length);
1221 fout.close();
1222 }
1223
1224
1225 }

  ViewVC Help
Powered by ViewVC 1.1.23