Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:10:46

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2020 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 http://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/Utilities/Paths.hpp"
0016 #include "ActsFatras/EventData/Barcode.hpp"
0017 
0018 #include <stdexcept>
0019 #include <vector>
0020 
0021 #include <dfe/dfe_io_dsv.hpp>
0022 #include <dfe/dfe_namedtuple.hpp>
0023 
0024 struct GraphData {
0025   int64_t edge0;
0026   int64_t edge1;
0027   float weight;
0028   DFE_NAMEDTUPLE(GraphData, edge0, edge1, weight);
0029 };
0030 
0031 ActsExamples::CsvExaTrkXGraphWriter::CsvExaTrkXGraphWriter(
0032     const ActsExamples::CsvExaTrkXGraphWriter::Config& config,
0033     Acts::Logging::Level level)
0034     : WriterT(config.inputGraph, "CsvExaTrkXGraphWriter", level),
0035       m_cfg(config) {}
0036 
0037 ActsExamples::ProcessCode ActsExamples::CsvExaTrkXGraphWriter::writeT(
0038     const ActsExamples::AlgorithmContext& ctx,
0039     const std::pair<std::vector<int64_t>, std::vector<float>>& graph) {
0040   std::string path = perEventFilepath(
0041       m_cfg.outputDir, m_cfg.outputStem + ".csv", ctx.eventNumber);
0042 
0043   dfe::NamedTupleCsvWriter<GraphData> writer(path);
0044 
0045   const auto& [edges, weights] = graph;
0046 
0047   for (auto i = 0ul; i < weights.size(); ++i) {
0048     GraphData edge{};
0049     edge.edge0 = edges[2 * i];
0050     edge.edge1 = edges[2 * i + 1];
0051     edge.weight = weights[i];
0052     writer.append(edge);
0053   }
0054 
0055   return ActsExamples::ProcessCode::SUCCESS;
0056 }