Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16135 from ghellwig/temporary-fix_multi-IOV-input…
…_MillePede_81X [81X] Temporary fix for multi-IOV input in MillePede
- Loading branch information
Showing
7 changed files
with
251 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
Alignment/MillePedeAlignmentAlgorithm/python/mpslib/tools.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import os | ||
import sys | ||
import subprocess | ||
import CondCore.Utilities.CondDBFW.shell as shell | ||
|
||
|
||
def create_single_iov_db(global_tag, run_number, output_db): | ||
"""Create an sqlite file with single-IOV tags for alignment payloads. | ||
Arguments: | ||
- `global_tag`: global tag from which to extract the payloads | ||
- `run_number`: run for which the IOVs are selected | ||
- `output_db`: name of the output sqlite file | ||
""" | ||
|
||
con = shell.connect() | ||
tags = con.global_tag_map(global_tag_name = global_tag, | ||
record = ["TrackerAlignmentRcd", | ||
"TrackerSurfaceDeformationRcd", | ||
"TrackerAlignmentErrorExtendedRcd"]) | ||
con.close_session() | ||
|
||
tags = {item["record"]: {"name": item["tag_name"]} | ||
for item in tags.as_dicts()} | ||
|
||
for record,tag in tags.iteritems(): | ||
iovs = con.tag(name = tag["name"]).iovs().as_dicts() | ||
run_is_covered = False | ||
for iov in reversed(iovs): | ||
if iov["since"] <= run_number: | ||
tag["since"] = str(iov["since"]) | ||
run_is_covered = True | ||
break | ||
if not run_is_covered: | ||
msg = ("Run number {0:d} is not covered in '{1:s}' ({2:s}) from" | ||
" '{3:s}'.".format(run_number, tag["name"], record, | ||
global_tag)) | ||
print msg | ||
print "Aborting..." | ||
sys.exit(1) | ||
|
||
result = {} | ||
if os.path.exists(output_db): os.remove(output_db) | ||
for record,tag in tags.iteritems(): | ||
result[record] = {"connect": "sqlite_file:"+output_db, | ||
"tag": "_".join([tag["name"], tag["since"]])} | ||
cmd = ("conddb_import", | ||
"-f", "frontier://PromptProd/cms_conditions", | ||
"-c", result[record]["connect"], | ||
"-i", tag["name"], | ||
"-t", result[record]["tag"], | ||
"-b", str(run_number), | ||
"-e", str(run_number)) | ||
run_checked(cmd) | ||
run_checked(["sqlite3", output_db, "update iov set since=1"]) | ||
|
||
return result | ||
|
||
|
||
def run_checked(cmd): | ||
"""Run `cmd` and exit in case of failures. | ||
Arguments: | ||
- `cmd`: list containing the strings of the command | ||
""" | ||
|
||
try: | ||
with open(os.devnull, "w") as devnull: | ||
subprocess.check_call(cmd, stdout = devnull) | ||
except subprocess.CalledProcessError as e: | ||
print "Problem in running the following command:" | ||
print " ".join(e.cmd) | ||
sys.exit(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
Alignment/MillePedeAlignmentAlgorithm/scripts/mps_prepare_input_db.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/usr/bin/env python | ||
|
||
import sys | ||
import argparse | ||
import Alignment.MillePedeAlignmentAlgorithm.mpslib.tools as mps_tools | ||
|
||
################################################################################ | ||
def main(argv = None): | ||
"""Main routine of the script. | ||
Arguments: | ||
- `argv`: arguments passed to the main routine | ||
""" | ||
|
||
if argv == None: | ||
argv = sys.argv[1:] | ||
|
||
parser = argparse.ArgumentParser( | ||
description="Prepare input db file for MillePede workflow.") | ||
parser.add_argument("-g", "--global-tag", dest="global_tag", required=True, | ||
metavar="TAG", | ||
help="global tag to extract the alignment payloads") | ||
parser.add_argument("-r", "--run-number", dest="run_number", required=True, | ||
metavar="INTEGER", type=int, | ||
help="run number to select IOV") | ||
parser.add_argument("-o", "--output-db", dest="output_db", | ||
default="alignment_input.db", metavar="PATH", | ||
help="name of the output file (default: '%(default)s')") | ||
args = parser.parse_args(argv) | ||
|
||
mps_tools.create_single_iov_db(args.global_tag, | ||
args.run_number, | ||
args.output_db) | ||
|
||
|
||
################################################################################ | ||
if __name__ == "__main__": | ||
try: | ||
main() | ||
except KeyboardInterrupt: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters