Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.0.X] Fix arrow plots in geometry comparison tool #21159

Merged
merged 8 commits into from Nov 10, 2017
390 changes: 390 additions & 0 deletions Alignment/OfflineValidation/macros/makeArrowPlots.C

Large diffs are not rendered by default.

Expand Up @@ -3,7 +3,7 @@
import re

import configTemplates
from helperFunctions import conddb, parsecolor, parsestyle, replaceByMap
from helperFunctions import conddb, parsecolor, parsestyle, replaceByMap, clean_name
from TkAlExceptions import AllInOneError

class Alignment(object):
Expand Down Expand Up @@ -39,7 +39,7 @@ def __init__(self, name, config, runGeomComp = "1"):
config.checkInput(section,
knownSimpleOptions = ['globaltag', 'style', 'color', 'title', 'mp', 'mp_alignments', 'mp_deformations', 'hp', 'hp_alignments', 'hp_deformations', 'sm', 'sm_alignments', 'sm_deformations'],
knownKeywords = ['condition'])
self.name = name
self.name = clean_name(name)
if config.exists(section,"title"):
self.title = config.get(section,"title")
else:
Expand Down
Expand Up @@ -125,6 +125,16 @@ def getAlignments( self ):
if "alignment:" in section:
alignments.append( Alignment( section.split( "alignment:" )[1],
self ) )
names_after_cleaning = [alignment.name for alignment in alignments]
duplicates = [name
for name, count
in collections.Counter(names_after_cleaning).items()
if count > 1]
if len(duplicates) > 0:
msg = "Duplicate alignment names after removing invalid characters: "
msg += ", ".join(duplicates) +"\n"
msg += "Please rename the alignments to avoid name clashes."
raise AllInOneError(msg)
return alignments

def getCompares( self ):
Expand Down
Expand Up @@ -59,10 +59,10 @@
#rfmkdir -p .oO[datadir]Oo. &>! /dev/null

#remove possible result file from previous runs
previous_results=$(eos ls /store/caf/user/$USER/.oO[eosdir]Oo.)
previous_results=$(ls /eos/cms/store/caf/user/$USER/.oO[eosdir]Oo.)
for file in ${previous_results}
do
if [ ${file} = /store/caf/user/$USER/.oO[eosdir]Oo./.oO[outputFile]Oo. ]
if [ ${file} = /eos/cms/store/caf/user/$USER/.oO[eosdir]Oo./.oO[outputFile]Oo. ]
then
xrdcp -f root://eoscms//eos/cms${file} root://eoscms//eos/cms${file}.bak
fi
Expand Down Expand Up @@ -98,7 +98,7 @@
find . -maxdepth 1 -name "LOGFILE*.oO[alignmentName]Oo.*" -print | xargs -I {} bash -c "rfcp {} .oO[logdir]Oo."

#copy root files to eos
eos mkdir -p /store/caf/user/$USER/.oO[eosdir]Oo.
mkdir -p /eos/cms/store/caf/user/$USER/.oO[eosdir]Oo.
if [ .oO[parallelJobs]Oo. -eq 1 ]
then
root_files=$(ls --color=never -d *.oO[alignmentName]Oo.*.root)
Expand Down Expand Up @@ -236,7 +236,7 @@

###############################################################################
# download root files from eos
root_files=$(eos ls /store/caf/user/$USER/.oO[eosdir]Oo. \
root_files=$(ls /eos/cms/store/caf/user/$USER/.oO[eosdir]Oo. \
| grep ".root$" | grep -v "result.root$")
#for file in ${root_files}
#do
Expand Down Expand Up @@ -267,7 +267,6 @@
######################################################################
mergeParallelOfflineTemplate="""
#!/bin/bash
eos='/afs/cern.ch/project/eos/installation/cms/bin/eos.select'
CWD=`pwd -P`
cd .oO[CMSSW_BASE]Oo./src
export SCRAM_ARCH=.oO[SCRAM_ARCH]Oo.
Expand Down Expand Up @@ -326,7 +325,7 @@
compareAlignmentsExecution="""
#merge for .oO[validationId]Oo. if it does not exist or is not up-to-date
echo -e "\n\nComparing validations"
eos mkdir -p /store/caf/user/$USER/.oO[eosdir]Oo./
mkdir -p /eos/cms/store/caf/user/$USER/.oO[eosdir]Oo./
cp .oO[Alignment/OfflineValidation]Oo./scripts/compareFileAges.C .
root -x -q -b -l "compareFileAges.C(\\\"root://eoscms.cern.ch//eos/cms/store/caf/user/$USER/.oO[eosdir]Oo./.oO[validationId]Oo._result.root\\\", \\\".oO[compareStringsPlain]Oo.\\\")"
comparisonNeeded=${?}
Expand Down
Expand Up @@ -2,7 +2,7 @@
import ConfigParser # needed for exceptions in this module
import configTemplates
from genericValidation import GenericValidation
from helperFunctions import replaceByMap, getCommandOutput2, cppboolstring, pythonboolstring
from helperFunctions import replaceByMap, getCommandOutput2, cppboolstring, pythonboolstring, clean_name
from TkAlExceptions import AllInOneError


Expand All @@ -17,7 +17,7 @@ class GeometryComparison(GenericValidation):
"modulesToPlot":"all",
"moduleList": "/store/caf/user/cschomak/emptyModuleList.txt",
"useDefaultRange":"false",
"plotOnlyGlobal":"false",
"plotOnlyGlobal":"true",
"plotPng":"true",
"makeProfilePlots":"true",
"dx_min":"-99999",
Expand Down Expand Up @@ -89,12 +89,12 @@ def getRepMap(self, alignment = None):
common = self.__compares.keys()[0]

repMap.update({
"common": common,
"common": clean_name(common),
"comparedGeometry": (".oO[alignmentName]Oo."
"ROOTGeometry.root"),
"referenceGeometry": "IDEAL", # will be replaced later
# if not compared to IDEAL
"reference": referenceName,
"reference": clean_name(referenceName),
"referenceTitle": referenceTitle,
"alignmentTitle": self.alignmentToValidate.title,
"moduleListBase": os.path.basename(repMap["moduleList"]),
Expand Down Expand Up @@ -230,18 +230,9 @@ def createScript(self, path):
"\"TkMap_SurfDeform*.png\" -print | xargs -I {} bash -c"
" \"rfcp {} .oO[datadir]Oo./.oO[name]Oo."
".Comparison_common"+name+"_Images/\" \n")
repMap["runComparisonScripts"] += \
("if [[ $HOSTNAME = lxplus[0-9]*[.a-z0-9]* ]]\n"
"then\n"
" rfmkdir -p .oO[workdir]Oo./.oO[name]Oo.."+name
+"_ArrowPlots\n"
"else\n"
" mkdir -p $CWD/TkAllInOneTool/.oO[name]Oo.."+name
+"_ArrowPlots\n"
"fi\n")
repMap["runComparisonScripts"] += \
("rfcp .oO[Alignment/OfflineValidation]Oo."
"/scripts/makeArrowPlots.C "
"/macros/makeArrowPlots.C "
".\n"
"root -b -q 'makeArrowPlots.C(\""
".oO[name]Oo..Comparison_common"+name
Expand All @@ -255,6 +246,11 @@ def createScript(self, path):
"-maxdepth 1 -name \"*.png\" -print | xargs -I {} bash "
"-c \"rfcp {} .oO[datadir]Oo./.oO[name]Oo."
".Comparison_common"+name+"_Images/ArrowPlots\"\n")
repMap["runComparisonScripts"] += \
("find .oO[name]Oo.."+name+"_ArrowPlots "
"-maxdepth 1 -name \"*.pdf\" -print | xargs -I {} bash "
"-c \"rfcp {} .oO[datadir]Oo./.oO[name]Oo."
".Comparison_common"+name+"_Images/ArrowPlots\"\n")
repMap["runComparisonScripts"] += \
("find . "
"-maxdepth 1 -name \".oO[common]Oo._.oO[name]Oo..Visualization_rotated.gif\" -print | xargs -I {} bash "
Expand Down
@@ -1,4 +1,5 @@
import os
import re
import ROOT
import sys
from TkAlExceptions import AllInOneError
Expand Down Expand Up @@ -226,3 +227,19 @@ def sysexit(number):
sys.stdout = bkpstdout

return result


def clean_name(s):
"""Transforms a string into a valid variable or method name.

Arguments:
- `s`: input string
"""

# Remove invalid characters
s = re.sub(r"[^0-9a-zA-Z_]", "", s)

# Remove leading characters until we find a letter or underscore
s = re.sub(r"^[^a-zA-Z_]+", "", s)

return s