6 from argparse
import ArgumentParser
7 from shutil
import copyfile, rmtree, move
14 with open(config)
as f:
16 line = line.replace(
" ",
"").strip()
19 if line[0] !=
'#' and line.split(
"=")[0] == parameter:
20 par = line.split(
"=")[1]
29 with open(config,
"r") as f: 33 line = line.replace(
" ",
"").strip()
36 if line[0] !=
'#' and line.split(
"=")[0] == parameter:
41 with open(config,
"w")
as f:
42 f.write(parameter+
" = \n")
49 with open(config,
"r") as f: 51 with open(config, "w")
as f:
53 l = line.replace(
" ",
"").strip()
57 if l[0] !=
'#' and l.split(
'=')[0] == parameter:
58 if l.split(
'=')[1] ==
"" :
60 newpar =
" = " + newpar
63 f.write(re.sub(par, newpar, line))
68 with open(config,
"r") as f: 70 with open(config, "w")
as f:
72 l = line.replace(
" ",
"").strip()
76 if l[0] !=
'#' and l.split(
'=')[0] == parameter:
82 with open(config,
"r") as f: 84 with open(config, "w")
as f:
86 f.write(re.sub(name, os.path.basename(name), line))
93 parser = ArgumentParser()
94 parser.add_argument(
"-e",
"--exe", dest=
"exe", help=
"Executable")
95 parser.add_argument(
"-n",
"--ntuples", dest=
"ntuples", help=
"List of ntuples file")
96 parser.add_argument(
"-x",
"--nfiles", dest=
"nfiles", type=int, default=1, help=
"Number of ntuple files per job")
97 parser.add_argument(
"-c",
"--config", dest=
"config", help=
"Configuration file")
98 parser.add_argument(
"-j",
"--json", dest=
"json", help=
"JSON file with certified data")
99 args = parser.parse_args()
101 print "nothing to be done" 104 ntuples = args.ntuples
111 if not os.path.isfile(config):
112 print "Configuration file does not exist" 117 ntuples = configNtuples[1]
119 print "*error* You must define the parameter ntuplesList in your configuration." 128 if not os.path.isfile(ntuples):
129 print "Ntuples list file does not exist" 132 if not os.path.isfile(json):
133 print "Json file does not exist" 137 maindir =
"Condor_"+os.path.basename(args.exe)
139 maindir = maindir+
"_"+ os.path.splitext(os.path.basename(config))[0]
141 if os.path.exists(cwd+
"/"+maindir):
142 print maindir +
"already exists. Rename or remove it and then resubmit" 145 splitcwd = cwd.split(
'/')
147 if splitcwd[1] ==
'afs':
148 newcwd =
'/nfs/dust/cms/user' 149 for d
in splitcwd[5:]:
151 print(
'nfs directory:',newcwd)
154 maindir = newcwd+
'/'+maindir
156 lncmd =
'ln -s ' + maindir
158 if not os.path.exists(
'histograms'):
159 ln2cmd =
'ln -s ' + newcwd +
' histograms' 167 tmpdir =
".tmp_" + str(pid)
169 copyfile(ntuples, tmpdir+
"/"+os.path.basename(ntuples))
171 copyfile(config, tmpdir+
"/"+os.path.basename(config))
184 splitcmd =
"split.csh" +
" " + str(args.nfiles) +
" " + os.path.basename(ntuples)
186 os.remove(os.path.basename(ntuples))
187 files = glob.glob(
'.*_x????.txt')
193 jobnum = os.path.splitext(f)[0][-4:]
194 jobid =
"job_"+jobnum
195 exedir = maindir+
"/"+jobid
198 move(tmpdir+
"/"+f,exedir+
"/"+os.path.basename(ntuples))
200 copyfile(json, exedir+
"/"+os.path.basename(json))
202 copyfile(tmpdir+
"/"+os.path.basename(config),exedir+
"/"+os.path.basename(config))
204 condorcmd =
"condor_job_prep.csh job " + args.exe +
" " + os.path.basename(config)
207 condorcmd =
"condor_job_prep.csh job "+ args.exe
210 jobf = open(
'./seed.txt',
'w+')
211 print >> jobf,
int(jobnum)+1
213 print "Submitting ",jobid,
"..." 220 exedir = maindir+
"/job_0000" 222 if os.path.isfile(args.exe):
223 copyfile(args.exe, exedir+
"/"+os.path.basename(args.exe))
225 jobf = open(
'./seed.txt',
'w+')
228 condorcmd =
"condor_submit.csh job_0000" +
" " + os.path.basename(args.exe)
236 condorcmd =
"condor_mult_submit.csh job " + args.exe +
" " + os.path.basename(config)
238 condorcmd =
"condor_mult_submit.csh job "+ args.exe
245 os.remove(tmpdir+
"/"+os.path.basename(config))
def basenameConfigParameter(config, name)
def replaceConfigParameter(config, parameter, newpar)
def getConfigParameter(config, parameter)
def createConfigParameter(config, parameter)
def removeConfigParameter(config, parameter)