Changeset 509 for XIOS/trunk/src/node
- Timestamp:
- 11/13/14 15:09:14 (10 years ago)
- Location:
- XIOS/trunk/src/node
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/trunk/src/node/context.cpp
r501 r509 16 16 17 17 namespace xios { 18 18 19 19 shared_ptr<CContextGroup> CContext::root ; 20 20 21 21 /// ////////////////////// Définitions ////////////////////// /// 22 22 23 23 CContext::CContext(void) 24 24 : CObjectTemplate<CContext>(), CContextAttributes() 25 , calendar(),hasClient(false),hasServer(false) 25 , calendar(),hasClient(false),hasServer(false), isPostProcessed(false), dataSize_() 26 26 { /* Ne rien faire de plus */ } 27 27 28 28 CContext::CContext(const StdString & id) 29 29 : CObjectTemplate<CContext>(id), CContextAttributes() 30 , calendar(),hasClient(false),hasServer(false) 30 , calendar(),hasClient(false),hasServer(false), isPostProcessed(false), dataSize_() 31 31 { /* Ne rien faire de plus */ } 32 32 33 33 CContext::~CContext(void) 34 { 34 { 35 35 if (hasClient) delete client ; 36 36 if (hasServer) delete server ; … … 38 38 39 39 //---------------------------------------------------------------- 40 40 //! Get name of context 41 41 StdString CContext::GetName(void) { return (StdString("context")); } 42 42 StdString CContext::GetDefName(void){ return (CContext::GetName()); } … … 44 44 45 45 //---------------------------------------------------------------- 46 46 /*! 47 \brief Get context group (context root) 48 \return Context root 49 */ 47 50 CContextGroup* CContext::getRoot(void) 48 { 51 { 49 52 if (root.get()==NULL) root=shared_ptr<CContextGroup>(new CContextGroup(xml::CXMLNode::GetRootName())) ; 50 return root.get(); 51 } 52 53 54 //---------------------------------------------------------------- 55 53 return root.get(); 54 } 55 56 57 //---------------------------------------------------------------- 58 /*! 59 \brief Get calendar of a context 60 \return Calendar 61 */ 56 62 boost::shared_ptr<CCalendar> CContext::getCalendar(void) const 57 63 { 58 64 return (this->calendar); 59 65 } 60 61 //---------------------------------------------------------------- 62 66 67 //---------------------------------------------------------------- 68 /*! 69 \brief Set a context with a calendar 70 \param[in] newCalendar new calendar 71 */ 63 72 void CContext::setCalendar(boost::shared_ptr<CCalendar> newCalendar) 64 73 { … … 67 76 start_date.setValue(this->calendar->getInitDate().toString()); 68 77 } 69 70 //---------------------------------------------------------------- 71 78 79 //---------------------------------------------------------------- 80 //! Process all information of calendar 72 81 void CContext::solveCalendar(void) 73 82 { … … 97 106 << "The calendar is not defined !"); 98 107 } 99 100 //---------------------------------------------------------------- 101 108 109 //---------------------------------------------------------------- 110 /*! 111 \brief Parse xml file and write information into context object 112 \param [in] node xmld node corresponding in xml file 113 */ 102 114 void CContext::parse(xml::CXMLNode & node) 103 115 { … … 135 147 136 148 if (attributes.end() != attributes.find("id")) 137 { DEBUG(<< "Definition node has an id," 138 << "it will not be taking account !"); } 149 { 150 DEBUG(<< "Definition node has an id," 151 << "it will not be taking account !"); 152 } 139 153 140 154 #define DECLARE_NODE(Name_, name_) \ … … 155 169 156 170 //---------------------------------------------------------------- 157 171 //! Show tree structure of context 158 172 void CContext::ShowTree(StdOStream & out) 159 173 { … … 166 180 out << "<? xml version=\"1.0\" ?>" << std::endl; 167 181 out << "<" << xml::CXMLNode::GetRootName() << " >" << std::endl; 168 182 169 183 for (; it != end; it++) 170 184 { 171 CContext* context = *it; 172 CContext::setCurrent(context->getId()); 185 CContext* context = *it; 186 CContext::setCurrent(context->getId()); 173 187 out << *context << std::endl; 174 188 } 175 189 176 190 out << "</" << xml::CXMLNode::GetRootName() << " >" << std::endl; 177 CContext::setCurrent(currentContextId); 178 } 179 180 181 //---------------------------------------------------------------- 182 191 CContext::setCurrent(currentContextId); 192 } 193 194 195 //---------------------------------------------------------------- 196 197 //! Convert context object into string (to print) 183 198 StdString CContext::toString(void) const 184 199 { … … 209 224 //---------------------------------------------------------------- 210 225 226 /*! 227 \brief Find all inheritace among objects in a context. 228 \param [in] apply (true) write attributes of parent into ones of child if they are empty 229 (false) write attributes of parent into a new container of child 230 \param [in] parent unused 231 */ 211 232 void CContext::solveDescInheritance(bool apply, const CAttributeMap * const UNUSED(parent)) 212 233 { … … 220 241 //---------------------------------------------------------------- 221 242 243 //! Verify if all root definition in the context have child. 222 244 bool CContext::hasChild(void) const 223 245 { … … 230 252 } 231 253 232 //----------------------------------------------------------------233 234 void CContext::solveFieldRefInheritance(bool apply)235 {236 if (!this->hasId()) return;237 vector<CField*> allField = CField::getAll() ;238 // = CObjectTemplate<CField>::GetAllVectobject(this->getId());239 std::vector<CField*>::iterator 240 it = allField.begin(), end = allField.end();241 242 for (; it != end; it++)243 {244 CField* field = *it;245 field->solveRefInheritance(apply);246 }247 }254 // //---------------------------------------------------------------- 255 // 256 // void CContext::solveFieldRefInheritance(bool apply) 257 // { 258 // if (!this->hasId()) return; 259 // vector<CField*> allField = CField::getAll() ; 260 //// = CObjectTemplate<CField>::GetAllVectobject(this->getId()); 261 // std::vector<CField*>::iterator 262 // it = allField.begin(), end = allField.end(); 263 // 264 // for (; it != end; it++) 265 // { 266 // CField* field = *it; 267 // field->solveRefInheritance(apply); 268 // } 269 // } 248 270 249 271 //---------------------------------------------------------------- … … 256 278 } 257 279 ///--------------------------------------------------------------- 258 280 281 //! Initialize client side 259 282 void CContext::initClient(MPI_Comm intraComm, MPI_Comm interComm) 260 283 { 261 284 hasClient=true ; 262 285 client = new CContextClient(this,intraComm, interComm) ; 263 } 264 286 } 287 288 void CContext::setClientServerBuffer() 289 { 290 if (hasClient) 291 { 292 client->setBufferSize(getDataSize()); 293 } 294 } 295 296 //! Verify whether a context is initialized 265 297 bool CContext::isInitialized(void) 266 298 { 267 299 return hasClient ; 268 300 } 269 301 302 //! Initialize server 270 303 void CContext::initServer(MPI_Comm intraComm,MPI_Comm interComm) 271 304 { 272 305 hasServer=true ; 273 306 server = new CContextServer(this,intraComm,interComm) ; 274 } 275 307 } 308 309 //! Server side: Put server into a loop in order to listen message from client 276 310 bool CContext::eventLoop(void) 277 311 { 278 312 return server->eventLoop() ; 279 } 280 313 } 314 315 //! Terminate a context 281 316 void CContext::finalize(void) 282 317 { … … 290 325 } 291 326 } 292 293 294 295 327 328 /*! 329 \brief Close all the context defintion and do processing data 330 After everything is well defined on client side, they will be processed and sent to server 331 From the version 2.0, sever and client work no more on the same database. Moreover, client(s) will send 332 all necessary information to server, from which each server can build its own database. 333 Because the role of server is to write out field data on a specific netcdf file, 334 the only information that it needs is the enabled files 335 and the active fields (fields will be written onto active files) 336 */ 296 337 void CContext::closeDefinition(void) 297 338 { 298 if (hasClient && !hasServer) sendCloseDefinition() ; 299 300 solveCalendar(); 301 302 // Résolution des héritages pour le context actuel. 303 this->solveAllInheritance(); 304 305 //Initialisation du vecteur 'enabledFiles' contenant la liste des fichiers à sortir. 306 this->findEnabledFiles(); 307 308 309 this->processEnabledFiles() ; 310 311 /* 339 if (hasClient && !hasServer) 340 { 341 // After xml is parsed, there are some more works with post processing 342 postProcessing(); 343 344 setClientServerBuffer(); 345 346 // Send all attributes of current context to server 347 this->sendAllAttributesToServer(); 348 349 // We have enough information to send to server 350 // First of all, send all enabled files 351 sendEnabledFiles(); 352 353 // Then, send all enabled fields 354 sendEnabledFields(); 355 356 // After that, send all grid (if any) 357 sendRefGrid(); 358 359 // At last, we have all info of domain and axis, then send them 360 sendRefDomainsAxis(); 361 } 362 363 // Now tell server that it can process all messages from client 364 if (hasClient && !hasServer) this->sendCloseDefinition(); 365 366 // We have a xml tree on the server side and now, it should be also processed 367 if (hasClient && !hasServer) sendPostProcessing(); 368 369 // There are some processings that should be done after all of above. For example: check mask or index 370 if (hasClient && !hasServer) 371 { 372 this->solveAllRefOfEnabledFields(true); 373 this->buildAllExpressionOfEnabledFields(); 374 } 375 376 // if (hasClient) 377 // { 378 // //solveCalendar(); 379 // 380 // // Résolution des héritages pour le context actuel. 381 //// this->solveAllInheritance(); 382 // 383 // 384 //// //Initialisation du vecteur 'enabledFiles' contenant la liste des fichiers à sortir. 385 //// this->findEnabledFiles(); 386 // 387 // this->processEnabledFiles() ; 388 // 389 // this->solveAllGridRef(); 390 // } 391 392 393 394 395 // solveCalendar(); 396 // 397 // // Résolution des héritages pour le context actuel. 398 // this->solveAllInheritance(); 399 // 400 // //Initialisation du vecteur 'enabledFiles' contenant la liste des fichiers à sortir. 401 // this->findEnabledFiles(); 402 // 403 // 404 // this->processEnabledFiles() ; 405 406 /* 312 407 //Recherche des champs à sortir (enable à true + niveau de sortie correct) 313 408 // pour chaque fichier précédemment listé. … … 324 419 */ 325 420 // Nettoyage de l'arborescence 326 CleanTree(); 421 if (hasClient && !hasServer) CleanTree(); // Only on client side?? 422 // if (hasClient) CleanTree(); 327 423 if (hasClient) sendCreateFileHeader() ; 328 424 } 329 425 330 426 void CContext::findAllEnabledFields(void) 331 427 { … … 333 429 (void)this->enabledFiles[i]->getEnabledFields(); 334 430 } 335 336 void CContext::processEnabledFiles(void) 337 { 338 for (unsigned int i = 0; i < this->enabledFiles.size(); i++) 339 this->enabledFiles[i]->processEnabledFile(); 340 } 341 342 343 void CContext::solveAllGridRef(void) 344 { 345 for (unsigned int i = 0; i < this->enabledFiles.size(); i++) 346 this->enabledFiles[i]->solveEFGridRef(); 347 } 348 349 void CContext::solveAllOperation(void) 350 { 351 for (unsigned int i = 0; i < this->enabledFiles.size(); i++) 352 this->enabledFiles[i]->solveEFOperation(); 353 } 354 355 void CContext::solveAllExpression(void) 356 { 357 for (unsigned int i = 0; i < this->enabledFiles.size(); i++) 358 this->enabledFiles[i]->solveEFExpression(); 359 } 360 431 432 // void CContext::processEnabledFiles(void) 433 // { 434 // for (unsigned int i = 0; i < this->enabledFiles.size(); i++) 435 // this->enabledFiles[i]->processEnabledFile(); 436 // } 437 438 439 void CContext::solveAllRefOfEnabledFields(bool sendToServer) 440 { 441 int size = this->enabledFiles.size(); 442 for (int i = 0; i < size; ++i) 443 { 444 this->enabledFiles[i]->solveAllRefOfEnabledFields(sendToServer); 445 } 446 } 447 448 void CContext::buildAllExpressionOfEnabledFields() 449 { 450 int size = this->enabledFiles.size(); 451 for (int i = 0; i < size; ++i) 452 { 453 this->enabledFiles[i]->buildAllExpressionOfEnabledFields(); 454 } 455 } 456 457 // void CContext::solveAllGridRef(void) 458 // { 459 // for (unsigned int i = 0; i < this->enabledFiles.size(); i++) 460 // this->enabledFiles[i]->solveEFGridRef(); 461 // } 462 // 463 // void CContext::solveAllOperation(void) 464 // { 465 // for (unsigned int i = 0; i < this->enabledFiles.size(); i++) 466 // this->enabledFiles[i]->solveEFOperation(); 467 // } 468 // 469 // void CContext::solveAllExpression(void) 470 // { 471 // for (unsigned int i = 0; i < this->enabledFiles.size(); i++) 472 // this->enabledFiles[i]->solveEFExpression(); 473 // } 474 361 475 void CContext::solveAllInheritance(bool apply) 362 476 { … … 368 482 const vector<CFile*> allFiles=CFile::getAll() ; 369 483 484 if (hasClient && !hasServer) 370 485 for (unsigned int i = 0; i < allFiles.size(); i++) 371 486 allFiles[i]->solveFieldRefInheritance(apply); … … 383 498 } 384 499 else enabledFiles.push_back(allFiles[i]); // otherwise true by default 385 500 386 501 387 502 if (enabledFiles.size() == 0) … … 394 509 std::vector<CFile*>::const_iterator 395 510 it = this->enabledFiles.begin(), end = this->enabledFiles.end(); 396 511 397 512 for (; it != end; it++) 398 513 { … … 401 516 } 402 517 } 403 518 519 /*! 520 \brief Dispatch event received from client 521 Whenever a message is received in buffer of server, it will be processed depending on 522 its event type. A new event type should be added in the switch list to make sure 523 it processed on server side. 524 \param [in] event: Received message 525 */ 404 526 bool CContext::dispatchEvent(CEventServer& event) 405 527 { 406 528 407 529 if (SuperClass::dispatchEvent(event)) return true ; 408 530 else … … 422 544 return true ; 423 545 break ; 546 case EVENT_ID_POST_PROCESS: 547 recvPostProcessing(event) ; 548 return true ; 549 break ; 424 550 default : 425 551 ERROR("bool CContext::dispatchEvent(CEventServer& event)", … … 429 555 } 430 556 } 431 557 558 //! Client side: Send a message to server to make it close 432 559 void CContext::sendCloseDefinition(void) 433 560 { 434 435 CEventClient event(getType(),EVENT_ID_CLOSE_DEFINITION) ; 561 CEventClient event(getType(),EVENT_ID_CLOSE_DEFINITION) ; 436 562 if (client->isServerLeader()) 437 563 { … … 443 569 else client->sendEvent(event) ; 444 570 } 445 571 572 //! Server side: Receive a message of client announcing a context close 446 573 void CContext::recvCloseDefinition(CEventServer& event) 447 574 { 448 575 449 576 CBufferIn* buffer=event.subEvents.begin()->buffer; 450 577 string id; 451 578 *buffer>>id ; 452 get(id)->closeDefinition() ; 453 } 454 579 get(id)->closeDefinition(); 580 } 581 582 //! Client side: Send a message to update calendar in each time step 455 583 void CContext::sendUpdateCalendar(int step) 456 584 { 457 585 if (!hasServer) 458 586 { 459 CEventClient event(getType(),EVENT_ID_UPDATE_CALENDAR) ; 587 CEventClient event(getType(),EVENT_ID_UPDATE_CALENDAR) ; 460 588 if (client->isServerLeader()) 461 589 { … … 468 596 } 469 597 } 470 598 599 //! Server side: Receive a message of client annoucing calendar update 471 600 void CContext::recvUpdateCalendar(CEventServer& event) 472 601 { 473 602 474 603 CBufferIn* buffer=event.subEvents.begin()->buffer; 475 604 string id; … … 477 606 get(id)->recvUpdateCalendar(*buffer) ; 478 607 } 479 608 609 //! Server side: Receive a message of client annoucing calendar update 480 610 void CContext::recvUpdateCalendar(CBufferIn& buffer) 481 611 { … … 484 614 updateCalendar(step) ; 485 615 } 486 616 617 //! Client side: Send a message to create header part of netcdf file 487 618 void CContext::sendCreateFileHeader(void) 488 619 { 489 490 CEventClient event(getType(),EVENT_ID_CREATE_FILE_HEADER) ; 620 CEventClient event(getType(),EVENT_ID_CREATE_FILE_HEADER) ; 491 621 if (client->isServerLeader()) 492 622 { … … 498 628 else client->sendEvent(event) ; 499 629 } 500 630 631 //! Server side: Receive a message of client annoucing the creation of header part of netcdf file 501 632 void CContext::recvCreateFileHeader(CEventServer& event) 502 633 { 503 504 634 CBufferIn* buffer=event.subEvents.begin()->buffer; 505 635 string id; … … 507 637 get(id)->recvCreateFileHeader(*buffer) ; 508 638 } 509 639 640 //! Server side: Receive a message of client annoucing the creation of header part of netcdf file 510 641 void CContext::recvCreateFileHeader(CBufferIn& buffer) 511 642 { 512 643 createFileHeader() ; 513 644 } 514 645 646 //! Client side: Send a message to do some post processing on server 647 void CContext::sendPostProcessing() 648 { 649 if (!hasServer) 650 { 651 CEventClient event(getType(),EVENT_ID_POST_PROCESS) ; 652 if (client->isServerLeader()) 653 { 654 CMessage msg ; 655 msg<<this->getId(); 656 event.push(client->getServerLeader(),1,msg) ; 657 client->sendEvent(event) ; 658 } 659 else client->sendEvent(event) ; 660 } 661 } 662 663 //! Server side: Receive a message to do some post processing 664 void CContext::recvPostProcessing(CEventServer& event) 665 { 666 CBufferIn* buffer=event.subEvents.begin()->buffer; 667 string id; 668 *buffer>>id; 669 get(id)->recvPostProcessing(*buffer); 670 } 671 672 //! Server side: Receive a message to do some post processing 673 void CContext::recvPostProcessing(CBufferIn& buffer) 674 { 675 postProcessing(); 676 } 677 678 /*! 679 \brief Do some simple post processings after parsing xml file 680 After the xml file (iodef.xml) is parsed, it is necessary to build all relations among 681 created object, e.g: inhertance among fields, domain, axis. After that, all fiels as well as their parents (reference fields), 682 which will be written out into netcdf files, are processed 683 */ 684 void CContext::postProcessing() 685 { 686 if (isPostProcessed) return; 687 688 this->solveCalendar(); 689 690 // Solve calendar for both side: client and server 691 this->solveCalendar(); 692 693 // Find all inheritance in xml structure 694 this->solveAllInheritance(); 695 696 //Initialisation du vecteur 'enabledFiles' contenant la liste des fichiers à sortir. 697 this->findEnabledFiles(); 698 699 // Find all enabled fields of each file 700 this->findAllEnabledFields(); 701 702 // Search and rebuild all reference object of enabled fields 703 this->solveAllRefOfEnabledFields(false); 704 isPostProcessed = true; 705 } 706 707 std::map<int, StdSize>& CContext::getDataSize() 708 { 709 std::set<StdString> domainIds; 710 711 // Find all reference domain and axis of all active fields 712 int numEnabledFiles = this->enabledFiles.size(); 713 for (int i = 0; i < numEnabledFiles; ++i) 714 { 715 std::vector<CField*> enabledFields = this->enabledFiles[i]->getEnabledFields(); 716 int numEnabledFields = enabledFields.size(); 717 for (int j = 0; j < numEnabledFields; ++j) 718 { 719 const std::pair<StdString, StdString>& prDomAxisId = enabledFields[j]->getDomainAxisIds(); 720 const std::map<int, StdSize> mapSize = enabledFields[j]->getGridDataSize(); 721 if (dataSize_.empty()) 722 { 723 dataSize_ = mapSize; 724 domainIds.insert(prDomAxisId.first); 725 } 726 else 727 { 728 if (domainIds.find(prDomAxisId.first) == domainIds.end()) 729 { 730 std::map<int, StdSize>::const_iterator it = mapSize.begin(), itE = mapSize.end(); 731 for (; it != itE; ++it) 732 { 733 if (0 < dataSize_.count(it->first)) dataSize_[it->first] += it->second; 734 else dataSize_.insert(make_pair(it->first, it->second)); 735 } 736 } 737 738 } 739 740 } 741 } 742 743 return dataSize_; 744 } 745 746 //! Client side: Send infomation of active files (files are enabled to write out) 747 void CContext::sendEnabledFiles() 748 { 749 int size = this->enabledFiles.size(); 750 751 // In a context, each type has a root definition, e.g: axis, domain, field. 752 // Every object must be a child of one of these root definition. In this case 753 // all new file objects created on server must be children of the root "file_definition" 754 StdString fileDefRoot("file_definition"); 755 CFileGroup* cfgrpPtr = CFileGroup::get(fileDefRoot); 756 757 for (int i = 0; i < size; ++i) 758 { 759 cfgrpPtr->sendCreateChild(this->enabledFiles[i]->getId()); 760 this->enabledFiles[i]->sendAllAttributesToServer(); 761 this->enabledFiles[i]->sendAddAllVariables(); 762 } 763 } 764 765 //! Client side: Send information of active fields (ones are written onto files) 766 void CContext::sendEnabledFields() 767 { 768 int size = this->enabledFiles.size(); 769 for (int i = 0; i < size; ++i) 770 { 771 this->enabledFiles[i]->sendEnabledFields(); 772 } 773 } 774 775 //! Client side: Send information of reference grid of active fields 776 void CContext::sendRefGrid() 777 { 778 std::set<StdString> gridIds; 779 int sizeFile = this->enabledFiles.size(); 780 CFile* filePtr(NULL); 781 782 // Firstly, find all reference grids of all active fields 783 for (int i = 0; i < sizeFile; ++i) 784 { 785 filePtr = this->enabledFiles[i]; 786 std::vector<CField*> enabledFields = filePtr->getEnabledFields(); 787 int sizeField = enabledFields.size(); 788 for (int numField = 0; numField < sizeField; ++numField) 789 { 790 if (0 != enabledFields[numField]->getRelGrid()) 791 gridIds.insert(CGrid::get(enabledFields[numField]->getRelGrid())->getId()); 792 } 793 } 794 795 // Create all reference grids on server side 796 StdString gridDefRoot("grid_definition"); 797 CGridGroup* gridPtr = CGridGroup::get(gridDefRoot); 798 std::set<StdString>::const_iterator it, itE = gridIds.end(); 799 for (it = gridIds.begin(); it != itE; ++it) 800 { 801 gridPtr->sendCreateChild(*it); 802 CGrid::get(*it)->sendAllAttributesToServer(); 803 } 804 } 805 806 807 //! Client side: Send information of reference domain and axis of active fields 808 void CContext::sendRefDomainsAxis() 809 { 810 std::set<StdString> domainIds; 811 std::set<StdString> axisIds; 812 813 // Find all reference domain and axis of all active fields 814 int numEnabledFiles = this->enabledFiles.size(); 815 for (int i = 0; i < numEnabledFiles; ++i) 816 { 817 std::vector<CField*> enabledFields = this->enabledFiles[i]->getEnabledFields(); 818 int numEnabledFields = enabledFields.size(); 819 for (int j = 0; j < numEnabledFields; ++j) 820 { 821 const std::pair<StdString, StdString>& prDomAxisId = enabledFields[j]->getDomainAxisIds(); 822 domainIds.insert(prDomAxisId.first); 823 axisIds.insert(prDomAxisId.second); 824 } 825 } 826 827 // Create all reference axis on server side 828 std::set<StdString>::iterator itDom, itAxis; 829 std::set<StdString>::const_iterator itE; 830 831 StdString axiDefRoot("axis_definition"); 832 CAxisGroup* axisPtr = CAxisGroup::get(axiDefRoot); 833 itE = axisIds.end(); 834 for (itAxis = axisIds.begin(); itAxis != itE; ++itAxis) 835 { 836 axisPtr->sendCreateChild(*itAxis); 837 CAxis::get(*itAxis)->sendAllAttributesToServer(); 838 } 839 840 // Create all reference domains on server side 841 StdString domDefRoot("domain_definition"); 842 CDomainGroup* domPtr = CDomainGroup::get(domDefRoot); 843 itE = domainIds.end(); 844 for (itDom = domainIds.begin(); itDom != itE; ++itDom) 845 { 846 domPtr->sendCreateChild(*itDom); 847 CDomain::get(*itDom)->sendAllAttributesToServer(); 848 } 849 } 850 851 //! Update calendar in each time step 515 852 void CContext::updateCalendar(int step) 516 853 { … … 519 856 info(50)<<"updateCalendar : after : "<<calendar->getCurrentDate()<<endl ; 520 857 } 521 858 859 //! Server side: Create header of netcdf file 522 860 void CContext::createFileHeader(void ) 523 861 { 524 862 vector<CFile*>::const_iterator it ; 525 863 526 864 for (it=enabledFiles.begin(); it != enabledFiles.end(); it++) 527 865 { 528 866 (*it)->initFile(); 529 867 } 530 } 531 868 } 869 870 //! Get current context 532 871 CContext* CContext::getCurrent(void) 533 872 { 534 873 return CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId()).get() ; 535 874 } 536 875 876 /*! 877 \brief Set context with an id be the current context 878 \param [in] id identity of context to be set to current 879 */ 537 880 void CContext::setCurrent(const string& id) 538 881 { … … 540 883 CGroupFactory::SetCurrentContextId(id); 541 884 } 542 885 886 /*! 887 \brief Create a context with specific id 888 \param [in] id identity of new context 889 \return pointer to the new context or already-existed one with identity id 890 */ 543 891 CContext* CContext::create(const StdString& id) 544 892 { 545 893 CContext::setCurrent(id) ; 546 894 547 895 bool hasctxt = CContext::has(id); 548 896 CContext* context = CObjectFactory::CreateObject<CContext>(id).get(); -
XIOS/trunk/src/node/context.hpp
r501 r509 18 18 class CContextClient ; 19 19 class CContextServer ; 20 21 20 21 22 22 /// ////////////////////// Déclarations ////////////////////// /// 23 23 class CContextGroup; … … 33 33 34 34 ///-------------------------------------------------------------- 35 35 /*! 36 \class CContext 37 This class corresponds to the concrete presentation of context in xml file and in play an essential role in XIOS 38 Each object of this class contains all root definition of elements: files, fiels, domains, axis, etc, ... from which 39 we can have access to each element. 40 In fact, every thing must a be inside a particuliar context. After the xml file (iodef.xml) is parsed, 41 object of the class is created and its contains all information of other elements in the xml file. 42 */ 36 43 class CContext 37 44 : public CObjectTemplate<CContext> … … 42 49 { 43 50 EVENT_ID_CLOSE_DEFINITION,EVENT_ID_UPDATE_CALENDAR, 44 EVENT_ID_CREATE_FILE_HEADER,EVENT_ID_CONTEXT_FINALIZE 51 EVENT_ID_CREATE_FILE_HEADER,EVENT_ID_CONTEXT_FINALIZE, 52 EVENT_ID_POST_PROCESS 45 53 } ; 46 54 47 55 /// typedef /// 48 56 typedef CObjectTemplate<CContext> SuperClass; … … 70 78 71 79 public : 72 80 73 81 /// Mutateurs /// 74 82 void setCalendar(boost::shared_ptr<CCalendar> newCalendar); 75 83 76 84 /// Accesseurs /// 77 85 boost::shared_ptr<CCalendar> getCalendar(void) const; 78 86 79 /// Accesseurs statiques /// 80 static StdString GetName(void); 81 static StdString GetDefName(void); 82 static ENodeType GetType(void); 83 84 static CContextGroup* GetContextGroup(void); 85 86 public : 87 88 /// Traitements /// 89 virtual void solveDescInheritance(bool apply, const CAttributeMap * const parent = 0); 90 void solveFieldRefInheritance(bool apply); 91 void solveCalendar(void); 92 93 /// Autres méthodes statiques /// 94 static void ShowTree(StdOStream & out = std::clog); 95 static void CleanTree(void); 96 97 /// Test /// 98 virtual bool hasChild(void) const; 99 87 public : 88 // Initialize server or client 89 void initServer(MPI_Comm intraComm, MPI_Comm interComm) ; 90 void initClient(MPI_Comm intraComm, MPI_Comm interComm) ; 91 bool isInitialized(void) ; 92 93 // Put sever or client into loop state 100 94 bool eventLoop(void) ; 101 95 bool serverLoop(void) ; 102 96 void clientLoop(void) ; 103 void initServer(MPI_Comm intraComm, MPI_Comm interComm) ; 104 void initClient(MPI_Comm intraComm, MPI_Comm interComm) ; 105 bool isInitialized(void) ; 106 CContextServer* server ; 107 CContextClient* client ; 108 bool hasClient ; 109 bool hasServer ; 97 98 // Process all information of calendar 99 void solveCalendar(void); 100 101 // Finalize a context 110 102 void finalize(void) ; 111 103 void closeDefinition(void) ; 104 105 // Some functions to process context 112 106 void findAllEnabledFields(void); 113 107 void processEnabledFiles(void) ; 114 void solveAllGridRef(void);115 void solveAllOperation(void);116 void solveAllExpression(void);117 108 void solveAllInheritance(bool apply=true) ; 118 109 void findEnabledFiles(void); … … 120 111 void updateCalendar(int step) ; 121 112 void createFileHeader(void ) ; 122 // dispatch event 123 static bool dispatchEvent(CEventServer& event) ; 113 void solveAllRefOfEnabledFields(bool sendToServer); 114 void buildAllExpressionOfEnabledFields(); 115 void postProcessing(); 116 117 std::map<int, StdSize>& getDataSize(); 118 void setClientServerBuffer(); 119 120 // Send context close definition 124 121 void sendCloseDefinition(void) ; 122 // There are something to send on closing context defintion 125 123 void sendUpdateCalendar(int step) ; 126 124 void sendCreateFileHeader(void) ; 125 void sendEnabledFiles(); 126 void sendEnabledFields(); 127 void sendRefDomainsAxis(); 128 void sendRefGrid(); 129 void sendPostProcessing(); 130 131 // Client side: Receive and process messages 127 132 static void recvUpdateCalendar(CEventServer& event) ; 128 133 void recvUpdateCalendar(CBufferIn& buffer) ; … … 130 135 static void recvCreateFileHeader(CEventServer& event) ; 131 136 void recvCreateFileHeader(CBufferIn& buffer) ; 132 static CContext* getCurrent(void) ; 133 static CContextGroup* getRoot(void) ; 134 static void setCurrent(const string& id) ; 135 static CContext* create(const string& id = "") ; 136 137 public : 138 139 /// Autres /// 137 static void recvSolveInheritanceContext(CEventServer& event); 138 void recvSolveInheritanceContext(CBufferIn& buffer); 139 static void recvPostProcessing(CEventServer& event); 140 void recvPostProcessing(CBufferIn& buffer); 141 142 // dispatch event 143 static bool dispatchEvent(CEventServer& event) ; 144 145 public: 146 // Get current context 147 static CContext* getCurrent(void); 148 149 // Get context root 150 static CContextGroup* getRoot(void); 151 152 // Set current context 153 static void setCurrent(const string& id); 154 155 // Create new context 156 static CContext* create(const string& id = ""); 157 158 /// Accesseurs statiques /// 159 static StdString GetName(void); 160 static StdString GetDefName(void); 161 static ENodeType GetType(void); 162 163 static CContextGroup* GetContextGroup(void); 164 165 // Some functions to visualize structure of current context 166 static void ShowTree(StdOStream & out = std::clog); 167 static void CleanTree(void); 168 169 public : 170 // Parse xml node and write all info into context 140 171 virtual void parse(xml::CXMLNode & node); 141 172 173 // Visualize a context 142 174 virtual StdString toString(void) const; 143 // virtual void toBinary (StdOStream & os) const; 144 // virtual void fromBinary(StdIStream & is); 145 146 public : 147 148 boost::shared_ptr<CCalendar> calendar; 149 175 176 177 // Solve all inheritance relation in current context 178 virtual void solveDescInheritance(bool apply, const CAttributeMap * const parent = 0); 179 180 // Verify if all root definition in a context have children 181 virtual bool hasChild(void) const; 182 183 public : 184 // Calendar of context 185 boost::shared_ptr<CCalendar> calendar; 186 187 // List of all enabled files (files on which fields are written) 150 188 std::vector<CFile*> enabledFiles; 189 190 // Context root 151 191 static shared_ptr<CContextGroup> root ; 152 192 193 // Determine context on client or not 194 bool hasClient ; 195 196 // Determine context on server or not 197 bool hasServer ; 198 199 // Concrete context server 200 CContextServer* server ; 201 202 // Concrete contex client 203 CContextClient* client ; 204 205 private: 206 bool isPostProcessed; 207 std::map<int, StdSize> dataSize_; 208 209 210 public: // Some function maybe removed in the near future 211 // virtual void toBinary (StdOStream & os) const; 212 // virtual void fromBinary(StdIStream & is); 213 // void solveAllGridRef(void); 214 // void solveAllOperation(void); 215 // void solveAllExpression(void); 216 // void solveFieldRefInheritance(bool apply); 153 217 154 218 }; // class CContext -
XIOS/trunk/src/node/domain.cpp
r501 r509 16 16 17 17 namespace xios { 18 18 19 19 /// ////////////////////// Définitions ////////////////////// /// 20 20 21 21 CDomain::CDomain(void) 22 22 : CObjectTemplate<CDomain>(), CDomainAttributes() 23 , isChecked(false), relFiles()23 , isChecked(false), relFiles(), isClientChecked(false) 24 24 { /* Ne rien faire de plus */ } 25 25 26 26 CDomain::CDomain(const StdString & id) 27 27 : CObjectTemplate<CDomain>(id), CDomainAttributes() 28 , isChecked(false), relFiles() 28 , isChecked(false), relFiles(), isClientChecked(false) 29 29 { /* Ne rien faire de plus */ } 30 30 31 31 CDomain::~CDomain(void) 32 { 32 { 33 33 } 34 34 … … 37 37 const std::set<StdString> & CDomain::getRelFiles(void) const 38 38 { 39 return (this->relFiles); 40 } 41 42 //---------------------------------------------------------------- 43 39 return (this->relFiles); 40 } 41 42 //---------------------------------------------------------------- 43 44 44 bool CDomain::hasZoom(void) const 45 45 { 46 return ((this->zoom_ni.getValue() != this->ni_glo.getValue()) && 46 return ((this->zoom_ni.getValue() != this->ni_glo.getValue()) && 47 47 (this->zoom_nj.getValue() != this->nj_glo.getValue())); 48 48 } 49 50 //---------------------------------------------------------------- 51 49 50 //---------------------------------------------------------------- 51 52 52 bool CDomain::isEmpty(void) const 53 53 { 54 return ((this->zoom_ni_srv == 0) || 54 return ((this->zoom_ni_srv == 0) || 55 55 (this->zoom_nj_srv == 0)); 56 56 } … … 86 86 << "[ Id = " << this->getId() << " ] " 87 87 << "The global domain is badly defined," 88 << " check the \'ni_glo\' value !") 88 << " check the \'ni_glo\' value !") 89 89 } 90 90 nj_glo=ni_glo ; … … 111 111 ibegin=1 ; 112 112 iend=1 ; 113 113 114 114 } 115 115 else if ((ni_glo.isEmpty() || ni_glo.getValue() <= 0 ) || … … 119 119 << "[ Id = " << this->getId() << " ] " 120 120 << "The global domain is badly defined," 121 << " check the \'ni_glo\' et \'nj_glo\' values !") 121 << " check the \'ni_glo\' et \'nj_glo\' values !") 122 122 } 123 123 checkLocalIDomain() ; 124 124 checkLocalJDomain() ; 125 125 126 126 if (i_index.isEmpty()) 127 127 { 128 128 i_index.resize(ni,nj) ; 129 129 for(int j=0;j<nj;j++) 130 for(int i=0;i<ni;i++) i_index(i,j)=i ; 130 for(int i=0;i<ni;i++) i_index(i,j)=i ; 131 131 } 132 132 133 133 if (j_index.isEmpty()) 134 134 { 135 135 j_index.resize(ni,nj) ; 136 136 for(int j=0;j<nj;j++) 137 for(int i=0;i<ni;i++) j_index(i,j)=j ; 137 for(int i=0;i<ni;i++) j_index(i,j)=j ; 138 138 } 139 139 140 140 } 141 141 … … 211 211 << "Domain is wrong defined," 212 212 << " Check the values : nj, nj_glo, jbegin, jend") ; 213 213 214 214 ibegin_client=ibegin ; iend_client=iend ; ni_client=ni ; 215 215 jbegin_client=jbegin ; jend_client=jend ; nj_client=nj ; … … 221 221 { 222 222 using namespace std; 223 223 224 224 int ibegin_mask = 0, 225 225 jbegin_mask = 0, 226 226 iend_mask = iend.getValue() - ibegin.getValue(), 227 227 jend_mask = jend.getValue() - jbegin.getValue(); 228 228 229 229 if (!zoom_ibegin.isEmpty()) 230 230 { 231 231 int zoom_iend = zoom_ibegin.getValue() + zoom_ni.getValue() - 1; 232 232 int zoom_jend = zoom_jbegin.getValue() + zoom_nj.getValue() - 1; 233 233 234 234 ibegin_mask = max (ibegin.getValue(), zoom_ibegin.getValue()); 235 235 jbegin_mask = max (jbegin.getValue(), zoom_jbegin.getValue()); 236 236 iend_mask = min (iend.getValue(), zoom_iend); 237 237 jend_mask = min (jend.getValue(), zoom_jend); 238 238 239 239 ibegin_mask -= ibegin.getValue(); 240 240 jbegin_mask -= jbegin.getValue(); … … 242 242 jend_mask -= jbegin.getValue(); 243 243 } 244 244 245 245 246 246 if (!mask.isEmpty()) … … 251 251 <<"the mask has not the same size than the local domain"<<endl 252 252 <<"Local size is "<<ni<<"x"<<nj<<endl 253 <<"Mask size is "<<mask.extent(0)<<"x"<<mask.extent(1)); 253 <<"Mask size is "<<mask.extent(0)<<"x"<<mask.extent(1)); 254 254 for (int i = 0; i < ni; i++) 255 255 { … … 283 283 284 284 void CDomain::checkDomainData(void) 285 { 285 { 286 286 if (!data_dim.isEmpty() && 287 287 !(data_dim.getValue() == 1 || data_dim.getValue() == 2)) … … 378 378 data_i_index.resize(dni) ; 379 379 data_j_index.resize(dni) ; 380 380 381 381 data_n_index.setValue(dni); 382 382 383 383 for(int count = 0, j = 0; j < data_nj.getValue(); j++) 384 384 { … … 394 394 395 395 //---------------------------------------------------------------- 396 396 397 397 void CDomain::completeLonLatClient(void) 398 398 { … … 402 402 CArray<double,2> bounds_lon_temp(nvertex,ni*nj) ; 403 403 CArray<double,2> bounds_lat_temp(nvertex,ni*nj) ; 404 404 405 405 if (type.isEmpty()) 406 406 { 407 if ( lonvalue.numElements() == ni*nj && latvalue.numElements() == ni*nj ) 407 if ( lonvalue.numElements() == ni*nj && latvalue.numElements() == ni*nj ) 408 408 { 409 409 type.setValue(type_attr::curvilinear) ; 410 410 isCurvilinear=true ; 411 411 } 412 else if ( lonvalue.numElements() == ni && latvalue.numElements() == nj ) 412 else if ( lonvalue.numElements() == ni && latvalue.numElements() == nj ) 413 413 { 414 414 type.setValue(type_attr::regular) ; … … 429 429 { 430 430 for(j=0;j<nj;j++) 431 for(i=0;i<ni;i++) 431 for(i=0;i<ni;i++) 432 432 { 433 433 k=j*ni+i ; … … 436 436 if (hasBounds) 437 437 { 438 for(int n=0;n<nvertex;n++) 438 for(int n=0;n<nvertex;n++) 439 439 { 440 440 bounds_lon_temp(n,k)=bounds_lon(n,i) ; … … 444 444 } 445 445 } 446 446 447 447 StdSize dm = zoom_ni_client * zoom_nj_client; 448 448 449 449 lonvalue.resize(dm); 450 450 latvalue.resize(dm); 451 451 452 452 for (int i = 0; i < zoom_ni_client; i++) 453 453 { 454 454 for (int j = 0; j < zoom_nj_client; j++) 455 455 { 456 lonvalue(i + j * zoom_ni_client) = lonvalue_temp( (i + zoom_ibegin_client-ibegin) + (j + zoom_jbegin_client -jbegin)*ni ); 456 lonvalue(i + j * zoom_ni_client) = lonvalue_temp( (i + zoom_ibegin_client-ibegin) + (j + zoom_jbegin_client -jbegin)*ni ); 457 457 latvalue(i + j * zoom_ni_client) = latvalue_temp( (i + zoom_ibegin_client - ibegin)+(j + zoom_jbegin_client - jbegin)*ni ); 458 458 if (hasBounds) 459 459 { 460 for(int n=0;n<nvertex;n++) 460 for(int n=0;n<nvertex;n++) 461 461 { 462 bounds_lon(n,i + j * zoom_ni_client) = bounds_lon_temp( n, (i + zoom_ibegin_client - ibegin) + (j + zoom_jbegin_client -jbegin)*ni ); 462 bounds_lon(n,i + j * zoom_ni_client) = bounds_lon_temp( n, (i + zoom_ibegin_client - ibegin) + (j + zoom_jbegin_client -jbegin)*ni ); 463 463 bounds_lat(n,i + j * zoom_ni_client) = bounds_lat_temp( n, (i + zoom_ibegin_client - ibegin)+(j + zoom_jbegin_client -jbegin)*ni ); 464 464 } … … 467 467 } 468 468 } 469 469 470 470 471 471 //---------------------------------------------------------------- … … 487 487 int zoom_iend = zoom_ibegin + zoom_ni - 1; 488 488 int zoom_jend = zoom_jbegin + zoom_nj - 1; 489 489 490 490 if (zoom_ibegin < 1 || zoom_jbegin < 1 || zoom_iend > ni_glo || zoom_jend > nj_glo) 491 491 ERROR("CDomain::checkZoom(void)", … … 496 496 else 497 497 { 498 zoom_ni = ni_glo; 498 zoom_ni = ni_glo; 499 499 zoom_nj = nj_glo; 500 500 zoom_ibegin = 1; 501 501 zoom_jbegin = 1; 502 502 } 503 503 504 504 // compute client zoom indices 505 505 … … 510 510 if (zoom_ni_client<0) zoom_ni_client=0 ; 511 511 512 512 513 513 int zoom_jend=zoom_jbegin+zoom_nj-1 ; 514 514 zoom_jbegin_client = jbegin_client > zoom_jbegin ? jbegin_client : zoom_jbegin ; … … 518 518 519 519 } 520 520 521 521 void CDomain::checkBounds(void) 522 522 { … … 524 524 { 525 525 hasBounds=true ; 526 526 527 527 } 528 else 528 else 529 529 { 530 530 hasBounds=false; … … 532 532 } 533 533 } 534 535 //---------------------------------------------------------------- 536 537 void CDomain::checkAttributes(void) 538 { 539 if (this->isChecked) return; 540 CContext* context=CContext::getCurrent() ; 534 535 //---------------------------------------------------------------- 536 // Divide function checkAttributes into 2 seperate ones 537 // This function only checks all attributes of current domain 538 void CDomain::checkAttributesOnClient() 539 { 540 if (this->isClientChecked) return; 541 CContext* context=CContext::getCurrent(); 541 542 542 543 this->checkDomain(); 543 544 this->checkZoom(); 544 545 this->checkBounds(); 545 546 546 547 if (context->hasClient) 547 548 { // CÃŽté client uniquement … … 550 551 this->checkCompression(); 551 552 this->completeLonLatClient(); 553 this->computeConnectedServer() ; 552 554 } 553 555 else … … 556 558 // ne sert plus // this->completeLonLatServer(); 557 559 } 558 560 561 this->isClientChecked = true; 562 } 563 564 // Send all checked attributes to server 565 void CDomain::sendCheckedAttributes() 566 { 567 if (!this->isClientChecked) checkAttributesOnClient(); 568 CContext* context=CContext::getCurrent() ; 569 570 if (this->isChecked) return; 571 if (context->hasClient) 572 { 573 sendServerAttribut() ; 574 sendLonLat() ; 575 } 576 577 this->isChecked = true; 578 } 579 580 void CDomain::checkAttributes(void) 581 { 582 if (this->isChecked) return; 583 CContext* context=CContext::getCurrent() ; 584 585 this->checkDomain(); 586 this->checkZoom(); 587 this->checkBounds(); 588 589 if (context->hasClient) 590 { // CÃŽté client uniquement 591 this->checkMask(); 592 this->checkDomainData(); 593 this->checkCompression(); 594 this->completeLonLatClient(); 595 } 596 else 597 { // CÃŽté serveur uniquement 598 // if (!this->isEmpty()) 599 // ne sert plus // this->completeLonLatServer(); 600 } 601 559 602 if (context->hasClient) 560 603 { … … 563 606 sendLonLat() ; 564 607 } 565 608 566 609 this->isChecked = true; 567 610 } 568 611 569 612 void CDomain::sendServerAttribut(void) 570 613 { … … 572 615 int ibegin_srv=1 ; 573 616 int iend_srv=ni_glo.getValue() ; 574 617 575 618 int nj_srv ; 576 619 int jbegin_srv ; 577 620 int jend_srv ; 578 621 579 622 CContext* context=CContext::getCurrent() ; 580 623 CContextClient* client=context->client ; 581 624 int nbServer=client->serverSize ; 582 625 int serverRank=client->getServerLeader() ; 583 626 584 627 jend_srv=0 ; 585 628 for(int i=0;i<=serverRank;i++) … … 590 633 jend_srv=jbegin_srv+nj_srv-1 ; 591 634 } 592 593 CEventClient event(getType(),EVENT_ID_SERVER_ATTRIBUT) ; 635 636 CEventClient event(getType(),EVENT_ID_SERVER_ATTRIBUT) ; 594 637 if (client->isServerLeader()) 595 638 { … … 606 649 { 607 650 int i,j,i_ind,j_ind ; 608 651 609 652 ibegin_client=ibegin ; iend_client=iend ; ni_client=ni ; 610 653 jbegin_client=jbegin ; jend_client=jend ; nj_client=nj ; 611 654 612 655 CContext* context = CContext::getCurrent() ; 613 656 CContextClient* client=context->client ; … … 617 660 int zoom_iend=zoom_ibegin+zoom_ni-1 ; 618 661 int zoom_jend=zoom_jbegin+zoom_nj-1 ; 619 662 620 663 int blockSize=nj_glo/nbServer ; 621 664 int ns=nj_glo%nbServer ; 622 665 int pos=ns*(blockSize+1) ; 623 666 int serverNum ; 624 667 625 668 mapConnectedServer.resize(ni,nj) ; 626 669 vector<int> nbData(nbServer,0) ; 627 670 vector<int> indServer(nbServer,-1) ; 628 671 vector<bool> IsConnected(nbServer,false) ; 629 672 630 673 for(j=0;j<nj;j++) 631 674 for(i=0;i<ni;i++) … … 633 676 i_ind=ibegin+i_index(i,j)-1 ; 634 677 j_ind=jbegin+j_index(i,j)-1 ; 635 678 636 679 if (j_ind<pos) serverNum=j_ind/(blockSize+1) ; 637 680 else serverNum=ns+(j_ind-pos)/blockSize ; 638 681 IsConnected[serverNum]=true ; 639 682 640 683 if (i_ind >= zoom_ibegin-1 && i_ind <= zoom_iend-1 && j_ind >= zoom_jbegin-1 && j_ind <= zoom_jend-1) 641 684 { … … 647 690 648 691 649 for(serverNum=0 ; serverNum<nbServer ; serverNum++) 692 for(serverNum=0 ; serverNum<nbServer ; serverNum++) 650 693 if (IsConnected[serverNum]) 651 694 { … … 655 698 nbDataSrv.push_back(nbData[serverNum]) ; 656 699 } 657 700 658 701 i_indSrv.resize(connectedServer.size()) ; 659 702 j_indSrv.resize(connectedServer.size()) ; 660 703 661 704 for(j=0;j<nj;j++) 662 for(i=0;i<ni;i++) 705 for(i=0;i<ni;i++) 663 706 { 664 707 if (mapConnectedServer(i,j)>=0) … … 670 713 } 671 714 } 672 715 673 716 int nbConnectedServer=connectedServer.size() ; 674 717 … … 677 720 int* sendBuff=new int[nbConnectedServer] ; 678 721 valarray<int> nbClient(0,client->serverSize) ; 679 722 680 723 for(int n=0;n<nbConnectedServer;n++) sendBuff[n]=connectedServer[n] ; 681 724 682 725 // get connected server for everybody 683 726 MPI_Allgather(&nbConnectedServer,1,MPI_INT,recvCount,1,MPI_INT,client->intraComm) ; 684 727 685 728 displ[0]=0 ; 686 729 for(int n=1;n<client->clientSize;n++) displ[n]=displ[n-1]+recvCount[n-1] ; 687 730 int recvSize=displ[client->clientSize-1]+recvCount[client->clientSize-1] ; 688 731 int* recvBuff=new int[recvSize] ; 689 690 732 733 691 734 MPI_Allgatherv(sendBuff,nbConnectedServer,MPI_INT,recvBuff,recvCount,displ,MPI_INT,client->intraComm) ; 692 735 for(int n=0;n<recvSize;n++) nbClient[recvBuff[n]]++ ; 693 736 694 737 for(int n=0;n<nbConnectedServer;n++) nbSenders.push_back(nbClient[connectedServer[n]]) ; 695 738 696 739 delete [] recvCount ; 697 740 delete [] displ ; … … 708 751 // send lon lat for each connected server 709 752 CEventClient event(getType(),EVENT_ID_LON_LAT) ; 710 711 list<shared_ptr<CMessage> > list_msg ; 753 754 list<shared_ptr<CMessage> > list_msg ; 712 755 list< CArray<int,1>* > list_indi,list_indj ; 713 756 list< CArray<double,1>* >list_lon,list_lat ; … … 723 766 CArray<double,2> boundslon(nvertex,nbData) ; 724 767 CArray<double,2> boundslat(nvertex,nbData) ; 725 726 for(n=0;n<nbData;n++) 768 769 for(n=0;n<nbData;n++) 727 770 { 728 771 i=i_indSrv[ns][n] ; 729 772 j=j_indSrv[ns][n] ; 730 773 ind=(i-(zoom_ibegin_client-1))+(j-(zoom_jbegin_client-1))*zoom_ni_client ; 731 774 732 775 lon(n)=lonvalue(ind) ; 733 776 lat(n)=latvalue(ind) ; … … 743 786 indj(n)=jbegin+j_index(i-ibegin+1,j-jbegin+1)-1 ; 744 787 } 745 788 746 789 list_indi.push_back(new CArray<int,1>(indi.copy())) ; 747 790 list_indj.push_back(new CArray<int,1>(indj.copy())) ; … … 761 804 762 805 client->sendEvent(event) ; 763 764 806 807 765 808 for(list<CArray<int,1>* >::iterator it=list_indi.begin();it!=list_indi.end();it++) delete *it; 766 809 for(list<CArray<int,1>* >::iterator it=list_indj.begin();it!=list_indj.end();it++) delete *it; … … 768 811 for(list<CArray<double,1>* >::iterator it=list_lat.begin();it!=list_lat.end();it++) delete *it; 769 812 if (hasBounds) for(list<CArray<double,2>* >::iterator it=list_boundslon.begin();it!=list_boundslon.end();it++) delete *it; 770 if (hasBounds) for(list<CArray<double,2>* >::iterator it=list_boundslat.begin();it!=list_boundslat.end();it++) delete *it; 771 813 if (hasBounds) for(list<CArray<double,2>* >::iterator it=list_boundslat.begin();it!=list_boundslat.end();it++) delete *it; 814 772 815 } 773 774 816 817 775 818 bool CDomain::dispatchEvent(CEventServer& event) 776 819 { 777 820 778 821 if (SuperClass::dispatchEvent(event)) return true ; 779 822 else … … 796 839 } 797 840 } 798 841 799 842 void CDomain::recvServerAttribut(CEventServer& event) 800 843 { … … 804 847 get(domainId)->recvServerAttribut(*buffer) ; 805 848 } 806 849 807 850 void CDomain::recvServerAttribut(CBufferIn& buffer) 808 851 { … … 811 854 812 855 buffer>>ni_srv>>ibegin_srv>>iend_srv>>nj_srv>>jbegin_srv>>jend_srv; 813 814 856 857 815 858 zoom_ibegin_srv = zoom_ibegin.getValue() > ibegin_srv ? zoom_ibegin.getValue() : ibegin_srv ; 816 859 zoom_iend_srv = zoom_iend < iend_srv ? zoom_iend : iend_srv ; 817 860 zoom_ni_srv=zoom_iend_srv-zoom_ibegin_srv+1 ; 818 861 819 862 zoom_jbegin_srv = zoom_jbegin.getValue() > jbegin_srv ? zoom_jbegin.getValue() : jbegin_srv ; 820 863 zoom_jend_srv = zoom_jend < jend_srv ? zoom_jend : jend_srv ; 821 864 zoom_nj_srv=zoom_jend_srv-zoom_jbegin_srv+1 ; 822 865 823 if (zoom_ni_srv<=0 || zoom_nj_srv<=0) 866 if (zoom_ni_srv<=0 || zoom_nj_srv<=0) 824 867 { 825 868 zoom_ibegin_srv=1 ; zoom_iend_srv=0 ; zoom_ni_srv=0 ; … … 830 873 latvalue_srv.resize(zoom_ni_srv*zoom_nj_srv) ; 831 874 latvalue_srv = 0. ; 832 if (hasBounds) 875 if (hasBounds) 833 876 { 834 877 bounds_lon_srv.resize(nvertex,zoom_ni_srv*zoom_nj_srv) ; … … 838 881 } 839 882 } 840 883 841 884 void CDomain::recvLonLat(CEventServer& event) 842 885 { … … 850 893 } 851 894 } 852 895 853 896 void CDomain::recvLonLat(CBufferIn& buffer) 854 897 { … … 859 902 CArray<double,2> boundslon ; 860 903 CArray<double,2> boundslat ; 861 904 862 905 int type_int ; 863 906 buffer>>type_int>>isCurvilinear>>indi>>indj>>lon>>lat ; … … 872 915 lonvalue_srv(ind_srv)=lon(ind) ; 873 916 latvalue_srv(ind_srv)=lat(ind) ; 874 if (hasBounds) 875 { 876 for(int nv=0;nv<nvertex;nv++) 917 if (hasBounds) 918 { 919 for(int nv=0;nv<nvertex;nv++) 877 920 { 878 921 bounds_lon_srv(nv,ind_srv)=boundslon(nv,ind) ; … … 883 926 } 884 927 //---------------------------------------------------------------- 885 886 887 928 929 930 888 931 ///--------------------------------------------------------------- 889 932 -
XIOS/trunk/src/node/domain.hpp
r501 r509 15 15 16 16 namespace xios { 17 17 18 18 /// ////////////////////// Déclarations ////////////////////// /// 19 19 … … 39 39 EVENT_ID_SERVER_ATTRIBUT, EVENT_ID_LON_LAT 40 40 } ; 41 41 42 42 /// typedef /// 43 43 typedef CObjectTemplate<CDomain> SuperClass; … … 58 58 void checkAttributes(void); 59 59 60 void checkAttributesOnClient(); 61 62 void sendCheckedAttributes(); 63 60 64 private : 61 65 … … 68 72 void checkDomainData(void); 69 73 void checkCompression(void); 70 74 71 75 void checkZoom(void); 72 76 void checkBounds(void); … … 74 78 75 79 public : 76 80 77 81 /// Autres /// 78 82 … … 84 88 bool hasZoom(void) const; 85 89 bool isEmpty(void) const; 86 87 90 91 88 92 int ni_client,ibegin_client,iend_client ; 89 93 int zoom_ni_client,zoom_ibegin_client,zoom_iend_client ; … … 100 104 CArray<double, 1> lonvalue_srv, latvalue_srv ; 101 105 CArray<double, 2> bounds_lon_srv, bounds_lat_srv ; 102 103 104 vector<int> connectedServer ; // list of connected server 106 107 108 vector<int> connectedServer ; // list of connected server 105 109 vector<int> nbSenders ; // for each communication with a server, number of communicating client 106 vector<int> nbDataSrv ; // size of data to send to each server 110 vector<int> nbDataSrv ; // size of data to send to each server 107 111 vector< vector<int> > i_indSrv ; // for each server, i global index to send 108 112 vector< vector<int> > j_indSrv ; // for each server, j global index to send 109 113 110 114 CArray<int,2> mapConnectedServer ; // (ni,nj) => mapped to connected server number, -1 if no server is target 111 115 112 116 // vector<int> ib_srv, ie_srv, in_srv ; 113 117 // vector<int> jb_srv, je_srv, jn_srv ; 114 118 115 119 public : 116 120 117 121 /// Mutateur /// 118 122 void addRelFile(const StdString & filename); … … 126 130 void recvLonLat(CBufferIn& buffer) ; 127 131 void recvServerAttribut(CBufferIn& buffer) ; 128 132 129 133 /// Destructeur /// 130 134 virtual ~CDomain(void); … … 133 137 static StdString GetName(void); 134 138 static StdString GetDefName(void); 135 139 136 140 static ENodeType GetType(void); 137 141 … … 144 148 bool isChecked; 145 149 std::set<StdString> relFiles; 150 bool isClientChecked; // Verify whether all attributes of domain on the client side is good 146 151 147 152 }; // class CDomain -
XIOS/trunk/src/node/field.cpp
r501 r509 14 14 15 15 namespace xios{ 16 16 17 17 /// ////////////////////// Définitions ////////////////////// /// 18 18 … … 26 26 , foperation(), hasInstantData(false), hasExpression(false) 27 27 , active(false) , hasOutputFile(false),hasFieldOut(false), slotUpdateDate(NULL) 28 , processed(false) 28 , processed(false), domAxisIds_("",""), areAllReferenceSolved(false), areAllExpressionBuilt(false) 29 29 { setVirtualVariableGroup() ; } 30 30 … … 38 38 , foperation(), hasInstantData(false), hasExpression(false) 39 39 , active(false), hasOutputFile(false), hasFieldOut(false), slotUpdateDate(NULL) 40 , processed(false) 40 , processed(false), domAxisIds_("",""), areAllReferenceSolved(false), areAllExpressionBuilt(false) 41 41 { setVirtualVariableGroup() ; } 42 42 … … 48 48 if (hasExpression) delete expression ; 49 49 if (slotUpdateDate!=NULL) delete slotUpdateDate ; 50 50 51 51 } 52 52 … … 55 55 56 56 void CField::setVirtualVariableGroup(CVariableGroup* newVVariableGroup) 57 { 58 this->vVariableGroup = newVVariableGroup; 59 } 60 57 { 58 this->vVariableGroup = newVVariableGroup; 59 } 60 61 61 void CField::setVirtualVariableGroup(void) 62 62 { 63 63 this->setVirtualVariableGroup(CVariableGroup::create()); 64 64 } 65 65 66 66 CVariableGroup* CField::getVirtualVariableGroup(void) const 67 67 { … … 69 69 } 70 70 71 71 72 72 std::vector<CVariable*> CField::getAllVariables(void) const 73 73 { 74 74 return (this->vVariableGroup->getAllChildren()); 75 75 } 76 76 77 77 void CField::solveDescInheritance(bool apply, const CAttributeMap * const parent) 78 78 { … … 88 88 { 89 89 const CDate opeDate = *last_operation + freq_operation; 90 const CDate writeDate = *last_Write + freq_write; 91 90 const CDate writeDate = *last_Write + freq_write; 91 92 92 if (opeDate <= currDate) 93 93 { … … 95 95 { 96 96 this->data.resize(this->grid->storeIndex[0] ->numElements()); 97 } 97 } 98 98 CArray<double,1> input(data.numElements()) ; 99 this->grid->inputFieldServer(storedClient, input); 99 this->grid->inputFieldServer(storedClient, input); 100 100 (*this->foperation)(input); 101 101 *last_operation = currDate; … … 106 106 this->incrementNStep(); 107 107 *last_Write = writeDate; 108 return (true); 108 return (true); 109 109 } 110 110 return (false); 111 111 } 112 112 113 113 bool CField::dispatchEvent(CEventServer& event) 114 114 { 115 115 116 116 if (SuperClass::dispatchEvent(event)) return true ; 117 117 else … … 128 128 return true ; 129 129 break ; 130 130 131 131 case EVENT_ID_ADD_VARIABLE_GROUP : 132 132 recvAddVariableGroup(event) ; 133 133 return true ; 134 break ; 135 134 break ; 135 136 136 default : 137 137 ERROR("bool CField::dispatchEvent(CEventServer& event)",<<"Unknown Event") ; … … 140 140 } 141 141 } 142 142 143 143 void CField::sendUpdateData(void) 144 144 { 145 145 CContext* context = CContext::getCurrent() ; 146 146 CContextClient* client=context->client ; 147 147 148 148 CEventClient event(getType(),EVENT_ID_UPDATE_DATA) ; 149 149 150 150 map<int,CArray<int, 1>* >::iterator it ; 151 151 list<shared_ptr<CMessage> > list_msg ; 152 152 list< CArray<double,1>* > list_data ; 153 153 154 154 for(it=grid->storeIndex_toSrv.begin();it!=grid->storeIndex_toSrv.end();it++) 155 155 { … … 157 157 CArray<int,1>& index = *(it->second) ; 158 158 CArray<double,1> data_tmp(index.numElements()) ; 159 159 160 160 for(int n=0;n<data_tmp.numElements();n++) data_tmp(n)=data(index(n)) ; 161 161 list_msg.push_back(shared_ptr<CMessage>(new CMessage)) ; … … 165 165 } 166 166 client->sendEvent(event) ; 167 167 168 168 for(list< CArray<double,1>* >::iterator it=list_data.begin();it!=list_data.end();it++) delete *it ; 169 169 } 170 170 171 171 void CField::recvUpdateData(CEventServer& event) 172 172 { 173 173 vector<int> ranks ; 174 174 vector<CBufferIn*> buffers ; 175 175 176 176 list<CEventServer::SSubEvent>::iterator it ; 177 177 string fieldId ; … … 185 185 buffers.push_back(buffer) ; 186 186 } 187 get(fieldId)->recvUpdateData(ranks,buffers) ; 188 } 189 187 get(fieldId)->recvUpdateData(ranks,buffers) ; 188 } 189 190 190 void CField::recvUpdateData(vector<int>& ranks, vector<CBufferIn*>& buffers) 191 191 { 192 192 193 193 if (data_srv.empty()) 194 194 { … … 205 205 const CDate & currDate = context->getCalendar()->getCurrentDate(); 206 206 const CDate opeDate = *last_operation_srv + freq_operation_srv; 207 const CDate writeDate = *last_Write_srv + freq_write_srv; 208 209 210 207 const CDate writeDate = *last_Write_srv + freq_write_srv; 208 209 210 211 211 if (opeDate <= currDate) 212 212 { … … 219 219 *last_operation_srv = currDate; 220 220 } 221 221 222 222 if (writeDate < (currDate + freq_operation_srv)) 223 223 { … … 226 226 this->foperation_srv[ranks[n]]->final(); 227 227 } 228 228 229 229 *last_Write_srv = writeDate; 230 230 writeField() ; … … 232 232 } 233 233 } 234 234 235 235 void CField::writeField(void) 236 236 { … … 246 246 247 247 void CField::setRelFile(CFile* _file) 248 { 248 { 249 249 this->file = _file; 250 hasOutputFile=true ; 250 hasOutputFile=true ; 251 251 } 252 252 … … 260 260 261 261 CGrid* CField::getRelGrid(void) const 262 { 263 return (this->grid); 262 { 263 return (this->grid); 264 264 } 265 265 … … 267 267 268 268 CFile* CField::getRelFile(void) const 269 { 269 { 270 270 return (this->file); 271 271 } 272 272 273 273 StdSize CField::getNStep(void) const 274 274 { 275 275 return (this->nstep); 276 276 } 277 277 278 278 void CField::incrementNStep(void) 279 279 { 280 280 this->nstep++; 281 281 } 282 282 283 283 void CField::resetNStep(void) 284 284 { … … 288 288 //---------------------------------------------------------------- 289 289 290 /*! 291 \brief Get pointer to direct field to which the current field refers. 292 */ 290 293 CField* CField::getDirectFieldReference(void) const 291 294 { … … 304 307 305 308 CField* CField::getBaseFieldReference(void) const 306 { 307 return (baseRefObject); 308 } 309 310 //---------------------------------------------------------------- 311 312 const std::vector<CField*>& CField::getAllReference(void) const 313 { 309 { 310 return (baseRefObject); 311 } 312 313 //---------------------------------------------------------------- 314 315 const std::vector<CField*>& CField::getAllReference(void) const 316 { 314 317 return (refObject); 315 318 } … … 318 321 319 322 const StdString & CField::getBaseFieldId(void) const 320 { 323 { 321 324 return (this->getBaseFieldReference()->getId()); 322 325 } 323 324 //---------------------------------------------------------------- 325 326 327 //---------------------------------------------------------------- 328 326 329 const CDuration & CField::getFreqOperation(void) const 327 330 { 328 331 return (this->freq_operation); 329 332 } 330 333 331 334 //---------------------------------------------------------------- 332 335 const CDuration & CField::getFreqWrite(void) const … … 334 337 return (this->freq_write); 335 338 } 336 337 //---------------------------------------------------------------- 338 339 340 //---------------------------------------------------------------- 341 339 342 boost::shared_ptr<func::CFunctor> CField::getFieldOperation(void) const 340 343 { … … 345 348 346 349 bool CField::hasDirectFieldReference(void) const 347 { 348 return (!this->field_ref.isEmpty()); 349 } 350 350 { 351 return (!this->field_ref.isEmpty()); 352 } 353 351 354 bool CField::isActive(void) const 352 { 353 return (!this->refObject.empty()); 354 } 355 //---------------------------------------------------------------- 356 355 { 356 return (!this->refObject.empty()); 357 } 358 //---------------------------------------------------------------- 359 357 360 CArray<double, 1> CField::getData(void) const 358 361 { … … 376 379 //---------------------------------------------------------------- 377 380 378 void CField::processEnabledField(void) 379 { 380 if (!processed) 381 { 382 processed=true ; 383 solveRefInheritance(true) ; 384 solveBaseReference() ; 385 solveOperation() ; 386 solveGridReference() ; 387 388 if (hasDirectFieldReference()) baseRefObject->processEnabledField() ; 389 buildExpression(); 390 active=true; 391 } 392 } 393 381 // void CField::processEnabledField(void) 382 // { 383 // if (!processed) 384 // { 385 // processed=true ; 386 // solveRefInheritance(true) ; 387 // solveBaseReference() ; 388 // solveOperation() ; 389 // solveGridReference() ; 390 // 391 // if (hasDirectFieldReference()) baseRefObject->processEnabledField() ; 392 // buildExpression(); 393 // active=true; 394 // } 395 // } 396 397 void CField::solveAllReferenceEnabledField(bool doSending2Sever) 398 { 399 CContext* context = CContext::getCurrent(); 400 if (!areAllReferenceSolved) 401 { 402 areAllReferenceSolved = true; 403 if (!context->hasServer) 404 { 405 solveRefInheritance(true); 406 solveBaseReference(); 407 } 408 409 solveOperation(); 410 solveGridReference(); 411 } 412 solveGridDomainAxisRef(doSending2Sever); 413 solveCheckMaskIndex(doSending2Sever); 414 } 415 416 std::map<int, StdSize> CField::getGridDataSize() 417 { 418 return grid->getConnectedServerDataSize(); 419 } 420 421 void CField::buildAllExpressionEnabledField() 422 { 423 if (!areAllReferenceSolved) solveAllReferenceEnabledField(true); 424 if (!areAllExpressionBuilt) 425 { 426 areAllExpressionBuilt = true; 427 // solveCheckMaskIndex(true); 428 // solveCheckMaskIndex(); 429 if (hasDirectFieldReference()) baseRefObject->buildAllExpressionEnabledField(); 430 buildExpression(); 431 active=true; 432 } 433 } 434 435 /*! 436 \brief Searching for all reference of a field 437 If a field refers to (an)other field(s), we will search for all its referenced parents. 438 Moreover, if any father, direct or indirect (e.g: two levels up), has non-empty attributes, 439 all its attributes will be added to the current field 440 \param [in] apply Flag to specify whether current field uses attributes of its father 441 in case the attribute is empty (true) or its attributes are replaced by ones of its father (false) 442 */ 394 443 void CField::solveRefInheritance(bool apply) 395 444 { … … 397 446 CField* refer_sptr; 398 447 CField * refer_ptr = this; 399 448 400 449 while (refer_ptr->hasDirectFieldReference()) 401 450 { … … 413 462 sset.insert(refer_ptr); 414 463 } 415 464 } 465 466 467 /*! 468 \brief Only on SERVER side. Remove all field_ref from current field 469 On creating a new field on server side, redundant "field_ref" is still kept in the attribute list 470 of the current field. This function removes this from current field 471 */ 472 void CField::removeRefInheritance() 473 { 474 if (this->field_ref.isEmpty()) return; 475 this->clearAttribute("field_ref"); 416 476 } 417 477 … … 421 481 CField* refer_sptr; 422 482 CField * refer_ptr = this; 423 483 424 484 if (this->hasDirectFieldReference()) baseRefObject = getDirectFieldReference(); 425 485 else baseRefObject = CField::get(this); 426 486 427 487 while (refer_ptr->hasDirectFieldReference()) 428 488 { … … 439 499 sset.insert(refer_ptr); 440 500 } 441 501 442 502 if (hasDirectFieldReference()) baseRefObject->addReference(this) ; 443 503 } 444 504 445 505 //---------------------------------------------------------------- 446 506 … … 448 508 { 449 509 using namespace func; 450 510 451 511 if (!hasOutputFile && !hasFieldOut) return ; 452 512 453 513 StdString id ; 454 514 if (hasId()) id=getId(); 455 515 else if (!name.isEmpty()) id=name ; 456 516 else if (hasDirectFieldReference()) id=baseRefObject->getId() ; 457 517 458 518 CContext* context = CContext::getCurrent(); 459 519 460 520 if (freq_op.isEmpty()) freq_op=string("1ts") ; 461 521 462 522 if (operation.isEmpty() ) 463 523 { … … 466 526 << "Impossible to define an operation for this field !"); 467 527 } 468 528 469 529 CDuration freq_offset_ = NoneDu; 470 530 if (!freq_offset.isEmpty()) … … 475 535 { 476 536 freq_offset.setValue(NoneDu.toString()); 477 } 537 } 478 538 479 539 // if (CXIOSManager::GetStatus() == CXIOSManager::LOC_SERVER) 480 540 if (context->hasServer) 481 541 { 482 if (hasOutputFile) 542 if (hasOutputFile) 483 543 { 484 544 this->freq_operation_srv =CDuration::FromString(this->file->output_freq.getValue()); … … 493 553 // this->foperation_srv = 494 554 // boost::shared_ptr<func::CFunctor>(new CInstant(this->data_srv)); 495 496 if (hasOutputFile) 555 556 if (hasOutputFile) 497 557 { 498 const CDuration toffset = this->freq_operation_srv - freq_offset_ - context->getCalendar()->getTimeStep(); 558 const CDuration toffset = this->freq_operation_srv - freq_offset_ - context->getCalendar()->getTimeStep(); 499 559 *this->last_operation_srv = *this->last_operation_srv - toffset; 500 560 } 501 561 } 502 562 503 563 // if (context->hasClient) 504 // { 564 // { 505 565 this->freq_operation = CDuration::FromString(freq_op.getValue()); 506 566 if (hasOutputFile) this->freq_write = CDuration::FromString(this->file->output_freq.getValue()); 507 if (hasFieldOut) 567 if (hasFieldOut) 508 568 { 509 569 this->freq_write = CDuration::FromString(this->fieldOut->freq_op.getValue()); … … 513 573 this->last_operation = boost::shared_ptr<CDate> 514 574 (new CDate(context->getCalendar()->getInitDate())); 515 516 const CDuration toffset = this->freq_operation - freq_offset_ - context->getCalendar()->getTimeStep(); 517 *this->last_operation = *this->last_operation - toffset; 518 575 576 const CDuration toffset = this->freq_operation - freq_offset_ - context->getCalendar()->getTimeStep(); 577 *this->last_operation = *this->last_operation - toffset; 578 519 579 if (operation.get()=="once") isOnceOperation=true ; 520 580 else isOnceOperation=false; 521 581 isFirstOperation=true; 522 523 582 583 524 584 #define DECLARE_FUNCTOR(MType, mtype) \ 525 585 if (operation.getValue().compare(#mtype) == 0) \ … … 537 597 return; \ 538 598 } 539 599 540 600 #include "functor_type.conf" 541 601 542 602 ERROR("CField::solveOperation(void)", 543 603 << "[ operation = " << operation.getValue() << "]" 544 604 << "The operation is not defined !"); 545 605 // } 546 547 548 } 549 606 607 608 } 609 550 610 //---------------------------------------------------------------- 551 611 /* … … 598 658 << grid_ref.getValue() << "\' is wrong"); 599 659 } 600 660 601 661 if (grid_ref.isEmpty() && domain_ref.isEmpty()) 602 662 { … … 605 665 606 666 } 607 667 608 668 CType<string> goodDomain ; 609 669 CType<string> goodAxis ; … … 615 675 if (!domain_ref.isEmpty()) goodDomain=domain_ref ; 616 676 if (!axis_ref.isEmpty()) goodAxis=axis_ref ; 617 618 619 if (goodDomain.isEmpty()) 677 678 679 if (goodDomain.isEmpty()) 620 680 { 621 681 ERROR("CField::solveGridReference(void)", << "The horizontal domain for this field is not defined"); 622 682 } 623 else 683 else 624 684 { 625 685 if (CDomain::has(goodDomain)) domain = CDomain::get(goodDomain) ; 626 686 else ERROR("CField::solveGridReference(void)",<< "Reference to the domain \'"<<goodDomain.get() << "\' is wrong") ; 627 687 } 628 688 629 689 if (!goodAxis.isEmpty()) 630 690 { … … 632 692 else ERROR("CField::solveGridReference(void)", << "Reference to the axis \'" 633 693 << goodAxis.get() <<"\' is wrong") ; 634 } 635 694 } 695 636 696 bool nothingToDo=false ; 637 697 638 698 if (!grid_ref.isEmpty()) 639 699 { 640 700 if (!grid->domain_ref.isEmpty() && goodDomain.get() == grid->domain_ref.get()) 641 701 if (goodAxis.isEmpty()) nothingToDo=true ; 642 else if (!grid->axis_ref.isEmpty()) 702 else if (!grid->axis_ref.isEmpty()) 643 703 if (grid->axis_ref.get()==goodAxis.get()) nothingToDo=true ; 644 704 } 645 705 646 706 if (!nothingToDo) 647 707 { … … 655 715 this->grid = CGrid::createGrid(domain) ; 656 716 this->grid_ref.setValue(this->grid->getId()); 657 } 717 } 658 718 } 659 719 660 grid->solveReference() ; 661 662 } 663 720 // grid->solveReference() ; 721 // grid->solveDomainAxisRef(); 722 // grid->checkMaskIndex(); 723 } 724 725 void CField::solveGridDomainAxisRef(bool checkAtt) 726 { 727 grid->solveDomainAxisRef(checkAtt); 728 } 729 730 void CField::solveCheckMaskIndex(bool doSendingIndex) 731 { 732 grid->checkMaskIndex(doSendingIndex); 733 } 664 734 665 735 ///------------------------------------------------------------------- … … 680 750 681 751 std::vector<CField*> allChildren = group->getAllChildren(); 682 std::vector<CField*>::iterator 752 std::vector<CField*>::iterator 683 753 it = allChildren.begin(), end = allChildren.end(); 684 754 685 755 for (; it != end; it++) 686 756 { 687 757 CField* child = *it; 688 758 if (child->hasId()) owner->createChild()->field_ref.setValue(child->getId()) ; 689 690 } 691 } 692 759 760 } 761 } 762 693 763 void CField::scaleFactorAddOffset(double scaleFactor, double addOffset) 694 764 { … … 696 766 for(it=data_srv.begin();it!=data_srv.end();it++) *it->second = (*it->second -addOffset) * 1./scaleFactor ; 697 767 } 698 768 699 769 void CField::outputField(CArray<double,3>& fieldOut) 700 770 { … … 702 772 for(it=data_srv.begin();it!=data_srv.end();it++) 703 773 grid->outputField(it->first,*it->second, fieldOut) ; 704 705 } 706 774 775 } 776 707 777 void CField::outputField(CArray<double,2>& fieldOut) 708 778 { … … 719 789 { 720 790 SuperClass::parse(node); 721 if (! node.getContent(this->content)) 791 if (! node.getContent(this->content)) 722 792 { 723 793 if (node.goToChildElement()) … … 731 801 } 732 802 } 733 803 734 804 CArray<double,1>* CField::getInstantData(void) 735 805 { 736 if (!hasInstantData) 806 if (!hasInstantData) 737 807 { 738 808 instantData.resize(grid->storeIndex_client.numElements()) ; … … 741 811 return &instantData ; 742 812 } 743 813 744 814 void CField::addReference(CField* field) 745 815 { 746 816 refObject.push_back(field) ; 747 817 } 748 818 749 819 void CField::addDependency(CField* field, int slotId) 750 820 { 751 821 fieldDependency.push_back(pair<CField*,int>(field,slotId)) ; 752 822 } 753 823 754 824 void CField::buildExpression(void) 755 825 { 756 if (content.size() > 0) 826 if (content.size() > 0) 757 827 { 758 828 CSimpleNodeExpr* simpleExpr=parseExpr(content+'\0') ; … … 762 832 map<string,CField*> associatedInstantFieldIds ; 763 833 expression->getInstantFieldIds(instantFieldIds) ; 764 for (set<string>::iterator it=instantFieldIds.begin() ; it!=instantFieldIds.end();++it) 765 { 766 if (*it!="this") 834 for (set<string>::iterator it=instantFieldIds.begin() ; it!=instantFieldIds.end();++it) 835 { 836 if (*it!="this") 767 837 { 768 if (CField::has(*it)) 838 if (CField::has(*it)) 769 839 { 770 840 CField* field=CField::get(*it) ; 771 field->processEnabledField() ; 841 // field->processEnabledField() ; 842 field->buildAllExpressionEnabledField(); 772 843 associatedInstantFieldIds[*it]=field ; 773 844 } … … 775 846 } 776 847 } 777 848 778 849 set<string> averageFieldIds ; 779 850 map<string,CField*> associatedAverageFieldIds ; 780 851 781 852 expression->getAverageFieldIds(averageFieldIds) ; 782 for (set<string>::iterator it=averageFieldIds.begin() ; it!=averageFieldIds.end();++it) 783 { 784 if (CField::has(*it)) 853 for (set<string>::iterator it=averageFieldIds.begin() ; it!=averageFieldIds.end();++it) 854 { 855 if (CField::has(*it)) 785 856 { 786 857 CFieldGroup* root=CFieldGroup::get("field_definition") ; … … 791 862 averageField->fieldOut=instantField ; 792 863 instantField->freq_op=freq_op ; 793 averageField-> processEnabledField() ; 864 // averageField-> processEnabledField() ; 865 averageField->buildAllExpressionEnabledField(); 794 866 instantField->SuperClassAttribute::setAttributes(averageField, true); 795 867 instantField->field_ref.reset() ; 796 868 instantField->operation.reset() ; 797 869 798 instantField-> processEnabledField() ; 870 // instantField-> processEnabledField() ; 871 instantField->buildAllExpressionEnabledField(); 799 872 associatedAverageFieldIds[*it]=instantField ; 800 873 } … … 810 883 expression->getFields(fields) ; 811 884 for (set<CField*>::iterator it=fields.begin() ; it!=fields.end();++it,++slotId) (*it)->addDependency(this,slotId) ; 812 hasExpression=true; 813 } 814 } 815 885 hasExpression=true; 886 } 887 } 888 816 889 void CField::resetSlots(void) 817 890 { 818 891 for(vector<bool>::iterator it=slots.begin();it!=slots.end();++it) *it=false ; 819 892 } 820 893 821 894 bool CField::slotsFull(void) 822 895 { … … 826 899 } 827 900 828 901 829 902 void CField::setSlot(int slotId) 830 903 { 831 904 CContext* context = CContext::getCurrent() ; 832 905 const CDate & currDate = context->getCalendar()->getCurrentDate(); 833 if (slotUpdateDate==NULL || currDate!=*slotUpdateDate) 906 if (slotUpdateDate==NULL || currDate!=*slotUpdateDate) 834 907 { 835 908 resetSlots() ; … … 841 914 { 842 915 CArray<double,1> expr(expression->compute()) ; 843 844 if (hasInstantData) 916 917 if (hasInstantData) 845 918 { 846 919 instantData=expr ; 847 for(list< pair<CField *,int> >::iterator it=fieldDependency.begin(); it!=fieldDependency.end(); ++it) 920 for(list< pair<CField *,int> >::iterator it=fieldDependency.begin(); it!=fieldDependency.end(); ++it) 848 921 if (it->first!=this) it->first->setSlot(it->second) ; 849 922 } 850 923 851 924 if (hasOutputFile) updateDataFromExpression(expr) ; 852 853 } 854 } 855 856 925 926 } 927 } 928 929 /*! 930 This function retrieves Id of corresponding domain_ref and axis_ref (if any) 931 of a field. In some cases, only domain exists but axis doesn't 932 \return pair of Domain and Axis id 933 */ 934 const std::pair<StdString,StdString>& CField::getDomainAxisIds() 935 { 936 CGrid* cgPtr = getRelGrid(); 937 if (NULL != cgPtr) 938 { 939 if (NULL != cgPtr->getRelDomain()) domAxisIds_.first = cgPtr->getRelDomain()->getId(); 940 if (NULL != cgPtr->getRelAxis()) domAxisIds_.second = cgPtr->getRelAxis()->getId(); 941 } 942 943 return (domAxisIds_); 944 } 857 945 858 946 CVariable* CField::addVariable(const string& id) … … 867 955 868 956 957 void CField::sendAddAllVariables() 958 { 959 if (!getAllVariables().empty()) 960 { 961 // Firstly, it's necessary to add virtual variable group 962 sendAddVariableGroup(getVirtualVariableGroup()->getId()); 963 964 // Okie, now we can add to this variable group 965 std::vector<CVariable*> allVar = getAllVariables(); 966 std::vector<CVariable*>::const_iterator it = allVar.begin(); 967 std::vector<CVariable*>::const_iterator itE = allVar.end(); 968 969 for (; it != itE; ++it) 970 { 971 std::cout << "Variable Fields " << (*it)->getId() << std::endl; 972 this->sendAddVariable((*it)->getId()); 973 (*it)->sendAllAttributesToServer(); 974 (*it)->sendValue(); 975 } 976 } 977 } 978 869 979 void CField::sendAddVariable(const string& id) 870 980 { 871 981 CContext* context=CContext::getCurrent() ; 872 982 873 983 if (! context->hasServer ) 874 984 { 875 985 CContextClient* client=context->client ; 876 986 877 CEventClient event(this->getType(),EVENT_ID_ADD_VARIABLE) ; 987 CEventClient event(this->getType(),EVENT_ID_ADD_VARIABLE) ; 878 988 if (client->isServerLeader()) 879 989 { … … 886 996 else client->sendEvent(event) ; 887 997 } 888 889 } 890 891 998 999 } 1000 1001 892 1002 void CField::sendAddVariableGroup(const string& id) 893 1003 { … … 897 1007 CContextClient* client=context->client ; 898 1008 899 CEventClient event(this->getType(),EVENT_ID_ADD_VARIABLE_GROUP) ; 1009 CEventClient event(this->getType(),EVENT_ID_ADD_VARIABLE_GROUP) ; 900 1010 if (client->isServerLeader()) 901 1011 { … … 908 1018 else client->sendEvent(event) ; 909 1019 } 910 911 } 912 1020 1021 } 1022 913 1023 void CField::recvAddVariable(CEventServer& event) 914 1024 { 915 1025 916 1026 CBufferIn* buffer=event.subEvents.begin()->buffer; 917 1027 string id; … … 919 1029 get(id)->recvAddVariable(*buffer) ; 920 1030 } 921 922 1031 1032 923 1033 void CField::recvAddVariable(CBufferIn& buffer) 924 1034 { … … 930 1040 void CField::recvAddVariableGroup(CEventServer& event) 931 1041 { 932 1042 933 1043 CBufferIn* buffer=event.subEvents.begin()->buffer; 934 1044 string id; … … 936 1046 get(id)->recvAddVariableGroup(*buffer) ; 937 1047 } 938 939 1048 1049 940 1050 void CField::recvAddVariableGroup(CBufferIn& buffer) 941 1051 { … … 947 1057 948 1058 949 1059 950 1060 } // namespace xios -
XIOS/trunk/src/node/field.hpp
r501 r509 18 18 19 19 namespace xios { 20 20 21 21 /// ////////////////////// Déclarations ////////////////////// /// 22 22 … … 56 56 EVENT_ID_UPDATE_DATA, EVENT_ID_ADD_VARIABLE, EVENT_ID_ADD_VARIABLE_GROUP 57 57 } ; 58 58 59 59 /// Constructeurs /// 60 60 CField(void); … … 83 83 84 84 boost::shared_ptr<func::CFunctor> getFieldOperation(void) const; 85 85 86 86 CArray<double, 1> getData(void) const; 87 87 … … 95 95 template <int N> bool updateData(const CArray<double, N>& data); 96 96 bool updateDataFromExpression(const CArray<double, 1>& data); 97 void setDataFromExpression(const CArray<double, 1>& _data) ; 98 97 void setDataFromExpression(const CArray<double, 1>& _data) ; 98 99 99 bool updateDataServer 100 100 (const CDate & currDate, 101 101 const std::deque< CArray<double, 1>* > storedClient); 102 102 103 std::map<int, StdSize> getGridDataSize(); 104 103 105 public : 104 106 … … 116 118 void solveGridReference(void); 117 119 void solveOperation(void); 120 void solveCheckMaskIndex(bool doSendingIndex); 121 void solveAllReferenceEnabledField(bool doSending2Sever); 122 void buildAllExpressionEnabledField(); 123 void solveGridDomainAxisRef(bool checkAtt); 124 void removeRefInheritance(); // Remove all reference of current field (it refers to itself) 118 125 119 126 // virtual void fromBinary(StdIStream & is); … … 125 132 static StdString GetName(void); 126 133 static StdString GetDefName(void); 127 134 128 135 static ENodeType GetType(void); 129 136 130 137 template <int N> void setData(const CArray<double, N>& _data) ; 131 138 static bool dispatchEvent(CEventServer& event) ; … … 139 146 void parse(xml::CXMLNode & node) ; 140 147 CArray<double,1>* getInstantData(void) ; 141 148 142 149 void setVirtualVariableGroup(CVariableGroup* newVVariableGroup); 143 150 void setVirtualVariableGroup(void); … … 145 152 vector<CVariable*> getAllVariables(void) const; 146 153 virtual void solveDescInheritance(bool apply, const CAttributeMap * const parent = 0); 147 154 148 155 CVariable* addVariable(const string& id="") ; 149 156 CVariableGroup* addVariableGroup(const string& id="") ; … … 154 161 static void recvAddVariableGroup(CEventServer& event) ; 155 162 void recvAddVariableGroup(CBufferIn& buffer) ; 156 163 void sendAddAllVariables(); 164 165 166 const std::pair<StdString, StdString>& getDomainAxisIds(); 157 167 public : 158 168 159 169 /// Propriétés privées /// 160 170 CVariableGroup* vVariableGroup ; 161 171 162 172 std::vector<CField*> refObject; 163 173 CField* baseRefObject; … … 172 182 boost::shared_ptr<CDate> last_Write, last_operation; 173 183 boost::shared_ptr<CDate> lastlast_Write_srv,last_Write_srv, last_operation_srv; 174 184 175 185 boost::shared_ptr<func::CFunctor> foperation; 176 186 map<int,boost::shared_ptr<func::CFunctor> > foperation_srv; 177 187 178 188 CArray<double, 1> data; 179 189 CArray<double, 1> instantData; … … 183 193 bool isFirstOperation ; 184 194 string content ; 185 195 186 196 list< pair<CField *,int> > fieldDependency ; 187 197 void buildExpression(void) ; … … 195 205 void setSlot(int slotId); 196 206 bool processed ; 207 bool areAllReferenceSolved; 208 bool areAllExpressionBuilt; 209 std::pair<StdString,StdString> domAxisIds_; 197 210 198 211 }; // class CField -
XIOS/trunk/src/node/file.cpp
r501 r509 18 18 19 19 namespace xios { 20 20 21 21 /// ////////////////////// Définitions ////////////////////// /// 22 22 … … 24 24 : CObjectTemplate<CFile>(), CFileAttributes() 25 25 , vFieldGroup(), data_out(), enabledFields(), fileComm(MPI_COMM_NULL) 26 { 26 { 27 27 setVirtualFieldGroup() ; 28 28 setVirtualVariableGroup() ; … … 32 32 : CObjectTemplate<CFile>(id), CFileAttributes() 33 33 , vFieldGroup(), data_out(), enabledFields(), fileComm(MPI_COMM_NULL) 34 { 34 { 35 35 setVirtualFieldGroup() ; 36 36 setVirtualVariableGroup() ; … … 41 41 42 42 ///--------------------------------------------------------------- 43 43 //! Get name of file 44 44 StdString CFile::GetName(void) { return (StdString("file")); } 45 45 StdString CFile::GetDefName(void){ return (CFile::GetName()); } … … 47 47 48 48 //---------------------------------------------------------------- 49 49 /*! 50 \brief Get data that will be written out. 51 Each enabled file in xml represents a physical netcdf file. 52 This function allows to access to data to be written out into netcdf file 53 \return data written out. 54 */ 50 55 boost::shared_ptr<CDataOutput> CFile::getDataOutput(void) const 51 56 { … … 53 58 } 54 59 60 /*! 61 \brief Get virtual field group 62 In each file, there always exists a field group which is the ancestor of all 63 fields in the file. This is considered be virtual because it is created automatically during 64 file initialization and it normally doesn't appear on xml file 65 \return Pointer to field group 66 */ 55 67 CFieldGroup* CFile::getVirtualFieldGroup(void) const 56 68 { … … 58 70 } 59 71 72 /*! 73 \brief Get virtual variable group 74 In each file, there always exists a variable group which is the ancestor of all 75 variable in the file. This is considered be virtual because it is created automatically during 76 file initialization and it normally doesn't appear on xml file 77 \return Pointer to variable group 78 */ 60 79 CVariableGroup* CFile::getVirtualVariableGroup(void) const 61 80 { … … 63 82 } 64 83 84 //! Get all fields of a file 65 85 std::vector<CField*> CFile::getAllFields(void) const 66 86 { 67 87 return (this->vFieldGroup->getAllChildren()); 68 88 } 69 89 90 //! Get all variables of a file 70 91 std::vector<CVariable*> CFile::getAllVariables(void) const 71 92 { … … 74 95 75 96 //---------------------------------------------------------------- 76 77 std::vector<CField*> CFile::getEnabledFields(int default_outputlevel, 97 /*! 98 \brief Get all enabled fields of file 99 A field is considered to be enabled if it fullfil these conditions: it is enabled, inside a enabled file 100 and its own level is not larger than file output level. 101 \param [in] default_outputlevel default value output level of file 102 \param [in] default_level default value level of field 103 \param [in] default_enabled flag determine by default if field is enabled 104 \return Vector of pointers of enabled fields 105 */ 106 std::vector<CField*> CFile::getEnabledFields(int default_outputlevel, 78 107 int default_level, 79 108 bool default_enabled) … … 88 117 89 118 std::vector<CField*> newEnabledFields; 90 119 91 120 for ( it = this->enabledFields.begin() ; it != this->enabledFields.end(); it++ ) 92 121 { … … 112 141 // { it--; this->enabledFields.erase(it+1); continue; } 113 142 } 114 143 115 144 // CField* field_tmp=(*it).get() ; 116 145 // shared_ptr<CField> sptfield=*it ; … … 130 159 131 160 //---------------------------------------------------------------- 132 161 //! Change virtual field group to a new one 133 162 void CFile::setVirtualFieldGroup(CFieldGroup* newVFieldGroup) 134 { 135 this->vFieldGroup = newVFieldGroup; 136 } 137 163 { 164 this->vFieldGroup = newVFieldGroup; 165 } 166 167 //! Change virtual variable group to new one 138 168 void CFile::setVirtualVariableGroup(CVariableGroup* newVVariableGroup) 139 { 140 this->vVariableGroup = newVVariableGroup; 141 } 142 143 //---------------------------------------------------------------- 144 169 { 170 this->vVariableGroup = newVVariableGroup; 171 } 172 173 //---------------------------------------------------------------- 174 //! Create virtual field group, which is done normally on initializing file 145 175 void CFile::setVirtualFieldGroup(void) 146 176 { … … 148 178 } 149 179 180 //! Create virtual variable group, which is done normally on initializing file 150 181 void CFile::setVirtualVariableGroup(void) 151 182 { … … 168 199 return false ; 169 200 } 170 201 202 //! Initialize a file in order to write into it 171 203 void CFile::initFile(void) 172 204 { … … 174 206 CDate& currentDate=context->calendar->getCurrentDate() ; 175 207 CContextServer* server=context->server ; 176 208 177 209 if (! sync_freq.isEmpty()) syncFreq = CDuration::FromString(sync_freq.getValue()); 178 210 if (! split_freq.isEmpty()) splitFreq = CDuration::FromString(split_freq.getValue()); … … 194 226 nbDomain=setDomain.size() ; 195 227 196 // create sub communicator for file 228 // create sub communicator for file 197 229 int color=allDomainEmpty?0:1 ; 198 230 MPI_Comm_split(server->intraComm,color,server->intraCommRank,&fileComm) ; 199 231 if (allDomainEmpty) MPI_Comm_free(&fileComm) ; 200 232 // 201 202 } 203 233 234 } 235 236 //! Verify state of a file 204 237 void CFile::checkFile(void) 205 238 { … … 208 241 checkSplit() ; 209 242 } 210 211 243 244 245 /*! 246 \brief Verify if synchronisation should be done 247 If syn option is enabled, syn frequence and current time will be used to 248 calculate the moment to syn file(s) 249 \return True if it is the moment to synchronize file, otherwise false 250 */ 212 251 bool CFile::checkSync(void) 213 252 { … … 225 264 return false ; 226 265 } 227 228 266 267 /*! 268 \brief Verify if splitting should be done 269 If split option is enabled, split frequence and current time will be used to 270 calculate the moment to split file 271 \return True if it is the moment to split file, otherwise false 272 */ 229 273 bool CFile::checkSplit(void) 230 274 { … … 235 279 if (currentDate > *lastSplit+splitFreq) 236 280 { 237 *lastSplit=*lastSplit+splitFreq ; 281 *lastSplit=*lastSplit+splitFreq ; 238 282 std::vector<CField*>::iterator it, end = this->enabledFields.end(); 239 283 for (it = this->enabledFields.begin() ;it != end; it++) (*it)->resetNStep() ; … … 244 288 return false ; 245 289 } 246 290 291 /*! 292 \brief Create header of netcdf file 293 There are some information to fill in header of each netcdf. 294 */ 247 295 void CFile::createHeader(void) 248 296 { 249 297 CContext* context = CContext::getCurrent() ; 250 298 CContextServer* server=context->server ; 251 299 252 300 if (!allDomainEmpty) 253 301 { … … 273 321 oss<<"_"<<lastSplit->getStr(splitFormat)<<"-"<< (*lastSplit+(splitFreq-1*Second)).getStr(splitFormat); 274 322 } 275 323 276 324 bool multifile=true ; 277 325 if (!type.isEmpty()) … … 280 328 else if (type==type_attr::multiple_file) multifile=true ; 281 329 282 } 330 } 283 331 #ifndef USING_NETCDF_PAR 284 332 if (!multifile) … … 288 336 } 289 337 #endif 290 if (multifile) 338 if (multifile) 291 339 { 292 340 int commSize, commRank ; 293 341 MPI_Comm_size(fileComm,&commSize) ; 294 342 MPI_Comm_rank(fileComm,&commRank) ; 295 296 if (server->intraCommSize > 1) 343 344 if (server->intraCommSize > 1) 297 345 { 298 346 oss << "_" ; 299 347 int width=0 ; int n=commSize-1 ; 300 348 while(n != 0) { n=n/10 ; width++ ;} 301 if (!min_digits.isEmpty()) 349 if (!min_digits.isEmpty()) 302 350 if (width<min_digits) width=min_digits ; 303 351 oss.width(width) ; … … 314 362 if (par_access.getValue()=="independent") isCollective=false ; 315 363 else if (par_access.getValue()=="collective") isCollective=true ; 316 else 364 else 317 365 { 318 366 ERROR("void Context::createDataOutput(void)", … … 332 380 } 333 381 this->data_out->writeTimeDimension(); 334 382 335 383 for (it = this->enabledFields.begin() ;it != end; it++) 336 384 { … … 338 386 this->data_out->writeField(field); 339 387 } 340 388 341 389 vector<CVariable*> listVars = getAllVariables() ; 342 390 for (vector<CVariable*>::iterator it = listVars.begin() ;it != listVars.end(); it++) this-> data_out-> writeAttribute(*it) ; 343 391 344 392 this->data_out->definition_end(); 345 393 } 346 394 } 347 395 396 //! Close file 348 397 void CFile::close(void) 349 398 { … … 351 400 delete lastSplit ; 352 401 if (!allDomainEmpty) 353 if (isOpen) 402 if (isOpen) 354 403 { 355 404 this->data_out->closeFile(); … … 359 408 //---------------------------------------------------------------- 360 409 410 /*! 411 \brief Parse xml file and write information into file object 412 \param [in] node xmld node corresponding in xml file 413 */ 361 414 void CFile::parse(xml::CXMLNode & node) 362 415 { 363 416 SuperClass::parse(node); 364 417 365 418 if (node.goToChildElement()) 366 419 { … … 376 429 //---------------------------------------------------------------- 377 430 431 /*! 432 \brief Represent a file in form of string with all its info 433 \return String 434 */ 378 435 StdString CFile::toString(void) const 379 436 { … … 391 448 392 449 //---------------------------------------------------------------- 393 450 451 /*! 452 \brief Find all inheritace among objects in a file. 453 \param [in] apply (true) write attributes of parent into ones of child if they are empty 454 (false) write attributes of parent into a new container of child 455 \param [in] parent 456 */ 394 457 void CFile::solveDescInheritance(bool apply, const CAttributeMap * const parent) 395 458 { 396 459 SuperClassAttribute::setAttributes(parent,apply); 397 this->getVirtualFieldGroup()->solveDescInheritance(apply, NULL); 460 this->getVirtualFieldGroup()->solveDescInheritance(apply, NULL); 398 461 this->getVirtualVariableGroup()->solveDescInheritance(apply, NULL); 399 462 } … … 401 464 //---------------------------------------------------------------- 402 465 403 void CFile::processEnabledFile(void) 404 { 405 if (output_freq.isEmpty()) ERROR("void CFile::processEnabledFile(void)", 406 <<"File attribute <<output_freq>> is undefined"); 407 solveFieldRefInheritance(true) ; 408 getEnabledFields() ; 409 processEnabledFields() ; 410 } 411 412 void CFile::processEnabledFields(void) 413 { 414 for (unsigned int i = 0; i < this->enabledFields.size(); i++) 415 { 416 this->enabledFields[i]->processEnabledField() ; 417 } 418 } 419 466 // void CFile::processEnabledFile(void) 467 // { 468 // if (output_freq.isEmpty()) ERROR("void CFile::processEnabledFile(void)", 469 // <<"File attribute <<output_freq>> is undefined"); 470 // solveFieldRefInheritance(true) ; 471 // getEnabledFields() ; 472 // processEnabledFields() ; 473 // } 474 475 // void CFile::processEnabledFields(void) 476 // { 477 // for (unsigned int i = 0; i < this->enabledFields.size(); i++) 478 // { 479 // this->enabledFields[i]->processEnabledField() ; 480 // } 481 // } 482 483 /*! 484 \brief Resolve all reference of active fields. 485 In order to know exactly which data each active field has, a search for all its 486 reference to find its parents or/and its base reference object must be done. Moreover 487 during this search, there are some information that can only be sent to server AFTER 488 all information of active fields are created on server side, e.g: checking mask or index 489 \param [in] sendToServer: Send all info to server (true) or only a part of it (false) 490 */ 491 void CFile::solveAllRefOfEnabledFields(bool sendToServer) 492 { 493 int size = this->enabledFields.size(); 494 for (int i = 0; i < size; ++i) 495 { 496 this->enabledFields[i]->solveAllReferenceEnabledField(sendToServer); 497 } 498 } 499 500 /*! 501 \brief Contruct all expression related to active fields. 502 Each field can do some expressions which appear on the xml file, and itself can be 503 a result of an expression among some other fields. This function builds all possible expression 504 relating to active fields. 505 */ 506 void CFile::buildAllExpressionOfEnabledFields() 507 { 508 int size = this->enabledFields.size(); 509 for (int i = 0; i < size; ++i) 510 { 511 this->enabledFields[i]->buildAllExpressionEnabledField(); 512 } 513 } 514 420 515 void CFile::solveFieldRefInheritance(bool apply) 421 516 { … … 441 536 this->enabledFields[i]->solveOperation(); 442 537 } 443 538 444 539 void CFile::solveEFExpression(void) 445 540 { 446 541 for (unsigned int i = 0; i < this->enabledFields.size(); i++) 447 542 this->enabledFields[i]->buildExpression(); 448 } 449 450 543 } 544 545 /*! 546 \brief Add a field into file. 547 A field is added into file and it will be written out if the file is enabled and 548 level of this field is smaller than level_output. A new field won't be created if one 549 with id has already existed 550 \param [in] id String identity of new field 551 \return Pointer to added (or already existed) field 552 */ 451 553 CField* CFile::addField(const string& id) 452 554 { … … 454 556 } 455 557 558 /*! 559 \brief Add a field group into file. 560 A field group is added into file and it will play a role as parents for fields. 561 A new field group won't be created if one with id has already existed 562 \param [in] id String identity of new field group 563 \return Pointer to added (or already existed) field group 564 */ 456 565 CFieldGroup* CFile::addFieldGroup(const string& id) 457 566 { 458 567 return vFieldGroup->createChildGroup(id) ; 459 568 } 460 569 570 /*! 571 \brief Add a variable into file. 572 A variable is added into file and if one with id has already existed, pointer to 573 it will be returned. 574 Variable as long as attributes are information container of file. 575 However, whereas attributes are "fixed" information, variables provides a more flexible way to user 576 to fill in (extra) information for a file. 577 \param [in] id String identity of new variable 578 \return Pointer to added (or already existed) variable 579 */ 461 580 CVariable* CFile::addVariable(const string& id) 462 581 { … … 464 583 } 465 584 585 /*! 586 \brief Add a variable group into file. 587 A variable group is added into file and it will play a role as parents for variables. 588 A new variable group won't be created if one with id has already existed 589 \param [in] id String identity of new variable group 590 \return Pointer to added (or already existed) variable group 591 */ 466 592 CVariableGroup* CFile::addVariableGroup(const string& id) 467 593 { 468 594 return vVariableGroup->createChildGroup(id) ; 469 595 } 470 471 596 597 /*! 598 \brief Send a message to create a field on server side 599 \param[in] id String identity of field that will be created on server 600 */ 472 601 void CFile::sendAddField(const string& id) 473 602 { 474 603 CContext* context=CContext::getCurrent() ; 475 604 476 605 if (! context->hasServer ) 477 606 { 478 607 CContextClient* client=context->client ; 479 608 480 CEventClient event(this->getType(),EVENT_ID_ADD_FIELD) ; 609 CEventClient event(this->getType(),EVENT_ID_ADD_FIELD) ; 481 610 if (client->isServerLeader()) 482 611 { … … 489 618 else client->sendEvent(event) ; 490 619 } 491 492 } 493 620 621 } 622 623 /*! 624 \brief Send a message to create a field group on server side 625 \param[in] id String identity of field group that will be created on server 626 */ 494 627 void CFile::sendAddFieldGroup(const string& id) 495 628 { … … 499 632 CContextClient* client=context->client ; 500 633 501 CEventClient event(this->getType(),EVENT_ID_ADD_FIELD_GROUP) ; 634 CEventClient event(this->getType(),EVENT_ID_ADD_FIELD_GROUP) ; 502 635 if (client->isServerLeader()) 503 636 { … … 510 643 else client->sendEvent(event) ; 511 644 } 512 513 } 514 645 646 } 647 648 /*! 649 \brief Receive a message annoucing the creation of a field on server side 650 \param[in] event Received event 651 */ 515 652 void CFile::recvAddField(CEventServer& event) 516 653 { 517 654 518 655 CBufferIn* buffer=event.subEvents.begin()->buffer; 519 656 string id; … … 521 658 get(id)->recvAddField(*buffer) ; 522 659 } 523 524 660 661 /*! 662 \brief Receive a message annoucing the creation of a field on server side 663 \param[in] buffer Buffer containing message 664 */ 525 665 void CFile::recvAddField(CBufferIn& buffer) 526 666 { … … 530 670 } 531 671 672 /*! 673 \brief Receive a message annoucing the creation of a field group on server side 674 \param[in] event Received event 675 */ 532 676 void CFile::recvAddFieldGroup(CEventServer& event) 533 677 { 534 678 535 679 CBufferIn* buffer=event.subEvents.begin()->buffer; 536 680 string id; … … 538 682 get(id)->recvAddFieldGroup(*buffer) ; 539 683 } 540 541 684 685 /*! 686 \brief Receive a message annoucing the creation of a field group on server side 687 \param[in] buffer Buffer containing message 688 */ 542 689 void CFile::recvAddFieldGroup(CBufferIn& buffer) 543 690 { … … 546 693 addFieldGroup(id) ; 547 694 } 548 549 550 551 552 553 554 555 556 557 558 695 696 /*! 697 \brief Send messages to duplicate all variables on server side 698 Because each variable has also its attributes. So first thing to do is replicate 699 all these attributes on server side. Because variable can have a value, the second thing 700 is to duplicate this value on server, too. 701 */ 702 void CFile::sendAddAllVariables() 703 { 704 if (!getAllVariables().empty()) 705 { 706 // Firstly, it's necessary to add virtual variable group 707 sendAddVariableGroup(getVirtualVariableGroup()->getId()); 708 709 // Okie, now we can add to this variable group 710 std::vector<CVariable*> allVar = getAllVariables(); 711 std::vector<CVariable*>::const_iterator it = allVar.begin(); 712 std::vector<CVariable*>::const_iterator itE = allVar.end(); 713 714 for (; it != itE; ++it) 715 { 716 std::cout << "Variable Files " << (*it)->getId() << std::endl; 717 this->sendAddVariable((*it)->getId()); 718 (*it)->sendAllAttributesToServer(); 719 (*it)->sendValue(); 720 } 721 } 722 } 723 724 /*! 725 \brief Send a message to create a variable on server side 726 A variable always belongs to a variable group 727 \param[in] id String identity of variable that will be created on server 728 */ 559 729 void CFile::sendAddVariable(const string& id) 560 730 { 561 731 CContext* context=CContext::getCurrent() ; 562 732 563 733 if (! context->hasServer ) 564 734 { 565 735 CContextClient* client=context->client ; 566 736 567 CEventClient event(this->getType(),EVENT_ID_ADD_VARIABLE) ; 737 CEventClient event(this->getType(),EVENT_ID_ADD_VARIABLE) ; 568 738 if (client->isServerLeader()) 569 739 { … … 576 746 else client->sendEvent(event) ; 577 747 } 578 579 } 580 748 749 } 750 751 /*! 752 \brief Send a message to create a variable group on server side 753 \param[in] id String identity of variable group that will be created on server 754 */ 581 755 void CFile::sendAddVariableGroup(const string& id) 582 756 { … … 586 760 CContextClient* client=context->client ; 587 761 588 CEventClient event(this->getType(),EVENT_ID_ADD_VARIABLE_GROUP) ; 762 CEventClient event(this->getType(),EVENT_ID_ADD_VARIABLE_GROUP) ; 589 763 if (client->isServerLeader()) 590 764 { … … 597 771 else client->sendEvent(event) ; 598 772 } 599 600 } 601 773 774 } 775 776 /*! 777 \brief Receive a message annoucing the creation of a variable on server side 778 \param[in] event Received event 779 */ 602 780 void CFile::recvAddVariable(CEventServer& event) 603 781 { 604 782 605 783 CBufferIn* buffer=event.subEvents.begin()->buffer; 606 784 string id; … … 608 786 get(id)->recvAddVariable(*buffer) ; 609 787 } 610 611 788 789 /*! 790 \brief Receive a message annoucing the creation of a variable on server side 791 \param[in] buffer Buffer containing message 792 */ 612 793 void CFile::recvAddVariable(CBufferIn& buffer) 613 794 { … … 617 798 } 618 799 800 /*! 801 \brief Receive a message annoucing the creation of a variable group on server side 802 \param[in] event Received event 803 */ 619 804 void CFile::recvAddVariableGroup(CEventServer& event) 620 805 { 621 806 622 807 CBufferIn* buffer=event.subEvents.begin()->buffer; 623 808 string id; … … 625 810 get(id)->recvAddVariableGroup(*buffer) ; 626 811 } 627 628 812 813 /*! 814 \brief Receive a message annoucing the creation of a variable group on server side 815 \param[in] buffer Buffer containing message 816 */ 629 817 void CFile::recvAddVariableGroup(CBufferIn& buffer) 630 818 { … … 634 822 } 635 823 636 637 638 639 824 /*! 825 \brief Sending all active (enabled) fields from client to server. 826 Each field is identified uniquely by its string identity. Not only should we 827 send the id to server but also we need to send ids of reference domain and reference axis. 828 With these two id, it's easier to make reference to grid where all data should be written. 829 Remark: This function must be called AFTER all active (enabled) files have been created on the server side 830 */ 831 void CFile::sendEnabledFields() 832 { 833 int size = this->enabledFields.size(); 834 CField* fieldPtr(0); 835 for (int i = 0; i < size; ++i) 836 { 837 fieldPtr = this->enabledFields[i]; 838 if (fieldPtr->name.isEmpty()) fieldPtr->name.setValue(fieldPtr->getBaseFieldReference()->getId()); 839 std::cout << "Enabled Fields " << i << " " << CField::get(fieldPtr)->getId() << std::endl; 840 this->sendAddField(fieldPtr->getId()); 841 fieldPtr->sendAllAttributesToServer(); 842 fieldPtr->sendAddAllVariables(); 843 } 844 } 845 846 /*! 847 \brief Dispatch event received from client 848 Whenever a message is received in buffer of server, it will be processed depending on 849 its event type. A new event type should be added in the switch list to make sure 850 it processed on server side. 851 \param [in] event: Received message 852 */ 640 853 bool CFile::dispatchEvent(CEventServer& event) 641 854 { … … 649 862 return true ; 650 863 break ; 651 864 652 865 case EVENT_ID_ADD_FIELD_GROUP : 653 866 recvAddFieldGroup(event) ; 654 867 return true ; 655 break ; 656 868 break ; 869 657 870 case EVENT_ID_ADD_VARIABLE : 658 871 recvAddVariable(event) ; 659 872 return true ; 660 873 break ; 661 874 662 875 case EVENT_ID_ADD_VARIABLE_GROUP : 663 876 recvAddVariableGroup(event) ; 664 877 return true ; 665 break ; 878 break ; 666 879 default : 667 880 ERROR("bool CFile::dispatchEvent(CEventServer& event)", <<"Unknown Event") ; … … 670 883 } 671 884 } 672 673 674 675 885 886 887 888 676 889 ///--------------------------------------------------------------- 677 890 -
XIOS/trunk/src/node/file.hpp
r501 r509 15 15 16 16 namespace xios { 17 17 18 18 /// ////////////////////// Déclarations ////////////////////// /// 19 19 … … 31 31 ///-------------------------------------------------------------- 32 32 33 /*! 34 \class CFile 35 This class corresponds to file component of the xml. 36 The class contains all the nessceary information to write data into a netcdf file: The most important thing 37 is the field(s) which will be written into file. Besides, there are some options to write 38 data into file, e.g: writting into only one file or multiple file; splitting a running into several files. 39 Moreover, there are some other attributes of netcdf file which are also stored in this class 40 */ 33 41 class CFile 34 42 : public CObjectTemplate<CFile> … … 38 46 typedef CObjectTemplate<CFile> SuperClass; 39 47 typedef CFileAttributes SuperClassAttribute; 40 48 41 49 public : 42 50 enum EEventId 43 51 { 44 EVENT_ID_ADD_FIELD=0,EVENT_ID_ADD_FIELD_GROUP, EVENT_ID_ADD_VARIABLE,EVENT_ID_ADD_VARIABLE_GROUP 52 EVENT_ID_ADD_FIELD=0,EVENT_ID_ADD_FIELD_GROUP, EVENT_ID_ADD_VARIABLE, 53 EVENT_ID_ADD_VARIABLE_GROUP, EVENT_ID_CREATE_ENABLED_FIELDS 45 54 } ; 46 55 47 56 typedef CFileAttributes RelAttributes; 48 57 typedef CFileGroup RelGroup; … … 54 63 CFile(const CFile * const file); // Not implemented yet. 55 64 65 /// Destructeur /// 66 virtual ~CFile(void); 67 68 public: 56 69 /// Accesseurs /// 57 70 boost::shared_ptr<CDataOutput> getDataOutput(void) const; … … 66 79 67 80 public : 68 69 /// Mutateurs /// 70 void setVirtualFieldGroup(CFieldGroup* newVFieldGroup); 71 void setVirtualFieldGroup(void); 72 void setVirtualVariableGroup(CVariableGroup* newVVariableGroup); 73 void setVirtualVariableGroup(void); 74 void processEnabledFile(void) ; 75 void processEnabledFields(void) ; 76 void createHeader(void); 77 void close(void) ; 78 79 /// Traitements /// 80 virtual void solveDescInheritance(bool apply, const CAttributeMap * const parent = 0); 81 void solveFieldRefInheritance(bool apply); 82 void solveEFGridRef(void); 83 void solveEFOperation(void); 84 void solveEFExpression(void); 85 86 /// Destructeur /// 87 virtual ~CFile(void); 88 89 /// Autres /// 90 virtual void parse(xml::CXMLNode & node); 91 virtual StdString toString(void) const; 92 93 // virtual void toBinary (StdOStream & os) const; 94 // virtual void fromBinary(StdIStream & is); 95 96 /// Accesseurs statiques /// 97 static StdString GetName(void); 98 static StdString GetDefName(void); 99 100 static ENodeType GetType(void); 101 102 bool allDomainEmpty ; 103 CField* addField(const string& id="") ; 104 CFieldGroup* addFieldGroup(const string& id="") ; 105 CVariable* addVariable(const string& id="") ; 106 CVariableGroup* addVariableGroup(const string& id="") ; 107 void sendAddField(const string& id="") ; 108 void sendAddFieldGroup(const string& id="") ; 109 static void recvAddField(CEventServer& event) ; 110 void recvAddField(CBufferIn& buffer) ; 111 static void recvAddFieldGroup(CEventServer& event) ; 112 void recvAddFieldGroup(CBufferIn& buffer) ; 113 114 void sendAddVariable(const string& id="") ; 115 void sendAddVariableGroup(const string& id="") ; 116 static void recvAddVariable(CEventServer& event) ; 117 void recvAddVariable(CBufferIn& buffer) ; 118 static void recvAddVariableGroup(CEventServer& event) ; 119 void recvAddVariableGroup(CBufferIn& buffer) ; 120 static bool dispatchEvent(CEventServer& event) ; 121 81 // Some functions to verify state of file 122 82 bool isSyncTime(void) ; 123 83 bool checkSplit(void) ; … … 125 85 void checkFile(void) ; 126 86 void initFile(void) ; 87 88 /// Mutateurs /// 89 // Set some root definitions in a file 90 void setVirtualFieldGroup(CFieldGroup* newVFieldGroup); 91 void setVirtualFieldGroup(void); 92 void setVirtualVariableGroup(CVariableGroup* newVVariableGroup); 93 void setVirtualVariableGroup(void); 94 95 void createHeader(void); 96 void close(void) ; 97 98 // Some processing on file 99 void solveFieldRefInheritance(bool apply); 100 void solveEFGridRef(void); 101 void solveEFOperation(void); 102 void solveEFExpression(void); 103 void processEnabledFile(void) ; 104 void processEnabledFields(void) ; 105 void solveAllRefOfEnabledFields(bool sendToServer); 106 void buildAllExpressionOfEnabledFields(); 107 108 // Add component into file 109 CField* addField(const string& id="") ; 110 CFieldGroup* addFieldGroup(const string& id="") ; 111 CVariable* addVariable(const string& id="") ; 112 CVariableGroup* addVariableGroup(const string& id="") ; 113 114 // Send info to serever 115 void sendEnabledFields(); 116 void sendAddField(const string& id="") ; 117 void sendAddFieldGroup(const string& id="") ; 118 void sendAddAllVariables(); 119 void sendAddVariable(const string& id="") ; 120 void sendAddVariableGroup(const string& id="") ; 121 122 // Receive info from client 123 static void recvAddField(CEventServer& event) ; 124 void recvAddField(CBufferIn& buffer) ; 125 static void recvAddFieldGroup(CEventServer& event) ; 126 void recvAddFieldGroup(CBufferIn& buffer) ; 127 static void recvAddVariable(CEventServer& event) ; 128 void recvAddVariable(CBufferIn& buffer) ; 129 static void recvAddVariableGroup(CEventServer& event) ; 130 void recvAddVariableGroup(CBufferIn& buffer) ; 131 132 // Dispatch event 133 static bool dispatchEvent(CEventServer& event) ; 134 135 public: 136 /// Accesseurs statiques /// 137 static StdString GetName(void); 138 static StdString GetDefName(void); 139 140 static ENodeType GetType(void); 141 public: 142 /// Traitements /// 143 virtual void solveDescInheritance(bool apply, const CAttributeMap * const parent = 0); 144 145 /// Autres /// 146 virtual void parse(xml::CXMLNode & node); 147 virtual StdString toString(void) const; 148 public: 149 127 150 CDate* lastSync ; 128 151 CDate* lastSplit ; … … 132 155 int nbDomain ; 133 156 bool isOpen ; 157 bool allDomainEmpty ; 134 158 MPI_Comm fileComm ; 159 135 160 private : 136 137 161 /// Propriétés privées /// 138 162 CFieldGroup* vFieldGroup; … … 140 164 boost::shared_ptr<CDataOutput> data_out; 141 165 std::vector<CField*> enabledFields; 166 167 public: 168 // virtual void toBinary (StdOStream & os) const; 169 // virtual void fromBinary(StdIStream & is); 142 170 143 171 }; // class CFile -
XIOS/trunk/src/node/grid.cpp
r501 r509 19 19 CGrid::CGrid(void) 20 20 : CObjectTemplate<CGrid>(), CGridAttributes() 21 , withAxis(false), isChecked(false), axis(), domain()22 , storeIndex(1), out_i_index(1), out_j_index(1), out_l_index(1) 21 , withAxis(false), isChecked(false), isDomainAxisChecked(false), axis(), domain() 22 , storeIndex(1), out_i_index(1), out_j_index(1), out_l_index(1), isDomConServerComputed_(false) 23 23 { /* Ne rien faire de plus */ } 24 24 25 25 CGrid::CGrid(const StdString & id) 26 26 : CObjectTemplate<CGrid>(id), CGridAttributes() 27 , withAxis(false), isChecked(false), axis(), domain()28 , storeIndex(1), out_i_index(1), out_j_index(1), out_l_index(1) 27 , withAxis(false), isChecked(false), isDomainAxisChecked(false), axis(), domain() 28 , storeIndex(1), out_i_index(1), out_j_index(1), out_l_index(1), isDomConServerComputed_(false) 29 29 { /* Ne rien faire de plus */ } 30 30 31 31 CGrid::~CGrid(void) 32 { 32 { 33 33 // this->axis.reset() ; 34 34 // this->domain.reset() ; 35 35 deque< CArray<int, 1>* >::iterator it ; 36 36 37 37 for(deque< CArray<int,1>* >::iterator it=storeIndex.begin(); it!=storeIndex.end();it++) delete *it ; 38 38 for(deque< CArray<int,1>* >::iterator it=out_i_index.begin();it!=out_i_index.end();it++) delete *it ; … … 55 55 56 56 const std::deque< CArray<int,1>* > & CGrid::getStoreIndex(void) const 57 { 57 { 58 58 return (this->storeIndex ); 59 59 } … … 62 62 63 63 const std::deque< CArray<int,1>* > & CGrid::getOutIIndex(void) const 64 { 65 return (this->out_i_index ); 64 { 65 return (this->out_i_index ); 66 66 } 67 67 … … 69 69 70 70 const std::deque< CArray<int,1>* > & CGrid::getOutJIndex(void) const 71 { 72 return (this->out_j_index ); 71 { 72 return (this->out_j_index ); 73 73 } 74 74 … … 76 76 77 77 const std::deque< CArray<int,1>* > & CGrid::getOutLIndex(void) const 78 { 79 return (this->out_l_index ); 78 { 79 return (this->out_l_index ); 80 80 } 81 81 … … 83 83 84 84 const CAxis* CGrid::getRelAxis (void) const 85 { 86 return (this->axis ); 85 { 86 return (this->axis ); 87 87 } 88 88 … … 90 90 91 91 const CDomain* CGrid::getRelDomain(void) const 92 { 93 return (this->domain ); 94 } 95 96 //--------------------------------------------------------------- 97 98 bool CGrid::hasAxis(void) const 99 { 100 return (this->withAxis); 92 { 93 return (this->domain ); 94 } 95 96 //--------------------------------------------------------------- 97 98 bool CGrid::hasAxis(void) const 99 { 100 return (this->withAxis); 101 101 } 102 102 … … 122 122 */ 123 123 //--------------------------------------------------------------- 124 124 125 125 /* 126 126 StdSize CGrid::getLocalSize(void) const … … 147 147 //--------------------------------------------------------------- 148 148 149 /* 149 /* 150 150 StdSize CGrid::getGlobalSize(void) const 151 151 { … … 166 166 } 167 167 168 //--------------------------------------------------------------- 169 170 void CGrid::solveReference(void) 171 { 172 if (this->isChecked) return; 173 CContext* context = CContext::getCurrent() ; 174 CContextClient* client=context->client ; 175 176 this->solveDomainRef() ; 177 this->solveAxisRef() ; 178 179 if (context->hasClient) 180 { 181 checkMask() ; 182 this->computeIndex() ; 183 184 this->storeIndex.push_front(new CArray<int,1>() ); 185 this->out_i_index.push_front(new CArray<int,1>()); 186 this->out_j_index.push_front(new CArray<int,1>()); 187 this->out_l_index.push_front(new CArray<int,1>()); 188 } 168 std::map<int, StdSize> CGrid::getConnectedServerDataSize() 169 { 170 std::map<int, StdSize> ret; 171 std::map<int, int>::const_iterator it = domConnectedServerSide_.begin(), 172 itE = domConnectedServerSide_.end(); 173 StdSize retVal = StdSize(0.0); 174 for (; it != itE; ++it) 175 { 176 retVal = it->second; 177 if (this->withAxis) retVal *= this->axis->size.getValue(); 178 retVal *= sizeof(double); 179 ret.insert(make_pair(it->first, retVal)); 180 } 181 return ret; 182 } 183 184 185 //--------------------------------------------------------------- 186 187 // void CGrid::solveReference(void) 188 // { 189 // if (this->isChecked) return; 190 // CContext* context = CContext::getCurrent() ; 191 // CContextClient* client=context->client ; 192 // 193 // this->solveDomainRef() ; 194 // this->solveAxisRef() ; 195 // 196 // if (context->hasClient) 197 // { 198 // checkMask() ; 199 // this->computeIndex() ; 200 // 201 // this->storeIndex.push_front(new CArray<int,1>() ); 202 // this->out_i_index.push_front(new CArray<int,1>()); 203 // this->out_j_index.push_front(new CArray<int,1>()); 204 // this->out_l_index.push_front(new CArray<int,1>()); 205 // } 206 //// this->computeIndexServer(); 207 // this->isChecked = true; 208 // } 209 210 void CGrid::solveDomainAxisRef(bool areAttributesChecked) 211 { 212 if (this->isDomainAxisChecked) return; 213 214 this->solveDomainRef(areAttributesChecked); 215 this->solveAxisRef(areAttributesChecked); 216 217 this->isDomainAxisChecked = areAttributesChecked; 218 } 219 220 void CGrid::checkMaskIndex(bool doSendingIndex) 221 { 222 CContext* context = CContext::getCurrent() ; 223 CContextClient* client=context->client ; 224 225 if (context->hasClient) 226 if (this->isChecked && doSendingIndex) sendIndex(); 227 228 if (this->isChecked) return; 229 230 if (context->hasClient) 231 { 232 checkMask() ; 233 this->computeIndex() ; 234 235 this->storeIndex.push_front(new CArray<int,1>() ); 236 this->out_i_index.push_front(new CArray<int,1>()); 237 this->out_j_index.push_front(new CArray<int,1>()); 238 this->out_l_index.push_front(new CArray<int,1>()); 239 } 189 240 // this->computeIndexServer(); 190 241 this->isChecked = true; 191 242 } 192 243 … … 206 257 (mask.extent(2) != nlu)) 207 258 ERROR("CGrid::checkAttributes(void)", 208 <<"The mask has not the same size than the local grid"<<endl 259 <<"The mask has not the same size than the local grid"<<endl 209 260 <<"Local size is "<<niu<<"x"<<nju<<"x"<<nlu<<endl 210 261 <<"Mask size is "<<mask.extent(0)<<"x"<<mask.extent(1)<<"x"<<mask.extent(2)); 211 262 } 212 else 263 else 213 264 { 214 265 mask.resize(niu,nju,nlu) ; 215 266 mask=true ; 216 267 } 217 268 218 269 CArray<bool,2>& domainMask = domain->mask ; 219 270 for (int l=0; l < nlu ; l++) 220 271 for (int j=0; j < nju ; j++) 221 272 for(int i=0; i<niu ; i++) mask(i,j,l) = mask(i,j,l) && domainMask(i,j) ; 222 223 224 } 225 226 //--------------------------------------------------------------- 227 228 void CGrid::solveDomainRef(void) 273 274 275 } 276 277 //--------------------------------------------------------------- 278 279 // void CGrid::solveDomainRef(void) 280 // { 281 // if (!domain_ref.isEmpty()) 282 // { 283 // if (CDomain::has(domain_ref.getValue())) 284 // { 285 // this->domain = CDomain::get(domain_ref.getValue()) ; 286 // domain->checkAttributes() ; 287 // } 288 // else ERROR("CGrid::solveDomainRef(void)", 289 // << "Wrong domain reference") ; 290 // } 291 // else ERROR("CGrid::solveDomainRef(void)", 292 // << "Domain reference is not defined") ; 293 // } 294 // 295 // //--------------------------------------------------------------- 296 // 297 // void CGrid::solveAxisRef(void) 298 // { 299 // if (!axis_ref.isEmpty()) 300 // { 301 // this->withAxis = true ; 302 // if (CAxis::get(axis_ref.getValue())) 303 // { 304 // this->axis = CAxis::get(axis_ref.getValue()) ; 305 // axis->checkAttributes() ; 306 // } 307 // else ERROR("CGrid::solveAxisRef(void)", 308 // << "Wrong axis reference") ; 309 // } 310 // else withAxis = false ; 311 // } 312 313 314 void CGrid::solveDomainRef(bool sendAtt) 229 315 { 230 316 if (!domain_ref.isEmpty()) … … 233 319 { 234 320 this->domain = CDomain::get(domain_ref.getValue()) ; 235 domain->checkAttributes() ; 321 if (sendAtt) domain->sendCheckedAttributes(); 322 else domain->checkAttributesOnClient() ; 236 323 } 237 324 else ERROR("CGrid::solveDomainRef(void)", … … 244 331 //--------------------------------------------------------------- 245 332 246 void CGrid::solveAxisRef( void)333 void CGrid::solveAxisRef(bool checkAtt) 247 334 { 248 335 if (!axis_ref.isEmpty()) … … 263 350 264 351 void CGrid::computeIndex(void) 265 { 266 352 { 353 267 354 const int ni = domain->ni.getValue() , 268 355 nj = domain->nj.getValue() , … … 280 367 CArray<int,1> data_i_index = domain->data_i_index ; 281 368 CArray<int,1> data_j_index = domain->data_j_index ; 282 369 283 370 284 371 int indexCount = 0; … … 302 389 } 303 390 } 304 391 305 392 storeIndex[0] = new CArray<int,1>(indexCount) ; 306 393 out_i_index[0] = new CArray<int,1>(indexCount) ; 307 394 out_j_index[0] = new CArray<int,1>(indexCount) ; 308 395 out_l_index[0] = new CArray<int,1>(indexCount) ; 309 396 310 397 storeIndex_client.resize(indexCount) ; 311 398 out_i_client.resize(indexCount) ; 312 399 out_j_client.resize(indexCount) ; 313 400 out_l_client.resize(indexCount) ; 314 315 401 402 316 403 for(int count = 0, indexCount = 0, l = 0; l < size; l++) 317 404 { … … 334 421 (*out_i_index[0])(indexCount) = i ; 335 422 (*out_j_index[0])(indexCount) = j ; 336 423 337 424 storeIndex_client(indexCount) = count ; 338 425 out_i_client(indexCount)=i+domain->ibegin_client-1 ; … … 343 430 } 344 431 } 345 sendIndex() ; 432 computeDomConServer(); 433 // sendIndex() ; 346 434 347 435 … … 370 458 //---------------------------------------------------------------- 371 459 372 void CGrid::outputField(int rank, const CArray<double, 1>& stored, CArray<double, 3>& field) 460 void CGrid::outputField(int rank, const CArray<double, 1>& stored, CArray<double, 3>& field) 373 461 { 374 462 CArray<int,1>& out_i=*out_i_fromClient[rank] ; 375 463 CArray<int,1>& out_j=*out_j_fromClient[rank] ; 376 464 CArray<int,1>& out_l=*out_l_fromClient[rank] ; 377 465 378 466 for(StdSize n = 0; n < stored.numElements(); n++) 379 467 field(out_i(n), out_j(n), out_l(n)) = stored(n) ; 380 468 } 381 469 382 void CGrid::outputField(int rank, const CArray<double, 1>& stored, CArray<double, 2>& field) 470 void CGrid::outputField(int rank, const CArray<double, 1>& stored, CArray<double, 2>& field) 383 471 { 384 472 CArray<int,1>& out_i=*out_i_fromClient[rank] ; 385 473 CArray<int,1>& out_j=*out_j_fromClient[rank] ; 386 474 387 475 for(StdSize n = 0; n < stored.numElements(); n++) 388 476 field(out_i(n), out_j(n)) = stored(n) ; } … … 393 481 { 394 482 CArray<int,1>& out_i=*out_i_fromClient[rank] ; 395 483 396 484 for(StdSize n = 0; n < stored.numElements(); n++) 397 485 field(out_i(n)) = stored(n) ; … … 399 487 400 488 //---------------------------------------------------------------- 401 489 402 490 403 491 void CGrid::storeField_arr … … 409 497 for(StdSize i = 0; i < size; i++) stored(i) = data[storeIndex_client(i)] ; 410 498 } 411 412 //--------------------------------------------------------------- 499 500 //--------------------------------------------------------------- 501 502 // void CGrid::sendIndex(void) 503 // { 504 // CContext* context = CContext::getCurrent() ; 505 // CContextClient* client=context->client ; 506 // 507 // CEventClient event(getType(),EVENT_ID_INDEX) ; 508 // int rank ; 509 // list<shared_ptr<CMessage> > list_msg ; 510 // list< CArray<int,1>* > list_out_i,list_out_j,list_out_l ; 511 // 512 // for(int ns=0;ns<domain->connectedServer.size();ns++) 513 // { 514 // rank=domain->connectedServer[ns] ; 515 // 516 // int i,j ; 517 // int nb=0 ; 518 // for(int k=0;k<storeIndex_client.numElements();k++) 519 // { 520 // i=out_i_client(k)- domain->ibegin +1; 521 // j=out_j_client(k)- domain->jbegin +1; 522 // if (domain->mapConnectedServer(i,j)==ns) nb++ ; 523 // } 524 // 525 // CArray<int,1> storeIndex(nb) ; 526 // CArray<int,1> out_i(nb) ; 527 // CArray<int,1> out_j(nb) ; 528 // CArray<int,1> out_l(nb) ; 529 // 530 // 531 // nb=0 ; 532 // for(int k=0;k<storeIndex_client.numElements();k++) 533 // { 534 // i=out_i_client(k)- domain->ibegin +1 ; 535 // j=out_j_client(k)- domain->jbegin +1 ; 536 // if (domain->mapConnectedServer(i,j)==ns) 537 // { 538 // storeIndex(nb)=k ; 539 // out_i(nb)=domain->i_index(i,j) + domain->ibegin-1; 540 // out_j(nb)=domain->j_index(i,j) + domain->jbegin-1; 541 // out_l(nb)=out_l_client(k) ; 542 // nb++ ; 543 // } 544 // } 545 // 546 // storeIndex_toSrv.insert( pair<int,CArray<int,1>* >(rank,new CArray<int,1>(storeIndex) )) ; 547 // nbSenders.insert(pair<int,int>(rank,domain->nbSenders[ns])) ; 548 // list_msg.push_back(shared_ptr<CMessage>(new CMessage)) ; 549 // list_out_i.push_back(new CArray<int,1>(out_i)) ; 550 // list_out_j.push_back(new CArray<int,1>(out_j)) ; 551 // list_out_l.push_back(new CArray<int,1>(out_l)) ; 552 // 553 // *list_msg.back()<<getId()<<*list_out_i.back()<<*list_out_j.back()<<*list_out_l.back() ; 554 // event.push(rank,domain->nbSenders[ns],*list_msg.back()) ; 555 // } 556 // client->sendEvent(event) ; 557 // 558 // for(list<CArray<int,1>* >::iterator it=list_out_i.begin();it!=list_out_i.end();it++) delete *it ; 559 // for(list<CArray<int,1>* >::iterator it=list_out_j.begin();it!=list_out_j.end();it++) delete *it ; 560 // for(list<CArray<int,1>* >::iterator it=list_out_l.begin();it!=list_out_l.end();it++) delete *it ; 561 // 562 // } 563 564 void CGrid::computeDomConServer() 565 { 566 if (!isDomConServerComputed_) 567 { 568 for(int ns=0;ns<domain->connectedServer.size(); ++ns) 569 { 570 int rank=domain->connectedServer[ns] ; 571 572 int i,j ; 573 int nb=0 ; 574 for(int k=0;k<storeIndex_client.numElements();++k) 575 { 576 i=out_i_client(k)- domain->ibegin +1; 577 j=out_j_client(k)- domain->jbegin +1; 578 if (domain->mapConnectedServer(i,j)==ns) ++nb ; 579 } 580 581 domConnectedServerSide_.insert(std::make_pair(rank, nb)); 582 } 583 isDomConServerComputed_ = true; 584 } 585 } 586 587 588 std::map<int, int> CGrid::getDomConServerSide() 589 { 590 return domConnectedServerSide_; 591 } 413 592 414 593 void CGrid::sendIndex(void) … … 416 595 CContext* context = CContext::getCurrent() ; 417 596 CContextClient* client=context->client ; 418 597 419 598 CEventClient event(getType(),EVENT_ID_INDEX) ; 420 599 int rank ; 421 600 list<shared_ptr<CMessage> > list_msg ; 422 601 list< CArray<int,1>* > list_out_i,list_out_j,list_out_l ; 423 602 603 if (!isDomConServerComputed_) computeDomConServer(); 604 424 605 for(int ns=0;ns<domain->connectedServer.size();ns++) 425 606 { 426 607 rank=domain->connectedServer[ns] ; 427 428 int i,j ; 429 int nb=0 ; 430 for(int k=0;k<storeIndex_client.numElements();k++) 431 { 432 i=out_i_client(k)- domain->ibegin +1; 433 j=out_j_client(k)- domain->jbegin +1; 434 if (domain->mapConnectedServer(i,j)==ns) nb++ ; 435 } 436 608 609 int nb = domConnectedServerSide_.find(rank)->second; 437 610 CArray<int,1> storeIndex(nb) ; 438 611 CArray<int,1> out_i(nb) ; 439 612 CArray<int,1> out_j(nb) ; 440 613 CArray<int,1> out_l(nb) ; 441 442 614 615 int i, j; 443 616 nb=0 ; 444 617 for(int k=0;k<storeIndex_client.numElements();k++) … … 450 623 storeIndex(nb)=k ; 451 624 out_i(nb)=domain->i_index(i,j) + domain->ibegin-1; 452 out_j(nb)=domain->j_index(i,j) + domain->jbegin-1; 625 out_j(nb)=domain->j_index(i,j) + domain->jbegin-1; 453 626 out_l(nb)=out_l_client(k) ; 454 627 nb++ ; 455 628 } 456 629 } 457 630 458 631 storeIndex_toSrv.insert( pair<int,CArray<int,1>* >(rank,new CArray<int,1>(storeIndex) )) ; 459 632 nbSenders.insert(pair<int,int>(rank,domain->nbSenders[ns])) ; … … 471 644 for(list<CArray<int,1>* >::iterator it=list_out_j.begin();it!=list_out_j.end();it++) delete *it ; 472 645 for(list<CArray<int,1>* >::iterator it=list_out_l.begin();it!=list_out_l.end();it++) delete *it ; 473 646 474 647 } 475 648 476 649 void CGrid::recvIndex(CEventServer& event) 477 650 { … … 486 659 } 487 660 } 488 661 489 662 void CGrid::recvIndex(int rank, CBufferIn& buffer) 490 663 { … … 492 665 CArray<int,1> out_j ; 493 666 CArray<int,1> out_l ; 494 667 495 668 buffer>>out_i>>out_j>>out_l ; 496 669 497 670 out_i -= domain->zoom_ibegin_srv-1 ; 498 671 out_j -= domain->zoom_jbegin_srv-1 ; 499 672 500 673 out_i_fromClient.insert(pair< int,CArray<int,1>* >(rank,new CArray<int,1>(out_i) )) ; 501 674 out_j_fromClient.insert(pair< int,CArray<int,1>* >(rank,new CArray<int,1>(out_j) )) ; … … 505 678 bool CGrid::dispatchEvent(CEventServer& event) 506 679 { 507 680 508 681 if (SuperClass::dispatchEvent(event)) return true ; 509 682 else … … 515 688 return true ; 516 689 break ; 517 690 518 691 default : 519 692 ERROR("bool CDomain::dispatchEvent(CEventServer& event)", … … 532 705 << "Data from clients are missing!") ; 533 706 storedServer.resize(storeIndex[0]->numElements()); 534 707 535 708 for (StdSize i = 0, n = 0; i < storedClient.size(); i++) 536 709 for (StdSize j = 0; j < storedClient[i]->numElements(); j++) … … 543 716 int nb=index.numElements() ; 544 717 fieldOut.resize(nb) ; 545 718 546 719 for(int k=0;k<nb;k++) fieldOut(k)=fieldIn(index(k)) ; 547 720 } -
XIOS/trunk/src/node/grid.hpp
r501 r509 13 13 14 14 namespace xios { 15 15 16 16 /// ////////////////////// Déclarations ////////////////////// /// 17 17 … … 46 46 EVENT_ID_INDEX 47 47 } ; 48 48 49 49 /// Constructeurs /// 50 50 CGrid(void); … … 54 54 55 55 /// Traitements /// 56 void solveReference(void); 56 // void solveReference(void); 57 58 void solveDomainAxisRef(bool areAttributesChecked); 59 60 void checkMaskIndex(bool doCalculateIndex); 57 61 58 62 // virtual void toBinary (StdOStream & os) const; … … 74 78 75 79 StdSize getDimension(void) const; 76 80 77 81 // StdSize getLocalSize(void) const; 78 82 // StdSize getGlobalSize(void) const; … … 84 88 template <int n> 85 89 void inputField(const CArray<double,n>& field, CArray<double,1>& stored) const; 86 90 87 91 void inputFieldServer(const std::deque< CArray<double, 1>* > storedClient, 88 92 CArray<double, 1>& storedServer) const; … … 90 94 void outputField(int rank, const CArray<double,1>& stored, CArray<double,3>& field) ; 91 95 void outputField(int rank, const CArray<double,1>& stored, CArray<double,2>& field) ; 92 void outputField(int rank, const CArray<double,1>& stored, CArray<double,1>& field) ; 93 96 void outputField(int rank, const CArray<double,1>& stored, CArray<double,1>& field) ; 97 94 98 /// Destructeur /// 95 99 virtual ~CGrid(void); … … 100 104 static StdString GetName(void); 101 105 static StdString GetDefName(void); 102 106 103 107 static ENodeType GetType(void); 104 108 … … 115 119 void computeIndexServer(void); 116 120 void computeIndex(void); 117 void solveDomainRef(void); 118 void solveAxisRef(void); 121 // void solveDomainRef(void); //TODO temporarily comment 122 // void solveAxisRef(void); // TODO: temporarily comment 123 124 void solveDomainRef(bool checkAtt); 125 void solveAxisRef(bool checkAtt); 119 126 120 127 static bool dispatchEvent(CEventServer& event) ; … … 123 130 void recvIndex(int rank, CBufferIn& buffer) ; 124 131 void sendIndex(void) ; 125 132 133 void computeDomConServer(); 134 std::map<int, int> getDomConServerSide(); 135 std::map<int, StdSize> getConnectedServerDataSize(); 126 136 public: 127 137 … … 129 139 bool withAxis ; 130 140 bool isChecked; 141 bool isDomainAxisChecked; 131 142 132 143 CAxis* axis ; … … 137 148 std::deque< CArray<int, 1>* > out_j_index ; 138 149 std::deque< CArray<int, 1>* > out_l_index ; 139 150 140 151 CArray<int, 1> storeIndex_client ; 141 152 CArray<int, 1> out_i_client ; 142 153 CArray<int, 1> out_j_client ; 143 154 CArray<int, 1> out_l_client ; 144 155 145 156 map<int, CArray<int, 1>* > storeIndex_toSrv ; 146 157 map<int,int> nbSenders ; … … 148 159 // std::deque<ARRAY(int, 1)> out_j_toSrv ; 149 160 // std::deque<ARRAY(int, 1)> out_l_toSrv ; 150 161 151 162 map<int, CArray<int, 1>* > out_i_fromClient ; 152 163 map<int, CArray<int, 1>* > out_j_fromClient ; 153 164 map<int, CArray<int, 1>* > out_l_fromClient ; 154 165 void checkMask(void) ; 166 167 std::map<int, int> domConnectedServerSide_; 168 bool isDomConServerComputed_; 155 169 }; // class CGrid 156 170
Note: See TracChangeset
for help on using the changeset viewer.