Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:11:16

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 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 https://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   // Replace the "/" in node names
0061   std::string nodeName = node.name;
0062   std::replace(nodeName.begin(), nodeName.end(), '/', '_');
0063 
0064   // Root / leaf or branch
0065   if (node.isRoot()) {
0066     ss << "digraph " << options.graphName << " {" << '\n';
0067     ss << nodeName << " " << labelStr(options.root, nodeName, node.auxiliary)
0068        << '\n';
0069     ss << nodeName << " " << shapeStr(options.root) << '\n';
0070 
0071   } else if (node.isLeaf()) {
0072     ss << nodeName << " " << labelStr(options.leaf, nodeName, node.auxiliary)
0073        << '\n';
0074     ss << nodeName << " "
0075        << ((node.internalsBuilder != nullptr) ? shapeStr(options.leaf)
0076                                               : shapeStr(options.gap))
0077        << '\n';
0078   } else {
0079     ss << nodeName << " " << labelStr(options.branch, nodeName, node.auxiliary)
0080        << '\n';
0081     ss << nodeName << " " << shapeStr(options.branch) << '\n';
0082   }
0083   // Recursive for children
0084   for (const auto& c : node.children) {
0085     // Replace the "/" in node names
0086     std::string childName = c->name;
0087     std::replace(childName.begin(), childName.end(), '/', '_');
0088     ss << nodeName << " -> " << childName << ";" << '\n';
0089     dotStream(ss, *c, options);
0090   }
0091 
0092   // Shape
0093   Options::Node shape = node.isLeaf() ? options.shape : options.virtualShape;
0094   std::stringstream bts;
0095   bts << node.boundsType;
0096   ss << nodeName + "_shape " << shapeStr(shape) << '\n';
0097   ss << nodeName + "_shape "
0098      << labelStr(shape, bts.str(),
0099                  {"t = " + toString(node.transform.translation(), 1),
0100                   "b = " + toString(node.boundaryValues, 1)})
0101      << '\n';
0102   ss << nodeName << " -> " << nodeName + "_shape [ arrowhead = \"none\" ];"
0103      << '\n';
0104 
0105   // Sub node detection
0106   if (node.internalsBuilder != nullptr) {
0107     ss << nodeName + "_int " << shapeStr(options.internals) << '\n';
0108     ss << nodeName << " -> " << nodeName + "_int;" << '\n';
0109   }
0110 
0111   if (node.geoIdGenerator != nullptr) {
0112     ss << nodeName + "_geoID " << shapeStr(options.geoID) << '\n';
0113     ss << nodeName << " -> " << nodeName + "_geoID;" << '\n';
0114   }
0115 
0116   if (node.rootVolumeFinderBuilder != nullptr) {
0117     ss << nodeName + "_roots " << shapeStr(options.roots) << '\n';
0118     ss << nodeName << " -> " << nodeName + "_roots;" << '\n';
0119   }
0120 
0121   if (node.isRoot()) {
0122     ss << "}" << '\n';
0123   }
0124 }