Belle II Software  release-05-02-19
NodeNetworkHelperFunctions.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2015 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Jakob Lettenbichler *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #pragma once
11 
12 #include <tracking/trackFindingVXD/segmentNetwork/CACell.h>
13 #include <tracking/trackFindingVXD/segmentNetwork/DirectedNodeNetwork.h>
14 
15 #include <fstream>
16 #include <string>
17 
18 namespace Belle2 {
25  namespace DNN {
26 
38  template<class NodeEntryType>
39  void printCANetwork(DirectedNodeNetwork<NodeEntryType, CACell>& network, const std::string& fName)
40  {
41  std::string fullOut = "digraph G {\n";
42  fullOut +=
43  "ranksep=\"0.2\" edge[labelfontsize=\"8\" fontsize=\"8\" arrowsize=\"0.9\"] nodesep=\"0.2\" node[shape=\"box\" width=\"0\" height=\"0\" fontsize=\"10\"]\n";
44  // write vertices:
45  for (auto* node : network) {
46  fullOut += "\"" + node->getEntry().getName() + "\"" +
47  " [label=\"" +
48  node->getEntry().getName() +
49  " State,Seed: " +
50  std::to_string(node->getMetaInfo().getState()) +
51  "," +
52  std::to_string(node->getMetaInfo().isSeed()) +
53  "\"];\n";
54  }
55  // write edges:
56  for (auto* node : network) {
57  for (auto* innerNode : node->getInnerNodes()) {
58  auto innerEntry = innerNode->getEntry();
59  std::string arrowStyle = (node->getMetaInfo().getState() == (innerNode->getMetaInfo().getState() + 1)) ? "" : " [style=dotted]";
60  fullOut += "\"" + node->getEntry().getName() + "\" -> \"" + innerEntry.getName() + "\"" + arrowStyle + ";\n";
61  }
62  }
63  fullOut += "labelloc=\"t\";\nlabel=\"" + fName + "\";\n";
64  fullOut += "}\n";
65 
66  std::ofstream ofs;
67  ofs.open(fName + ".gv", std::ofstream::out | std::ofstream::trunc);
68  ofs << fullOut;
69  ofs.close();
70  };
71 
72 
74  template<class NodeEntryType, class AnyMetaInfo>
75  void printNetwork(DirectedNodeNetwork<NodeEntryType, AnyMetaInfo>& network, const std::string& fName)
76  {
77  std::string fullOut = "digraph G {\n";
78  fullOut +=
79  "ranksep=\"0.2\" edge[labelfontsize=\"8\" fontsize=\"8\" arrowsize=\"0.9\"] nodesep=\"0.2\" node[shape=\"box\" width=\"0\" height=\"0\" fontsize=\"10\"]\n";
80 
81  // write vertices:
82  for (auto* node : network) {
83  fullOut += "\"" + node->getEntry().getName() + "\"" +
84  " [label=\"" +
85  node->getEntry().getName() +
86  "\"];\n";
87  }
88  // write edges:
89  for (auto* node : network) {
90  for (auto* innerNode : node->getInnerNodes()) {
91  auto innerEntry = innerNode->getEntry();
92  std::string arrowStyle = "";
93  fullOut += "\"" + node->getEntry().getName() + "\" -> \"" + innerEntry.getName() + "\"" + arrowStyle + ";\n";
94  }
95  }
96  fullOut += "labelloc=\"t\";\nlabel=\"" + fName + "\";\n";
97  fullOut += "}\n";
98 
99  std::ofstream ofs;
100  ofs.open(fName + ".gv", std::ofstream::out | std::ofstream::trunc);
101  ofs << fullOut;
102  ofs.close();
103  };
104 
105  } // DNN namespace
107 } //Belle2 namespace
Belle2::DNN::printCANetwork
void printCANetwork(DirectedNodeNetwork< NodeEntryType, CACell > &network, const std::string &fName)
TODO.
Definition: NodeNetworkHelperFunctions.h:47
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::DNN::printNetwork
void printNetwork(DirectedNodeNetwork< NodeEntryType, AnyMetaInfo > &network, const std::string &fName)
overloaded print-version for typical activeSector-networks without CACell-stuff
Definition: NodeNetworkHelperFunctions.h:83