/** * ParamTableNode.cc * * Created on: 10 oct. 2014 * Author: AKKA */ #include #include #include #include "ParamTableNode.hh" #include "Config.hh" #include "Parameter.hh" #include "ParamTable.hh" #include "ParamInfo.hh" #include "Constant.hh" using namespace log4cxx; using namespace AMDA::Parameters; using namespace AMDA::XMLConfigurator; namespace AMDA { namespace Info { /* * @brief Bounds table node */ class BoundsTable: public AMDA::XMLConfigurator::NodeCfg { public: void proceed( xmlNodePtr pNode, const AMDA::Parameters::CfgContext& context) { LOG4CXX_DEBUG(gLogger, "BoundsTable::proceed"); ParamInfo* pParamInfo = context.get(); std::string paramId = pParamInfo->getId(); //Get name xmlChar* value = xmlGetProp(pNode, (const xmlChar *) "name"); std::string name; if (value != NULL) { name = (char *)value; xmlFree(value); } //Get units value = xmlGetProp(pNode, (const xmlChar *) "units"); std::string units; if (value != NULL) { units = (char *)value; xmlFree(value); } //Get dim value = xmlGetProp(pNode, (const xmlChar *) "dim"); int dim = 0; if (value != NULL) { dim = atoi((char *)value); xmlFree(value); } //Get variable value = xmlGetProp(pNode, (const xmlChar *) "variable"); bool variable = false; if (value != NULL) { variable = (strcmp((char*)value,"true") == 0); xmlFree(value); } xmlChar* lboundsName = NULL; try { if (!(lboundsName = xmlGetProp(pNode, (const xmlChar *) "boundsName"))) { ERROR_EXCEPTION( ERROR_MANDATORY_ATTRIBUTE_MISSING << pNode->name << "@boundsName") } LOG4CXX_DEBUG(gLogger, "BoundsTable::proceed - Bounds name : " << lboundsName); boost::shared_ptr table(new ParamBoundsTable( paramId.c_str())); table->addTableParam(ParamBoundsTable::_boundsParamKey, (const char*)lboundsName); table->setName(name); table->setUnits(units); table->setIsVariable(variable); pParamInfo->addTable(dim, table); } catch (...) { if (lboundsName) { xmlFree(lboundsName); } throw; } if (lboundsName) { xmlFree(lboundsName); } } }; /* * @brief Min / Max table node */ class MinMaxTable: public AMDA::XMLConfigurator::NodeCfg { public: void proceed( xmlNodePtr pNode, const AMDA::Parameters::CfgContext& context) { LOG4CXX_DEBUG(gLogger, "MinMaxTable::proceed") ParamInfo* pParamInfo = context.get(); std::string paramId = pParamInfo->getId(); //Get name xmlChar* value = xmlGetProp(pNode, (const xmlChar *) "name"); std::string name; if (value != NULL) { name = (char *)value; xmlFree(value); } //Get units value = xmlGetProp(pNode, (const xmlChar *) "units"); std::string units; if (value != NULL) { units = (char *)value; xmlFree(value); } //Get dim value = xmlGetProp(pNode, (const xmlChar *) "dim"); int dim = 0; if (value != NULL) { dim = atoi((char *)value); xmlFree(value); } //Get variable value = xmlGetProp(pNode, (const xmlChar *) "variable"); bool variable = false; if (value != NULL) { variable = (strcmp((char*)value,"true") == 0); xmlFree(value); } xmlChar* lminTableName = NULL; xmlChar* lmaxTableName = NULL; try { if (!(lminTableName = xmlGetProp(pNode, (const xmlChar *) "minName"))) { ERROR_EXCEPTION( ERROR_MANDATORY_ATTRIBUTE_MISSING << pNode->name << "@minName") } if (!(lmaxTableName = xmlGetProp(pNode, (const xmlChar *) "maxName"))) { ERROR_EXCEPTION( ERROR_MANDATORY_ATTRIBUTE_MISSING << pNode->name << "@maxName") } LOG4CXX_DEBUG(gLogger, "MinMaxTable::proceed - Min Table name : " << lminTableName << " - Max Table name : " << lmaxTableName); boost::shared_ptr table(new ParamMinMaxTable( paramId.c_str())); table->addTableParam(ParamMinMaxTable::_minParamKey, (const char*)lminTableName); table->addTableParam(ParamMinMaxTable::_maxParamKey, (const char*)lmaxTableName); table->setName(name); table->setUnits(units); table->setIsVariable(variable); pParamInfo->addTable(dim,table); } catch (...) { if (lminTableName) xmlFree(lminTableName); if (lmaxTableName) xmlFree(lmaxTableName); throw; } if (lminTableName) xmlFree(lminTableName); if (lmaxTableName) xmlFree(lmaxTableName); } }; /* * @brief Center table node */ class CenterTable: public AMDA::XMLConfigurator::NodeCfg { public: void proceed( xmlNodePtr pNode, const AMDA::Parameters::CfgContext& context) { LOG4CXX_DEBUG(gLogger, "CenterTable::proceed"); ParamInfo* pParamInfo = context.get(); std::string paramId = pParamInfo->getId(); //Get name xmlChar* value = xmlGetProp(pNode, (const xmlChar *) "name"); std::string name; if (value != NULL) { name = (char *)value; xmlFree(value); } //Get units value = xmlGetProp(pNode, (const xmlChar *) "units"); std::string units; if (value != NULL) { units = (char *)value; xmlFree(value); } //Get dim value = xmlGetProp(pNode, (const xmlChar *) "dim"); int dim = 0; if (value != NULL) { dim = atoi((char *)value); xmlFree(value); } //Get variable value = xmlGetProp(pNode, (const xmlChar *) "variable"); bool variable = false; if (value != NULL) { variable = (strcmp((char*)value,"true") == 0); xmlFree(value); } xmlChar* lcenterName = NULL; xmlChar* lsize = NULL; try { if (!(lcenterName = xmlGetProp(pNode, (const xmlChar *) "centerName"))) { ERROR_EXCEPTION( ERROR_MANDATORY_ATTRIBUTE_MISSING << pNode->name << "@centerName") } LOG4CXX_DEBUG(gLogger, "BoundsTable::proceed - Center name : " << lcenterName); if (!(lsize = xmlGetProp(pNode, (const xmlChar *) "size"))) { ERROR_EXCEPTION( ERROR_MANDATORY_ATTRIBUTE_MISSING << pNode->name << "@size") } boost::shared_ptr table(new ParamCenterTable( paramId.c_str(), atof((const char*)lsize))); table->addTableParam(ParamCenterTable::_centersParamKey, (const char*)lcenterName); table->setName(name); table->setUnits(units); table->setIsVariable(variable); pParamInfo->addTable(dim, table); } catch (...) { if (lcenterName) { xmlFree(lcenterName); } if (lsize) { xmlFree(lsize); } throw; } if (lcenterName) { xmlFree(lcenterName); } if (lsize) { xmlFree(lsize); } } }; /* * @brief Center table node with band width */ class CenterWidthTable: public AMDA::XMLConfigurator::NodeCfg { public: void proceed( xmlNodePtr pNode, const AMDA::Parameters::CfgContext& context) { LOG4CXX_DEBUG(gLogger, "CenterWidthTable::proceed"); ParamInfo* pParamInfo = context.get(); std::string paramId = pParamInfo->getId(); //Get name xmlChar* value = xmlGetProp(pNode, (const xmlChar *) "name"); std::string name; if (value != NULL) { name = (char *)value; xmlFree(value); } //Get units value = xmlGetProp(pNode, (const xmlChar *) "units"); std::string units; if (value != NULL) { units = (char *)value; xmlFree(value); } //Get dim value = xmlGetProp(pNode, (const xmlChar *) "dim"); int dim = 0; if (value != NULL) { dim = atoi((char *)value); xmlFree(value); } //Get variable value = xmlGetProp(pNode, (const xmlChar *) "variable"); bool variable = false; if (value != NULL) { variable = (strcmp((char*)value,"true") == 0); xmlFree(value); } xmlChar* lcenterName = NULL; xmlChar* lwidthName = NULL; try { if (!(lcenterName = xmlGetProp(pNode, (const xmlChar *) "centerName"))) { ERROR_EXCEPTION( ERROR_MANDATORY_ATTRIBUTE_MISSING << pNode->name << "@centerName") } LOG4CXX_DEBUG(gLogger, "CenterWidthTable::proceed - Center name : " << lcenterName); if (!(lwidthName = xmlGetProp(pNode, (const xmlChar *) "widthName"))) { ERROR_EXCEPTION( ERROR_MANDATORY_ATTRIBUTE_MISSING << pNode->name << "@centerName") } LOG4CXX_DEBUG(gLogger, "CenterWidthTable::proceed - Width name : " << lwidthName); boost::shared_ptr table(new ParamCenterWidthTable( paramId.c_str())); table->addTableParam(ParamCenterWidthTable::_centersParamKey, (const char*)lcenterName); table->addTableParam(ParamCenterWidthTable::_widthsParamKey, (const char*)lwidthName); table->setName(name); table->setUnits(units); table->setIsVariable(variable); pParamInfo->addTable(dim, table); } catch (...) { if (lcenterName) { xmlFree(lcenterName); } if (lwidthName) { xmlFree(lwidthName); } throw; } if (lcenterName) { xmlFree(lcenterName); } if (lwidthName) { xmlFree(lwidthName); } } }; /* * @brief Center table node - Bounds automatically computed to be at the center of two consecutive channels */ class CenterAutoTable: public AMDA::XMLConfigurator::NodeCfg { public: void proceed( xmlNodePtr pNode, const AMDA::Parameters::CfgContext& context) { LOG4CXX_DEBUG(gLogger, "CenterAutoTable::proceed"); ParamInfo* pParamInfo = context.get(); std::string paramId = pParamInfo->getId(); //Get name xmlChar* value = xmlGetProp(pNode, (const xmlChar *) "name"); std::string name; if (value != NULL) { name = (char *)value; xmlFree(value); } //Get units value = xmlGetProp(pNode, (const xmlChar *) "units"); std::string units; if (value != NULL) { units = (char *)value; xmlFree(value); } //Get dim value = xmlGetProp(pNode, (const xmlChar *) "dim"); int dim = 0; if (value != NULL) { dim = atoi((char *)value); xmlFree(value); } //Get variable value = xmlGetProp(pNode, (const xmlChar *) "variable"); bool variable = false; if (value != NULL) { variable = (strcmp((char*)value,"true") == 0); xmlFree(value); } xmlChar* lcenterName = NULL; try { xmlChar* llog = NULL; if (!(lcenterName = xmlGetProp(pNode, (const xmlChar *) "centerName"))) { ERROR_EXCEPTION( ERROR_MANDATORY_ATTRIBUTE_MISSING << pNode->name << "@centerName") } LOG4CXX_DEBUG(gLogger, "CenterAutoTable::proceed - Center name : " << lcenterName); bool isLog = false; if ((llog = xmlGetProp(pNode, (const xmlChar *) "log"))) { isLog = (strcmp((char*)llog, "true") == 0); xmlFree(llog); } boost::shared_ptr table(new ParamCenterAutoTable( paramId.c_str(), isLog)); table->addTableParam(ParamCenterAutoTable::_centersParamKey, (const char*)lcenterName); table->setName(name); table->setUnits(units); table->setIsVariable(variable); pParamInfo->addTable(dim, table); } catch (...) { if (lcenterName) { xmlFree(lcenterName); } throw; } if (lcenterName) { xmlFree(lcenterName); } } }; /* * @brief table node */ ParamTableNode::ParamTableNode() : AMDA::XMLConfigurator::NodeGrpCfg() { getChildList()["boundsTable"]=NodeCfgSPtr(new BoundsTable); getChildList()["minMaxTable"]=NodeCfgSPtr(new MinMaxTable); getChildList()["centerTable"]=NodeCfgSPtr(new CenterTable); getChildList()["centerWidthTable"]=NodeCfgSPtr(new CenterWidthTable); getChildList()["centerAutoTable"]=NodeCfgSPtr(new CenterAutoTable); } ParamTableNode::~ParamTableNode() { } void ParamTableNode::proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext) { LOG4CXX_DEBUG(gLogger, "ParamTableNode::proceed"); AMDA::Parameters::CfgContext lContext(pContext); ParamInfo* pParamInfo = pContext.get(); lContext.push(pParamInfo); NodeGrpCfg::proceed(pNode, lContext); } }/* namespace Info */ } /* namespace AMDA */