trajectory_collator.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2018 The Cartographer Authors
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #ifndef CARTOGRAPHER_SENSOR_INTERNAL_TRAJECTORY_COLLATOR_H_
00018 #define CARTOGRAPHER_SENSOR_INTERNAL_TRAJECTORY_COLLATOR_H_
00019 
00020 #include <memory>
00021 #include <vector>
00022 
00023 #include "absl/container/flat_hash_map.h"
00024 #include "cartographer/metrics/counter.h"
00025 #include "cartographer/metrics/family_factory.h"
00026 #include "cartographer/sensor/collator_interface.h"
00027 #include "cartographer/sensor/internal/ordered_multi_queue.h"
00028 
00029 namespace cartographer {
00030 namespace sensor {
00031 
00032 // Waits to see at least one data item for all sensor ids and dispatches data
00033 // in merge-sorted order. Contrary to 'Collator', it does not wait for other
00034 // trajectories.
00035 // Also contrary to 'Collator', whose output is deterministic, the sequence in
00036 // which data is dispatched is not sorted, so non-deterministic input sequences
00037 // will result in non-deterministic output.
00038 class TrajectoryCollator : public CollatorInterface {
00039  public:
00040   TrajectoryCollator() {}
00041 
00042   TrajectoryCollator(const TrajectoryCollator&) = delete;
00043   TrajectoryCollator& operator=(const TrajectoryCollator&) = delete;
00044 
00045   void AddTrajectory(
00046       int trajectory_id,
00047       const absl::flat_hash_set<std::string>& expected_sensor_ids,
00048       const Callback& callback) override;
00049 
00050   void FinishTrajectory(int trajectory_id) override;
00051 
00052   void AddSensorData(int trajectory_id, std::unique_ptr<Data> data) override;
00053 
00054   void Flush() override;
00055 
00056   absl::optional<int> GetBlockingTrajectoryId() const override;
00057 
00058   static void RegisterMetrics(metrics::FamilyFactory* family_factory);
00059 
00060  private:
00061   metrics::Counter* GetOrCreateSensorMetric(const std::string& sensor_id,
00062                                             int trajectory_id);
00063 
00064   static cartographer::metrics::Family<metrics::Counter>*
00065       collator_metrics_family_;
00066 
00067   // Holds individual counters for each trajectory/sensor pair.
00068   absl::flat_hash_map<std::string, metrics::Counter*> metrics_map_;
00069 
00070   absl::flat_hash_map<int, OrderedMultiQueue> trajectory_to_queue_;
00071 
00072   // Map of trajectory ID to all associated QueueKeys.
00073   absl::flat_hash_map<int, std::vector<QueueKey>> trajectory_to_queue_keys_;
00074 };
00075 
00076 }  // namespace sensor
00077 }  // namespace cartographer
00078 
00079 #endif  // CARTOGRAPHER_SENSOR_INTERNAL_TRAJECTORY_COLLATOR_H_


cartographer
Author(s): The Cartographer Authors
autogenerated on Thu May 9 2019 02:27:36