Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions dapreader/DapRequestHandler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,14 @@ const string module = "dapreader";

static void read_key_value(const std::string &key_name, bool &key_value, bool &is_key_set)
{
if (is_key_set == false) {
if (!is_key_set) {
bool key_found = false;
string doset;
TheBESKeys::TheKeys()->get_value(key_name, doset, key_found);
if (key_found) {
// It was set in the conf file
is_key_set = true;

doset = BESUtil::lowercase(doset);
key_value = (doset == "true" || doset == "yes");
key_value = TheBESKeys::read_bool_key(key_name, key_value);
}
}
}
Expand All @@ -98,7 +96,7 @@ static bool extension_match(const string &data_source, const string &extension)
}

DapRequestHandler::DapRequestHandler(const string &name) :
BESRequestHandler(name)
BESRequestHandler(name)
{
add_method(DAS_RESPONSE, dap_build_das);
add_method(DDS_RESPONSE, dap_build_dds);
Expand Down Expand Up @@ -127,13 +125,13 @@ void DapRequestHandler::load_dds_from_data_file(const string &accessed, DDS &dds
TestTypeFactory t_factory;
BaseTypeFactory b_factory;
if (d_use_test_types)
dds.set_factory(&t_factory);
//valgrind shows the leaking caused by the following line. KY 2019-12-12
//dds.set_factory(new TestTypeFactory); // DDS deletes the factory
dds.set_factory(&t_factory);
//valgrind shows the leaking caused by the following line. KY 2019-12-12
//dds.set_factory(new TestTypeFactory); // DDS deletes the factory
else
dds.set_factory(&b_factory);
//valgrind shows the leaking caused by the following line. KY 2019-12-12
//dds.set_factory(new BaseTypeFactory);
//valgrind shows the leaking caused by the following line. KY 2019-12-12
//dds.set_factory(new BaseTypeFactory);

unique_ptr<Connect> url(new Connect(accessed));
Response r(fopen(accessed.c_str(), "r"), 0);
Expand Down Expand Up @@ -241,7 +239,7 @@ void DapRequestHandler::build_dmr_from_file(const string& accessed, bool explici
url->read_data_no_mime(*dmr, r);
}
else if (extension_match(accessed, ".dds") || extension_match(accessed, ".dods")
|| extension_match(accessed, ".data")) {
|| extension_match(accessed, ".data")) {

unique_ptr<DDS> dds(new DDS(0 /*factory*/));

Expand Down Expand Up @@ -542,4 +540,3 @@ void DapRequestHandler::dump(ostream &strm) const
BESRequestHandler::dump(strm);
BESIndent::UnIndent();
}

46 changes: 46 additions & 0 deletions dispatch/TheBESKeys.cc
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,52 @@ uint64_t TheBESKeys::read_uint64_key(const string &key, uint64_t default_value)
}
}

/**
* @brief Read a float key from the bes.conf file.
*
* Look-up the bes key \arg key and return its value if set. If the
* key is not set, return the default value.
*
* @param key The key to look up
* @param default_value Return this value if \arg key is not found.
* @return The double value of \arg key.
*/
double TheBESKeys::read_double_key(const std::string &key, double default_value) {
bool found = false;
string value;
TheBESKeys::TheKeys()->get_value(key, value, found);
// 'key' holds the string value at this point if found is true
if (found) {
double double_val = std::stod(value);
return double_val;
} else {
return default_value;
}
}

/**
* @brief Read a float key from the bes.conf file.
*
* Look-up the bes key \arg key and return its value if set. If the
* key is not set, return the default value.
*
* @param key The key to look up
* @param default_value Return this value if \arg key is not found.
* @return The float value of \arg key.
*/
float TheBESKeys::read_float_key(const std::string &key, float default_value) {
bool found = false;
string value;
TheBESKeys::TheKeys()->get_value(key, value, found);
// 'key' holds the string value at this point if found is true
if (found) {
float float_val = std::stof(value);
return float_val;
} else {
return default_value;
}
}

/**
* @brief @return The BES configuration keys, sorted by the std::map default rule for std:string, formatted for ingest
* by the BES.
Expand Down
4 changes: 4 additions & 0 deletions dispatch/TheBESKeys.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ class TheBESKeys : public BESObj {

static uint64_t read_uint64_key(const std::string &key, uint64_t default_value);

static double read_double_key(const std::string &key, double default_value);

static float read_float_key(const std::string &key, float default_value);

std::unordered_map<std::string, std::vector<std::string>>::const_iterator keys_begin() {
return d_the_keys.begin();
}
Expand Down
68 changes: 10 additions & 58 deletions modules/dmrpp_module/DmrppRequestHandler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,55 +139,6 @@ namespace dmrpp
bool DmrppRequestHandler::disable_direct_io = false;

bool DmrppRequestHandler::use_buffer_chunk = true;
// There are methods in TheBESKeys that should be used instead of these.
// jhrg 9/26/23
static void read_key_value(const std::string &key_name, bool &key_value)
{
bool key_found = false;
string value;
TheBESKeys::TheKeys()->get_value(key_name, value, key_found);
if (key_found)
{
value = BESUtil::lowercase(value);
key_value = (value == "true" || value == "yes");
}
}

static void read_key_value(const std::string &key_name, unsigned int &key_value)
{
bool key_found = false;
string value;
TheBESKeys::TheKeys()->get_value(key_name, value, key_found);
if (key_found)
{
istringstream iss(value);
iss >> key_value;
}
}

static void read_key_value(const std::string &key_name, unsigned long long &key_value)
{
bool key_found = false;
string value;
TheBESKeys::TheKeys()->get_value(key_name, value, key_found);
if (key_found)
{
istringstream iss(value);
iss >> key_value;
}
}

static void read_key_value(const std::string &key_name, double &key_value)
{
bool key_found = false;
string value;
TheBESKeys::TheKeys()->get_value(key_name, value, key_found);
if (key_found)
{
istringstream iss(value);
iss >> key_value;
}
}

/**
* Here we register all of our handler functions so that the BES Dispatch machinery
Expand All @@ -206,8 +157,9 @@ namespace dmrpp

stringstream msg;

read_key_value(DMRPP_USE_COMPUTE_THREADS_KEY, d_use_compute_threads);
read_key_value(DMRPP_MAX_COMPUTE_THREADS_KEY, d_max_compute_threads);
// Using TheBESKeys calls instead of custom functions kln 4/1/26
d_use_compute_threads = TheBESKeys::read_bool_key(DMRPP_USE_COMPUTE_THREADS_KEY, d_use_compute_threads);
d_max_compute_threads = TheBESKeys::read_bool_key(DMRPP_MAX_COMPUTE_THREADS_KEY, d_max_compute_threads);
msg << prolog << "Concurrent Compute Threads: ";
if (DmrppRequestHandler::d_use_compute_threads)
{
Expand All @@ -222,18 +174,18 @@ namespace dmrpp
msg.str(std::string());

// DMRPP_CONTIGUOUS_CONCURRENT_THRESHOLD_KEY
read_key_value(DMRPP_CONTIGUOUS_CONCURRENT_THRESHOLD_KEY, d_contiguous_concurrent_threshold);
d_contiguous_concurrent_threshold = TheBESKeys::read_ulong_key(DMRPP_CONTIGUOUS_CONCURRENT_THRESHOLD_KEY, d_contiguous_concurrent_threshold);
msg << prolog << "Contiguous Concurrency Threshold: " << d_contiguous_concurrent_threshold << " bytes." << endl;
INFO_LOG(msg.str());

// Whether the default direct IO feature is disabled. Read the key in.
read_key_value(DMRPP_DISABLE_DIRECT_IO, disable_direct_io);
disable_direct_io = TheBESKeys::read_bool_key(DMRPP_DISABLE_DIRECT_IO, disable_direct_io);

read_key_value(DMRPP_USE_BUFFER_CHUNK, use_buffer_chunk);
use_buffer_chunk = TheBESKeys::read_bool_key(DMRPP_USE_BUFFER_CHUNK, use_buffer_chunk);

// Check the value of FONc.ClassicModel to determine if this response is a netCDF-4 classic from fileout netCDF
// This must be done here since direct IO flag for individual variables should NOT be set for netCDF-4 classic response.
read_key_value(DMRPP_USE_CLASSIC_IN_FILEOUT_NETCDF, is_netcdf4_classic_response);
is_netcdf4_classic_response = TheBESKeys::read_bool_key(DMRPP_USE_CLASSIC_IN_FILEOUT_NETCDF, is_netcdf4_classic_response);

if (!curl_handle_pool)
{
Expand All @@ -242,11 +194,11 @@ namespace dmrpp
}

// This can be set to true using the bes conf file; the default value is false
read_key_value(DMRPP_USE_OBJECT_CACHE_KEY, d_use_object_cache);
d_use_object_cache = TheBESKeys::read_bool_key(DMRPP_USE_OBJECT_CACHE_KEY, d_use_object_cache);
if (d_use_object_cache)
{
read_key_value(DMRPP_OBJECT_CACHE_ENTRIES_KEY, d_object_cache_entries);
read_key_value(DMRPP_OBJECT_CACHE_PURGE_LEVEL_KEY, d_object_cache_purge_level);
d_object_cache_entries = TheBESKeys::read_int_key(DMRPP_OBJECT_CACHE_ENTRIES_KEY, d_object_cache_entries);
d_object_cache_purge_level = TheBESKeys::read_double_key(DMRPP_OBJECT_CACHE_PURGE_LEVEL_KEY, d_object_cache_purge_level);
// The default value of these is nullptr
dds_cache = make_unique<ObjMemCache>(d_object_cache_entries, d_object_cache_purge_level);
das_cache = make_unique<ObjMemCache>(d_object_cache_entries, d_object_cache_purge_level);
Expand Down
20 changes: 2 additions & 18 deletions modules/fileout_covjson/FoCovJsonRequestHandler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,6 @@ using std::map;
bool FoCovJsonRequestHandler::_may_ignore_z_axis = true;
bool FoCovJsonRequestHandler::_simple_geo = true;

// Borrow from the HDF5 handler
bool FoCovJsonRequestHandler::obtain_beskeys_info(const string & key, bool &has_key) {

bool ret_value = false;
string doset ="";
TheBESKeys::TheKeys()->get_value( key, doset, has_key ) ;
if(has_key) {
const string dosettrue ="true";
const string dosetyes = "yes";
doset = BESUtil::lowercase(doset) ;
ret_value = (dosettrue == doset || dosetyes == doset);
}
return ret_value;

}

/** @brief Constructor for FileOut Coverage JSON module
*
* This constructor adds functions to add to the build of a help request
Expand All @@ -73,10 +57,10 @@ FoCovJsonRequestHandler::FoCovJsonRequestHandler(const string &name) :
add_handler( HELP_RESPONSE, FoCovJsonRequestHandler::build_help);
add_handler( VERS_RESPONSE, FoCovJsonRequestHandler::build_version);
bool has_key = false;
bool key_value = obtain_beskeys_info("FoCovJson.MAY_IGNORE_Z_AXIS",has_key);
bool key_value = TheBESKeys::read_bool_key("FoCovJson.MAY_IGNORE_Z_AXIS",has_key);
if (has_key)
_may_ignore_z_axis = key_value;
key_value = obtain_beskeys_info("FoCovJson.SIMPLE_GEO",has_key);
key_value = TheBESKeys::read_bool_key("FoCovJson.SIMPLE_GEO",has_key);
if (has_key)
_simple_geo = key_value;

Expand Down
3 changes: 1 addition & 2 deletions modules/fileout_covjson/FoCovJsonRequestHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ class FoCovJsonRequestHandler: public BESRequestHandler {
virtual ~FoCovJsonRequestHandler(void);

void dump(std::ostream &strm) const override;

static bool obtain_beskeys_info(const std::string& key, bool & has_key);

static bool get_may_ignore_z_axis() { return _may_ignore_z_axis; }
static bool get_simple_geo() { return _simple_geo; }
static bool build_help(BESDataHandlerInterface &dhi);
Expand Down
Loading
Loading