CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/Alignment/MuonAlignmentAlgorithms/scripts/convertSQLiteXML.py

Go to the documentation of this file.
00001 #! /usr/bin/env python
00002 
00003 import os, sys, optparse, math
00004 
00005 prog = sys.argv[0]
00006 
00007 usage = """%(prog)s INPUT_FILE OUTPUT_FILE [--noChambers] [--noLayers] [--ringsOnly] [--relativeTo ideal|none]
00008 
00009 performs either sqlite-->xml or xml-->sqlite conversion following the documentation at 
00010 https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideMuonGeometryConversion
00011 
00012 Arguments:
00013 
00014 INPUT_FILE      is either .db SQLite or .xml file that should be converted
00015 OUTPUT_FILE     is either .xml or .db output file, the result of conversion
00016 
00017 Options for sqlite-->xml conversion:
00018 
00019 --noChambers    if present, no chambers info would be written into xml
00020 --noLayers      if present, no layers (and no DT superlayers) info would be written into xml
00021 --relativeTo X  by default, xml conversion is done relative to ideal DDD description,
00022                 if "none" is specified, absolute positions would be written into xml
00023 --ringsOnly     special flag for xml dumping of CSC ring structure only, it automatically
00024                 turns off all DTs and also CSC's chambers and layers on output and coordinates
00025                 are relative "to none"
00026 --runNumber N   Use run #N to extract xml from necessary IOV
00027 """ % vars()
00028 
00029 if len(sys.argv) < 3:
00030   print "Too few arguments!\n\n"+usage
00031   sys.exit()
00032 
00033 parser=optparse.OptionParser(usage)
00034 
00035 parser.add_option("--noChambers",
00036   help="if present, no chambers info would be written into xml",
00037   action="store_true",
00038   default=False,
00039   dest="noChambers")
00040 
00041 parser.add_option("--noLayers",
00042   help="if present, no layers (and no DT superlayers) info would be written into xml",
00043   action="store_true",
00044   default=False,
00045   dest="noLayers")
00046 
00047 parser.add_option("-l", "--relativeTo",
00048   help="by default, xml conversion is done relative to ideal DDD description, if \"none\" is specified, absolute positions would be written into xml",
00049   type="string",
00050   default='ideal',
00051   dest="relativeTo")
00052 
00053 parser.add_option("--ringsOnly",
00054   help="special flag for xml dumping of CSC ring structure only, it automatically turns off all DTs and also CSC's chambers and layers",
00055   action="store_true",
00056   default=False,
00057   dest="ringsOnly")
00058 
00059 parser.add_option("-r", "--runNumber",
00060   help="Use run #N to extract xml from necessary IOV (default is 1)",
00061   type="int",
00062   default=1,
00063   dest="runNumber")
00064 
00065 parser.add_option("--gprcdconnect",
00066   help="connect string for GlobalPositionRcd (frontier://... or sqlite_file:...). The defailt is a trivial/inert GPR",
00067   type="string",
00068   default="sqlite_file:inertGlobalPositionRcd.db",
00069   dest="gprcdconnect")
00070 
00071 parser.add_option("--gprcd",
00072   help="name of GlobalPositionRcd tag",
00073   type="string",
00074   default="inertGlobalPositionRcd",
00075   dest="gprcd")
00076 
00077 
00078 options, args = parser.parse_args(sys.argv[3:])
00079 
00080 supRings="True"
00081 if options.ringsOnly: supRings="False"
00082 supChambers="False"
00083 if options.noChambers or options.ringsOnly: supChambers="True"
00084 supLayers="False"
00085 if options.noLayers or options.ringsOnly: supLayers="True"
00086 
00087 relativeTo=options.relativeTo
00088 if options.ringsOnly: relativeTo="none"
00089 
00090 runNumber = options.runNumber
00091 gprcdconnect = options.gprcdconnect
00092 gprcd = options.gprcd
00093 
00094 theInputFile = sys.argv[1]
00095 theOutputFile = sys.argv[2]
00096 
00097 ok = False
00098 
00099 if theInputFile[-4:]==".xml" and theOutputFile[-3:]==".db":
00100   ok = True
00101   file("tmp_converter_cfg.py","w").write("""# xml2sqlite conversion
00102 from Alignment.MuonAlignment.convertXMLtoSQLite_cfg import *
00103 process.MuonGeometryDBConverter.fileName = "%(theInputFile)s"
00104 process.PoolDBOutputService.connect = "sqlite_file:%(theOutputFile)s"
00105 process.inertGlobalPositionRcd.connect = "%(gprcdconnect)s"
00106 process.inertGlobalPositionRcd.toGet =  cms.VPSet(cms.PSet(record = cms.string('GlobalPositionRcd'), tag = cms.string('%(gprcd)s')))
00107 
00108 """ % vars())
00109 
00110 if theInputFile[-3:]==".db" and theOutputFile[-4:]==".xml":
00111   ok = True
00112   file("tmp_converter_cfg.py","w").write("""# sqlite2xml conversion
00113 from Alignment.MuonAlignment.convertSQLitetoXML_cfg import *
00114 
00115 process.source = cms.Source("EmptySource",
00116     numberEventsInRun = cms.untracked.uint32(1),
00117     firstRun = cms.untracked.uint32(%(runNumber)d)
00118 )
00119 
00120 process.inertGlobalPositionRcd.connect = "%(gprcdconnect)s"
00121 process.inertGlobalPositionRcd.toGet =  cms.VPSet(cms.PSet(record = cms.string('GlobalPositionRcd'), tag = cms.string('%(gprcd)s')))
00122 
00123 process.PoolDBESSource.connect = "sqlite_file:%(theInputFile)s"
00124 process.MuonGeometryDBConverter.outputXML.fileName = "%(theOutputFile)s"
00125 
00126 process.MuonGeometryDBConverter.outputXML.relativeto = "%(relativeTo)s"
00127 
00128 process.MuonGeometryDBConverter.outputXML.suppressDTBarrel = True
00129 process.MuonGeometryDBConverter.outputXML.suppressDTWheels = True
00130 process.MuonGeometryDBConverter.outputXML.suppressDTStations = True
00131 process.MuonGeometryDBConverter.outputXML.suppressDTChambers = %(supChambers)s
00132 process.MuonGeometryDBConverter.outputXML.suppressDTSuperLayers = %(supLayers)s
00133 process.MuonGeometryDBConverter.outputXML.suppressDTLayers = %(supLayers)s
00134 
00135 process.MuonGeometryDBConverter.outputXML.suppressCSCEndcaps = True
00136 process.MuonGeometryDBConverter.outputXML.suppressCSCStations = True
00137 process.MuonGeometryDBConverter.outputXML.suppressCSCRings = %(supRings)s
00138 process.MuonGeometryDBConverter.outputXML.suppressCSCChambers = %(supChambers)s
00139 process.MuonGeometryDBConverter.outputXML.suppressCSCLayers = %(supLayers)s
00140 
00141 """ % vars())
00142 
00143 if not ok:
00144   print usage
00145   sys.exit()
00146 
00147 exit_code = os.system("cmsRun tmp_converter_cfg.py")
00148 
00149 if exit_code>0:
00150   print "problem: cmsRun exited with code:", exit_code
00151 else: 
00152   os.system("rm tmp_converter_cfg.py")