EIC 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 
18 
19 #include <memory>
20 #include <string>
21 
22 namespace ActsExamples {
23 
39 template <typename write_data_t>
40 class WriterT : public IWriter {
41  public:
45  WriterT(std::string objectName, std::string writerName,
46  Acts::Logging::Level level);
47 
49  std::string name() const final override;
50 
52  ProcessCode write(const AlgorithmContext& context) final override;
53 
55  ProcessCode endRun() override;
56 
57  protected:
63  virtual ProcessCode writeT(const AlgorithmContext& context,
64  const write_data_t& t) = 0;
65 
66  const Acts::Logger& logger() const { return *m_logger; }
67 
68  private:
69  std::string m_objectName;
70  std::string m_writerName;
71  std::unique_ptr<const Acts::Logger> m_logger;
72 };
73 
74 } // namespace ActsExamples
75 
76 template <typename write_data_t>
78  std::string writerName,
80  : m_objectName(std::move(objectName)),
81  m_writerName(std::move(writerName)),
82  m_logger(Acts::getDefaultLogger(m_writerName, level)) {
83  if (m_objectName.empty()) {
84  throw std::invalid_argument("Missing input collection");
85  } else if (m_writerName.empty()) {
86  throw std::invalid_argument("Missing writer name");
87  }
88 }
89 
90 template <typename write_data_t>
91 inline std::string ActsExamples::WriterT<write_data_t>::name() const {
92  return m_writerName;
93 }
94 
95 template <typename write_data_t>
97  return ProcessCode::SUCCESS;
98 }
99 
100 template <typename write_data_t>
102  const AlgorithmContext& context) {
103  return writeT(context, context.eventStore.get<write_data_t>(m_objectName));
104 }