File indexing completed on 2024-11-25 02:29:04
0001
0002
0003 import os, sys, optparse, math
0004
0005 prog = sys.argv[0]
0006
0007 usage = """%(prog)s INPUT_FILE OUTPUT_FILE [--noChambers] [--noLayers] [--ringsOnly] [--relativeTo ideal|none]
0008
0009 performs either sqlite-->xml or xml-->sqlite conversion following the documentation at
0010 https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideMuonGeometryConversion
0011
0012 Arguments:
0013
0014 INPUT_FILE is either .db SQLite or .xml file that should be converted
0015 OUTPUT_FILE is either .xml or .db output file, the result of conversion
0016
0017 Options for sqlite-->xml conversion:
0018
0019 --noChambers if present, no chambers info would be written into xml
0020 --noLayers if present, no layers (and no DT superlayers) info would be written into xml
0021 --relativeTo X by default, xml conversion is done relative to ideal DDD description,
0022 if "none" is specified, absolute positions would be written into xml
0023 --ringsOnly special flag for xml dumping of CSC ring structure only, it automatically
0024 turns off all DTs and also CSC's chambers and layers on output and coordinates
0025 are relative "to none"
0026 --runNumber N Use run #N to extract xml from necessary IOV
0027 """ % vars()
0028
0029 if len(sys.argv) < 3:
0030 print("Too few arguments!\n\n"+usage)
0031 sys.exit()
0032
0033 parser=optparse.OptionParser(usage)
0034
0035 parser.add_option("--noChambers",
0036 help="if present, no chambers info would be written into xml",
0037 action="store_true",
0038 default=False,
0039 dest="noChambers")
0040
0041 parser.add_option("--noLayers",
0042 help="if present, no layers (and no DT superlayers) info would be written into xml",
0043 action="store_true",
0044 default=False,
0045 dest="noLayers")
0046
0047 parser.add_option("-l", "--relativeTo",
0048 help="by default, xml conversion is done relative to ideal DDD description, if \"none\" is specified, absolute positions would be written into xml",
0049 type="string",
0050 default='ideal',
0051 dest="relativeTo")
0052
0053 parser.add_option("--ringsOnly",
0054 help="special flag for xml dumping of CSC ring structure only, it automatically turns off all DTs and also CSC's chambers and layers",
0055 action="store_true",
0056 default=False,
0057 dest="ringsOnly")
0058
0059 parser.add_option("-r", "--runNumber",
0060 help="Use run #N to extract xml from necessary IOV (default is 1)",
0061 type="int",
0062 default=1,
0063 dest="runNumber")
0064
0065 parser.add_option("--gprcdconnect",
0066 help="connect string for GlobalPositionRcd (frontier://... or sqlite_file:...). The defailt is a trivial/inert GPR",
0067 type="string",
0068 default="sqlite_file:inertGlobalPositionRcd.db",
0069 dest="gprcdconnect")
0070
0071 parser.add_option("--gprcd",
0072 help="name of GlobalPositionRcd tag",
0073 type="string",
0074 default="inertGlobalPositionRcd",
0075 dest="gprcd")
0076
0077
0078 options, args = parser.parse_args(sys.argv[3:])
0079
0080 supRings="True"
0081 if options.ringsOnly: supRings="False"
0082 supChambers="False"
0083 if options.noChambers or options.ringsOnly: supChambers="True"
0084 supLayers="False"
0085 if options.noLayers or options.ringsOnly: supLayers="True"
0086
0087 relativeTo=options.relativeTo
0088 if options.ringsOnly: relativeTo="none"
0089
0090 runNumber = options.runNumber
0091 gprcdconnect = options.gprcdconnect
0092 gprcd = options.gprcd
0093
0094 theInputFile = sys.argv[1]
0095 theOutputFile = sys.argv[2]
0096
0097 ok = False
0098
0099 if theInputFile[-4:]==".xml" and theOutputFile[-3:]==".db":
0100 ok = True
0101 file("tmp_converter_cfg.py","w").write("""# xml2sqlite conversion
0102 from Alignment.MuonAlignment.convertXMLtoSQLite_cfg import *
0103 process.MuonGeometryDBConverter.fileName = "%(theInputFile)s"
0104 process.PoolDBOutputService.connect = "sqlite_file:%(theOutputFile)s"
0105 process.inertGlobalPositionRcd.connect = "%(gprcdconnect)s"
0106 process.inertGlobalPositionRcd.toGet = cms.VPSet(cms.PSet(record = cms.string('GlobalPositionRcd'), tag = cms.string('%(gprcd)s')))
0107
0108 """ % vars())
0109
0110 if theInputFile[-3:]==".db" and theOutputFile[-4:]==".xml":
0111 ok = True
0112 file("tmp_converter_cfg.py","w").write("""# sqlite2xml conversion
0113 from Alignment.MuonAlignment.convertSQLitetoXML_cfg import *
0114
0115 process.source = cms.Source("EmptySource",
0116 numberEventsInRun = cms.untracked.uint32(1),
0117 firstRun = cms.untracked.uint32(%(runNumber)d)
0118 )
0119
0120 process.inertGlobalPositionRcd.connect = "%(gprcdconnect)s"
0121 process.inertGlobalPositionRcd.toGet = cms.VPSet(cms.PSet(record = cms.string('GlobalPositionRcd'), tag = cms.string('%(gprcd)s')))
0122
0123 process.PoolDBESSource.connect = "sqlite_file:%(theInputFile)s"
0124 process.MuonGeometryDBConverter.outputXML.fileName = "%(theOutputFile)s"
0125
0126 process.MuonGeometryDBConverter.outputXML.relativeto = "%(relativeTo)s"
0127
0128 process.MuonGeometryDBConverter.outputXML.suppressDTBarrel = True
0129 process.MuonGeometryDBConverter.outputXML.suppressDTWheels = True
0130 process.MuonGeometryDBConverter.outputXML.suppressDTStations = True
0131 process.MuonGeometryDBConverter.outputXML.suppressDTChambers = %(supChambers)s
0132 process.MuonGeometryDBConverter.outputXML.suppressDTSuperLayers = %(supLayers)s
0133 process.MuonGeometryDBConverter.outputXML.suppressDTLayers = %(supLayers)s
0134
0135 process.MuonGeometryDBConverter.outputXML.suppressCSCEndcaps = True
0136 process.MuonGeometryDBConverter.outputXML.suppressCSCStations = True
0137 process.MuonGeometryDBConverter.outputXML.suppressCSCRings = %(supRings)s
0138 process.MuonGeometryDBConverter.outputXML.suppressCSCChambers = %(supChambers)s
0139 process.MuonGeometryDBConverter.outputXML.suppressCSCLayers = %(supLayers)s
0140
0141 """ % vars())
0142
0143 if not ok:
0144 print(usage)
0145 sys.exit()
0146
0147 exit_code = os.system("cmsRun tmp_converter_cfg.py")
0148
0149 if exit_code>0:
0150 print("problem: cmsRun exited with code:", exit_code)
0151 else:
0152 os.system("rm tmp_converter_cfg.py")