3 import os, sys, optparse, math
7 usage =
"""%(prog)s INPUT_FILE OUTPUT_FILE [--noChambers] [--noLayers] [--ringsOnly] [--relativeTo ideal|none]
9 performs either sqlite-->xml or xml-->sqlite conversion following the documentation at
10 https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideMuonGeometryConversion
14 INPUT_FILE is either .db SQLite or .xml file that should be converted
15 OUTPUT_FILE is either .xml or .db output file, the result of conversion
17 Options for sqlite-->xml conversion:
19 --noChambers if present, no chambers info would be written into xml
20 --noLayers if present, no layers (and no DT superlayers) info would be written into xml
21 --relativeTo X by default, xml conversion is done relative to ideal DDD description,
22 if "none" is specified, absolute positions would be written into xml
23 --ringsOnly special flag for xml dumping of CSC ring structure only, it automatically
24 turns off all DTs and also CSC's chambers and layers on output and coordinates
25 are relative "to none"
29 print "Too few arguments!\n\n"+usage
32 parser=optparse.OptionParser(usage)
34 parser.add_option(
"--noChambers",
35 help=
"if present, no chambers info would be written into xml",
40 parser.add_option(
"--noLayers",
41 help=
"if present, no layers (and no DT superlayers) info would be written into xml",
46 parser.add_option(
"-l",
"--relativeTo",
47 help=
"by default, xml conversion is done relative to ideal DDD description, if \"none\" is specified, absolute positions would be written into xml",
52 parser.add_option(
"--ringsOnly",
53 help=
"special flag for xml dumping of CSC ring structure only, it automatically turns off all DTs and also CSC's chambers and layers",
58 options, args = parser.parse_args(sys.argv[3:])
61 if options.ringsOnly: supRings=
"False"
63 if options.noChambers
or options.ringsOnly: supChambers=
"True"
65 if options.noLayers
or options.ringsOnly: supLayers=
"True"
67 relativeTo=options.relativeTo
68 if options.ringsOnly: relativeTo=
"none"
71 theInputFile = sys.argv[1]
72 theOutputFile = sys.argv[2]
76 if theInputFile[-4:]==
".xml" and theOutputFile[-3:]==
".db":
78 file(
"tmp_converter_cfg.py",
"w").write(
"""# xml2sqlite conversion
79 from Alignment.MuonAlignment.convertXMLtoSQLite_cfg import *
80 process.MuonGeometryDBConverter.fileName = "%(theInputFile)s"
81 process.PoolDBOutputService.connect = "sqlite_file:%(theOutputFile)s"
85 if theInputFile[-3:]==
".db" and theOutputFile[-4:]==
".xml":
87 file(
"tmp_converter_cfg.py",
"w").write(
"""# sqlite2xml conversion
88 from Alignment.MuonAlignment.convertSQLitetoXML_cfg import *
90 process.PoolDBESSource.connect = "sqlite_file:%(theInputFile)s"
91 process.MuonGeometryDBConverter.outputXML.fileName = "%(theOutputFile)s"
93 process.MuonGeometryDBConverter.outputXML.relativeto = "%(relativeTo)s"
95 process.MuonGeometryDBConverter.outputXML.suppressDTBarrel = True
96 process.MuonGeometryDBConverter.outputXML.suppressDTWheels = True
97 process.MuonGeometryDBConverter.outputXML.suppressDTStations = True
98 process.MuonGeometryDBConverter.outputXML.suppressDTChambers = %(supChambers)s
99 process.MuonGeometryDBConverter.outputXML.suppressDTSuperLayers = %(supLayers)s
100 process.MuonGeometryDBConverter.outputXML.suppressDTLayers = %(supLayers)s
102 process.MuonGeometryDBConverter.outputXML.suppressCSCEndcaps = True
103 process.MuonGeometryDBConverter.outputXML.suppressCSCStations = True
104 process.MuonGeometryDBConverter.outputXML.suppressCSCRings = %(supRings)s
105 process.MuonGeometryDBConverter.outputXML.suppressCSCChambers = %(supChambers)s
106 process.MuonGeometryDBConverter.outputXML.suppressCSCLayers = %(supLayers)s
114 exit_code = os.system(
"cmsRun tmp_converter_cfg.py")
117 print "problem: cmsRun exited with code:", exit_code
119 os.system(
"rm tmp_converter_cfg.py")