from PLOT.PLOT import PLOT
from RetrieveData.RetrieveDataForPlot import RetrieveDataForPlot
from RetrieveData.Retriever import Retriever

__author__ = 'mmateja'
basic_path = "/home/mmateja/PycharmProjects/OperationPlots/"
#nameFileEnd = "Mu"


startfillnumber = 3819
endfillnumber = 4000

d = Retriever( basic_path, "lumi_LHCb", startfillnumber, endfillnumber)
data = d.retrieve("LPC") #LPC, CONDITION
r = RetrieveDataForPlot(data)
datax,datay=r.retrieveData("fillnumber","max_lumi")
for (key1, value1),(key2, value2) in zip(datax.iteritems(), datay.iteritems()): #-key2,0iteritems ze wzgledu na typy danych
        plot=PLOT(value1, value2)
        plot.setTitle("LHCb Peak Instantaneous Lumi at p-p 6.5 TeV in 2015") #key1
        plot.setxlabel("LHC Fillnumber")
        plot.setylabel("Peak Inst Luminosity (10^24/cm^2*s^1)")
        plot.draw()
datax,datay=r.retrieveData("fillnumber","average_lumi")
for (key1, value1),(key2, value2) in zip(datax.iteritems(), datay.iteritems()): #-key2,0iteritems ze wzgledu na typy danych
        plot=PLOT(value1, value2)
        plot.setTitle("LHCb Peak Instantaneous Lumi at p-p 6.5 TeV in 2015") #key1
        plot.setxlabel("LHC Fillnumber")
        plot.setylabel("Peak Inst Luminosity (10^24/cm^2*s^1)")
        plot.draw()
        #plot.savefig("OUTPUTPLOTS/2015PeakLumiFill.png")
plot.show()
# Start by retrieving data for LPC/lumi_LHCb files in the range of fillnumbers
print 'Retrieving data from lumi_LHCb between fill# ' + str(startfillnumber) + ' and fill# ' + str(endfillnumber)
d = Retriever( basic_path, "lumi_LHCb", startfillnumber, endfillnumber)
lumi = d.retrieve("LPC") #LPC, CONDITION
r = RetrieveDataForPlot(lumi)

xaxis = "fillnumber"  
yaxis = "max_lumi_lumi"
print 'Doing ' + yaxis + ' vs ' + xaxis
datax,datay = r.retrieveData(xaxis,yaxis)
for (key1, value1),(key2, value2) in zip(datax.iteritems(), datay.iteritems()):
        plot=PLOT()
        plot.setTitle("LHCb Peak Instantaneous Lumi at p-p 6.5 TeV in 2015")
        plot.setxlabel("LHC Fillnumber")
        plot.setylabel("Peak Inst Luminosity (Hz/ub)")
        plot.draw(value1, value2, 'b', 6)
        plot.savefig("OUTPUTPLOTS/2015PeakLumiFill.png")


xaxis = "time_date"  
yaxis = "max_lumi_lumi"
print 'Doing ' + yaxis + ' vs ' + xaxis
datax,datay = r.retrieveData(xaxis,yaxis)
for (key1, value1),(key2, value2) in zip(datax.iteritems(), datay.iteritems()): 
        value1 = dateformat(value1)
        plot=PLOT()
        plot.setDate()
        plot.setTitle("LHCb Peak Instantaneous Lumi at p-p 6.5 TeV in 2015") 
        plot.setxlabel("Date")
        plot.setylabel("Peak Inst Luminosity (Hz/ub)")
        plot.draw(value1, value2, 'b', 6)