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