DP3
SourceDBBlob.h
Go to the documentation of this file.
1 // SourceDBBlob.h: Class for a Blob file 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_SOURCEDBBLOB_H
11 #define LOFAR_PARMDB_SOURCEDBBLOB_H
12 
13 #include "SourceDB.h"
14 
15 #include <fstream>
16 #include "blob/BlobOBufStream.h"
17 #include "blob/BlobIBufStream.h"
18 #include "blob/BlobOStream.h"
19 #include "blob/BlobIStream.h"
20 
21 namespace dp3 {
22 namespace parmdb {
23 
26 
28 class SourceDBBlob : public SourceDBRep {
29  public:
30  SourceDBBlob(const ParmDBMeta& pdm, bool forceNew);
31 
32  ~SourceDBBlob() override;
33 
37  void lock(bool lockForWrite) override;
38  void unlock() override;
40 
43  void checkDuplicates() override;
44 
46  std::vector<std::string> findDuplicatePatches() override;
47 
49  std::vector<std::string> findDuplicateSources() override;
50 
52  bool patchExists(const std::string& patchName) override;
53 
55  bool sourceExists(const std::string& sourceName) override;
56 
61  unsigned int addPatch(const std::string& patchName, int catType,
62  double apparentBrightness, double ra, double dec,
63  bool check) override;
64 
66  void updatePatch(unsigned int patchId, double apparentBrightness, double ra,
67  double dec) override;
68 
77  void addSource(const SourceInfo& sourceInfo, const std::string& patchName,
78  const ParmMap& defaultParameters, double ra, double dec,
79  bool check) override;
80  void addSource(const SourceData& source, bool check) override;
82 
85  void addSource(const SourceInfo& sourceInfo, const std::string& patchName,
86  int catType, double apparentBrightness,
87  const ParmMap& defaultParameters, double ra, double dec,
88  bool check) override;
89 
93  std::vector<std::string> getPatches(int category, const std::string& pattern,
94  double minBrightness,
95  double maxBrightness) override;
96 
98  std::vector<PatchInfo> getPatchInfo(int category, const std::string& pattern,
99  double minBrightness,
100  double maxBrightness) override;
101 
103  std::vector<SourceInfo> getPatchSources(
104  const std::string& patchName) override;
105 
107  std::vector<SourceData> getPatchSourceData(
108  const std::string& patchName) override;
109 
111  SourceInfo getSource(const std::string& sourceName) override;
112 
114  std::vector<SourceInfo> getSources(const std::string& pattern) override;
115 
118  void deleteSources(const std::string& sourceNamePattern) override;
119 
121  void clearTables() override;
122 
125  void getNextSource(SourceData& src) override;
126 
128  bool atEnd() override;
129 
131  void rewind() override;
132 
133  private:
135  void readAll();
136 
137  std::fstream itsFile;
138  std::shared_ptr<blob::BlobIBufStream> itsBufIn;
139  std::shared_ptr<blob::BlobOBufStream> itsBufOut;
140  std::shared_ptr<blob::BlobIStream> itsBlobIn;
141  std::shared_ptr<blob::BlobOStream> itsBlobOut;
142  bool itsCanWrite;
143  int64_t itsEndPos;
144  std::map<std::string, PatchInfo> itsPatches;
145  std::map<std::string, std::vector<SourceData>>
146  itsSources;
147 };
148 
150 
151 } // namespace parmdb
152 } // namespace dp3
153 
154 #endif
Base class for a table holding sources and their parameters.
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 Blob file holding source parameters.
Definition: SourceDBBlob.h:28
bool sourceExists(const std::string &sourceName) override
Test if the source already exists.
void addSource(const SourceInfo &sourceInfo, const std::string &patchName, int catType, double apparentBrightness, const ParmMap &defaultParameters, double ra, double dec, bool check) override
void updatePatch(unsigned int patchId, double apparentBrightness, double ra, double dec) override
Update the ra/dec and apparent brightness of a patch.
std::vector< std::string > findDuplicatePatches() override
Find non-unique patch names.
void clearTables() override
Clear file (i.e. remove everything).
void lock(bool lockForWrite) override
std::vector< std::string > getPatches(int category, const std::string &pattern, double minBrightness, double maxBrightness) override
SourceInfo getSource(const std::string &sourceName) override
Get the source info of the given source.
std::vector< SourceInfo > getPatchSources(const std::string &patchName) override
Get the sources belonging to the given patch.
bool patchExists(const std::string &patchName) override
Test if the patch already exists.
void addSource(const SourceData &source, bool check) override
unsigned int addPatch(const std::string &patchName, int catType, double apparentBrightness, double ra, double dec, bool check) override
void checkDuplicates() override
void deleteSources(const std::string &sourceNamePattern) override
SourceDBBlob(const ParmDBMeta &pdm, bool forceNew)
void rewind() override
Reset to the beginning of the file.
void unlock() override
std::vector< std::string > findDuplicateSources() override
Find non-unique source names.
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< SourceData > getPatchSourceData(const std::string &patchName) override
Get all data of the sources belonging to the given patch.
void getNextSource(SourceData &src) override
std::vector< SourceInfo > getSources(const std::string &pattern) override
Get the info of all sources matching the given (filename like) pattern.
bool atEnd() override
Tell if we are the end of the file.
void addSource(const SourceInfo &sourceInfo, const std::string &patchName, const ParmMap &defaultParameters, double ra, double dec, bool check) override
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