47#include <libdap/InternalErr.h>
51#include "ObjMemCache.h"
56BaseType *HDF5BaseArray::ptr_duplicate()
63bool HDF5BaseArray::read()
65 BESDEBUG(
"h5",
"Coming to HDF5BaseArray read "<<endl);
74HDF5BaseArray::format_constraint (
int *offset,
int *step,
int *count)
79 Dim_iter p = dim_begin ();
81 while (p != dim_end ()) {
83 int start = dimension_start (p,
true);
84 int stride = dimension_stride (p,
true);
85 int stop = dimension_stop (p,
true);
90 oss <<
"Array/Grid hyperslab start point "<< start <<
91 " is greater than stop point " << stop <<
".";
92 throw Error(malformed_expr, oss.str());
97 count[id] = ((stop - start) / stride) + 1;
101 "=format_constraint():"
102 <<
"id=" <<
id <<
" offset=" << offset[
id]
103 <<
" step=" << step[
id]
104 <<
" count=" << count[
id]
114void HDF5BaseArray::write_nature_number_buffer(
int rank,
int tnumelm) {
117 throw InternalErr(__FILE__, __LINE__,
"Currently the rank of the missing field should be 1");
127 int nelms = format_constraint(offset.data(), step.data(), count.data());
135 if (nelms == tnumelm) {
136 for (
int i = 0; i < nelms; i++)
138 set_value(val.data(), nelms);
141 for (
int i = 0; i < count[0]; i++)
142 val[i] = offset[0] + step[0] * i;
143 set_value(val.data(), nelms);
148void HDF5BaseArray::read_data_from_mem_cache(H5DataType h5type,
const vector<size_t> &h5_dimsizes,
void* buf,
const bool is_dap4){
150 BESDEBUG(
"h5",
"Coming to read_data_from_mem_cache"<<endl);
155 auto ndims = (
int)(h5_dimsizes.size());
157 throw InternalErr(__FILE__, __LINE__,
"Currently we only support array numeric data in the cache, the number of dimension for this file is 0");
160 offset.resize(ndims);
163 int nelms = format_constraint (offset.data(), step.data(), count.data());
166 vector<size_t>pos(ndims,0);
167 for (
int i = 0; i< ndims; i++)
176 vector<unsigned char> val;
177 subset<unsigned char>(
189 set_value ((dods_byte *) val.data(), nelms);
209 if(
false == is_dap4) {
212 newval.resize(nelms);
214 for (
int counter = 0; counter < nelms; counter++)
215 newval[counter] = (
short) (val[counter]);
216 set_value ((dods_int16 *) val.data(), nelms);
219 set_value ((dods_int8 *) val.data(), nelms);
241 set_value ((dods_int16 *) val.data(), nelms);
248 vector<unsigned short> val;
249 subset<unsigned short>(
262 set_value ((dods_uint16 *) val.data(), nelms);
281 set_value ((dods_int32 *) val.data(), nelms);
287 vector<unsigned int>val;
288 subset<unsigned int>(
300 set_value ((dods_uint32 *) val.data(), nelms);
309 vector<long long>val;
322 set_value ((dods_int64 *) val.data(), nelms);
328 vector<unsigned long long>val;
329 subset<unsigned long long>(
341 set_value ((dods_uint64 *) val.data(), nelms);
360 set_value ((dods_float32 *) val.data(), nelms);
380 set_value ((dods_float64 *) val.data(), nelms);
385 throw InternalErr(__FILE__,__LINE__,
"Non-supported datatype");
405 const vector<size_t> & dim,
413 for(
int k=0; k<edge[index]; k++)
415 pos[index] = start[index] + k*stride[index];
417 subset(input, rank, dim, start, stride, edge, poutput,pos,index+1);
420 size_t cur_pos = INDEX_nD_TO_1D( dim, pos);
421 void* tempbuf = (
void*)((
char*)input+cur_pos*
sizeof(T));
422 poutput->push_back(*(
static_cast<T*
>(tempbuf)));
429size_t HDF5BaseArray::INDEX_nD_TO_1D (
const std::vector < size_t > &dims,
430 const std::vector < size_t > &pos)
const {
435 if(dims.size () != pos.size ())
436 throw InternalErr(__FILE__,__LINE__,
"dimension error in INDEX_nD_TO_1D routine.");
440 for (
size_t p = 0; p < pos.size (); p++) {
443 for (
size_t j = start; j < dims.size (); j++)
453string HDF5BaseArray::
454check_str_sect_in_list(
const vector<string>&str_list,
const string &cur_str,
const char sep)
const {
457 string::size_type start = 0;
458 string::size_type end = 0;
461 while ((end = cur_str.find(sep, start)) != string::npos) {
462 if(std::find(str_list.begin(),str_list.end(),cur_str.substr(start,end-start))!=
464 ret_str = cur_str.substr(start,end-start);
488check_var_cache_files(
const vector<string>&slist,
const string &fname,
const string &varname)
const {
490 bool ret_value =
false;
491 if(fname==
"" || varname==
"")
496 if(fname[fname.size()-1] ==
'/') {
498 fullpath = fname+varname;
500 fullpath = fname.substr(0,fname.size()-1)+varname;
504 fullpath = fname+
'/'+varname;
506 fullpath = fname+varname;
510 for(
unsigned int i = 0; i<slist.size();i++) {
517 if(fullpath.rfind(slist[i])==(fullpath.size()-slist[i].size())){
527handle_data_with_mem_cache(H5DataType h5_dtype,
size_t total_elems,
const short cache_flag,
const string & cache_key,
const bool is_dap4) {
532 mem_data_cache = HDF5RequestHandler::get_srdata_mem_cache();
533 else if(cache_flag > 1) {
534 mem_data_cache = HDF5RequestHandler::get_lrdata_mem_cache();
547 if(mem_data_cache ==
nullptr)
548 throw InternalErr(__FILE__,__LINE__,
"The memory data cache should NOT be nullptr.");
553 BESDEBUG(
"h5",
"Cache flag: 1 small data cache, 2 large data cache genenral"
554 <<
" 3 large data cache common dir, 4 large data cache real var" <<endl);
556 BESDEBUG(
"h5",
"Data Memory Cache hit, the variable name is "<<name() <<
". The cache flag is "<< cache_flag<<endl);
563 const size_t var_size = mem_cache_ptr->get_var_buf_size();
565 throw InternalErr(__FILE__,__LINE__,
"The cached data buffer size is 0.");
568 void *buf = mem_cache_ptr->get_var_buf();
571 vector<size_t> dim_sizes;
572 Dim_iter i_dim = dim_begin();
573 Dim_iter i_enddim = dim_end();
574 while (i_dim != i_enddim) {
575 dim_sizes.push_back(dimension_size(i_dim));
579 read_data_from_mem_cache(h5_dtype,dim_sizes,buf,is_dap4);
584 BESDEBUG(
"h5",
"Cache flag: 1 small data cache, 2 large data cache genenral"
585 <<
" 3 large data cache common dir, 4 large data cache real var" <<endl);
587 BESDEBUG(
"h5",
"Data Memory added to the cache, the variable name is "<<name() <<
". The cache flag is "<< cache_flag<<endl);
591 throw InternalErr(__FILE__,__LINE__,
"The total number of elements is 0.");
593 buf.resize(total_elems*HDF5CFUtil::H5_numeric_atomic_type_size(h5_dtype));
596 read_data_NOT_from_mem_cache(
true,buf.data());
603 new_mem_cache_ele->set_databuf(buf);
606 mem_data_cache->
add(new_mem_cache_ele, cache_key);
612BaseType* HDF5BaseArray::h5cfdims_transform_to_dap4(D4Group *grp) {
622 D4Dimensions *grp_dims = grp->dims();
623 for (Array::Dim_iter dap2_dim = dest->dim_begin(), e = dest->dim_end(); dap2_dim != e; ++dap2_dim) {
624 if (!(*dap2_dim).name.empty()) {
627 D4Dimension *d4_dim = grp_dims->find_dim((*dap2_dim).name);
629 d4_dim =
new D4Dimension((*dap2_dim).name, (*dap2_dim).size);
630 grp_dims->add_dim_nocopy(d4_dim);
634 (*dap2_dim).dim = d4_dim;
A helper class that aims to reduce code redundence for different special CF derived array class For e...
include the entry functions to execute the handlers
int subset(void *input, int rank, const std::vector< size_t > &dim, int start[], int stride[], int edge[], std::vector< T > *poutput, std::vector< size_t > &pos, int index)
Getting a subset of a variable.
An in-memory cache for DapObj (DAS, DDS, ...) objects.
virtual void add(libdap::DapObj *obj, const std::string &key)
Add an object to the cache and associate it with a key.
virtual libdap::DapObj * get(const std::string &key)
Get the cached pointer.