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