base_metric.h
Go to the documentation of this file.
1 
10 #pragma once
11 
12 #include <limits>
13 #include "interop/util/assert.h"
17 
18 namespace illumina { namespace interop { namespace model { namespace metric_base
19 {
24  class empty_header { };
25 
26  // Forward declaration
27  class base_metric;
28  class empty_metric;
29 
31  template<class Metric>
32  struct metric_attributes : public Metric{};
33 
36  {
37  public:
40  public:
46  {
47  return base_metric_header();
48  }
49 
50  protected:
55  void clear(){}
63  { }
64  };
65 
71  {
72  public:
74  typedef ::uint32_t id_t;
77  typedef ::uint32_t uint_t;
80 
81  public:
86  template<class BaseMetric>
87  void set_base(const BaseMetric &/*base*/)
88  {
89  }
95  void set_base(const uint_t /*lane*/, const uint_t /*tile*/)
96  {
97  }
102  static const char *suffix()
103  {
104  return "";
105  }
106 
112  bool operator< (const empty_metric& /*metric2*/) const
113  {
114  return false;
115  }
120  static id_t create_id(const id_t, const id_t, const id_t= 0)// TODO: remove hack (const id_t=0)
121  {
122  return 1;// Cannot be zero
123  }
124  };
125 
130  class base_metric : public empty_metric
131  {
132  public:
135  typedef ::uint64_t ulong_t;
138  typedef ulong_t id_t;
141  typedef ::uint16_t ushort_t;
144  typedef ::uint32_t uint_t;
149  typedef ::uint8_t lane_t;
151  typedef ::uint32_t tile_t;
154  enum
155  {
156  //Compress Lane, Tile and cycle into a 64-bit Integer
157  // Bit order: LTCR or Lane, Tile, Cycle/Read, Reserved
158  // Reserved: Bits 0-16
159  // Read/Cycle: Bits 16-32
160  // Tile: Bits 32-58
161  // Lane: Bits 58-64
162  LANE_BIT_COUNT = 6, // Supports up to 63 lanes
163  TILE_BIT_COUNT = 26, // Support 7 digit tile (up to 67108864)
164  CYCLE_BIT_COUNT = 16, // Support up to 65535 cycles
165  READ_BIT_COUNT = 16, // Support up to 65535 reads
166  RESERVED_BIT_COUNT = 16, // Support up to 65535 values
170  LANE_BIT_SHIFT = TILE_BIT_SHIFT+TILE_BIT_COUNT // Supports up to 63 lanes=
171  };
172  public:
178  base_metric(const uint_t lane=0, const uint_t tile=0) :
179  m_lane(static_cast<lane_t>(lane)), m_tile(static_cast<tile_t>(tile))
180  { }
181 
182  public:
188  void set_base(const uint_t lane, const uint_t tile)
189  {
190  m_lane = static_cast<lane_t>(lane);
191  m_tile = static_cast<tile_t>(tile);
192  }
193 
198  template<class BaseMetric>
199  void set_base(const BaseMetric &base)
200  {
201  m_lane = static_cast<lane_t>(base.lane);
202  m_tile = static_cast<tile_t>(base.tile);
203  }
204 
209  id_t id() const
210  {
211  return create_id(m_lane, m_tile);
212  }
213 
218  id_t tile_hash() const
219  {
220  return create_id(m_lane, m_tile);
221  }
222 
229  static id_t create_id(const id_t lane, const id_t tile, const id_t= 0)// TODO: remove hack (const id_t=0)
230  {
231  return (lane << LANE_BIT_SHIFT) | (tile << TILE_BIT_SHIFT);
232  }
233 
239  static id_t lane_from_id(const id_t id)
240  {
241  return id >> LANE_BIT_SHIFT;
242  }
248  static id_t tile_hash_from_id(const id_t id)
249  {
250  // 1. Remove cycle and reserved information
251  return (id >> TILE_BIT_SHIFT) << TILE_BIT_SHIFT;
252  }
258  static id_t tile_from_id(const id_t id)
259  {
260  // 1. Shift off lane
261  // 2. Shift tile id into proper position (removing cycle and reserved)
263  }
264 
269  uint_t lane() const
270  { return m_lane; }
271 
284  uint_t tile() const
285  { return m_tile; }
286 
294  {
295  return m_tile % 100;
296  }
297 
305  {
306  if (method == constants::FiveDigit)
307  return (m_tile / 100) % 10;
308  return std::numeric_limits<uint_t>::min();
309  }
310 
318  {
319  if (method == constants::FiveDigit)
320  return (m_tile / 10000);
321  if (method == constants::FourDigit)
322  return m_tile / 1000;
323  return 1;
324  }
325 
333  {
334  if (method == constants::FiveDigit)
335  return (m_tile / 1000) % 10;
336  if (method == constants::FourDigit)
337  return (m_tile / 100) % 10;
338  return 1;
339  }
340 
352  const uint_t section_per_lane,
353  const uint_t tile_count,
354  const uint_t swath_count,
355  const bool all_surfaces) const
356  {
357  const uint_t column = phyiscalLocationColumn(method, swath_count, all_surfaces);
358  const uint_t row = phyiscalLocationRow(method, section_per_lane, tile_count);
359  const uint_t row_count = section_per_lane * tile_count;
360  return column * row_count + row;
361  }
362 
372  const uint_t swath_count,
373  const bool all_surfaces) const
374  {
375  if (!(method == constants::FiveDigit || method == constants::FourDigit)) return 0;
376  uint_t col = swath(method);
377  if (all_surfaces && surface(method) == 2) col += swath_count;
378  return col;
379  }
380 
390  const uint_t section_per_lane,
391  const uint_t tile_count) const
392  {
393  uint_t section;
394  switch (method)
395  {
397  section = ((m_tile % 1000) - (m_tile % 100)) / 100;
398  if (section == 4) section = 6;
399  else if (section == 6) section = 4;
400  section = (section - 1) * section_per_lane;
401  return (section * tile_count) + (m_tile % 100);
403  return m_tile % 100;
404  default:
405  return m_tile;
406  }
407  }
408 
419  const uint_t section_per_lane,
420  const uint_t tile_count,
421  const uint_t swath_count,
422  const bool all_surfaces) const
423  {
424 
425  INTEROP_ASSERTMSG(swath(method) <= swath_count, swath(method) << " <= " << swath_count);
426  INTEROP_ASSERTMSG(number(method) <= tile_count, number(method) << " <= " << tile_count);
427  const uint_t column = physical_location_column(method, swath_count, all_surfaces);
428  const uint_t row = physical_location_row(method, section_per_lane, tile_count);
429  const uint_t row_count = section_per_lane * tile_count;
430  return static_cast<size_t>(column * row_count + row);
431  }
432 
441  const uint_t swath_count,
442  const bool all_surfaces) const
443  {
444  if (!(method == constants::FiveDigit || method == constants::FourDigit)) return 0;
445  uint_t col = swath(method);
446  if (all_surfaces && surface(method) == 2) col += swath_count;
447  return col - 1;
448  }
449 
458  const uint_t section_per_lane,
459  const uint_t tile_count) const
460  {
461  uint_t section;
462  switch (method)
463  {
465  section = ((m_tile % 1000) - (m_tile % 100)) / 100;
466  if (section == 4) section = 6;
467  else if (section == 6) section = 4;
468  section = (section - 1) % section_per_lane;
469  return (section * tile_count) + (m_tile % 100) - 1;
471  return m_tile % 100 - 1;
472  default:
473  return m_tile - 1;
474  }
475  }
480  static const char *suffix()
481  {
482  return "";
483  }
489  bool operator< (const base_metric& metric2) const
490  {
491  return id() < metric2.id();
492  }
493 
494  private:
495  lane_t m_lane;
496  tile_t m_tile;
497  };
498 
499 
501  template<>
503  {
504  enum
505  {
511  LATEST_VERSION=0
512  };
513 
518  static const char *prefix()
519  {
520  return "";
521  }
526  static const char *suffix()
527  {
528  return "";
529  }
530  };
531 
532 
533 }}}}
534 
#define INTEROP_ASSERTMSG(TST, MSG)
Definition: assert.h:32
uint_t swath(const illumina::interop::constants::tile_naming_method method) const
Definition: base_metric.h:332
constants::base_tile_t base_t
Definition: base_metric.h:39
::uint32_t uint_t
Definition: base_metric.h:144
uint_t phyiscalLocationIndex(const illumina::interop::constants::tile_naming_method method, const uint_t section_per_lane, const uint_t tile_count, const uint_t swath_count, const bool all_surfaces) const
Definition: base_metric.h:351
::uint32_t id_t
Definition: base_metric.h:74
uint_t physical_location_row(const illumina::interop::constants::tile_naming_method method, const uint_t section_per_lane, const uint_t tile_count) const
Definition: base_metric.h:457
uint_t section(const illumina::interop::constants::tile_naming_method method) const
Definition: base_metric.h:304
bool operator<(const base_metric &metric2) const
Definition: base_metric.h:489
static const char * prefix()
Definition: base_metric.h:518
Definition: enum_description.h:15
uint_t tile() const
Definition: base_metric.h:284
constants::base_run_t base_t
Definition: base_metric.h:79
id_t id() const
Definition: base_metric.h:209
uint_t phyiscalLocationRow(const illumina::interop::constants::tile_naming_method method, const uint_t section_per_lane, const uint_t tile_count) const
Definition: base_metric.h:389
static id_t lane_from_id(const id_t id)
Definition: base_metric.h:239
static id_t tile_hash_from_id(const id_t id)
Definition: base_metric.h:248
uint_t physical_location_column(const illumina::interop::constants::tile_naming_method method, const uint_t swath_count, const bool all_surfaces) const
Definition: base_metric.h:440
::uint16_t ushort_t
Definition: base_metric.h:141
uint_t number(const illumina::interop::constants::tile_naming_method) const
Definition: base_metric.h:293
void set_base(const uint_t lane, const uint_t tile)
Definition: base_metric.h:188
static id_t create_id(const id_t, const id_t, const id_t=0)
Definition: base_metric.h:120
uint_t phyiscalLocationColumn(const illumina::interop::constants::tile_naming_method method, const uint_t swath_count, const bool all_surfaces) const
Definition: base_metric.h:371
static id_t create_id(const id_t lane, const id_t tile, const id_t=0)
Definition: base_metric.h:229
base_metric_header header_type
Definition: base_metric.h:147
static base_metric_header default_header()
Definition: base_metric.h:45
static id_t tile_from_id(const id_t id)
Definition: base_metric.h:258
Definition: type_traits.h:131
::uint32_t uint_t
Definition: base_metric.h:77
void set_base(const uint_t, const uint_t)
Definition: base_metric.h:95
static const char * suffix()
Definition: base_metric.h:102
::uint64_t ulong_t
Definition: base_metric.h:135
uint_t surface(const illumina::interop::constants::tile_naming_method method) const
Definition: base_metric.h:317
id_t tile_hash() const
Definition: base_metric.h:218
static const char * suffix()
Definition: base_metric.h:526
uint_t lane() const
Definition: base_metric.h:269
size_t physical_location_index(const illumina::interop::constants::tile_naming_method method, const uint_t section_per_lane, const uint_t tile_count, const uint_t swath_count, const bool all_surfaces) const
Definition: base_metric.h:418
base_metric(const uint_t lane=0, const uint_t tile=0)
Definition: base_metric.h:178
bool operator<(const empty_metric &) const
Definition: base_metric.h:112
void set_base(const BaseMetric &)
Definition: base_metric.h:87
void set_base(const BaseMetric &base)
Definition: base_metric.h:199
constants::base_tile_t base_t
Definition: base_metric.h:153
void update_max_cycle(const empty_metric &)
Definition: base_metric.h:62
tile_naming_method
Definition: enums.h:294
::uint32_t tile_t
Definition: base_metric.h:151
ulong_t id_t
Definition: base_metric.h:138
::uint8_t lane_t
Definition: base_metric.h:149
static const char * suffix()
Definition: base_metric.h:480