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 import os,sys, DLFCN,getopt
0004 sys.setdlopenflags(DLFCN.RTLD_GLOBAL+DLFCN.RTLD_LAZY)
0005 
0006 from CondCore.Utilities import iovInspector as inspect
0007 from pluginCondDBPyInterface import *
0008 import pluginCondDBPyInterface as CondDB
0009 from ROOT import TCanvas,TH1F, TH2F,TFile
0010 
0011 
0012 def unhashEBDetId(i):
0013        pseudo_eta= i/360 - 85;
0014        ieta=0
0015        if pseudo_eta <0 :
0016           ieta = pseudo_eta
0017        else :
0018           ieta = pseudo_eta +1
0019           
0020        iphi = i%360 +1
0021        return ieta,iphi
0022 
0023 def setWhat(w,ret) :
0024        for key in ret.keys():
0025               _val = ret[key]
0026               if (isinstance(_val, type([]))) :
0027                      _vi = CondDB.VInt()
0028                      for i in _val :
0029                             _vi.append(i)
0030                      exec ('w.set_'+key+'(_vi)')
0031               else :
0032                      exec ('w.set_'+key+'(w.'+key+'().'+ret[key]+')')
0033        return w 
0034 
0035 
0036 
0037 def usage():
0038     print("inspectEcal -c [connectstring] -P [authpath] -t [tag] -f [outfile] -l -h")
0039     print("   dump records in xml") 
0040     print("               -l: list tags and exit")
0041     print("               -f [file] : dump to file")
0042     print("               -p plot distribution   ")
0043     print("               -q compare [tag]       ")
0044     print("               -r reference [tag]     ")
0045     print("               -m draw map")
0046     print("               -h : help")
0047       
0048 try:
0049     opts, args = getopt.getopt(sys.argv[1:], "c:P:t:f:lhpq:r:m", ["connect=","authpath=","tag","file","listtags","help","plot","compare","reference","map"])
0050     
0051     if not len(opts):
0052         usage()
0053         sys.exit(0)
0054 
0055 except getopt.GetoptError:
0056     #* print help information and exit:*
0057     usage()
0058     sys.exit(2)
0059 
0060 
0061 dbName =  "oracle://cms_orcoff_prod/CMS_COND_31X_ECAL"
0062 authpath= "/afs/cern.ch/cms/DB/conddb"
0063 tag='EcalIntercalibConstants_mc'
0064 do_list_tags= 0
0065 dump_to_file =0
0066 outfile=""
0067 do_plot=0
0068 do_compare=0
0069 compare_tag=""
0070 reference_tag=""
0071 drawmap=0
0072 
0073 for opt,arg in opts:
0074 
0075     if opt in ("-c","--connect"):
0076         try: 
0077             dbname=arg
0078         except Exception as er :
0079             print(er)
0080     
0081     if opt in ("-P","--authpath"):
0082         try: 
0083             rdbms=RDBMS(arg)
0084         except Exception as er :
0085             print(er)
0086     if opt in ("-t","--tag"):
0087         tag=arg
0088 
0089     if opt in ("-l","--listtags"):
0090         do_list_tags= 1
0091         
0092     if opt in ("-f","--file"):
0093         dump_to_file= 1
0094         outfile=arg    
0095 
0096     if opt in ("-p","--plot"):
0097         do_plot= 1       
0098 
0099     if opt in ("-q","--compare"):
0100         do_compare=1
0101         compare_tag=arg
0102 
0103     if opt in ("-r","--reference"):
0104         reference_tag=arg
0105 
0106     if opt in ("-m","--map"):
0107         drawmap=1
0108         
0109     if opt in ("-h","--help"):
0110         usage()
0111         sys.exit(0)    
0112 
0113 a = FWIncantation()
0114 
0115 rdbms = RDBMS(authpath)
0116 db = rdbms.getDB(dbName)
0117 
0118 if do_list_tags :
0119     tags=db.allTags()
0120     for tag in tags.split():
0121         print(tag)
0122     sys.exit(0)    
0123 
0124 
0125 try :
0126     iov = inspect.Iov(db,tag)
0127     print("===iov list ===")
0128     iovlist=iov.list()
0129     print(iovlist)
0130     print("===iov summaries ===")
0131     print(iov.summaries())
0132     print("===payload dump ===")
0133     for p in iovlist:
0134         payload=inspect.PayLoad(db,p[0])
0135         #print payload.summary()
0136         if dump_to_file:
0137             print("Dumping to file:", outfile) 
0138             out = open(outfile,"w")
0139             print(payload, file=out)
0140         else:
0141              #print payload
0142              if  drawmap:
0143                 payload.plot("plot","",[],[])
0144 
0145     if do_plot:
0146        exec('import '+db.moduleName(tag)+' as Plug')
0147            #what = {'how':'singleChannel','which': [0,1,2]}
0148        what = {'how':'barrel'}
0149        w = setWhat(Plug.What(),what)
0150        ex = Plug.Extractor(w)
0151        for elem in db.iov(tag).elements :
0152           p = Plug.Object(elem)
0153           p.extract(ex)
0154           v = [i for i in ex.values()]        
0155  #      print v
0156        histo=TH1F("h","h",100,-2,2) 
0157        for c in v :
0158           histo.Fill(c)       
0159        f=TFile("f.root","recreate")
0160        histo.Write()
0161 
0162     if do_compare:
0163        exec('import '+db.moduleName(tag)+' as Plug')
0164        what = {'how':'barrel'}
0165        w = setWhat(Plug.What(),what)
0166        ex = Plug.Extractor(w)
0167        for elem in db.iov(reference_tag).elements :
0168           p = Plug.Object(elem)
0169           p.extract(ex)
0170           coeff_1 = [i for i in ex.values()]
0171 
0172        for elem in db.iov(compare_tag).elements :
0173           p = Plug.Object(elem)
0174           p.extract(ex)
0175           coeff_2 = [i for i in ex.values()]
0176 
0177        can=TCanvas("c","c")
0178 
0179        histo = TH1F("h","h",100,-2,2)
0180        for i,c in enumerate(coeff_1):  
0181           histo.Fill(c-coeff_2[i])
0182        histo.Draw()   
0183 
0184        can.SaveAs("h.svg")
0185 
0186        can2=TCanvas("cc","cc")
0187        histo2=TH2F("hh","hh",171,-85,86,360,1,361)
0188        for i,c in enumerate(coeff_1):  
0189               factor = c/coeff_2[i]
0190               ieta,iphi= unhashEBDetId(i)
0191               histo2.Fill(ieta,iphi,factor)
0192 
0193        histo2.SetStats(0)       
0194        histo2.Draw("colz")
0195        can2.SaveAs("h2.svg")
0196               
0197 except Exception as er :
0198     print(er)
0199 
0200