11 |
#include <TFile.h> |
#include <TFile.h> |
12 |
#include <TTree.h> |
#include <TTree.h> |
13 |
#include <TTimeStamp.h> |
#include <TTimeStamp.h> |
14 |
|
#include <TTreeCloner.h> |
15 |
#include <RunGlue.h> |
#include <RunGlue.h> |
16 |
// |
// |
17 |
ClassImp(RunGlue); |
ClassImp(RunGlue); |
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(); |
wd = gSystem->WorkingDirectory(); |
35 |
// |
// |
36 |
outdir = wrkdi; |
outdir = wrkdi; |
37 |
if ( !strcmp(outdir.Data(),"") ) outdir = wd; |
if ( !strcmp(outdir.Data(),"") ) outdir = wd; |
47 |
// |
// |
48 |
}; |
}; |
49 |
|
|
|
|
|
50 |
void RunGlue::Clear() { |
void RunGlue::Clear() { |
51 |
fEnd = false; |
fEnd = false; |
52 |
run = 0; |
run = 0; |
75 |
if (list.Contains("+ALL", TString::kIgnoreCase)) RUN = true; |
if (list.Contains("+ALL", TString::kIgnoreCase)) RUN = true; |
76 |
// |
// |
77 |
fDList = list; |
fDList = list; |
78 |
li->SetWhichTrees(fDList); |
// li->SetWhichTrees(fDList); |
79 |
// |
// |
80 |
if ( DebugMode() ) printf(" Detector list is %s \n",fDList.Data()); |
if ( DebugMode() ) printf(" Detector list is %s \n",fDList.Data()); |
81 |
// |
// |
82 |
}; |
}; |
83 |
|
|
84 |
TList *RunGlue::GetRunList(){ |
TList *RunGlue::GetRunList(){ |
85 |
// |
// |
86 |
lList = new TList(); |
lList = new TList(); |
87 |
lList->Clear(); |
lList->Clear(); |
88 |
TString thisrun; |
TString thisrun; |
116 |
UInt_t lowerlimit = llim->GetSec(); |
UInt_t lowerlimit = llim->GetSec(); |
117 |
UInt_t upperlimit = lowerlimit + 86401; |
UInt_t upperlimit = lowerlimit + 86401; |
118 |
// |
// |
|
stringstream myquery; |
|
|
myquery.str(""); |
|
|
myquery << "SELECT ID FROM GL_RUN WHERE RUNHEADER_TIME>=" << (UInt_t)lowerlimit |
|
|
<< " AND RUNHEADER_TIME<" << (UInt_t)upperlimit << " ORDER BY RUNHEADER_TIME ASC;"; |
|
|
// |
|
|
pResult = dbc->Query(myquery.str().c_str()); |
|
|
for( UInt_t r=0; r < 1000; r++){ |
|
|
Row = pResult->Next(); |
|
|
if( Row == NULL ) break; |
|
|
if ( DebugMode() ) printf(" %u RUN %s \n",r,Row->GetField(0)); |
|
|
// |
|
|
thisrun=dir+(TString)Row->GetField(0)+".Level2.root"; |
|
|
// |
|
|
if ( DebugMode() ) printf(" Filename is %s \n",thisrun.Data()); |
|
|
// |
|
|
su = TFile::Open(thisrun); |
|
|
if ( li->CheckLevel2File(thisrun) ){ |
|
|
lList->Add(su); |
|
|
} else { |
|
|
if ( DebugMode() ) printf(" RUN %s DISCARDED \n",Row->GetField(0)); |
|
|
}; |
|
|
// |
|
|
}; |
|
|
// |
|
119 |
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); |
120 |
// |
// |
121 |
YY -= 2000; |
YY -= 2000; |
149 |
// |
// |
150 |
printf(" Output filename is %s \n",fFilename.Data()); |
printf(" Output filename is %s \n",fFilename.Data()); |
151 |
// |
// |
152 |
|
if ( !this->OpenFile() ){ |
153 |
|
fEnd = true; |
154 |
|
return(0); |
155 |
|
}; |
156 |
|
// |
157 |
|
stringstream myquery; |
158 |
|
myquery.str(""); |
159 |
|
myquery << "SELECT ID FROM GL_RUN WHERE RUNHEADER_TIME>=" << (UInt_t)lowerlimit |
160 |
|
<< " AND RUNHEADER_TIME<" << (UInt_t)upperlimit << " ORDER BY RUNHEADER_TIME ASC;"; |
161 |
|
// |
162 |
|
pResult = dbc->Query(myquery.str().c_str()); |
163 |
|
for( UInt_t r=0; r < 1000; r++){ |
164 |
|
Row = pResult->Next(); |
165 |
|
if( Row == NULL ) break; |
166 |
|
if ( DebugMode() ) printf(" %u RUN %s \n",r,Row->GetField(0)); |
167 |
|
// |
168 |
|
thisrun=dir+(TString)Row->GetField(0)+".Level2.root"; |
169 |
|
// |
170 |
|
if ( DebugMode() ) printf(" Filename is %s \n",thisrun.Data()); |
171 |
|
// |
172 |
|
su = TFile::Open(thisrun); |
173 |
|
if ( li->CheckLevel2File(thisrun) ){ |
174 |
|
lList->Add(su); |
175 |
|
} else { |
176 |
|
if ( DebugMode() ) printf(" RUN %s DISCARDED \n",Row->GetField(0)); |
177 |
|
}; |
178 |
|
// |
179 |
|
}; |
180 |
|
// |
181 |
|
// |
182 |
delete glrun; |
delete glrun; |
183 |
delete dbtime; |
delete dbtime; |
184 |
// |
// |
283 |
UInt_t lowerlimit = llim->GetSec(); |
UInt_t lowerlimit = llim->GetSec(); |
284 |
UInt_t upperlimit = lowerlimit + 86401; |
UInt_t upperlimit = lowerlimit + 86401; |
285 |
// |
// |
|
stringstream myquery; |
|
|
myquery.str(""); |
|
|
myquery << "SELECT ID FROM GL_RUN WHERE RUNHEADER_TIME>=" << (UInt_t)lowerlimit |
|
|
<< " AND RUNHEADER_TIME<" << (UInt_t)upperlimit << " ORDER BY RUNHEADER_TIME ASC;"; |
|
|
// |
|
|
pResult = dbc->Query(myquery.str().c_str()); |
|
|
for( UInt_t r=0; r < 1000; r++){ |
|
|
Row = pResult->Next(); |
|
|
if( Row == NULL ) break; |
|
|
if ( DebugMode() ) printf(" %u RUN %s \n",r,Row->GetField(0)); |
|
|
// |
|
|
thisrun=dir+(TString)Row->GetField(0)+".Level2.root"; |
|
|
// |
|
|
if ( DebugMode() ) printf(" Filename is %s \n",thisrun.Data()); |
|
|
// |
|
|
su = TFile::Open(thisrun); |
|
|
if ( su ){ |
|
|
TFile *su0 = TFile::Open(thisrun); |
|
|
fDoneList->Add(su0); |
|
|
fNlistdone++; |
|
|
}; |
|
|
if ( li->CheckLevel2File(thisrun) ){ |
|
|
lList->Add(su); |
|
|
if ( DebugMode() ) printf(" RUN %s ADDED \n",Row->GetField(0)); |
|
|
} else { |
|
|
if ( DebugMode() ) printf(" RUN %s DISCARDED \n",Row->GetField(0)); |
|
|
}; |
|
|
// |
|
|
}; |
|
|
// |
|
286 |
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); |
287 |
// |
// |
288 |
YY -= 2000; |
YY -= 2000; |
316 |
// |
// |
317 |
printf(" Output filename is %s \n",fFilename.Data()); |
printf(" Output filename is %s \n",fFilename.Data()); |
318 |
// |
// |
319 |
|
if ( !this->OpenFile() ) return(0); |
320 |
|
// |
321 |
|
stringstream myquery; |
322 |
|
myquery.str(""); |
323 |
|
myquery << "SELECT ID FROM GL_RUN WHERE RUNHEADER_TIME>=" << (UInt_t)lowerlimit |
324 |
|
<< " AND RUNHEADER_TIME<" << (UInt_t)upperlimit << " ORDER BY RUNHEADER_TIME ASC;"; |
325 |
|
// |
326 |
|
pResult = dbc->Query(myquery.str().c_str()); |
327 |
|
for( UInt_t r=0; r < 1000; r++){ |
328 |
|
Row = pResult->Next(); |
329 |
|
if( Row == NULL ) break; |
330 |
|
if ( DebugMode() ) printf(" %u RUN %s \n",r,Row->GetField(0)); |
331 |
|
// |
332 |
|
thisrun=dir+(TString)Row->GetField(0)+".Level2.root"; |
333 |
|
// |
334 |
|
if ( DebugMode() ) printf(" Filename is %s \n",thisrun.Data()); |
335 |
|
// |
336 |
|
su = TFile::Open(thisrun); |
337 |
|
if ( su ){ |
338 |
|
TFile *su0 = TFile::Open(thisrun); |
339 |
|
fDoneList->Add(su0); |
340 |
|
fNlistdone++; |
341 |
|
}; |
342 |
|
if ( li->CheckLevel2File(thisrun) ){ |
343 |
|
lList->Add(su); |
344 |
|
if ( DebugMode() ) printf(" RUN %s ADDED \n",Row->GetField(0)); |
345 |
|
} else { |
346 |
|
if ( DebugMode() ) printf(" RUN %s DISCARDED \n",Row->GetField(0)); |
347 |
|
}; |
348 |
|
// |
349 |
|
}; |
350 |
|
// |
351 |
if ( DebugMode() ){ |
if ( DebugMode() ){ |
352 |
UInt_t ll = 0; |
UInt_t ll = 0; |
353 |
while ( (TFile*)lList->At(ll) ){ |
while ( (TFile*)lList->At(ll) ){ |
380 |
|
|
381 |
Bool_t RunGlue::OpenFile(){ |
Bool_t RunGlue::OpenFile(){ |
382 |
// |
// |
383 |
|
fOpen = false; |
384 |
printf(" Check if output file already exists \n"); |
printf(" Check if output file already exists \n"); |
385 |
Target = TFile::Open((this->GetFilename()).Data(), "READ" ); |
ifstream myfile; |
386 |
// |
myfile.open((this->GetFilename()).Data()); |
387 |
if ( Target ){ |
if ( myfile ){ |
388 |
Target->Close(); |
// Target = TFile::Open((this->GetFilename()).Data(), "READ" ); |
389 |
|
// |
390 |
|
// if ( Target ){ |
391 |
|
// Target->Close(); |
392 |
|
myfile.close(); |
393 |
printf("Error opening target file, %s already exist!\n",(this->GetFilename()).Data()); |
printf("Error opening target file, %s already exist!\n",(this->GetFilename()).Data()); |
394 |
return(false); |
return(false); |
395 |
} else { |
} else { |
396 |
// |
// |
397 |
printf(" Output file does not exist, creating it\n"); |
printf(" Output file does not exist, creating it\n"); |
398 |
// |
// |
399 |
Long64_t maxsize = 10000000000LL; |
Long64_t maxsize = 99900000000LL; |
400 |
// |
// |
401 |
Target = TFile::Open((this->GetFilename()).Data(), "RECREATE" ); |
Target = TFile::Open((this->GetFilename()).Data(), "RECREATE" ); |
402 |
//fastMethod = kTRUE; |
//fastMethod = kTRUE; |
409 |
} |
} |
410 |
// |
// |
411 |
TTree::SetMaxTreeSize(maxsize); |
TTree::SetMaxTreeSize(maxsize); |
412 |
|
// Target->SetCompressionLevel(2); |
413 |
|
Target->SetCompressionLevel(3); |
414 |
|
//Target->SetCompressionLevel(5); |
415 |
// |
// |
416 |
|
fOpen = true; |
417 |
return(true); |
return(true); |
418 |
// |
// |
419 |
}; |
}; |
473 |
}; |
}; |
474 |
// |
// |
475 |
myquery.str(""); |
myquery.str(""); |
476 |
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 << ",'" << outdir.Data() << "','" << ((TString)gSystem->BaseName(this->GetFilename())).Data() << "');"; |
477 |
|
myquery << "insert into GL_ROOT (ID_RAW,PATH,NAME) values (" << idr << ",'$PAM_L2','" << ((TString)gSystem->BaseName(this->GetFilename())).Data() << "');"; |
478 |
if ( DebugMode() ) printf(" query is %s \n",myquery.str().c_str()); |
if ( DebugMode() ) printf(" query is %s \n",myquery.str().c_str()); |
479 |
// |
// |
480 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
530 |
// |
// |
531 |
void RunGlue::MergeRootfile(TList *sourcelist) { |
void RunGlue::MergeRootfile(TList *sourcelist) { |
532 |
// |
// |
533 |
merged = false; |
merged = true; |
|
// |
|
|
TDirectory *target = Target; |
|
|
// |
|
|
if ( DebugMode() ) printf("\nTarget path is: %s \n",target->GetPath()); |
|
534 |
// |
// |
535 |
TString path( (char*)strstr( target->GetPath(), ":" ) ); |
if ( li ) li->Delete(); |
536 |
path.Remove(0,2); |
li = new PamLevel2(wd,sourcelist,fDList); |
537 |
// |
// |
538 |
TDirectory *first_source = (TDirectory*)sourcelist->First(); |
Target->cd(); |
|
THashList allNames; |
|
|
// |
|
|
while ( first_source ){ |
|
|
// |
|
|
TDirectory *current_sourcedir = first_source->GetDirectory(path); |
|
|
// |
|
|
if ( !current_sourcedir ){ |
|
|
first_source = (TDirectory*)sourcelist->After(first_source); |
|
|
continue; |
|
|
} |
|
|
// |
|
|
// loop over all keys in this directory |
|
|
// |
|
|
TChain *globChain = 0; |
|
|
TIter nextkey( current_sourcedir->GetListOfKeys() ); |
|
|
TKey *key, *oldkey=0; |
|
|
TH1::AddDirectory(kFALSE); // gain time, do not add the objects in the list in memory |
|
|
// |
|
|
while ( (key = (TKey*)nextkey()) ) { |
|
|
// |
|
|
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->TRK2 && !li->TRK1 && !li->TRKh ) continue; |
|
|
// |
|
|
if ( !strcmp(key->GetName(),"Calorimeter") && !li->CAL2 && !li->CAL1 ) continue; |
|
|
// |
|
|
if ( !strcmp(key->GetName(),"ToF") && !li->TOF ) continue; |
|
|
// |
|
|
if ( !strcmp(key->GetName(),"Trigger") && !li->TRG ) continue; |
|
|
// |
|
|
if ( !strcmp(key->GetName(),"Anticounter") && !li->AC ) continue; |
|
|
// |
|
|
if ( !strcmp(key->GetName(),"S4") && !li->S4 ) continue; |
|
|
// |
|
|
if ( !strcmp(key->GetName(),"NeutronD") && !li->ND ) continue; |
|
|
// |
|
|
if ( !strcmp(key->GetName(),"OrbitalInfo") && !li->ORB ) continue; |
|
|
// |
|
|
if ( !strcmp(key->GetName(),"Run") && !RUN ) 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->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); |
|
|
}; |
|
|
// |
|
|
} 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") ) { |
|
|
// |
|
|
// |
|
|
if ( fastMethod ){ |
|
|
globChain->Merge(target->GetFile(),0,"keep fast"); |
|
|
} else { |
|
|
globChain->Merge(target->GetFile(),0,"keep"); |
|
|
}; |
|
|
// |
|
|
merged = true; |
|
|
// |
|
|
if ( DebugMode() ) globChain->ls(); |
|
|
// |
|
|
delete globChain; |
|
|
// |
|
|
} else { |
|
|
// |
|
|
// obj->Write( key->GetName() ); // <================================================================================== |
|
|
// |
|
|
}; |
|
|
}; |
|
|
oldkey = key; |
|
|
}; |
|
|
// |
|
|
first_source = (TDirectory*)sourcelist->After(first_source); |
|
|
// |
|
|
}; |
|
|
// save modifications to target file |
|
|
target->SaveSelf(kTRUE); |
|
539 |
// |
// |
540 |
|
li->CreateCloneTrees(Target); |
541 |
|
ULong64_t nevents = li->GetEntries(); |
542 |
|
printf(" NEVENTS %llu \n",nevents); |
543 |
|
for(ULong64_t iev=0; iev<nevents; iev++){ |
544 |
|
li->Clear(); |
545 |
|
if( li->GetEntry(iev) ){ |
546 |
|
li->FillCloneTrees(); |
547 |
|
}; |
548 |
|
}; |
549 |
|
Target->cd(); |
550 |
|
li->WriteCloneTrees(); |
551 |
|
printf("Written file %s \n",Target->GetName()); |
552 |
|
// Target->Write(); |
553 |
|
TTree *slist = (TTree*)Target->Get("SelectionList"); |
554 |
|
slist->Delete("all"); |
555 |
|
Target->Close(); |
556 |
|
|
557 |
|
// // |
558 |
|
// TDirectory *target = Target; |
559 |
|
// // |
560 |
|
// if ( DebugMode() ) printf("\nTarget path is: %s \n",target->GetPath()); |
561 |
|
// // |
562 |
|
// TString path( (char*)strstr( target->GetPath(), ":" ) ); |
563 |
|
// path.Remove(0,2); |
564 |
|
// // |
565 |
|
// TDirectory *first_source = (TDirectory*)sourcelist->First(); |
566 |
|
// THashList allNames; |
567 |
|
// // |
568 |
|
// while ( first_source ){ |
569 |
|
// // |
570 |
|
// TDirectory *current_sourcedir = first_source->GetDirectory(path); |
571 |
|
// // |
572 |
|
// if ( !current_sourcedir ){ |
573 |
|
// first_source = (TDirectory*)sourcelist->After(first_source); |
574 |
|
// continue; |
575 |
|
// } |
576 |
|
// // |
577 |
|
// // loop over all keys in this directory |
578 |
|
// // |
579 |
|
// TChain *globChain = 0; |
580 |
|
// TIter nextkey( current_sourcedir->GetListOfKeys() ); |
581 |
|
// TKey *key = 0; |
582 |
|
// TKey *oldkey = 0; |
583 |
|
// TH1::AddDirectory(kFALSE); // gain time, do not add the objects in the list in memory |
584 |
|
// // |
585 |
|
// while ( (key = (TKey*)nextkey()) ) { |
586 |
|
// // |
587 |
|
// // printf(" target ls \n"); |
588 |
|
// // Target->ls(); |
589 |
|
// // |
590 |
|
// if ( current_sourcedir == target ) break; |
591 |
|
// // |
592 |
|
// if ( oldkey && !strcmp(oldkey->GetName(),key->GetName()) ) continue; //keep only the highest cycle number for each key |
593 |
|
// // |
594 |
|
// if ( allNames.FindObject(key->GetName()) ) continue; |
595 |
|
// // |
596 |
|
// if ( DebugMode() ) printf(" Key name is -%s- \n",key->GetName()); |
597 |
|
// // |
598 |
|
// // |
599 |
|
// // |
600 |
|
// if ( !strcmp(key->GetName(),"Tracker") && !li->IsTRK2() && !li->IsTRK1() && !li->IsTRKh() ) continue; |
601 |
|
// // |
602 |
|
// if ( !strcmp(key->GetName(),"Calorimeter") && !li->IsCAL2() && !li->IsCAL1() ) continue; |
603 |
|
// // |
604 |
|
// if ( !strcmp(key->GetName(),"ToF") && !li->IsTOF() ) continue; |
605 |
|
// // |
606 |
|
// if ( !strcmp(key->GetName(),"Trigger") && !li->IsTRG() ) continue; |
607 |
|
// // |
608 |
|
// if ( !strcmp(key->GetName(),"Anticounter") && !li->IsAC() ) continue; |
609 |
|
// // |
610 |
|
// if ( !strcmp(key->GetName(),"S4") && !li->IsS4() ) continue; |
611 |
|
// // |
612 |
|
// if ( !strcmp(key->GetName(),"NeutronD") && !li->IsND() ) continue; |
613 |
|
// // |
614 |
|
// if ( !strcmp(key->GetName(),"OrbitalInfo") && !li->IsORB() ) continue; |
615 |
|
// // |
616 |
|
// if ( !strcmp(key->GetName(),"Run") && !li->IsRUN() ) continue; |
617 |
|
// // |
618 |
|
// 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") ){ |
619 |
|
// if ( DebugMode() ) printf(" ERROR UNKNOWN KEY %s !\n",key->GetName()); |
620 |
|
// continue; |
621 |
|
// }; |
622 |
|
// // |
623 |
|
// printf(" 1 \n"); |
624 |
|
// allNames.Add(new TObjString(key->GetName())); |
625 |
|
// printf(" 2 \n"); |
626 |
|
// // |
627 |
|
// // read object from first source file |
628 |
|
// // |
629 |
|
// current_sourcedir->cd(); |
630 |
|
// TObject *obj = key->ReadObj(); |
631 |
|
// printf(" 3 \n"); |
632 |
|
// // |
633 |
|
// if ( obj->IsA()->InheritsFrom("TTree") ){ |
634 |
|
// // |
635 |
|
// // loop over all source files create a chain of Trees "globChain" |
636 |
|
// // |
637 |
|
// TString obj_name; |
638 |
|
// printf(" 4 \n"); |
639 |
|
// // |
640 |
|
// if ( path.Length() ) { |
641 |
|
// obj_name = path + "/" + obj->GetName(); |
642 |
|
// } else { |
643 |
|
// obj_name = obj->GetName(); |
644 |
|
// }; |
645 |
|
// // |
646 |
|
// globChain = new TChain(obj_name); |
647 |
|
// // |
648 |
|
// globChain->SetCacheSize(0); |
649 |
|
// // |
650 |
|
// printf(" 5 \n"); |
651 |
|
// globChain->Add(first_source->GetName()); |
652 |
|
// printf(" 6 \n"); |
653 |
|
// // |
654 |
|
// TFile *nextsource = (TFile*)sourcelist->After( first_source ); |
655 |
|
// // |
656 |
|
// while ( nextsource ) { |
657 |
|
// // |
658 |
|
// //do not add to the list a file that does not contain this Tree |
659 |
|
// // |
660 |
|
// printf(" 7 \n"); |
661 |
|
// TFile *curf = TFile::Open(nextsource->GetName()); |
662 |
|
// // |
663 |
|
// if ( curf ) { |
664 |
|
// // |
665 |
|
// Bool_t mustAdd = kFALSE; |
666 |
|
// // |
667 |
|
// if (curf->FindKey(obj_name)) { |
668 |
|
// // |
669 |
|
// mustAdd = kTRUE; |
670 |
|
// // |
671 |
|
// } else { |
672 |
|
// // |
673 |
|
// //we could be more clever here. No need to import the object |
674 |
|
// //we are missing a function in TDirectory |
675 |
|
// // |
676 |
|
// TObject *aobj = curf->Get(obj_name); |
677 |
|
// // |
678 |
|
// if ( aobj ){ |
679 |
|
// mustAdd = kTRUE; |
680 |
|
// delete aobj; |
681 |
|
// }; |
682 |
|
// }; |
683 |
|
// if (mustAdd) { |
684 |
|
// printf(" 8 \n"); |
685 |
|
// globChain->Add(nextsource->GetName()); |
686 |
|
// printf(" 9 \n"); |
687 |
|
// }; |
688 |
|
// }; |
689 |
|
// delete curf; |
690 |
|
// nextsource = (TFile*)sourcelist->After(nextsource); |
691 |
|
// }; |
692 |
|
// // |
693 |
|
// printf(" 10 \n"); |
694 |
|
// delete nextsource; |
695 |
|
// printf(" 11 \n"); |
696 |
|
// // |
697 |
|
// } else { |
698 |
|
// // |
699 |
|
// // object is of no type that we know or can handle |
700 |
|
// // |
701 |
|
// if ( DebugMode() ) cout << "Unknown object type, name: " |
702 |
|
// << obj->GetName() << " title: " << obj->GetTitle() << endl; |
703 |
|
// }; |
704 |
|
// // |
705 |
|
// // now write the merged histogram (which is "in" obj) to the target file |
706 |
|
// // note that this will just store obj in the current directory level, |
707 |
|
// // which is not persistent until the complete directory itself is stored |
708 |
|
// // by "target->Write()" below |
709 |
|
// // |
710 |
|
// printf(" 12 \n"); |
711 |
|
// if ( obj ){ |
712 |
|
// // |
713 |
|
// target->cd(); |
714 |
|
// // |
715 |
|
// if( obj->IsA()->InheritsFrom("TTree") ) { |
716 |
|
// // |
717 |
|
// Long64_t nfiles = 0; |
718 |
|
// if ( fastMethod ){ |
719 |
|
// // globChain->Merge(target->GetFile(),0,"C keep fast"); |
720 |
|
// nfiles=this->Mergy((TChain*)globChain,target->GetFile(),0,"C keep fast"); |
721 |
|
// } else { |
722 |
|
// //globChain->Merge(target->GetFile(),0,"C keep"); |
723 |
|
// printf(" 13 %llu \n",globChain->GetEntries()); |
724 |
|
// nfiles=this->Mergy((TChain*)globChain,target->GetFile(),0,"C keep"); |
725 |
|
// printf(" 14 \n"); |
726 |
|
// }; |
727 |
|
// // |
728 |
|
// merged = true; |
729 |
|
// // |
730 |
|
// if ( DebugMode() ){ |
731 |
|
// printf(" Merged %i files\n",(int)nfiles); |
732 |
|
// globChain->ls(); |
733 |
|
// }; |
734 |
|
// // |
735 |
|
// delete globChain; |
736 |
|
// // return; |
737 |
|
// // |
738 |
|
// } else { |
739 |
|
// // |
740 |
|
// // obj->Write( key->GetName() ); // <================================================================================== |
741 |
|
// // |
742 |
|
// }; |
743 |
|
// }; |
744 |
|
// delete obj; |
745 |
|
// oldkey = key; |
746 |
|
// }; |
747 |
|
// // |
748 |
|
// first_source = (TDirectory*)sourcelist->After(first_source); |
749 |
|
// // |
750 |
|
// }; |
751 |
|
// // save modifications to target file |
752 |
|
// // |
753 |
|
// target->SaveSelf(kTRUE); |
754 |
|
// // |
755 |
|
}; |
756 |
|
|
757 |
|
|
758 |
|
Long64_t RunGlue::Mergy(TChain *mychain, TFile* file, Int_t basketsize, Option_t* option){ |
759 |
|
// We must have been passed a file, we will use it |
760 |
|
// later to reset the compression level of the branches. |
761 |
|
if (!file) { |
762 |
|
// FIXME: We need an error message here. |
763 |
|
printf(" 19 \n"); |
764 |
|
return 0; |
765 |
|
} |
766 |
|
printf(" 20 \n"); |
767 |
|
|
768 |
|
// Options |
769 |
|
Bool_t fastClone = kFALSE; |
770 |
|
TString opt = option; |
771 |
|
opt.ToLower(); |
772 |
|
if (opt.Contains("fast")) { |
773 |
|
fastClone = kTRUE; |
774 |
|
printf(" 21 \n"); |
775 |
|
} |
776 |
|
// The chain tree must have a list of branches |
777 |
|
// because we may try to change their basket |
778 |
|
// size later. |
779 |
|
TObjArray* lbranches = mychain->GetListOfBranches(); |
780 |
|
if (!lbranches) { |
781 |
|
// FIXME: We need an error message here. |
782 |
|
printf(" 22 \n"); |
783 |
|
return 0; |
784 |
|
} |
785 |
|
|
786 |
|
// file->cd(); |
787 |
|
// The chain must have a current tree because |
788 |
|
// that is the one we will clone. |
789 |
|
// if (!fTree) { |
790 |
|
// -- LoadTree() has not yet been called, no current tree. |
791 |
|
// FIXME: We need an error message here. |
792 |
|
// return 0; |
793 |
|
// } |
794 |
|
|
795 |
|
// Copy the chain's current tree without |
796 |
|
// copying any entries, we will do that later. |
797 |
|
printf(" 23 \n"); |
798 |
|
TTree* newTree = mychain->CloneTree(0); |
799 |
|
if (!newTree) { |
800 |
|
// FIXME: We need an error message here. |
801 |
|
printf(" 24 \n"); |
802 |
|
return 0; |
803 |
|
} |
804 |
|
printf(" 25 \n"); |
805 |
|
|
806 |
|
|
807 |
|
// Strip out the (potential) directory name. |
808 |
|
// FIXME: The merged chain may or may not have the |
809 |
|
// same name as the original chain. This is |
810 |
|
// bad because the chain name determines the |
811 |
|
// names of the trees in the chain by default. |
812 |
|
printf(" 26 \n"); |
813 |
|
newTree->SetName(gSystem->BaseName(mychain->GetName())); |
814 |
|
printf(" 27 \n"); |
815 |
|
|
816 |
|
// FIXME: Why do we do this? |
817 |
|
// newTree->SetAutoSave(-1); |
818 |
|
newTree->SetAutoSave(900000000000000LL); |
819 |
|
|
820 |
|
printf(" 28 \n"); |
821 |
|
// Circularity is incompatible with merging, it may |
822 |
|
// force us to throw away entries, which is not what |
823 |
|
// we are supposed to do. |
824 |
|
newTree->SetCircular(0); |
825 |
|
|
826 |
|
// Reset the compression level of the branches. |
827 |
|
if (opt.Contains("c")) { |
828 |
|
TBranch* branch = 0; |
829 |
|
TIter nextb(newTree->GetListOfBranches()); |
830 |
|
while ((branch = (TBranch*) nextb())) { |
831 |
|
printf(" 29 \n"); |
832 |
|
branch->SetCompressionLevel(file->GetCompressionLevel()); |
833 |
|
} |
834 |
|
} |
835 |
|
|
836 |
|
printf(" 30 \n"); |
837 |
|
// Reset the basket size of the branches. |
838 |
|
if (basketsize > 1000) { |
839 |
|
TBranch* branch = 0; |
840 |
|
TIter nextb(newTree->GetListOfBranches()); |
841 |
|
while ((branch = (TBranch*) nextb())) { |
842 |
|
printf(" 31 \n"); |
843 |
|
branch->SetBasketSize(basketsize); |
844 |
|
} |
845 |
|
} |
846 |
|
|
847 |
|
printf(" 32 \n"); |
848 |
|
Long64_t nentries = mychain->GetEntriesFast(); |
849 |
|
//Long64_t nentries = mychain->GetEntries(); |
850 |
|
|
851 |
|
// Copy the entries. |
852 |
|
if (fastClone) { |
853 |
|
// For each tree in the chain. |
854 |
|
for (Long64_t i = 0; i < nentries; i += mychain->GetTree()->GetEntries()) { |
855 |
|
if (mychain->LoadTree(i) < 0) { |
856 |
|
break; |
857 |
|
} |
858 |
|
TTreeCloner cloner(mychain->GetTree(), newTree, option); |
859 |
|
if (cloner.IsValid()) { |
860 |
|
newTree->SetEntries(newTree->GetEntries() + mychain->GetTree()->GetEntries()); |
861 |
|
cloner.Exec(); |
862 |
|
} else { |
863 |
|
if (mychain->GetFile()) { |
864 |
|
printf("Merge Skipped file %s\n", mychain->GetFile()->GetName()); |
865 |
|
// } else { |
866 |
|
// Warning("Merge", "Skipped file number %d\n", fTreeNumber); |
867 |
|
} |
868 |
|
} |
869 |
|
} |
870 |
|
} else { |
871 |
|
printf(" 33 %llu \n",nentries); |
872 |
|
mychain->Print(); |
873 |
|
for (Long64_t i = 0; i < nentries; i++) { |
874 |
|
printf(" i %llu \n",i); |
875 |
|
// for (Long64_t i = 0; i < 1; i++) { |
876 |
|
if (mychain->GetEntry(i) <= 0) { |
877 |
|
break; |
878 |
|
} |
879 |
|
newTree->Fill(); |
880 |
|
} |
881 |
|
printf(" 34 \n"); |
882 |
|
} |
883 |
|
|
884 |
|
// Write the new tree header. |
885 |
|
printf(" 35 \n"); |
886 |
|
newTree->Write(); |
887 |
|
|
888 |
|
printf(" 36 \n"); |
889 |
|
// Get our return value. |
890 |
|
Int_t nfiles = newTree->GetFileNumber() + 1; |
891 |
|
|
892 |
|
// Close and delete the current file of the new tree. |
893 |
|
if (!opt.Contains("keep")) { |
894 |
|
// FIXME: What happens to fDirectory in newTree here? |
895 |
|
delete newTree->GetCurrentFile(); |
896 |
|
} |
897 |
|
return nfiles; |
898 |
} |
} |