1111#include < nix/util/util.hpp>
1212#include < nix/DataArray.hpp>
1313#include " DataArrayHDF5.hpp"
14+ #include " DataFrameHDF5.hpp"
1415
1516
1617using namespace std ;
@@ -71,10 +72,27 @@ FeatureHDF5::FeatureHDF5(const shared_ptr<IFile> &file, const shared_ptr<IBlock>
7172 : EntityHDF5(file, group, id, time), block(block)
7273{
7374 linkType (link_type);
74- targetType (TargetType::DataArray);
7575 // TODO: the line below currently throws an exception if the DataArray
7676 // 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);
7896}
7997
8098
@@ -91,8 +109,8 @@ void FeatureHDF5::targetType(TargetType ttype) {
91109}
92110
93111
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 () );
96114 if (!ida) {
97115 throw std::runtime_error (" FeatureHDF5::data: DataArray not found in block!" );
98116 }
@@ -103,6 +121,48 @@ void FeatureHDF5::data(const std::string &name_or_id) {
103121 auto target = dynamic_pointer_cast<DataArrayHDF5>(ida);
104122
105123 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);
106166 forceUpdatedAt ();
107167}
108168
0 commit comments