10 from PhysicsTools.HeppyCore.utils.batchmanager
import BatchManager
12 from PhysicsTools.HeppyCore.framework.heppy
import split
16 '''prepare the LSF version of the batch script, to run on LSF'''
17 script =
"""#!/bin/bash
21 export VO_CMS_SW_DIR=/cvmfs/cms.cern.ch
22 source $VO_CMS_SW_DIR/cmsset_default.sh
27 # ulimit -v 3000000 # NO
28 echo 'copying job dir to worker'
30 eval `scramv1 runtime -sh`
31 #eval `scramv1 ru -sh`
33 # eval `scramv1 ru -sh`
37 echo `find . -type d | grep /`
39 python $CMSSW_BASE/src/PhysicsTools/HeppyCore/python/framework/looper.py pycfg.py config.pck >& local.output
42 #echo 'sending the job directory back'
43 #echo cp -r Loop/* $LS_SUBCWD
49 '''prepare the LSF version of the batch script, to run on LSF'''
50 script =
"""#!/bin/bash
55 # ulimit -v 3000000 # NO
56 echo 'copying job dir to worker'
60 # eval `scramv1 ru -sh`
64 cd `find . -type d | grep /`
66 python $CMSSW_BASE/src/PhysicsTools/HeppyCore/python/framework/looper.py pycfg.py config.pck
68 echo 'sending the job directory back'
69 cp -r Loop/* $LS_SUBCWD
75 '''prepare the SGE version of the batch script, to run on the PSI tier3 batch system'''
77 cmssw_release = os.environ[
'CMSSW_BASE']
78 VO_CMS_SW_DIR =
"/swshare/cms"
81 cpCmd=
"""echo 'sending the job directory back'
82 cp -r Loop/* $SUBMISIONDIR"""
83 elif remoteDir.startswith(
"/pnfs/psi.ch"):
84 cpCmd=
"""echo 'sending root files to remote dir'
85 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib64/dcap/ # Fabio's workaround to fix gfal-tools
86 for f in Loop/treeProducerSusyFullHad/*.root
89 ff=`basename $f | cut -d . -f 1`
92 echo "gfal-copy file:///`pwd`/Loop/treeProducerSusyFullHad/$file.root {srm}/${{ff}}_{idx}.root"
93 gfal-copy file:///`pwd`/Loop/treeProducerSusyFullHad/$ff.root {srm}/${{ff}}_{idx}.root
95 rm Loop/treeProducerSusyFullHad/*.root
96 echo 'sending the logs back'
97 cp -r Loop/* $SUBMISIONDIR""".
format(idx=index, srm=
'srm://t3se01.psi.ch'+remoteDir+jobDir[jobDir.rfind(
"/"):jobDir.find(
"_Chunk")])
99 print "remote directory not supported yet: ", remoteDir
100 print 'path must start with "/pnfs/psi.ch"'
104 script =
"""#!/bin/bash
106 ##### MONITORING/DEBUG INFORMATION ###############################
107 DATE_START=`date +%s`
108 echo "Job started at " `date`
110 ################################################################
111 ## QUEUEING SYSTEM SETTINGS:
121 echo "######## Environment Variables ##########"
123 echo "################################################################"
124 TOPWORKDIR=/scratch/`whoami`
125 JOBDIR=sgejob-$JOB_ID
126 WORKDIR=$TOPWORKDIR/$JOBDIR
128 if test -e "$WORKDIR"; then
129 echo "ERROR: WORKDIR ($WORKDIR) already exists! Aborting..." >&2
133 if test ! -d "$WORKDIR"; then
134 echo "ERROR: Failed to create workdir ($WORKDIR)! Aborting..." >&2
138 #source $VO_CMS_SW_DIR/cmsset_default.sh
139 source {vo}/cmsset_default.sh
140 export SCRAM_ARCH=slc6_amd64_gcc481
143 shopt -s expand_aliases
146 cp -rf $SUBMISIONDIR .
148 cd `find . -type d | grep /`
150 #python $CMSSW_BASE/src/CMGTools/RootTools/python/fwlite/looper.py config.pck
151 python {cmssw}/src/CMGTools/RootTools/python/fwlite/looper.py pycfg.py config.pck
154 ###########################################################################
156 RUNTIME=$((DATE_END-DATE_START))
157 echo "################################################################"
158 echo "Job finished at " `date`
159 echo "Wallclock running time: $RUNTIME s"
161 """.
format(jdir=jobDir, vo=VO_CMS_SW_DIR,cmssw=cmssw_release, copy=cpCmd)
166 '''prepare a IC version of the batch script'''
169 cmssw_release = os.environ[
'CMSSW_BASE']
170 script =
"""#!/bin/bash
171 export X509_USER_PROXY=/home/hep/$USER/myproxy
172 source /vols/cms/grid/setup.sh
175 eval `scramv1 ru -sh`
178 python {cmssw}/src/PhysicsTools/HeppyCore/python/framework/looper.py pycfg.py config.pck
180 echo 'sending the job directory back'
182 """.
format(jobdir = jobDir,cmssw = cmssw_release)
186 '''prepare a local version of the batch script, to run using nohup'''
188 script =
"""#!/bin/bash
190 python $CMSSW_BASE/src/PhysicsTools/HeppyCore/python/framework/looper.py pycfg.py config.pck echo
191 echo 'sending the job directory back'
198 '''Batch manager specific to cmsRun processes.'''
201 '''Prepare one job. This function is called by the base class.'''
203 print components[value]
206 scriptFileName = jobDir+
'/batchScript.sh'
207 scriptFile = open(scriptFileName,
'w')
208 storeDir = self.remoteOutputDir_.replace(
'/castor/cern.ch/cms',
'')
209 mode = self.RunningMode(options.batch)
213 scriptFile.write( batchScriptPSI ( value, jobDir, storeDir ) )
214 elif mode ==
'LOCAL':
216 elif mode ==
'PISA' :
221 os.system(
'chmod +x %s' % scriptFileName)
223 shutil.copyfile(cfgFileName, jobDir+
'/pycfg.py')
226 cfgFile = open(jobDir+
'/config.pck',
'w')
227 pickle.dump( components[value] , cfgFile )
232 if __name__ ==
'__main__':
234 batchManager.parser_.usage=
"""
235 %prog [options] <cfgFile>
237 Run Colin's python analysis system on the batch.
238 Job splitting is determined by your configuration file.
241 options, args = batchManager.ParseOptions()
243 cfgFileName = args[0]
245 handle = open(cfgFileName,
'r')
246 cfo = imp.load_source("pycfg", cfgFileName, handle)
250 components =
split( [comp
for comp
in config.components
if len(comp.files)>0] )
251 listOfValues = range(0, len(components))
252 listOfNames = [comp.name
for comp
in components]
254 batchManager.PrepareJobs( listOfValues, listOfNames )
256 batchManager.SubmitJobs( waitingTime )