Crombie Tools
submitlxbatch.sh
Go to the documentation of this file.
1 #!/bin/bash
2 
3 ##
4 # @file submitlxbatch.sh
5 #
6 # Script that is used to submit jobs to lxbatch.
7 # See the [command line tool reference](@ref commandref)
8 # for more information on subcommands.
9 #
10 # @author Daniel Abercrombie <dabercro@mit.edu>
11 #
12 
13 export fresh=$1
14 
15 # Check for the configuration file
16 
17 if [ ! -f CrombieSlimmingConfig.sh ]
18 then
19 
20  echo "CrombieSlimmingConfig.sh isn't here."
21  echo "You should probably go somewhere else."
22  exit 1
23 
24 fi
25 
26 # Requires CMSSW to get ROOT, unfortunately
27 ## @todo Try to eliminate the dependency on CMSSW
28 
29 if [ "$CMSSW_BASE" = "" ]
30 then
31 
32  echo "Require you to be cmsenv somewhere"
33  exit 1
34 
35 fi
36 
37 # Record the submission in this log file
38 
39 logFile=$(pwd)/LxbatchFileChecks.log
40 sub=""
41 
42 if [ "$fresh" != "" ]
43 then
44 
45  sub=" $fresh"
46 
47 fi
48 
49 submitLog="Ran crombie submitlxbatch$sub at "$(date -u)
50 export subLogCharNum=${#submitLog}
51 delim=$(perl -e 'print "=" x $ENV{'subLogCharNum'}';)
52 
53 echo "$delim" >> $logFile
54 echo "$submitLog" >> $logFile
55 echo "$delim" >> $logFile
56 
57 if [ ! -d bout ] # Make sure there's a place for the job's stdout.
58 then
59 
60  mkdir bout
61 
62 fi
63 
64 source CrombieSlimmingConfig.sh # Get needed environment variables
65 
66 # Check that needed environment variables are present
67 
68 echo "${CrombieFilesPerJob:?}" > /dev/null
69 echo "${CrombieQueue:?}" > /dev/null
70 echo "${CrombieEosDir:?}" > /dev/null
71 echo "${CrombieTempDir:?}" > /dev/null
72 echo "${CrombieFullDir:?}" > /dev/null
73 echo "${CrombieSlimmerScript:?}" > /dev/null
74 echo "${CrombieJobScriptList:?}" > /dev/null
75 echo "${CrombieCheckerScript:?}" > /dev/null
76 
77 export haddFile=$CrombieTempDir/myHadd.txt
78 
79 if [ "$CrombieNBatchProcs" = "" ]
80 then
81 
82  if [ "$CrombieQueue" = "2nw4cores" ]
83  then
84 
85  CrombieNBatchProcs=4
86 
87  else
88 
89  CrombieNBatchProcs=1
90 
91  fi
92 
93 fi
94 
95 # Dump the list of files on EOS to run on
96 
97 if [ "$fresh" != "resub" -a "$fresh" != "hadd" ]
98 then
99 
100  crombie dumpfilelist eos
101 
102  if [ $? -ne 0 ]
103  then
104 
105  echo "Crashed while dumping file list."
106  exit 1
107 
108  fi
109 
110 fi
111 
112 ranOnFile=0 # Keep track on if files are submitted or not
113 
114 if [ "$fresh" != "hadd" ]
115 then
116 
117  rootNames=$(ls $CrombieTempDir/$CrombieFileBase\_*_*.txt | sed 's/.txt//')
118 
119  for outFile in $rootNames
120  do
121 
122  if [ ! -f $outFile.root ] # Check each file to see if they exist, if not, submit
123  then
124 
125  echo "Making: $outFile"
126  command="bsub -q $CrombieQueue -n $CrombieNBatchProcs -o bout/out_$(date +%y%m%d)_$(basename $outFile)_%J.log crombie dojob $outFile"
127 
128  if [ "$fresh" = "test" ] # Echo the command if a test
129  then # otherwise, execute it
130 
131  echo $command
132 
133  else
134 
135  $command
136 
137  fi
138 
139  ranOnFile=1 # Job was submitted
140  fi
141 
142  done
143 
144 else
145 
146  echo "Going directly to hadd step."
147 
148 fi
149 
150 if [ "$ranOnFile" -eq 0 ] # If no jobs submitted or tested, hadd
151 then
152 
153  echo "${CrombieNLocalProcs:?}" > /dev/null
154  cat $haddFile | xargs -n2 -P$CrombieNLocalProcs crombie hadd
155  echo "All files merged!"
156 
157 fi