|
||||
File indexing completed on 2025-01-18 10:10:32
0001 // Author: Enrico Guiraud, Danilo Piparo, CERN, Massimo Tumolo Politecnico di Torino 08/2018 0002 0003 /************************************************************************* 0004 * Copyright (C) 1995-2018, Rene Brun and Fons Rademakers. * 0005 * All rights reserved. * 0006 * * 0007 * For the licensing terms see $ROOTSYS/LICENSE. * 0008 * For the list of contributors see $ROOTSYS/README/CREDITS. * 0009 *************************************************************************/ 0010 0011 #ifndef ROOT_RDF_GRAPHNODE 0012 #define ROOT_RDF_GRAPHNODE 0013 0014 #include <string> 0015 #include <memory> 0016 #include <vector> 0017 #include <string_view> 0018 0019 #include <iostream> 0020 0021 namespace ROOT { 0022 namespace Internal { 0023 namespace RDF { 0024 namespace GraphDrawing { 0025 0026 enum class ENodeType { 0027 kAction, 0028 kDefine, 0029 kFilter, 0030 kRange, 0031 kRoot, 0032 kUsedAction, 0033 }; 0034 0035 class GraphCreatorHelper; 0036 0037 // clang-format off 0038 /** 0039 \class ROOT::Internal::RDF::GraphDrawing::GraphNode 0040 \ingroup dataframe 0041 \brief Class used to create the operation graph to be printed in the dot representation 0042 0043 This represent a single node of the overall graph. Each node maps the real RNode keeping just 0044 the name and the columns defined up to that point. 0045 */ 0046 // clang-format on 0047 class GraphNode { 0048 /// Nodes may share the same name (e.g. Filter). To manage this situation in dot, each node 0049 /// is represented by an unique id. 0050 unsigned int fID; 0051 0052 std::string fName, fColor, fShape; 0053 0054 /// Columns defined up to this node. By checking the defined columns between two consecutive 0055 /// nodes, it is possible to know if there was some Define in between. 0056 std::vector<std::string> fDefinedColumns; 0057 0058 std::shared_ptr<GraphNode> fPrevNode; 0059 0060 /// When the graph is reconstructed, the first time this node has been explored this flag 0061 /// is set and it won't be explored anymore. 0062 bool fIsExplored = false; 0063 0064 /// A just created node. This means that in no other exploration the node was already created 0065 /// (this is needed because branches may share some common node). 0066 bool fIsNew = true; 0067 0068 //////////////////////////////////////////////////////////////////////////// 0069 /// \brief Gives a different shape based on the node type 0070 void SetRoot() 0071 { 0072 fColor = "#f4b400"; 0073 fShape = "ellipse"; 0074 } 0075 0076 //////////////////////////////////////////////////////////////////////////// 0077 /// \brief Gives a different shape based on the node type 0078 void SetFilter() 0079 { 0080 fColor = "#0f9d58"; 0081 fShape = "hexagon"; 0082 } 0083 0084 //////////////////////////////////////////////////////////////////////////// 0085 /// \brief Gives a different shape based on the node type 0086 void SetDefine() 0087 { 0088 fColor = "#4285f4"; 0089 fShape = "ellipse"; 0090 } 0091 0092 //////////////////////////////////////////////////////////////////////////// 0093 /// \brief Gives a different shape based on the node type 0094 void SetRange() 0095 { 0096 fColor = "#9574b4"; 0097 fShape = "diamond"; 0098 } 0099 0100 //////////////////////////////////////////////////////////////////////////// 0101 /// \brief Gives a different shape based on the node type 0102 void SetAction(bool hasRun) 0103 { 0104 if (hasRun) { 0105 fName += "\\n(already run)"; 0106 fColor = "#e6e5e6"; 0107 } else { 0108 fColor = "#e47c7e"; 0109 } 0110 fShape = "box"; 0111 } 0112 0113 public: 0114 //////////////////////////////////////////////////////////////////////////// 0115 /// \brief Creates a node with a name 0116 GraphNode(std::string_view name, unsigned int id, ENodeType t) : fID(id), fName(name) 0117 { 0118 switch (t) { 0119 case ENodeType::kAction: SetAction(/*hasRun=*/false); break; 0120 case ENodeType::kDefine: SetDefine(); break; 0121 case ENodeType::kFilter: SetFilter(); break; 0122 case ENodeType::kRange: SetRange(); break; 0123 case ENodeType::kRoot: SetRoot(); break; 0124 case ENodeType::kUsedAction: SetAction(/*hasRun=*/true); break; 0125 }; 0126 } 0127 0128 //////////////////////////////////////////////////////////////////////////// 0129 /// \brief Appends a node on the head of the current node 0130 void SetPrevNode(const std::shared_ptr<GraphNode> &node) { fPrevNode = node; } 0131 0132 //////////////////////////////////////////////////////////////////////////// 0133 /// \brief Adds the column defined up to the node 0134 void AddDefinedColumns(const std::vector<std::string_view> &columns) 0135 { 0136 // TODO: Converting the string_views for backward compatibility. 0137 // Since they are names of defined columns, they were added to the 0138 // register of column names of the RLoopManager object by the 0139 // RColumnRegister, so we could also change fDefinedColumns to only 0140 // store string_views 0141 fDefinedColumns.clear(); 0142 fDefinedColumns.reserve(columns.size()); 0143 for (const auto &col : columns) { 0144 fDefinedColumns.push_back(std::string(col)); 0145 }; 0146 } 0147 0148 std::string GetColor() const { return fColor; } 0149 unsigned int GetID() const { return fID; } 0150 std::string GetName() const { return fName; } 0151 std::string GetShape() const { return fShape; } 0152 GraphNode *GetPrevNode() const { return fPrevNode.get(); } 0153 0154 //////////////////////////////////////////////////////////////////////////// 0155 /// \brief Gets the column defined up to the node 0156 const std::vector<std::string> &GetDefinedColumns() const { return fDefinedColumns; } 0157 0158 bool IsExplored() const { return fIsExplored; } 0159 bool IsNew() const { return fIsNew; } 0160 0161 //////////////////////////////////////////////////////////////////////////// 0162 /// \brief Allows to stop the graph traversal when an explored node is encountered 0163 void SetExplored() { fIsExplored = true; } 0164 0165 //////////////////////////////////////////////////////////////////////////// 0166 /// \brief Mark this node as "not newly created" 0167 void SetNotNew() { fIsNew = false; } 0168 }; 0169 0170 } // namespace GraphDrawing 0171 } // namespace RDF 0172 } // namespace Internal 0173 } // namespace ROOT 0174 0175 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |