Commit 65c661e85c776c5f01797b81e78281c5968ec3c9

Authored by Benjamin Renard
1 parent 47e87499

Table definition with only center defined (min max bounds are automatically computed)

Fix a bug in DD_SetTimeInfo
Fix "total" function to not sum NaN componants
Stereo A SWEA-PAD parameter definition
config/DataBaseParameters/cass_caps_snghr5.xml 0 → 100644
... ... @@ -0,0 +1,28 @@
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<param xml:id="cass_caps_snghr5">
  3 + <info>
  4 + <name>Energy-time spectrogram of ion count rates observed by anode 5</name>
  5 + <short_name>CAPS SNG Anode 5</short_name>
  6 + <components></components>
  7 + <units>counts.s-1</units>
  8 + <coordinates_system></coordinates_system>
  9 + <tensor_order>1</tensor_order>
  10 + <si_conversion></si_conversion>
  11 + <table>
  12 + <boundsTable name="Energy" boundsName="Energy" units="eV"/>
  13 + </table>
  14 + <fill_value>-1.0e+31</fill_value>
  15 + <ucd>phys.count;phys.atmol.ionStage;arith.rate</ucd>
  16 + <dataset_id></dataset_id>
  17 + </info>
  18 + <gap_threshold>8</gap_threshold>
  19 + <get>
  20 + <vi name="cass:caps:snghr">
  21 + <baseParam name="SNG_ANODE5_PER_SEC">
  22 + <clb name="Energy"/>
  23 + </baseParam>
  24 + </vi>
  25 + </get>
  26 + <process/>
  27 + <output/>
  28 +</param>
... ...
config/DataBaseParameters/sta_swea_pad.xml 0 → 100644
... ... @@ -0,0 +1,23 @@
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<param xml:id="sta_swea_pad">
  3 + <info>
  4 + <name>Stereo-A SWEA PAD Total under all energies</name>
  5 + <short_name>SWEA PAD Total under all energies</short_name>
  6 + <components></components>
  7 + <units>s3/km6</units>
  8 + <coordinates_system></coordinates_system>
  9 + <tensor_order>0</tensor_order>
  10 + <si_conversion></si_conversion>
  11 + <table>
  12 + <centerTable name="PA" centerName="PitchAngles" size="15" units="deg."/>
  13 + </table>
  14 + <fill_value>-1e+31</fill_value>
  15 + <ucd></ucd>
  16 + <dataset_id></dataset_id>
  17 + </info>
  18 + <get>
  19 + <amdaParam name="sta_swea_pad_tab2d"/>
  20 + </get>
  21 + <process description="total(sta_swea_pad_tab2d,2)">total($sta_swea_pad_tab2d,2)</process>
  22 + <output/>
  23 +</param>
... ...
config/DataBaseParameters/sta_swea_pad_tab2d.xml 0 → 100644
... ... @@ -0,0 +1,30 @@
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<param xml:id="sta_swea_pad_tab2d">
  3 + <info>
  4 + <name>Stereo-A SWEA PAD</name>
  5 + <short_name>SWEA PAD</short_name>
  6 + <components></components>
  7 + <units>s3/km6</units>
  8 + <coordinates_system></coordinates_system>
  9 + <tensor_order>0</tensor_order>
  10 + <si_conversion></si_conversion>
  11 + <table>
  12 + <centerTable dim="0" name="PA" centerName="PitchAngles" size="15" units="deg."/>
  13 + <centerAutoTable dim="1" name="Energy" units="eV" centerName="ETab0" log="false"/>
  14 + </table>
  15 + <fill_value>-1e+31</fill_value>
  16 + <ucd></ucd>
  17 + <dataset_id></dataset_id>
  18 + </info>
  19 + <get>
  20 + <vi name="sta:swea:pad">
  21 + <baseParam name="PAD250">
  22 + <clb name="PitchAngles"/>
  23 + <clb name="ETab0"/>
  24 + <clb name="ETab1"/>
  25 + </baseParam>
  26 + </vi>
  27 + </get>
  28 + <process/>
  29 + <output/>
  30 +</param>
... ...
config/DataBaseParameters/xsd/info/paramInfo.xsd
... ... @@ -50,6 +50,14 @@
50 50 </xs:complexType>
51 51 </xs:element>
52 52  
  53 + <xs:element name="centerAutoTable" substitutionGroup="TableDef">
  54 + <xs:complexType>
  55 + <xs:attributeGroup ref="TableGroup" />
  56 + <xs:attribute name="centerName" type="xs:string" use="required" />
  57 + <xs:attribute name="log" type="xs:boolean" use="required" />
  58 + </xs:complexType>
  59 + </xs:element>
  60 +
53 61 <xs:attributeGroup name="StatusGroup">
54 62 <xs:attribute name="minVal" type="xs:double" />
55 63 <xs:attribute name="maxVal" type="xs:double" />
... ...
src/DD_Client_r_Lib/DD_client.cc
... ... @@ -589,7 +589,12 @@ int DD_Client:: DD_SetTimeInfo(int VarID, char *Time, double *RealTime)
589 589 }
590 590  
591 591 *RealTime = DD_Time2Double((char *)data->Variables[0]);
592   -
  592 +
  593 + //BRE - When the corresponding time is the last one of a file, MOREDATA is returned by DDServer.
  594 + // => force recall of DD_GetData to open the next file and finish correctly the request
  595 + if (err == MOREDATA)
  596 + err = DD_GetData(VarID, (char *)"Time", TimeInt, &data);
  597 +
593 598 return 1 ;
594 599 }
595 600  
... ...
src/Info/ParamTable.cc
... ... @@ -212,6 +212,110 @@ t_TableBound ParamCenterWidthTable::getBound(ParameterManager *parameterManager,
212 212 return bound;
213 213 }
214 214  
  215 +ParamCenterAutoTable::ParamCenterAutoTable(const char *paramId, const char *centerName, bool log) :
  216 + ParamTable(paramId), _centerName(centerName), _log(log)
  217 +{
  218 +}
  219 +
  220 +/*
  221 + * @brief Get size of the table
  222 + */
  223 +int ParamCenterAutoTable::getSize(ParameterManager *parameterManager)
  224 +{
  225 + ParameterSPtr tmpParam = parameterManager->getParameter(_paramId);
  226 + AMDA::Parameters::Parameter::InfoList lInfoList = tmpParam->getInfoList();
  227 + AMDA::Parameters::Parameter::InfoValuesSPtr pTableInfo = lInfoList[_centerName];
  228 + return pTableInfo->size();
  229 +}
  230 +
  231 +/*
  232 + * @brief Get a bound for a specified index
  233 + */
  234 +t_TableBound ParamCenterAutoTable::getBound(ParameterManager *parameterManager, unsigned int index)
  235 +{
  236 + ParameterSPtr tmpParam = parameterManager->getParameter(_paramId);
  237 +
  238 + t_TableBound bound;
  239 + bound.index = index;
  240 +
  241 + if (tmpParam == nullptr)
  242 + {
  243 + LOG4CXX_ERROR(_logger, "Associated parameter not reachable!");
  244 + bound.min = index;
  245 + bound.max = index+1;
  246 + return bound;
  247 + }
  248 +
  249 + //get table info from parameter info list
  250 +
  251 + AMDA::Parameters::Parameter::InfoList lInfoList = tmpParam->getInfoList();
  252 + AMDA::Parameters::Parameter::InfoValuesSPtr pTableInfo = lInfoList[_centerName];
  253 +
  254 + if (index >= pTableInfo->size())
  255 + {
  256 + LOG4CXX_ERROR(_logger, "Index " << index << " outside of table definition => Cannot get real bound" );
  257 + bound.min = index;
  258 + bound.max = index+1;
  259 + return bound;
  260 + }
  261 +
  262 + //Compute bounds
  263 +
  264 + if (pTableInfo->size() <= 1)
  265 + {
  266 + LOG4CXX_ERROR(_logger, "Table dimension too small to compute bound" );
  267 + bound.min = index;
  268 + bound.max = index+1;
  269 + return bound;
  270 + }
  271 +
  272 + double minus = 0.;
  273 + double plus = 0.;
  274 +
  275 + if (index == 0)
  276 + {
  277 + if (_log)
  278 + plus = exp((log10((*pTableInfo)[1]) - log10((*pTableInfo)[0]))/2.);
  279 + else
  280 + plus = ((*pTableInfo)[1] - (*pTableInfo)[0])/2.;
  281 + minus = plus;
  282 + }
  283 + else if (index == pTableInfo->size() - 1)
  284 + {
  285 + if (_log)
  286 + minus = exp((log10((*pTableInfo)[pTableInfo->size() - 1]) - log10((*pTableInfo)[pTableInfo->size() - 2]))/2.);
  287 + else
  288 + minus = ((*pTableInfo)[pTableInfo->size() - 1] - (*pTableInfo)[pTableInfo->size() - 2])/2.;
  289 + plus = minus;
  290 +
  291 + }
  292 + else
  293 + {
  294 + if (_log)
  295 + {
  296 + minus = exp((log10((*pTableInfo)[index]) - log10((*pTableInfo)[index-1]))/2.);
  297 + plus = exp((log10((*pTableInfo)[index+1]) - log10((*pTableInfo)[index]))/2.);
  298 + }
  299 + else
  300 + {
  301 + minus = ((*pTableInfo)[index] - (*pTableInfo)[index-1])/2.;
  302 + plus = ((*pTableInfo)[index+1] - (*pTableInfo)[index])/2.;
  303 + }
  304 + }
  305 +
  306 + bound.min = (*pTableInfo)[index] - minus;
  307 + bound.max = (*pTableInfo)[index] + plus;
  308 +
  309 + if (bound.min > bound.max)
  310 + {
  311 + double temp = bound.max;
  312 + bound.max = bound.min;
  313 + bound.min = temp;
  314 + }
  315 +
  316 + return bound;
  317 +}
  318 +
215 319 ParamMinMaxTable::ParamMinMaxTable(const char *paramId, const char *minName, const char *maxName) :
216 320 ParamTable(paramId), _minName(minName), _maxName(maxName)
217 321 {
... ...
src/Info/ParamTable.hh
... ... @@ -117,6 +117,24 @@ namespace Info {
117 117 };
118 118  
119 119 /**
  120 + * @class ParamCenterAutoTable
  121 + * @brief Implementation of a ParamTable for a table defined by a list of center value. Bounds automatically computed to be at the center of two consecutive channels
  122 + * @details
  123 + */
  124 + class ParamCenterAutoTable : public ParamTable {
  125 + public:
  126 + ParamCenterAutoTable(const char *paramId, const char *centerName, bool log);
  127 +
  128 + virtual int getSize(ParameterManager *parameterManager);
  129 +
  130 + virtual t_TableBound getBound(ParameterManager *parameterManager, unsigned int index);
  131 +
  132 + private:
  133 + std::string _centerName;
  134 + bool _log;
  135 + };
  136 +
  137 + /**
120 138 * @class ParamMinMaxTable
121 139 * @brief Implementation of a ParamTable for a table defined by two list: one for min and one for max
122 140 * @details
... ...
src/Info/ParamTableNode.cc
... ... @@ -329,6 +329,80 @@ public:
329 329 };
330 330  
331 331 /*
  332 + * @brief Center table node - Bounds automatically computed to be at the center of two consecutive channels
  333 + */
  334 +class CenterAutoTable: public AMDA::XMLConfigurator::NodeCfg {
  335 +public:
  336 + void proceed( xmlNodePtr pNode, const AMDA::Parameters::CfgContext& context) {
  337 + LOG4CXX_DEBUG(gLogger, "CenterAutoTable::proceed");
  338 +
  339 + ParamInfo* pParamInfo = context.get<ParamInfo*>();
  340 +
  341 + std::string paramId = pParamInfo->getId();
  342 +
  343 + //Get name
  344 + xmlChar* value = xmlGetProp(pNode, (const xmlChar *) "name");
  345 + std::string name;
  346 + if (value != NULL)
  347 + {
  348 + name = (char *)value;
  349 + xmlFree(value);
  350 + }
  351 +
  352 + //Get units
  353 + value = xmlGetProp(pNode, (const xmlChar *) "units");
  354 + std::string units;
  355 + if (value != NULL)
  356 + {
  357 + units = (char *)value;
  358 + xmlFree(value);
  359 + }
  360 +
  361 + //Get dim
  362 + value = xmlGetProp(pNode, (const xmlChar *) "dim");
  363 + int dim = 0;
  364 + if (value != NULL)
  365 + {
  366 + dim = atoi((char *)value);
  367 + xmlFree(value);
  368 + }
  369 +
  370 + xmlChar* lcenterName = NULL;
  371 + xmlChar* llog = NULL;
  372 + try {
  373 + if (!(lcenterName = xmlGetProp(pNode, (const xmlChar *) "centerName"))) {
  374 + ERROR_EXCEPTION(
  375 + ERROR_MANDATORY_ATTRIBUTE_MISSING << pNode->name << "@centerName")
  376 + }
  377 +
  378 + LOG4CXX_DEBUG(gLogger, "CenterAutoTable::proceed - Center name : " << lcenterName);
  379 +
  380 + bool isLog = false;
  381 + if ((llog = xmlGetProp(pNode, (const xmlChar *) "log"))) {
  382 + isLog = (strcmp((char*)llog, "true") == 0);
  383 + xmlFree(llog);
  384 + }
  385 +
  386 + boost::shared_ptr<ParamTable> table(new ParamCenterAutoTable(
  387 + paramId.c_str(), (const char*)lcenterName, isLog));
  388 +
  389 + table->setName(name);
  390 + table->setUnits(units);
  391 +
  392 + pParamInfo->addTable(dim, table);
  393 + } catch (...) {
  394 + if (lcenterName) {
  395 + xmlFree(lcenterName);
  396 + }
  397 + throw;
  398 + }
  399 + if (lcenterName) {
  400 + xmlFree(lcenterName);
  401 + }
  402 + }
  403 +};
  404 +
  405 +/*
332 406 * @brief table node
333 407 */
334 408 ParamTableNode::ParamTableNode() : AMDA::XMLConfigurator::NodeGrpCfg()
... ... @@ -337,6 +411,7 @@ ParamTableNode::ParamTableNode() : AMDA::XMLConfigurator::NodeGrpCfg()
337 411 getChildList()["minMaxTable"]=NodeCfgSPtr(new MinMaxTable);
338 412 getChildList()["centerTable"]=NodeCfgSPtr(new CenterTable);
339 413 getChildList()["centerWidthTable"]=NodeCfgSPtr(new CenterWidthTable);
  414 + getChildList()["centerAutoTable"]=NodeCfgSPtr(new CenterAutoTable);
340 415 }
341 416  
342 417 ParamTableNode::~ParamTableNode()
... ...
src/ParamGetImpl/DDServerInterface/ParamGetDDBase.cc
... ... @@ -53,6 +53,12 @@ namespace AMDA {
53 53 _vi = VirtualInstrumentManager::getInstance()->getVirtualInstrument(
54 54 _viName);
55 55 _pusher = _vi->getParamPusher(_parName);
  56 + //Param info
  57 + AMDA::Info::ParamInfoSPtr paramInfo = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(_parameter.getInfoId(),true);
  58 + if ((paramInfo != nullptr) && (isnan(_pusher->getFillValue())) && (!isnan(paramInfo->getFillValue())))
  59 + {
  60 + _pusher->setFillValue(paramInfo->getFillValue());
  61 + }
56 62 _paramData = ParamDataSPtr(_pusher->_paramData);
57 63 _paramData->setMinSampling(_vi->getMinSampling());
58 64  
... ...
src/ParamGetImpl/DDServerInterface/Pusher.hh
... ... @@ -30,6 +30,9 @@ namespace Base {
30 30 void setFillValue(double pFillValue) {
31 31 _fillValue = pFillValue;
32 32 }
  33 + double getFillValue() {
  34 + return _fillValue;
  35 + }
33 36 int _dim1; /*!< Used for vector and Tab2D */
34 37 int _dim2; /*!< Used for Tab2D */
35 38 ParamData* _paramData; /*!< return ParamData to a Process*/
... ...
src/Parameters/DataTypeMath.hh
... ... @@ -962,11 +962,20 @@ AMDA::Parameters::Tab2DData&lt;Type1&gt; operator /(const AMDA::Parameters::Tab2DData&lt;
962 962 template <typename Type>
963 963 Type total(const AMDA::Parameters::Tab2DData<Type>& a)
964 964 {
965   - Type sum = 0;
  965 + Type sum;
  966 + sum << NotANumber();
966 967  
967 968 for(int i = 0; i < a.getDim1Size(); ++i)
968 969 for(int j = 0; j < a.getDim2Size(); ++j)
969   - sum += a[i][j];
  970 + {
  971 + if (isFinite(a[i][j]))
  972 + {
  973 + if (isNAN(sum))
  974 + sum = a[i][j];
  975 + else
  976 + sum += a[i][j];
  977 + }
  978 + }
970 979 return sum;
971 980 }
972 981  
... ... @@ -985,18 +994,36 @@ std::vector&lt;Type&gt; total(const AMDA::Parameters::Tab2DData&lt;Type&gt;&amp; a,int mode)
985 994 case 1 :
986 995 for(int j = 0; j < a.getDim2Size(); ++j)
987 996 {
988   - Type elem = 0;
  997 + Type elem;
  998 + elem << NotANumber();
989 999 for(int i = 0; i < a.getDim1Size(); ++i)
990   - elem += a[i][j];
  1000 + {
  1001 + if (isFinite(a[i][j]))
  1002 + {
  1003 + if (isNAN(elem))
  1004 + elem = a[i][j];
  1005 + else
  1006 + elem += a[i][j];
  1007 + }
  1008 + }
991 1009 sum.push_back(elem);
992 1010 }
993 1011 break;
994 1012 case 2 :
995 1013 for(int i = 0; i < a.getDim1Size(); ++i)
996 1014 {
997   - Type elem = 0;
  1015 + Type elem;
  1016 + elem << NotANumber();
998 1017 for(int j = 0; j < a.getDim2Size(); ++j)
999   - elem += a[i][j];
  1018 + {
  1019 + if (isFinite(a[i][j]))
  1020 + {
  1021 + if (isNAN(elem))
  1022 + elem = a[i][j];
  1023 + else
  1024 + elem += a[i][j];
  1025 + }
  1026 + }
1000 1027 sum.push_back(elem);
1001 1028 }
1002 1029 break;
... ...