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