| 1 |
//============================================================================ |
//============================================================================ |
| 2 |
// $Id: PacketUser.cpp,v 1.7 2009-07-24 13:53:38 mocchiut Exp $ |
// $Id: PacketUser.cpp,v 1.20 2012/03/27 09:50:34 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; |
| 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 |
|
|
| 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; |
| 66 |
last_time_sync_info_prevvalue = 0; |
last_time_sync_info_prevvalue = 0; |
| 67 |
time_is_estimated = false; |
time_is_estimated = false; |
| 68 |
|
|
| 69 |
|
//EM |
| 70 |
|
recoverlimit = 400; |
| 71 |
|
idtorecover = new TArrayI(100); |
| 72 |
|
arsize = 0; |
| 73 |
|
|
| 74 |
real_time_init = 0; |
real_time_init = 0; |
| 75 |
real_time_last = 0; |
real_time_last = 0; |
| 76 |
bad_pkt = 0; |
bad_pkt = 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 |
obt_time_sync_prevvalue = obt_time_sync; |
if ( obt_time_sync ) obt_time_sync_prevvalue = obt_time_sync; // save the last NOT NULL obt_time_sync! EM |
| 263 |
last_time_sync_info_prevvalue = last_time_sync_info; |
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; |
time_is_estimated = false; |
| 265 |
obt_time_sync = 0; |
obt_time_sync = 0; |
| 266 |
last_time_sync_info = 0; |
last_time_sync_info = 0; |
| 275 |
void PacketUser::StartGroup() { |
void PacketUser::StartGroup() { |
| 276 |
pRun = new PamelaRun(rootfilename, gSystem->ExpandPathName(outDir), multiFile, compression); // EMI |
pRun = new PamelaRun(rootfilename, gSystem->ExpandPathName(outDir), multiFile, compression); // EMI |
| 277 |
strcat(rootfilename, ".root"); |
strcat(rootfilename, ".root"); |
| 278 |
|
//if ( !pRun ) printf(" horror! -%s- \n",rootfilename); |
| 279 |
reader->Init(pRun); |
reader->Init(pRun); |
| 280 |
stringstream oss; |
stringstream oss; |
| 281 |
oss.str() = ""; |
oss.str() = ""; |
| 334 |
} |
} |
| 335 |
else if (type == PacketType::Mcmd) { |
else if (type == PacketType::Mcmd) { |
| 336 |
// mainLogUtil->logAll("TODO: Packet Mcmd now is not used to retrieve Absolute time. This may cause problems somewhere."); |
// mainLogUtil->logAll("TODO: Packet Mcmd now is not used to retrieve Absolute time. This may cause problems somewhere."); |
| 337 |
return; |
// return; |
| 338 |
|
offset = -1; |
| 339 |
} |
} |
| 340 |
else { |
else { |
| 341 |
return; |
return; |
| 342 |
} |
} |
| 343 |
|
|
| 344 |
//I don't need to retrieve them again if they are good |
//I don't need to retrieve them again if they are good |
| 345 |
if ((obt_time_sync) || (last_time_sync_info)) |
// if ((obt_time_sync) || (last_time_sync_info)) |
| 346 |
return; |
// return; |
| 347 |
|
// no, do it, since there is a (small indeed) time drift due to different clock of PAMELA CPU and RESURS CPU... |
| 348 |
|
// 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 && !obt_time_sync && !last_time_sync_info ){ // try with inclination mcmd but only if everything else fails and check that the result is good |
| 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 |
|
if ( labs(labs(last_time_sync_info_prevvalue-obt_time_sync_prevvalue)-labs(TSYNC-int(OBT/1000))) > 10 ) return; |
| 524 |
|
}; |
| 525 |
|
if ( !existsts ) return; |
| 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() = ""; |
| 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; |
time_is_estimated = true; |
| 579 |
obt_time_sync = obt_time_sync_prevvalue; |
obt_time_sync = obt_time_sync_prevvalue; |
| 580 |
last_time_sync_info = last_time_sync_info_prevvalue; |
last_time_sync_info = last_time_sync_info_prevvalue; |
| 599 |
} |
} |
| 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(const char * table) { |
unsigned long int PacketUser::retrieveTimeOffset(const char * table) { |
| 636 |
//if(!table){table=Table_GL_RESURS_OFFSET} |
//if(!table){table=Table_GL_RESURS_OFFSET} |
| 637 |
|
|
| 638 |
if (!single_connection) { |
if (!single_connection) { |
| 639 |
OpenDBConnection(table);//Nota qui ho deciso di lockare solo questa tabella e non tutte |
OpenDBConnection(NULL);// no, locak tutto Nota qui ho deciso di lockare solo questa tabella e non tutte |
| 640 |
} |
} |
| 641 |
|
|
| 642 |
UInt_t t0 = 0;//toffset |
UInt_t t0 = 0;//toffset |
| 711 |
setReal_Time(); |
setReal_Time(); |
| 712 |
FinishGroup(rootfilename); |
FinishGroup(rootfilename); |
| 713 |
mainLogUtil->logAll("######################### Closed the last group ############################"); |
mainLogUtil->logAll("######################### Closed the last group ############################"); |
| 714 |
|
// |
| 715 |
if (single_connection) { |
if (single_connection) { |
| 716 |
CloseDBConnection(); |
CloseDBConnection(); |
| 717 |
} |
} |
| 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) { |
if (pRun) { |
| 723 |
pRun->WriteFiles(); |
if ( !( !real_time_init && !real_time_last && numPKTSaved <= recoverlimit ) || !candelete ) pRun->WriteFiles(); |
| 724 |
delete pRun; |
delete pRun; |
| 725 |
pRun = NULL; |
pRun = NULL; |
| 726 |
stringstream close; |
stringstream close; |
| 727 |
close.str() = ""; |
close.str() = ""; |
| 728 |
string msg; |
string msg; |
| 729 |
|
|
| 730 |
close << "######################### Close group in file: " << rootfilename << " ############################"; |
close << "TAG XX ######################### Close group in file: " << rootfilename << " ############################"; |
| 731 |
msg = close.str(); |
msg = close.str(); |
| 732 |
mainLogUtil->logInfo(msg); |
mainLogUtil->logInfo(msg); |
| 733 |
|
|
| 746 |
err << "NO PACKET SAVED in file: " << rootfilename << " The group is empty: you can remove this file."; |
err << "NO PACKET SAVED in file: " << rootfilename << " The group is empty: you can remove this file."; |
| 747 |
msg = err.str(); |
msg = err.str(); |
| 748 |
mainLogUtil->logError(msg); |
mainLogUtil->logError(msg); |
| 749 |
return; |
// return; |
| 750 |
} |
} |
| 751 |
|
|
| 752 |
//se non ho salvato nessun pacchetto buono |
//se non ho salvato nessun pacchetto buono |
| 764 |
OpenDBConnection(NULL);//Nota qui ho deciso di lockare tutte le tabelle |
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 |
//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)) { |
if ((!real_time_init) && (!real_time_last)) { |
| 770 |
//saved in another table for future study |
//saved in another table for future study |
| 786 |
mainLogUtil->logError(msg); |
mainLogUtil->logError(msg); |
| 787 |
} |
} |
| 788 |
|
|
|
if (!single_connection) { |
|
|
CloseDBConnection(); |
|
|
} |
|
| 789 |
|
|
|
return; |
|
|
} |
|
| 790 |
|
|
| 791 |
//saves info in DB in table Table_ROOT_Good |
if ( numPKTSaved > recoverlimit){ // EM |
| 792 |
if (boot_number == 0) |
// |
| 793 |
boot_number = boot_number_prevvalue; |
if ( obt_time_sync && last_time_sync_info ){ |
| 794 |
|
stringstream err; |
| 795 |
if (saveROOT_DB( |
err.str() = ""; |
| 796 |
Table_ROOT_Good, |
err << "(EM): -- RECOVERING WHEN NUMPACKET > "<< recoverlimit <<"!! -- file=<" << filename << ">. We have a previous time sync, immediate recovery!\n"; |
| 797 |
outDir, // here outDir is good, no expand EMI |
msg = err.str(); |
| 798 |
filename, pkt_number_init, pkt_number_last, obt_init, obt_last, obt_time_sync, last_time_sync_info, |
mainLogUtil->logInfo(msg); |
| 799 |
real_time_init, real_time_last, boot_number, timeOffset, bad_pkt, bad_pkt_EventReader, bad_pkt_CalibReader, |
// |
| 800 |
numPKTSaved, fni, time_is_estimated) == true) { |
setReal_TimeRECOVERY( |
| 801 |
oss << "Saved information regarding file: " << filename << " in table " << Table_ROOT_Good << " id= " << my_id; |
real_time_init, |
| 802 |
msg = oss.str(); |
real_time_last, |
| 803 |
mainLogUtil->logInfo(msg); |
obt_init, |
| 804 |
|
obt_last |
| 805 |
if (tryMerge) { |
); |
| 806 |
merge_ROOTfiles(); |
// |
| 807 |
} |
} else { |
| 808 |
} |
stringstream err; |
| 809 |
else { |
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=%lu 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 |
|
if (tryMerge) { |
| 855 |
|
merge_ROOTfiles(); |
| 856 |
|
} |
| 857 |
|
} else { |
| 858 |
|
oss.str() = ""; |
| 859 |
oss << "Problem storing information in DB regarding file: " << filename; |
oss << "Problem storing information in DB regarding file: " << filename; |
| 860 |
msg = oss.str(); |
msg = oss.str(); |
| 861 |
mainLogUtil->logError(msg); |
mainLogUtil->logError(msg); |
| 862 |
} |
} |
| 863 |
|
}; |
| 864 |
|
|
| 865 |
|
// if dbinfo is not empty than |
| 866 |
|
if ( arsize > 0 ){ |
| 867 |
|
|
| 868 |
|
if ( !obt_time_sync || !last_time_sync_info ){ |
| 869 |
|
TString *nomino=new TString(rootfilename); |
| 870 |
|
nomino->Remove(15); |
| 871 |
|
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 |
|
// |
| 873 |
|
oss.str() = ""; |
| 874 |
|
oss << "(EM) Trying to find obt_time_sync and last_time_sync_info from DB, query is: " << qu.Data(); |
| 875 |
|
msg = oss.str(); |
| 876 |
|
mainLogUtil->logInfo(msg); |
| 877 |
|
// |
| 878 |
|
TSQLResult *result = sqlServer->Query(qu.Data()); |
| 879 |
|
TSQLRow *row = result->Next(); |
| 880 |
|
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 |
|
oss.str() = ""; |
| 884 |
|
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 |
|
mainLogUtil->logInfo(msg); |
| 887 |
|
}; |
| 888 |
|
delete nomino; |
| 889 |
|
}; |
| 890 |
|
|
| 891 |
|
if ( obt_time_sync && last_time_sync_info ){ |
| 892 |
|
// if(!m_dbinfos.empty()){ |
| 893 |
|
// while(!m_dbinfos.empty()){ |
| 894 |
|
// dbinfo *app = m_dbinfos.back(); |
| 895 |
|
// m_dbinfos.pop_back(); |
| 896 |
|
Int_t ez=0; |
| 897 |
|
while ( ez < arsize ){ |
| 898 |
|
Int_t eid = idtorecover->At(ez); |
| 899 |
|
if ( eid > -1 ){ |
| 900 |
|
|
| 901 |
|
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 |
|
TSQLRow *row = result->Next(); |
| 904 |
|
|
| 905 |
|
TString efolder_name=""; |
| 906 |
|
TString efile_name=""; |
| 907 |
|
unsigned long int epkt_number_in=0ULL; |
| 908 |
|
unsigned long int epkt_number_fin=0ULL; |
| 909 |
|
unsigned long int eobt_in=0ULL; |
| 910 |
|
unsigned long int eobt_fin=0ULL; |
| 911 |
|
unsigned long int emboot_num=0ULL; |
| 912 |
|
unsigned long int etime_offset=0ULL; |
| 913 |
|
int ebad_pkt=0; |
| 914 |
|
int ebad_pkt_read=0; |
| 915 |
|
int ebad_pkt_CalRead=0; |
| 916 |
|
int enum_PKT_Saved=0; |
| 917 |
|
TString enome_input=""; |
| 918 |
|
bool e_time_is_estimated=false; |
| 919 |
|
|
| 920 |
|
if ( row ){ |
| 921 |
|
efolder_name = (TString)row->GetField(0); |
| 922 |
|
efile_name = (TString)row->GetField(1); |
| 923 |
|
epkt_number_in = (unsigned long int)atoll(row->GetField(2)); |
| 924 |
|
epkt_number_fin = (unsigned long int)atoll(row->GetField(3)); |
| 925 |
|
eobt_in = (unsigned long int)atoll(row->GetField(4)); |
| 926 |
|
eobt_fin = (unsigned long int)atoll(row->GetField(5)); |
| 927 |
|
emboot_num = (unsigned long int)atoll(row->GetField(6)); |
| 928 |
|
etime_offset = (unsigned long int)atoll(row->GetField(7)); |
| 929 |
|
ebad_pkt = (int)atoi(row->GetField(8)); |
| 930 |
|
ebad_pkt_read = (int)atoi(row->GetField(9)); |
| 931 |
|
ebad_pkt_CalRead = (int)atoi(row->GetField(10)); |
| 932 |
|
enum_PKT_Saved = (int)atoi(row->GetField(11)); |
| 933 |
|
enome_input = (TString)row->GetField(12); |
| 934 |
|
e_time_is_estimated = (bool)atoi(row->GetField(13)); |
| 935 |
|
}; |
| 936 |
|
delete result; |
| 937 |
|
|
| 938 |
|
setReal_TimeRECOVERY( |
| 939 |
|
real_time_init, |
| 940 |
|
real_time_last, |
| 941 |
|
eobt_in, |
| 942 |
|
eobt_fin |
| 943 |
|
); |
| 944 |
|
// |
| 945 |
|
|
| 946 |
|
if (saveROOT_DB( |
| 947 |
|
Table_ROOT_Good, |
| 948 |
|
efolder_name.Data(), |
| 949 |
|
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) { |
if (!single_connection) { |
| 1009 |
CloseDBConnection(); |
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(const 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 obt_in, |
unsigned long int pkt_number_in, unsigned long int pkt_number_fin, unsigned long int obt_in, |
| 1047 |
unsigned long int obt_fin, unsigned long int oT_sync, unsigned long int lT_sync_info, unsigned long int mtime_init, |
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 mtime_last, unsigned long int mboot_num, unsigned long int time_offset, int bad_pkt, |
unsigned long int mtime_last, unsigned long int mboot_num, unsigned long int time_offset, int bad_pkt, |
| 1049 |
int bad_pkt_read, int bad_pkt_CalRead, int num_PKT_Saved, char* nome_input, bool _time_is_estimated) { |
int bad_pkt_read, int bad_pkt_CalRead, int num_PKT_Saved, const char* nome_input, bool _time_is_estimated) { |
| 1050 |
//TODO: forse far ritornare ID della cosa appena inserita se e' andatato tutto ok invece che true false? |
//TODO: forse far ritornare ID della cosa appena inserita se e' andatato tutto ok invece che true false? |
| 1051 |
|
|
| 1052 |
|
// 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 |
|
stringstream oss1; |
| 1054 |
|
oss1.str() = ""; |
| 1055 |
|
string msg1; |
| 1056 |
|
stringstream ass; |
| 1057 |
|
ass.str(""); |
| 1058 |
|
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 |
|
TSQLResult* ares = NULL; |
| 1060 |
|
ares = sqlServer->Query(ass.str().c_str()); |
| 1061 |
|
if (!ares) { |
| 1062 |
|
oss1 << "DBError UNABLE to: " << ass.str().c_str() << endl; |
| 1063 |
|
msg1 = oss1.str(); |
| 1064 |
|
mainLogUtil->logError(msg1); |
| 1065 |
|
return false; |
| 1066 |
|
} |
| 1067 |
|
TSQLRow *arow = ares->Next(); |
| 1068 |
|
if ( arow ){ |
| 1069 |
|
TString bla=file_name; |
| 1070 |
|
TString *blabla=new TString(file_name); |
| 1071 |
|
blabla->Remove(15); |
| 1072 |
|
stringstream oss; |
| 1073 |
|
oss.str(""); |
| 1074 |
|
// oss << "UPDATE " << table_name |
| 1075 |
|
// << " 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 |
|
// << "',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 |
|
// << "',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 |
|
oss << " DELETE FROM ROOT_TABLE_BAD WHERE FILE_NAME LIKE '"<<blabla->Data()<<"%';"; |
| 1080 |
|
string msg = oss.str(); |
| 1081 |
|
mainLogUtil->logAll(msg); |
| 1082 |
|
string query; |
| 1083 |
|
|
| 1084 |
|
TSQLResult* res = NULL; |
| 1085 |
|
|
| 1086 |
|
query = oss.str(); |
| 1087 |
|
msg1 = "DeleteROOT_DB_BAD query: "; |
| 1088 |
|
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 |
|
|
| 1125 |
|
|
| 1126 |
|
|
| 1127 |
|
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; |
stringstream oss; |
| 1153 |
oss.str(""); |
oss.str(""); |
| 1154 |
oss << "INSERT INTO " << table_name |
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)" |
<< " (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 << "','" |
<< " VALUES ('" << 0 << "','" << folder_name << "','" << file_name << "','" << pkt_number_in << "','" |
| 1157 |
<< pkt_number_fin << "','" << obt_in << "','" << obt_fin << "','" << oT_sync << "','" << lT_sync_info << "','" |
<< pkt_number_fin << "','" << obt_in << "','" << obt_fin << "','" << oT_sync << "','" << lT_sync_info << "','" |
| 1158 |
<< mtime_init << "','" << mtime_last << "','" << mboot_num << "','" << time_offset << "','" << bad_pkt << "','" |
<< mtime_init << "','" << mtime_last << "','" << mboot_num << "','" << time_offset << "','" << bad_pkt << "','" |
| 1159 |
<< bad_pkt_read << "','" << bad_pkt_CalRead << "','" << num_PKT_Saved << "','" << nome_input << "'," << "NULL," |
<< bad_pkt_read << "','" << bad_pkt_CalRead << "','" << num_PKT_Saved << "','" << nome_input << "'," << "NULL," |
| 1160 |
<< _time_is_estimated << ");"; |
<< _time_is_estimated << ",'" << tag_value << "'" << ");"; |
| 1161 |
string msg = oss.str(); |
string msg = oss.str(); |
| 1162 |
mainLogUtil->logAll(msg); |
mainLogUtil->logAll(msg); |
| 1163 |
|
|
|
stringstream oss1; |
|
|
oss1.str() = ""; |
|
|
string msg1; |
|
| 1164 |
string query; |
string query; |
| 1165 |
|
|
| 1166 |
TSQLResult* res = NULL; |
TSQLResult* res = NULL; |
| 1176 |
msg1 = oss1.str(); |
msg1 = oss1.str(); |
| 1177 |
mainLogUtil->logError(msg1); |
mainLogUtil->logError(msg1); |
| 1178 |
return false; |
return false; |
| 1179 |
|
} else { |
| 1180 |
|
delete res; |
| 1181 |
|
res = NULL; |
| 1182 |
} |
} |
|
|
|
|
//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(); |
|
| 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; |
// cout<<"DBG: my_id = "<<my_id<<endl; |
| 1196 |
if (res) { |
} |
| 1197 |
delete res; |
if (ares) { |
| 1198 |
res = NULL; |
delete ares; |
| 1199 |
|
ares = NULL; |
| 1200 |
} |
} |
| 1201 |
return true; |
return true; |
| 1202 |
} |
} |
| 1450 |
if (type_rel == AFTER) { |
if (type_rel == AFTER) { |
| 1451 |
mainLogUtil->logInfo("Relaz:AFTER = Updating Last values of the DB ROOT file"); |
mainLogUtil->logInfo("Relaz:AFTER = Updating Last values of the DB ROOT file"); |
| 1452 |
//marco_new:tolti tutti gli apici che qui non devono essere |
//marco_new:tolti tutti gli apici che qui non devono essere |
| 1453 |
|
|
| 1454 |
|
int good = 1; |
| 1455 |
|
if ( pkt_number_in >= (pkt_number_init - 1) && abs((int)(pkt_number_in-(pkt_number_init-1)))<10 ) good = 0; |
| 1456 |
|
|
| 1457 |
oss << "UPDATE " << table_name << " SET PKT_NUMBER_FINAL =" << (pkt_number_init - 1) << ", PKT_OBT_FINAL =" |
oss << "UPDATE " << table_name << " SET PKT_NUMBER_FINAL =" << (pkt_number_init - 1) << ", PKT_OBT_FINAL =" |
| 1458 |
<< obt_init << ", REAL_TIME_LAST =" << real_time_init << " WHERE ID_N =" << ID_record << ";"; |
<< obt_init << ", REAL_TIME_LAST =" << real_time_init << ", GOOD="<< good << " WHERE ID_N =" << ID_record << ";"; |
| 1459 |
|
|
| 1460 |
} |
} |
| 1461 |
else if (type_rel == BEFORE) { |
else if (type_rel == BEFORE) { |
| 1462 |
mainLogUtil->logInfo("Relaz:BEFORE = Updating Init values of the DB ROOT file"); |
mainLogUtil->logInfo("Relaz:BEFORE = Updating Init values of the DB ROOT file"); |
| 1463 |
|
|
| 1464 |
|
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 |
|
|
| 1467 |
oss << "UPDATE " << table_name << " SET PKT_NUMBER_INIT =" << (pkt_number_last + 1) << ", PKT_OBT_INIT =" |
oss << "UPDATE " << table_name << " SET PKT_NUMBER_INIT =" << (pkt_number_last + 1) << ", PKT_OBT_INIT =" |
| 1468 |
<< obt_last << ", REAL_TIME_INIT =" << real_time_last << " WHERE ID_N =" << ID_record << ";"; |
<< obt_last << ", REAL_TIME_INIT =" << real_time_last << ", GOOD="<< good << " WHERE ID_N =" << ID_record << ";"; |
| 1469 |
} |
} |
| 1470 |
else if (type_rel == SMALLER) { |
else if (type_rel == SMALLER) { |
| 1471 |
//spezzettamentento |
//spezzettamentento |
| 1472 |
mainLogUtil->logInfo("Relaz:SMALLER = (1st part) Updating Last values of the DB ROOT file"); |
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 =" |
oss << "UPDATE " << table_name << " SET PKT_NUMBER_FINAL=" << (pkt_number_init - 1) << ", PKT_OBT_FINAL =" |
| 1478 |
<< obt_init << ", REAL_TIME_LAST =" << real_time_init << " WHERE ID_N =" << ID_record << ";"; |
<< 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"); |
mainLogUtil->logInfo("Relaz:SMALLER = (2nd part) Saving the second part of the DB ROOT file"); |
| 1481 |
|
|
| 1538 |
else |
else |
| 1539 |
return 0; |
return 0; |
| 1540 |
|
|
| 1541 |
query << " order by REAL_TIME_INIT ASC";//marco_new: inutile |
query << " order by REAL_TIME_INIT ASC;";//marco_new: inutile |
| 1542 |
//se volessi mettere un filtro sulla qualita' |
//se volessi mettere un filtro sulla qualita' |
| 1543 |
// query<<" and NUM_PKT_SAVED - BAD_PKT_CALREAD - BAD_PKT_READ - BAD_PKT >= 2" ; |
// query<<" and NUM_PKT_SAVED - BAD_PKT_CALREAD - BAD_PKT_READ - BAD_PKT >= 2" ; |
| 1544 |
string msg = query.str(); |
string msg = query.str(); |
| 1561 |
unsigned long int pkt_number_fin, unsigned long int obt_in, unsigned long int obt_fin, |
unsigned long int pkt_number_fin, unsigned long int obt_in, unsigned long int obt_fin, |
| 1562 |
unsigned long int mtime_init, unsigned long int mtime_last, unsigned long int mboot_num, double percentage) { |
unsigned long int mtime_init, unsigned long int mtime_last, unsigned long int mboot_num, double percentage) { |
| 1563 |
|
|
| 1564 |
|
int good = 1; |
| 1565 |
|
if ( pkt_number_in >= pkt_number_fin && abs((int)(pkt_number_fin-pkt_number_in))<10 ) good = 0; |
| 1566 |
|
|
| 1567 |
stringstream oss; |
stringstream oss; |
| 1568 |
oss.str(""); |
oss.str(""); |
| 1569 |
oss << "INSERT INTO " << table_name |
oss << "INSERT INTO " << table_name |
| 1570 |
<< " (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)" |
<< " (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 |
<< " VALUES ('" << 0 << "','" << root_id << "','" << pkt_number_in << "','" << pkt_number_fin << "','" << obt_in |
<< " VALUES ('" << 0 << "','" << root_id << "','" << pkt_number_in << "','" << pkt_number_fin << "','" << obt_in |
| 1572 |
<< "','" << obt_fin << "','" << mtime_init << "','" << mtime_last << "','" << mboot_num << "','" << percentage |
<< "','" << obt_fin << "','" << mtime_init << "','" << mtime_last << "','" << mboot_num << "','" << percentage |
| 1573 |
<< "'," << "NULL" << ",'" << tag_value << "'" << ")"; |
<< "'," << "NULL" << ",'" << tag_value << "','" << good <<"');"; |
| 1574 |
|
|
| 1575 |
string msg = oss.str(); |
string msg = oss.str(); |
| 1576 |
mainLogUtil->logAll(msg); |
mainLogUtil->logAll(msg); |
| 1606 |
} |
} |
| 1607 |
|
|
| 1608 |
//Utility: return max(IDN) |
//Utility: return max(IDN) |
| 1609 |
unsigned int PacketUser::select_maxIDN_DB(const 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; |
return 0; |
| 1615 |
TSQLResult* res = NULL; |
TSQLResult* res = NULL; |
| 1616 |
stringstream oss; |
stringstream oss; |
| 1617 |
oss.str(""); |
oss.str(""); |
| 1618 |
oss << "select max(ID_N) from " << table_name; |
oss << "select ID_N from " << table_name << " where FILE_NAME='" << file_name <<"';"; |
| 1619 |
// string msg = oss.str(); |
// string msg = oss.str(); |
| 1620 |
// mainLogUtil->logAll(msg); |
// mainLogUtil->logAll(msg); |
| 1621 |
res = sqlServer->Query(oss.str().c_str()); |
res = sqlServer->Query(oss.str().c_str()); |
| 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 |
oss << "lock table " << Table_ROOT_Good << " write, " << Table_ROOT_Bad << " write, " << Table_GL_RESURS_OFFSET |
| 1673 |
<< " write, " << Table_ROOT_Merging << " write;"; |
<< " write, " << Table_ROOT_Merging << " write;"; |
| 1674 |
else |
// else |
| 1675 |
oss << "lock table " << tableTobeLocked << " write; "; |
// oss << "lock table " << tableTobeLocked << " write; "; |
| 1676 |
|
|
| 1677 |
string msg = oss.str(); |
string msg = oss.str(); |
| 1678 |
mainLogUtil->logAll(msg); |
mainLogUtil->logAll(msg); |
| 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()))) { |
if ((!sqlServer) || (!(sqlServer->IsConnected()))) { |
| 1747 |
cout << "Can not connect with MYSQL sever" << endl; |
cout << "Can not connect with MYSQL sever" << endl; |
| 1748 |
} |
} |
| 1749 |
mainLogUtil->logAll("Connected to DB"); |
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 |
//blocca le tabelle |
| 1755 |
LockTables(tableTobeLocked); |
LockTables(tableTobeLocked); |
| 1756 |
} |
} |