Skip to content

Commit 4339414

Browse files
committed
Revert "Merge pull request #8733 from matthiasrichter/dev-datadescriptormatcher-serializer"
This reverts commit 48f0113.
1 parent 9877677 commit 4339414

File tree

2 files changed

+19
-183
lines changed

2 files changed

+19
-183
lines changed

Framework/Core/include/Framework/DataDescriptorMatcher.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,6 @@ class DataDescriptorMatcher
297297

298298
Node const& getLeft() const { return mLeft; };
299299
Node const& getRight() const { return mRight; };
300-
Node& getLeft() { return mLeft; };
301-
Node& getRight() { return mRight; };
302300
Op getOp() const { return mOp; };
303301

304302
private:

Framework/Core/src/WorkflowSerializationHelpers.cxx

Lines changed: 19 additions & 181 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@
1313
#include "Framework/WorkflowSpec.h"
1414
#include "Framework/DataDescriptorQueryBuilder.h"
1515
#include "Framework/DataSpecUtils.h"
16-
#include "Framework/VariantHelpers.h"
1716
#include "Framework/VariantJSONHelpers.h"
1817
#include "Framework/DataDescriptorMatcher.h"
19-
#include "Framework/DataMatcherWalker.h"
2018
#include "Framework/Logger.h"
2119

2220
#include <rapidjson/reader.h>
@@ -58,7 +56,6 @@ struct WorkflowImporter : public rapidjson::BaseReaderHandler<rapidjson::UTF8<>,
5856
IN_INPUT_DESCRIPTION,
5957
IN_INPUT_SUBSPEC,
6058
IN_INPUT_LIFETIME,
61-
IN_INPUT_STARTTIME,
6259
IN_INPUT_MATCHER,
6360
IN_INPUT_MATCHER_OPERATION,
6461
IN_INPUT_LEFT_MATCHER,
@@ -169,9 +166,6 @@ struct WorkflowImporter : public rapidjson::BaseReaderHandler<rapidjson::UTF8<>,
169166
case State::IN_INPUT_LIFETIME:
170167
s << "IN_INPUT_LIFETIME";
171168
break;
172-
case State::IN_INPUT_STARTTIME:
173-
s << "IN_INPUT_STARTTIME";
174-
break;
175169
case State::IN_INPUT_OPTIONS:
176170
s << "IN_INPUT_OPTIONS";
177171
break;
@@ -273,13 +267,11 @@ struct WorkflowImporter : public rapidjson::BaseReaderHandler<rapidjson::UTF8<>,
273267
push(State::IN_INPUT);
274268
inputMatcherNodes.clear();
275269
} else if (in(State::IN_INPUT_MATCHER)) {
276-
// start a new embedded matcher
270+
assert(0); // to be implemented
277271
} else if (in(State::IN_INPUT_LEFT_MATCHER)) {
278-
// this is a matcher leaf, i.e. last matcher of a branch
279-
// will be merged into the parent matcher
272+
assert(0); // to be implemented
280273
} else if (in(State::IN_INPUT_RIGHT_MATCHER)) {
281-
// this is a matcher leaf, i.e. last matcher of a branch
282-
// will be merged into the parent matcher
274+
assert(0); // to be implemented
283275
} else if (in(State::IN_OUTPUTS)) {
284276
push(State::IN_OUTPUT);
285277
outputHasSubSpec = false;
@@ -321,13 +313,7 @@ struct WorkflowImporter : public rapidjson::BaseReaderHandler<rapidjson::UTF8<>,
321313
return lastMatcher;
322314
};
323315

324-
std::unique_ptr<DataDescriptorMatcher> matcher;
325-
if (auto* pval = std::get_if<std::unique_ptr<DataDescriptorMatcher>>(&inputMatcherNodes[0])) {
326-
assert(inputMatcherNodes.size() == 1);
327-
matcher = std::move(*pval);
328-
} else {
329-
matcher = buildMatcher(inputMatcherNodes);
330-
}
316+
auto matcher = buildMatcher(inputMatcherNodes);
331317
auto concrete = DataSpecUtils::optionalConcreteDataMatcherFrom(*matcher);
332318
if (concrete.has_value()) {
333319
// the matcher is fully qualified with unique parameters so we add ConcreteDataMatcher
@@ -338,60 +324,6 @@ struct WorkflowImporter : public rapidjson::BaseReaderHandler<rapidjson::UTF8<>,
338324
inputMatcherNodes.clear();
339325
inputOptions.clear();
340326

341-
} else if (in(State::IN_INPUT_MATCHER) && inputMatcherNodes.size() > 1) {
342-
data_matcher::Node child = std::move(inputMatcherNodes.back());
343-
inputMatcherNodes.pop_back();
344-
auto* matcher = std::get_if<std::unique_ptr<DataDescriptorMatcher>>(&child);
345-
assert(matcher != nullptr);
346-
auto* parent = std::get_if<std::unique_ptr<DataDescriptorMatcher>>(&inputMatcherNodes.back());
347-
assert(parent != nullptr);
348-
std::unique_ptr<DataDescriptorMatcher> node;
349-
auto mergeDown = [&node, &parent, &child]() -> bool {
350-
// FIXME: do we need a dedicated default state, or can we simply use ConstantValueMatcher
351-
if (auto* pval1 = std::get_if<ConstantValueMatcher>(&((*parent)->getLeft()))) {
352-
if (*pval1 == ConstantValueMatcher{false}) {
353-
node = std::make_unique<DataDescriptorMatcher>((*parent)->getOp(),
354-
std::move(child),
355-
std::move((*parent)->getRight()));
356-
return true;
357-
}
358-
}
359-
if (auto* pval2 = std::get_if<ConstantValueMatcher>(&((*parent)->getRight()))) {
360-
if (*pval2 == ConstantValueMatcher{false}) {
361-
node = std::make_unique<DataDescriptorMatcher>((*parent)->getOp(),
362-
std::move((*parent)->getLeft()),
363-
std::move(child));
364-
return true;
365-
}
366-
}
367-
return false;
368-
};
369-
if (!mergeDown()) {
370-
states.push_back(State::IN_ERROR);
371-
}
372-
inputMatcherNodes.pop_back();
373-
inputMatcherNodes.push_back(std::move(node));
374-
} else if (in(State::IN_INPUT_LEFT_MATCHER)) {
375-
assert(inputMatcherNodes.size() >= 2);
376-
size_t nMatchers = inputMatcherNodes.size();
377-
auto* parent = std::get_if<std::unique_ptr<DataDescriptorMatcher>>(&inputMatcherNodes[nMatchers - 2]);
378-
assert(parent != nullptr);
379-
auto node = std::make_unique<DataDescriptorMatcher>((*parent)->getOp(),
380-
std::move(inputMatcherNodes[nMatchers - 1]),
381-
std::move((*parent)->getRight()));
382-
inputMatcherNodes.pop_back();
383-
inputMatcherNodes.pop_back();
384-
inputMatcherNodes.push_back(std::move(node));
385-
} else if (in(State::IN_INPUT_RIGHT_MATCHER)) {
386-
data_matcher::Node child = std::move(inputMatcherNodes.back());
387-
inputMatcherNodes.pop_back();
388-
auto* parent = std::get_if<std::unique_ptr<DataDescriptorMatcher>>(&inputMatcherNodes.back());
389-
assert(parent != nullptr);
390-
auto node = std::make_unique<DataDescriptorMatcher>((*parent)->getOp(),
391-
std::move((*parent)->getLeft()),
392-
std::move(child));
393-
inputMatcherNodes.pop_back();
394-
inputMatcherNodes.push_back(std::move(node));
395327
} else if (in(State::IN_OUTPUT)) {
396328
if (outputHasSubSpec) {
397329
dataProcessors.back().outputs.push_back(OutputSpec({binding}, origin, description, subspec, lifetime));
@@ -547,13 +479,13 @@ struct WorkflowImporter : public rapidjson::BaseReaderHandler<rapidjson::UTF8<>,
547479
} else if (in(State::IN_INPUT) && strncmp(str, "subspec", length) == 0) {
548480
push(State::IN_INPUT_SUBSPEC);
549481
} else if (in(State::IN_INPUT) && strncmp(str, "matcher", length) == 0) {
482+
assert(0);
550483
// the outermost matcher is starting here
551484
// we create a placeholder which is being updated later
552485
inputMatcherNodes.push_back(std::make_unique<DataDescriptorMatcher>(DataDescriptorMatcher::Op::And, ConstantValueMatcher{false}));
553486
push(State::IN_INPUT_MATCHER);
554487
} else if (in(State::IN_INPUT_MATCHER) && strncmp(str, "matcher", length) == 0) {
555-
// recursive matchers
556-
inputMatcherNodes.push_back(std::make_unique<DataDescriptorMatcher>(DataDescriptorMatcher::Op::And, ConstantValueMatcher{false}));
488+
// recursive matchers, can maybe combine with above
557489
push(State::IN_INPUT_MATCHER);
558490
} else if (in(State::IN_INPUT_MATCHER) && strncmp(str, "operation", length) == 0) {
559491
push(State::IN_INPUT_MATCHER_OPERATION);
@@ -573,14 +505,8 @@ struct WorkflowImporter : public rapidjson::BaseReaderHandler<rapidjson::UTF8<>,
573505
push(State::IN_INPUT_SUBSPEC);
574506
} else if (in(State::IN_INPUT_RIGHT_MATCHER) && strncmp(str, "subspec", length) == 0) {
575507
push(State::IN_INPUT_SUBSPEC);
576-
} else if (in(State::IN_INPUT_LEFT_MATCHER) && strncmp(str, "starttime", length) == 0) {
577-
push(State::IN_INPUT_STARTTIME);
578-
} else if (in(State::IN_INPUT_RIGHT_MATCHER) && strncmp(str, "starttime", length) == 0) {
579-
push(State::IN_INPUT_STARTTIME);
580508
} else if (in(State::IN_INPUT) && strncmp(str, "lifetime", length) == 0) {
581509
push(State::IN_INPUT_LIFETIME);
582-
} else if (in(State::IN_INPUT) && strncmp(str, "starttime", length) == 0) {
583-
push(State::IN_INPUT_STARTTIME);
584510
} else if (in(State::IN_INPUT) && strncmp(str, "metadata", length) == 0) {
585511
push(State::IN_INPUT_OPTIONS);
586512
} else if (in(State::IN_OUTPUT) && strncmp(str, "binding", length) == 0) {
@@ -668,30 +594,8 @@ struct WorkflowImporter : public rapidjson::BaseReaderHandler<rapidjson::UTF8<>,
668594
description.runtimeInit(s.c_str(), std::min(s.size(), 16UL));
669595
std::string v(s.c_str(), std::min(s.size(), 16UL));
670596
inputMatcherNodes.push_back(DescriptionValueMatcher{v});
671-
} else if (in(State::IN_INPUT_STARTTIME)) {
672-
// we add StartTimeValueMatcher with ContextRef for starttime, no matter what
673-
// has been in the configuration.
674-
inputMatcherNodes.push_back(StartTimeValueMatcher(ContextRef{ContextPos::STARTTIME_POS}));
675597
} else if (in(State::IN_INPUT_MATCHER_OPERATION)) {
676-
// FIXME: need to implement operator>> to read the op parameter
677-
DataDescriptorMatcher::Op op = DataDescriptorMatcher::Op::And;
678-
if (s == "and") {
679-
op = DataDescriptorMatcher::Op::And;
680-
} else if (s == "or") {
681-
op = DataDescriptorMatcher::Op::Or;
682-
} else if (s == "xor") {
683-
op = DataDescriptorMatcher::Op::Xor;
684-
} else if (s == "just") {
685-
op = DataDescriptorMatcher::Op::Just;
686-
} else if (s == "not") {
687-
op = DataDescriptorMatcher::Op::Not;
688-
}
689-
// FIXME: we could drop the placeholder which has been added when entering
690-
// the states which can read key 'operation', but then we need to make sure
691-
// that this key is always present
692-
auto node = std::make_unique<DataDescriptorMatcher>(op, ConstantValueMatcher{false});
693-
inputMatcherNodes.pop_back();
694-
inputMatcherNodes.push_back(std::move(node));
598+
// FIXME: read operation
695599
} else if (in(State::IN_OUTPUT_BINDING)) {
696600
binding = s;
697601
} else if (in(State::IN_OUTPUT_ORIGIN)) {
@@ -725,10 +629,6 @@ struct WorkflowImporter : public rapidjson::BaseReaderHandler<rapidjson::UTF8<>,
725629
push(State::IN_METADATUM_CHANNEL);
726630
} else if (in(State::IN_COMMAND)) {
727631
command.merge({s});
728-
} else {
729-
std::stringstream errstr;
730-
errstr << "No string handling for argument '" << std::string(str, length) << "' in state " << states.back() << std::endl;
731-
throw std::runtime_error(errstr.str());
732632
}
733633
pop();
734634
return true;
@@ -888,67 +788,6 @@ void WorkflowSerializationHelpers::dump(std::ostream& out,
888788
rapidjson::OStreamWrapper osw(out);
889789
rapidjson::PrettyWriter<rapidjson::OStreamWrapper> w(osw);
890790

891-
// handlers for serialization of InputSpec matchers
892-
auto edgeWalker = overloaded{
893-
[&w](EdgeActions::EnterNode action) {
894-
w.Key("matcher");
895-
w.StartObject();
896-
w.Key("operation");
897-
std::stringstream ss;
898-
ss << action.node->getOp();
899-
w.String(ss.str().c_str());
900-
if (action.node->getOp() == DataDescriptorMatcher::Op::Just ||
901-
action.node->getOp() == DataDescriptorMatcher::Op::Not) {
902-
return ChildAction::VisitLeft;
903-
}
904-
return ChildAction::VisitBoth;
905-
},
906-
[&w](EdgeActions::EnterLeft) {
907-
w.Key("left");
908-
w.StartObject();
909-
},
910-
[&w](EdgeActions::ExitLeft) {
911-
w.EndObject();
912-
},
913-
[&w](EdgeActions::EnterRight) {
914-
w.Key("right");
915-
w.StartObject();
916-
},
917-
[&w](EdgeActions::ExitRight) {
918-
w.EndObject();
919-
},
920-
[&w](EdgeActions::ExitNode) {
921-
w.EndObject();
922-
},
923-
[&w](auto) {}};
924-
auto leafWalker = overloaded{
925-
[&w](OriginValueMatcher const& origin) {
926-
w.Key("origin");
927-
std::stringstream ss;
928-
ss << origin;
929-
w.String(ss.str().c_str());
930-
},
931-
[&w](DescriptionValueMatcher const& description) {
932-
w.Key("description");
933-
std::stringstream ss;
934-
ss << description;
935-
w.String(ss.str().c_str());
936-
},
937-
[&w](SubSpecificationTypeValueMatcher const& subspec) {
938-
w.Key("subspec");
939-
std::stringstream ss;
940-
ss << subspec;
941-
w.Uint64(std::stoul(ss.str()));
942-
},
943-
[&w](StartTimeValueMatcher const& startTime) {
944-
w.Key("starttime");
945-
std::stringstream ss;
946-
ss << startTime;
947-
w.String(ss.str().c_str());
948-
},
949-
[&w](ConstantValueMatcher const& constant) {},
950-
[&w](auto t) {}};
951-
952791
w.StartObject();
953792
w.Key("workflow");
954793
w.StartArray();
@@ -963,28 +802,27 @@ void WorkflowSerializationHelpers::dump(std::ostream& out,
963802

964803
w.Key("inputs");
965804
w.StartArray();
966-
for (auto const& input : processor.inputs) {
805+
for (auto& input : processor.inputs) {
967806
/// FIXME: this only works for a selected set of InputSpecs...
968807
/// a proper way to fully serialize an InputSpec with
969808
/// a DataDescriptorMatcher is needed.
970809
w.StartObject();
971810
w.Key("binding");
972811
w.String(input.binding.c_str());
973-
if (auto const* concrete = std::get_if<ConcreteDataMatcher>(&input.matcher)) {
812+
auto origin = DataSpecUtils::getOptionalOrigin(input);
813+
if (origin.has_value()) {
974814
w.Key("origin");
975-
w.String(concrete->origin.str, strnlen(concrete->origin.str, 4));
815+
w.String(origin->str, strnlen(origin->str, 4));
816+
}
817+
auto description = DataSpecUtils::getOptionalDescription(input);
818+
if (description.has_value()) {
976819
w.Key("description");
977-
w.String(concrete->description.str, strnlen(concrete->description.str, 16));
820+
w.String(description->str, strnlen(description->str, 16));
821+
}
822+
auto subSpec = DataSpecUtils::getOptionalSubSpec(input);
823+
if (subSpec.has_value()) {
978824
w.Key("subspec");
979-
w.Uint64(concrete->subSpec);
980-
//auto tmp = DataSpecUtils::dataDescriptorMatcherFrom(*concrete);
981-
//DataMatcherWalker::walk(tmp,
982-
// edgeWalker,
983-
// leafWalker);
984-
} else if (auto const* matcher = std::get_if<DataDescriptorMatcher>(&input.matcher)) {
985-
DataMatcherWalker::walk(*matcher,
986-
edgeWalker,
987-
leafWalker);
825+
w.Uint64(*subSpec);
988826
}
989827
w.Key("lifetime");
990828
w.Uint((int)input.lifetime);

0 commit comments

Comments
 (0)