Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ExaTrkXPipeline.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ExaTrkXPipeline.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2023 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 
11 namespace Acts {
12 
14  std::shared_ptr<GraphConstructionBase> graphConstructor,
15  std::vector<std::shared_ptr<EdgeClassificationBase>> edgeClassifiers,
16  std::shared_ptr<TrackBuildingBase> trackBuilder,
17  std::unique_ptr<const Acts::Logger> logger)
18  : m_logger(std::move(logger)),
19  m_graphConstructor(graphConstructor),
20  m_edgeClassifiers(edgeClassifiers),
21  m_trackBuilder(trackBuilder) {
22  if (!m_graphConstructor) {
23  throw std::invalid_argument("Missing graph construction module");
24  }
25  if (!m_trackBuilder) {
26  throw std::invalid_argument("Missing track building module");
27  }
28  if (m_edgeClassifiers.empty() or
29  not std::all_of(m_edgeClassifiers.begin(), m_edgeClassifiers.end(),
30  [](const auto &a) { return static_cast<bool>(a); })) {
31  throw std::invalid_argument("Missing graph construction module");
32  }
33 }
34 
35 std::vector<std::vector<int>> ExaTrkXPipeline::run(
36  std::vector<float> &features, std::vector<int> &spacepointIDs,
37  int deviceHint, const ExaTrkXHook &hook, ExaTrkXTiming *timing) const {
38  auto t0 = std::chrono::high_resolution_clock::now();
39  auto [nodes, edges] =
40  (*m_graphConstructor)(features, spacepointIDs.size(), deviceHint);
41  auto t1 = std::chrono::high_resolution_clock::now();
42 
43  if (timing != nullptr) {
44  timing->graphBuildingTime = t1 - t0;
45  }
46 
47  hook(nodes, edges);
48 
49  std::any edge_weights;
50  timing->classifierTimes.clear();
51 
52  for (auto edgeClassifier : m_edgeClassifiers) {
53  t0 = std::chrono::high_resolution_clock::now();
54  auto [newNodes, newEdges, newWeights] =
55  (*edgeClassifier)(std::move(nodes), std::move(edges), deviceHint);
56  t1 = std::chrono::high_resolution_clock::now();
57 
58  if (timing != nullptr) {
59  timing->classifierTimes.push_back(t1 - t0);
60  }
61 
62  nodes = std::move(newNodes);
63  edges = std::move(newEdges);
64  edge_weights = std::move(newWeights);
65 
66  hook(nodes, edges);
67  }
68 
69  t0 = std::chrono::high_resolution_clock::now();
70  auto res =
71  (*m_trackBuilder)(std::move(nodes), std::move(edges),
72  std::move(edge_weights), spacepointIDs, deviceHint);
73  t1 = std::chrono::high_resolution_clock::now();
74 
75  if (timing != nullptr) {
76  timing->trackBuildingTime = t1 - t0;
77  }
78 
79  return res;
80 }
81 
82 } // namespace Acts