Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-03-28 07:46:19

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include "ActsPlugins/Root/RootSpacePointIo.hpp"
0010 
0011 #include "Acts/EventData/SourceLink.hpp"
0012 #include "Acts/EventData/SpacePointContainer2.hpp"
0013 #include "Acts/EventData/Types.hpp"
0014 
0015 #include <TChain.h>
0016 #include <TTree.h>
0017 
0018 using namespace Acts;
0019 
0020 namespace ActsPlugins {
0021 
0022 void RootSpacePointIo::connectForRead(TChain& tchain,
0023                                       const SpacePointContainer2& spacePoints) {
0024   using enum SpacePointColumns;
0025 
0026   if (spacePoints.hasColumns(X)) {
0027     tchain.SetBranchAddress("x", &m_x);
0028   }
0029   if (spacePoints.hasColumns(Y)) {
0030     tchain.SetBranchAddress("y", &m_y);
0031   }
0032   if (spacePoints.hasColumns(Z)) {
0033     tchain.SetBranchAddress("z", &m_z);
0034   }
0035 
0036   if (spacePoints.hasColumns(Time)) {
0037     tchain.SetBranchAddress("t", &m_t);
0038   }
0039 
0040   if (spacePoints.hasColumns(R)) {
0041     tchain.SetBranchAddress("r", &m_r);
0042   }
0043 
0044   if (spacePoints.hasColumns(VarianceZ)) {
0045     tchain.SetBranchAddress("var_z", &m_varZ);
0046   }
0047   if (spacePoints.hasColumns(VarianceR)) {
0048     tchain.SetBranchAddress("var_r", &m_varR);
0049   }
0050 }
0051 
0052 void RootSpacePointIo::connectForWrite(
0053     TTree& ttree, const SpacePointContainer2& spacePoints) {
0054   using enum SpacePointColumns;
0055 
0056   if (spacePoints.hasColumns(X)) {
0057     ttree.Branch("x", &m_x);
0058   }
0059   if (spacePoints.hasColumns(Y)) {
0060     ttree.Branch("y", &m_y);
0061   }
0062   if (spacePoints.hasColumns(Z)) {
0063     ttree.Branch("z", &m_z);
0064   }
0065 
0066   if (spacePoints.hasColumns(Time)) {
0067     ttree.Branch("t", &m_t);
0068   }
0069 
0070   if (spacePoints.hasColumns(R)) {
0071     ttree.Branch("r", &m_r);
0072   }
0073 
0074   if (spacePoints.hasColumns(VarianceZ)) {
0075     ttree.Branch("var_z", &m_varZ);
0076   }
0077   if (spacePoints.hasColumns(VarianceR)) {
0078     ttree.Branch("var_r", &m_varR);
0079   }
0080 }
0081 
0082 void RootSpacePointIo::write(const ConstSpacePointProxy2& spacePoint) {
0083   using enum SpacePointColumns;
0084 
0085   if (spacePoint.container().hasColumns(X)) {
0086     m_x = spacePoint.x();
0087   }
0088   if (spacePoint.container().hasColumns(Y)) {
0089     m_y = spacePoint.y();
0090   }
0091   if (spacePoint.container().hasColumns(Z)) {
0092     m_z = spacePoint.z();
0093   }
0094 
0095   if (spacePoint.container().hasColumns(Time)) {
0096     m_t = spacePoint.time();
0097   }
0098 
0099   if (spacePoint.container().hasColumns(R)) {
0100     m_r = spacePoint.r();
0101   }
0102 
0103   if (spacePoint.container().hasColumns(VarianceZ)) {
0104     m_varZ = spacePoint.varianceZ();
0105   }
0106   if (spacePoint.container().hasColumns(VarianceR)) {
0107     m_varR = spacePoint.varianceR();
0108   }
0109 }
0110 
0111 void RootSpacePointIo::write(const SpacePointContainer2& spacePoints,
0112                              TTree& ttree) {
0113   connectForWrite(ttree, spacePoints);
0114 
0115   for (ConstSpacePointProxy2 spacePoint : spacePoints) {
0116     write(spacePoint);
0117     ttree.Fill();
0118   }
0119 }
0120 
0121 void RootSpacePointIo::read(MutableSpacePointProxy2& spacePoint,
0122                             SpacePointIndex2 index) {
0123   using enum SpacePointColumns;
0124 
0125   if (spacePoint.container().hasColumns(SourceLinks)) {
0126     spacePoint.assignSourceLinks(std::array<SourceLink, 1>{SourceLink(index)});
0127   }
0128 
0129   if (spacePoint.container().hasColumns(X)) {
0130     spacePoint.x() = m_x;
0131   }
0132   if (spacePoint.container().hasColumns(Y)) {
0133     spacePoint.y() = m_y;
0134   }
0135   if (spacePoint.container().hasColumns(Z)) {
0136     spacePoint.z() = m_z;
0137   }
0138 
0139   if (spacePoint.container().hasColumns(Time)) {
0140     spacePoint.time() = m_t;
0141   }
0142 
0143   if (spacePoint.container().hasColumns(R)) {
0144     spacePoint.r() = m_r;
0145   }
0146 
0147   if (spacePoint.container().hasColumns(VarianceZ)) {
0148     spacePoint.varianceZ() = m_varZ;
0149   }
0150   if (spacePoint.container().hasColumns(VarianceR)) {
0151     spacePoint.varianceR() = m_varR;
0152   }
0153 }
0154 
0155 void RootSpacePointIo::read(TChain& tchain, SpacePointContainer2& spacePoints) {
0156   connectForRead(tchain, spacePoints);
0157 
0158   std::size_t nEntries = tchain.GetEntries();
0159   for (std::size_t i = 0; i < nEntries; ++i) {
0160     tchain.GetEntry(i);
0161 
0162     auto spacePoint = spacePoints.createSpacePoint();
0163     read(spacePoint, static_cast<SpacePointIndex2>(i));
0164   }
0165 }
0166 
0167 }  // namespace ActsPlugins