Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Blueprint.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Blueprint.hpp
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 
9 #pragma once
10 
15 
16 #include <memory>
17 #include <string>
18 #include <vector>
19 
20 namespace Acts {
21 namespace Experimental {
22 
26 
38 namespace Blueprint {
39 
40 struct Node final {
50  const std::vector<ActsScalar>& bv, const std::vector<BinningValue>& bss,
51  std::vector<std::unique_ptr<Node>> cs = {})
52  : name(n),
53  transform(t),
54  boundsType(bt),
55  boundaryValues(bv),
56  children(std::move(cs)),
57  binning(bss) {
58  for_each(children.begin(), children.end(),
59  [this](std::unique_ptr<Node>& c) { c->parent = this; });
60  }
61 
70  const std::vector<ActsScalar>& bv,
71  std::shared_ptr<const IInternalStructureBuilder> isb = nullptr)
72  : name(n),
73  transform(t),
74  boundsType(bt),
75  boundaryValues(bv),
76  internalsBuilder(std::move(isb)) {}
77 
81  Transform3 transform = Transform3::Identity();
85  std::vector<ActsScalar> boundaryValues = {};
87  const Node* parent = nullptr;
89  std::vector<std::unique_ptr<Node>> children = {};
91  std::vector<BinningValue> binning = {};
92 
94  std::shared_ptr<const IRootVolumeFinderBuilder> rootVolumeFinderBuilder =
95  nullptr;
97  std::shared_ptr<const IGeometryIdGenerator> geoIdGenerator = nullptr;
99  std::shared_ptr<const IInternalStructureBuilder> internalsBuilder = nullptr;
100 
102  bool isLeaf() const { return children.empty(); }
103 
105  bool isRoot() const { return parent == nullptr; }
106 
109  void add(std::unique_ptr<Node> c) {
110  c->parent = this;
111  children.push_back(std::move(c));
112  }
113 
115  template <typename stream_type>
116  void dotStream(stream_type& ss,
117  const std::string& graphName = "blueprint") const {
118  if (isRoot()) {
119  ss << "digraph " << graphName << " {" << '\n';
120  ss << name
121  << " [shape=\"circle\";style=\"filled\";fillcolor=\"darkorange\"];"
122  << '\n';
123 
124  } else if (isLeaf()) {
126  (internalsBuilder != nullptr) ? "darkolivegreen1" : "darkolivegreen3";
127 
128  ss << name << " [shape=\"box\";style=\"filled\";fillcolor=\"";
129  ss << color << "\"];" << '\n';
130  } else {
131  ss << name << " [shape=\"diamond\"];" << '\n';
132  }
133 
134  ss << name << " [label=\"" << name << "\"];" << '\n';
135  for (const auto& c : children) {
136  ss << name << " -> " << c->name << ";" << '\n';
137  c->dotStream(ss);
138  }
139  if (children.empty()) {
140  ss << name + "_shape"
141  << " [shape=\"cylinder\";style=\"filled\";fillcolor=\"lightgrey\"];"
142  << '\n';
143  ss << name << " -> " << name + "_shape"
144  << ";" << '\n';
145  }
146 
147  if (internalsBuilder != nullptr) {
148  ss << name + "_int"
149  << " [shape=\"doubleoctagon\";style=\"filled\";fillcolor="
150  "\"cadetblue1\"];"
151  << '\n';
152  ss << name << " -> " << name + "_int"
153  << ";" << '\n';
154  }
155 
156  if (geoIdGenerator != nullptr) {
157  ss << name + "_geoID"
158  << " [shape=\"note\";style=\"filled\";fillcolor=\"azure\"];" << '\n';
159  ss << name << " -> " << name + "_geoID"
160  << ";" << '\n';
161  }
162 
163  if (rootVolumeFinderBuilder != nullptr) {
164  ss << name + "_roots"
165  << " [shape=\"Msquare\";style=\"filled\";fillcolor=\"darkkhaki\"];"
166  << '\n';
167  ss << name << " -> " << name + "_roots"
168  << ";" << '\n';
169  }
170 
171  if (isRoot()) {
172  ss << "}" << '\n';
173  }
174  }
175 };
176 
177 } // namespace Blueprint
178 } // namespace Experimental
179 } // namespace Acts