$treeview $search $mathjax $extrastylesheet
otsdaq
v2_03_00
$projectbrief
|
$projectbrief
|
$searchbox |
00001 #ifndef _ots_ConfigurationTree_h_ 00002 #define _ots_ConfigurationTree_h_ 00003 00004 #include "otsdaq-core/TableCore/TableView.h" 00005 00006 namespace ots 00007 { 00008 class ConfigurationManager; 00009 class TableBase; 00010 00011 template<typename T> 00012 struct identity 00013 { 00014 typedef T type; 00015 }; 00016 00017 class ConfigurationTree 00018 { 00019 friend class ConfigurationGUISupervisor; 00020 friend class Iterator; 00021 00022 public: 00023 // Note: due to const members, implicit copy constructor exists, but NOT assignment 00024 // operator= 00025 // ... so ConfigurationTree t = mytree.GetNode(nodeString); //OK 00026 // ... or ConfigurationTree t(mytree.GetNode(nodeString)); //OK 00027 // ... but mytree = mytree.GetNode(nodeString); //does NOT work 00028 ConfigurationTree(); 00029 // ConfigurationTree(const ConfigurationTree& a) 00030 // : 00031 // configMgr_ (a.configMgr_), 00032 // table_ (a.table_), 00033 // groupId_ (a.groupId_), 00034 // linkColName_ (a.linkColName_), 00035 // disconnectedTargetName_ (a.disconnectedTargetName_), 00036 // childLinkIndex_ (a.childLinkIndex_), 00037 // row_ (a.row_), 00038 // col_ (a.col_), 00039 // tableView_ (a.tableView_) 00040 // { 00041 // __COUT__ << std::endl; 00042 // //return *this; 00043 // } 00044 00045 ConfigurationTree(const ConfigurationManager* const& configMgr, 00046 const TableBase* const& config); 00047 ~ConfigurationTree(void); 00048 00049 ConfigurationTree& operator=(const ConfigurationTree& a) 00050 { 00051 __COUT__ << "OPERATOR= COPY CONSTRUCTOR ConfigManager: " << configMgr_ 00052 << " configuration: " << table_ << std::endl; 00053 // Note: Members of the ConfigurationTree are declared constant. 00054 // (Refer to comments at top of class declaration for solutions) 00055 // So this operator cannot work.. SO I am going to crash just in case it is 00056 // called by mistake 00057 __COUT__ << "OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - ConfigurationTree is a " 00058 "const class. SO YOUR CODE IS WRONG! You should probably instantiate " 00059 "and initialize another ConfigurationTree, rather than assigning to " 00060 "an existing ConfigurationTree. Crashing now." 00061 << std::endl; 00062 __COUT__ << "OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - ConfigurationTree is a " 00063 "const class. SO YOUR CODE IS WRONG! You should probably instantiate " 00064 "and initialize another ConfigurationTree, rather than assigning to " 00065 "an existing ConfigurationTree. Crashing now." 00066 << std::endl; 00067 __COUT__ << "OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - ConfigurationTree is a " 00068 "const class. SO YOUR CODE IS WRONG! You should probably instantiate " 00069 "and initialize another ConfigurationTree, rather than assigning to " 00070 "an existing ConfigurationTree. Crashing now." 00071 << std::endl; 00072 __COUT__ << "OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - ConfigurationTree is a " 00073 "const class. SO YOUR CODE IS WRONG! You should probably instantiate " 00074 "and initialize another ConfigurationTree, rather than assigning to " 00075 "an existing ConfigurationTree. Crashing now." 00076 << std::endl; 00077 __COUT__ << "OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - ConfigurationTree is a " 00078 "const class. SO YOUR CODE IS WRONG! You should probably instantiate " 00079 "and initialize another ConfigurationTree, rather than assigning to " 00080 "an existing ConfigurationTree. Crashing now." 00081 << std::endl; 00082 __COUT__ << "OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - ConfigurationTree is a " 00083 "const class. SO YOUR CODE IS WRONG! You should probably instantiate " 00084 "and initialize another ConfigurationTree, rather than assigning to " 00085 "an existing ConfigurationTree. Crashing now." 00086 << std::endl; 00087 exit(0); 00088 00089 // copy to const members is not allowed.. but would look like this: 00090 00091 configMgr_ = a.configMgr_; 00092 table_ = a.table_; 00093 // groupId_ = a.groupId_; 00094 // linkColName_ = a.linkColName_; 00095 // childLinkIndex_ = a.childLinkIndex_; 00096 // row_ = a.row_; 00097 // col_ = a.col_; 00098 tableView_ = a.tableView_; 00099 __COUT__ << "OPERATOR COPY CONSTRUCTOR" << std::endl; 00100 return *this; 00101 }; 00102 00103 static const std::string DISCONNECTED_VALUE; 00104 static const std::string VALUE_TYPE_DISCONNECTED; 00105 static const std::string VALUE_TYPE_NODE; 00106 00107 static const std::string NODE_TYPE_GROUP_TABLE; 00108 static const std::string NODE_TYPE_TABLE; 00109 static const std::string NODE_TYPE_GROUP_LINK; 00110 static const std::string NODE_TYPE_UID_LINK; 00111 static const std::string NODE_TYPE_VALUE; 00112 static const std::string NODE_TYPE_UID; 00113 static const std::string NODE_TYPE_ROOT; 00114 00115 struct BitMap 00116 { 00117 BitMap() : isDefault_(true), zero_(0) {} 00118 00119 friend ConfigurationTree; // so ConfigurationTree can access private 00120 const uint64_t& get(unsigned int row, unsigned int col) const 00121 { 00122 return isDefault_ ? zero_ : bitmap_[row][col]; 00123 } 00124 unsigned int numberOfRows() const { return bitmap_.size(); } 00125 unsigned int numberOfColumns(unsigned int row) const 00126 { 00127 return bitmap_[row].size(); 00128 } 00129 00130 private: 00131 std::vector<std::vector<uint64_t>> bitmap_; 00132 bool isDefault_; // when default always return 0 00133 uint64_t zero_; 00134 }; 00135 00136 // Methods 00137 00138 //============================================================================== 00139 // getValue (not std::string value) 00140 // throw exception unless it value node 00141 // NOTE: can not overload functions based on return type, so T& passed as value 00142 template<class T> 00143 void getValue(T& value) const; // defined in included .icc source 00144 // special version of getValue for string type 00145 // Note: necessary because types of std::basic_string<char> cause compiler problems 00146 // if no string specific function 00147 void getValue(std::string& value) const; 00148 void getValueAsBitMap(ConfigurationTree::BitMap& value) const; 00149 00150 //============================================================================== 00151 // getValue (not std::string value) 00152 // throw exception unless it value node 00153 // NOTE: can not overload functions based on return type, so calls function with T& 00154 // passed as value 00155 template<class T> 00156 T getValue(void) const; // defined in included .icc source 00157 // special version of getValue for string type 00158 // Note: necessary because types of std::basic_string<char> cause compiler problems 00159 // if no string specific function 00160 std::string getValue(void) const; 00161 ConfigurationTree::BitMap getValueAsBitMap(void) const; 00162 00163 private: 00164 template<typename T> 00165 T handleValidateValueForColumn( 00166 const TableView* configView, 00167 std::string value, 00168 unsigned int col, 00169 ots::identity<T>) const; // defined in included .icc source 00170 std::string handleValidateValueForColumn(const TableView* configView, 00171 std::string value, 00172 unsigned int col, 00173 ots::identity<std::string>) const; 00174 00175 public: 00176 // navigating between nodes 00177 ConfigurationTree getNode(const std::string& nodeName, 00178 bool doNotThrowOnBrokenUIDLinks = false) const; 00179 ConfigurationTree getBackNode(std::string nodeName, unsigned int backSteps = 1) const; 00180 ConfigurationTree getForwardNode(std::string nodeName, 00181 unsigned int forwardSteps = 1) const; 00182 00183 // extracting information from node 00184 const ConfigurationManager* getConfigurationManager(void) const { return configMgr_; } 00185 const std::string& getTableName(void) const; 00186 const std::string& getFieldTableName(void) const; 00187 const TableVersion& getTableVersion(void) const; 00188 const time_t& getTableCreationTime(void) const; 00189 std::vector<std::vector<std::string>> getChildrenNamesByPriority( 00190 bool onlyStatusTrue = false) const; 00191 std::vector<std::string> getChildrenNames(bool byPriority = false, 00192 bool onlyStatusTrue = false) const; 00193 std::vector<std::vector<std::pair<std::string, ConfigurationTree>>> 00194 getChildrenByPriority( 00195 std::map<std::string /*relative-path*/, std::string /*value*/> filterMap = 00196 std::map<std::string /*relative-path*/, std::string /*value*/>(), 00197 bool onlyStatusTrue = false) const; 00198 std::vector<std::pair<std::string, ConfigurationTree>> getChildren( 00199 std::map<std::string /*relative-path*/, std::string /*value*/> filterMap = 00200 std::map<std::string /*relative-path*/, std::string /*value*/>(), 00201 bool byPriority = false, 00202 bool onlyStatusTrue = false) const; 00203 std::map<std::string, ConfigurationTree> getChildrenMap(void) const; 00204 std::string getEscapedValue(void) const; 00205 const std::string& getValueAsString(bool returnLinkTableValue = false) const; 00206 const std::string& getUIDAsString(void) const; 00207 const std::string& getValueDataType(void) const; 00208 const std::string& getValueType(void) const; 00209 const std::string& getValueName(void) const; 00210 std::string getNodeType(void) const; 00211 const std::string& getDisconnectedTableName(void) const; 00212 const std::string& getDisconnectedLinkID(void) const; 00213 const std::string& getChildLinkIndex(void) const; 00214 std::vector<std::string> getFixedChoices(void) const; 00215 00216 public: 00217 // boolean info 00218 bool isDefaultValue(void) const; 00219 bool isRootNode(void) const; 00220 bool isConfigurationNode(void) const; 00221 bool isValueNode(void) const; 00222 bool isValueBoolType(void) const; 00223 bool isValueNumberDataType(void) const; 00224 bool isDisconnected(void) const; 00225 bool isLinkNode(void) const; 00226 bool isGroupLinkNode(void) const; 00227 bool isUIDLinkNode(void) const; 00228 bool isUIDNode(void) const; 00229 00230 void print(const unsigned int& depth = -1, std::ostream& out = std::cout) const; 00231 std::string nodeDump(void) const; // used for debugging (when throwing exception) 00232 00233 // make stream output easy 00234 friend std::ostream& operator<<(std::ostream& out, const ConfigurationTree& t) 00235 { 00236 out << t.getValueAsString(); 00237 return out; 00238 } 00239 00240 protected: 00241 const unsigned int& getRow(void) const; 00242 const unsigned int& getColumn(void) const; 00243 const unsigned int& getFieldRow(void) const; 00244 const unsigned int& getFieldColumn(void) const; 00245 const TableViewColumnInfo& getColumnInfo(void) const; 00246 00247 // extracting information from a list of records 00248 struct RecordField 00249 { 00250 RecordField(const std::string& table, 00251 const std::string& uid, 00252 const std::string& columnName, 00253 const std::string& relativePath, 00254 const TableViewColumnInfo* columnInfo) 00255 : tableName_(table) 00256 , columnName_(columnName) 00257 , relativePath_(relativePath) 00258 , columnInfo_(columnInfo) 00259 { 00260 } 00261 00262 std::string tableName_, columnName_, relativePath_; 00263 // relativePath_ is relative to record uid node, not including columnName_ 00264 00265 const TableViewColumnInfo* columnInfo_; 00266 }; 00267 std::vector<ConfigurationTree::RecordField> getCommonFields( 00268 const std::vector<std::string /*relative-path*/>& recordList, 00269 const std::vector<std::string /*relative-path*/>& fieldAcceptList, 00270 const std::vector<std::string /*relative-path*/>& fieldRejectList, 00271 unsigned int depth = -1) const; 00272 std::set<std::string /*unique-value*/> getUniqueValuesForField( 00273 const std::vector<std::string /*relative-path*/>& recordList, 00274 const std::string& fieldName) const; 00275 00276 private: 00277 // privately ONLY allow full access to member variables through constructor 00278 ConfigurationTree(const ConfigurationManager* const& configMgr, 00279 const TableBase* const& config, 00280 const std::string& groupId, 00281 const TableBase* const& linkParentConfig, 00282 const std::string& linkColName, 00283 const std::string& linkColValue, 00284 const unsigned int linkBackRow, 00285 const unsigned int linkBackCol, 00286 const std::string& disconnectedTargetName, 00287 const std::string& disconnectedLinkID, 00288 const std::string& childLinkIndex, 00289 const unsigned int row = TableView::INVALID, 00290 const unsigned int col = TableView::INVALID); 00291 00292 static ConfigurationTree recurse(const ConfigurationTree& t, 00293 const std::string& childPath, 00294 bool doNotThrowOnBrokenUIDLinks, 00295 const std::string& originalNodeString); 00296 ConfigurationTree recursiveGetNode(const std::string& nodeName, 00297 bool doNotThrowOnBrokenUIDLinks, 00298 const std::string& originalNodeString) const; 00299 static void recursivePrint(const ConfigurationTree& t, 00300 unsigned int depth, 00301 std::ostream& out, 00302 std::string space); 00303 00304 void recursiveGetCommonFields( 00305 std::vector<ConfigurationTree::RecordField>& fieldCandidateList, 00306 std::vector<int>& fieldCount, 00307 const std::vector<std::string /*relative-path*/>& fieldAcceptList, 00308 const std::vector<std::string /*relative-path*/>& fieldRejectList, 00309 unsigned int depth, 00310 const std::string& relativePathBase, 00311 bool inFirstRecord) const; 00312 ConfigurationTree getValueAsTreeNode(void) const; 00313 00314 // Any given ConfigurationTree is either a config, uid, or value node: 00315 // - config node is a pointer to a config table 00316 // - uid node is a pointer to a row in a config table 00317 // - value node is a pointer to a cell in a config table 00318 // 00319 // Assumption: uid column is present 00320 const ConfigurationManager* configMgr_; // root node 00321 const TableBase* table_; // config node 00322 const std::string groupId_; // group config node 00323 const TableBase* linkParentConfig_; // link node parent config pointer (could be used 00324 // to traverse backwards through tree) 00325 const std::string linkColName_; // link node field name 00326 const std::string linkColValue_; // link node field value 00327 const unsigned int linkBackRow_; // source table link row 00328 const unsigned int linkBackCol_; // source table link col 00329 const std::string disconnectedTargetName_; // only used if disconnected to determine 00330 // target table name 00331 const std::string 00332 disconnectedLinkID_; // only used if disconnected to determine target link ID 00333 const std::string childLinkIndex_; // child link index 00334 const unsigned int row_; // uid node 00335 const unsigned int col_; // value node 00336 const TableView* tableView_; 00337 }; 00338 00339 #include "otsdaq-core/ConfigurationInterface/ConfigurationTree.icc" //define template functions 00340 00341 } // namespace ots 00342 00343 #endif