Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2026-07-16 08:08:12

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/CsvGnnGraphWriter.hpp"
0010 
0011 #include "ActsExamples/Framework/AlgorithmContext.hpp"
0012 #include "ActsExamples/Io/Csv/CsvInputOutput.hpp"
0013 #include "ActsExamples/Utilities/Paths.hpp"
0014 
0015 #include <vector>
0016 
0017 #include "CsvOutputData.hpp"
0018 
0019 namespace ActsExamples {
0020 
0021 CsvGnnGraphWriter::CsvGnnGraphWriter(const Config& config,
0022                                      Acts::Logging::Level level)
0023     : WriterT(config.inputGraph, "CsvGnnGraphWriter", level), m_cfg(config) {}
0024 
0025 ProcessCode CsvGnnGraphWriter::writeT(const AlgorithmContext& ctx,
0026                                       const Graph& graph) {
0027   assert(graph.weights.empty() ||
0028          (graph.edges.size() / 2 == graph.weights.size()));
0029   assert(graph.edges.size() % 2 == 0);
0030 
0031   if (graph.weights.empty()) {
0032     ACTS_DEBUG("No weights provide, write default value of 1");
0033   }
0034 
0035   std::string path = perEventFilepath(
0036       m_cfg.outputDir, m_cfg.outputStem + ".csv", ctx.eventNumber);
0037 
0038   NamedTupleCsvWriter<GraphData> writer(path);
0039 
0040   const auto nEdges = graph.edges.size() / 2;
0041   for (auto i = 0ul; i < nEdges; ++i) {
0042     GraphData edge{};
0043     edge.edge0 = graph.edges[2 * i];
0044     edge.edge1 = graph.edges[2 * i + 1];
0045     edge.weight = graph.weights.empty() ? 1.f : graph.weights[i];
0046     writer.append(edge);
0047   }
0048 
0049   return ProcessCode::SUCCESS;
0050 }
0051 
0052 }  // namespace ActsExamples