diff --git a/include/VariableMapper.h b/include/VariableMapper.h index 221db9af744175168a5033cc64e78eead51fc210..afa68a6bff04b0a16bd8ec2cef59774a02aef98a 100644 --- a/include/VariableMapper.h +++ b/include/VariableMapper.h @@ -53,6 +53,7 @@ namespace ChimeraTK{ void processLocationNode(xmlpp::Node const * locationNode); void processPropertyNode(xmlpp::Node const * propertyNode, std::string locationName); void processSpectrumNode(xmlpp::Node const * node, std::string locationName); + void processArrayNode(xmlpp::Node const * node, std::string locationName); void processImportNode(xmlpp::Node const * importNode, std::string importLocationName=std::string()); void import(std::string importSource, std::string importLocationName, std::string directory=""); diff --git a/src/VariableMapper.cc b/src/VariableMapper.cc index 8c1035a0b682e97ec4a957c2fe0bb169e029e0e7..001151bb4f1d6f0e72fc663d98d331f404a9a2de 100644 --- a/src/VariableMapper.cc +++ b/src/VariableMapper.cc @@ -50,6 +50,8 @@ namespace ChimeraTK{ locationInfo.isWriteable = evaluateBool(getContentString(node)); }else if (node->get_name() == "D_spectrum"){ processSpectrumNode(node, locationName); + }else if (node->get_name() == "D_array"){ + processArrayNode(node, locationName); }else{ throw std::invalid_argument(std::string("Error parsing xml file in location ") + locationName + ": Unknown node '"+node->get_name()+"'"); } @@ -149,6 +151,40 @@ namespace ChimeraTK{ addDescription(spectrumDescription, absoluteSource); } + void VariableMapper::processArrayNode(xmlpp::Node const * node, std::string locationName){ + auto arrayXml = asXmlElement(node); + + // the "main source" of a spectum + std::string source = getAttributeValue(arrayXml, "source"); + std::string name = determineName(arrayXml, source); + + const xmlpp::Attribute* typeAttribute = arrayXml->get_attribute("type"); + std::map< std::string, ArrayDescription::DataType > dataTypeMap( + { {"auto", ArrayDescription::DataType::Auto}, + {"byte", ArrayDescription::DataType::Byte}, + {"short", ArrayDescription::DataType::Short}, + {"int", ArrayDescription::DataType::Int}, + {"long", ArrayDescription::DataType::Long}, + {"float", ArrayDescription::DataType::Float}, + {"double", ArrayDescription::DataType::Double} }); + + ArrayDescription::DataType type; + if (typeAttribute){ + type = dataTypeMap[typeAttribute->get_value()]; + }else{ + type = ArrayDescription::DataType::Auto; + } + + std::string absoluteSource = getAbsoluteSource(source, locationName); + + // prepare the property description + auto arrayDescription = std::make_shared<ArrayDescription>(absoluteSource, locationName, name); + + processHistoryAndWritableAttributes(arrayDescription, arrayXml, locationName); + + addDescription(arrayDescription, absoluteSource); + } + void VariableMapper::processImportNode(xmlpp::Node const * importNode, std::string importLocationName){ const xmlpp::Element* importElement = dynamic_cast<const xmlpp::Element*>(importNode); std::string directory; diff --git a/tests/src/serverTestSpectrumArray.cpp b/tests/src/serverTestSpectrumArray.cpp index 92dddca1cfb40756aeeb52feb1982e36282d8561..615c8f0ec24a60954fe14aae7e16676d10bf0f86 100644 --- a/tests/src/serverTestSpectrumArray.cpp +++ b/tests/src/serverTestSpectrumArray.cpp @@ -41,7 +41,7 @@ void testReadWrite(){ // running update now does not change anything, the application has not acted yet DoocsServerTestHelper::runUpdate(); - auto notIntArray = DoocsServerTestHelper::doocsGetArray<float>("//INT/FROM_DEVICE_ARRAY"); + auto notIntArray = DoocsServerTestHelper::doocsGetArray<float>("//INT/MY_RENAMED_INTARRAY"); for (auto val : notIntArray){ BOOST_CHECK( std::fabs(val) < 0.001 ); } @@ -53,7 +53,7 @@ void testReadWrite(){ // run the application loop. Still no changes until we run the doocs server update referenceTestApplication.runMainLoopOnce(); - notIntArray = DoocsServerTestHelper::doocsGetArray<float>("//INT/FROM_DEVICE_ARRAY"); + notIntArray = DoocsServerTestHelper::doocsGetArray<float>("//INT/MY_RENAMED_INTARRAY"); for (auto val : notIntArray){ BOOST_CHECK( std::fabs(val) < 0.001 ); } @@ -65,7 +65,7 @@ void testReadWrite(){ // now finally after the next update we should see the new data in doocs DoocsServerTestHelper::runUpdate(); - notIntArray = DoocsServerTestHelper::doocsGetArray<float>("//INT/FROM_DEVICE_ARRAY"); + notIntArray = DoocsServerTestHelper::doocsGetArray<float>("//INT/MY_RENAMED_INTARRAY"); int testVal = 140; for (auto val : notIntArray){ BOOST_CHECK( std::fabs(val - testVal++) < 0.001 );