Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-10 22:50:05

0001 #!/usr/bin/env python3
0002 
0003 # Script to submit Tau Validation jobs to lxbatch
0004 #  Author: Evan Friis evan.klose.friis@cern.ch
0005 from __future__ import print_function
0006 from builtins import range
0007 import time
0008 import random
0009 from Validation.RecoTau.ValidationOptions_cff import *
0010 
0011 options.parseArguments()
0012 checkOptionsForBadInput()
0013 
0014 # Make sure we dont' clobber another directory!
0015 if not CMSSWEnvironmentIsCurrent():
0016    print("CMSSW_BASE points to a different directory, please rerun cmsenv!")
0017    sys.exit()
0018 
0019 if options.nJobs == 0:
0020    print("Must specify nJobs > 0. Run 'python3 LXBatchValidation.py help' for options")
0021    sys.exit()
0022 
0023 if options.maxEvents == -1 and options.nJobs > 1:
0024    print("Please use maxEvents to specify the number of events to process per job.")
0025    sys.exit()
0026 
0027 # Setup path to CASTOR home if desired
0028 if options.writeEDMFile != "":
0029    if options.copyToCastorDir == "<home>":
0030       options.copyToCastorDir = "/castor/cern.ch/user/%s/%s/" % (os.environ["LOGNAME"][0], os.environ["LOGNAME"])
0031       print("Setting castor directory to your home @ %s" % options.copyToCastorDir)
0032 
0033 if options.copyToCastorDir != "":
0034    checkCastor = os.system("nsls %s" % options.copyToCastorDir)
0035    if checkCastor:
0036       print("Error: castor reports an error when checking the supplied castor location: ", options.copyToCastorDir)
0037       sys.exit()
0038 
0039 #print "Converting all relative paths to absolutes..."
0040 #if options.sourceFile != "<none>":
0041 #  options.sourceFile = os.path.abspath(options.sourceFile)
0042 #  if not os.path.exists(opitons.sourceFile):
0043 #     print "Can't stat sourceFile %s after converting to absolute path." % options.sourceFile
0044 #     sys.exit()
0045 
0046 #bsoluteModifications = []
0047 #or aModification in options.myModifications:
0048 #  if aModification != "<none>":
0049 #     absoluteModPath = os.path.abspath(aModification)
0050 #     if not os.path.exists(absoluteModPath):
0051 #        print "Can't stat modification file %s after converting to absolute path" % absoluteModPath
0052 #        absoluteModifications.append(absoluteModPath)
0053 #        sys.exit()
0054 
0055 #ptions.myModifications = absoluteModifications
0056 
0057 print("") 
0058 print("I'm going to submit %i %s jobs, each with %i events, for a total of %i events" % (options.nJobs, options.eventType, options.maxEvents, options.nJobs*options.maxEvents))
0059 
0060 if options.writeEDMFile != "":
0061    print("EDM files with the prefix %s will be produced and stored in %s" % (options.writeEDMFile, castorLocation))
0062 
0063 print("Hit Ctrl-c in the next 3 seconds to cancel...")
0064 try:
0065    time.sleep(2)
0066 except KeyboardInterrupt:
0067    print("Canceled, exiting.")
0068    sys.exit()
0069 
0070 # Setup the environment variables
0071 setupCommands = "cd $PWD; scramv1 runtime -sh > tempEnvs_%i; source tempEnvs_%i; rm tempEnvs_%i; cd -;"
0072 cmsRunCommands = "cmsRun $PWD/RunValidation_cfg.py %s;" % returnOptionsString()
0073 cleanupCommands = ""
0074 if options.writeEDMFile != "":
0075    cleanupCommand += " rfcp *.root %s;" % options.copyToCastorDir
0076 
0077 for iJob in range(0, options.nJobs):
0078    options.batchNumber = iJob #increment batch number
0079    #setupCommands = "cd $PWD; scramv1 runtime -sh > tempEnvs_%s_%i; source tempEnvs_%s_%i; rm tempEnvs_%s_%i; export PYTHONPATH=$PWD:$PYTHONPATH; cd -;" % (options.eventType, iJob, options.eventType, iJob, options.eventType, iJob)
0080    #cmsRunCommand = "cmsRun $PWD/RunValidation_cfg.py %s;" % returnOptionsString()
0081    #setupCommands = "cd $PWD; scramv1 runtime -sh > tempEnvs_%s_%i; source tempEnvs_%s_%i; rm tempEnvs_%s_%i; export PYTHONPATH=$PWD:$PYTHONPATH; cd -;" % (options.eventType, iJob, options.eventType, iJob, options.eventType, iJob)
0082    setupCommands = "export edmOutputDir=\$PWD; cd $PWD; scramv1 runtime -sh > tempEnvs_%s_%i; source tempEnvs_%s_%i; rm tempEnvs_%s_%i;" % (options.eventType, iJob, options.eventType, iJob, options.eventType, iJob)
0083    cmsRunCommand = "cmsRun RunValidation_cfg.py %s;" % returnOptionsString()
0084    cleanupCommand = ""
0085    if options.writeEDMFile != "":
0086       cleanupCommand += "cd -; rfcp *.root %s;" % options.copyToCastorDir
0087 
0088    totalCommand = setupCommands + cmsRunCommand + cleanupCommand
0089    bsubCommand  = "bsub -J %s_%i -q %s \"%s\"" % (options.eventType, iJob, options.lxbatchQueue, totalCommand)
0090    #bsubCommand  = "echo -J %s_%i -q %s \"%s\"" % (options.eventType, iJob, options.lxbatchQueue, totalCommand)
0091    os.system(bsubCommand)
0092