| 1 |
//============================================================================ |
//============================================================================ |
| 2 |
// $Id: PacketUser.cpp,v 1.16 2010/02/02 15:26:09 mocchiut 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" |
| 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; |
| 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... |
// 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 ){ // 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() = ""; |
| 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, const 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 |
| 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 |
|
} |
| 1183 |
} |
} |
|
|
|
| 1184 |
|
|
| 1185 |
if(!strcmp(table_name,Table_ROOT_Good)) { |
if(!strcmp(table_name,Table_ROOT_Good)) { |
| 1186 |
//the ID of the current ROOT file in table Table_ROOT_Good |
//the ID of the current ROOT file in table Table_ROOT_Good |
| 1187 |
my_id = select_maxIDN_DB(table_name); |
my_id = select_maxIDN_DB(table_name,file_name); |
| 1188 |
if (!boot_number) { |
if (!boot_number) { |
| 1189 |
if (id_to_recover_index < 1000) |
if (id_to_recover_index < 1000) |
| 1190 |
id_to_recover[id_to_recover_index++] = my_id; |
id_to_recover[id_to_recover_index++] = my_id; |
| 1192 |
else if (boot_number && id_to_recover_index && !is_new_route) { |
else if (boot_number && id_to_recover_index && !is_new_route) { |
| 1193 |
recover_boot_number(); |
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 |
} |
} |
| 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()); |