Exemple #1
0
    def __init__(self, options, **kwargs):

        super(C3POProcessor, self).__init__(**kwargs)
        parser = ArgumentParser()
        parser.add_argument('--student-verbose',
            dest='verbose',
            action='store_true', default=False)
        parser.add_argument('--syst-terms', default=None)
        self.args = parser.parse_args(options)
        if self.args.syst_terms is not None:
            self.args.syst_terms = set([
                eval('Systematics.%s' % term) for term in
                self.args.syst_terms.split(',')])
Exemple #2
0
def get_parser():
    parser = ArgumentParser()
    parser.add_argument('--format', choices=('latex', 'text'), default='text')
    parser.add_argument('--errors', action='store_true', default=False)
    parser.add_argument('--precision', default=2)
    parser.add_argument('--proc', default='HHProcessor')
    parser.add_argument('--db', default='datasets_hh')
    parser.add_argument('--year', type=int, default=2012)
    parser.add_argument('--no-weight', action='store_true', default=False)
    parser.add_argument('--verbose', action='store_true', default=False)
    parser.add_argument('--rst', action='store_true', default=False)
    parser.add_argument('--rst-class', default='cutflow')
    parser.add_argument('--total', action='store_true', default=False)
    parser.add_argument('--landscape', action='store_true', default=False)
    parser.add_argument('--warn-missing', action='store_true', default=False)
    return parser
Exemple #3
0
    def __init__(self, options, **kwargs):
        super(hhskim_truth, self).__init__(**kwargs)
        parser = ArgumentParser()
        parser.add_argument('--local', action='store_true', default=False)
        parser.add_argument('--syst-terms', default=None)
        parser.add_argument('--student-verbose',
                            action='store_true',
                            default=False)
        parser.add_argument('--student-very-verbose',
                            action='store_true',
                            default=False)
        parser.add_argument('--redo-selection',
                            action='store_true',
                            default=False)
        parser.add_argument('--nominal-values',
                            action='store_true',
                            default=False)
        args = parser.parse_args(options)
        self.args = args
        if args.syst_terms is not None:
            args.syst_terms = set([
                eval('Systematics.%s' % term)
                for term in args.syst_terms.split(',')
            ])
        if args.local:

            def merge(inputs, output, metadata):
                # merge output trees
                root_output = output + '.root'
                log.info("merging output trees")
                subprocess.call(['hadd', root_output] + inputs)
                if metadata.datatype == datasets.DATA:
                    # merge GRLs
                    log.info("merging GRL fragments")
                    grl = goodruns.GRL()
                    for input in inputs:
                        grl |= goodruns.GRL('%s:/lumi' % input)
                    grl.save('%s:/lumi' % root_output)

            hhskim_truth.merge = staticmethod(merge)
Exemple #4
0
import logging
import os

# rootpy/ROOT imports
import rootpy
from rootpy.extern.argparse import ArgumentParser
# setup the argument parser
parser = ArgumentParser()
parser.add_argument('--test_mode',
                    type=str,
                    default='VBF',
                    choices=['VBF', 'gg', 'mix', 'Z'])
parser.add_argument('--test_level',
                    type=str,
                    default='reco',
                    choices=['truth', 'reco'])
parser.add_argument('--train_level',
                    type=str,
                    default='truth',
                    choices=['truth', 'reco'])
parser.add_argument(
    '--train_id',
    type=str,
    default='0000',
)

parser.add_argument('--channel',
                    type=str,
                    default='hh',
                    choices=['hh', 'lh', 'll'])
parser.add_argument('--train_mode',
Exemple #5
0
def main():

    import rootpy
    from rootpy.extern.argparse import (ArgumentParser,
                                        ArgumentDefaultsHelpFormatter,
                                        RawTextHelpFormatter)

    class formatter_class(ArgumentDefaultsHelpFormatter, RawTextHelpFormatter):
        pass

    parser = ArgumentParser(
        formatter_class=formatter_class,
        description="Convert ROOT files containing TTrees into HDF5 files "
        "containing HDF5 tables")
    parser.add_argument('--version',
                        action='version',
                        version=rootpy.__version__,
                        help="show the version number and exit")
    parser.add_argument('-n',
                        '--entries',
                        type=int,
                        default=100000,
                        help="number of entries to read at once")
    parser.add_argument('-f',
                        '--force',
                        action='store_true',
                        default=False,
                        help="overwrite existing output files")
    parser.add_argument('-u',
                        '--update',
                        action='store_true',
                        default=False,
                        help="update existing output files")
    parser.add_argument('--ext', default='h5', help="output file extension")
    parser.add_argument('-c',
                        '--complevel',
                        type=int,
                        default=5,
                        choices=range(0, 10),
                        help="compression level")
    parser.add_argument('-l',
                        '--complib',
                        default='zlib',
                        choices=('zlib', 'lzo', 'bzip2', 'blosc'),
                        help="compression algorithm")
    parser.add_argument('-s',
                        '--selection',
                        default=None,
                        help="apply a selection on each "
                        "tree with a cut expression")
    parser.add_argument(
        '--script',
        default=None,
        help="Python script containing a function with the same name \n"
        "that will be called on each tree and must return a tree or \n"
        "list of trees that will be converted instead of the \n"
        "original tree")
    parser.add_argument('-q',
                        '--quiet',
                        action='store_true',
                        default=False,
                        help="suppress all warnings")
    parser.add_argument('-d',
                        '--debug',
                        action='store_true',
                        default=False,
                        help="show stack trace in the event of "
                        "an uncaught exception")
    parser.add_argument('--no-progress-bar',
                        action='store_true',
                        default=False,
                        help="do not show the progress bar")
    parser.add_argument('--ignore-exception',
                        action='store_true',
                        default=False,
                        help="ignore exceptions raised in converting trees "
                        "and instead skip such trees")
    parser.add_argument('files', nargs='+')
    args = parser.parse_args()

    rootpy.log.basic_config_colorized()
    import logging
    if hasattr(logging, 'captureWarnings'):
        logging.captureWarnings(True)

    def formatwarning(message, category, filename, lineno, line=None):
        return "{0}: {1}".format(category.__name__, message)

    warnings.formatwarning = formatwarning
    args.ext = args.ext.strip('.')

    if args.quiet:
        warnings.simplefilter("ignore", RootNumpyUnconvertibleWarning)
        warnings.simplefilter("ignore", tables.NaturalNameWarning)

    userfunc = None
    if args.script is not None:
        # get user-defined function
        try:
            exec(compile(open(args.script).read(), args.script, 'exec'),
                 globals(), locals())
        except IOError:
            sys.exit('Could not open script {0}'.format(args.script))
        funcname = os.path.splitext(os.path.basename(args.script))[0]
        try:
            userfunc = locals()[funcname]
        except KeyError:
            sys.exit(
                "Could not find the function '{0}' in the script {1}".format(
                    funcname, args.script))

    for inputname in args.files:
        outputname = os.path.splitext(inputname)[0] + '.' + args.ext
        output_exists = os.path.exists(outputname)
        if output_exists and not (args.force or args.update):
            sys.exit(
                "Output {0} already exists. "
                "Use the --force option to overwrite it".format(outputname))
        try:
            rootfile = root_open(inputname)
        except IOError:
            sys.exit("Could not open {0}".format(inputname))
        try:
            if args.complevel > 0:
                filters = tables.Filters(complib=args.complib,
                                         complevel=args.complevel)
            else:
                filters = None
            hd5file = tables_open(filename=outputname,
                                  mode='a' if args.update else 'w',
                                  title='Data',
                                  filters=filters)
        except IOError:
            sys.exit("Could not create {0}".format(outputname))
        try:
            log.info("Converting {0} ...".format(inputname))
            root2hdf5(rootfile,
                      hd5file,
                      entries=args.entries,
                      userfunc=userfunc,
                      selection=args.selection,
                      show_progress=not args.no_progress_bar,
                      ignore_exception=args.ignore_exception)
            log.info("{0} {1}".format(
                "Updated" if output_exists and args.update else "Created",
                outputname))
        except KeyboardInterrupt:
            log.info("Caught Ctrl-c ... cleaning up")
            hd5file.close()
            rootfile.Close()
            if not output_exists:
                log.info("Removing {0}".format(outputname))
                os.unlink(outputname)
            sys.exit(1)
        except Exception as e:
            if args.debug:
                # If in debug mode show full stack trace
                import traceback
                traceback.print_exception(*sys.exc_info())
            log.error(str(e))
            sys.exit(1)
        finally:
            hd5file.close()
            rootfile.Close()
Exemple #6
0
def main():

    from rootpy.extern.argparse import (ArgumentParser,
                                        ArgumentDefaultsHelpFormatter,
                                        RawTextHelpFormatter)

    class formatter_class(ArgumentDefaultsHelpFormatter, RawTextHelpFormatter):
        pass

    parser = ArgumentParser(formatter_class=formatter_class)
    parser.add_argument('-n',
                        '--entries',
                        type=int,
                        default=1E5,
                        help="number of entries to read at once")
    parser.add_argument('-f',
                        '--force',
                        action='store_true',
                        default=False,
                        help="overwrite existing output files")
    parser.add_argument('--ext', default='h5', help="output file extension")
    parser.add_argument('-c',
                        '--complevel',
                        type=int,
                        default=5,
                        choices=range(0, 10),
                        help="compression level")
    parser.add_argument('-l',
                        '--complib',
                        default='zlib',
                        choices=('zlib', 'lzo', 'bzip2', 'blosc'),
                        help="compression algorithm")
    parser.add_argument(
        '-s',
        '--selection',
        default=None,
        help="apply a selection on each tree with a cut expression")
    parser.add_argument(
        '--script',
        default=None,
        help="Python script containing a function with the same name \n"
        "that will be called on each tree and must return a tree or \n"
        "list of trees that will be converted instead of the \n"
        "original tree")
    parser.add_argument('-q',
                        '--quiet',
                        action='store_true',
                        default=False,
                        help="suppress all warnings")
    parser.add_argument('files', nargs='+')
    args = parser.parse_args()

    import rootpy
    rootpy.log.basic_config_colorized()
    import logging
    if hasattr(logging, 'captureWarnings'):
        logging.captureWarnings(True)

    def formatwarning(message, category, filename, lineno, line=None):
        return "{0}: {1}".format(category.__name__, message)

    warnings.formatwarning = formatwarning
    args.ext = args.ext.strip('.')

    if args.quiet:
        warnings.simplefilter("ignore", RootNumpyUnconvertibleWarning)

    userfunc = None
    if args.script is not None:
        # get user-defined function
        try:
            exec(compile(open(args.script).read(), args.script, 'exec'),
                 globals(), locals())
        except IOError:
            sys.exit('Could not open script %s' % args.script)
        funcname = os.path.splitext(os.path.basename(args.script))[0]
        try:
            userfunc = locals()[funcname]
        except KeyError:
            sys.exit("Could not find the function '%s' in the script %s" %
                     (funcname, args.script))

    for inputname in args.files:
        outputname = os.path.splitext(inputname)[0] + '.' + args.ext
        if os.path.exists(outputname) and not args.force:
            sys.exit(('Output %s already exists. '
                      'Use the --force option to overwrite it') % outputname)
        try:
            rootfile = root_open(inputname)
        except IOError:
            sys.exit("Could not open %s" % inputname)
        try:
            if args.complevel > 0:
                filters = tables.Filters(complib=args.complib,
                                         complevel=args.complevel)
            else:
                filters = None
            hd5file = tables.openFile(filename=outputname,
                                      mode='w',
                                      title='Data',
                                      filters=filters)
        except IOError:
            sys.exit("Could not create %s" % outputname)
        try:
            log.info("Converting %s ..." % inputname)
            convert(rootfile,
                    hd5file,
                    entries=args.entries,
                    userfunc=userfunc,
                    selection=args.selection)
            log.info("Created %s" % outputname)
        except KeyboardInterrupt:
            log.info("Caught Ctrl-c ... cleaning up")
            os.unlink(outputname)
            break
        finally:
            hd5file.close()
            rootfile.Close()