|
| 1 | +// This file is part of the ACTS project. |
| 2 | +// |
| 3 | +// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/. |
| 8 | + |
| 9 | +#include "Acts/EventData/SpacePointContainer2.hpp" |
| 10 | +#include "Acts/Plugins/Root/RootSpacePoints2Accessor.hpp" |
| 11 | + |
| 12 | +#include <TChain.h> |
| 13 | +#include <TTree.h> |
| 14 | + |
| 15 | +namespace Acts { |
| 16 | + |
| 17 | +void RootSpacePointIo::connectForRead( |
| 18 | + TChain& tchain, const Experimental::SpacePointContainer2& spacePoints) { |
| 19 | + tchain.SetBranchAddress("index", &m_index); |
| 20 | + |
| 21 | + tchain.SetBranchAddress("x", &m_x); |
| 22 | + tchain.SetBranchAddress("y", &m_y); |
| 23 | + tchain.SetBranchAddress("z", &m_z); |
| 24 | + |
| 25 | + if (spacePoints.hasExtraColumns( |
| 26 | + Experimental::SpacePointKnownExtraColumn::Time)) { |
| 27 | + tchain.SetBranchAddress("t", &m_t); |
| 28 | + } |
| 29 | + |
| 30 | + if (spacePoints.hasExtraColumns( |
| 31 | + Experimental::SpacePointKnownExtraColumn::R)) { |
| 32 | + tchain.SetBranchAddress("r", &m_r); |
| 33 | + } |
| 34 | + |
| 35 | + if (spacePoints.hasExtraColumns( |
| 36 | + Experimental::SpacePointKnownExtraColumn::VarianceZ)) { |
| 37 | + tchain.SetBranchAddress("var_z", &m_varZ); |
| 38 | + } |
| 39 | + if (spacePoints.hasExtraColumns( |
| 40 | + Experimental::SpacePointKnownExtraColumn::VarianceR)) { |
| 41 | + tchain.SetBranchAddress("var_r", &m_varR); |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | +void RootSpacePointIo::connectForWrite( |
| 46 | + TTree& ttree, const Experimental::SpacePointContainer2& spacePoints) { |
| 47 | + ttree.Branch("index", &m_index); |
| 48 | + |
| 49 | + ttree.Branch("x", &m_x); |
| 50 | + ttree.Branch("y", &m_y); |
| 51 | + ttree.Branch("z", &m_z); |
| 52 | + |
| 53 | + if (spacePoints.hasExtraColumns( |
| 54 | + Experimental::SpacePointKnownExtraColumn::Time)) { |
| 55 | + ttree.Branch("t", &m_t); |
| 56 | + } |
| 57 | + |
| 58 | + if (spacePoints.hasExtraColumns( |
| 59 | + Experimental::SpacePointKnownExtraColumn::R)) { |
| 60 | + ttree.Branch("r", &m_r); |
| 61 | + } |
| 62 | + |
| 63 | + if (spacePoints.hasExtraColumns( |
| 64 | + Experimental::SpacePointKnownExtraColumn::VarianceZ)) { |
| 65 | + ttree.Branch("var_z", &m_varZ); |
| 66 | + } |
| 67 | + if (spacePoints.hasExtraColumns( |
| 68 | + Experimental::SpacePointKnownExtraColumn::VarianceR)) { |
| 69 | + ttree.Branch("var_r", &m_varR); |
| 70 | + } |
| 71 | +} |
| 72 | + |
| 73 | +void RootSpacePointIo::write( |
| 74 | + const Experimental::ConstSpacePointProxy2& spacePoint) { |
| 75 | + m_index = spacePoint.index(); |
| 76 | + |
| 77 | + m_x = spacePoint.x(); |
| 78 | + m_y = spacePoint.y(); |
| 79 | + m_z = spacePoint.z(); |
| 80 | + |
| 81 | + if (spacePoint.container().hasExtraColumns( |
| 82 | + Experimental::SpacePointKnownExtraColumn::Time)) { |
| 83 | + m_t = spacePoint.time(); |
| 84 | + } |
| 85 | + |
| 86 | + if (spacePoint.container().hasExtraColumns( |
| 87 | + Experimental::SpacePointKnownExtraColumn::R)) { |
| 88 | + m_r = spacePoint.r(); |
| 89 | + } |
| 90 | + |
| 91 | + if (spacePoint.container().hasExtraColumns( |
| 92 | + Experimental::SpacePointKnownExtraColumn::VarianceZ)) { |
| 93 | + m_varZ = spacePoint.varianceZ(); |
| 94 | + } |
| 95 | + if (spacePoint.container().hasExtraColumns( |
| 96 | + Experimental::SpacePointKnownExtraColumn::VarianceR)) { |
| 97 | + m_varR = spacePoint.varianceR(); |
| 98 | + } |
| 99 | +} |
| 100 | + |
| 101 | +void RootSpacePointIo::write( |
| 102 | + const Experimental::SpacePointContainer2& spacePoints, TTree& ttree) { |
| 103 | + connectForWrite(ttree, spacePoints); |
| 104 | + |
| 105 | + for (Experimental::ConstSpacePointProxy2 spacePoint : spacePoints) { |
| 106 | + write(spacePoint); |
| 107 | + ttree.Fill(); |
| 108 | + } |
| 109 | +} |
| 110 | + |
| 111 | +void RootSpacePointIo::read(Experimental::MutableSpacePointProxy2& spacePoint) { |
| 112 | + spacePoint.x() = m_x; |
| 113 | + spacePoint.y() = m_y; |
| 114 | + spacePoint.z() = m_z; |
| 115 | + |
| 116 | + if (spacePoint.container().hasExtraColumns( |
| 117 | + Experimental::SpacePointKnownExtraColumn::Time)) { |
| 118 | + spacePoint.time() = m_t; |
| 119 | + } |
| 120 | + |
| 121 | + if (spacePoint.container().hasExtraColumns( |
| 122 | + Experimental::SpacePointKnownExtraColumn::R)) { |
| 123 | + spacePoint.r() = m_r; |
| 124 | + } |
| 125 | + |
| 126 | + if (spacePoint.container().hasExtraColumns( |
| 127 | + Experimental::SpacePointKnownExtraColumn::VarianceZ)) { |
| 128 | + spacePoint.varianceZ() = m_varZ; |
| 129 | + } |
| 130 | + if (spacePoint.container().hasExtraColumns( |
| 131 | + Experimental::SpacePointKnownExtraColumn::VarianceR)) { |
| 132 | + spacePoint.varianceR() = m_varR; |
| 133 | + } |
| 134 | +} |
| 135 | + |
| 136 | +void RootSpacePointIo::read(TChain& tchain, |
| 137 | + Experimental::SpacePointContainer2& spacePoints) { |
| 138 | + connectForRead(tchain, spacePoints); |
| 139 | + |
| 140 | + std::size_t nEntries = tchain.GetEntries(); |
| 141 | + for (std::size_t i = 0; i < nEntries; ++i) { |
| 142 | + tchain.GetEntry(i); |
| 143 | + |
| 144 | + auto spacePoint = spacePoints.createSpacePoint( |
| 145 | + std::array<SourceLink, 1>{SourceLink(i)}, 0, 0, 0); |
| 146 | + read(spacePoint); |
| 147 | + } |
| 148 | +} |
| 149 | + |
| 150 | +} // namespace Acts |
0 commit comments