def _day_loop(detection_streams, template, min_cc, detections,<EOL>horizontal_chans, vertical_chans, interpolate, cores, parallel,<EOL>debug=<NUM_LIT:0>):
if len(detection_streams) == <NUM_LIT:0>:<EOL><INDENT>return Catalog()<EOL><DEDENT>if not cores:<EOL><INDENT>num_cores = cpu_count()<EOL><DEDENT>else:<EOL><INDENT>num_cores = cores<EOL><DEDENT>if num_cores > len(detection_streams):<EOL><INDENT>num_cores = len(detection_streams)<EOL><DEDENT>if parallel:<EOL><INDENT>pool = Pool(processes=num_cores)<EOL>debug_print('<STR_LIT>' % num_cores, <NUM_LIT:4>, debug)<EOL>results = [pool.apply_async(<EOL>_channel_loop, (detection_streams[i], ),<EOL>{'<STR_LIT>': template, '<STR_LIT>': min_cc,<EOL>'<STR_LIT>': detections[i].id, '<STR_LIT>': interpolate,<EOL>'<STR_LIT:i>': i, '<STR_LIT>': detections[i].detect_val,<EOL>'<STR_LIT>': detections[i].no_chans,<EOL>'<STR_LIT>': horizontal_chans,<EOL>'<STR_LIT>': vertical_chans})<EOL>for i in range(len(detection_streams))]<EOL>pool.close()<EOL>try:<EOL><INDENT>events_list = [p.get() for p in results]<EOL><DEDENT>except KeyboardInterrupt as e:  <EOL><INDENT>pool.terminate()<EOL>raise e<EOL><DEDENT>pool.join()<EOL>events_list.sort(key=lambda tup: tup[<NUM_LIT:0>])  <EOL><DEDENT>else:<EOL><INDENT>events_list = []<EOL>for i in range(len(detection_streams)):<EOL><INDENT>events_list.append(_channel_loop(<EOL>detection=detection_streams[i], template=template,<EOL>min_cc=min_cc, detection_id=detections[i].id,<EOL>interpolate=interpolate, i=i,<EOL>pre_lag_ccsum=detections[i].detect_val,<EOL>detect_chans=detections[i].no_chans,<EOL>horizontal_chans=horizontal_chans,<EOL>vertical_chans=vertical_chans, debug=debug))<EOL><DEDENT><DEDENT>temp_catalog = Catalog()<EOL>temp_catalog.events = [event_tup[<NUM_LIT:1>] for event_tup in events_list]<EOL>return temp_catalog<EOL>
Function to loop through multiple detections for one template.

Designed to run for the same day of data for I/O simplicity, but as you
are passing stream objects it could run for all the detections ever, as
long as you have the RAM!

:type detection_streams: list
:param detection_streams:
    List of all the detections for this template that you want to compute
    the optimum pick for. Individual things in list should be of
    :class:`obspy.core.stream.Stream` type.
:type template: obspy.core.stream.Stream
:param template: The original template used to detect the detections passed
:type min_cc: float
:param min_cc: Minimum cross-correlation value to be allowed for a pick.
:type detections: list
:param detections:
    List of detections to associate events with an input detection.
:type horizontal_chans: list
:param horizontal_chans:
    List of channel endings for horizontal-channels, on which S-picks will
    be made.
:type vertical_chans: list
:param vertical_chans:
    List of channel endings for vertical-channels, on which P-picks will
    be made.
:type interpolate: bool
:param interpolate:
    Interpolate the correlation function to achieve sub-sample precision.
:type debug: int
:param debug: debug output level 0-5.

:returns:
    Catalog object containing Event objects for each detection created by
    this template.
:rtype: :class:`obspy.core.event.Catalog`