Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:03:03

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