Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
WriterT.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file WriterT.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 
12 
13 #pragma once
14 
19 
20 #include <limits>
21 #include <memory>
22 #include <string>
23 
24 namespace ActsExamples {
25 
27 constexpr double NaNdouble = std::numeric_limits<double>::quiet_NaN();
28 constexpr float NaNfloat = std::numeric_limits<float>::quiet_NaN();
29 constexpr float NaNint = std::numeric_limits<int>::quiet_NaN();
30 
46 template <typename write_data_t>
47 class WriterT : public IWriter {
48  public:
52  WriterT(std::string objectName, std::string writerName,
54 
56  std::string name() const override;
57 
59  ProcessCode write(const AlgorithmContext& context) override;
60 
62  ProcessCode finalize() override;
63 
64  protected:
70  virtual ProcessCode writeT(const AlgorithmContext& context,
71  const write_data_t& t) = 0;
72 
73  const Acts::Logger& logger() const { return *m_logger; }
74 
75  private:
78  std::unique_ptr<const Acts::Logger> m_logger;
79 
81 };
82 
83 } // namespace ActsExamples
84 
85 template <typename write_data_t>
87  std::string writerName,
89  : m_objectName(std::move(objectName)),
90  m_writerName(std::move(writerName)),
91  m_logger(Acts::getDefaultLogger(m_writerName, level)) {
92  if (m_objectName.empty()) {
93  throw std::invalid_argument("Missing input collection");
94  } else if (m_writerName.empty()) {
95  throw std::invalid_argument("Missing writer name");
96  }
97 
99 }
100 
101 template <typename write_data_t>
103  return m_writerName;
104 }
105 
106 template <typename write_data_t>
109  return ProcessCode::SUCCESS;
110 }
111 
112 template <typename write_data_t>
114  const AlgorithmContext& context) {
115  return writeT(context, m_inputHandle(context));
116 }