| 42 | } |
| 43 | |
| 44 | void TransformationXMLFile::store(const String& filename, const TransformationDescription& transformation) |
| 45 | { |
| 46 | if (transformation.getModelType().empty()) |
| 47 | { |
| 48 | throw Exception::IllegalArgument(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "will not write a transformation with empty name"); |
| 49 | } |
| 50 | |
| 51 | //open stream |
| 52 | std::ofstream os(filename.c_str()); |
| 53 | if (!os) |
| 54 | { |
| 55 | throw Exception::UnableToCreateFile(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, filename); |
| 56 | } |
| 57 | os.precision(writtenDigits<double>(0.0)); |
| 58 | |
| 59 | //write header |
| 60 | os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; |
| 61 | //add XSLT file if it can be found |
| 62 | os << "<TrafoXML version=\"" << getVersion() << "\" xsi:noNamespaceSchemaLocation=\"https://raw.githubusercontent.com/OpenMS/OpenMS/develop/share/OpenMS/SCHEMAS/" |
| 63 | << schema_location_.suffix('/') << "\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n"; |
| 64 | |
| 65 | // open tag |
| 66 | os << "\t<Transformation name=\"" << transformation.getModelType() |
| 67 | << "\">\n"; |
| 68 | |
| 69 | // write parameters |
| 70 | const Param& params = transformation.getModelParameters(); |
| 71 | for (Param::ParamIterator it = params.begin(); it != params.end(); ++it) |
| 72 | { |
| 73 | if (it->value.valueType() != ParamValue::EMPTY_VALUE) |
| 74 | { |
| 75 | switch (it->value.valueType()) |
| 76 | { |
| 77 | case ParamValue::INT_VALUE: |
| 78 | os << "\t\t<Param type=\"int\" name=\"" << it->name << "\" value=\"" << it->value.toString() << "\"/>\n"; |
| 79 | break; |
| 80 | |
| 81 | case ParamValue::DOUBLE_VALUE: |
| 82 | os << "\t\t<Param type=\"float\" name=\"" << it->name << "\" value=\"" << it->value.toString() << "\"/>\n"; |
| 83 | break; |
| 84 | |
| 85 | case ParamValue::STRING_VALUE: |
| 86 | case ParamValue::STRING_LIST: |
| 87 | case ParamValue::INT_LIST: |
| 88 | case ParamValue::DOUBLE_LIST: |
| 89 | os << "\t\t<Param type=\"string\" name=\"" << it->name << "\" value=\"" << it->value.toString() << "\"/>\n"; |
| 90 | break; |
| 91 | |
| 92 | default: // no other value types are supported! |
| 93 | fatalError(STORE, String("Unsupported parameter type of parameter '") + it->name + "'"); |
| 94 | break; |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | //write pairs |
| 100 | if (!transformation.getDataPoints().empty()) |
| 101 | { |