Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:10:47

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2022 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 http://mozilla.org/MPL/2.0/.
0008 
0009 #include "ActsExamples/Io/EDM4hep/EDM4hepMeasurementWriter.hpp"
0010 
0011 #include "Acts/Definitions/Units.hpp"
0012 #include "Acts/EventData/Measurement.hpp"
0013 #include "ActsExamples/EventData/Cluster.hpp"
0014 #include "ActsExamples/Framework/WhiteBoard.hpp"
0015 #include "ActsExamples/Io/EDM4hep/EDM4hepUtil.hpp"
0016 
0017 #include <stdexcept>
0018 
0019 #include <podio/Frame.h>
0020 
0021 namespace ActsExamples {
0022 
0023 EDM4hepMeasurementWriter::EDM4hepMeasurementWriter(
0024     const EDM4hepMeasurementWriter::Config& config, Acts::Logging::Level level)
0025     : WriterT(config.inputMeasurements, "EDM4hepMeasurementWriter", level),
0026       m_cfg(config),
0027       m_writer(config.outputPath) {
0028   ACTS_VERBOSE("Created output file " << config.outputPath);
0029 
0030   // Input container for measurements is already checked by base constructor
0031   m_inputClusters.maybeInitialize(m_cfg.inputClusters);
0032 }
0033 
0034 ActsExamples::ProcessCode EDM4hepMeasurementWriter::finalize() {
0035   m_writer.finish();
0036 
0037   return ProcessCode::SUCCESS;
0038 }
0039 
0040 ActsExamples::ProcessCode EDM4hepMeasurementWriter::writeT(
0041     const AlgorithmContext& ctx, const MeasurementContainer& measurements) {
0042   ClusterContainer clusters;
0043 
0044   podio::Frame frame;
0045 
0046   edm4hep::TrackerHitPlaneCollection hitsPlane;
0047   edm4hep::TrackerHitCollection hits;
0048 
0049   if (!m_cfg.inputClusters.empty()) {
0050     ACTS_VERBOSE("Fetch clusters for writing: " << m_cfg.inputClusters);
0051     clusters = m_inputClusters(ctx);
0052   }
0053 
0054   ACTS_VERBOSE("Writing " << measurements.size()
0055                           << " measurements in this event.");
0056 
0057   for (Index hitIdx = 0u; hitIdx < measurements.size(); ++hitIdx) {
0058     const auto& from = measurements[hitIdx];
0059     const Cluster* fromCluster = clusters.empty() ? nullptr : &clusters[hitIdx];
0060 
0061     auto to = hitsPlane.create();
0062     EDM4hepUtil::writeMeasurement(
0063         from, to, fromCluster, hits,
0064         [](Acts::GeometryIdentifier id) { return id.value(); });
0065   }
0066 
0067   frame.put(std::move(hitsPlane), "ActsTrackerHitsPlane");
0068   frame.put(std::move(hits), "ActsTrackerHitsRaw");
0069 
0070   std::lock_guard guard(m_writeMutex);
0071   m_writer.writeFrame(frame, "events");
0072 
0073   return ActsExamples::ProcessCode::SUCCESS;
0074 }
0075 
0076 }  // namespace ActsExamples