Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-01-10 09:17:22

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 "ActsExamples/Io/Csv/CsvSpacePointsBucketWriter.hpp"
0010 
0011 #include "ActsExamples/EventData/SimSpacePoint.hpp"
0012 #include "ActsExamples/Io/Csv/CsvInputOutput.hpp"
0013 #include "ActsExamples/Utilities/Paths.hpp"
0014 
0015 #include <cstddef>
0016 
0017 #include "CsvOutputData.hpp"
0018 
0019 namespace ActsExamples {
0020 
0021 CsvSpacePointsBucketWriter::CsvSpacePointsBucketWriter(
0022     const Config& config, Acts::Logging::Level level)
0023     : WriterT(config.inputBuckets, "CsvSpacePointsBucketWriter", level),
0024       m_cfg(config) {}
0025 
0026 CsvSpacePointsBucketWriter::~CsvSpacePointsBucketWriter() = default;
0027 
0028 ProcessCode CsvSpacePointsBucketWriter::finalize() {
0029   // Write the tree
0030   return ProcessCode::SUCCESS;
0031 }
0032 
0033 ProcessCode CsvSpacePointsBucketWriter::writeT(
0034     const AlgorithmContext& ctx,
0035     const std::vector<SimSpacePointContainer>& buckets) {
0036   // Open per-event file for all components
0037   std::string pathBucket =
0038       perEventFilepath(m_cfg.outputDir, "buckets.csv", ctx.eventNumber);
0039 
0040   NamedTupleCsvWriter<SpacePointBucketData> writerBucket(pathBucket,
0041                                                          m_cfg.outputPrecision);
0042 
0043   SpacePointBucketData bucketData{};
0044 
0045   int bucketIdx = 0;
0046   for (const auto& bucket : buckets) {
0047     if (bucket.empty()) {
0048       continue;
0049     }
0050     // Split the bucket into lines of 20 space points to manage variable sizes
0051     auto numLines =
0052         static_cast<int>((bucket.size() / 20) +
0053                          static_cast<std::size_t>(bucket.size() % 20 != 0));
0054     for (int nLines = 0; nLines < numLines; nLines++) {
0055       bucketData.bucketIdx = bucketIdx;
0056       bucketData.bucketSize = bucket.size();
0057       int maxSPIdx =
0058           std::min(20, static_cast<int>(bucket.size() - nLines * 20));
0059       for (int SPIdx = 0; SPIdx < maxSPIdx; SPIdx++) {
0060         bucketData.measurement_id[SPIdx] = (bucket[nLines * 20 + SPIdx])
0061                                                .sourceLinks()[0]
0062                                                .get<IndexSourceLink>()
0063                                                .index();
0064       }
0065       writerBucket.append(bucketData);
0066     }
0067     bucketIdx++;
0068   }
0069 
0070   return ProcessCode::SUCCESS;
0071 }
0072 
0073 }  // namespace ActsExamples