42 |
runmode = false; |
runmode = false; |
43 |
createlist = true; |
createlist = true; |
44 |
}; |
}; |
45 |
|
fUpgrade = true; |
46 |
// |
// |
47 |
// lList = new TList(); |
// lList = new TList(); |
48 |
// |
// |
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 |
// |
// |
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 |
// |
// |
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 = TFile::Open((this->GetFilename()).Data(), "RECREATE" ); |
if ( !Target || Target->IsZombie()) { |
432 |
|
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",(this->GetFilename()).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); |
//Target->SetCompressionLevel(5); |
447 |
// |
// |
448 |
fOpen = true; |
fOpen = 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 |
// |
// |
565 |
// |
// |
566 |
merged = true; |
merged = true; |
567 |
// |
// |
568 |
if ( li ) li->Delete(); |
// if ( li ) li->Delete(); |
569 |
li = new PamLevel2(wd,sourcelist,fDList); |
PamLevel2 *nli = new PamLevel2(wd,sourcelist,fDList); |
570 |
|
nli->SetSELLI(2); |
571 |
// |
// |
572 |
Target->cd(); |
Target->cd(); |
573 |
// |
// |
574 |
li->CreateCloneTrees(Target); |
nli->CreateCloneTrees(Target); |
575 |
ULong64_t nevents = li->GetEntries(); |
// |
576 |
|
/* nli->GetCloneTree("Tracker")->SetAutoSave(900000000000000LL); |
577 |
|
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); |
printf(" NEVENTS %llu \n",nevents); |
588 |
for(ULong64_t iev=0; iev<nevents; iev++){ |
for(ULong64_t iev=0; iev<nevents; iev++){ |
589 |
li->Clear(); |
nli->Clear(); |
590 |
if( li->GetEntry(iev) ){ |
if( nli->GetEntry(iev) ){ |
591 |
li->FillCloneTrees(); |
nli->FillCloneTrees(); |
592 |
}; |
}; |
593 |
}; |
}; |
594 |
Target->cd(); |
Target->cd(); |
595 |
li->WriteCloneTrees(); |
nli->WriteCloneTrees(); |
596 |
printf(" file %s \n",Target->GetName()); |
printf("Written file %s \n",Target->GetName()); |
597 |
// Target->Write(); |
// Target->Write(); |
598 |
TTree *slist = (TTree*)Target->Get("SelectionList"); |
// TTree *slist = (TTree*)Target->Get("SelectionList"); |
599 |
slist->Delete("all"); |
// 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 |
|
Target->cd(); |
611 |
|
Pclone->Write("ProcessingInfo",TObject::kOverwrite); |
612 |
|
P->Delete(); |
613 |
|
P=0; |
614 |
|
} |
615 |
|
// |
616 |
Target->Close(); |
Target->Close(); |
617 |
|
|
618 |
// // |
// // |
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 |
// We must have been passed a file, we will use it |
// // We must have been passed a file, we will use it |
821 |
// later to reset the compression level of the branches. |
// // later to reset the compression level of the branches. |
822 |
if (!file) { |
// if (!file) { |
823 |
// FIXME: We need an error message here. |
// // FIXME: We need an error message here. |
824 |
printf(" 19 \n"); |
// printf(" 19 \n"); |
825 |
return 0; |
// return 0; |
826 |
} |
// } |
827 |
printf(" 20 \n"); |
// printf(" 20 \n"); |
828 |
|
|
829 |
// Options |
// // Options |
830 |
Bool_t fastClone = kFALSE; |
// Bool_t fastClone = kFALSE; |
831 |
TString opt = option; |
// TString opt = option; |
832 |
opt.ToLower(); |
// opt.ToLower(); |
833 |
if (opt.Contains("fast")) { |
// if (opt.Contains("fast")) { |
834 |
fastClone = kTRUE; |
// fastClone = kTRUE; |
835 |
printf(" 21 \n"); |
// printf(" 21 \n"); |
836 |
} |
// } |
837 |
// The chain tree must have a list of branches |
// // The chain tree must have a list of branches |
838 |
// because we may try to change their basket |
// // because we may try to change their basket |
839 |
// size later. |
// // size later. |
840 |
TObjArray* lbranches = mychain->GetListOfBranches(); |
// TObjArray* lbranches = mychain->GetListOfBranches(); |
841 |
if (!lbranches) { |
// if (!lbranches) { |
842 |
// FIXME: We need an error message here. |
// // FIXME: We need an error message here. |
843 |
printf(" 22 \n"); |
// printf(" 22 \n"); |
844 |
return 0; |
// return 0; |
845 |
} |
// } |
846 |
|
|
847 |
// file->cd(); |
// // file->cd(); |
848 |
// The chain must have a current tree because |
// // The chain must have a current tree because |
849 |
// that is the one we will clone. |
// // that is the one we will clone. |
850 |
// if (!fTree) { |
// // if (!fTree) { |
851 |
// -- LoadTree() has not yet been called, no current tree. |
// // -- LoadTree() has not yet been called, no current tree. |
852 |
// FIXME: We need an error message here. |
// // FIXME: We need an error message here. |
853 |
// return 0; |
// // return 0; |
854 |
// } |
// // } |
855 |
|
|
856 |
// Copy the chain's current tree without |
// // Copy the chain's current tree without |
857 |
// copying any entries, we will do that later. |
// // copying any entries, we will do that later. |
858 |
printf(" 23 \n"); |
// printf(" 23 \n"); |
859 |
TTree* newTree = mychain->CloneTree(0); |
// TTree* newTree = mychain->CloneTree(0); |
860 |
if (!newTree) { |
// if (!newTree) { |
861 |
// FIXME: We need an error message here. |
// // FIXME: We need an error message here. |
862 |
printf(" 24 \n"); |
// printf(" 24 \n"); |
863 |
return 0; |
// return 0; |
864 |
} |
// } |
865 |
printf(" 25 \n"); |
// printf(" 25 \n"); |
866 |
|
|
867 |
|
|
868 |
// Strip out the (potential) directory name. |
// // Strip out the (potential) directory name. |
869 |
// FIXME: The merged chain may or may not have the |
// // FIXME: The merged chain may or may not have the |
870 |
// same name as the original chain. This is |
// // same name as the original chain. This is |
871 |
// bad because the chain name determines the |
// // bad because the chain name determines the |
872 |
// names of the trees in the chain by default. |
// // names of the trees in the chain by default. |
873 |
printf(" 26 \n"); |
// printf(" 26 \n"); |
874 |
newTree->SetName(gSystem->BaseName(mychain->GetName())); |
// newTree->SetName(gSystem->BaseName(mychain->GetName())); |
875 |
printf(" 27 \n"); |
// printf(" 27 \n"); |
876 |
|
|
877 |
// FIXME: Why do we do this? |
// // FIXME: Why do we do this? |
878 |
// newTree->SetAutoSave(-1); |
// // newTree->SetAutoSave(-1); |
879 |
newTree->SetAutoSave(900000000000000LL); |
// newTree->SetAutoSave(900000000000000LL); |
880 |
|
|
881 |
printf(" 28 \n"); |
// printf(" 28 \n"); |
882 |
// Circularity is incompatible with merging, it may |
// // Circularity is incompatible with merging, it may |
883 |
// force us to throw away entries, which is not what |
// // force us to throw away entries, which is not what |
884 |
// we are supposed to do. |
// // we are supposed to do. |
885 |
newTree->SetCircular(0); |
// newTree->SetCircular(0); |
886 |
|
|
887 |
// Reset the compression level of the branches. |
// // Reset the compression level of the branches. |
888 |
if (opt.Contains("c")) { |
// if (opt.Contains("c")) { |
889 |
TBranch* branch = 0; |
// TBranch* branch = 0; |
890 |
TIter nextb(newTree->GetListOfBranches()); |
// TIter nextb(newTree->GetListOfBranches()); |
891 |
while ((branch = (TBranch*) nextb())) { |
// while ((branch = (TBranch*) nextb())) { |
892 |
printf(" 29 \n"); |
// printf(" 29 \n"); |
893 |
branch->SetCompressionLevel(file->GetCompressionLevel()); |
// branch->SetCompressionLevel(file->GetCompressionLevel()); |
894 |
} |
// } |
895 |
} |
// } |
896 |
|
|
897 |
printf(" 30 \n"); |
// printf(" 30 \n"); |
898 |
// Reset the basket size of the branches. |
// // Reset the basket size of the branches. |
899 |
if (basketsize > 1000) { |
// if (basketsize > 1000) { |
900 |
TBranch* branch = 0; |
// TBranch* branch = 0; |
901 |
TIter nextb(newTree->GetListOfBranches()); |
// TIter nextb(newTree->GetListOfBranches()); |
902 |
while ((branch = (TBranch*) nextb())) { |
// while ((branch = (TBranch*) nextb())) { |
903 |
printf(" 31 \n"); |
// printf(" 31 \n"); |
904 |
branch->SetBasketSize(basketsize); |
// branch->SetBasketSize(basketsize); |
905 |
} |
// } |
906 |
} |
// } |
907 |
|
|
908 |
printf(" 32 \n"); |
// printf(" 32 \n"); |
909 |
Long64_t nentries = mychain->GetEntriesFast(); |
// Long64_t nentries = mychain->GetEntriesFast(); |
910 |
//Long64_t nentries = mychain->GetEntries(); |
// //Long64_t nentries = mychain->GetEntries(); |
911 |
|
|
912 |
// Copy the entries. |
// // Copy the entries. |
913 |
if (fastClone) { |
// if (fastClone) { |
914 |
// For each tree in the chain. |
// // For each tree in the chain. |
915 |
for (Long64_t i = 0; i < nentries; i += mychain->GetTree()->GetEntries()) { |
// for (Long64_t i = 0; i < nentries; i += mychain->GetTree()->GetEntries()) { |
916 |
if (mychain->LoadTree(i) < 0) { |
// if (mychain->LoadTree(i) < 0) { |
917 |
break; |
// break; |
918 |
} |
// } |
919 |
TTreeCloner cloner(mychain->GetTree(), newTree, option); |
// TTreeCloner cloner(mychain->GetTree(), newTree, option); |
920 |
if (cloner.IsValid()) { |
// if (cloner.IsValid()) { |
921 |
newTree->SetEntries(newTree->GetEntries() + mychain->GetTree()->GetEntries()); |
// newTree->SetEntries(newTree->GetEntries() + mychain->GetTree()->GetEntries()); |
922 |
cloner.Exec(); |
// cloner.Exec(); |
923 |
} else { |
// } else { |
924 |
if (mychain->GetFile()) { |
// if (mychain->GetFile()) { |
925 |
printf("Merge Skipped file %s\n", mychain->GetFile()->GetName()); |
// printf("Merge Skipped file %s\n", mychain->GetFile()->GetName()); |
926 |
// } else { |
// // } else { |
927 |
// Warning("Merge", "Skipped file number %d\n", fTreeNumber); |
// // Warning("Merge", "Skipped file number %d\n", fTreeNumber); |
928 |
} |
// } |
929 |
} |
// } |
930 |
} |
// } |
931 |
} else { |
// } else { |
932 |
printf(" 33 %llu \n",nentries); |
// printf(" 33 %llu \n",nentries); |
933 |
mychain->Print(); |
// mychain->Print(); |
934 |
for (Long64_t i = 0; i < nentries; i++) { |
// for (Long64_t i = 0; i < nentries; i++) { |
935 |
printf(" i %llu \n",i); |
// printf(" i %llu \n",i); |
936 |
// for (Long64_t i = 0; i < 1; i++) { |
// // for (Long64_t i = 0; i < 1; i++) { |
937 |
if (mychain->GetEntry(i) <= 0) { |
// if (mychain->GetEntry(i) <= 0) { |
938 |
break; |
// break; |
939 |
} |
// } |
940 |
newTree->Fill(); |
// newTree->Fill(); |
941 |
} |
// } |
942 |
printf(" 34 \n"); |
// printf(" 34 \n"); |
943 |
} |
// } |
944 |
|
|
945 |
// Write the new tree header. |
// // Write the new tree header. |
946 |
printf(" 35 \n"); |
// printf(" 35 \n"); |
947 |
newTree->Write(); |
// newTree->Write(); |
948 |
|
|
949 |
printf(" 36 \n"); |
// printf(" 36 \n"); |
950 |
// Get our return value. |
// // Get our return value. |
951 |
Int_t nfiles = newTree->GetFileNumber() + 1; |
// Int_t nfiles = newTree->GetFileNumber() + 1; |
952 |
|
|
953 |
// Close and delete the current file of the new tree. |
// // Close and delete the current file of the new tree. |
954 |
if (!opt.Contains("keep")) { |
// if (!opt.Contains("keep")) { |
955 |
// FIXME: What happens to fDirectory in newTree here? |
// // FIXME: What happens to fDirectory in newTree here? |
956 |
delete newTree->GetCurrentFile(); |
// delete newTree->GetCurrentFile(); |
957 |
} |
// } |
958 |
return nfiles; |
// return nfiles; |
959 |
} |
// } |