[219] | 1 | #include "field.hpp" |
---|
| 2 | |
---|
[352] | 3 | #include "attribute_template.hpp" |
---|
| 4 | #include "object_template.hpp" |
---|
| 5 | #include "group_template.hpp" |
---|
[219] | 6 | |
---|
| 7 | #include "node_type.hpp" |
---|
| 8 | #include "calendar_util.hpp" |
---|
[352] | 9 | #include "message.hpp" |
---|
[591] | 10 | #include "xios_spl.hpp" |
---|
[352] | 11 | #include "type.hpp" |
---|
[638] | 12 | #include "timer.hpp" |
---|
[352] | 13 | #include "context_client.hpp" |
---|
[586] | 14 | #include "context_server.hpp" |
---|
[459] | 15 | #include <set> |
---|
[640] | 16 | #include "garbage_collector.hpp" |
---|
| 17 | #include "source_filter.hpp" |
---|
| 18 | #include "store_filter.hpp" |
---|
| 19 | #include "file_writer_filter.hpp" |
---|
[641] | 20 | #include "pass_through_filter.hpp" |
---|
[642] | 21 | #include "filter_expr_node.hpp" |
---|
| 22 | #include "lex_parser.hpp" |
---|
[643] | 23 | #include "temporal_filter.hpp" |
---|
[644] | 24 | #include "spatial_transform_filter.hpp" |
---|
[219] | 25 | |
---|
[335] | 26 | namespace xios{ |
---|
[509] | 27 | |
---|
[219] | 28 | /// ////////////////////// Définitions ////////////////////// /// |
---|
| 29 | |
---|
| 30 | CField::CField(void) |
---|
| 31 | : CObjectTemplate<CField>(), CFieldAttributes() |
---|
| 32 | , refObject(), baseRefObject() |
---|
| 33 | , grid(), file() |
---|
[707] | 34 | , written(false) |
---|
[645] | 35 | , nstep(0), nstepMax(0) |
---|
| 36 | , hasOutputFile(false) |
---|
| 37 | , domAxisIds_("", ""), areAllReferenceSolved(false) |
---|
[676] | 38 | , useCompressedOutput(false) |
---|
[598] | 39 | , isReadDataRequestPending(false) |
---|
[640] | 40 | { setVirtualVariableGroup(); } |
---|
[219] | 41 | |
---|
[562] | 42 | CField::CField(const StdString& id) |
---|
[219] | 43 | : CObjectTemplate<CField>(id), CFieldAttributes() |
---|
| 44 | , refObject(), baseRefObject() |
---|
| 45 | , grid(), file() |
---|
[707] | 46 | , written(false) |
---|
[645] | 47 | , nstep(0), nstepMax(0) |
---|
| 48 | , hasOutputFile(false) |
---|
| 49 | , domAxisIds_("", ""), areAllReferenceSolved(false) |
---|
[676] | 50 | , useCompressedOutput(false) |
---|
[598] | 51 | , isReadDataRequestPending(false) |
---|
[562] | 52 | { setVirtualVariableGroup(); } |
---|
[219] | 53 | |
---|
| 54 | CField::~CField(void) |
---|
[645] | 55 | {} |
---|
[509] | 56 | |
---|
[472] | 57 | //---------------------------------------------------------------- |
---|
| 58 | |
---|
| 59 | void CField::setVirtualVariableGroup(CVariableGroup* newVVariableGroup) |
---|
[509] | 60 | { |
---|
| 61 | this->vVariableGroup = newVVariableGroup; |
---|
[472] | 62 | } |
---|
[509] | 63 | |
---|
[472] | 64 | void CField::setVirtualVariableGroup(void) |
---|
| 65 | { |
---|
| 66 | this->setVirtualVariableGroup(CVariableGroup::create()); |
---|
| 67 | } |
---|
[509] | 68 | |
---|
[472] | 69 | CVariableGroup* CField::getVirtualVariableGroup(void) const |
---|
| 70 | { |
---|
[562] | 71 | return this->vVariableGroup; |
---|
[472] | 72 | } |
---|
| 73 | |
---|
[509] | 74 | |
---|
[472] | 75 | std::vector<CVariable*> CField::getAllVariables(void) const |
---|
| 76 | { |
---|
[562] | 77 | return this->vVariableGroup->getAllChildren(); |
---|
[472] | 78 | } |
---|
[509] | 79 | |
---|
[562] | 80 | void CField::solveDescInheritance(bool apply, const CAttributeMap* const parent) |
---|
[472] | 81 | { |
---|
[562] | 82 | SuperClassAttribute::setAttributes(parent, apply); |
---|
[472] | 83 | this->getVirtualVariableGroup()->solveDescInheritance(apply, NULL); |
---|
| 84 | } |
---|
[219] | 85 | |
---|
[645] | 86 | //---------------------------------------------------------------- |
---|
[509] | 87 | |
---|
[598] | 88 | bool CField::dispatchEvent(CEventServer& event) |
---|
[300] | 89 | { |
---|
[562] | 90 | if (SuperClass::dispatchEvent(event)) return true; |
---|
[300] | 91 | else |
---|
| 92 | { |
---|
| 93 | switch(event.type) |
---|
| 94 | { |
---|
| 95 | case EVENT_ID_UPDATE_DATA : |
---|
[562] | 96 | recvUpdateData(event); |
---|
| 97 | return true; |
---|
| 98 | break; |
---|
[472] | 99 | |
---|
[598] | 100 | case EVENT_ID_READ_DATA : |
---|
| 101 | recvReadDataRequest(event); |
---|
| 102 | return true; |
---|
| 103 | break; |
---|
[509] | 104 | |
---|
[598] | 105 | case EVENT_ID_READ_DATA_READY : |
---|
| 106 | recvReadDataReady(event); |
---|
| 107 | return true; |
---|
| 108 | break; |
---|
[509] | 109 | |
---|
[598] | 110 | case EVENT_ID_ADD_VARIABLE : |
---|
| 111 | recvAddVariable(event); |
---|
| 112 | return true; |
---|
| 113 | break; |
---|
| 114 | |
---|
| 115 | case EVENT_ID_ADD_VARIABLE_GROUP : |
---|
| 116 | recvAddVariableGroup(event); |
---|
| 117 | return true; |
---|
| 118 | break; |
---|
| 119 | |
---|
[300] | 120 | default : |
---|
[562] | 121 | ERROR("bool CField::dispatchEvent(CEventServer& event)", << "Unknown Event"); |
---|
| 122 | return false; |
---|
[300] | 123 | } |
---|
| 124 | } |
---|
| 125 | } |
---|
[509] | 126 | |
---|
[638] | 127 | void CField::sendUpdateData(const CArray<double,1>& data) |
---|
| 128 | { |
---|
| 129 | CTimer::get("XIOS Send Data").resume(); |
---|
| 130 | |
---|
| 131 | CContext* context = CContext::getCurrent(); |
---|
| 132 | CContextClient* client = context->client; |
---|
| 133 | |
---|
| 134 | CEventClient event(getType(), EVENT_ID_UPDATE_DATA); |
---|
| 135 | |
---|
[650] | 136 | map<int, CArray<int,1> >::iterator it; |
---|
[638] | 137 | list<CMessage> list_msg; |
---|
| 138 | list<CArray<double,1> > list_data; |
---|
| 139 | |
---|
| 140 | if (!grid->doGridHaveDataDistributed()) |
---|
| 141 | { |
---|
| 142 | if (0 == client->clientRank) |
---|
| 143 | { |
---|
| 144 | for (it = grid->storeIndex_toSrv.begin(); it != grid->storeIndex_toSrv.end(); it++) |
---|
| 145 | { |
---|
[650] | 146 | int rank = it->first; |
---|
| 147 | CArray<int,1>& index = it->second; |
---|
[638] | 148 | |
---|
| 149 | list_msg.push_back(CMessage()); |
---|
| 150 | list_data.push_back(CArray<double,1>(index.numElements())); |
---|
| 151 | |
---|
| 152 | CArray<double,1>& data_tmp = list_data.back(); |
---|
| 153 | for (int n = 0; n < data_tmp.numElements(); n++) data_tmp(n) = data(index(n)); |
---|
| 154 | |
---|
| 155 | list_msg.back() << getId() << data_tmp; |
---|
| 156 | event.push(rank, 1, list_msg.back()); |
---|
| 157 | } |
---|
| 158 | client->sendEvent(event); |
---|
| 159 | } else client->sendEvent(event); |
---|
| 160 | } |
---|
| 161 | else |
---|
| 162 | { |
---|
| 163 | for (it = grid->storeIndex_toSrv.begin(); it != grid->storeIndex_toSrv.end(); it++) |
---|
| 164 | { |
---|
[650] | 165 | int rank = it->first; |
---|
| 166 | CArray<int,1>& index = it->second; |
---|
[638] | 167 | |
---|
| 168 | list_msg.push_back(CMessage()); |
---|
| 169 | list_data.push_back(CArray<double,1>(index.numElements())); |
---|
| 170 | |
---|
| 171 | CArray<double,1>& data_tmp = list_data.back(); |
---|
| 172 | for (int n = 0; n < data_tmp.numElements(); n++) data_tmp(n) = data(index(n)); |
---|
| 173 | |
---|
| 174 | list_msg.back() << getId() << data_tmp; |
---|
| 175 | event.push(rank, grid->nbSenders[rank], list_msg.back()); |
---|
| 176 | } |
---|
| 177 | client->sendEvent(event); |
---|
| 178 | } |
---|
[687] | 179 | |
---|
[638] | 180 | CTimer::get("XIOS Send Data").suspend(); |
---|
| 181 | } |
---|
| 182 | |
---|
[300] | 183 | void CField::recvUpdateData(CEventServer& event) |
---|
| 184 | { |
---|
[562] | 185 | vector<int> ranks; |
---|
| 186 | vector<CBufferIn*> buffers; |
---|
[509] | 187 | |
---|
[562] | 188 | list<CEventServer::SSubEvent>::iterator it; |
---|
| 189 | string fieldId; |
---|
[219] | 190 | |
---|
[562] | 191 | for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it) |
---|
[300] | 192 | { |
---|
[562] | 193 | int rank = it->rank; |
---|
| 194 | CBufferIn* buffer = it->buffer; |
---|
| 195 | *buffer >> fieldId; |
---|
| 196 | ranks.push_back(rank); |
---|
| 197 | buffers.push_back(buffer); |
---|
[300] | 198 | } |
---|
[562] | 199 | get(fieldId)->recvUpdateData(ranks,buffers); |
---|
[300] | 200 | } |
---|
[509] | 201 | |
---|
[300] | 202 | void CField::recvUpdateData(vector<int>& ranks, vector<CBufferIn*>& buffers) |
---|
| 203 | { |
---|
| 204 | if (data_srv.empty()) |
---|
| 205 | { |
---|
[650] | 206 | for (map<int, CArray<size_t, 1> >::iterator it = grid->outIndexFromClient.begin(); it != grid->outIndexFromClient.end(); ++it) |
---|
[300] | 207 | { |
---|
[562] | 208 | int rank = it->first; |
---|
[651] | 209 | data_srv.insert(std::make_pair(rank, CArray<double,1>(it->second.numElements()))); |
---|
| 210 | foperation_srv.insert(pair<int,boost::shared_ptr<func::CFunctor> >(rank,boost::shared_ptr<func::CFunctor>(new func::CInstant(data_srv[rank])))); |
---|
[300] | 211 | } |
---|
| 212 | } |
---|
| 213 | |
---|
[562] | 214 | CContext* context = CContext::getCurrent(); |
---|
| 215 | const CDate& currDate = context->getCalendar()->getCurrentDate(); |
---|
[651] | 216 | const CDate opeDate = last_operation_srv + freq_operation_srv; |
---|
| 217 | const CDate writeDate = last_Write_srv + freq_write_srv; |
---|
[300] | 218 | |
---|
| 219 | if (opeDate <= currDate) |
---|
| 220 | { |
---|
[562] | 221 | for (int n = 0; n < ranks.size(); n++) |
---|
[300] | 222 | { |
---|
[562] | 223 | CArray<double,1> data_tmp; |
---|
| 224 | *buffers[n] >> data_tmp; |
---|
| 225 | (*foperation_srv[ranks[n]])(data_tmp); |
---|
[300] | 226 | } |
---|
[651] | 227 | last_operation_srv = currDate; |
---|
[300] | 228 | } |
---|
[509] | 229 | |
---|
[300] | 230 | if (writeDate < (currDate + freq_operation_srv)) |
---|
| 231 | { |
---|
[562] | 232 | for (int n = 0; n < ranks.size(); n++) |
---|
[300] | 233 | { |
---|
| 234 | this->foperation_srv[ranks[n]]->final(); |
---|
| 235 | } |
---|
[509] | 236 | |
---|
[651] | 237 | last_Write_srv = writeDate; |
---|
[562] | 238 | writeField(); |
---|
[651] | 239 | lastlast_Write_srv = last_Write_srv; |
---|
[300] | 240 | } |
---|
| 241 | } |
---|
[509] | 242 | |
---|
[300] | 243 | void CField::writeField(void) |
---|
| 244 | { |
---|
[562] | 245 | if (!getRelFile()->allDomainEmpty) |
---|
[586] | 246 | { |
---|
[599] | 247 | if (grid->doGridHaveDataToWrite() || getRelFile()->type == CFile::type_attr::one_file) |
---|
[379] | 248 | { |
---|
| 249 | getRelFile()->checkFile(); |
---|
| 250 | this->incrementNStep(); |
---|
| 251 | getRelFile()->getDataOutput()->writeFieldData(CField::get(this)); |
---|
| 252 | } |
---|
[586] | 253 | } |
---|
[300] | 254 | } |
---|
[562] | 255 | |
---|
[598] | 256 | void CField::sendReadDataRequest(void) |
---|
| 257 | { |
---|
| 258 | CContext* context = CContext::getCurrent(); |
---|
| 259 | CContextClient* client = context->client; |
---|
| 260 | |
---|
[708] | 261 | lastDataRequestedFromServer = context->getCalendar()->getCurrentDate(); |
---|
| 262 | isReadDataRequestPending = true; |
---|
| 263 | |
---|
[598] | 264 | CEventClient event(getType(), EVENT_ID_READ_DATA); |
---|
| 265 | if (client->isServerLeader()) |
---|
| 266 | { |
---|
| 267 | CMessage msg; |
---|
| 268 | msg << getId(); |
---|
| 269 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
| 270 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 271 | event.push(*itRank, 1, msg); |
---|
| 272 | client->sendEvent(event); |
---|
| 273 | } |
---|
| 274 | else client->sendEvent(event); |
---|
| 275 | } |
---|
| 276 | |
---|
| 277 | /*! |
---|
| 278 | Send request new data read from file if need be, that is the current data is out-of-date. |
---|
| 279 | \return true if and only if some data was requested |
---|
| 280 | */ |
---|
| 281 | bool CField::sendReadDataRequestIfNeeded(void) |
---|
| 282 | { |
---|
| 283 | const CDate& currentDate = CContext::getCurrent()->getCalendar()->getCurrentDate(); |
---|
| 284 | |
---|
| 285 | bool requestData = (currentDate >= lastDataRequestedFromServer + file->output_freq.getValue()); |
---|
| 286 | |
---|
| 287 | if (requestData) |
---|
| 288 | sendReadDataRequest(); |
---|
| 289 | |
---|
| 290 | return requestData; |
---|
| 291 | } |
---|
| 292 | |
---|
| 293 | void CField::recvReadDataRequest(CEventServer& event) |
---|
| 294 | { |
---|
| 295 | CBufferIn* buffer = event.subEvents.begin()->buffer; |
---|
| 296 | StdString fieldId; |
---|
| 297 | *buffer >> fieldId; |
---|
| 298 | get(fieldId)->recvReadDataRequest(); |
---|
| 299 | } |
---|
| 300 | |
---|
| 301 | void CField::recvReadDataRequest(void) |
---|
| 302 | { |
---|
| 303 | CContext* context = CContext::getCurrent(); |
---|
| 304 | CContextClient* client = context->client; |
---|
| 305 | |
---|
| 306 | CEventClient event(getType(), EVENT_ID_READ_DATA_READY); |
---|
| 307 | std::list<CMessage> msgs; |
---|
| 308 | |
---|
[599] | 309 | bool hasData = readField(); |
---|
[598] | 310 | |
---|
[651] | 311 | map<int, CArray<double,1> >::iterator it; |
---|
[598] | 312 | for (it = data_srv.begin(); it != data_srv.end(); it++) |
---|
| 313 | { |
---|
| 314 | msgs.push_back(CMessage()); |
---|
| 315 | CMessage& msg = msgs.back(); |
---|
[599] | 316 | msg << getId(); |
---|
| 317 | if (hasData) |
---|
[651] | 318 | msg << getNStep() - 1 << it->second; |
---|
[599] | 319 | else |
---|
[603] | 320 | msg << size_t(-1); |
---|
[598] | 321 | event.push(it->first, grid->nbSenders[it->first], msg); |
---|
| 322 | } |
---|
| 323 | client->sendEvent(event); |
---|
[599] | 324 | } |
---|
[598] | 325 | |
---|
[599] | 326 | bool CField::readField(void) |
---|
| 327 | { |
---|
| 328 | if (!getRelFile()->allDomainEmpty) |
---|
| 329 | { |
---|
| 330 | if (grid->doGridHaveDataToWrite() || getRelFile()->type == CFile::type_attr::one_file) |
---|
| 331 | { |
---|
| 332 | if (data_srv.empty()) |
---|
| 333 | { |
---|
[650] | 334 | for (map<int, CArray<size_t, 1> >::iterator it = grid->outIndexFromClient.begin(); it != grid->outIndexFromClient.end(); ++it) |
---|
[651] | 335 | data_srv.insert(std::make_pair(it->first, CArray<double,1>(it->second.numElements()))); |
---|
[599] | 336 | } |
---|
| 337 | |
---|
| 338 | getRelFile()->checkFile(); |
---|
| 339 | this->incrementNStep(); |
---|
| 340 | |
---|
| 341 | if (!nstepMax) |
---|
| 342 | { |
---|
| 343 | nstepMax = getRelFile()->getDataInput()->getFieldNbRecords(CField::get(this)); |
---|
| 344 | } |
---|
| 345 | |
---|
| 346 | if (getNStep() > nstepMax) |
---|
| 347 | return false; |
---|
| 348 | |
---|
| 349 | getRelFile()->getDataInput()->readFieldData(CField::get(this)); |
---|
| 350 | } |
---|
| 351 | } |
---|
| 352 | |
---|
| 353 | return true; |
---|
[598] | 354 | } |
---|
| 355 | |
---|
| 356 | void CField::recvReadDataReady(CEventServer& event) |
---|
| 357 | { |
---|
| 358 | string fieldId; |
---|
| 359 | vector<int> ranks; |
---|
| 360 | vector<CBufferIn*> buffers; |
---|
| 361 | |
---|
| 362 | list<CEventServer::SSubEvent>::iterator it; |
---|
| 363 | for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it) |
---|
| 364 | { |
---|
| 365 | ranks.push_back(it->rank); |
---|
| 366 | CBufferIn* buffer = it->buffer; |
---|
| 367 | *buffer >> fieldId; |
---|
| 368 | buffers.push_back(buffer); |
---|
| 369 | } |
---|
| 370 | get(fieldId)->recvReadDataReady(ranks, buffers); |
---|
| 371 | } |
---|
| 372 | |
---|
| 373 | void CField::recvReadDataReady(vector<int> ranks, vector<CBufferIn*> buffers) |
---|
| 374 | { |
---|
| 375 | CContext* context = CContext::getCurrent(); |
---|
| 376 | StdSize record; |
---|
[640] | 377 | std::map<int, CArray<double,1> > data; |
---|
| 378 | |
---|
[645] | 379 | bool isEOF = false; |
---|
| 380 | |
---|
[598] | 381 | for (int i = 0; i < ranks.size(); i++) |
---|
| 382 | { |
---|
| 383 | int rank = ranks[i]; |
---|
[599] | 384 | *buffers[i] >> record; |
---|
[603] | 385 | isEOF = (record == size_t(-1)); |
---|
[598] | 386 | |
---|
[599] | 387 | if (!isEOF) |
---|
[640] | 388 | *buffers[i] >> data[rank]; |
---|
| 389 | else |
---|
| 390 | break; |
---|
| 391 | } |
---|
| 392 | |
---|
| 393 | if (isEOF) |
---|
| 394 | serverSourceFilter->signalEndOfStream(lastDataRequestedFromServer); |
---|
| 395 | else |
---|
| 396 | serverSourceFilter->streamDataFromServer(lastDataRequestedFromServer, data); |
---|
| 397 | |
---|
[598] | 398 | isReadDataRequestPending = false; |
---|
| 399 | } |
---|
| 400 | |
---|
[219] | 401 | //---------------------------------------------------------------- |
---|
| 402 | |
---|
[347] | 403 | void CField::setRelFile(CFile* _file) |
---|
[509] | 404 | { |
---|
[459] | 405 | this->file = _file; |
---|
[562] | 406 | hasOutputFile = true; |
---|
[219] | 407 | } |
---|
| 408 | |
---|
| 409 | //---------------------------------------------------------------- |
---|
| 410 | |
---|
[562] | 411 | StdString CField::GetName(void) { return StdString("field"); } |
---|
| 412 | StdString CField::GetDefName(void) { return CField::GetName(); } |
---|
| 413 | ENodeType CField::GetType(void) { return eField; } |
---|
[219] | 414 | |
---|
| 415 | //---------------------------------------------------------------- |
---|
| 416 | |
---|
[347] | 417 | CGrid* CField::getRelGrid(void) const |
---|
[509] | 418 | { |
---|
[562] | 419 | return this->grid; |
---|
[219] | 420 | } |
---|
| 421 | |
---|
| 422 | //---------------------------------------------------------------- |
---|
| 423 | |
---|
[347] | 424 | CFile* CField::getRelFile(void) const |
---|
[509] | 425 | { |
---|
[562] | 426 | return this->file; |
---|
[219] | 427 | } |
---|
[509] | 428 | |
---|
[266] | 429 | StdSize CField::getNStep(void) const |
---|
| 430 | { |
---|
[562] | 431 | return this->nstep; |
---|
[266] | 432 | } |
---|
[509] | 433 | |
---|
[645] | 434 | func::CFunctor::ETimeType CField::getOperationTimeType() const |
---|
| 435 | { |
---|
| 436 | return operationTimeType; |
---|
| 437 | } |
---|
| 438 | |
---|
| 439 | //---------------------------------------------------------------- |
---|
| 440 | |
---|
[266] | 441 | void CField::incrementNStep(void) |
---|
| 442 | { |
---|
| 443 | this->nstep++; |
---|
| 444 | } |
---|
[509] | 445 | |
---|
[707] | 446 | void CField::resetNStep(StdSize nstep /*= 0*/) |
---|
[321] | 447 | { |
---|
[707] | 448 | this->nstep = nstep; |
---|
[321] | 449 | } |
---|
[219] | 450 | |
---|
[599] | 451 | void CField::resetNStepMax(void) |
---|
| 452 | { |
---|
| 453 | this->nstepMax = 0; |
---|
| 454 | } |
---|
| 455 | |
---|
[219] | 456 | //---------------------------------------------------------------- |
---|
| 457 | |
---|
[310] | 458 | bool CField::isActive(void) const |
---|
[509] | 459 | { |
---|
[562] | 460 | return !this->refObject.empty(); |
---|
[310] | 461 | } |
---|
[562] | 462 | |
---|
[219] | 463 | //---------------------------------------------------------------- |
---|
[509] | 464 | |
---|
[707] | 465 | bool CField::wasWritten() const |
---|
| 466 | { |
---|
| 467 | return written; |
---|
| 468 | } |
---|
| 469 | |
---|
| 470 | void CField::setWritten() |
---|
| 471 | { |
---|
| 472 | written = true; |
---|
| 473 | } |
---|
| 474 | |
---|
| 475 | //---------------------------------------------------------------- |
---|
| 476 | |
---|
[676] | 477 | bool CField::getUseCompressedOutput() const |
---|
| 478 | { |
---|
| 479 | return useCompressedOutput; |
---|
| 480 | } |
---|
| 481 | |
---|
| 482 | void CField::setUseCompressedOutput() |
---|
| 483 | { |
---|
| 484 | useCompressedOutput = true; |
---|
| 485 | } |
---|
| 486 | |
---|
| 487 | //---------------------------------------------------------------- |
---|
| 488 | |
---|
[641] | 489 | boost::shared_ptr<COutputPin> CField::getInstantDataFilter() |
---|
| 490 | { |
---|
| 491 | return instantDataFilter; |
---|
| 492 | } |
---|
| 493 | |
---|
| 494 | //---------------------------------------------------------------- |
---|
| 495 | |
---|
[509] | 496 | void CField::solveAllReferenceEnabledField(bool doSending2Sever) |
---|
[459] | 497 | { |
---|
[509] | 498 | CContext* context = CContext::getCurrent(); |
---|
| 499 | if (!areAllReferenceSolved) |
---|
| 500 | { |
---|
| 501 | areAllReferenceSolved = true; |
---|
[644] | 502 | |
---|
[510] | 503 | if (context->hasClient) |
---|
[509] | 504 | { |
---|
| 505 | solveRefInheritance(true); |
---|
| 506 | solveBaseReference(); |
---|
[644] | 507 | if (hasDirectFieldReference()) getDirectFieldReference()->solveAllReferenceEnabledField(false); |
---|
[509] | 508 | } |
---|
[645] | 509 | else if (context->hasServer) |
---|
| 510 | solveServerOperation(); |
---|
[478] | 511 | |
---|
[509] | 512 | solveGridReference(); |
---|
| 513 | } |
---|
[687] | 514 | if (context->hasClient) |
---|
| 515 | { |
---|
| 516 | solveGenerateGrid(); |
---|
| 517 | } |
---|
| 518 | |
---|
[509] | 519 | solveGridDomainAxisRef(doSending2Sever); |
---|
[687] | 520 | |
---|
[619] | 521 | if (context->hasClient) |
---|
| 522 | { |
---|
| 523 | solveTransformedGrid(); |
---|
| 524 | } |
---|
[687] | 525 | |
---|
[623] | 526 | solveCheckMaskIndex(doSending2Sever); |
---|
[509] | 527 | } |
---|
| 528 | |
---|
[731] | 529 | std::map<int, StdSize> CField::getGridAttributesBufferSize() |
---|
[509] | 530 | { |
---|
[731] | 531 | return grid->getAttributesBufferSize(); |
---|
[509] | 532 | } |
---|
| 533 | |
---|
[731] | 534 | std::map<int, StdSize> CField::getGridDataBufferSize() |
---|
| 535 | { |
---|
| 536 | return grid->getDataBufferSize(getId()); |
---|
| 537 | } |
---|
| 538 | |
---|
[219] | 539 | //---------------------------------------------------------------- |
---|
| 540 | |
---|
[645] | 541 | void CField::solveServerOperation(void) |
---|
[219] | 542 | { |
---|
[640] | 543 | CContext* context = CContext::getCurrent(); |
---|
[509] | 544 | |
---|
[640] | 545 | if (!context->hasServer || !hasOutputFile) return; |
---|
| 546 | |
---|
[645] | 547 | if (freq_op.isEmpty()) |
---|
| 548 | freq_op.setValue(TimeStep); |
---|
[509] | 549 | |
---|
[538] | 550 | if (freq_offset.isEmpty()) |
---|
| 551 | freq_offset.setValue(NoneDu); |
---|
[219] | 552 | |
---|
[645] | 553 | freq_operation_srv = file->output_freq.getValue(); |
---|
| 554 | freq_write_srv = file->output_freq.getValue(); |
---|
[509] | 555 | |
---|
[651] | 556 | lastlast_Write_srv = context->getCalendar()->getInitDate(); |
---|
| 557 | last_Write_srv = context->getCalendar()->getInitDate(); |
---|
| 558 | last_operation_srv = context->getCalendar()->getInitDate(); |
---|
[509] | 559 | |
---|
[645] | 560 | const CDuration toffset = freq_operation_srv - freq_offset.getValue() - context->getCalendar()->getTimeStep(); |
---|
[651] | 561 | last_operation_srv = last_operation_srv - toffset; |
---|
[509] | 562 | |
---|
[645] | 563 | if (operation.isEmpty()) |
---|
| 564 | ERROR("void CField::solveServerOperation(void)", |
---|
| 565 | << "An operation must be defined for field \"" << getId() << "\"."); |
---|
[509] | 566 | |
---|
[645] | 567 | boost::shared_ptr<func::CFunctor> functor; |
---|
| 568 | CArray<double, 1> dummyData; |
---|
[598] | 569 | |
---|
[562] | 570 | #define DECLARE_FUNCTOR(MType, mtype) \ |
---|
[645] | 571 | if (operation.getValue().compare(#mtype) == 0) \ |
---|
[470] | 572 | { \ |
---|
[645] | 573 | functor.reset(new func::C##MType(dummyData)); \ |
---|
| 574 | } |
---|
[509] | 575 | |
---|
[219] | 576 | #include "functor_type.conf" |
---|
[509] | 577 | |
---|
[645] | 578 | if (!functor) |
---|
| 579 | ERROR("void CField::solveServerOperation(void)", |
---|
| 580 | << "\"" << operation << "\" is not a valid operation."); |
---|
| 581 | |
---|
| 582 | operationTimeType = functor->timeType(); |
---|
[219] | 583 | } |
---|
[509] | 584 | |
---|
[219] | 585 | //---------------------------------------------------------------- |
---|
[640] | 586 | |
---|
| 587 | /*! |
---|
| 588 | * Constructs the graph filter for the field, enabling or not the data output. |
---|
| 589 | * This method should not be called more than once with enableOutput equal to true. |
---|
| 590 | * |
---|
| 591 | * \param gc the garbage collector to use when building the filter graph |
---|
| 592 | * \param enableOutput must be true when the field data is to be |
---|
| 593 | * read by the client or/and written to a file |
---|
| 594 | */ |
---|
| 595 | void CField::buildFilterGraph(CGarbageCollector& gc, bool enableOutput) |
---|
| 596 | { |
---|
[641] | 597 | if (!areAllReferenceSolved) solveAllReferenceEnabledField(false); |
---|
| 598 | |
---|
[640] | 599 | // Start by building a filter which can provide the field's instant data |
---|
| 600 | if (!instantDataFilter) |
---|
| 601 | { |
---|
[642] | 602 | // Check if we have an expression to parse |
---|
| 603 | if (!content.empty()) |
---|
| 604 | { |
---|
| 605 | boost::scoped_ptr<IFilterExprNode> expr(parseExpr(content + '\0')); |
---|
| 606 | instantDataFilter = expr->reduce(gc, *this); |
---|
| 607 | } |
---|
[641] | 608 | // Check if we have a reference on another field |
---|
[642] | 609 | else if (!field_ref.isEmpty()) |
---|
[737] | 610 | instantDataFilter = getFieldReference(gc); |
---|
[640] | 611 | // Check if the data is to be read from a file |
---|
[641] | 612 | else if (file && !file->mode.isEmpty() && file->mode == CFile::mode_attr::read) |
---|
[640] | 613 | instantDataFilter = serverSourceFilter = boost::shared_ptr<CSourceFilter>(new CSourceFilter(grid)); |
---|
| 614 | else // The data might be passed from the model |
---|
| 615 | instantDataFilter = clientSourceFilter = boost::shared_ptr<CSourceFilter>(new CSourceFilter(grid)); |
---|
| 616 | } |
---|
| 617 | |
---|
| 618 | // If the field data is to be read by the client or/and written to a file |
---|
| 619 | if (enableOutput && !storeFilter && !fileWriterFilter) |
---|
| 620 | { |
---|
[741] | 621 | if (!read_access.isEmpty() && read_access) |
---|
[640] | 622 | { |
---|
| 623 | storeFilter = boost::shared_ptr<CStoreFilter>(new CStoreFilter(gc, CContext::getCurrent(), grid)); |
---|
| 624 | instantDataFilter->connectOutput(storeFilter, 0); |
---|
| 625 | } |
---|
| 626 | |
---|
| 627 | if (file && (file->mode.isEmpty() || file->mode == CFile::mode_attr::write)) |
---|
| 628 | { |
---|
| 629 | fileWriterFilter = boost::shared_ptr<CFileWriterFilter>(new CFileWriterFilter(gc, this)); |
---|
[643] | 630 | getTemporalDataFilter(gc, file->output_freq)->connectOutput(fileWriterFilter, 0); |
---|
[640] | 631 | } |
---|
| 632 | } |
---|
| 633 | } |
---|
| 634 | |
---|
[642] | 635 | /*! |
---|
[737] | 636 | * Returns the filter needed to handle the field reference. |
---|
| 637 | * This method should only be called when building the filter graph corresponding to the field. |
---|
| 638 | * |
---|
| 639 | * \param gc the garbage collector to use |
---|
| 640 | * \return the output pin corresponding to the field reference |
---|
| 641 | */ |
---|
| 642 | boost::shared_ptr<COutputPin> CField::getFieldReference(CGarbageCollector& gc) |
---|
| 643 | { |
---|
| 644 | if (instantDataFilter || field_ref.isEmpty()) |
---|
| 645 | ERROR("COutputPin* CField::getFieldReference(CGarbageCollector& gc)", |
---|
| 646 | "Impossible to get the field reference for a field which has already been parsed or which does not have a field_ref."); |
---|
| 647 | |
---|
| 648 | CField* fieldRef = CField::get(field_ref); |
---|
| 649 | fieldRef->buildFilterGraph(gc, false); |
---|
| 650 | |
---|
| 651 | std::pair<boost::shared_ptr<CFilter>, boost::shared_ptr<CFilter> > filters; |
---|
| 652 | // Check if a spatial transformation is needed |
---|
| 653 | if (!grid_ref.isEmpty() && !fieldRef->grid_ref.isEmpty() && grid_ref.getValue() != fieldRef->grid_ref.getValue()) |
---|
| 654 | filters = CSpatialTransformFilter::buildFilterGraph(gc, fieldRef->grid, grid); |
---|
| 655 | else |
---|
| 656 | filters.first = filters.second = boost::shared_ptr<CFilter>(new CPassThroughFilter(gc)); |
---|
| 657 | |
---|
| 658 | fieldRef->getInstantDataFilter()->connectOutput(filters.first, 0); |
---|
| 659 | |
---|
| 660 | return filters.second; |
---|
| 661 | } |
---|
| 662 | |
---|
| 663 | /*! |
---|
| 664 | * Returns the filter needed to handle a self reference in the field's expression. |
---|
| 665 | * If the needed filter does not exist, it is created, otherwise it is reused. |
---|
[642] | 666 | * This method should only be called when building the filter graph corresponding |
---|
| 667 | * to the field's expression. |
---|
| 668 | * |
---|
| 669 | * \param gc the garbage collector to use |
---|
| 670 | * \return the output pin corresponding to a self reference |
---|
| 671 | */ |
---|
| 672 | boost::shared_ptr<COutputPin> CField::getSelfReference(CGarbageCollector& gc) |
---|
| 673 | { |
---|
| 674 | if (instantDataFilter || content.empty()) |
---|
| 675 | ERROR("COutputPin* CField::getSelfReference(CGarbageCollector& gc)", |
---|
| 676 | "Impossible to add a self reference to a field which has already been parsed or which does not have an expression."); |
---|
| 677 | |
---|
[737] | 678 | if (!selfReferenceFilter) |
---|
| 679 | { |
---|
[741] | 680 | if (file && !file->mode.isEmpty() && file->mode == CFile::mode_attr::read) |
---|
| 681 | { |
---|
| 682 | if (!serverSourceFilter) |
---|
| 683 | serverSourceFilter = boost::shared_ptr<CSourceFilter>(new CSourceFilter(grid)); |
---|
| 684 | |
---|
| 685 | selfReferenceFilter = serverSourceFilter; |
---|
| 686 | } |
---|
| 687 | else if (!field_ref.isEmpty()) |
---|
[737] | 688 | selfReferenceFilter = getFieldReference(gc); |
---|
| 689 | else |
---|
| 690 | { |
---|
| 691 | if (!clientSourceFilter) |
---|
| 692 | clientSourceFilter = boost::shared_ptr<CSourceFilter>(new CSourceFilter(grid)); |
---|
[642] | 693 | |
---|
[737] | 694 | selfReferenceFilter = clientSourceFilter; |
---|
| 695 | } |
---|
| 696 | } |
---|
| 697 | |
---|
| 698 | return selfReferenceFilter; |
---|
[642] | 699 | } |
---|
| 700 | |
---|
[643] | 701 | /*! |
---|
| 702 | * Returns the temporal filter corresponding to the field's temporal operation |
---|
| 703 | * for the specified operation frequency. The filter is created if it does not |
---|
| 704 | * exist, otherwise it is reused. |
---|
| 705 | * |
---|
| 706 | * \param gc the garbage collector to use |
---|
| 707 | * \param outFreq the operation frequency, i.e. the frequency at which the output data will be computed |
---|
| 708 | * \return the output pin corresponding to the requested temporal filter |
---|
| 709 | */ |
---|
| 710 | boost::shared_ptr<COutputPin> CField::getTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq) |
---|
| 711 | { |
---|
| 712 | std::map<CDuration, boost::shared_ptr<COutputPin> >::iterator it = temporalDataFilters.find(outFreq); |
---|
| 713 | |
---|
| 714 | if (it == temporalDataFilters.end()) |
---|
| 715 | { |
---|
| 716 | if (operation.isEmpty()) |
---|
| 717 | ERROR("void CField::getTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq)", |
---|
| 718 | << "An operation must be defined for field \"" << getId() << "\"."); |
---|
| 719 | |
---|
| 720 | if (freq_op.isEmpty()) |
---|
| 721 | freq_op.setValue(TimeStep); |
---|
| 722 | if (freq_offset.isEmpty()) |
---|
| 723 | freq_offset.setValue(NoneDu); |
---|
| 724 | |
---|
| 725 | const bool ignoreMissingValue = (!detect_missing_value.isEmpty() && !default_value.isEmpty() && detect_missing_value == true); |
---|
| 726 | |
---|
| 727 | boost::shared_ptr<CTemporalFilter> temporalFilter(new CTemporalFilter(gc, operation, |
---|
| 728 | CContext::getCurrent()->getCalendar()->getInitDate(), |
---|
| 729 | freq_op, freq_offset, outFreq, |
---|
| 730 | ignoreMissingValue, ignoreMissingValue ? default_value : 0.0)); |
---|
| 731 | instantDataFilter->connectOutput(temporalFilter, 0); |
---|
| 732 | |
---|
| 733 | it = temporalDataFilters.insert(std::make_pair(outFreq, temporalFilter)).first; |
---|
| 734 | } |
---|
| 735 | |
---|
| 736 | return it->second; |
---|
| 737 | } |
---|
| 738 | |
---|
[640] | 739 | //---------------------------------------------------------------- |
---|
[369] | 740 | /* |
---|
[562] | 741 | void CField::fromBinary(StdIStream& is) |
---|
[219] | 742 | { |
---|
| 743 | SuperClass::fromBinary(is); |
---|
| 744 | #define CLEAR_ATT(name_)\ |
---|
[369] | 745 | SuperClassAttribute::operator[](#name_)->reset() |
---|
[219] | 746 | |
---|
| 747 | CLEAR_ATT(domain_ref); |
---|
| 748 | CLEAR_ATT(axis_ref); |
---|
| 749 | #undef CLEAR_ATT |
---|
| 750 | |
---|
| 751 | } |
---|
[369] | 752 | */ |
---|
[219] | 753 | //---------------------------------------------------------------- |
---|
| 754 | |
---|
| 755 | void CField::solveGridReference(void) |
---|
| 756 | { |
---|
[742] | 757 | if (grid_ref.isEmpty() && domain_ref.isEmpty() && axis_ref.isEmpty()) |
---|
| 758 | { |
---|
| 759 | ERROR("CField::solveGridReference(void)", |
---|
[744] | 760 | << "A grid must be defined for field '" << (!name.isEmpty() ? name.getValue() : getId()) << "' ."); |
---|
[742] | 761 | } |
---|
[744] | 762 | else if (!grid_ref.isEmpty() && (!domain_ref.isEmpty() || !axis_ref.isEmpty())) |
---|
[219] | 763 | { |
---|
[744] | 764 | ERROR("CField::solveGridReference(void)", |
---|
| 765 | << "Field '" << (!name.isEmpty() ? name.getValue() : getId()) << "' has both a grid and a domain/axis." << std::endl |
---|
| 766 | << "Please define either 'grid_ref' or 'domain_ref'/'axis_ref'."); |
---|
[219] | 767 | } |
---|
| 768 | |
---|
[744] | 769 | if (grid_ref.isEmpty()) |
---|
[219] | 770 | { |
---|
[744] | 771 | std::vector<CDomain*> vecDom; |
---|
| 772 | std::vector<CAxis*> vecAxis; |
---|
[742] | 773 | |
---|
[744] | 774 | if (!domain_ref.isEmpty()) |
---|
| 775 | { |
---|
| 776 | if (CDomain::has(domain_ref)) |
---|
| 777 | vecDom.push_back(CDomain::get(domain_ref)); |
---|
| 778 | else |
---|
[219] | 779 | ERROR("CField::solveGridReference(void)", |
---|
[744] | 780 | << "Invalid reference to domain '" << domain_ref.getValue() << "'."); |
---|
| 781 | } |
---|
[219] | 782 | |
---|
[744] | 783 | if (!axis_ref.isEmpty()) |
---|
[742] | 784 | { |
---|
[744] | 785 | if (CAxis::has(axis_ref)) |
---|
| 786 | vecAxis.push_back(CAxis::get(axis_ref)); |
---|
| 787 | else |
---|
| 788 | ERROR("CField::solveGridReference(void)", |
---|
| 789 | << "Invalid reference to axis '" << axis_ref.getValue() << "'."); |
---|
[742] | 790 | } |
---|
[744] | 791 | |
---|
[745] | 792 | // Warning: the gridId shouldn't be set as the grid_ref since it could be inherited |
---|
| 793 | StdString gridId = CGrid::generateId(vecDom, vecAxis); |
---|
| 794 | if (CGrid::has(gridId)) |
---|
| 795 | this->grid = CGrid::get(gridId); |
---|
| 796 | else |
---|
| 797 | this->grid = CGrid::createGrid(gridId, vecDom, vecAxis); |
---|
[219] | 798 | } |
---|
[586] | 799 | else |
---|
| 800 | { |
---|
[744] | 801 | if (CGrid::has(grid_ref)) |
---|
| 802 | this->grid = CGrid::get(grid_ref); |
---|
| 803 | else |
---|
| 804 | ERROR("CField::solveGridReference(void)", |
---|
| 805 | << "Invalid reference to grid '" << grid_ref.getValue() << "'."); |
---|
[586] | 806 | } |
---|
[509] | 807 | } |
---|
[459] | 808 | |
---|
[509] | 809 | void CField::solveGridDomainAxisRef(bool checkAtt) |
---|
| 810 | { |
---|
| 811 | grid->solveDomainAxisRef(checkAtt); |
---|
[219] | 812 | } |
---|
| 813 | |
---|
[509] | 814 | void CField::solveCheckMaskIndex(bool doSendingIndex) |
---|
| 815 | { |
---|
| 816 | grid->checkMaskIndex(doSendingIndex); |
---|
| 817 | } |
---|
[219] | 818 | |
---|
[619] | 819 | void CField::solveTransformedGrid() |
---|
| 820 | { |
---|
[644] | 821 | if (!grid_ref.isEmpty() && hasDirectFieldReference() && !getDirectFieldReference()->grid_ref.isEmpty() |
---|
| 822 | && grid_ref.getValue() != getDirectFieldReference()->grid_ref.getValue() && !grid->isTransformed()) |
---|
| 823 | grid->transformGrid(getDirectFieldReference()->grid); |
---|
[619] | 824 | } |
---|
| 825 | |
---|
[687] | 826 | void CField::solveGenerateGrid() |
---|
| 827 | { |
---|
| 828 | if (!grid_ref.isEmpty() && hasDirectFieldReference() && !getDirectFieldReference()->grid_ref.isEmpty() |
---|
| 829 | && grid_ref.getValue() != getDirectFieldReference()->grid_ref.getValue() && !grid->isTransformed()) |
---|
| 830 | grid->completeGrid(getDirectFieldReference()->grid); |
---|
| 831 | } |
---|
| 832 | |
---|
[219] | 833 | ///------------------------------------------------------------------- |
---|
| 834 | |
---|
| 835 | template <> |
---|
[562] | 836 | void CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void) |
---|
[219] | 837 | { |
---|
| 838 | if (this->group_ref.isEmpty()) return; |
---|
| 839 | StdString gref = this->group_ref.getValue(); |
---|
| 840 | |
---|
[346] | 841 | if (!CFieldGroup::has(gref)) |
---|
[219] | 842 | ERROR("CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void)", |
---|
| 843 | << "[ gref = " << gref << "]" |
---|
| 844 | << " invalid group name !"); |
---|
| 845 | |
---|
[347] | 846 | CFieldGroup* group = CFieldGroup::get(gref); |
---|
| 847 | CFieldGroup* owner = CFieldGroup::get(boost::polymorphic_downcast<CFieldGroup*>(this)); |
---|
[219] | 848 | |
---|
[347] | 849 | std::vector<CField*> allChildren = group->getAllChildren(); |
---|
[562] | 850 | std::vector<CField*>::iterator it = allChildren.begin(), end = allChildren.end(); |
---|
[509] | 851 | |
---|
[219] | 852 | for (; it != end; it++) |
---|
| 853 | { |
---|
[347] | 854 | CField* child = *it; |
---|
[562] | 855 | if (child->hasId()) owner->createChild()->field_ref.setValue(child->getId()); |
---|
[509] | 856 | |
---|
[219] | 857 | } |
---|
| 858 | } |
---|
[509] | 859 | |
---|
[464] | 860 | void CField::scaleFactorAddOffset(double scaleFactor, double addOffset) |
---|
| 861 | { |
---|
[651] | 862 | map<int, CArray<double,1> >::iterator it; |
---|
| 863 | for (it = data_srv.begin(); it != data_srv.end(); it++) it->second = (it->second - addOffset) / scaleFactor; |
---|
[464] | 864 | } |
---|
[509] | 865 | |
---|
[599] | 866 | void CField::invertScaleFactorAddOffset(double scaleFactor, double addOffset) |
---|
| 867 | { |
---|
[651] | 868 | map<int, CArray<double,1> >::iterator it; |
---|
| 869 | for (it = data_srv.begin(); it != data_srv.end(); it++) it->second = it->second * scaleFactor + addOffset; |
---|
[599] | 870 | } |
---|
| 871 | |
---|
[369] | 872 | void CField::outputField(CArray<double,3>& fieldOut) |
---|
[300] | 873 | { |
---|
[651] | 874 | map<int, CArray<double,1> >::iterator it; |
---|
[562] | 875 | for (it = data_srv.begin(); it != data_srv.end(); it++) |
---|
[551] | 876 | { |
---|
[651] | 877 | grid->outputField(it->first, it->second, fieldOut.dataFirst()); |
---|
[551] | 878 | } |
---|
[300] | 879 | } |
---|
[509] | 880 | |
---|
[369] | 881 | void CField::outputField(CArray<double,2>& fieldOut) |
---|
[300] | 882 | { |
---|
[651] | 883 | map<int, CArray<double,1> >::iterator it; |
---|
[567] | 884 | for(it=data_srv.begin();it!=data_srv.end();it++) |
---|
| 885 | { |
---|
[676] | 886 | grid->outputField(it->first, it->second, fieldOut.dataFirst()); |
---|
[567] | 887 | } |
---|
| 888 | } |
---|
[219] | 889 | |
---|
[567] | 890 | void CField::outputField(CArray<double,1>& fieldOut) |
---|
| 891 | { |
---|
[651] | 892 | map<int, CArray<double,1> >::iterator it; |
---|
[567] | 893 | |
---|
[562] | 894 | for (it = data_srv.begin(); it != data_srv.end(); it++) |
---|
[300] | 895 | { |
---|
[676] | 896 | grid->outputField(it->first, it->second, fieldOut.dataFirst()); |
---|
[300] | 897 | } |
---|
| 898 | } |
---|
[551] | 899 | |
---|
[599] | 900 | void CField::inputField(CArray<double,3>& fieldOut) |
---|
| 901 | { |
---|
[651] | 902 | map<int, CArray<double,1> >::iterator it; |
---|
[599] | 903 | for (it = data_srv.begin(); it != data_srv.end(); it++) |
---|
| 904 | { |
---|
[651] | 905 | grid->inputField(it->first, fieldOut.dataFirst(), it->second); |
---|
[599] | 906 | } |
---|
| 907 | } |
---|
| 908 | |
---|
| 909 | void CField::inputField(CArray<double,2>& fieldOut) |
---|
| 910 | { |
---|
[651] | 911 | map<int, CArray<double,1> >::iterator it; |
---|
[599] | 912 | for(it = data_srv.begin(); it != data_srv.end(); it++) |
---|
| 913 | { |
---|
[651] | 914 | grid->inputField(it->first, fieldOut.dataFirst(), it->second); |
---|
[599] | 915 | } |
---|
| 916 | } |
---|
| 917 | |
---|
| 918 | void CField::inputField(CArray<double,1>& fieldOut) |
---|
| 919 | { |
---|
[651] | 920 | map<int, CArray<double,1> >::iterator it; |
---|
[599] | 921 | for (it = data_srv.begin(); it != data_srv.end(); it++) |
---|
| 922 | { |
---|
[651] | 923 | grid->inputField(it->first, fieldOut.dataFirst(), it->second); |
---|
[599] | 924 | } |
---|
| 925 | } |
---|
| 926 | |
---|
[676] | 927 | void CField::outputCompressedField(CArray<double,1>& fieldOut) |
---|
| 928 | { |
---|
| 929 | map<int, CArray<double,1> >::iterator it; |
---|
| 930 | |
---|
| 931 | for (it = data_srv.begin(); it != data_srv.end(); it++) |
---|
| 932 | { |
---|
| 933 | grid->outputCompressedField(it->first, it->second, fieldOut.dataFirst()); |
---|
| 934 | } |
---|
| 935 | } |
---|
| 936 | |
---|
[219] | 937 | ///------------------------------------------------------------------- |
---|
| 938 | |
---|
[562] | 939 | void CField::parse(xml::CXMLNode& node) |
---|
[459] | 940 | { |
---|
| 941 | SuperClass::parse(node); |
---|
[562] | 942 | if (!node.getContent(this->content)) |
---|
[472] | 943 | { |
---|
[476] | 944 | if (node.goToChildElement()) |
---|
[472] | 945 | { |
---|
[476] | 946 | do |
---|
| 947 | { |
---|
[562] | 948 | if (node.getElementName() == "variable" || node.getElementName() == "variable_group") this->getVirtualVariableGroup()->parseChild(node); |
---|
| 949 | } while (node.goToNextElement()); |
---|
[476] | 950 | node.goToParentElement(); |
---|
| 951 | } |
---|
[472] | 952 | } |
---|
[459] | 953 | } |
---|
[509] | 954 | |
---|
| 955 | /*! |
---|
| 956 | This function retrieves Id of corresponding domain_ref and axis_ref (if any) |
---|
| 957 | of a field. In some cases, only domain exists but axis doesn't |
---|
| 958 | \return pair of Domain and Axis id |
---|
| 959 | */ |
---|
[569] | 960 | const std::pair<StdString,StdString>& CField::getRefDomainAxisIds() |
---|
| 961 | { |
---|
| 962 | CGrid* cgPtr = getRelGrid(); |
---|
| 963 | if (NULL != cgPtr) |
---|
| 964 | { |
---|
| 965 | std::vector<StdString>::iterator it; |
---|
| 966 | if (!domain_ref.isEmpty()) |
---|
| 967 | { |
---|
| 968 | std::vector<StdString> domainList = cgPtr->getDomainList(); |
---|
| 969 | it = std::find(domainList.begin(), domainList.end(), domain_ref.getValue()); |
---|
| 970 | if (domainList.end() != it) domAxisIds_.first = *it; |
---|
| 971 | } |
---|
[472] | 972 | |
---|
[569] | 973 | if (!axis_ref.isEmpty()) |
---|
| 974 | { |
---|
| 975 | std::vector<StdString> axisList = cgPtr->getAxisList(); |
---|
| 976 | it = std::find(axisList.begin(), axisList.end(), axis_ref.getValue()); |
---|
| 977 | if (axisList.end() != it) domAxisIds_.second = *it; |
---|
| 978 | } |
---|
| 979 | } |
---|
| 980 | return (domAxisIds_); |
---|
| 981 | } |
---|
| 982 | |
---|
[472] | 983 | CVariable* CField::addVariable(const string& id) |
---|
| 984 | { |
---|
[562] | 985 | return vVariableGroup->createChild(id); |
---|
[472] | 986 | } |
---|
| 987 | |
---|
| 988 | CVariableGroup* CField::addVariableGroup(const string& id) |
---|
| 989 | { |
---|
[562] | 990 | return vVariableGroup->createChildGroup(id); |
---|
[472] | 991 | } |
---|
| 992 | |
---|
[509] | 993 | void CField::sendAddAllVariables() |
---|
| 994 | { |
---|
| 995 | if (!getAllVariables().empty()) |
---|
| 996 | { |
---|
| 997 | // Firstly, it's necessary to add virtual variable group |
---|
| 998 | sendAddVariableGroup(getVirtualVariableGroup()->getId()); |
---|
| 999 | |
---|
| 1000 | // Okie, now we can add to this variable group |
---|
| 1001 | std::vector<CVariable*> allVar = getAllVariables(); |
---|
| 1002 | std::vector<CVariable*>::const_iterator it = allVar.begin(); |
---|
| 1003 | std::vector<CVariable*>::const_iterator itE = allVar.end(); |
---|
| 1004 | |
---|
| 1005 | for (; it != itE; ++it) |
---|
| 1006 | { |
---|
| 1007 | this->sendAddVariable((*it)->getId()); |
---|
| 1008 | (*it)->sendAllAttributesToServer(); |
---|
| 1009 | (*it)->sendValue(); |
---|
| 1010 | } |
---|
| 1011 | } |
---|
| 1012 | } |
---|
| 1013 | |
---|
[472] | 1014 | void CField::sendAddVariable(const string& id) |
---|
| 1015 | { |
---|
[562] | 1016 | CContext* context = CContext::getCurrent(); |
---|
[509] | 1017 | |
---|
[562] | 1018 | if (!context->hasServer) |
---|
[472] | 1019 | { |
---|
[562] | 1020 | CContextClient* client = context->client; |
---|
[472] | 1021 | |
---|
[562] | 1022 | CEventClient event(this->getType(),EVENT_ID_ADD_VARIABLE); |
---|
[472] | 1023 | if (client->isServerLeader()) |
---|
| 1024 | { |
---|
[562] | 1025 | CMessage msg; |
---|
| 1026 | msg << this->getId(); |
---|
| 1027 | msg << id; |
---|
[595] | 1028 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
| 1029 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 1030 | event.push(*itRank,1,msg); |
---|
[562] | 1031 | client->sendEvent(event); |
---|
[472] | 1032 | } |
---|
[562] | 1033 | else client->sendEvent(event); |
---|
[472] | 1034 | } |
---|
| 1035 | } |
---|
[509] | 1036 | |
---|
[472] | 1037 | void CField::sendAddVariableGroup(const string& id) |
---|
| 1038 | { |
---|
[562] | 1039 | CContext* context = CContext::getCurrent(); |
---|
| 1040 | if (!context->hasServer) |
---|
[472] | 1041 | { |
---|
[562] | 1042 | CContextClient* client = context->client; |
---|
[472] | 1043 | |
---|
[562] | 1044 | CEventClient event(this->getType(),EVENT_ID_ADD_VARIABLE_GROUP); |
---|
[472] | 1045 | if (client->isServerLeader()) |
---|
| 1046 | { |
---|
[562] | 1047 | CMessage msg; |
---|
| 1048 | msg << this->getId(); |
---|
| 1049 | msg << id; |
---|
[595] | 1050 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
| 1051 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 1052 | event.push(*itRank,1,msg); |
---|
[562] | 1053 | client->sendEvent(event); |
---|
[472] | 1054 | } |
---|
[562] | 1055 | else client->sendEvent(event); |
---|
[472] | 1056 | } |
---|
| 1057 | } |
---|
[509] | 1058 | |
---|
[472] | 1059 | void CField::recvAddVariable(CEventServer& event) |
---|
| 1060 | { |
---|
[509] | 1061 | |
---|
[562] | 1062 | CBufferIn* buffer = event.subEvents.begin()->buffer; |
---|
[472] | 1063 | string id; |
---|
[562] | 1064 | *buffer >> id; |
---|
| 1065 | get(id)->recvAddVariable(*buffer); |
---|
[472] | 1066 | } |
---|
[509] | 1067 | |
---|
[472] | 1068 | void CField::recvAddVariable(CBufferIn& buffer) |
---|
| 1069 | { |
---|
[562] | 1070 | string id; |
---|
| 1071 | buffer >> id; |
---|
| 1072 | addVariable(id); |
---|
[472] | 1073 | } |
---|
| 1074 | |
---|
| 1075 | void CField::recvAddVariableGroup(CEventServer& event) |
---|
| 1076 | { |
---|
[509] | 1077 | |
---|
[562] | 1078 | CBufferIn* buffer = event.subEvents.begin()->buffer; |
---|
[472] | 1079 | string id; |
---|
[562] | 1080 | *buffer >> id; |
---|
| 1081 | get(id)->recvAddVariableGroup(*buffer); |
---|
[472] | 1082 | } |
---|
[509] | 1083 | |
---|
[472] | 1084 | void CField::recvAddVariableGroup(CBufferIn& buffer) |
---|
| 1085 | { |
---|
[562] | 1086 | string id; |
---|
| 1087 | buffer >> id; |
---|
| 1088 | addVariableGroup(id); |
---|
[472] | 1089 | } |
---|
| 1090 | |
---|
[540] | 1091 | DEFINE_REF_FUNC(Field,field) |
---|
[335] | 1092 | } // namespace xios |
---|