CMS 3D CMS Logo

EcalCondDB.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 
3 
4 #
5 # Main script to list, plot, draw, dump Ecal conditions
6 #
7 #
8 import os,sys,getopt
9 
10 
11 def usage():
12  print
13  print "NAME "
14  print " EcalCondDB - inpect EcalCondDB"
15  print
16  print "SYNOPSIS"
17  print " EcalCondDB [options] [command] [command_options]"
18  print
19  print "OPTIONS"
20  print
21  print "Specify short options as '-o foo', long options as '--option=foo'"
22  print
23  print " -c, --connect= [connectstring]"
24  print " specify database, default frontier://FrontierProd/CMS_COND_31X_ECAL"
25  print
26  print " -P, --authpath= [authenticationpath], default /afs/cern.ch/cms/DB/conddb "
27  print
28  print "COMMAND OPTIONS"
29  print
30  print " -t, --tag= [tag,file] specify tag or xml file (histo,compare)"
31  print
32  print " -s, --since= [runnumber] specify since"
33 
34  print "COMMANDS"
35 
36  print " -l, --listtags list all tags and exit"
37  print
38  print " -m, --listiovs list iovs for a given tag"
39  print " Example EcalCondDB.py -t tag"
40  print
41  print " -d, --dump= [file] dump record to xml file"
42  print " Example EcalCondDB.py -d file.xml -t tag -s since"
43  print
44  print " -p, --plot= [file] plot record to file, extension specifies ",\
45  "format (.root,.png,.jpg,.gif,.svg)"
46  print " Example: EcalCondDB.py -p=plot.png -t tag -s since"
47  print
48 
49  print " -q, --compare= [file]"
50  print " compare two tags and write histograms to file, extension",\
51  " specifies format."
52  print " Example:"
53  print " EcalCondDB -q=h.root -t tag1 -s since1 -t tag2 -s since2"
54  print
55  print " -g, --histo= [file] make histograms and write to file"
56  print " Example : "
57  print " EcalCondDB -g=h.png -t tag1 -s since1 "
58  print
59 
60 try:
61  opts, args = getopt.getopt(sys.argv[1:],
62  "c:P:t:ld:p:q:g:ms:h",
63  ["connect=","authpath=","tag=","listtags",\
64  "dump=","plot=","compare=","histo=","listiovs",\
65  "since=","help"])
66 
67  if not len(opts):
68  usage()
69  sys.exit(0)
70 
71 except getopt.GetoptError as ex:
72  print
73  print ex," , use -h or --help for help"
74  sys.exit(0)
75 
76 dbName = "frontier://FrontierProd/CMS_COND_31X_ECAL"
77 authpath= "/afs/cern.ch/cms/DB/conddb"
78 
79 tags=[]
80 sinces=[]
81 
82 
83 
84 do_list=0
85 do_liio=0
86 do_dump=0
87 do_plot=0
88 do_comp=0
89 do_hist=0
90 
91 outfilename=None
92 
93 #shortcut for infinity
94 inf="4294967295"
95 
96 for opt,arg in opts:
97 
98  if opt in ("-c","--connect"):
99  dbName=arg
100 
101  if opt in ("-P","--authpath"):
102  authpath=arg
103 
104  if opt in ("-h","--help"):
105  usage()
106  sys.exit(0)
107 
108  if opt in ("-t","--tag"):
109  tags.append(arg)
110  if arg.find(".xml")>0 :
111  print "WARNING : plot from XML is not protected against changes"
112  print " in DetId or CondFormats"
113 
114  if opt in ("-l","--listtags"):
115  do_list=1
116 
117  if opt in ("-q","--compare"):
118  do_comp=1
119  outfilename=arg
120 
121  if opt in ("-d","--dump"):
122  do_dump=1
123  outfilename=arg
124 
125  if opt in ("-p","--plot"):
126  do_plot=1
127  outfilename=arg
128 
129  if opt in ("-g","--histo"):
130  do_hist=1
131  outfilename=arg
132 
133  if opt in ("-m","--listiovs"):
134  do_liio=1
135 
136  if opt in ("-s","--since"):
137  sinces.append(arg)
138 
139 
140 
141 #done parsing options, now steer
142 
143 
144 import DLFCN
145 sys.setdlopenflags(DLFCN.RTLD_GLOBAL+DLFCN.RTLD_LAZY)
146 from pluginCondDBPyInterface import *
147 
148 a = FWIncantation()
149 
150 rdbms = RDBMS(authpath)
151 db = rdbms.getReadOnlyDB(dbName)
152 
153 import EcalCondTools
154 
155 if do_list :
157 
158 if do_dump :
159  if not len(tags):
160  print "Must specify tag with -t"
161  sys.exit(0)
162  EcalCondTools.dumpXML(db,tags[0],sinces[0],outfilename)
163 
164 if do_plot:
165  if not len(tags) or not len (sinces):
166  print "Must specify tag with -t [tag] -s [since]"
167  sys.exit(0)
168  EcalCondTools.plot(db,tags[0],sinces[0],outfilename)
169 
170 if do_comp:
171  if len(tags) != 2 :
172  print "Must give exactly two tags to compare: -t tag1 -t tag2"
173  sys.exit(0)
174  if tags[0].find('.xml')<0 and len(sinces)!=2 :
175  print "Must specify tag, since to compare with -t [tag1] \
176  -s [since1] -t [tag2] -s [since2] "
177  sys.exit(0)
178 
179  EcalCondTools.compare(tags[0],db,sinces[0],
180  tags[1],db,sinces[1],outfilename)
181 
182 if do_hist:
183  if not len(tags):
184  print "Must specify tag, since, with -t [tag] \
185  -s [runsince] (since not needed for xml)"
186  sys.exit(0)
187 
188  if tags[0].find('.xml')<0 and not len(sinces) :
189  print "Must specify tag, since, with -t [tag] \
190  -s [runsince] "
191  sys.exit(0)
192 
193  EcalCondTools.histo(db,tags[0],sinces[0],outfilename)
194 
195 if do_liio:
196  if not len(tags):
197  print "Must specify tag with -t [tag]"
198  sys.exit(0)
199  EcalCondTools.listIovs(db,tags[0])
200 
201 
def dumpXML(db, tag, since, filename='dump.xml')
def usage()
Definition: EcalCondDB.py:11
def listIovs(db, tag)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
def histo(db, tag, since, filename='histo.root')
def compare(tag1, db1, since1, tag2, db2, since2, filename='compare.root')
def listTags(db)
def plot(db, tag, since, filename='plot.root')