Changeset 562 for XIOS/trunk/src/node/field.cpp
- Timestamp:
- 02/24/15 09:50:14 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/trunk/src/node/field.cpp
r551 r562 26 26 , foperation(), hasInstantData(false), hasExpression(false) 27 27 , active(false) , hasOutputFile(false),hasFieldOut(false), slotUpdateDate(NULL) 28 , processed(false), domAxisIds_("", ""), areAllReferenceSolved(false), areAllExpressionBuilt(false)29 { setVirtualVariableGroup() 30 31 CField::CField(const StdString 28 , processed(false), domAxisIds_("", ""), areAllReferenceSolved(false), areAllExpressionBuilt(false) 29 { setVirtualVariableGroup(); } 30 31 CField::CField(const StdString& id) 32 32 : CObjectTemplate<CField>(id), CFieldAttributes() 33 33 , refObject(), baseRefObject() … … 38 38 , foperation(), hasInstantData(false), hasExpression(false) 39 39 , active(false), hasOutputFile(false), hasFieldOut(false), slotUpdateDate(NULL) 40 , processed(false), domAxisIds_("", ""), areAllReferenceSolved(false), areAllExpressionBuilt(false)41 { setVirtualVariableGroup() 40 , processed(false), domAxisIds_("", ""), areAllReferenceSolved(false), areAllExpressionBuilt(false) 41 { setVirtualVariableGroup(); } 42 42 43 43 CField::~CField(void) 44 44 { 45 // this->grid.reset() 46 // this->file.reset() 47 this->foperation.reset() 48 if (hasExpression) delete expression 49 if (slotUpdateDate !=NULL) delete slotUpdateDate;45 // this->grid.reset(); 46 // this->file.reset(); 47 this->foperation.reset(); 48 if (hasExpression) delete expression; 49 if (slotUpdateDate != NULL) delete slotUpdateDate; 50 50 51 51 } … … 66 66 CVariableGroup* CField::getVirtualVariableGroup(void) const 67 67 { 68 return (this->vVariableGroup);68 return this->vVariableGroup; 69 69 } 70 70 … … 72 72 std::vector<CVariable*> CField::getAllVariables(void) const 73 73 { 74 return (this->vVariableGroup->getAllChildren());75 } 76 77 void CField::solveDescInheritance(bool apply, const CAttributeMap 78 { 79 SuperClassAttribute::setAttributes(parent, apply);74 return this->vVariableGroup->getAllChildren(); 75 } 76 77 void CField::solveDescInheritance(bool apply, const CAttributeMap* const parent) 78 { 79 SuperClassAttribute::setAttributes(parent, apply); 80 80 this->getVirtualVariableGroup()->solveDescInheritance(apply, NULL); 81 81 } … … 84 84 85 85 bool CField::updateDataServer 86 (const CDate 86 (const CDate& currDate, 87 87 const std::deque< CArray<double, 1>* > storedClient) 88 88 { … … 94 94 if (this->data.numElements() != this->grid->storeIndex[0]->numElements()) 95 95 { 96 this->data.resize(this->grid->storeIndex[0] 96 this->data.resize(this->grid->storeIndex[0]->numElements()); 97 97 } 98 CArray<double,1> input(data.numElements()) 98 CArray<double,1> input(data.numElements()); 99 99 this->grid->inputFieldServer(storedClient, input); 100 100 (*this->foperation)(input); … … 106 106 this->incrementNStep(); 107 107 *last_Write = writeDate; 108 return (true);109 } 110 return (false);108 return true; 109 } 110 return false; 111 111 } 112 112 … … 114 114 { 115 115 116 if (SuperClass::dispatchEvent(event)) return true 116 if (SuperClass::dispatchEvent(event)) return true; 117 117 else 118 118 { … … 120 120 { 121 121 case EVENT_ID_UPDATE_DATA : 122 recvUpdateData(event) 123 return true 124 break 122 recvUpdateData(event); 123 return true; 124 break; 125 125 126 126 case EVENT_ID_ADD_VARIABLE : 127 recvAddVariable(event) 128 return true 129 break 127 recvAddVariable(event); 128 return true; 129 break; 130 130 131 131 case EVENT_ID_ADD_VARIABLE_GROUP : 132 recvAddVariableGroup(event) 133 return true 134 break 132 recvAddVariableGroup(event); 133 return true; 134 break; 135 135 136 136 default : 137 ERROR("bool CField::dispatchEvent(CEventServer& event)", <<"Unknown Event");138 return false 137 ERROR("bool CField::dispatchEvent(CEventServer& event)", << "Unknown Event"); 138 return false; 139 139 } 140 140 } … … 143 143 void CField::sendUpdateData(void) 144 144 { 145 CContext* context = CContext::getCurrent() 146 CContextClient* client =context->client;147 148 CEventClient event(getType(),EVENT_ID_UPDATE_DATA) 149 150 map<int,CArray<int, 1>* >::iterator it 151 list<shared_ptr<CMessage> > list_msg 152 list< CArray<double,1>* > list_data 153 154 for (it=grid->storeIndex_toSrv.begin();it!=grid->storeIndex_toSrv.end();it++)155 { 156 int rank =(*it).first;157 CArray<int,1>& index = *(it->second) 158 CArray<double,1> data_tmp(index.numElements()) 159 for (int n=0;n<data_tmp.numElements();n++) data_tmp(n)=data(index(n));160 list_msg.push_back(shared_ptr<CMessage>(new CMessage)) 161 list_data.push_back(new CArray<double,1>(data_tmp)) 162 *list_msg.back() <<getId()<<*list_data.back();163 event.push(rank,grid->nbSenders[rank],*list_msg.back()) 164 } 165 client->sendEvent(event) 166 167 for (list< CArray<double,1>* >::iterator it=list_data.begin();it!=list_data.end();it++) delete *it;145 CContext* context = CContext::getCurrent(); 146 CContextClient* client = context->client; 147 148 CEventClient event(getType(),EVENT_ID_UPDATE_DATA); 149 150 map<int,CArray<int, 1>* >::iterator it; 151 list<shared_ptr<CMessage> > list_msg; 152 list< CArray<double,1>* > list_data; 153 154 for (it = grid->storeIndex_toSrv.begin(); it != grid->storeIndex_toSrv.end(); it++) 155 { 156 int rank = (*it).first; 157 CArray<int,1>& index = *(it->second); 158 CArray<double,1> data_tmp(index.numElements()); 159 for (int n = 0; n < data_tmp.numElements(); n++) data_tmp(n) = data(index(n)); 160 list_msg.push_back(shared_ptr<CMessage>(new CMessage)); 161 list_data.push_back(new CArray<double,1>(data_tmp)); 162 *list_msg.back() << getId() << *list_data.back(); 163 event.push(rank,grid->nbSenders[rank],*list_msg.back()); 164 } 165 client->sendEvent(event); 166 167 for (list< CArray<double,1>* >::iterator it = list_data.begin(); it != list_data.end(); it++) delete *it; 168 168 } 169 169 170 170 void CField::recvUpdateData(CEventServer& event) 171 171 { 172 vector<int> ranks 173 vector<CBufferIn*> buffers 174 175 list<CEventServer::SSubEvent>::iterator it 176 string fieldId 177 178 for (it =event.subEvents.begin();it!=event.subEvents.end();++it)179 { 180 int rank =it->rank;181 CBufferIn* buffer =it->buffer;182 *buffer >>fieldId;183 ranks.push_back(rank) 184 buffers.push_back(buffer) 185 } 186 get(fieldId)->recvUpdateData(ranks,buffers) 172 vector<int> ranks; 173 vector<CBufferIn*> buffers; 174 175 list<CEventServer::SSubEvent>::iterator it; 176 string fieldId; 177 178 for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it) 179 { 180 int rank = it->rank; 181 CBufferIn* buffer = it->buffer; 182 *buffer >> fieldId; 183 ranks.push_back(rank); 184 buffers.push_back(buffer); 185 } 186 get(fieldId)->recvUpdateData(ranks,buffers); 187 187 } 188 188 … … 192 192 if (data_srv.empty()) 193 193 { 194 // for (map<int, CArray<int, 1>* >::iterator it=grid->out_i_fromClient.begin();it!=grid->out_i_fromClient.end();it++)195 for (map<int, CArray<size_t, 1>* >::iterator it=grid->outIndexFromClient.begin();it!=grid->outIndexFromClient.end();++it)196 { 197 int rank =it->first;198 CArray<double,1> data_tmp(it->second->numElements()) 199 data_srv.insert( pair<int, CArray<double,1>* >(rank, new CArray<double,1>(data_tmp) ) );200 foperation_srv.insert(pair<int,boost::shared_ptr<func::CFunctor> >(rank,boost::shared_ptr<func::CFunctor>(new func::CInstant(*data_srv[rank])))) 201 } 202 } 203 204 CContext* context = CContext::getCurrent() 205 const CDate 194 // for (map<int, CArray<int, 1>* >::iterator it = grid->out_i_fromClient.begin(); it != grid->out_i_fromClient.end(); it++) 195 for (map<int, CArray<size_t, 1>* >::iterator it = grid->outIndexFromClient.begin(); it != grid->outIndexFromClient.end(); ++it) 196 { 197 int rank = it->first; 198 CArray<double,1> data_tmp(it->second->numElements()); 199 data_srv.insert( pair<int, CArray<double,1>* >(rank, new CArray<double,1>(data_tmp))); 200 foperation_srv.insert(pair<int,boost::shared_ptr<func::CFunctor> >(rank,boost::shared_ptr<func::CFunctor>(new func::CInstant(*data_srv[rank])))); 201 } 202 } 203 204 CContext* context = CContext::getCurrent(); 205 const CDate& currDate = context->getCalendar()->getCurrentDate(); 206 206 const CDate opeDate = *last_operation_srv + freq_operation_srv; 207 207 const CDate writeDate = *last_Write_srv + freq_write_srv; 208 208 209 210 211 209 if (opeDate <= currDate) 212 210 { 213 for (int n=0;n<ranks.size();n++)214 { 215 CArray<double,1> data_tmp 216 *buffers[n] >>data_tmp;217 (*foperation_srv[ranks[n]])(data_tmp) 211 for (int n = 0; n < ranks.size(); n++) 212 { 213 CArray<double,1> data_tmp; 214 *buffers[n] >> data_tmp; 215 (*foperation_srv[ranks[n]])(data_tmp); 218 216 } 219 217 *last_operation_srv = currDate; … … 222 220 if (writeDate < (currDate + freq_operation_srv)) 223 221 { 224 for (int n=0;n<ranks.size();n++)222 for (int n = 0; n < ranks.size(); n++) 225 223 { 226 224 this->foperation_srv[ranks[n]]->final(); … … 228 226 229 227 *last_Write_srv = writeDate; 230 writeField() 231 *lastlast_Write_srv =*last_Write_srv;228 writeField(); 229 *lastlast_Write_srv = *last_Write_srv; 232 230 } 233 231 } … … 235 233 void CField::writeField(void) 236 234 { 237 if (! getRelFile()->allDomainEmpty)238 if (! 235 if (!getRelFile()->allDomainEmpty) 236 if (!grid->domain->isEmpty() || getRelFile()->type == CFile::type_attr::one_file) 239 237 { 240 238 getRelFile()->checkFile(); … … 243 241 } 244 242 } 243 245 244 //---------------------------------------------------------------- 246 245 … … 248 247 { 249 248 this->file = _file; 250 hasOutputFile =true;251 } 252 253 //---------------------------------------------------------------- 254 255 StdString CField::GetName(void) { return (StdString("field")); }256 StdString CField::GetDefName(void) { return (CField::GetName()); }257 ENodeType CField::GetType(void) { return (eField); }249 hasOutputFile = true; 250 } 251 252 //---------------------------------------------------------------- 253 254 StdString CField::GetName(void) { return StdString("field"); } 255 StdString CField::GetDefName(void) { return CField::GetName(); } 256 ENodeType CField::GetType(void) { return eField; } 258 257 259 258 //---------------------------------------------------------------- … … 261 260 CGrid* CField::getRelGrid(void) const 262 261 { 263 return (this->grid);262 return this->grid; 264 263 } 265 264 … … 268 267 CFile* CField::getRelFile(void) const 269 268 { 270 return (this->file);269 return this->file; 271 270 } 272 271 273 272 StdSize CField::getNStep(void) const 274 273 { 275 return (this->nstep);274 return this->nstep; 276 275 } 277 276 … … 283 282 void CField::resetNStep(void) 284 283 { 285 this->nstep=0; 286 } 287 288 //---------------------------------------------------------------- 289 290 const CDuration & CField::getFreqOperation(void) const 291 { 292 return (this->freq_operation); 293 } 294 295 //---------------------------------------------------------------- 296 const CDuration & CField::getFreqWrite(void) const 297 { 298 return (this->freq_write); 284 this->nstep = 0; 285 } 286 287 //---------------------------------------------------------------- 288 289 const CDuration& CField::getFreqOperation(void) const 290 { 291 return this->freq_operation; 292 } 293 294 //---------------------------------------------------------------- 295 296 const CDuration& CField::getFreqWrite(void) const 297 { 298 return this->freq_write; 299 299 } 300 300 … … 303 303 boost::shared_ptr<func::CFunctor> CField::getFieldOperation(void) const 304 304 { 305 return (this->foperation); 306 } 307 305 return this->foperation; 306 } 308 307 309 308 bool CField::isActive(void) const 310 309 { 311 return (!this->refObject.empty()); 312 } 310 return !this->refObject.empty(); 311 } 312 313 313 //---------------------------------------------------------------- 314 314 … … 338 338 // if (!processed) 339 339 // { 340 // processed =true;341 // solveRefInheritance(true) 342 // solveBaseReference() 343 // solveOperation() 344 // solveGridReference() 345 // 346 // if (hasDirectFieldReference()) baseRefObject->processEnabledField() 340 // processed = true; 341 // solveRefInheritance(true); 342 // solveBaseReference(); 343 // solveOperation(); 344 // solveGridReference(); 345 // 346 // if (hasDirectFieldReference()) baseRefObject->processEnabledField(); 347 347 // buildExpression(); 348 // active =true;348 // active = true; 349 349 // } 350 350 // } … … 384 384 if (hasDirectFieldReference()) baseRefObject->buildAllExpressionEnabledField(); 385 385 buildExpression(); 386 active =true;386 active = true; 387 387 } 388 388 } … … 394 394 using namespace func; 395 395 396 if (!hasOutputFile && !hasFieldOut) return 397 398 StdString id 399 if (hasId()) id =getId();400 else if (!name.isEmpty()) id =name;401 else if (hasDirectFieldReference()) id =baseRefObject->getId();396 if (!hasOutputFile && !hasFieldOut) return; 397 398 StdString id; 399 if (hasId()) id = getId(); 400 else if (!name.isEmpty()) id = name; 401 else if (hasDirectFieldReference()) id = baseRefObject->getId(); 402 402 403 403 CContext* context = CContext::getCurrent(); … … 405 405 if (freq_op.isEmpty()) freq_op.setValue(TimeStep); 406 406 407 if (operation.isEmpty() 407 if (operation.isEmpty()) 408 408 { 409 409 ERROR("CField::solveOperation(void)", … … 455 455 *this->last_operation = *this->last_operation - toffset; 456 456 457 if (operation.get()=="once") isOnceOperation=true ; 458 else isOnceOperation=false; 459 isFirstOperation=true; 460 461 462 #define DECLARE_FUNCTOR(MType, mtype) \ 463 if (operation.getValue().compare(#mtype) == 0) \ 464 { \ 465 if (!detect_missing_value.isEmpty() && !default_value.isEmpty() && detect_missing_value==true) \ 457 if (operation.get() == "once") isOnceOperation = true; 458 else isOnceOperation = false; 459 isFirstOperation = true; 460 461 #define DECLARE_FUNCTOR(MType, mtype) \ 462 if (operation.getValue().compare(#mtype) == 0) \ 463 { \ 464 if (!detect_missing_value.isEmpty() && !default_value.isEmpty() && detect_missing_value == true) \ 466 465 { \ 467 466 boost::shared_ptr<func::CFunctor> foperation_(new C##MType(this->data,default_value)); \ … … 471 470 { \ 472 471 boost::shared_ptr<func::CFunctor> foperation_(new C##MType(this->data)); \ 473 this->foperation = foperation_; 472 this->foperation = foperation_; \ 474 473 } \ 475 return; 474 return; \ 476 475 } 477 476 … … 482 481 << "The operation is not defined !"); 483 482 // } 484 485 486 483 } 487 484 488 485 //---------------------------------------------------------------- 489 486 /* 490 void CField::fromBinary(StdIStream 487 void CField::fromBinary(StdIStream& is) 491 488 { 492 489 SuperClass::fromBinary(is); … … 514 511 if (CDomain::has(domain_ref.getValue())) 515 512 { 516 domain = CDomain::get(domain_ref.getValue()) 513 domain = CDomain::get(domain_ref.getValue()); 517 514 vecDom.push_back(domain); 518 515 } … … 520 517 ERROR("CField::solveGridReference(void)", 521 518 << "Reference to the domain \'" 522 << domain_ref.getValue() << "\' is wrong") 519 << domain_ref.getValue() << "\' is wrong"); 523 520 } 524 521 … … 527 524 if (CAxis::has(axis_ref.getValue())) 528 525 { 529 axis = CAxis::get(axis_ref.getValue()) 526 axis = CAxis::get(axis_ref.getValue()); 530 527 vecAxis.push_back(axis); 531 528 } … … 533 530 ERROR("CField::solveGridReference(void)", 534 531 << "Reference to the axis \'" 535 << axis_ref.getValue() <<"\' is wrong") 532 << axis_ref.getValue() <<"\' is wrong"); 536 533 } 537 534 … … 540 537 if (CGrid::has(grid_ref.getValue())) 541 538 { 542 this->grid = CGrid::get(grid_ref.getValue()) 539 this->grid = CGrid::get(grid_ref.getValue()); 543 540 domList = grid->getDomainList(); 544 541 axisList = grid->getAxisList(); … … 550 547 } 551 548 552 if (grid_ref.isEmpty() && 549 if (grid_ref.isEmpty() && domain_ref.isEmpty() && axis_ref.isEmpty()) 553 550 { 554 551 ERROR("CField::solveGridReference(void)", … … 562 559 // } 563 560 564 // CType<string> goodDomain 565 // CType<string> goodAxis 561 // CType<string> goodDomain; 562 // CType<string> goodAxis; 566 563 // if (!grid_ref.isEmpty()) 567 564 // { 568 // if (!grid->domain_ref.isEmpty()) goodDomain =grid->domain_ref;569 // if (!grid->axis_ref.isEmpty()) goodAxis =grid->axis_ref;565 // if (!grid->domain_ref.isEmpty()) goodDomain = grid->domain_ref; 566 // if (!grid->axis_ref.isEmpty()) goodAxis = grid->axis_ref; 570 567 // } 571 // if (!domain_ref.isEmpty()) goodDomain =domain_ref;572 // if (!axis_ref.isEmpty()) goodAxis =axis_ref;568 // if (!domain_ref.isEmpty()) goodDomain = domain_ref; 569 // if (!axis_ref.isEmpty()) goodAxis = axis_ref; 573 570 574 571 // CArray<std::string,1> domListTmp = grid->domainList.getValue(); … … 590 587 // else 591 588 // { 592 // if (CDomain::has(goodDomain)) domain = CDomain::get(goodDomain) 589 // if (CDomain::has(goodDomain)) domain = CDomain::get(goodDomain); 593 590 // else ERROR("CField::solveGridReference(void)",<< "Reference to the domain \'" 594 // << goodDomain << "\' is wrong");595 //// <<goodDomain.get() << "\' is wrong");591 // << goodDomain << "\' is wrong"); 592 //// << goodDomain.get() << "\' is wrong"); 596 593 // } 597 594 // … … 599 596 // if (!goodAxis.empty()) 600 597 // { 601 // if (CAxis::has(goodAxis)) axis = CAxis::get(goodAxis) 598 // if (CAxis::has(goodAxis)) axis = CAxis::get(goodAxis); 602 599 // else ERROR("CField::solveGridReference(void)", << "Reference to the axis \'" 603 // << goodAxis <<"\' is wrong");604 // << goodAxis.get() <<"\' is wrong");600 // << goodAxis <<"\' is wrong"); 601 // << goodAxis.get() <<"\' is wrong"); 605 602 // } 606 603 607 // bool nothingToDo =false;604 // bool nothingToDo = false; 608 605 // 609 606 // if (!grid_ref.isEmpty()) 610 607 // { 611 608 // if (!grid->domain_ref.isEmpty() && goodDomain.get() == grid->domain_ref.get()) 612 // if (goodAxis.isEmpty()) nothingToDo =true;609 // if (goodAxis.isEmpty()) nothingToDo = true; 613 610 // else if (!grid->axis_ref.isEmpty()) 614 // if (grid->axis_ref.get() ==goodAxis.get()) nothingToDo=true;611 // if (grid->axis_ref.get() == goodAxis.get()) nothingToDo = true; 615 612 // } 616 613 // … … 620 617 // if (!goodAxis.isEmpty()) 621 618 // { 622 // this->grid = CGrid::createGrid(domain, axis) 619 // this->grid = CGrid::createGrid(domain, axis); 623 620 // this->grid_ref.setValue(this->grid->getId()); 624 621 // } 625 622 // else 626 623 // { 627 // this->grid = CGrid::createGrid(domain) 624 // this->grid = CGrid::createGrid(domain); 628 625 // this->grid_ref.setValue(this->grid->getId()); 629 626 // } 630 627 // } 631 628 632 // grid->solveReference() 629 // grid->solveReference(); 633 630 // grid->solveDomainAxisRef(); 634 631 // grid->checkMaskIndex(); … … 648 645 649 646 template <> 650 647 void CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void) 651 648 { 652 649 if (this->group_ref.isEmpty()) return; … … 662 659 663 660 std::vector<CField*> allChildren = group->getAllChildren(); 664 std::vector<CField*>::iterator 665 it = allChildren.begin(), end = allChildren.end(); 661 std::vector<CField*>::iterator it = allChildren.begin(), end = allChildren.end(); 666 662 667 663 for (; it != end; it++) 668 664 { 669 665 CField* child = *it; 670 if (child->hasId()) owner->createChild()->field_ref.setValue(child->getId()) 666 if (child->hasId()) owner->createChild()->field_ref.setValue(child->getId()); 671 667 672 668 } … … 676 672 { 677 673 map<int, CArray<double,1>* >::iterator it; 678 for (it=data_srv.begin();it!=data_srv.end();it++) *it->second = (*it->second -addOffset) * 1./scaleFactor;674 for (it = data_srv.begin(); it != data_srv.end(); it++) *it->second = (*it->second - addOffset) / scaleFactor; 679 675 } 680 676 … … 682 678 { 683 679 map<int, CArray<double,1>* >::iterator it; 684 for(it=data_srv.begin();it!=data_srv.end();it++) 685 { 686 grid->outputField(it->first,*it->second, fieldOut.dataFirst()) ; 687 } 688 689 // grid->outputField(it->first,*it->second, fieldOut.) ; 690 680 for (it = data_srv.begin(); it != data_srv.end(); it++) 681 { 682 grid->outputField(it->first,*it->second, fieldOut.dataFirst()); 683 } 684 685 // grid->outputField(it->first,*it->second, fieldOut.); 691 686 } 692 687 … … 695 690 map<int, CArray<double,1>* >::iterator it; 696 691 697 for (it=data_srv.begin();it!=data_srv.end();it++)698 { 699 grid->outputField(it->first, *it->second, fieldOut);692 for (it = data_srv.begin(); it != data_srv.end(); it++) 693 { 694 grid->outputField(it->first, *it->second, fieldOut); 700 695 } 701 696 } … … 703 698 ///------------------------------------------------------------------- 704 699 705 void CField::parse(xml::CXMLNode 700 void CField::parse(xml::CXMLNode& node) 706 701 { 707 702 SuperClass::parse(node); 708 if (! 703 if (!node.getContent(this->content)) 709 704 { 710 705 if (node.goToChildElement()) … … 712 707 do 713 708 { 714 if (node.getElementName() =="variable" || node.getElementName()=="variable_group") this->getVirtualVariableGroup()->parseChild(node);715 } while (node.goToNextElement()) 709 if (node.getElementName() == "variable" || node.getElementName() == "variable_group") this->getVirtualVariableGroup()->parseChild(node); 710 } while (node.goToNextElement()); 716 711 node.goToParentElement(); 717 712 } … … 723 718 if (!hasInstantData) 724 719 { 725 instantData.resize(grid->storeIndex_client.numElements()) 726 hasInstantData =true;727 } 728 return &instantData 720 instantData.resize(grid->storeIndex_client.numElements()); 721 hasInstantData = true; 722 } 723 return &instantData; 729 724 } 730 725 731 726 void CField::addDependency(CField* field, int slotId) 732 727 { 733 fieldDependency.push_back(pair<CField*,int>(field,slotId)) 728 fieldDependency.push_back(pair<CField*,int>(field,slotId)); 734 729 } 735 730 … … 738 733 if (content.size() > 0) 739 734 { 740 CSimpleNodeExpr* simpleExpr =parseExpr(content+'\0');741 expression =CFieldNode::newNode(simpleExpr);742 delete simpleExpr 743 set<string> instantFieldIds 744 map<string,CField*> associatedInstantFieldIds 745 expression->getInstantFieldIds(instantFieldIds) 746 for (set<string>::iterator it =instantFieldIds.begin() ; it!=instantFieldIds.end();++it)747 { 748 if (*it !="this")735 CSimpleNodeExpr* simpleExpr = parseExpr(content+'\0'); 736 expression = CFieldNode::newNode(simpleExpr); 737 delete simpleExpr; 738 set<string> instantFieldIds; 739 map<string,CField*> associatedInstantFieldIds; 740 expression->getInstantFieldIds(instantFieldIds); 741 for (set<string>::iterator it = instantFieldIds.begin(); it != instantFieldIds.end(); ++it) 742 { 743 if (*it != "this") 749 744 { 750 745 if (CField::has(*it)) 751 746 { 752 CField* field =CField::get(*it);753 // field->processEnabledField() 747 CField* field = CField::get(*it); 748 // field->processEnabledField(); 754 749 field->buildAllExpressionEnabledField(); 755 associatedInstantFieldIds[*it] =field;750 associatedInstantFieldIds[*it] = field; 756 751 } 757 else ERROR("void CField::buildExpression(void)", <<" Field "<<*it<<" does not exist");752 else ERROR("void CField::buildExpression(void)", << " Field " << *it << " does not exist"); 758 753 } 759 754 } 760 755 761 set<string> averageFieldIds 762 map<string,CField*> associatedAverageFieldIds 763 764 expression->getAverageFieldIds(averageFieldIds) 765 for (set<string>::iterator it =averageFieldIds.begin() ; it!=averageFieldIds.end();++it)756 set<string> averageFieldIds; 757 map<string,CField*> associatedAverageFieldIds; 758 759 expression->getAverageFieldIds(averageFieldIds); 760 for (set<string>::iterator it = averageFieldIds.begin(); it != averageFieldIds.end(); ++it) 766 761 { 767 762 if (CField::has(*it)) 768 763 { 769 CFieldGroup* root =CFieldGroup::get("field_definition");770 CField* averageField =root->createChild();771 CField* instantField =root->createChild();772 averageField->field_ref =*it;773 averageField->hasFieldOut =true;774 averageField->fieldOut =instantField;775 instantField->freq_op =freq_op;776 // averageField-> processEnabledField() 764 CFieldGroup* root = CFieldGroup::get("field_definition"); 765 CField* averageField = root->createChild(); 766 CField* instantField = root->createChild(); 767 averageField->field_ref = *it; 768 averageField->hasFieldOut = true; 769 averageField->fieldOut = instantField; 770 instantField->freq_op = freq_op; 771 // averageField-> processEnabledField(); 777 772 averageField->buildAllExpressionEnabledField(); 778 773 instantField->SuperClassAttribute::setAttributes(averageField, true); 779 instantField->field_ref.reset() 780 instantField->operation.reset() 781 782 // instantField-> processEnabledField() 774 instantField->field_ref.reset(); 775 instantField->operation.reset(); 776 777 // instantField-> processEnabledField(); 783 778 instantField->buildAllExpressionEnabledField(); 784 associatedAverageFieldIds[*it] =instantField;779 associatedAverageFieldIds[*it] = instantField; 785 780 } 786 else ERROR("void CField::buildExpression(void)", <<" Field "<<*it<<" does not exist");787 } 788 789 expression->reduce(this,associatedInstantFieldIds,associatedAverageFieldIds) 790 791 slots.resize(instantFieldIds.size() +averageFieldIds.size());792 resetSlots() 793 int slotId =0;794 set<CField*> fields 795 expression->getFields(fields) 796 for (set<CField*>::iterator it =fields.begin() ; it!=fields.end();++it,++slotId) (*it)->addDependency(this,slotId);797 hasExpression =true;781 else ERROR("void CField::buildExpression(void)", << " Field " << *it << " does not exist"); 782 } 783 784 expression->reduce(this,associatedInstantFieldIds,associatedAverageFieldIds); 785 786 slots.resize(instantFieldIds.size() + averageFieldIds.size()); 787 resetSlots(); 788 int slotId = 0; 789 set<CField*> fields; 790 expression->getFields(fields); 791 for (set<CField*>::iterator it = fields.begin(); it != fields.end(); ++it, ++slotId) (*it)->addDependency(this,slotId); 792 hasExpression = true; 798 793 } 799 794 } … … 801 796 void CField::resetSlots(void) 802 797 { 803 for (vector<bool>::iterator it=slots.begin();it!=slots.end();++it) *it=false;798 for (vector<bool>::iterator it = slots.begin(); it != slots.end(); ++it) *it = false; 804 799 } 805 800 806 801 bool CField::slotsFull(void) 807 802 { 808 bool ret =true;809 for (vector<bool>::iterator it=slots.begin();it!=slots.end();++it) ret &= *it;810 return ret 803 bool ret = true; 804 for (vector<bool>::iterator it = slots.begin(); it != slots.end(); ++it) ret &= *it; 805 return ret; 811 806 } 812 813 807 814 808 void CField::setSlot(int slotId) 815 809 { 816 CContext* context = CContext::getCurrent() 817 const CDate 818 if (slotUpdateDate ==NULL || currDate!=*slotUpdateDate)819 { 820 resetSlots() 821 if (slotUpdateDate ==NULL) slotUpdateDate=new CDate(currDate);822 else *slotUpdateDate =currDate;823 } 824 slots[slotId] =true;810 CContext* context = CContext::getCurrent(); 811 const CDate& currDate = context->getCalendar()->getCurrentDate(); 812 if (slotUpdateDate == NULL || currDate != *slotUpdateDate) 813 { 814 resetSlots(); 815 if (slotUpdateDate == NULL) slotUpdateDate = new CDate(currDate); 816 else *slotUpdateDate = currDate; 817 } 818 slots[slotId] = true; 825 819 if (slotsFull()) 826 820 { 827 CArray<double,1> expr(expression->compute()) 821 CArray<double,1> expr(expression->compute()); 828 822 829 823 if (hasInstantData) 830 824 { 831 instantData=expr ; 832 for(list< pair<CField *,int> >::iterator it=fieldDependency.begin(); it!=fieldDependency.end(); ++it) 833 if (it->first!=this) it->first->setSlot(it->second) ; 834 } 835 836 if (hasOutputFile) updateDataFromExpression(expr) ; 837 825 instantData = expr; 826 for (list< pair<CField *,int> >::iterator it = fieldDependency.begin(); it != fieldDependency.end(); ++it) 827 if (it->first != this) it->first->setSlot(it->second); 828 } 829 830 if (hasOutputFile) updateDataFromExpression(expr); 831 832 const std::vector<CField*>& refField = getAllReference(); 833 for (std::vector<CField*>::const_iterator it = refField.begin(); it != refField.end(); it++) 834 { 835 if (!(*it)->hasExpression) 836 (*it)->setDataFromExpression(expr); 837 } 838 838 } 839 839 } … … 853 853 } 854 854 855 return (domAxisIds_);855 return domAxisIds_; 856 856 } 857 857 858 858 CVariable* CField::addVariable(const string& id) 859 859 { 860 return vVariableGroup->createChild(id) 860 return vVariableGroup->createChild(id); 861 861 } 862 862 863 863 CVariableGroup* CField::addVariableGroup(const string& id) 864 864 { 865 return vVariableGroup->createChildGroup(id) ; 866 } 867 865 return vVariableGroup->createChildGroup(id); 866 } 868 867 869 868 void CField::sendAddAllVariables() … … 890 889 void CField::sendAddVariable(const string& id) 891 890 { 892 CContext* context =CContext::getCurrent();893 894 if (! context->hasServer)895 { 896 CContextClient* client =context->client;897 898 CEventClient event(this->getType(),EVENT_ID_ADD_VARIABLE) 891 CContext* context = CContext::getCurrent(); 892 893 if (!context->hasServer) 894 { 895 CContextClient* client = context->client; 896 897 CEventClient event(this->getType(),EVENT_ID_ADD_VARIABLE); 899 898 if (client->isServerLeader()) 900 899 { 901 CMessage msg 902 msg <<this->getId();903 msg <<id;904 event.push(client->getServerLeader(),1,msg) 905 client->sendEvent(event) 900 CMessage msg; 901 msg << this->getId(); 902 msg << id; 903 event.push(client->getServerLeader(),1,msg); 904 client->sendEvent(event); 906 905 } 907 else client->sendEvent(event) ; 908 } 909 910 } 911 906 else client->sendEvent(event); 907 } 908 } 912 909 913 910 void CField::sendAddVariableGroup(const string& id) 914 911 { 915 CContext* context =CContext::getCurrent();916 if (! context->hasServer)917 { 918 CContextClient* client =context->client;919 920 CEventClient event(this->getType(),EVENT_ID_ADD_VARIABLE_GROUP) 912 CContext* context = CContext::getCurrent(); 913 if (!context->hasServer) 914 { 915 CContextClient* client = context->client; 916 917 CEventClient event(this->getType(),EVENT_ID_ADD_VARIABLE_GROUP); 921 918 if (client->isServerLeader()) 922 919 { 923 CMessage msg 924 msg <<this->getId();925 msg <<id;926 event.push(client->getServerLeader(),1,msg) 927 client->sendEvent(event) 920 CMessage msg; 921 msg << this->getId(); 922 msg << id; 923 event.push(client->getServerLeader(),1,msg); 924 client->sendEvent(event); 928 925 } 929 else client->sendEvent(event) ; 930 } 931 926 else client->sendEvent(event); 927 } 932 928 } 933 929 … … 935 931 { 936 932 937 CBufferIn* buffer =event.subEvents.begin()->buffer;933 CBufferIn* buffer = event.subEvents.begin()->buffer; 938 934 string id; 939 *buffer>>id ; 940 get(id)->recvAddVariable(*buffer) ; 941 } 942 935 *buffer >> id; 936 get(id)->recvAddVariable(*buffer); 937 } 943 938 944 939 void CField::recvAddVariable(CBufferIn& buffer) 945 940 { 946 string id 947 buffer >>id;948 addVariable(id) 941 string id; 942 buffer >> id; 943 addVariable(id); 949 944 } 950 945 … … 952 947 { 953 948 954 CBufferIn* buffer =event.subEvents.begin()->buffer;949 CBufferIn* buffer = event.subEvents.begin()->buffer; 955 950 string id; 956 *buffer>>id ; 957 get(id)->recvAddVariableGroup(*buffer) ; 958 } 959 951 *buffer >> id; 952 get(id)->recvAddVariableGroup(*buffer); 953 } 960 954 961 955 void CField::recvAddVariableGroup(CBufferIn& buffer) 962 956 { 963 string id 964 buffer >>id;965 addVariableGroup(id) 957 string id; 958 buffer >> id; 959 addVariableGroup(id); 966 960 } 967 961 … … 970 964 // void CField::addReference(CField* field) 971 965 // { 972 // refObject.push_back(field) 966 // refObject.push_back(field); 973 967 // } 974 968 // … … 977 971 // bool CField::hasDirectFieldReference(void) const 978 972 // { 979 // return (!this->field_ref.isEmpty());973 // return !this->field_ref.isEmpty(); 980 974 // } 981 975 // 982 976 // //---------------------------------------------------------------- 983 977 // 984 // const StdString 978 // const StdString& CField::getBaseFieldId(void) const 985 979 // { 986 // return (this->getBaseFieldReference()->getId());980 // return this->getBaseFieldReference()->getId(); 987 981 // } 988 //989 982 // 990 983 // //---------------------------------------------------------------- … … 996 989 // { 997 990 // if (this->field_ref.isEmpty()) 998 // return (this->getBaseFieldReference());999 // 1000 // if (! 991 // return this->getBaseFieldReference(); 992 // 993 // if (!CField::has(this->field_ref.getValue())) 1001 994 // ERROR("CField::getDirectFieldReference(void)", 1002 995 // << "[ ref_name = " << this->field_ref.getValue() << "]" 1003 996 // << " invalid field name !"); 1004 997 // 1005 // return (CField::get(this->field_ref.getValue()));998 // return CField::get(this->field_ref.getValue()); 1006 999 // } 1007 1000 // … … 1010 1003 // CField* CField::getBaseFieldReference(void) const 1011 1004 // { 1012 // return (baseRefObject);1005 // return baseRefObject; 1013 1006 // } 1014 1007 // … … 1017 1010 // const std::vector<CField*>& CField::getAllReference(void) const 1018 1011 // { 1019 // return (refObject);1012 // return refObject; 1020 1013 // } 1021 //1022 1014 // 1023 1015 // /*! … … 1033 1025 // std::set<CField *> sset; 1034 1026 // CField* refer_sptr; 1035 // CField 1027 // CField* refer_ptr = this; 1036 1028 // 1037 1029 // while (refer_ptr->hasDirectFieldReference()) … … 1067 1059 // std::set<CField *> sset; 1068 1060 // CField* refer_sptr; 1069 // CField 1061 // CField* refer_ptr = this; 1070 1062 // 1071 1063 // if (this->hasDirectFieldReference()) baseRefObject = getDirectFieldReference(); … … 1087 1079 // } 1088 1080 // 1089 // if (hasDirectFieldReference()) baseRefObject->addReference(this) 1081 // if (hasDirectFieldReference()) baseRefObject->addReference(this); 1090 1082 // } 1091 //1092 1093 1083 } // namespace xios
Note: See TracChangeset
for help on using the changeset viewer.