def i3extract(infile, outfile=None):
    """Main event loop"""
    if outfile is None:
        outfile = infile + '.h5'
    tray = I3Tray()
    tray.AddModule('I3Reader', 'i3_reader', filename=infile)
    # tray.AddModule(KeepReconstructed, "event_selector")
    tray.AddModule(ReadEventMeta, 'read_meta')    # grab the event ID
    tray.AddModule(
        Distance,
        "compare_space",
        particle_1="best_FirstDusjOrcaVertexFit_FitResult",
        particle_2="best_SecondDusjOrcaVertexFit_FitResult"
    )
    tray.AddModule(
        TimeDistance,
        "compare_time",
        particle_1="best_FirstDusjOrcaVertexFit_FitResult",
        particle_2="best_SecondDusjOrcaVertexFit_FitResult",
    )
    tray.AddModule(
        ReadRecoParticle,
        'read_particle_first',
        ParticleName='best_FirstDusjOrcaVertexFit_FitResult'
    )
    tray.AddModule(
        ReadRecoParticle,
        'read_particle_second',
        ParticleName='best_SecondDusjOrcaVertexFit_FitResult'
    )
    tray.AddModule(
        ReadRecoParticle,
        'read_particle_proba',
        ParticleName='best_DusjOrcaUsingProbabilitiesFinalFit_FitResult'
    )    # noqa
    tray.AddModule(
        ReadLLHValues,
        'read_llh_chere',
        LLHParamContainer=
        'best_DusjOrcaUsingProbabilitiesFinalFit_FitResult_FinalLLHValues'
    )    # noqa
    tray.AddModule(WriteScalars, 'write_scalars', filename=outfile)
    tray.AddModule('TrashCan', 'dustbin')
    tray.Execute()
    tray.Finish()
Main event loop