Back to home page

sPhenix code displayed by LXR

 
 

    


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

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/CsvVertexWriter.hpp"
0010 
0011 #include "ActsExamples/Framework/AlgorithmContext.hpp"
0012 #include "ActsExamples/Io/Csv/CsvInputOutput.hpp"
0013 #include "ActsExamples/Utilities/Paths.hpp"
0014 #include <Acts/Definitions/Units.hpp>
0015 
0016 #include <stdexcept>
0017 
0018 #include "CsvOutputData.hpp"
0019 
0020 namespace ActsExamples {
0021 
0022 CsvVertexWriter::CsvVertexWriter(const Config& cfg, Acts::Logging::Level lvl)
0023     : WriterT(cfg.inputVertices, "CsvVertexWriter", lvl), m_cfg(cfg) {
0024   // inputVertices is already checked by base constructor
0025   if (m_cfg.outputStem.empty()) {
0026     throw std::invalid_argument("Missing output filename stem");
0027   }
0028 }
0029 
0030 ProcessCode CsvVertexWriter::writeT(const AlgorithmContext& ctx,
0031                                     const SimVertexContainerV& vertices) {
0032   auto pathVertices = perEventFilepath(
0033       m_cfg.outputDir, m_cfg.outputStem + ".csv", ctx.eventNumber);
0034   NamedTupleCsvWriter<VertexData> writer(pathVertices, m_cfg.outputPrecision);
0035 
0036   // Iterate over the vertices, and write out the 4 positions
0037   VertexData data;
0038   for (const auto& vertex : vertices) {
0039     data.x = vertex.fullPosition()[Acts::CoordinateIndices::eX];
0040     data.y = vertex.fullPosition()[Acts::CoordinateIndices::eY];
0041     data.z = vertex.fullPosition()[Acts::CoordinateIndices::eZ];
0042     data.T = vertex.fullPosition()[Acts::CoordinateIndices::eTime];
0043 
0044     writer.append(data);
0045   }
0046 
0047   return ProcessCode::SUCCESS;
0048 }
0049 
0050 }  // namespace ActsExamples