Skip to content

Commit d31a7f1

Browse files
Attribute Writing: Create Group if Missing
- check if dataset/group exists - create group if not exists
1 parent a047ab5 commit d31a7f1

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

src/ParallelDataCollector.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,9 @@ namespace splash
466466
if (ndims < 1u || ndims > DSP_DIM_MAX)
467467
throw DCException(getExceptionString("writeAttribute", "maximum dimension `ndims` is invalid"));
468468

469+
/* group_path: absolute path to the last inode
470+
* obj_name: last inode, can be a group or a dataset
471+
*/
469472
std::string group_path, obj_name;
470473
std::string dataNameInternal = "";
471474
if (dataName)
@@ -475,6 +478,16 @@ namespace splash
475478
DCParallelGroup group;
476479
if (dataName)
477480
{
481+
/* if the specified inode (obj_name) does not exist
482+
* (as dataset or group), create all missing groups along group_path
483+
* and even create an empty group for obj_name itself
484+
*
485+
* group_path + "/" + obj_name is the absolute path of dataName
486+
*/
487+
std::string pathAndName(group_path + "/" + obj_name);
488+
if(!DCParallelGroup::exists(handles.get(id), pathAndName))
489+
group.create(handles.get(id), pathAndName);
490+
478491
// attach attribute to the dataset or group
479492
group.open(handles.get(id), group_path);
480493
hid_t obj_id = H5Oopen(group.getHandle(), obj_name.c_str(), H5P_DEFAULT);

src/SerialDataCollector.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,9 @@ namespace splash
382382
if (ndims < 1u || ndims > DSP_DIM_MAX)
383383
throw DCException(getExceptionString("writeAttribute", "maximum dimension `ndims` is invalid"));
384384

385+
/* group_path: absolute path to the last inode
386+
* obj_name: last inode, can be a group or a dataset
387+
*/
385388
std::string group_path, obj_name;
386389
std::string dataNameInternal = "";
387390
if (dataName)
@@ -391,6 +394,16 @@ namespace splash
391394
DCGroup group;
392395
if (dataName)
393396
{
397+
/* if the specified inode (obj_name) does not exist
398+
* (as dataset or group), create all missing groups along group_path
399+
* and even create an empty group for obj_name itself
400+
*
401+
* group_path + "/" + obj_name is the absolute path of dataName
402+
*/
403+
std::string pathAndName(group_path + "/" + obj_name);
404+
if(!DCGroup::exists(handles.get(id), pathAndName))
405+
group.create(handles.get(id), pathAndName);
406+
394407
// attach attribute to the dataset or group
395408
group.open(handles.get(0), group_path);
396409

0 commit comments

Comments
 (0)