Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-26 02:34:38

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