00001 #ifndef _ots_ConfigurationTree_h_
00002 #define _ots_ConfigurationTree_h_
00003
00004 #include "otsdaq-core/ConfigurationDataFormats/ConfigurationView.h"
00005
00006
00007
00008 #include <iostream>
00009 #include <string>
00010 #include <set>
00011
00012
00013 namespace ots
00014 {
00015
00016 class ConfigurationManager;
00017 class ConfigurationBase;
00018 class ConfigurationView;
00019
00020 class ConfigurationTree
00021 {
00022 friend class ConfigurationGUISupervisor;
00023
00024 public:
00025
00026
00027
00028
00029 ConfigurationTree ();
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 ConfigurationTree (const ConfigurationManager* const& configMgr, const ConfigurationBase* const &config);
00047 ~ConfigurationTree (void);
00048
00049 ConfigurationTree& operator=(const ConfigurationTree& a)
00050 {
00051 std::cout << __PRETTY_FUNCTION__ << "OPERATOR= COPY CONSTRUCTOR ConfigManager: " << configMgr_ << " configuration: " << configuration_ << std::endl;
00052
00053
00054
00055 std::cout << __PRETTY_FUNCTION__ << "OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - SO YOUR CODE IS WRONG! Crashing now." << std::endl;
00056 std::cout << __PRETTY_FUNCTION__ << "OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - SO YOUR CODE IS WRONG! Crashing now." << std::endl;
00057 std::cout << __PRETTY_FUNCTION__ << "OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - SO YOUR CODE IS WRONG! Crashing now." << std::endl;
00058 std::cout << __PRETTY_FUNCTION__ << "OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - SO YOUR CODE IS WRONG! Crashing now." << std::endl;
00059 std::cout << __PRETTY_FUNCTION__ << "OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - SO YOUR CODE IS WRONG! Crashing now." << std::endl;
00060 std::cout << __PRETTY_FUNCTION__ << "OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - SO YOUR CODE IS WRONG! Crashing now." << std::endl;
00061 std::cout << __PRETTY_FUNCTION__ << "OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - SO YOUR CODE IS WRONG! Crashing now." << std::endl;
00062 exit(0);
00063
00064
00065
00066 configMgr_ = a.configMgr_;
00067 configuration_ = a.configuration_;
00068
00069
00070
00071
00072
00073 configView_ = a.configView_;
00074 std::cout << __PRETTY_FUNCTION__ << "OPERATOR COPY CONSTRUCTOR" << std::endl;
00075 return *this;
00076 };
00077
00078
00079 static const std::string DISCONNECTED_VALUE;
00080 static const std::string VALUE_TYPE_DISCONNECTED;
00081 static const std::string VALUE_TYPE_NODE;
00082
00083 static const std::string NODE_TYPE_GROUP_TABLE;
00084 static const std::string NODE_TYPE_TABLE;
00085 static const std::string NODE_TYPE_GROUP_LINK;
00086 static const std::string NODE_TYPE_UID_LINK;
00087 static const std::string NODE_TYPE_VALUE;
00088 static const std::string NODE_TYPE_UID;
00089
00090
00091
00092
00093
00094
00095
00096
00097 template<class T>
00098 void getValue(T& value) const
00099 {
00100 if(row_ != ConfigurationView::INVALID && col_ != ConfigurationView::INVALID)
00101 configView_->getValue(value,row_,col_);
00102 else if(row_ == ConfigurationView::INVALID && col_ == ConfigurationView::INVALID)
00103 throw std::runtime_error("Requesting getValue on config node level. Must be a value node.");
00104 else if(row_ == ConfigurationView::INVALID)
00105 {
00106 std::cout << __COUT_HDR_FL__ << std::endl;
00107 throw std::runtime_error("Malformed ConfigurationTree");
00108 }
00109 else if(col_ == ConfigurationView::INVALID)
00110 throw std::runtime_error("Requesting getValue on uid node level. Must be a value node.");
00111 else
00112 {
00113 std::cout << __COUT_HDR_FL__ << std::endl;
00114 throw std::runtime_error("Impossible");
00115 }
00116 }
00117
00118
00119
00120
00121 template<class T>
00122 T getValue(void) const
00123 {
00124 T value;
00125 if(row_ != ConfigurationView::INVALID && col_ != ConfigurationView::INVALID)
00126 {
00127 configView_->getValue(value,row_,col_);
00128 return value;
00129 }
00130 else if(row_ == ConfigurationView::INVALID && col_ == ConfigurationView::INVALID)
00131 throw std::runtime_error("Requesting getValue on config node level. Must be a value node.");
00132 else if(row_ == ConfigurationView::INVALID)
00133 {
00134 std::cout << __COUT_HDR_FL__ << std::endl;
00135 throw std::runtime_error("Malformed ConfigurationTree");
00136 }
00137 else if(col_ == ConfigurationView::INVALID)
00138 throw std::runtime_error("Requesting getValue on uid node level. Must be a value node.");
00139 else
00140 {
00141 std::cout << __COUT_HDR_FL__ << std::endl;
00142 throw std::runtime_error("Impossible");
00143 }
00144 }
00145
00146
00147 ConfigurationTree getNode (const std::string& nodeName, bool doNotThrowOnBrokenUIDLinks=false) const;
00148 ConfigurationTree getBackNode ( std::string nodeName, unsigned int backSteps=1) const;
00149
00150
00151
00152 const std::string& getConfigurationName (void) const;
00153 const ConfigurationVersion& getConfigurationVersion (void) const;
00154 const time_t& getConfigurationCreationTime(void) const;
00155 std::vector<std::string> getChildrenNames (void) const;
00156 std::vector<std::pair<std::string,ConfigurationTree> > getChildren (std::map<std::string /*relative-path*/, std::string /*value*/> filterMap = std::map<std::string /*relative-path*/, std::string /*value*/>()) const;
00157 std::map<std::string,ConfigurationTree> getChildrenMap (void) const;
00158 void getValue (std::string& value) const;
00159 std::string getValue (void) const;
00160 std::string getEscapedValue (void) const;
00161 const std::string& getValueAsString (bool returnLinkTableValue=false) const;
00162 const std::string& getUIDAsString (void) const;
00163 const std::string& getValueDataType (void) const;
00164 const std::string& getValueType (void) const;
00165 const std::string& getValueName (void) const;
00166 std::string getNodeType (void) const;
00167 const std::string& getDisconnectedTableName (void) const;
00168 const std::string& getDisconnectedLinkID (void) const;
00169 const std::string& getChildLinkIndex (void) const;
00170 std::vector<std::string> getFixedChoices (void) const;
00171
00172 protected:
00173 const unsigned int& getRow (void) const;
00174 const unsigned int& getColumn (void) const;
00175 const ViewColumnInfo& getColumnInfo (void) const;
00176
00177
00178 struct RecordField
00179 {
00180 RecordField(const std::string &table, const std::string &uid,
00181 const std::string &columnName, const std::string &relativePath,
00182 const ViewColumnInfo *columnInfo)
00183 :tableName_(table)
00184 ,columnName_(columnName)
00185 ,relativePath_(relativePath)
00186 ,columnInfo_(columnInfo)
00187 {}
00188
00189 std::string tableName_, columnName_, relativePath_;
00190
00191
00192 const ViewColumnInfo *columnInfo_;
00193 };
00194 std::vector<ConfigurationTree::RecordField> getCommonFields(const std::vector<std::string /*relative-path*/> &recordList, const std::vector<std::string /*relative-path*/> &fieldAcceptList, const std::vector<std::string /*relative-path*/> &fieldRejectList, unsigned int depth = -1) const;
00195 std::set<std::string > getUniqueValuesForField(const std::vector<std::string /*relative-path*/> &recordList, const std::string &fieldName) const;
00196
00197
00198 public:
00199
00200
00201
00202 bool isDefaultValue (void) const;
00203 bool isConfigurationNode (void) const;
00204 bool isValueNode (void) const;
00205 bool isDisconnected (void) const;
00206 bool isLinkNode (void) const;
00207 bool isGroupLinkNode (void) const;
00208 bool isUIDLinkNode (void) const;
00209 bool isUIDNode (void) const;
00210
00211
00212 void print (const unsigned int &depth = -1, std::ostream &out = std::cout) const;
00213
00214
00215 friend std::ostream& operator<< (std::ostream& out, const ConfigurationTree& t)
00216 {
00217 out << t.getValueAsString();
00218 return out;
00219 }
00220 private:
00221
00222 ConfigurationTree(const ConfigurationManager* const& configMgr, const ConfigurationBase* const& config, const std::string& groupId, const std::string &linkColName, const std::string &linkColValue, const std::string& disconnectedTargetName, const std::string& disconnectedLinkID, const std::string &childLinkIndex, const unsigned int row = ConfigurationView::INVALID, const unsigned int col = ConfigurationView::INVALID);
00223
00224 static ConfigurationTree recurse (const ConfigurationTree& t, const std::string& childPath);
00225 static void recursivePrint(const ConfigurationTree& t, unsigned int depth, std::ostream &out, std::string space);
00226
00227 void recursiveGetCommonFields(std::vector<ConfigurationTree::RecordField> &fieldCandidateList, std::vector<int> &fieldCount, const std::vector<std::string /*relative-path*/> &fieldAcceptList, const std::vector<std::string /*relative-path*/> &fieldRejectList, unsigned int depth, const std::string &relativePathBase, bool inFirstRecord) const;
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237 const ConfigurationManager* configMgr_;
00238 const ConfigurationBase* configuration_;
00239 const std::string groupId_;
00240 const std::string linkColName_;
00241 const std::string linkColValue_;
00242 const std::string disconnectedTargetName_;
00243 const std::string disconnectedLinkID_;
00244 const std::string childLinkIndex_;
00245 const unsigned int row_;
00246 const unsigned int col_;
00247 const ConfigurationView* configView_;
00248
00249 };
00250 }
00251
00252 #endif