Commit 65414a1ce472a9707978644c19893efd3a76993b

Authored by Hacene SI HADJ MOHAND
1 parent 295de3cf

working for mav

src/Info/ParamInfo.cc
... ... @@ -17,7 +17,9 @@
17 17  
18 18 namespace AMDA {
19 19 namespace Info {
20   -
  20 +
  21 +LoggerPtr ParamInfo::_logger(Logger::getLogger("AMDA-Kernel.ParamInfo"));
  22 +
21 23 std::ostream& operator<<(std::ostream& out, const ParamInfo& pi){
22 24  
23 25 out << "[ParamInfo]" << std::endl;
... ... @@ -102,64 +104,6 @@ std::vector&lt;std::pair&lt;std::string,std::string&gt;&gt; ParamInfo::getInfoMap(ParameterM
102 104 PUSHINFO(infoMap, infoKey.str(),crtVal.str());
103 105 }
104 106 }
105   -
106   - if (!_tables.empty())
107   - {
108   - //push tables definition
109   - PUSHINFO(infoMap,TABLES_DESCRIPTION ,std::string(" "));
110   - for (auto table : _tables)
111   - {
112   - if(table.second != nullptr)
113   - table.second->addTableInfo(parameterManager, table.first, infoMap);
114   - }
115   - }
116   - ParameterSPtr param = parameterManager->getParameter(getId());
117   - AMDA::Parameters::SemiVariableTable semiVariableTable = param->getSemiVariableTable();
118   - if(! semiVariableTable.tabHeader.empty()){
119   - std::stringstream head;
120   - head.str("");
121   - head<<"mode"<<" ";
122   - for (auto h :semiVariableTable.tabHeader){
123   - head<<h<<" ";
124   - }
125   - PUSHINFO(infoMap, "",head.str());
126   - }
127   - for(auto v:semiVariableTable.tabValues){
128   - std::ostringstream values;
129   - values<<std::to_string(v.first)<<" ";
130   - // Convert all doubles to string ","
131   - std::copy(v.second.begin(), v.second.end(),
132   - std::ostream_iterator<double>(values, " "));
133   - PUSHINFO(infoMap, "",values.str());
134   - values.str("");
135   - }
136   -
137   -
138   - //adjout des info de tables
139   - /**
140   - ParameterSPtr param = parameterManager->getParameter(getId());
141   - std::map<std::string, boost::shared_ptr<std::vector<double>>> infoList =param->getInfoList();
142   - if(! infoList.empty()){
143   - //Adding descripion of table info
144   - for (auto inf : infoList){
145   - if(! inf.second->empty()){
146   - std::ostringstream values;
147   -
148   - // Convert all but the last element to avoid a trailing ","
149   - std::copy(inf.second->begin(), inf.second->end()-1,
150   - std::ostream_iterator<double>(values, ","));
151   -
152   - // Now add the last element with no delimiter
153   - values<< inf.second->back();
154   - std::stringstream infoKey;
155   - infoKey.str("");
156   - infoKey << PARAMETER_INFO<< "[" << inf.first << "]";
157   - PUSHINFO(infoMap , infoKey.str() , values.str());
158   - }
159   - }
160   - }
161   -
162   - */
163 107 }
164 108 else
165 109 {
... ... @@ -178,50 +122,30 @@ std::vector&lt;std::pair&lt;std::string,std::string&gt;&gt; ParamInfo::getInfoMap(ParameterM
178 122 }
179 123  
180 124 PUSHINFO(infoMap, PARAMETER_LINKED_PARAM, linkedParam.str());
181   -
182   - if (!_tables.empty())
  125 + }
  126 +
  127 + return infoMap;
  128 +}
  129 +
  130 +std::vector<std::pair<std::string,std::string>> ParamInfo::getTableInfoMap(ParameterManager *parameterManager)
  131 +{
  132 + std::vector<std::pair<std::string,std::string>> tableInfoMap;
  133 + if (!_tables.empty())
183 134 {
184   - PUSHINFO(infoMap,TABLES_DESCRIPTION ,std::string(" "));
  135 + PUSHINFO(tableInfoMap, PARAMETER_ID, getId());
  136 + PUSHINFO(tableInfoMap, PARAMETER_NAME,getName());
  137 + PUSHINFO(tableInfoMap, PARAMETER_SHORT_NAME,getShortName());
185 138 //push tables definition
  139 + PUSHINFO(tableInfoMap,TABLES_DESCRIPTION ,std::string(" "));
186 140 for (auto table : _tables)
187 141 {
188 142 if(table.second != nullptr)
189   - table.second->addTableInfo(parameterManager, table.first, infoMap);
  143 + table.second->addTableInfo(parameterManager, table.first, tableInfoMap);
190 144 }
191   - }
192   - /**
193   - ParameterSPtr pParam = parameterManager->getParameter(getId());
194   - Process* lProcess = dynamic_cast<Process*>(pParam->getDataWriterTemplate().get());
195   - if( lProcess != NULL){
196   - std::list<std::string>clbList= lProcess->getUsedClbInfo();
197   - if(! clbList.empty()){
198   - std::map<std::string, boost::shared_ptr<std::vector<double>>> infoList =pParam->getInfoList();
199   - if(! infoList.empty()){
200   - for (auto inf : infoList){
201   - if(! inf.second->empty() && (std::find(clbList.begin(), clbList.end(), inf.first) != clbList.end())) {
202   - std::ostringstream values;
203   - // Convert all but the last element to avoid a trailing ","
204   - std::copy(inf.second->begin(), inf.second->end()-1,
205   - std::ostream_iterator<double>(values, ","));
206   -
207   - // Now add the last element with no delimiter
208   - values<< inf.second->back();
209   - std::stringstream infoKey;
210   - infoKey.str("");
211   - infoKey << PARAMETER_INFO<< "[" << inf.first << "]";
212   - PUSHINFO(infoMap , infoKey.str() , values.str());
213   - }
214   - }
215   - }
216   -
217   - }
218   - }
219   - */
220   -
221   - //Process* lProcess = ServicesServer::getInstance()->getProcess("sampling_classic", &param);
222   - }
223   -
224   - return infoMap;
  145 + }else{
  146 + LOG4CXX_WARN(_logger, "Parameter "<<getId()<<" has no table");
  147 + }
  148 + return tableInfoMap;
225 149 }
226 150  
227 151 } /* namespace Info */
... ...
src/Info/ParamInfo.hh
... ... @@ -13,6 +13,7 @@
13 13 #include <set>
14 14 #include <boost/shared_ptr.hpp>
15 15 #include <algorithm>
  16 +#include "log4cxx/logger.h"
16 17  
17 18 #include "InfoLogger.hh"
18 19 #include "ParamTable.hh"
... ... @@ -384,6 +385,10 @@ public:
384 385 * @brief Get a map with parameter info
385 386 */
386 387 std::vector<std::pair<std::string,std::string>> getInfoMap(ParameterManager *parameterManager);
  388 + /*
  389 + * @brief Get a map with variable table info
  390 + */
  391 + std::vector<std::pair<std::string,std::string>> getTableInfoMap(ParameterManager *parameterManager);
387 392  
388 393 protected:
389 394 std::string _id;
... ... @@ -403,6 +408,7 @@ protected:
403 408 std::vector<std::string> _linkedParamList;
404 409 std::string _dataset_id;
405 410 std::string _instrument_id;
  411 + static log4cxx::LoggerPtr _logger;
406 412 };
407 413  
408 414 typedef boost::shared_ptr<ParamInfo> ParamInfoSPtr;
... ...
src/Info/ParamTable.cc
... ... @@ -200,6 +200,59 @@ void ParamTable::addTableInfo(ParameterManager *parameterManager, int dim, std::
200 200 PUSHINFO(infoMap, infoKey.str(), tableMaxValues.str());
201 201 }
202 202 }
  203 +void ParamTable::addSemiVariableTableInfo(ParameterManager* parameterManager, int dim, std::string paramId, std::string tabKey, std::vector<std::pair<std::string,std::string>>& infoMap){
  204 + AMDA::Parameters::ParameterSPtr pParam = parameterManager->getParameter(paramId);
  205 + AMDA::Parameters::SemiVariableTable semiVariableTable = pParam->getSemiVariableTable();
  206 + if(! semiVariableTable.tabHeader.empty()){
  207 + std::stringstream head;
  208 + head.str("");
  209 + head<<"mode"<<" ";
  210 + for (auto h :semiVariableTable.tabHeader){
  211 + head<<h<<" ";
  212 + }
  213 + PUSHINFO(infoMap, "",head.str());
  214 + // recuperer les centres
  215 + int nModes = semiVariableTable.tabValues.size();
  216 + int nValues = semiVariableTable.tabValues.begin()->second.size();
  217 + std::vector<double> energyVec;
  218 + std::map<std::string, std::vector<double>> paramsTableData;
  219 + std::map<int, std::vector<double>> semiVariableTableData;
  220 + for(int i=0; i<nValues; ++i){
  221 + energyVec.clear();
  222 + for (int j=0; j<nModes; ++j){
  223 + energyVec.push_back(semiVariableTable.tabValues[j][i]);
  224 + }
  225 + paramsTableData[tabKey] = energyVec;
  226 + for (int j=0; j<2*nModes; j= j+2){
  227 + t_TableBound bound = getBound(parameterManager, j/2, &paramsTableData);
  228 + semiVariableTableData[j].push_back(bound.min);
  229 + semiVariableTableData[j+1].push_back(bound.max);
  230 + }
  231 + }
  232 + int l = 0;
  233 + int k = 0;
  234 + for(auto v : semiVariableTableData){
  235 + std::ostringstream values;
  236 + std::string born;
  237 + (l%2 ==0) ? born =" Min " : born = " Max ";
  238 + values<<std::to_string(k)<<born;
  239 + // Convert all doubles to string ","
  240 + std::copy(v.second.begin(), v.second.end(),
  241 + std::ostream_iterator<double>(values, " "));
  242 + PUSHINFO(infoMap, "",values.str());
  243 + values.str("");
  244 + if(l%2 != 0)
  245 + k ++;
  246 + l ++;
  247 +
  248 + }
  249 + }
  250 + AMDA::Info::ParamInfoSPtr paramInfo = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(paramId);
  251 + const std::vector<std::string>& paramLinkedParams = paramInfo->getLinkedParamList();
  252 + for(auto pId:paramLinkedParams)
  253 + addSemiVariableTableInfo(parameterManager, dim, pId, tabKey, infoMap);
  254 +
  255 +}
203 256  
204 257 void ParamTable::addVariableTableInfo(ParameterManager * parameterManager, int dim, std::vector<std::pair<std::string,std::string>>& tableInfo) {
205 258 std::map<std::string, std::string>& tableParams=this->getTableParams(parameterManager);
... ... @@ -211,11 +264,11 @@ void ParamTable::addVariableTableInfo(ParameterManager * parameterManager, int d
211 264 infoKey << VARIABLE_PARAMETER_TABLE << linkedParam.first << "[" << i<< "]";
212 265 PUSHINFO(tableInfo, infoKey.str(), linkedParam.second);
213 266 AMDA::Parameters::ParameterSPtr variableTableParam = parameterManager->getParameter(linkedParam.second);
214   -
  267 + addSemiVariableTableInfo(parameterManager, dim, linkedParam.second, linkedParam.first, tableInfo);
215 268 // adding balib tables if exist
216 269 ParameterSPtr pParam = parameterManager->getParameter(linkedParam.second);
217   - std::map<std::string, boost::shared_ptr<std::vector<double>>> infoList =pParam->getInfoList();
218   - if(! infoList.empty()){
  270 + std::map<std::string, boost::shared_ptr<std::vector<double>>> infoList =pParam->getInfoList();
  271 + if(! infoList.empty()){
219 272 // pour l'instant rien
220 273 }
221 274 i++;
... ...
src/Info/ParamTable.hh
... ... @@ -18,6 +18,8 @@
18 18 #define PARAMETER_TABLE_MAXVAL "PARAMETER_TABLE_MAX_VALUES"
19 19 #define VARIABLE_PARAMETER_TABLE "PARAMETER_TABLE_"
20 20  
  21 +using namespace log4cxx;
  22 +
21 23 namespace AMDA {
22 24 namespace Info {
23 25  
... ... @@ -73,6 +75,8 @@ namespace Info {
73 75 virtual std::map<std::string, std::string>& getTableParams(ParameterManager *parameterManager);
74 76  
75 77 void addTableInfo(ParameterManager *parameterManager, int dim, std::vector<std::pair<std::string,std::string>>& infoMap);
  78 +
  79 + void addSemiVariableTableInfo(ParameterManager *parameterManager, int dim, std::string paramId, std::string key, std::vector<std::pair<std::string,std::string>>& infoMap);
76 80  
77 81 protected:
78 82 /** logger of paramTable */
... ...
src/ParamOutputImpl/Download/DownloadOutput.cc
... ... @@ -78,9 +78,6 @@ namespace AMDA {
78 78 AMDA::Parameters::ParameterSPtr param = _parameterManager.getParameter(paramProperties->getOriginalId());
79 79  
80 80 AMDA::Info::ParamInfoSPtr paramInfo = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(paramProperties->getOriginalId());
81   - const std::vector<std::string>& paramLinkedParams = paramInfo->getLinkedParamList();
82   - std::vector<std::string> linkedParams;
83   - linkedParams.insert(std::end(linkedParams), std::begin(paramLinkedParams), std::end(paramLinkedParams));
84 81 // adding tableParams
85 82 std::map<int, boost::shared_ptr < AMDA::Info::ParamTable>> tables = paramInfo->getTables();
86 83 if (!tables.empty()) {
... ... @@ -93,29 +90,11 @@ namespace AMDA {
93 90 AMDA::Parameters::ParameterSPtr tableParam = _parameterManager.getParameter(tableParamId.second);
94 91 tableParam ->openConnection(this);
95 92 AMDA::Info::ParamInfoSPtr tableInfo = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(tableParamId.second);
96   - const std::vector<std::string>& tableLinkedParams = tableInfo->getLinkedParamList();
97   - linkedParams.insert(std::end(linkedParams), std::begin(tableLinkedParams), std::end(tableLinkedParams));
98 93 }
99   -
100 94 }
101   -
102 95 }
103 96 }
104   -
105 97 }
106   - for (auto paramId:linkedParams)
107   - addAditionalDownloadParams(paramId);
108   - // ceci est un test
109   - /**
110   - std::string pId = "mavpds_sta_c0_swp_ind";
111   - AMDA::Parameters::ParameterSPtr pParam = _parameterManager.getParameter(pId);
112   - pParam->openConnection(this);
113   - ParamProperties* paramProperties = new ParamProperties();
114   - paramProperties->setOriginalId(pId);
115   - paramProperties->setOutputId(pId);
116   - _downloadProperties.addParamProperties(paramProperties);
117   - * */
118   - //ceci est un test
119 98 } catch (...) {
120 99 LOG4CXX_ERROR(_logger, "DownloadOutput::establishConnection - It's impossible to open connection for " << paramProperties->getOutputId());
121 100 std::string filePath = getFilePath(_fileWriter->getExtension());
... ... @@ -125,8 +104,6 @@ namespace AMDA {
125 104 throw;
126 105 }
127 106 }
128   -
129   -
130 107 }
131 108  
132 109 void DownloadOutput::addAditionalDownloadParams(std::string paramId){
... ... @@ -186,24 +163,22 @@ namespace AMDA {
186 163 if (!tables.empty()) {
187 164 for (auto table : tables) {
188 165 if (table.second != nullptr) {
189   - if (table.second->isVariable(&_parameterManager)) {
190 166 std::map<std::string, std::string> tableParamIds = table.second->getTableParams(&_parameterManager);
191 167 if (!tableParamIds.empty())
192 168 for (auto tableParamId : tableParamIds) {
193 169 AMDA::Parameters::ParameterSPtr tableParam = _parameterManager.getParameter(tableParamId.second);
194 170 tableParam -> init(this, _timeIntervalList);
195 171 AMDA::Info::ParamInfoSPtr tableInfo = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(tableParamId.second);
  172 + _tableParamsList.push_back( tableParamId.second);
  173 + _tableParamsList.push_back(paramProperties->getOriginalId());
196 174 for(auto linkedParamId : tableInfo->getLinkedParamList()){
197   - // AMDA::Parameters::ParameterSPtr linkedParam = _parameterManager.getParameter(linkedParamId);
198 175 addAditionalDownloadParams(linkedParamId);
199 176 }
200 177 }
201   - }
202 178 }
203 179 }
204 180 }
205 181  
206   -
207 182 } catch (...) {
208 183  
209 184 LOG4CXX_ERROR(_logger, "DownloadOutput::init : Error to init parameter " <<
... ... @@ -274,6 +249,18 @@ namespace AMDA {
274 249 //build too small interval file if needed
275 250 if (isNeedToGenerateTooSmallIntervalFile())
276 251 buildTooSmallIntervalCatalog();
  252 + if( !_tableParamsList.empty()){
  253 + std::string filePath = getTableInfoFilePath(_fileWriter->getExtension());
  254 + if (!_fileWriter->createNewFile(filePath)) {
  255 + LOG4CXX_ERROR(_logger, "DownloadOutput::apply : Cannot create table info file " << filePath);
  256 + BOOST_THROW_EXCEPTION(AMDA::Parameters::ParamOutput_exception());
  257 + }
  258 + _files.push_back(filePath);
  259 + //write info
  260 + writeAMDAInfo();
  261 + _fileWriter->writeTableParamsInfo(_tableParamsList,0);
  262 + _fileWriter->finalize(true);
  263 + }
277 264  
278 265 } catch (...) {
279 266 _fileWriter->closeFile();
... ... @@ -315,7 +302,6 @@ namespace AMDA {
315 302 }
316 303 }
317 304 }
318   -
319 305 /*
320 306 * @brief Apply structure for "one-file-per-interval"
321 307 */
... ... @@ -459,9 +445,9 @@ namespace AMDA {
459 445 _fileWriter->writeIntervalInfo(startTime.str(), stopTime.str());
460 446 }
461 447  
462   - void DownloadOutput::writeParamInfo(void) {
  448 + void DownloadOutput::writeParamInfo() {
463 449 _fileWriter->writeParamsInfo(_downloadProperties.getParamPropertiesList(),
464   - _downloadProperties.getOutputStructure(), _currentParamId);
  450 + _downloadProperties.getOutputStructure(), _currentParamId);;
465 451 }
466 452  
467 453 bool DownloadOutput::isNeedToGenerateTooSmallIntervalFile() {
... ... @@ -841,14 +827,20 @@ namespace AMDA {
841 827 std::string DownloadOutput::getInfoFilePath(std::string extension) {
842 828 return getFilePath(extension, true);
843 829 }
844   -
845   - /*
846   - * @brief Get file table info path in relation with the sequence step (only used if info constant or variable but finite table)
  830 +
  831 + /*
  832 + * @brief Get file info path in relation with the sequence step (only used if info is written is separate file)
847 833 */
848 834 std::string DownloadOutput::getTableInfoFilePath(std::string extension) {
849   - return "Table" + getFilePath(extension, true);
  835 + std::string suffix ="_table" ;
  836 + std::string path = getInfoFilePath(extension);
  837 + int pos = path.size()-extension.size()-1;
  838 + pos = std::max(pos,0);
  839 + path.insert(pos, suffix);
  840 + return path;
850 841 }
851 842  
  843 +
852 844 void DownloadOutput::getParameterDataFromServer(std::string paramId) {
853 845 try {
854 846 _currentParamId = paramId;
... ...
src/ParamOutputImpl/Download/DownloadOutput.hh
... ... @@ -271,6 +271,12 @@ protected:
271 271 * @brief Init mean processes for small interval treatments
272 272 */
273 273 void initMeanProcessMapForSmallInterval(std::map<std::string,std::shared_ptr<AMDA::Parameters::StatisticProcess>>& meanProcessMap);
  274 +
  275 + /*
  276 + * @brief list of tables
  277 + */
  278 + std::vector<std::string> _tableParamsList;
  279 +
274 280  
275 281 private:
276 282 /**
... ...
src/ParamOutputImpl/Download/FileWriter.hh
... ... @@ -118,6 +118,10 @@ public:
118 118 */
119 119 virtual bool writeParamsInfo(ParamPropertiesList& paramPropertiesList, OutputStructure outputStructure,
120 120 std::string currentParamId = "") = 0;
  121 + /*
  122 + * @brief Write a parameters table info bloc in current opened file
  123 + */
  124 + virtual bool writeTableParamsInfo(std::vector<std::string> tableParams, int level) = 0;
121 125  
122 126 /*
123 127 * @brief Write an interval info bloc in current opened file
... ...
src/ParamOutputImpl/Download/FileWriterASCIIAbstract.cc
... ... @@ -399,6 +399,18 @@ bool FileWriterASCIIAbstract::writeParameterInfo(ParamInfoSPtr parameterInfo, in
399 399  
400 400 return true;
401 401 }
  402 +bool FileWriterASCIIAbstract::writeTableParamsInfo(std::vector<std::string> tableParams, int level){
  403 + if(tableParams.empty())
  404 + return false;
  405 + for (auto tableId:tableParams){
  406 + //get current param info
  407 + AMDA::Info::ParamInfoSPtr tableInfo = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(tableId);
  408 + std::vector<std::pair<std::string,std::string>> tableInfoMap = tableInfo->getTableInfoMap(&_parameterManager);
  409 + for (auto info : tableInfoMap)
  410 + writeSingleInfo(info.first, info.second, level);
  411 + }
  412 + return true;
  413 +}
402 414  
403 415 bool FileWriterASCIIAbstract::writeParamsInfo(ParamPropertiesList& paramPropertiesList, OutputStructure outputStructure,
404 416 std::string currentParamId)
... ...
src/ParamOutputImpl/Download/FileWriterASCIIAbstract.hh
... ... @@ -215,6 +215,8 @@ public:
215 215 */
216 216 virtual bool writeParamsInfo(ParamPropertiesList& paramPropertiesList, OutputStructure outputStructure,
217 217 std::string currentParamId = "");
  218 +
  219 + virtual bool writeTableParamsInfo(std::vector<std::string> tableParams, int level);
218 220  
219 221 /*
220 222 * @overload FileWriter::writeIntervalInfo - Write an interval info bloc for ASCII file
... ...
src/ParamOutputImpl/Download/FileWriterCDF.cc
... ... @@ -285,6 +285,20 @@ bool FileWriterCDF::writeParameterInfo(ParamInfoSPtr parameterInfo, long varNum)
285 285  
286 286 return true;
287 287 }
  288 +bool FileWriterCDF::writeTableParamsInfo(std::vector<std::string> tableParams, int level){
  289 + if(tableParams.empty())
  290 + return false;
  291 + for (auto tableId:tableParams){
  292 + //get current param info
  293 + AMDA::Info::ParamInfoSPtr tableInfo = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(tableId);
  294 + std::vector<std::pair<std::string,std::string>> tableInfoMap = tableInfo->getTableInfoMap(&_parameterManager);
  295 + for (auto info : tableInfoMap)
  296 + addAttribute(info.first, info.second, VARIABLE_SCOPE, level);
  297 + DataSetInfoSPtr dataSetInfo = DataSetMgr::getInstance()->getDataSetInfoFromId(tableInfo ->getDatasetId());
  298 + writeDatasetInfo(dataSetInfo, level);
  299 + }
  300 + return true;
  301 +}
288 302  
289 303 bool FileWriterCDF::writeParamsInfo(ParamPropertiesList& paramPropertiesList, OutputStructure outputStructure,
290 304 std::string currentParamId)
... ...
src/ParamOutputImpl/Download/FileWriterCDF.hh
... ... @@ -196,6 +196,11 @@ protected:
196 196 * @brief Write parameter info attributes in the CDF file
197 197 */
198 198 bool writeParameterInfo(ParamInfoSPtr parameterInfo, long varNum);
  199 +
  200 + /*
  201 + * @brief Write parameter table info attributes in the CDF file
  202 + */
  203 + bool writeTableParamsInfo(std::vector<std::string> tableParams, int level);
199 204  
200 205 private:
201 206 /*
... ...