39 #include <sys/types.h>
45 #include <D4BaseTypeFactory.h>
46 #include <BESDMRResponse.h>
47 #include <ObjMemCache.h>
50 #include <mime_util.h>
55 #include <BESDASResponse.h>
56 #include <BESDDSResponse.h>
57 #include <BESDataDDSResponse.h>
58 #include <Ancillary.h>
60 #include <BESDapNames.h>
61 #include <BESResponseNames.h>
62 #include <BESContainer.h>
63 #include <BESResponseHandler.h>
64 #include <BESVersionInfo.h>
65 #include <BESServiceRegistry.h>
67 #include <BESDapError.h>
68 #include <BESInternalFatalError.h>
69 #include <TheBESKeys.h>
72 #include "config_hdf5.h"
74 #define HDF5_NAME "h5"
81 void get_attr_contents(AttrTable* temp_table);
85 void write_das_to_file(DAS*das_ptr,FILE* das_file);
88 void write_das_table_to_file(AttrTable*temp_table,FILE* das_file);
91 void write_container_name_to_file(
const string&,FILE* das_file);
94 void write_das_attr_info(AttrTable* dtp,
const string&,
const string&,FILE * das_file);
97 char* copy_str(
char *temp_ptr,
const string & str);
101 char* obtain_str(
char*temp_ptr,
string & str);
104 char* get_attr_info_from_dc(
char*temp_pointer,DAS *das,AttrTable *at);
107 bool check_beskeys(
const string);
110 static unsigned int get_uint_key(
const string &key,
unsigned int def_val);
111 static unsigned long get_ulong_key(
const string &key,
unsigned long def_val);
114 static float get_float_key(
const string &key,
float def_val);
117 static string get_beskeys(
const string&);
120 extern void read_cfdas(DAS &das,
const string & filename,hid_t fileid);
121 extern void read_cfdds(DDS &dds,
const string & filename,hid_t fileid);
125 unsigned int HDF5RequestHandler::_mdcache_entries = 500;
126 unsigned int HDF5RequestHandler::_lrdcache_entries = 0;
127 unsigned int HDF5RequestHandler::_srdcache_entries = 0;
128 float HDF5RequestHandler::_cache_purge_level = 0.2;
135 ObjMemCache *HDF5RequestHandler::lrdata_mem_cache = 0;
136 ObjMemCache *HDF5RequestHandler::srdata_mem_cache = 0;
139 bool HDF5RequestHandler::_usecf =
false;
140 bool HDF5RequestHandler::_pass_fileid =
false;
141 bool HDF5RequestHandler::_disable_structmeta =
false;
142 bool HDF5RequestHandler::_disable_ecsmeta =
false;
143 bool HDF5RequestHandler::_keep_var_leading_underscore =
false;
144 bool HDF5RequestHandler::_check_name_clashing =
false;
145 bool HDF5RequestHandler::_add_path_attrs =
false;
146 bool HDF5RequestHandler::_drop_long_string =
false;
147 bool HDF5RequestHandler::_fillvalue_check =
false;
148 bool HDF5RequestHandler::_check_ignore_obj =
false;
149 bool HDF5RequestHandler::_flatten_coor_attr =
false;
150 bool HDF5RequestHandler::_default_handle_dimension =
false;
152 bool HDF5RequestHandler::_common_cache_dirs =
false;
154 bool HDF5RequestHandler::_use_disk_cache =
false;
155 bool HDF5RequestHandler::_use_disk_dds_cache =
false;
156 string HDF5RequestHandler::_disk_cache_dir =
"";
157 string HDF5RequestHandler::_disk_cachefile_prefix =
"";
158 unsigned long long HDF5RequestHandler::_disk_cache_size =0;
161 bool HDF5RequestHandler::_disk_cache_comp_data =
false;
162 bool HDF5RequestHandler::_disk_cache_float_only_comp_data =
false;
163 float HDF5RequestHandler::_disk_cache_comp_threshold =1.0;
164 unsigned long HDF5RequestHandler::_disk_cache_var_size =0;
166 bool HDF5RequestHandler::_use_disk_meta_cache =
false;
167 string HDF5RequestHandler::_disk_meta_cache_path =
"";
169 bool HDF5RequestHandler::_use_latlon_disk_cache =
false;
170 long HDF5RequestHandler::_latlon_disk_cache_size =0;
171 string HDF5RequestHandler::_latlon_disk_cache_dir =
"";
172 string HDF5RequestHandler::_latlon_disk_cachefile_prefix=
"";
174 DMR* HDF5RequestHandler::dmr_int64 = 0;
181 string HDF5RequestHandler::_stp_east_filename;
182 string HDF5RequestHandler::_stp_north_filename;
183 vector<string> HDF5RequestHandler::lrd_cache_dir_list;
184 vector<string> HDF5RequestHandler::lrd_non_cache_dir_list;
185 vector<string> HDF5RequestHandler::lrd_var_cache_file_list;
192 HDF5RequestHandler::HDF5RequestHandler(
const string & name)
196 BESDEBUG(HDF5_NAME,
"In HDF5RequestHandler::HDF5RequestHandler" << endl);
198 add_handler(DAS_RESPONSE, HDF5RequestHandler::hdf5_build_das);
199 add_handler(DDS_RESPONSE, HDF5RequestHandler::hdf5_build_dds);
200 add_handler(DATA_RESPONSE, HDF5RequestHandler::hdf5_build_data);
201 add_handler(DMR_RESPONSE, HDF5RequestHandler::hdf5_build_dmr);
202 add_handler(DAP4DATA_RESPONSE, HDF5RequestHandler::hdf5_build_dmr);
204 add_handler(HELP_RESPONSE, HDF5RequestHandler::hdf5_build_help);
205 add_handler(VERS_RESPONSE, HDF5RequestHandler::hdf5_build_version);
208 HDF5RequestHandler::_mdcache_entries = get_uint_key(
"H5.MetaDataMemCacheEntries", 0);
209 HDF5RequestHandler::_lrdcache_entries = get_uint_key(
"H5.LargeDataMemCacheEntries", 0);
210 HDF5RequestHandler::_srdcache_entries = get_uint_key(
"H5.SmallDataMemCacheEntries", 0);
211 HDF5RequestHandler::_cache_purge_level = get_float_key(
"H5.CachePurgeLevel", 0.2);
213 if (get_mdcache_entries()) {
214 das_cache =
new ObjMemCache(get_mdcache_entries(), get_cache_purge_level());
215 dds_cache =
new ObjMemCache(get_mdcache_entries(), get_cache_purge_level());
216 dmr_cache =
new ObjMemCache(get_mdcache_entries(), get_cache_purge_level());
220 _usecf = check_beskeys(
"H5.EnableCF");
223 _pass_fileid = check_beskeys(
"H5.EnablePassFileID");
224 _disable_structmeta = check_beskeys(
"H5.DisableStructMetaAttr");
225 _disable_ecsmeta = check_beskeys(
"H5.DisableECSMetaAttr");
226 _keep_var_leading_underscore = check_beskeys(
"H5.KeepVarLeadingUnderscore");
227 _check_name_clashing = check_beskeys(
"H5.EnableCheckNameClashing");
228 _add_path_attrs = check_beskeys(
"H5.EnableAddPathAttrs");
229 _drop_long_string = check_beskeys(
"H5.EnableDropLongString");
230 _fillvalue_check = check_beskeys(
"H5.EnableFillValueCheck");
231 _check_ignore_obj = check_beskeys(
"H5.CheckIgnoreObj");
232 _flatten_coor_attr = check_beskeys(
"H5.ForceFlattenNDCoorAttr");
233 _default_handle_dimension = check_beskeys(
"H5.DefaultHandleDimension");
235 _use_disk_cache = check_beskeys(
"H5.EnableDiskDataCache");
236 _disk_cache_dir = get_beskeys(
"H5.DiskCacheDataPath");
237 _disk_cachefile_prefix = get_beskeys(
"H5.DiskCacheFilePrefix");
238 _disk_cache_size = get_ulong_key(
"H5.DiskCacheSize",0);
240 _disk_cache_comp_data = check_beskeys(
"H5.DiskCacheComp");
241 _disk_cache_float_only_comp_data = check_beskeys(
"H5.DiskCacheFloatOnlyComp");
242 _disk_cache_comp_threshold = get_float_key(
"H5.DiskCacheCompThreshold",1.0);
243 _disk_cache_var_size = 1024*get_uint_key(
"H5.DiskCacheCompVarSize",0);
245 _use_disk_meta_cache = check_beskeys(
"H5.EnableDiskMetaDataCache");
246 _use_disk_dds_cache = check_beskeys(
"H5.EnableDiskDDSCache");
247 _disk_meta_cache_path = get_beskeys(
"H5.DiskMetaDataCachePath");
249 _use_latlon_disk_cache = check_beskeys(
"H5.EnableEOSGeoCacheFile");
250 _latlon_disk_cache_size = get_uint_key(
"H5.Cache.latlon.size",0);
251 _latlon_disk_cache_dir = get_beskeys(
"H5.Cache.latlon.path");
252 _latlon_disk_cachefile_prefix= get_beskeys(
"H5.Cache.latlon.prefix");
255 if(get_lrdcache_entries()) {
256 lrdata_mem_cache =
new ObjMemCache(get_lrdcache_entries(), get_cache_purge_level());
257 if(
true == check_beskeys(
"H5.LargeDataMemCacheConfig")) {
258 _common_cache_dirs =obtain_lrd_common_cache_dirs();
260 if(
false == _common_cache_dirs)
261 cerr<<
"No specific cache info"<<endl;
266 if(get_srdcache_entries()) {
268 BESDEBUG(HDF5_NAME,
"Generate memory cache for smaller coordinate variables" << endl);
269 srdata_mem_cache =
new ObjMemCache(get_srdcache_entries(),get_cache_purge_level());
273 if(_disk_cache_comp_data ==
true && _use_disk_cache ==
true) {
274 if(_disk_cache_comp_threshold < 1.0) {
276 ss<< _disk_cache_comp_threshold;
277 string _comp_threshold_str(ss.str());
278 string invalid_comp_threshold =
"The Compression Threshold is the total size of the variable array";
279 invalid_comp_threshold+=
" divided by the storage size of compressed array. It should always be >1";
280 invalid_comp_threshold+=
" The current threhold set at h5.conf is ";
281 invalid_comp_threshold+=_comp_threshold_str;
282 invalid_comp_threshold+=
" . Go back to h5.conf and change the H5.DiskCacheCompThreshold to a >1.0 number.";
286 _stp_east_filename = get_beskeys(
"H5.STPEastFileName");
287 _stp_north_filename = get_beskeys(
"H5.STPNorthFileName");
291 BESDEBUG(HDF5_NAME,
"Exiting HDF5RequestHandler::HDF5RequestHandler" << endl);
294 HDF5RequestHandler::~HDF5RequestHandler()
300 delete lrdata_mem_cache;
301 delete srdata_mem_cache;
310 hid_t cf_fileid = -1;
319 BESDASResponse *bdas = dynamic_cast < BESDASResponse * >(response) ;
325 DAS *das = bdas->get_das();
328 DAS *cached_das_ptr = 0;
329 bool use_das_cache =
false;
331 cached_das_ptr = static_cast<DAS*>(das_cache->
get(filename));
333 use_das_cache =
true;
335 if (
true == use_das_cache) {
338 BESDEBUG(HDF5_NAME,
"DAS Cached hit for : " << filename << endl);
339 *das = *cached_das_ptr;
343 bool das_from_dc =
false;
344 string das_cache_fname;
347 if(_use_disk_meta_cache ==
true) {
349 string base_filename = HDF5CFUtil::obtain_string_after_lastslash(filename);
350 das_cache_fname = _disk_meta_cache_path+
"/" +base_filename+
"_das";
352 if(access(das_cache_fname.c_str(),F_OK) !=-1)
358 if(
true == das_from_dc) {
359 read_das_from_disk_cache(das_cache_fname,das);
364 BESDEBUG(HDF5_NAME,
"HDF5 DAS reading DAS from the disk cache. For memory cache, DAS added to the cache for : " << filename << endl);
365 das_cache->
add(
new DAS(*das), filename);
370 H5Eset_auto2(H5E_DEFAULT,NULL,NULL);
371 if (
true == _usecf) {
373 cf_fileid = H5Fopen(filename.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
375 string invalid_file_msg=
"Could not open this HDF5 file ";
376 invalid_file_msg +=filename;
377 invalid_file_msg +=
". It is very possible that this file is not an HDF5 file ";
378 invalid_file_msg +=
" but with the .h5/.HDF5 suffix. Please check with the data";
379 invalid_file_msg +=
" distributor.";
383 if(HDF5RequestHandler::get_dmr_64bit_int()!=NULL)
384 HDF5RequestHandler::set_dmr_64bit_int(NULL);
385 read_cfdas( *das,filename,cf_fileid);
391 string invalid_file_msg=
"Could not open this HDF5 file ";
392 invalid_file_msg +=filename;
393 invalid_file_msg +=
". It is very possible that this file is not an HDF5 file ";
394 invalid_file_msg +=
" but with the .h5/.HDF5 suffix. Please check with the data";
395 invalid_file_msg +=
" distributor.";
405 Ancillary::read_ancillary_das( *das, filename ) ;
409 AttrTable* top_table = das->get_top_level_attributes();
410 get_attr_contents(top_table);
413 AttrTable::Attr_iter start_aiter=das->var_begin();
414 AttrTable::Attr_iter it = start_aiter;
415 AttrTable::Attr_iter end_aiter = das->var_end();
416 while(it != end_aiter) {
417 AttrTable* temp_table = das->get_table(it);
419 cerr<<
"var_begin"<<endl;
420 temp_table->print(cerr);
428 BESDEBUG(HDF5_NAME,
"DAS added to the cache for : " << filename << endl);
429 das_cache->
add(
new DAS(*das), filename);
434 if(das_cache_fname!=
"") {
435 BESDEBUG(HDF5_NAME,
"HDF5 Build DAS: Write DAS to disk cache " << das_cache_fname << endl);
436 write_das_to_disk_cache(das_cache_fname,das);
443 catch(InternalErr & e) {
447 throw BESDapError(e.get_error_message(),
true, e.get_error_code(),
454 throw BESDapError(e.get_error_message(),
false, e.get_error_code(),
461 string s =
"unknown exception caught building HDF5 DAS";
471 void HDF5RequestHandler::get_dds_with_attributes(
BESDDSResponse*bdds,
BESDataDDSResponse*data_bdds,
const string &container_name,
const string& filename,
const string &dds_cache_fname,
const string &das_cache_fname,
bool dds_from_dc,
bool das_from_dc,
bool build_data)
474 if(
true == build_data)
475 dds = data_bdds->get_dds();
480 hid_t cf_fileid = -1;
485 DDS* cached_dds_ptr = 0;
486 bool use_dds_cache =
false;
488 cached_dds_ptr = static_cast<DDS*>(dds_cache->
get(filename));
490 use_dds_cache =
true;
491 if (
true == use_dds_cache) {
494 BESDEBUG(HDF5_NAME,
"DDS Metadata Cached hit for : " << filename << endl);
495 *dds = *cached_dds_ptr;
497 else if (
true ==dds_from_dc) {
498 read_dds_from_disk_cache(bdds,data_bdds,build_data,container_name,filename,dds_cache_fname,das_cache_fname,-1,das_from_dc);
501 BESDEBUG(HDF5_NAME,
"Build DDS from the HDF5 file. " << filename << endl);
502 H5Eset_auto2(H5E_DEFAULT,NULL,NULL);
503 dds->filename(filename);
508 cf_fileid = H5Fopen(filename.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
510 string invalid_file_msg=
"Could not open this HDF5 file ";
511 invalid_file_msg +=filename;
512 invalid_file_msg +=
". It is very possible that this file is not an HDF5 file ";
513 invalid_file_msg +=
" but with the .h5/.HDF5 suffix. Please check with the data";
514 invalid_file_msg +=
" distributor.";
519 if(HDF5RequestHandler::get_dmr_64bit_int() != NULL)
520 HDF5RequestHandler::set_dmr_64bit_int(NULL);
521 read_cfdds(*dds,filename,cf_fileid);
527 string invalid_file_msg=
"Could not open this HDF5 file ";
528 invalid_file_msg +=filename;
529 invalid_file_msg +=
". It is very possible that this file is not an HDF5 file ";
530 invalid_file_msg +=
" but with the .h5/.HDF5 suffix. Please check with the data";
531 invalid_file_msg +=
" distributor.";
535 depth_first(fileid, (
char*)
"/", *dds, filename.c_str());
539 if (!dds->check_semantics()) {
541 throw InternalErr(__FILE__, __LINE__,
542 "DDS check_semantics() failed. This can happen when duplicate variable names are defined. ");
545 Ancillary::read_ancillary_dds( *dds, filename ) ;
548 if(dds_cache_fname!=
"" && dds_from_dc ==
false)
549 write_dds_to_disk_cache(dds_cache_fname,dds);
558 add_das_to_dds(dds,container_name,filename,das_cache_fname,h5_fd,das_from_dc);
564 BESDEBUG(HDF5_NAME,
"DDS added to the cache for : " << filename << endl);
565 dds_cache->
add(
new DDS(*dds), filename);
576 catch(InternalErr & e) {
584 throw BESDapError(e.get_error_message(),
true, e.get_error_code(),
594 throw BESDapError(e.get_error_message(),
false, e.get_error_code(),
604 string s =
"unknown exception caught building HDF5 DDS";
613 void HDF5RequestHandler::get_dds_with_attributes(
const string &filename,
const string &container_name, DDS*dds) {
617 hid_t cf_fileid = -1;
622 DDS* cached_dds_ptr = 0;
623 if (dds_cache && (cached_dds_ptr = static_cast<DDS*>(dds_cache->
get(filename)))) {
626 BESDEBUG(HDF5_NAME,
"DDS Cached hit for : " << filename << endl);
627 *dds = *cached_dds_ptr;
632 H5Eset_auto2(H5E_DEFAULT,NULL,NULL);
633 if (!container_name.empty())
634 dds->container_name(container_name);
635 dds->filename(filename);
641 string base_filename = HDF5CFUtil::obtain_string_after_lastslash(filename);
642 string dds_filename =
"/tmp/"+base_filename+
"_dds";
643 FILE *dds_file = fopen(dds_filename.c_str(),
"r");
644 cerr<<
"before parsing "<<endl;
646 DDS tdds(&tf,name_path(filename),
"3.2");
647 tdds.filename(filename);
649 tdds.parse(dds_file);
651 cache_dds =
new DDS(tdds);
657 cerr<<
"after parsing "<<endl;
666 cf_fileid = H5Fopen(filename.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
668 string invalid_file_msg=
"Could not open this HDF5 file ";
669 invalid_file_msg +=filename;
670 invalid_file_msg +=
". It is very possible that this file is not an HDF5 file ";
671 invalid_file_msg +=
" but with the .h5/.HDF5 suffix. Please check with the data";
672 invalid_file_msg +=
" distributor.";
676 read_cfdds(*dds,filename,cf_fileid);
679 string base_filename = HDF5CFUtil::obtain_string_after_lastslash(filename);
680 string dds_filename =
"/tmp/"+base_filename+
"_dds";
681 FILE *dds_file = fopen(dds_filename.c_str(),
"w");
682 dds->print(dds_file);
690 string invalid_file_msg=
"Could not open this HDF5 file ";
691 invalid_file_msg +=filename;
692 invalid_file_msg +=
". It is very possible that this file is not an HDF5 file ";
693 invalid_file_msg +=
" but with the .h5/.HDF5 suffix. Please check with the data";
694 invalid_file_msg +=
" distributor.";
698 depth_first(fileid, (
char*)
"/", *dds, filename.c_str());
704 if (!dds->check_semantics()) {
706 throw InternalErr(__FILE__, __LINE__,
707 "DDS check_semantics() failed. This can happen when duplicate variable names are defined. ");
710 Ancillary::read_ancillary_dds( *dds, filename ) ;
716 if (das_cache && (das = static_cast<DAS*>(das_cache->
get(filename)))) {
717 BESDEBUG(HDF5_NAME,
"DAS Cached hit for : " << filename << endl);
718 dds->transfer_attributes(das);
725 if (!container_name.empty())
726 das->container_name(container_name);
728 if (
true == _usecf) {
731 read_cfdas( *das,filename,cf_fileid);
744 Ancillary::read_ancillary_das( *das, filename ) ;
746 dds->transfer_attributes(das);
752 BESDEBUG(HDF5_NAME,
"DAS added to the cache for : " << filename << endl);
754 das_cache->
add(das, filename);
763 BESDEBUG(HDF5_NAME,
"DDS added to the cache for : " << filename << endl);
764 dds_cache->
add(
new DDS(*dds), filename);
772 catch(InternalErr & e) {
780 throw BESDapError(e.get_error_message(),
true, e.get_error_code(),
790 throw BESDapError(e.get_error_message(),
false, e.get_error_code(),
800 string s =
"unknown exception caught building HDF5 DDS";
816 BESDDSResponse *bdds = dynamic_cast < BESDDSResponse * >(response);
823 bool dds_from_dc =
false;
824 bool das_from_dc =
false;
825 bool build_data =
false;
826 string dds_cache_fname;
827 string das_cache_fname;
829 if(_use_disk_meta_cache ==
true) {
831 string base_filename = HDF5CFUtil::obtain_string_after_lastslash(filename);
834 if(_use_disk_dds_cache ==
true) {
835 dds_cache_fname = _disk_meta_cache_path+
"/" +base_filename+
"_dds";
836 if(access(dds_cache_fname.c_str(),F_OK) !=-1)
840 das_cache_fname = _disk_meta_cache_path+
"/" +base_filename+
"_das";
842 if(access(das_cache_fname.c_str(),F_OK) !=-1)
847 get_dds_with_attributes(bdds, NULL,container_name,filename, dds_cache_fname,das_cache_fname,dds_from_dc,das_from_dc,build_data);
851 string base_filename = HDF5CFUtil::obtain_string_after_lastslash(filename);
852 string dds_filename =
"/tmp/"+base_filename+
"_dds";
855 DDS tdds(&tf,name_path(filename),
"3.2");
856 tdds.filename(filename);
859 FILE *dds_file = fopen(dds_filename.c_str(),
"r");
860 tdds.parse(dds_file);
862 DDS* cache_dds =
new DDS(tdds);
873 catch(InternalErr & e) {
875 throw BESDapError(e.get_error_message(),
true, e.get_error_code(),
880 throw BESDapError(e.get_error_message(),
false, e.get_error_code(),
885 string s =
"unknown exception caught building HDF5 DDS";
897 if(
true == _pass_fileid)
898 return hdf5_build_data_with_IDs(dhi);
912 bool dds_from_dc =
false;
913 bool das_from_dc =
false;
914 bool build_data =
true;
915 string dds_cache_fname;
916 string das_cache_fname;
919 if(_use_disk_meta_cache ==
true) {
921 string base_filename = HDF5CFUtil::obtain_string_after_lastslash(filename);
922 das_cache_fname = _disk_meta_cache_path+
"/" +base_filename+
"_das";
924 if(access(das_cache_fname.c_str(),F_OK) !=-1)
929 get_dds_with_attributes(NULL,bdds, container_name,filename, dds_cache_fname,das_cache_fname,dds_from_dc,das_from_dc,build_data);
935 catch(InternalErr & e) {
937 throw BESDapError(e.get_error_message(),
true, e.get_error_code(),
942 throw BESDapError(e.get_error_message(),
false, e.get_error_code(),
947 string s =
"unknown exception caught building HDF5 DDS";
958 BESDEBUG(
"h5",
"Building DataDDS by passing file IDs. "<<endl);
959 hid_t cf_fileid = -1;
963 H5Eset_auto2(H5E_DEFAULT,NULL,NULL);
964 cf_fileid = H5Fopen(filename.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
966 string invalid_file_msg=
"Could not open this HDF5 file ";
967 invalid_file_msg +=filename;
968 invalid_file_msg +=
". It is very possible that this file is not an HDF5 file ";
969 invalid_file_msg +=
" but with the .h5/.HDF5 suffix. Please check with the data";
970 invalid_file_msg +=
" distributor.";
984 delete bdds->get_dds();
988 hdds->setHDF5Dataset(cf_fileid);
990 read_cfdds( *hdds,filename,cf_fileid);
992 if (!hdds->check_semantics()) {
994 throw InternalErr(__FILE__, __LINE__,
995 "DDS check_semantics() failed. This can happen when duplicate variable names are defined.");
998 Ancillary::read_ancillary_dds( *hdds, filename ) ;
1000 DAS *das =
new DAS ;
1003 read_cfdas( *das,filename,cf_fileid);
1004 Ancillary::read_ancillary_das( *das, filename ) ;
1006 hdds->transfer_attributes(das);
1012 catch(InternalErr & e) {
1014 H5Fclose(cf_fileid);
1015 throw BESDapError(e.get_error_message(),
true, e.get_error_code(),
1016 __FILE__, __LINE__);
1020 H5Fclose(cf_fileid);
1021 throw BESDapError(e.get_error_message(),
false, e.get_error_code(),
1022 __FILE__, __LINE__);
1026 H5Fclose(cf_fileid);
1027 string s =
"unknown exception caught building HDF5 DataDDS";
1041 BESDMRResponse &bes_dmr = dynamic_cast<BESDMRResponse &>(*response);
1045 DMR *dmr = bes_dmr.get_dmr();
1049 hid_t cf_fileid = -1;
1053 DMR* cached_dmr_ptr = 0;
1054 bool use_dmr_cache =
false;
1056 cached_dmr_ptr = static_cast<DMR*>(dmr_cache->
get(filename));
1058 use_dmr_cache =
true;
1059 if (
true == use_dmr_cache) {
1061 BESDEBUG(HDF5_NAME,
"DMR Cached hit for : " << filename << endl);
1062 *dmr = *cached_dmr_ptr;
1066 H5Eset_auto2(H5E_DEFAULT,NULL,NULL);
1067 D4BaseTypeFactory MyD4TypeFactory;
1068 dmr->set_factory(&MyD4TypeFactory);
1072 if(
true == _pass_fileid)
1073 return hdf5_build_dmr_with_IDs(dhi);
1075 cf_fileid = H5Fopen(filename.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
1077 string invalid_file_msg=
"Could not open this HDF5 file ";
1078 invalid_file_msg +=filename;
1079 invalid_file_msg +=
". It is very possible that this file is not an HDF5 file ";
1080 invalid_file_msg +=
" but with the .h5/.HDF5 suffix. Please check with the data";
1081 invalid_file_msg +=
" distributor.";
1085 BaseTypeFactory factory;
1086 DDS dds(&factory, name_path(filename),
"3.2");
1087 dds.filename(filename);
1093 HDF5RequestHandler::set_dmr_64bit_int(dmr);
1094 read_cfdds( dds,filename,cf_fileid);
1095 if (!dds.check_semantics()) {
1097 throw InternalErr(__FILE__, __LINE__,
1098 "DDS check_semantics() failed. This can happen when duplicate variable names are defined.");
1101 read_cfdas(das,filename,cf_fileid);
1102 Ancillary::read_ancillary_das( das, filename ) ;
1104 dds.transfer_attributes(&das);
1108 H5Fclose(cf_fileid);
1110 dmr->build_using_dds(dds);
1118 string invalid_file_msg=
"Could not open this HDF5 file ";
1119 invalid_file_msg +=filename;
1120 invalid_file_msg +=
". It is very possible that this file is not an HDF5 file ";
1121 invalid_file_msg +=
" but with the .h5/.HDF5 suffix. Please check with the data";
1122 invalid_file_msg +=
" distributor.";
1126 bool use_dimscale =
false;
1127 if(
true == _default_handle_dimension)
1128 use_dimscale = check_dimscale(fileid);
1129 dmr->set_name(name_path(filename));
1130 dmr->set_filename(name_path(filename));
1132 D4Group* root_grp = dmr->root();
1133 breadth_first(fileid,(
char*)
"/",root_grp,filename.c_str(),use_dimscale);
1136 if(
true == use_dimscale)
1138 breadth_first(fileid,(
char*)
"/",root_grp,filename.c_str(),
true);
1140 depth_first(fileid,(
char*)
"/",root_grp,filename.c_str());
1151 BESDEBUG(HDF5_NAME,
"DMR added to the cache for : " << filename << endl);
1152 dmr_cache->
add(
new DMR(*dmr), filename);
1157 catch(InternalErr & e) {
1160 H5Fclose(cf_fileid);
1164 throw BESDapError(e.get_error_message(),
true, e.get_error_code(),
1165 __FILE__, __LINE__);
1170 H5Fclose(cf_fileid);
1173 throw BESDapError(e.get_error_message(),
false, e.get_error_code(),
1174 __FILE__, __LINE__);
1179 H5Fclose(cf_fileid);
1182 string s =
"unknown exception caught building HDF5 DMR";
1195 dmr->set_factory(0);
1204 BESDEBUG(
"h5",
"Building DMR with passing file IDs. "<<endl);
1206 hid_t cf_fileid = -1;
1208 H5Eset_auto2(H5E_DEFAULT,NULL,NULL);
1209 cf_fileid = H5Fopen(filename.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
1211 string invalid_file_msg=
"Could not open this HDF5 file ";
1212 invalid_file_msg +=filename;
1213 invalid_file_msg +=
". It is very possible that this file is not an HDF5 file ";
1214 invalid_file_msg +=
" but with the .h5/.HDF5 suffix. Please check with the data";
1215 invalid_file_msg +=
" distributor.";
1219 BaseTypeFactory factory;
1220 DDS dds(&factory, name_path(filename),
"3.2");
1221 dds.filename(filename);
1229 read_cfdds( dds,filename,cf_fileid);
1231 if (!dds.check_semantics()) {
1233 throw InternalErr(__FILE__, __LINE__,
1234 "DDS check_semantics() failed. This can happen when duplicate variable names are defined.");
1237 Ancillary::read_ancillary_dds( dds, filename ) ;
1240 read_cfdas(das,filename,cf_fileid);
1242 Ancillary::read_ancillary_das( das, filename ) ;
1244 dds.transfer_attributes(&das);
1251 catch(InternalErr & e) {
1254 H5Fclose(cf_fileid);
1256 throw BESDapError(e.get_error_message(),
true, e.get_error_code(),
1257 __FILE__, __LINE__);
1262 H5Fclose(cf_fileid);
1264 throw BESDapError(e.get_error_message(),
false, e.get_error_code(),
1265 __FILE__, __LINE__);
1270 H5Fclose(cf_fileid);
1272 string s =
"unknown exception caught building HDF5 DataDDS";
1279 BESDMRResponse &bes_dmr = dynamic_cast<BESDMRResponse &>(*response);
1286 DMR *dmr = bes_dmr.get_dmr();
1287 D4BaseTypeFactory MyD4TypeFactory;
1288 dmr->set_factory(&MyD4TypeFactory);
1289 dmr->build_using_dds(dds);
1292 hdf5_dmr->setHDF5Dataset(cf_fileid);
1294 bes_dmr.set_dmr(hdf5_dmr);
1303 hdf5_dmr->set_factory(0);
1311 BESInfo *info = dynamic_cast<BESInfo *>(response);
1315 string add_info=
"Just for Test";
1317 map<string,string> attrs ;
1318 attrs[
"name"] = MODULE_NAME ;
1319 attrs[
"version"] = MODULE_VERSION ;
1320 list<string> services ;
1321 BESServiceRegistry::TheRegistry()->
services_handled( HDF5_NAME, services );
1322 if( services.size() > 0 )
1325 attrs[
"handles"] = handles ;
1327 info->begin_tag(
"module", &attrs ) ;
1328 info->end_tag(
"module" ) ;
1337 BESVersionInfo *info = dynamic_cast < BESVersionInfo * >(response);
1341 info->add_module( MODULE_NAME, MODULE_VERSION ) ;
1347 bool HDF5RequestHandler::obtain_lrd_common_cache_dirs()
1349 string lrd_config_fpath;
1350 string lrd_config_fname;
1353 lrd_config_fpath = get_beskeys(
"H5.DataCachePath");
1356 lrd_config_fname = get_beskeys(
"H5.LargeDataMemCacheFileName");
1359 if(lrd_config_fpath==
"" || lrd_config_fname==
"")
1366 string mcache_config_fname = lrd_config_fpath+
"/"+lrd_config_fname;
1370 ifstream mcache_config_file(mcache_config_fname.c_str());
1373 if(mcache_config_file.is_open()==
false){
1374 BESDEBUG(HDF5_NAME,
"The large data memory cache configure file "<<mcache_config_fname );
1375 BESDEBUG(HDF5_NAME,
" cannot be opened."<<endl);
1380 while(getline(mcache_config_file,temp_line)) {
1383 if(temp_line.size()>1 && temp_line.at(1)==
' ') {
1385 string subline = temp_line.substr(2);
1386 vector<string> temp_name_list;
1389 if(temp_line.at(0)==
'1') {
1390 HDF5CFUtil::Split_helper(temp_name_list,subline,sep);
1392 lrd_cache_dir_list.insert(lrd_cache_dir_list.end(),temp_name_list.begin(),temp_name_list.end());
1395 else if(temp_line.at(0)==
'0'){
1396 HDF5CFUtil::Split_helper(temp_name_list,subline,sep);
1398 lrd_non_cache_dir_list.insert(lrd_non_cache_dir_list.end(),temp_name_list.begin(),temp_name_list.end());
1401 else if(temp_line.at(0)==
'2') {
1407 for(
unsigned int i = 0; i<subline.size();i++){
1408 if(subline[i]==
'"') {
1409 dq_pos.push_back(i);
1411 else if(subline[i]==
'\'')
1412 sq_pos.push_back(i);
1414 if(dq_pos.size()==0 && sq_pos.size()==0)
1415 HDF5CFUtil::Split_helper(temp_name_list,subline,sep);
1416 else if((dq_pos.size()!=0) &&(dq_pos.size()%2==0)&& sq_pos.size()==0) {
1417 unsigned int dq_index= 0;
1418 while(dq_index < dq_pos.size()){
1419 if(dq_pos[dq_index+1]>(dq_pos[dq_index]+1)) {
1420 temp_name_list.push_back
1421 (subline.substr(dq_pos[dq_index]+1,dq_pos[dq_index+1]-dq_pos[dq_index]-1));
1423 dq_index = dq_index + 2;
1426 else if((sq_pos.size()!=0) &&(sq_pos.size()%2==0)&& dq_pos.size()==0) {
1427 unsigned int sq_index= 0;
1428 while(sq_index < sq_pos.size()){
1429 if(sq_pos[sq_index+1]>(sq_pos[sq_index]+1)) {
1430 temp_name_list.push_back
1431 (subline.substr(sq_pos[sq_index]+1,sq_pos[sq_index+1]-sq_pos[sq_index]-1));
1433 sq_index = sq_index+2;
1437 lrd_var_cache_file_list.insert(lrd_var_cache_file_list.end(),temp_name_list.begin(),temp_name_list.end());
1445 for(
int i =0; i<lrd_cache_dir_list.size();i++)
1446 cerr<<
"lrd cache list is "<<lrd_cache_dir_list[i] <<endl;
1447 for(
int i =0; i<lrd_non_cache_dir_list.size();i++)
1448 cerr<<
"lrd non cache list is "<<lrd_non_cache_dir_list[i] <<endl;
1449 for(
int i =0; i<lrd_var_cache_file_list.size();i++)
1450 cerr<<
"lrd var cache file list is "<<lrd_var_cache_file_list[i] <<endl;
1454 mcache_config_file.close();
1455 if(lrd_cache_dir_list.size()==0 && lrd_non_cache_dir_list.size()==0 && lrd_var_cache_file_list.size()==0)
1462 bool HDF5RequestHandler::read_das_from_disk_cache(
const string & cache_filename,DAS *das_ptr) {
1464 BESDEBUG(HDF5_NAME,
"Coming to read_das_from_disk_cache() " << cache_filename << endl);
1465 bool ret_value =
true;
1466 FILE *md_file = NULL;
1467 md_file = fopen(cache_filename.c_str(),
"rb");
1469 if(NULL == md_file) {
1470 string bes_error =
"An error occurred trying to open a metadata cache file " + cache_filename;
1475 int fd_md = fileno(md_file);
1477 l_md = lock(F_RDLCK);
1480 if(fcntl(fd_md,F_SETLKW,l_md) == -1) {
1483 oss <<
"cache process: " << l_md->l_pid <<
" triggered a locking error: " << get_errno();
1490 if(stat(cache_filename.c_str(),&sb) != 0) {
1491 string bes_error =
"An error occurred trying to stat a metadata cache file size " + cache_filename;
1497 size_t bytes_expected_read=(size_t)sb.st_size;
1498 BESDEBUG(HDF5_NAME,
"DAS Disk cache file size is " << bytes_expected_read << endl);
1501 buf.resize(bytes_expected_read);
1502 size_t bytes_to_read =fread((
void*)&buf[0],1,bytes_expected_read,md_file);
1503 if(bytes_to_read != bytes_expected_read)
1504 throw InternalErr(__FILE__,__LINE__,
"Fail to read the data from the das cache file.");
1506 char* temp_pointer =&buf[0];
1508 AttrTable*at = NULL;
1511 temp_pointer = get_attr_info_from_dc(temp_pointer,das_ptr,at);
1517 if(fcntl(fd_md,F_SETLK,lock(F_UNLCK)) == -1) {
1519 throw BESInternalError(
"An error occurred trying to unlock the file" + get_errno(), __FILE__, __LINE__);
1523 throw InternalErr(__FILE__,__LINE__,
"Fail to parse a das cache file.");
1527 if(fcntl(fd_md,F_SETLK,lock(F_UNLCK)) == -1) {
1529 throw BESInternalError(
"An error occurred trying to unlock the file" + get_errno(), __FILE__, __LINE__);
1538 bool HDF5RequestHandler::write_dds_to_disk_cache(
const string& dds_cache_fname,DDS *dds_ptr) {
1540 BESDEBUG(HDF5_NAME,
"Write DDS to disk cache " << dds_cache_fname << endl);
1541 FILE *dds_file = fopen(dds_cache_fname.c_str(),
"w");
1543 if(NULL == dds_file) {
1544 string bes_error =
"An error occurred trying to open a metadata cache file " + dds_cache_fname;
1549 int fd_md = fileno(dds_file);
1551 l_md = lock(F_WRLCK);
1554 if(fcntl(fd_md,F_SETLKW,l_md) == -1) {
1557 oss <<
"cache process: " << l_md->l_pid <<
" triggered a locking error: " << get_errno();
1562 dds_ptr->print(dds_file);
1565 if(fcntl(fd_md,F_SETLK,lock(F_UNLCK)) == -1) {
1567 throw BESInternalError(
"An error occurred trying to unlock the file" + get_errno(), __FILE__, __LINE__);
1571 throw InternalErr(__FILE__,__LINE__,
"Fail to parse a dds cache file.");
1574 if(fcntl(fd_md,F_SETLK,lock(F_UNLCK)) == -1) {
1576 throw BESInternalError(
"An error occurred trying to unlock the file" + get_errno(), __FILE__, __LINE__);
1586 bool HDF5RequestHandler::write_das_to_disk_cache(
const string & das_cache_fname, DAS *das_ptr) {
1588 BESDEBUG(HDF5_NAME,
"Write DAS to disk cache " << das_cache_fname << endl);
1589 FILE *das_file = fopen(das_cache_fname.c_str(),
"wb");
1590 if(NULL == das_file) {
1591 string bes_error =
"An error occurred trying to open a metadata cache file " + das_cache_fname;
1595 int fd_md = fileno(das_file);
1597 l_md = lock(F_WRLCK);
1600 if(fcntl(fd_md,F_SETLKW,l_md) == -1) {
1603 oss <<
"cache process: " << l_md->l_pid <<
" triggered a locking error: " << get_errno();
1608 write_das_to_file(das_ptr,das_file);
1611 if(fcntl(fd_md,F_SETLK,lock(F_UNLCK)) == -1) {
1613 throw BESInternalError(
"An error occurred trying to unlock the file" + get_errno(), __FILE__, __LINE__);
1617 throw InternalErr(__FILE__,__LINE__,
"Fail to parse a dds cache file.");
1620 if(fcntl(fd_md,F_SETLK,lock(F_UNLCK)) == -1) {
1622 throw BESInternalError(
"An error occurred trying to unlock the file" + get_errno(), __FILE__, __LINE__);
1634 void write_das_to_file(DAS*das_ptr,FILE* das_file) {
1637 uint8_t category_flag = 2;
1638 AttrTable* top_table = das_ptr->get_top_level_attributes();
1639 write_das_table_to_file(top_table,das_file);
1642 fwrite((
const void*)&category_flag,1,1,das_file);
1648 void write_das_table_to_file(AttrTable*temp_table,FILE* das_file) {
1650 if(temp_table !=NULL) {
1653 uint8_t category_flag = 2;
1656 AttrTable::Attr_iter top_startit = temp_table->attr_begin();
1657 AttrTable::Attr_iter top_endit = temp_table->attr_end();
1658 AttrTable::Attr_iter top_it = top_startit;
1659 while(top_it !=top_endit) {
1660 AttrType atype = temp_table->get_attr_type(top_it);
1661 if(atype == Attr_unknown)
1662 throw InternalErr(__FILE__,__LINE__,
"Unsupported DAS Attribute type");
1663 else if(atype!=Attr_container) {
1664 BESDEBUG(HDF5_NAME,
"DAS to the disk cache, attr name is: "
1665 << temp_table->get_name(top_it) << endl);
1666 BESDEBUG(HDF5_NAME,
"DAS to the disk cache, attr type is: "
1667 << temp_table->get_type(top_it) << endl);
1676 write_das_attr_info(temp_table,temp_table->get_name(top_it),temp_table->get_type(top_it),das_file);
1679 BESDEBUG(HDF5_NAME,
"DAS to the disk cache, attr container name is: "
1680 << (*top_it)->name << endl);
1682 AttrTable* sub_table = temp_table->get_attr_table(top_it);
1683 write_container_name_to_file(sub_table->get_name(),das_file);
1684 write_das_table_to_file(sub_table,das_file);
1687 fwrite((
const void*)&category_flag,1,1,das_file);
1697 void write_container_name_to_file(
const string& cont_name,FILE *das_file) {
1700 uint8_t category_flag = 1;
1702 size_t bytes_to_write = cont_name.size()+
sizeof(size_t)+1;
1703 buf.resize(bytes_to_write);
1704 char*temp_pointer =&buf[0];
1705 memcpy((
void*)temp_pointer,(
void*)&category_flag,1);
1707 temp_pointer=copy_str(temp_pointer,cont_name);
1709 size_t bytes_to_be_written = fwrite((
const void*)&buf[0],1,bytes_to_write,das_file);
1710 if(bytes_to_be_written != bytes_to_write)
1711 throw InternalErr(__FILE__, __LINE__,
"Failed to write a DAS container name to a cache");
1717 void write_das_attr_info(AttrTable* dtp,
const string& attr_name,
const string & attr_type,FILE * das_file) {
1720 uint8_t category_flag = 0;
1722 unsigned int num_attr_elems = dtp->get_attr_num(attr_name);
1723 vector<string> attr_values;
1724 size_t total_attr_values_size = 0;
1725 for (
unsigned int i = 0; i <num_attr_elems;i++){
1726 attr_values.push_back((*(dtp->get_attr_vector(attr_name)))[i]);
1727 total_attr_values_size += attr_values[i].size();
1731 size_t bytes_to_write_attr = 1 + attr_name.size() + attr_type.size() + 2*
sizeof(size_t);
1737 bytes_to_write_attr +=
sizeof(
unsigned int) + num_attr_elems*
sizeof(
size_t)+total_attr_values_size;
1739 vector<char>attr_buf;
1740 attr_buf.resize(bytes_to_write_attr);
1741 char* temp_attrp =&attr_buf[0];
1744 memcpy((
void*)temp_attrp,(
void*)&category_flag,1);
1748 temp_attrp=copy_str(temp_attrp,attr_name);
1749 temp_attrp=copy_str(temp_attrp,attr_type);
1752 memcpy((
void*)temp_attrp,(
void*)&num_attr_elems,
sizeof(
unsigned int));
1753 temp_attrp+=
sizeof(
unsigned int);
1756 for (
unsigned int i = 0; i <num_attr_elems;i++)
1757 temp_attrp=copy_str(temp_attrp,(*(dtp->get_attr_vector(attr_name)))[i]);
1759 size_t bytes_to_be_written = fwrite((
const void*)&attr_buf[0],1,bytes_to_write_attr,das_file);
1760 if(bytes_to_be_written != bytes_to_write_attr)
1761 throw InternalErr(__FILE__, __LINE__,
"Failed to write a DAS attribute to a cache");
1769 bool build_data,
const string & container_name,
const string & h5_fname,
1770 const string & dds_cache_fname,
const string &das_cache_fname, hid_t h5_fd,
1774 BESDEBUG(HDF5_NAME,
"Read DDS from disk cache " << dds_cache_fname << endl);
1777 if(
true == build_data)
1778 dds = data_bdds->get_dds();
1784 DDS tdds(&tf,name_path(h5_fname),
"3.2");
1785 tdds.filename(h5_fname);
1787 FILE *dds_file = fopen(dds_cache_fname.c_str(),
"r");
1788 tdds.parse(dds_file);
1789 DDS* cache_dds =
new DDS(tdds);
1791 cerr<<
"before dds "<<endl;
1793 cerr<<
"after dds "<<endl;
1794 cerr<<
"before tdds "<<endl;
1795 cache_dds->dump(cerr);
1796 cerr<<
"after tdds "<<endl;
1801 Ancillary::read_ancillary_dds( *cache_dds, h5_fname ) ;
1803 add_das_to_dds(cache_dds,container_name,h5_fname,das_cache_fname,h5_fd,das_from_dc);
1804 if(
true == build_data)
1805 data_bdds->
set_dds(cache_dds);
1812 BESDEBUG(HDF5_NAME,
"Reading DDS from Disk Cache routine, For memory cache, DDS added to the cache for : " << h5_fname << endl);
1813 dds_cache->
add(
new DDS(*cache_dds), h5_fname);
1819 void HDF5RequestHandler::add_das_to_dds(DDS *dds,
const string &,
const string &filename,
1820 const string &das_cache_fname, hid_t h5_fd,
bool das_from_dc) {
1822 BESDEBUG(HDF5_NAME,
"Coming to add_das_to_dds() " << endl);
1826 bool use_das_cache =
false;
1828 das = static_cast<DAS*>(das_cache->
get(filename));
1830 use_das_cache =
true;
1832 if (
true == use_das_cache) {
1833 BESDEBUG(HDF5_NAME,
"DAS Cached hit for : " << filename << endl);
1834 dds->transfer_attributes(das);
1841 if (!container_name.empty())
1842 das->container_name(container_name);
1844 if(das_from_dc ==
true)
1845 read_das_from_disk_cache(das_cache_fname,das);
1848 bool h5_file_open =
true;
1850 h5_file_open =
false;
1851 if (
true == _usecf) {
1853 if(h5_file_open ==
false)
1854 h5_fd = H5Fopen(filename.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
1856 read_cfdas( *das,filename,h5_fd);
1857 if(h5_file_open ==
false)
1861 if(h5_file_open ==
false)
1865 if(h5_file_open ==
false)
1869 Ancillary::read_ancillary_das( *das, filename ) ;
1871 if(das_cache_fname!=
"" && das_from_dc ==
false)
1872 write_das_to_disk_cache(das_cache_fname,das);
1875 dds->transfer_attributes(das);
1879 BESDEBUG(HDF5_NAME,
"Reading DDS from Disk Cache routine, For memory cache, DAS added to the cache for : " << filename << endl);
1880 das_cache->
add(
new DAS(*das), filename);
1888 bool check_beskeys(
const string key) {
1892 const string dosettrue =
"true";
1893 const string dosetyes =
"yes";
1896 if(
true == found ) {
1898 if( dosettrue == doset || dosetyes == doset )
1907 static unsigned int get_uint_key(
const string &key,
unsigned int def_val)
1913 if (
true == found) {
1915 return atoi(doset.c_str());
1922 static unsigned long get_ulong_key(
const string &key,
unsigned long def_val)
1928 if (
true == found) {
1930 return atol(doset.c_str());
1936 static float get_float_key(
const string &key,
float def_val)
1942 if (
true == found) {
1943 return atof(doset.c_str());
1950 static string get_beskeys(
const string &key) {
1953 string ret_value =
"";
1961 char* copy_str(
char*temp_ptr,
const string & str) {
1963 size_t str_size=str.size();
1964 memcpy((
void*)temp_ptr,(
void*)&str_size,
sizeof(
size_t));
1965 temp_ptr+=
sizeof(size_t);
1966 vector<char>temp_vc2(str.begin(),str.end());
1967 memcpy((
void*)temp_ptr,(
void*)&temp_vc2[0],str.size());
1968 temp_ptr+=str.size();
1977 char* obtain_str(
char*temp_ptr,
string & str) {
1979 size_t oname_size = *((
size_t *)temp_ptr);
1980 temp_ptr = temp_ptr +
sizeof(size_t);
1982 for(
unsigned int i =0; i<oname_size; i++){
1983 oname.push_back(*temp_ptr);
1994 char* get_attr_info_from_dc(
char*temp_pointer,DAS *das,AttrTable *at_par) {
1999 flag = *((uint8_t*)(temp_pointer));
2000 BESDEBUG(HDF5_NAME,
"Build DAS from the disk cache file flag: "
2001 <<
" flag = 0, attribute; flag = 1, container; flag =2; end of container;"
2002 <<
" flag = 3; the initial value to get the attribute retrieval process started."
2003 <<
" The flag value is "
2004 << (
int)flag <<endl);
2008 string container_name;
2009 temp_pointer = obtain_str(temp_pointer,container_name);
2010 BESDEBUG(HDF5_NAME,
"DAS from the disk cache, container name is " << container_name << endl);
2013 AttrTable*temp_at_par = at_par;
2015 at_par = das->add_table(container_name,
new AttrTable);
2017 at_par = at_par->append_container(container_name);
2019 temp_pointer = get_attr_info_from_dc(temp_pointer,das,at_par);
2021 at_par = temp_at_par;
2024 else if(flag == 0) {
2027 throw BESInternalError(
"The AttrTable must exist for DAS attributes", __FILE__, __LINE__ ) ;
2031 temp_pointer = obtain_str(temp_pointer,attr_name);
2032 BESDEBUG(HDF5_NAME,
"DAS from the disk cache, attr name is: " << attr_name << endl);
2036 temp_pointer = obtain_str(temp_pointer,attr_type);
2037 BESDEBUG(HDF5_NAME,
"DAS from the disk cache, attr type is: " << attr_type << endl);
2040 unsigned int num_values = *((
unsigned int*)(temp_pointer));
2041 BESDEBUG(HDF5_NAME,
"DAS from the disk cache, number of attribute values is: " << num_values << endl);
2042 temp_pointer+=
sizeof(
unsigned int);
2044 vector <string> attr_values;
2046 for(
unsigned int i = 0; i<num_values; i++) {
2048 temp_pointer = obtain_str(temp_pointer,attr_value);
2049 attr_values.push_back(attr_value);
2050 BESDEBUG(HDF5_NAME,
"DAS from the disk cache, attribute value is: " << attr_value << endl);
2053 at_par->append_attr(attr_name,attr_type,&attr_values);
2057 return temp_pointer;
2062 void get_attr_contents(AttrTable*temp_table) {
2063 if(temp_table !=NULL) {
2064 AttrTable::Attr_iter top_startit = temp_table->attr_begin();
2065 AttrTable::Attr_iter top_endit = temp_table->attr_end();
2066 AttrTable::Attr_iter top_it = top_startit;
2067 while(top_it !=top_endit) {
2068 AttrType atype = temp_table->get_attr_type(top_it);
2069 if(atype == Attr_unknown)
2070 cerr<<
"unsupported DAS attributes" <<endl;
2071 else if(atype!=Attr_container) {
2073 cerr<<
"Attribute name is "<<temp_table->get_name(top_it)<<endl;
2074 cerr<<
"Attribute type is "<<temp_table->get_type(top_it)<<endl;
2075 unsigned int num_attrs = temp_table->get_attr_num(temp_table->get_name(top_it));
2076 cerr<<
"Attribute values are "<<endl;
2077 for (
unsigned int i = 0; i <num_attrs;i++)
2078 cerr<<(*(temp_table->get_attr_vector(temp_table->get_name(top_it))))[i]<<
" ";
2082 cerr<<
"Coming to the attribute container. "<<endl;
2083 cerr<<
"container name is "<<(*top_it)->name <<endl;
2084 AttrTable* sub_table = temp_table->get_attr_table(top_it);
2085 cerr<<
"container table name is "<<sub_table->get_name() <<endl;
2086 get_attr_contents(sub_table);