Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-25 02:29:24

0001 #! /usr/bin/env python
0002 
0003 
0004 #
0005 # Main script to list, plot, draw, dump Ecal conditions
0006 #
0007 #
0008 import os,sys,getopt
0009 
0010 
0011 def usage():
0012     print()
0013     print("NAME ")
0014     print("   EcalCondDB - inpect EcalCondDB")
0015     print()
0016     print("SYNOPSIS")
0017     print("   EcalCondDB [options] [command] [command_options]")
0018     print()
0019     print("OPTIONS")
0020     print()
0021     print("Specify short options as '-o foo', long options as '--option=foo'")
0022     print()
0023     print("   -c, --connect= [connectstring]")
0024     print("      specify database, default frontier://FrontierProd/CMS_COND_31X_ECAL")
0025     print()
0026     print("   -P, --authpath=  [authenticationpath], default /afs/cern.ch/cms/DB/conddb ")
0027     print()
0028     print("COMMAND OPTIONS")
0029     print()
0030     print("   -t, --tag= [tag,file] specify tag or xml file (histo,compare)")
0031     print()
0032     print("   -s, --since= [runnumber] specify since")
0033     
0034     print("COMMANDS")
0035     
0036     print("   -l, --listtags  list all tags and exit")
0037     print()
0038     print("   -m, --listiovs  list iovs for a given tag")
0039     print("                   Example EcalCondDB.py -t tag") 
0040     print()
0041     print("   -d, --dump= [file] dump record to xml file")
0042     print("         Example EcalCondDB.py -d file.xml -t tag -s since")
0043     print()
0044     print("   -p, --plot= [file] plot record to file, extension specifies ",\
0045                     "format (.root,.png,.jpg,.gif,.svg)")
0046     print("         Example: EcalCondDB.py -p=plot.png -t tag -s since")
0047     print()
0048     
0049     print("   -q, --compare= [file]")
0050     print("         compare two tags and write histograms to file, extension",\
0051                     " specifies format.")               
0052     print("         Example:")
0053     print("           EcalCondDB -q=h.root -t tag1 -s since1 -t tag2 -s since2")
0054     print()
0055     print("   -g, --histo= [file] make histograms and write to file")
0056     print("         Example : ")
0057     print("           EcalCondDB -g=h.png -t tag1 -s since1 ")
0058     print()
0059     
0060 try:
0061     opts, args = getopt.getopt(sys.argv[1:],
0062                              "c:P:t:ld:p:q:g:ms:h",
0063                              ["connect=","authpath=","tag=","listtags",\
0064                               "dump=","plot=","compare=","histo=","listiovs",\
0065                               "since=","help"])
0066     
0067     if not len(opts):
0068         usage()
0069         sys.exit(0)
0070 
0071 except getopt.GetoptError as ex:
0072     print()
0073     print(ex," , use -h or --help for help")
0074     sys.exit(0)
0075 
0076 dbName =  "frontier://FrontierProd/CMS_COND_31X_ECAL"
0077 authpath= "/afs/cern.ch/cms/DB/conddb"
0078 
0079 tags=[]
0080 sinces=[]
0081 
0082 
0083 
0084 do_list=0
0085 do_liio=0
0086 do_dump=0
0087 do_plot=0
0088 do_comp=0
0089 do_hist=0
0090 
0091 outfilename=None
0092 
0093 #shortcut for infinity
0094 inf="4294967295"
0095 
0096 for opt,arg in opts:
0097 
0098     if opt in ("-c","--connect"):
0099        dbName=arg
0100     
0101     if opt in ("-P","--authpath"):
0102        authpath=arg 
0103 
0104     if opt in ("-h","--help"):
0105        usage()
0106        sys.exit(0)
0107 
0108     if opt in ("-t","--tag"):
0109        tags.append(arg)
0110        if arg.find(".xml")>0 :
0111            print("WARNING : plot from XML is not protected against changes")
0112            print("          in DetId or CondFormats")
0113            
0114     if opt in ("-l","--listtags"):
0115        do_list=1  
0116        
0117     if opt in ("-q","--compare"):
0118        do_comp=1
0119        outfilename=arg
0120 
0121     if opt in ("-d","--dump"):
0122        do_dump=1
0123        outfilename=arg
0124 
0125     if opt in ("-p","--plot"):
0126        do_plot=1 
0127        outfilename=arg
0128    
0129     if opt in ("-g","--histo"):
0130        do_hist=1
0131        outfilename=arg 
0132 
0133     if opt in ("-m","--listiovs"):
0134        do_liio=1
0135        
0136     if opt in ("-s","--since"):
0137        sinces.append(arg)
0138 
0139 
0140    
0141 #done parsing options, now steer
0142 
0143 
0144 import DLFCN
0145 sys.setdlopenflags(DLFCN.RTLD_GLOBAL+DLFCN.RTLD_LAZY)
0146 from pluginCondDBPyInterface import *
0147           
0148 a = FWIncantation()
0149 
0150 rdbms = RDBMS(authpath)
0151 db = rdbms.getReadOnlyDB(dbName)
0152 
0153 from . import EcalCondTools
0154 
0155 if do_list :
0156    EcalCondTools.listTags(db)
0157 
0158 if do_dump :
0159    if not len(tags):
0160       print("Must specify tag with -t")
0161       sys.exit(0)
0162    EcalCondTools.dumpXML(db,tags[0],sinces[0],outfilename)
0163 
0164 if do_plot:
0165    if not len(tags) or not len (sinces):
0166        print("Must specify tag with -t [tag] -s [since]")
0167        sys.exit(0)       
0168    EcalCondTools.plot(db,tags[0],sinces[0],outfilename) 
0169  
0170 if do_comp:
0171    if len(tags) != 2 :
0172        print("Must give exactly two tags to compare: -t tag1 -t tag2")
0173        sys.exit(0)
0174    if  tags[0].find('.xml')<0 and  len(sinces)!=2 :
0175        print("Must specify tag, since  to compare  with -t [tag1] \
0176               -s [since1]  -t [tag2] -s [since2]     ")
0177        sys.exit(0)
0178        
0179    EcalCondTools.compare(tags[0],db,sinces[0],
0180                          tags[1],db,sinces[1],outfilename)       
0181 
0182 if do_hist:
0183    if not len(tags):
0184        print("Must specify tag, since,  with -t [tag] \
0185               -s [runsince]   (since  not needed for xml)")
0186        sys.exit(0)
0187        
0188    if  tags[0].find('.xml')<0 and  not len(sinces) :
0189        print("Must specify tag, since, with -t [tag] \
0190               -s [runsince]   ")
0191        sys.exit(0)
0192        
0193    EcalCondTools.histo(db,tags[0],sinces[0],outfilename) 
0194 
0195 if do_liio:
0196     if not len(tags):
0197        print("Must specify tag  with -t [tag]")
0198        sys.exit(0)
0199     EcalCondTools.listIovs(db,tags[0])
0200      
0201