CMS 3D CMS Logo

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