doFlowSubmitOne.pl 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #!/usr/bin/perl -w
  2. # doFlowSubmitOne.pl is a perl script to submit doFlowEvents.C
  3. # It is meant for StFlowDirectCumulantMaker because all centralities are done at once in this Maker
  4. # The $homeDir directory should contain a link to your inDir, and to your outDir
  5. # The $macDir directory should contain doFlowEvents.C
  6. # The $rootDir directory should contain the library dot file
  7. # $inDir should be a link to a directory containing subdirectories of files
  8. # $outDir is a link to where you want your output
  9. # If the 1st pass has completed there is no submission
  10. # rm outDir/*/doFlowEvents.C if it has changed
  11. # by Art Poskanzer
  12. use strict;
  13. use File::Basename;
  14. use File::Copy;
  15. use Getopt::Std;
  16. my $events = 200000;
  17. #my $events = 100;
  18. my $queTime = "25:00:00"; # always bombs after 1 day
  19. #my $queTime = "01:00:00";
  20. # options
  21. # -t :test, no submission
  22. my %opt;
  23. getopts('t',\%opt);
  24. my $usage = "usage: -opts inDir runNo \n";
  25. # set directories
  26. my $inDir = shift or die $usage;
  27. my $outDir = "./outDir"; # directory for output
  28. my $runNo = shift or die $usage;
  29. -e $inDir or die "$inDir :$!\n";
  30. ###### User defined:
  31. my $homeDir = "~posk/directCumulant"; # directory containing the links
  32. my $macDir = "$homeDir/mac"; # directory containing the macro
  33. my $rootDir = "$homeDir"; # directory containing the library
  34. print "homeDir = $homeDir\n";
  35. print "inDir = $inDir\n";
  36. print "outDir = $outDir\n";
  37. print "macDir = $macDir\n";
  38. print "rootDir = $rootDir\n";
  39. my $fileExt = "*MuDst.root";
  40. my $starVer = basename $ENV{STAR};
  41. my $io = 1;
  42. my $resource = '';
  43. # which machine are we at?
  44. if ($ENV{HOST} =~ /pdsf/) {
  45. if ($inDir eq "in4") {
  46. $resource = "-l eliza9io=$io"; # in4
  47. } elsif ($inDir eq "in7" || $inDir eq "in73") {
  48. $resource = "-l eliza12io=$io"; # in7
  49. } else {
  50. $resource = "-l eliza3io=$io"; # eliza3 year7 data
  51. }
  52. } else {
  53. die "wrong host $ENV{HOST}\n";
  54. }
  55. print "host = $ENV{HOST}\n";
  56. print "resource = $resource\n";
  57. print "star ver.= $starVer\n";
  58. print "max time = $queTime\n";
  59. print "events = $events\n";
  60. my $command;
  61. my $firstPass;
  62. my $workDir;
  63. my $exec = "qsub -V -m e"; # for mail at the end
  64. #my $exec = "qsub -V"; # for no mail
  65. my $subDirNo;
  66. # subdirectory loop
  67. my @subDirs;
  68. if ( `ls -l $inDir/ | grep ^d` ) { # subdirectories?
  69. @subDirs = split(/\n/,`ls $inDir`); # yes
  70. } else {
  71. @subDirs = "."; # no subdirectories
  72. }
  73. print "subdirectories: @subDirs\n";
  74. foreach my $subDir (@subDirs) {
  75. if ( -d "$inDir/$subDir" && `ls $inDir/$subDir/` ) { # dir exists and contains a file
  76. $firstPass = "kFALSE";
  77. #$subDirNo = substr($subDir, index($subDir, ".")+1, 4); # 4 chars after the dot
  78. $subDirNo = substr($subDir,-3, 3); # last 3 chars
  79. # make work directory
  80. $workDir = "$outDir/$inDir-$subDir-$runNo";
  81. -e $workDir or do {
  82. print "making $workDir directory\n";
  83. mkdir $workDir,0755 or die "$!\n";
  84. };
  85. # copy doFlowEvents.C
  86. -e "$workDir/doFlowEvents.C" or do {
  87. $command = "cp $macDir/doFlowEvents.C $workDir/doFlowEvents.C"; # don't use copy
  88. print $command,"\n";
  89. `$command`;
  90. };
  91. # make links
  92. -e "$workDir/.sl44_gcc346" or do {
  93. $command = "ln -s $rootDir/.sl44_gcc346 $workDir/.sl44_gcc346";
  94. print $command,"\n";
  95. `$command`;
  96. };
  97. -e "$workDir/M_WeightsY7.root" or do {
  98. $command = "ln -s $rootDir/M_WeightsY7.root $workDir/M_WeightsY7.root";
  99. print $command,"\n";
  100. `$command`;
  101. };
  102. -e "$workDir/$inDir" or do {
  103. $command = "ln -s $homeDir/$inDir $workDir/$inDir";
  104. print $command,"\n";
  105. `$command`;
  106. };
  107. my $firstPassOutput = "$workDir/flow.dirCumulant.root";
  108. my $firstPassDone = "kFALSE";
  109. if (-e $firstPassOutput) {
  110. $firstPassDone = "kTRUE";
  111. print "$subDir-$runNo firstPassDone\n";
  112. }
  113. # make the shell script
  114. my $scriptName = "$workDir/flow.csh";
  115. open(FH,">$scriptName") or die "$scriptName : $!\n";
  116. print FH <<EOF;
  117. #!/bin/csh
  118. #\$ -o /dev/null
  119. #\$ -e /dev/null
  120. #\$ -M AMPoskanzer\@LBL.gov
  121. #\$ -m a
  122. cd $workDir
  123. source \$GROUP_DIR/.starver $starVer
  124. set logDir = \$SCRATCH
  125. set log = \$logDir/ana.log
  126. root4star -b << FINIS >&! \$log
  127. .L doFlowEvents.C
  128. doFlowEvents($events,"$inDir/$subDir","$fileExt")
  129. .q
  130. FINIS
  131. set outLog = ana.log
  132. head -130 \$log > \$outLog
  133. echo " " >> \$outLog
  134. echo "######################## head -> tail ##########################" >> \$outLog
  135. echo " " >> \$outLog
  136. tail -300 \$log >> \$outLog
  137. exit
  138. EOF
  139. # execute the shell script, option N should have only 10 characters
  140. close FH;
  141. chmod 0755, $scriptName;
  142. $command = "$exec -hard $resource -l h_cpu=$queTime -N $inDir$subDirNo-$runNo $scriptName";
  143. if ($firstPassDone eq "kFALSE") { # skip if 1st pass completed
  144. print "##### ",$command,"\n";
  145. `$command` unless $opt{t};
  146. };
  147. }
  148. }
  149. #///////////////////////////////////////////////////////////////////////////////
  150. #//
  151. #// $Log: doFlowSubmitOne.pl,v $
  152. #// Revision 1.1 2010/03/08 16:54:51 posk
  153. #// Added StFlowDirectCumulantMaker written by Dhevan Gangadharan.
  154. #//
  155. #//
  156. #///////////////////////////////////////////////////////////////////////////////