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

convenient interface for HipPy and MP alignments #18900

Merged
merged 2 commits into from
May 24, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 109 additions & 5 deletions Alignment/OfflineValidation/python/TkAlAllInOneTool/alignment.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import collections
import os
import re

import configTemplates
from helperFunctions import replaceByMap, parsecolor, parsestyle
import os
from TkAlExceptions import AllInOneError

class Alignment:
Expand Down Expand Up @@ -28,7 +31,7 @@ def __init__(self, name, config, runGeomComp = "1"):
raise AllInOneError("section %s not found. Please define the "
"alignment!"%section)
config.checkInput(section,
knownSimpleOptions = ['globaltag', 'style', 'color', 'title'],
knownSimpleOptions = ['globaltag', 'style', 'color', 'title', 'mp', 'mp_alignments', 'mp_deformations', 'hp', 'sm'],
knownKeywords = ['condition'])
self.name = name
if config.exists(section,"title"):
Expand Down Expand Up @@ -65,12 +68,106 @@ def __shorthandExists(self, theRcdName, theShorthand):
return True
else:
return False



def __getConditions( self, theConfig, theSection ):
conditions = []
for option in theConfig.options( theSection ):
if option.startswith( "condition " ):
if option in ("mp", "mp_alignments", "mp_deformations"):
condPars = theConfig.get(theSection, option).split(",")
condPars = [_.strip() for _ in condPars]
if len(condPars) == 1:
number, = condPars
jobm = None
elif len(condPars) == 2:
number, jobm = condPars
else:
raise AllInOneError("Up to 2 arguments accepted for {} (job number, and optionally jobm index)".format(option))

if option == "mp":
alignments = True
deformations = True
elif option == "mp_alignments":
alignments = True
deformations = False
option = "mp"
elif option == "mp_deformations":
alignments = False
deformations = True
option = "mp"
else:
assert False

folder = "/afs/cern.ch/cms/CAF/CMSALCA/ALCA_TRACKERALIGN/MP/MPproduction/{}{}/".format(option, number)
if not os.path.exists(folder):
raise AllInOneError(folder+" does not exist.")
folder = os.path.join(folder, "jobData")
jobmfolders = set()
if jobm is None:
for filename in os.listdir(folder):
if re.match("jobm([0-9]*)", filename) and os.path.isdir(os.path.join(folder, filename)):
jobmfolders.add(filename)
if len(jobmfolders) == 0:
raise AllInOneError("No jobm or jobm(number) folder in {}".format(folder))
elif len(jobmfolders) == 1:
folder = os.path.join(folder, jobmfolders.pop())
else:
raise AllInOneError(
"Multiple jobm or jobm(number) folders in {}\n".format(folder)
+ ", ".join(jobmfolders) + "\n"
+ "Please specify 0 for jobm, or a number for one of the others."
)
elif jobm == "0":
folder = os.path.join(folder, "jobm")
if os.path.exists(folder + "0"):
raise AllInOneError("Not set up to handle a folder named jobm0")
else:
folder = os.path.join(folder, "jobm{}".format(jobm))

dbfile = os.path.join(folder, "alignments_MP.db")
if not os.path.exists(dbfile):
raise AllInOneError("No file {}. Maybe your alignment folder is corrupted, or maybe you specified the wrong jobm?".format(dbfile))

if alignments:
conditions.append({"rcdName": "TrackerAlignmentRcd",
"connectString": "sqlite_file:"+dbfile,
"tagName": "Alignments",
"labelName": ""})
if deformations:
conditions.append({"rcdName": "TrackerSurfaceDeformationRcd",
"connectString": "sqlite_file:"+dbfile,
"tagName": "Deformations",
"labelName": ""})

elif option in ("hp", "sm"):
condPars = theConfig.get(theSection, option).split(",")
condPars = [_.strip() for _ in condPars]
if len(condPars) == 1:
number, = condPars
iteration = None
elif len(condPars) == 2:
number, iteration = condPars
else:
raise AllInOneError("Up to 2 arguments accepted for {} (job number, and optionally iteration)".format(option))
folder = "/afs/cern.ch/cms/CAF/CMSALCA/ALCA_TRACKERALIGN2/HipPy/alignments/{}{}".format(option, number)
if not os.path.exists(folder):
raise AllInOneError(folder+" does not exist.")
if iteration is None:
for filename in os.listdir(folder):
match = re.match("alignments_iter([0-9]*).db", filename)
if match:
if iteration is None or int(match.group(1)) > iteration:
iteration = int(match.group(1))
if iteration is None:
raise AllInOneError("No alignments in {}".format(folder))
dbfile = os.path.join(folder, "alignments_iter{}.db".format(iteration))
if not os.path.exists(dbfile):
raise AllInOneError("No file {}.".format(dbfile))
conditions.append({"rcdName": "TrackerAlignmentRcd",
"connectString": "sqlite_file:"+dbfile,
"tagName": "Alignments",
"labelName": ""})

elif option.startswith( "condition " ):
rcdName = option.split( "condition " )[1]
condPars = theConfig.get( theSection, option ).split( "," )
if len(condPars) == 1:
Expand Down Expand Up @@ -115,6 +212,13 @@ def __getConditions( self, theConfig, theSection ):
"connectString": condPars[0].strip(),
"tagName": condPars[1].strip(),
"labelName": condPars[2].strip()})

rcdnames = collections.Counter(condition["rcdName"] for condition in conditions)
if max(rcdnames.values()) >= 2:
raise AllInOneError("Some conditions are specified multiple times (possibly through mp or hp options)!\n"
+ ", ".join(rcdname for rcdname, count in rcdnames.iteritems() if count >= 2))


return conditions

def __testDbExist(self, dbpath):
Expand Down