3 import os,glob,shutil,re
6 if not (
"getOpenLoops" in options.performOnly
or "all" in options.performOnly):
9 if len(options.Sherpa_i.OpenLoopsLibs) == 0:
13 if not options.OLskipcvmfs:
14 olpath =
str(os.environ[
'OPENLOOPSPATH'])
15 cvmfsInstalledOpenLoopsLibs = glob.glob(olpath +
"/proclib/*.so")
16 if not any(
not any(x
in fil
for fil
in cvmfsInstalledOpenLoopsLibs)
for x
in options.Sherpa_i.OpenLoopsLibs):
17 print(
"You requested the inclusion of OpenLoops libs in the tarball (genSeq.Sherpa_i.OpenLoopsLibs), but all of them are available centrally in /cvmfs. Will continue without including them in the tarball, and you can remove the genSeq.Sherpa_i.OpenLoopsLibs line from your JO.")
21 installedOpenLoopsLibs = glob.glob(
"Process/OpenLoops/proclib/*.so")
23 if len(options.Sherpa_i.OpenLoopsLibs) == len(installedOpenLoopsLibs)
and not any(
not any(x
in fil
for fil
in installedOpenLoopsLibs)
for x
in options.Sherpa_i.OpenLoopsLibs):
27 if os.path.exists(
"Process/OpenLoops"):
28 shutil.rmtree(
"Process/OpenLoops")
30 job = options.batchSystemModule.batchJob(
"0.getOpenLoops", hours=2, nCores=options.ncoresScons, memMB=1, basedir=options.jobOptionDir[0])
32 job.cmds += [
"source $AtlasSetup/scripts/asetup.sh "+options.athenaVersion]
33 job.cmds += [
"set -e"]
35 olbranch = options.OLbranch
if options.OLbranch
is not None else (
'OpenLoops-'+os.environ[
'OPENLOOPSVER'])
36 job.cmds += [
"git clone -b "+olbranch+
" https://gitlab.com/openloops/OpenLoops.git"]
38 job.cmds += [
"cd OpenLoops"]
39 job.cmds += [
"./scons num_jobs="+
str(options.ncoresScons)]
40 job.cmds += [
"./openloops libinstall process_repositories="+options.OLprocessrepos+
" num_jobs="+
str(options.ncoresScons)+
" "+
' '.
join(options.Sherpa_i.OpenLoopsLibs)]
43 job.cmds += [
"rm -rf Process/OpenLoops"]
44 job.cmds += [
"mkdir -p Process/OpenLoops"]
45 job.cmds += [
"mv OpenLoops/proclib OpenLoops/lib Process/OpenLoops/"]
46 job.cmds += [
"rm -rf OpenLoops"]
49 job.submit(dryRun=options.dryRun)
54 if not (
"createLibs" in options.performOnly
or "all" in options.performOnly):
57 procName =
"Process/*.db" if os.environ[
"SHERPAVER"].startswith(
'2.')
else "Process/*.zip"
58 if len(glob.glob(procName)) > 0:
61 job = options.batchSystemModule.batchJob(
"1.createLibs", hours=48, nCores=1, memMB=options.createLibsRAM, basedir=options.jobOptionDir[0])
64 job.dependsOnOk.append(prevJob.id)
66 job.cmds += [
"source $AtlasSetup/scripts/asetup.sh "+options.athenaVersion]
67 job.cmds += [
"set -e"]
69 if os.environ[
"SHERPAVER"].startswith(
'2.'):
70 job.cmds += [
"rm -rf Process/Amegic.db Process/Comix.db Process/Sherpa.db Process/Amegic"]
71 job.cmds += [
"echo 'genSeq.Sherpa_i.Parameters += [ \"INIT_ONLY=1\", \"EVENTS=0\", \"FRAGMENTATION=Off\", \"MI_HANDLER=None\", \"LOG_FILE=\"]\n' > events.py"]
73 job.cmds += [
"rm -rf Process/Amegic.zip Process/Comix.zip Process/Sherpa.zip Process/Amegic"]
74 job.cmds += [
"echo 'genSeq.Sherpa_i.BaseFragment += \"\"\"\nINIT_ONLY: 1\nEVENTS: 0\nFRAGMENTATION: Off\nMI_HANDLER: None\n\"\"\"' > events.py"]
76 job.cmds += [
"outputEVNTFile=$(mktemp -u /tmp/XXXXXXXX.pool.root)"]
77 job.cmds += [
"returncode=0"]
78 job.cmds += [
"Gen_tf.py --ecmEnergy="+
str(options.ecm[0]*1000.)+
" --maxEvents=1 --firstEvent=1 --randomSeed=10 --jobConfig="+options.jobOptionDir[0]+
" --postInclude=events.py --outputEVNTFile=${outputEVNTFile} || returncode=$?"]
79 job.cmds += [
"echo Pasting log.generate ==============="]
80 job.cmds += [
"cat log.generate"]
81 job.cmds += [
"echo Gen_tf exited with return code $returncode"]
82 job.cmds += [
"if [ $returncode -eq 251 ]; then"]
83 job.cmds += [
" echo 'ERROR: OpenLoops-libary is missing: add missing OpenLoops-libary (see http://openloops.hepforge.org/process_library.php) to variable genSeq.Sherpa_i.OpenLoopsLibs in the jobOption-file, remove Process directory and start again'"]
84 job.cmds += [
" exit 1"]
86 job.cmds += [
"if [ $returncode -eq 65 ]; then"]
87 job.cmds += [
" if grep -q 'Sherpa: Sherpa::InitializeTheRun throws normal exit' log.generate || grep -q 'ERROR Have to compile Amegic libraries' log.generate; then"]
88 job.cmds += [
" echo 'Libraries successfully written out. (Ignore errors above.)'"]
89 job.cmds += [
" elif grep -q 'INFO Have to compile Amegic libraries' log.generate; then"]
90 job.cmds += [
" echo 'Libraries successfully written out with <=2.2.1. (Ignore errors above.)'"]
92 job.cmds += [
" echo 'ERROR: Gen_tf.py has failed in an unexpected way. This likely means your job options are incorrect. This log file will have more details.'"]
93 job.cmds += [
" exit 1"]
96 job.cmds += [
"if [ $returncode -ne 0 -a $returncode -ne 251 -a $returncode -ne 65 ]; then"]
97 job.cmds += [
" echo 'ERROR: unexpexted error from Gen_tf'"]
98 job.cmds += [
" exit 1"]
101 job.cmds += [
"rm -rf ${outputEVNTFile} _joproxy* AtRndmGenSvc.out AthenaSummary_Generate.txt Generate_messageSvc_jobOptions.py Generate_runathena PoolFileCatalog.xml PoolFileCatalog.xml.BAK TransformTimer_Generate.pickle config.pickle dmesg_trf.txt hostnamelookup.tmp inputDictionary.pickle jobInfo.xml jobInfo_Generate.xml jobReport* last.Generate last.runargs.gpickle runargs.Generate.gpickle runargs.Generate.py metadata_Generate.xml metadata.xml Sherpa_References.tex ntuple.pmon.stream setupevprod.sh share ntuple.pmon.gz testHepMC.root events.py Bdecays0.dat Bs2Jpsiphi.DEC DECAY.DEC G4particle_acceptlist.txt PDGTABLE.MeV pdt.table runargs.generate.py runwrapper.generate.sh eventLoopHeartBeat.txt susyParticlePdgid.txt TestHepMC.root log.generate mem.full.generate mem.summary.generate.json env.txt Run.dat Sherpa.yaml"]
104 job.submit(dryRun=options.dryRun)
109 if not (
"makelibs" in options.performOnly
or "all" in options.performOnly):
112 if os.path.exists(
"Process/Amegic/lib"):
115 job = options.batchSystemModule.batchJob(
"2.makelibs", hours=48, nCores=options.ncoresMakelibs, memMB=1, basedir=options.jobOptionDir[0])
118 job.dependsOnOk.append(prevJob.id)
120 job.cmds += [
"if ! test -f makelibs; then echo INFO: No makelibs file found; exit 0; fi"]
122 job.cmds += [
"source $AtlasSetup/scripts/asetup.sh "+options.athenaVersion]
125 job.cmds += [
"wget http://prdownloads.sourceforge.net/scons/scons-local-3.1.2.tar.gz"]
126 job.cmds += [
"tar xzf scons-local-*.tar.gz"]
127 job.cmds += [
"ln -s scons.py scons"]
128 job.cmds += [
"export PATH=$PATH:$PWD"]
130 job.cmds += [
"set -e"]
131 job.cmds += [
"./makelibs -j"+
str(options.ncoresMakelibs)]
132 job.cmds += [
"rm -rf Process/Amegic/P2_*"]
134 job.cmds += [
"rm -rf scons*"]
137 job.submit(dryRun=options.dryRun)
142 ecmfolder =
"ecm"+(
'{0:g}'.
format(ecm)).
replace(
".",
"p")+
"TeV"
144 if not (
"integrate" in options.performOnly
or "all" in options.performOnly):
147 resname =
"Results.db" if os.environ[
"SHERPAVER"].startswith(
'2.')
else "Results.zip"
148 if os.path.isfile(ecmfolder+
"/"+resname)
and os.path.isfile(ecmfolder+
"/3.integrate.log"):
153 targetCores = options.Sherpa_i.NCores
154 if options.maxCores < options.Sherpa_i.NCores:
155 targetHours =
int(
round(24.*options.Sherpa_i.NCores/options.maxCores))
156 targetCores = options.maxCores
158 if options.RAM > 100:
159 options.Sherpa_i.MemoryMB = options.RAM
160 job = options.batchSystemModule.batchJob(
"3.integrate", hours=targetHours, nCores=targetCores, memMB=options.Sherpa_i.MemoryMB, basedir=options.jobOptionDir[0]+
"/"+ecmfolder)
163 job.dependsOnOk.append(prevJob.id)
165 job.cmds += [
"source $AtlasSetup/scripts/asetup.sh "+options.athenaVersion]
166 job.cmds += [
"set -e"]
168 if os.environ[
"SHERPAVER"].startswith(
'3.'):
170 job.cmds += [
"cat > Base.yaml <<EOL"]
171 job.cmds += [options.Sherpa_i.BaseFragment]
174 job.cmds += [
r"sed '/.*EXTERNAL_RNG.*/d' -i Base.yaml"]
176 configname =
"Run.dat" if os.environ[
"SHERPAVER"].startswith(
'2.')
else "Sherpa.yaml"
177 job.cmds += [
"cat > "+configname+
" <<EOL"]
178 job.cmds += [options.Sherpa_i.RunCard]
181 ecmopt = [
"BEAM_ENERGY_1="+
str(ecm/2.*1000),
"BEAM_ENERGY_2="+
str(ecm/2.*1000)] \
182 if os.environ[
"SHERPAVER"].startswith(
'2.')
else [
"BEAM_ENERGIES: "+
str(ecm/2.*1000)]
183 ignoreopt = [
"RUNDATA",
"LOG_FILE",
"NNPDF_GRID_PATH",
"RESULT_DIRECTORY"]
184 totopt = options.Sherpa_i.Parameters + ecmopt
185 if options.Sherpa_i.PluginCode !=
"":
186 if os.environ[
"SHERPAVER"].startswith(
'2.'):
187 totopt.append(
"SHERPA_LDADD=Sherpa_iPlugin")
189 totopt.append(
"SHERPA_LDADD: Sherpa_iPlugin")
191 if not (re.split(
r'\W',s)[0]
in ignoreopt):
192 if os.environ[
"SHERPAVER"].startswith(
'2.'):
193 job.cmds += [
r"sed '/.*\}(run).*/i\ \ "+s+
"' -i Run.dat"]
195 job.cmds += [
r"sed '/.*PROCESSES:.*/i"+s+
"\\n' -i Sherpa.yaml"]
197 olpath =
str(os.environ[
'OPENLOOPSPATH'])
198 lcglayer = olpath[olpath.find(
"LCG_"):olpath.find(
"/MCGenerators")]
199 sftlayer =
"/cvmfs/sft.cern.ch/lcg/releases/" + lcglayer
200 lcgbase =
"_".
join(lcglayer.split(
'_')[:2])
201 sftbase =
"/cvmfs/sft.cern.ch/lcg/releases/" + lcgbase
203 if not options.sherpaInstallPath:
204 options.sherpaInstallPath = sftlayer+
"/MCGenerators/sherpa/${SHERPAVER}.openmpi3/${LCG_PLATFORM}"
207 LCG_PLATFORM =
str(os.environ[
'LCG_PLATFORM'])
209 openmpi_path =
":".
join(glob.glob(sftbase+
"/openmpi/*/"+LCG_PLATFORM+
"/bin"))
210 opal_prefix =
":".
join(glob.glob(sftbase+
"/openmpi/*/"+LCG_PLATFORM))
211 ld_library_path =
":".
join(glob.glob(sftbase+
"/openmpi/*/"+LCG_PLATFORM+
"/lib"))
212 gccpath =
str(os.environ[
'COMPILER_PATH'])
214 job.cmds += [
"source "+gccpath+
"/setup.sh" ]
215 job.cmds += [
"export PATH="+openmpi_path+
":$PATH"]
216 job.cmds += [
"export LHAPATH=/cvmfs/sft.cern.ch/lcg/external/lhapdfsets/current:/cvmfs/atlas.cern.ch/repo/sw/Generators/lhapdfsets/current/"]
217 job.cmds += [
"export OPAL_PREFIX="+opal_prefix]
218 job.cmds += [
"export LD_LIBRARY_PATH="+ld_library_path+
":" \
219 +sftbase+
"/zlib/*/${LCG_PLATFORM}/lib:" \
220 +sftbase+
"/sqlite/*/${LCG_PLATFORM}/lib:" \
221 +sftbase+
"/HepMC/*/${LCG_PLATFORM}/lib:" \
222 +sftlayer+
"/MCGenerators/lhapdf/*/${LCG_PLATFORM}/lib:" \
223 +sftlayer+
"/fastjet/*/${LCG_PLATFORM}/lib:" \
224 +olpath+
"/lib:"+olpath+
"/proclib:" \
225 +options.sherpaInstallPath+
"/lib64/SHERPA-MC:" \
226 +options.sherpaInstallPath+
"/lib/SHERPA-MC:$LD_LIBRARY_PATH"]
228 cmdLineOpts =
"EVENTS=0 FRAGMENTATION=Off MI_HANDLER=None"
229 if os.environ[
"SHERPAVER"].startswith(
'2.'):
230 cmdLineOpts +=
" BEAM_ENERGY_1="+
str(ecm/2.*1000)+
" BEAM_ENERGY_2="+
str(ecm/2.*1000)
232 cmdLineOpts +=
" \"RUNDATA: [Base.yaml, Sherpa.yaml]\" BEAM_ENERGIES="+
str(ecm/2.*1000)
233 job.cmds += [
"mpirun -n {0} ".
format(
str(targetCores))+options.sherpaInstallPath+
"/bin/Sherpa "+cmdLineOpts]
235 job.write(extraDirs=[options.jobOptionDir[0]])
236 job.submit(dryRun=options.dryRun)
242 if not (
"makeTarball" in options.performOnly
or "all" in options.performOnly):
245 physicsShort = options.mainJOfile.split(
".")[1]
247 ecmfolder =
"ecm"+ecmstring
248 tarballname =
"mc_"+ecmstring+
"."+physicsShort+
".GRID.tar.gz"
250 job = options.batchSystemModule.batchJob(
"4.makeTarball", hours=1, nCores=1, memMB=1, basedir=options.jobOptionDir[0]+
"/"+ecmfolder)
251 job.cmds += [
"set -e"]
254 job.dependsOnOk.append(prevJob.id)
256 resname =
"Results.db" if os.environ[
"SHERPAVER"].startswith(
'2.')
else "Results.zip"
257 job.cmds += [
"tar czhf "+options.jobOptionDir[0]+
"/"+tarballname+
" $(ls -d "+resname+
" Process 3.integrate.log 2>/dev/null) "+
" ".
join(options.Sherpa_i.ExtraFiles)]
258 for jodir
in options.jobOptionDir[1:]:
259 job.cmds += [
"ln -s "+options.jobOptionDir[0]+
"/"+tarballname+
" "+jodir]
261 job.write(useSingularity=
False, extraDirs=options.jobOptionDir)
262 job.submit(dryRun=options.dryRun)
269 if not (
"evgen" in options.performOnly
or "all" in options.performOnly):
273 ecmfolder =
"ecm"+ecmstring
275 job = options.batchSystemModule.batchJob(
"5.EvntGenTest", hours=24, nCores=1, memMB=1, basedir=jodir+
"/"+ecmfolder)
278 job.dependsOnOk.append(prevJob.id)
280 job.cmds += [
"source $AtlasSetup/scripts/asetup.sh "+options.athenaVersion]
281 job.cmds += [
"set -e"]
283 job.cmds += [
"rm -rf 5.EvntGenTest"]
284 job.cmds += [
"mkdir 5.EvntGenTest"]
285 job.cmds += [
"cd 5.EvntGenTest"]
286 if os.environ[
"SHERPAVER"].startswith(
'2.'):
287 job.cmds += [
"echo 'genSeq.Sherpa_i.Parameters += [ \"LOG_FILE=\" ]' > events.py"]
288 job.cmds += [
"outputEVNTFile=$(mktemp -u /tmp/XXXXXXXX.pool.root)"]
289 if os.environ[
"SHERPAVER"].startswith(
'2.'):
290 job.cmds += [
"Gen_tf.py --ecmEnergy="+
str(ecm*1000.)+
" --maxEvents=1 --firstEvent=1 --randomSeed=10 --jobConfig="+jodir+
" --postInclude=events.py --outputEVNTFile=${outputEVNTFile} --maxEvents="+
str(options.nEvts)]
292 job.cmds += [
"Gen_tf.py --ecmEnergy="+
str(ecm*1000.)+
" --maxEvents=1 --firstEvent=1 --randomSeed=10 --jobConfig="+jodir+
" --outputEVNTFile=${outputEVNTFile} --maxEvents="+
str(options.nEvts)]
293 job.cmds += [
"cat log.generate"]
296 job.cmds += [
"post_ini_time=$(grep snapshot_post_ini log.generate | awk '{ print $5}')"]
297 job.cmds += [
"post_lastevt_time=$(grep snapshot_post_lastevt log.generate | awk '{ print $5}')"]
298 job.cmds += [
"nPer12h=$(awk -v a=\"$post_lastevt_time\" -v b=\"$post_ini_time\" 'BEGIN { printf \"%.0f\", "
299 +
str(options.nEvts)+
"*12*60*60*1000/(a-b) }' </dev/null)"]
300 job.cmds += [
"finalEventsPerJob=0"]
301 job.cmds += [
"for i in 1 2 5 10 20 50 100 200 500 1000 2000 5000 10000; do if test $nPer12h -gt $i; then finalEventsPerJob=$i; fi; done"]
302 job.cmds += [
"echo \"Possible number of events per 12h: ${nPer12h} -> ${finalEventsPerJob} \""]
303 job.cmds += [
"if grep -q evgenConfig.nEventsPerJob "+jodir+
"/mc.*.py; then"]
304 job.cmds += [
r' sed -e "s/evgenConfig.nEventsPerJob.*=.*\([0-9]*\)/evgenConfig.nEventsPerJob = ${finalEventsPerJob}/g" -i '+jodir+
"/mc.*.py"]
306 job.cmds += [
" echo \"evgenConfig.nEventsPerJob = ${finalEventsPerJob}\" >> "+jodir+
"/mc.*.py"]
310 job.cmds += [
"cp log.generate ../../"]
312 job.cmds += [
"cd .."]
313 job.cmds += [
"rm -rf 5.EvntGenTest"]
315 job.write(extraDirs=[jodir])
316 job.submit(dryRun=options.dryRun)