ProcessPPFX.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 ##################################################
3 # ppfx grid job submitter
4 # 2019.07 -- L. Aliaga
5 ##################################################
6 import os, optparse, random, shutil, tarfile, sys
7 import subprocess, string
8 
9 CACHE_PNFS_AREA = "/pnfs/nova/scratch/users/{USER}/grid_cache/".format(USER = os.getenv("USER"))
10 PWD = os.getenv("PWD")
11 
12 ##################################################
13 # Job Defaults
14 ##################################################
15 N_JOBS = 1
16 OUTDIR = "/pnfs/nova/persistent/users/{USER}/ppfx/test/".format(USER = os.getenv("USER"))
17 #INPUT_OPTIONS = "{0}/scripts/inputs_default.xml".format(PWD)
18 INPUT_OPTIONS = "scripts/inputs_default.xml"
19 IDET = "3"
20 INDIR = "/pnfs/nova/data/flux/g4numi/v6r1"
21 TARFILE_NAME = "local_install.tar.gz"
22 BEAMCONFIG = "me000z200i"
23 
24 ##################################################
25 
26 def main():
27  options = get_options()
28 
29  cache_folder = CACHE_PNFS_AREA + str(random.randint(10000,99999)) + "/"
30  os.makedirs(cache_folder)
31 
32  os.makedirs(options.outdir)
33 
34  print "\nTarring up local area..."
35  make_tarfile(TARFILE_NAME, ".")
36 
37  shutil.move(TARFILE_NAME, cache_folder)
38  shutil.copy("ppfx_job.sh", cache_folder)
39 
40  print "\nTarball of local area:", cache_folder + TARFILE_NAME
41 
42  logfile = options.outdir + "/ppfx_{BEAMCONFIG}_\$PROCESS.log".format(BEAMCONFIG = options.beamconfig)
43 
44  print "\nOutput logfile(s):",logfile
45 
46  submit_command = ("jobsub_submit {GRID} {MEMORY} -N {NJOBS} -dPPFX {OUTDIR} "
47  "-G nova "
48  "-e BEAMCONFIG={BEAMCONFIG} "
49  "-e IN_DIR={IN_DIR} "
50  "-e INPUT_OPTIONS={INPUT_OPTIONS} "
51  "-e IDET={IDET} "
52  "-f {TARFILE} "
53  "-L {LOGFILE} "
54  "file://{CACHE}/ppfx_job.sh".format(
55  GRID = ("--OS=SL6 -g "
56  "--resource-provides=usage_model=DEDICATED,OPPORTUNISTIC "
57  "--role=Analysis "),
58  MEMORY = "--memory 200MB ",
59  NJOBS = options.n_jobs,
60  OUTDIR = options.outdir,
61  BEAMCONFIG = options.beamconfig,
62  IN_DIR = INDIR,
63  INPUT_OPTIONS = options.input_options,
64  IDET = options.idet,
65  TARFILE = cache_folder + TARFILE_NAME,
66  LOGFILE = logfile,
67  CACHE = cache_folder)
68  )
69 
70  #Ship it
71  print "\nSubmitting to grid:\n"+submit_command+"\n"
72  status = subprocess.call(submit_command, shell=True)
73 
75  parser = optparse.OptionParser(usage="usage: %prog [options]")
76  grid_group = optparse.OptionGroup(parser, "Grid Options")
77 
78  grid_group.add_option("--outdir",
79  default = OUTDIR,
80  help = "Output flux histograms location. Default = %default.")
81 
82  grid_group.add_option("--n_jobs",
83  default = N_JOBS,
84  help = "Number of g4numi jobs. Default = %default.")
85 
86  beam_group = optparse.OptionGroup(parser, "Beam Options")
87 
88  beam_group.add_option('--beamconfig', default = BEAMCONFIG,
89  help="Select the neutrino beam: me000z200i, me000z-200i me000z000i.Default = %default.")
90 
91  run_group = optparse.OptionGroup(parser, "Run Options")
92 
93  run_group.add_option("--input_options",
94  default = INPUT_OPTIONS,
95  help = "PPFX input: number of universes, MIPP on/off, etc. Default = %default.")
96 
97  run_group.add_option("--idet",
98  default = IDET,
99  help = "Index of the detector to be used (see at location.name in dkmetaTree->Show(0)). Default = %default.")
100 
101  parser.add_option_group(grid_group)
102  parser.add_option_group(beam_group)
103  parser.add_option_group(run_group)
104 
105  options, remainder = parser.parse_args()
106 
107  return options
108 
109 def make_tarfile(output_filename, source_dir):
110  tar = tarfile.open(output_filename, "w:gz")
111  for i in os.listdir(source_dir):
112  tar.add(i)
113  tar.close()
114 
115 if __name__ == "__main__":
116  sys.exit(main())
static bool format(QChar::Decomposition tag, QString &str, int index, int len)
Definition: qstring.cpp:11496
def main()
Definition: ProcessPPFX.py:26
def make_tarfile(output_filename, source_dir)
Definition: ProcessPPFX.py:109
def get_options()
Definition: ProcessPPFX.py:74
static QCString str