Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:10:21

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2023 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 http://mozilla.org/MPL/2.0/.
0008 
0009 #include "Acts/Detector/detail/BlueprintDrawer.hpp"
0010 
0011 #include <vector>
0012 
0013 namespace {
0014 
0015 /// @brief Generate the shape string
0016 /// @param s the shape of the object
0017 /// @param c the color of the object
0018 /// @return a string with the shape and color
0019 std::string shapeStr(
0020     const Acts::Experimental::detail::BlueprintDrawer::Options::Node& node) {
0021   return "[shape=\"" + node.shape + "\";style=\"filled\";fillcolor=\"" +
0022          node.color + "\"];";
0023 }
0024 
0025 /// @brief Generate text output
0026 ///
0027 /// @param node the node options
0028 /// @param label the label text
0029 /// @param info the info text
0030 std::string labelStr(
0031     const Acts::Experimental::detail::BlueprintDrawer::Options::Node& node,
0032     const std::string& label, const std::vector<std::string>& info = {}) {
0033   std::string lText = "[label=<<font face=\"";
0034   lText += node.face;
0035   lText += "\" point-size=\"";
0036   lText += std::to_string(node.labelText);
0037   lText += "\">" + label;
0038   if (!info.empty()) {
0039     lText += "</font><br/>";
0040     lText += "<font face=\"";
0041     lText += node.face;
0042     lText += "\" point-size=\"";
0043     lText += std::to_string(node.infoText);
0044     lText += "\">";
0045     for (const auto& i : info) {
0046       lText += i;
0047       lText += "<br/>";
0048     }
0049   }
0050   lText += "</font>";
0051   lText += ">];";
0052   return lText;
0053 }
0054 
0055 }  // namespace
0056 
0057 void Acts::Experimental::detail::BlueprintDrawer::dotStream(
0058     std::ostream& ss, const Acts::Experimental::Blueprint::Node& node,
0059     const Options& options) {
0060   // Root / leaf or branch
0061   if (node.isRoot()) {
0062     ss << "digraph " << options.graphName << " {" << '\n';
0063     ss << node.name << " " << labelStr(options.root, node.name, node.auxiliary)
0064        << '\n';
0065     ss << node.name << " " << shapeStr(options.root) << '\n';
0066 
0067   } else if (node.isLeaf()) {
0068     ss << node.name << " " << labelStr(options.leaf, node.name, node.auxiliary)
0069        << '\n';
0070     ss << node.name << " "
0071        << ((node.internalsBuilder != nullptr) ? shapeStr(options.leaf)
0072                                               : shapeStr(options.gap))
0073        << '\n';
0074   } else {
0075     ss << node.name << " "
0076        << labelStr(options.branch, node.name, node.auxiliary) << '\n';
0077     ss << node.name << " " << shapeStr(options.branch) << '\n';
0078   }
0079   // Recursive for children
0080   for (const auto& c : node.children) {
0081     ss << node.name << " -> " << c->name << ";" << '\n';
0082     dotStream(ss, *c, options);
0083   }
0084 
0085   // Shape
0086   Options::Node shape = node.isLeaf() ? options.shape : options.virtualShape;
0087   ss << node.name + "_shape " << shapeStr(shape) << '\n';
0088   ss << node.name + "_shape "
0089      << labelStr(shape, VolumeBounds::s_boundsTypeNames[node.boundsType],
0090                  {"t = " + toString(node.transform.translation(), 1),
0091                   "b = " + toString(node.boundaryValues, 1)})
0092      << '\n';
0093   ss << node.name << " -> " << node.name + "_shape [ arrowhead = \"none\" ];"
0094      << '\n';
0095 
0096   // Sub node detection
0097   if (node.internalsBuilder != nullptr) {
0098     ss << node.name + "_int " << shapeStr(options.internals) << '\n';
0099     ss << node.name << " -> " << node.name + "_int;" << '\n';
0100   }
0101 
0102   if (node.geoIdGenerator != nullptr) {
0103     ss << node.name + "_geoID " << shapeStr(options.geoID) << '\n';
0104     ss << node.name << " -> " << node.name + "_geoID;" << '\n';
0105   }
0106 
0107   if (node.rootVolumeFinderBuilder != nullptr) {
0108     ss << node.name + "_roots " << shapeStr(options.roots) << '\n';
0109     ss << node.name << " -> " << node.name + "_roots;" << '\n';
0110   }
0111 
0112   if (node.isRoot()) {
0113     ss << "}" << '\n';
0114   }
0115 }