BdsApi 3.1.4
This is the Blacknest BDS API.
Loading...
Searching...
No Matches
BdsDataFileBds.h
Go to the documentation of this file.
1/*******************************************************************************
2 * BdsDataFileBds.h Bds internal data file format
3 * T.Barnaby, BEAM Ltd, 2008-05-06
4 *******************************************************************************
5 *
6 * Supported sub-formats:
7 * BDS, BDS-SM BDS Sample Multiplexed
8 * BDS-CM BDS Channel Multiplexed
9 * BDS-SM-CC BDS Sample Multiplexed, Canadian Compression
10 *
11 * A BDS data file contains multiple streams. Each stream, numbered from 0 upwards, contains information blocks or
12 * data blocks for a specic data channel or set of channels if the channel data is sample multiplexed into a block.
13 * Data streams are split into segments at time discontinuities when using the getInfo() function..
14 * Each segment consists of a set of data blocks and each data block can be for one channel or a number of sample multiplexed channels.
15 * The siesmic channel to stream mapping is stored in the Information blocks. An information block is located at the start of the
16 * file and at each append point. You can only append data channels that the files was originally created for (ie. the first setInfo() API call).
17 *
18 * If the ReadOptionReorder option is used the data segments and blocks are sorted into time order.
19 *
20 * The file can be appended to. When opened for appending
21 */
22#ifndef BdsDataFileBds_H
23#define BdsDataFileBds_H 1
24
25#include <BdsDataFile.h>
26#include <BBuffer.h>
27
28namespace Bds {
29
31enum BdsDataType { BdsDataTypeBlock = 0x42534442, BdsDataTypeInfo = 0x30534442, BdsDataTypeData = 0x31534442, BdsDataTypeInfoExtra = 0x32534442 };
32
38};
39
43 char data[4];
44};
45
55};
56
59public:
62
63 void clear();
64 void reset();
65
68
71
72 void dump();
73};
74
77public:
80 int operator<(const BdsDataBlockPos& b) const { return startTime < b.startTime; }
81
89};
90
93public:
95 int operator<(const BdsDataSegment& b) const { return startTime < b.startTime; }
96
102 BArray<BdsDataBlockPos> blocks; // The list of blocks in the segment
103};
104
107public:
109
112 BUInt32 channel; // The base channel number of data in this streamlet
113 BUInt32 numChannels; // The number of channels of data in this streamlet
114 BArray<BdsDataBlockPos> blocks; // All blocks in this streamlet
115 BArray<BdsDataSegment> segments; // Segments of data
116};
117
118
120class DataFileBds : public DataFile {
121public:
122 enum { StreamsMax = 256 };
123 enum { DefaultBlockSize = 65536 };
125
126 // Generic access
127 DataFileBds();
128 ~DataFileBds();
129
130 BError open(BString fileName, BString mode);
131 BError flush();
132 BError close();
133
134 // Write routines
135 BError setFormat(BString format);
136 BError setInfo(const DataInfo& dataInfo, const ChannelInfos& channelInfos, WriteOptionsList options = WriteOptionSensorData);
137 BError writeData(const DataBlock& data);
138
139 // Read routines
141 BError getInfo(DataInfo& dataInfo, DataFileOptions options, BList<DataError>& errors);
142 BError seekBlock(BUInt32 channel, BUInt segment, BTimeStamp time, BUInt32& blockNumber, BUInt64& sampleNumber, DataBlock& dataBlock);
143 BError readData(BUInt32 channel, BUInt segment, BUInt32 blockNumber, DataBlock& dataBlock);
144
145 static DataFormats getFormats();
146
147 BError setDiskBlockSize(BUInt32 blockSize);
149
150
151 // Low Level Packet I/O
152 BError streamletToChannel(BUInt streamlet, BUInt& channel);
157
158private:
159 void clear();
160
161 // DataBlock exists checks
162 BError dataBlockAdd(BUInt32 streamlet, BTimeStamp startTime, BTimeStamp endTime);
163 Bool dataBlockCheckIfExists(BUInt32 streamlet, BTimeStamp startTime, BTimeStamp endTime);
164
165 // Low level file access
166 BError setInfoRepeat(BUInt32 repeat);
167 BError infoSet(BUInt32 streamlet, BTimeStamp startTime, BTimeStamp endTime, BDictString& info);
168 BError infoGet(BdsDataPacket& packet, BDictString& info);
169 BError readInfoPacket();
170 BError addInfoPacket();
171 BError addInfoExtraPacket();
172 BError streamletFromChannel(BUInt channel, BUInt& streamlet);
173
174 BError dataAppend(const DataBlock& data);
175 BError dataGet(BUInt channel, BdsDataPacket& packet, DataBlock& data);
176
177 // Low level Disk Block access functions
178 BError diskBlockWrite(void* data, BUInt32 numBytes, int header = 0);
179 BError diskBlockWriteFlush();
180 BError diskBlockRead(void* data, BUInt32 numBytes, int header = 0);
181 BError diskBlockSeek(BUInt64 position);
182
183 BString omode;
184 BString oformat;
185 PackFormat opackFormat;
186 DataInfo odataInfo;
187 ChannelInfos ochannelInfos;
188
189 BUInt32 oinfoRepeat;
190 BDictString oinfo;
191 BdsDataPacketHeader oinfoHeader;
192
193 // Disk Block access data
194 BUInt32 odiskBlockSize;
195 BdsDataBlock* odiskBlockRead;
196 BUInt64 odiskPositionRead;
197 BdsDataBlock* odiskBlockWrite;
198 BUInt64 odiskPositionWrite;
199
200 BArray<BdsDataStreamlet> ostreamlets;
201 BdsDataPacket opacket;
202};
203}
204#endif
BUInt32 BUInt
uint32_t BUInt32
bool Bool
uint64_t BUInt64
BdsDataFileBds: internal file storage data block position.
Definition: BdsDataFileBds.h:76
BTimeStamp startTime
Definition: BdsDataFileBds.h:82
BdsDataBlockPos(BTimeStamp startTime=0, BTimeStamp endTime=0, BUInt32 channel=0, BUInt32 numChannels=0, BUInt32 segment=0, BUInt64 position=0, BUInt64 numSamples=0)
Definition: BdsDataFileBds.h:78
BTimeStamp endTime
Definition: BdsDataFileBds.h:83
BUInt32 segment
Definition: BdsDataFileBds.h:86
BUInt32 channel
Definition: BdsDataFileBds.h:84
BUInt64 numSamples
Definition: BdsDataFileBds.h:88
BUInt32 numChannels
Definition: BdsDataFileBds.h:85
int operator<(const BdsDataBlockPos &b) const
Definition: BdsDataFileBds.h:80
BUInt64 position
Definition: BdsDataFileBds.h:87
BdsDataFileBds: internal file storage packet.
Definition: BdsDataFileBds.h:58
BdsDataPacket()
Definition: BdsDataFileBds.cpp:71
~BdsDataPacket()
Definition: BdsDataFileBds.cpp:75
void setChecksumAndLength()
Definition: BdsDataFileBds.cpp:88
void reset()
Definition: BdsDataFileBds.cpp:83
void clear()
Definition: BdsDataFileBds.cpp:78
BError validateChecksum()
Definition: BdsDataFileBds.cpp:106
BError setHeader(const BdsDataPacketHeader &header)
Definition: BdsDataFileBds.cpp:131
void dump()
Definition: BdsDataFileBds.cpp:155
BError getHeader(BdsDataPacketHeader &header)
Definition: BdsDataFileBds.cpp:143
BdsDataFileBds: internal file storage data segment.
Definition: BdsDataFileBds.h:92
BUInt32 numSamples
Definition: BdsDataFileBds.h:100
BTimeStamp endTime
Definition: BdsDataFileBds.h:98
BArray< BdsDataBlockPos > blocks
Definition: BdsDataFileBds.h:102
BdsDataSegment()
Definition: BdsDataFileBds.h:94
int operator<(const BdsDataSegment &b) const
Definition: BdsDataFileBds.h:95
BUInt32 numBlocks
Definition: BdsDataFileBds.h:99
double sampleRate
Definition: BdsDataFileBds.h:101
BTimeStamp startTime
Definition: BdsDataFileBds.h:97
BdsDataFileBds: internal file storage data streamlet.
Definition: BdsDataFileBds.h:106
BArray< BdsDataSegment > segments
Definition: BdsDataFileBds.h:115
BUInt64 position
Definition: BdsDataFileBds.h:111
BdsDataStreamlet()
Definition: BdsDataFileBds.h:108
BArray< BdsDataBlockPos > blocks
Definition: BdsDataFileBds.h:114
BUInt32 channel
Definition: BdsDataFileBds.h:112
BUInt32 packetNumber
Definition: BdsDataFileBds.h:110
BUInt32 numChannels
Definition: BdsDataFileBds.h:113
This class provides Metadata information on a set of channels.
Definition: BdsD.h:564
This class provides the actual Sensor data values contained within a single data block.
Definition: BdsD.h:707
This class implements the BDS Data File/Stream access system.
Definition: BdsDataFileBds.h:120
BError setDiskBlockSize(BUInt32 blockSize)
Sets up file/stream block size.
Definition: BdsDataFileBds.cpp:989
BError setInfo(const DataInfo &dataInfo, const ChannelInfos &channelInfos, WriteOptionsList options=WriteOptionSensorData)
Sets the information.
Definition: BdsDataFileBds.cpp:369
BError flush()
Flush any data to disk even if blocks are not full.
Definition: BdsDataFileBds.cpp:203
BError readData(BUInt32 channel, BUInt segment, BUInt32 blockNumber, DataBlock &dataBlock)
Read the data block for the given channel or all channels if blockNumber is 0.
Definition: BdsDataFileBds.cpp:877
BError setWritePositionForAppend()
Sets the next packet write position.
Definition: BdsDataFileBds.cpp:228
static DataFormats getFormats()
Get the names of the supported formats.
Definition: BdsDataFileBds.cpp:53
BError open(BString fileName, BString mode)
Open the file for reading or writing.
Definition: BdsDataFileBds.cpp:275
@ StreamsMax
Definition: BdsDataFileBds.h:122
BError packetRead(BdsDataPacket &packet)
Reads a packet from the file.
Definition: BdsDataFileBds.cpp:932
BError setFormat(BString format)
Sets the sub-format.
Definition: BdsDataFileBds.cpp:348
DataFileBds()
Definition: BdsDataFileBds.cpp:178
BError getInfo(DataInfo &dataInfo, DataFileOptions options, BList< DataError > &errors)
Get information on open file.
Definition: BdsDataFileBds.cpp:531
~DataFileBds()
Definition: BdsDataFileBds.cpp:184
BError setReadPositionToStart()
Definition: BdsDataFileBds.cpp:923
PackFormat
Definition: BdsDataFileBds.h:124
@ PackFormat_SM
Definition: BdsDataFileBds.h:124
@ PackFormat_CM
Definition: BdsDataFileBds.h:124
@ PackFormat_Unknown
Definition: BdsDataFileBds.h:124
@ PackFormat_SM_CC
Definition: BdsDataFileBds.h:124
BError close()
Close file.
Definition: BdsDataFileBds.cpp:194
BError seekBlock(BUInt32 channel, BUInt segment, BTimeStamp time, BUInt32 &blockNumber, BUInt64 &sampleNumber, DataBlock &dataBlock)
Find the block that contains the samples for the time requested.
Definition: BdsDataFileBds.cpp:829
BUInt32 getDiskBlockSize()
Returns the data block size in bytes.
Definition: BdsDataFileBds.cpp:985
BError streamletToChannel(BUInt streamlet, BUInt &channel)
Find streamlet given channel.
Definition: BdsDataFileBds.cpp:818
DataOrder getDataOrder()
Get the expected order of writing data, by sample or by channel.
Definition: BdsDataFileBds.cpp:475
BError writeData(const DataBlock &data)
Writes a data block to the file.
Definition: BdsDataFileBds.cpp:460
BError packetWrite(BdsDataPacket &packet)
Writes a packet to the file.
Definition: BdsDataFileBds.cpp:919
@ DefaultBlockSize
Definition: BdsDataFileBds.h:123
This defines a list of BDS data converter options.
Definition: BdsDataFile.h:30
This class defines the interface for generic data file access that all of the BDS data converters sha...
Definition: BdsDataFile.h:41
DataOrder
Definition: BdsDataFile.h:43
WriteOptionsList
Definition: BdsDataFile.h:45
@ WriteOptionSensorData
Definition: BdsDataFile.h:45
This class defines information on a set of data.
Definition: BdsD.h:640
Definition: BdsC.cc:8
BdsDataType
BdsDataFileBds: internal file block type field.
Definition: BdsDataFileBds.h:31
@ BdsDataTypeInfo
Definition: BdsDataFileBds.h:31
@ BdsDataTypeData
Definition: BdsDataFileBds.h:31
@ BdsDataTypeInfoExtra
Definition: BdsDataFileBds.h:31
@ BdsDataTypeBlock
Definition: BdsDataFileBds.h:31
BdsDataFileBds: internal fixed size BDS Data Block header.
Definition: BdsDataFileBds.h:34
BUInt32 packetOffset
Offset to first packet header within block or 0 if no packet header within block.
Definition: BdsDataFileBds.h:37
BUInt32 length
Packet length.
Definition: BdsDataFileBds.h:36
BUInt32 type
Blocks type, contains magic number for synchronisation.
Definition: BdsDataFileBds.h:35
BdsDataFileBds: internal fixed size BDS Data Block.
Definition: BdsDataFileBds.h:41
char data[4]
The packet data.
Definition: BdsDataFileBds.h:43
BdsDataBlockHeader header
Definition: BdsDataFileBds.h:42
BdsDataFileBds internal file storage packet header.
Definition: BdsDataFileBds.h:47
BUInt32 type
Packets type.
Definition: BdsDataFileBds.h:48
BTimeStamp startTime
The time of the first sample.
Definition: BdsDataFileBds.h:53
BUInt32 checksum
Checksum of packet.
Definition: BdsDataFileBds.h:52
BUInt32 length
Length in bytes of packet.
Definition: BdsDataFileBds.h:49
BUInt32 streamlet
The streamlet id.
Definition: BdsDataFileBds.h:50
BUInt32 sequence
The streamlet packet sequence number.
Definition: BdsDataFileBds.h:51
BTimeStamp endTime
The time of the last sample + 1.
Definition: BdsDataFileBds.h:54