DP3
ParmDB.h
Go to the documentation of this file.
1 // ParmDB.h: Base class for a table holding parameters
2 //
3 // Copyright (C) 2020 ASTRON (Netherlands Institute for Radio Astronomy)
4 // SPDX-License-Identifier: GPL-3.0-or-later
5 
9 
10 #ifndef LOFAR_PARMDB_PARMDB_H
11 #define LOFAR_PARMDB_PARMDB_H
12 
13 #include "ParmMap.h"
14 #include "ParmDBMeta.h"
15 #include "ParmSet.h"
16 
17 #include <vector>
18 #include <map>
19 
20 namespace dp3 {
21 namespace parmdb {
22 
25 
27 class ParmDBRep {
28  public:
30 
31  virtual ~ParmDBRep();
32 
34  void link() { itsCount++; }
35 
37  int unlink() { return --itsCount; }
38 
43  virtual void flush(bool fsync);
44 
50  virtual void lock(bool lockForWrite);
51  virtual void unlock();
53 
58  virtual Box getRange(const std::string& parmNamePattern) const = 0;
59  virtual Box getRange(const std::vector<std::string>& parmNames) const = 0;
61 
63  const std::vector<double>& getDefaultSteps() const { return itsDefSteps; }
64 
66  virtual void setDefaultSteps(const std::vector<double>&) = 0;
67 
71  virtual void getValuesPattern(ParmMap& result,
72  const std::string& parmNamePattern,
73  const Box& domain);
74 
77  virtual void getValues(std::vector<ParmValueSet>& values,
78  const std::vector<unsigned int>& nameIds,
79  const std::vector<ParmId>& parmIds,
80  const Box& domain) = 0;
81 
85  virtual void putValues(const std::string& parmName, int& nameId,
86  ParmValueSet& values) = 0;
87 
92  // virtual void putValues (ParmMap& parmSet) = 0;
93 
95  virtual void deleteValues(const std::string& parmNamePattern,
96  const Box& domain) = 0;
97 
101  ParmValueSet getDefValue(const std::string& parmName,
102  const ParmValue& defaultValue);
103 
106  virtual void getDefValues(ParmMap& result,
107  const std::string& parmNamePattern) = 0;
108 
110  virtual void putDefValue(const std::string& parmName,
111  const ParmValueSet& value, bool check = true) = 0;
112 
114  virtual void deleteDefValues(const std::string& parmNamePattern) = 0;
115 
117  virtual std::vector<std::string> getNames(const std::string& pattern) = 0;
118 
121  virtual int getNameId(const std::string& parmName) = 0;
122 
124  virtual void clearTables() = 0;
125 
128  void setParmDBMeta(const ParmDBMeta& ptm) { itsPTM = ptm; }
129  const ParmDBMeta& getParmDBMeta() const { return itsPTM; }
131 
134  void setParmDBSeqNr(int seqnr) { itsSeqNr = seqnr; }
135  int getParmDBSeqNr() const { return itsSeqNr; }
137 
140  void clearDefFilled() { itsDefFilled = false; }
141 
142  protected:
144  void setDefStep(unsigned int i, double value) { itsDefSteps[i] = value; }
145 
146  private:
148  virtual void fillDefMap(ParmMap& defMap) = 0;
149 
150  int itsCount;
151  ParmDBMeta itsPTM;
152  int itsSeqNr;
153  bool itsDefFilled;
154  ParmMap itsDefValues;
155  std::vector<double> itsDefSteps;
156 };
157 
159 class ParmDB {
160  public:
163  explicit ParmDB(const ParmDBMeta& ptm, bool forceNew = false);
164 
166  ParmDB(const ParmDB&);
167 
169  ~ParmDB() { decrCount(); }
170 
173 
177  void flush(bool fsync = false) { itsRep->flush(fsync); }
178 
183  void lock(bool lockForWrite = true) { itsRep->lock(lockForWrite); }
184  void unlock() { itsRep->unlock(); }
185 
190  Box getRange(const std::string& parmNamePattern = "") const {
191  return itsRep->getRange(parmNamePattern);
192  }
193  Box getRange(const std::vector<std::string>& parmNames) const {
194  return itsRep->getRange(parmNames);
195  }
197 
199  const std::vector<double>& getDefaultSteps() const {
200  return itsRep->getDefaultSteps();
201  }
202 
204  void setDefaultSteps(const std::vector<double>& steps) {
205  itsRep->setDefaultSteps(steps);
206  }
207 
210  void getValues(ParmMap& result, const std::string& parmNamePattern,
211  const Box& domain) const {
212  itsRep->getValuesPattern(result, parmNamePattern, domain);
213  }
214 
217  void getValues(std::vector<ParmValueSet>& values,
218  const std::vector<unsigned int>& nameIds,
219  const std::vector<ParmId>& parmIds, const Box& domain) {
220  itsRep->getValues(values, nameIds, parmIds, domain);
221  }
222 
226  void putValues(const std::string& name, int& nameId, ParmValueSet& values) {
227  itsRep->putValues(name, nameId, values);
228  }
229 
231  void deleteValues(const std::string& parmNamePattern, const Box& domain) {
232  itsRep->deleteValues(parmNamePattern, domain);
233  }
234 
236  ParmValueSet getDefValue(const std::string& parmName,
237  const ParmValue& defaultValue = ParmValue()) const {
238  return itsRep->getDefValue(parmName, defaultValue);
239  }
240 
243  void getDefValues(ParmMap& result, const std::string& parmNamePattern) const {
244  itsRep->getDefValues(result, parmNamePattern);
245  }
246 
248  void putDefValue(const std::string& parmName, const ParmValueSet& value,
249  bool check = true) {
250  itsRep->putDefValue(parmName, value, check);
251  }
252 
254  void deleteDefValues(const std::string& parmNamePattern) {
255  itsRep->deleteDefValues(parmNamePattern);
256  }
257 
259  std::vector<std::string> getNames(const std::string& pattern) const {
260  return itsRep->getNames(pattern);
261  }
262 
265  int getNameId(const std::string& parmName) {
266  return itsRep->getNameId(parmName);
267  }
268 
270  void clearTables() { itsRep->clearTables(); }
271 
273  const ParmDBMeta& getParmDBMeta() const { return itsRep->getParmDBMeta(); }
274 
276  int getParmDBSeqNr() const { return itsRep->getParmDBSeqNr(); }
277 
280  static ParmDB getParmDB(unsigned int index);
281 
282  private:
284  ParmDB(ParmDBRep*);
285 
287  void decrCount();
288 
289  ParmDBRep* itsRep;
290 
292  static std::map<std::string, int> theirDBNames;
293  static std::vector<ParmDBRep*> theirParmDBs;
294 };
295 
297 
298 } // namespace parmdb
299 } // namespace dp3
300 
301 #endif
Meta information for the name and type of a ParmDB.
A map of parameter name to value set.
Set of parameters to be used.
Class representing a 2-dim box.
Definition: Box.h:36
Meta information for the name and type of a ParmDB.
Definition: ParmDBMeta.h:27
Abstract base class for a table holding parameters.
Definition: ParmDB.h:27
virtual void flush(bool fsync)
virtual void lock(bool lockForWrite)
void setParmDBSeqNr(int seqnr)
Definition: ParmDB.h:134
virtual void setDefaultSteps(const std::vector< double > &)=0
Set the default step values.
virtual void deleteDefValues(const std::string &parmNamePattern)=0
Delete the default value records for the given parameters.
void link()
Link to the DBRep by incrementing the count.
Definition: ParmDB.h:34
virtual Box getRange(const std::vector< std::string > &parmNames) const =0
virtual void getDefValues(ParmMap &result, const std::string &parmNamePattern)=0
void clearDefFilled()
Definition: ParmDB.h:140
const std::vector< double > & getDefaultSteps() const
Get the default step values for the axes.
Definition: ParmDB.h:63
const ParmDBMeta & getParmDBMeta() const
Definition: ParmDB.h:129
virtual void putValues(const std::string &parmName, int &nameId, ParmValueSet &values)=0
virtual void deleteValues(const std::string &parmNamePattern, const Box &domain)=0
Delete the records for the given parameters and domain.
virtual void unlock()
virtual void getValues(std::vector< ParmValueSet > &values, const std::vector< unsigned int > &nameIds, const std::vector< ParmId > &parmIds, const Box &domain)=0
void setDefStep(unsigned int i, double value)
Set the i-th default step value (i<2) in order x,y.
Definition: ParmDB.h:144
virtual int getNameId(const std::string &parmName)=0
virtual void clearTables()=0
Clear database or table.
virtual void putDefValue(const std::string &parmName, const ParmValueSet &value, bool check=true)=0
Put the default value.
virtual Box getRange(const std::string &parmNamePattern) const =0
int getParmDBSeqNr() const
Definition: ParmDB.h:135
void setParmDBMeta(const ParmDBMeta &ptm)
Definition: ParmDB.h:128
ParmValueSet getDefValue(const std::string &parmName, const ParmValue &defaultValue)
virtual std::vector< std::string > getNames(const std::string &pattern)=0
Get the names of all parms matching the given (filename like) pattern.
virtual void getValuesPattern(ParmMap &result, const std::string &parmNamePattern, const Box &domain)
int unlink()
Unlink by decrementing the count.
Definition: ParmDB.h:37
Envelope class for a table holding parameters.
Definition: ParmDB.h:159
ParmValueSet getDefValue(const std::string &parmName, const ParmValue &defaultValue=ParmValue()) const
Get the initial value for the given parameter.
Definition: ParmDB.h:236
void flush(bool fsync=false)
Definition: ParmDB.h:177
static ParmDB getParmDB(unsigned int index)
Box getRange(const std::vector< std::string > &parmNames) const
Definition: ParmDB.h:193
ParmDB(const ParmDBMeta &ptm, bool forceNew=false)
int getNameId(const std::string &parmName)
Definition: ParmDB.h:265
void deleteValues(const std::string &parmNamePattern, const Box &domain)
Delete the records for the given parameters and domain.
Definition: ParmDB.h:231
const ParmDBMeta & getParmDBMeta() const
Get the name and type of the ParmDB.
Definition: ParmDB.h:273
Box getRange(const std::string &parmNamePattern="") const
Definition: ParmDB.h:190
ParmDB(const ParmDB &)
Copy contructor has reference semantics.
void getValues(ParmMap &result, const std::string &parmNamePattern, const Box &domain) const
Definition: ParmDB.h:210
void unlock()
Definition: ParmDB.h:184
const std::vector< double > & getDefaultSteps() const
Get the default step values for the axes.
Definition: ParmDB.h:199
ParmDB & operator=(const ParmDB &)
Assignment has reference semantics.
~ParmDB()
Delete underlying object if no more references to it.
Definition: ParmDB.h:169
void putDefValue(const std::string &parmName, const ParmValueSet &value, bool check=true)
Put the default value for the given parameter.
Definition: ParmDB.h:248
void setDefaultSteps(const std::vector< double > &steps)
Set the default step values.
Definition: ParmDB.h:204
void putValues(const std::string &name, int &nameId, ParmValueSet &values)
Definition: ParmDB.h:226
int getParmDBSeqNr() const
Get ParmDB sequence nr.
Definition: ParmDB.h:276
std::vector< std::string > getNames(const std::string &pattern) const
Get the names matching the pattern in the table.
Definition: ParmDB.h:259
void getValues(std::vector< ParmValueSet > &values, const std::vector< unsigned int > &nameIds, const std::vector< ParmId > &parmIds, const Box &domain)
Definition: ParmDB.h:217
void deleteDefValues(const std::string &parmNamePattern)
Delete the default value records for the given parameters.
Definition: ParmDB.h:254
void clearTables()
Clear database tables (i.e. remove all rows from all tables).
Definition: ParmDB.h:270
void lock(bool lockForWrite=true)
Definition: ParmDB.h:183
void getDefValues(ParmMap &result, const std::string &parmNamePattern) const
Definition: ParmDB.h:243
A map of parameter name to value set.
Definition: ParmMap.h:30
A class holding information of multiple domains of a parameter. ParmValueSet holds the information of...
Definition: ParmValue.h:146
A class containing the values of a parameter.
Definition: ParmValue.h:39
This file has generic helper routines for testing steps.
Definition: AntennaConfig.h:53