Commit ad920fd6b9bcc9c49dc666ad74a39e1482d53c55

Authored by Benjamin Renard
1 parent a6490f4d

First implementation of amdaParameterInfo executable to get information about a parameter

CMakeLists.txt
... ... @@ -69,6 +69,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
69 69 add_subdirectory(src/XMLRequest)
70 70 add_subdirectory(src/amdaXMLRequestorTool)
71 71 add_subdirectory(src/amdaParameterGenerator)
  72 + add_subdirectory(src/amdaParameterInfo)
72 73 add_subdirectory(src/PostProcessing)
73 74 add_subdirectory(src/ParamOutputImpl/Download)
74 75 add_subdirectory(src/ParamOutputImpl/IntervalTrue)
... ... @@ -82,6 +83,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
82 83 add_subdirectory(src/InternLib)
83 84 add_subdirectory(src/ExternLib/Deriv)
84 85 add_subdirectory(src/ExternLib/Magnitude)
  86 + #add_subdirectory(src/ExternLib/Morschhauser)
85 87 add_subdirectory(src/ExternLib/Ram_Presure)
86 88 add_subdirectory(src/ExternLib/TimeShifted)
87 89 add_subdirectory(src/ExternLib/GetClbInfo)
... ...
src/Parameters/ParamData.hh
... ... @@ -88,6 +88,9 @@ public:
88 88 virtual const char *getParamDataType() = 0;
89 89 virtual const char *getElementType() = 0;
90 90  
  91 + virtual unsigned int getDim1()= 0;
  92 + virtual unsigned int getDim2()= 0;
  93 +
91 94 unsigned int getDataNumber() { return _blockTimeTab.size(); }
92 95  
93 96 protected:
... ... @@ -133,6 +136,9 @@ public:
133 136  
134 137 void push(ElementType el) { _dataList.push_back(el); }
135 138  
  139 + virtual unsigned int getDim1() { return _dim1; }
  140 + virtual unsigned int getDim2() { return _dim2; }
  141 +
136 142 /**
137 143 * design pattern visitor
138 144 * accept a visitor
... ...
src/amdaParameterInfo/CMakeLists.txt 0 → 100644
... ... @@ -0,0 +1,45 @@
  1 +
  2 +PROJECT(amdaParameterInfo)
  3 +
  4 +include_directories(
  5 + ${CMAKE_HOME_DIRECTORY}/src/helpers/
  6 + ${CMAKE_HOME_DIRECTORY}/src/Info/
  7 + ${CMAKE_HOME_DIRECTORY}/src/Common/
  8 + ${CMAKE_HOME_DIRECTORY}/src/Parameters/
  9 + ${CMAKE_HOME_DIRECTORY}/src/PostProcessing/
  10 + ${CMAKE_HOME_DIRECTORY}/src/XMLConfigurator/
  11 + ${CMAKE_HOME_DIRECTORY}/src/XMLParameterConfigurator/
  12 + ${CMAKE_HOME_DIRECTORY}/src/Plugins/
  13 + ${CMAKE_HOME_DIRECTORY}/src/TimeTableCatalog/
  14 + ${LOG4CXX_INCLUDE_DIR}
  15 + ${LIBXML2_INCLUDE_DIR}
  16 + ${Boost_INCLUDE_DIR}
  17 +)
  18 +
  19 +#Configuration de la librairie
  20 +file(
  21 + GLOB_RECURSE
  22 + source_files
  23 + ./*
  24 +)
  25 +
  26 +ADD_EXECUTABLE( amdaParameterInfo ${source_files} )
  27 +
  28 +
  29 +target_link_libraries(
  30 + amdaParameterInfo
  31 + AMDA_COMMON
  32 + ${CMAKE_THREAD_LIBS_INIT}
  33 + Parameters
  34 + ${LOG4CXX_LIBRARIES}
  35 + ${LIBXML2_LIBRARIES}
  36 + Plugin
  37 + XMLParameterConfigurator
  38 + ${BOOST_ROOT}/lib/libboost_system.so
  39 + ${BOOST_ROOT}/lib/libboost_thread.so
  40 + ${BOOST_ROOT}/lib/libboost_program_options.so
  41 + ParamOutputImpl
  42 + TimeTableCatalog
  43 + Info
  44 + ${DDCLIENTLIBRARY}
  45 +)
... ...
src/amdaParameterInfo/Main.cc 0 → 100644
... ... @@ -0,0 +1,103 @@
  1 +/**
  2 + * Main.cc
  3 + * Created on: 18 mar. 2016
  4 + * Author: AKKA IS
  5 + */
  6 +
  7 +#include <iostream>
  8 +
  9 +#include <boost/program_options.hpp>
  10 +
  11 +#include "AMDA-Kernel_Config.hh"
  12 +#include <Application.hh>
  13 +
  14 +// Parameters module include
  15 +#include "ParameterManager.hh"
  16 +#include "Parameter.hh"
  17 +#include "Process.hh"
  18 +#include "ParameterInfo.hh"
  19 +#include "ServicesServer.hh"
  20 +
  21 +using namespace std;
  22 +namespace po = boost::program_options;
  23 +using namespace log4cxx;
  24 +using namespace log4cxx::helpers;
  25 +using namespace AMDA::Parameters;
  26 +
  27 +
  28 +/**
  29 + * Main function
  30 + */
  31 +int main(int argc, char *argv[]) {
  32 + int result = AMDA_EXIT_OK;
  33 +
  34 + /// Parse command line parameters
  35 + po::options_description desc("Allowed options");
  36 +
  37 + desc.add_options()
  38 + ("help,h", "Produce help message")
  39 + ("version,v", "Program version")
  40 + ("parameter,p", po::value< vector<string> >(), "Parameter(s) name")
  41 + ;
  42 +
  43 + po::positional_options_description p;
  44 + p.add("parameter", -1);
  45 +
  46 + po::variables_map vm;
  47 + po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
  48 + po::notify(vm);
  49 +
  50 + if (vm.count("help")) {
  51 + cout << desc << "\n";
  52 + return result;
  53 + }
  54 + if (vm.count("version")) {
  55 + cout << "Version: " << AMDA_Kernel_VERSION << "\n";
  56 + return result;
  57 + }
  58 +
  59 + if (!vm.count("parameter")) {
  60 + return result;
  61 + }
  62 +
  63 + AMDA::Common::Application lMain;
  64 +
  65 + return lMain.main(argc,argv,[&](int argc, char *argv[], AMDA::helpers::Properties& lProperties) -> int {
  66 +
  67 + vector<string> lParameterList = vm["parameter"].as< vector<string> >();
  68 +
  69 + ///Create ParameterManager and configuration
  70 + ParameterManager parameterManager;
  71 + std::string emptyStr;
  72 + parameterManager.addInputInterval(0, 0, 0, emptyStr, emptyStr, 0);
  73 +
  74 + if (!lProperties["app.param.gapthreshold"].empty())
  75 + {
  76 + double defaultGapThreshold = 0.;
  77 + defaultGapThreshold = atof(lProperties["app.param.gapthreshold"].c_str());
  78 + if (defaultGapThreshold > 0.)
  79 + parameterManager.setDefaultGapThreshold(defaultGapThreshold);
  80 + }
  81 +
  82 + for (auto lParamName : lParameterList) {
  83 + try {
  84 + ///Create Parameter
  85 + parameterManager.createParameter(lParamName);
  86 +
  87 + ///Generate Output
  88 + AMDA::Parameters::ParameterInfo* lParameterInfo =
  89 + new AMDA::Parameters::ParameterInfo(parameterManager);
  90 + ParamOutputSPtr lParamOutput(lParameterInfo);
  91 + lParameterInfo->setParamName(lParamName);
  92 + parameterManager.getParamOutputList().push_back( lParamOutput);
  93 + } catch (...) {
  94 + }
  95 + }
  96 + /// launch request
  97 + parameterManager.execute("");
  98 +
  99 + return result;
  100 +});
  101 +
  102 +}
  103 +
... ...
src/amdaParameterInfo/ParameterInfo.cc 0 → 100644
... ... @@ -0,0 +1,161 @@
  1 +/*
  2 + * ParameterInfo.cc
  3 + *
  4 + * Created on: Mar 18 2016
  5 + * Author: b.renard
  6 + */
  7 +
  8 +#include "ParameterInfo.hh"
  9 +
  10 +#include <boost/algorithm/string.hpp>
  11 +#include <string>
  12 +
  13 +namespace AMDA {
  14 +namespace Parameters {
  15 +
  16 +ParameterInfo::ParameterInfo(ParameterManager& pParameterManager) :
  17 + ParamOutput(pParameterManager),
  18 + _parameter(NULL) {
  19 +}
  20 +
  21 +ParameterInfo::~ParameterInfo() {
  22 +}
  23 +
  24 +void ParameterInfo::establishConnection() {
  25 + _parameter = _parameterManager.getSampledParameter(_paramName, _samplingMode, _samplingValue, _gapThreshold).get();
  26 + if(_parameter == NULL) {
  27 + LOG4CXX_ERROR(_logger,"ParamOutput::init parameter : \""<< _paramName <<"\" Not Exist" );
  28 + BOOST_THROW_EXCEPTION( ParamOutput_exception());
  29 + }
  30 + _parameter->openConnection(this);
  31 +}
  32 +
  33 +
  34 +void ParameterInfo::init() {
  35 + _parameter->init(this, _timeIntervalList);
  36 +
  37 + AMDA::ParameterInfo::ParameterInfoFileWriter fileWriter;
  38 +
  39 + std::stringstream filePath;
  40 + filePath << "info_" << _paramName.c_str() << ".xml";
  41 + fileWriter.initWriter(filePath.str().c_str());
  42 + fileWriter.addAttribute("id", _parameter->getId().c_str());
  43 +
  44 + unsigned int dim1 = _parameter->getDataWriterTemplate()->getParamData()->getDim1();
  45 + unsigned int dim2 = _parameter->getDataWriterTemplate()->getParamData()->getDim2();
  46 +
  47 + //Write dimensions info
  48 + fileWriter.startElement("dimensions"); /* dimensions */
  49 + std::string dim_1 = std::to_string(dim1);
  50 + std::string dim_2 = std::to_string(dim2);
  51 + fileWriter.addAttribute("dim_1",dim_1.c_str());
  52 + fileWriter.addAttribute("dim_2",dim_2.c_str());
  53 + fileWriter.endElement(); /* dimensions */
  54 +
  55 + //Write components info
  56 + std::vector<std::string> components = this->getComponents();
  57 + if (!components.empty()) {
  58 + fileWriter.startElement("components"); /* components */
  59 +
  60 + for (int i = 0; i < (int)dim1; ++i) {
  61 + for (int j = 0; j < (int)dim2; ++j) {
  62 + fileWriter.startElement("component"); /* component */
  63 + std::string index_1 = std::to_string(i);
  64 + std::string index_2 = std::to_string(j);
  65 +
  66 + fileWriter.addAttribute("index_1",index_1.c_str());
  67 + if (dim2 > 1)
  68 + fileWriter.addAttribute("index_2",index_2.c_str());
  69 + fileWriter.addAttribute("name",(components[i*(int)dim2+j]).c_str());
  70 + fileWriter.endElement(); /* component */
  71 + }
  72 + }
  73 +
  74 + fileWriter.endElement(); /* components */
  75 + }
  76 +
  77 + // Write tables info
  78 + AMDA::Info::ParamInfoSPtr paramInfo = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(_parameter->getInfoId());
  79 +
  80 + fileWriter.startElement("tables"); /* tables */
  81 + boost::shared_ptr<AMDA::Info::ParamTable> table1SPtr = paramInfo->getTable(0);
  82 + if (table1SPtr != nullptr) {
  83 + this->writeTable(table1SPtr, fileWriter, "dim_1");
  84 + }
  85 +
  86 + boost::shared_ptr<AMDA::Info::ParamTable> table2SPtr = paramInfo->getTable(1);
  87 + if (table2SPtr != nullptr) {
  88 + this->writeTable(table2SPtr, fileWriter, "dim_2");
  89 + }
  90 +
  91 + fileWriter.endElement(); /* tables */
  92 +
  93 + fileWriter.closeWriter();
  94 +}
  95 +
  96 +std::vector<std::string> ParameterInfo::getComponents() {
  97 + unsigned int dim1 = _parameter->getDataWriterTemplate()->getParamData()->getDim1();
  98 + unsigned int dim2 = _parameter->getDataWriterTemplate()->getParamData()->getDim2();
  99 +
  100 + AMDA::Info::ParamInfoSPtr paramInfo = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(_parameter->getInfoId());
  101 +
  102 + std::vector<std::string> components;
  103 +
  104 + if ( dim1 * dim2 <= 1 ) //scalar => no components
  105 + return components;
  106 +
  107 + std::string componentsStr = paramInfo->getComponents();
  108 +
  109 + //Split labels
  110 + boost::split(components,componentsStr,boost::is_any_of(","));
  111 +
  112 + if (components.size() != dim1 * dim2) {
  113 + //If labels not defined (or misdefined)
  114 + components.clear();
  115 + for (int i = 0; i < (int)dim1; ++i) {
  116 + for (int j = 0; j < (int)dim2; ++j) {
  117 + std::string crtComp;
  118 + crtComp += (!paramInfo->getShortName().empty() ? paramInfo->getShortName() : paramInfo->getId());
  119 + crtComp += "[";
  120 + if (dim1 > 1)
  121 + crtComp += std::to_string(i);
  122 + if (dim1 > 1 && dim2 > 1)
  123 + crtComp += ",";
  124 + if (dim2 > 1)
  125 + crtComp += std::to_string(j);
  126 + crtComp += "]";
  127 + components.push_back(crtComp);
  128 + }
  129 + }
  130 + }
  131 +
  132 + return components;
  133 +}
  134 +
  135 +void ParameterInfo::writeTable(boost::shared_ptr<AMDA::Info::ParamTable> tableSPtr, AMDA::ParameterInfo::ParameterInfoFileWriter& fileWriter, std::string relatedDim) {
  136 + if (tableSPtr == nullptr)
  137 + return;
  138 + fileWriter.startElement("table"); /* table */
  139 + fileWriter.addAttribute("relatedDim", relatedDim.c_str() );
  140 + if (tableSPtr->isVariable()) {
  141 + fileWriter.addAttribute("variable","true");
  142 + }
  143 + else {
  144 + fileWriter.addAttribute("name",tableSPtr->getName().c_str());
  145 + fileWriter.addAttribute("units",tableSPtr->getUnits().c_str());
  146 + for (int i = 0; i < tableSPtr->getSize(&_parameter->getParameterManager()); ++i) {
  147 + AMDA::Info::t_TableBound bound = tableSPtr->getBound(&_parameter->getParameterManager(),i);
  148 + fileWriter.startElement("channel"); /* channel */
  149 + std::string min = std::to_string(bound.min);
  150 + std::string max = std::to_string(bound.max);
  151 + fileWriter.addAttribute("min",min.c_str());
  152 + fileWriter.addAttribute("max",max.c_str());
  153 + fileWriter.endElement(); /* channel */
  154 + }
  155 + }
  156 + fileWriter.endElement(); /* table */
  157 +}
  158 +
  159 +
  160 +} /* namespace Parameters */
  161 +} /* namespace AMDA */
... ...
src/amdaParameterInfo/ParameterInfo.hh 0 → 100644
... ... @@ -0,0 +1,70 @@
  1 +/*
  2 + * ParameterInfo.hh
  3 + *
  4 + * Created on: Mar 18, 2016
  5 + * Author: b.renard
  6 + */
  7 +
  8 +#ifndef PARAMETERINFO_HH_
  9 +#define PARAMETERINFO_HH_
  10 +
  11 +#include "ParamOutput.hh"
  12 +
  13 +#include "ParamMgr.hh"
  14 +#include "ParameterInfoFileWriter.hh"
  15 +
  16 +namespace AMDA {
  17 +namespace Parameters {
  18 +
  19 +/**
  20 + * @class ParameterInfo
  21 + * @brief Get information about a given parameter.
  22 + * @details
  23 + */
  24 +class ParameterInfo: public AMDA::Parameters::ParamOutput {
  25 +public:
  26 + /**
  27 + * Constructor.
  28 + */
  29 + ParameterInfo(AMDA::Parameters::ParameterManager& pParameterManager);
  30 + /**
  31 + * Destructor.
  32 + */
  33 + virtual ~ParameterInfo();
  34 +
  35 + // Getter methods
  36 + const std::string& getParamName() const { return _paramName; }
  37 +
  38 + // Setter methods
  39 + void setParamName(const std::string& paramName) { _paramName = paramName; }
  40 +
  41 + /**
  42 + * @overload DataClient::establishConnection()
  43 + */
  44 + virtual void establishConnection();
  45 +
  46 + /**
  47 + * @overload ParamOutput::apply()
  48 + * @brief Empty method.
  49 + */
  50 + virtual void apply() {}
  51 +
  52 +protected:
  53 +
  54 + /**
  55 + * @overload ParamOutput::init()
  56 + */
  57 + virtual void init();
  58 +
  59 +private:
  60 + AMDA::Parameters::Parameter* _parameter;
  61 + std::string _paramName;
  62 +
  63 + std::vector<std::string> getComponents();
  64 +
  65 + void writeTable(boost::shared_ptr<AMDA::Info::ParamTable> table1SPtr, AMDA::ParameterInfo::ParameterInfoFileWriter& fileWriter, std::string relatedDim);
  66 +};
  67 +
  68 +} /* namespace Parameters */
  69 +} /* namespace AMDA */
  70 +#endif /* PARAMETERINFO_HH_ */
... ...
src/amdaParameterInfo/ParameterInfoFileWriter.cc 0 → 100644
... ... @@ -0,0 +1,97 @@
  1 +/*
  2 + * ParameterInfoFileWriter.cc
  3 + *
  4 + * Created on: 18 mar. 2016
  5 + * Author: AKKA
  6 + */
  7 +
  8 +#include "ParameterInfoFileWriter.hh"
  9 +
  10 +namespace AMDA
  11 +{
  12 +namespace ParameterInfo
  13 +{
  14 +
  15 +
  16 +ParameterInfoFileWriter::ParameterInfoFileWriter() : _writer(NULL) {
  17 +
  18 +}
  19 +
  20 +ParameterInfoFileWriter::~ParameterInfoFileWriter() {
  21 + closeWriter();
  22 +}
  23 +
  24 +bool ParameterInfoFileWriter::initWriter(const char* filePath) {
  25 + if (_writer != NULL)
  26 + return false;
  27 +
  28 + LIBXML_TEST_VERSION
  29 +
  30 + _writer = xmlNewTextWriterFilename(filePath, 0);
  31 + if (_writer == NULL) {
  32 + return false;
  33 + }
  34 +
  35 + int rc;
  36 + rc = xmlTextWriterStartDocument(_writer, "1.0", "UTF-8", NULL);
  37 +
  38 + if (rc < 0) {
  39 + return false;
  40 + }
  41 +
  42 + return startElement("paraminfo");
  43 +}
  44 +
  45 +bool ParameterInfoFileWriter::closeWriter() {
  46 + if (_writer == NULL)
  47 + return false;
  48 +
  49 + int rc = xmlTextWriterEndDocument(_writer);
  50 + if (rc < 0)
  51 + return false;
  52 +
  53 + xmlFreeTextWriter(_writer);
  54 +
  55 + _writer = NULL;
  56 +
  57 + return true;
  58 +}
  59 +
  60 +bool ParameterInfoFileWriter::startElement(const char* name) {
  61 + if (_writer == NULL)
  62 + return false;
  63 +
  64 + int rc = xmlTextWriterStartElement(_writer, BAD_CAST name);
  65 + if (rc < 0) {
  66 + return false;
  67 + }
  68 +
  69 + return true;
  70 +}
  71 +
  72 +bool ParameterInfoFileWriter::endElement() {
  73 + if (_writer == NULL)
  74 + return false;
  75 +
  76 + int rc = xmlTextWriterEndElement(_writer);
  77 + if (rc < 0) {
  78 + return false;
  79 + }
  80 +
  81 + return true;
  82 +}
  83 +
  84 +bool ParameterInfoFileWriter::addAttribute(const char* name, const char* value) {
  85 + if (_writer == NULL)
  86 + return false;
  87 +
  88 + int rc = xmlTextWriterWriteAttribute(_writer, BAD_CAST name, BAD_CAST value);
  89 + if (rc < 0) {
  90 + return false;
  91 + }
  92 +
  93 + return false;
  94 +}
  95 +
  96 +} /* namespace ParameterInfo */
  97 +} /* namespace AMDA */
... ...
src/amdaParameterInfo/ParameterInfoFileWriter.hh 0 → 100644
... ... @@ -0,0 +1,39 @@
  1 +/*
  2 + * ParameterInfoFileWriter.hh
  3 + *
  4 + * Created on: 18 mar. 2016
  5 + * Author: AKKA
  6 + */
  7 +
  8 +#ifndef PARAMETERINFOFILEWRITER_HH_
  9 +#define PARAMETERINFOFILEWRITER_HH_
  10 +
  11 +#include <libxml/xmlwriter.h>
  12 +
  13 +namespace AMDA {
  14 +namespace ParameterInfo {
  15 +
  16 +class ParameterInfoFileWriter {
  17 +public:
  18 + ParameterInfoFileWriter();
  19 +
  20 + virtual ~ParameterInfoFileWriter();
  21 +
  22 + bool initWriter(const char* filePath);
  23 +
  24 + bool closeWriter();
  25 +
  26 + bool startElement(const char* name);
  27 +
  28 + bool endElement();
  29 +
  30 + bool addAttribute(const char* name, const char* value);
  31 +
  32 +private:
  33 + xmlTextWriterPtr _writer;
  34 +};
  35 +
  36 +} /* namespace ParameterInfo */
  37 +} /* namespace AMDA */
  38 +
  39 +#endif
... ...