Skip to content

Commit

Permalink
#63: Move attributes from ObjectInfo to ObjectWork
Browse files Browse the repository at this point in the history
  • Loading branch information
thearusable committed Feb 12, 2024
1 parent d789381 commit 695e862
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 31 deletions.
16 changes: 2 additions & 14 deletions src/vt-tv/api/object_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,11 @@ struct ObjectInfo {
ElementIDType in_id,
NodeType in_home,
bool in_migratable,
std::vector<UniqueIndexBitType> const& in_index,
std::unordered_map<std::string, QOIVariantTypes> in_attributes = {}
std::vector<UniqueIndexBitType> const& in_index
) : id_(in_id),
home_(in_home),
migratable_(in_migratable),
index_(in_index),
attributes_(std::move(in_attributes))
index_(in_index)
{ }

/**
Expand Down Expand Up @@ -157,13 +155,6 @@ struct ObjectInfo {
*/
CollectionObjGroupIDType getMetaID() const { return meta_id_; }

/**
* \brief Get attribute fields
*
* \return attribute fields
*/
auto const& getAttributes() const { return attributes_; }

/**
* \brief Serializer for data
*
Expand All @@ -178,7 +169,6 @@ struct ObjectInfo {
s | meta_id_;
s | is_objgroup_;
s | is_collection_;
s | attributes_;
}

private:
Expand All @@ -196,8 +186,6 @@ struct ObjectInfo {
bool is_objgroup_ = false;
/// Whether it's an collection
bool is_collection_ = false;
/// QOIs to be visualized
std::unordered_map<std::string, QOIVariantTypes> attributes_;
};

} /* end namespace vt::tv */
Expand Down
16 changes: 14 additions & 2 deletions src/vt-tv/api/object_work.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,14 @@ struct ObjectWork {
ElementIDType in_id,
TimeType in_whole_phase_load,
std::unordered_map<SubphaseType, TimeType> in_subphase_loads,
std::unordered_map<std::string, VariantType> in_user_defined = {}
std::unordered_map<std::string, VariantType> in_user_defined = {},
std::unordered_map<std::string, QOIVariantTypes> in_attributes = {}
) : id_(in_id),
whole_phase_load_(in_whole_phase_load),
subphase_loads_(std::move(in_subphase_loads)),
user_defined_(std::move(in_user_defined)),
communicator_(id_)
communicator_(id_),
attributes_(std::move(in_attributes))
{ }

/**
Expand Down Expand Up @@ -113,6 +115,13 @@ struct ObjectWork {
*/
auto const& getUserDefined() const { return user_defined_; }

/**
* \brief Get attribute fields
*
* \return attribute fields
*/
auto const& getAttributes() const { return attributes_; }

/**
* \brief set communications for this object
*
Expand Down Expand Up @@ -174,6 +183,7 @@ struct ObjectWork {
s | subphase_loads_;
s | user_defined_;
s | communicator_;
s | attributes_;
}

private:
Expand All @@ -185,6 +195,8 @@ struct ObjectWork {
std::unordered_map<SubphaseType, TimeType> subphase_loads_;
// User-defined field---used to populate the memory block
std::unordered_map<std::string, VariantType> user_defined_;
/// QOIs to be visualized
std::unordered_map<std::string, QOIVariantTypes> attributes_;

/// @todo: add communications
ObjectCommunicator communicator_;
Expand Down
25 changes: 13 additions & 12 deletions src/vt-tv/utility/json_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,7 @@ std::unique_ptr<Info> JSONReader::parseFile() {
}
}

std::unordered_map<std::string, QOIVariantTypes> readed_metadata;
if (task["entity"].find("attributes") != task["entity"].end()) {
auto attributes = task["entity"]["attributes"];
if (attributes.is_object()) {
for (auto& [key, value] : attributes.items()) {
readed_metadata[key] = value;
}
}
}

ObjectInfo oi{object, home, migratable, std::move(index_arr), std::move(readed_metadata)};
ObjectInfo oi{object, home, migratable, std::move(index_arr)};

if (task["entity"].find("collection_id") != task["entity"].end()) {
oi.setIsCollection(true);
Expand Down Expand Up @@ -196,11 +186,22 @@ std::unique_ptr<Info> JSONReader::parseFile() {
}
}
}

std::unordered_map<std::string, QOIVariantTypes> readed_metadata;
if (task["entity"].find("attributes") != task["entity"].end()) {
auto attributes = task["entity"]["attributes"];
if (attributes.is_object()) {
for (auto& [key, value] : attributes.items()) {
readed_metadata[key] = value;
}
}
}

// fmt::print(" Add object {}\n", (ElementIDType)object);
objects.try_emplace(
object,
ObjectWork{
object, time, std::move(subphase_loads), std::move(user_defined)
object, time, std::move(subphase_loads), std::move(user_defined), std::move(readed_metadata)
}
);
}
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/test_json_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ TEST_F(TestJSONReader, test_json_reader_object_info_attributes) {
auto& rank_info = info->getRank(rank);
EXPECT_EQ(rank_info.getRankID(), rank);

auto const& objects = info->getObjectInfo();
auto const& object_info = objects.at(3407875);
auto const& objects = info->getRankObjects(0, 0);
auto const& object_work = objects.at(3407875);

auto& object_attributes = object_info.getAttributes();
auto& object_attributes = object_work.getAttributes();
EXPECT_TRUE(object_attributes.find("boolSample") != object_attributes.end());
EXPECT_EQ(false, std::get<bool>(object_attributes.at("boolSample")));

Expand Down

0 comments on commit 695e862

Please sign in to comment.