event.andsegments([[idq.extract_start_stop(fap, suffix=".gwf")],
                               idqsegs]))
]

### compute total time covered
#T = event.livetime( [idq.extract_start_stop(fap, suffix='.gwf') for fap in faps] )*1.0
T = event.livetime(idqsegs) * 1.0

### combine timeseries and generate segments
if opts.verbose:
    print "generating segments from %d fap files" % (len(faps))
segs = dict((fapThr, [[], 1.0]) for fapThr in opts.FAPthr)
t, ts = idq.combine_gwf(faps, [fap_channame])
for t, ts in zip(t, ts):

    t, ts = idq.timeseries_in_segments(t, ts, idqsegs)

    for fapThr in opts.FAPthr:
        s, minFAP = idq.timeseries_to_segments(
            t, -ts, -fapThr)  # we want FAP <= FAPthr <--> -FAP >= -FAPthr
        s = event.andsegments(
            [s, idqsegs]
        )  ### necessary because of how timeseries_to_segments may interact with timeseries_in_segments

        segs[fapThr][0] += s
        if minFAP != None:
            segs[fapThr][1] = min(segs[fapThr][1], -minFAP)
if opts.verbose:
    print "computing associated deadtimes"
dt = [event.livetime(segs[fapThr][0]) / T for fapThr in opts.FAPthr]
maxFAP = [segs[fapThr][1] for fapThr in opts.FAPthr]
            cache = idq.cache(output_dir, classifier, "_rankcache%s"%usertag)
            logger.info('writing list of rank files to %s'%cache)
            f = open(cache, 'w')
            for rank in ranksD[classifier]:
                print >>f, rank
            f.close()

            logger.info('  analyzing rank timeseries to obtain mapping from rank->fap')

            ### load in timeseries
            _times, timeseries = idq.combine_ts(ranksD[classifier], n=1)

            times = []
            ranks = []
            for t, ts in zip(_times, timeseries):
                _t, _ts = idq.timeseries_in_segments(t, ts, idqsegs)
                if len(_ts):
                    times.append( _t )
                    ranks.append( _ts )

            ### need to compute deadsecs for every rank in r -> function call (probably within calibration module)!
            crank = []
            for _r in r:

                dsec = 0
                for t, ts in zip(times, ranks):
                    dt = t[1]-t[0] ### get time spacing.
                    dsec += calibration.timeseries_to_livetime(dt, ts, _r)[0] # we don't care about segments, so just get livetime and smallest stated value
                crank.append( dsec )
 
            ### dump uroc file