CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
convertSQLiteXML.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 
3 import os, sys, optparse, math
4 
5 prog = sys.argv[0]
6 
7 usage = """%(prog)s INPUT_FILE OUTPUT_FILE [--noChambers] [--noLayers] [--ringsOnly] [--relativeTo ideal|none]
8 
9 performs either sqlite-->xml or xml-->sqlite conversion following the documentation at
10 https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideMuonGeometryConversion
11 
12 Arguments:
13 
14 INPUT_FILE is either .db SQLite or .xml file that should be converted
15 OUTPUT_FILE is either .xml or .db output file, the result of conversion
16 
17 Options for sqlite-->xml conversion:
18 
19 --noChambers if present, no chambers info would be written into xml
20 --noLayers if present, no layers (and no DT superlayers) info would be written into xml
21 --relativeTo X by default, xml conversion is done relative to ideal DDD description,
22  if "none" is specified, absolute positions would be written into xml
23 --ringsOnly special flag for xml dumping of CSC ring structure only, it automatically
24  turns off all DTs and also CSC's chambers and layers on output and coordinates
25  are relative "to none"
26 """ % vars()
27 
28 if len(sys.argv) < 3:
29  print "Too few arguments!\n\n"+usage
30  sys.exit()
31 
32 parser=optparse.OptionParser(usage)
33 
34 parser.add_option("--noChambers",
35  help="if present, no chambers info would be written into xml",
36  action="store_true",
37  default=False,
38  dest="noChambers")
39 
40 parser.add_option("--noLayers",
41  help="if present, no layers (and no DT superlayers) info would be written into xml",
42  action="store_true",
43  default=False,
44  dest="noLayers")
45 
46 parser.add_option("-l", "--relativeTo",
47  help="by default, xml conversion is done relative to ideal DDD description, if \"none\" is specified, absolute positions would be written into xml",
48  type="string",
49  default='ideal',
50  dest="relativeTo")
51 
52 parser.add_option("--ringsOnly",
53  help="special flag for xml dumping of CSC ring structure only, it automatically turns off all DTs and also CSC's chambers and layers",
54  action="store_true",
55  default=False,
56  dest="ringsOnly")
57 
58 options, args = parser.parse_args(sys.argv[3:])
59 
60 supRings="True"
61 if options.ringsOnly: supRings="False"
62 supChambers="False"
63 if options.noChambers or options.ringsOnly: supChambers="True"
64 supLayers="False"
65 if options.noLayers or options.ringsOnly: supLayers="True"
66 
67 relativeTo=options.relativeTo
68 if options.ringsOnly: relativeTo="none"
69 
70 
71 theInputFile = sys.argv[1]
72 theOutputFile = sys.argv[2]
73 
74 ok = False
75 
76 if theInputFile[-4:]==".xml" and theOutputFile[-3:]==".db":
77  ok = True
78  file("tmp_converter_cfg.py","w").write("""# xml2sqlite conversion
79 from Alignment.MuonAlignment.convertXMLtoSQLite_cfg import *
80 process.MuonGeometryDBConverter.fileName = "%(theInputFile)s"
81 process.PoolDBOutputService.connect = "sqlite_file:%(theOutputFile)s"
82 
83 """ % vars())
84 
85 if theInputFile[-3:]==".db" and theOutputFile[-4:]==".xml":
86  ok = True
87  file("tmp_converter_cfg.py","w").write("""# sqlite2xml conversion
88 from Alignment.MuonAlignment.convertSQLitetoXML_cfg import *
89 
90 process.PoolDBESSource.connect = "sqlite_file:%(theInputFile)s"
91 process.MuonGeometryDBConverter.outputXML.fileName = "%(theOutputFile)s"
92 
93 process.MuonGeometryDBConverter.outputXML.relativeto = "%(relativeTo)s"
94 
95 process.MuonGeometryDBConverter.outputXML.suppressDTBarrel = True
96 process.MuonGeometryDBConverter.outputXML.suppressDTWheels = True
97 process.MuonGeometryDBConverter.outputXML.suppressDTStations = True
98 process.MuonGeometryDBConverter.outputXML.suppressDTChambers = %(supChambers)s
99 process.MuonGeometryDBConverter.outputXML.suppressDTSuperLayers = %(supLayers)s
100 process.MuonGeometryDBConverter.outputXML.suppressDTLayers = %(supLayers)s
101 
102 process.MuonGeometryDBConverter.outputXML.suppressCSCEndcaps = True
103 process.MuonGeometryDBConverter.outputXML.suppressCSCStations = True
104 process.MuonGeometryDBConverter.outputXML.suppressCSCRings = %(supRings)s
105 process.MuonGeometryDBConverter.outputXML.suppressCSCChambers = %(supChambers)s
106 process.MuonGeometryDBConverter.outputXML.suppressCSCLayers = %(supLayers)s
107 
108 """ % vars())
109 
110 if not ok:
111  print usage
112  sys.exit()
113 
114 exit_code = os.system("cmsRun tmp_converter_cfg.py")
115 
116 if exit_code>0:
117  print "problem: cmsRun exited with code:", exit_code
118 else:
119  os.system("rm tmp_converter_cfg.py")