3 from __future__
import print_function
4 import os, sys, optparse, math
8 usage =
"""%(prog)s INPUT_FILE OUTPUT_FILE [--noChambers] [--noLayers] [--ringsOnly] [--relativeTo ideal|none] 10 performs either sqlite-->xml or xml-->sqlite conversion following the documentation at 11 https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideMuonGeometryConversion 15 INPUT_FILE is either .db SQLite or .xml file that should be converted 16 OUTPUT_FILE is either .xml or .db output file, the result of conversion 18 Options for sqlite-->xml conversion: 20 --noChambers if present, no chambers info would be written into xml 21 --noLayers if present, no layers (and no DT superlayers) info would be written into xml 22 --relativeTo X by default, xml conversion is done relative to ideal DDD description, 23 if "none" is specified, absolute positions would be written into xml 24 --ringsOnly special flag for xml dumping of CSC ring structure only, it automatically 25 turns off all DTs and also CSC's chambers and layers on output and coordinates 26 are relative "to none" 27 --runNumber N Use run #N to extract xml from necessary IOV 31 print(
"Too few arguments!\n\n"+usage)
34 parser=optparse.OptionParser(usage)
36 parser.add_option(
"--noChambers",
37 help=
"if present, no chambers info would be written into xml",
42 parser.add_option(
"--noLayers",
43 help=
"if present, no layers (and no DT superlayers) info would be written into xml",
48 parser.add_option(
"-l",
"--relativeTo",
49 help=
"by default, xml conversion is done relative to ideal DDD description, if \"none\" is specified, absolute positions would be written into xml",
54 parser.add_option(
"--ringsOnly",
55 help=
"special flag for xml dumping of CSC ring structure only, it automatically turns off all DTs and also CSC's chambers and layers",
60 parser.add_option(
"-r",
"--runNumber",
61 help=
"Use run #N to extract xml from necessary IOV (default is 1)",
66 parser.add_option(
"--gprcdconnect",
67 help=
"connect string for GlobalPositionRcd (frontier://... or sqlite_file:...). The defailt is a trivial/inert GPR",
69 default=
"sqlite_file:inertGlobalPositionRcd.db",
72 parser.add_option(
"--gprcd",
73 help=
"name of GlobalPositionRcd tag",
75 default=
"inertGlobalPositionRcd",
79 options, args = parser.parse_args(sys.argv[3:])
82 if options.ringsOnly: supRings=
"False" 84 if options.noChambers
or options.ringsOnly: supChambers=
"True" 86 if options.noLayers
or options.ringsOnly: supLayers=
"True" 88 relativeTo=options.relativeTo
89 if options.ringsOnly: relativeTo=
"none" 91 runNumber = options.runNumber
92 gprcdconnect = options.gprcdconnect
95 theInputFile = sys.argv[1]
96 theOutputFile = sys.argv[2]
100 if theInputFile[-4:]==
".xml" and theOutputFile[-3:]==
".db":
102 file(
"tmp_converter_cfg.py",
"w").
write(
"""# xml2sqlite conversion 103 from Alignment.MuonAlignment.convertXMLtoSQLite_cfg import * 104 process.MuonGeometryDBConverter.fileName = "%(theInputFile)s" 105 process.PoolDBOutputService.connect = "sqlite_file:%(theOutputFile)s" 106 process.inertGlobalPositionRcd.connect = "%(gprcdconnect)s" 107 process.inertGlobalPositionRcd.toGet = cms.VPSet(cms.PSet(record = cms.string('GlobalPositionRcd'), tag = cms.string('%(gprcd)s'))) 111 if theInputFile[-3:]==
".db" and theOutputFile[-4:]==
".xml":
113 file(
"tmp_converter_cfg.py",
"w").
write(
"""# sqlite2xml conversion 114 from Alignment.MuonAlignment.convertSQLitetoXML_cfg import * 116 process.source = cms.Source("EmptySource", 117 numberEventsInRun = cms.untracked.uint32(1), 118 firstRun = cms.untracked.uint32(%(runNumber)d) 121 process.inertGlobalPositionRcd.connect = "%(gprcdconnect)s" 122 process.inertGlobalPositionRcd.toGet = cms.VPSet(cms.PSet(record = cms.string('GlobalPositionRcd'), tag = cms.string('%(gprcd)s'))) 124 process.PoolDBESSource.connect = "sqlite_file:%(theInputFile)s" 125 process.MuonGeometryDBConverter.outputXML.fileName = "%(theOutputFile)s" 127 process.MuonGeometryDBConverter.outputXML.relativeto = "%(relativeTo)s" 129 process.MuonGeometryDBConverter.outputXML.suppressDTBarrel = True 130 process.MuonGeometryDBConverter.outputXML.suppressDTWheels = True 131 process.MuonGeometryDBConverter.outputXML.suppressDTStations = True 132 process.MuonGeometryDBConverter.outputXML.suppressDTChambers = %(supChambers)s 133 process.MuonGeometryDBConverter.outputXML.suppressDTSuperLayers = %(supLayers)s 134 process.MuonGeometryDBConverter.outputXML.suppressDTLayers = %(supLayers)s 136 process.MuonGeometryDBConverter.outputXML.suppressCSCEndcaps = True 137 process.MuonGeometryDBConverter.outputXML.suppressCSCStations = True 138 process.MuonGeometryDBConverter.outputXML.suppressCSCRings = %(supRings)s 139 process.MuonGeometryDBConverter.outputXML.suppressCSCChambers = %(supChambers)s 140 process.MuonGeometryDBConverter.outputXML.suppressCSCLayers = %(supLayers)s 148 exit_code = os.system(
"cmsRun tmp_converter_cfg.py")
151 print(
"problem: cmsRun exited with code:", exit_code)
153 os.system(
"rm tmp_converter_cfg.py")
S & print(S &os, JobReport::InputFile const &f)