Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-08-28 08:12:25

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/CsvGnnGraphReader.hpp"
0010 
0011 #include "Acts/Definitions/PdgParticle.hpp"
0012 #include "Acts/Definitions/Units.hpp"
0013 #include "Acts/Utilities/Logger.hpp"
0014 #include "ActsExamples/EventData/SimParticle.hpp"
0015 #include "ActsExamples/Framework/AlgorithmContext.hpp"
0016 #include "ActsExamples/Io/Csv/CsvInputOutput.hpp"
0017 #include "ActsExamples/Utilities/Paths.hpp"
0018 #include "ActsFatras/EventData/Barcode.hpp"
0019 #include "ActsFatras/EventData/Particle.hpp"
0020 #include "ActsFatras/EventData/ProcessType.hpp"
0021 #include <ActsExamples/Utilities/Paths.hpp>
0022 
0023 #include <array>
0024 #include <cmath>
0025 #include <stdexcept>
0026 #include <string>
0027 
0028 #include "CsvOutputData.hpp"
0029 
0030 namespace ActsExamples {
0031 
0032 CsvGnnGraphReader::CsvGnnGraphReader(const Config& config,
0033                                      Acts::Logging::Level level)
0034     : m_cfg(config),
0035       m_eventsRange(
0036           determineEventFilesRange(m_cfg.inputDir, m_cfg.inputStem + ".csv")),
0037       m_logger(Acts::getDefaultLogger("CsvGnnGraphReader", level)) {
0038   if (m_cfg.inputStem.empty()) {
0039     throw std::invalid_argument("Missing input filename stem");
0040   }
0041 
0042   m_outputGraph.initialize(m_cfg.outputGraph);
0043 }
0044 
0045 std::pair<std::size_t, std::size_t> CsvGnnGraphReader::availableEvents() const {
0046   return m_eventsRange;
0047 }
0048 
0049 ProcessCode CsvGnnGraphReader::read(const AlgorithmContext& ctx) {
0050   SimParticleContainer::sequence_type unordered;
0051 
0052   auto path = perEventFilepath(m_cfg.inputDir, m_cfg.inputStem + ".csv",
0053                                ctx.eventNumber);
0054   // vt and m are an optional columns
0055   ActsExamples::NamedTupleCsvReader<GraphData> reader(path, {"vt", "m"});
0056   GraphData data;
0057 
0058   Graph g;
0059 
0060   while (reader.read(data)) {
0061     g.edges.push_back(data.edge0);
0062     g.edges.push_back(data.edge1);
0063     g.weights.push_back(data.weight);
0064   }
0065 
0066   m_outputGraph(ctx, std::move(g));
0067 
0068   return ProcessCode::SUCCESS;
0069 }
0070 
0071 }  // namespace ActsExamples