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"
26 --runNumber N Use run #N to extract xml from necessary IOV
30 print "Too few arguments!\n\n"+usage
33 parser=optparse.OptionParser(usage)
35 parser.add_option(
"--noChambers",
36 help=
"if present, no chambers info would be written into xml",
41 parser.add_option(
"--noLayers",
42 help=
"if present, no layers (and no DT superlayers) info would be written into xml",
47 parser.add_option(
"-l",
"--relativeTo",
48 help=
"by default, xml conversion is done relative to ideal DDD description, if \"none\" is specified, absolute positions would be written into xml",
53 parser.add_option(
"--ringsOnly",
54 help=
"special flag for xml dumping of CSC ring structure only, it automatically turns off all DTs and also CSC's chambers and layers",
59 parser.add_option(
"-r",
"--runNumber",
60 help=
"Use run #N to extract xml from necessary IOV (default is 1)",
65 parser.add_option(
"--gprcdconnect",
66 help=
"connect string for GlobalPositionRcd (frontier://... or sqlite_file:...). The defailt is a trivial/inert GPR",
68 default=
"sqlite_file:inertGlobalPositionRcd.db",
71 parser.add_option(
"--gprcd",
72 help=
"name of GlobalPositionRcd tag",
74 default=
"inertGlobalPositionRcd",
78 options, args = parser.parse_args(sys.argv[3:])
81 if options.ringsOnly: supRings=
"False"
83 if options.noChambers
or options.ringsOnly: supChambers=
"True"
85 if options.noLayers
or options.ringsOnly: supLayers=
"True"
87 relativeTo=options.relativeTo
88 if options.ringsOnly: relativeTo=
"none"
90 runNumber = options.runNumber
91 gprcdconnect = options.gprcdconnect
94 theInputFile = sys.argv[1]
95 theOutputFile = sys.argv[2]
99 if theInputFile[-4:]==
".xml" and theOutputFile[-3:]==
".db":
101 file(
"tmp_converter_cfg.py",
"w").
write(
"""# xml2sqlite conversion
102 from Alignment.MuonAlignment.convertXMLtoSQLite_cfg import *
103 process.MuonGeometryDBConverter.fileName = "%(theInputFile)s"
104 process.PoolDBOutputService.connect = "sqlite_file:%(theOutputFile)s"
105 process.inertGlobalPositionRcd.connect = "%(gprcdconnect)s"
106 process.inertGlobalPositionRcd.toGet = cms.VPSet(cms.PSet(record = cms.string('GlobalPositionRcd'), tag = cms.string('%(gprcd)s')))
110 if theInputFile[-3:]==
".db" and theOutputFile[-4:]==
".xml":
112 file(
"tmp_converter_cfg.py",
"w").
write(
"""# sqlite2xml conversion
113 from Alignment.MuonAlignment.convertSQLitetoXML_cfg import *
115 process.source = cms.Source("EmptySource",
116 numberEventsInRun = cms.untracked.uint32(1),
117 firstRun = cms.untracked.uint32(%(runNumber)d)
120 process.inertGlobalPositionRcd.connect = "%(gprcdconnect)s"
121 process.inertGlobalPositionRcd.toGet = cms.VPSet(cms.PSet(record = cms.string('GlobalPositionRcd'), tag = cms.string('%(gprcd)s')))
123 process.PoolDBESSource.connect = "sqlite_file:%(theInputFile)s"
124 process.MuonGeometryDBConverter.outputXML.fileName = "%(theOutputFile)s"
126 process.MuonGeometryDBConverter.outputXML.relativeto = "%(relativeTo)s"
128 process.MuonGeometryDBConverter.outputXML.suppressDTBarrel = True
129 process.MuonGeometryDBConverter.outputXML.suppressDTWheels = True
130 process.MuonGeometryDBConverter.outputXML.suppressDTStations = True
131 process.MuonGeometryDBConverter.outputXML.suppressDTChambers = %(supChambers)s
132 process.MuonGeometryDBConverter.outputXML.suppressDTSuperLayers = %(supLayers)s
133 process.MuonGeometryDBConverter.outputXML.suppressDTLayers = %(supLayers)s
135 process.MuonGeometryDBConverter.outputXML.suppressCSCEndcaps = True
136 process.MuonGeometryDBConverter.outputXML.suppressCSCStations = True
137 process.MuonGeometryDBConverter.outputXML.suppressCSCRings = %(supRings)s
138 process.MuonGeometryDBConverter.outputXML.suppressCSCChambers = %(supChambers)s
139 process.MuonGeometryDBConverter.outputXML.suppressCSCLayers = %(supLayers)s
147 exit_code = os.system(
"cmsRun tmp_converter_cfg.py")
150 print "problem: cmsRun exited with code:", exit_code
152 os.system(
"rm tmp_converter_cfg.py")