10 from PhysicsTools.HeppyCore.utils.batchmanager
import BatchManager
15 '''prepare the LSF version of the batch script, to run on LSF'''
16 script =
"""#!/bin/bash
23 export VO_CMS_SW_DIR=/cvmfs/cms.cern.ch
24 source $VO_CMS_SW_DIR/cmsset_default.sh
29 # ulimit -v 3000000 # NO
30 echo 'copying job dir to worker'
31 eval `scram runtime -sh`
34 python $CMSSW_BASE/src/PhysicsTools/HeppyCore/python/framework/looper.py pycfg.py config.pck >& local.output
37 #echo 'sending the job directory back'
38 #echo cp -r Loop/* $LS_SUBCWD
44 '''prepare the LSF version of the batch script, to run on LSF'''
45 script =
"""#!/bin/bash
49 export VO_CMS_SW_DIR=/cvmfs/cms.cern.ch
50 source $VO_CMS_SW_DIR/cmsset_default.sh
55 # ulimit -v 3000000 # NO
56 echo 'copying job dir to worker'
58 eval `scramv1 runtime -sh`
59 #eval `scramv1 ru -sh`
61 # eval `scramv1 ru -sh`
65 echo `find . -type d | grep /`
67 python $CMSSW_BASE/src/PhysicsTools/HeppyCore/python/framework/looper.py pycfg.py config.pck >& local.output
70 #echo 'sending the job directory back'
71 #echo cp -r Loop/* $LS_SUBCWD
76 '''prepare the LSF version of the batch script, to run on LSF'''
78 dirCopy =
"""echo 'sending the logs back' # will send also root files if copy failed
79 cp -r Loop/* $LS_SUBCWD
81 echo 'ERROR: problem copying job directory back'
83 echo 'job directory copy succeeded'
87 elif remoteDir.startswith(
"/pnfs/psi.ch"):
88 cpCmd=
"""echo 'sending root files to remote dir'
89 export LD_LIBRARY_PATH=/usr/lib64:$LD_LIBRARY_PATH # Fabio's workaround to fix gfal-tools with CMSSW
90 for f in Loop/mt2*.root
92 ff=`basename $f | cut -d . -f 1`
93 #d=`echo $f | cut -d / -f 2`
95 echo "gfal-copy file://`pwd`/Loop/$ff.root {srm}/${{ff}}_{idx}.root"
96 gfal-copy file://`pwd`/Loop/$ff.root {srm}/${{ff}}_{idx}.root
98 echo "ERROR: remote copy failed for file $ff"
100 echo "remote copy succeeded"
105 """.
format(idx=jobDir[jobDir.find(
"_Chunk")+6:].strip(
"/"), srm=
'srm://t3se01.psi.ch'+remoteDir+jobDir[jobDir.rfind(
"/"):jobDir.find(
"_Chunk")]) + dirCopy
107 print "chosen location not supported yet: ", remoteDir
108 print 'path must start with "/pnfs/psi.ch"'
111 script =
"""#!/bin/bash
116 # ulimit -v 3000000 # NO
117 echo 'copying job dir to worker'
119 eval `scramv1 ru -sh`
121 # eval `scramv1 ru -sh`
125 cd `find . -type d | grep /`
127 python $CMSSW_BASE/src/PhysicsTools/HeppyCore/python/framework/looper.py pycfg.py config.pck
136 '''prepare the SGE version of the batch script, to run on the PSI tier3 batch system'''
138 cmssw_release = os.environ[
'CMSSW_BASE']
139 VO_CMS_SW_DIR =
"/swshare/cms"
142 cpCmd=
"""echo 'sending the job directory back'
143 cp -r Loop/* $SUBMISIONDIR"""
144 elif remoteDir.startswith(
"/pnfs/psi.ch"):
145 cpCmd=
"""echo 'sending root files to remote dir'
146 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib64/dcap/ # Fabio's workaround to fix gfal-tools
147 for f in Loop/treeProducerSusyFullHad/*.root
150 ff=`basename $f | cut -d . -f 1`
153 echo "gfal-copy file:///`pwd`/Loop/treeProducerSusyFullHad/$file.root {srm}/${{ff}}_{idx}.root"
154 gfal-copy file:///`pwd`/Loop/treeProducerSusyFullHad/$ff.root {srm}/${{ff}}_{idx}.root
156 rm Loop/treeProducerSusyFullHad/*.root
157 echo 'sending the logs back'
158 cp -r Loop/* $SUBMISIONDIR""".
format(idx=index, srm=
'srm://t3se01.psi.ch'+remoteDir+jobDir[jobDir.rfind(
"/"):jobDir.find(
"_Chunk")])
160 print "remote directory not supported yet: ", remoteDir
161 print 'path must start with "/pnfs/psi.ch"'
165 script =
"""#!/bin/bash
167 ##### MONITORING/DEBUG INFORMATION ###############################
168 DATE_START=`date +%s`
169 echo "Job started at " `date`
171 ################################################################
172 ## QUEUEING SYSTEM SETTINGS:
182 echo "######## Environment Variables ##########"
184 echo "################################################################"
185 TOPWORKDIR=/scratch/`whoami`
186 JOBDIR=sgejob-$JOB_ID
187 WORKDIR=$TOPWORKDIR/$JOBDIR
189 if test -e "$WORKDIR"; then
190 echo "ERROR: WORKDIR ($WORKDIR) already exists! Aborting..." >&2
194 if test ! -d "$WORKDIR"; then
195 echo "ERROR: Failed to create workdir ($WORKDIR)! Aborting..." >&2
199 #source $VO_CMS_SW_DIR/cmsset_default.sh
200 source {vo}/cmsset_default.sh
201 export SCRAM_ARCH=slc6_amd64_gcc481
204 shopt -s expand_aliases
207 cp -rf $SUBMISIONDIR .
209 cd `find . -type d | grep /`
211 #python $CMSSW_BASE/src/CMGTools/RootTools/python/fwlite/looper.py config.pck
212 python {cmssw}/src/CMGTools/RootTools/python/fwlite/looper.py pycfg.py config.pck
215 ###########################################################################
217 RUNTIME=$((DATE_END-DATE_START))
218 echo "################################################################"
219 echo "Job finished at " `date`
220 echo "Wallclock running time: $RUNTIME s"
222 """.
format(jdir=jobDir, vo=VO_CMS_SW_DIR,cmssw=cmssw_release, copy=cpCmd)
227 '''prepare a IC version of the batch script'''
230 cmssw_release = os.environ[
'CMSSW_BASE']
231 script =
"""#!/bin/bash
232 export X509_USER_PROXY=/home/hep/$USER/myproxy
233 source /vols/cms/grid/setup.sh
236 eval `scramv1 ru -sh`
239 python {cmssw}/src/PhysicsTools/HeppyCore/python/framework/looper.py pycfg.py config.pck
241 echo 'sending the job directory back'
242 mv Loop/* ./ && rm -r Loop
243 """.
format(jobdir = jobDir,cmssw = cmssw_release)
247 '''prepare a local version of the batch script, to run using nohup'''
249 script =
"""#!/bin/bash
251 python $CMSSW_BASE/src/PhysicsTools/HeppyCore/python/framework/looper.py pycfg.py config.pck
253 echo 'sending the job directory back'
260 '''Batch manager specific to cmsRun processes.'''
263 '''Prepare one job. This function is called by the base class.'''
265 print components[value]
268 scriptFileName = jobDir+
'/batchScript.sh'
269 scriptFile = open(scriptFileName,
'w')
270 storeDir = self.remoteOutputDir_.replace(
'/castor/cern.ch/cms',
'')
271 mode = self.RunningMode(options.batch)
275 scriptFile.write( batchScriptPSI ( value, jobDir, storeDir ) )
276 elif mode ==
'LOCAL':
278 elif mode ==
'PISA' :
280 elif mode ==
'PADOVA' :
285 os.system(
'chmod +x %s' % scriptFileName)
287 shutil.copyfile(cfgFileName, jobDir+
'/pycfg.py')
290 cfgFile = open(jobDir+
'/config.pck',
'w')
291 pickle.dump( components[value] , cfgFile )
296 if __name__ ==
'__main__':
298 batchManager.parser_.usage=
"""
299 %prog [options] <cfgFile>
301 Run Colin's python analysis system on the batch.
302 Job splitting is determined by your configuration file.
305 options, args = batchManager.ParseOptions()
307 cfgFileName = args[0]
309 handle = open(cfgFileName,
'r')
311 cfo = imp.load_source(
"pycfg", cfgFileName, handle)
315 components =
split( [comp
for comp
in config.components
if len(comp.files)>0] )
316 listOfValues = range(0, len(components))
317 listOfNames = [comp.name
for comp
in components]
319 batchManager.PrepareJobs( listOfValues, listOfNames )
321 batchManager.SubmitJobs( waitingTime )