Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
#! /usr/bin/env python


#
# Main script to list, plot, draw, dump Ecal conditions
#
#
import os,sys,getopt


def usage():
    print()
    print("NAME ")
    print("   EcalCondDB - inpect EcalCondDB")
    print()
    print("SYNOPSIS")
    print("   EcalCondDB [options] [command] [command_options]")
    print()
    print("OPTIONS")
    print()
    print("Specify short options as '-o foo', long options as '--option=foo'")
    print()
    print("   -c, --connect= [connectstring]")
    print("      specify database, default frontier://FrontierProd/CMS_COND_31X_ECAL")
    print()
    print("   -P, --authpath=  [authenticationpath], default /afs/cern.ch/cms/DB/conddb ")
    print()
    print("COMMAND OPTIONS")
    print()
    print("   -t, --tag= [tag,file] specify tag or xml file (histo,compare)")
    print()
    print("   -s, --since= [runnumber] specify since")
    
    print("COMMANDS")
    
    print("   -l, --listtags  list all tags and exit")
    print()
    print("   -m, --listiovs  list iovs for a given tag")
    print("                   Example EcalCondDB.py -t tag") 
    print()
    print("   -d, --dump= [file] dump record to xml file")
    print("         Example EcalCondDB.py -d file.xml -t tag -s since")
    print()
    print("   -p, --plot= [file] plot record to file, extension specifies ",\
                    "format (.root,.png,.jpg,.gif,.svg)")
    print("         Example: EcalCondDB.py -p=plot.png -t tag -s since")
    print()
    
    print("   -q, --compare= [file]")
    print("         compare two tags and write histograms to file, extension",\
                    " specifies format.")               
    print("         Example:")
    print("           EcalCondDB -q=h.root -t tag1 -s since1 -t tag2 -s since2")
    print()
    print("   -g, --histo= [file] make histograms and write to file")
    print("         Example : ")
    print("           EcalCondDB -g=h.png -t tag1 -s since1 ")
    print()
    
try:
    opts, args = getopt.getopt(sys.argv[1:],
                             "c:P:t:ld:p:q:g:ms:h",
                             ["connect=","authpath=","tag=","listtags",\
                              "dump=","plot=","compare=","histo=","listiovs",\
                              "since=","help"])
    
    if not len(opts):
        usage()
        sys.exit(0)

except getopt.GetoptError as ex:
    print()
    print(ex," , use -h or --help for help")
    sys.exit(0)

dbName =  "frontier://FrontierProd/CMS_COND_31X_ECAL"
authpath= "/afs/cern.ch/cms/DB/conddb"

tags=[]
sinces=[]



do_list=0
do_liio=0
do_dump=0
do_plot=0
do_comp=0
do_hist=0

outfilename=None

#shortcut for infinity
inf="4294967295"

for opt,arg in opts:

    if opt in ("-c","--connect"):
       dbName=arg
    
    if opt in ("-P","--authpath"):
       authpath=arg 

    if opt in ("-h","--help"):
       usage()
       sys.exit(0)

    if opt in ("-t","--tag"):
       tags.append(arg)
       if arg.find(".xml")>0 :
           print("WARNING : plot from XML is not protected against changes")
           print("          in DetId or CondFormats")
           
    if opt in ("-l","--listtags"):
       do_list=1  
       
    if opt in ("-q","--compare"):
       do_comp=1
       outfilename=arg

    if opt in ("-d","--dump"):
       do_dump=1
       outfilename=arg

    if opt in ("-p","--plot"):
       do_plot=1 
       outfilename=arg
   
    if opt in ("-g","--histo"):
       do_hist=1
       outfilename=arg 

    if opt in ("-m","--listiovs"):
       do_liio=1
       
    if opt in ("-s","--since"):
       sinces.append(arg)


   
#done parsing options, now steer


import DLFCN
sys.setdlopenflags(DLFCN.RTLD_GLOBAL+DLFCN.RTLD_LAZY)
from pluginCondDBPyInterface import *
          
a = FWIncantation()

rdbms = RDBMS(authpath)
db = rdbms.getReadOnlyDB(dbName)

from . import EcalCondTools

if do_list :
   EcalCondTools.listTags(db)

if do_dump :
   if not len(tags):
      print("Must specify tag with -t")
      sys.exit(0)
   EcalCondTools.dumpXML(db,tags[0],sinces[0],outfilename)

if do_plot:
   if not len(tags) or not len (sinces):
       print("Must specify tag with -t [tag] -s [since]")
       sys.exit(0)       
   EcalCondTools.plot(db,tags[0],sinces[0],outfilename) 
 
if do_comp:
   if len(tags) != 2 :
       print("Must give exactly two tags to compare: -t tag1 -t tag2")
       sys.exit(0)
   if  tags[0].find('.xml')<0 and  len(sinces)!=2 :
       print("Must specify tag, since  to compare  with -t [tag1] \
              -s [since1]  -t [tag2] -s [since2]     ")
       sys.exit(0)
       
   EcalCondTools.compare(tags[0],db,sinces[0],
                         tags[1],db,sinces[1],outfilename)       

if do_hist:
   if not len(tags):
       print("Must specify tag, since,  with -t [tag] \
              -s [runsince]   (since  not needed for xml)")
       sys.exit(0)
       
   if  tags[0].find('.xml')<0 and  not len(sinces) :
       print("Must specify tag, since, with -t [tag] \
              -s [runsince]   ")
       sys.exit(0)
       
   EcalCondTools.histo(db,tags[0],sinces[0],outfilename) 

if do_liio:
    if not len(tags):
       print("Must specify tag  with -t [tag]")
       sys.exit(0)
    EcalCondTools.listIovs(db,tags[0])