Commit 34aae4c3 authored by Robert Butora's avatar Robert Butora
Browse files

vlkb-obscore: code refactor (eliminates metadata/Surveys from add-obscore-row)

parent 86c16695
Loading
Loading
Loading
Loading
+12 −11
Original line number Diff line number Diff line
@@ -208,7 +208,6 @@ inline void trim(std::string &s) {
// returns band in wavelen [m]
double parse_transition(string trans)
{
   // Surveys::survTransition "num unit" <-- for images
   string::size_type pos = trans.find(' ');
   std::string num  = trans.substr(0, pos);
   std::string unit = trans.substr(pos+1);
@@ -239,13 +238,17 @@ void SqlSchema_INSERT::appendRow(
      const string& obs_id,
      const string& obs_publisher_did,

      const string& dataproduct_type,
      const string& o_ucd,

      const string& access_url,
      const string& access_format,
      const uintmax_t access_estsize,

      const fitsfiles::Hdu& hdu,
      const Survey& surv,

      const double rest_frequency,
      const string& auth_policy,
      const string& auth_groups)
{
   LOG_trace(__func__);
@@ -263,11 +266,11 @@ void SqlSchema_INSERT::appendRow(
   obscoreRow[SqlSchema::obscoreColId::access_format]  = to_sqlstring(access_format);
   obscoreRow[SqlSchema::obscoreColId::access_estsize] = to_string(access_estsize);

   obscoreRow[o_ucd]            = to_sqlstring(surv.oUcd);
   obscoreRow[dataproduct_type] = to_sqlstring(surv.dataproductType);
   obscoreRow[SqlSchema::obscoreColId::o_ucd]            = to_sqlstring(o_ucd);
   obscoreRow[SqlSchema::obscoreColId::dataproduct_type] = to_sqlstring(dataproduct_type);

   obscoreRow[facility_name]   = to_sql_value(hdu.key_values, surv.fitskeyFacilityName);
   obscoreRow[instrument_name] = to_sql_value(hdu.key_values, surv.fitskeyInstrumentName);
   obscoreRow[facility_name]   = to_sql_value(hdu.key_values, "TELESCOP");
   obscoreRow[instrument_name] = to_sql_value(hdu.key_values, "INSTRUME");
   obscoreRow[target_name]     = to_sql_value(hdu.key_values, "OBJECT");

   // sky & spectrum
@@ -304,17 +307,15 @@ void SqlSchema_INSERT::appendRow(
   }
   else if(icrsBounds.size() == 2) // 2D images
   {
      // surv.survTransition "num unit" <-- for images
      try
      {
         //double val{parse_transition(surv.survTransition)};
         const double SPEED_OF_LIGHT{299792458};// [m/s]
         double val{SPEED_OF_LIGHT / surv.restFrequency};
         double val{SPEED_OF_LIGHT / rest_frequency};
         obscoreRow[em_min] = to_string(val); //get_wavelen(EM_PRECISION, hdu.key_values);
      }
      catch(const std::exception&  ex)
      {
         LOG_STREAM << "parse_transition failed for " << surv.survTransition << endl;
         LOG_STREAM << "calc em_min failed: " << ex.what() << endl;
         obscoreRow[em_min] = "NULL";
      }
      obscoreRow[em_max] = obscoreRow[em_min];
@@ -366,7 +367,7 @@ void SqlSchema_INSERT::appendRow(
   obscoreRow[polygon_region] = to_sqlstring(region_spoly(icrsVerts));
   obscoreRow[coordinates]    = to_sqlstring("(" + obscoreRow[s_ra] + "," + obscoreRow[s_dec] + ")");
   // authorization
   obscoreRow[policy]               = to_sqlstring(authPolicyToSQLEnum(surv.authPolicy)) + "::auth_policy";
   obscoreRow[policy]               = to_sqlstring(authPolicyToSQLEnum(auth_policy)) + "::auth_policy";
   obscoreRow[obscoreColId::groups] = to_sqlstring("{" + auth_groups + "}");
   // ?
   obscoreRow[proposal_id] = "NULL";
+10 −6
Original line number Diff line number Diff line
@@ -5,7 +5,6 @@
#include <vector>

#include "SqlSchema.hpp"
#include "SqlSurvey.hpp"

#include "fitsfiles.hpp" // Hdu needed
#include "ObsCoreKeys.hpp"
@@ -33,14 +32,19 @@ class SqlSchema_INSERT : public SqlSchema
            const std::string& obs_id,
            const std::string& obs_publisher_did,
            // optional
            const std::string& dataproduct_type,
            const std::string& o_ucd,

            const std::string& access_url,
            const std::string& access_format,
            const uintmax_t access_estsize,
            // optional
            const fitsfiles::Hdu& hdu,  // header
            const Survey& surv,         // metadata
            // optional
            const std::string& auth_groups); // security

            const fitsfiles::Hdu& hdu,

            // vlkb extra
            const double rest_frequency,
            const std::string& auth_policy,
            const std::string& auth_groups);


      std::vector<std::string> getINSERT(void);
+5 −1
Original line number Diff line number Diff line
@@ -320,8 +320,12 @@ void database::dbAddSurvey(int sid, const string groups,
                  obs_collection,
                  obs_id,
                  obs_publisher_did,
                  surv.dataproductType,
                  surv.oUcd,
                  access_url, access_format, access_estsize,
                  hdu, surv,
                  hdu,
                  surv.restFrequency,
                  surv.authPolicy,
                  groups);
         }
      }