Class Writer¶
Defined in File writer.h
Class Documentation¶
-
class Writer¶
OSF Writer provides the base universal interface to store the collection of metadata entries, streams, and corresponding objects.
Detailed description of the class follows here.
Public Functions
-
Writer(std::string file_name, uint32_t chunk_size = 0)¶
- Throws:
std::runtime_error – Exception on file writing issues.
- Parameters:
file_name[in] The file name of the output OSF file.
chunk_size[in] The chunk size in bytes to use for the OSF file. This argument is optional, and if not provided the default value of 2MB is used. If the current chunk being written exceeds the chunk_size, a new chunk will be started on the next call to save. This allows an application to tune the number of messages (e.g. lidar frames) per chunk, which affects the granularity of the message index stored in the StreamingInfo in the file metadata. A smaller chunk_size means more messages are indexed and a larger number of index entries. A more granular index allows for more precise seeking at the slight expense of a larger file.
- Parameters:
filename[in] The file name to output to.
info[in] The sensor info to use for a single stream OSF file.
fields_to_write[in] The fields from frames to actually save into the OSF. If not provided uses the fields from the first saved lidar frame for this sensor. This parameter is optional.
chunk_size[in] The chunksize to use for the OSF file, this parameter is optional.
encoder[in] An optional Encoder instance for configuring how the Writer should encode the OSF.
- Parameters:
filename[in] The file name to output to.
info[in] The sensor info vector to use for a multi stream OSF file.
chunk_size[in] The chunksize to use for the OSF file, this parameter is optional.
fields_to_write[in] The fields from frames to actually save into the OSF. If not provided uses the fields from the first saved lidar frame for this sensor. This parameter is optional.
encoder[in] An optional Encoder instance for configuring how the Writer should encode the OSF.
-
template<typename MetaType, typename ...MetaParams>
inline uint32_t add_metadata(MetaParams&&... params)¶ Add metadata to the OSF file.
- Template Parameters:
MetaType – The type of metadata to add.
MetaParams – The type of meta parameters to add.
- Parameters:
params[in] The parameters to add.
- Returns:
The corresponding lidar id of the metadata entry.
-
uint32_t add_metadata(MetadataEntry &&entry)¶
Adds a MetadataEntry to the OSF file.
- Parameters:
entry[in] The metadata entry to add to the OSF file.
- Returns:
The corresponding lidar id of the metadata entry
-
uint32_t add_metadata(MetadataEntry &entry)¶
Adds a MetadataEntry to the OSF file.
- Parameters:
entry[in] The metadata entry to add to the OSF file.
- Returns:
The corresponding lidar id of the metadata entry
-
void save(const FrameSetSourceMetadataSet &frame_set_source_metadata_set)¶
Save a set of frame set source metadata to the OSF file.
- Parameters:
frame_set_source_metadata_set[in] The set of metadata entries to save.
-
std::shared_ptr<MetadataEntry> get_metadata(const uint32_t metadata_id) const¶
Get and return a metadata entry.
- Parameters:
metadata_id[in] The id of the metadata to get and return.
- Returns:
The correct MetadataEntry.
Get and return a metadata entry.
- Parameters:
metadata_id[in] The id of the metadata to get and return.
- Template Parameters:
MetadataEntryClass – The type of metadata to get and return.
- Returns:
The correct MetadataEntry.
-
template<typename Stream, typename ...StreamParams>
inline Stream create_stream(StreamParams&&... params)¶ Creating streams by passing itself as first argument of the ctor and following the all other parameters.
- Template Parameters:
Stream – The specified stream object type.
StreamParams – The specified stream parameter types.
- Parameters:
params[in] The parameters to use when creating a stream.
- Returns:
Stream object created.
-
void save_message(const uint32_t stream_id, const ts_t receive_ts, const ts_t sensor_ts, const std::vector<uint8_t> &buf, const std::string &type)¶
Writer accepts messages in the form of bytes buffers with linked meta_id and timestamp.
- Throws:
std::logic_error – Exception on non existent stream id.
- Parameters:
stream_id[in] The stream to save the message to.
receive_ts[in] The receive timestamp to use for the message.
sensor_ts[in] The sensor timestamp to use for the message.
buf[in] The message to save in the form of a byte vector.
type[in] Message type string of the message being saved.
-
uint32_t add_sensor(const ouster::sdk::core::SensorInfo &info, const std::vector<std::string> &fields_to_write = std::vector<std::string>())¶
Adds info about a sensor to the OSF and returns the stream index to to write frames to it’s stream.
- Parameters:
info[in] The info of the sensor to add to the file.
fields_to_write[in] The fields from frames to actually save into the OSF. If not provided uses the fields from the first saved lidar frame for this sensor. This parameter is optional.
- Returns:
The stream index for the newly added sensor.
-
void save(uint32_t stream_index, const ouster::sdk::core::LidarFrame &frame)¶
Save a single frame to the specified stream_index in an OSF file.
The concept of the stream_index is related to the SensorInfo vector. Consider the following:
SensorInfo info1; // The first sensor in this OSF file SensorInfo info2; // The second sensor in this OSF file SensorInfo info3; // The third sensor in this OSF file Writer output = Writer(filename, {info1, info2, info3}); LidarFrame frame = RANDOM_FRAME_HERE; // To save the LidarFrame to the first sensor, you would do the // following output.save(0, frame); // To save the LidarFrame to the second sensor, you would do the // following output.save(1, frame); // To save the LidarFrame to the third sensor, you would do the // following output.save(2, frame);
- Throws:
std::logic_error – Will throw exception on writer being closed.
std::logic_error – ///< Will throw exception on ///< out of bound stream_index.
- Parameters:
stream_index[in] The index of the corrosponding SensorInfo to use.
frame[in] The frame to save.
-
void save(uint32_t stream_index, const ouster::sdk::core::LidarFrame &frame, ouster::sdk::osf::ts_t timestamp)¶
Save a single frame with the specified timestamp to the specified stream_index in an OSF file.
- Throws:
std::logic_error – Will throw exception on writer being closed.
std::logic_error – ///< Will throw exception on ///< out of bound stream_index.
- Parameters:
stream_index[in] The index of the corrosponding SensorInfo to use.
frame[in] The frame to save.
timestamp[in] Receive timestamp to index this frame with.
-
void save(const ouster::sdk::core::FrameSet &collation)¶
Save collation of frames to the OSF file.
The concept of the stream_index is related to the SensorInfo vector. Consider the following:
SensorInfo info1; // The first sensor in this OSF file SensorInfo info2; // The second sensor in this OSF file SensorInfo info3; // The third sensor in this OSF file Writer output = Writer(filename, {info1, info2, info3}); LidarFrame sensor1_frame = RANDOM_FRAME_HERE; LidarFrame sensor2_frame = RANDOM_FRAME_HERE; LidarFrame sensor3_frame = RANDOM_FRAME_HERE; // To save the frames matched appropriately to their sensors, you would do // the following. FrameSet collation({sensor1_frame, sensor2_frame, sensor3_frame}); // Collation also optionally allows saving custom fields directly to it // which are saved directly to osf collation.add_field("my_field", fd_array<double>(100, 200)); output.save(collation);
- Throws:
std::logic_error – Will throw exception on writer being closed
std::logic_error – Will throw exception on collation size not matching the number of sensor infos
OsfDropFrameError – Will throw exception on missing timestamps
- Parameters:
collation[in] The FrameSet to save
-
const MetadataStore &meta_store() const¶
Returns the metadata store.
This is used for getting the entire set of flatbuffer metadata entries.
- Returns:
The flatbuffer metadata entries.
-
const std::string &metadata_id() const¶
Returns the metadata id label.
- Returns:
The metadata id label.
-
void set_metadata_id(const std::string&id)¶
Sets the metadata id label.
- Parameters:
id[in] The metadata id label to set.
-
const std::string &filename() const¶
Return the filename for the OSF file.
- Returns:
The file name for the OSF file.
-
uint32_t chunk_size() const¶
Get the chunk size used for the OSF file.
- Returns:
The chunk size for the OSF file.
-
const std::vector<ouster::sdk::core::SensorInfo> &sensor_info() const¶
Return the sensor info vector.
Consider the following:
SensorInfo info1; // The first sensor in this OSF file SensorInfo info2; // The second sensor in this OSF file SensorInfo info3; // The third sensor in this OSF file Writer output = Writer(filename, {info1, info2, info3}); // The following will be true output.sensor_info() == std::vector<SensorInfo>{info1, info2, info3};
- Returns:
The sensor info vector.
-
void close(bool fsync = false)¶
Finish file with a proper metadata object, and header.
This method blocks until all remaining tasks generated by save() have been finalized.
- Parameters:
fsync[in] If true, force all writes on this file to disk.
-
inline bool is_closed() const¶
Returns if the writer is closed or not.
- Returns:
If the writer is closed or not.
-
ChunksLayout chunks_layout() const¶
Get the specific chunks layout of the OSF file.
- Returns:
The chunks layout of the OSF file.
-
~Writer()¶
-
Writer(std::string file_name, uint32_t chunk_size = 0)¶