diff --git a/bin/rivet-mkvaldir b/bin/rivet-mkvaldir --- a/bin/rivet-mkvaldir +++ b/bin/rivet-mkvaldir @@ -1,331 +1,331 @@ #! /usr/bin/env python """ Build a directory with a Makefile for running a validation suit. """ import os, sys, shutil, commands ## Load the rivet module try: import rivet except: ## If rivet loading failed, try to bootstrap the Python path! try: # TODO: Is this a good idea? Maybe just notify the user that # their PYTHONPATH is wrong? modname = sys.modules[__name__].__file__ binpath = os.path.dirname(modname) rivetconfigpath = os.path.join(binpath, "rivet-config") rivetpypath = commands.getoutput(rivetconfigpath + " --pythonpath") sys.path.append(rivetpypath) import rivet except: sys.stderr.write("The rivet Python module could not be loaded: " + \ "is your PYTHONPATH set correctly?\n") sys.exit(5) rivet.util.check_python_version() rivet.util.set_process_name("rivet-merge") import time, datetime, logging, signal ## Parse command line options import argparse parser = argparse.ArgumentParser(description=__doc__) extragroup = parser.add_argument_group("Run settings") extragroup.add_argument("VALDIR", nargs=1, help="directory where the " + \ "Makefile for running the validation will be written") extragroup.add_argument("--hepmc-dir", dest="HEPMCDIR", default="", help="specify the directory where the HepMC files used for " + \ "the validation should be downloaded") extragroup.add_argument("--ref-dir", dest="REFDIR", default="", help="specify the directory where the reference " + \ "yodas are located.") args = parser.parse_args() #################################################### ## create and configure validation directory valdir = str(args.VALDIR[0]) hepmcdir = valdir + "/HEPMC" if not os.path.exists(valdir) and not os.path.realpath(valdir)==os.getcwd(): try: os.makedirs(valdir) except: print("Error: failed to make new directory '%s'" % valdir) sys.exit(1) if not args.HEPMCDIR : if not os.path.exists(hepmcdir): try: os.makedirs(hepmcdir) except: print("Error: failed to make new directory '%s'" % hepmcdir) sys.exit(1) else: if os.path.exists(hepmcdir) and os.path.islink(hepmcdir): out = commands.getstatusoutput("rm -f " + hepmcdir) if os.path.exists(hepmcdir): print("Error: please remove directory '" + hepmcdir + \ "' before spicifying a new location for HepMC files") sys.exit(1) if not os.path.exists(args.HEPMCDIR): try: os.makedirs(args.HEPMCDIR) except: print("Error: failed to make new directory '%s'" % args.HEPMCDIR) sys.exit(1) out = commands.getstatusoutput("ln -sf " + os.path.relpath(args.HEPMCDIR, valdir) + " " + hepmcdir) if os.path.exists(valdir + "/tmp"): shutil.rmtree(valdir + "/tmp") try: os.makedirs(valdir + "/tmp") except: print("Error: failed to make tmo directory '%s'" % valdir + "/tmp") sys.exit(1) refdir = args.REFDIR if not refdir : rivetdatapath = commands.getoutput("rivet-config --datadir") refdir = rivetdatapath + "/refyodas" out = commands.getstatusoutput("rm -f " + valdir + "/refyodas") out = commands.getstatusoutput("ln -s " + os.path.relpath(refdir, valdir) + " " + valdir + "/refyodas") ####################################### ## Collect information from .info files valtargets = dict() hepmctargets = dict() reentranttargets = set() ## Get all analysis names all_analyses = rivet.AnalysisLoader.analysisNames() for ananame in all_analyses: ana = rivet.AnalysisLoader.getAnalysis(ananame) for line in ana.validation(): line = line.replace("$A", ananame) sublines = line.split(";"); targets = sublines[0].split(" ") targetname = targets.pop(0) if ana.reentrant(): reentranttargets.add(targetname) hepmcname = targets.pop(0) options = ""; if len(targets) > 0 : options = targets[0].strip() if len(options) > 0 and options[0] == ":": targets.pop(0) else: options = "" if len(sublines) == 1: valtargets[targetname] = "tmp/" + hepmcname + ".yoda " + \ " ".join(targets) + "\n\t$(V)echo extracting " + \ targetname + ".yoda\n\t$(V)echo " + hepmcname + " > tmp/" + \ targetname + ".log\n\t$(V)yoda2yoda -m '/_XSEC|/_EVTCOUNT|/" +\ ananame + options + \ "/' tmp/" + hepmcname + ".yoda " + targetname + ".yoda >> tmp/" + \ targetname + ".log 2>&1\n" if not hepmctargets.has_key(hepmcname): hepmctargets[hepmcname] = ananame + options else: hepmctargets[hepmcname] += " " + ananame + options else: valtargets[targetname] = "HEPMC/" + hepmcname + ".hepmc.gz " +\ " ".join(targets) if len(sublines) > 1: valtargets[targetname] += "\n\t$(V)echo running " + \ targetname + ".yoda\n\t$(V)echo " + hepmcname + " > tmp/" + \ targetname + ".log\n\t$(V)" + sublines[1].strip() +\ " >> tmp/" + targetname + ".log 2>&1\n" for subline in sublines[2:]: valtargets[targetname] += "\t" + subline.strip() + \ " >> tmp/" + targetname + ".log 2>&1\n" if len(sublines) > 1: valtargets[targetname] += "\t$(V)echo done " + \ targetname + ".yoda\n" ############################# ## Write the Makefile mf = open(valdir + "/Makefile", 'w') ## Header and default and help targets. mf.write("""# # This Makefile administers the validation for Rivet. # # Usage: make check # # For more information use: make help # # This Makefile was produced by rivet-mkvaldir which scanned all # analysis .info files and parsed the "Validation:" section for # determining how to use the existing HepMC validation files to obtain # a set of reference YODA files that should be reproduced. The # directory where these reference files are stored is linked to # ./refyodas . The HepMC files are stored in ./HEPMC and will be # automatically downloaded if missing. In the end of running 'make # check', the newly produced YODA files will be compared with the # reference ones. If differences are found in any histogram, the # corresponing plot will be produced by rivet-mkhtml and can be # accessed from the index.html file. # # The syntax for specifying a reference YODA in the .info file looks # as follows: # # - YODA-name HEPMC-name [:option=val] [dependencies] [[; commandline] ...] # # the YODA-name should be given without the .yoda suffix and typically # is constructed from the analysis name with some number appended if # there are more than one reference YODA for an analysis. Note that # the sting "$A" can be used anywher and will be expanded to the # analysis name. HEPMC-name should given without the ".hepmc.gz" # suffix. "dependencies" can eg. include the reference YODA from # another analysis that are referenced in any of the # "commandline"s. If no commandline is given the analysis will be run # together with a bunch of other analyses and the YODA-name.yoda will # be extracted form the resulting yoda. In this case the analysis will # be run using the "options" if present. The command lines will be used # as "make" recipes where the output YODA file can be given by $@ and the # HepMC file by $< possible options must then be included by explicitly # # When submitting a new analysis to Rivet, the "Validation:" section # of the .info file must be present and all the corresponding YODA # reference file should be be included in the submission. If a # non-standard HepMC file is needed to reproduce the reference YODA, # this must be included as well. # V=@ all: $(V)head -7 $(firstword $(MAKEFILE_LIST)) help: $(V)head -44 $(firstword $(MAKEFILE_LIST)) | grep -v "# For more information" """) ## target for comparing the generated yodas with the reference ones mf.write(""" %.diff: %.yoda $(V)rm -rf $@ $(V)if [ -e refyodas/$< ]; then \\ if ! yodadiff $< refyodas/$< -t 1e-2 -q; then \\ echo $< differs from reference yoda; \\ only=""; \\ for plot in `yodadiff $< refyodas/$< -t 1e-2 -l`; do \\ only="$$only -m $$plot"; \\ done; \\ rivet-mkhtml $$only -o $@ $< refyodas/$<:Title=ref > /dev/null 2>&1; \\ else \\ echo $< is the same as reference yoda; \\ touch $@; \\ fi \\ else \\ echo $< has no reference yoda; \\ echo "$< has no reference yoda.
" > $@; \\ fi %.reent: %.yoda $(V)rm -rf $@ $(V)logfile=$<; logfile="tmp/$${logfile/.yoda/.log}"; \\ if rivet-merge $< -o $<.yoda >> $$logfile 2>&1; then\\ if yodadiff -q $< $<.yoda ; then \\ echo $< is reentrant; \\ touch $@; \\ else \\ echo $< is NOT reentrant; \\ echo "$< was declared reentrant but is not.
" > $@; \\ fi \\ fi $(V)rm -rf $<.yoda """) ## the main check target mf.write("VALYODAS =") for ana in valtargets: mf.write(" " + ana + ".yoda") mf.write("\n\nVALDIFFS =") for ana in valtargets: mf.write(" " + ana + ".diff") mf.write("\n\nREENTRANTS =") for ana in reentranttargets: mf.write(" " + ana + ".reent") mf.write("\n\nHEPMCYODAS =") for hepmc in hepmctargets: mf.write(" tmp/" + hepmc + ".yoda") mf.write("""\n .PRECIOUS: $(VALYODAS) $(HEPMCYODAS) check: $(VALDIFFS) $(REENTRANTS) $(V)echo "

Problematic analyses in Rivet validation

" > index.html $(V)for dir in $^; do \\ if [ -d $$dir ]; then \\ for subdir in `ls $$dir`; do \\ if [ -f $$dir/$$subdir/index.html ]; then\\ echo -n "$${dir/.diff/} (" >> index.html; \\ echo -n `head -1 tmp/$${dir/.diff/.log}` >> index.html; \\ echo ")
" >> index.html; \\ fi \\ done \\ elif [ -s $$dir ]; then \\ cat $$dir >> index.html; \\ fi \\ done $(V)echo "" $(V)if test `cat index.html | wc -l` -gt 1; then \\ echo "Differences found, open index.html to inspect plots."; \\ else \\ echo "No differences found!"; \\ fi clean: rm -f $(VALYODAS) $(REENTRANTS) rm -rf tmp mkdir tmp rm -rf $(VALDIFFS) rm -f index.html %.recheck: %.yoda rm -f $< hepmc=tmp/$<; rm -f tmp/`head -1 $${hepmc/.yoda/.log}`".yoda" $(MAKE) check """) ## targets for hepmc files with several analyses for hepmc in hepmctargets: mf.write("tmp/" + hepmc + ".yoda: HEPMC/" + hepmc + ".hepmc.gz\n") mf.write("\t$(V)echo running " + hepmc + "\n") cmd = "\t$(V)rivet HEPMC/" + hepmc + ".hepmc.gz -o tmp/" + hepmc + ".yoda" for ana in hepmctargets[hepmc].split(" "): cmd += " -a " + ana mf.write(cmd + " > tmp/" + hepmc + ".log 2>&1\n") mf.write("\t$(V)echo done " + hepmc + "\n\n") ## targets for the .yoda files to be compared to the reference ones for ana in valtargets: mf.write(ana + ".yoda: " + valtargets[ana] + "\n") mf.write("\n") -## target for fetching the standard HepMC files fromcernbox +## target for fetching the standard HepMC files from cernbox mf.write("HEPMC/%.hepmc.gz:\n") mf.write("\twget 'https://cernbox.cern.ch/index.php/s/6QD1dvXFt1FJ7Dy/download?path=%2F&x-access-token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkcm9wX29ubHkiOmZhbHNlLCJleHAiOiIyMDE5LTA1LTMxVDE0OjAwOjU3LjgzNzgzMzIwMSswMjowMCIsImV4cGlyZXMiOjAsImlkIjoiMTYzMTI1IiwiaXRlbV90eXBlIjoxLCJtdGltZSI6MTU0OTk2OTEwOCwib3duZXIiOiJhYnVja2xleSIsInBhdGgiOiJlb3Nob21lLWE6MTkwOTgzOTkiLCJwcm90ZWN0ZWQiOmZhbHNlLCJyZWFkX29ubHkiOnRydWUsInNoYXJlX25hbWUiOiJSaXZldCB2YWxpZGF0aW9uIEhlcE1DIiwidG9rZW4iOiI2UUQxZHZYRnQxRko3RHkifQ.lvLykwYq_NheD6ld2IidhogrKdQfVz43y8wOooYF6Kg&files=$(@F)' -O $@\n\n")