Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 09:17:03

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/Obj/ObjPropagationStepsWriter.hpp"
0010 
0011 namespace ActsExamples {
0012 
0013 ObjPropagationStepsWriter::ObjPropagationStepsWriter(const Config& cfg,
0014                                                      Acts::Logging::Level level)
0015     : WriterT<PropagationSummaries>(cfg.collection, "ObjPropagationStepsWriter",
0016                                     level),
0017       m_cfg(cfg) {
0018   if (m_cfg.collection.empty()) {
0019     throw std::invalid_argument("Missing input collection");
0020   }
0021 }
0022 
0023 /// This implementation holds the actual writing method
0024 /// and is called by the WriterT<>::write interface
0025 ProcessCode ObjPropagationStepsWriter::writeT(
0026     const AlgorithmContext& context, const PropagationSummaries& summaries) {
0027   // open per-event file
0028   std::string path = ActsExamples::perEventFilepath(
0029       m_cfg.outputDir, "propagation-steps.obj", context.eventNumber);
0030   std::ofstream os(path, std::ofstream::out | std::ofstream::trunc);
0031   if (!os) {
0032     throw std::ios_base::failure("Could not open '" + path + "' to write");
0033   }
0034 
0035   // Initialize the vertex counter
0036   unsigned int vCounter = 0;
0037 
0038   for (const auto& summary : summaries) {
0039     const auto& steps = summary.steps;
0040     // At least three points to draw
0041     if (steps.size() > 2) {
0042       // We start from one
0043       ++vCounter;
0044       for (auto& step : steps) {
0045         // Write the space point
0046         os << "v " << m_cfg.outputScalor * step.position.x() << " "
0047            << m_cfg.outputScalor * step.position.y() << " "
0048            << m_cfg.outputScalor * step.position.z() << '\n';
0049       }
0050       // Write out the line - only if we have at least two points created
0051       std::size_t vBreak = vCounter + steps.size() - 1;
0052       for (; vCounter < vBreak; ++vCounter) {
0053         os << "l " << vCounter << " " << vCounter + 1 << '\n';
0054       }
0055     }
0056   }
0057   return ActsExamples::ProcessCode::SUCCESS;
0058 }
0059 
0060 }  // namespace ActsExamples