1 #ifndef _ots_ConfigurationTree_h_
2 #define _ots_ConfigurationTree_h_
4 #include "otsdaq-core/ConfigurationDataFormats/ConfigurationView.h"
15 class ConfigurationManager;
16 class ConfigurationBase;
17 class ConfigurationView;
40 friend class ConfigurationGUISupervisor;
70 __COUT__ <<
"OPERATOR= COPY CONSTRUCTOR ConfigManager: " << configMgr_ <<
" configuration: " << configuration_ << std::endl;
74 __COUT__ <<
"OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - SO YOUR CODE IS WRONG! Crashing now." << std::endl;
75 __COUT__ <<
"OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - SO YOUR CODE IS WRONG! Crashing now." << std::endl;
76 __COUT__ <<
"OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - SO YOUR CODE IS WRONG! Crashing now." << std::endl;
77 __COUT__ <<
"OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - SO YOUR CODE IS WRONG! Crashing now." << std::endl;
78 __COUT__ <<
"OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - SO YOUR CODE IS WRONG! Crashing now." << std::endl;
79 __COUT__ <<
"OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - SO YOUR CODE IS WRONG! Crashing now." << std::endl;
80 __COUT__ <<
"OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - SO YOUR CODE IS WRONG! Crashing now." << std::endl;
85 configMgr_ = a.configMgr_;
86 configuration_ = a.configuration_;
92 configView_ = a.configView_;
93 __COUT__ <<
"OPERATOR COPY CONSTRUCTOR" << std::endl;
98 static const std::string DISCONNECTED_VALUE;
99 static const std::string VALUE_TYPE_DISCONNECTED;
100 static const std::string VALUE_TYPE_NODE;
102 static const std::string NODE_TYPE_GROUP_TABLE;
103 static const std::string NODE_TYPE_TABLE;
104 static const std::string NODE_TYPE_GROUP_LINK;
105 static const std::string NODE_TYPE_UID_LINK;
106 static const std::string NODE_TYPE_VALUE;
107 static const std::string NODE_TYPE_UID;
108 static const std::string NODE_TYPE_ROOT;
112 BitMap():isDefault_(
true), zero_(0) {}
115 const uint64_t&
get (
unsigned int row,
unsigned int col)
const {
return isDefault_?zero_:bitmap_[row][col]; }
116 unsigned int numberOfRows ()
const {
return bitmap_.size(); }
117 unsigned int numberOfColumns (
unsigned int row)
const {
return bitmap_[row].size(); }
120 std::vector<std::vector<uint64_t>> bitmap_;
134 void getValue(T& value)
const
136 if(row_ != ConfigurationView::INVALID && col_ != ConfigurationView::INVALID)
143 __COUT__ <<
"Success following path to tree node!" << std::endl;
153 value = handleValidateValueForColumn(configView_,
154 valueAsTreeNode.getValueAsString(),col_,
identity<T>());
156 __COUT__ <<
"Successful value!" << std::endl;
165 configView_->getValue(value,row_,col_);
167 else if(row_ == ConfigurationView::INVALID && col_ == ConfigurationView::INVALID)
169 __SS__ <<
"Requesting getValue on config node level. Must be a value node." << std::endl;
170 __COUT_ERR__ << ss.str();
171 throw std::runtime_error(ss.str());
173 else if(row_ == ConfigurationView::INVALID)
175 __SS__ <<
"Malformed ConfigurationTree" << std::endl;
176 __COUT_ERR__ << ss.str();
177 throw std::runtime_error(ss.str());
179 else if(col_ == ConfigurationView::INVALID)
181 __SS__ <<
"Requesting getValue on uid node level. Must be a value node." << std::endl;
182 __COUT_ERR__ << ss.str();
183 throw std::runtime_error(ss.str());
187 __SS__ <<
"Impossible" << std::endl;
188 __COUT_ERR__ << ss.str();
189 throw std::runtime_error(ss.str());
194 void getValue (std::string& value)
const;
195 void getValueAsBitMap (ConfigurationTree::BitMap& value)
const;
202 T getValue(
void)
const
205 ConfigurationTree::getValue<T>(value);
210 std::string getValue (
void)
const;
211 ConfigurationTree::BitMap getValueAsBitMap (
void)
const;
215 T handleValidateValueForColumn(
const ConfigurationView* configView, std::string value,
unsigned int col,
ots::identity<T>)
const
219 __SS__ <<
"Null configView" << std::endl;
220 __COUT_ERR__ << ss.str();
221 throw std::runtime_error(ss.str());
223 std::cout <<
"210:::::" <<
"handleValidateValueForColumn<T>" << std::endl;
224 return configView->validateValueForColumn<T>(
228 std::string handleValidateValueForColumn(
const ConfigurationView* configView, std::string value,
unsigned int col,
ots::identity<std::string>)
const
232 __SS__ <<
"Null configView" << std::endl;
233 __COUT_ERR__ << ss.str();
234 throw std::runtime_error(ss.str());
236 std::cout <<
"210:::::" <<
"handleValidateValueForColumn<string>" << std::endl;
237 return configView->validateValueForColumn(
244 ConfigurationTree getNode (
const std::string& nodeName,
bool doNotThrowOnBrokenUIDLinks=
false)
const;
245 ConfigurationTree getBackNode ( std::string nodeName,
unsigned int backSteps=1)
const;
246 ConfigurationTree getForwardNode ( std::string nodeName,
unsigned int forwardSteps=1)
const;
250 const ConfigurationManager* getConfigurationManager (
void)
const {
return configMgr_; }
251 const std::string& getConfigurationName (
void)
const;
252 const std::string& getFieldConfigurationName (
void)
const;
253 const ConfigurationVersion& getConfigurationVersion (
void)
const;
254 const time_t& getConfigurationCreationTime(
void)
const;
255 std::vector<std::string> getChildrenNames (
bool byPriority =
false)
const;
256 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*/>(),
bool byPriority =
false)
const;
257 std::map<std::string,ConfigurationTree> getChildrenMap (
void)
const;
258 std::string getEscapedValue (
void)
const;
259 const std::string& getValueAsString (
bool returnLinkTableValue=
false)
const;
260 const std::string& getUIDAsString (
void)
const;
261 const std::string& getValueDataType (
void)
const;
262 const std::string& getValueType (
void)
const;
263 const std::string& getValueName (
void)
const;
264 std::string getNodeType (
void)
const;
265 const std::string& getDisconnectedTableName (
void)
const;
266 const std::string& getDisconnectedLinkID (
void)
const;
267 const std::string& getChildLinkIndex (
void)
const;
268 std::vector<std::string> getFixedChoices (
void)
const;
274 bool isDefaultValue (
void)
const;
275 bool isRootNode (
void)
const;
276 bool isConfigurationNode (
void)
const;
277 bool isValueNode (
void)
const;
278 bool isDisconnected (
void)
const;
279 bool isLinkNode (
void)
const;
280 bool isGroupLinkNode (
void)
const;
281 bool isUIDLinkNode (
void)
const;
282 bool isUIDNode (
void)
const;
285 void print (
const unsigned int &depth = -1, std::ostream &out = std::cout)
const;
288 friend std::ostream& operator<< (std::ostream& out,
const ConfigurationTree& t)
290 out << t.getValueAsString();
295 const unsigned int& getRow (
void)
const;
296 const unsigned int& getColumn (
void)
const;
297 const unsigned int& getFieldRow (
void)
const;
298 const unsigned int& getFieldColumn (
void)
const;
299 const ViewColumnInfo& getColumnInfo (
void)
const;
304 RecordField(
const std::string &table,
const std::string &uid,
305 const std::string &columnName,
const std::string &relativePath,
308 ,columnName_(columnName)
309 ,relativePath_(relativePath)
310 ,columnInfo_(columnInfo)
313 std::string tableName_, columnName_, relativePath_;
318 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;
319 std::set<std::string > getUniqueValuesForField(
const std::vector<std::string /*relative-path*/> &recordList,
const std::string &fieldName)
const;
323 ConfigurationTree(
const ConfigurationManager*
const& configMgr,
const ConfigurationBase*
const& config,
const std::string& groupId,
const ConfigurationBase*
const& linkParentConfig,
const std::string &linkColName,
const std::string &linkColValue,
const unsigned int linkBackRow,
const unsigned int linkBackCol,
const std::string& disconnectedTargetName,
const std::string& disconnectedLinkID,
const std::string &childLinkIndex,
const unsigned int row = ConfigurationView::INVALID,
const unsigned int col = ConfigurationView::INVALID);
326 static void recursivePrint(
const ConfigurationTree& t,
unsigned int depth, std::ostream &out, std::string space);
329 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;
340 const std::string groupId_;
342 const std::string linkColName_;
343 const std::string linkColValue_;
344 const unsigned int linkBackRow_;
345 const unsigned int linkBackCol_;
346 const std::string disconnectedTargetName_;
347 const std::string disconnectedLinkID_;
348 const std::string childLinkIndex_;
349 const unsigned int row_;
350 const unsigned int col_;