#! /usr/bin/env python

"""\
%(prog)s [-h|--help] yodafile [-i|--inspire_id INSPIRE_ID] [-d|--yodafile_from_hepdata YODAFILE_FROM_HEPDATA] [-o|--output OUTPUT]

Check compatibility of a YODA reference data file, intended for inclusion in Rivet, with the YODA file downloaded from HEPData.
Specify either the INSPIRE_ID (to download the YODA file from HEPData) or the already-downloaded YODAFILE_FROM_HEPDATA.
Make the comparison using the yodadiff script distributed with YODA (https://yoda.hepforge.org/trac/browser/bin/yodadiff).
Optionally write the yodadiff output to a file OUTPUT instead of stdout.

Examples:
 rivet-diffhepdata ATLAS_2017_I1614149.yoda -i 1614149
 rivet-diffhepdata ATLAS_2017_I1614149.yoda -d HEPData-ins1614149-v2-yoda.yoda
"""

import os, importlib, glob, requests, argparse

from rivet import hepdatautils

parser = argparse.ArgumentParser(usage='Check compatibility of YODA reference data file with HEPData')
parser.add_argument('yodafile', help='name of YODA reference data file (intended for inclusion in Rivet)')
group = parser.add_mutually_exclusive_group()
group.add_argument('-i', '--inspire_id', nargs=1, default=[0], type=int, help='INSPIRE ID (to download the YODA file from HEPData')
group.add_argument('-d', '--yodafile_from_hepdata', nargs=1, default=[None], help='name of YODA file already downloaded from HEPData')
parser.add_argument('-o', '--output', nargs=1, default=[None], help='name of output file to write yodadiff output')
args = parser.parse_args()
compatible = hepdatautils.compare_with_hepdata(args.yodafile, args.inspire_id[0], args.yodafile_from_hepdata[0], args.output[0])
if compatible:
    print('YODA reference data files from Rivet and HEPData are compatible!')
else:
    print('YODA reference data files from Rivet and HEPData are NOT compatible!')
