11
11
#include < nix/util/util.hpp>
12
12
#include < nix/DataArray.hpp>
13
13
#include " DataArrayHDF5.hpp"
14
+ #include " DataFrameHDF5.hpp"
14
15
15
16
16
17
using namespace std ;
@@ -71,10 +72,27 @@ FeatureHDF5::FeatureHDF5(const shared_ptr<IFile> &file, const shared_ptr<IBlock>
71
72
: EntityHDF5(file, group, id, time), block(block)
72
73
{
73
74
linkType (link_type);
74
- targetType (TargetType::DataArray);
75
75
// TODO: the line below currently throws an exception if the DataArray
76
76
// is not in block - to consider if we prefer copying it to the block
77
- this ->data (data.id ());
77
+ this ->data (data);
78
+ }
79
+
80
+
81
+ FeatureHDF5::FeatureHDF5 (const shared_ptr<IFile> &file, const shared_ptr<IBlock> &block, const H5Group &group,
82
+ const string &id, DataFrame data, LinkType link_type)
83
+ : FeatureHDF5(file, block, group, id, data, link_type, util::getTime())
84
+ {
85
+ }
86
+
87
+
88
+ FeatureHDF5::FeatureHDF5 (const shared_ptr<IFile> &file, const shared_ptr<IBlock> &block, const H5Group &group,
89
+ const string &id, DataFrame data, LinkType link_type, time_t time)
90
+ : EntityHDF5(file, group, id, time), block(block)
91
+ {
92
+ linkType (link_type);
93
+ // TODO: the line below currently throws an exception if the DataArray
94
+ // is not in block - to consider if we prefer copying it to the block
95
+ this ->data (data);
78
96
}
79
97
80
98
@@ -91,8 +109,8 @@ void FeatureHDF5::targetType(TargetType ttype) {
91
109
}
92
110
93
111
94
- void FeatureHDF5::data (const std::string &name_or_id ) {
95
- std::shared_ptr<IDataArray> ida = block->getEntity <IDataArray>(name_or_id );
112
+ void FeatureHDF5::data (const DataArray &data ) {
113
+ std::shared_ptr<IDataArray> ida = block->getEntity <IDataArray>(data. name () );
96
114
if (!ida) {
97
115
throw std::runtime_error (" FeatureHDF5::data: DataArray not found in block!" );
98
116
}
@@ -103,6 +121,48 @@ void FeatureHDF5::data(const std::string &name_or_id) {
103
121
auto target = dynamic_pointer_cast<DataArrayHDF5>(ida);
104
122
105
123
group ().createLink (target->group (), " data" );
124
+ targetType (TargetType::DataArray);
125
+
126
+ forceUpdatedAt ();
127
+ }
128
+
129
+
130
+ void FeatureHDF5::data (const DataFrame &data) {
131
+ std::shared_ptr<IDataFrame> idf = block->getEntity <IDataFrame>(data.name ());
132
+ if (!idf) {
133
+ throw std::runtime_error (" FeatureHDF5::data: DataFrame not found in block!" );
134
+ }
135
+ if (group ().hasGroup (" data" )) {
136
+ group ().removeGroup (" data" );
137
+ }
138
+
139
+ auto target = dynamic_pointer_cast<DataFrameHDF5>(idf);
140
+
141
+ group ().createLink (target->group (), " data" );
142
+ targetType (TargetType::DataFrame);
143
+ forceUpdatedAt ();
144
+ }
145
+
146
+
147
+ void FeatureHDF5::data (const std::string &name_or_id) {
148
+ TargetType tt = TargetType::DataArray;
149
+ if (group ().hasGroup (" data" )) {
150
+ group ().removeGroup (" data" );
151
+ }
152
+ std::shared_ptr<IDataArray> ida = block->getEntity <IDataArray>(name_or_id);
153
+ if (!ida) {
154
+ std::shared_ptr<IDataFrame> idf = block->getEntity <IDataFrame>(name_or_id);
155
+ if (!idf) {
156
+ throw std::runtime_error (" FeatureHDF5::data: entity is not found in block, neither DataArray nor DataFrame!" );
157
+ }
158
+ tt = TargetType::DataFrame;
159
+ auto target = dynamic_pointer_cast<DataFrameHDF5>(idf);
160
+ group ().createLink (target->group (), " data" );
161
+ } else {
162
+ auto target = dynamic_pointer_cast<DataArrayHDF5>(ida);
163
+ group ().createLink (target->group (), " data" );
164
+ }
165
+ targetType (tt);
106
166
forceUpdatedAt ();
107
167
}
108
168
0 commit comments