15 #include "stream_tools.h"
19 #define LZ4_BUFFER_SIZE 2000000000
20 #define CACHE_SIZE 4000000000
27 size_t size_, sites_, cached_sites_;
35 size_t size_, sites_, cached_sites_, block_size_, lz4_buffer_size_;
36 bool streaming_, cached_, transposed_, masked_;
38 char *lz4_ptr_, *lz4_start_, *lz4_end_, *lz4_last_, *temp_lz4_ptr_;
42 static Data * create(
const std::vector <std::string> & Columns){
43 return new State(Columns);
46 void increase_buffer_(
void);
48 void uncompress_ (
char *&, uint32_t *&, uint32_t *&)
const;
49 void compress_ (
char *&,
char *&,
const uint32_t *a,
const uint32_t *b)
const;
51 void uncompress_ (
char *&)
const;
52 void compress_ (
char *&,
char *&)
const;
54 inline void set_private_(
const State &rhs)
58 cached_sites_=rhs.cached_sites_;
59 block_size_=rhs.block_size_;
60 lz4_buffer_size_=rhs.lz4_buffer_size_;
61 streaming_=rhs.streaming_;
63 transposed_=rhs.transposed_;
70 State(
const std::vector <std::string> &);
74 std::cerr <<
"Copy constructor called from:" << size_t(&rhs) <<
" to " << size_t (
this) <<
" lz4_buffer_size: " << lz4_buffer_size_ << std::endl;
75 std::cerr <<
"Some addressed: " << size_t (rhs.lz4_start_) <<
" and " << size_t (lz4_start_) << std::endl;
76 lz4_buffer_size_=rhs.lz4_buffer_size_;
78 lz4_start_ =
new char [lz4_buffer_size_];
79 std::cerr <<
"Allocating " << size_t(lz4_start_) <<
", " << lz4_buffer_size_ << std::endl;
80 lz4_end_ = lz4_start_ + lz4_buffer_size_;
81 lz4_last_ = lz4_start_+(rhs.lz4_last_-rhs.lz4_start_);
82 memcpy(lz4_start_, rhs.lz4_start_, rhs.lz4_end_-rhs.lz4_start_);
89 std::cerr <<
"Move constructor called from " << size_t(lz4_start_) <<
" to " << size_t(rhs.lz4_start_) << std::endl;
92 lz4_buffer_size_=rhs.lz4_buffer_size_;
93 lz4_start_ = rhs.lz4_start_;
94 lz4_end_ = rhs.lz4_end_;
95 lz4_last_ = rhs.lz4_last_;
99 rhs.lz4_start_ =
nullptr;
100 rhs.lz4_end_ =
nullptr;
101 rhs.lz4_last_ =
nullptr;
107 std::cerr <<
"Assignment constructor called " << std::endl;
110 if (lz4_start_)
delete [] lz4_start_;
111 std::cerr <<
"Some addressed: " << size_t (rhs.lz4_start_) <<
" and " << size_t (lz4_start_) << std::endl;
112 std::cerr <<
"Assign from:" << size_t(&rhs) <<
" to " << size_t (
this) <<
" lz4_buffer_size: " << lz4_buffer_size_ << std::endl;
113 lz4_buffer_size_=rhs.lz4_buffer_size_;
115 lz4_start_ =
new char [lz4_buffer_size_];
116 std::cerr <<
"Allocating " << size_t(lz4_start_) <<
", " << lz4_buffer_size_ <<
", " << size_t(rhs.lz4_last_-rhs.lz4_start_) <<
", " << size_t(rhs.lz4_end_-rhs.lz4_start_) << std::endl;
117 lz4_end_ = lz4_start_ + lz4_buffer_size_;
118 lz4_last_ = lz4_start_+(rhs.lz4_last_-rhs.lz4_start_);
119 memcpy(lz4_start_, rhs.lz4_start_, rhs.lz4_end_-rhs.lz4_start_);
127 State(
const uint32_t &);
128 State(
const uint32_t &,
const uint32_t &,
const uint32_t &);
131 void set_k(
const uint8_t &);
132 uint8_t get_k (
void)
const;
136 void uncompress (uint32_t *a, uint32_t *b);
137 void uncompress_inplace (uint32_t *a, uint32_t *b);
138 void uncompress (uint32_t *a, uint32_t *b,
const uint32_t &k);
139 void uncompress (uint32_t *a, uint32_t *b,
State_stream &)
const;
141 void compress (
const uint32_t *a,
const uint32_t *b);
142 void compress_inplace (
const uint32_t *a,
const uint32_t *b);
144 void uncompress (uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d);
145 void uncompress_inplace (uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d);
146 void uncompress (uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d,
const uint32_t &k);
147 void uncompress (uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d,
State_stream &)
const;
149 void compress (
const uint32_t *a,
const uint32_t *b,
const uint32_t *c,
const uint32_t *d);
150 void compress_inplace (
const uint32_t *a,
const uint32_t *b,
const uint32_t *c,
const uint32_t *d);
152 void transpose (
void);
157 void finalize (
void);
164 const std::string get_file_name()
const;
165 const std::string get_table_name()
const;
169 inline const size_t & sample_size(
void)
const {
return size_;};
170 inline const size_t & genome_size(
void)
const {
return sites_;};
171 inline void set_streaming(
const bool &b) {streaming_=b;};
173 void read(std::istream& str);
174 void write(std::ostream& str)
const;
176 void read_binary(std::istream& str);
177 void write_binary(std::ostream& str)
const;
179 std::string header()
const;
183 inline size_t get_free(
void)
const {
return (
size_t)(lz4_end_-lz4_last_); };
185 double compression_ratio(
void)
const;
186 size_t buffer_size(
void)
const;
188 bool empty(
void)
const;
189 bool cached(
void)
const;
191 inline void swap(
State &rhs)
193 std::cerr <<
"swapping " << size_t (rhs.lz4_start_) <<
" and " << size_t (lz4_start_) << std::endl;
195 std::swap(size_, rhs.size_);
196 std::swap(sites_, rhs.sites_);
197 std::swap(cached_sites_, rhs.cached_sites_);
198 std::swap(block_size_, rhs.block_size_);
199 std::swap(lz4_buffer_size_, rhs.lz4_buffer_size_);
200 std::swap(k_, rhs.k_);
202 std::swap(cached_, rhs.cached_);
203 std::swap(masked_, rhs.masked_);
204 std::swap(streaming_, rhs.streaming_);
205 std::swap(transposed_, rhs.transposed_);
207 std::swap(lz4_ptr_, rhs.lz4_ptr_);
208 std::swap(lz4_start_, rhs.lz4_start_);
209 std::swap(lz4_end_, rhs.lz4_end_);
210 std::swap(lz4_last_, rhs.lz4_last_);
216 State sub_sample(
const State &,
const size_t &,
const uint32_t *mask);
static const bool binary
Destination table in Db.
Definition: state.h:167
void read(std::istream &str)
The read function must be defined in the child class.
Definition: state.cc:779
void write(std::ostream &str) const
The write function must be defined in the child class.
Definition: state.cc:672
static const std::string file_name
The dafualt extention for files.
Definition: state.h:161
State()
constructor needed by map_file. String should be column names.
Definition: state.cc:9
A class which registers a child of Data in Data::new_data_.
Definition: data.h:222
A class which can be written as flat text file or into an SQL database.
Definition: data.h:34
static const std::string table_name
Destination table in Db.
Definition: state.h:162