def write_hits_in_events(hit_table_in, hit_table_out, events, start_hit_word=<NUM_LIT:0>, chunk_size=<NUM_LIT>, condition=None):
if len(events) > <NUM_LIT:0>:  <EOL><INDENT>min_event = np.amin(events)<EOL>max_event = np.amax(events)<EOL>logging.debug("<STR_LIT>" % (start_hit_word, len(events), min_event, max_event))<EOL>table_size = hit_table_in.shape[<NUM_LIT:0>]<EOL>iHit = <NUM_LIT:0><EOL>for iHit in range(start_hit_word, table_size, chunk_size):<EOL><INDENT>hits = hit_table_in.read(iHit, iHit + chunk_size)<EOL>last_event_number = hits[-<NUM_LIT:1>]['<STR_LIT>']<EOL>hit_table_out.append(get_hits_in_events(hits, events=events, condition=condition))<EOL>if last_event_number > max_event:  <EOL><INDENT>return iHit<EOL><DEDENT><DEDENT><DEDENT>return start_hit_word<EOL>
Selects the hits that occurred in events and writes them to a pytable. This function reduces the in RAM operations and has to be
    used if the get_hits_in_events function raises a memory error. Also a condition can be set to select hits.

    Parameters
    ----------
    hit_table_in : pytable.table
    hit_table_out : pytable.table
        functions need to be able to write to hit_table_out
    events : array like
        defines the events to be written from hit_table_in to hit_table_out. They do not have to exists at all.
    start_hit_word: int
        Index of the first hit word to be analyzed. Used for speed up.
    chunk_size : int
        defines how many hits are analyzed in RAM. Bigger numbers increase the speed, too big numbers let the program crash with a memory error.
    condition : string
        A condition that is applied to the hits in numexpr style. Only if the expression evaluates to True the hit is taken.

    Returns
    -------
    start_hit_word: int
        Index of the last hit word analyzed. Used to speed up the next call of write_hits_in_events.