Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ObjSpacePointWriter.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ObjSpacePointWriter.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2017-2018 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 
14 
15 #include <fstream>
16 
17 namespace ActsExamples {
18 
29 template <typename T>
30 class ObjSpacePointWriter : public WriterT<GeometryIdMultimap<T>> {
31  public:
32  struct Config {
35  double outputScalor = 1.0;
36  size_t outputPrecision = 6;
37  };
38 
41 
42  protected:
43  ProcessCode writeT(const AlgorithmContext& context,
44  const GeometryIdMultimap<T>& spacePoints);
45 
46  private:
47  // since class iitself is templated, base class template must be fixed
49 
51 };
52 
53 } // namespace ActsExamples
54 
55 template <typename T>
58  : Base(cfg.collection, "ObjSpacePointWriter", level), m_cfg(cfg) {
59  if (m_cfg.collection.empty()) {
60  throw std::invalid_argument("Missing input collection");
61  }
62 }
63 
64 template <typename T>
66  const ActsExamples::AlgorithmContext& context,
67  const ActsExamples::GeometryIdMultimap<T>& spacePoints) {
68  // open per-event file
70  m_cfg.outputDir, "spacepoints.obj", context.eventNumber);
71  std::ofstream os(path, std::ofstream::out | std::ofstream::trunc);
72  if (!os) {
73  throw std::ios_base::failure("Could not open '" + path + "' to write");
74  }
75 
76  os << std::setprecision(m_cfg.outputPrecision);
77  // count the vertex
78  size_t vertex = 0;
79  // loop and fill the space point data
80  for (auto& volumeData : spacePoints) {
81  for (auto& layerData : volumeData.second) {
82  for (auto& moduleData : layerData.second) {
83  for (auto& data : moduleData.second) {
84  // write the space point
85  os << "v " << m_cfg.outputScalor * data.x() << " "
86  << m_cfg.outputScalor * data.y() << " "
87  << m_cfg.outputScalor * data.z() << '\n';
88  os << "p " << ++vertex << '\n';
89  }
90  }
91  }
92  }
93  return ProcessCode::SUCCESS;
94 }