Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:11:52

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