reSubmitParallelFlowJobs.pl 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. #! /opt/star/bin/perl -w
  2. use Carp ();
  3. local $SIG{__WARN__} = \&Carp::cluck;
  4. $help =<<"EOF";
  5. usage: $0 --f=
  6. --f, the configuration file of a job.
  7. EOF
  8. use Cwd 'abs_path'; # aka realpath()
  9. use Getopt::Long;
  10. GetOptions( "f=s" => \$configFile );
  11. die $help," Pl. specify the configuration file."
  12. unless defined $configFile;
  13. # read in config file
  14. open (CONFIG, "< $configFile") or die "can't open $configFile $!";
  15. while (<CONFIG>){
  16. chomp; # no newline
  17. s/#.*//; # no comments
  18. s/^\s+//; # no leading white
  19. s/\s+$//; # no trailing white
  20. next unless length; # anything left?
  21. my ($var, $value) = split (/\s*:\s*/, $_,2);
  22. $ConfigMap{$var} = $value;
  23. }
  24. close(CONFIG);
  25. @flowCents = (
  26. "cen1", # do not change these names
  27. "cen2",
  28. "cen3",
  29. "cen4",
  30. "cen5",
  31. "cen6",
  32. "cen7",
  33. "cen8"
  34. );
  35. my $macroName = $ConfigMap{"macroName"};
  36. my $libVersion = $ConfigMap{"libVersion"};
  37. my $runJob = $ConfigMap{"scriptName"};
  38. my $jobPrefix = $ConfigMap{"partnPrefix"};
  39. my $picoDstLink = $ConfigMap{"picoDSTLink"};
  40. my $NPartition = $ConfigMap{"NPartition"};
  41. my $jobDir = $ConfigMap{"jobDir"};
  42. my $jobName = $ConfigMap{"jobName"};
  43. my $dataDir = $ConfigMap{"dataDir"};
  44. my $logFile = $ConfigMap{"logFileName"};
  45. my $histFile = $ConfigMap{"histoFile"};
  46. my $meanGFile = $ConfigMap{"meanGFile"};
  47. my $weightFile = $ConfigMap{"weightFile"};
  48. my $yieldFile = $ConfigMap{"yieldFile"};
  49. ($meanGCombined = $meanGFile) =~ s/New//;
  50. ($weightCombined = $weightFile) =~ s/New//;
  51. my $starVer = $ENV{STAR_LEVEL};
  52. if ($libVersion !~ m/$starVer/) {
  53. die "#### Your current STAR_LEVEL is $starVer, please change it to $libVersion and run this script again. \n";
  54. }
  55. # check the existence
  56. for ($m=1; $m<$NPartition+1; $m++) {
  57. foreach $cent(@flowCents){
  58. -e "$jobDir/$jobName/$jobPrefix$m/$cent/$histFile" or
  59. die " $jobDir/$jobName/$jobPrefix$m/$cent/$histFile doesn't exists \n";
  60. -e "$jobDir/$jobName/$jobPrefix$m/$cent/$meanGFile" or
  61. die " $jobDir/$jobName/$jobPrefix$m/$cent/$meanGFile doesn't exists \n";
  62. -e "$jobDir/$jobName/$jobPrefix$m/$cent/$weightFile" or
  63. warn " $jobDir/$jobName/$jobPrefix$m/$cent/$weightFile doesn't exists \n";
  64. -e "$jobDir/$jobName/$jobPrefix$m/$cent/$logFile" or
  65. warn " $jobDir/$jobName/$jobPrefix$m/$cent/$logFile doesn't exists \n";
  66. }
  67. }
  68. # cleaning
  69. for ($m=1; $m<$NPartition+1; $m++) {
  70. foreach $cent(@flowCents){
  71. `mv $jobDir/$jobName/$jobPrefix$m/$cent/$logFile $jobDir/$jobName/$jobPrefix$m/$cent/$logFile.old`;
  72. `mv $jobDir/$jobName/$jobPrefix$m/$cent/$histFile $jobDir/$jobName/$jobPrefix$m/$cent/$histFile.old`;
  73. `mv $jobDir/$jobName/$jobPrefix$m/$cent/$yieldFile $jobDir/$jobName/$jobPrefix$m/$cent/$yieldFile.old`;
  74. }
  75. }
  76. # combine histo
  77. my $combineMacroName="myCombine";
  78. foreach $cent(@flowCents){
  79. # create a macro that combine files
  80. open ( combineMacro, ">".$combineMacroName.".C");
  81. print combineMacro "void $combineMacroName(const char* histoFileName, const char* newfilename) { \n";
  82. print combineMacro " TObjArray* toBeAddedFiles = new TObjArray(); \n";
  83. for ($m=1; $m<$NPartition+1; $m++) {
  84. print combineMacro "char dummyName$m\[256\]; \n";
  85. print combineMacro "sprintf(dummyName$m,\"$jobDir/$jobName/$jobPrefix$m/$cent/\%s\",histoFileName); \n";
  86. print combineMacro "toBeAddedFiles->AddLast((TObject *)(new TObjString(dummyName$m))); \n";
  87. }
  88. print combineMacro " TFile* newfile = new TFile(newfilename,\"RECREATE\"); \n";
  89. print combineMacro " TFile* oldfile1 = new TFile(((TObjString *)(toBeAddedFiles->At(0)))->GetName(),\"READ\"); \n";
  90. print combineMacro " TList* list = oldfile1->GetListOfKeys(); \n";
  91. print combineMacro " TIter next(list); \n";
  92. print combineMacro " TKey* key; \n";
  93. print combineMacro " TObject* obj; \n";
  94. print combineMacro " while (key = (TKey*)next()) { \n";
  95. print combineMacro " obj = oldfile1->Get(key->GetName()); \n";
  96. print combineMacro " if (!obj) return; \n";
  97. print combineMacro " if(obj->IsA() == TDirectory::Class()){ \n";
  98. print combineMacro " delete obj; \n";
  99. print combineMacro " obj = NULL; \n";
  100. print combineMacro " continue; \n";
  101. print combineMacro " } \n";
  102. print combineMacro " TObject* newobj = obj->Clone(); \n";
  103. print combineMacro " if (newobj->InheritsFrom( TH1::Class())) { \n";
  104. print combineMacro " for (int k=1; k<toBeAddedFiles->GetEntries(); k++){ \n";
  105. print combineMacro " TFile* f =new TFile(((TObjString *)(toBeAddedFiles->At(k)))->GetName(), \"READ\"); \n";
  106. print combineMacro "((TH1 *) newobj)->Add(((TH1 *)f->Get(key->GetName()))); \n";
  107. print combineMacro " delete f; \n";
  108. print combineMacro " } \n";
  109. print combineMacro " } \n";
  110. print combineMacro " newfile->cd(); \n";
  111. print combineMacro " newobj->Write(); \n";
  112. print combineMacro " delete newobj; \n";
  113. print combineMacro " } \n";
  114. print combineMacro " gROOT->cd(); \n";
  115. print combineMacro " delete key; \n";
  116. print combineMacro " newfile->Write(); \n";
  117. print combineMacro " newfile->Close(); \n";
  118. print combineMacro " } \n";
  119. close combineMacro;
  120. # now run the combine macro
  121. # do not combine the phi weight file!! otherwise the combined weight
  122. # is around 1*NPartition, NOT GOOD! Should change phiweight from histo.to
  123. # TProfile.
  124. print "combining $meanGFile for $cent \n";
  125. `source /auto/u/aihong/.starver $libVersion \n`;
  126. `time root4star -b -q '$combineMacroName.C("$meanGFile", "$meanGCombined")' > myCombineMeanG$cent.log`;
  127. # copy the combined files to run dirs
  128. for ($m=1; $m<$NPartition+1; $m++) {
  129. `cp $meanGCombined $jobDir/$jobName/$jobPrefix$m/$cent/$meanGCombined `;
  130. }
  131. `rm $meanGCombined`;
  132. `rm myCombineMeanG$cent.log`;
  133. }
  134. # re-submit jobs
  135. for ($m=1; $m<$NPartition+1; $m++) {
  136. foreach $cent(@flowCents) {
  137. print `bsub -q medium < $jobDir/$jobName/$jobPrefix$m/$cent/$runJob`;
  138. }
  139. }
  140. exit;