Add helper classes for log reading

The goal is to inject span reader factory deep into the log reading
and sorting. LogFilesContainer encapsulates log files and provides
a couple of useful validations and abstractions to simplify log sorting.

It is the first part of change. Follow one will push SelectedLogParts
even deeper into the log reader.

Change-Id: Ic5253bd2b7c87fbbf55ad8d39a480af2871ddb71
Signed-off-by: James Kuszmaul <james.kuszmaul@bluerivertech.com>
diff --git a/aos/events/logging/single_node_merge.cc b/aos/events/logging/single_node_merge.cc
index cc78c2b..afb88af 100644
--- a/aos/events/logging/single_node_merge.cc
+++ b/aos/events/logging/single_node_merge.cc
@@ -19,30 +19,10 @@
 
 namespace chrono = std::chrono;
 
-std::string LogFileVectorToString(std::vector<logger::LogFile> log_files) {
-  std::stringstream ss;
-  for (const auto &f : log_files) {
-    ss << f << "\n";
-  }
-  return ss.str();
-}
-
 int Main(int argc, char **argv) {
   const std::vector<std::string> unsorted_logfiles = FindLogs(argc, argv);
-  const std::vector<LogFile> log_files = SortParts(unsorted_logfiles);
-
-  CHECK_GT(log_files.size(), 0u);
-  // Validate that we have the same config everwhere.  This will be true if
-  // all the parts were sorted together and the configs match.
-  const Configuration *config = nullptr;
-  for (const LogFile &log_file : log_files) {
-    VLOG(1) << log_file;
-    if (config == nullptr) {
-      config = log_file.config.get();
-    } else {
-      CHECK_EQ(config, log_file.config.get());
-    }
-  }
+  const LogFilesContainer log_files(SortParts(unsorted_logfiles));
+  const Configuration *config = log_files.config();
 
   // Haven't tested this on a single node log, and don't really see a need to
   // right now.  The higher layers just work.
@@ -53,16 +33,14 @@
   TimestampMapper *node_mapper = nullptr;
 
   for (const Node *node : configuration::GetNodes(config)) {
-    std::vector<LogParts> filtered_parts =
-        FilterPartsForNode(log_files, node->name()->string_view());
-
+    const auto node_name = MaybeNodeName(node);
     // Confirm that all the parts are from the same boot if there are enough
     // parts to not be from the same boot.
-    if (!filtered_parts.empty()) {
+    if (log_files.ContainsPartsForNode(node_name)) {
       // Filter the parts relevant to each node when building the mapper.
       mappers.emplace_back(
-          std::make_unique<TimestampMapper>(std::move(filtered_parts)));
-      if (node->name()->string_view() == FLAGS_node) {
+          std::make_unique<TimestampMapper>(node_name, log_files));
+      if (node_name == FLAGS_node) {
         node_mapper = mappers.back().get();
       }
     } else {