// -*- mode: c++; indent-tabs-mode: nil; -*- // // Copyright 2009 Illumina, Inc. // // This software is covered by the "Illumina Genome Analyzer Software // License Agreement" and the "Illumina Source Code License Agreement", // and certain third party copyright/licenses, and any user of this // source file is bound by the terms therein (see accompanying files // Illumina_Genome_Analyzer_Software_License_Agreement.pdf and // Illumina_Source_Code_License_Agreement.pdf and third party // copyright/license notices). // // /// \file /// /// \author Chris Saunders /// #ifndef __MULTI_STAGE_CIRCULAR_MANAGER_H #define __MULTI_STAGE_CIRCULAR_MANAGER_H #include "pos_processor_base.hh" #include "blt_util/pos_range.hh" #include #include /// \brief help to manage information which is being gathered in an /// approximately sequential fasion and processed in sequence in /// multiple stages. /// /// assumes that information related to each position will be /// available in an approximately sequential fashion, where all /// position values submitted after position X will be greater than /// X-first_stage_buffer_size+1. A violation of this assumption will /// trigger a runtime error. /// /// range policy: /// /// if begin_pos is not specified, then event processiing and /// reporting start at the first pos >= 0 with position information /// submitted, else at begin_pos /// /// if end_pos is not specified, then processing ends after last_pos /// with information submitted, else at end_pos. /// struct multi_stage_circular_manager { // stage_length specifies size of stages from front to back. multi_stage_circular_manager(const std::vector& stage_size, const pos_range& report_range, pos_processor_base& ppb); // process any remaining positions void reset(); // validate that submitted pos is legal wrt previous submitted pos values and advance buffer head pos as necessary: void handle_new_pos_value(const pos_t pos); // test whether position would be legal for this stage: bool is_new_pos_value_valid(const pos_t pos, const int stage); // validate that submitted pos is legal wrt previous current buffer head position, but do not advance head pos void validate_new_pos_value(const pos_t pos, const int stage=0); // lookup position in the buffer: unsigned pos_to_pindex(const pos_t pos) const { if(pos<0){ return pos+_buffer_size*(1-(pos/_buffer_size)); } else { return pos%_buffer_size; } } pos_t max_pos() const { return _max_pos; } pos_t min_pos() const { return _min_pos; } bool is_first_pos_set() const { return _is_first_pos_set; } private: void process_pos(const pos_t pos); void finish_process_pos(); const unsigned _n_stages; bool _is_head_pos; pos_t _head_pos; std::vector _stage_n_buffer_size; int _buffer_size; pos_t _max_pos; pos_t _min_pos; bool _is_first_pos_set; const pos_range& _report_range; pos_processor_base& _ppb; }; #endif