tdaq-develop-2025-02-12
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  struct BitMap
124  {
125  BitMap() : isDefault_(true), zero_(0) {}
126 
128  const uint64_t& get(unsigned int row, unsigned int col) const
129  {
130  return isDefault_ ? zero_ : bitmap_[row][col];
131  }
132  unsigned int numberOfRows() const { return bitmap_.size(); }
133  unsigned int numberOfColumns(unsigned int row) const
134  {
135  return bitmap_[row].size();
136  }
137 
138  private:
139  std::vector<std::vector<uint64_t>> bitmap_;
140  bool isDefault_;
141  uint64_t zero_;
142  };
143 
146  //==============================================================================
150  template<class T>
151  void getValue (T& value) const;
155  void getValue (std::string& value) const;
156  void getValueAsBitMap (ConfigurationTree::BitMap& value) const;
157 
158  //==============================================================================
163  template<class T>
164  T getValue (void) const;
165  template<class T>
166  T getValueWithDefault (const T& defaultValue) const;
170  std::string getValue (void) const;
171  std::string getValueWithDefault (const std::string& defaultValue) const;
173 
174  private:
175  template<typename T>
176  T handleValidateValueForColumn(
177  const TableView* configView,
178  std::string value,
179  unsigned int col,
180  ots::identity<T>) const;
181  std::string handleValidateValueForColumn(
182  const TableView* configView,
183  std::string value,
184  unsigned int col,
186 
187  public:
189  ConfigurationTree getNode (const std::string& nodeName, bool doNotThrowOnBrokenUIDLinks = false) const;
190  std::map<std::string, ConfigurationTree> getNodes (const std::string& nodeString) const;
191  ConfigurationTree getBackNode (std::string nodeName, unsigned int backSteps = 1) const;
192  ConfigurationTree getForwardNode (std::string nodeName, unsigned int forwardSteps = 1) const;
193 
195  const ConfigurationManager* getConfigurationManager (void) const { return configMgr_; }
196  const std::string& getTableName (void) const;
197  const std::string& getParentTableName (void) const;
198  const std::string& getFieldTableName (void) const;
199  const TableVersion& getTableVersion (void) const;
200  const time_t& getTableCreationTime (void) const;
201  std::vector<std::vector<std::string>> getChildrenNamesByPriority (bool onlyStatusTrue = false) const;
202  std::vector<std::string> getChildrenNames (bool byPriority = false, bool onlyStatusTrue = false) const;
203  std::vector<std::vector<std::pair<
204  std::string, ConfigurationTree>>> getChildrenByPriority (std::map<std::string /*relative-path*/,
205  std::string /*value*/> filterMap = std::map<std::string /*relative-path*/, std::string /*value*/>(),
206  bool onlyStatusTrue = false) const;
207  std::vector<std::pair<std::string,
208  ConfigurationTree>> getChildren (std::map<std::string /*relative-path*/,
209  std::string /*value*/> filterMap = std::map<std::string /*relative-path*/, std::string /*value*/>(),
210  bool byPriority = false,
211  bool onlyStatusTrue = false) const;
212  std::map<std::string, ConfigurationTree> getChildrenMap (std::map<std::string /*relative-path*/,
213  std::string /*value*/> filterMap = std::map<std::string /*relative-path*/, std::string /*value*/>(),
214  bool onlyStatusTrue = false) const;
215  bool passFilterMap (const std::string& childName, std::map<std::string /*relative-path*/, std::string /*value*/> filterMap) const;
216  std::string getEscapedValue (void) const;
217  const std::string& getValueAsString (bool returnLinkTableValue = false) const;
218  const std::string& getUIDAsString (void) const;
219  const std::string& getComment (void) const;
220  const std::string& getAuthor (void) const;
221  const std::string& getValueDataType (void) const;
222  const std::string& getValueType (void) const;
223  const std::string& getValueName (void) const;
224  const std::string& getDefaultValue (void) const;
225  inline const std::string& getFieldName (void) const { return getValueName(); }
226  std::string getNodeType (void) const;
227  const unsigned int& getNodeRow (void) const;
228  const std::string& getDisconnectedTableName (void) const;
229  const std::string& getDisconnectedLinkID (void) const;
230  const std::string& getChildLinkIndex (void) const;
231  std::vector<std::string> getFixedChoices (void) const;
232  std::set<std::string> getSetOfGroupIDs (void) const;
233 
234  public:
236  bool isDefaultValue (void) const;
237  inline bool isRootNode (void) const { return (!isLinkNode() && !table_); }
238  inline bool isTableNode (void) const { return (table_ && row_ == TableView::INVALID && col_ == TableView::INVALID); }
239  bool isValueNode (void) const;
240  bool isValueBoolType (void) const;
241  bool isValueNumberDataType (void) const;
242  bool isDisconnected (void) const;
243  bool isLinkNode (void) const;
244  bool isGroupLinkNode (void) const;
245  bool isUIDLinkNode (void) const;
246  bool isGroupIDNode (void) const;
247  bool isUIDNode (void) const;
248  bool isStatusNode (void) const;
249  bool isEnabled (void) const;
250  inline bool status (void) const { return isEnabled(); }
251 
252  void print (const unsigned int& depth = -1, std::ostream& out = std::cout) const;
253  std::string nodeDump (void) const;
254 
256  friend std::ostream& operator<< (
257  std::ostream& out, const ConfigurationTree& t)
258  {
259  out << t.getValueAsString();
260  return out;
261  }
262 
263  protected:
264  const unsigned int& getRow (void) const;
265  const unsigned int& getColumn (void) const;
266  const unsigned int& getFieldRow (void) const;
267  const unsigned int& getFieldColumn (void) const;
268  const TableViewColumnInfo& getColumnInfo (void) const;
269 
271  struct RecordField
272  {
273  RecordField(const std::string& table,
274  const std::string& /*uid*/,
275  const std::string& columnName,
276  const std::string& relativePath,
277  const TableViewColumnInfo* columnInfo)
278  : tableName_(table)
279  , columnName_(columnName)
280  , relativePath_(relativePath)
281  , columnInfo_(columnInfo)
282  {
283  }
284 
285  std::string tableName_, columnName_, relativePath_;
286  // relativePath_ is relative to record uid node, not including columnName_
287 
288  const TableViewColumnInfo* columnInfo_;
289  };
290  std::vector<ConfigurationTree::RecordField> getCommonFields (
291  const std::vector<std::string /*relative-path*/>& recordList,
292  const std::vector<std::string /*relative-path*/>& fieldAcceptList,
293  const std::vector<std::string /*relative-path*/>& fieldRejectList,
294  unsigned int depth = -1,
295  bool autoSelectFilterFields = false) const;
296  std::set<std::string /*unique-value*/> getUniqueValuesForField (
297  const std::vector<std::string /*relative-path*/>& recordList,
298  const std::string& fieldName,
299  std::string* fieldGroupIDChildLinkIndex = 0) const;
300 
301  private:
303  ConfigurationTree(const ConfigurationManager* const& configMgr,
304  const TableBase* const& config,
305  const std::string& groupId,
306  const TableBase* const& linkParentConfig,
307  const std::string& linkColName,
308  const std::string& linkColValue,
309  const unsigned int linkBackRow,
310  const unsigned int linkBackCol,
311  const std::string& disconnectedTargetName,
312  const std::string& disconnectedLinkID,
313  const std::string& childLinkIndex,
314  const unsigned int row = TableView::INVALID,
315  const unsigned int col = TableView::INVALID);
316 
317  static ConfigurationTree recurse (const ConfigurationTree& t, const std::string& childPath, bool doNotThrowOnBrokenUIDLinks, const std::string& originalNodeString);
318  ConfigurationTree recursiveGetNode (const std::string& nodeName, bool doNotThrowOnBrokenUIDLinks, const std::string& originalNodeString) const;
319  static void recursivePrint (const ConfigurationTree& t, unsigned int depth, std::ostream& out, std::string space);
320 
321  void recursiveGetCommonFields (
322  std::vector<ConfigurationTree::RecordField>& fieldCandidateList,
323  std::vector<int>& fieldCount,
324  const std::vector<std::string /*relative-path*/>& fieldAcceptList,
325  const std::vector<std::string /*relative-path*/>& fieldRejectList,
326  unsigned int depth,
327  const std::string& relativePathBase,
328  bool inFirstRecord) const;
329  ConfigurationTree getValueAsTreeNode (void) const;
330 
337  const ConfigurationManager* configMgr_;
338  const TableBase* table_;
339  const std::string groupId_;
340  const TableBase* linkParentTable_;
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_;
348  const std::string disconnectedLinkID_;
349  const std::string childLinkIndex_;
350  const unsigned int row_;
351  const unsigned int col_;
352  const TableView* tableView_;
353 };
354 
355 #include "otsdaq/ConfigurationInterface/ConfigurationTree.icc" //define template functions
356 
357 // clang-format on
358 } // namespace ots
359 
360 #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
ConfigurationTree::BitMap getValueAsBitMap(void) const
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
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
const std::string & getDefaultValue(void) const
const time_t & getTableCreationTime(void) const
getTableCreationTime
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
std::string nodeDump(void) const
used for debugging (when throwing exception)
~ConfigurationTree(void)
destructor
bool isGroupLinkNode(void) const
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
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
T getValue(void) const
defined in included .icc source
const unsigned int & getFieldColumn(void) const
friend ConfigurationTree
so ConfigurationTree can access private
extracting information from a list of records
static std::string stackTrace(void)