def rapidpe_to_hdf(basegrp, bankfile, samplefiles):
    # import (or look up template bank)
    #bank_xmldoc = utils.load_filename(args.tmplt_bank_file, contenthandler=ligolw.LIGOLWContentHandler)
    bank_xmldoc = utils.load_filename(bankfile, contenthandler=ligolw.LIGOLWContentHandler)
    try:
        tmplt_bank = lsctables.SimInspiralTable.get_table(bank_xmldoc)
    except:
        tmplt_bank = lsctables.SnglInspiralTable.get_table(bank_xmldoc)

    for sample_file in samplesfiles:
        print "Processing %s" % sample_file

        # Get tables from xmldoc
        xmldoc = utils.load_filename(sample_file, contenthandler=ligolw.LIGOLWContentHandler)
        process_params = lsctables.ProcessParamsTable.get_table(xmldoc)
        samples = lsctables.SimInspiralTable.get_table(xmldoc)
        run_result = lsctables.SnglInspiralTable.get_table(xmldoc)[0]

        # Get intrinsic parameter used
        intr_prms = get_intr_prms_from_pp_table(process_params)

        # Identify intrinisic ID
        tmplt_id = obtain_tmplt_id(tmplt_bank, **intr_prms)

        # Append sample data and metadata
        subgrp = base_grp.create_group(str(tmplt_id))
        xmlutils.append_samples_to_hdf5_group(subgrp, samples)

        def pp_table_to_dict(pptable):
            return dict([(pp.param, pp.value) for pp in pptable])

        run_info = pp_table_to_dict(process_params)
        for key in ("snr", "tau0", "ttotal"):
            run_info[KEY_MAPPING[key]] = getattr(run_result, key)

        xmlutils.append_metadata_to_hdf5_group(subgrp, run_info)

        xmldoc.unlink()
def txt_to_hdf(basegrp, samplefile):

    samplefile = samplefile[0]
    print "Processing %s" % samplefile

    samples = numpy.genfromtxt(samplefile, names=True)

    # Append sample data and metadata
    #subgrp = base_grp.create_group(str(tmplt_id))
    subgrp = base_grp.create_group("run_identifier")
    append_lalinf_samples_to_hdf5_group(subgrp, samples)

    return
    def pp_table_to_dict(pptable):
        return dict([(pp.param, pp.value) for pp in pptable])

    run_info = pp_table_to_dict(process_params)
    for key in ("snr", "tau0", "ttotal"):
        run_info[KEY_MAPPING[key]] = getattr(run_result, key)

    xmlutils.append_metadata_to_hdf5_group(subgrp, run_info)

    xmldoc.unlink()