Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-03-03 02:23:12

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