Skip to content

Commit

Permalink
ENH: Create DataModifiedAction that marks DataObjects as being modifi…
Browse files Browse the repository at this point in the history
…ed by a filter

Signed-off-by: Michael Jackson <[email protected]>
  • Loading branch information
imikejackson committed Oct 18, 2023
1 parent 1807f62 commit b101542
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ std::string RemoveMinimumSizeFeaturesFilter::humanName() const
//------------------------------------------------------------------------------
std::vector<std::string> RemoveMinimumSizeFeaturesFilter::defaultTags() const
{
return {className(), "Processing", "Cleanup", "MinSize"};
return {className(), "Processing", "Cleanup", "MinSize", "Feature Removal"};
}

Parameters RemoveMinimumSizeFeaturesFilter::parameters() const
Expand Down Expand Up @@ -363,10 +363,8 @@ IFilter::PreflightResult RemoveMinimumSizeFeaturesFilter::preflightImpl(const Da
}

// Create the preflightResult object
IFilter::PreflightResult preflightResult;

// Create our OutputActions Object
OutputActions outputActions;
complex::Result<OutputActions> resultOutputActions;
std::vector<PreflightValue> preflightUpdatedValues;

// Throw a warning to inform the user that the neighbor list arrays could be deleted by this filter
std::string ss = fmt::format("If this filter modifies the Cell Level Array '{}', all arrays of type NeighborList will be deleted from the feature data group '{}'. These arrays are:\n",
Expand All @@ -383,12 +381,25 @@ IFilter::PreflightResult RemoveMinimumSizeFeaturesFilter::preflightImpl(const Da
{
ss.append(" " + featureNeighborList.toString() + "\n");
auto action = std::make_unique<DeleteDataAction>(featureNeighborList);
outputActions.appendAction(std::move(action));
resultOutputActions.value().actions.emplace_back(std::move(action));
}

result = complex::GetAllChildDataPaths(data, featureGroupDataPath);
if(!result.has_value())
{
return {nonstd::make_unexpected(
std::vector<Error>{Error{k_FetchChildArrayError, fmt::format("Errors were encountered trying to retrieve the children of DataGroup '{}'", featureGroupDataPath.toString())}})};
}
const std::vector<DataPath> featureDataGroupChildren = result.value();
for(const auto& child : featureDataGroupChildren)
{
resultOutputActions.value().modifiedActions.emplace_back(DataModifiedAction{child, DataModifiedAction::ModifiedType::DataArrayModified});
}

preflightResult.outputActions.warnings().push_back(Warning{k_NeighborListRemoval, ss});
resultOutputActions.warnings().push_back(Warning{k_NeighborListRemoval, ss});

return preflightResult;
// Return both the resultOutputActions and the preflightUpdatedValues via std::move()
return {std::move(resultOutputActions), std::move(preflightUpdatedValues)};
}

// -----------------------------------------------------------------------------
Expand Down
22 changes: 22 additions & 0 deletions src/complex/Filter/Output.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,30 @@ class COMPLEX_EXPORT IDataCreationAction : public IDataAction
DataPath m_CreatedPath;
};

/**
* @brief
*/
struct COMPLEX_EXPORT DataModifiedAction
{

enum class ModifiedType : uint64
{
DataArrayModified = 0,
DataArrayPossiblyDeleted = 1,
};

DataPath m_ModifiedPath;
ModifiedType m_ModifiedType;
};

/**
* @brief Container for IDataActions
*/
struct COMPLEX_EXPORT OutputActions
{
std::vector<AnyDataAction> actions = {};
std::vector<AnyDataAction> deferredActions = {};
std::vector<DataModifiedAction> modifiedActions = {};

OutputActions() = default;

Expand All @@ -139,6 +156,11 @@ struct COMPLEX_EXPORT OutputActions
deferredActions.emplace_back(std::move(action));
}

void appendModifiedAction(const DataPath& dataPath, DataModifiedAction::ModifiedType modifiedType)
{
modifiedActions.emplace_back(DataModifiedAction{dataPath, modifiedType});
}

static Result<> ApplyActions(nonstd::span<const AnyDataAction> actions, DataStructure& dataStructure, IDataAction::Mode mode);

Result<> applyRegular(DataStructure& dataStructure, IDataAction::Mode mode) const;
Expand Down
21 changes: 17 additions & 4 deletions src/complex/Pipeline/PipelineFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,25 +140,33 @@ bool PipelineFilter::preflight(DataStructure& data, RenamedPaths& renamedPaths,
}

std::vector<DataPath> newCreatedPaths;
std::vector<DataPath> newModifiedPaths;
for(const auto& action : result.outputActions.value().actions)
{
if(const auto* creationAction = dynamic_cast<const IDataCreationAction*>(action.get()); creationAction != nullptr)
if(const auto* creationActionPtr = dynamic_cast<const IDataCreationAction*>(action.get()); creationActionPtr != nullptr)
{
auto allCreatedPaths = creationAction->getAllCreatedPaths();
auto allCreatedPaths = creationActionPtr->getAllCreatedPaths();
newCreatedPaths.insert(newCreatedPaths.end(), allCreatedPaths.begin(), allCreatedPaths.end());
}
}

for(const auto& action : result.outputActions.value().deferredActions)
{
if(const auto* creationAction = dynamic_cast<const IDataCreationAction*>(action.get()); creationAction != nullptr)
if(const auto* creationActionPtr = dynamic_cast<const IDataCreationAction*>(action.get()); creationActionPtr != nullptr)
{
auto allCreatedPaths = creationAction->getAllCreatedPaths();
auto allCreatedPaths = creationActionPtr->getAllCreatedPaths();
newCreatedPaths.insert(newCreatedPaths.end(), allCreatedPaths.begin(), allCreatedPaths.end());
}
}

for(const auto& action : result.outputActions.value().modifiedActions)
{
newModifiedPaths.emplace_back(action.m_ModifiedPath);
}

// Do not clear the created paths unless the preflight succeeded
m_CreatedPaths = newCreatedPaths;
m_ModifiedPaths = newModifiedPaths;

setPreflightStructure(data);
sendFilterFaultMessage(m_Index, getFaultState());
Expand Down Expand Up @@ -219,6 +227,11 @@ std::vector<DataPath> PipelineFilter::getCreatedPaths() const
return m_CreatedPaths;
}

std::vector<DataPath> PipelineFilter::getModifiedPaths() const
{
return m_ModifiedPaths;
}

namespace
{
/**
Expand Down
7 changes: 7 additions & 0 deletions src/complex/Pipeline/PipelineFilter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ class COMPLEX_EXPORT PipelineFilter : public AbstractPipelineNode
*/
std::vector<DataPath> getCreatedPaths() const;

/**
* @brief Returns a vector of DataPaths that would be modified when executing the node
* @return std::vector<DataPath>
*/
std::vector<DataPath> getModifiedPaths() const;

/**
* @brief Returns a collection of warnings returned by the target filter.
* This collection is cleared when the node is preflighted or executed.
Expand Down Expand Up @@ -220,5 +226,6 @@ class COMPLEX_EXPORT PipelineFilter : public AbstractPipelineNode
std::vector<complex::Error> m_Errors;
std::vector<IFilter::PreflightValue> m_PreflightValues;
std::vector<DataPath> m_CreatedPaths;
std::vector<DataPath> m_ModifiedPaths;
};
} // namespace complex

0 comments on commit b101542

Please sign in to comment.