48#include <libdap/InternalErr.h> 
   52#include "ObjMemCache.h" 
   60HDF5BaseArray::format_constraint (int64_t *offset, int64_t *step, int64_t *count)
 
   65    Dim_iter p = dim_begin ();
 
   67    while (p != dim_end ()) {
 
   69        int64_t start = dimension_start_ll (p, 
true);
 
   70        int64_t stride = dimension_stride_ll (p, 
true);
 
   71        int64_t stop = dimension_stop_ll (p, 
true);
 
   76            oss << 
"Array/Grid hyperslab start point "<< start <<
 
   77                   " is greater than stop point " <<  stop <<
".";
 
   78            throw Error(malformed_expr, oss.str());
 
   83        count[id] = ((stop - start) / stride) + 1;      
 
   87                         "=format_constraint():" 
   88                         << 
"id=" << 
id << 
" offset=" << offset[
id]
 
   89                         << 
" step=" << step[
id]
 
   90                         << 
" count=" << count[
id]
 
  100void HDF5BaseArray::write_nature_number_buffer(
int rank, int64_t tnumelm) {
 
  103        throw InternalErr(__FILE__, __LINE__, 
"Currently the rank of the missing field should be 1");
 
  105    if (tnumelm >DODS_INT_MAX)
 
  106        throw InternalErr(__FILE__, __LINE__, 
"Currently the maximum number for this dimension is less than DODS_INT_MAX");
 
  108    vector<int64_t>offset;
 
  109    vector<int64_t>count;
 
  116    int64_t nelms = format_constraint(offset.data(), step.data(), count.data());
 
  124    if (nelms == tnumelm) {
 
  125        for (int64_t i = 0; i < nelms; i++)
 
  127        set_value_ll(val.data(), nelms);
 
  130        for (int64_t i = 0; i < count[0]; i++)
 
  131            val[i] = (
int)(offset[0] + step[0] * i);
 
  132        set_value_ll(val.data(), nelms);
 
  137void HDF5BaseArray::read_data_from_mem_cache(H5DataType h5type, 
const vector<size_t> &h5_dimsizes,
void* buf,
const bool is_dap4){
 
  139    BESDEBUG(
"h5", 
"Coming to read_data_from_mem_cache"<<endl);
 
  140    vector<int64_t>offset;
 
  141    vector<int64_t>count;
 
  144    auto ndims = (int)(h5_dimsizes.size());
 
  146        throw InternalErr(__FILE__, __LINE__, 
"Currently we only support array numeric data in the cache, the number of dimension for this file is 0");
 
  149    offset.resize(ndims);
 
  152    int64_t nelms = format_constraint (offset.data(), step.data(), count.data());
 
  155    vector<size_t>pos(ndims,0);
 
  156    for (int64_t i = 0; i< ndims; i++)
 
  165            vector<unsigned char> val;
 
  178            set_value_ll ((dods_byte *) val.data(), nelms);
 
  198            if(
false == is_dap4) {
 
  201                newval.resize(nelms);
 
  203                for (int64_t counter = 0; counter < nelms; counter++)
 
  204                    newval[counter] = (
short) (val[counter]);
 
  205                set_value_ll ((dods_int16 *) val.data(), nelms);
 
  208                set_value_ll ((dods_int8 *) val.data(), nelms);
 
  230            set_value_ll (val.data(), nelms);
 
  237            vector<unsigned short> val;
 
  251            set_value_ll (val.data(), nelms);
 
  270            set_value_ll (val.data(), nelms);
 
  276            vector<unsigned int>val;
 
  289            set_value_ll (val.data(), nelms);
 
  298            vector<long long>val;
 
  311            set_value_ll ((dods_int64 *) val.data(), nelms);
 
  317            vector<unsigned long long>val;
 
  330            set_value_ll ((dods_uint64 *) val.data(), nelms);
 
  349            set_value_ll (val.data(), nelms);
 
  369            set_value_ll (val.data(), nelms);
 
  374           throw InternalErr(__FILE__,__LINE__,
"Non-supported datatype");
 
  394    const vector<size_t> & dim,
 
  402    for(
int k=0; k<edge[index]; k++) 
 
  404        pos[index] = start[index] + k*stride[index];
 
  406            subset(input, rank, dim, start, stride, edge, poutput,pos,index+1);           
 
  409            size_t cur_pos = INDEX_nD_TO_1D( dim, pos);
 
  410            void* tempbuf = (
void*)((
char*)input+cur_pos*
sizeof(T));
 
  411            poutput->push_back(*(
static_cast<T*
>(tempbuf)));
 
 
  418size_t HDF5BaseArray::INDEX_nD_TO_1D (
const std::vector < size_t > &dims,
 
  419                                 const std::vector < size_t > &pos)
 const {
 
  424    if(dims.size () != pos.size ())
 
  425        throw InternalErr(__FILE__,__LINE__,
"dimension error in INDEX_nD_TO_1D routine.");
 
  429    for (
size_t p = 0; p < pos.size (); p++) {
 
  432        for (
size_t j = start; j < dims.size (); j++)
 
  442string HDF5BaseArray::
 
  443check_str_sect_in_list(
const vector<string>&str_list, 
const string &cur_str,
const char sep)
 const {
 
  446    string::size_type start = 0;
 
  447    string::size_type end = 0;
 
  450    while ((end = cur_str.find(sep, start)) != string::npos) {
 
  451        if(std::find(str_list.begin(),str_list.end(),cur_str.substr(start,end-start))!=
 
  453           ret_str = cur_str.substr(start,end-start);
 
  477check_var_cache_files(
const vector<string>&slist, 
const string &fname,
const string &varname)
 const {
 
  479    bool ret_value = 
false;
 
  480    if(fname==
"" || varname==
"")
 
  485    if(fname[fname.size()-1] == 
'/') {
 
  487            fullpath = fname+varname;
 
  489            fullpath = fname.substr(0,fname.size()-1)+varname;
 
  493            fullpath = fname+
'/'+varname;
 
  495            fullpath = fname+varname;
 
  499    for(
unsigned int i = 0; i<slist.size();i++) {
 
  506        if(fullpath.rfind(slist[i])==(fullpath.size()-slist[i].size())){
 
  516handle_data_with_mem_cache(H5DataType h5_dtype, 
size_t total_elems,
const short cache_flag, 
const string & cache_key, 
const bool is_dap4) {     
 
  519    ObjMemCache * mem_data_cache= 
nullptr;
 
  521        mem_data_cache = HDF5RequestHandler::get_srdata_mem_cache();
 
  522    else if(cache_flag > 1) {
 
  523        mem_data_cache = HDF5RequestHandler::get_lrdata_mem_cache();
 
  536    if(mem_data_cache == 
nullptr)
 
  537        throw InternalErr(__FILE__,__LINE__,
"The memory data cache should NOT be nullptr.");
 
  539    auto mem_cache_ptr = 
static_cast<HDF5DataMemCache*
>(mem_data_cache->
get(cache_key));
 
  542        BESDEBUG(
"h5",
"Cache flag: 1 small data cache, 2 large data cache general" 
  543                 <<
" 3 large data cache common dir, 4 large data cache real var" <<endl);
 
  545        BESDEBUG(
"h5",
"Data Memory Cache hit, the variable name is "<<name() <<
". The cache flag is "<< cache_flag<<endl);
 
  552        const size_t var_size = mem_cache_ptr->get_var_buf_size();
 
  554            throw InternalErr(__FILE__,__LINE__,
"The cached data buffer size is 0.");
 
  557            void *buf = mem_cache_ptr->get_var_buf();
 
  560            vector<size_t> dim_sizes;
 
  561        Dim_iter i_dim = dim_begin();
 
  562        Dim_iter i_enddim = dim_end();
 
  563        while (i_dim != i_enddim) {
 
  564        dim_sizes.push_back(dimension_size_ll(i_dim));
 
  568            read_data_from_mem_cache(h5_dtype,dim_sizes,buf,is_dap4);
 
  573        BESDEBUG(
"h5",
"Cache flag: 1 small data cache, 2 large data cache genenral" 
  574                 <<
" 3 large data cache common dir, 4 large data cache real var" <<endl);
 
  576        BESDEBUG(
"h5",
"Data Memory added to the cache, the variable name is "<<name() <<
". The cache flag is "<< cache_flag<<endl);
 
  579        if (total_elems == 0)
 
  580                throw InternalErr(__FILE__,__LINE__,
"The total number of elements is 0.");
 
  582        buf.resize(total_elems*HDF5CFUtil::H5_numeric_atomic_type_size(h5_dtype));
 
  585        read_data_NOT_from_mem_cache(
true,buf.data());
 
  589        auto new_mem_cache_ele_unique = make_unique<HDF5DataMemCache>();
 
  590        auto new_mem_cache_ele = new_mem_cache_ele_unique.release();
 
  591        new_mem_cache_ele->set_databuf(buf);
 
  594        mem_data_cache->
add(new_mem_cache_ele, cache_key);
 
  599BaseType* HDF5BaseArray::h5cfdims_transform_to_dap4(D4Group *grp) {
 
  603    Array *dest = 
static_cast<HDF5BaseArray*
>(ptr_duplicate());
 
  609    D4Dimensions *grp_dims = grp->dims();
 
  610    for (Array::Dim_iter dap2_dim = dest->dim_begin(), e = dest->dim_end(); dap2_dim != e; ++dap2_dim) {
 
  611        if (!(*dap2_dim).name.empty()) {
 
  614            D4Dimension *d4_dim = grp_dims->find_dim((*dap2_dim).name);
 
  616                auto d4_dim_unique = make_unique<D4Dimension>((*dap2_dim).name, (*dap2_dim).size);
 
  617                d4_dim = d4_dim_unique.release();
 
  618                grp_dims->add_dim_nocopy(d4_dim);
 
  622            (*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, int64_t start[], int64_t stride[], int64_t edge[], std::vector< T > *poutput, std::vector< size_t > &pos, int index)
Getting a subset of a variable.
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.