Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DetectorBuilder.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file DetectorBuilder.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 
15 
16 #include <stdexcept>
17 
20  std::unique_ptr<const Acts::Logger> mlogger)
21  : IDetectorBuilder(), m_cfg(cfg), m_logger(std::move(mlogger)) {
22  if (m_cfg.builder == nullptr) {
23  throw std::invalid_argument(
24  "DetectorBuilder: no top level builder defined.");
25  }
26 }
27 
28 std::shared_ptr<const Acts::Experimental::Detector>
30  const GeometryContext& gctx) const {
31  // Screen printout of the auxiliary information
32  if (not m_cfg.auxiliary.empty()) {
33  ACTS_DEBUG(m_cfg.auxiliary);
34  }
35  ACTS_DEBUG("Building a detector with name " << m_cfg.name);
36 
37  auto [volumes, portals, roots] = m_cfg.builder->construct(gctx);
38 
39  if (m_cfg.geoIdGenerator != nullptr) {
40  ACTS_DEBUG("Assigning geometry ids to the detector");
41  auto cache = m_cfg.geoIdGenerator->generateCache();
42  std::for_each(roots.volumes.begin(), roots.volumes.end(), [&](auto& v) {
43  m_cfg.geoIdGenerator->assignGeometryId(cache, *v);
44  });
45  }
46 
47  return Detector::makeShared(m_cfg.name, std::move(roots.volumes),
48  std::move(roots.volumeFinder));
49 }