logger.info("waiting %.2f seconds until we pass gps=%.3f" %
                (wait, gps_end))
    time.sleep(wait)

if options.realtime_log:
    ### now we need to parse the realtime log to figure out where the realtime job is
    logger.info("parsing %s to extract idq-realtime state" %
                options.realtime_log)

    realtime_log = open(options.realtime_log,
                        "r")  ### open realtime log for reading
    realtime_log.seek(0, 2)  ### go to end of file

    ### wait until realtime has passed gps_end+delay
    past, dead, timed_out = idq.block_until(gps_end,
                                            realtime_log,
                                            max_wait=max_wait,
                                            timeout=2 * max_wait)

    if past:
        logger.info("found realtime stride starting after t=%.3f" % (gps_end))

    elif timed_out:
        logger.info(
            "WARNING: could not find a recent enough stride in %s after searching for %.1f seconds. Realtime process may be behind"
            % (options.realtime_log, 2 * max_wait))
        if not options.skip_gracedb_upload:
            gracedb.writeLog(
                gdb_id,
                message=
                "WARNING: iDQ data quality coverage was not complete and no new information was reported after waiting %.1f seconds. Data quality information at %s may not be complete."
                % (2 * max_wait, ifo),
#=================================================
### figure out if we need to wait for time to pass
wait = gps_end - (idq.nowgps()+delay)
if wait > 0:
    logger.info("waiting %.2f seconds until we pass gps=%.3f"%(wait, gps_end))
    time.sleep(wait)

if options.realtime_log:
    ### now we need to parse the realtime log to figure out where the realtime job is
    logger.info("parsing %s to extract idq-realtime state"%options.realtime_log)

    realtime_log = open(options.realtime_log, "r") ### open realtime log for reading
    realtime_log.seek(0, 2) ### go to end of file

    ### wait until realtime has passed gps_end+delay
    past, dead, timed_out = idq.block_until(gps_end, realtime_log, max_wait=max_wait, timeout=2*max_wait)

    if past:
        logger.info("found realtime stride starting after t=%.3f"%(gps_end))

    elif timed_out:
        logger.info("WARNING: could not find a recent enough stride in %s after searching for %.1f seconds. Realtime process may be behind"%(options.realtime_log, 2*max_wait))
        if not options.skip_gracedb_upload:
            gracedb.writeLog(gdb_id, message="WARNING: iDQ data quality coverage was not complete and no new information was reported after waiting %.1f seconds. Data quality information at %s may not be complete."%(2*max_wait, ifo))

    else: # dead
        logger.info("WARNING: no new iDQ information was reported to %s after waiting %.1f seconds. Realtime process may be dead."%(options.realtime_log, max_wait))
        if not options.skip_gracedb_upload:
            gracedb.writeLog(gdb_id, message="WARNING: iDQ data quality coverage was not complete and no new information was reported after waiting %.1f seconds. Data quality information at %s may not be complete."%(max_wait, ifo))
else:
    logger.info("no idq-realtime.log provided. Proceeding without checking idq-realtime state")
if not opts.ignore_science_segments:
    ### load settings for accessing dmt segment files
    dq_name = config.get('get_science_segments', 'include')
    segdb_url = config.get('get_science_segments', 'segdb')

#========================
### wait for realtime.log to pass endgps

if opts.realtime_log:
    logger.info("parsing %s to extract idq-realtime state"%opts.realtime_log)

    realtime_log = open(realtime_log, "r") ### open realtime log for reading
    realtime_log.seek(0, 2) ### go to end of file

    ### wait until realtime has passed gps_end+delay
    past, dead, timed_out = idq.block_until(endgps+opts.left_padding-opts.t_lag, realtime_log, max_wait=opts.max_wait, timeout=2*opts.max_wait)

    if past:
        logger.info("found realtime stride starting after t=%.3f+%.3f-%.3f"%(endgps,opts.left_padding,opts.t_lag))
    elif timed_out:
        logger.info("WARNING: could not find a recent enough stride in %s after searching for %.1f seconds. Realtime process may be behind"%(opts.realtime_log, 2*opts.max_wait))
    else: # dead
        logger.info("WARNING: no new iDQ information was reported to %s after waiting %.1f seconds. Realtime process may be dead."%(opts.realtime_log, opts.max_wait))

#===================================================================================================
### begin the analysis

stride = endgps - startgps

lookup_startgps = startgps - opts.right_padding - opts.t_lag
lookup_endgps = endgps + opts.left_padding - opts.t_lag
    dq_name = config.get('get_science_segments', 'include')
    segdb_url = config.get('get_science_segments', 'segdb')

#========================
### wait for realtime.log to pass endgps

if opts.realtime_log:
    logger.info("parsing %s to extract idq-realtime state" % opts.realtime_log)

    realtime_log = open(realtime_log, "r")  ### open realtime log for reading
    realtime_log.seek(0, 2)  ### go to end of file

    ### wait until realtime has passed gps_end+delay
    past, dead, timed_out = idq.block_until(endgps + opts.left_padding -
                                            opts.t_lag,
                                            realtime_log,
                                            max_wait=opts.max_wait,
                                            timeout=2 * opts.max_wait)

    if past:
        logger.info("found realtime stride starting after t=%.3f+%.3f-%.3f" %
                    (endgps, opts.left_padding, opts.t_lag))
    elif timed_out:
        logger.info(
            "WARNING: could not find a recent enough stride in %s after searching for %.1f seconds. Realtime process may be behind"
            % (opts.realtime_log, 2 * opts.max_wait))
    else:  # dead
        logger.info(
            "WARNING: no new iDQ information was reported to %s after waiting %.1f seconds. Realtime process may be dead."
            % (opts.realtime_log, opts.max_wait))