[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 | |
---|
[1149] | 28 | /// ////////////////////// Dfinitions ////////////////////// /// |
---|
[219] | 29 | |
---|
| 30 | CField::CField(void) |
---|
| 31 | : CObjectTemplate<CField>(), CFieldAttributes() |
---|
| 32 | , grid(), file() |
---|
[707] | 33 | , written(false) |
---|
[645] | 34 | , nstep(0), nstepMax(0) |
---|
| 35 | , hasOutputFile(false) |
---|
[887] | 36 | , domAxisScalarIds_(vector<StdString>(3,"")), areAllReferenceSolved(false), isReferenceSolved(false) |
---|
[676] | 37 | , useCompressedOutput(false) |
---|
[989] | 38 | , hasTimeInstant(false) |
---|
| 39 | , hasTimeCentered(false) |
---|
[1013] | 40 | , wasDataAlreadyReceivedFromServer(false) |
---|
[1017] | 41 | , isEOF(false) |
---|
[957] | 42 | { setVirtualVariableGroup(CVariableGroup::create(getId() + "_virtual_variable_group")); } |
---|
[219] | 43 | |
---|
[562] | 44 | CField::CField(const StdString& id) |
---|
[219] | 45 | : CObjectTemplate<CField>(id), CFieldAttributes() |
---|
| 46 | , grid(), file() |
---|
[707] | 47 | , written(false) |
---|
[645] | 48 | , nstep(0), nstepMax(0) |
---|
| 49 | , hasOutputFile(false) |
---|
[887] | 50 | , domAxisScalarIds_(vector<StdString>(3,"")), areAllReferenceSolved(false), isReferenceSolved(false) |
---|
[676] | 51 | , useCompressedOutput(false) |
---|
[989] | 52 | , hasTimeInstant(false) |
---|
| 53 | , hasTimeCentered(false) |
---|
[1013] | 54 | , wasDataAlreadyReceivedFromServer(false) |
---|
[1017] | 55 | , isEOF(false) |
---|
[957] | 56 | { setVirtualVariableGroup(CVariableGroup::create(getId() + "_virtual_variable_group")); } |
---|
[219] | 57 | |
---|
| 58 | CField::~CField(void) |
---|
[645] | 59 | {} |
---|
[509] | 60 | |
---|
[472] | 61 | //---------------------------------------------------------------- |
---|
| 62 | |
---|
| 63 | void CField::setVirtualVariableGroup(CVariableGroup* newVVariableGroup) |
---|
[509] | 64 | { |
---|
| 65 | this->vVariableGroup = newVVariableGroup; |
---|
[472] | 66 | } |
---|
[509] | 67 | |
---|
[472] | 68 | CVariableGroup* CField::getVirtualVariableGroup(void) const |
---|
| 69 | { |
---|
[562] | 70 | return this->vVariableGroup; |
---|
[472] | 71 | } |
---|
| 72 | |
---|
| 73 | std::vector<CVariable*> CField::getAllVariables(void) const |
---|
| 74 | { |
---|
[562] | 75 | return this->vVariableGroup->getAllChildren(); |
---|
[472] | 76 | } |
---|
[509] | 77 | |
---|
[562] | 78 | void CField::solveDescInheritance(bool apply, const CAttributeMap* const parent) |
---|
[472] | 79 | { |
---|
[562] | 80 | SuperClassAttribute::setAttributes(parent, apply); |
---|
[472] | 81 | this->getVirtualVariableGroup()->solveDescInheritance(apply, NULL); |
---|
| 82 | } |
---|
[219] | 83 | |
---|
[645] | 84 | //---------------------------------------------------------------- |
---|
[509] | 85 | |
---|
[598] | 86 | bool CField::dispatchEvent(CEventServer& event) |
---|
[300] | 87 | { |
---|
[562] | 88 | if (SuperClass::dispatchEvent(event)) return true; |
---|
[300] | 89 | else |
---|
| 90 | { |
---|
| 91 | switch(event.type) |
---|
| 92 | { |
---|
| 93 | case EVENT_ID_UPDATE_DATA : |
---|
[562] | 94 | recvUpdateData(event); |
---|
| 95 | return true; |
---|
| 96 | break; |
---|
[472] | 97 | |
---|
[598] | 98 | case EVENT_ID_READ_DATA : |
---|
| 99 | recvReadDataRequest(event); |
---|
| 100 | return true; |
---|
| 101 | break; |
---|
[509] | 102 | |
---|
[598] | 103 | case EVENT_ID_READ_DATA_READY : |
---|
| 104 | recvReadDataReady(event); |
---|
| 105 | return true; |
---|
| 106 | break; |
---|
[509] | 107 | |
---|
[598] | 108 | case EVENT_ID_ADD_VARIABLE : |
---|
| 109 | recvAddVariable(event); |
---|
| 110 | return true; |
---|
| 111 | break; |
---|
| 112 | |
---|
| 113 | case EVENT_ID_ADD_VARIABLE_GROUP : |
---|
| 114 | recvAddVariableGroup(event); |
---|
| 115 | return true; |
---|
| 116 | break; |
---|
| 117 | |
---|
[300] | 118 | default : |
---|
[562] | 119 | ERROR("bool CField::dispatchEvent(CEventServer& event)", << "Unknown Event"); |
---|
| 120 | return false; |
---|
[300] | 121 | } |
---|
| 122 | } |
---|
| 123 | } |
---|
[509] | 124 | |
---|
[638] | 125 | void CField::sendUpdateData(const CArray<double,1>& data) |
---|
| 126 | { |
---|
[1160] | 127 | CTimer::get("XIOS Send Data").resume(); |
---|
[638] | 128 | |
---|
| 129 | CContext* context = CContext::getCurrent(); |
---|
| 130 | CContextClient* client = context->client; |
---|
| 131 | |
---|
| 132 | CEventClient event(getType(), EVENT_ID_UPDATE_DATA); |
---|
| 133 | |
---|
[650] | 134 | map<int, CArray<int,1> >::iterator it; |
---|
[638] | 135 | list<CMessage> list_msg; |
---|
| 136 | list<CArray<double,1> > list_data; |
---|
| 137 | |
---|
| 138 | if (!grid->doGridHaveDataDistributed()) |
---|
| 139 | { |
---|
[967] | 140 | if (client->isServerLeader()) |
---|
[638] | 141 | { |
---|
| 142 | for (it = grid->storeIndex_toSrv.begin(); it != grid->storeIndex_toSrv.end(); it++) |
---|
| 143 | { |
---|
[650] | 144 | int rank = it->first; |
---|
| 145 | CArray<int,1>& index = it->second; |
---|
[638] | 146 | |
---|
| 147 | list_msg.push_back(CMessage()); |
---|
| 148 | list_data.push_back(CArray<double,1>(index.numElements())); |
---|
| 149 | |
---|
| 150 | CArray<double,1>& data_tmp = list_data.back(); |
---|
| 151 | for (int n = 0; n < data_tmp.numElements(); n++) data_tmp(n) = data(index(n)); |
---|
| 152 | |
---|
| 153 | list_msg.back() << getId() << data_tmp; |
---|
| 154 | event.push(rank, 1, list_msg.back()); |
---|
| 155 | } |
---|
| 156 | client->sendEvent(event); |
---|
[967] | 157 | } |
---|
| 158 | else client->sendEvent(event); |
---|
[638] | 159 | } |
---|
| 160 | else |
---|
| 161 | { |
---|
| 162 | for (it = grid->storeIndex_toSrv.begin(); it != grid->storeIndex_toSrv.end(); it++) |
---|
| 163 | { |
---|
[650] | 164 | int rank = it->first; |
---|
| 165 | CArray<int,1>& index = it->second; |
---|
[638] | 166 | |
---|
| 167 | list_msg.push_back(CMessage()); |
---|
| 168 | list_data.push_back(CArray<double,1>(index.numElements())); |
---|
| 169 | |
---|
| 170 | CArray<double,1>& data_tmp = list_data.back(); |
---|
| 171 | for (int n = 0; n < data_tmp.numElements(); n++) data_tmp(n) = data(index(n)); |
---|
| 172 | |
---|
| 173 | list_msg.back() << getId() << data_tmp; |
---|
| 174 | event.push(rank, grid->nbSenders[rank], list_msg.back()); |
---|
| 175 | } |
---|
| 176 | client->sendEvent(event); |
---|
| 177 | } |
---|
[687] | 178 | |
---|
[1160] | 179 | CTimer::get("XIOS Send Data").suspend(); |
---|
[638] | 180 | } |
---|
| 181 | |
---|
[300] | 182 | void CField::recvUpdateData(CEventServer& event) |
---|
| 183 | { |
---|
[562] | 184 | vector<int> ranks; |
---|
| 185 | vector<CBufferIn*> buffers; |
---|
[509] | 186 | |
---|
[562] | 187 | list<CEventServer::SSubEvent>::iterator it; |
---|
| 188 | string fieldId; |
---|
[1160] | 189 | |
---|
[562] | 190 | for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it) |
---|
[300] | 191 | { |
---|
[562] | 192 | int rank = it->rank; |
---|
| 193 | CBufferIn* buffer = it->buffer; |
---|
| 194 | *buffer >> fieldId; |
---|
| 195 | ranks.push_back(rank); |
---|
| 196 | buffers.push_back(buffer); |
---|
[300] | 197 | } |
---|
[562] | 198 | get(fieldId)->recvUpdateData(ranks,buffers); |
---|
[300] | 199 | } |
---|
[509] | 200 | |
---|
[300] | 201 | void CField::recvUpdateData(vector<int>& ranks, vector<CBufferIn*>& buffers) |
---|
| 202 | { |
---|
| 203 | if (data_srv.empty()) |
---|
| 204 | { |
---|
[650] | 205 | for (map<int, CArray<size_t, 1> >::iterator it = grid->outIndexFromClient.begin(); it != grid->outIndexFromClient.end(); ++it) |
---|
[300] | 206 | { |
---|
[562] | 207 | int rank = it->first; |
---|
[651] | 208 | data_srv.insert(std::make_pair(rank, CArray<double,1>(it->second.numElements()))); |
---|
| 209 | foperation_srv.insert(pair<int,boost::shared_ptr<func::CFunctor> >(rank,boost::shared_ptr<func::CFunctor>(new func::CInstant(data_srv[rank])))); |
---|
[300] | 210 | } |
---|
| 211 | } |
---|
| 212 | |
---|
[562] | 213 | CContext* context = CContext::getCurrent(); |
---|
| 214 | const CDate& currDate = context->getCalendar()->getCurrentDate(); |
---|
[854] | 215 | const CDate opeDate = last_operation_srv +freq_op + freq_operation_srv - freq_op; |
---|
[651] | 216 | const CDate writeDate = last_Write_srv + freq_write_srv; |
---|
[300] | 217 | |
---|
| 218 | if (opeDate <= currDate) |
---|
| 219 | { |
---|
[562] | 220 | for (int n = 0; n < ranks.size(); n++) |
---|
[300] | 221 | { |
---|
[562] | 222 | CArray<double,1> data_tmp; |
---|
| 223 | *buffers[n] >> data_tmp; |
---|
| 224 | (*foperation_srv[ranks[n]])(data_tmp); |
---|
[300] | 225 | } |
---|
[651] | 226 | last_operation_srv = currDate; |
---|
[300] | 227 | } |
---|
[509] | 228 | |
---|
[300] | 229 | if (writeDate < (currDate + freq_operation_srv)) |
---|
| 230 | { |
---|
[562] | 231 | for (int n = 0; n < ranks.size(); n++) |
---|
[300] | 232 | { |
---|
| 233 | this->foperation_srv[ranks[n]]->final(); |
---|
| 234 | } |
---|
[509] | 235 | |
---|
[651] | 236 | last_Write_srv = writeDate; |
---|
[562] | 237 | writeField(); |
---|
[651] | 238 | lastlast_Write_srv = last_Write_srv; |
---|
[300] | 239 | } |
---|
| 240 | } |
---|
[509] | 241 | |
---|
[300] | 242 | void CField::writeField(void) |
---|
| 243 | { |
---|
[562] | 244 | if (!getRelFile()->allDomainEmpty) |
---|
[586] | 245 | { |
---|
[599] | 246 | if (grid->doGridHaveDataToWrite() || getRelFile()->type == CFile::type_attr::one_file) |
---|
[379] | 247 | { |
---|
| 248 | getRelFile()->checkFile(); |
---|
| 249 | this->incrementNStep(); |
---|
| 250 | getRelFile()->getDataOutput()->writeFieldData(CField::get(this)); |
---|
| 251 | } |
---|
[586] | 252 | } |
---|
[300] | 253 | } |
---|
[562] | 254 | |
---|
[1017] | 255 | bool CField::sendReadDataRequest(const CDate& tsDataRequested) |
---|
[598] | 256 | { |
---|
| 257 | CContext* context = CContext::getCurrent(); |
---|
| 258 | CContextClient* client = context->client; |
---|
| 259 | |
---|
[1013] | 260 | lastDataRequestedFromServer = tsDataRequested; |
---|
[708] | 261 | |
---|
[1017] | 262 | if (!isEOF) // No need to send the request if we already know we are at EOF |
---|
[598] | 263 | { |
---|
[1017] | 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); |
---|
[598] | 275 | } |
---|
[1017] | 276 | else |
---|
| 277 | serverSourceFilter->signalEndOfStream(tsDataRequested); |
---|
| 278 | |
---|
| 279 | return !isEOF; |
---|
[598] | 280 | } |
---|
| 281 | |
---|
| 282 | /*! |
---|
| 283 | Send request new data read from file if need be, that is the current data is out-of-date. |
---|
| 284 | \return true if and only if some data was requested |
---|
| 285 | */ |
---|
| 286 | bool CField::sendReadDataRequestIfNeeded(void) |
---|
| 287 | { |
---|
| 288 | const CDate& currentDate = CContext::getCurrent()->getCalendar()->getCurrentDate(); |
---|
| 289 | |
---|
[1013] | 290 | bool dataRequested = false; |
---|
[598] | 291 | |
---|
[1013] | 292 | while (currentDate >= lastDataRequestedFromServer) |
---|
[850] | 293 | { |
---|
[1155] | 294 | #pragma omp critical (_output) |
---|
| 295 | { |
---|
| 296 | info(20) << "currentDate : " << currentDate << endl ; |
---|
| 297 | info(20) << "lastDataRequestedFromServer : " << lastDataRequestedFromServer << endl ; |
---|
| 298 | info(20) << "file->output_freq.getValue() : " << file->output_freq.getValue() << endl ; |
---|
| 299 | info(20) << "lastDataRequestedFromServer + file->output_freq.getValue() : " << lastDataRequestedFromServer + file->output_freq << endl ; |
---|
| 300 | } |
---|
[1017] | 301 | dataRequested |= sendReadDataRequest(lastDataRequestedFromServer + file->output_freq); |
---|
[850] | 302 | } |
---|
[598] | 303 | |
---|
[1013] | 304 | return dataRequested; |
---|
[598] | 305 | } |
---|
| 306 | |
---|
| 307 | void CField::recvReadDataRequest(CEventServer& event) |
---|
| 308 | { |
---|
| 309 | CBufferIn* buffer = event.subEvents.begin()->buffer; |
---|
| 310 | StdString fieldId; |
---|
| 311 | *buffer >> fieldId; |
---|
| 312 | get(fieldId)->recvReadDataRequest(); |
---|
| 313 | } |
---|
| 314 | |
---|
| 315 | void CField::recvReadDataRequest(void) |
---|
| 316 | { |
---|
| 317 | CContext* context = CContext::getCurrent(); |
---|
| 318 | CContextClient* client = context->client; |
---|
| 319 | |
---|
| 320 | CEventClient event(getType(), EVENT_ID_READ_DATA_READY); |
---|
| 321 | std::list<CMessage> msgs; |
---|
| 322 | |
---|
[599] | 323 | bool hasData = readField(); |
---|
[598] | 324 | |
---|
[651] | 325 | map<int, CArray<double,1> >::iterator it; |
---|
[988] | 326 | if (!grid->doGridHaveDataDistributed()) |
---|
[598] | 327 | { |
---|
[988] | 328 | if (client->isServerLeader()) |
---|
| 329 | { |
---|
| 330 | if (!data_srv.empty()) |
---|
| 331 | { |
---|
| 332 | it = data_srv.begin(); |
---|
| 333 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
| 334 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 335 | { |
---|
| 336 | msgs.push_back(CMessage()); |
---|
| 337 | CMessage& msg = msgs.back(); |
---|
| 338 | msg << getId(); |
---|
| 339 | if (hasData) |
---|
| 340 | msg << getNStep() - 1 << it->second; |
---|
| 341 | else |
---|
| 342 | msg << int(-1); |
---|
| 343 | event.push(*itRank, 1, msg); |
---|
| 344 | } |
---|
| 345 | } |
---|
| 346 | client->sendEvent(event); |
---|
| 347 | } |
---|
| 348 | else |
---|
| 349 | { |
---|
| 350 | // if (!data_srv.empty()) |
---|
| 351 | // { |
---|
| 352 | // it = data_srv.begin(); |
---|
| 353 | // const std::list<int>& ranks = client->getRanksServerNotLeader(); |
---|
| 354 | // for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 355 | // { |
---|
| 356 | // msgs.push_back(CMessage()); |
---|
| 357 | // CMessage& msg = msgs.back(); |
---|
| 358 | // msg << getId(); |
---|
| 359 | // if (hasData) |
---|
| 360 | // msg << getNStep() - 1 << it->second; |
---|
| 361 | // else |
---|
| 362 | // msg << int(-1); |
---|
| 363 | // event.push(*itRank, 1, msg); |
---|
| 364 | // } |
---|
| 365 | // } |
---|
| 366 | client->sendEvent(event); |
---|
| 367 | } |
---|
[598] | 368 | } |
---|
[988] | 369 | else |
---|
| 370 | { |
---|
| 371 | for (it = data_srv.begin(); it != data_srv.end(); it++) |
---|
| 372 | { |
---|
| 373 | msgs.push_back(CMessage()); |
---|
| 374 | CMessage& msg = msgs.back(); |
---|
| 375 | msg << getId(); |
---|
| 376 | if (hasData) |
---|
| 377 | msg << getNStep() - 1 << it->second; |
---|
| 378 | else |
---|
| 379 | msg << int(-1); |
---|
| 380 | event.push(it->first, grid->nbSenders[it->first], msg); |
---|
| 381 | } |
---|
| 382 | client->sendEvent(event); |
---|
| 383 | } |
---|
[599] | 384 | } |
---|
[598] | 385 | |
---|
[599] | 386 | bool CField::readField(void) |
---|
| 387 | { |
---|
| 388 | if (!getRelFile()->allDomainEmpty) |
---|
| 389 | { |
---|
| 390 | if (grid->doGridHaveDataToWrite() || getRelFile()->type == CFile::type_attr::one_file) |
---|
| 391 | { |
---|
| 392 | if (data_srv.empty()) |
---|
| 393 | { |
---|
[650] | 394 | for (map<int, CArray<size_t, 1> >::iterator it = grid->outIndexFromClient.begin(); it != grid->outIndexFromClient.end(); ++it) |
---|
[651] | 395 | data_srv.insert(std::make_pair(it->first, CArray<double,1>(it->second.numElements()))); |
---|
[599] | 396 | } |
---|
| 397 | |
---|
| 398 | getRelFile()->checkFile(); |
---|
| 399 | if (!nstepMax) |
---|
| 400 | { |
---|
| 401 | nstepMax = getRelFile()->getDataInput()->getFieldNbRecords(CField::get(this)); |
---|
| 402 | } |
---|
[873] | 403 | |
---|
[850] | 404 | this->incrementNStep(); |
---|
[599] | 405 | |
---|
[850] | 406 | if (getNStep() > nstepMax && (getRelFile()->cyclic.isEmpty() || !getRelFile()->cyclic) ) |
---|
[599] | 407 | return false; |
---|
| 408 | |
---|
| 409 | getRelFile()->getDataInput()->readFieldData(CField::get(this)); |
---|
| 410 | } |
---|
| 411 | } |
---|
| 412 | |
---|
| 413 | return true; |
---|
[598] | 414 | } |
---|
| 415 | |
---|
| 416 | void CField::recvReadDataReady(CEventServer& event) |
---|
| 417 | { |
---|
| 418 | string fieldId; |
---|
| 419 | vector<int> ranks; |
---|
| 420 | vector<CBufferIn*> buffers; |
---|
| 421 | |
---|
| 422 | list<CEventServer::SSubEvent>::iterator it; |
---|
| 423 | for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it) |
---|
| 424 | { |
---|
| 425 | ranks.push_back(it->rank); |
---|
| 426 | CBufferIn* buffer = it->buffer; |
---|
| 427 | *buffer >> fieldId; |
---|
| 428 | buffers.push_back(buffer); |
---|
| 429 | } |
---|
| 430 | get(fieldId)->recvReadDataReady(ranks, buffers); |
---|
| 431 | } |
---|
| 432 | |
---|
| 433 | void CField::recvReadDataReady(vector<int> ranks, vector<CBufferIn*> buffers) |
---|
| 434 | { |
---|
| 435 | CContext* context = CContext::getCurrent(); |
---|
[959] | 436 | int record; |
---|
[640] | 437 | std::map<int, CArray<double,1> > data; |
---|
| 438 | |
---|
[598] | 439 | for (int i = 0; i < ranks.size(); i++) |
---|
| 440 | { |
---|
| 441 | int rank = ranks[i]; |
---|
[599] | 442 | *buffers[i] >> record; |
---|
[959] | 443 | isEOF = (record == int(-1)); |
---|
[598] | 444 | |
---|
[599] | 445 | if (!isEOF) |
---|
[640] | 446 | *buffers[i] >> data[rank]; |
---|
| 447 | else |
---|
| 448 | break; |
---|
| 449 | } |
---|
| 450 | |
---|
[1013] | 451 | if (wasDataAlreadyReceivedFromServer) |
---|
| 452 | lastDataReceivedFromServer = lastDataReceivedFromServer + file->output_freq; |
---|
| 453 | else |
---|
| 454 | { |
---|
| 455 | lastDataReceivedFromServer = context->getCalendar()->getInitDate(); |
---|
| 456 | wasDataAlreadyReceivedFromServer = true; |
---|
| 457 | } |
---|
| 458 | |
---|
[640] | 459 | if (isEOF) |
---|
[1013] | 460 | serverSourceFilter->signalEndOfStream(lastDataReceivedFromServer); |
---|
[640] | 461 | else |
---|
[1013] | 462 | serverSourceFilter->streamDataFromServer(lastDataReceivedFromServer, data); |
---|
[598] | 463 | } |
---|
| 464 | |
---|
[219] | 465 | //---------------------------------------------------------------- |
---|
| 466 | |
---|
[347] | 467 | void CField::setRelFile(CFile* _file) |
---|
[509] | 468 | { |
---|
[459] | 469 | this->file = _file; |
---|
[562] | 470 | hasOutputFile = true; |
---|
[219] | 471 | } |
---|
| 472 | |
---|
| 473 | //---------------------------------------------------------------- |
---|
| 474 | |
---|
[562] | 475 | StdString CField::GetName(void) { return StdString("field"); } |
---|
| 476 | StdString CField::GetDefName(void) { return CField::GetName(); } |
---|
| 477 | ENodeType CField::GetType(void) { return eField; } |
---|
[219] | 478 | |
---|
| 479 | //---------------------------------------------------------------- |
---|
| 480 | |
---|
[347] | 481 | CGrid* CField::getRelGrid(void) const |
---|
[509] | 482 | { |
---|
[562] | 483 | return this->grid; |
---|
[219] | 484 | } |
---|
| 485 | |
---|
| 486 | //---------------------------------------------------------------- |
---|
| 487 | |
---|
[347] | 488 | CFile* CField::getRelFile(void) const |
---|
[509] | 489 | { |
---|
[562] | 490 | return this->file; |
---|
[219] | 491 | } |
---|
[509] | 492 | |
---|
[952] | 493 | int CField::getNStep(void) const |
---|
[266] | 494 | { |
---|
[562] | 495 | return this->nstep; |
---|
[266] | 496 | } |
---|
[509] | 497 | |
---|
[645] | 498 | func::CFunctor::ETimeType CField::getOperationTimeType() const |
---|
| 499 | { |
---|
| 500 | return operationTimeType; |
---|
| 501 | } |
---|
| 502 | |
---|
| 503 | //---------------------------------------------------------------- |
---|
| 504 | |
---|
[266] | 505 | void CField::incrementNStep(void) |
---|
| 506 | { |
---|
| 507 | this->nstep++; |
---|
| 508 | } |
---|
[509] | 509 | |
---|
[952] | 510 | void CField::resetNStep(int nstep /*= 0*/) |
---|
[321] | 511 | { |
---|
[707] | 512 | this->nstep = nstep; |
---|
[321] | 513 | } |
---|
[219] | 514 | |
---|
[599] | 515 | void CField::resetNStepMax(void) |
---|
| 516 | { |
---|
| 517 | this->nstepMax = 0; |
---|
| 518 | } |
---|
| 519 | |
---|
[219] | 520 | //---------------------------------------------------------------- |
---|
| 521 | |
---|
[1119] | 522 | bool CField::isActive(bool atCurrentTimestep /*= false*/) const |
---|
[509] | 523 | { |
---|
[1120] | 524 | if (clientSourceFilter) |
---|
| 525 | return atCurrentTimestep ? clientSourceFilter->isDataExpected(CContext::getCurrent()->getCalendar()->getCurrentDate()) : true; |
---|
| 526 | else if (storeFilter) |
---|
| 527 | return true; |
---|
| 528 | else if (instantDataFilter) |
---|
| 529 | ERROR("bool CField::isActive(bool atCurrentTimestep)", |
---|
| 530 | << "Impossible to check if field [ id = " << getId() << " ] is active as it cannot be used to receive nor send data."); |
---|
| 531 | |
---|
| 532 | return false; |
---|
[310] | 533 | } |
---|
[562] | 534 | |
---|
[219] | 535 | //---------------------------------------------------------------- |
---|
[509] | 536 | |
---|
[707] | 537 | bool CField::wasWritten() const |
---|
| 538 | { |
---|
| 539 | return written; |
---|
| 540 | } |
---|
| 541 | |
---|
| 542 | void CField::setWritten() |
---|
| 543 | { |
---|
| 544 | written = true; |
---|
| 545 | } |
---|
| 546 | |
---|
| 547 | //---------------------------------------------------------------- |
---|
| 548 | |
---|
[676] | 549 | bool CField::getUseCompressedOutput() const |
---|
| 550 | { |
---|
| 551 | return useCompressedOutput; |
---|
| 552 | } |
---|
| 553 | |
---|
| 554 | void CField::setUseCompressedOutput() |
---|
| 555 | { |
---|
| 556 | useCompressedOutput = true; |
---|
| 557 | } |
---|
| 558 | |
---|
| 559 | //---------------------------------------------------------------- |
---|
| 560 | |
---|
[641] | 561 | boost::shared_ptr<COutputPin> CField::getInstantDataFilter() |
---|
| 562 | { |
---|
| 563 | return instantDataFilter; |
---|
| 564 | } |
---|
| 565 | |
---|
| 566 | //---------------------------------------------------------------- |
---|
| 567 | |
---|
[823] | 568 | void CField::solveOnlyReferenceEnabledField(bool doSending2Server) |
---|
[459] | 569 | { |
---|
[509] | 570 | CContext* context = CContext::getCurrent(); |
---|
[823] | 571 | if (!isReferenceSolved) |
---|
[509] | 572 | { |
---|
[823] | 573 | isReferenceSolved = true; |
---|
[644] | 574 | |
---|
[510] | 575 | if (context->hasClient) |
---|
[509] | 576 | { |
---|
| 577 | solveRefInheritance(true); |
---|
[823] | 578 | if (hasDirectFieldReference()) getDirectFieldReference()->solveOnlyReferenceEnabledField(false); |
---|
[509] | 579 | } |
---|
[645] | 580 | else if (context->hasServer) |
---|
| 581 | solveServerOperation(); |
---|
[478] | 582 | |
---|
[509] | 583 | solveGridReference(); |
---|
[823] | 584 | |
---|
| 585 | if (context->hasClient) |
---|
| 586 | { |
---|
| 587 | solveGenerateGrid(); |
---|
| 588 | buildGridTransformationGraph(); |
---|
| 589 | } |
---|
[509] | 590 | } |
---|
[823] | 591 | } |
---|
| 592 | |
---|
| 593 | /*! |
---|
| 594 | Build up graph of grids which plays role of destination and source in grid transformation |
---|
| 595 | This function should be called before \func solveGridReference() |
---|
| 596 | */ |
---|
| 597 | void CField::buildGridTransformationGraph() |
---|
| 598 | { |
---|
| 599 | CContext* context = CContext::getCurrent(); |
---|
[687] | 600 | if (context->hasClient) |
---|
| 601 | { |
---|
[823] | 602 | if (grid && !grid->isTransformed() && hasDirectFieldReference() && grid != getDirectFieldReference()->grid) |
---|
| 603 | { |
---|
| 604 | grid->addTransGridSource(getDirectFieldReference()->grid); |
---|
| 605 | } |
---|
[687] | 606 | } |
---|
[823] | 607 | } |
---|
[687] | 608 | |
---|
[823] | 609 | /*! |
---|
| 610 | Generate a new grid destination if there are more than one grid source pointing to a same grid destination |
---|
| 611 | */ |
---|
| 612 | void CField::generateNewTransformationGridDest() |
---|
| 613 | { |
---|
| 614 | CContext* context = CContext::getCurrent(); |
---|
| 615 | if (context->hasClient) |
---|
| 616 | { |
---|
| 617 | std::map<CGrid*,std::pair<bool,StdString> >& gridSrcMap = grid->getTransGridSource(); |
---|
| 618 | if (1 < gridSrcMap.size()) |
---|
| 619 | { |
---|
| 620 | // Search for grid source |
---|
| 621 | CGrid* gridSrc = grid; |
---|
| 622 | CField* currField = this; |
---|
| 623 | std::vector<CField*> hieraField; |
---|
[687] | 624 | |
---|
[823] | 625 | while (currField->hasDirectFieldReference() && (gridSrc == grid)) |
---|
| 626 | { |
---|
| 627 | hieraField.push_back(currField); |
---|
| 628 | CField* tmp = currField->getDirectFieldReference(); |
---|
| 629 | currField = tmp; |
---|
| 630 | gridSrc = currField->grid; |
---|
| 631 | } |
---|
| 632 | |
---|
| 633 | if (gridSrcMap.end() != gridSrcMap.find(gridSrc)) |
---|
| 634 | { |
---|
| 635 | CGrid* gridTmp; |
---|
| 636 | std::pair<bool,StdString> newGridDest = gridSrcMap[gridSrc]; |
---|
| 637 | if (newGridDest.first) |
---|
| 638 | { |
---|
| 639 | StdString newIdGridDest = newGridDest.second; |
---|
| 640 | if (!CGrid::has(newIdGridDest)) |
---|
| 641 | { |
---|
| 642 | ERROR("CGrid* CGrid::generateNewTransformationGridDest()", |
---|
| 643 | << " Something wrong happened! Grid whose id " << newIdGridDest |
---|
| 644 | << "should exist "); |
---|
| 645 | } |
---|
| 646 | gridTmp = CGrid::get(newIdGridDest); |
---|
| 647 | } |
---|
| 648 | else |
---|
| 649 | { |
---|
| 650 | StdString newIdGridDest = CGrid::generateId(gridSrc, grid); |
---|
| 651 | gridTmp = CGrid::cloneGrid(newIdGridDest, grid); |
---|
| 652 | |
---|
| 653 | (gridSrcMap[gridSrc]).first = true; |
---|
| 654 | (gridSrcMap[gridSrc]).second = newIdGridDest; |
---|
| 655 | } |
---|
| 656 | |
---|
| 657 | // Update all descendants |
---|
| 658 | for (std::vector<CField*>::iterator it = hieraField.begin(); it != hieraField.end(); ++it) |
---|
| 659 | { |
---|
| 660 | (*it)->grid = gridTmp; |
---|
| 661 | (*it)->updateRef((*it)->grid); |
---|
| 662 | } |
---|
| 663 | } |
---|
| 664 | } |
---|
| 665 | } |
---|
| 666 | } |
---|
| 667 | |
---|
| 668 | void CField::updateRef(CGrid* grid) |
---|
| 669 | { |
---|
| 670 | if (!grid_ref.isEmpty()) grid_ref.setValue(grid->getId()); |
---|
| 671 | else |
---|
| 672 | { |
---|
| 673 | std::vector<CAxis*> axisTmp = grid->getAxis(); |
---|
| 674 | std::vector<CDomain*> domainTmp = grid->getDomains(); |
---|
| 675 | if ((1<axisTmp.size()) || (1<domainTmp.size())) |
---|
| 676 | ERROR("void CField::updateRef(CGrid* grid)", |
---|
| 677 | << "More than one domain or axis is available for domain_ref/axis_ref of field " << this->getId()); |
---|
| 678 | |
---|
| 679 | if ((!domain_ref.isEmpty()) && (domainTmp.empty())) |
---|
| 680 | ERROR("void CField::updateRef(CGrid* grid)", |
---|
| 681 | << "Incoherent between available domain and domain_ref of field " << this->getId()); |
---|
| 682 | if ((!axis_ref.isEmpty()) && (axisTmp.empty())) |
---|
| 683 | ERROR("void CField::updateRef(CGrid* grid)", |
---|
| 684 | << "Incoherent between available axis and axis_ref of field " << this->getId()); |
---|
| 685 | |
---|
| 686 | if (!domain_ref.isEmpty()) domain_ref.setValue(domainTmp[0]->getId()); |
---|
| 687 | if (!axis_ref.isEmpty()) axis_ref.setValue(axisTmp[0]->getId()); |
---|
| 688 | } |
---|
| 689 | } |
---|
| 690 | |
---|
| 691 | void CField::solveAllReferenceEnabledField(bool doSending2Server) |
---|
| 692 | { |
---|
| 693 | CContext* context = CContext::getCurrent(); |
---|
| 694 | solveOnlyReferenceEnabledField(doSending2Server); |
---|
[1149] | 695 | int myRank; |
---|
| 696 | MPI_Comm_rank(context->client->intraComm, &myRank); |
---|
[823] | 697 | |
---|
| 698 | if (!areAllReferenceSolved) |
---|
| 699 | { |
---|
| 700 | areAllReferenceSolved = true; |
---|
| 701 | |
---|
| 702 | if (context->hasClient) |
---|
| 703 | { |
---|
| 704 | solveRefInheritance(true); |
---|
| 705 | if (hasDirectFieldReference()) getDirectFieldReference()->solveAllReferenceEnabledField(false); |
---|
| 706 | } |
---|
| 707 | else if (context->hasServer) |
---|
| 708 | solveServerOperation(); |
---|
| 709 | |
---|
| 710 | solveGridReference(); |
---|
| 711 | } |
---|
| 712 | |
---|
| 713 | solveGridDomainAxisRef(doSending2Server); |
---|
| 714 | |
---|
[619] | 715 | if (context->hasClient) |
---|
| 716 | { |
---|
| 717 | solveTransformedGrid(); |
---|
| 718 | } |
---|
[687] | 719 | |
---|
[823] | 720 | solveCheckMaskIndex(doSending2Server); |
---|
[509] | 721 | } |
---|
| 722 | |
---|
[731] | 723 | std::map<int, StdSize> CField::getGridAttributesBufferSize() |
---|
[509] | 724 | { |
---|
[731] | 725 | return grid->getAttributesBufferSize(); |
---|
[509] | 726 | } |
---|
| 727 | |
---|
[731] | 728 | std::map<int, StdSize> CField::getGridDataBufferSize() |
---|
| 729 | { |
---|
| 730 | return grid->getDataBufferSize(getId()); |
---|
| 731 | } |
---|
| 732 | |
---|
[219] | 733 | //---------------------------------------------------------------- |
---|
| 734 | |
---|
[645] | 735 | void CField::solveServerOperation(void) |
---|
[219] | 736 | { |
---|
[640] | 737 | CContext* context = CContext::getCurrent(); |
---|
[509] | 738 | |
---|
[640] | 739 | if (!context->hasServer || !hasOutputFile) return; |
---|
| 740 | |
---|
[645] | 741 | if (freq_op.isEmpty()) |
---|
| 742 | freq_op.setValue(TimeStep); |
---|
[509] | 743 | |
---|
[538] | 744 | if (freq_offset.isEmpty()) |
---|
| 745 | freq_offset.setValue(NoneDu); |
---|
[219] | 746 | |
---|
[645] | 747 | freq_operation_srv = file->output_freq.getValue(); |
---|
| 748 | freq_write_srv = file->output_freq.getValue(); |
---|
[509] | 749 | |
---|
[651] | 750 | lastlast_Write_srv = context->getCalendar()->getInitDate(); |
---|
| 751 | last_Write_srv = context->getCalendar()->getInitDate(); |
---|
| 752 | last_operation_srv = context->getCalendar()->getInitDate(); |
---|
[509] | 753 | |
---|
[645] | 754 | const CDuration toffset = freq_operation_srv - freq_offset.getValue() - context->getCalendar()->getTimeStep(); |
---|
[651] | 755 | last_operation_srv = last_operation_srv - toffset; |
---|
[509] | 756 | |
---|
[645] | 757 | if (operation.isEmpty()) |
---|
| 758 | ERROR("void CField::solveServerOperation(void)", |
---|
| 759 | << "An operation must be defined for field \"" << getId() << "\"."); |
---|
[509] | 760 | |
---|
[645] | 761 | boost::shared_ptr<func::CFunctor> functor; |
---|
| 762 | CArray<double, 1> dummyData; |
---|
[598] | 763 | |
---|
[562] | 764 | #define DECLARE_FUNCTOR(MType, mtype) \ |
---|
[645] | 765 | if (operation.getValue().compare(#mtype) == 0) \ |
---|
[470] | 766 | { \ |
---|
[645] | 767 | functor.reset(new func::C##MType(dummyData)); \ |
---|
| 768 | } |
---|
[509] | 769 | |
---|
[219] | 770 | #include "functor_type.conf" |
---|
[509] | 771 | |
---|
[645] | 772 | if (!functor) |
---|
| 773 | ERROR("void CField::solveServerOperation(void)", |
---|
| 774 | << "\"" << operation << "\" is not a valid operation."); |
---|
| 775 | |
---|
| 776 | operationTimeType = functor->timeType(); |
---|
[219] | 777 | } |
---|
[509] | 778 | |
---|
[219] | 779 | //---------------------------------------------------------------- |
---|
[640] | 780 | |
---|
| 781 | /*! |
---|
| 782 | * Constructs the graph filter for the field, enabling or not the data output. |
---|
| 783 | * This method should not be called more than once with enableOutput equal to true. |
---|
| 784 | * |
---|
| 785 | * \param gc the garbage collector to use when building the filter graph |
---|
| 786 | * \param enableOutput must be true when the field data is to be |
---|
| 787 | * read by the client or/and written to a file |
---|
| 788 | */ |
---|
| 789 | void CField::buildFilterGraph(CGarbageCollector& gc, bool enableOutput) |
---|
| 790 | { |
---|
[641] | 791 | if (!areAllReferenceSolved) solveAllReferenceEnabledField(false); |
---|
[1000] | 792 | |
---|
[640] | 793 | // Start by building a filter which can provide the field's instant data |
---|
| 794 | if (!instantDataFilter) |
---|
| 795 | { |
---|
[642] | 796 | // Check if we have an expression to parse |
---|
[1000] | 797 | if (hasExpression()) |
---|
[642] | 798 | { |
---|
[1000] | 799 | boost::scoped_ptr<IFilterExprNode> expr(parseExpr(getExpression() + '\0')); |
---|
| 800 | boost::shared_ptr<COutputPin> filter = expr->reduce(gc, *this); |
---|
| 801 | |
---|
| 802 | // Check if a spatial transformation is needed |
---|
| 803 | if (!field_ref.isEmpty()) |
---|
[998] | 804 | { |
---|
[1000] | 805 | CGrid* gridRef = CField::get(field_ref)->grid; |
---|
| 806 | |
---|
| 807 | if (grid && grid != gridRef && grid->hasTransform()) |
---|
| 808 | { |
---|
[1018] | 809 | bool hasMissingValue = (!detect_missing_value.isEmpty() && !default_value.isEmpty() && detect_missing_value == true); |
---|
| 810 | double defaultValue = hasMissingValue ? default_value : (!default_value.isEmpty() ? default_value : 0.0); |
---|
| 811 | std::pair<boost::shared_ptr<CFilter>, boost::shared_ptr<CFilter> > filters = CSpatialTransformFilter::buildFilterGraph(gc, gridRef, grid, hasMissingValue, defaultValue); |
---|
[1000] | 812 | |
---|
| 813 | filter->connectOutput(filters.first, 0); |
---|
| 814 | filter = filters.second; |
---|
| 815 | } |
---|
[998] | 816 | } |
---|
[1000] | 817 | |
---|
| 818 | instantDataFilter = filter; |
---|
| 819 | } |
---|
| 820 | // Check if we have a reference on another field |
---|
| 821 | else if (!field_ref.isEmpty()) |
---|
| 822 | instantDataFilter = getFieldReference(gc); |
---|
[640] | 823 | // Check if the data is to be read from a file |
---|
[641] | 824 | else if (file && !file->mode.isEmpty() && file->mode == CFile::mode_attr::read) |
---|
[1006] | 825 | instantDataFilter = serverSourceFilter = boost::shared_ptr<CSourceFilter>(new CSourceFilter(gc, grid, |
---|
| 826 | freq_offset.isEmpty() ? NoneDu : freq_offset, |
---|
| 827 | true)); |
---|
[640] | 828 | else // The data might be passed from the model |
---|
[1018] | 829 | { |
---|
| 830 | bool ignoreMissingValue = (!detect_missing_value.isEmpty() && !default_value.isEmpty() && detect_missing_value == true); |
---|
| 831 | double defaultValue = ignoreMissingValue ? default_value : (!default_value.isEmpty() ? default_value : 0.0); |
---|
| 832 | instantDataFilter = clientSourceFilter = boost::shared_ptr<CSourceFilter>(new CSourceFilter(gc, grid, NoneDu, false, |
---|
| 833 | ignoreMissingValue, defaultValue)); } |
---|
[640] | 834 | } |
---|
| 835 | |
---|
| 836 | // If the field data is to be read by the client or/and written to a file |
---|
| 837 | if (enableOutput && !storeFilter && !fileWriterFilter) |
---|
| 838 | { |
---|
[741] | 839 | if (!read_access.isEmpty() && read_access) |
---|
[640] | 840 | { |
---|
| 841 | storeFilter = boost::shared_ptr<CStoreFilter>(new CStoreFilter(gc, CContext::getCurrent(), grid)); |
---|
| 842 | instantDataFilter->connectOutput(storeFilter, 0); |
---|
| 843 | } |
---|
| 844 | |
---|
| 845 | if (file && (file->mode.isEmpty() || file->mode == CFile::mode_attr::write)) |
---|
| 846 | { |
---|
| 847 | fileWriterFilter = boost::shared_ptr<CFileWriterFilter>(new CFileWriterFilter(gc, this)); |
---|
[643] | 848 | getTemporalDataFilter(gc, file->output_freq)->connectOutput(fileWriterFilter, 0); |
---|
[640] | 849 | } |
---|
| 850 | } |
---|
| 851 | } |
---|
| 852 | |
---|
[642] | 853 | /*! |
---|
[737] | 854 | * Returns the filter needed to handle the field reference. |
---|
| 855 | * This method should only be called when building the filter graph corresponding to the field. |
---|
| 856 | * |
---|
| 857 | * \param gc the garbage collector to use |
---|
| 858 | * \return the output pin corresponding to the field reference |
---|
| 859 | */ |
---|
[1000] | 860 | boost::shared_ptr<COutputPin> CField::getFieldReference(CGarbageCollector& gc) |
---|
[737] | 861 | { |
---|
| 862 | if (instantDataFilter || field_ref.isEmpty()) |
---|
| 863 | ERROR("COutputPin* CField::getFieldReference(CGarbageCollector& gc)", |
---|
| 864 | "Impossible to get the field reference for a field which has already been parsed or which does not have a field_ref."); |
---|
| 865 | |
---|
| 866 | CField* fieldRef = CField::get(field_ref); |
---|
[1000] | 867 | fieldRef->buildFilterGraph(gc, false); |
---|
[737] | 868 | |
---|
| 869 | std::pair<boost::shared_ptr<CFilter>, boost::shared_ptr<CFilter> > filters; |
---|
| 870 | // Check if a spatial transformation is needed |
---|
[824] | 871 | if (grid && grid != fieldRef->grid && grid->hasTransform()) |
---|
[1018] | 872 | { |
---|
| 873 | bool hasMissingValue = (!detect_missing_value.isEmpty() && !default_value.isEmpty() && detect_missing_value == true); |
---|
| 874 | double defaultValue = hasMissingValue ? default_value : (!default_value.isEmpty() ? default_value : 0.0); |
---|
| 875 | filters = CSpatialTransformFilter::buildFilterGraph(gc, fieldRef->grid, grid, hasMissingValue, defaultValue); |
---|
[873] | 876 | } |
---|
[737] | 877 | else |
---|
| 878 | filters.first = filters.second = boost::shared_ptr<CFilter>(new CPassThroughFilter(gc)); |
---|
| 879 | |
---|
[1000] | 880 | fieldRef->getInstantDataFilter()->connectOutput(filters.first, 0); |
---|
[737] | 881 | |
---|
| 882 | return filters.second; |
---|
| 883 | } |
---|
| 884 | |
---|
| 885 | /*! |
---|
| 886 | * Returns the filter needed to handle a self reference in the field's expression. |
---|
| 887 | * If the needed filter does not exist, it is created, otherwise it is reused. |
---|
[642] | 888 | * This method should only be called when building the filter graph corresponding |
---|
| 889 | * to the field's expression. |
---|
| 890 | * |
---|
| 891 | * \param gc the garbage collector to use |
---|
| 892 | * \return the output pin corresponding to a self reference |
---|
| 893 | */ |
---|
| 894 | boost::shared_ptr<COutputPin> CField::getSelfReference(CGarbageCollector& gc) |
---|
| 895 | { |
---|
[1000] | 896 | if (instantDataFilter || !hasExpression()) |
---|
[642] | 897 | ERROR("COutputPin* CField::getSelfReference(CGarbageCollector& gc)", |
---|
| 898 | "Impossible to add a self reference to a field which has already been parsed or which does not have an expression."); |
---|
| 899 | |
---|
[737] | 900 | if (!selfReferenceFilter) |
---|
| 901 | { |
---|
[741] | 902 | if (file && !file->mode.isEmpty() && file->mode == CFile::mode_attr::read) |
---|
| 903 | { |
---|
| 904 | if (!serverSourceFilter) |
---|
[1006] | 905 | serverSourceFilter = boost::shared_ptr<CSourceFilter>(new CSourceFilter(gc, grid, |
---|
| 906 | freq_offset.isEmpty() ? NoneDu : freq_offset, |
---|
| 907 | true)); |
---|
[741] | 908 | |
---|
| 909 | selfReferenceFilter = serverSourceFilter; |
---|
| 910 | } |
---|
| 911 | else if (!field_ref.isEmpty()) |
---|
[998] | 912 | { |
---|
| 913 | CField* fieldRef = CField::get(field_ref); |
---|
| 914 | fieldRef->buildFilterGraph(gc, false); |
---|
| 915 | selfReferenceFilter = fieldRef->getInstantDataFilter(); |
---|
| 916 | } |
---|
[737] | 917 | else |
---|
| 918 | { |
---|
| 919 | if (!clientSourceFilter) |
---|
[1018] | 920 | { |
---|
| 921 | bool ignoreMissingValue = (!detect_missing_value.isEmpty() && !default_value.isEmpty() && detect_missing_value == true); |
---|
| 922 | double defaultValue = ignoreMissingValue ? default_value : (!default_value.isEmpty() ? default_value : 0.0); |
---|
| 923 | clientSourceFilter = boost::shared_ptr<CSourceFilter>(new CSourceFilter(gc, grid, NoneDu, false, |
---|
| 924 | ignoreMissingValue, defaultValue)); |
---|
| 925 | } |
---|
[642] | 926 | |
---|
[737] | 927 | selfReferenceFilter = clientSourceFilter; |
---|
| 928 | } |
---|
| 929 | } |
---|
| 930 | |
---|
| 931 | return selfReferenceFilter; |
---|
[642] | 932 | } |
---|
| 933 | |
---|
[643] | 934 | /*! |
---|
| 935 | * Returns the temporal filter corresponding to the field's temporal operation |
---|
| 936 | * for the specified operation frequency. The filter is created if it does not |
---|
| 937 | * exist, otherwise it is reused. |
---|
| 938 | * |
---|
| 939 | * \param gc the garbage collector to use |
---|
| 940 | * \param outFreq the operation frequency, i.e. the frequency at which the output data will be computed |
---|
| 941 | * \return the output pin corresponding to the requested temporal filter |
---|
| 942 | */ |
---|
| 943 | boost::shared_ptr<COutputPin> CField::getTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq) |
---|
| 944 | { |
---|
| 945 | std::map<CDuration, boost::shared_ptr<COutputPin> >::iterator it = temporalDataFilters.find(outFreq); |
---|
| 946 | |
---|
| 947 | if (it == temporalDataFilters.end()) |
---|
| 948 | { |
---|
| 949 | if (operation.isEmpty()) |
---|
| 950 | ERROR("void CField::getTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq)", |
---|
| 951 | << "An operation must be defined for field \"" << getId() << "\"."); |
---|
| 952 | |
---|
| 953 | if (freq_op.isEmpty()) |
---|
| 954 | freq_op.setValue(TimeStep); |
---|
| 955 | if (freq_offset.isEmpty()) |
---|
| 956 | freq_offset.setValue(NoneDu); |
---|
| 957 | |
---|
| 958 | const bool ignoreMissingValue = (!detect_missing_value.isEmpty() && !default_value.isEmpty() && detect_missing_value == true); |
---|
[1134] | 959 | |
---|
[643] | 960 | boost::shared_ptr<CTemporalFilter> temporalFilter(new CTemporalFilter(gc, operation, |
---|
| 961 | CContext::getCurrent()->getCalendar()->getInitDate(), |
---|
| 962 | freq_op, freq_offset, outFreq, |
---|
| 963 | ignoreMissingValue, ignoreMissingValue ? default_value : 0.0)); |
---|
| 964 | instantDataFilter->connectOutput(temporalFilter, 0); |
---|
| 965 | |
---|
| 966 | it = temporalDataFilters.insert(std::make_pair(outFreq, temporalFilter)).first; |
---|
| 967 | } |
---|
| 968 | |
---|
| 969 | return it->second; |
---|
| 970 | } |
---|
| 971 | |
---|
[998] | 972 | /*! |
---|
| 973 | * Returns the temporal filter corresponding to the field's temporal operation |
---|
[1000] | 974 | * for the specified operation frequency. |
---|
[998] | 975 | * |
---|
| 976 | * \param gc the garbage collector to use |
---|
| 977 | * \param outFreq the operation frequency, i.e. the frequency at which the output data will be computed |
---|
| 978 | * \return the output pin corresponding to the requested temporal filter |
---|
| 979 | */ |
---|
| 980 | |
---|
| 981 | boost::shared_ptr<COutputPin> CField::getSelfTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq) |
---|
| 982 | { |
---|
| 983 | if (instantDataFilter || !hasExpression()) |
---|
| 984 | ERROR("COutputPin* CField::getSelfTemporalDataFilter(CGarbageCollector& gc)", |
---|
| 985 | "Impossible to add a self reference to a field which has already been parsed or which does not have an expression."); |
---|
| 986 | |
---|
| 987 | if (!selfReferenceFilter) getSelfReference(gc) ; |
---|
| 988 | |
---|
| 989 | if (serverSourceFilter || clientSourceFilter) |
---|
| 990 | { |
---|
| 991 | if (operation.isEmpty()) |
---|
| 992 | ERROR("void CField::getSelfTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq)", |
---|
| 993 | << "An operation must be defined for field \"" << getId() << "\"."); |
---|
| 994 | |
---|
| 995 | if (freq_op.isEmpty()) freq_op.setValue(TimeStep); |
---|
| 996 | if (freq_offset.isEmpty()) freq_offset.setValue(NoneDu); |
---|
| 997 | |
---|
| 998 | const bool ignoreMissingValue = (!detect_missing_value.isEmpty() && !default_value.isEmpty() && detect_missing_value == true); |
---|
| 999 | |
---|
| 1000 | boost::shared_ptr<CTemporalFilter> temporalFilter(new CTemporalFilter(gc, operation, |
---|
| 1001 | CContext::getCurrent()->getCalendar()->getInitDate(), |
---|
| 1002 | freq_op, freq_offset, outFreq, |
---|
| 1003 | ignoreMissingValue, ignoreMissingValue ? default_value : 0.0)); |
---|
| 1004 | selfReferenceFilter->connectOutput(temporalFilter, 0); |
---|
| 1005 | return temporalFilter ; |
---|
| 1006 | } |
---|
| 1007 | else if (!field_ref.isEmpty()) |
---|
| 1008 | { |
---|
| 1009 | CField* fieldRef = CField::get(field_ref); |
---|
| 1010 | fieldRef->buildFilterGraph(gc, false); |
---|
| 1011 | return fieldRef->getTemporalDataFilter(gc, outFreq) ; |
---|
| 1012 | } |
---|
| 1013 | } |
---|
| 1014 | |
---|
[640] | 1015 | //---------------------------------------------------------------- |
---|
[369] | 1016 | /* |
---|
[562] | 1017 | void CField::fromBinary(StdIStream& is) |
---|
[219] | 1018 | { |
---|
| 1019 | SuperClass::fromBinary(is); |
---|
| 1020 | #define CLEAR_ATT(name_)\ |
---|
[369] | 1021 | SuperClassAttribute::operator[](#name_)->reset() |
---|
[219] | 1022 | |
---|
| 1023 | CLEAR_ATT(domain_ref); |
---|
| 1024 | CLEAR_ATT(axis_ref); |
---|
| 1025 | #undef CLEAR_ATT |
---|
| 1026 | |
---|
| 1027 | } |
---|
[369] | 1028 | */ |
---|
[219] | 1029 | //---------------------------------------------------------------- |
---|
| 1030 | |
---|
| 1031 | void CField::solveGridReference(void) |
---|
| 1032 | { |
---|
[887] | 1033 | if (grid_ref.isEmpty() && domain_ref.isEmpty() && axis_ref.isEmpty() && scalar_ref.isEmpty()) |
---|
[742] | 1034 | { |
---|
| 1035 | ERROR("CField::solveGridReference(void)", |
---|
[770] | 1036 | << "A grid must be defined for field '" << getFieldOutputName() << "' ."); |
---|
[742] | 1037 | } |
---|
[887] | 1038 | else if (!grid_ref.isEmpty() && (!domain_ref.isEmpty() || !axis_ref.isEmpty() || !scalar_ref.isEmpty())) |
---|
[219] | 1039 | { |
---|
[744] | 1040 | ERROR("CField::solveGridReference(void)", |
---|
[887] | 1041 | << "Field '" << getFieldOutputName() << "' has both a grid and a domain/axis/scalar." << std::endl |
---|
| 1042 | << "Please define either 'grid_ref' or 'domain_ref'/'axis_ref'/'scalar_ref'."); |
---|
[219] | 1043 | } |
---|
| 1044 | |
---|
[744] | 1045 | if (grid_ref.isEmpty()) |
---|
[219] | 1046 | { |
---|
[744] | 1047 | std::vector<CDomain*> vecDom; |
---|
| 1048 | std::vector<CAxis*> vecAxis; |
---|
[887] | 1049 | std::vector<CScalar*> vecScalar; |
---|
[894] | 1050 | std::vector<int> axisDomainOrderTmp; |
---|
| 1051 | |
---|
[744] | 1052 | if (!domain_ref.isEmpty()) |
---|
| 1053 | { |
---|
[823] | 1054 | StdString tmp = domain_ref.getValue(); |
---|
[744] | 1055 | if (CDomain::has(domain_ref)) |
---|
[894] | 1056 | { |
---|
[744] | 1057 | vecDom.push_back(CDomain::get(domain_ref)); |
---|
[894] | 1058 | axisDomainOrderTmp.push_back(2); |
---|
| 1059 | } |
---|
[744] | 1060 | else |
---|
[219] | 1061 | ERROR("CField::solveGridReference(void)", |
---|
[744] | 1062 | << "Invalid reference to domain '" << domain_ref.getValue() << "'."); |
---|
| 1063 | } |
---|
[219] | 1064 | |
---|
[744] | 1065 | if (!axis_ref.isEmpty()) |
---|
[742] | 1066 | { |
---|
[744] | 1067 | if (CAxis::has(axis_ref)) |
---|
[894] | 1068 | { |
---|
[744] | 1069 | vecAxis.push_back(CAxis::get(axis_ref)); |
---|
[894] | 1070 | axisDomainOrderTmp.push_back(1); |
---|
| 1071 | } |
---|
[744] | 1072 | else |
---|
| 1073 | ERROR("CField::solveGridReference(void)", |
---|
| 1074 | << "Invalid reference to axis '" << axis_ref.getValue() << "'."); |
---|
[742] | 1075 | } |
---|
[744] | 1076 | |
---|
[887] | 1077 | if (!scalar_ref.isEmpty()) |
---|
| 1078 | { |
---|
| 1079 | if (CScalar::has(scalar_ref)) |
---|
[894] | 1080 | { |
---|
[887] | 1081 | vecScalar.push_back(CScalar::get(scalar_ref)); |
---|
[894] | 1082 | axisDomainOrderTmp.push_back(0); |
---|
| 1083 | } |
---|
[887] | 1084 | else |
---|
| 1085 | ERROR("CField::solveGridReference(void)", |
---|
| 1086 | << "Invalid reference to scalar '" << scalar_ref.getValue() << "'."); |
---|
| 1087 | } |
---|
[894] | 1088 | |
---|
| 1089 | CArray<int,1> axisDomainOrder(axisDomainOrderTmp.size()); |
---|
| 1090 | for (int idx = 0; idx < axisDomainOrderTmp.size(); ++idx) |
---|
| 1091 | { |
---|
| 1092 | axisDomainOrder(idx) = axisDomainOrderTmp[idx]; |
---|
| 1093 | } |
---|
[887] | 1094 | |
---|
[745] | 1095 | // Warning: the gridId shouldn't be set as the grid_ref since it could be inherited |
---|
[894] | 1096 | StdString gridId = CGrid::generateId(vecDom, vecAxis, vecScalar,axisDomainOrder); |
---|
[745] | 1097 | if (CGrid::has(gridId)) |
---|
| 1098 | this->grid = CGrid::get(gridId); |
---|
| 1099 | else |
---|
[894] | 1100 | this->grid = CGrid::createGrid(gridId, vecDom, vecAxis, vecScalar,axisDomainOrder); |
---|
[219] | 1101 | } |
---|
[586] | 1102 | else |
---|
| 1103 | { |
---|
[744] | 1104 | if (CGrid::has(grid_ref)) |
---|
| 1105 | this->grid = CGrid::get(grid_ref); |
---|
| 1106 | else |
---|
| 1107 | ERROR("CField::solveGridReference(void)", |
---|
| 1108 | << "Invalid reference to grid '" << grid_ref.getValue() << "'."); |
---|
[586] | 1109 | } |
---|
[509] | 1110 | } |
---|
[459] | 1111 | |
---|
[509] | 1112 | void CField::solveGridDomainAxisRef(bool checkAtt) |
---|
| 1113 | { |
---|
| 1114 | grid->solveDomainAxisRef(checkAtt); |
---|
[219] | 1115 | } |
---|
| 1116 | |
---|
[509] | 1117 | void CField::solveCheckMaskIndex(bool doSendingIndex) |
---|
| 1118 | { |
---|
| 1119 | grid->checkMaskIndex(doSendingIndex); |
---|
| 1120 | } |
---|
[219] | 1121 | |
---|
[619] | 1122 | void CField::solveTransformedGrid() |
---|
| 1123 | { |
---|
[746] | 1124 | if (grid && !grid->isTransformed() && hasDirectFieldReference() && grid != getDirectFieldReference()->grid) |
---|
[790] | 1125 | { |
---|
| 1126 | std::vector<CGrid*> grids; |
---|
| 1127 | // Source grid |
---|
| 1128 | grids.push_back(getDirectFieldReference()->grid); |
---|
| 1129 | // Intermediate grids |
---|
| 1130 | if (!grid_path.isEmpty()) |
---|
| 1131 | { |
---|
| 1132 | std::string gridId; |
---|
| 1133 | size_t start = 0, end; |
---|
| 1134 | |
---|
| 1135 | do |
---|
| 1136 | { |
---|
| 1137 | end = grid_path.getValue().find(',', start); |
---|
| 1138 | if (end != std::string::npos) |
---|
| 1139 | { |
---|
| 1140 | gridId = grid_path.getValue().substr(start, end - start); |
---|
| 1141 | start = end + 1; |
---|
| 1142 | } |
---|
| 1143 | else |
---|
| 1144 | gridId = grid_path.getValue().substr(start); |
---|
| 1145 | |
---|
| 1146 | if (!CGrid::has(gridId)) |
---|
| 1147 | ERROR("void CField::solveTransformedGrid()", |
---|
| 1148 | << "Invalid grid_path, the grid '" << gridId << "' does not exist."); |
---|
| 1149 | |
---|
| 1150 | grids.push_back(CGrid::get(gridId)); |
---|
| 1151 | } |
---|
| 1152 | while (end != std::string::npos); |
---|
| 1153 | } |
---|
| 1154 | // Destination grid |
---|
| 1155 | grids.push_back(grid); |
---|
| 1156 | |
---|
| 1157 | for (size_t i = 0, count = grids.size() - 1; i < count; ++i) |
---|
| 1158 | { |
---|
| 1159 | CGrid *gridSrc = grids[i]; |
---|
| 1160 | CGrid *gridDest = grids[i + 1]; |
---|
| 1161 | if (!gridDest->isTransformed()) |
---|
| 1162 | gridDest->transformGrid(gridSrc); |
---|
| 1163 | } |
---|
| 1164 | } |
---|
[934] | 1165 | else if (grid && grid->hasTransform() && !grid->isTransformed()) |
---|
| 1166 | { |
---|
[1003] | 1167 | // Temporarily deactivate the self-transformation of grid |
---|
| 1168 | //grid->transformGrid(grid); |
---|
[934] | 1169 | } |
---|
[619] | 1170 | } |
---|
| 1171 | |
---|
[687] | 1172 | void CField::solveGenerateGrid() |
---|
| 1173 | { |
---|
[746] | 1174 | if (grid && !grid->isTransformed() && hasDirectFieldReference() && grid != getDirectFieldReference()->grid) |
---|
[687] | 1175 | grid->completeGrid(getDirectFieldReference()->grid); |
---|
[775] | 1176 | else |
---|
| 1177 | grid->completeGrid(); |
---|
[687] | 1178 | } |
---|
| 1179 | |
---|
[775] | 1180 | void CField::solveGridDomainAxisBaseRef() |
---|
| 1181 | { |
---|
| 1182 | grid->solveDomainAxisRef(false); |
---|
| 1183 | grid->solveDomainAxisBaseRef(); |
---|
| 1184 | } |
---|
| 1185 | |
---|
[219] | 1186 | ///------------------------------------------------------------------- |
---|
| 1187 | |
---|
| 1188 | template <> |
---|
[562] | 1189 | void CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void) |
---|
[219] | 1190 | { |
---|
| 1191 | if (this->group_ref.isEmpty()) return; |
---|
| 1192 | StdString gref = this->group_ref.getValue(); |
---|
| 1193 | |
---|
[346] | 1194 | if (!CFieldGroup::has(gref)) |
---|
[219] | 1195 | ERROR("CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void)", |
---|
| 1196 | << "[ gref = " << gref << "]" |
---|
| 1197 | << " invalid group name !"); |
---|
| 1198 | |
---|
[347] | 1199 | CFieldGroup* group = CFieldGroup::get(gref); |
---|
| 1200 | CFieldGroup* owner = CFieldGroup::get(boost::polymorphic_downcast<CFieldGroup*>(this)); |
---|
[219] | 1201 | |
---|
[347] | 1202 | std::vector<CField*> allChildren = group->getAllChildren(); |
---|
[562] | 1203 | std::vector<CField*>::iterator it = allChildren.begin(), end = allChildren.end(); |
---|
[509] | 1204 | |
---|
[219] | 1205 | for (; it != end; it++) |
---|
| 1206 | { |
---|
[347] | 1207 | CField* child = *it; |
---|
[562] | 1208 | if (child->hasId()) owner->createChild()->field_ref.setValue(child->getId()); |
---|
[509] | 1209 | |
---|
[219] | 1210 | } |
---|
| 1211 | } |
---|
[509] | 1212 | |
---|
[464] | 1213 | void CField::scaleFactorAddOffset(double scaleFactor, double addOffset) |
---|
| 1214 | { |
---|
[651] | 1215 | map<int, CArray<double,1> >::iterator it; |
---|
| 1216 | for (it = data_srv.begin(); it != data_srv.end(); it++) it->second = (it->second - addOffset) / scaleFactor; |
---|
[464] | 1217 | } |
---|
[509] | 1218 | |
---|
[599] | 1219 | void CField::invertScaleFactorAddOffset(double scaleFactor, double addOffset) |
---|
| 1220 | { |
---|
[651] | 1221 | map<int, CArray<double,1> >::iterator it; |
---|
| 1222 | for (it = data_srv.begin(); it != data_srv.end(); it++) it->second = it->second * scaleFactor + addOffset; |
---|
[599] | 1223 | } |
---|
| 1224 | |
---|
[369] | 1225 | void CField::outputField(CArray<double,3>& fieldOut) |
---|
[300] | 1226 | { |
---|
[651] | 1227 | map<int, CArray<double,1> >::iterator it; |
---|
[562] | 1228 | for (it = data_srv.begin(); it != data_srv.end(); it++) |
---|
[551] | 1229 | { |
---|
[651] | 1230 | grid->outputField(it->first, it->second, fieldOut.dataFirst()); |
---|
[551] | 1231 | } |
---|
[300] | 1232 | } |
---|
[509] | 1233 | |
---|
[369] | 1234 | void CField::outputField(CArray<double,2>& fieldOut) |
---|
[300] | 1235 | { |
---|
[651] | 1236 | map<int, CArray<double,1> >::iterator it; |
---|
[567] | 1237 | for(it=data_srv.begin();it!=data_srv.end();it++) |
---|
| 1238 | { |
---|
[676] | 1239 | grid->outputField(it->first, it->second, fieldOut.dataFirst()); |
---|
[567] | 1240 | } |
---|
| 1241 | } |
---|
[219] | 1242 | |
---|
[567] | 1243 | void CField::outputField(CArray<double,1>& fieldOut) |
---|
| 1244 | { |
---|
[651] | 1245 | map<int, CArray<double,1> >::iterator it; |
---|
[567] | 1246 | |
---|
[562] | 1247 | for (it = data_srv.begin(); it != data_srv.end(); it++) |
---|
[300] | 1248 | { |
---|
[676] | 1249 | grid->outputField(it->first, it->second, fieldOut.dataFirst()); |
---|
[300] | 1250 | } |
---|
| 1251 | } |
---|
[551] | 1252 | |
---|
[599] | 1253 | void CField::inputField(CArray<double,3>& fieldOut) |
---|
| 1254 | { |
---|
[651] | 1255 | map<int, CArray<double,1> >::iterator it; |
---|
[599] | 1256 | for (it = data_srv.begin(); it != data_srv.end(); it++) |
---|
| 1257 | { |
---|
[651] | 1258 | grid->inputField(it->first, fieldOut.dataFirst(), it->second); |
---|
[599] | 1259 | } |
---|
| 1260 | } |
---|
| 1261 | |
---|
| 1262 | void CField::inputField(CArray<double,2>& fieldOut) |
---|
| 1263 | { |
---|
[651] | 1264 | map<int, CArray<double,1> >::iterator it; |
---|
[599] | 1265 | for(it = data_srv.begin(); it != data_srv.end(); it++) |
---|
| 1266 | { |
---|
[651] | 1267 | grid->inputField(it->first, fieldOut.dataFirst(), it->second); |
---|
[599] | 1268 | } |
---|
| 1269 | } |
---|
| 1270 | |
---|
| 1271 | void CField::inputField(CArray<double,1>& fieldOut) |
---|
| 1272 | { |
---|
[651] | 1273 | map<int, CArray<double,1> >::iterator it; |
---|
[599] | 1274 | for (it = data_srv.begin(); it != data_srv.end(); it++) |
---|
| 1275 | { |
---|
[651] | 1276 | grid->inputField(it->first, fieldOut.dataFirst(), it->second); |
---|
[599] | 1277 | } |
---|
| 1278 | } |
---|
| 1279 | |
---|
[676] | 1280 | void CField::outputCompressedField(CArray<double,1>& fieldOut) |
---|
| 1281 | { |
---|
| 1282 | map<int, CArray<double,1> >::iterator it; |
---|
| 1283 | |
---|
| 1284 | for (it = data_srv.begin(); it != data_srv.end(); it++) |
---|
| 1285 | { |
---|
| 1286 | grid->outputCompressedField(it->first, it->second, fieldOut.dataFirst()); |
---|
| 1287 | } |
---|
| 1288 | } |
---|
| 1289 | |
---|
[219] | 1290 | ///------------------------------------------------------------------- |
---|
| 1291 | |
---|
[562] | 1292 | void CField::parse(xml::CXMLNode& node) |
---|
[459] | 1293 | { |
---|
| 1294 | SuperClass::parse(node); |
---|
[562] | 1295 | if (!node.getContent(this->content)) |
---|
[472] | 1296 | { |
---|
[476] | 1297 | if (node.goToChildElement()) |
---|
[472] | 1298 | { |
---|
[476] | 1299 | do |
---|
| 1300 | { |
---|
[562] | 1301 | if (node.getElementName() == "variable" || node.getElementName() == "variable_group") this->getVirtualVariableGroup()->parseChild(node); |
---|
| 1302 | } while (node.goToNextElement()); |
---|
[476] | 1303 | node.goToParentElement(); |
---|
| 1304 | } |
---|
[472] | 1305 | } |
---|
[459] | 1306 | } |
---|
[509] | 1307 | |
---|
| 1308 | /*! |
---|
| 1309 | This function retrieves Id of corresponding domain_ref and axis_ref (if any) |
---|
| 1310 | of a field. In some cases, only domain exists but axis doesn't |
---|
| 1311 | \return pair of Domain and Axis id |
---|
| 1312 | */ |
---|
[887] | 1313 | const std::vector<StdString>& CField::getRefDomainAxisIds() |
---|
[569] | 1314 | { |
---|
| 1315 | CGrid* cgPtr = getRelGrid(); |
---|
| 1316 | if (NULL != cgPtr) |
---|
| 1317 | { |
---|
| 1318 | std::vector<StdString>::iterator it; |
---|
| 1319 | if (!domain_ref.isEmpty()) |
---|
| 1320 | { |
---|
| 1321 | std::vector<StdString> domainList = cgPtr->getDomainList(); |
---|
| 1322 | it = std::find(domainList.begin(), domainList.end(), domain_ref.getValue()); |
---|
[887] | 1323 | if (domainList.end() != it) domAxisScalarIds_[0] = *it; |
---|
[569] | 1324 | } |
---|
[472] | 1325 | |
---|
[569] | 1326 | if (!axis_ref.isEmpty()) |
---|
| 1327 | { |
---|
| 1328 | std::vector<StdString> axisList = cgPtr->getAxisList(); |
---|
| 1329 | it = std::find(axisList.begin(), axisList.end(), axis_ref.getValue()); |
---|
[887] | 1330 | if (axisList.end() != it) domAxisScalarIds_[1] = *it; |
---|
[569] | 1331 | } |
---|
[887] | 1332 | |
---|
| 1333 | if (!scalar_ref.isEmpty()) |
---|
| 1334 | { |
---|
| 1335 | std::vector<StdString> scalarList = cgPtr->getScalarList(); |
---|
| 1336 | it = std::find(scalarList.begin(), scalarList.end(), scalar_ref.getValue()); |
---|
| 1337 | if (scalarList.end() != it) domAxisScalarIds_[2] = *it; |
---|
| 1338 | } |
---|
[569] | 1339 | } |
---|
[887] | 1340 | return (domAxisScalarIds_); |
---|
[569] | 1341 | } |
---|
| 1342 | |
---|
[472] | 1343 | CVariable* CField::addVariable(const string& id) |
---|
| 1344 | { |
---|
[562] | 1345 | return vVariableGroup->createChild(id); |
---|
[472] | 1346 | } |
---|
| 1347 | |
---|
| 1348 | CVariableGroup* CField::addVariableGroup(const string& id) |
---|
| 1349 | { |
---|
[562] | 1350 | return vVariableGroup->createChildGroup(id); |
---|
[472] | 1351 | } |
---|
| 1352 | |
---|
[509] | 1353 | void CField::sendAddAllVariables() |
---|
| 1354 | { |
---|
[957] | 1355 | std::vector<CVariable*> allVar = getAllVariables(); |
---|
| 1356 | std::vector<CVariable*>::const_iterator it = allVar.begin(); |
---|
| 1357 | std::vector<CVariable*>::const_iterator itE = allVar.end(); |
---|
| 1358 | |
---|
| 1359 | for (; it != itE; ++it) |
---|
[509] | 1360 | { |
---|
[957] | 1361 | this->sendAddVariable((*it)->getId()); |
---|
| 1362 | (*it)->sendAllAttributesToServer(); |
---|
| 1363 | (*it)->sendValue(); |
---|
[509] | 1364 | } |
---|
| 1365 | } |
---|
| 1366 | |
---|
[472] | 1367 | void CField::sendAddVariable(const string& id) |
---|
| 1368 | { |
---|
[562] | 1369 | CContext* context = CContext::getCurrent(); |
---|
[509] | 1370 | |
---|
[562] | 1371 | if (!context->hasServer) |
---|
[472] | 1372 | { |
---|
[562] | 1373 | CContextClient* client = context->client; |
---|
[472] | 1374 | |
---|
[562] | 1375 | CEventClient event(this->getType(),EVENT_ID_ADD_VARIABLE); |
---|
[472] | 1376 | if (client->isServerLeader()) |
---|
| 1377 | { |
---|
[562] | 1378 | CMessage msg; |
---|
| 1379 | msg << this->getId(); |
---|
| 1380 | msg << id; |
---|
[595] | 1381 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
| 1382 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 1383 | event.push(*itRank,1,msg); |
---|
[562] | 1384 | client->sendEvent(event); |
---|
[472] | 1385 | } |
---|
[562] | 1386 | else client->sendEvent(event); |
---|
[472] | 1387 | } |
---|
| 1388 | } |
---|
[509] | 1389 | |
---|
[472] | 1390 | void CField::sendAddVariableGroup(const string& id) |
---|
| 1391 | { |
---|
[562] | 1392 | CContext* context = CContext::getCurrent(); |
---|
| 1393 | if (!context->hasServer) |
---|
[472] | 1394 | { |
---|
[562] | 1395 | CContextClient* client = context->client; |
---|
[472] | 1396 | |
---|
[562] | 1397 | CEventClient event(this->getType(),EVENT_ID_ADD_VARIABLE_GROUP); |
---|
[472] | 1398 | if (client->isServerLeader()) |
---|
| 1399 | { |
---|
[562] | 1400 | CMessage msg; |
---|
| 1401 | msg << this->getId(); |
---|
| 1402 | msg << id; |
---|
[595] | 1403 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
| 1404 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 1405 | event.push(*itRank,1,msg); |
---|
[562] | 1406 | client->sendEvent(event); |
---|
[472] | 1407 | } |
---|
[562] | 1408 | else client->sendEvent(event); |
---|
[472] | 1409 | } |
---|
| 1410 | } |
---|
[509] | 1411 | |
---|
[472] | 1412 | void CField::recvAddVariable(CEventServer& event) |
---|
| 1413 | { |
---|
[509] | 1414 | |
---|
[562] | 1415 | CBufferIn* buffer = event.subEvents.begin()->buffer; |
---|
[472] | 1416 | string id; |
---|
[562] | 1417 | *buffer >> id; |
---|
| 1418 | get(id)->recvAddVariable(*buffer); |
---|
[472] | 1419 | } |
---|
[509] | 1420 | |
---|
[472] | 1421 | void CField::recvAddVariable(CBufferIn& buffer) |
---|
| 1422 | { |
---|
[562] | 1423 | string id; |
---|
| 1424 | buffer >> id; |
---|
| 1425 | addVariable(id); |
---|
[472] | 1426 | } |
---|
| 1427 | |
---|
| 1428 | void CField::recvAddVariableGroup(CEventServer& event) |
---|
| 1429 | { |
---|
[509] | 1430 | |
---|
[562] | 1431 | CBufferIn* buffer = event.subEvents.begin()->buffer; |
---|
[472] | 1432 | string id; |
---|
[562] | 1433 | *buffer >> id; |
---|
| 1434 | get(id)->recvAddVariableGroup(*buffer); |
---|
[472] | 1435 | } |
---|
[509] | 1436 | |
---|
[472] | 1437 | void CField::recvAddVariableGroup(CBufferIn& buffer) |
---|
| 1438 | { |
---|
[562] | 1439 | string id; |
---|
| 1440 | buffer >> id; |
---|
| 1441 | addVariableGroup(id); |
---|
[472] | 1442 | } |
---|
| 1443 | |
---|
[998] | 1444 | /*! |
---|
| 1445 | * Returns string arithmetic expression associated to the field. |
---|
| 1446 | * \return if content is defined return content string, otherwise, if "expr" attribute is defined, return expr string. |
---|
| 1447 | */ |
---|
[1000] | 1448 | const string& CField::getExpression(void) |
---|
[998] | 1449 | { |
---|
[1000] | 1450 | if (!expr.isEmpty() && content.empty()) |
---|
[998] | 1451 | { |
---|
[1000] | 1452 | content = expr; |
---|
| 1453 | expr.reset(); |
---|
[998] | 1454 | } |
---|
[1000] | 1455 | |
---|
[998] | 1456 | return content; |
---|
| 1457 | } |
---|
[1000] | 1458 | |
---|
| 1459 | bool CField::hasExpression(void) const |
---|
[998] | 1460 | { |
---|
[1000] | 1461 | return (!expr.isEmpty() || !content.empty()); |
---|
| 1462 | } |
---|
| 1463 | |
---|
[540] | 1464 | DEFINE_REF_FUNC(Field,field) |
---|
[335] | 1465 | } // namespace xios |
---|