DP3
SourceDBCasa.h
Go to the documentation of this file.
1 // SourceDBCasa.h: Class for a Casa table holding sources and their 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_SOURCEDBCASA_H
11 #define LOFAR_PARMDB_SOURCEDBCASA_H
12 
13 #include <set>
14 
15 #include <casacore/tables/Tables/Table.h>
16 #include <casacore/casa/version.h>
17 
18 #include "SourceDB.h"
19 #include "PatchInfo.h"
20 
21 #include "common/Types.h"
22 
23 namespace dp3 {
24 namespace parmdb {
25 
28 
30 class SourceDBCasa : public SourceDBRep {
31  public:
32  SourceDBCasa(const ParmDBMeta& pdm, bool forceNew);
33 
34  ~SourceDBCasa() override;
35 
41  void lock(bool lockForWrite) override;
42  void unlock() override;
44 
47  void checkDuplicates() override;
48 
50  std::vector<std::string> findDuplicatePatches() override;
51 
53  std::vector<std::string> findDuplicateSources() override;
54 
56  bool patchExists(const std::string& patchName) override;
57 
59  bool sourceExists(const std::string& sourceName) override;
60 
65  unsigned int addPatch(const std::string& patchName, int catType,
66  double apparentBrightness, double ra, double dec,
67  bool check) override;
68 
70  void updatePatch(unsigned int patchId, double apparentBrightness, double ra,
71  double dec) override;
72 
81  void addSource(const SourceInfo& sourceInfo, const std::string& patchName,
82  const ParmMap& defaultParameters, double ra, double dec,
83  bool check) override;
84  void addSource(const SourceData& source, bool check) override;
86 
89  void addSource(const SourceInfo& sourceInfo, const std::string& patchName,
90  int catType, double apparentBrightness,
91  const ParmMap& defaultParameters, double ra, double dec,
92  bool check) override;
93 
97  std::vector<std::string> getPatches(int category, const std::string& pattern,
98  double minBrightness,
99  double maxBrightness) override;
100 
102  std::vector<PatchInfo> getPatchInfo(int category, const std::string& pattern,
103  double minBrightness,
104  double maxBrightness) override;
105 
107  std::vector<SourceInfo> getPatchSources(
108  const std::string& patchName) override;
109 
111  std::vector<SourceData> getPatchSourceData(
112  const std::string& patchName) override;
113 
115  SourceInfo getSource(const std::string& sourceName) override;
116 
118  std::vector<SourceInfo> getSources(const std::string& pattern) override;
119 
121  void deleteSources(const std::string& sourceNamePattern) override;
122 
124  void clearTables() override;
125 
128  void getNextSource(SourceData& src) override;
129 
131  bool atEnd() override;
132 
134  void rewind() override;
135 
136  private:
138  void createTables(const std::string& tableName);
139 
141  void addSrc(const SourceInfo& sourceInfo, unsigned int patchId,
142  const ParmMap& defaultParameters, double ra, double dec);
143 
145  void writePatch(double apparentBrightness, double ra, double dec,
146  unsigned int rownr);
147 
149  std::vector<std::string> findDuplicates(casacore::Table& table,
150  const std::string& columnName);
151 
154  void fillSets();
155 
157  std::vector<SourceInfo> readSources(const casacore::Table& table);
158 
160  casacore::Table selectPatches(int category, const std::string& pattern,
161  double minBrightness,
162  double maxBrightness) const;
163 
165  double getDefaultParmValue(const std::string& name);
166 
167  casacore::Table itsPatchTable;
168  casacore::Table itsSourceTable;
169  std::set<std::string> itsPatchSet;
170  std::set<std::string> itsSourceSet;
171  bool itsSetsFilled;
172  casacore::Vector<common::rownr_t> itsRowNr;
173 };
174 
176 
177 } // namespace parmdb
178 } // namespace dp3
179 
180 #endif
Info about a patch.
Base class for a table holding sources and their parameters.
Define common types.
Meta information for the name and type of a ParmDB.
Definition: ParmDBMeta.h:27
A map of parameter name to value set.
Definition: ParmMap.h:30
Class for a Casa table holding source parameters.
Definition: SourceDBCasa.h:30
std::vector< std::string > getPatches(int category, const std::string &pattern, double minBrightness, double maxBrightness) override
void addSource(const SourceInfo &sourceInfo, const std::string &patchName, const ParmMap &defaultParameters, double ra, double dec, bool check) override
void lock(bool lockForWrite) override
std::vector< SourceData > getPatchSourceData(const std::string &patchName) override
Get all data of the sources belonging to the given patch.
SourceDBCasa(const ParmDBMeta &pdm, bool forceNew)
void unlock() override
SourceInfo getSource(const std::string &sourceName) override
Get the source info of the given source.
bool patchExists(const std::string &patchName) override
Test if the patch already exists.
std::vector< std::string > findDuplicateSources() override
Find non-unique source names.
bool atEnd() override
Tell if we are the end of the file.
void addSource(const SourceInfo &sourceInfo, const std::string &patchName, int catType, double apparentBrightness, const ParmMap &defaultParameters, double ra, double dec, bool check) override
void getNextSource(SourceData &src) override
bool sourceExists(const std::string &sourceName) override
Test if the source already exists.
void clearTables() override
Clear database or table.
std::vector< PatchInfo > getPatchInfo(int category, const std::string &pattern, double minBrightness, double maxBrightness) override
Get the info of all patches (name, ra, dec).
std::vector< std::string > findDuplicatePatches() override
Find non-unique patch names.
void deleteSources(const std::string &sourceNamePattern) override
Delete the sources records matching the given (filename like) pattern.
void addSource(const SourceData &source, bool check) override
void checkDuplicates() override
void rewind() override
Reset to the beginning of the file.
std::vector< SourceInfo > getSources(const std::string &pattern) override
Get the info of all sources matching the given (filename like) pattern.
unsigned int addPatch(const std::string &patchName, int catType, double apparentBrightness, double ra, double dec, bool check) override
std::vector< SourceInfo > getPatchSources(const std::string &patchName) override
Get the sources belonging to the given patch.
void updatePatch(unsigned int patchId, double apparentBrightness, double ra, double dec) override
Update the ra/dec and apparent brightness of a patch.
Abstract base class for a table holding source parameters.
Definition: SourceDB.h:29
Class holding a data of a source.
Definition: SourceData.h:31
Info about a source.
Definition: SourceInfo.h:29
This file has generic helper routines for testing steps.
Definition: AntennaConfig.h:53