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