11 from PhysicsTools.HeppyCore.utils.batchmanager
import BatchManager
13 from PhysicsTools.HeppyCore.framework.heppy_loop
import split
16 '''prepare the LSF version of the batch script, to run on LSF'''
17 script =
"""#!/bin/bash
24 export VO_CMS_SW_DIR=/cvmfs/cms.cern.ch
25 source $VO_CMS_SW_DIR/cmsset_default.sh
30 # ulimit -v 3000000 # NO
31 echo 'copying job dir to worker'
32 eval `scram runtime -sh`
35 python $CMSSW_BASE/src/PhysicsTools/HeppyCore/python/framework/looper.py pycfg.py config.pck --options=options.json >& local.output
38 #echo 'sending the job directory back'
39 #echo cp -r Loop/* $LS_SUBCWD
45 '''prepare the LSF version of the batch script, to run on LSF'''
46 script =
"""#!/bin/bash
50 export VO_CMS_SW_DIR=/cvmfs/cms.cern.ch
51 source $VO_CMS_SW_DIR/cmsset_default.sh
56 # ulimit -v 3000000 # NO
57 echo 'copying job dir to worker'
59 eval `scramv1 runtime -sh`
60 #eval `scramv1 ru -sh`
62 # eval `scramv1 ru -sh`
66 echo `find . -type d | grep /`
68 python $CMSSW_BASE/src/PhysicsTools/HeppyCore/python/framework/looper.py pycfg.py config.pck --options=options.json >& local.output
71 #echo 'sending the job directory back'
72 #echo cp -r Loop/* $LS_SUBCWD
77 '''prepare the LSF version of the batch script, to run on LSF'''
79 dirCopy =
"""echo 'sending the logs back' # will send also root files if copy failed
80 rm Loop/cmsswPreProcessing.root
81 cp -r Loop/* $LS_SUBCWD
83 echo 'ERROR: problem copying job directory back'
85 echo 'job directory copy succeeded'
90 elif remoteDir.startswith(
"root://eoscms.cern.ch//eos/cms/store/"):
91 cpCmd=
"""echo 'sending root files to remote dir'
92 export LD_LIBRARY_PATH=/usr/lib64:$LD_LIBRARY_PATH #
93 for f in Loop/tree*.root
95 ff=`basename $f | cut -d . -f 1`
98 export VO_CMS_SW_DIR=/cvmfs/cms.cern.ch
99 source $VO_CMS_SW_DIR/cmsset_default.sh
100 echo "gfal-copy file://`pwd`/Loop/$ff.root {srm}/${{ff}}_{idx}.root"
101 gfal-copy file://`pwd`/Loop/$ff.root {srm}/${{ff}}_{idx}.root
103 if [ $? -ne 0 ]; then
104 echo "ERROR: remote copy failed for file $ff"
106 echo "remote copy succeeded"
111 """.
format(idx=jobDir[jobDir.find(
"_Chunk")+6:].strip(
"/"), srm=
""+remoteDir+jobDir[jobDir.rfind(
"/"):jobDir.find(
"_Chunk")])
113 print "chosen location not supported yet: ", remoteDir
114 print 'path must start with /store/'
117 script =
"""#!/bin/bash
122 # ulimit -v 3000000 # NO
123 echo 'copying job dir to worker'
125 eval `scramv1 ru -sh`
127 # eval `scramv1 ru -sh`
131 cd `find . -type d | grep /`
133 python $CMSSW_BASE/src/PhysicsTools/HeppyCore/python/framework/looper.py pycfg.py config.pck --options=options.json
142 '''prepare the SGE version of the batch script, to run on the PSI tier3 batch system'''
144 cmssw_release = os.environ[
'CMSSW_BASE']
145 VO_CMS_SW_DIR =
"/swshare/cms"
148 cpCmd=
"""echo 'sending the job directory back'
149 cp -r Loop/* $SUBMISIONDIR"""
150 elif remoteDir.startswith(
"/pnfs/psi.ch"):
151 cpCmd=
"""echo 'sending root files to remote dir'
152 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib64/dcap/ # Fabio's workaround to fix gfal-tools
153 for f in Loop/treeProducerSusyFullHad/*.root
156 ff=`basename $f | cut -d . -f 1`
159 echo "gfal-copy file:///`pwd`/Loop/treeProducerSusyFullHad/$file.root {srm}/${{ff}}_{idx}.root"
160 gfal-copy file:///`pwd`/Loop/treeProducerSusyFullHad/$ff.root {srm}/${{ff}}_{idx}.root
162 rm Loop/treeProducerSusyFullHad/*.root
163 echo 'sending the logs back'
164 cp -r Loop/* $SUBMISIONDIR""".
format(idx=index, srm=
'srm://t3se01.psi.ch'+remoteDir+jobDir[jobDir.rfind(
"/"):jobDir.find(
"_Chunk")])
166 print "remote directory not supported yet: ", remoteDir
167 print 'path must start with "/pnfs/psi.ch"'
171 script =
"""#!/bin/bash
173 ##### MONITORING/DEBUG INFORMATION ###############################
174 DATE_START=`date +%s`
175 echo "Job started at " `date`
177 ################################################################
178 ## QUEUEING SYSTEM SETTINGS:
188 echo "######## Environment Variables ##########"
190 echo "################################################################"
191 TOPWORKDIR=/scratch/`whoami`
192 JOBDIR=sgejob-$JOB_ID
193 WORKDIR=$TOPWORKDIR/$JOBDIR
195 if test -e "$WORKDIR"; then
196 echo "ERROR: WORKDIR ($WORKDIR) already exists! Aborting..." >&2
200 if test ! -d "$WORKDIR"; then
201 echo "ERROR: Failed to create workdir ($WORKDIR)! Aborting..." >&2
205 #source $VO_CMS_SW_DIR/cmsset_default.sh
206 source {vo}/cmsset_default.sh
207 export SCRAM_ARCH=slc6_amd64_gcc481
210 shopt -s expand_aliases
213 cp -rf $SUBMISIONDIR .
215 cd `find . -type d | grep /`
217 python $CMSSW_BASE/src/PhysicsTools/HeppyCore/python/framework/looper.py pycfg.py config.pck --options=options.json
218 #python $CMSSW_BASE/src/CMGTools/RootTools/python/fwlite/looper.py config.pck
221 ###########################################################################
223 RUNTIME=$((DATE_END-DATE_START))
224 echo "################################################################"
225 echo "Job finished at " `date`
226 echo "Wallclock running time: $RUNTIME s"
228 """.
format(jdir=jobDir, vo=VO_CMS_SW_DIR,cmssw=cmssw_release, copy=cpCmd)
233 '''prepare a IC version of the batch script'''
236 cmssw_release = os.environ[
'CMSSW_BASE']
237 script =
"""#!/bin/bash
238 export X509_USER_PROXY=/home/hep/$USER/myproxy
239 source /vols/cms/grid/setup.sh
242 eval `scramv1 ru -sh`
245 python {cmssw}/src/PhysicsTools/HeppyCore/python/framework/looper.py pycfg.py config.pck --options=options.json
247 echo 'sending the job directory back'
248 mv Loop/* ./ && rm -r Loop
249 """.
format(jobdir = jobDir,cmssw = cmssw_release)
253 '''prepare a local version of the batch script, to run using nohup'''
255 script =
"""#!/bin/bash
257 python $CMSSW_BASE/src/PhysicsTools/HeppyCore/python/framework/looper.py pycfg.py config.pck --options=options.json
259 echo 'sending the job directory back'
266 '''Batch manager specific to cmsRun processes.'''
269 '''Prepare one job. This function is called by the base class.'''
271 print components[value]
274 scriptFileName = jobDir+
'/batchScript.sh'
275 scriptFile = open(scriptFileName,
'w')
276 storeDir = self.remoteOutputDir_.replace(
'/castor/cern.ch/cms',
'')
277 mode = self.RunningMode(options.batch)
281 scriptFile.write( batchScriptPSI ( value, jobDir, storeDir ) )
282 elif mode ==
'LOCAL':
284 elif mode ==
'PISA' :
286 elif mode ==
'PADOVA' :
291 os.system(
'chmod +x %s' % scriptFileName)
293 shutil.copyfile(cfgFileName, jobDir+
'/pycfg.py')
296 cfgFile = open(jobDir+
'/config.pck',
'w')
297 pickle.dump( components[value] , cfgFile )
300 if hasattr(self,
"heppyOptions_"):
301 optjsonfile = open(jobDir+
'/options.json',
'w')
302 optjsonfile.write(json.dumps(self.heppyOptions_))
305 if __name__ ==
'__main__':
307 batchManager.parser_.usage=
"""
308 %prog [options] <cfgFile>
310 Run Colin's python analysis system on the batch.
311 Job splitting is determined by your configuration file.
314 options, args = batchManager.ParseOptions()
316 from PhysicsTools.HeppyCore.framework.heppy_loop
import _heppyGlobalOptions
317 for opt
in options.extraOptions:
319 (key,val) = opt.split(
"=",1)
320 _heppyGlobalOptions[key] = val
322 _heppyGlobalOptions[opt] =
True
323 batchManager.heppyOptions_=_heppyGlobalOptions
325 cfgFileName = args[0]
327 handle = open(cfgFileName,
'r')
329 cfo = imp.load_source(
"pycfg", cfgFileName, handle)
333 components =
split( [comp
for comp
in config.components
if len(comp.files)>0] )
334 listOfValues = range(0, len(components))
335 listOfNames = [comp.name
for comp
in components]
337 batchManager.PrepareJobs( listOfValues, listOfNames )
339 batchManager.SubmitJobs( waitingTime )