Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EDM4hepMeasurementWriter.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EDM4hepMeasurementWriter.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2022 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 http://mozilla.org/MPL/2.0/.
8 
10 
16 
17 #include <stdexcept>
18 
19 #include <podio/Frame.h>
20 
21 namespace ActsExamples {
22 
25  : WriterT(config.inputMeasurements, "EDM4hepMeasurementWriter", level),
26  m_cfg(config),
27  m_writer(config.outputPath) {
28  ACTS_VERBOSE("Created output file " << config.outputPath);
29 
30  // Input container for measurements is already checked by base constructor
32 }
33 
35  m_writer.finish();
36 
37  return ProcessCode::SUCCESS;
38 }
39 
41  const AlgorithmContext& ctx, const MeasurementContainer& measurements) {
43 
44  podio::Frame frame;
45 
46  edm4hep::TrackerHitPlaneCollection hitsPlane;
47  edm4hep::TrackerHitCollection hits;
48 
49  if (!m_cfg.inputClusters.empty()) {
50  ACTS_VERBOSE("Fetch clusters for writing: " << m_cfg.inputClusters);
51  clusters = m_inputClusters(ctx);
52  }
53 
54  ACTS_VERBOSE("Writing " << measurements.size()
55  << " measurements in this event.");
56 
57  for (Index hitIdx = 0u; hitIdx < measurements.size(); ++hitIdx) {
58  const auto& from = measurements[hitIdx];
59  const Cluster* fromCluster = clusters.empty() ? nullptr : &clusters[hitIdx];
60 
61  auto to = hitsPlane.create();
63  from, to, fromCluster, hits,
64  [](Acts::GeometryIdentifier id) { return id.value(); });
65  }
66 
67  frame.put(std::move(hitsPlane), "ActsTrackerHitsPlane");
68  frame.put(std::move(hits), "ActsTrackerHitsRaw");
69 
70  m_writer.writeFrame(frame, "events");
71 
73 }
74 
75 } // namespace ActsExamples