#! /usr/bin/env python

"""\
%prog yodafile [aidafile]

Convert a YODA data file to the old AIDA XML data format.

WARNING: flat2yoda is DEPRECATED
It will die when AIDA does! Which is *soon*...
"""

import yoda, os, sys, optparse
from yoda.script_helpers import parse_x2y_args, filter_aos

parser = optparse.OptionParser(usage=__doc__)
parser.add_option("-m", "--match", dest="MATCH", metavar="PATT", default=None,
                  help="only write out histograms whose path matches this regex")
parser.add_option("-M", "--unmatch", dest="UNMATCH", metavar="PATT", default=None,
                  help="exclude histograms whose path matches this regex")

sys.stderr.write("WARNING: yoda2aida is DEPRECATED.\n  It will die when AIDA does... *soon*\n"

opts, args = parser.parse_args()
in_out = parse_x2y_args(args, ".yoda", ".aida")
if not in_out:
    sys.stderr.write("You must specify the YODA and AIDA file names\n")
    sys.exit(1)

for i, o in in_out:
    analysisobjects = yoda.readYODA(i)
    filter_aos(analysisobjects, opts.MATCH, opts.UNMATCH)
    yoda.writeAIDA(analysisobjects, o)
