5 from __future__
import print_function
6 import os, sys, imp, re, pprint, string, time,shutil,copy,pickle,math
7 from optparse
import OptionParser
10 from PhysicsTools.HeppyCore.utils.batchmanager
import BatchManager
11 import PhysicsTools.HeppyCore.utils.eostools
as eostools
14 import FWCore.ParameterSet.Config
as cms
15 from IOMC.RandomEngine.RandomServiceHelper
import RandomNumberServiceHelper
19 script =
"""!/usr/bin/env bash 20 #PBS -l platform=LINUX,u_sps_cmsf,M=2000MB,T=2000000 27 source $HOME/.bash_profile 29 echo '***********************' 33 # coming back to submission dir do setup the env 42 cp -r $PBS_O_WORKDIR . 50 cat > sysinfo.sh <<EOF 52 echo '************** ENVIRONMENT ****************' 57 echo '************** WORKER *********************' 64 echo '************** START *********************' 68 source sysinfo.sh > sysinfo.txt 72 # copy job dir do disk 74 cp -r $jobdir $PBS_O_WORKDIR 83 for file in *.root; do 84 newFileName=`echo $file | sed -r -e 's/\./_{index}\./'` 85 fullFileName={remoteDir}/$newFileName 86 {eos} cp $file /eos/cms/$fullFileName 87 {eos} chmod 755 /eos/cms/$fullFileName 90 """.
format(index=index, remoteDir=remoteDir, eos=eostools.eos_select)
94 '''prepare the LSF version of the batch script, to run on LSF''' 95 script =
"""#!/bin/bash 103 echo 'copying job dir to worker' 105 eval `scramv1 ru -sh` 109 cd `find . -type d | grep /` 113 echo wrong exit code! removing all root files 117 echo 'sending the job directory back' 123 script +=
'cp -rf * $LS_SUBCWD\n' 128 '''prepare a local version of the batch script, to run using nohup''' 130 script =
"""#!/bin/bash 134 echo wrong exit code! removing all root files 138 echo 'sending the job directory back' 148 '''Exception class for this script''' 158 '''Batch manager specific to cmsRun processes.''' 161 '''Prepare one job. This function is called by the base class.''' 163 process.source = fullSource.clone()
166 scriptFileName = jobDir+
'/batchScript.sh' 167 scriptFile = open(scriptFileName,
'w')
168 storeDir = self.remoteOutputDir_.replace(
'/castor/cern.ch/cms',
'')
169 mode = self.RunningMode(options.batch)
172 elif mode ==
'LOCAL':
175 os.system(
'chmod +x %s' % scriptFileName)
180 randSvc = RandomNumberServiceHelper(process.RandomNumberGeneratorService)
183 iFileMin = (value-1)*grouping
184 iFileMax = (value)*grouping
185 process.source.fileNames = fullSource.fileNames[iFileMin:iFileMax]
186 print(process.source)
187 cfgFile = open(jobDir+
'/run_cfg.py',
'w')
188 cfgFile.write(
'import FWCore.ParameterSet.Config as cms\n\n')
189 cfgFile.write(
'import os,sys\n')
191 cfgFile.write(
"sys.path.append('%s')\n" % os.path.dirname(jobDir) )
192 cfgFile.write(
'from base_cfg import *\n')
193 cfgFile.write(
'process.source = ' + process.source.dumpPython() +
'\n')
195 cfgFile.write(
'process.RandomNumberGeneratorService = ' + process.RandomNumberGeneratorService.dumpPython() +
'\n')
202 file = open(
'cmsBatch.txt',
'w')
203 file.write(string.join(sys.argv) +
"\n")
206 batchManager.parser_.usage =
""" 207 %prog [options] <number of input files per job> <your_cfg.py>. 209 Submits a number of jobs taking your_cfg.py as a template. your_cfg.py can either read events from input files, or produce them with a generator. In the later case, the seeds are of course updated for each job. 211 A local output directory is created locally. This directory contains a job directory for each job, and a Logger/ directory containing information on the software you are using. 213 - the name of the output directory is created automatically. 214 - the output root files end up in the job directories. 216 Each job directory contains: 217 - the full python configuration for this job. You can run it interactively by doing: 219 - the batch script to run the job. You can submit it again by calling the batch command yourself, see the -b option. 220 - while running interactively: nohup.out, where the job stderr and stdout are redirected. To check the status of a job running interactively, do: 223 o the full nohup.out (your log) and your root files, in case you ran interactively 224 o the LSF directory, in case you ran on LSF 226 Also see fwBatch.py, which is a layer on top of cmsBatch.py adapted to the organization of our samples on the CMST3. 231 cd $CMSSW_BASE/src/CMGTools/Common/test 233 to run on your local machine: 234 cmsBatch.py 1 testCMGTools_cfg.py -b 'nohup ./batchScript.sh&' 236 to run on LSF (you must be logged on lxplus, not on your interactive machine, so that you have access to LSF) 237 cmsBatch.py 1 testCMGTools_cfg.py -b 'bsub -q 8nm < ./batchScript.sh' 239 batchManager.parser_.add_option(
"-p",
"--program", dest=
"prog",
240 help=
"program to run on your cfg file",
245 batchManager.parser_.add_option(
"-c",
"--command-args", dest=
"cmdargs",
246 help=
"command line arguments for the job",
248 batchManager.parser_.add_option(
"--notagCVS", dest=
"tagPackages",
249 default=
True,action=
"store_false",
250 help=
"tag the package on CVS (True)")
252 (options,args) = batchManager.parser_.parse_args()
253 batchManager.ParseOptions()
256 doCVSTag = options.tagPackages
259 batchManager.parser_.print_help()
265 runningMode = batchManager.RunningMode( options.batch )
266 except CmsBatchException
as err:
272 cfgFileName = args[1]
276 pycfg_params = options.cmdargs
278 sys.argv = [cfgFileName]
280 sys.argv.extend(pycfg_params.split(
' '))
285 handle = open(cfgFileName,
'r') 286 cfo = imp.load_source("pycfg", cfgFileName, handle)
287 process = cfo.process
295 fullSource = process.source.clone()
299 process.source.fileNames
301 print(
'No input file. This is a generator process.')
303 listOfValues = [i+1
for i
in range( nJobs )]
305 print(
"Number of files in the source:",len(process.source.fileNames),
":")
306 pprint.pprint(process.source.fileNames)
307 nFiles = len(process.source.fileNames)
308 nJobs = nFiles / grouping
309 if (nJobs!=0
and (nFiles % grouping) > 0)
or nJobs==0:
312 print(
"number of jobs to be created: ", nJobs)
313 listOfValues = [i+1
for i
in range( nJobs )]
316 batchManager.PrepareJobs( listOfValues )
320 cfgFile = open(batchManager.outputDir_+
'/base_cfg.py',
'w')
321 cfgFile.write( process.dumpPython() +
'\n')
327 if runningMode ==
'LOCAL':
331 batchManager.SubmitJobs( waitingTime )
336 from PhysicsTools.HeppyCore.utils.logger
import logger
339 os.chdir(batchManager.outputDir_)
341 os.system(
'mkdir ' + logDir )
347 log.addFile( oldPwd +
'/' + cfgFileName )
349 if not batchManager.options_.negate:
350 if batchManager.remoteOutputDir_ !=
"":
353 log.stageOut( batchManager.remoteOutputDir_ )
def rootfiles_to_eos_script(index, remoteDir)
S & print(S &os, JobReport::InputFile const &f)
def PrepareJobUser(self, jobDir, value)
def batchScriptCERN(remoteDir, index)
def __init__(self, value)
def batchScriptLocal(remoteDir, index)