Apollo 10.0
自动驾驶开放平台
apollo::cyber::record::Spliter类 参考

#include <spliter.h>

apollo::cyber::record::Spliter 的协作图:

Public 成员函数

 Spliter (const std::string &input_file, const std::string &output_file, const std::vector< std::string > &white_channels, const std::vector< std::string > &black_channels, uint64_t begin_time=0, uint64_t end_time=std::numeric_limits< uint64_t >::max())
 
virtual ~Spliter ()
 
bool Proc ()
 

详细描述

在文件 spliter.h41 行定义.

构造及析构函数说明

◆ Spliter()

apollo::cyber::record::Spliter::Spliter ( const std::string &  input_file,
const std::string &  output_file,
const std::vector< std::string > &  white_channels,
const std::vector< std::string > &  black_channels,
uint64_t  begin_time = 0,
uint64_t  end_time = std::numeric_limits<uint64_t>::max() 
)

在文件 spliter.cc26 行定义.

30 : input_file_(input_file),
31 output_file_(output_file),
32 white_channels_(white_channels),
33 black_channels_(black_channels),
34 begin_time_(begin_time),
35 end_time_(end_time) {}

◆ ~Spliter()

apollo::cyber::record::Spliter::~Spliter ( )
virtual

在文件 spliter.cc37 行定义.

37{}

成员函数说明

◆ Proc()

bool apollo::cyber::record::Spliter::Proc ( )

在文件 spliter.cc39 行定义.

39 {
40 // check params
41 if (begin_time_ >= end_time_) {
42 AERROR << "begin time larger or equal than end time, begin_time_: "
43 << begin_time_ << "end_time_: " << end_time_;
44 return false;
45 }
46 for (const auto& channel_name : white_channels_) {
47 if (std::find(black_channels_.begin(), black_channels_.end(),
48 channel_name) != black_channels_.end()) {
49 AERROR << "find channel in both of white list and black list, channel: "
50 << channel_name;
51 return false;
52 }
53 }
54
55 AINFO << "split record file started.";
56
57 // open input file
58 if (!reader_.Open(input_file_)) {
59 AERROR << "open input file failed, file: " << input_file_;
60 return false;
61 }
62 Header header = reader_.GetHeader();
63 if (begin_time_ > header.end_time() || end_time_ < header.begin_time()) {
64 AERROR << "time range " << begin_time_ << " to " << end_time_
65 << " is not include in this record file.";
66 return false;
67 }
68
69 // open output file
70 Header new_hdr = HeaderBuilder::GetHeader();
71 if (!writer_.Open(output_file_)) {
72 AERROR << "open output file failed. file: " << output_file_;
73 return false;
74 }
75 if (!writer_.WriteHeader(new_hdr)) {
76 AERROR << "write header to output file failed. file: " << output_file_;
77 return false;
78 }
79
80 // read through record file
81 bool skip_next_chunk_body(false);
82 reader_.Reset();
83 while (!reader_.EndOfFile()) {
84 Section section;
85 if (!reader_.ReadSection(&section)) {
86 AERROR << "read section failed.";
87 return false;
88 }
89 if (section.type == SectionType::SECTION_INDEX) {
90 break;
91 }
92 switch (section.type) {
93 case SectionType::SECTION_CHANNEL: {
94 Channel chan;
95 if (!reader_.ReadSection<Channel>(section.size, &chan)) {
96 AERROR << "read channel section fail.";
97 return false;
98 }
99 if (white_channels_.empty() ||
100 std::find(white_channels_.begin(), white_channels_.end(),
101 chan.name()) != white_channels_.end()) {
102 if (std::find(black_channels_.begin(), black_channels_.end(),
103 chan.name()) == black_channels_.end()) {
104 writer_.WriteChannel(chan);
105 }
106 }
107 break;
108 }
109 case SectionType::SECTION_CHUNK_HEADER: {
110 ChunkHeader chdr;
111 if (!reader_.ReadSection<ChunkHeader>(section.size, &chdr)) {
112 AERROR << "read chunk header section fail.";
113 return false;
114 }
115 if (begin_time_ > chdr.end_time() || end_time_ < chdr.begin_time()) {
116 skip_next_chunk_body = true;
117 }
118 break;
119 }
120 case SectionType::SECTION_CHUNK_BODY: {
121 if (skip_next_chunk_body) {
122 reader_.SkipSection(section.size);
123 skip_next_chunk_body = false;
124 break;
125 }
126 ChunkBody cbd;
127 if (!reader_.ReadSection<ChunkBody>(section.size, &cbd)) {
128 AERROR << "read chunk body section fail.";
129 return false;
130 }
131 for (int idx = 0; idx < cbd.messages_size(); ++idx) {
132 if (!white_channels_.empty() &&
133 std::find(white_channels_.begin(), white_channels_.end(),
134 cbd.messages(idx).channel_name()) ==
135 white_channels_.end()) {
136 continue;
137 }
138 if (std::find(black_channels_.begin(), black_channels_.end(),
139 cbd.messages(idx).channel_name()) !=
140 black_channels_.end()) {
141 continue;
142 }
143 if (cbd.messages(idx).time() < begin_time_ ||
144 cbd.messages(idx).time() > end_time_) {
145 continue;
146 }
147 if (!writer_.WriteMessage(cbd.messages(idx))) {
148 AERROR << "add new message failed.";
149 return false;
150 }
151 }
152 break;
153 }
154 default: {
155 AERROR << "this section should not be here, section type: "
156 << section.type;
157 break;
158 }
159 } // end for switch
160 } // end for while
161 AINFO << "split record file done.";
162 return true;
163} // end for Proc()
static proto::Header GetHeader()
Build a default record header.
const proto::Header & GetHeader() const
bool Open(const std::string &path) override
bool Open(const std::string &path) override
bool WriteHeader(const proto::Header &header)
bool WriteChannel(const proto::Channel &channel)
bool WriteMessage(const proto::SingleMessage &message)
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42

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