51 #include <boost/optional.hpp> 245 mWaitForAlteredStartTime(false),
246 mMaxMessageBlockSize(64 * 1024* 1024),
247 mSortWindowSize(
Duration::seconds(2))
257 void open(
const Path&
file, OpenMode mode);
271 void repair(
const Path&
file,
const Path& outFile,
bool displayProgress =
false);
284 void waitForAlteredStartTime();
294 void alterStartTime(
const Time& startTime);
306 template <
typename T>
307 MIRA_DEPRECATED(
"Please use int compressionLevel(=0/-1) instead of bool compress(=false/true)",
312 if (!mIsOpen || mMode != WRITE)
313 MIRA_THROW(XIO,
"Tape is not opened in write mode");
315 value->timestamp, value.readSerialized(),
316 (compress ? -1 : 0), meta, metaDB);
330 template <
typename T>
335 if (!mIsOpen || mMode != WRITE)
336 MIRA_THROW(XIO,
"Tape is not opened in write mode");
338 value->timestamp, value.readSerialized(),
339 compressionLevel, meta, metaDB);
354 template <
typename T>
355 MIRA_DEPRECATED(
"Please use int compressionLevel(=0/-1) instead of bool compress(=false/true)",
357 std::list<BinarySerializerCodecPtr>& codecs,
361 if (!mIsOpen || mMode != WRITE)
362 MIRA_THROW(XIO,
"Tape is not opened in write mode");
364 value->timestamp, value.readSerialized(codecs),
365 (compress ? -1 : 0), meta, metaDB);
381 template <
typename T>
383 std::list<BinarySerializerCodecPtr>& codecs,
387 if (!mIsOpen || mMode != WRITE)
388 MIRA_THROW(XIO,
"Tape is not opened in write mode");
390 value->timestamp, value.readSerialized(codecs),
391 compressionLevel, meta, metaDB);
406 template <
typename T>
407 MIRA_DEPRECATED(
"Please use int compressionLevel(=0/-1) instead of bool compress(=false/true)",
408 std::size_t
write(
const std::string& channelID,
const Stamped<T>& value,
417 buffer, (compress ? -1 : 0), meta, metaDB);
433 template <
typename T>
443 buffer, compressionLevel, meta, metaDB);
460 MIRA_DEPRECATED(
"Please use int compressionLevel(=0/-1) instead of bool compress(=false/true)",
461 std::size_t
write(
const std::string& channelID,
const std::string&
typeName,
468 header.
sequenceID, data, (compress ? -1 : 0), meta, metaDB);
486 std::size_t
write(
const std::string& channelID,
const std::string&
typeName,
493 header.
sequenceID, data, compressionLevel, meta, metaDB);
511 MIRA_DEPRECATED(
"Please use int compressionLevel(=0/-1) instead of bool compress(=false/true)",
512 std::size_t
write(
const std::string& channelID,
const std::string&
typeName,
513 const Time& time,
const std::string& frameID, uint32 sequenceID,
519 data, (compress ? -1 : 0), meta, metaDB);
538 std::size_t
write(
const std::string& channelID,
const std::string&
typeName,
539 const Time& time,
const std::string& frameID, uint32 sequenceID,
550 mMaxMessageBlockSize = size;
562 mSortWindowSize = interval;
574 mFile.timezoneOffset = mFile.start.
toLocal() - mFile.start;
598 return mFile.start + mFile.timezoneOffset;
610 if (mMessageBlocks.size()==0)
612 return mFile.start + mMessageBlocks.rbegin()->second.lastMessageOffset;
627 return mFile.timezoneOffset;
651 return mMessageBlocks;
663 return mFile.version;
672 static uint32 getCurrentVersion();
687 void readMessage(
const MessageIndex& index, std::string& frameID,
695 void readMessage(
const MessageIndex& index, std::string& frameID,
702 uint64 getFileHeaderSize()
const;
712 void readFileHeader();
713 void readChannelInfo();
714 void readMessageBlocks();
715 void readMessageBlock(uint64 offset);
716 void writeFileHeader();
718 void writeHeader(HeaderType
type, uint32 size);
719 void writeChannelInfo(ChannelInfo& info);
720 void startMessageBlock(
Duration time);
721 void finishMessageBlock();
MessageBlockMap mMessageBlocks
Pairs of offset - message block.
Definition: Tape.h:733
A tape is a binary file that contains recorded/serialized data of one or multiple channels...
Definition: Tape.h:142
static const uint32 sHeaderSize
size of the header packet
Definition: Tape.h:146
Duration timezoneOffset
Offset of the timezone on the recording machine to UTC.
Definition: Tape.h:206
Definition: BinarySerializer.h:324
std::size_t write(const std::string &channelID, const std::string &typeName, const StampedHeader &header, const Buffer< uint8 > &data, int compressionLevel=0, TypeMetaPtr meta=TypeMetaPtr(), const MetaTypeDatabase &metaDB=MetaTypeDatabase())
Write the serialized data into the tape.
Definition: Tape.h:486
uint32 nrBlocks
Nr of message data blocks.
Definition: Tape.h:209
T & value()
Returns a read-write reference to the underlying data.
Definition: Stamped.h:202
Duration timeOffset
Time offset of the message relative to start time of tape.
Definition: Tape.h:182
HeaderType
The type of the header specifying the following packet.
Definition: Tape.h:162
std::vector< MessageIndex > MessageVector
Definition: Tape.h:188
boost::mutex mMutex
Definition: Tape.h:731
uint32 getVersion() const
Get the version of the tape.
Definition: Tape.h:659
Buffer< uint8 > buffer
Buffer for the block data.
Definition: Tape.h:222
PropertyHint file(const std::string &filters=std::string(), bool save=false)
Tells the property editor that the path is for a file, and that it should show a "File Open"/"File Sa...
Definition: Path.h:247
Time toLocal() const
Converts to local time zone based on the settings of the machine.
Definition: Time.h:555
MetaTypeDatabase metaDB
Database of meta information needed by this type.
Definition: Tape.h:196
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
uint64 offsetToIndexTable
Offset in bytes of the index table for the channel.
Definition: Tape.h:190
boost::filesystem::path Path
Typedef of a Path (shorter version for boost::filesystem::path)
Definition: Path.h:69
bool mIsOpen
Definition: Tape.h:725
Duration firstMessageOffset
Time offset of the first message in the channel.
Definition: Tape.h:191
bool mWaitForAlteredStartTime
Definition: Tape.h:726
Time getStartTime() const
Get the time when the recording started.
Definition: Tape.h:582
Duration mSortWindowSize
Size of the window used for sorting messages in a tape.
Definition: Tape.h:739
TypeMetaPtr meta
Type meta information.
Definition: Tape.h:195
const Tape::ChannelMap & getChannels() const
Get a list of channels in the tape.
Definition: Tape.h:635
static const uint32 sMessageBlockSize
Definition: Tape.h:148
Duration lastMessageOffset
Time offset of the last message in the block.
Definition: Tape.h:221
OpenMode
The open mode for a tape.
Definition: Tape.h:151
static Time unixEpoch()
Returns the unix epoch 1.1.1970 0:0:0.000.
Definition: Time.h:509
Time getLocalStartTime() const
Get the time when the recording started in the local timezone of the machine the recording took place...
Definition: Tape.h:594
std::string name
Name of the messages channel.
Definition: Tape.h:229
Time start
Start recording time.
Definition: Tape.h:205
An object that allows read access to data of a channel.
Definition: ChannelReadWrite.h:440
std::size_t write(ChannelRead< T > value, int compressionLevel=0, TypeMetaPtr meta=TypeMetaPtr(), const MetaTypeDatabase &metaDB=MetaTypeDatabase())
Write the content of a channel into the tape.
Definition: Tape.h:331
#define MIRA_THROW(ex, msg)
Macro for throwing an exception.
Definition: Exception.h:82
void serialize(const T &value, bool enableTypeCheck=true)
Provides a special serialize interface for the BinarySerializer.
Definition: BinarySerializer.h:598
uint32 nrChannels
Nr of channels.
Definition: Tape.h:210
Information about a channel in a tape.
Definition: Tape.h:186
std::string filename
Name of the tape.
Definition: Tape.h:207
const Tape::MessageBlockMap & getMessageBlocks() const
Get a list of the tapes message blocks.
Definition: Tape.h:647
Wrapper class for boost::posix_time::ptime for adding more functionality to it.
Definition: Time.h:416
uint32 sequenceID
Sequence id of the message.
Definition: Tape.h:231
Duration getTZOffset() const
Get the time zone offset.
Definition: Tape.h:623
ChannelMap mChannels
Definition: Tape.h:728
uint32 size
Size of the block.
Definition: Tape.h:219
std::string type
Typename of the channel.
Definition: Tape.h:194
MIRA_BASE_EXPORT void write(const Value &value, std::ostream &ioStream, bool formatted=false, int precision=-1)
Writes a json::Value into a given stream using the JSON format.
std::map< uint64, MessageBlock > MessageBlockMap
maps a message block to an offset
Definition: Tape.h:239
std::string frameID
Frame id of the message.
Definition: Tape.h:230
std::size_t write(ChannelRead< T > value, std::list< BinarySerializerCodecPtr > &codecs, int compressionLevel=0, TypeMetaPtr meta=TypeMetaPtr(), const MetaTypeDatabase &metaDB=MetaTypeDatabase())
Write the content of a channel into the tape.
Definition: Tape.h:382
MIRA_DEPRECATED("Please use int compressionLevel(=0/-1) instead of bool compress(=false/true)", std::size_t write(const std::string &channelID, const std::string &typeName, const StampedHeader &header, const Buffer< uint8 > &data, bool compress, TypeMetaPtr meta=TypeMetaPtr(), const MetaTypeDatabase &metaDB=MetaTypeDatabase()))
Write the serialized data into the tape.
Definition: Tape.h:460
FileInfo mFile
File informations.
Definition: Tape.h:734
uint64 offsetToFirstInfo
Offset to the first channel info packet.
Definition: Tape.h:211
#define MIRA_FRAMEWORK_EXPORT
Definition: FrameworkExports.h:61
MessageVector messages
Messages.
Definition: Tape.h:197
PropertyHint type(const std::string &t)
Sets the attribute "type" to the specified value.
Definition: PropertyHint.h:295
bool compressed
Is message compressed.
Definition: Tape.h:228
void setMaxMessageBlockSize(uint32 size)
Set the maximum size of the chunks.
Definition: Tape.h:548
Use this class to represent time durations.
Definition: Time.h:104
void setStartTime(Time time)
Set an alternative start time for recording.
Definition: Tape.h:571
boost::optional< MessageBlock > mCurrentMessageBlock
Definition: Tape.h:730
std::size_t write(const std::string &channelID, const Stamped< T > &value, int compressionLevel=0, TypeMetaPtr meta=TypeMetaPtr(), const MetaTypeDatabase &metaDB=MetaTypeDatabase())
Write the stamped data into the tape.
Definition: Tape.h:434
uint64 offset
Offset in bytes of the info packet in the tape.
Definition: Tape.h:189
uint64 mLastInfo
Offset to the last written info field.
Definition: Tape.h:735
boost::mutex mMessageMutex
Definition: Tape.h:732
MessageMap mMessages
Messages we have not yet written to file (in the sort window)
Definition: Tape.h:738
MIRA_DEPRECATED("Please use int compressionLevel(=0/-1) instead of bool compress(=false/true)", std::size_t write(ChannelRead< T > value, std::list< BinarySerializerCodecPtr > &codecs, bool compress, TypeMetaPtr meta=TypeMetaPtr(), const MetaTypeDatabase &metaDB=MetaTypeDatabase()))
Write the content of a channel into the tape.
Definition: Tape.h:355
MIRA_DEPRECATED("Please use int compressionLevel(=0/-1) instead of bool compress(=false/true)", std::size_t write(const std::string &channelID, const Stamped< T > &value, bool compress, TypeMetaPtr meta=TypeMetaPtr(), const MetaTypeDatabase &metaDB=MetaTypeDatabase()))
Write the stamped data into the tape.
Definition: Tape.h:407
const std::string & getChannelID()
Definition: ChannelReadWrite.h:190
Mix in for adding a time stamp, an optional frame id and an optional sequence id to data types like P...
Definition: Stamped.h:149
boost::shared_ptr< TypeMeta > TypeMetaPtr
Definition: MetaSerializer.h:309
OpenMode mMode
Definition: Tape.h:727
uint64 dataSize
Size of all messages in bytes.
Definition: Tape.h:198
uint64 block
Offset in bytes of the containing block in the tape.
Definition: Tape.h:180
Time getEndTime() const
Get the time of the last entry.
Definition: Tape.h:606
uint32 mMaxMessageBlockSize
Maximum size of a message block.
Definition: Tape.h:736
MIRA_DEPRECATED("Please use int compressionLevel(=0/-1) instead of bool compress(=false/true)", std::size_t write(const std::string &channelID, const std::string &typeName, const Time &time, const std::string &frameID, uint32 sequenceID, const Buffer< uint8 > &data, bool compress, TypeMetaPtr meta=TypeMetaPtr(), const MetaTypeDatabase &metaDB=MetaTypeDatabase()))
Low level write method to write serialized binary data to the tape.
Definition: Tape.h:511
uint32 version
Tape version.
Definition: Tape.h:208
std::string getTypename() const
Definition: ChannelReadWrite.h:195
uint64 offset
Offset in bytes of the message in the containing block.
Definition: Tape.h:181
Functions for modifying file system paths.
std::multimap< Duration, Message > MessageMap
maps a message to an time offset
Definition: Tape.h:241
Struct for a message block in a tape.
Definition: Tape.h:215
Buffer< uint8 > data
Buffer for the message data.
Definition: Tape.h:232
void setSortWindowSize(const Duration &interval)
Messages get sorted before they are written to a tape to guarantee a correct temporal order...
Definition: Tape.h:560
Duration lastMessageOffset
Time offset of the last message in the channel.
Definition: Tape.h:192
uint64 offset
Offset in bytes of the block in the tape.
Definition: Tape.h:217
std::map< std::string, ChannelInfo > ChannelMap
maps channel information to a channel names
Definition: Tape.h:237
std::set< std::string > mWrittenChannels
Definition: Tape.h:729
std::fstream file
The file stream.
Definition: Tape.h:204
Duration firstMessageOffset
Time offset of the first message in the block.
Definition: Tape.h:220
Index entry for a message in the tape.
Definition: Tape.h:178
uint32 uncompressedSize
Uncompressed size of the message.
Definition: Tape.h:233
Information about a tape file.
Definition: Tape.h:202
MIRA_DEPRECATED("Please use int compressionLevel(=0/-1) instead of bool compress(=false/true)", std::size_t write(ChannelRead< T > value, bool compress, TypeMetaPtr meta=TypeMetaPtr(), const MetaTypeDatabase &metaDB=MetaTypeDatabase()))
Write the content of a channel into the tape.
Definition: Tape.h:307
The framework that holds all manager classes and provides startup and shutdown of all framework relat...
Struct for message data in a tape.
Definition: Tape.h:226
Typename typeName(bool cvqualify=true)
Returns a compiler and platform independent typename of T.
Definition: Typename.h:103
std::string name
Name of the channel.
Definition: Tape.h:193
Tape()
Definition: Tape.h:243
uint32 nrMessages
Nr of contained messages.
Definition: Tape.h:218