[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" |
---|
[641] | 17 | #include "pass_through_filter.hpp" |
---|
[642] | 18 | #include "filter_expr_node.hpp" |
---|
| 19 | #include "lex_parser.hpp" |
---|
[643] | 20 | #include "temporal_filter.hpp" |
---|
[1930] | 21 | #include "server_from_client_source_filter.hpp" |
---|
[2507] | 22 | #include "client_online_reader_filter.hpp" |
---|
[1930] | 23 | #include "file_reader_source_filter.hpp" |
---|
[2507] | 24 | #include "grid_redistribute_filter.hpp" |
---|
[1751] | 25 | #include "tracer.hpp" |
---|
[2144] | 26 | #include "graph_package.hpp" |
---|
[219] | 27 | |
---|
[1869] | 28 | namespace xios |
---|
| 29 | { |
---|
[509] | 30 | |
---|
[1869] | 31 | /// ////////////////////// Définitions ////////////////////// /// |
---|
[219] | 32 | |
---|
[1869] | 33 | CField::CField(void) |
---|
| 34 | : CObjectTemplate<CField>(), CFieldAttributes() |
---|
| 35 | , written(false) |
---|
| 36 | , hasOutputFile(false) |
---|
| 37 | , domAxisScalarIds_(vector<StdString>(3,"")) |
---|
| 38 | , areAllReferenceSolved(false), isReferenceSolved(false), isReferenceSolvedAndTransformed(false) |
---|
| 39 | , isGridChecked(false) |
---|
| 40 | , useCompressedOutput(false) |
---|
| 41 | , hasTimeInstant(false) |
---|
| 42 | , hasTimeCentered(false) |
---|
| 43 | , mustAutoTrigger(false) |
---|
| 44 | { setVirtualVariableGroup(CVariableGroup::create(getId() + "_virtual_variable_group")); } |
---|
[219] | 45 | |
---|
[1869] | 46 | CField::CField(const StdString& id) |
---|
| 47 | : CObjectTemplate<CField>(id), CFieldAttributes() |
---|
| 48 | , written(false) |
---|
| 49 | , hasOutputFile(false) |
---|
| 50 | , domAxisScalarIds_(vector<StdString>(3,"")) |
---|
| 51 | , areAllReferenceSolved(false), isReferenceSolved(false), isReferenceSolvedAndTransformed(false) |
---|
| 52 | , isGridChecked(false) |
---|
| 53 | , useCompressedOutput(false) |
---|
| 54 | , hasTimeInstant(false) |
---|
| 55 | , hasTimeCentered(false) |
---|
| 56 | , mustAutoTrigger(false) |
---|
[1962] | 57 | { setVirtualVariableGroup(CVariableGroup::create(getId() + "_virtual_variable_group")); } |
---|
[219] | 58 | |
---|
[1869] | 59 | CField::~CField(void) |
---|
| 60 | {} |
---|
[509] | 61 | |
---|
[472] | 62 | //---------------------------------------------------------------- |
---|
| 63 | |
---|
[1869] | 64 | void CField::setVirtualVariableGroup(CVariableGroup* newVVariableGroup) |
---|
| 65 | TRY |
---|
| 66 | { |
---|
| 67 | this->vVariableGroup = newVVariableGroup; |
---|
| 68 | } |
---|
| 69 | CATCH |
---|
[509] | 70 | |
---|
[1869] | 71 | CVariableGroup* CField::getVirtualVariableGroup(void) const |
---|
| 72 | TRY |
---|
| 73 | { |
---|
| 74 | return this->vVariableGroup; |
---|
| 75 | } |
---|
| 76 | CATCH |
---|
[472] | 77 | |
---|
[1869] | 78 | std::vector<CVariable*> CField::getAllVariables(void) const |
---|
| 79 | TRY |
---|
| 80 | { |
---|
| 81 | return this->vVariableGroup->getAllChildren(); |
---|
| 82 | } |
---|
| 83 | CATCH |
---|
[509] | 84 | |
---|
[1869] | 85 | void CField::solveDescInheritance(bool apply, const CAttributeMap* const parent) |
---|
| 86 | TRY |
---|
| 87 | { |
---|
| 88 | SuperClassAttribute::setAttributes(parent, apply); |
---|
| 89 | this->getVirtualVariableGroup()->solveDescInheritance(apply, NULL); |
---|
| 90 | } |
---|
| 91 | CATCH_DUMP_ATTR |
---|
[219] | 92 | |
---|
[645] | 93 | //---------------------------------------------------------------- |
---|
[509] | 94 | |
---|
[598] | 95 | bool CField::dispatchEvent(CEventServer& event) |
---|
[1622] | 96 | TRY |
---|
[300] | 97 | { |
---|
[562] | 98 | if (SuperClass::dispatchEvent(event)) return true; |
---|
[300] | 99 | else |
---|
| 100 | { |
---|
| 101 | switch(event.type) |
---|
| 102 | { |
---|
| 103 | case EVENT_ID_UPDATE_DATA : |
---|
[2264] | 104 | // return true; // temporary |
---|
[562] | 105 | recvUpdateData(event); |
---|
| 106 | return true; |
---|
| 107 | break; |
---|
[472] | 108 | |
---|
[598] | 109 | case EVENT_ID_READ_DATA : |
---|
| 110 | recvReadDataRequest(event); |
---|
| 111 | return true; |
---|
| 112 | break; |
---|
[509] | 113 | |
---|
[598] | 114 | case EVENT_ID_READ_DATA_READY : |
---|
| 115 | recvReadDataReady(event); |
---|
| 116 | return true; |
---|
| 117 | break; |
---|
[509] | 118 | |
---|
[598] | 119 | case EVENT_ID_ADD_VARIABLE : |
---|
| 120 | recvAddVariable(event); |
---|
| 121 | return true; |
---|
| 122 | break; |
---|
| 123 | |
---|
| 124 | case EVENT_ID_ADD_VARIABLE_GROUP : |
---|
| 125 | recvAddVariableGroup(event); |
---|
| 126 | return true; |
---|
| 127 | break; |
---|
[1875] | 128 | |
---|
| 129 | case EVENT_ID_GRID_COMPLETED : |
---|
| 130 | recvGridCompleted(event); |
---|
| 131 | return true; |
---|
| 132 | break; |
---|
[300] | 133 | default : |
---|
[562] | 134 | ERROR("bool CField::dispatchEvent(CEventServer& event)", << "Unknown Event"); |
---|
| 135 | return false; |
---|
[300] | 136 | } |
---|
| 137 | } |
---|
| 138 | } |
---|
[1622] | 139 | CATCH |
---|
[2230] | 140 | |
---|
| 141 | bool CField::isCollectiveEvent(CEventServer& event) |
---|
| 142 | TRY |
---|
| 143 | { |
---|
| 144 | switch(event.type) |
---|
| 145 | { |
---|
| 146 | case EVENT_ID_UPDATE_DATA : |
---|
| 147 | recvUpdateData(event); |
---|
| 148 | return true; |
---|
| 149 | break; |
---|
[509] | 150 | |
---|
[2230] | 151 | case EVENT_ID_READ_DATA : |
---|
| 152 | recvReadDataRequest(event); |
---|
| 153 | return true; |
---|
| 154 | break; |
---|
[1930] | 155 | |
---|
[2230] | 156 | case EVENT_ID_READ_DATA_READY : |
---|
| 157 | recvReadDataReady(event); |
---|
| 158 | return false; |
---|
| 159 | break; |
---|
| 160 | |
---|
| 161 | case EVENT_ID_ADD_VARIABLE : |
---|
| 162 | recvAddVariable(event); |
---|
| 163 | return false; |
---|
| 164 | break; |
---|
| 165 | |
---|
| 166 | case EVENT_ID_ADD_VARIABLE_GROUP : |
---|
| 167 | recvAddVariableGroup(event); |
---|
| 168 | return false; |
---|
| 169 | break; |
---|
| 170 | |
---|
| 171 | case EVENT_ID_GRID_COMPLETED : |
---|
| 172 | recvGridCompleted(event); |
---|
| 173 | return true; |
---|
| 174 | break; |
---|
| 175 | default : |
---|
| 176 | ERROR("bool CField::dispatchEvent(CEventServer& event)", << "Unknown Event"); |
---|
| 177 | return false; |
---|
| 178 | } |
---|
| 179 | } |
---|
| 180 | CATCH |
---|
| 181 | |
---|
[300] | 182 | void CField::recvUpdateData(CEventServer& event) |
---|
[1622] | 183 | TRY |
---|
[300] | 184 | { |
---|
[562] | 185 | string fieldId; |
---|
[1930] | 186 | for (auto& subEvent : event.subEvents) (*subEvent.buffer) >> fieldId ; |
---|
| 187 | get(fieldId)->receiveUpdateData(event); |
---|
| 188 | } |
---|
| 189 | CATCH |
---|
[1875] | 190 | |
---|
[1930] | 191 | void CField::receiveUpdateData(CEventServer& event) |
---|
[1622] | 192 | TRY |
---|
[300] | 193 | { |
---|
[1930] | 194 | if (hasCouplerIn()) clientFromClientSourceFilter_->streamData(event) ; |
---|
| 195 | else serverFromClientSourceFilter_->streamData(event) ; |
---|
[1875] | 196 | } |
---|
| 197 | CATCH |
---|
| 198 | |
---|
[1232] | 199 | /* |
---|
| 200 | Send a request for reading data. |
---|
| 201 | Client sends a request to server for demanding server to read data and send back to it. |
---|
| 202 | For now, this function is called only by client |
---|
| 203 | In the future, it can be called by level-1 servers |
---|
| 204 | \param [in] tsDataRequested timestamp when the call is made |
---|
| 205 | */ |
---|
[1934] | 206 | bool CField::sendReadDataRequest(const CDate& tsDataRequested) |
---|
[1622] | 207 | TRY |
---|
[598] | 208 | { |
---|
[2507] | 209 | if (clientFromServerSourceFilter_) return clientFromServerSourceFilter_->sendReadDataRequest(tsDataRequested) ; |
---|
| 210 | else if (clientOnlineReaderFilter_) return clientOnlineReaderFilter_->sendReadDataRequest(tsDataRequested) ; |
---|
| 211 | else ERROR("bool CField::sendReadDataRequest(const CDate& tsDataRequested)", << "uninitialized source filter"); |
---|
[598] | 212 | } |
---|
[1622] | 213 | CATCH_DUMP_ATTR |
---|
[1934] | 214 | |
---|
| 215 | |
---|
[598] | 216 | /*! |
---|
| 217 | Send request new data read from file if need be, that is the current data is out-of-date. |
---|
| 218 | \return true if and only if some data was requested |
---|
| 219 | */ |
---|
| 220 | bool CField::sendReadDataRequestIfNeeded(void) |
---|
[1622] | 221 | TRY |
---|
[598] | 222 | { |
---|
[2507] | 223 | if (clientFromServerSourceFilter_) return clientFromServerSourceFilter_->sendReadDataRequestIfNeeded() ; |
---|
| 224 | else if (clientOnlineReaderFilter_) return clientOnlineReaderFilter_->sendReadDataRequestIfNeeded() ; |
---|
| 225 | else ERROR("bool CField::sendReadDataRequestIfNeeded(void)", << "uninitialized source filter"); |
---|
[598] | 226 | } |
---|
[1622] | 227 | CATCH_DUMP_ATTR |
---|
[598] | 228 | |
---|
[1934] | 229 | |
---|
[598] | 230 | void CField::recvReadDataRequest(CEventServer& event) |
---|
[1622] | 231 | TRY |
---|
[598] | 232 | { |
---|
| 233 | CBufferIn* buffer = event.subEvents.begin()->buffer; |
---|
| 234 | StdString fieldId; |
---|
| 235 | *buffer >> fieldId; |
---|
[1930] | 236 | get(fieldId)->recvReadDataRequest(); |
---|
[598] | 237 | } |
---|
[1622] | 238 | CATCH |
---|
[1930] | 239 | |
---|
[1232] | 240 | /*! |
---|
| 241 | Receive data request sent from client and process it |
---|
| 242 | Every time server receives this request, it will try to read data and sent read data back to client |
---|
| 243 | At the moment, this function is called by server level 1 |
---|
| 244 | In the future, this should (only) be done by the last level servers. |
---|
| 245 | */ |
---|
[1930] | 246 | void CField::recvReadDataRequest(void) |
---|
| 247 | TRY |
---|
| 248 | { |
---|
| 249 | fileReaderSourceFilter_->streamData() ; |
---|
| 250 | } |
---|
| 251 | CATCH_DUMP_ATTR |
---|
| 252 | |
---|
[1934] | 253 | |
---|
[1930] | 254 | /* |
---|
[1232] | 255 | Receive read data from server. |
---|
| 256 | At the moment, this function is called in the client side. |
---|
| 257 | In the future, this function can be called hiearachically (server n-1, server n -2, ..., client) |
---|
| 258 | \param event event containing read data |
---|
| 259 | */ |
---|
[598] | 260 | void CField::recvReadDataReady(CEventServer& event) |
---|
[1622] | 261 | TRY |
---|
[598] | 262 | { |
---|
| 263 | string fieldId; |
---|
[1930] | 264 | for (auto& subEvent : event.subEvents) (*subEvent.buffer) >> fieldId ; |
---|
[1934] | 265 | get(fieldId)->receiveReadDataReady(event); |
---|
[598] | 266 | } |
---|
[1622] | 267 | CATCH |
---|
[598] | 268 | |
---|
[1934] | 269 | void CField::receiveReadDataReady(CEventServer& event) |
---|
| 270 | TRY |
---|
| 271 | { |
---|
| 272 | clientFromServerSourceFilter_->streamData(event) ; |
---|
| 273 | } |
---|
| 274 | CATCH_DUMP_ATTR |
---|
[1930] | 275 | |
---|
[1875] | 276 | |
---|
| 277 | void CField::checkForLateDataFromCoupler(void) |
---|
| 278 | TRY |
---|
| 279 | { |
---|
| 280 | CContext* context = CContext::getCurrent(); |
---|
| 281 | const CDate& currentDate = context->getCalendar()->getCurrentDate(); |
---|
| 282 | |
---|
| 283 | CTimer timer("CField::checkForLateDataFromCoupler"); |
---|
| 284 | timer.resume(); |
---|
| 285 | traceOff() ; |
---|
| 286 | timer.suspend(); |
---|
[1930] | 287 | |
---|
| 288 | bool isDataLate; |
---|
[1875] | 289 | do |
---|
| 290 | { |
---|
[1930] | 291 | isDataLate=clientFromClientSourceFilter_->isDataLate() ; |
---|
[1875] | 292 | if (isDataLate) |
---|
| 293 | { |
---|
| 294 | timer.resume(); |
---|
| 295 | context->globalEventLoop(); |
---|
| 296 | timer.suspend(); |
---|
| 297 | } |
---|
| 298 | } while (isDataLate && timer.getCumulatedTime() < CXios::recvFieldTimeout); |
---|
| 299 | |
---|
| 300 | timer.resume(); |
---|
| 301 | traceOn() ; |
---|
| 302 | timer.suspend() ; |
---|
| 303 | |
---|
| 304 | if (isDataLate) ERROR("void CField::checkForLateDataFromCoupler(void)", |
---|
| 305 | << "Late data at timestep = " << currentDate); |
---|
| 306 | } |
---|
| 307 | CATCH_DUMP_ATTR |
---|
| 308 | |
---|
[1318] | 309 | void CField::checkForLateDataFromServer(void) |
---|
[1622] | 310 | TRY |
---|
[1318] | 311 | { |
---|
[2507] | 312 | if (clientFromServerSourceFilter_) return clientFromServerSourceFilter_->checkForLateData() ; |
---|
| 313 | else if (clientOnlineReaderFilter_) return clientOnlineReaderFilter_->checkForLateData() ; |
---|
| 314 | else ERROR("void CField::checkForLateDataFromServer(void)", << "uninitialized source filter"); |
---|
[1318] | 315 | } |
---|
[1934] | 316 | CATCH_DUMP_ATTR |
---|
| 317 | |
---|
| 318 | |
---|
[1875] | 319 | void CField::triggerLateField(void) |
---|
| 320 | TRY |
---|
| 321 | { |
---|
| 322 | if (hasFileIn()) |
---|
| 323 | { |
---|
| 324 | checkForLateDataFromServer() ; |
---|
[2507] | 325 | if (clientFromServerSourceFilter_) clientFromServerSourceFilter_->trigger(CContext::getCurrent()->getCalendar()->getCurrentDate()) ; |
---|
| 326 | else if (clientOnlineReaderFilter_) clientOnlineReaderFilter_->trigger(CContext::getCurrent()->getCalendar()->getCurrentDate()) ; |
---|
[1875] | 327 | } |
---|
| 328 | else if (hasCouplerIn()) |
---|
| 329 | { |
---|
| 330 | checkForLateDataFromCoupler() ; |
---|
[1930] | 331 | clientFromClientSourceFilter_->trigger(CContext::getCurrent()->getCalendar()->getCurrentDate()) ; |
---|
[1875] | 332 | } |
---|
| 333 | } |
---|
| 334 | CATCH_DUMP_ATTR |
---|
| 335 | |
---|
[2507] | 336 | |
---|
[1875] | 337 | |
---|
[1869] | 338 | //---------------------------------------------------------------- |
---|
[219] | 339 | |
---|
[1869] | 340 | StdString CField::GetName(void) { return StdString("field"); } |
---|
| 341 | StdString CField::GetDefName(void) { return CField::GetName(); } |
---|
| 342 | ENodeType CField::GetType(void) { return eField; } |
---|
[219] | 343 | |
---|
[1869] | 344 | //---------------------------------------------------------------- |
---|
[219] | 345 | |
---|
[1869] | 346 | CGrid* CField::getRelGrid(void) const |
---|
| 347 | TRY |
---|
| 348 | { |
---|
| 349 | return this->grid_; |
---|
| 350 | } |
---|
| 351 | CATCH |
---|
[219] | 352 | |
---|
[1869] | 353 | //---------------------------------------------------------------- |
---|
[219] | 354 | |
---|
[1869] | 355 | CFile* CField::getRelFile(void) const |
---|
| 356 | TRY |
---|
| 357 | { |
---|
[1872] | 358 | if (hasFileIn()) return this->fileIn_; |
---|
| 359 | else if (hasFileOut()) return this->fileOut_ ; |
---|
| 360 | else return nullptr ; |
---|
[1869] | 361 | } |
---|
| 362 | CATCH |
---|
[509] | 363 | |
---|
[2311] | 364 | CGrid* CField::getAssociatedGrid(void) const |
---|
| 365 | TRY |
---|
| 366 | { |
---|
| 367 | return this->grid_; |
---|
| 368 | } |
---|
| 369 | CATCH |
---|
| 370 | |
---|
[2206] | 371 | CDomain* CField::getAssociatedDomain(const string& domainId, bool noError) const |
---|
[2203] | 372 | { |
---|
[2206] | 373 | if (grid_==nullptr) |
---|
| 374 | { |
---|
| 375 | if (noError) return nullptr ; |
---|
| 376 | else ERROR("CDomain* CField::getAssociatedDomain(const string& domainId)", <<" field with id="<<getId()<<" has no associated grid, " |
---|
[2203] | 377 | <<"check if the worklfow is enabled for this field"); |
---|
[2206] | 378 | } |
---|
| 379 | return grid_->getAssociatedDomain(domainId, noError) ; |
---|
[2203] | 380 | } |
---|
| 381 | |
---|
[2206] | 382 | CAxis* CField::getAssociatedAxis(const string& axisId, bool noError) const |
---|
[2203] | 383 | { |
---|
[2206] | 384 | if (grid_==nullptr) |
---|
| 385 | { |
---|
| 386 | if (noError) return nullptr ; |
---|
| 387 | else ERROR("CAxis* CField::getAssociatedAxis(const string& axisId)", <<" field with id="<<getId()<<" has no associated grid, " |
---|
[2203] | 388 | <<"check if the worklfow is enabled for this field"); |
---|
[2206] | 389 | } |
---|
| 390 | return grid_->getAssociatedAxis(axisId, noError) ; |
---|
[2203] | 391 | } |
---|
| 392 | |
---|
[2206] | 393 | CScalar* CField::getAssociatedScalar(const string& scalarId, bool noError) const |
---|
[2203] | 394 | { |
---|
[2206] | 395 | if (grid_==nullptr) |
---|
| 396 | { |
---|
| 397 | if (noError) return nullptr ; |
---|
| 398 | else ERROR("CScalar* CField::getAssociatedScalar(const string& scalarId)", <<" field with id="<<getId()<<" has no associated grid, " |
---|
[2203] | 399 | <<"check if the worklfow is enabled for this field"); |
---|
[2206] | 400 | } |
---|
| 401 | return grid_->getAssociatedScalar(scalarId, noError) ; |
---|
[2203] | 402 | } |
---|
| 403 | |
---|
| 404 | |
---|
[1869] | 405 | func::CFunctor::ETimeType CField::getOperationTimeType() const |
---|
| 406 | TRY |
---|
| 407 | { |
---|
| 408 | return operationTimeType; |
---|
| 409 | } |
---|
| 410 | CATCH |
---|
[645] | 411 | |
---|
| 412 | |
---|
[1869] | 413 | //---------------------------------------------------------------- |
---|
[219] | 414 | |
---|
[1869] | 415 | bool CField::isActive(bool atCurrentTimestep /*= false*/) const |
---|
| 416 | TRY |
---|
| 417 | { |
---|
[1930] | 418 | if (modelToClientSourceFilter_) |
---|
| 419 | return atCurrentTimestep ? modelToClientSourceFilter_->isDataExpected(CContext::getCurrent()->getCalendar()->getCurrentDate()) : true; |
---|
| 420 | else if (clientToModelStoreFilter_) return true; |
---|
[1869] | 421 | else if (instantDataFilter) |
---|
| 422 | ERROR("bool CField::isActive(bool atCurrentTimestep)", |
---|
| 423 | << "Impossible to check if field [ id = " << getId() << " ] is active as it cannot be used to receive nor send data."); |
---|
[1158] | 424 | |
---|
[1869] | 425 | return false; |
---|
| 426 | } |
---|
| 427 | CATCH |
---|
[562] | 428 | |
---|
[1869] | 429 | //---------------------------------------------------------------- |
---|
[509] | 430 | |
---|
[1869] | 431 | bool CField::wasWritten() const |
---|
| 432 | TRY |
---|
| 433 | { |
---|
| 434 | return written; |
---|
| 435 | } |
---|
| 436 | CATCH |
---|
[707] | 437 | |
---|
[1869] | 438 | void CField::setWritten() |
---|
| 439 | TRY |
---|
| 440 | { |
---|
| 441 | written = true; |
---|
| 442 | } |
---|
| 443 | CATCH_DUMP_ATTR |
---|
[707] | 444 | |
---|
[1869] | 445 | //---------------------------------------------------------------- |
---|
[707] | 446 | |
---|
[1869] | 447 | bool CField::getUseCompressedOutput() const |
---|
| 448 | TRY |
---|
| 449 | { |
---|
| 450 | return useCompressedOutput; |
---|
| 451 | } |
---|
| 452 | CATCH |
---|
[676] | 453 | |
---|
[1869] | 454 | void CField::setUseCompressedOutput() |
---|
| 455 | TRY |
---|
| 456 | { |
---|
| 457 | useCompressedOutput = true; |
---|
| 458 | } |
---|
| 459 | CATCH_DUMP_ATTR |
---|
[676] | 460 | |
---|
[2011] | 461 | |
---|
[1869] | 462 | //---------------------------------------------------------------- |
---|
[2182] | 463 | |
---|
[676] | 464 | |
---|
[1869] | 465 | void CField::checkGridOfEnabledFields() |
---|
| 466 | TRY |
---|
| 467 | { |
---|
| 468 | if (!isGridChecked) |
---|
| 469 | { |
---|
| 470 | isGridChecked = true; |
---|
| 471 | solveCheckMaskIndex(false); |
---|
| 472 | } |
---|
| 473 | } |
---|
| 474 | CATCH_DUMP_ATTR |
---|
[1025] | 475 | |
---|
[1869] | 476 | void CField::sendGridComponentOfEnabledFields() |
---|
| 477 | TRY |
---|
| 478 | { |
---|
| 479 | solveGridDomainAxisRef(true); |
---|
| 480 | // solveCheckMaskIndex(true); |
---|
| 481 | } |
---|
| 482 | CATCH_DUMP_ATTR |
---|
[1025] | 483 | |
---|
[1869] | 484 | void CField::sendGridOfEnabledFields() |
---|
| 485 | TRY |
---|
| 486 | { |
---|
| 487 | // solveGridDomainAxisRef(true); |
---|
| 488 | solveCheckMaskIndex(true); |
---|
| 489 | } |
---|
| 490 | CATCH_DUMP_ATTR |
---|
[1025] | 491 | |
---|
[1870] | 492 | /*! |
---|
| 493 | * Compute the required buffer size to send the fields data. |
---|
| 494 | * \param [in/out] bufferSize Modifying the bufferSize for the client context |
---|
| 495 | * \param [in/out] maxEventSize Modifying the maximum event size for the client context |
---|
| 496 | * \param [in] bufferForWriting True if buffers are used for sending data for writing |
---|
| 497 | */ |
---|
| 498 | void CField::setContextClientDataBufferSize(map<CContextClient*,map<int,size_t>>& bufferSize, |
---|
| 499 | map<CContextClient*,map<int,size_t>>& maxEventSize, |
---|
| 500 | bool bufferForWriting) |
---|
| 501 | { |
---|
[2507] | 502 | auto& contextBufferSize = bufferSize[client_] ; |
---|
| 503 | auto& contextMaxEventSize = maxEventSize[client_] ; |
---|
| 504 | const std::map<int, size_t> mapSize = grid_->getDataBufferSize(client_, getId(), bufferForWriting); |
---|
[1870] | 505 | for(auto& it : mapSize ) |
---|
| 506 | { |
---|
| 507 | // If contextBufferSize[it.first] does not exist, it will be zero-initialized |
---|
| 508 | // so we can use it safely without checking for its existance |
---|
| 509 | if (CXios::isOptPerformance) contextBufferSize[it.first] += it.second; |
---|
| 510 | else if (contextBufferSize[it.first] < it.second) contextBufferSize[it.first] = it.second; |
---|
| 511 | |
---|
| 512 | if (contextMaxEventSize[it.first] < it.second) contextMaxEventSize[it.first] = it.second; |
---|
| 513 | } |
---|
| 514 | |
---|
| 515 | } |
---|
| 516 | |
---|
| 517 | void CField::setContextClientAttributesBufferSize(map<CContextClient*,map<int,size_t>>& bufferSize, |
---|
| 518 | map<CContextClient*,map<int,size_t>>& maxEventSize, |
---|
| 519 | bool bufferForWriting) |
---|
| 520 | { |
---|
[2507] | 521 | auto& contextBufferSize = bufferSize[client_] ; |
---|
| 522 | auto& contextMaxEventSize = maxEventSize[client_] ; |
---|
| 523 | const std::map<int, size_t> mapSize = grid_->getAttributesBufferSize(client_, bufferForWriting); |
---|
[1870] | 524 | for(auto& it : mapSize ) |
---|
| 525 | { |
---|
| 526 | // If contextBufferSize[it.first] does not exist, it will be zero-initialized |
---|
| 527 | // so we can use it safely without checking for its existance |
---|
| 528 | if (contextBufferSize[it.first] < it.second) contextBufferSize[it.first] = it.second; |
---|
| 529 | if (contextMaxEventSize[it.first] < it.second) contextMaxEventSize[it.first] = it.second; |
---|
| 530 | } |
---|
| 531 | |
---|
| 532 | } |
---|
| 533 | |
---|
| 534 | |
---|
| 535 | // ym obsolete to be removed |
---|
[1869] | 536 | std::map<int, StdSize> CField::getGridAttributesBufferSize(CContextClient* client, bool bufferForWriting /*= "false"*/) |
---|
| 537 | TRY |
---|
| 538 | { |
---|
| 539 | return grid_->getAttributesBufferSize(client, bufferForWriting); |
---|
| 540 | } |
---|
| 541 | CATCH_DUMP_ATTR |
---|
[509] | 542 | |
---|
[1870] | 543 | // ym obsolete to be removed |
---|
[1869] | 544 | std::map<int, StdSize> CField::getGridDataBufferSize(CContextClient* client, bool bufferForWriting /*= "false"*/) |
---|
| 545 | TRY |
---|
| 546 | { |
---|
| 547 | return grid_->getDataBufferSize(client, getId(), bufferForWriting); |
---|
| 548 | } |
---|
| 549 | CATCH_DUMP_ATTR |
---|
[731] | 550 | |
---|
[2130] | 551 | bool CField::evaluateBufferSize(map<CContextClient*,map<int,size_t>>& evaluateBuffer, bool isOptPerformance) |
---|
| 552 | { |
---|
| 553 | CContextClient* client=nullptr ; |
---|
[2326] | 554 | const size_t headerSize=100 ; |
---|
[1870] | 555 | |
---|
[2130] | 556 | for(int i=0;i<2;i++) |
---|
| 557 | { |
---|
| 558 | map<int,int> dataSize ; |
---|
| 559 | if (i==0 && clientToServerStoreFilter_) client = clientToServerStoreFilter_-> getTransferedDataSize(dataSize) ; |
---|
| 560 | if (i==1 && serverToClientStoreFilter_) client = serverToClientStoreFilter_-> getTransferedDataSize(dataSize) ; |
---|
[1870] | 561 | |
---|
[2130] | 562 | if (client!=nullptr) |
---|
| 563 | { |
---|
| 564 | map<int,size_t> bufferSize ; |
---|
| 565 | |
---|
[2326] | 566 | bufferSize = evaluateBuffer[client] ; |
---|
[2130] | 567 | if (isOptPerformance) |
---|
| 568 | { |
---|
| 569 | for(auto& it : dataSize) |
---|
| 570 | { |
---|
[2433] | 571 | if (bufferSize.count(it.first)==0) bufferSize[it.first]=sizeof(double)*it.second+headerSize ; |
---|
| 572 | else bufferSize[it.first]+=sizeof(double)*it.second+headerSize ; |
---|
[2130] | 573 | } |
---|
| 574 | } |
---|
| 575 | else |
---|
| 576 | { |
---|
| 577 | for(auto& it : dataSize) |
---|
| 578 | { |
---|
[2433] | 579 | if (bufferSize.count(it.first)==0) bufferSize[it.first]=sizeof(double)*it.second+headerSize ; |
---|
| 580 | else bufferSize[it.first]=std::max(bufferSize[it.first],(size_t)(sizeof(double)*it.second+headerSize)) ; |
---|
[2130] | 581 | } |
---|
| 582 | } |
---|
| 583 | evaluateBuffer[client] = bufferSize ; |
---|
| 584 | client=nullptr ; |
---|
| 585 | } |
---|
| 586 | } |
---|
| 587 | if (client==nullptr) return false ; |
---|
| 588 | else return true; |
---|
| 589 | } |
---|
| 590 | |
---|
| 591 | |
---|
[1869] | 592 | size_t CField::getGlobalWrittenSize() |
---|
| 593 | TRY |
---|
| 594 | { |
---|
| 595 | return grid_->getGlobalWrittenSize(); |
---|
| 596 | } |
---|
| 597 | CATCH_DUMP_ATTR |
---|
[1215] | 598 | |
---|
[1869] | 599 | //---------------------------------------------------------------- |
---|
[219] | 600 | |
---|
[1869] | 601 | void CField::solveServerOperation(void) |
---|
| 602 | TRY |
---|
| 603 | { |
---|
| 604 | CContext* context = CContext::getCurrent(); |
---|
[509] | 605 | |
---|
[1869] | 606 | if (freq_op.isEmpty()) freq_op.setValue(TimeStep); |
---|
[509] | 607 | |
---|
[1869] | 608 | if (freq_offset.isEmpty()) freq_offset.setValue(NoneDu); |
---|
[219] | 609 | |
---|
[1869] | 610 | if (operation.isEmpty()) |
---|
| 611 | ERROR("void CField::solveServerOperation(void)", |
---|
| 612 | << "An operation must be defined for field \"" << getId() << "\"."); |
---|
[509] | 613 | |
---|
[1869] | 614 | std::shared_ptr<func::CFunctor> functor; |
---|
| 615 | CArray<double, 1> dummyData; |
---|
[598] | 616 | |
---|
[562] | 617 | #define DECLARE_FUNCTOR(MType, mtype) \ |
---|
[1869] | 618 | if (operation.getValue().compare(#mtype) == 0) \ |
---|
| 619 | { \ |
---|
| 620 | functor.reset(new func::C##MType(dummyData)); \ |
---|
| 621 | } |
---|
[509] | 622 | |
---|
[219] | 623 | #include "functor_type.conf" |
---|
[509] | 624 | |
---|
[1869] | 625 | if (!functor) |
---|
| 626 | ERROR("void CField::solveServerOperation(void)", |
---|
| 627 | << "\"" << operation << "\" is not a valid operation."); |
---|
[645] | 628 | |
---|
[1869] | 629 | operationTimeType = functor->timeType(); |
---|
| 630 | } |
---|
| 631 | CATCH_DUMP_ATTR |
---|
[509] | 632 | |
---|
[1869] | 633 | //---------------------------------------------------------------- |
---|
[640] | 634 | |
---|
[1869] | 635 | bool CField::buildWorkflowGraph(CGarbageCollector& gc) |
---|
| 636 | { |
---|
| 637 | if (buildWorkflowGraphDone_) return true ; |
---|
[2193] | 638 | |
---|
[1875] | 639 | |
---|
[1869] | 640 | const bool detectMissingValues = (!detect_missing_value.isEmpty() && !default_value.isEmpty() && detect_missing_value == true); |
---|
[2144] | 641 | const double defaultValue = detectMissingValues ? default_value : (!default_value.isEmpty() ? default_value : 0.0); |
---|
| 642 | bool buildGraph_ = !build_workflow_graph.isEmpty() && build_workflow_graph == true ; |
---|
[2193] | 643 | |
---|
[1869] | 644 | if (!inputFilter) inputFilter = std::shared_ptr<CPassThroughFilter>(new CPassThroughFilter(gc)); |
---|
[2193] | 645 | |
---|
[1869] | 646 | if (hasDirectFieldReference()) |
---|
| 647 | { |
---|
| 648 | CField* fieldRef = getDirectFieldReference(); |
---|
[2193] | 649 | |
---|
[2144] | 650 | //------ build_workflow_graph start |
---|
| 651 | if(buildGraph_) |
---|
| 652 | { |
---|
| 653 | (*fieldRef).build_workflow_graph.set(build_workflow_graph); |
---|
| 654 | } |
---|
| 655 | else |
---|
| 656 | { |
---|
| 657 | this->build_workflow_graph.set(fieldRef->build_workflow_graph); |
---|
| 658 | buildGraph_ = !build_workflow_graph.isEmpty() && build_workflow_graph == true ; |
---|
| 659 | } |
---|
| 660 | |
---|
| 661 | |
---|
[2193] | 662 | // if(buildGraph_) this->build_workflow_graph.set(build_workflow_graph); |
---|
[2144] | 663 | //------ build_workflow_graph end |
---|
| 664 | |
---|
[1869] | 665 | bool ret=fieldRef->buildWorkflowGraph(gc); |
---|
| 666 | if (!ret) return false ; // workflow graph cannot be built at this stage |
---|
[2144] | 667 | |
---|
| 668 | this->build_workflow_graph.set(fieldRef->build_workflow_graph); |
---|
| 669 | buildGraph_ = !build_workflow_graph.isEmpty() && build_workflow_graph == true ; |
---|
[1869] | 670 | } |
---|
| 671 | |
---|
[1875] | 672 | // now construct grid and check if element are enabled |
---|
| 673 | solveGridReference() ; // grid_ is now defined |
---|
| 674 | if (!isGridCompleted()) return false; |
---|
[2206] | 675 | if (grid_->activateFieldWorkflow(gc)==false) return false; // workflow graph cannot be built at this stage |
---|
[1875] | 676 | |
---|
[1869] | 677 | // Check if we have an expression to parse |
---|
| 678 | std::shared_ptr<COutputPin> filterExpr ; |
---|
| 679 | if (hasExpression()) |
---|
| 680 | { |
---|
| 681 | boost::scoped_ptr<IFilterExprNode> expr(parseExpr(getExpression() + '\0')); |
---|
| 682 | filterExpr = expr->reduce(gc, *this); |
---|
[2193] | 683 | |
---|
| 684 | |
---|
[1869] | 685 | if (!filterExpr) return false ; // workflow graph cannot be built at this stage |
---|
| 686 | } |
---|
| 687 | |
---|
| 688 | // prepare transformation. Need to know before if workflow of auxillary field can be built |
---|
| 689 | if (hasDirectFieldReference()) |
---|
| 690 | { |
---|
| 691 | auto gridPath=getGridPath() ; |
---|
| 692 | gridPath.push_back(grid_) ; |
---|
| 693 | |
---|
| 694 | CGrid* gridSrc=getDirectFieldReference()->getGrid() ; |
---|
[1984] | 695 | std::shared_ptr<COutputPin> lastFilter ; |
---|
| 696 | if (filterExpr) lastFilter=filterExpr ; |
---|
| 697 | else lastFilter = inputFilter ; |
---|
| 698 | CGrid* newGrid ; |
---|
| 699 | |
---|
[1869] | 700 | for(auto grid : gridPath) |
---|
| 701 | { |
---|
| 702 | grid->solveElementsRefInheritance() ; |
---|
[2144] | 703 | std::pair<std::shared_ptr<CFilter>, std::shared_ptr<CFilter> > filters = grid->buildTransformationGraph(gc, false, gridSrc, detectMissingValues, defaultValue, newGrid, buildGraph_, this) ; |
---|
[1984] | 704 | lastFilter->connectOutput(filters.first, 0); |
---|
| 705 | lastFilter = filters.second; |
---|
| 706 | gridSrc = newGrid ; |
---|
[1869] | 707 | } |
---|
[1984] | 708 | |
---|
| 709 | grid_=newGrid ; |
---|
| 710 | grid_ref=grid_->getId() ; // for server |
---|
[1869] | 711 | instantDataFilter = lastFilter ; |
---|
| 712 | |
---|
| 713 | // connect the input Filter to the reference |
---|
| 714 | getDirectFieldReference()->getInstantDataFilter()->connectOutput(inputFilter,0); |
---|
[2144] | 715 | if(buildGraph_) |
---|
| 716 | { |
---|
| 717 | inputFilter->graphEnabled=true; |
---|
| 718 | inputFilter->graphPackage = new CGraphPackage; |
---|
| 719 | inputFilter->graphPackage->inFields.push_back(this); |
---|
| 720 | inputFilter->label_field_id = getDirectFieldReference()->getId(); |
---|
| 721 | } |
---|
[1869] | 722 | } |
---|
| 723 | else |
---|
| 724 | { |
---|
[2172] | 725 | std::shared_ptr<COutputPin> lastFilter = inputFilter; |
---|
| 726 | if (hasExpression()) |
---|
| 727 | { |
---|
[2193] | 728 | if (filterExpr) |
---|
| 729 | { |
---|
| 730 | lastFilter=filterExpr ; |
---|
| 731 | } |
---|
[2172] | 732 | } |
---|
| 733 | |
---|
[1871] | 734 | if (hasFileIn()) // input file, attemp to read the grid from file |
---|
| 735 | { |
---|
| 736 | // must be checked |
---|
| 737 | fileIn_->initRead() ; |
---|
| 738 | fileIn_->checkReadFile(); |
---|
| 739 | grid_->solveElementsRefInheritance() ; |
---|
| 740 | if (fileIn_->isClientSide()) fileIn_->readFieldAttributesMetaData(this); |
---|
[1988] | 741 | CGrid* newGrid ; |
---|
[2144] | 742 | std::pair<std::shared_ptr<CFilter>, std::shared_ptr<CFilter> > filters = grid_->buildTransformationGraph(gc, true, nullptr, detectMissingValues, defaultValue, newGrid, buildGraph_, this) ; |
---|
[1988] | 743 | grid_ = newGrid ; |
---|
| 744 | grid_ref=grid_->getId() ; // for server |
---|
| 745 | //grid_->completeGrid(); // grid generation, to be checked |
---|
[1871] | 746 | if (fileIn_->isClientSide()) fileIn_->readFieldAttributesValues(this); |
---|
| 747 | grid_->checkElementsAttributes() ; |
---|
[1988] | 748 | // grid_->solveDomainAxisBaseRef(); |
---|
[1871] | 749 | // probably in future tag grid incomplete if coming from a reading |
---|
[2172] | 750 | instantDataFilter=lastFilter ; |
---|
[1871] | 751 | } |
---|
[1875] | 752 | else if (hasCouplerIn()) |
---|
[1871] | 753 | { |
---|
[1875] | 754 | grid_->checkElementsAttributes() ; |
---|
[2172] | 755 | instantDataFilter=lastFilter ; |
---|
[1875] | 756 | } |
---|
| 757 | else |
---|
| 758 | { |
---|
[1871] | 759 | setModelIn() ; // no reference, the field is potentially a source field from model |
---|
| 760 | |
---|
| 761 | grid_->solveElementsRefInheritance() ; |
---|
[1984] | 762 | CGrid* newGrid ; |
---|
[2144] | 763 | std::pair<std::shared_ptr<CFilter>, std::shared_ptr<CFilter> > filters = grid_->buildTransformationGraph(gc, true, nullptr, detectMissingValues, defaultValue, newGrid, buildGraph_, this) ; |
---|
[1999] | 764 | newGrid->duplicateAttributes(grid_) ; // for grid attributes (mask) |
---|
[1984] | 765 | grid_ = newGrid ; |
---|
| 766 | grid_ref=grid_->getId() ; // for server |
---|
[1871] | 767 | grid_->checkElementsAttributes() ; |
---|
[2172] | 768 | instantDataFilter=lastFilter ; |
---|
[1871] | 769 | } |
---|
[1869] | 770 | } |
---|
| 771 | |
---|
[1872] | 772 | if (hasFileOut()) |
---|
| 773 | { |
---|
| 774 | if (fileOut_->isServerSide()) |
---|
| 775 | { |
---|
| 776 | this->solveServerOperation() ; |
---|
| 777 | } |
---|
| 778 | } |
---|
| 779 | |
---|
[1869] | 780 | buildWorkflowGraphDone_ = true ; |
---|
| 781 | workflowEnabled_ = true ; |
---|
| 782 | return true ; |
---|
| 783 | } |
---|
| 784 | |
---|
[1870] | 785 | /*! |
---|
| 786 | * Connect field to filter to send data to server. A temporal filter is inserted before accordingly to the |
---|
| 787 | * output frequency of the file |
---|
| 788 | * \param gc the garbage collector to use when building the filter graph |
---|
| 789 | */ |
---|
[1869] | 790 | void CField::connectToFileServer(CGarbageCollector& gc) |
---|
| 791 | { |
---|
| 792 | // insert temporal filter before sending to files |
---|
[2507] | 793 | clientToServerStoreFilter_ = std::shared_ptr<CClientToServerStoreFilter>(new CClientToServerStoreFilter(gc, this, client_)); |
---|
[1869] | 794 | // insert temporal filter before sending to files |
---|
[1935] | 795 | getTemporalDataFilter(gc, fileOut_->output_freq)->connectOutput(clientToServerStoreFilter_, 0); |
---|
[2144] | 796 | const bool buildGraph_ = !build_workflow_graph.isEmpty() && build_workflow_graph == true ; |
---|
| 797 | if(buildGraph_) |
---|
| 798 | { |
---|
| 799 | clientToServerStoreFilter_->graphPackage = new CGraphPackage; |
---|
| 800 | clientToServerStoreFilter_->graphEnabled = true; |
---|
| 801 | clientToServerStoreFilter_->graphPackage->inFields.push_back(this); |
---|
| 802 | } |
---|
[1869] | 803 | } |
---|
| 804 | |
---|
[2507] | 805 | /* |
---|
| 806 | void CField::connectToOnlineWriter(CGarbageCollector& gc) |
---|
| 807 | { |
---|
| 808 | // insert temporal filter before sending to files |
---|
| 809 | CField* fieldOut ; |
---|
| 810 | redistributeFilter_ = std::shared_ptr<CGridRedistributeFilter>(new CGridRedistributeFilter(gc, this, fieldOut)); |
---|
| 811 | fieldOut->setFileOut(this->getFileOut()); |
---|
| 812 | fileOut_->replaceEnabledFields(this, fieldOut) ; |
---|
| 813 | // insert temporal filter before sending to files |
---|
| 814 | getTemporalDataFilter(gc, fileOut_->output_freq)->connectOutput(redistributeFilter_, 0); |
---|
| 815 | fieldOut->inputFilter = std::shared_ptr<CPassThroughFilter>(new CPassThroughFilter(gc)); |
---|
| 816 | fieldOut->instantDataFilter = fieldOut->inputFilter ; |
---|
| 817 | redistributeFilter_->connectOutput(fieldOut->inputFilter, 0); |
---|
| 818 | fieldOut->connectToFileWriter(gc) ; |
---|
| 819 | fieldOut->solveServerOperation() ; // might not be called, create a new time functor.... find a better solution later |
---|
| 820 | const bool buildGraph_ = !build_workflow_graph.isEmpty() && build_workflow_graph == true ; |
---|
| 821 | |
---|
| 822 | if(buildGraph_) |
---|
| 823 | { |
---|
| 824 | clientToServerStoreFilter_->graphPackage = new CGraphPackage; |
---|
| 825 | clientToServerStoreFilter_->graphEnabled = true; |
---|
| 826 | clientToServerStoreFilter_->graphPackage->inFields.push_back(this); |
---|
| 827 | } |
---|
| 828 | } |
---|
| 829 | */ |
---|
| 830 | void CField::connectToOnlineWriter(CGarbageCollector& gc) |
---|
| 831 | { |
---|
| 832 | // insert temporal filter before sending to files |
---|
| 833 | clientOnlineWriterFilter_ = std::shared_ptr<CClientOnlineWriterFilter>(new CClientOnlineWriterFilter(gc,this)) ; |
---|
[2544] | 834 | getTemporalDataFilter(gc, fileOut_->output_freq)->connectOutput(clientOnlineWriterFilter_, 0); |
---|
[2507] | 835 | |
---|
| 836 | const bool buildGraph_ = !build_workflow_graph.isEmpty() && build_workflow_graph == true ; |
---|
| 837 | |
---|
| 838 | if(buildGraph_) |
---|
| 839 | { |
---|
| 840 | // to do |
---|
| 841 | } |
---|
| 842 | } |
---|
| 843 | |
---|
| 844 | void CField::connectToOnlineReader(CGarbageCollector& gc) |
---|
| 845 | { |
---|
| 846 | // insert temporal filter before sending to files |
---|
[2544] | 847 | checkTimeAttributes(); |
---|
[2507] | 848 | clientOnlineReaderFilter_ = std::shared_ptr<CClientOnlineReaderFilter>(new CClientOnlineReaderFilter(gc,this)) ; |
---|
| 849 | clientOnlineReaderFilter_ -> connectOutput(inputFilter,0) ; |
---|
| 850 | } |
---|
| 851 | |
---|
[1875] | 852 | void CField::connectToCouplerOut(CGarbageCollector& gc) |
---|
| 853 | { |
---|
| 854 | // insert temporal filter before sending to files |
---|
[2507] | 855 | clientToServerStoreFilter_ = std::shared_ptr<CClientToServerStoreFilter>(new CClientToServerStoreFilter(gc, this, client_)); |
---|
[1935] | 856 | instantDataFilter->connectOutput(clientToServerStoreFilter_, 0); |
---|
[2144] | 857 | const bool buildGraph_ = !build_workflow_graph.isEmpty() && build_workflow_graph == true ; |
---|
| 858 | if(buildGraph_) |
---|
| 859 | { |
---|
| 860 | clientToServerStoreFilter_->graphPackage = new CGraphPackage; |
---|
| 861 | clientToServerStoreFilter_->graphEnabled = true; |
---|
| 862 | clientToServerStoreFilter_->graphPackage->inFields.push_back(this); |
---|
| 863 | } |
---|
[1875] | 864 | } |
---|
| 865 | |
---|
[1973] | 866 | |
---|
[1870] | 867 | /*! |
---|
| 868 | * Connect field to a source filter to receive data from model. |
---|
| 869 | */ |
---|
| 870 | void CField::connectToModelInput(CGarbageCollector& gc) |
---|
| 871 | { |
---|
| 872 | const bool detectMissingValues = (!detect_missing_value.isEmpty() && !default_value.isEmpty() && detect_missing_value == true); |
---|
| 873 | const double defaultValue = detectMissingValues ? default_value : (!default_value.isEmpty() ? default_value : 0.0); |
---|
| 874 | |
---|
| 875 | if (check_if_active.isEmpty()) check_if_active = false; |
---|
[1930] | 876 | modelToClientSourceFilter_ = std::shared_ptr<CModelToClientSourceFilter>(new CModelToClientSourceFilter(gc, grid_, detectMissingValues, defaultValue)); |
---|
| 877 | modelToClientSourceFilter_ -> connectOutput(inputFilter,0) ; |
---|
[2144] | 878 | const bool buildGraph_ = !build_workflow_graph.isEmpty() && build_workflow_graph == true ; |
---|
| 879 | if(buildGraph_ ) |
---|
| 880 | { |
---|
| 881 | modelToClientSourceFilter_->graphPackage = new CGraphPackage; |
---|
| 882 | modelToClientSourceFilter_->graphEnabled = true; |
---|
| 883 | modelToClientSourceFilter_->graphPackage->inFields.push_back(this); |
---|
| 884 | } |
---|
[1870] | 885 | } |
---|
| 886 | |
---|
| 887 | /*! |
---|
[1871] | 888 | * Connect field to a source filter to receive data from a client (on server side). |
---|
| 889 | */ |
---|
| 890 | void CField::connectToClientInput(CGarbageCollector& gc) |
---|
| 891 | { |
---|
[1930] | 892 | serverFromClientSourceFilter_ = std::shared_ptr<CServerFromClientSourceFilter>(new CServerFromClientSourceFilter(gc, grid_)); |
---|
| 893 | serverFromClientSourceFilter_ -> connectOutput(inputFilter,0) ; |
---|
[2144] | 894 | const bool buildGraph_ = !build_workflow_graph.isEmpty() && build_workflow_graph == true ; |
---|
| 895 | if(buildGraph_) |
---|
| 896 | { |
---|
| 897 | serverFromClientSourceFilter_->graphPackage = new CGraphPackage; |
---|
| 898 | serverFromClientSourceFilter_->graphEnabled = true; |
---|
| 899 | serverFromClientSourceFilter_->graphPackage->inFields.push_back(this); |
---|
| 900 | } |
---|
[1871] | 901 | } |
---|
| 902 | |
---|
| 903 | |
---|
| 904 | /*! |
---|
| 905 | * Connect field to a source filter to receive data from a server (on client side). |
---|
| 906 | */ |
---|
| 907 | void CField::connectToServerInput(CGarbageCollector& gc) |
---|
| 908 | { |
---|
[1872] | 909 | checkTimeAttributes(); |
---|
[1934] | 910 | clientFromServerSourceFilter_ = std::shared_ptr<CClientFromServerSourceFilter>(new CClientFromServerSourceFilter(gc,this)) ; |
---|
| 911 | clientFromServerSourceFilter_ -> connectOutput(inputFilter,0) ; |
---|
[2144] | 912 | const bool buildGraph_ = !build_workflow_graph.isEmpty() && build_workflow_graph == true ; |
---|
| 913 | if(buildGraph_) |
---|
| 914 | { |
---|
| 915 | clientFromServerSourceFilter_->graphPackage = new CGraphPackage; |
---|
| 916 | clientFromServerSourceFilter_->graphEnabled = true; |
---|
| 917 | clientFromServerSourceFilter_->graphPackage->inFields.push_back(this); |
---|
| 918 | } |
---|
[1871] | 919 | } |
---|
| 920 | |
---|
| 921 | /*! |
---|
[1875] | 922 | * Connect field to a source filter to receive data from coupler (on client side). |
---|
| 923 | */ |
---|
| 924 | void CField::connectToCouplerIn(CGarbageCollector& gc) |
---|
| 925 | { |
---|
| 926 | CContext* context = CContext::getCurrent(); |
---|
| 927 | |
---|
| 928 | if (freq_op.isEmpty()) freq_op.setValue(TimeStep); |
---|
| 929 | if (freq_offset.isEmpty()) freq_offset.setValue(freq_op.getValue() - TimeStep); |
---|
[1930] | 930 | clientFromClientSourceFilter_ = std::shared_ptr<CClientFromClientSourceFilter>(new CClientFromClientSourceFilter(gc, this)) ; |
---|
| 931 | clientFromClientSourceFilter_ -> connectOutput(inputFilter,0) ; |
---|
[2144] | 932 | const bool buildGraph_ = !build_workflow_graph.isEmpty() && build_workflow_graph == true ; |
---|
| 933 | if(buildGraph_) |
---|
| 934 | { |
---|
| 935 | clientFromClientSourceFilter_->graphPackage = new CGraphPackage; |
---|
| 936 | clientFromClientSourceFilter_->graphEnabled = true; |
---|
| 937 | clientFromClientSourceFilter_->graphPackage->inFields.push_back(this); |
---|
| 938 | } |
---|
[1875] | 939 | } |
---|
| 940 | |
---|
| 941 | /*! |
---|
[1871] | 942 | * Connect field to a file writer filter to write data in file (on server side). |
---|
| 943 | */ |
---|
| 944 | void CField::connectToFileWriter(CGarbageCollector& gc) |
---|
| 945 | { |
---|
[1935] | 946 | fileWriterStoreFilter_ = std::shared_ptr<CFileWriterStoreFilter>(new CFileWriterStoreFilter(gc, this)); |
---|
| 947 | instantDataFilter->connectOutput(fileWriterStoreFilter_, 0); |
---|
[2144] | 948 | const bool buildGraph_ = !build_workflow_graph.isEmpty() && build_workflow_graph == true ; |
---|
| 949 | if(buildGraph_) |
---|
| 950 | { |
---|
| 951 | fileWriterStoreFilter_->graphPackage = new CGraphPackage; |
---|
| 952 | fileWriterStoreFilter_->graphEnabled = true; |
---|
| 953 | fileWriterStoreFilter_->graphPackage->inFields.push_back(this); |
---|
| 954 | } |
---|
[1871] | 955 | } |
---|
[1930] | 956 | |
---|
[1883] | 957 | /*! |
---|
| 958 | * Connect field to a file reader filter to read data from file (on server side). |
---|
| 959 | */ |
---|
| 960 | void CField::connectToFileReader(CGarbageCollector& gc) |
---|
| 961 | { |
---|
[1930] | 962 | fileReaderSourceFilter_ = std::shared_ptr<CFileReaderSourceFilter>(new CFileReaderSourceFilter(gc, this)); |
---|
[1934] | 963 | fileReaderSourceFilter_->connectOutput(inputFilter, 0); |
---|
[2144] | 964 | const bool buildGraph_ = !build_workflow_graph.isEmpty() && build_workflow_graph == true ; |
---|
| 965 | if(buildGraph_) |
---|
| 966 | { |
---|
| 967 | fileReaderSourceFilter_->graphPackage = new CGraphPackage; |
---|
| 968 | fileReaderSourceFilter_->graphEnabled = true; |
---|
| 969 | fileReaderSourceFilter_->graphPackage->inFields.push_back(this); |
---|
| 970 | } |
---|
[1930] | 971 | } |
---|
[1871] | 972 | |
---|
[1930] | 973 | |
---|
[1871] | 974 | /*! |
---|
| 975 | * Connect field to a store filter to output data to model on client Side |
---|
| 976 | */ |
---|
| 977 | void CField::connectToModelOutput(CGarbageCollector& gc) |
---|
| 978 | { |
---|
[1930] | 979 | clientToModelStoreFilter_ = std::shared_ptr<CClientToModelStoreFilter>(new CClientToModelStoreFilter(gc, this)); |
---|
| 980 | instantDataFilter->connectOutput(clientToModelStoreFilter_, 0); |
---|
[2144] | 981 | const bool buildGraph_ = !build_workflow_graph.isEmpty() && build_workflow_graph == true ; |
---|
| 982 | if(buildGraph_) |
---|
| 983 | { |
---|
| 984 | clientToModelStoreFilter_->graphPackage = new CGraphPackage; |
---|
| 985 | clientToModelStoreFilter_->graphEnabled = true; |
---|
| 986 | clientToModelStoreFilter_->graphPackage->inFields.push_back(this); |
---|
| 987 | } |
---|
[1871] | 988 | } |
---|
| 989 | |
---|
[1883] | 990 | |
---|
| 991 | |
---|
| 992 | void CField::connectToServerToClient(CGarbageCollector& gc) |
---|
| 993 | { |
---|
[2507] | 994 | serverToClientStoreFilter_ = std::shared_ptr<CServerToClientStoreFilter>(new CServerToClientStoreFilter(gc, this, client_)); |
---|
[1934] | 995 | instantDataFilter->connectOutput(serverToClientStoreFilter_, 0); |
---|
[2144] | 996 | const bool buildGraph_ = !build_workflow_graph.isEmpty() && build_workflow_graph == true ; |
---|
| 997 | if(buildGraph_) |
---|
| 998 | { |
---|
| 999 | serverToClientStoreFilter_->graphPackage = new CGraphPackage; |
---|
| 1000 | serverToClientStoreFilter_->graphEnabled = true; |
---|
| 1001 | serverToClientStoreFilter_->graphPackage->inFields.push_back(this); |
---|
| 1002 | } |
---|
[1883] | 1003 | } |
---|
| 1004 | |
---|
[1871] | 1005 | /*! |
---|
[1869] | 1006 | * Transform the grid_path attribut into vector of grid. |
---|
| 1007 | * \return the vector CGrid* containing the list of grid path for tranformation |
---|
| 1008 | */ |
---|
| 1009 | vector<CGrid*> CField::getGridPath(void) |
---|
| 1010 | { |
---|
| 1011 | std::vector<CGrid*> gridPath; |
---|
| 1012 | |
---|
| 1013 | if (hasDirectFieldReference() && grid_ != getDirectFieldReference()->grid_) |
---|
| 1014 | { |
---|
| 1015 | if (!grid_path.isEmpty()) |
---|
| 1016 | { |
---|
| 1017 | std::string gridId; |
---|
| 1018 | size_t start = 0, end; |
---|
| 1019 | |
---|
| 1020 | do |
---|
| 1021 | { |
---|
| 1022 | end = grid_path.getValue().find(',', start); |
---|
| 1023 | if (end != std::string::npos) |
---|
| 1024 | { |
---|
| 1025 | gridId = grid_path.getValue().substr(start, end - start); |
---|
| 1026 | start = end + 1; |
---|
| 1027 | } |
---|
| 1028 | else gridId = grid_path.getValue().substr(start); |
---|
| 1029 | |
---|
| 1030 | if (!CGrid::has(gridId)) |
---|
| 1031 | ERROR("void CField::solveTransformedGrid()", |
---|
| 1032 | << "Invalid grid_path, the grid '" << gridId << "' does not exist."); |
---|
| 1033 | |
---|
| 1034 | gridPath.push_back(CGrid::get(gridId)); |
---|
| 1035 | } |
---|
| 1036 | while (end != std::string::npos); |
---|
| 1037 | } |
---|
| 1038 | } |
---|
| 1039 | return gridPath ; |
---|
| 1040 | } |
---|
| 1041 | |
---|
[2002] | 1042 | |
---|
| 1043 | |
---|
[1869] | 1044 | /*! |
---|
| 1045 | * Returns the filter needed to handle a self reference in the field's expression. |
---|
| 1046 | * If the needed filter does not exist, it is created, otherwise it is reused. |
---|
| 1047 | * This method should only be called when building the filter graph corresponding |
---|
| 1048 | * to the field's expression. |
---|
| 1049 | * |
---|
| 1050 | * \param gc the garbage collector to use |
---|
| 1051 | * \return the output pin corresponding to a self reference |
---|
| 1052 | */ |
---|
[642] | 1053 | |
---|
[1869] | 1054 | /* old version |
---|
| 1055 | std::shared_ptr<COutputPin> CField::getSelfReference(CGarbageCollector& gc) |
---|
| 1056 | TRY |
---|
| 1057 | { |
---|
| 1058 | if (instantDataFilter || !hasExpression()) |
---|
| 1059 | ERROR("COutputPin* CField::getSelfReference(CGarbageCollector& gc)", |
---|
| 1060 | "Impossible to add a self reference to a field which has already been parsed or which does not have an expression."); |
---|
[1201] | 1061 | |
---|
[1869] | 1062 | if (!selfReferenceFilter) |
---|
| 1063 | { |
---|
| 1064 | const bool detectMissingValues = (!detect_missing_value.isEmpty() && !default_value.isEmpty() && detect_missing_value == true); |
---|
| 1065 | const double defaultValue = detectMissingValues ? default_value : (!default_value.isEmpty() ? default_value : 0.0); |
---|
[1201] | 1066 | |
---|
[1869] | 1067 | if (file && !file->mode.isEmpty() && file->mode == CFile::mode_attr::read) |
---|
| 1068 | { |
---|
| 1069 | if (!serverSourceFilter) |
---|
| 1070 | { |
---|
| 1071 | checkTimeAttributes(); |
---|
| 1072 | serverSourceFilter = std::shared_ptr<CSourceFilter>(new CSourceFilter(gc, grid_, true, false, freq_offset, true, |
---|
| 1073 | detectMissingValues, defaultValue)); |
---|
[1158] | 1074 | } |
---|
[642] | 1075 | |
---|
[1869] | 1076 | selfReferenceFilter = serverSourceFilter; |
---|
| 1077 | } |
---|
| 1078 | else if (!field_ref.isEmpty()) |
---|
| 1079 | { |
---|
| 1080 | CField* fieldRef = CField::get(field_ref); |
---|
| 1081 | fieldRef->buildFilterGraph(gc, false); |
---|
| 1082 | selfReferenceFilter = fieldRef->getInstantDataFilter(); |
---|
| 1083 | } |
---|
| 1084 | else |
---|
| 1085 | { |
---|
| 1086 | if (!clientSourceFilter) |
---|
| 1087 | { |
---|
| 1088 | if (check_if_active.isEmpty()) check_if_active = false; |
---|
| 1089 | clientSourceFilter = std::shared_ptr<CSourceFilter>(new CSourceFilter(gc, grid_, true, true, NoneDu, false, |
---|
| 1090 | detectMissingValues, defaultValue)); |
---|
| 1091 | } |
---|
[737] | 1092 | |
---|
[1869] | 1093 | selfReferenceFilter = clientSourceFilter; |
---|
| 1094 | } |
---|
| 1095 | } |
---|
[642] | 1096 | |
---|
[1869] | 1097 | return selfReferenceFilter; |
---|
| 1098 | } |
---|
| 1099 | CATCH_DUMP_ATTR |
---|
| 1100 | */ |
---|
| 1101 | std::shared_ptr<COutputPin> CField::getSelfReference(CGarbageCollector& gc) |
---|
| 1102 | TRY |
---|
| 1103 | { |
---|
| 1104 | return inputFilter ; |
---|
| 1105 | } |
---|
| 1106 | CATCH_DUMP_ATTR |
---|
[643] | 1107 | |
---|
[1869] | 1108 | /*! |
---|
| 1109 | * Returns the temporal filter corresponding to the field's temporal operation |
---|
| 1110 | * for the specified operation frequency. The filter is created if it does not |
---|
| 1111 | * exist, otherwise it is reused. |
---|
| 1112 | * |
---|
| 1113 | * \param gc the garbage collector to use |
---|
| 1114 | * \param outFreq the operation frequency, i.e. the frequency at which the output data will be computed |
---|
| 1115 | * \return the output pin corresponding to the requested temporal filter |
---|
| 1116 | */ |
---|
| 1117 | std::shared_ptr<COutputPin> CField::getTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq) |
---|
| 1118 | TRY |
---|
| 1119 | { |
---|
| 1120 | std::map<CDuration, std::shared_ptr<COutputPin> >::iterator it = temporalDataFilters.find(outFreq); |
---|
[643] | 1121 | |
---|
[1869] | 1122 | if (it == temporalDataFilters.end()) |
---|
| 1123 | { |
---|
| 1124 | if (operation.isEmpty()) |
---|
| 1125 | ERROR("void CField::getTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq)", |
---|
| 1126 | << "An operation must be defined for field \"" << getId() << "\"."); |
---|
[1315] | 1127 | |
---|
[1869] | 1128 | checkTimeAttributes(&outFreq); |
---|
| 1129 | |
---|
| 1130 | const bool detectMissingValues = (!detect_missing_value.isEmpty() && detect_missing_value == true); |
---|
| 1131 | std::shared_ptr<CTemporalFilter> temporalFilter(new CTemporalFilter(gc, operation, |
---|
[643] | 1132 | CContext::getCurrent()->getCalendar()->getInitDate(), |
---|
[1440] | 1133 | freq_op, freq_offset, outFreq, detectMissingValues)); |
---|
[1278] | 1134 | |
---|
[1869] | 1135 | instantDataFilter->connectOutput(temporalFilter, 0); |
---|
[2144] | 1136 | const bool buildGraph_ = !build_workflow_graph.isEmpty() && build_workflow_graph == true ; |
---|
| 1137 | if(buildGraph_) |
---|
| 1138 | { |
---|
| 1139 | info(100)<<"=== Workflow Graph === field "<<this->getId()<<" calls a getTemporalDataFilter ============== "<<instantDataFilter << " _ "<<temporalFilter<<std::endl; |
---|
| 1140 | temporalFilter->graphPackage = new CGraphPackage; |
---|
| 1141 | temporalFilter->graphEnabled = true; |
---|
| 1142 | temporalFilter->graphPackage->inFields.push_back(this); |
---|
| 1143 | } |
---|
[643] | 1144 | |
---|
[1869] | 1145 | it = temporalDataFilters.insert(std::make_pair(outFreq, temporalFilter)).first; |
---|
| 1146 | } |
---|
[643] | 1147 | |
---|
[1869] | 1148 | return it->second; |
---|
| 1149 | } |
---|
| 1150 | CATCH_DUMP_ATTR |
---|
[643] | 1151 | |
---|
[1158] | 1152 | /*! |
---|
| 1153 | * Returns the temporal filter corresponding to the field's temporal operation |
---|
| 1154 | * for the specified operation frequency. |
---|
| 1155 | * |
---|
| 1156 | * \param gc the garbage collector to use |
---|
| 1157 | * \param outFreq the operation frequency, i.e. the frequency at which the output data will be computed |
---|
| 1158 | * \return the output pin corresponding to the requested temporal filter |
---|
| 1159 | */ |
---|
| 1160 | |
---|
[1869] | 1161 | std::shared_ptr<COutputPin> CField::getSelfTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq) |
---|
| 1162 | TRY |
---|
| 1163 | { |
---|
| 1164 | if (instantDataFilter || !hasExpression()) |
---|
| 1165 | ERROR("COutputPin* CField::getSelfTemporalDataFilter(CGarbageCollector& gc)", |
---|
| 1166 | "Impossible to add a self reference to a field which has already been parsed or which does not have an expression."); |
---|
| 1167 | |
---|
| 1168 | if (selfTemporalDataFilter) return selfTemporalDataFilter; |
---|
[1158] | 1169 | |
---|
[1869] | 1170 | if (hasDirectFieldReference()) |
---|
| 1171 | { |
---|
| 1172 | CField* fieldRef=getDirectFieldReference(); |
---|
| 1173 | return fieldRef->getTemporalDataFilter(gc, outFreq) ; |
---|
| 1174 | } |
---|
| 1175 | else |
---|
| 1176 | { |
---|
| 1177 | if (selfTemporalDataFilter) return selfTemporalDataFilter ; |
---|
[1158] | 1178 | |
---|
[1869] | 1179 | if (operation.isEmpty()) |
---|
| 1180 | ERROR("void CField::getSelfTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq)", |
---|
| 1181 | << "An operation must be defined for field \"" << getId() << "\"."); |
---|
[1315] | 1182 | |
---|
[1869] | 1183 | checkTimeAttributes(&outFreq); //bof |
---|
[1278] | 1184 | |
---|
[1869] | 1185 | const bool detectMissingValues = (!detect_missing_value.isEmpty() && detect_missing_value == true); |
---|
| 1186 | selfTemporalDataFilter = std::shared_ptr<CTemporalFilter>(new CTemporalFilter(gc, operation, |
---|
| 1187 | CContext::getCurrent()->getCalendar()->getInitDate(), |
---|
| 1188 | freq_op, freq_offset, outFreq, detectMissingValues)); |
---|
| 1189 | |
---|
| 1190 | inputFilter->connectOutput(selfTemporalDataFilter, 0); |
---|
[2144] | 1191 | const bool buildGraph_ = !build_workflow_graph.isEmpty() && build_workflow_graph == true ; |
---|
| 1192 | if(buildGraph_) |
---|
| 1193 | { |
---|
| 1194 | info(100)<<"=== Workflow Graph === field "<<this->getId()<<" calls a getSelfTemporalDataFilter ============== "<<inputFilter << " _ "<<selfTemporalDataFilter<<std::endl; |
---|
| 1195 | selfTemporalDataFilter->graphPackage = new CGraphPackage; |
---|
| 1196 | selfTemporalDataFilter->graphEnabled = true; |
---|
| 1197 | selfTemporalDataFilter->graphPackage->inFields.push_back(this); |
---|
| 1198 | } |
---|
[1869] | 1199 | return selfTemporalDataFilter ; |
---|
| 1200 | } |
---|
[1158] | 1201 | } |
---|
[1869] | 1202 | CATCH_DUMP_ATTR |
---|
[1158] | 1203 | |
---|
[1869] | 1204 | /* old version |
---|
| 1205 | std::shared_ptr<COutputPin> CField::getSelfTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq) |
---|
| 1206 | TRY |
---|
| 1207 | { |
---|
| 1208 | if (instantDataFilter || !hasExpression()) |
---|
| 1209 | ERROR("COutputPin* CField::getSelfTemporalDataFilter(CGarbageCollector& gc)", |
---|
| 1210 | "Impossible to add a self reference to a field which has already been parsed or which does not have an expression."); |
---|
| 1211 | |
---|
| 1212 | if (!selfReferenceFilter) getSelfReference(gc) ; |
---|
| 1213 | |
---|
| 1214 | if (serverSourceFilter || clientSourceFilter) |
---|
| 1215 | { |
---|
| 1216 | if (operation.isEmpty()) |
---|
| 1217 | ERROR("void CField::getSelfTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq)", |
---|
| 1218 | << "An operation must be defined for field \"" << getId() << "\"."); |
---|
| 1219 | |
---|
| 1220 | checkTimeAttributes(&outFreq); |
---|
| 1221 | |
---|
| 1222 | const bool detectMissingValues = (!detect_missing_value.isEmpty() && detect_missing_value == true); |
---|
| 1223 | std::shared_ptr<CTemporalFilter> temporalFilter(new CTemporalFilter(gc, operation, |
---|
| 1224 | CContext::getCurrent()->getCalendar()->getInitDate(), |
---|
| 1225 | freq_op, freq_offset, outFreq, detectMissingValues)); |
---|
| 1226 | |
---|
| 1227 | selfReferenceFilter->connectOutput(temporalFilter, 0); |
---|
| 1228 | return temporalFilter ; |
---|
| 1229 | } |
---|
| 1230 | else if (!field_ref.isEmpty()) |
---|
| 1231 | { |
---|
| 1232 | CField* fieldRef = CField::get(field_ref); |
---|
| 1233 | fieldRef->buildFilterGraph(gc, false); |
---|
| 1234 | return fieldRef->getTemporalDataFilter(gc, outFreq) ; |
---|
| 1235 | } |
---|
| 1236 | } |
---|
| 1237 | CATCH_DUMP_ATTR |
---|
| 1238 | */ |
---|
| 1239 | |
---|
| 1240 | //---------------------------------------------------------------- |
---|
[369] | 1241 | /* |
---|
[562] | 1242 | void CField::fromBinary(StdIStream& is) |
---|
[219] | 1243 | { |
---|
| 1244 | SuperClass::fromBinary(is); |
---|
| 1245 | #define CLEAR_ATT(name_)\ |
---|
[369] | 1246 | SuperClassAttribute::operator[](#name_)->reset() |
---|
[219] | 1247 | |
---|
| 1248 | CLEAR_ATT(domain_ref); |
---|
| 1249 | CLEAR_ATT(axis_ref); |
---|
| 1250 | #undef CLEAR_ATT |
---|
| 1251 | |
---|
| 1252 | } |
---|
[369] | 1253 | */ |
---|
[219] | 1254 | //---------------------------------------------------------------- |
---|
| 1255 | |
---|
[1869] | 1256 | void CField::solveGridReference(void) |
---|
| 1257 | TRY |
---|
| 1258 | { |
---|
| 1259 | if (grid_!=nullptr) return ; // already done |
---|
[219] | 1260 | |
---|
[1869] | 1261 | if (grid_ref.isEmpty() && domain_ref.isEmpty() && axis_ref.isEmpty() && scalar_ref.isEmpty()) |
---|
| 1262 | { |
---|
| 1263 | ERROR("CField::solveGridReference(void)", |
---|
| 1264 | << "A grid must be defined for field '" << getFieldOutputName() << "' ."); |
---|
| 1265 | } |
---|
| 1266 | else if (!grid_ref.isEmpty() && (!domain_ref.isEmpty() || !axis_ref.isEmpty() || !scalar_ref.isEmpty())) |
---|
| 1267 | { |
---|
| 1268 | ERROR("CField::solveGridReference(void)", |
---|
| 1269 | << "Field '" << getFieldOutputName() << "' has both a grid and a domain/axis/scalar." << std::endl |
---|
| 1270 | << "Please define either 'grid_ref' or 'domain_ref'/'axis_ref'/'scalar_ref'."); |
---|
| 1271 | } |
---|
[1524] | 1272 | |
---|
[1869] | 1273 | if (grid_ref.isEmpty()) |
---|
| 1274 | { |
---|
| 1275 | std::vector<CDomain*> vecDom; |
---|
| 1276 | std::vector<CAxis*> vecAxis; |
---|
| 1277 | std::vector<CScalar*> vecScalar; |
---|
| 1278 | std::vector<int> axisDomainOrderTmp; |
---|
[1524] | 1279 | |
---|
[1869] | 1280 | std::vector<CDomain*> vecDomRef; |
---|
| 1281 | std::vector<CAxis*> vecAxisRef; |
---|
| 1282 | std::vector<CScalar*> vecScalarRef; |
---|
[894] | 1283 | |
---|
[1869] | 1284 | if (!domain_ref.isEmpty()) |
---|
| 1285 | { |
---|
[2206] | 1286 | CField* field=CDomain::getFieldFromId(domain_ref) ; |
---|
| 1287 | if (field!=nullptr) field->solveGridReference() ; |
---|
[1869] | 1288 | if (CDomain::has(domain_ref)) |
---|
[744] | 1289 | { |
---|
[1869] | 1290 | vecDom.push_back(CDomain::get(domain_ref)); |
---|
| 1291 | vecDomRef.push_back(CDomain::createDomain()); |
---|
| 1292 | vecDomRef.back()->domain_ref=domain_ref; |
---|
| 1293 | axisDomainOrderTmp.push_back(2); |
---|
[744] | 1294 | } |
---|
[1869] | 1295 | else ERROR("CField::solveGridReference(void)", |
---|
| 1296 | << "Invalid reference to domain '" << domain_ref.getValue() << "'."); |
---|
| 1297 | } |
---|
[219] | 1298 | |
---|
[1869] | 1299 | if (!axis_ref.isEmpty()) |
---|
| 1300 | { |
---|
[2206] | 1301 | CField* field=CAxis::getFieldFromId(axis_ref) ; |
---|
| 1302 | if (field!=nullptr) field->solveGridReference() ; |
---|
[1869] | 1303 | if (CAxis::has(axis_ref)) |
---|
[742] | 1304 | { |
---|
[1869] | 1305 | vecAxis.push_back(CAxis::get(axis_ref)); |
---|
| 1306 | vecAxisRef.push_back(CAxis::createAxis()); |
---|
| 1307 | vecAxisRef.back()->axis_ref=axis_ref; |
---|
| 1308 | axisDomainOrderTmp.push_back(1); |
---|
[742] | 1309 | } |
---|
[1869] | 1310 | else ERROR("CField::solveGridReference(void)", |
---|
| 1311 | << "Invalid reference to axis '" << axis_ref.getValue() << "'."); |
---|
| 1312 | } |
---|
[744] | 1313 | |
---|
[1869] | 1314 | if (!scalar_ref.isEmpty()) |
---|
| 1315 | { |
---|
[2206] | 1316 | CField* field=CScalar::getFieldFromId(scalar_ref) ; |
---|
| 1317 | if (field!=nullptr) field->solveGridReference() ; |
---|
[1869] | 1318 | if (CScalar::has(scalar_ref)) |
---|
[887] | 1319 | { |
---|
[1869] | 1320 | vecScalar.push_back(CScalar::get(scalar_ref)); |
---|
| 1321 | vecScalarRef.push_back(CScalar::createScalar()); |
---|
| 1322 | vecScalarRef.back()->scalar_ref=scalar_ref; |
---|
| 1323 | axisDomainOrderTmp.push_back(0); |
---|
[887] | 1324 | } |
---|
[1869] | 1325 | else ERROR("CField::solveGridReference(void)", |
---|
| 1326 | << "Invalid reference to scalar '" << scalar_ref.getValue() << "'."); |
---|
| 1327 | } |
---|
[894] | 1328 | |
---|
[1869] | 1329 | CArray<int,1> axisDomainOrder(axisDomainOrderTmp.size()); |
---|
| 1330 | for (int idx = 0; idx < axisDomainOrderTmp.size(); ++idx) |
---|
[586] | 1331 | { |
---|
[1869] | 1332 | axisDomainOrder(idx) = axisDomainOrderTmp[idx]; |
---|
[586] | 1333 | } |
---|
[459] | 1334 | |
---|
[1869] | 1335 | // Warning: the gridId shouldn't be set as the grid_ref since it could be inherited |
---|
| 1336 | StdString gridId = CGrid::generateId(vecDom, vecAxis, vecScalar,axisDomainOrder); |
---|
| 1337 | if (CGrid::has(gridId)) this->grid_ = CGrid::get(gridId); |
---|
| 1338 | else this->grid_ = CGrid::createGrid(gridId, vecDomRef, vecAxisRef, vecScalarRef,axisDomainOrder); |
---|
| 1339 | } |
---|
| 1340 | else |
---|
| 1341 | { |
---|
[2315] | 1342 | CField* field=CGrid::getFieldFromId(grid_ref) ; |
---|
| 1343 | if (field!=nullptr) field->solveGridReference() ; |
---|
[1869] | 1344 | if (CGrid::has(grid_ref)) this->grid_ = CGrid::get(grid_ref); |
---|
| 1345 | else ERROR("CField::solveGridReference(void)", |
---|
| 1346 | << "Invalid reference to grid '" << grid_ref.getValue() << "'."); |
---|
| 1347 | } |
---|
| 1348 | } |
---|
| 1349 | CATCH_DUMP_ATTR |
---|
[219] | 1350 | |
---|
[1869] | 1351 | void CField::solveGridDomainAxisRef(bool checkAtt) |
---|
| 1352 | TRY |
---|
| 1353 | { |
---|
| 1354 | grid_->solveDomainAxisRef(checkAtt); |
---|
| 1355 | } |
---|
| 1356 | CATCH_DUMP_ATTR |
---|
[219] | 1357 | |
---|
[1869] | 1358 | void CField::solveCheckMaskIndex(bool doSendingIndex) |
---|
| 1359 | TRY |
---|
| 1360 | { |
---|
| 1361 | grid_->checkMaskIndex(doSendingIndex); |
---|
| 1362 | } |
---|
| 1363 | CATCH_DUMP_ATTR |
---|
[790] | 1364 | |
---|
[2002] | 1365 | |
---|
[1869] | 1366 | void CField::solveGridDomainAxisBaseRef() |
---|
| 1367 | TRY |
---|
| 1368 | { |
---|
| 1369 | grid_->solveDomainAxisRef(false); |
---|
| 1370 | grid_->solveDomainAxisBaseRef(); |
---|
| 1371 | } |
---|
| 1372 | CATCH_DUMP_ATTR |
---|
[619] | 1373 | |
---|
[1869] | 1374 | ///------------------------------------------------------------------- |
---|
[687] | 1375 | |
---|
[1869] | 1376 | template <> |
---|
| 1377 | void CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void) |
---|
| 1378 | TRY |
---|
| 1379 | { |
---|
| 1380 | if (this->group_ref.isEmpty()) return; |
---|
| 1381 | StdString gref = this->group_ref.getValue(); |
---|
[775] | 1382 | |
---|
[1869] | 1383 | if (!CFieldGroup::has(gref)) |
---|
| 1384 | ERROR("CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void)", |
---|
| 1385 | << "[ gref = " << gref << "]" |
---|
| 1386 | << " invalid group name !"); |
---|
[219] | 1387 | |
---|
[1869] | 1388 | CFieldGroup* group = CFieldGroup::get(gref); |
---|
| 1389 | CFieldGroup* owner = CFieldGroup::get(boost::polymorphic_downcast<CFieldGroup*>(this)); |
---|
| 1390 | owner->setAttributes(group); // inherite of attributes of group reference |
---|
| 1391 | |
---|
| 1392 | std::vector<CField*> allChildren = group->getAllChildren(); |
---|
| 1393 | std::vector<CField*>::iterator it = allChildren.begin(), end = allChildren.end(); |
---|
[219] | 1394 | |
---|
[1869] | 1395 | for (; it != end; it++) |
---|
| 1396 | { |
---|
| 1397 | CField* child = *it; |
---|
| 1398 | if (child->hasId()) owner->createChild()->field_ref.setValue(child->getId()); |
---|
| 1399 | } |
---|
| 1400 | } |
---|
| 1401 | CATCH_DUMP_ATTR |
---|
[219] | 1402 | |
---|
[1869] | 1403 | ///------------------------------------------------------------------- |
---|
| 1404 | |
---|
| 1405 | void CField::parse(xml::CXMLNode& node) |
---|
| 1406 | TRY |
---|
| 1407 | { |
---|
| 1408 | string newContent ; |
---|
| 1409 | SuperClass::parse(node); |
---|
| 1410 | if (node.goToChildElement()) |
---|
| 1411 | { |
---|
| 1412 | do |
---|
[1129] | 1413 | { |
---|
[1869] | 1414 | if (node.getElementName() == "variable" || node.getElementName() == "variable_group") this->getVirtualVariableGroup()->parseChild(node); |
---|
| 1415 | else if (node.getElementName() == "expr") if (node.getContent(newContent)) content+=newContent ; |
---|
| 1416 | } while (node.goToNextElement()); |
---|
| 1417 | node.goToParentElement(); |
---|
| 1418 | } |
---|
| 1419 | if (node.getContent(newContent)) content=newContent ; |
---|
| 1420 | } |
---|
| 1421 | CATCH_DUMP_ATTR |
---|
[1129] | 1422 | |
---|
[1869] | 1423 | /*! |
---|
| 1424 | This function retrieves Id of corresponding domain_ref and axis_ref (if any) |
---|
| 1425 | of a field. In some cases, only domain exists but axis doesn't |
---|
| 1426 | \return pair of Domain and Axis id |
---|
| 1427 | */ |
---|
| 1428 | const std::vector<StdString>& CField::getRefDomainAxisIds() |
---|
| 1429 | TRY |
---|
| 1430 | { |
---|
| 1431 | CGrid* cgPtr = getRelGrid(); |
---|
| 1432 | if (NULL != cgPtr) |
---|
| 1433 | { |
---|
| 1434 | std::vector<StdString>::iterator it; |
---|
| 1435 | if (!domain_ref.isEmpty()) |
---|
[599] | 1436 | { |
---|
[1869] | 1437 | std::vector<StdString> domainList = cgPtr->getDomainList(); |
---|
| 1438 | it = std::find(domainList.begin(), domainList.end(), domain_ref.getValue()); |
---|
| 1439 | if (domainList.end() != it) domAxisScalarIds_[0] = *it; |
---|
[599] | 1440 | } |
---|
| 1441 | |
---|
[1869] | 1442 | if (!axis_ref.isEmpty()) |
---|
[676] | 1443 | { |
---|
[1869] | 1444 | std::vector<StdString> axisList = cgPtr->getAxisList(); |
---|
| 1445 | it = std::find(axisList.begin(), axisList.end(), axis_ref.getValue()); |
---|
| 1446 | if (axisList.end() != it) domAxisScalarIds_[1] = *it; |
---|
[676] | 1447 | } |
---|
| 1448 | |
---|
[1869] | 1449 | if (!scalar_ref.isEmpty()) |
---|
[472] | 1450 | { |
---|
[1869] | 1451 | std::vector<StdString> scalarList = cgPtr->getScalarList(); |
---|
| 1452 | it = std::find(scalarList.begin(), scalarList.end(), scalar_ref.getValue()); |
---|
| 1453 | if (scalarList.end() != it) domAxisScalarIds_[2] = *it; |
---|
[472] | 1454 | } |
---|
[459] | 1455 | } |
---|
[1869] | 1456 | return (domAxisScalarIds_); |
---|
| 1457 | } |
---|
| 1458 | CATCH_DUMP_ATTR |
---|
[509] | 1459 | |
---|
[1869] | 1460 | CVariable* CField::addVariable(const string& id) |
---|
| 1461 | TRY |
---|
| 1462 | { |
---|
| 1463 | return vVariableGroup->createChild(id); |
---|
| 1464 | } |
---|
| 1465 | CATCH |
---|
[472] | 1466 | |
---|
[1869] | 1467 | CVariableGroup* CField::addVariableGroup(const string& id) |
---|
| 1468 | TRY |
---|
| 1469 | { |
---|
| 1470 | return vVariableGroup->createChildGroup(id); |
---|
| 1471 | } |
---|
| 1472 | CATCH |
---|
[887] | 1473 | |
---|
[1869] | 1474 | void CField::setContextClient(CContextClient* contextClient) |
---|
| 1475 | TRY |
---|
| 1476 | { |
---|
| 1477 | CContext* context = CContext::getCurrent(); |
---|
[2507] | 1478 | client_ = contextClient; |
---|
[1853] | 1479 | |
---|
[1869] | 1480 | // A grid is sent by a client (both for read or write) or by primary server (write only) |
---|
| 1481 | if (context->getServiceType()==CServicesManager::GATHERER) |
---|
| 1482 | { |
---|
[1872] | 1483 | if (getRelFile()->mode.isEmpty() || (!getRelFile()->mode.isEmpty() && getRelFile()->mode == CFile::mode_attr::write)) |
---|
[2507] | 1484 | /*grid_->setContextClient(contextClient) */; // => nothing to do with thats now, to remove... |
---|
[1869] | 1485 | } |
---|
| 1486 | else if (context->getServiceType()==CServicesManager::CLIENT) |
---|
[2302] | 1487 | { |
---|
| 1488 | if (grid_) |
---|
[2507] | 1489 | /*grid_->setContextClient(contextClient)*/; // => nothing to do with thats now, to remove... |
---|
[2302] | 1490 | else |
---|
[2507] | 1491 | |
---|
[2302] | 1492 | ERROR( "CField::setContextClient(contextClient)", |
---|
| 1493 | << "Grid not defined for " << getId() |
---|
| 1494 | << " (if field is an input field, set read_access to true)" |
---|
| 1495 | ); |
---|
| 1496 | } |
---|
[1869] | 1497 | } |
---|
| 1498 | CATCH_DUMP_ATTR |
---|
[1294] | 1499 | |
---|
| 1500 | |
---|
[1870] | 1501 | void CField::sendFieldToFileServer(void) |
---|
| 1502 | { |
---|
[2507] | 1503 | CContext::getCurrent()->sendContextToFileServer(client_); |
---|
| 1504 | getRelFile()->sendFileToFileServer(client_); |
---|
[1984] | 1505 | sentGrid_ = grid_-> duplicateSentGrid() ; |
---|
[2507] | 1506 | sentGrid_->sendGridToFileServer(client_, false); |
---|
[1984] | 1507 | name = getFieldOutputName() ; |
---|
[2507] | 1508 | this->sendAllAttributesToServer(client_); |
---|
| 1509 | this->sendAddAllVariables(client_); |
---|
[1870] | 1510 | } |
---|
[1875] | 1511 | |
---|
[1934] | 1512 | void CField::sendFieldToInputFileServer(void) |
---|
| 1513 | { |
---|
[2507] | 1514 | CContext::getCurrent()->sendContextToFileServer(client_); |
---|
| 1515 | getRelFile()->sendFileToFileServer(client_); |
---|
[1988] | 1516 | sentGrid_ = grid_-> duplicateSentGrid() ; |
---|
[2507] | 1517 | sentGrid_->sendGridToFileServer(client_, true); |
---|
[1934] | 1518 | read_access=true ; // not the best solution, but on server side, the field must be a starting point of the workflow |
---|
| 1519 | // must be replace by a better solution when implementing filters for reading and send to client |
---|
| 1520 | // on server side |
---|
[2507] | 1521 | this->sendAllAttributesToServer(client_); |
---|
| 1522 | this->sendAddAllVariables(client_); |
---|
[1934] | 1523 | } |
---|
| 1524 | |
---|
[1875] | 1525 | void CField::sendFieldToCouplerOut(void) |
---|
| 1526 | { |
---|
| 1527 | if (sendFieldToCouplerOut_done_) return ; |
---|
| 1528 | else sendFieldToCouplerOut_done_=true ; |
---|
[2022] | 1529 | sentGrid_ = grid_-> duplicateSentGrid() ; |
---|
[2507] | 1530 | sentGrid_->sendGridToCouplerOut(client_, this->getId()); |
---|
[1875] | 1531 | this->sendGridCompleted(); |
---|
| 1532 | |
---|
| 1533 | } |
---|
[1872] | 1534 | |
---|
[1875] | 1535 | void CField::makeGridAliasForCoupling(void) |
---|
| 1536 | { |
---|
| 1537 | grid_->makeAliasForCoupling(this->getId()); |
---|
| 1538 | } |
---|
| 1539 | |
---|
| 1540 | //! Client side: Send a message announcing that the grid definition has been received from a coupling context |
---|
| 1541 | void CField::sendGridCompleted(void) |
---|
| 1542 | TRY |
---|
| 1543 | { |
---|
| 1544 | CEventClient event(getType(),EVENT_ID_GRID_COMPLETED); |
---|
| 1545 | |
---|
[2507] | 1546 | if (client_->isServerLeader()) |
---|
[1875] | 1547 | { |
---|
| 1548 | CMessage msg; |
---|
| 1549 | msg<<this->getId(); |
---|
[2507] | 1550 | for (auto& rank : client_->getRanksServerLeader()) event.push(rank,1,msg); |
---|
| 1551 | client_->sendEvent(event); |
---|
[1875] | 1552 | } |
---|
[2507] | 1553 | else client_->sendEvent(event); |
---|
[1875] | 1554 | } |
---|
| 1555 | CATCH_DUMP_ATTR |
---|
| 1556 | |
---|
| 1557 | //! Server side: Receive a message announcing that the grid definition has been received from a coupling context |
---|
| 1558 | void CField::recvGridCompleted(CEventServer& event) |
---|
| 1559 | TRY |
---|
| 1560 | { |
---|
| 1561 | CBufferIn* buffer=event.subEvents.begin()->buffer; |
---|
| 1562 | string id; |
---|
| 1563 | *buffer>>id ; |
---|
| 1564 | get(id)->recvGridCompleted(*buffer); |
---|
| 1565 | } |
---|
| 1566 | CATCH |
---|
| 1567 | |
---|
| 1568 | //! Server side: Receive a message message announcing that the grid definition has been received from a coupling context |
---|
| 1569 | void CField::recvGridCompleted(CBufferIn& buffer) |
---|
| 1570 | TRY |
---|
| 1571 | { |
---|
| 1572 | setGridCompleted() ; |
---|
| 1573 | } |
---|
| 1574 | CATCH_DUMP_ATTR |
---|
| 1575 | |
---|
[2022] | 1576 | bool CField::isGridCompleted(void) |
---|
| 1577 | TRY |
---|
| 1578 | { |
---|
| 1579 | bool isFullCompleted ; |
---|
| 1580 | MPI_Allreduce(&isGridCompleted_,&isFullCompleted,1,MPI_C_BOOL, MPI_LAND, CContext::getCurrent()->getIntraComm() ) ; |
---|
| 1581 | if ( (isGridCompleted_==false && isFullCompleted==true) ) ERROR("bool CField::isGridCompleted(void)",<< "incoherecy in MPI_AllReduce") ; |
---|
| 1582 | return isFullCompleted ; |
---|
| 1583 | } |
---|
| 1584 | CATCH_DUMP_ATTR |
---|
[1875] | 1585 | |
---|
[1869] | 1586 | void CField::sendAddAllVariables(CContextClient* client) |
---|
| 1587 | TRY |
---|
| 1588 | { |
---|
| 1589 | std::vector<CVariable*> allVar = getAllVariables(); |
---|
| 1590 | std::vector<CVariable*>::const_iterator it = allVar.begin(); |
---|
| 1591 | std::vector<CVariable*>::const_iterator itE = allVar.end(); |
---|
[1009] | 1592 | |
---|
[1869] | 1593 | for (; it != itE; ++it) |
---|
| 1594 | { |
---|
| 1595 | this->sendAddVariable((*it)->getId(), client); |
---|
| 1596 | (*it)->sendAllAttributesToServer(client); |
---|
| 1597 | (*it)->sendValue(client); |
---|
| 1598 | } |
---|
| 1599 | } |
---|
| 1600 | CATCH_DUMP_ATTR |
---|
[1009] | 1601 | |
---|
[1869] | 1602 | /*! |
---|
| 1603 | * Send all Attributes to server. This method is overloaded, since only grid_ref attribute |
---|
| 1604 | * must be sent to server and not domain_ref/axis_ref/scalar_ref. |
---|
| 1605 | */ |
---|
[1524] | 1606 | |
---|
[1869] | 1607 | void CField::sendAllAttributesToServer(CContextClient* client) |
---|
| 1608 | TRY |
---|
| 1609 | { |
---|
| 1610 | if (grid_ref.isEmpty()) |
---|
| 1611 | { |
---|
[1984] | 1612 | grid_ref=sentGrid_->getId() ; |
---|
[1869] | 1613 | SuperClass::sendAllAttributesToServer(client) ; |
---|
[1870] | 1614 | domain_ref.reset() ; |
---|
| 1615 | axis_ref.reset() ; |
---|
| 1616 | scalar_ref.reset() ; |
---|
[1869] | 1617 | grid_ref.reset(); |
---|
| 1618 | } |
---|
[1984] | 1619 | else |
---|
| 1620 | { |
---|
| 1621 | string tmp = grid_ref; |
---|
| 1622 | grid_ref = sentGrid_->getId() ; |
---|
| 1623 | SuperClass::sendAllAttributesToServer(client) ; |
---|
| 1624 | grid_ref = tmp ; |
---|
| 1625 | } |
---|
[1869] | 1626 | } |
---|
| 1627 | CATCH_DUMP_ATTR |
---|
[1524] | 1628 | |
---|
[1869] | 1629 | void CField::sendAddVariable(const string& id, CContextClient* client) |
---|
| 1630 | TRY |
---|
| 1631 | { |
---|
| 1632 | sendAddItem(id, (int)EVENT_ID_ADD_VARIABLE, client); |
---|
| 1633 | } |
---|
| 1634 | CATCH_DUMP_ATTR |
---|
[1021] | 1635 | |
---|
[1869] | 1636 | void CField::sendAddVariableGroup(const string& id, CContextClient* client) |
---|
| 1637 | TRY |
---|
| 1638 | { |
---|
| 1639 | sendAddItem(id, (int)EVENT_ID_ADD_VARIABLE_GROUP, client); |
---|
| 1640 | } |
---|
| 1641 | CATCH_DUMP_ATTR |
---|
[509] | 1642 | |
---|
[1869] | 1643 | void CField::recvAddVariable(CEventServer& event) |
---|
| 1644 | TRY |
---|
| 1645 | { |
---|
| 1646 | CBufferIn* buffer = event.subEvents.begin()->buffer; |
---|
| 1647 | string id; |
---|
| 1648 | *buffer >> id; |
---|
| 1649 | get(id)->recvAddVariable(*buffer); |
---|
| 1650 | } |
---|
| 1651 | CATCH |
---|
[509] | 1652 | |
---|
[1869] | 1653 | void CField::recvAddVariable(CBufferIn& buffer) |
---|
| 1654 | TRY |
---|
| 1655 | { |
---|
| 1656 | string id; |
---|
| 1657 | buffer >> id; |
---|
| 1658 | addVariable(id); |
---|
| 1659 | } |
---|
| 1660 | CATCH_DUMP_ATTR |
---|
[509] | 1661 | |
---|
[1869] | 1662 | void CField::recvAddVariableGroup(CEventServer& event) |
---|
| 1663 | TRY |
---|
| 1664 | { |
---|
| 1665 | CBufferIn* buffer = event.subEvents.begin()->buffer; |
---|
| 1666 | string id; |
---|
| 1667 | *buffer >> id; |
---|
| 1668 | get(id)->recvAddVariableGroup(*buffer); |
---|
| 1669 | } |
---|
| 1670 | CATCH |
---|
[472] | 1671 | |
---|
[1869] | 1672 | void CField::recvAddVariableGroup(CBufferIn& buffer) |
---|
| 1673 | TRY |
---|
| 1674 | { |
---|
| 1675 | string id; |
---|
| 1676 | buffer >> id; |
---|
| 1677 | addVariableGroup(id); |
---|
| 1678 | } |
---|
| 1679 | CATCH_DUMP_ATTR |
---|
[509] | 1680 | |
---|
[1869] | 1681 | /*! |
---|
| 1682 | * Check on freq_off and freq_op attributes. |
---|
| 1683 | */ |
---|
| 1684 | void CField::checkTimeAttributes(CDuration* freqOp) |
---|
| 1685 | TRY |
---|
| 1686 | { |
---|
[1875] | 1687 | if (hasFileIn() && !(operation.getValue() == "instant" || operation.getValue() == "once") ) |
---|
[1869] | 1688 | ERROR("void CField::checkTimeAttributes(void)", |
---|
| 1689 | << "Unsupported operation for field '" << getFieldOutputName() << "'." << std::endl |
---|
| 1690 | << "Currently only \"instant\" is supported for fields read from file.") |
---|
[509] | 1691 | |
---|
[1869] | 1692 | if (freq_op.isEmpty()) |
---|
| 1693 | { |
---|
| 1694 | if (operation.getValue() == "instant") |
---|
| 1695 | { |
---|
[1875] | 1696 | if (hasFileIn() || hasFileOut()) freq_op.setValue(getRelFile()->output_freq.getValue()); |
---|
[1869] | 1697 | else freq_op=*freqOp ; |
---|
| 1698 | } |
---|
| 1699 | else freq_op.setValue(TimeStep); |
---|
| 1700 | } |
---|
[1875] | 1701 | if (freq_offset.isEmpty()) freq_offset.setValue(hasFileIn() ? NoneDu : (freq_op.getValue() - TimeStep)); |
---|
[1869] | 1702 | } |
---|
| 1703 | CATCH_DUMP_ATTR |
---|
[472] | 1704 | |
---|
[1869] | 1705 | /*! |
---|
| 1706 | * Returns string arithmetic expression associated to the field. |
---|
| 1707 | * \return if content is defined return content string, otherwise, if "expr" attribute is defined, return expr string. |
---|
| 1708 | */ |
---|
| 1709 | const string& CField::getExpression(void) |
---|
| 1710 | TRY |
---|
| 1711 | { |
---|
| 1712 | if (!expr.isEmpty() && content.empty()) |
---|
| 1713 | { |
---|
| 1714 | content = expr; |
---|
| 1715 | expr.reset(); |
---|
| 1716 | } |
---|
[1315] | 1717 | |
---|
[1869] | 1718 | return content; |
---|
| 1719 | } |
---|
| 1720 | CATCH_DUMP_ATTR |
---|
[1278] | 1721 | |
---|
[1869] | 1722 | bool CField::hasExpression(void) const |
---|
| 1723 | TRY |
---|
| 1724 | { |
---|
| 1725 | return (!expr.isEmpty() || !content.empty()); |
---|
| 1726 | } |
---|
| 1727 | CATCH |
---|
[1021] | 1728 | |
---|
[1869] | 1729 | bool CField::hasGridMask(void) const |
---|
| 1730 | TRY |
---|
| 1731 | { |
---|
| 1732 | return (this->grid_->hasMask()); |
---|
| 1733 | } |
---|
| 1734 | CATCH |
---|
[1021] | 1735 | |
---|
[1869] | 1736 | DEFINE_REF_FUNC(Field,field) |
---|
[335] | 1737 | } // namespace xios |
---|