|
9 | 9 | // granted to it by virtue of its status as an Intergovernmental Organization |
10 | 10 | // or submit itself to any jurisdiction. |
11 | 11 | #include <memory> |
| 12 | +#include "Framework/TopologyPolicyHelpers.h" |
12 | 13 | #define BOOST_BIND_GLOBAL_PLACEHOLDERS |
13 | 14 | #include <stdexcept> |
14 | 15 | #include "Framework/BoostOptionsRetriever.h" |
@@ -2835,20 +2836,6 @@ std::unique_ptr<o2::framework::ServiceRegistry> createRegistry() |
2835 | 2836 | return std::make_unique<o2::framework::ServiceRegistry>(); |
2836 | 2837 | } |
2837 | 2838 |
|
2838 | | -void describeDataProcessorSpec(std::ostream& stream, DataProcessorSpec const& spec) |
2839 | | -{ |
2840 | | - stream << spec.name; |
2841 | | - if (!spec.labels.empty()) { |
2842 | | - stream << "("; |
2843 | | - bool first = false; |
2844 | | - for (auto& label : spec.labels) { |
2845 | | - stream << (first ? "" : ",") << label.value; |
2846 | | - first = true; |
2847 | | - } |
2848 | | - stream << ")"; |
2849 | | - } |
2850 | | -} |
2851 | | - |
2852 | 2839 | // This is a toy executor for the workflow spec |
2853 | 2840 | // What it needs to do is: |
2854 | 2841 | // |
@@ -3034,65 +3021,12 @@ int doMain(int argc, char** argv, o2::framework::WorkflowSpec const& workflow, |
3034 | 3021 | [](OutputSpec const& a, OutputSpec const& b) { return DataSpecUtils::describe(a) < DataSpecUtils::describe(b); }); |
3035 | 3022 | } |
3036 | 3023 |
|
3037 | | - std::vector<TopologyPolicy> topologyPolicies = TopologyPolicy::createDefaultPolicies(); |
3038 | | - std::vector<TopologyPolicy::DependencyChecker> dependencyCheckers; |
3039 | | - dependencyCheckers.reserve(physicalWorkflow.size()); |
3040 | | - |
3041 | | - for (auto& spec : physicalWorkflow) { |
3042 | | - for (auto& policy : topologyPolicies) { |
3043 | | - if (policy.matcher(spec)) { |
3044 | | - dependencyCheckers.push_back(policy.checkDependency); |
3045 | | - break; |
3046 | | - } |
3047 | | - } |
3048 | | - } |
3049 | | - assert(dependencyCheckers.size() == physicalWorkflow.size()); |
3050 | | - // check if DataProcessorSpec at i depends on j |
3051 | | - auto checkDependencies = [&workflow = physicalWorkflow, |
3052 | | - &dependencyCheckers](int i, int j) { |
3053 | | - TopologyPolicy::DependencyChecker& checker = dependencyCheckers[i]; |
3054 | | - return checker(workflow[i], workflow[j]); |
3055 | | - }; |
3056 | | - |
3057 | 3024 | // Create a list of all the edges, so that we can do a topological sort |
3058 | 3025 | // before we create the graph. |
3059 | 3026 | std::vector<std::pair<int, int>> edges; |
3060 | 3027 |
|
3061 | 3028 | if (physicalWorkflow.size() > 1) { |
3062 | | - for (size_t i = 0; i < physicalWorkflow.size() - 1; ++i) { |
3063 | | - for (size_t j = i; j < physicalWorkflow.size(); ++j) { |
3064 | | - if (i == j && checkDependencies(i, j)) { |
3065 | | - throw std::runtime_error(physicalWorkflow[i].name + " depends on itself"); |
3066 | | - } |
3067 | | - bool both = false; |
3068 | | - if (checkDependencies(i, j)) { |
3069 | | - edges.emplace_back(j, i); |
3070 | | - both = true; |
3071 | | - } |
3072 | | - if (checkDependencies(j, i)) { |
3073 | | - edges.emplace_back(i, j); |
3074 | | - if (both) { |
3075 | | - std::ostringstream str; |
3076 | | - describeDataProcessorSpec(str, physicalWorkflow[i]); |
3077 | | - str << " has circular dependency with "; |
3078 | | - describeDataProcessorSpec(str, physicalWorkflow[j]); |
3079 | | - str << ":\n"; |
3080 | | - for (auto x : {i, j}) { |
3081 | | - str << physicalWorkflow[x].name << ":\n"; |
3082 | | - str << "inputs:\n"; |
3083 | | - for (auto& input : physicalWorkflow[x].inputs) { |
3084 | | - str << "- " << input << " " << (int)input.lifetime << "\n"; |
3085 | | - } |
3086 | | - str << "outputs:\n"; |
3087 | | - for (auto& output : physicalWorkflow[x].outputs) { |
3088 | | - str << "- " << output << " " << (int)output.lifetime << "\n"; |
3089 | | - } |
3090 | | - } |
3091 | | - throw std::runtime_error(str.str()); |
3092 | | - } |
3093 | | - } |
3094 | | - } |
3095 | | - } |
| 3029 | + edges = TopologyPolicyHelpers::buildEdges(physicalWorkflow); |
3096 | 3030 |
|
3097 | 3031 | auto topoInfos = WorkflowHelpers::topologicalSort(physicalWorkflow.size(), &edges[0].first, &edges[0].second, sizeof(std::pair<int, int>), edges.size()); |
3098 | 3032 | if (topoInfos.size() != physicalWorkflow.size()) { |
|
0 commit comments