# Renata Kopecna

#########################################################
#							                            #
#	Set of functions used for running FCNC fitter	    #
#                                                       #
#########################################################
import sys
import os
import subprocess
from runUtils import *
from runArgs import *

allYearsDict ={ 2011:1,
                2012:1,
                2015:2, 
                2016:2, 
                2017:2,
                2018:2,
                }  

if '__main__' == __name__:
    print ("")

    #Add and parse arguments
    parser = ShowArgumentsParser(
        formatter_class=argparse.RawTextHelpFormatter,
        prog=os.path.basename(sys.argv[0]),
        description=("""Do the comparison for:

        For a full list of arguments, do: 'python {0} -h'
        """).format(os.path.basename(sys.argv[0]))
        )
    addAllArgs(parser)
    opts = parser.parse_args()
    dir(opts)

    #check dir is the FCNC dir
    print ("Starting program in directory: ")
    os.system('pwd')
    print ("\n")

    #Open output file; if none specified, print into console
    if (opts.log!=""): logFile = open(opts.log,'w')
    else: logFile = open("dummy",'w') #easiest is to create a dummy and then not save anything in it

    
    #if (opts.compile): 
    #Just compile always, because you're a dumb dumb
    if (not opts.dontCompile):
        waitForCommand("bash",["cmake.sh"], logFile)
        print ("\n\nCompiled.")

    cmd = './bu2kstarmumu'
    
    arg_list = []
    arg_list.append('-v ' + str(opts.verbosity))
    if (opts.hilfe):  
        arg_list.append("-h")
        waitForCommand(cmd,arg_list,logFile)
    else:            
        argListList= fullArgListPerRun(opts)
        for arguments in argListList:
            print("Runinng ./bu2kstarmumu ", arguments, "\n")
            waitForCommand(cmd,arguments,logFile)
        
  
    print ("\n\nDone running FCNC.\n")


