otsdaq  3.06.00
ConfigurationTree.h
1 #ifndef _ots_ConfigurationTree_h_
2 #define _ots_ConfigurationTree_h_
3 
4 #include "otsdaq/TableCore/TableView.h"
5 
6 namespace ots
7 {
8 class ConfigurationManager;
9 class TableBase;
10 
11 template<typename T>
12 struct identity
13 {
14  typedef T type;
15 };
16 
18 {
19  friend class ConfigurationGUISupervisor;
20  friend class Iterator;
21  friend class ARTDAQTableBase;
22 
23  // clang-format off
24  public:
47  ConfigurationTree(const ConfigurationManager* const& configMgr,
48  const TableBase* const& table);
49  ~ConfigurationTree(void);
50 
51  ConfigurationTree(ConfigurationTree const& a) = default;
52 
53  ConfigurationTree& operator=(const ConfigurationTree& a)
54  {
55  __COUT__ << "OPERATOR= COPY CONSTRUCTOR ConfigManager: " << configMgr_
56  << " configuration: " << table_ << std::endl;
57  // Note: Members of the ConfigurationTree are declared constant.
58  // (Refer to comments at top of class declaration for solutions)
59  // So this operator cannot work.. SO I am going to crash just in case it is
60  // called by mistake
61  __COUT__ << "OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - ConfigurationTree is a "
62  "const class. SO YOUR CODE IS WRONG! You should probably instantiate "
63  "and initialize another ConfigurationTree, rather than assigning to "
64  "an existing ConfigurationTree. Crashing now."
65  << std::endl;
66  __COUT__ << "OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - ConfigurationTree is a "
67  "const class. SO YOUR CODE IS WRONG! You should probably instantiate "
68  "and initialize another ConfigurationTree, rather than assigning to "
69  "an existing ConfigurationTree. Crashing now."
70  << std::endl;
71  __COUT__ << "OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - ConfigurationTree is a "
72  "const class. SO YOUR CODE IS WRONG! You should probably instantiate "
73  "and initialize another ConfigurationTree, rather than assigning to "
74  "an existing ConfigurationTree. Crashing now."
75  << std::endl;
76  __COUT__ << "OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - ConfigurationTree is a "
77  "const class. SO YOUR CODE IS WRONG! You should probably instantiate "
78  "and initialize another ConfigurationTree, rather than assigning to "
79  "an existing ConfigurationTree. Crashing now."
80  << std::endl;
81  __COUT__ << "OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - ConfigurationTree is a "
82  "const class. SO YOUR CODE IS WRONG! You should probably instantiate "
83  "and initialize another ConfigurationTree, rather than assigning to "
84  "an existing ConfigurationTree. Crashing now."
85  << std::endl;
86  __COUT__ << "OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - ConfigurationTree is a "
87  "const class. SO YOUR CODE IS WRONG! You should probably instantiate "
88  "and initialize another ConfigurationTree, rather than assigning to "
89  "an existing ConfigurationTree. Crashing now."
90  << std::endl;
91 
93  exit(0);
94 
95  // copy to const members is not allowed.. but would look like this:
96 
97  configMgr_ = a.configMgr_;
98  table_ = a.table_;
99  // groupId_ = a.groupId_;
100  // linkColName_ = a.linkColName_;
101  // childLinkIndex_ = a.childLinkIndex_;
102  // row_ = a.row_;
103  // col_ = a.col_;
104  tableView_ = a.tableView_;
105  __COUT__ << "OPERATOR COPY CONSTRUCTOR" << std::endl;
106  return *this;
107  }; //end operator=
108 
109  static const std::string DISCONNECTED_VALUE;
110  static const std::string VALUE_TYPE_DISCONNECTED;
111  static const std::string VALUE_TYPE_NODE;
112 
113  static const std::string NODE_TYPE_GROUP_TABLE;
114  static const std::string NODE_TYPE_TABLE;
115  static const std::string NODE_TYPE_GROUP_LINK;
116  static const std::string NODE_TYPE_UID_LINK;
117  static const std::string NODE_TYPE_VALUE;
118  static const std::string NODE_TYPE_UID;
119  static const std::string NODE_TYPE_ROOT;
120 
121  static const std::string ROOT_NAME;
122 
123  template<typename T>
124  struct BitMap
125  {
126  BitMap() : isDefault_(true), zero_(T()) {}
127 
129  const T& get(unsigned int row, unsigned int col) const
130  {
131  if(row >= numberOfRows() || col >= numberOfColumns(row))
132  {
133  __SS__ << "Illegal bitmap get of [row,col] = [" << row << "," << col <<
134  "]. Row and column size is [" <<
135  numberOfRows() << " " << numberOfColumns(row) << __E__;
136  __SS_THROW__;
137  }
138  return isDefault_ ? zero_ : bitmap_[row][col];
139  }
140  unsigned int numberOfRows() const { return bitmap_.size(); }
141  unsigned int numberOfColumns(unsigned int row) const
142  {
143  if(row >= numberOfRows())
144  {
145  __SS__ << "Illegal bitmap get numberOfColumns of row = " << row << "." <<
146  "]. Row count is " <<
147  numberOfRows() << __E__;
148  __SS_THROW__;
149  }
150  return bitmap_[row].size();
151  }
152  void print(std::ostream& out = std::cout) const;
153 
154  private:
155  std::vector<std::vector<T>> bitmap_;
156  bool isDefault_;
157  T zero_;
158  };
159 
162  //==============================================================================
166  template<class T>
167  void getValue (T& value) const;
171  void getValue (std::string& value) const;
172  template<class T>
173  void getValueAsBitMap (ConfigurationTree::BitMap<T>& value) const;
174  void getValueAsBitMap (ConfigurationTree::BitMap<std::string>& value) const;
175 
176  //==============================================================================
181  template<class T>
182  T getValue (void) const;
183  template<class T>
184  T getValueWithDefault (const T& defaultValue) const;
188  std::string getValue (void) const;
189  std::string getValueWithDefault (const std::string& defaultValue) const;
190  template<class T>
191  ConfigurationTree::BitMap<T> getValueAsBitMap (void) const;
192  ConfigurationTree::BitMap<std::string> getValueAsBitMap (void) const;
193 
194  private:
195  template<typename T>
196  T handleValidateValueForColumn(
197  const TableView* configView,
198  std::string value,
199  unsigned int col,
200  ots::identity<T>) const;
201  std::string handleValidateValueForColumn(
202  const TableView* configView,
203  std::string value,
204  unsigned int col,
206 
207  public:
209  ConfigurationTree getNode (const std::string& nodeName, bool doNotThrowOnBrokenUIDLinks = false) const;
210  std::map<std::string, ConfigurationTree> getNodes (const std::string& nodeString) const;
211  ConfigurationTree getBackNode (std::string nodeName, unsigned int backSteps = 1) const;
212  ConfigurationTree getForwardNode (std::string nodeName, unsigned int forwardSteps = 1) const;
213 
215  const ConfigurationManager* getConfigurationManager (void) const { return configMgr_; }
216  const std::string& getTableName (void) const;
217  const std::string& getParentTableName (void) const;
218  const std::string& getParentRecordName (void) const;
219  const std::string& getParentLinkColumnName (void) const;
220  std::string getParentLinkID (void) const;
221  std::string getParentLinkIndex (void) const;
222  const std::string& getFieldTableName (void) const;
223  const TableVersion& getTableVersion (void) const;
224  const time_t& getTableCreationTime (void) const;
225  std::vector<std::vector<std::string>> getChildrenNamesByPriority (bool onlyStatusTrue = false) const;
226  std::vector<std::string> getChildrenNames (bool byPriority = false, bool onlyStatusTrue = false) const;
227  std::vector<std::vector<std::pair<
228  std::string, ConfigurationTree>>> getChildrenByPriority (std::map<std::string /*relative-path*/,
229  std::string /*value*/> filterMap = std::map<std::string /*relative-path*/, std::string /*value*/>(),
230  bool onlyStatusTrue = false) const;
231  std::vector<std::pair<std::string,
232  ConfigurationTree>> getChildren (std::map<std::string /*relative-path*/,
233  std::string /*value*/> filterMap = std::map<std::string /*relative-path*/, std::string /*value*/>(),
234  bool byPriority = false,
235  bool onlyStatusTrue = false) const;
236  std::map<std::string, ConfigurationTree> getChildrenMap (std::map<std::string /*relative-path*/,
237  std::string /*value*/> filterMap = std::map<std::string /*relative-path*/, std::string /*value*/>(),
238  bool onlyStatusTrue = false) const;
239  bool passFilterMap (const std::string& childName, std::map<std::string /*relative-path*/, std::string /*value*/> filterMap) const;
240  std::string getEscapedValue (void) const;
241  const std::string& getValueAsString (bool returnLinkTableValue = false) const;
242  const std::string& getUIDAsString (void) const;
243  const std::string& getComment (void) const;
244  bool hasComment (void) const;
245  const std::string& getAuthor (void) const;
246  const std::string& getValueDataType (void) const;
247  const std::string& getValueType (void) const;
248  const std::string& getValueName (void) const;
249  const std::string& getDefaultValue (void) const;
250  inline const std::string& getFieldName (void) const { return getValueName(); }
251  std::string getNodeType (void) const;
252  const unsigned int& getNodeRow (void) const;
253  const std::string& getDisconnectedTableName (void) const;
254  const std::string& getDisconnectedLinkID (void) const;
255  const std::string& getChildLinkIndex (void) const;
256  std::vector<std::string> getFixedChoices (void) const;
257  std::set<std::string> getSetOfGroupIDs (void) const;
258 
259  public:
261  bool isDefaultValue (void) const;
262  inline bool isRootNode (void) const { return (!isLinkNode() && !table_); }
263  inline bool isTableNode (void) const { return (table_ && row_ == TableView::INVALID && col_ == TableView::INVALID); }
264  bool isValueNode (void) const;
265  bool isValueBoolType (void) const;
266  bool isValueNumberDataType (void) const;
267  bool isDisconnected (void) const;
268  bool isLinkNode (void) const;
269  bool isGroupLinkNode (void) const;
270  bool isUIDLinkNode (void) const;
271  bool isGroupIDNode (void) const;
272  bool isUIDNode (void) const;
273  bool isStatusNode (void) const;
274  bool isEnabled (void) const;
275  inline bool status (void) const { return isEnabled(); }
276 
277  void print (const unsigned int& depth = -1, std::ostream& out = std::cout) const;
278  std::string nodeDump (bool forcePrintout = false) const;
279 
281  friend std::ostream& operator<< (
282  std::ostream& out, const ConfigurationTree& t)
283  {
284  out << t.getValueAsString();
285  return out;
286  }
287 
288  const TableViewColumnInfo& getColumnInfo (void) const;
289 
290  protected:
291  const unsigned int& getRow (void) const;
292  const unsigned int& getColumn (void) const;
293  const unsigned int& getFieldRow (void) const;
294  const unsigned int& getFieldColumn (void) const;
295 
296 
298  struct RecordField
299  {
300  RecordField(const std::string& table,
301  const std::string& /*uid*/,
302  const std::string& columnName,
303  const std::string& relativePath,
304  const TableViewColumnInfo* columnInfo)
305  : tableName_(table)
306  , columnName_(columnName)
307  , relativePath_(relativePath)
308  , columnInfo_(columnInfo)
309  {
310  }
311 
312  std::string tableName_, columnName_, relativePath_;
313  // relativePath_ is relative to record uid node, not including columnName_
314 
315  const TableViewColumnInfo* columnInfo_;
316  };
317  std::vector<ConfigurationTree::RecordField> getCommonFields (
318  const std::vector<std::string /*relative-path*/>& recordList,
319  const std::vector<std::string /*relative-path*/>& fieldAcceptList,
320  const std::vector<std::string /*relative-path*/>& fieldRejectList,
321  unsigned int depth = -1,
322  bool autoSelectFilterFields = false) const;
323  std::set<std::string /*unique-value*/> getUniqueValuesForField (
324  const std::vector<std::string /*relative-path*/>& recordList,
325  const std::string& fieldName,
326  std::string* fieldGroupIDChildLinkIndex = 0) const;
327 
328  private:
330  ConfigurationTree(const ConfigurationManager* const& configMgr,
331  const TableBase* const& config,
332  const std::string& groupId,
333  const TableBase* const& linkParentConfig,
334  const std::string& linkColName,
335  const std::string& linkColValue,
336  const unsigned int linkBackRow,
337  const unsigned int linkBackCol,
338  const std::string& disconnectedTargetName,
339  const std::string& disconnectedLinkID,
340  const std::string& childLinkIndex,
341  const unsigned int row = TableView::INVALID,
342  const unsigned int col = TableView::INVALID);
343 
344  static ConfigurationTree recurse (const ConfigurationTree& t, const std::string& childPath, bool doNotThrowOnBrokenUIDLinks, const std::string& originalNodeString);
345  ConfigurationTree recursiveGetNode (const std::string& nodeName, bool doNotThrowOnBrokenUIDLinks, const std::string& originalNodeString) const;
346  static void recursivePrint (const ConfigurationTree& t, unsigned int depth, std::ostream& out, std::string space);
347 
348  void recursiveGetCommonFields (
349  std::vector<ConfigurationTree::RecordField>& fieldCandidateList,
350  std::vector<int>& fieldCount,
351  const std::vector<std::string /*relative-path*/>& fieldAcceptList,
352  const std::vector<std::string /*relative-path*/>& fieldRejectList,
353  unsigned int depth,
354  const std::string& relativePathBase,
355  bool inFirstRecord) const;
356  ConfigurationTree getValueAsTreeNode (void) const;
357 
364  const ConfigurationManager* configMgr_;
365  const TableBase* table_;
366  const std::string groupId_;
367  const TableBase* linkParentTable_;
369  const std::string linkColName_;
370  const std::string linkColValue_;
371  const unsigned int linkBackRow_;
372  const unsigned int linkBackCol_;
373  const std::string disconnectedTargetName_;
375  const std::string disconnectedLinkID_;
376  const std::string childLinkIndex_;
377  const unsigned int row_;
378  const unsigned int col_;
379  const TableView* tableView_;
380 
381  static time_t LAST_NODE_DUMP_TIME;
382 };
383 
384 #include "otsdaq/ConfigurationInterface/ConfigurationTree.icc" //define template functions
385 
386 //==============================================================================
390 template<typename T>
391 inline void ConfigurationTree::BitMap<T>::print(std::ostream& out) const
392 {
393  if(!bitmap_.size())
394  {
395  out << "Bitmap print of empty bitmap.";
396  return;
397  }
398 
399  out << "Bitmap print of size " << bitmap_.size() << " x " << bitmap_[0].size() << __E__;
400  out << " r x c : ";
401  for(unsigned int c = 0; c < bitmap_[0].size(); ++c)
402  out << std::right << std::setw(15) << c << ' ';
403  out << "\n-------+-";
404  for(unsigned int c = 0; c < bitmap_[0].size(); ++c)
405  out << "---------------+";
406  for(unsigned int r = 0; r < bitmap_.size(); ++r)
407  {
408  out << "\n" << std::right << std::setw(6) << r << " : ";
409  if(sizeof(T) == 1) //force 8-bit to number display
410  for(unsigned int c = 0; c < bitmap_[r].size(); ++c)
411  out << std::right << std::setw(15) << std::fixed << std::setprecision(3) << (uint16_t)get(r,c) << ' ';
412  else
413  for(unsigned int c = 0; c < bitmap_[r].size(); ++c)
414  out << std::right << std::setw(15) << std::fixed << std::setprecision(3) << get(r,c) << ' ';
415  }
416  out << "\n=======+=";
417  for(unsigned int c = 0; c < bitmap_[0].size(); ++c)
418  out << "===============+";
419 
420  out << "\n";
421 } //end print()
422 
423 //==============================================================================
427 template<>
428 inline void ConfigurationTree::BitMap<std::string>::print(std::ostream& out) const
429 {
430  if(!bitmap_.size())
431  {
432  out << "Bitmap print of empty bitmap.";
433  return;
434  }
435 
436  out << "Bitmap print of size " << bitmap_.size() << " x " << bitmap_[0].size() << __E__;
437  out << " r x c : ";
438  for(unsigned int c = 0; c < bitmap_[0].size(); ++c)
439  out << std::right << std::setw(15) << c << ' ';
440  out << "\n-------+-";
441  for(unsigned int c = 0; c < bitmap_[0].size(); ++c)
442  out << "---------------+";
443  for(unsigned int r = 0; r < bitmap_.size(); ++r)
444  {
445  out << "\n" << std::right << std::setw(6) << r << " : ";
446  for(unsigned int c = 0; c < bitmap_[r].size(); ++c)
447  out << std::right << std::setw(15) << get(r,c) << ' ';
448  }
449  out << "\n=======+=";
450  for(unsigned int c = 0; c < bitmap_[0].size(); ++c)
451  out << "===============+";
452 
453  out << "\n";
454 } //end print() T=std:string
455 
456 // clang-format on
457 } // namespace ots
458 
459 #endif
<virtual so future plugins can inherit from multiple table base classes
const unsigned int & getRow(void) const
getRow
const std::string & getValueDataType(void) const
std::map< std::string, ConfigurationTree > getNodes(const std::string &nodeString) const
getNodes
const TableVersion & getTableVersion(void) const
getTableVersion
bool isDisconnected(void) const
const std::string & getAuthor(void) const
getAuthor
const std::string & getComment(void) const
getComment
std::vector< std::string > getChildrenNames(bool byPriority=false, bool onlyStatusTrue=false) const
bool isEnabled(void) const
same as status()
static const std::string NODE_TYPE_GROUP_TABLE
bool isValueNumberDataType(void) const
ConfigurationTree getNode(const std::string &nodeName, bool doNotThrowOnBrokenUIDLinks=false) const
navigating between nodes
const std::string & getTableName(void) const
getTableName
T getValueWithDefault(const T &defaultValue) const
const unsigned int & getFieldRow(void) const
std::map< std::string, ConfigurationTree > getChildrenMap(std::map< std::string, std::string > filterMap=std::map< std::string, std::string >(), bool onlyStatusTrue=false) const
std::string nodeDump(bool forcePrintout=false) const
used for debugging (when throwing exception)
const std::string & getValueName(void) const
const std::string & getValueAsString(bool returnLinkTableValue=false) const
const ConfigurationManager * getConfigurationManager(void) const
extracting information from node
const std::string & getChildLinkIndex(void) const
getChildLinkIndex
void print(const unsigned int &depth=-1, std::ostream &out=std::cout) const
bool isGroupIDNode(void) const
void getValue(T &value) const
const std::string & getDisconnectedTableName(void) const
getDisconnectedTableName
bool isValueBoolType(void) const
std::vector< std::pair< std::string, ConfigurationTree > > getChildren(std::map< std::string, std::string > filterMap=std::map< std::string, std::string >(), bool byPriority=false, bool onlyStatusTrue=false) const
std::vector< std::string > getFixedChoices(void) const
bool hasComment(void) const
hasComment
const std::string & getDefaultValue(void) const
const time_t & getTableCreationTime(void) const
getTableCreationTime
std::string getParentLinkIndex(void) const
getParentLinkIndex
const std::string & getUIDAsString(void) const
bool status(void) const
same as isEnabled()
std::vector< ConfigurationTree::RecordField > getCommonFields(const std::vector< std::string > &recordList, const std::vector< std::string > &fieldAcceptList, const std::vector< std::string > &fieldRejectList, unsigned int depth=-1, bool autoSelectFilterFields=false) const
const unsigned int & getNodeRow(void) const
getNodeRow
std::set< std::string > getSetOfGroupIDs(void) const
bool isValueNode(void) const
const std::string & getFieldName(void) const
alias for getValueName
std::vector< std::vector< std::string > > getChildrenNamesByPriority(bool onlyStatusTrue=false) const
std::set< std::string > getUniqueValuesForField(const std::vector< std::string > &recordList, const std::string &fieldName, std::string *fieldGroupIDChildLinkIndex=0) const
const std::string & getValueType(void) const
bool passFilterMap(const std::string &childName, std::map< std::string, std::string > filterMap) const
~ConfigurationTree(void)
destructor
bool isGroupLinkNode(void) const
std::string getParentLinkID(void) const
getParentLinkID
const std::string & getFieldTableName(void) const
const unsigned int & getColumn(void) const
getColumn
const std::string & getDisconnectedLinkID(void) const
getDisconnectedLinkID
const std::string & getParentTableName(void) const
getParentTableName
bool isUIDLinkNode(void) const
const std::string & getParentRecordName(void) const
getParentRecordName
std::string getEscapedValue(void) const
friend std::ostream & operator<<(std::ostream &out, const ConfigurationTree &t)
make stream output easy
const TableViewColumnInfo & getColumnInfo(void) const
bool isDefaultValue(void) const
boolean info
std::vector< std::vector< std::pair< std::string, ConfigurationTree > > > getChildrenByPriority(std::map< std::string, std::string > filterMap=std::map< std::string, std::string >(), bool onlyStatusTrue=false) const
const std::string & getParentLinkColumnName(void) const
getParentLinkColumnName
T getValue(void) const
defined in included .icc source
const unsigned int & getFieldColumn(void) const
defines used also by OtsConfigurationWizardSupervisor
friend ConfigurationTree
so ConfigurationTree can access private
void print(std::ostream &out=std::cout) const
extracting information from a list of records
static std::string stackTrace(void)