#!/usr/bin/env python3
#####################################################################################
# (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations #
#                                                                                   #
# This software is distributed under the terms of the Apache version 2 licence,     #
# copied verbatim in the file "LICENSE".                                            #
#                                                                                   #
# In applying this licence, CERN does not waive the privileges and immunities       #
# granted to it by virtue of its status as an Intergovernmental Organization        #
# or submit itself to any jurisdiction.                                             #
#####################################################################################
"""
Print metadata recorded by MetaDataSvc from a ROOT file.
"""

if __name__ == "__main__":
    import os
    from optparse import OptionParser
    from pprint import pprint

    from GaudiSvc import getMetaData

    parser = OptionParser(usage="%prog filename", description=__doc__)

    opts, args = parser.parse_args()

    if len(args) != 1:
        parser.error("wrong number of arguments")

    filename = args[0]

    if not os.path.exists(filename):
        parser.error("invalid filename {0}".format(filename))

    try:
        pprint(getMetaData(filename))
    except RuntimeError as x:
        parser.error(str(x))
