ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ObjPropagationStepsWriter.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ObjPropagationStepsWriter.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2017 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #pragma once
10 
11 #include <fstream>
12 
16 
17 namespace FW {
18 
19 namespace Obj {
20 
30 template <typename step_t>
32  : public WriterT<std::vector<std::vector<step_t>>> {
33  public:
34  struct Config {
35  std::string collection;
36  std::string outputDir;
37  double outputScalor = 1.0;
38  size_t outputPrecision = 6;
39  };
40 
47  : WriterT<std::vector<std::vector<step_t>>>(cfg.collection,
48  "ObjSpacePointWriter", level),
49  m_cfg(cfg) {
50  if (m_cfg.collection.empty()) {
51  throw std::invalid_argument("Missing input collection");
52  }
53  }
54 
56  ~ObjPropagationStepsWriter() override = default;
57 
59  ProcessCode endRun() final override { return FW::ProcessCode::SUCCESS; }
60 
61  private:
63 
64  protected:
69  const std::vector<std::vector<step_t>>& stepCollection) final override {
70  // open per-event file
71  std::string path = FW::perEventFilepath(
72  m_cfg.outputDir, "propagation-steps.obj", context.eventNumber);
73  std::ofstream os(path, std::ofstream::out | std::ofstream::trunc);
74  if (!os) {
75  throw std::ios_base::failure("Could not open '" + path + "' to write");
76  }
77 
78  // Initialize the vertex counter
79  unsigned int vCounter = 0;
80 
81  for (auto& steps : stepCollection) {
82  // At least three points to draw
83  if (steps.size() > 2) {
84  // We start from one
85  ++vCounter;
86  for (auto& step : steps) {
87  // Write the space point
88  os << "v " << m_cfg.outputScalor * step.position.x() << " "
89  << m_cfg.outputScalor * step.position.y() << " "
90  << m_cfg.outputScalor * step.position.z() << '\n';
91  }
92  // Write out the line - only if we have at least two points created
93  size_t vBreak = vCounter + steps.size() - 1;
94  for (; vCounter < vBreak; ++vCounter)
95  os << "l " << vCounter << " " << vCounter + 1 << '\n';
96  }
97  }
99  }
100 };
101 
102 } // namespace Obj
103 } // namespace FW