コード例 #1
0
ファイル: trendPlots.py プロジェクト: aashaqshah/cmssw-1
def getHistoFromDQM(serverUrl, runNr, dataset, histoPath):
    print "**************>>>> GETTING HISTO"
    from src.dqmjson import dqm_get_json
    from os.path import split as splitPath
    print "fetching",serverUrl, runNr, dataset, histoPath
    print "*** histoPath = ", histoPath
    paths  = re.split('[,]',histoPath)
    print "paths = ", paths
    print "histoPath = ", histoPath
    if len(paths)>1 :
        print "paths[0] = ", paths[0]
        print "paths[1] = ", paths[1]
        for path in paths:
            print "splitPath(path)[1] = ", splitPath(path)[1] 
            if splitPath(path)[1] :
                #histoPath=path
                print "path = ", path

    json = dqm_get_json( serverUrl, runNr, dataset, histoPath[0], rootContent=True)
    result = None
    for path in paths:
        print "looping over histo paths, path = ", path 
        #json = dqm_get_json( serverUrl, runNr, dataset, splitPath(histoPath)[0], rootContent=True)
        json = dqm_get_json( serverUrl, runNr, dataset, splitPath(path)[0], rootContent=True)
        #print "===> if this crashes you might consider changing the relativePats in ./cfg/trendPlotsTracker.py"
        #print "test = ", splitPath(path)[1] in json
        #if splitPath(histoPath)[1] in json :
        if splitPath(path)[1] in json :
            print "path in json = ", path
            #assert splitPath(histoPath)[1] in json, "could not find '%s' in run %s of '%s'"%(histoPath, runNr, dataset)
            assert splitPath(path)[1] in json, "could not find '%s' in run %s of '%s'"%(path, runNr, dataset)
#            print "using split path"
            #result = json[splitPath(histoPath)[1]]["rootobj"]
            result = json[splitPath(path)[1]]["rootobj"]
    return result
コード例 #2
0
def getHistoFromDQM(serverUrl, runNr, dataset, histoPath):
    print "**************>>>> GETTING HISTO"
    from src.dqmjson import dqm_get_json
    from os.path import split as splitPath
    print "fetching",serverUrl, runNr, dataset, histoPath
    print "*** histoPath = ", histoPath
    paths  = re.split('[,]',histoPath)
    print "paths = ", paths
    print "histoPath = ", histoPath
    if len(paths)>1 :
        print "paths[0] = ", paths[0]
        print "paths[1] = ", paths[1]
        for path in paths:
            print "splitPath(path)[1] = ", splitPath(path)[1] 
            if splitPath(path)[1] :
                #histoPath=path
                print "path = ", path
                
    #print "DEBUUUUG1"
    #print dataset
    #print "histoPath[0]: ", histoPath[0]
    #print "histoPath: " , histoPath
    #json = dqm_get_json( serverUrl, runNr, dataset, histoPath[0], rootContent=True)

    result = None
    for path in paths:
        print "looping over histo paths, path = ", path 
        print "DEBUUUUG2"
        print dataset
        print splitPath(histoPath)[0]
        json = dqm_get_json( serverUrl, runNr, dataset, splitPath(histoPath)[0], rootContent=True)
#        print dqm_get_json( serverUrl, runNr, dataset, splitPath(histoPath)[0]+"/"+splitPath(histoPath)[1], rootContent=True)
    
        #jsonT = dqm_get_json( serverUrl, runNr, dataset, splitPath(path)[0], rootContent=True)


        #if ( path == "SiStrip/MechanicalView/TIB/Summary_ClusterStoNCorr_OnTrack__TIB" ):
            #print "JSOOOOON " , jsonT
            #print "JSOOOOON REPR " , repr(jsonT)
            #print "OK?"
            #data_string = json.dumps(jsonT)
            #print "OK!"
            #print "JSOOOOON STRING " , data_string
            #with open('testjson.txt', 'w') as outfile:
             #   json.dump(jsonT, outfile)
                #outfile.write(data_string)
            #outfile.close()
      
        #print "===> if this crashes you might consider changing the relativePats in ./cfg/trendPlotsTracker.py"
        #print "test = ", splitPath(path)[1] in json
        #if splitPath(histoPath)[1] in json :
        if splitPath(path)[1] in json :
            print "path in json = ", path
            #assert splitPath(histoPath)[1] in json, "could not find '%s' in run %s of '%s'"%(histoPath, runNr, dataset)
            assert splitPath(path)[1] in json, "could not find '%s' in run %s of '%s'"%(path, runNr, dataset)
#            print "using split path"
            #result = json[splitPath(histoPath)[1]]["rootobj"]
            result = json[splitPath(path)[1]]["rootobj"]
            print result
    return result
コード例 #3
0
def getHistoFromDQM(serverUrl, runNr, dataset, histoPath):
    print "**************>>>> GETTING HISTO"
    from src.dqmjson import dqm_get_json
    from os.path import split as splitPath
    print "fetching", serverUrl, runNr, dataset, histoPath
    print "*** histoPath = ", histoPath
    paths = re.split('[,]', histoPath)
    print "paths = ", paths
    print "histoPath = ", histoPath
    if len(paths) > 1:
        print "paths[0] = ", paths[0]
        print "paths[1] = ", paths[1]
        for path in paths:
            print "splitPath(path)[1] = ", splitPath(path)[1]
            if splitPath(path)[1]:
                #histoPath=path
                print "path = ", path

    json = dqm_get_json(serverUrl,
                        runNr,
                        dataset,
                        histoPath[0],
                        rootContent=True)
    result = None
    for path in paths:
        print "looping over histo paths, path = ", path
        #json = dqm_get_json( serverUrl, runNr, dataset, splitPath(histoPath)[0], rootContent=True)
        json = dqm_get_json(serverUrl,
                            runNr,
                            dataset,
                            splitPath(path)[0],
                            rootContent=True)
        #print "===> if this crashes you might consider changing the relativePats in ./cfg/trendPlotsTracker.py"
        #print "test = ", splitPath(path)[1] in json
        #if splitPath(histoPath)[1] in json :
        if splitPath(path)[1] in json:
            print "path in json = ", path
            #assert splitPath(histoPath)[1] in json, "could not find '%s' in run %s of '%s'"%(histoPath, runNr, dataset)
            assert splitPath(
                path)[1] in json, "could not find '%s' in run %s of '%s'" % (
                    path, runNr, dataset)
            #            print "using split path"
            #result = json[splitPath(histoPath)[1]]["rootobj"]
            result = json[splitPath(path)[1]]["rootobj"]
    return result
コード例 #4
0
def getHistoFromDQM(serverUrl, runNr, dataset, histoPath):
    print "**************>>>> GETTING HISTO"
    from src.dqmjson import dqm_get_json
    from os.path import split as splitPath
    print "fetching",serverUrl, runNr, dataset, histoPath
    print "*** histoPath = ", histoPath
    paths  = re.split('[,]',histoPath)
    print "paths = ", paths
    print "histoPath = ", histoPath
    if len(paths)>1 :
        print "paths[0] = ", paths[0]
        print "paths[1] = ", paths[1]
        for path in paths:
            print "splitPath(path)[1] = ", splitPath(path)[1] 
            if splitPath(path)[1] :
                #histoPath=path
                print "path = ", path
                
    #print "DEBUUUUG1"
    #print dataset
    #print "histoPath[0]: ", histoPath[0]
    #print "histoPath: " , histoPath
    #json = dqm_get_json( serverUrl, runNr, dataset, histoPath[0], rootContent=True)

    result = None
    for path in paths:
        print "looping over histo paths, path = ", path 
        print "DEBUUUUG2"
        print dataset
        print splitPath(histoPath)[0]
        json = dqm_get_json( serverUrl, runNr, dataset, splitPath(histoPath)[0], rootContent=True)
        #jsonT = dqm_get_json( serverUrl, runNr, dataset, splitPath(path)[0], rootContent=True)


        #if ( path == "SiStrip/MechanicalView/TIB/Summary_ClusterStoNCorr_OnTrack__TIB" ):
            #print "JSOOOOON " , jsonT
            #print "JSOOOOON REPR " , repr(jsonT)
            #print "OK?"
            #data_string = json.dumps(jsonT)
            #print "OK!"
            #print "JSOOOOON STRING " , data_string
            #with open('testjson.txt', 'w') as outfile:
             #   json.dump(jsonT, outfile)
                #outfile.write(data_string)
            #outfile.close()
      
        #print "===> if this crashes you might consider changing the relativePats in ./cfg/trendPlotsTracker.py"
        #print "test = ", splitPath(path)[1] in json
        #if splitPath(histoPath)[1] in json :
        if splitPath(path)[1] in json :
            print "path in json = ", path
            #assert splitPath(histoPath)[1] in json, "could not find '%s' in run %s of '%s'"%(histoPath, runNr, dataset)
            assert splitPath(path)[1] in json, "could not find '%s' in run %s of '%s'"%(path, runNr, dataset)
#            print "using split path"
            #result = json[splitPath(histoPath)[1]]["rootobj"]
            result = json[splitPath(path)[1]]["rootobj"]
    return result
コード例 #5
0
def main(argv=None):
    import sys
    import os
    from optparse import OptionParser
    from ROOT import TCanvas,TFile
    from src.dqmjson import dqm_get_json    

    if argv == None:
        argv = sys.argv[1:]
    parser = OptionParser()
    parser.add_option("-C", "--config", dest="config", default=[], action="append", 
                      help="configuration defining the plots to make")
    parser.add_option("-o", "--output", dest="outPath", default=None, 
                      help="path to output plots. If it does not exsist it is created")
    parser.add_option("-r", "--runs", dest="runs", default="all", 
                      help="mask for the run (full boolean and math capabilities e.g. run > 10 and run *2 < -1)")
    parser.add_option("-D", "--dataset", dest="dset", default="Jet",
                      help="mask for the primary dataset (default is Jet), e.g. Cosmics, MinimumBias")
    parser.add_option("-E", "--epoch", dest="epoch", default="Run2012",
                      help="mask for the data-taking epoch (default is Run2012), e.g. Run2011B, Run2011A, etc.")
    parser.add_option("-R", "--reco", dest="reco", default="Prompt",
                      help="mask for the reconstruction type (default is Prompt), e.g. 08Nov2011, etc.")
    parser.add_option("-t", "--tag", dest="tag", default="v*",
                      help="mask for the reco dataset tag (default is v*), e.g. v5")
    parser.add_option("-d", "--datatier", dest="datatier", default="DQMIO",
                      help="mask for the datatier name (default is DQMIO)")
    parser.add_option("-s", "--state", dest="state", default="ALL",
                      help="mask for strip state, options are ALL, PEAK, DECO, or MIXED -- only applicable if dataset is 'Cosmics'")
    parser.add_option("-L", "--list", dest="list", type="string", default=[] , action="store")
    parser.add_option("-J", "--json", dest="json", type="string", default=[] , action="store")
    (opts, args) = parser.parse_args(argv)
    if opts.config ==[]:
        opts.config = "trendPlots.ini"
    config = BetterConfigParser()
    config.read(opts.config)
#    if opts.json!=[]:
#        import simplejson as json
#        aaf = open("Cert_190456-191276_8TeV_PromptReco_Collisions12_JSON_MuonPhys.txt","r")
#        tempF=open("temp.txt")
 
    initStyle(config)

    dsetmask = ".*/" + opts.dset +"/"+opts.epoch+".*"+opts.reco+"*.*"+opts.tag+"/"+opts.datatier
    print "dsetmask = ",dsetmask
    print "opts.state = ",opts.state
    print "opts.runs = ",opts.runs
    print "opts.list = ",opts.list
    print "opts.json = ",opts.json
     
    runs = getRunsFromDQM(config, dsetmask, opts.dset, opts.state, opts.runs,opts.list,opts.json)
    if not runs : raise StandardError, "*** Number of runs matching run/mask/etc criteria is equal to zero!!!"

    print "runs= ", runs

    print "got %s run between %s and %s"%(len(runs), min(runs.keys()), max(runs.keys()))
#    getReferenceRun(config, runs)
    plots, cache = initPlots(config)

    runInCache = []
    for itest in range(0,len(cache.keys())):
        runInCache.append(cache.keys()[itest][1])

    for run in sorted(runs.keys()):
        if cache == None or runs[run][1] not in runInCache:
            print "............------------>>> RUN %s NOT IN CACHE"%(runs[run][1])
            rc = dqm_get_json(runs[run][0],runs[run][1],runs[run][2], "Info/ProvInfo")
            print "............------------>>> RunIsComplete flag: " , rc['runIsComplete']['value']
            isDone = int(rc['runIsComplete']['value'])
        else:
            isDone = 1
            print "............------------>>> RUN %s IN CACHE"%(runs[run][1])
        if isDone == 1 :
            for plot in plots:
                plot.addRun(*(runs[run]))
        else:
            print "################### RUN %s NOT FULLY PROCESSED, SKIP #############"%(runs[run][1])

    cachePath = config.get("output","cachePath")
    cacheFile = open(cachePath,"w")
    cacheFile.write(str(cache))
    cacheFile.close()

    outPath = "fig/"+opts.reco+"/"+opts.epoch+"/"+opts.dset
    if 'Cosmics' in opts.dset:
        outPath = outPath + "/" + opts.state
    ##outPath = config.get("output","defautlOutputPath")
    if not opts.outPath == None: outPath  = opts.outPath
    if not os.path.exists(outPath): os.makedirs(outPath)
    makeSummary = config.getboolean("output","makeSummary")
    canvasSize = [int(i) for i in config.get("styleDefaults","canvasSize").split("x")]
    canvas = TCanvas("trendplot","trendplot", canvasSize[0], canvasSize[1])
    canvas.Clear()
    canvas.SetBottomMargin(0.14)
    canvas.SetGridy()


    if makeSummary: canvas.Print(os.path.join(outPath,"trendPlots.ps["))
    for plot in plots:
        #(graph, legend, refLabel) = plot.getGraph()
        try: plot.getGraph(opts.dset)
        except:
            print "Error producing plot:", plot.getName()
            print "Possible cause: no entries, or non-existing plot name"
            continue
        (graph, legend) = plot.getGraph(opts.dset)
        canvas.Clear()
        graph.Draw("AP")
        graph.GetYaxis().SetTitleOffset(1.6)
        plot.formatGraphAxis(graph)
        #refLabel.Draw()
        legend.Draw()
        canvas.SetLeftMargin(0.125)
        plot.drawAnnotation()
        canvas.Modified()
        canvas.Update()
        for formatExt in config.get("output","formats").split():
            if formatExt=='root':
                (histotemp, legend) = plot.getHISTO()
                #(graphtemp, legend1) = plot.getGraphSimple()
            #plot.formatGraphAxis(graphtemp)
                F_out=TFile.Open(os.path.join(outPath,"%s.%s"%(plot.getName(), formatExt)),"RECREATE")
                F_out.cd()
                histotemp.Write()
                graph.Write()
#                graphtemp.SetDrawOption("AP")
#                graphtemp.Write("P")
                F_out.Close()

            else:
                canvas.Print(os.path.join(outPath,"%s.%s"%(plot.getName(), formatExt)))

        if makeSummary: canvas.Print(os.path.join(outPath,"trendPlots.ps"))
        
        if makeSummary: canvas.Print(os.path.join(outPath,"trendPlots.ps]"))
コード例 #6
0
def main(argv=None):
    import sys
    import os
    from optparse import OptionParser
    from ROOT import TCanvas, TFile
    from src.dqmjson import dqm_get_json, dqm_getTFile, dqm_getTFile_Version2

    if argv == None:
        argv = sys.argv[1:]
    parser = OptionParser()
    parser.add_option("-C",
                      "--config",
                      dest="config",
                      default=[],
                      action="append",
                      help="configuration defining the plots to make")
    parser.add_option(
        "-o",
        "--output",
        dest="outPath",
        default=None,
        help="path to output plots. If it does not exsist it is created")
    parser.add_option(
        "-r",
        "--runs",
        dest="runs",
        default="all",
        help=
        "mask for the run (full boolean and math capabilities e.g. run > 10 and run *2 < -1)"
    )
    parser.add_option(
        "-D",
        "--dataset",
        dest="dset",
        default="Jet",
        help=
        "mask for the primary dataset (default is Jet), e.g. Cosmics, MinimumBias"
    )
    parser.add_option(
        "-E",
        "--epoch",
        dest="epoch",
        default=[],
        action="append",
        help=
        "mask for the data-taking epoch (default is Run2012), e.g. Run2011B, Run2011A, etc."
    )
    parser.add_option(
        "-R",
        "--reco",
        dest="reco",
        default="Prompt",
        help=
        "mask for the reconstruction type (default is Prompt), e.g. 08Nov2011, etc."
    )
    parser.add_option(
        "-t",
        "--tag",
        dest="tag",
        default="v*",
        help="mask for the reco dataset tag (default is v*), e.g. v5")
    parser.add_option("-d",
                      "--datatier",
                      dest="datatier",
                      default="DQMIO",
                      help="mask for the datatier name (default is DQMIO)")
    parser.add_option(
        "-s",
        "--state",
        dest="state",
        default="ALL",
        help=
        "mask for strip state, options are ALL, PEAK, DECO, or MIXED -- only applicable if dataset is 'Cosmics'"
    )
    parser.add_option("-L",
                      "--list",
                      dest="list",
                      type="string",
                      default=[],
                      action="store")
    parser.add_option("-J",
                      "--json",
                      dest="json",
                      type="string",
                      default=[],
                      action="store")
    (opts, args) = parser.parse_args(argv)
    if opts.config == []:
        opts.config = "trendPlots.ini"
    config = BetterConfigParser()
    config.read(opts.config)

    initStyle(config)
    print "opts.state = ", opts.state
    print "opts.runs = ", opts.runs
    print "opts.list = ", opts.list
    print "opts.json = ", opts.json

    runs = getRunsFromDQM(config, opts.dset, opts.epoch, opts.reco, opts.tag,
                          opts.datatier, opts.runs, opts.list, opts.json)
    if not runs:
        raise StandardError, "*** Number of runs matching run/mask/etc criteria is equal to zero!!!"

    print "got %s run between %s and %s" % (len(runs), min(
        runs.keys()), max(runs.keys()))
    plots, cache = initPlots(config)

    print "Loading cache........", len(cache.keys()), " items"
    runInCache = []
    for itest in range(0, len(cache.keys())):
        runInCache.append(cache.keys()[itest][1])
    print "Cache loaded!"
    for run in sorted(runs.keys()):
        if cache == None or runs[run][1] not in runInCache:
            print "------------>>> RUN %s NOT IN CACHE" % (runs[run][1])
            rc = dqm_get_json(runs[run][0], runs[run][1], runs[run][2],
                              "Info/ProvInfo")
            print "------------>>> RunIsComplete flag: ", rc['runIsComplete'][
                'value']
            isDone = int(rc['runIsComplete']['value'])
            if opts.datatier != "DQMIO":
                isDone = 1
        else:
            isDone = 1
            print "------------>>> RUN %s IN CACHE" % (runs[run][1])
        if isDone == 1:
            fopen = False
            fpresent = True
            incache = False
            fchecked = False
            tfile = None
            for plot in plots:
                cacheLocation = (runs[run][0], runs[run][1], runs[run][2],
                                 plot.getPath(), plot.getMetric())
                incache = (cacheLocation in cache)
                if (cache == None and not fchecked) or (not incache
                                                        and not fchecked):
                    version = dqm_getTFile_Version2(runs[run][0], runs[run][1],
                                                    runs[run][2], runs[run][3],
                                                    opts.datatier)
                    if (version != 0):
                        tfile = dqm_getTFile(runs[run][0], runs[run][1],
                                             runs[run][2], version,
                                             runs[run][3], opts.datatier)
                        print "### Openning ROOT File Version {0} for Run{1}".format(
                            version, runs[run][1])
                        fopen = True
                    else:
                        fpresent = False
                        print "### ROOT file not present for Run{0} -> JSON information will be used".format(
                            runs[run][1])
                    fchecked = True
                plot.addRun(runs[run][0], runs[run][1], runs[run][2], tfile)
            if fopen:
                tfile.Close()
        else:
            print "############ RUN %s NOT FULLY PROCESSED, SKIP ############" % (
                runs[run][1])

    cachePath = config.get("output", "cachePath")
    cacheFile = open(cachePath, "w")
    cacheFile.write(str(cache))
    cacheFile.close()

    for plot in plots:
        plot.dumpJSON()

    outPath = "fig/" + opts.reco + "/" + opts.dset
    if 'Cosmics' in opts.dset:
        outPath = outPath + "/" + opts.state
    ##outPath = config.get("output","defautlOutputPath")
    if not opts.outPath == None: outPath = opts.outPath
    if not os.path.exists(outPath): os.makedirs(outPath)
    makeSummary = config.getboolean("output", "makeSummary")
    canvasSize = [
        int(i) for i in config.get("styleDefaults", "canvasSize").split("x")
    ]
    canvas = TCanvas("trendplot", "trendplot", canvasSize[0], canvasSize[1])
    canvas.Clear()
    canvas.SetBottomMargin(0.14)
    canvas.SetGridy()

    if makeSummary: canvas.Print(os.path.join(outPath, "trendPlots.ps["))
    for plot in plots:
        #(graph, legend, refLabel) = plot.getGraph()
        try:
            plot.getGraph()
        except:
            print "Error producing plot:", plot.getName()
            print "Possible cause: no entries, or non-existing plot name"
            continue
        (graph, legend) = plot.getGraph()
        canvas.Clear()
        graph.Draw("AP")
        graph.GetYaxis().SetTitleOffset(1.6)
        plot.formatGraphAxis(graph)
        legend.Draw()
        canvas.SetLeftMargin(0.125)
        canvas.Modified()
        canvas.Update()
        for formatExt in config.get("output", "formats").split():
            if formatExt == 'root':
                (histotemp, legend) = plot.getHISTO()
                F_out = TFile.Open(
                    os.path.join(outPath,
                                 "%s.%s" % (plot.getName(), formatExt)),
                    "RECREATE")
                F_out.cd()
                histotemp.Write()
                graph.Write()
                F_out.Close()
            else:
                canvas.Print(
                    os.path.join(outPath,
                                 "%s.%s" % (plot.getName(), formatExt)))

        if makeSummary: canvas.Print(os.path.join(outPath, "trendPlots.ps"))

        if makeSummary: canvas.Print(os.path.join(outPath, "trendPlots.ps]"))