Skip to content
Snippets Groups Projects
Commit 3e20f558 authored by Christoph Kampmeyer's avatar Christoph Kampmeyer
Browse files

wip #107: Prepare code for detection of instances from parent node on

Currently does not get the modules in a way that they can be downcasted
to test if StatusMonitor, etc
parent 499fa143
No related branches found
No related tags found
No related merge requests found
......@@ -44,6 +44,8 @@ namespace ChimeraTK {
/// Recursivly search for StatusMonitors and other StatusAggregators
void populateStatusInput();
/// Helper for populateStatusInput
void scanAndPopulateFromHierarchyLevel(std::list<VariableNetworkNode> nodes);
/**One of four possible states to be reported*/
ScalarOutput<uint16_t> status;
......
......@@ -9,24 +9,9 @@ namespace ChimeraTK {
std::cout << "Populating aggregator " << getName() << ", fully qualified name is: " << getQualifiedName()
<< std::endl;
// This does not work, we need to operate on the virtual hierarchy
//std::list<Module*> subModuleList{getOwner()->getSubmoduleList()};
// This approach crashes
// auto subModuleList = getOwner()->findTag(".*").getSubmoduleList();
// for(auto module : subModuleList){
// std::cout << "Testing Module " << module->getName() << std::endl;
// auto accList{module->getAccessorList()};
// }
// Another try, virtualise the entire Application
auto virtualisedApplication = Application::getInstance().findTag(".*");
auto virtualPathToThis = getVirtualQualifiedName();
std::cout << " ** Fully qualified name in vitual hierarchy: "
<< getVirtualQualifiedName() << std::endl;
// Remove application name and name of leaf node from the path
auto pathBegin = virtualPathToThis.find_first_not_of("/" + Application::getInstance().getName() + "/");
......@@ -38,54 +23,82 @@ namespace ChimeraTK {
std::list<Module*> allSubmodules;
if(pathWithoutAppAndLeafNode == getName()) {
// Path to this module, the parent is the Application
allAccessors = virtualisedApplication.getAccessorListRecursive();
allSubmodules = virtualisedApplication.getSubmoduleListRecursive();
std::cout << "Parent is the Application" << std::endl;
allAccessors = virtualisedApplication.getAccessorList();
allSubmodules = virtualisedApplication.getSubmoduleList();
}
else {
std::cout << "SubPath to this aggregator's parent : " << pathWithoutAppAndLeafNode << std::endl;
Module& virtualParent =
virtualisedApplication.submodule(virtualPathToThis.substr(pathBegin, pathEnd - pathBegin + 1));
virtualParent.dump();
allAccessors = virtualParent.getAccessorListRecursive();
allSubmodules = virtualParent.getSubmoduleListRecursive();
allAccessors = virtualParent.getAccessorList();
allSubmodules = virtualParent.getSubmoduleList();
}
// Works, as long as we do not use HIerarchyModifiers other than "none" in the test app
// Update: This still has problems, because getOwner gives us the "real" C++ Module
// We need to do everything on the virtual plane
//auto allAccessors{virtualParent.getAccessorListRecursive()};
//auto allSubmodules{virtualParent.getSubmoduleListRecursive()};
std::cout << " Size of allAccessors: " << allAccessors.size() << std::endl;
std::cout << " Size of allSubmodules: " << allSubmodules.size() << std::endl;
for(auto acc : allAccessors) {
if(acc.getDirection().dir == VariableDirection::feeding) {
std::cout << " -- Accessor: " << acc.getName() << " of module: " << acc.getOwningModule()->getName()
<< std::endl;
}
}
// Two approaches to get the modules of interest to feed to scanAndPopulateFromHierarchyLeve:
// 1. directly call getSubmoduleList on each level: gives VirtualModules and the dynamic_casts below fail
// 2.use getAccessorList and call getOwningModule() on each Accessor (as done below): Does not find the status outputs right now
// Also, this means more effort to detect and recurse into ModuleGroups
//for(auto acc : allAccessors) {
//if(acc.getDirection().dir == VariableDirection::feeding) {
//std::cout << " -- Accessor: " << acc.getName() << " of module: " << acc.getOwningModule()->getName()
//<< std::endl;
//}
scanAndPopulateFromHierarchyLevel(allAccessors);
// if(dynamic_cast<StatusMonitor*>(module)){
// std::cout << " Found Monitor " << module->getName() << std::endl;
// }
// else if(dynamic_cast<StatusAggregator*>(module)){
// std::string moduleName = module->getName();
// std::cout << "Found Aggregator " << moduleName << std::endl;
// statusInput.emplace_back(this, moduleName, "", "");
// }
// else if(dynamic_cast<ModuleGroup*>(module)){
// std::cout << "Found ModuleGroup " << module->getName() << std::endl;
// }
// else{}
// }
std::cout << std::endl << std::endl;
} // poplateStatusInput()*/
void StatusAggregator::scanAndPopulateFromHierarchyLevel(std::list<VariableNetworkNode> nodes) {
if(nodes.empty()) {
return;
}
bool statusAggregatorFound{false};
std::list<Module*> instancesToBeAggregated;
// This does loops per level:
// 1. Find all StatusMonitors and StatusAggregators on this level, if there
// is an aggregator, we can discard the Monitors on this level
// 2. Iterate over instancesToBeAggregated and add to statusInput
for(auto node : nodes) {
// Only check feeding nodes to test each Module only once on the status output
if(node.getDirection().dir != VariableDirection::feeding){
continue;
}
auto module{node.getOwningModule()};
std::cout << "Scanning Module " << module->getName() << std::endl;
if(dynamic_cast<StatusMonitor*>(module)) {
std::cout << " Found Monitor " << module->getName() << std::endl;
}
else if(dynamic_cast<StatusAggregator*>(module)) {
std::string moduleName = module->getName();
if(statusAggregatorFound){
throw ChimeraTK::logic_error("StatusAggregator: A second instance was found on the same hierarchy level.");
}
statusAggregatorFound = true;
std::cout << "Found Aggregator " << moduleName << std::endl;
statusInput.emplace_back(this, moduleName, "", "");
}
else if(dynamic_cast<ModuleGroup*>(module)) {
std::cout << "Found ModuleGroup " << module->getName() << std::endl;
// Process level below
scanAndPopulateFromHierarchyLevel(module->getAccessorList());
}
else {
}
}
// 2. TODO Add status inputs
}
} // namespace ChimeraTK
......@@ -16,17 +16,19 @@ struct OuterGroup : public ctk::ModuleGroup {
using ctk::ModuleGroup::ModuleGroup;
virtual ~OuterGroup() {}
ctk::MinMonitor<double_t> outerMinMonitor{this, "outerMinMonitor", "", "watch", "status",
ctk::StateMonitor<uint8_t> outerStateMonitor{this, "outerStateMonitor", "", "watch", "status",
ctk::HierarchyModifier::none, {"OUTER_MON_OUTPUT"}, {"OUTER_MON_PARAMS"}, {"OUTER_MON_INPUT"}};
struct InnerGroup : public ctk::ModuleGroup {
using ctk::ModuleGroup::ModuleGroup;
ctk::MinMonitor<double_t> innerMinMonitor{this, "innerMinMonitor", "", "minWatch", "minStatus",
ctk::StateMonitor<uint8_t> innerStateMonitorNone{this, "innerMinMonitorNone", "", "watch", "status",
ctk::HierarchyModifier::none, {"INNER_MON_OUTPUT"}, {"INNER_MON_PARAMS"}, {"INNER_MON_INPUT"}};
// A Monitor which gets hidden in the hierarchy
ctk::StateMonitor<uint8_t> innerStateMonitor{this, "innerStateMonitor", "", "stateWatch", "stateStatus",
ctk::StateMonitor<uint8_t> innerStateMonitorHideThis{this, "innerStateMonitorHideThis", "", "watch", "status",
ctk::HierarchyModifier::hideThis, {"INNER_MON_OUTPUT"}, {"INNER_MON_PARAMS"}, {"INNER_MON_INPUT"}};
ctk::StateMonitor<uint8_t> innerStateMonitorOneUp{this, "innerStateMonitorOneUp", "", "watch", "status",
ctk::HierarchyModifier::oneLevelUp, {"INNER_MON_OUTPUT"}, {"INNER_MON_PARAMS"}, {"INNER_MON_INPUT"}};
} innerGroup{this, "innerModuleGroup", "", ctk::HierarchyModifier::none};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment