Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CsvSpacePointReader.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CsvSpacePointReader.cpp
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 
10 
16 
17 #include <array>
18 #include <fstream>
19 #include <stdexcept>
20 #include <string>
21 
22 #include <boost/container/static_vector.hpp>
23 #include <dfe/dfe_io_dsv.hpp>
24 
25 #include "CsvOutputData.hpp"
26 
30  m_cfg = cfg;
31  if (m_cfg.inputStem.empty()) {
32  throw std::invalid_argument("Missing input filename stem");
33  }
34  auto& filename = m_cfg.inputCollection.empty()
35  ? cfg.inputStem
36  : cfg.inputStem + '_' + cfg.inputCollection;
38  m_logger = Acts::getDefaultLogger("CsvSpacePointReader", lvl);
39 
41 }
42 
44  const {
45  return "CsvSpacePointReader";
46 }
47 
49  const {
50  return m_eventsRange;
51 }
52 
54  const ActsExamples::AlgorithmContext& ctx) {
55  SimSpacePointContainer spacePoints;
56 
57  const auto& filename = m_cfg.inputCollection.empty()
58  ? m_cfg.inputStem
59  : m_cfg.inputStem + '_' + m_cfg.inputCollection;
60  const auto& path =
61  perEventFilepath(m_cfg.inputDir, filename + ".csv", ctx.eventNumber);
62 
63  dfe::NamedTupleCsvReader<SpacePointData> reader(path);
65 
66  while (reader.read(data)) {
67  Acts::Vector3 globalPos(data.sp_x, data.sp_y, data.sp_z);
68 
69  if (m_cfg.inputCollection == "pixel" || m_cfg.inputCollection == "strip" ||
70  m_cfg.inputCollection == "overlap") {
71  boost::container::static_vector<Acts::SourceLink, 2> sLinks;
72  // auto sp = SimSpacePoint(globalPos, data.sp_covr, data.sp_covz, sLinks);
73 
74  if (m_cfg.extendCollection) {
75  Acts::Vector3 topStripDirection(data.sp_topStripDirection[0],
76  data.sp_topStripDirection[1],
77  data.sp_topStripDirection[2]);
78  Acts::Vector3 bottomStripDirection(data.sp_bottomStripDirection[0],
80  data.sp_bottomStripDirection[2]);
81  Acts::Vector3 stripCenterDistance(data.sp_stripCenterDistance[0],
82  data.sp_stripCenterDistance[1],
83  data.sp_stripCenterDistance[2]);
84  Acts::Vector3 topStripCenterPosition(data.sp_topStripCenterPosition[0],
87 
88  spacePoints.emplace_back(globalPos, data.sp_covr, data.sp_covz, sLinks,
91  topStripDirection, bottomStripDirection,
92  stripCenterDistance, topStripCenterPosition);
93  } else {
94  spacePoints.emplace_back(globalPos, data.sp_covr, data.sp_covz, sLinks);
95  }
96  } else {
97  ACTS_ERROR("Invalid space point type " << m_cfg.inputStem);
98  return ProcessCode::ABORT;
99  }
100  }
101 
102  ACTS_DEBUG("Created " << spacePoints.size() << " " << m_cfg.inputCollection
103  << " space points");
104  m_outputSpacePoints(ctx, std::move(spacePoints));
105 
106  return ProcessCode::SUCCESS;
107 }