test
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 --runNumber N Use run #N to extract xml from necessary IOV
27 """ % vars()
28 
29 if len(sys.argv) < 3:
30  print "Too few arguments!\n\n"+usage
31  sys.exit()
32 
33 parser=optparse.OptionParser(usage)
34 
35 parser.add_option("--noChambers",
36  help="if present, no chambers info would be written into xml",
37  action="store_true",
38  default=False,
39  dest="noChambers")
40 
41 parser.add_option("--noLayers",
42  help="if present, no layers (and no DT superlayers) info would be written into xml",
43  action="store_true",
44  default=False,
45  dest="noLayers")
46 
47 parser.add_option("-l", "--relativeTo",
48  help="by default, xml conversion is done relative to ideal DDD description, if \"none\" is specified, absolute positions would be written into xml",
49  type="string",
50  default='ideal',
51  dest="relativeTo")
52 
53 parser.add_option("--ringsOnly",
54  help="special flag for xml dumping of CSC ring structure only, it automatically turns off all DTs and also CSC's chambers and layers",
55  action="store_true",
56  default=False,
57  dest="ringsOnly")
58 
59 parser.add_option("-r", "--runNumber",
60  help="Use run #N to extract xml from necessary IOV (default is 1)",
61  type="int",
62  default=1,
63  dest="runNumber")
64 
65 parser.add_option("--gprcdconnect",
66  help="connect string for GlobalPositionRcd (frontier://... or sqlite_file:...). The defailt is a trivial/inert GPR",
67  type="string",
68  default="sqlite_file:inertGlobalPositionRcd.db",
69  dest="gprcdconnect")
70 
71 parser.add_option("--gprcd",
72  help="name of GlobalPositionRcd tag",
73  type="string",
74  default="inertGlobalPositionRcd",
75  dest="gprcd")
76 
77 
78 options, args = parser.parse_args(sys.argv[3:])
79 
80 supRings="True"
81 if options.ringsOnly: supRings="False"
82 supChambers="False"
83 if options.noChambers or options.ringsOnly: supChambers="True"
84 supLayers="False"
85 if options.noLayers or options.ringsOnly: supLayers="True"
86 
87 relativeTo=options.relativeTo
88 if options.ringsOnly: relativeTo="none"
89 
90 runNumber = options.runNumber
91 gprcdconnect = options.gprcdconnect
92 gprcd = options.gprcd
93 
94 theInputFile = sys.argv[1]
95 theOutputFile = sys.argv[2]
96 
97 ok = False
98 
99 if theInputFile[-4:]==".xml" and theOutputFile[-3:]==".db":
100  ok = True
101  file("tmp_converter_cfg.py","w").write("""# xml2sqlite conversion
102 from Alignment.MuonAlignment.convertXMLtoSQLite_cfg import *
103 process.MuonGeometryDBConverter.fileName = "%(theInputFile)s"
104 process.PoolDBOutputService.connect = "sqlite_file:%(theOutputFile)s"
105 process.inertGlobalPositionRcd.connect = "%(gprcdconnect)s"
106 process.inertGlobalPositionRcd.toGet = cms.VPSet(cms.PSet(record = cms.string('GlobalPositionRcd'), tag = cms.string('%(gprcd)s')))
107 
108 """ % vars())
109 
110 if theInputFile[-3:]==".db" and theOutputFile[-4:]==".xml":
111  ok = True
112  file("tmp_converter_cfg.py","w").write("""# sqlite2xml conversion
113 from Alignment.MuonAlignment.convertSQLitetoXML_cfg import *
114 
115 process.source = cms.Source("EmptySource",
116  numberEventsInRun = cms.untracked.uint32(1),
117  firstRun = cms.untracked.uint32(%(runNumber)d)
118 )
119 
120 process.inertGlobalPositionRcd.connect = "%(gprcdconnect)s"
121 process.inertGlobalPositionRcd.toGet = cms.VPSet(cms.PSet(record = cms.string('GlobalPositionRcd'), tag = cms.string('%(gprcd)s')))
122 
123 process.PoolDBESSource.connect = "sqlite_file:%(theInputFile)s"
124 process.MuonGeometryDBConverter.outputXML.fileName = "%(theOutputFile)s"
125 
126 process.MuonGeometryDBConverter.outputXML.relativeto = "%(relativeTo)s"
127 
128 process.MuonGeometryDBConverter.outputXML.suppressDTBarrel = True
129 process.MuonGeometryDBConverter.outputXML.suppressDTWheels = True
130 process.MuonGeometryDBConverter.outputXML.suppressDTStations = True
131 process.MuonGeometryDBConverter.outputXML.suppressDTChambers = %(supChambers)s
132 process.MuonGeometryDBConverter.outputXML.suppressDTSuperLayers = %(supLayers)s
133 process.MuonGeometryDBConverter.outputXML.suppressDTLayers = %(supLayers)s
134 
135 process.MuonGeometryDBConverter.outputXML.suppressCSCEndcaps = True
136 process.MuonGeometryDBConverter.outputXML.suppressCSCStations = True
137 process.MuonGeometryDBConverter.outputXML.suppressCSCRings = %(supRings)s
138 process.MuonGeometryDBConverter.outputXML.suppressCSCChambers = %(supChambers)s
139 process.MuonGeometryDBConverter.outputXML.suppressCSCLayers = %(supLayers)s
140 
141 """ % vars())
142 
143 if not ok:
144  print usage
145  sys.exit()
146 
147 exit_code = os.system("cmsRun tmp_converter_cfg.py")
148 
149 if exit_code>0:
150  print "problem: cmsRun exited with code:", exit_code
151 else:
152  os.system("rm tmp_converter_cfg.py")