Apollo 11.0
自动驾驶开放平台
feature_output.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2020 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
18
19#include "absl/strings/str_cat.h"
20
21#include "cyber/common/file.h"
23
24namespace apollo {
25namespace planning {
26
27LearningData FeatureOutput::learning_data_;
28int FeatureOutput::learning_data_file_index_ = 0;
29
31
33 learning_data_.Clear();
34 learning_data_file_index_ = 0;
35}
36
38 Clear();
39 return true;
40}
41
43 const std::string& record_file,
44 const LearningDataFrame& learning_data_frame) {
45 learning_data_.add_learning_data_frame()->CopyFrom(learning_data_frame);
46
47 // write frames into a file
48 if (learning_data_.learning_data_frame_size() >=
49 FLAGS_learning_data_frame_num_per_file) {
50 WriteLearningData(record_file);
51 }
52}
53
55 const int size = learning_data_.learning_data_frame_size();
56 return size > 0 ? learning_data_.mutable_learning_data_frame(size - 1)
57 : nullptr;
58}
59
61
62void FeatureOutput::WriteLearningData(const std::string& record_file) {
63 std::string src_file_name =
64 record_file.substr(record_file.find_last_of("/") + 1);
65 src_file_name = src_file_name.empty() ? "00000" : src_file_name;
66 const std::string dest_file =
67 absl::StrCat(FLAGS_planning_data_dir, "/", src_file_name, ".",
68 learning_data_file_index_, ".bin");
69 cyber::common::SetProtoToBinaryFile(learning_data_, dest_file);
70 // cyber::common::SetProtoToASCIIFile(learning_data_, dest_file + ".txt");
71 learning_data_.Clear();
72 learning_data_file_index_++;
73}
74
76 const std::string& record_file) {
77 if (learning_data_.learning_data_frame_size() > 0) {
78 WriteLearningData(record_file);
79 }
80}
81
82} // namespace planning
83} // namespace apollo
static LearningDataFrame * GetLatestLearningDataFrame()
static void InsertLearningDataFrame(const std::string &record_filename, const LearningDataFrame &learning_data_frame)
Insert a a frame of learning data
static void WriteRemainderiLearningData(const std::string &record_file)
static bool Ready()
Check if output is ready
static void Close()
Close the output stream
static void WriteLearningData(const std::string &record_file)
Write LearningData to a file
Planning module main class.
bool SetProtoToBinaryFile(const google::protobuf::Message &message, const std::string &file_name)
Sets the content of the file specified by the file_name to be the binary representation of the input ...
Definition file.cc:111
class register implement
Definition arena_queue.h:37