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