Class: Pocolog::StreamInfo Private

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStreamInfo

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.



39
40
41
42
43
44
45
46
# File 'lib/pocolog/stream_info.rb', line 39

def initialize
    @declaration_blocks = Array.new
    @interval_io = []
    @interval_lg = []
    @interval_rt = []
    @size        = 0
    @index       = StreamIndex.new
end

Instance Attribute Details

#declaration_blocksArray<Integer> (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 in the file of the declaration blocks

Returns:

  • (Array<Integer>)


9
10
11
# File 'lib/pocolog/stream_info.rb', line 9

def declaration_blocks
  @declaration_blocks
end

#indexObject (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



25
26
27
# File 'lib/pocolog/stream_info.rb', line 25

def index
  @index
end

#interval_ioObject (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.



13
14
15
# File 'lib/pocolog/stream_info.rb', line 13

def interval_io
  @interval_io
end

#interval_lgObject (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.



16
17
18
# File 'lib/pocolog/stream_info.rb', line 16

def interval_lg
  @interval_lg
end

#interval_rtObject (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.



19
20
21
# File 'lib/pocolog/stream_info.rb', line 19

def interval_rt
  @interval_rt
end

#sizeObject (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



21
22
23
# File 'lib/pocolog/stream_info.rb', line 21

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



33
34
35
36
37
# File 'lib/pocolog/stream_info.rb', line 33

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.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/pocolog/stream_info.rb', line 52

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

Parameters:

  • file_pos_offset (Integer) (defaults to: 0)

    an offset that should be applied on all file positions within stream_info. This is used to concatenate streaminfo objects for streams backed by a IOSequence



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/pocolog/stream_info.rb', line 79

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

Returns:

  • (Boolean)


28
29
30
# File 'lib/pocolog/stream_info.rb', line 28

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.

Raises:

  • (NotImplementedError)


48
49
50
# File 'lib/pocolog/stream_info.rb', line 48

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



108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/pocolog/stream_info.rb', line 108

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.sample_count
    return 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