File indexing completed on 2026-09-14 08:37:52
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Utilities/Logger.hpp"
0012 #include "ActsExamples/Framework/DataHandle.hpp"
0013 #include "ActsExamples/Framework/IWriter.hpp"
0014
0015 #include <limits>
0016 #include <memory>
0017 #include <string>
0018
0019 namespace ActsExamples {
0020
0021
0022 constexpr double NaNdouble = std::numeric_limits<double>::quiet_NaN();
0023 constexpr float NaNfloat = std::numeric_limits<float>::quiet_NaN();
0024 constexpr float NaNint = std::numeric_limits<int>::quiet_NaN();
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041 template <typename write_data_t>
0042 class WriterT : public IWriter {
0043 public:
0044
0045
0046
0047 WriterT(std::string objectName, std::string writerName,
0048 Acts::Logging::Level level);
0049
0050
0051 std::string name() const override;
0052
0053
0054 ProcessCode write(const AlgorithmContext& context) override;
0055
0056
0057 ProcessCode finalize() override;
0058
0059 protected:
0060
0061
0062
0063
0064
0065 virtual ProcessCode writeT(const AlgorithmContext& context,
0066 const write_data_t& t) = 0;
0067
0068 const Acts::Logger& logger() const { return *m_logger; }
0069
0070 private:
0071 std::string m_objectName;
0072 std::string m_writerName;
0073 std::unique_ptr<const Acts::Logger> m_logger;
0074
0075 ReadDataHandle<write_data_t> m_inputHandle{this, "InputHandle"};
0076 };
0077
0078 template <typename write_data_t>
0079 WriterT<write_data_t>::WriterT(std::string objectName, std::string writerName,
0080 Acts::Logging::Level level)
0081 : m_objectName(std::move(objectName)),
0082 m_writerName(std::move(writerName)),
0083 m_logger(Acts::getDefaultLogger(m_writerName, level)) {
0084 if (m_objectName.empty()) {
0085 throw std::invalid_argument("Missing input collection");
0086 } else if (m_writerName.empty()) {
0087 throw std::invalid_argument("Missing writer name");
0088 }
0089
0090 m_inputHandle.initialize(m_objectName);
0091 }
0092
0093 template <typename write_data_t>
0094 inline std::string WriterT<write_data_t>::name() const {
0095 return m_writerName;
0096 }
0097
0098 template <typename write_data_t>
0099 inline ProcessCode WriterT<write_data_t>::finalize() {
0100 return ProcessCode::SUCCESS;
0101 }
0102
0103 template <typename write_data_t>
0104 inline ProcessCode WriterT<write_data_t>::write(
0105 const AlgorithmContext& context) {
0106 return writeT(context, m_inputHandle(context));
0107 }
0108
0109 }