47 #ifndef _MIRA_TAPEVISITOR_H_ 48 #define _MIRA_TAPEVISITOR_H_ 74 tape(NULL), offset(0) {}
124 typedef std::map<std::string, const Tape::ChannelInfo*>
ChannelMap;
167 if (!mVisitor || mMessage == mVisitor->mMessages.end() )
168 MIRA_THROW(XIO,
"Cannot instantiate message from the end iterator");
171 if (mInstance.tape == mMessage->tape &&
172 mInstance.offset == (mMessage->index->block+mMessage->index->offset))
176 mInstance.tape = mMessage->tape;
177 mInstance.offset = mMessage->index->block+mMessage->index->offset;
181 mMessage->tape->readMessage(*mMessage->index, mInstance.frameID,
182 mInstance.sequenceID, mInstance.data, oTime,
183 mInstance.compressed);
192 return &this->operator *();
202 template <
typename T>
207 if(mMessage->info->type!=typeName<T>()) {
208 MIRA_THROW(XIO,
"Cannot read a '"<<typeName<T>()<<
209 "' from Tape-Iterator message which has type '"<<mMessage->info->type<<
"'");
219 oData.
timestamp = mVisitor->getStartTime() + getTimeOffset();
250 return mMessage->timeOffset;
261 return mMessage->info;
270 return mMessage->tape->getTZOffset();
280 if (!mVisitor || mMessage == mVisitor->mMessages.end())
281 MIRA_THROW(XIO,
"Cannot access message at the end iterator");
305 void visit(
Tape* iTape,
308 bool ignoreStartTime =
false);
320 void visit(
Tape* iTape,
const std::vector<std::string>& channels,
323 bool ignoreStartTime =
false);
342 for (uint32 i=0; i<mMessages.size(); ++i)
343 mMessages[i].timeOffset = (mMessages[i].tape->getStartTime() +
344 mMessages[i].index->timeOffset) - *mStart;
353 if (mMessages.size() > 0)
354 return mMessages.begin()->timeOffset;
364 if (mMessages.size() > 0)
365 return mMessages.rbegin()->timeOffset;
375 if (mMessages.size() > 0)
376 return mMessages.rbegin()->tape->getTZOffset();
386 return mMessages.size();
395 return iterator(
this, mMessages.begin());
405 if ( mMessages.size() == 0 )
406 return iterator(
this, mMessages.end());
407 if ( mMessages.size() == 1 )
408 return iterator(
this, mMessages.begin());
409 MessageMap::iterator it = mMessages.begin();
410 Duration diffNext =
abs(mMessages[0].timeOffset-timeOffset);
411 for(uint32 i=0; i<mMessages.size()-1;++i, ++it)
414 diffNext =
abs(mMessages[i+1].timeOffset-timeOffset);
415 if ( diffNow < diffNext )
418 return iterator(
this, mMessages.end());
427 return iterator(
this, mMessages.end());
437 return findNextOf(at(startOffset), channel);
447 MessageMap::iterator i = start.
mMessage;
448 for(; i!=mMessages.end(); ++i)
449 if (i->info->name == channel)
451 return iterator(
this, mMessages.end());
461 return findNextOfAnyOf(at(startOffset), channels);
471 MessageMap::iterator i = start.
mMessage;
472 for(; i!=mMessages.end(); ++i)
473 if (std::find(channels.begin(), channels.end(), i->info->name) != channels.end())
476 return iterator(
this, mMessages.end());
494 void reIndex(
Tape* tape,
bool ignoreStartTime =
false);
iterator & operator++()
Definition: TapeVisitor.h:150
A tape is a binary file that contains recorded/serialized data of one or multiple channels...
Definition: Tape.h:142
iterator & operator--()
Definition: TapeVisitor.h:156
T & value()
Returns a read-write reference to the underlying data.
Definition: Stamped.h:202
const MessageInstance * operator->() const
Instantiates the message by loading it from the underlying tape file.
Definition: TapeVisitor.h:190
ChannelMap mChannels
Definition: TapeVisitor.h:498
Duration getTimeOffset() const
Get the offset of the recording time for this message.
Definition: TapeVisitor.h:247
iterator at(Duration timeOffset)
Iterator to the message at the given offset since start of tape.
Definition: TapeVisitor.h:403
A Tape is a representation of recorded channel data in a binary file.
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
const ChannelMap & getChannels() const
Get a list of the visited channels.
Definition: TapeVisitor.h:483
std::map< std::string, const Tape::ChannelInfo * > ChannelMap
Maps channel info to channel names.
Definition: TapeVisitor.h:124
iterator end()
Iterator to the end of visited messages.
Definition: TapeVisitor.h:425
Duration timeOffset
time offset of the message relative to start of recording
Definition: TapeVisitor.h:107
Time getStartTime() const
Get the common start time of the visit for all tapes.
Definition: TapeVisitor.h:329
MessageInstance mInstance
Definition: TapeVisitor.h:284
Duration getLastMessageTimeOffset() const
Get the time offset of the last visited message.
Definition: TapeVisitor.h:362
#define MIRA_THROW(ex, msg)
Macro for throwing an exception.
Definition: Exception.h:82
Information about a channel in a tape.
Definition: Tape.h:186
Iterator to iterate over all messages in all tapes visited by the visitor.
Definition: TapeVisitor.h:133
Buffer< uint8 > data
serialized message data
Definition: TapeVisitor.h:89
Duration getTZOffset() const
Get the time zone offset of the tape containing this message.
Definition: TapeVisitor.h:267
Wrapper class for boost::posix_time::ptime for adding more functionality to it.
Definition: Time.h:416
iterator & operator=(const iterator &other)
Definition: TapeVisitor.h:143
Duration abs(const Duration &duration)
Get the absolute duration from a duration.
Definition: Time.h:399
uint32 getMessageCount() const
Get the number of messages to visit.
Definition: TapeVisitor.h:384
TapeVisitor * mVisitor
Definition: TapeVisitor.h:285
MessageMap mMessages
Definition: TapeVisitor.h:497
const Tape::ChannelInfo * info
pointer to the info object of the channel
Definition: TapeVisitor.h:110
const Tape::ChannelInfo * getChannelInfo() const
Get the information object about the channel this message belongs to.
Definition: TapeVisitor.h:259
MessageMap::iterator mMessage
Definition: TapeVisitor.h:286
bool operator<(const MessageInfo &other) const
Definition: TapeVisitor.h:115
void read(Stamped< T > &oData)
Instantiates the message by loading it from the underlying tape file and deserializes its content int...
Definition: TapeVisitor.h:203
#define MIRA_FRAMEWORK_EXPORT
Definition: FrameworkExports.h:61
Use this class to represent time durations.
Definition: Time.h:104
boost::optional< Time > mStart
Definition: TapeVisitor.h:496
void setStartTime(const Time &start)
Set the common start time of the visit for all tapes.
Definition: TapeVisitor.h:339
uint64 offset
offset of the message in the tape
Definition: TapeVisitor.h:80
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
iterator(TapeVisitor *visitor, MessageMap::iterator message)
Definition: TapeVisitor.h:139
iterator findNextOf(const iterator &start, const std::string &channel)
Returns the iterator to the next message from given channel, starting at the given start iterator...
Definition: TapeVisitor.h:445
static Duration infinity()
Returns a special duration time representing positive infinity.
Definition: Time.h:240
Duration getFirstMessageTimeOffset() const
Get the time offset of the first visited message.
Definition: TapeVisitor.h:351
Instance of a message from a tape.
Definition: TapeVisitor.h:71
iterator begin()
Iterator to the first visited message in a tape.
Definition: TapeVisitor.h:393
Visitor class to inspect tapes by channels and/or time interval.
Definition: TapeVisitor.h:66
static Duration negativeInfinity()
Returns a special duration time representing negative infinity.
Definition: Time.h:233
std::vector< MessageInfo > MessageMap
Vector of message informations.
Definition: TapeVisitor.h:122
const Tape::MessageIndex * index
pointer to the index object of the message
Definition: TapeVisitor.h:113
iterator findNextOfAnyOf(Duration startOffset, const std::vector< std::string > &channels)
Returns the iterator to the next message from any of the given channels with a time offset of at leas...
Definition: TapeVisitor.h:459
Info about a message entry in a tape.
Definition: TapeVisitor.h:96
iterator findNextOfAnyOf(const iterator &start, const std::vector< std::string > &channels)
Returns the iterator to the next message from any of the given channels, starting at the given start ...
Definition: TapeVisitor.h:469
void deserialize(T &value, bool enableTypeCheck=true, bool recursive=false)
Provides a special deserialize interface for the BinaryDeserializer.
Definition: BinarySerializer.h:1340
Tape * tape
pointer to tape the message is stored in
Definition: TapeVisitor.h:77
static Time invalid()
Returns an invalid time.
Definition: Time.h:500
MessageInstance()
Definition: TapeVisitor.h:73
bool compressed
specifies whether the data was compressed within the tape or not
Definition: TapeVisitor.h:92
MessageInfo()
Definition: TapeVisitor.h:98
iterator findNextOf(Duration startOffset, const std::string &channel)
Returns the iterator to the next message from given channel with a time offset of at least startOffse...
Definition: TapeVisitor.h:435
const MessageInstance & operator*() const
Instantiates the message by loading it from the underlying tape file.
Definition: TapeVisitor.h:165
tick_type nanoseconds() const
Returns normalized number of nanoseconds (0..999)
Definition: Time.h:293
Index entry for a message in the tape.
Definition: Tape.h:178
void validate() const
Definition: TapeVisitor.h:278
std::string frameID
frame id of the channel
Definition: TapeVisitor.h:83
Duration getLastMessageTZOffset() const
Get the time zone offset of the last visited message.
Definition: TapeVisitor.h:373
bool operator!=(const iterator &other) const
Definition: TapeVisitor.h:237
uint32 sequenceID
sequence id
Definition: TapeVisitor.h:86
bool operator==(const iterator &other) const
Definition: TapeVisitor.h:232
iterator()
Definition: TapeVisitor.h:136
Tape * tape
pointer to tape the message is stored in
Definition: TapeVisitor.h:104