Apollo 10.0
自动驾驶开放平台
record_processor.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2019 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 "cyber/common/file.h"
20#include "cyber/common/log.h"
21
30
31namespace apollo {
32namespace data {
33
37using cyber::record::RecordWriter;
38
39RecordProcessor::RecordProcessor(const std::string& source_record_dir,
40 const std::string& restored_output_dir)
41 : source_record_dir_(source_record_dir),
42 restored_output_dir_(restored_output_dir) {}
43
44bool RecordProcessor::Init(const SmartRecordTrigger& trigger_conf) {
45 // Init input/output
46 if (!DirectoryExists(source_record_dir_)) {
47 AERROR << "source record dir does not exist: " << source_record_dir_;
48 return false;
49 }
50 if (!EnsureDirectory(restored_output_dir_)) {
51 AERROR << "unable to open output dir: " << restored_output_dir_;
52 return false;
53 }
54 // Init triggers
55 if (!InitTriggers(trigger_conf)) {
56 AERROR << "unable to init triggers";
57 return false;
58 }
59 // Init writer
60 static constexpr uint64_t kMBToKB = 1024UL;
61 writer_.reset(new RecordWriter());
62 writer_->SetIntervalOfFileSegmentation(
63 trigger_conf.segment_setting().time_segment());
64 writer_->SetSizeOfFileSegmentation(
65 trigger_conf.segment_setting().size_segment() * kMBToKB);
66 const std::string output_file = GetDefaultOutputFile();
67 AINFO << "output file path: " << output_file;
68 if (!writer_->Open(output_file)) {
69 AERROR << "failed to open file for writing: " << output_file;
70 return false;
71 }
72 // Init intervals pool
73 IntervalPool::Instance()->Reset();
74 IntervalPool::Instance()->SetIntervalEventLogFilePath(
75 trigger_conf.trigger_log_file_path(), GetFileName(restored_output_dir_));
76 return true;
77}
78
80 triggers_.push_back(std::unique_ptr<TriggerBase>(new DriveEventTrigger));
81 triggers_.push_back(std::unique_ptr<TriggerBase>(new EmergencyModeTrigger));
82 triggers_.push_back(std::unique_ptr<TriggerBase>(new HardBrakeTrigger));
83 triggers_.push_back(std::unique_ptr<TriggerBase>(new SmallTopicsTrigger));
84 triggers_.push_back(std::unique_ptr<TriggerBase>(new RegularIntervalTrigger));
85 triggers_.push_back(std::unique_ptr<TriggerBase>(new SwerveTrigger));
86 triggers_.push_back(std::unique_ptr<TriggerBase>(new BumperCrashTrigger));
87 for (const auto& trigger : triggers_) {
88 if (!trigger->Init(trigger_conf)) {
89 AERROR << "unable to initiate trigger and collect channels";
90 return false;
91 }
92 }
93 return true;
94}
95
97 const cyber::record::RecordMessage& msg) const {
98 for (const auto& trigger : triggers_) {
99 if (trigger->ShouldRestore(msg)) {
100 return true;
101 }
102 }
103 return false;
104}
105
106} // namespace data
107} // namespace apollo
BumperCrash trigger that fires when emergency mode is engaged
DriveEvent trigger that records drive events
EmergencyMode trigger that fires when emergency mode is engaged
HardBrake trigger that fires when hard break is engaged
bool InitTriggers(const SmartRecordTrigger &trigger_conf)
std::vector< std::unique_ptr< TriggerBase > > triggers_
RecordProcessor(const std::string &source_record_dir, const std::string &restored_output_dir)
const std::string restored_output_dir_
std::unique_ptr< cyber::record::RecordWriter > writer_
bool ShouldRestore(const cyber::record::RecordMessage &msg) const
const std::string source_record_dir_
virtual std::string GetDefaultOutputFile() const =0
virtual bool Init(const SmartRecordTrigger &trigger_conf)
A specialized trigger that does not trigger anything but indicates what small topics need to be resto...
Swerve trigger that fires when swerve is engaged
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
std::string GetFileName(const std::string &path, const bool remove_extension)
Definition file.cc:415
bool DirectoryExists(const std::string &directory_path)
Check if the directory specified by directory_path exists and is indeed a directory.
Definition file.cc:207
bool EnsureDirectory(const std::string &directory_path)
Check if a specified directory specified by directory_path exists.
Definition file.cc:299
class register implement
Definition arena_queue.h:37
Basic data struct of record message.
optional RecordSegmentSetting segment_setting