3 from datetime
import datetime
4 from optparse
import OptionParser
15 This class manages batch jobs
31 self.parser_.add_option(
"-o",
"--output-dir", dest=
"outputDir",
32 help=
"Name of the local output directory for your jobs. This directory will be created automatically.",
34 self.parser_.add_option(
"-r",
"--remote-copy", dest=
"remoteCopy",
35 help=
"remote output directory for your jobs. Example: /store/cmst3/user/cbern/CMG/HT/Run2011A-PromptReco-v1/AOD/PAT_CMG/RA2. This directory *must* be provided as a logical file name (LFN). When this option is used, all root files produced by a job are copied to the remote directory, and the job index is appended to the root file name. The Logger directory is tarred and compressed into Logger.tgz, and sent to the remote output directory as well. Afterwards, use logger.py to access the information contained in Logger.tgz. For remote copy to PSI specify path like: '/pnfs/psi.ch/...'. Logs will be sent back to the submision directory.",
37 self.parser_.add_option(
"-f",
"--force", action=
"store_true",
38 dest=
"force", default=
False,
39 help=
"Don't ask any questions, just over-write")
41 self.parser_.add_option(
"-n",
"--negate", action=
"store_true",
42 dest=
"negate", default=
False,
43 help=
"create jobs, but does not submit the jobs.")
44 self.parser_.add_option(
"-b",
"--batch", dest=
"batch",
45 help=
"batch command. default is: 'bsub -q 8nh < batchScript.sh'. You can also use 'nohup < ./batchScript.sh &' to run locally.",
46 default=
"bsub -q 8nh < ./batchScript.sh")
50 (self.options_,self.args_) = self.parser_.parse_args()
51 if self.options_.remoteCopy ==
None:
55 import CMGTools.Production.eostools
as castortools
60 if self.remoteOutputDir_.startswith(
"/pnfs/psi.ch"):
62 outputDir = self.options_.outputDir
64 today = datetime.today()
65 outputDir =
'OutCmsBatch_%s' % today.strftime(
"%d%h%y_%H%M")
69 print "remote directory must start with /pnfs/psi.ch to send to the tier3 at PSI"
74 print 'When providing an output directory, you must give its LFN, starting by /store. You gave:'
90 if self.options_.negate
is False and self.options_.force
is False:
97 return (self.options_, self.args_)
101 print 'PREPARING JOBS ======== '
104 if listOfDirNames
is None:
105 for value
in listOfValues:
108 for value, name
in zip( listOfValues, listOfDirNames):
110 print "list of jobs:"
111 pp = pprint.PrettyPrinter(indent=4)
123 outputDir = self.options_.outputDir
126 today = datetime.today()
127 outputDir =
'OutCmsBatch_%s' % today.strftime(
"%d%h%y_%H%M%S")
128 print 'output directory not specified, using %s' % outputDir
134 if not self.options_.force:
135 while input !=
'y' and input !=
'n':
136 input = raw_input(
'The directory ' + self.
outputDir_ +
' exists. Are you sure you want to continue? its contents will be overwritten [y/n]' )
146 '''Prepare a job for a given value.
148 calls PrepareJobUser, which should be overloaded by the user.
150 print 'PrepareJob : %s' % value
153 dname =
'Job_{value}'.
format( value=value )
157 self.listOfJobs_.append( jobDir )
161 '''Hook allowing user to define how one of his jobs should be prepared.'''
162 print '\to be customized'
166 '''Submit all jobs. Possibly wait between each job'''
168 if(self.options_.negate):
169 print '*NOT* SUBMITTING JOBS - exit '
171 print 'SUBMITTING JOBS ======== '
175 print 'processing ', jobDir
180 print 'waiting %s seconds...' % waitingTimeInSec
181 time.sleep( waitingTimeInSec )
185 '''Hook for job submission.'''
186 print 'submitting (to be customized): ', jobDir
187 os.system( self.options_.batch )
192 if batchScript ==
'':
195 if( os.path.isfile(batchScript)==
False ):
196 print 'file ',batchScript,
' does not exist'
200 ifile = open(batchScript)
202 print 'cannot open input %s' % batchScript
206 p = re.compile(
"\s*cp.*\$jobdir\s+(\S+)$");
209 if os.path.isdir( os.path.expandvars(m.group(1)) ):
210 print 'output directory ', m.group(1),
'already exists!'
214 if self.options_.negate==
False:
215 os.mkdir( os.path.expandvars(m.group(1)) )
217 print 'not making dir', self.options_.negate
222 mkdir =
'mkdir -p %s' % dirname
223 ret = os.system( mkdir )
225 print 'please remove or rename directory: ', dirname
230 '''Returns "LXPLUS", "PSI", "LOCAL", or None,
232 "LXPLUS" : batch command is bsub, and logged on lxplus
233 "PSI" : batch command is qsub, and logged to t3uiXX
234 "LOCAL" : batch command is nohup.
235 In all other cases, a CmsBatchException is raised
238 hostName = os.environ[
'HOSTNAME']
239 onLxplus = hostName.startswith(
'lxplus')
240 onPSI = hostName.startswith(
't3ui' )
241 onPISA = re.match(
'.*gridui.*',hostName)
or re.match(
'.*faiwn.*',hostName)
242 batchCmd = batch.split()[0]
244 if batchCmd ==
'bsub':
245 if not (onLxplus
or onPISA) :
246 err =
'Cannot run %s on %s' % (batchCmd, hostName)
247 raise ValueError( err )
249 print 'running on LSF pisa : %s from %s' % (batchCmd, hostName)
252 print 'running on LSF lxplus: %s from %s' % (batchCmd, hostName)
254 elif batchCmd ==
"qsub":
256 err =
'Cannot run %s on %s' % (batchCmd, hostName)
257 raise ValueError( err )
259 print 'running on SGE : %s from %s' % (batchCmd, hostName)
261 elif batchCmd ==
'nohup' or batchCmd ==
'./batchScript.sh':
262 print 'running locally : %s on %s' % (batchCmd, hostName)
265 err =
'unknown batch command: X%sX' % batchCmd
266 raise ValueError( err )
static std::string join(char **cmd)
if(conf.exists("allCellsPositionCalc"))