Skip to content
Snippets Groups Projects
Commit 9ad73a98 authored by Robert Butora's avatar Robert Butora
Browse files

vlkb-obscore: removes all deprecated tables, leaves only obscore-table

parent fb2a84d4
No related branches found
No related tags found
No related merge requests found
......@@ -14,7 +14,7 @@ class config
std::string getFitsDir() const {return m_settings.at(fits_dir);}
std::string getDbUri(bool with_password = false) const {return m_settings.at(pg_uri);}
std::string getDbUri(/*bool with_password = false*/) const {return m_settings.at(pg_uri);}
std::string getDbSchema() const {return m_settings.at(pg_schema);}
std::string getObsCorePublisher() const {return m_settings.at(obscore_publisher);}
......
......@@ -12,73 +12,6 @@ SqlSchema::SqlSchema()
void SqlSchema::reset(void)
{
headersRow
= {
{headersColId::filename, "filename VARCHAR(4096) NOT NULL"},
{headersColId::hdunum, "hdunum INTEGER NOT NULL"},
{headersColId::pubdid, "pubdid VARCHAR(4096) UNIQUE"},
{headersColId::header, "header TEXT NOT NULL"},
{headersColId::survey_id, "survey_id INTEGER"},
{headersColId::header_id, "header_id INTEGER PRIMARY KEY"}
};
boundsgalRow
= {
{bgheader_id, "header_id INTEGER PRIMARY KEY"},
{lfrom, "lon_from DECIMAL(21,16) NOT NULL" },
{lto, "lon_to DECIMAL(21,16) NOT NULL" },
{lunit, "lon_unit VARCHAR(16)" },
{bfrom, "lat_from DECIMAL(21,16) NOT NULL" },
{bto, "lat_to DECIMAL(21,16) NOT NULL" },
{bunit, "lat_unit VARCHAR(16)" },
{vfrom, "vel_from DECIMAL(21,8)" },// FIXME check why 8 not 16
{vto, "vel_to DECIMAL(21,8)" },
{vunit, "vel_unit VARCHAR(16)" },
};
boundsicrsRow
= {
{biheader_id, "header_id INTEGER PRIMARY KEY"},
{rfrom, "ra_from DECIMAL(21,16) NOT NULL" },
{rto, "ra_to DECIMAL(21,16) NOT NULL" },
{runit, "ra_unit VARCHAR(16)" },
{dfrom, "dec_from DECIMAL(21,16) NOT NULL" },
{dto, "dec_to DECIMAL(21,16) NOT NULL" },
{dunit, "dec_unit VARCHAR(16)" },
};
verticesgalRow
= {
{vgheader_id, "header_id INTEGER PRIMARY KEY"},
{p1lon, "p1_lon DECIMAL(21,16) NOT NULL"},
{p1lat, "p1_lat DECIMAL(21,16) NOT NULL"},
{p2lon, "p2_lon DECIMAL(21,16) NOT NULL"},
{p2lat, "p2_lat DECIMAL(21,16) NOT NULL"},
{p3lon, "p3_lon DECIMAL(21,16) NOT NULL"},
{p3lat, "p3_lat DECIMAL(21,16) NOT NULL"},
{p4lon, "p4_lon DECIMAL(21,16) NOT NULL"},
{p4lat, "p4_lat DECIMAL(21,16) NOT NULL"}
};
verticesicrsRow
= {
{viheader_id, "header_id INTEGER PRIMARY KEY"},
{p1ra, "p1_ra DECIMAL(21,16) NOT NULL"},
{p1dec, "p1_dec DECIMAL(21,16) NOT NULL"},
{p2ra, "p2_ra DECIMAL(21,16) NOT NULL"},
{p2dec, "p2_dec DECIMAL(21,16) NOT NULL"},
{p3ra, "p3_ra DECIMAL(21,16) NOT NULL"},
{p3dec, "p3_dec DECIMAL(21,16) NOT NULL"},
{p4ra, "p4_ra DECIMAL(21,16) NOT NULL"},
{p4dec, "p4_dec DECIMAL(21,16) NOT NULL"}
};
obscoreRow
= {
{dataproduct_type, "dataproduct_type VARCHAR"},
......@@ -132,13 +65,6 @@ void SqlSchema::reset(void)
void SqlSchema::initCols(void)
{
// using namespace columns;
m_columns[headers] = "(" + headersRow.concat_val_first_word() + ")";
m_columns[boundsgal] = "(" + boundsgalRow.concat_val_first_word() + ")";
m_columns[boundsicrs] = "(" + boundsicrsRow.concat_val_first_word() + ")";
m_columns[verticesgal] = "(" + verticesgalRow.concat_val_first_word() + ")";
m_columns[verticesicrs] = "(" + verticesicrsRow.concat_val_first_word() + ")";
m_columns[obscore] = "(" + obscoreRow.concat_val_first_word() + ")";
};
......@@ -146,13 +72,6 @@ void SqlSchema::initCols(void)
void SqlSchema::appendRow(void)
{
// using namespace columns;
m_values[headers] += "(" + headersRow.concat_val_all() + "),";
m_values[boundsgal] += "(" + boundsgalRow.concat_val_all() + "),";
m_values[boundsicrs] += "(" + boundsicrsRow.concat_val_all() + "),";
m_values[verticesgal] += "(" + verticesgalRow.concat_val_all() + "),";
m_values[verticesicrs] += "(" + verticesicrsRow.concat_val_all() + "),";
m_values[obscore] += "(" + obscoreRow.concat_val_all() + "),";
};
......@@ -166,45 +85,3 @@ string SqlSchema::skl(string str)
return str.substr(0, str.size() - 1);
}
#if 0
vector<string> SqlSchema::concatedValues(void)
{
vector<string> vVals;
std::map<Tables, std::string>::const_iterator it = m_values.begin();
while(it != m_values.end())
{
Tables t = it->first;
string cmd = it->second;
vVals.push_back(cmd);
it++;
}
return vVals;
}
vector<string> SqlSchema::map2vect(const map<SqlSchema::Tables, string>& amap)
{
vector<string> vVals;
std::map<SqlSchema::Tables, std::string>::const_iterator it = amap.begin();
while(it != amap.end())
{
SqlSchema::Tables t = it->first;
string cmd = it->second;
vVals.push_back(cmd);
it++;
}
return vVals;
}
vector<string> SqlSchema::concatedColumns(void)
{
return map2vect(m_columns);
}
#endif
......@@ -25,15 +25,9 @@ class SqlSchema
void initCols(void);
void appendRow(void);
// groups of columns
enum class headersColId {header_id, filename, hdunum, pubdid, header, survey_id};
enum boundsgalColId {bgheader_id, lfrom, lto, lunit, bfrom, bto, bunit, vfrom, vto, vunit};
enum boundsicrsColId {biheader_id, rfrom, rto, runit, dfrom, dto, dunit};
enum verticesgalColId {vgheader_id, p1lon, p1lat, p2lon, p2lat, p3lon, p3lat, p4lon, p4lat};
enum verticesicrsColId {viheader_id, p1ra, p1dec, p2ra, p2dec, p3ra, p3dec, p4ra, p4dec};
enum obscoreColId {dataproduct_type, calib_level,
enum /* class */ obscoreColId {dataproduct_type, calib_level,
obs_collection, obs_title, obs_id, obs_publisher_id,
bib_reference, data_rights,
access_url, access_format, access_estsize, target_name,
......@@ -47,40 +41,24 @@ class SqlSchema
proposal_id,
policy, groups};
colmap<headersColId, std::string> headersRow;
colmap<boundsgalColId, std::string> boundsgalRow;
colmap<boundsicrsColId, std::string> boundsicrsRow;
colmap<verticesgalColId, std::string> verticesgalRow;
colmap<verticesicrsColId, std::string> verticesicrsRow;
colmap<obscoreColId, std::string> obscoreRow;
// organize columns into tables
enum Tables {headers,
boundsgal, boundsicrs, verticesgal, verticesicrs,
obscore};
enum Tables { obscore };
std::map<Tables, std::string> m_columns;
std::map<Tables, std::string> m_values;
// utils
std::string eto_string(enum headersColId cid) {return headersRow[cid].substr(0, headersRow[cid].find(' ')); };
std::string eto_string(enum boundsgalColId cid) {return boundsgalRow[cid].substr(0, boundsgalRow[cid].find(' ')); };
std::string eto_string(enum Tables tid) {return tableNames[tid].substr(0, tableNames[tid].find(' ')); };
std::string eto_string(enum Tables tid)
{return tableNames[tid].substr(0, tableNames[tid].find(' ')); };
void reset(void);
std::string skl(std::string str);
// skip last character
std::string skl(std::string str); // skip last character
std::map<Tables, std::string> tableNames{
{headers , "headers"},
{boundsgal, "cubeboundsgalactic"},
{boundsicrs, "cubeboundsicrs"},
{verticesgal, "verticesgalactic"},
{verticesicrs, "verticesicrs"},
{obscore, "obscore"},
};
......
......@@ -9,8 +9,7 @@ SqlSchema_CREATE::SqlSchema_CREATE(void)
appendRow();
}
// skip first '(' and last ',' character
// FIXME this is no good
// skip first '(' and last ',' character; FIXME this is no good
string skfl(string str)
{
return str.substr(1, str.size() - 2);
......@@ -20,12 +19,6 @@ string skfl(string str)
vector<string> SqlSchema_CREATE::getCREATE(void)
{
vector<string> vCREATE{
/* {"DROP TABLE IF EXISTS headers CASCADE; CREATE TABLE headers (" + skfl(m_values[headers])},
{"DROP TABLE IF EXISTS cubeboundsgalactic CASCADE; CREATE TABLE cubeboundsgalactic (" + skfl(m_values[boundsgal])},
{"DROP TABLE IF EXISTS cubeboundsicrs CASCADE; CREATE TABLE cubeboundsicrs (" + skfl(m_values[boundsicrs])},
{"DROP TABLE IF EXISTS verticesgalactic CASCADE; CREATE TABLE verticesgalactic (" + skfl(m_values[verticesgal])},
{"DROP TABLE IF EXISTS verticesicrs CASCADE; CREATE TABLE verticesicrs (" + skfl(m_values[verticesicrs])},
*/
{"DROP TABLE IF EXISTS obscore CASCADE; CREATE TABLE obscore " + skl(m_values[obscore])},
};
return vCREATE;
......
......@@ -18,28 +18,10 @@ vector<string> SqlSchema_DELETE::getCommand(int sid, const Survey& surv)
string obsTitleStr = surv.getObsTitle();
vector<string> vDELETE{
/* {"DELETE FROM cubeboundsgalactic WHERE header_id IN (SELECT header_id FROM headers WHERE survey_id = " + sidStr + ")"},
{"DELETE FROM cubeboundsicrs WHERE header_id IN (SELECT header_id FROM headers WHERE survey_id = " + sidStr + ")"},
{"DELETE FROM verticesgalactic WHERE header_id IN (SELECT header_id FROM headers WHERE survey_id = " + sidStr + ")"},
{"DELETE FROM verticesicrs WHERE header_id IN (SELECT header_id FROM headers WHERE survey_id = " + sidStr + ")"},
{"DELETE FROM headers WHERE survey_id = " + sidStr},
*/
{"DELETE FROM obscore WHERE obs_collection = \'" + obsCollStr + "\' AND obs_title = \'" + obsTitleStr + "\'"},
{"DELETE FROM obscore WHERE obs_collection = \'" + obsCollStr
+ "\' AND obs_title = \'" + obsTitleStr + "\'"},
};
return vDELETE;
}
/* NOTE:
obscore handled separately
obscore_vlkb handled separately
static relative to for-cycle: sid & tabName[headers]
for(tableName : tableNames)
{
cmdString = "DELETE FROM " + tableName + " WHERE header_id IN (SELECT header_id FROM " + tabName[headers] + " WHERE survey_id = " + to_string(sid) + ")"
vCmd.push_back(cmdString);
}
*/
......@@ -21,10 +21,6 @@
using namespace std;
//----------------------------------------------------------------
// utils
//----------------------------------------------------------------
string to_string(int precision, double value)
{
stringstream stream;
......@@ -161,53 +157,6 @@ string to_sql_value(fitsfiles::key_values_by_type key_values, string key)
}
}
/*
string get_wavelen(int precision, fitsfiles::key_values_by_type key_values)
{
const double UNIT_CONVERT = 0.001; // FIXME header-card unit [mm] but ObsCore em_ is [m]
if(key_values.doubleValues.find("WAVELEN") == key_values.doubleValues.end() )
{
if(key_values.doubleValues.find("WAVELENG") == key_values.doubleValues.end() )
{
if(key_values.doubleValues.find("WAVELNTH") == key_values.doubleValues.end() )
{
return "NULL";
}
else
{
return to_string(precision, UNIT_CONVERT * key_values.doubleValues["WAVELNTH"]);
}
}
else
{
return to_string(precision, UNIT_CONVERT * key_values.doubleValues["WAVELENG"]);
}
}
else
{
return to_string(precision, UNIT_CONVERT * key_values.doubleValues["WAVELEN"]);
}
}*/
/*/ trim from start (in place)
inline void ltrim(std::string &s) {
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](char ch) {
return !std::isspace(ch);
}));
}
// trim from end (in place)
inline void rtrim(std::string &s) {
s.erase(std::find_if(s.rbegin(), s.rend(), [](char ch) {return !std::isspace(ch);} ).base(), s.end());
}
// trim from both ends (in place)
inline void trim(std::string &s) {
rtrim(s);
ltrim(s);
}
*/
// returns band in wavelen [m]
double parse_transition(string trans)
......@@ -233,9 +182,6 @@ double parse_transition(string trans)
}
//----------------------------------------------------------------------
// public API: ObsCore row
//----------------------------------------------------------------------
void SqlSchema_INSERT::appendRow(
const int calib_level,
const string& obs_collection,
......@@ -320,7 +266,7 @@ void SqlSchema_INSERT::appendRow(
{
const double SPEED_OF_LIGHT{299792458};// [m/s]
double val{SPEED_OF_LIGHT / rest_frequency};
obscoreRow[em_min] = (rest_frequency==0.0) ? "NULL" : to_string(val); //get_wavelen(EM_PRECISION, hdu.key_values);
obscoreRow[em_min] = (rest_frequency==0.0) ? "NULL" : to_string(val);
}
catch(const std::exception& ex)
{
......@@ -390,12 +336,6 @@ void SqlSchema_INSERT::appendRow(
vector<string> SqlSchema_INSERT::getINSERT(void)
{
vector<string> vCmds{
/* {"INSERT INTO headers " + m_columns[headers] + " VALUES " + skl(m_values[headers])},
{"INSERT INTO cubeboundsgalactic " + m_columns[boundsgal] + " VALUES " + skl(m_values[boundsgal])},
{"INSERT INTO cubeboundsicrs " + m_columns[boundsicrs] + " VALUES " + skl(m_values[boundsicrs])},
{"INSERT INTO verticesgalactic " + m_columns[verticesgal] + " VALUES " + skl(m_values[verticesgal])},
{"INSERT INTO verticesicrs " + m_columns[verticesicrs] + " VALUES " + skl(m_values[verticesicrs])},
*/
{"INSERT INTO obscore " + m_columns[obscore] + " VALUES " + skl(m_values[obscore])},
};
reset();
......
......@@ -18,7 +18,6 @@
using namespace std;
// internal
struct db_bounds
{
......@@ -29,75 +28,7 @@ struct db_bounds
double lat_to;
};
vector<db_bounds> bounds_reversed(DbConn& db)
{
LOG_trace(__func__);
const double default_when_null = 0.0;
struct db_bounds bounds;
vector<db_bounds> returned_bounds;
SqlSchema schema;
const string lon_from{schema.eto_string(SqlSchema::lfrom)};
const string lon_to {schema.eto_string(SqlSchema::lto)};
const string lat_from{schema.eto_string(SqlSchema::bfrom)};
const string lat_to {schema.eto_string(SqlSchema::bto)};
const string table_boundsgalactic{schema.eto_string(SqlSchema::boundsgal)};
//--- assert LON LAT from < to
string sql{
"SELECT header_id," + lon_from + "," + lon_to + "," + lat_from + "," + lat_to
+ " FROM "+ table_boundsgalactic
+ " WHERE ("
+ lon_from + " > " + lon_to
+ ") or ("
+ lat_from + " > " + lat_to + ")"};
//---- assert LON LAT are normalized
string sql2{
"SELECT header_id," + lon_from + "," + lon_to + "," + lat_from + "," + lat_to
+ " FROM "+ table_boundsgalactic
+ " WHERE ("
+ lon_from + " > " + lon_to
+ ") or ("
"(" + lon_from + " < 0) and ((" + lon_from + " < -180) or (" + lon_to + " >= 180 ))"
") or ("
"(" + lon_from + " >= 0) and ((" + lon_from + " >= 360) or (" + lon_to + " >= 360))"
") or ("
+ lat_from + " > " + lat_to
+ ") or ("
"(" + lat_from + " < -90 ) or (" + lat_from + " >= 90) or "
"(" + lat_to + " < -90 ) or (" + lat_to + " >= 90)"
")"};
//----
pqxx::result pqxx_result{db.dbExecQuery3(sql2)};
try
{
for (auto row: pqxx_result)
{
// FIXME take col-names SqlSchema_SELECT_bouns
bounds.header_id = row["header_id"].as<unsigned int>();
bounds.lon_from = row[lon_from].as<double>(default_when_null);
bounds.lon_to = row[lon_to].as<double>(default_when_null);
bounds.lat_from = row[lat_from].as<double>(default_when_null);
bounds.lat_to = row[lat_to].as<double>(default_when_null);
returned_bounds.push_back(bounds);
}
}
catch (std::exception const &e)
{
LOG_STREAM << "ERR " + string(__FILE__) + "." + to_string(__LINE__) + ": " << e.what() << endl;
}
return returned_bounds;
}
// external
//----------------------------------------------------------------------//
// init db:
......@@ -138,24 +69,7 @@ vector<string> database::dbCheck(const string db_uri, const string db_schema)
vector<string> result_strings;
// check 1: cube/image bounds in right order: from <= to
/* vector<db_bounds> reversed_bounds = bounds_reversed(db);
if(reversed_bounds.size() > 0) result_strings.push_back("assert from < to failed in these rows:");
for(db_bounds one_row : reversed_bounds)
{
result_strings.push_back(
to_string(one_row.header_id)
+ ": (" + to_string(one_row.lon_from)
+ ", " + to_string(one_row.lon_to)
+ ") (" + to_string(one_row.lat_from)
+ ", " + to_string(one_row.lat_to)
+ ")"
);
}
*/
// check 2: rows count equal in all tables
// check 1: rows count equal in all tables
vector<string> tables = db.queryTableNames();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment