19 namespace illumina {
namespace interop {
namespace io
30 template<
class MetricType>
33 return paths::interop_filename<MetricType>(run_directory, use_out);
44 template<
class MetricType>
47 return paths::interop_basename<MetricType>(use_out);
54 template<
class MetricType,
typename OutputIterator>
58 typedef typename factory_t::metric_format_map metric_format_map;
59 metric_format_map &format_map = factory_t::metric_formats();
60 for(
typename metric_format_map::const_iterator it = format_map.begin();it != format_map.end();++it, ++oit)
62 if(it->second->is_deprecated())
continue;
72 template<
class MetricSet>
77 typedef typename factory_t::metric_format_map metric_format_map;
78 metric_format_map &format_map = factory_t::metric_formats();
80 const int version = in.get();
82 if (format_map.find(version) == format_map.end())
84 <<
" with version: " << version <<
" of "
85 << format_map.size() );
87 metrics.set_version(static_cast< ::int16_t>(version));
88 return format_map[version]->read_header(in, metrics);
98 template<
class MetricSet>
103 typedef typename factory_t::metric_format_map metric_format_map;
104 metric_format_map &format_map = factory_t::metric_formats();
106 const int version = in.get();
108 if (format_map.find(version) == format_map.end())
110 <<
" with version: " << version <<
" of "
111 << format_map.size() );
114 metrics.set_version(static_cast< ::int16_t>(version));
117 format_map[version]->read_metrics(in, metrics, file_size);
121 if(rebuild)metrics.rebuild_index();
124 if(rebuild)metrics.rebuild_index();
133 template<
class MetricType>
134 size_t record_size(
const typename MetricType::header_type &header,
135 const ::int16_t version = MetricType::LATEST_VERSION)
138 typedef typename factory_type::metric_format_map metric_format_map;
139 metric_format_map &format_map = factory_type::metric_formats();
141 if (format_map.find(version) == format_map.end())
143 version <<
" of " << format_map.size());
146 return format_map[version]->record_size(header);
155 template<
class MetricType,
class HeaderType>
157 const ::int16_t version = MetricType::LATEST_VERSION)
160 typedef typename factory_type::metric_format_map metric_format_map;
161 metric_format_map &format_map = factory_type::metric_formats();
163 if (format_map.find(version) == format_map.end())
165 version <<
" of " << format_map.size());
168 return format_map[version]->record_size(header);
176 template<
class MetricSet>
178 ::int16_t version = -1)
182 typedef typename factory_type::metric_format_map metric_format_map;
183 metric_format_map &format_map = factory_type::metric_formats();
184 if(version < 1) version = header.version();
186 if (format_map.find(version) == format_map.end())
188 version <<
" of " << format_map.size());
191 return format_map[version]->is_multi_record();
201 template<
class MetricSet>
203 ::int16_t version=-1)
207 typedef typename factory_type::metric_format_map metric_format_map;
208 if(version < 1) version = metric_set.version();
209 metric_format_map &format_map = factory_type::metric_formats();
210 if (format_map.find(version) == format_map.end())
212 << version <<
" of " << format_map.size());
215 return format_map[version]->buffer_size(metric_set);
225 template<
class MetricType,
class Header>
227 const ::int16_t version=MetricType::LATEST_VERSION)
230 typedef typename factory_type::metric_format_map metric_format_map;
231 metric_format_map &format_map = factory_type::metric_formats();
232 if (format_map.find(version) == format_map.end())
234 version <<
" of " << format_map.size());
237 return format_map[version]->header_size(header);
246 template<
class MetricSet>
248 ::int16_t version = -1)
251 if(version < 1) version = header.version();
252 return size_of_header<metric_t>(header, version);
262 template<
class MetricType>
264 const MetricType &metric,
265 const typename MetricType::header_type &header,
266 const ::int16_t version)
269 typedef typename factory_type::metric_format_map metric_format_map;
270 metric_format_map &format_map = factory_type::metric_formats();
272 if (format_map.find(version) == format_map.end())
274 version <<
" of " << format_map.size());
277 format_map[version]->write_metric(out, metric, header);
286 template<
class MetricType>
288 const ::int16_t version,
289 const typename MetricType::header_type &header =
typename MetricType::header_type())
292 typedef typename factory_type::metric_format_map metric_format_map;
293 metric_format_map &format_map = factory_type::metric_formats();
294 if (format_map.find(version) == format_map.end())
296 version <<
" of " << format_map.size());
299 format_map[version]->write_metric_header(out, header);
308 template<
class MetricSet>
309 static void write_metrics(std::ostream &out,
const MetricSet &metrics, ::int16_t version = -1)
312 typedef metric_format_factory<metric_type> factory_type;
313 typedef typename factory_type::metric_format_map metric_format_map;
314 metric_format_map &format_map = factory_type::metric_formats();
316 if (version < 0) version = metrics.version();
317 if (format_map.find(version) == format_map.end())
318 INTEROP_THROW(bad_format_exception,
"No format found to write file with version: " <<
319 version <<
" of " << format_map.size()
320 <<
" for " << metric_type::prefix() <<
"" << metric_type::suffix()
321 <<
" with " << metrics.size() <<
" metrics");
324 format_map[version]->write_metric_header(out, metrics);
325 for (
typename MetricSet::const_iterator it = metrics.begin();
326 it != metrics.end(); it++)
339 template<
class MetricSet>
340 static void write_text(std::ostream &out,
341 const MetricSet &metrics,
342 const std::vector<std::string>& channel_names,
343 ::int16_t version = -1,
346 const char missing=
'-')
349 typedef text_format_factory<metric_type> factory_type;
350 typedef typename factory_type::abstract_text_format_t* abstract_text_format_pointer_t;
352 factory_type &factory = factory_type::instance();
353 abstract_text_format_pointer_t
format = factory.find(version);
356 "No format found to write file with version: "
357 << version <<
" of " << factory.size()
358 <<
" for " << metric_type::prefix() <<
"" << metric_type::suffix()
359 <<
" with " << metrics.size() <<
" metrics");
361 format->write_header(out, metrics, channel_names, sep, eol);
362 for (
typename MetricSet::const_iterator it = metrics.begin();
363 it != metrics.end(); it++)
364 format->write_metric(out, *it, metrics, sep, eol, missing);
378 template<
class MetricType>
379 std::string
interop_filename(
const std::string &run_directory,
const size_t cycle,
bool use_out =
true)
381 return paths::interop_filename<MetricType>(run_directory, cycle, use_out);
void write_metric(std::ostream &out, const MetricType &metric, const typename MetricType::header_type &header, const ::int16_t version)
Definition: metric_stream.h:263
metric_type
Definition: enums.h:284
Definition: enum_description.h:15
void write_metric_header(std::ostream &out, const ::int16_t version, const typename MetricType::header_type &header=typename MetricType::header_type())
Definition: metric_stream.h:287
#define INTEROP_THROW(EXCEPTION, MESSAGE)
Definition: exception.h:18
size_t header_size(const MetricSet &header,::int16_t version=-1)
Definition: metric_stream.h:247
bool is_multi_record(const MetricSet &header,::int16_t version=-1)
Definition: metric_stream.h:177
#define INTEROP_ASSERT(TST)
Definition: assert.h:21
void copy_versions(OutputIterator oit)
Definition: metric_stream.h:55
size_t size_of_header(const Header &header, const ::int16_t version=MetricType::LATEST_VERSION)
Definition: metric_stream.h:226
size_t record_size(const typename MetricType::header_type &header, const ::int16_t version=MetricType::LATEST_VERSION)
Definition: metric_stream.h:134
std::string format(const float val, const int width, const int precision, const char fill= ' ', const bool fixed=true)
Definition: lexical_cast.h:278
std::string interop_basename(bool use_out=true)
Definition: metric_stream.h:45
std::string interop_filename(const std::string &run_directory, bool use_out=true)
Definition: metric_stream.h:31
Definition: stream_exceptions.h:73
size_t size_of_record(const HeaderType &header, const ::int16_t version=MetricType::LATEST_VERSION)
Definition: metric_stream.h:156
bool is_deprecated(const int version)
Definition: metric_file_stream.h:375
size_t size_of_buffer(const MetricSet &metric_set,::int16_t version=-1)
Definition: metric_stream.h:202
::int64_t file_size(const std::string &path)
Definition: filesystem.cpp:156
void read_metrics(std::istream &in, MetricSet &metrics, const size_t file_size, const bool rebuild=true)
Definition: metric_stream.h:99
size_t read_header(std::istream &in, MetricSet &metrics)
Definition: metric_stream.h:73