Commit b08c1680 authored by Alessio Netti's avatar Alessio Netti
Browse files

Analytics: refactored UnitGenerator

- Streamlined the public interface
- Added methods for single and multiple unit generation (plain and hierarchical)
- Added methods to automatically tell whether to build plain or hierarchical units
- Added pointer to parent in UnitTemplate
- Added methods to distinguish top and subunits in UnitTemplate
parent 63f27050
......@@ -95,7 +95,7 @@ protected:
op.setDuplicate(false);
vector <shared_ptr<UnitTemplate<SBase>>> *units = NULL;
try {
units = this->_unitGen.generateUnits(protoInputs, protoOutputs, inputMode, op.getMqttPart(), true, op.getRelaxed());
units = this->_unitGen.generateUnits(std::list<std::string>(), protoInputs, protoOutputs, inputMode, op.getMqttPart(), true, op.getRelaxed());
}
catch (const std::exception &e) {
LOG(error) << this->_operatorName << " " << op.getName() << ": Error when creating template job unit: " << e.what();
......
......@@ -514,7 +514,7 @@ protected:
LOG(debug) << " No output specified, generating sink unit.";
try {
units = _unitGen.generateUnits(protoInputs, protoOutputs, inputMode, op.getMqttPart(), !op.getStreaming(), op.getRelaxed());
units = _unitGen.generateUnits(std::list<std::string>(), protoInputs, protoOutputs, inputMode, op.getMqttPart(), !op.getStreaming(), op.getRelaxed());
}
catch (const std::exception &e) {
LOG(error) << _operatorName << " " << op.getName() << ": Error when creating units: " << e.what();
......
This diff is collapsed.
......@@ -60,12 +60,8 @@ public:
UnitTemplate(const std::string& name) :
UnitInterface(),
_name(name),
_inputMode(SELECTIVE) {
// base inputs and outputs vectors are constructed using iterators
_baseInputs = std::vector<SBasePtr>(_inputs.begin(), _inputs.end());
_baseOutputs = std::vector<SBasePtr>(_outputs.begin(), _outputs.end());
}
_inputMode(SELECTIVE),
_parent(nullptr) {}
/**
* @brief Class constructor
......@@ -79,7 +75,8 @@ public:
_name(name),
_inputMode(SELECTIVE),
_inputs(inputs),
_outputs(outputs) {
_outputs(outputs),
_parent(nullptr) {
// base inputs and outputs vectors are constructed using iterators
_baseInputs = std::vector<SBasePtr>(_inputs.begin(), _inputs.end());
......@@ -91,7 +88,8 @@ public:
*/
UnitTemplate(const UnitTemplate& other) :
_name(other._name),
_inputMode(other._inputMode) {
_inputMode(other._inputMode),
_parent(other._parent) {
for(auto s : other._inputs) {
_inputs.push_back(s);
......@@ -114,6 +112,7 @@ public:
UnitTemplate& operator=(const UnitTemplate& other) {
_name = other._name;
_inputMode = other._inputMode;
_parent = other._parent;
_inputs.clear();
_baseInputs.clear();
......@@ -151,8 +150,30 @@ public:
_baseOutputs.clear();
_outputs.clear();
_subUnits.clear();
_parent = nullptr;
}
/**
* @brief Tells whether this is a sub-unit in a hierarchical unit with no further sub-units
*
* @return True if this is a terminal sub-unit, false otherwise
*/
bool isLeafUnit() { return _parent && _subUnits.empty(); }
/**
* @brief Tells whether this is a sub-unit in a hierarchical unit
*
* @return True if this is a sub-unit, false otherwise
*/
bool isSubUnit() { return _parent && !_subUnits.empty(); }
/**
* @brief Tells whether this is the top entity of a hierarchical unit
*
* @return True if this is a "top" unit, false otherwise
*/
bool isTopUnit() { return !_parent && !_subUnits.empty(); }
/**
* @brief Initializes the sensors in the unit
*
......@@ -203,6 +224,20 @@ public:
*/
inputMode_t getInputMode() override { return _inputMode; }
/**
* @brief Sets the parent of this unit
*
* @param p Pointer to a UnitTemplate object
*/
void setParent(UnitTemplate<S>* p) { _parent = p; }
/**
* @brief Get the pointer to this unit's parent
*
* @return The unit's parent
*/
UnitTemplate<S> *getParent() { return _parent; }
/**
* @brief Get the (base) input sensors of this unit
*
......@@ -273,6 +308,8 @@ public:
*/
void setSubUnits(const std::vector<std::shared_ptr<UnitTemplate<S>>>& sUnits) {
_subUnits = sUnits;
for(const auto& subUnit : _subUnits)
subUnit->setParent(this);
}
/**
......@@ -295,7 +332,7 @@ public:
*
* @param sUnit A shared pointer to a UnitTemplate object
*/
void addSubUnit(const std::shared_ptr<UnitTemplate<S>> sUnit) { _subUnits.push_back(sUnit); }
void addSubUnit(const std::shared_ptr<UnitTemplate<S>> sUnit) { _subUnits.push_back(sUnit); sUnit->setParent(this); }
/**
* @brief Prints the current unit configuration
......@@ -332,6 +369,8 @@ protected:
std::vector<S_Ptr> _outputs;
// Vector of sub-units that are associated to this unit
std::vector<std::shared_ptr<UnitTemplate<S>>> _subUnits;
// Pointer to the unit's parent (if it is a sub-unit)
UnitTemplate<S>* _parent;
// Same as baseInputs
std::vector<SBasePtr> _baseOutputs;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment