File: RangeSplitter.h

package info (click to toggle)
snap-aligner 2.0.3%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 6,652 kB
  • sloc: cpp: 41,051; ansic: 5,239; python: 227; makefile: 85; sh: 28
file content (132 lines) | stat: -rw-r--r-- 3,763 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*++

Module Name:

    RangeSplitter.h

Abstract:

    Headers for code to split a range into pieces for multiple cores to process.  It's designed
    to handle cores that proceed at varying rates.

Authors:

    Bill Bolosky, 2011

Environment:

    User mode service.

Revision History:

    Pulled out of cSNAP.cpp to make it useful for various versions of the aligner
    Generalized from FileSplitter to ranges, e.g. for scanning the genome /ravip/5/2012/

--*/

#pragma once

#include "Compat.h"
#include "Read.h"
#include "Genome.h"
#include "AlignerOptions.h"

//
// Utility class for letting multiple threads split chunks of a range to process.
// This is used by the parallel versions of the aligners.
//
class RangeSplitter
{
public:
    RangeSplitter(_int64 rangeEnd_, int numThreads_, unsigned divisonSize_ = 5, _int64 rangeBegin_ = 0, unsigned minMillis_ = 200, unsigned minRangeSize_ = 32768);

    // Get the next range for a thread to process, or return false if the whole range is done.
    bool getNextRange(_int64 *rangeStart, _int64 *rangeLength);

private:
    int numThreads;
    _int64 rangeBegin;
    _int64 rangeEnd;
    unsigned divisionSize;
    unsigned minMillis;
    unsigned minRangeSize;
    volatile _int64 position;
    volatile _int64 startTime;
};

class RangeSplittingReadSupplier : public ReadSupplier {
public:
    RangeSplittingReadSupplier(RangeSplitter *i_splitter, ReadReader *i_underlyingReader) : 
      splitter(i_splitter), underlyingReader(i_underlyingReader), read() {}

    virtual ~RangeSplittingReadSupplier();

    Read *getNextRead();
 
    virtual void holdBatch(DataBatch batch)
    { underlyingReader->holdBatch(batch); }
    
    virtual bool releaseBatch(DataBatch batch)
    { return underlyingReader->releaseBatch(batch); }

private:
    RangeSplitter *splitter;
    ReadReader *underlyingReader;
    Read read;
};

class RangeSplittingReadSupplierGenerator: public ReadSupplierGenerator {
public:
    RangeSplittingReadSupplierGenerator(const char *i_fileName, bool i_isSAM, unsigned numThreads, const ReaderContext& context);
    ~RangeSplittingReadSupplierGenerator() {delete splitter; delete [] fileName;}

    ReadSupplier *generateNewReadSupplier();
    ReaderContext* getContext() { return &context; }

private:
    RangeSplitter *splitter;
    char *fileName;
    const bool isSAM;
    const int numThreads;
    ReaderContext context;
};


class RangeSplittingPairedReadSupplier : public PairedReadSupplier {
public:
    RangeSplittingPairedReadSupplier(RangeSplitter *i_splitter, PairedReadReader *i_underlyingReader) : splitter(i_splitter), underlyingReader(i_underlyingReader) {}
    virtual ~RangeSplittingPairedReadSupplier();

    virtual bool getNextReadPair(Read **read1, Read **read2);
       
    virtual void holdBatch(DataBatch batch)
    { underlyingReader->releaseBatch(batch); }

    virtual bool releaseBatch(DataBatch batch)
    { return underlyingReader->releaseBatch(batch); }

 private:
    PairedReadReader *underlyingReader;
    RangeSplitter *splitter;
    Read internalRead1;
    Read internalRead2;
 };

class RangeSplittingPairedReadSupplierGenerator: public PairedReadSupplierGenerator {
public:
    RangeSplittingPairedReadSupplierGenerator(const char *i_fileName1, const char *i_fileName2, enum FileType i_fileType, unsigned numThreads, bool i_quicklyDropUnpairedReads, const ReaderContext& context);
    ~RangeSplittingPairedReadSupplierGenerator();

    PairedReadSupplier *generateNewPairedReadSupplier();
    ReaderContext* getContext() { return &context; }

private:
    RangeSplitter *splitter;
    char *fileName1;
    char *fileName2;
    const int numThreads;
    enum FileType fileType;
    ReaderContext context;
    bool quicklyDropUnpairedReads;
};