CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/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 """ % vars()
00027 
00028 if len(sys.argv) < 3:
00029   print "Too few arguments!\n\n"+usage
00030   sys.exit()
00031 
00032 parser=optparse.OptionParser(usage)
00033 
00034 parser.add_option("--noChambers",
00035   help="if present, no chambers info would be written into xml",
00036   action="store_true",
00037   default=False,
00038   dest="noChambers")
00039 
00040 parser.add_option("--noLayers",
00041   help="if present, no layers (and no DT superlayers) info would be written into xml",
00042   action="store_true",
00043   default=False,
00044   dest="noLayers")
00045 
00046 parser.add_option("-l", "--relativeTo",
00047   help="by default, xml conversion is done relative to ideal DDD description, if \"none\" is specified, absolute positions would be written into xml",
00048   type="string",
00049   default='ideal',
00050   dest="relativeTo")
00051 
00052 parser.add_option("--ringsOnly",
00053   help="special flag for xml dumping of CSC ring structure only, it automatically turns off all DTs and also CSC's chambers and layers",
00054   action="store_true",
00055   default=False,
00056   dest="ringsOnly")
00057 
00058 options, args = parser.parse_args(sys.argv[3:])
00059 
00060 supRings="True"
00061 if options.ringsOnly: supRings="False"
00062 supChambers="False"
00063 if options.noChambers or options.ringsOnly: supChambers="True"
00064 supLayers="False"
00065 if options.noLayers or options.ringsOnly: supLayers="True"
00066 
00067 relativeTo=options.relativeTo
00068 if options.ringsOnly: relativeTo="none"
00069 
00070 
00071 theInputFile = sys.argv[1]
00072 theOutputFile = sys.argv[2]
00073 
00074 ok = False
00075 
00076 if theInputFile[-4:]==".xml" and theOutputFile[-3:]==".db":
00077   ok = True
00078   file("tmp_converter_cfg.py","w").write("""# xml2sqlite conversion
00079 from Alignment.MuonAlignment.convertXMLtoSQLite_cfg import *
00080 process.MuonGeometryDBConverter.fileName = "%(theInputFile)s"
00081 process.PoolDBOutputService.connect = "sqlite_file:%(theOutputFile)s"
00082 
00083 """ % vars())
00084 
00085 if theInputFile[-3:]==".db" and theOutputFile[-4:]==".xml":
00086   ok = True
00087   file("tmp_converter_cfg.py","w").write("""# sqlite2xml conversion
00088 from Alignment.MuonAlignment.convertSQLitetoXML_cfg import *
00089 
00090 process.PoolDBESSource.connect = "sqlite_file:%(theInputFile)s"
00091 process.MuonGeometryDBConverter.outputXML.fileName = "%(theOutputFile)s"
00092 
00093 process.MuonGeometryDBConverter.outputXML.relativeto = "%(relativeTo)s"
00094 
00095 process.MuonGeometryDBConverter.outputXML.suppressDTBarrel = True
00096 process.MuonGeometryDBConverter.outputXML.suppressDTWheels = True
00097 process.MuonGeometryDBConverter.outputXML.suppressDTStations = True
00098 process.MuonGeometryDBConverter.outputXML.suppressDTChambers = %(supChambers)s
00099 process.MuonGeometryDBConverter.outputXML.suppressDTSuperLayers = %(supLayers)s
00100 process.MuonGeometryDBConverter.outputXML.suppressDTLayers = %(supLayers)s
00101 
00102 process.MuonGeometryDBConverter.outputXML.suppressCSCEndcaps = True
00103 process.MuonGeometryDBConverter.outputXML.suppressCSCStations = True
00104 process.MuonGeometryDBConverter.outputXML.suppressCSCRings = %(supRings)s
00105 process.MuonGeometryDBConverter.outputXML.suppressCSCChambers = %(supChambers)s
00106 process.MuonGeometryDBConverter.outputXML.suppressCSCLayers = %(supLayers)s
00107 
00108 """ % vars())
00109 
00110 if not ok:
00111   print usage
00112   sys.exit()
00113 
00114 exit_code = os.system("cmsRun tmp_converter_cfg.py")
00115 
00116 if exit_code>0:
00117   print "problem: cmsRun exited with code:", exit_code
00118 else: 
00119   os.system("rm tmp_converter_cfg.py")