Class: Pocolog::StreamInfo Private
- Inherits:
-
Object
- Object
- Pocolog::StreamInfo
- Defined in:
- lib/pocolog/stream_info.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Information about a stream for indexing purposes
Instance Attribute Summary collapse
-
#declaration_blocks ⇒ Object
readonly
private
Positions of the declaration blocks.
-
#index ⇒ Object
readonly
private
The index data itself.
-
#interval_io ⇒ Object
readonly
private
The position of the first and last samples in the file set, as [[raw_pos, io_index], [raw_pos, io_index]].
-
#interval_lg ⇒ Object
readonly
private
The logical time of the first and last samples of that stream [beginning, end].
-
#interval_rt ⇒ Object
readonly
private
The real time of the first and last samples of that stream [beginning, end].
-
#size ⇒ Object
readonly
private
The number of samples in this stream.
Class Method Summary collapse
-
.from_raw_data(declaration_block, interval_rt, base_time, index_map) ⇒ Object
private
Initialize a stream info object from raw information.
Instance Method Summary collapse
- #add_sample(pos, rt, lg) ⇒ Object private
-
#concat(stream_info, file_pos_offset = 0) ⇒ Object
private
When using IO sequences, use this to append information about the same stream coming from a separate IO.
-
#empty? ⇒ Boolean
private
True if this stream is empty.
-
#initialize ⇒ StreamInfo
constructor
private
A new instance of StreamInfo.
- #initialize_copy(copy) ⇒ Object private
-
#initialize_from_raw_data(declaration_block, interval_rt, base_time, index_map) ⇒ Object
private
Initializes self based on raw information.
Constructor Details
#initialize ⇒ StreamInfo
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of StreamInfo
35 36 37 38 39 40 41 42 |
# File 'lib/pocolog/stream_info.rb', line 35 def initialize @declaration_blocks = Array.new @interval_io = [] @interval_lg = [] @interval_rt = [] @size = 0 @index = StreamIndex.new end |
Instance Attribute Details
#declaration_blocks ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Positions of the declaration blocks
7 8 9 |
# File 'lib/pocolog/stream_info.rb', line 7 def declaration_blocks @declaration_blocks end |
#index ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The index data itself. This is a instance of StreamIndex
23 24 25 |
# File 'lib/pocolog/stream_info.rb', line 23 def index @index end |
#interval_io ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The position of the first and last samples in the file set, as [[raw_pos, io_index], [raw_pos, io_index]]. It is empty for empty streams.
11 12 13 |
# File 'lib/pocolog/stream_info.rb', line 11 def interval_io @interval_io end |
#interval_lg ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The logical time of the first and last samples of that stream [beginning, end]. It is empty for empty streams.
14 15 16 |
# File 'lib/pocolog/stream_info.rb', line 14 def interval_lg @interval_lg end |
#interval_rt ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The real time of the first and last samples of that stream [beginning, end]. It is empty for empty streams.
17 18 19 |
# File 'lib/pocolog/stream_info.rb', line 17 def interval_rt @interval_rt end |
#size ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The number of samples in this stream
19 20 21 |
# File 'lib/pocolog/stream_info.rb', line 19 def size @size end |
Class Method Details
.from_raw_data(declaration_block, interval_rt, base_time, index_map) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize a stream info object from raw information
29 30 31 32 33 |
# File 'lib/pocolog/stream_info.rb', line 29 def self.from_raw_data(declaration_block, interval_rt, base_time, index_map) info = StreamInfo.new info.initialize_from_raw_data(declaration_block, interval_rt, base_time, index_map) info end |
Instance Method Details
#add_sample(pos, rt, lg) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/pocolog/stream_info.rb', line 48 def add_sample(pos, rt, lg) if !@interval_io[0] @interval_io[0] = @interval_io[1] = pos @interval_rt[0] = @interval_rt[1] = Integer(rt) @interval_lg[0] = @interval_lg[1] = Integer(lg) else if pos <= @interval_io[1] raise ArgumentError, "attempting to go back in stream in StreamInfo#add_sample (from #{@interval_io[1]} to #{pos}" elsif rt < @interval_rt[1] raise ArgumentError, "attempting to go back in time in StreamInfo#add_sample (from #{@interval_rt[1]} to #{rt}" elsif lg < @interval_lg[1] raise ArgumentError, "attempting to go back in time in StreamInfo#add_sample (from #{@interval_lg[1]} to #{lg}" end @interval_io[1] = pos @interval_rt[1] = rt @interval_lg[1] = lg end @size += 1 index.add_sample(pos, lg) end |
#concat(stream_info, file_pos_offset = 0) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
When using IO sequences, use this to append information about the same stream coming from a separate IO
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 |
# File 'lib/pocolog/stream_info.rb', line 75 def concat(stream_info, file_pos_offset = 0) return if stream_info.empty? stream_interval_io = stream_info.interval_io.map { |v| v + file_pos_offset } if empty? interval_io[0] = stream_interval_io[0] interval_lg[0] = stream_info.interval_lg[0] interval_rt[0] = stream_info.interval_rt[0] else if @interval_io[1] >= stream_interval_io[0] raise ArgumentError, "the IO range of the given stream starts before the range of self" elsif @interval_lg[1] > stream_info.interval_lg[0] raise ArgumentError, "the logical time range of the given stream starts (#{stream_info.interval_lg[0]}) before the range of self (#{@interval_lg[1]})" elsif @interval_rt[1] > stream_info.interval_rt[0] raise ArgumentError, "the realtime range of the given stream starts before the range of self" end end interval_io[1] = stream_interval_io[1] interval_lg[1] = stream_info.interval_lg[1] interval_rt[1] = stream_info.interval_rt[1] @size += stream_info.size index.concat(stream_info.index, file_pos_offset) end |
#empty? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
True if this stream is empty
26 |
# File 'lib/pocolog/stream_info.rb', line 26 def empty?; size == 0 end |
#initialize_copy(copy) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
44 45 46 |
# File 'lib/pocolog/stream_info.rb', line 44 def initialize_copy(copy) raise NotImplementedError, "StreamInfo is non-copyable" end |
#initialize_from_raw_data(declaration_block, interval_rt, base_time, index_map) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initializes self based on raw information
This is used when marshalling/demarshalling index data
104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/pocolog/stream_info.rb', line 104 def initialize_from_raw_data(declaration_block, interval_rt, base_time, index_map) @declaration_blocks = [declaration_block] @index = StreamIndex.from_raw_data(base_time, index_map) @interval_rt = interval_rt @size = index.size if !index.empty? @interval_io = [index.file_position_by_sample_number(0), index.file_position_by_sample_number(-1)] @interval_lg = [index.internal_time_by_sample_number(0) + index.base_time, index.internal_time_by_sample_number(-1) + index.base_time] end end |