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