Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:11:50

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include "ActsExamples/Io/Csv/CsvExaTrkXGraphWriter.hpp"
0010 
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Definitions/Common.hpp"
0013 #include "Acts/Definitions/Units.hpp"
0014 #include "ActsExamples/Framework/AlgorithmContext.hpp"
0015 #include "ActsExamples/Io/Csv/CsvInputOutput.hpp"
0016 #include "ActsExamples/Utilities/Paths.hpp"
0017 #include "ActsFatras/EventData/Barcode.hpp"
0018 
0019 #include <stdexcept>
0020 #include <vector>
0021 
0022 #include "CsvOutputData.hpp"
0023 
0024 ActsExamples::CsvExaTrkXGraphWriter::CsvExaTrkXGraphWriter(
0025     const ActsExamples::CsvExaTrkXGraphWriter::Config& config,
0026     Acts::Logging::Level level)
0027     : WriterT(config.inputGraph, "CsvExaTrkXGraphWriter", level),
0028       m_cfg(config) {}
0029 
0030 ActsExamples::ProcessCode ActsExamples::CsvExaTrkXGraphWriter::writeT(
0031     const ActsExamples::AlgorithmContext& ctx, const Graph& graph) {
0032   assert(graph.weights.empty() ||
0033          (graph.edges.size() / 2 == graph.weights.size()));
0034   assert(graph.edges.size() % 2 == 0);
0035 
0036   if (graph.weights.empty()) {
0037     ACTS_DEBUG("No weights provide, write default value of 1");
0038   }
0039 
0040   std::string path = perEventFilepath(
0041       m_cfg.outputDir, m_cfg.outputStem + ".csv", ctx.eventNumber);
0042 
0043   ActsExamples::NamedTupleCsvWriter<GraphData> writer(path);
0044 
0045   const auto nEdges = graph.edges.size() / 2;
0046   for (auto i = 0ul; i < nEdges; ++i) {
0047     GraphData edge{};
0048     edge.edge0 = graph.edges[2 * i];
0049     edge.edge1 = graph.edges[2 * i + 1];
0050     edge.weight = graph.weights.empty() ? 1.f : graph.weights[i];
0051     writer.append(edge);
0052   }
0053 
0054   return ActsExamples::ProcessCode::SUCCESS;
0055 }