Search in sources :

Example 1 with ThreadSafeIntCounter

use of uk.ac.babraham.SeqMonk.Utilities.ThreadSafeIntCounter in project SeqMonk by s-andrews.

the class DataSet method finalise.

/**
 * This call optimises the data structure from a flexible structure
 * which can accept more data, to a fixed structure optimised for
 * size and speed of access.  If required it can also cache the data
 * to disk.
 *
 * This call should only be made by DataParsers who know that no
 * more data will be added.
 */
public synchronized void finalise() {
    if (isFinalised)
        return;
    // To make querying the data more efficient we're going to convert
    // all of the vectors in our data structure into SequenceRead arrays
    // which are sorted by start position.  This means that subsequent
    // access will be a lot more efficient.
    Enumeration<Chromosome> e = readData.keys();
    chromosomesStillToFinalise = new ThreadSafeIntCounter();
    while (e.hasMoreElements()) {
        while (chromosomesStillToFinalise.value() >= MAX_CONCURRENT_FINALISE) {
            try {
                Thread.sleep(20);
            } catch (InterruptedException ex) {
            }
        }
        Chromosome c = e.nextElement();
        chromosomesStillToFinalise.increment();
        readData.get(c).finalise();
    }
    while (chromosomesStillToFinalise.value() > 0) {
        try {
            Thread.sleep(20);
        } catch (InterruptedException ex) {
        }
    }
    isFinalised = true;
}
Also used : Chromosome(uk.ac.babraham.SeqMonk.DataTypes.Genome.Chromosome) ThreadSafeIntCounter(uk.ac.babraham.SeqMonk.Utilities.ThreadSafeIntCounter)

Example 2 with ThreadSafeIntCounter

use of uk.ac.babraham.SeqMonk.Utilities.ThreadSafeIntCounter in project SeqMonk by s-andrews.

the class PairedDataSet method finalise.

/**
 * This call optimises the data structure from a flexible structure
 * which can accept more data, to a fixed structure optimised for
 * size and speed of access.  If required it can also cache the data
 * to disk.
 *
 * This call should only be made by DataParsers who know that no
 * more data will be added.
 */
public synchronized void finalise() {
    if (isFinalised)
        return;
    // To make querying the data more efficient we're going to convert
    // all of the vectors in our data structure into SequenceRead arrays
    // which are sorted by start position.  This means that subsequent
    // access will be a lot more efficient.
    long finaliseStartTime = System.currentTimeMillis();
    Enumeration<Chromosome> e = readData.keys();
    chromosomesStillToFinalise = new ThreadSafeIntCounter();
    while (e.hasMoreElements()) {
        while (chromosomesStillToFinalise.value() >= MAX_CONCURRENT_FINALISE) {
            try {
                Thread.sleep(20);
            } catch (InterruptedException ex) {
            }
        }
        Chromosome c = e.nextElement();
        chromosomesStillToFinalise.increment();
        readData.get(c).finalise();
    }
    while (chromosomesStillToFinalise.value() > 0) {
        try {
            Thread.sleep(20);
        } catch (InterruptedException ex) {
        }
    }
    isFinalised = true;
    long finaliseEndTime = System.currentTimeMillis();
    // Finally, now that we've sent all of the correct data up to the superclass
    // we can let that finalise itself.
    long superSubEndTime = System.currentTimeMillis();
    super.finalise();
    long superFinaliseEndTime = System.currentTimeMillis();
    System.err.println("HiC finalise=" + ((finaliseEndTime - finaliseStartTime) / 1000d) + " super submit=" + ((superSubEndTime - finaliseEndTime) / 1000d) + " super finalise=" + ((superFinaliseEndTime - superSubEndTime) / 1000d));
}
Also used : Chromosome(uk.ac.babraham.SeqMonk.DataTypes.Genome.Chromosome) NonThreadSafeIntCounter(uk.ac.babraham.SeqMonk.Utilities.NonThreadSafeIntCounter) ThreadSafeIntCounter(uk.ac.babraham.SeqMonk.Utilities.ThreadSafeIntCounter)

Aggregations

Chromosome (uk.ac.babraham.SeqMonk.DataTypes.Genome.Chromosome)2 ThreadSafeIntCounter (uk.ac.babraham.SeqMonk.Utilities.ThreadSafeIntCounter)2 NonThreadSafeIntCounter (uk.ac.babraham.SeqMonk.Utilities.NonThreadSafeIntCounter)1