| 5 |
* The file contains implementation of the methods to query the DB. |
* The file contains implementation of the methods to query the DB. |
| 6 |
*/ |
*/ |
| 7 |
// |
// |
| 8 |
|
#include <sstream> |
| 9 |
|
#include <iostream> |
| 10 |
|
// |
| 11 |
|
#include <TFile.h> |
| 12 |
|
#include <TTree.h> |
| 13 |
|
#include <TTimeStamp.h> |
| 14 |
|
#include <TTreeCloner.h> |
| 15 |
#include <RunGlue.h> |
#include <RunGlue.h> |
| 16 |
// |
// |
| 17 |
ClassImp(RunGlue); |
ClassImp(RunGlue); |
| 22 |
this->Clear(); |
this->Clear(); |
| 23 |
} |
} |
| 24 |
|
|
| 25 |
RunGlue::RunGlue(TSQLServer *da, UInt_t ru, TString di, TString wrkdi, Bool_t fcas) { |
RunGlue::RunGlue(TSQLServer *da, UInt_t ru, TString di, TString wrkdi) { |
| 26 |
fDBG = false; |
fDBG = false; |
|
castor = fcas; |
|
| 27 |
li = new PamLevel2(); |
li = new PamLevel2(); |
| 28 |
|
// li = 0; |
| 29 |
this->Clear(); |
this->Clear(); |
| 30 |
dbc = da; |
dbc = da; |
| 31 |
run = ru; |
run = ru; |
| 32 |
dir = di; |
dir = di; |
| 33 |
// |
// |
| 34 |
TString wd = gSystem->WorkingDirectory(); |
wd = gSystem->WorkingDirectory(); |
| 35 |
// |
// |
| 36 |
outdir = wrkdi; |
outdir = wrkdi; |
| 37 |
if ( !strcmp(outdir.Data(),"") ) outdir = wd; |
if ( !strcmp(outdir.Data(),"") ) outdir = wd; |
| 42 |
runmode = false; |
runmode = false; |
| 43 |
createlist = true; |
createlist = true; |
| 44 |
}; |
}; |
| 45 |
|
fUpgrade = true; |
| 46 |
// |
// |
| 47 |
// lList = new TList(); |
// lList = new TList(); |
| 48 |
// |
// |
| 49 |
}; |
}; |
| 50 |
|
|
|
|
|
| 51 |
void RunGlue::Clear() { |
void RunGlue::Clear() { |
| 52 |
fEnd = false; |
fEnd = false; |
| 53 |
run = 0; |
run = 0; |
| 76 |
if (list.Contains("+ALL", TString::kIgnoreCase)) RUN = true; |
if (list.Contains("+ALL", TString::kIgnoreCase)) RUN = true; |
| 77 |
// |
// |
| 78 |
fDList = list; |
fDList = list; |
| 79 |
li->SetWhichTrees(fDList); |
// li->SetWhichTrees(fDList); |
| 80 |
// |
// |
| 81 |
if ( DebugMode() ) printf(" Detector list is %s \n",fDList.Data()); |
if ( DebugMode() ) printf(" Detector list is %s \n",fDList.Data()); |
| 82 |
// |
// |
| 83 |
}; |
}; |
| 84 |
|
|
| 85 |
TList *RunGlue::GetRunList(){ |
TList *RunGlue::GetRunList(){ |
| 86 |
// |
// |
| 87 |
lList = new TList(); |
lList = new TList(); |
| 88 |
lList->Clear(); |
lList->Clear(); |
| 89 |
TString thisrun; |
TString thisrun; |
|
// TFile *su; |
|
| 90 |
TFile *su; |
TFile *su; |
| 91 |
// |
// |
| 92 |
TSQLResult *pResult; |
TSQLResult *pResult; |
| 115 |
TTimeStamp *llim = new TTimeStamp(YY,MM,DD,0,0,0,0,true,0); |
TTimeStamp *llim = new TTimeStamp(YY,MM,DD,0,0,0,0,true,0); |
| 116 |
// |
// |
| 117 |
UInt_t lowerlimit = llim->GetSec(); |
UInt_t lowerlimit = llim->GetSec(); |
| 118 |
UInt_t upperlimit = lowerlimit + 86401; |
UInt_t upperlimit = lowerlimit + 86400; |
| 119 |
// |
// |
| 120 |
if ( DebugMode() ) printf(" YY %u MM %u DD %u ll %u ul %u \n",YY,MM,DD,lowerlimit,upperlimit); |
if ( DebugMode() ) printf(" YY %u MM %u DD %u ll %u ul %u \n",YY,MM,DD,lowerlimit,upperlimit); |
| 121 |
// |
// |
| 170 |
// |
// |
| 171 |
if ( DebugMode() ) printf(" Filename is %s \n",thisrun.Data()); |
if ( DebugMode() ) printf(" Filename is %s \n",thisrun.Data()); |
| 172 |
// |
// |
|
//su = TFile::Open(thisrun); |
|
| 173 |
su = TFile::Open(thisrun); |
su = TFile::Open(thisrun); |
| 174 |
if ( li->CheckLevel2File(thisrun) ){ |
if ( li->CheckLevel2File(thisrun) ){ |
| 175 |
lList->Add(su); |
lList->Add(su); |
| 176 |
} else { |
} else { |
| 177 |
if ( DebugMode() ) printf(" RUN %s DISCARDED \n",Row->GetField(0)); |
if ( DebugMode() ) printf(" RUN %s DISCARDED \n",Row->GetField(0)); |
| 178 |
}; |
}; |
| 179 |
// |
// |
| 180 |
}; |
}; |
| 213 |
if ( DebugMode() ) printf(" fullpath = %s name %s \n",fullpath.Data(),name.Data()); |
if ( DebugMode() ) printf(" fullpath = %s name %s \n",fullpath.Data(),name.Data()); |
| 214 |
// |
// |
| 215 |
// |
// |
|
//su = TFile::Open(fullpath); |
|
| 216 |
su = TFile::Open(fullpath); |
su = TFile::Open(fullpath); |
| 217 |
if ( li->CheckLevel2File((TString)fullpath) ){ |
if ( li->CheckLevel2File((TString)fullpath) ){ |
| 218 |
fList->Add(su); |
fList->Add(su); |
| 282 |
TTimeStamp *llim = new TTimeStamp(YY,MM,DD,0,0,0,0,true,0); |
TTimeStamp *llim = new TTimeStamp(YY,MM,DD,0,0,0,0,true,0); |
| 283 |
// |
// |
| 284 |
UInt_t lowerlimit = llim->GetSec(); |
UInt_t lowerlimit = llim->GetSec(); |
| 285 |
UInt_t upperlimit = lowerlimit + 86401; |
UInt_t upperlimit = lowerlimit + 86400; |
| 286 |
// |
// |
| 287 |
if ( DebugMode() ) printf(" YY %u MM %u DD %u ll %u ul %u \n",YY,MM,DD,lowerlimit,upperlimit); |
if ( DebugMode() ) printf(" YY %u MM %u DD %u ll %u ul %u \n",YY,MM,DD,lowerlimit,upperlimit); |
| 288 |
// |
// |
| 336 |
// |
// |
| 337 |
su = TFile::Open(thisrun); |
su = TFile::Open(thisrun); |
| 338 |
if ( su ){ |
if ( su ){ |
|
// TFile *su0 = TFile::Open(thisrun); |
|
| 339 |
TFile *su0 = TFile::Open(thisrun); |
TFile *su0 = TFile::Open(thisrun); |
| 340 |
fDoneList->Add(su0); |
fDoneList->Add(su0); |
| 341 |
fNlistdone++; |
fNlistdone++; |
| 381 |
|
|
| 382 |
Bool_t RunGlue::OpenFile(){ |
Bool_t RunGlue::OpenFile(){ |
| 383 |
// |
// |
|
ifstream myfile; |
|
|
TString thename; |
|
|
// |
|
|
Bool_t exi = false; |
|
| 384 |
fOpen = false; |
fOpen = false; |
| 385 |
thename = Form("rfio://%s",(this->GetFilename()).Data()); |
printf(" Check if output file already exists \n"); |
| 386 |
Target = 0; |
ifstream myfile; |
| 387 |
if ( castor ){ |
myfile.open((this->GetFilename()).Data()); |
| 388 |
Target = new TRFIOFile(thename.Data(),"READ","",1); |
if ( myfile ){ |
|
if ( !Target->IsZombie()) exi = true; |
|
|
} else { |
|
|
// thename = Form("rfio://%s",(this->GetFilename()).Data()); |
|
|
printf(" Check if output file already exists \n"); |
|
|
myfile.open((this->GetFilename()).Data()); |
|
|
if ( myfile ) exi = true; |
|
|
}; |
|
|
if ( exi ){ |
|
| 389 |
// Target = TFile::Open((this->GetFilename()).Data(), "READ" ); |
// Target = TFile::Open((this->GetFilename()).Data(), "READ" ); |
| 390 |
// |
// |
| 391 |
// if ( Target ){ |
// if ( Target ){ |
| 392 |
// Target->Close(); |
// Target->Close(); |
| 393 |
if ( myfile ) myfile.close(); |
myfile.close(); |
| 394 |
// |
printf("Error opening target file, %s already exist!\n",(this->GetFilename()).Data()); |
|
if ( Target ) Target->Close(); |
|
|
// |
|
|
printf("Error opening target file, %s already exist!\n",thename.Data()); |
|
| 395 |
return(false); |
return(false); |
|
// |
|
| 396 |
} else { |
} else { |
| 397 |
// |
// |
| 398 |
|
// try to lock tables and work on a db level to avoid multiple file simultaneous access |
| 399 |
|
// |
| 400 |
|
stringstream oss; |
| 401 |
|
// |
| 402 |
|
if ( fUpgrade ){ |
| 403 |
|
oss.str(""); |
| 404 |
|
oss << "lock table GL_ROOT write;"; |
| 405 |
|
TSQLResult *result = 0; |
| 406 |
|
TSQLRow *row = 0; |
| 407 |
|
result = dbc->Query(oss.str().c_str()); |
| 408 |
|
oss.str(""); |
| 409 |
|
oss << "select ID from GL_ROOT where NAME='" << ((TString)gSystem->BaseName(this->GetFilename())).Data() << "';"; |
| 410 |
|
result = dbc->Query(oss.str().c_str()); |
| 411 |
|
row = result->Next(); |
| 412 |
|
if ( row ){ |
| 413 |
|
printf("Error opening target file (does %s exist? already in the DB? are the permissions ok?)\n",(this->GetFilename()).Data()); |
| 414 |
|
return(false); |
| 415 |
|
} else { |
| 416 |
|
oss.str(""); |
| 417 |
|
oss << "insert into GL_ROOT (PATH,NAME) values ('$PAM_L2','" << ((TString)gSystem->BaseName(this->GetFilename())).Data() << "');"; |
| 418 |
|
result = dbc->Query(oss.str().c_str()); |
| 419 |
|
}; |
| 420 |
|
oss.str(""); |
| 421 |
|
oss << "unlock tables;"; |
| 422 |
|
result = dbc->Query(oss.str().c_str()); |
| 423 |
|
}; |
| 424 |
|
// Target = TFile::Open((this->GetFilename()).Data(), "RECREATE" ); |
| 425 |
|
Target = TFile::Open((this->GetFilename()).Data(), "NEW" ); |
| 426 |
|
// |
| 427 |
printf(" Output file does not exist, creating it\n"); |
printf(" Output file does not exist, creating it\n"); |
| 428 |
// |
// |
| 429 |
Long64_t maxsize = 99900000000LL; |
Long64_t maxsize = 99900000000LL; |
| 430 |
// |
// |
| 431 |
Target = new TRFIOFile(thename.Data(), "RECREATE", "", 2 ); |
if ( !Target || Target->IsZombie()) { |
| 432 |
// Target = TFile::Open((this->GetFilename()).Data(), "RECREATE" ); |
printf("Error opening target file (does %s exist? are the permissions ok?)\n",(this->GetFilename()).Data()); |
| 433 |
|
// exit(1); |
| 434 |
|
return(false); |
| 435 |
|
} |
| 436 |
|
// |
| 437 |
|
Target->Write(); |
| 438 |
// |
// |
| 439 |
//fastMethod = kTRUE; |
//fastMethod = kTRUE; |
| 440 |
fastMethod = kFALSE; |
fastMethod = kFALSE; |
| 441 |
// |
// |
|
// |
|
|
if ( !Target || Target->IsZombie()) { |
|
|
printf("Error opening target file (does %s exist?)\n",thename.Data()); |
|
|
exit(1); |
|
|
} |
|
| 442 |
// |
// |
| 443 |
TTree::SetMaxTreeSize(maxsize); |
TTree::SetMaxTreeSize(maxsize); |
| 444 |
Target->SetCompressionLevel(2); |
// Target->SetCompressionLevel(2); |
| 445 |
|
Target->SetCompressionLevel(3); |
| 446 |
|
//Target->SetCompressionLevel(5); |
| 447 |
// |
// |
| 448 |
fOpen = true; |
fOpen = true; |
| 449 |
return(true); |
return(true); |
| 505 |
}; |
}; |
| 506 |
// |
// |
| 507 |
myquery.str(""); |
myquery.str(""); |
|
// myquery << "insert into GL_ROOT (ID_RAW,PATH,NAME) values (" << idr << ",'" << outdir.Data() << "','" << ((TString)gSystem->BaseName(this->GetFilename())).Data() << "');"; |
|
|
myquery << "insert into GL_ROOT (ID_RAW,PATH,NAME) values (" << idr << ",'$PAM_L2','" << ((TString)gSystem->BaseName(this->GetFilename())).Data() << "');"; |
|
|
if ( DebugMode() ) printf(" query is %s \n",myquery.str().c_str()); |
|
|
// |
|
|
pResult = dbc->Query(myquery.str().c_str()); |
|
|
if ( !pResult ){ |
|
|
printf(" ERROR WRITING ON DB!\n"); |
|
|
return; |
|
|
}; |
|
|
myquery.str(""); |
|
| 508 |
myquery << "select ID from GL_ROOT where NAME='" << ((TString)gSystem->BaseName(this->GetFilename())).Data() << "';"; |
myquery << "select ID from GL_ROOT where NAME='" << ((TString)gSystem->BaseName(this->GetFilename())).Data() << "';"; |
| 509 |
if ( DebugMode() ) printf(" query is %s \n",myquery.str().c_str()); |
if ( DebugMode() ) printf(" query is %s \n",myquery.str().c_str()); |
| 510 |
// |
// |
| 520 |
} else { |
} else { |
| 521 |
idl2 = (UInt_t)atoll(Row->GetField(0)); |
idl2 = (UInt_t)atoll(Row->GetField(0)); |
| 522 |
}; |
}; |
| 523 |
|
myquery.str(""); |
| 524 |
|
// myquery << "insert into GL_ROOT (ID_RAW,PATH,NAME) values (" << idr << ",'" << outdir.Data() << "','" << ((TString)gSystem->BaseName(this->GetFilename())).Data() << "');"; |
| 525 |
|
// myquery << "insert into GL_ROOT (ID_RAW,PATH,NAME) values (" << idr << ",'$PAM_L2','" << ((TString)gSystem->BaseName(this->GetFilename())).Data() << "');"; |
| 526 |
|
myquery << "update GL_ROOT set ID_RAW=" << idr << " where ID=" << idl2 << ";"; |
| 527 |
|
if ( DebugMode() ) printf(" query is %s \n",myquery.str().c_str()); |
| 528 |
|
// |
| 529 |
|
pResult = dbc->Query(myquery.str().c_str()); |
| 530 |
|
if ( !pResult ){ |
| 531 |
|
printf(" ERROR WRITING ON DB!\n"); |
| 532 |
|
return; |
| 533 |
|
}; |
| 534 |
// |
// |
| 535 |
// |
// |
| 536 |
// |
// |
| 563 |
// |
// |
| 564 |
void RunGlue::MergeRootfile(TList *sourcelist) { |
void RunGlue::MergeRootfile(TList *sourcelist) { |
| 565 |
// |
// |
| 566 |
merged = false; |
merged = true; |
|
// |
|
|
TDirectory *target = Target; |
|
|
// |
|
|
if ( DebugMode() ) printf("\nTarget path is: %s \n",target->GetPath()); |
|
|
// |
|
|
TString path; |
|
|
//if ( castor ){ |
|
|
path = TString(":/"); |
|
|
// } else { |
|
|
// path = TString( (char*)strstr( target->GetPath(), ":" ) ); |
|
|
// }; |
|
|
path.Remove(0,2); |
|
|
if ( DebugMode() ) printf("path is %s \n",path.Data()); |
|
| 567 |
// |
// |
| 568 |
TDirectory *first_source = (TDirectory*)sourcelist->First(); |
// if ( li ) li->Delete(); |
| 569 |
THashList allNames; |
PamLevel2 *nli = new PamLevel2(wd,sourcelist,fDList); |
| 570 |
// |
nli->SetSELLI(2); |
| 571 |
while ( first_source ){ |
// |
| 572 |
// |
Target->cd(); |
| 573 |
TDirectory *current_sourcedir = first_source->GetDirectory(path); |
// |
| 574 |
// |
nli->CreateCloneTrees(Target); |
| 575 |
if ( !current_sourcedir ){ |
// |
| 576 |
first_source = (TDirectory*)sourcelist->After(first_source); |
/* nli->GetCloneTree("Tracker")->SetAutoSave(900000000000000LL); |
| 577 |
continue; |
nli->GetCloneTree("Trigger")->SetAutoSave(900000000000000LL); |
| 578 |
|
nli->GetCloneTree("Calorimeter")->SetAutoSave(900000000000000LL); |
| 579 |
|
nli->GetCloneTree("S4")->SetAutoSave(900000000000000LL); |
| 580 |
|
nli->GetCloneTree("Anticounter")->SetAutoSave(900000000000000LL); |
| 581 |
|
nli->GetCloneTree("NeutronD")->SetAutoSave(900000000000000LL); |
| 582 |
|
nli->GetCloneTree("OrbitalInfo")->SetAutoSave(900000000000000LL); |
| 583 |
|
nli->GetCloneTree("Run")->SetAutoSave(900000000000000LL); |
| 584 |
|
nli->GetCloneTree("ToF")->SetAutoSave(900000000000000LL);*/ |
| 585 |
|
// |
| 586 |
|
ULong64_t nevents = nli->GetEntries(); |
| 587 |
|
printf(" NEVENTS %llu \n",nevents); |
| 588 |
|
for(ULong64_t iev=0; iev<nevents; iev++){ |
| 589 |
|
nli->Clear(); |
| 590 |
|
if( nli->GetEntry(iev) ){ |
| 591 |
|
nli->FillCloneTrees(); |
| 592 |
|
}; |
| 593 |
|
}; |
| 594 |
|
Target->cd(); |
| 595 |
|
nli->WriteCloneTrees(); |
| 596 |
|
printf("Written file %s \n",Target->GetName()); |
| 597 |
|
// Target->Write(); |
| 598 |
|
// TTree *slist = (TTree*)Target->Get("SelectionList"); |
| 599 |
|
// slist->Delete("all"); |
| 600 |
|
if ( !nli->GetCloneTree("ProcessingInfo") ){ |
| 601 |
|
TChain *P = new TChain("ProcessingInfo"); |
| 602 |
|
// loop over files and create chains |
| 603 |
|
TIter next(sourcelist); |
| 604 |
|
TSystemFile *questo = 0; |
| 605 |
|
while ((questo = (TSystemFile*) next())) { |
| 606 |
|
TString name = questo->GetName(); |
| 607 |
|
P->Add(name); |
| 608 |
} |
} |
| 609 |
// |
TTree *Pclone = P->CloneTree(); |
| 610 |
// loop over all keys in this directory |
Target->cd(); |
| 611 |
// |
Pclone->Write("ProcessingInfo",TObject::kOverwrite); |
| 612 |
TChain *globChain = 0; |
P->Delete(); |
| 613 |
TIter nextkey( current_sourcedir->GetListOfKeys() ); |
P=0; |
| 614 |
TKey *key = 0; |
} |
| 615 |
TKey *oldkey = 0; |
// |
| 616 |
TH1::AddDirectory(kFALSE); // gain time, do not add the objects in the list in memory |
Target->Close(); |
| 617 |
// |
|
| 618 |
while ( (key = (TKey*)nextkey()) ) { |
// // |
| 619 |
// |
// TDirectory *target = Target; |
| 620 |
// printf(" target ls \n"); |
// // |
| 621 |
// Target->ls(); |
// if ( DebugMode() ) printf("\nTarget path is: %s \n",target->GetPath()); |
| 622 |
// |
// // |
| 623 |
if ( current_sourcedir == target ) break; |
// TString path( (char*)strstr( target->GetPath(), ":" ) ); |
| 624 |
// |
// path.Remove(0,2); |
| 625 |
if ( oldkey && !strcmp(oldkey->GetName(),key->GetName()) ) continue; //keep only the highest cycle number for each key |
// // |
| 626 |
// |
// TDirectory *first_source = (TDirectory*)sourcelist->First(); |
| 627 |
if ( allNames.FindObject(key->GetName()) ) continue; |
// THashList allNames; |
| 628 |
// |
// // |
| 629 |
if ( DebugMode() ) printf(" Key name is -%s- \n",key->GetName()); |
// while ( first_source ){ |
| 630 |
// |
// // |
| 631 |
// |
// TDirectory *current_sourcedir = first_source->GetDirectory(path); |
| 632 |
// |
// // |
| 633 |
if ( !strcmp(key->GetName(),"Tracker") && !li->IsTRK2() && !li->IsTRK1() && !li->IsTRKh() ) continue; |
// if ( !current_sourcedir ){ |
| 634 |
// |
// first_source = (TDirectory*)sourcelist->After(first_source); |
| 635 |
if ( !strcmp(key->GetName(),"Calorimeter") && !li->IsCAL2() && !li->IsCAL1() ) continue; |
// continue; |
| 636 |
// |
// } |
| 637 |
if ( !strcmp(key->GetName(),"ToF") && !li->IsTOF() ) continue; |
// // |
| 638 |
// |
// // loop over all keys in this directory |
| 639 |
if ( !strcmp(key->GetName(),"Trigger") && !li->IsTRG() ) continue; |
// // |
| 640 |
// |
// TChain *globChain = 0; |
| 641 |
if ( !strcmp(key->GetName(),"Anticounter") && !li->IsAC() ) continue; |
// TIter nextkey( current_sourcedir->GetListOfKeys() ); |
| 642 |
// |
// TKey *key = 0; |
| 643 |
if ( !strcmp(key->GetName(),"S4") && !li->IsS4() ) continue; |
// TKey *oldkey = 0; |
| 644 |
// |
// TH1::AddDirectory(kFALSE); // gain time, do not add the objects in the list in memory |
| 645 |
if ( !strcmp(key->GetName(),"NeutronD") && !li->IsND() ) continue; |
// // |
| 646 |
// |
// while ( (key = (TKey*)nextkey()) ) { |
| 647 |
if ( !strcmp(key->GetName(),"OrbitalInfo") && !li->IsORB() ) continue; |
// // |
| 648 |
// |
// // printf(" target ls \n"); |
| 649 |
if ( !strcmp(key->GetName(),"Run") && !li->IsRUN() ) continue; |
// // Target->ls(); |
| 650 |
// |
// // |
| 651 |
if ( strcmp(key->GetName(),"Calorimeter") && strcmp(key->GetName(),"Tracker") && strcmp(key->GetName(),"ToF") && strcmp(key->GetName(),"Trigger") && strcmp(key->GetName(),"Anticounter") && strcmp(key->GetName(),"S4") && strcmp(key->GetName(),"NeutronD") && strcmp(key->GetName(),"OrbitalInfo") && strcmp(key->GetName(),"Run") && strcmp(key->GetName(),"ProcessID0") ){ |
// if ( current_sourcedir == target ) break; |
| 652 |
if ( DebugMode() ) printf(" ERROR UNKNOWN KEY %s !\n",key->GetName()); |
// // |
| 653 |
continue; |
// if ( oldkey && !strcmp(oldkey->GetName(),key->GetName()) ) continue; //keep only the highest cycle number for each key |
| 654 |
}; |
// // |
| 655 |
// |
// if ( allNames.FindObject(key->GetName()) ) continue; |
| 656 |
allNames.Add(new TObjString(key->GetName())); |
// // |
| 657 |
// |
// if ( DebugMode() ) printf(" Key name is -%s- \n",key->GetName()); |
| 658 |
// read object from first source file |
// // |
| 659 |
// |
// // |
| 660 |
current_sourcedir->cd(); |
// // |
| 661 |
TObject *obj = key->ReadObj(); |
// if ( !strcmp(key->GetName(),"Tracker") && !li->IsTRK2() && !li->IsTRK1() && !li->IsTRKh() ) continue; |
| 662 |
// |
// // |
| 663 |
if ( obj->IsA()->InheritsFrom("TTree") ){ |
// if ( !strcmp(key->GetName(),"Calorimeter") && !li->IsCAL2() && !li->IsCAL1() ) continue; |
| 664 |
// |
// // |
| 665 |
// loop over all source files create a chain of Trees "globChain" |
// if ( !strcmp(key->GetName(),"ToF") && !li->IsTOF() ) continue; |
| 666 |
// |
// // |
| 667 |
TString obj_name; |
// if ( !strcmp(key->GetName(),"Trigger") && !li->IsTRG() ) continue; |
| 668 |
// |
// // |
| 669 |
if ( path.Length() ) { |
// if ( !strcmp(key->GetName(),"Anticounter") && !li->IsAC() ) continue; |
| 670 |
obj_name = path + "/" + obj->GetName(); |
// // |
| 671 |
} else { |
// if ( !strcmp(key->GetName(),"S4") && !li->IsS4() ) continue; |
| 672 |
obj_name = obj->GetName(); |
// // |
| 673 |
}; |
// if ( !strcmp(key->GetName(),"NeutronD") && !li->IsND() ) continue; |
| 674 |
// |
// // |
| 675 |
globChain = new TChain(obj_name); |
// if ( !strcmp(key->GetName(),"OrbitalInfo") && !li->IsORB() ) continue; |
| 676 |
// |
// // |
| 677 |
globChain->SetCacheSize(0); |
// if ( !strcmp(key->GetName(),"Run") && !li->IsRUN() ) continue; |
| 678 |
// |
// // |
| 679 |
globChain->Add(first_source->GetName()); |
// if ( strcmp(key->GetName(),"Calorimeter") && strcmp(key->GetName(),"Tracker") && strcmp(key->GetName(),"ToF") && strcmp(key->GetName(),"Trigger") && strcmp(key->GetName(),"Anticounter") && strcmp(key->GetName(),"S4") && strcmp(key->GetName(),"NeutronD") && strcmp(key->GetName(),"OrbitalInfo") && strcmp(key->GetName(),"Run") && strcmp(key->GetName(),"ProcessID0") ){ |
| 680 |
// |
// if ( DebugMode() ) printf(" ERROR UNKNOWN KEY %s !\n",key->GetName()); |
| 681 |
// TFile *nextsource = (TFile*)sourcelist->After( first_source ); |
// continue; |
| 682 |
TFile *nextsource = (TFile*)sourcelist->After( first_source ); |
// }; |
| 683 |
// |
// // |
| 684 |
while ( nextsource ) { |
// printf(" 1 \n"); |
| 685 |
// |
// allNames.Add(new TObjString(key->GetName())); |
| 686 |
//do not add to the list a file that does not contain this Tree |
// printf(" 2 \n"); |
| 687 |
// |
// // |
| 688 |
TFile *curf = TFile::Open(nextsource->GetName()); |
// // read object from first source file |
| 689 |
// TFile *curf = TFile::Open(nextsource->GetName()); |
// // |
| 690 |
// |
// current_sourcedir->cd(); |
| 691 |
if ( curf ) { |
// TObject *obj = key->ReadObj(); |
| 692 |
// |
// printf(" 3 \n"); |
| 693 |
Bool_t mustAdd = kFALSE; |
// // |
| 694 |
// |
// if ( obj->IsA()->InheritsFrom("TTree") ){ |
| 695 |
if (curf->FindKey(obj_name)) { |
// // |
| 696 |
// |
// // loop over all source files create a chain of Trees "globChain" |
| 697 |
mustAdd = kTRUE; |
// // |
| 698 |
// |
// TString obj_name; |
| 699 |
} else { |
// printf(" 4 \n"); |
| 700 |
// |
// // |
| 701 |
//we could be more clever here. No need to import the object |
// if ( path.Length() ) { |
| 702 |
//we are missing a function in TDirectory |
// obj_name = path + "/" + obj->GetName(); |
| 703 |
// |
// } else { |
| 704 |
TObject *aobj = curf->Get(obj_name); |
// obj_name = obj->GetName(); |
| 705 |
// |
// }; |
| 706 |
if ( aobj ){ |
// // |
| 707 |
mustAdd = kTRUE; |
// globChain = new TChain(obj_name); |
| 708 |
delete aobj; |
// // |
| 709 |
}; |
// globChain->SetCacheSize(0); |
| 710 |
}; |
// // |
| 711 |
if (mustAdd) { |
// printf(" 5 \n"); |
| 712 |
globChain->Add(nextsource->GetName()); |
// globChain->Add(first_source->GetName()); |
| 713 |
}; |
// printf(" 6 \n"); |
| 714 |
}; |
// // |
| 715 |
delete curf; |
// TFile *nextsource = (TFile*)sourcelist->After( first_source ); |
| 716 |
nextsource = (TFile*)sourcelist->After(nextsource); |
// // |
| 717 |
}; |
// while ( nextsource ) { |
| 718 |
// |
// // |
| 719 |
delete nextsource; |
// //do not add to the list a file that does not contain this Tree |
| 720 |
// |
// // |
| 721 |
} else { |
// printf(" 7 \n"); |
| 722 |
// |
// TFile *curf = TFile::Open(nextsource->GetName()); |
| 723 |
// object is of no type that we know or can handle |
// // |
| 724 |
// |
// if ( curf ) { |
| 725 |
if ( DebugMode() ) cout << "Unknown object type, name: " |
// // |
| 726 |
<< obj->GetName() << " title: " << obj->GetTitle() << endl; |
// Bool_t mustAdd = kFALSE; |
| 727 |
}; |
// // |
| 728 |
// |
// if (curf->FindKey(obj_name)) { |
| 729 |
// now write the merged histogram (which is "in" obj) to the target file |
// // |
| 730 |
// note that this will just store obj in the current directory level, |
// mustAdd = kTRUE; |
| 731 |
// which is not persistent until the complete directory itself is stored |
// // |
| 732 |
// by "target->Write()" below |
// } else { |
| 733 |
// |
// // |
| 734 |
if ( obj ){ |
// //we could be more clever here. No need to import the object |
| 735 |
// |
// //we are missing a function in TDirectory |
| 736 |
target->cd(); |
// // |
| 737 |
// |
// TObject *aobj = curf->Get(obj_name); |
| 738 |
if( obj->IsA()->InheritsFrom("TTree") ) { |
// // |
| 739 |
// |
// if ( aobj ){ |
| 740 |
Long64_t nfiles = 0; |
// mustAdd = kTRUE; |
| 741 |
if ( fastMethod ){ |
// delete aobj; |
| 742 |
// globChain->Merge(target->GetFile(),0,"C keep fast"); |
// }; |
| 743 |
nfiles=this->Mergy((TChain*)globChain,target->GetFile(),0,"C keep fast"); |
// }; |
| 744 |
} else { |
// if (mustAdd) { |
| 745 |
//globChain->Merge(target->GetFile(),0,"C keep"); |
// printf(" 8 \n"); |
| 746 |
nfiles=this->Mergy((TChain*)globChain,target->GetFile(),0,"C keep"); |
// globChain->Add(nextsource->GetName()); |
| 747 |
}; |
// printf(" 9 \n"); |
| 748 |
// |
// }; |
| 749 |
merged = true; |
// }; |
| 750 |
// |
// delete curf; |
| 751 |
if ( DebugMode() ){ |
// nextsource = (TFile*)sourcelist->After(nextsource); |
| 752 |
printf(" Merged %i files\n",(int)nfiles); |
// }; |
| 753 |
globChain->ls(); |
// // |
| 754 |
}; |
// printf(" 10 \n"); |
| 755 |
// |
// delete nextsource; |
| 756 |
delete globChain; |
// printf(" 11 \n"); |
| 757 |
// return; |
// // |
| 758 |
// |
// } else { |
| 759 |
} else { |
// // |
| 760 |
// |
// // object is of no type that we know or can handle |
| 761 |
// obj->Write( key->GetName() ); // <================================================================================== |
// // |
| 762 |
// |
// if ( DebugMode() ) cout << "Unknown object type, name: " |
| 763 |
}; |
// << obj->GetName() << " title: " << obj->GetTitle() << endl; |
| 764 |
}; |
// }; |
| 765 |
delete obj; |
// // |
| 766 |
oldkey = key; |
// // now write the merged histogram (which is "in" obj) to the target file |
| 767 |
}; |
// // note that this will just store obj in the current directory level, |
| 768 |
// |
// // which is not persistent until the complete directory itself is stored |
| 769 |
first_source = (TDirectory*)sourcelist->After(first_source); |
// // by "target->Write()" below |
| 770 |
// |
// // |
| 771 |
}; |
// printf(" 12 \n"); |
| 772 |
// save modifications to target file |
// if ( obj ){ |
| 773 |
// |
// // |
| 774 |
target->SaveSelf(kTRUE); |
// target->cd(); |
| 775 |
// |
// // |
| 776 |
|
// if( obj->IsA()->InheritsFrom("TTree") ) { |
| 777 |
|
// // |
| 778 |
|
// Long64_t nfiles = 0; |
| 779 |
|
// if ( fastMethod ){ |
| 780 |
|
// // globChain->Merge(target->GetFile(),0,"C keep fast"); |
| 781 |
|
// nfiles=this->Mergy((TChain*)globChain,target->GetFile(),0,"C keep fast"); |
| 782 |
|
// } else { |
| 783 |
|
// //globChain->Merge(target->GetFile(),0,"C keep"); |
| 784 |
|
// printf(" 13 %llu \n",globChain->GetEntries()); |
| 785 |
|
// nfiles=this->Mergy((TChain*)globChain,target->GetFile(),0,"C keep"); |
| 786 |
|
// printf(" 14 \n"); |
| 787 |
|
// }; |
| 788 |
|
// // |
| 789 |
|
// merged = true; |
| 790 |
|
// // |
| 791 |
|
// if ( DebugMode() ){ |
| 792 |
|
// printf(" Merged %i files\n",(int)nfiles); |
| 793 |
|
// globChain->ls(); |
| 794 |
|
// }; |
| 795 |
|
// // |
| 796 |
|
// delete globChain; |
| 797 |
|
// // return; |
| 798 |
|
// // |
| 799 |
|
// } else { |
| 800 |
|
// // |
| 801 |
|
// // obj->Write( key->GetName() ); // <================================================================================== |
| 802 |
|
// // |
| 803 |
|
// }; |
| 804 |
|
// }; |
| 805 |
|
// delete obj; |
| 806 |
|
// oldkey = key; |
| 807 |
|
// }; |
| 808 |
|
// // |
| 809 |
|
// first_source = (TDirectory*)sourcelist->After(first_source); |
| 810 |
|
// // |
| 811 |
|
// }; |
| 812 |
|
// // save modifications to target file |
| 813 |
|
// // |
| 814 |
|
// target->SaveSelf(kTRUE); |
| 815 |
|
// // |
| 816 |
}; |
}; |
| 817 |
|
|
| 818 |
|
|
| 819 |
//Long64_t RunGlue::Mergy(TChain *mychain, TFile* file, Int_t basketsize, Option_t* option){ |
// Long64_t RunGlue::Mergy(TChain *mychain, TFile* file, Int_t basketsize, Option_t* option){ |
| 820 |
Long64_t RunGlue::Mergy(TChain *mychain, TFile* file, Int_t basketsize, Option_t* option){ |
// // We must have been passed a file, we will use it |
| 821 |
// We must have been passed a file, we will use it |
// // later to reset the compression level of the branches. |
| 822 |
// later to reset the compression level of the branches. |
// if (!file) { |
| 823 |
if (!file) { |
// // FIXME: We need an error message here. |
| 824 |
// FIXME: We need an error message here. |
// printf(" 19 \n"); |
| 825 |
return 0; |
// return 0; |
| 826 |
} |
// } |
| 827 |
|
// printf(" 20 \n"); |
| 828 |
// Options |
|
| 829 |
Bool_t fastClone = kFALSE; |
// // Options |
| 830 |
TString opt = option; |
// Bool_t fastClone = kFALSE; |
| 831 |
opt.ToLower(); |
// TString opt = option; |
| 832 |
if (opt.Contains("fast")) { |
// opt.ToLower(); |
| 833 |
fastClone = kTRUE; |
// if (opt.Contains("fast")) { |
| 834 |
} |
// fastClone = kTRUE; |
| 835 |
|
// printf(" 21 \n"); |
| 836 |
// The chain tree must have a list of branches |
// } |
| 837 |
// because we may try to change their basket |
// // The chain tree must have a list of branches |
| 838 |
// size later. |
// // because we may try to change their basket |
| 839 |
TObjArray* lbranches = mychain->GetListOfBranches(); |
// // size later. |
| 840 |
if (!lbranches) { |
// TObjArray* lbranches = mychain->GetListOfBranches(); |
| 841 |
// FIXME: We need an error message here. |
// if (!lbranches) { |
| 842 |
return 0; |
// // FIXME: We need an error message here. |
| 843 |
} |
// printf(" 22 \n"); |
| 844 |
|
// return 0; |
| 845 |
// The chain must have a current tree because |
// } |
| 846 |
// that is the one we will clone. |
|
| 847 |
// if (!fTree) { |
// // file->cd(); |
| 848 |
// -- LoadTree() has not yet been called, no current tree. |
// // The chain must have a current tree because |
| 849 |
// FIXME: We need an error message here. |
// // that is the one we will clone. |
| 850 |
// return 0; |
// // if (!fTree) { |
| 851 |
// } |
// // -- LoadTree() has not yet been called, no current tree. |
| 852 |
|
// // FIXME: We need an error message here. |
| 853 |
// Copy the chain's current tree without |
// // return 0; |
| 854 |
// copying any entries, we will do that later. |
// // } |
| 855 |
TTree* newTree = mychain->CloneTree(0); |
|
| 856 |
if (!newTree) { |
// // Copy the chain's current tree without |
| 857 |
// FIXME: We need an error message here. |
// // copying any entries, we will do that later. |
| 858 |
return 0; |
// printf(" 23 \n"); |
| 859 |
} |
// TTree* newTree = mychain->CloneTree(0); |
| 860 |
|
// if (!newTree) { |
| 861 |
// Strip out the (potential) directory name. |
// // FIXME: We need an error message here. |
| 862 |
// FIXME: The merged chain may or may not have the |
// printf(" 24 \n"); |
| 863 |
// same name as the original chain. This is |
// return 0; |
| 864 |
// bad because the chain name determines the |
// } |
| 865 |
// names of the trees in the chain by default. |
// printf(" 25 \n"); |
| 866 |
newTree->SetName(gSystem->BaseName(mychain->GetName())); |
|
| 867 |
|
|
| 868 |
// FIXME: Why do we do this? |
// // Strip out the (potential) directory name. |
| 869 |
// newTree->SetAutoSave(-1); |
// // FIXME: The merged chain may or may not have the |
| 870 |
newTree->SetAutoSave(900000000000000LL); |
// // same name as the original chain. This is |
| 871 |
|
// // bad because the chain name determines the |
| 872 |
// Circularity is incompatible with merging, it may |
// // names of the trees in the chain by default. |
| 873 |
// force us to throw away entries, which is not what |
// printf(" 26 \n"); |
| 874 |
// we are supposed to do. |
// newTree->SetName(gSystem->BaseName(mychain->GetName())); |
| 875 |
newTree->SetCircular(0); |
// printf(" 27 \n"); |
| 876 |
|
|
| 877 |
// Reset the compression level of the branches. |
// // FIXME: Why do we do this? |
| 878 |
if (opt.Contains("c")) { |
// // newTree->SetAutoSave(-1); |
| 879 |
TBranch* branch = 0; |
// newTree->SetAutoSave(900000000000000LL); |
| 880 |
TIter nextb(newTree->GetListOfBranches()); |
|
| 881 |
while ((branch = (TBranch*) nextb())) { |
// printf(" 28 \n"); |
| 882 |
branch->SetCompressionLevel(file->GetCompressionLevel()); |
// // Circularity is incompatible with merging, it may |
| 883 |
} |
// // force us to throw away entries, which is not what |
| 884 |
} |
// // we are supposed to do. |
| 885 |
|
// newTree->SetCircular(0); |
| 886 |
// Reset the basket size of the branches. |
|
| 887 |
if (basketsize > 1000) { |
// // Reset the compression level of the branches. |
| 888 |
TBranch* branch = 0; |
// if (opt.Contains("c")) { |
| 889 |
TIter nextb(newTree->GetListOfBranches()); |
// TBranch* branch = 0; |
| 890 |
while ((branch = (TBranch*) nextb())) { |
// TIter nextb(newTree->GetListOfBranches()); |
| 891 |
branch->SetBasketSize(basketsize); |
// while ((branch = (TBranch*) nextb())) { |
| 892 |
} |
// printf(" 29 \n"); |
| 893 |
} |
// branch->SetCompressionLevel(file->GetCompressionLevel()); |
| 894 |
|
// } |
| 895 |
Long64_t nentries = mychain->GetEntriesFast(); |
// } |
| 896 |
|
|
| 897 |
// Copy the entries. |
// printf(" 30 \n"); |
| 898 |
if (fastClone) { |
// // Reset the basket size of the branches. |
| 899 |
// For each tree in the chain. |
// if (basketsize > 1000) { |
| 900 |
for (Long64_t i = 0; i < nentries; i += mychain->GetTree()->GetEntries()) { |
// TBranch* branch = 0; |
| 901 |
if (mychain->LoadTree(i) < 0) { |
// TIter nextb(newTree->GetListOfBranches()); |
| 902 |
break; |
// while ((branch = (TBranch*) nextb())) { |
| 903 |
} |
// printf(" 31 \n"); |
| 904 |
TTreeCloner cloner(mychain->GetTree(), newTree, option); |
// branch->SetBasketSize(basketsize); |
| 905 |
if (cloner.IsValid()) { |
// } |
| 906 |
newTree->SetEntries(newTree->GetEntries() + mychain->GetTree()->GetEntries()); |
// } |
| 907 |
cloner.Exec(); |
|
| 908 |
} else { |
// printf(" 32 \n"); |
| 909 |
if (mychain->GetFile()) { |
// Long64_t nentries = mychain->GetEntriesFast(); |
| 910 |
printf("Merge Skipped file %s\n", mychain->GetFile()->GetName()); |
// //Long64_t nentries = mychain->GetEntries(); |
| 911 |
// } else { |
|
| 912 |
// Warning("Merge", "Skipped file number %d\n", fTreeNumber); |
// // Copy the entries. |
| 913 |
} |
// if (fastClone) { |
| 914 |
} |
// // For each tree in the chain. |
| 915 |
} |
// for (Long64_t i = 0; i < nentries; i += mychain->GetTree()->GetEntries()) { |
| 916 |
} else { |
// if (mychain->LoadTree(i) < 0) { |
| 917 |
for (Long64_t i = 0; i < nentries; i++) { |
// break; |
| 918 |
if (mychain->GetEntry(i) <= 0) { |
// } |
| 919 |
break; |
// TTreeCloner cloner(mychain->GetTree(), newTree, option); |
| 920 |
} |
// if (cloner.IsValid()) { |
| 921 |
newTree->Fill(); |
// newTree->SetEntries(newTree->GetEntries() + mychain->GetTree()->GetEntries()); |
| 922 |
} |
// cloner.Exec(); |
| 923 |
} |
// } else { |
| 924 |
|
// if (mychain->GetFile()) { |
| 925 |
// Write the new tree header. |
// printf("Merge Skipped file %s\n", mychain->GetFile()->GetName()); |
| 926 |
newTree->Write(); |
// // } else { |
| 927 |
|
// // Warning("Merge", "Skipped file number %d\n", fTreeNumber); |
| 928 |
// Get our return value. |
// } |
| 929 |
Int_t nfiles = newTree->GetFileNumber() + 1; |
// } |
| 930 |
|
// } |
| 931 |
// Close and delete the current file of the new tree. |
// } else { |
| 932 |
if (!opt.Contains("keep")) { |
// printf(" 33 %llu \n",nentries); |
| 933 |
// FIXME: What happens to fDirectory in newTree here? |
// mychain->Print(); |
| 934 |
delete newTree->GetCurrentFile(); |
// for (Long64_t i = 0; i < nentries; i++) { |
| 935 |
} |
// printf(" i %llu \n",i); |
| 936 |
return nfiles; |
// // for (Long64_t i = 0; i < 1; i++) { |
| 937 |
} |
// if (mychain->GetEntry(i) <= 0) { |
| 938 |
|
// break; |
| 939 |
|
// } |
| 940 |
|
// newTree->Fill(); |
| 941 |
|
// } |
| 942 |
|
// printf(" 34 \n"); |
| 943 |
|
// } |
| 944 |
|
|
| 945 |
|
// // Write the new tree header. |
| 946 |
|
// printf(" 35 \n"); |
| 947 |
|
// newTree->Write(); |
| 948 |
|
|
| 949 |
|
// printf(" 36 \n"); |
| 950 |
|
// // Get our return value. |
| 951 |
|
// Int_t nfiles = newTree->GetFileNumber() + 1; |
| 952 |
|
|
| 953 |
|
// // Close and delete the current file of the new tree. |
| 954 |
|
// if (!opt.Contains("keep")) { |
| 955 |
|
// // FIXME: What happens to fDirectory in newTree here? |
| 956 |
|
// delete newTree->GetCurrentFile(); |
| 957 |
|
// } |
| 958 |
|
// return nfiles; |
| 959 |
|
// } |