Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
WhiteBoardUtilities.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file WhiteBoardUtilities.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2023 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 
9 #pragma once
10 
14 
15 #include <tuple>
16 
17 namespace Acts::Test {
19  ActsExamples::ProcessCode initialize() override { return {}; };
20  ActsExamples::ProcessCode finalize() override { return {}; };
22  const ActsExamples::AlgorithmContext & /*context*/) override {
23  return {};
24  };
25  std::string name() const override { return {}; };
26 };
27 
28 template <typename T>
30  DummySequenceElement dummyElement;
31 
32  ActsExamples::WriteDataHandle<T> handle(&dummyElement, name + "handle");
33  handle.initialize(name);
34  handle(wb, std::move(data));
35 }
36 
37 template <typename T>
39  DummySequenceElement dummyElement;
40 
41  ActsExamples::ReadDataHandle<T> handle(&dummyElement, name + "handle");
42  handle.initialize(name);
43  return handle(wb);
44 }
45 
46 template <typename val_tuple_t = std::tuple<>,
47  typename str_tuple_t = std::tuple<>>
49  val_tuple_t tuple;
50  str_tuple_t strings;
51 
52  constexpr static std::size_t kSize = std::tuple_size_v<val_tuple_t>;
53  static_assert(kSize == std::tuple_size_v<str_tuple_t>);
54 
55  template <typename T>
56  auto add(const std::string &name, T value) {
57  auto newTuple = std::tuple_cat(tuple, std::tuple<T>{value});
58  auto newStrings = std::tuple_cat(strings, std::tuple<std::string>{name});
59 
61  newInstance.tuple = std::move(newTuple);
62  newInstance.strings = std::move(newStrings);
63 
64  return newInstance;
65  }
66 
67  template <typename writer_t>
68  auto write(writer_t &writer, std::size_t eventId = 0) {
70  ActsExamples::AlgorithmContext ctx(0, eventId, board);
71 
72  auto add = [&](auto &self, auto N) {
73  if constexpr (N() < kSize) {
74  addToWhiteBoard(std::get<N()>(strings), std::get<N()>(tuple), board);
75  self(self, std::integral_constant<std::size_t, N() + 1>{});
76  }
77  };
78 
79  add(add, std::integral_constant<std::size_t, 0>{});
80 
81  writer.internalExecute(ctx);
82  }
83 
84  template <typename reader_t>
85  auto read(reader_t &reader, std::size_t eventId = 0) {
87  ActsExamples::AlgorithmContext ctx(0, eventId, board);
88 
89  reader.internalExecute(ctx);
90 
91  auto get = [&](auto &self, auto res, auto N) {
92  if constexpr (N() < kSize) {
93  using T = std::tuple_element_t<N(), val_tuple_t>;
94  auto val = getFromWhiteBoard<T>(std::get<N()>(strings), board);
95  return self(self, std::tuple_cat(res, std::make_tuple(val)),
96  std::integral_constant<std::size_t, N() + 1>{});
97  } else {
98  return res;
99  }
100  };
101 
102  return get(get, std::tuple<>{}, std::integral_constant<std::size_t, 0>{});
103  }
104 };
105 } // namespace Acts::Test