#!/usr/bin/env python3
import Utils.Parse
from optparse import OptionParser#NOTE: The optparse module is deprecated - we should stop using it at some point

parser = OptionParser(usage='%prog <INFILE.shist> <OUTFILE.root>',
                      description='Convert histograms in a SimpleHist file to their closest equivalent ROOT histograms and store in a ROOT file')
parser.add_option("-f", "--force",
                  action="store_true", dest="force", default=False,
                  help="Overwrite existing output file")
(opt, args) = parser.parse_args()

if len(args)!=2:
    parser.error("Wrong number of arguments")

infile_ok,infile = Utils.Parse.decode_inputfile(args[0],require_ext='.shist',rel_path=True)
if not infile_ok:
    parser.error("Input file %s"%infile)

outfile_ok,outfile = Utils.Parse.decode_outputfile(args[1],require_ext='.root',rel_path=True,can_exist=opt.force)
if not outfile_ok:
    parser.error("Output file %s"%outfile)

import SimpleHists2ROOT.ConvertFile
SimpleHists2ROOT.ConvertFile.convertToROOTFile(infile,outfile)
