Apollo 10.0
自动驾驶开放平台
apollo::data::IntervalPool类 参考

The intervals collection class that organizes the intervals 更多...

#include <interval_pool.h>

apollo::data::IntervalPool 的协作图:

Public 成员函数

void AddInterval (const Interval &interval)
 
void AddInterval (const uint64_t begin_time, const uint64_t end_time)
 
void ReorgIntervals ()
 
bool MessageFallIntoRange (const uint64_t msg_time)
 
void Reset ()
 
void PrintIntervals () const
 
Interval GetNextInterval () const
 
void SetIntervalEventLogFilePath (const std::string &path, const std::string &task_id)
 
void LogIntervalEvent (const std::string &name, const std::string &description, const uint64_t msg_time, const uint64_t backward_time, const uint64_t forward_time) const
 

详细描述

The intervals collection class that organizes the intervals

在文件 interval_pool.h40 行定义.

成员函数说明

◆ AddInterval() [1/2]

void apollo::data::IntervalPool::AddInterval ( const Interval interval)

在文件 interval_pool.cc30 行定义.

30 {
31 if (pool_.empty() || interval.begin_time > pool_iter_->end_time) {
32 pool_.push_back(interval);
33 pool_iter_ = std::prev(pool_.end());
34 return;
35 }
36 pool_iter_->begin_time =
37 std::min(interval.begin_time, pool_iter_->begin_time);
38 pool_iter_->end_time = std::max(interval.end_time, pool_iter_->end_time);
39}

◆ AddInterval() [2/2]

void apollo::data::IntervalPool::AddInterval ( const uint64_t  begin_time,
const uint64_t  end_time 
)

在文件 interval_pool.cc41 行定义.

42 {
43 struct Interval interval;
44 interval.begin_time = begin_time;
45 interval.end_time = end_time;
46 AddInterval(interval);
47}
void AddInterval(const Interval &interval)

◆ GetNextInterval()

Interval apollo::data::IntervalPool::GetNextInterval ( ) const

在文件 interval_pool.cc109 行定义.

109 {
110 if (pool_.empty()) {
111 struct Interval interval;
112 interval.begin_time = 0;
113 interval.end_time = 0;
114 return interval;
115 }
116 return *pool_iter_;
117}

◆ LogIntervalEvent()

void apollo::data::IntervalPool::LogIntervalEvent ( const std::string &  name,
const std::string &  description,
const uint64_t  msg_time,
const uint64_t  backward_time,
const uint64_t  forward_time 
) const

在文件 interval_pool.cc91 行定义.

95 {
96 std::ofstream logfile(interval_event_log_file_path_,
97 std::ios::out | std::ios::app);
98 if (!logfile) {
99 AERROR << "Failed to write " << interval_event_log_file_path_;
100 return;
101 }
102 logfile << std::fixed << std::setprecision(9);
103 logfile << "name=" << name << ", description=\"" << description << "\""
104 << ", msg_time=" << msg_time << ", interval_range=["
105 << msg_time - backward_time << ":" << msg_time + forward_time << "]"
106 << std::endl;
107}
#define AERROR
Definition log.h:44

◆ MessageFallIntoRange()

bool apollo::data::IntervalPool::MessageFallIntoRange ( const uint64_t  msg_time)

在文件 interval_pool.cc59 行定义.

59 {
60 // For each message comes for checking, the logic is:
61 // 1. Add end_time of any intervals whose begin_time is smaller
62 // than message time to the helper set
63 // 2. Now if the helper set is not empty, means some range is still
64 // in progress, returns true
65 // 3. After this, remove end_time equals to message time from the set,
66 // which means these ranges are done being used
67 // This way range groups iterate along with messages, time complexity O(N)
68 while (pool_iter_ != pool_.end() && msg_time >= pool_iter_->begin_time) {
69 accu_end_values_.insert(pool_iter_->end_time);
70 ++pool_iter_;
71 }
72 bool found = !accu_end_values_.empty();
73 accu_end_values_.erase(msg_time);
74 return found;
75}

◆ PrintIntervals()

void apollo::data::IntervalPool::PrintIntervals ( ) const

在文件 interval_pool.cc83 行定义.

83 {
84 auto idx = 0;
85 for (const auto& interval : pool_) {
86 AINFO << "Interval " << ++idx << ": " << interval.begin_time << " - "
87 << interval.end_time;
88 }
89}
#define AINFO
Definition log.h:42

◆ ReorgIntervals()

void apollo::data::IntervalPool::ReorgIntervals ( )

在文件 interval_pool.cc49 行定义.

49 {
50 // Sort the intervals by begin_time ascending
51 std::sort(pool_.begin(), pool_.end(),
52 [](const Interval& x, const Interval& y) {
53 return x.begin_time < y.begin_time;
54 });
55 pool_iter_ = pool_.begin();
56 accu_end_values_.clear();
57}

◆ Reset()

void apollo::data::IntervalPool::Reset ( )

在文件 interval_pool.cc77 行定义.

77 {
78 pool_.clear();
79 pool_iter_ = pool_.begin();
80 accu_end_values_.clear();
81}

◆ SetIntervalEventLogFilePath()

void apollo::data::IntervalPool::SetIntervalEventLogFilePath ( const std::string &  path,
const std::string &  task_id 
)
inline

在文件 interval_pool.h49 行定义.

50 {
51 interval_event_log_file_path_ = absl::StrCat(path, "_", task_id);
52 }

该类的文档由以下文件生成: