def METHOD_NAME(root_files, raw_file=None, n_max=None, config=None, verbose=False, buffer_size=1024, chans=None, tree_name='MGTree'):
    # Load up the tree (or trees)
    ch = ROOT.TChain(tree_name)
    if isinstance(root_files, str):
        ch.Add(root_files)
    else:
        for root_file in raw_files:
            ch.Add(raw_file)
    dec = MGDODecoder(buffer_size)
    lh5_st = lh5.Store()
    if not raw_file:
        raw_file = root_files.replace('.root', '.lh5')
    tables = {} # map from detector channel to output table
    n_tot = 0 # total waveforms
    # loop through MGTEvents in ttree
    for event in ch:
        # loop through waveforms in event
        for i_wf in range(event.event.GetNWaveforms()):
            # Get digitizer data, waveform and auxwaveform (if applicable)
            dd = event.event.GetDigitizerData(i_wf)
            wf = event.event.GetWaveform(i_wf)
            auxwf = event.event.GetAuxWaveform(i_wf) if event.event.GetAuxWaveformArrayStatus() else None
            # Get the output table for this channel
            tb = tables.get(dd.GetID(), None)
            if not tb:
                if verbose:
                    print('Create table for channel', dd.GetID())
                tb = dec.get_table(dd, wf, auxwf)
                tables[dd.GetID()]=tb
            i_chan = tb.loc
            dec.read_waveform(tb, dd, wf, auxwf)
            # write table if it is full
            tb.push_row()
            if tb.is_full():
                lh5_st.write_object( tb, 'g{:04d}/raw'.format(dd.GetID()), raw_file, n_rows = tb.loc )
                tb.clear()
            n_tot += 1
        # check if we have hit n_wf limit. Note that we always include all WFs in an event, which can result in including a few extra waveforms
        if n_max and n_tot >= n_max:
            break
    # Fill remaining events for each table
    for channel, tb in tables.items():
        if verbose:
            print('Wrote to', 'g{:04d}/raw'.format(channel), 'in', raw_file)
        lh5_st.write_object( tb, 'g{:04d}/raw'.format(channel), raw_file, n_rows = tb.loc)
        tb.clear()