CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/CondTools/Ecal/python/EcalCondDB.py

Go to the documentation of this file.
00001 #! /usr/bin/env python
00002 
00003 
00004 #
00005 # Main script to list, plot, draw, dump Ecal conditions
00006 #
00007 #
00008 import os,sys,getopt
00009 
00010 
00011 def usage():
00012     print
00013     print "NAME "
00014     print "   EcalCondDB - inpect EcalCondDB"
00015     print
00016     print "SYNOPSIS"
00017     print "   EcalCondDB [options] [command] [command_options]"
00018     print
00019     print "OPTIONS"
00020     print
00021     print "Specify short options as '-o foo', long options as '--option=foo'"
00022     print
00023     print "   -c, --connect= [connectstring]"
00024     print "      specify database, default oracle://cms_orcoff_prod/CMS_COND_31X_ECAL"
00025     print
00026     print "   -P, --authpath=  [authenticationpath], default /afs/cern.ch/cms/DB/conddb "
00027     print
00028     print "COMMAND OPTIONS"
00029     print
00030     print "   -t, --tag= [tag,file] specify tag or xml file (histo,compare)"
00031     print
00032     print "   -s, --since= [runnumber] specify since"
00033     
00034     print "COMMANDS"
00035     
00036     print "   -l, --listtags  list all tags and exit"
00037     print
00038     print "   -m, --listiovs  list iovs for a given tag"
00039     print "                   Example EcalCondDB.py -t tag" 
00040     print
00041     print "   -d, --dump= [file] dump record to xml file"
00042     print "         Example EcalCondDB.py -d=file.xml -t tag -s since"
00043     print
00044     print "   -p, --plot= [file] plot record to file, extension specifies ",\
00045                     "format (.root,.png,.jpg,.gif,.svg)"
00046     print "         Example: EcalCondDB.py -p=plot.png -t tag -s since"
00047     print
00048     
00049     print "   -q, --compare= [file]"
00050     print "         compare two tags and write histograms to file, extension",\
00051                     " specifies format."               
00052     print "         Example:"
00053     print "           EcalCondDB -q=h.root -t tag1 -s since1 -t tag2 -s since2"
00054     print
00055     print "   -g, --histo= [file] make histograms and write to file"
00056     print "         Example : "
00057     print "           EcalCondDB -g=h.png -t tag1 -s since1 "
00058     print
00059     
00060 try:
00061     opts, args = getopt.getopt(sys.argv[1:],
00062                              "c:P:t:ld:p:q:g:ms:h",
00063                              ["connect=","authpath=","tag=","listtags",\
00064                               "dump=","plot=","compare=","histo=","listiovs",\
00065                               "since=","help"])
00066     
00067     if not len(opts):
00068         usage()
00069         sys.exit(0)
00070 
00071 except getopt.GetoptError,ex:
00072     print
00073     print ex," , use -h or --help for help"
00074     sys.exit(0)
00075 
00076 dbName =  "oracle://cms_orcoff_prod/CMS_COND_31X_ECAL"
00077 authpath= "/afs/cern.ch/cms/DB/conddb"
00078 
00079 tags=[]
00080 sinces=[]
00081 
00082 
00083 
00084 do_list=0
00085 do_liio=0
00086 do_dump=0
00087 do_plot=0
00088 do_comp=0
00089 do_hist=0
00090 
00091 outfilename=None
00092 
00093 #shortcut for infinity
00094 inf="4294967295"
00095 
00096 for opt,arg in opts:
00097 
00098     if opt in ("-c","--connect"):
00099        dbName=arg
00100     
00101     if opt in ("-P","--authpath"):
00102        authpath=arg 
00103 
00104     if opt in ("-h","--help"):
00105        usage()
00106        sys.exit(0)
00107 
00108     if opt in ("-t","--tag"):
00109        tags.append(arg)
00110        if arg.find(".xml")>0 :
00111            print "WARNING : plot from XML is not protected against changes"
00112            print "          in DetId or CondFormats"
00113            
00114     if opt in ("-l","--listtags"):
00115        do_list=1  
00116        
00117     if opt in ("-q","--compare"):
00118        do_comp=1
00119        outfilename=arg
00120 
00121     if opt in ("-d","--dump"):
00122        do_dump=1
00123        outfilename=arg
00124 
00125     if opt in ("-p","--plot"):
00126        do_plot=1 
00127        outfilename=arg
00128    
00129     if opt in ("-g","--histo"):
00130        do_hist=1
00131        outfilename=arg 
00132 
00133     if opt in ("-m","--listiovs"):
00134        do_liio=1
00135        
00136     if opt in ("-s","--since"):
00137        sinces.append(arg)
00138 
00139 
00140    
00141 #done parsing options, now steer
00142 
00143 
00144 import DLFCN
00145 sys.setdlopenflags(DLFCN.RTLD_GLOBAL+DLFCN.RTLD_LAZY)
00146 from pluginCondDBPyInterface import *
00147           
00148 a = FWIncantation()
00149 
00150 rdbms = RDBMS(authpath)
00151 db = rdbms.getDB(dbName)
00152 
00153 import EcalCondTools
00154 
00155 if do_list :
00156    EcalCondTools.listTags(db)
00157 
00158 if do_dump :
00159    if not len(tags):
00160       print "Must specify tag with -t"
00161       sys.exit(0)
00162    EcalCondTools.dumpXML(db,tags[0],sinces[0],outfilename)
00163 
00164 if do_plot:
00165    if not len(tags) or not len (sinces):
00166        print "Must specify tag with -t [tag] -s [since]"
00167        sys.exit(0)       
00168    EcalCondTools.plot(db,tags[0],sinces[0],outfilename) 
00169  
00170 if do_comp:
00171    if len(tags) != 2 :
00172        print "Must give exactly two tags to compare: -t tag1 -t tag2"
00173        sys.exit(0)
00174    if  tags[0].find('.xml')<0 and  len(sinces)!=2 :
00175        print "Must specify tag, since  to compare  with -t [tag1] \
00176               -s [since1]  -t [tag2] -s [since2]     "
00177        sys.exit(0)
00178        
00179    EcalCondTools.compare(tags[0],db,sinces[0],
00180                          tags[1],db,sinces[1],outfilename)       
00181 
00182 if do_hist:
00183    if not len(tags):
00184        print "Must specify tag, since,  with -t [tag] \
00185               -s [runsince]   (since  not needed for xml)"
00186        sys.exit(0)
00187        
00188    if  tags[0].find('.xml')<0 and  not len(sinces) :
00189        print "Must specify tag, since, with -t [tag] \
00190               -s [runsince]   "
00191        sys.exit(0)
00192        
00193    EcalCondTools.histo(db,tags[0],sinces[0],outfilename) 
00194 
00195 if do_liio:
00196     if not len(tags):
00197        print "Must specify tag  with -t [tag]"
00198        sys.exit(0)
00199     EcalCondTools.listIovs(db,tags[0])
00200      
00201