
#setting up DaVinci directory
DV = GaudiExec()

for polarity in ["Down","Up"]:
    for yr in ["15","16"]:
        E = 0
        nu = 0
        trigger = 0
        if (yr=="11"):
            E = 3500
            nu = 2
            reco="14"
            stripping = "21r1p2"
            DV.directory = '/afs/cern.ch/work/r/rekopecn/public/B_2_KstarMuMu/DaVinciDev_v38r1p3/' 
        elif (yr=="12"):
            E = 4000
            reco="14"
            stripping = "21r0p1a"
            DV.directory = '/afs/cern.ch/work/r/rekopecn/public/B_2_KstarMuMu/DaVinciDev_v38r1p3/' 
        elif (yr=="15"):
            E = 6500
            reco="15a"
            stripping = "24r2"
            DV.directory = '/afs/cern.ch/work/r/rekopecn/public/B_2_KstarMuMu/DaVinciDev_v44r3/' 
            DV.platform = "x86_64-centos7-gcc62-opt"
        elif (yr=="16"):
            E = 6500
            reco="16"
            stripping = "28r2"
            DV.directory = '/afs/cern.ch/work/r/rekopecn/public/B_2_KstarMuMu/DaVinciDev_v44r3/'
            DV.platform = "x86_64-centos7-gcc62-opt"
        elif (yr=="17"):
            E = 6500
            reco="17"
            stripping = "29r2"
            DV.directory = '/afs/cern.ch/work/r/rekopecn/public/B_2_KstarMuMu/DaVinciDev_v44r3/' 
            DV.platform = "x86_64-centos7-gcc62-opt"
        elif (yr=="18"):
            E = 6500
            reco="18"
            stripping = "34r0p1"
            DV.directory = '/afs/cern.ch/work/r/rekopecn/public/B_2_KstarMuMu/DaVinciDev_v44r3/'
            DV.platform = "x86_64-centos7-gcc62-opt" 

        script_opts = {"YEAR":yr,"POL":polarity,"DATA_TYPE":"data","ENERGY":E,"RECO":reco,"STRIP":stripping}
        script_1 ='/afs/cern.ch/work/r/rekopecn/public/B_2_KstarMuMu/DaVinciDev_v41r2/tuplecreation/optfiles/%(DATA_TYPE)s/20%(YEAR)s%(POL)s_%(DATA_TYPE)s.py'% script_opts
        #  script_basic = '/afs/cern.ch/work/r/rekopecn/public/B_2_KstarMuMu/DaVinciDev_v41r2/tuplecreation/optfiles/BasicOptfile.py'%(YEAR)s%(POL)s_%(DATA_TYPE)s_%(CHAN)s
        print ('Using optsfile: ',script_1)
        optsfile = [script_1]

        PATH ="/LHCb/Collision%(YEAR)s/Beam%(ENERGY)sGeV-VeloClosed-Mag%(POL)s/Real Data/Reco%(RECO)s/Stripping%(STRIP)s/90000000/LEPTONIC.MDST" % script_opts
        print ('Using data: ', PATH)

        DV.options = optsfile

        j = Job(
            name           		= '%(YEAR)s%(POL)s' % script_opts,
            application    		= DV,
            splitter       		= SplitByFiles(filesPerJob = 50,ignoremissing = True),
            inputdata      		= BKQuery(path=PATH).getDataset(),
            outputfiles     		= [DiracFile(namePattern='*.root')],
            do_auto_resubmit 		= False,
            backend        		= Dirac(),	      
        )	
        #j.backend.settings['Destination'] = ['LCG.CERN.cern']
        j.backend.settings['BannedSites'] = ['LCG.RAL.uk']
        j.submit()
