Changeset 509 for XIOS/trunk/src/node


Ignore:
Timestamp:
11/13/14 15:09:14 (10 years ago)
Author:
mhnguyen
Message:

Implementing buffer size auto-detection for mode client -server

+) Process xml tree in client side then send all the information to server
+) Only information enabled fields in enabled files are sent to server
+) Some important change in structure of code which must be refactored

Test
+) On Curie
+) Only mode client-server
+) Passed for all tests

Location:
XIOS/trunk/src/node
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/node/context.cpp

    r501 r509  
    1616 
    1717namespace xios { 
    18    
     18 
    1919  shared_ptr<CContextGroup> CContext::root ; 
    20     
     20 
    2121   /// ////////////////////// Définitions ////////////////////// /// 
    2222 
    2323   CContext::CContext(void) 
    2424      : CObjectTemplate<CContext>(), CContextAttributes() 
    25       , calendar(),hasClient(false),hasServer(false) 
     25      , calendar(),hasClient(false),hasServer(false), isPostProcessed(false), dataSize_() 
    2626   { /* Ne rien faire de plus */ } 
    2727 
    2828   CContext::CContext(const StdString & id) 
    2929      : CObjectTemplate<CContext>(id), CContextAttributes() 
    30       , calendar(),hasClient(false),hasServer(false) 
     30      , calendar(),hasClient(false),hasServer(false), isPostProcessed(false), dataSize_() 
    3131   { /* Ne rien faire de plus */ } 
    3232 
    3333   CContext::~CContext(void) 
    34    {  
     34   { 
    3535     if (hasClient) delete client ; 
    3636     if (hasServer) delete server ; 
     
    3838 
    3939   //---------------------------------------------------------------- 
    40  
     40   //! Get name of context 
    4141   StdString CContext::GetName(void)   { return (StdString("context")); } 
    4242   StdString CContext::GetDefName(void){ return (CContext::GetName()); } 
     
    4444 
    4545   //---------------------------------------------------------------- 
    46  
     46   /*! 
     47   \brief Get context group (context root) 
     48   \return Context root 
     49   */ 
    4750   CContextGroup* CContext::getRoot(void) 
    48    {   
     51   { 
    4952      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   */ 
    5662   boost::shared_ptr<CCalendar> CContext::getCalendar(void) const 
    5763   { 
    5864      return (this->calendar); 
    5965   } 
    60     
    61    //---------------------------------------------------------------- 
    62     
     66 
     67   //---------------------------------------------------------------- 
     68   /*! 
     69   \brief Set a context with a calendar 
     70   \param[in] newCalendar new calendar 
     71   */ 
    6372   void CContext::setCalendar(boost::shared_ptr<CCalendar> newCalendar) 
    6473   { 
     
    6776      start_date.setValue(this->calendar->getInitDate().toString()); 
    6877   } 
    69     
    70    //---------------------------------------------------------------- 
    71  
     78 
     79   //---------------------------------------------------------------- 
     80   //! Process all information of calendar 
    7281   void CContext::solveCalendar(void) 
    7382   { 
     
    97106            << "The calendar is not defined !"); 
    98107   } 
    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   */ 
    102114   void CContext::parse(xml::CXMLNode & node) 
    103115   { 
     
    135147 
    136148            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            } 
    139153 
    140154#define DECLARE_NODE(Name_, name_)    \ 
     
    155169 
    156170   //---------------------------------------------------------------- 
    157  
     171   //! Show tree structure of context 
    158172   void CContext::ShowTree(StdOStream & out) 
    159173   { 
     
    166180      out << "<? xml version=\"1.0\" ?>" << std::endl; 
    167181      out << "<"  << xml::CXMLNode::GetRootName() << " >" << std::endl; 
    168        
     182 
    169183      for (; it != end; it++) 
    170184      { 
    171          CContext* context = *it;          
    172          CContext::setCurrent(context->getId());          
     185         CContext* context = *it; 
     186         CContext::setCurrent(context->getId()); 
    173187         out << *context << std::endl; 
    174188      } 
    175        
     189 
    176190      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) 
    183198   StdString CContext::toString(void) const 
    184199   { 
     
    209224   //---------------------------------------------------------------- 
    210225 
     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   */ 
    211232   void CContext::solveDescInheritance(bool apply, const CAttributeMap * const UNUSED(parent)) 
    212233   { 
     
    220241   //---------------------------------------------------------------- 
    221242 
     243   //! Verify if all root definition in the context have child. 
    222244   bool CContext::hasChild(void) const 
    223245   { 
     
    230252} 
    231253 
    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//   } 
    248270 
    249271   //---------------------------------------------------------------- 
     
    256278   } 
    257279   ///--------------------------------------------------------------- 
    258     
     280 
     281   //! Initialize client side 
    259282   void CContext::initClient(MPI_Comm intraComm, MPI_Comm interComm) 
    260283   { 
    261284     hasClient=true ; 
    262285     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 
    265297   bool CContext::isInitialized(void) 
    266298   { 
    267299     return hasClient ; 
    268300   } 
    269      
     301 
     302   //! Initialize server 
    270303   void CContext::initServer(MPI_Comm intraComm,MPI_Comm interComm) 
    271304   { 
    272305     hasServer=true ; 
    273306     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 
    276310   bool CContext::eventLoop(void) 
    277311   { 
    278312     return server->eventLoop() ; 
    279    }  
    280     
     313   } 
     314 
     315   //! Terminate a context 
    281316   void CContext::finalize(void) 
    282317   { 
     
    290325      } 
    291326   } 
    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   */ 
    296337   void CContext::closeDefinition(void) 
    297338   { 
    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/* 
    312407      //Recherche des champs à sortir (enable à true + niveau de sortie correct) 
    313408      // pour chaque fichier précédemment listé. 
     
    324419*/ 
    325420      // Nettoyage de l'arborescence 
    326       CleanTree(); 
     421      if (hasClient && !hasServer) CleanTree(); // Only on client side?? 
     422//      if (hasClient) CleanTree(); 
    327423      if (hasClient) sendCreateFileHeader() ; 
    328424   } 
    329     
     425 
    330426   void CContext::findAllEnabledFields(void) 
    331427   { 
     
    333429     (void)this->enabledFiles[i]->getEnabledFields(); 
    334430   } 
    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 
    361475   void CContext::solveAllInheritance(bool apply) 
    362476   { 
     
    368482      const vector<CFile*> allFiles=CFile::getAll() ; 
    369483 
     484     if (hasClient && !hasServer) 
    370485      for (unsigned int i = 0; i < allFiles.size(); i++) 
    371486         allFiles[i]->solveFieldRefInheritance(apply); 
     
    383498         } 
    384499         else enabledFiles.push_back(allFiles[i]); // otherwise true by default 
    385                 
     500 
    386501 
    387502      if (enabledFiles.size() == 0) 
     
    394509     std::vector<CFile*>::const_iterator 
    395510            it = this->enabledFiles.begin(), end = this->enabledFiles.end(); 
    396           
     511 
    397512     for (; it != end; it++) 
    398513     { 
     
    401516     } 
    402517   } 
    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   */ 
    404526   bool CContext::dispatchEvent(CEventServer& event) 
    405527   { 
    406        
     528 
    407529      if (SuperClass::dispatchEvent(event)) return true ; 
    408530      else 
     
    422544             return true ; 
    423545             break ; 
     546           case EVENT_ID_POST_PROCESS: 
     547             recvPostProcessing(event) ; 
     548             return true ; 
     549             break ; 
    424550           default : 
    425551             ERROR("bool CContext::dispatchEvent(CEventServer& event)", 
     
    429555      } 
    430556   } 
    431     
     557 
     558   //! Client side: Send a message to server to make it close 
    432559   void CContext::sendCloseDefinition(void) 
    433560   { 
    434  
    435      CEventClient event(getType(),EVENT_ID_CLOSE_DEFINITION) ;    
     561     CEventClient event(getType(),EVENT_ID_CLOSE_DEFINITION) ; 
    436562     if (client->isServerLeader()) 
    437563     { 
     
    443569     else client->sendEvent(event) ; 
    444570   } 
    445     
     571 
     572   //! Server side: Receive a message of client announcing a context close 
    446573   void CContext::recvCloseDefinition(CEventServer& event) 
    447574   { 
    448        
     575 
    449576      CBufferIn* buffer=event.subEvents.begin()->buffer; 
    450577      string id; 
    451578      *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 
    455583   void CContext::sendUpdateCalendar(int step) 
    456584   { 
    457585     if (!hasServer) 
    458586     { 
    459        CEventClient event(getType(),EVENT_ID_UPDATE_CALENDAR) ;    
     587       CEventClient event(getType(),EVENT_ID_UPDATE_CALENDAR) ; 
    460588       if (client->isServerLeader()) 
    461589       { 
     
    468596     } 
    469597   } 
    470     
     598 
     599   //! Server side: Receive a message of client annoucing calendar update 
    471600   void CContext::recvUpdateCalendar(CEventServer& event) 
    472601   { 
    473        
     602 
    474603      CBufferIn* buffer=event.subEvents.begin()->buffer; 
    475604      string id; 
     
    477606      get(id)->recvUpdateCalendar(*buffer) ; 
    478607   } 
    479     
     608 
     609   //! Server side: Receive a message of client annoucing calendar update 
    480610   void CContext::recvUpdateCalendar(CBufferIn& buffer) 
    481611   { 
     
    484614      updateCalendar(step) ; 
    485615   } 
    486     
     616 
     617   //! Client side: Send a message to create header part of netcdf file 
    487618   void CContext::sendCreateFileHeader(void) 
    488619   { 
    489  
    490      CEventClient event(getType(),EVENT_ID_CREATE_FILE_HEADER) ;    
     620     CEventClient event(getType(),EVENT_ID_CREATE_FILE_HEADER) ; 
    491621     if (client->isServerLeader()) 
    492622     { 
     
    498628     else client->sendEvent(event) ; 
    499629   } 
    500     
     630 
     631   //! Server side: Receive a message of client annoucing the creation of header part of netcdf file 
    501632   void CContext::recvCreateFileHeader(CEventServer& event) 
    502633   { 
    503        
    504634      CBufferIn* buffer=event.subEvents.begin()->buffer; 
    505635      string id; 
     
    507637      get(id)->recvCreateFileHeader(*buffer) ; 
    508638   } 
    509     
     639 
     640   //! Server side: Receive a message of client annoucing the creation of header part of netcdf file 
    510641   void CContext::recvCreateFileHeader(CBufferIn& buffer) 
    511642   { 
    512643      createFileHeader() ; 
    513644   } 
    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 
    515852   void CContext::updateCalendar(int step) 
    516853   { 
     
    519856      info(50)<<"updateCalendar : after : "<<calendar->getCurrentDate()<<endl ; 
    520857   } 
    521   
     858 
     859   //! Server side: Create header of netcdf file 
    522860   void CContext::createFileHeader(void ) 
    523861   { 
    524862      vector<CFile*>::const_iterator it ; 
    525           
     863 
    526864      for (it=enabledFiles.begin(); it != enabledFiles.end(); it++) 
    527865      { 
    528866         (*it)->initFile(); 
    529867      } 
    530    }  
    531     
     868   } 
     869 
     870   //! Get current context 
    532871   CContext* CContext::getCurrent(void) 
    533872   { 
    534873     return CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId()).get() ; 
    535874   } 
    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   */ 
    537880   void CContext::setCurrent(const string& id) 
    538881   { 
     
    540883     CGroupFactory::SetCurrentContextId(id); 
    541884   } 
    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  */ 
    543891  CContext* CContext::create(const StdString& id) 
    544892  { 
    545893    CContext::setCurrent(id) ; 
    546   
     894 
    547895    bool hasctxt = CContext::has(id); 
    548896    CContext* context = CObjectFactory::CreateObject<CContext>(id).get(); 
  • XIOS/trunk/src/node/context.hpp

    r501 r509  
    1818   class CContextClient ; 
    1919   class CContextServer ; 
    20     
    21     
     20 
     21 
    2222   /// ////////////////////// Déclarations ////////////////////// /// 
    2323   class CContextGroup; 
     
    3333 
    3434   ///-------------------------------------------------------------- 
    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  */ 
    3643   class CContext 
    3744      : public CObjectTemplate<CContext> 
     
    4249         { 
    4350           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 
    4553         } ; 
    46           
     54 
    4755         /// typedef /// 
    4856         typedef CObjectTemplate<CContext>   SuperClass; 
     
    7078 
    7179      public : 
    72        
     80 
    7381         /// Mutateurs /// 
    7482         void setCalendar(boost::shared_ptr<CCalendar> newCalendar); 
    75        
     83 
    7684         /// Accesseurs /// 
    7785         boost::shared_ptr<CCalendar>      getCalendar(void) const; 
    7886 
    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 
    10094         bool eventLoop(void) ; 
    10195         bool serverLoop(void) ; 
    10296         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 
    110102         void finalize(void) ; 
    111103         void closeDefinition(void) ; 
     104 
     105         // Some functions to process context 
    112106         void findAllEnabledFields(void); 
    113107         void processEnabledFiles(void) ; 
    114          void solveAllGridRef(void); 
    115          void solveAllOperation(void); 
    116          void solveAllExpression(void); 
    117108         void solveAllInheritance(bool apply=true) ; 
    118109         void findEnabledFiles(void); 
     
    120111         void updateCalendar(int step) ; 
    121112         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 
    124121         void sendCloseDefinition(void) ; 
     122         // There are something to send on closing context defintion 
    125123         void sendUpdateCalendar(int step) ; 
    126124         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 
    127132         static void recvUpdateCalendar(CEventServer& event) ; 
    128133         void recvUpdateCalendar(CBufferIn& buffer) ; 
     
    130135         static void recvCreateFileHeader(CEventServer& event) ; 
    131136         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 
    140171         virtual void parse(xml::CXMLNode & node); 
    141172 
     173         // Visualize a context 
    142174         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) 
    150188         std::vector<CFile*> enabledFiles; 
     189 
     190         // Context root 
    151191         static shared_ptr<CContextGroup> root ; 
    152192 
     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); 
    153217 
    154218   }; // class CContext 
  • XIOS/trunk/src/node/domain.cpp

    r501 r509  
    1616 
    1717namespace xios { 
    18     
     18 
    1919   /// ////////////////////// Définitions ////////////////////// /// 
    2020 
    2121   CDomain::CDomain(void) 
    2222      : CObjectTemplate<CDomain>(), CDomainAttributes() 
    23       , isChecked(false),  relFiles() 
     23      , isChecked(false), relFiles(), isClientChecked(false) 
    2424   { /* Ne rien faire de plus */ } 
    2525 
    2626   CDomain::CDomain(const StdString & id) 
    2727      : CObjectTemplate<CDomain>(id), CDomainAttributes() 
    28       , isChecked(false), relFiles() 
     28      , isChecked(false), relFiles(), isClientChecked(false) 
    2929         { /* Ne rien faire de plus */ } 
    3030 
    3131   CDomain::~CDomain(void) 
    32    {  
     32   { 
    3333   } 
    3434 
     
    3737   const std::set<StdString> & CDomain::getRelFiles(void) const 
    3838   { 
    39       return (this->relFiles);  
    40    } 
    41  
    42    //---------------------------------------------------------------- 
    43     
     39      return (this->relFiles); 
     40   } 
     41 
     42   //---------------------------------------------------------------- 
     43 
    4444   bool CDomain::hasZoom(void) const 
    4545   { 
    46       return ((this->zoom_ni.getValue() != this->ni_glo.getValue()) &&  
     46      return ((this->zoom_ni.getValue() != this->ni_glo.getValue()) && 
    4747              (this->zoom_nj.getValue() != this->nj_glo.getValue())); 
    4848   } 
    49     
    50    //---------------------------------------------------------------- 
    51     
     49 
     50   //---------------------------------------------------------------- 
     51 
    5252   bool CDomain::isEmpty(void) const 
    5353   { 
    54       return ((this->zoom_ni_srv == 0) ||  
     54      return ((this->zoom_ni_srv == 0) || 
    5555              (this->zoom_nj_srv == 0)); 
    5656   } 
     
    8686               << "[ Id = " << this->getId() << " ] " 
    8787               << "The global domain is badly defined," 
    88                << " check the \'ni_glo\'  value !")  
     88               << " check the \'ni_glo\'  value !") 
    8989         } 
    9090         nj_glo=ni_glo ; 
     
    111111         ibegin=1 ; 
    112112         iend=1 ; 
    113           
     113 
    114114      } 
    115115      else if ((ni_glo.isEmpty() || ni_glo.getValue() <= 0 ) || 
     
    119119               << "[ Id = " << this->getId() << " ] " 
    120120               << "The global domain is badly defined," 
    121                << " check the \'ni_glo\' et \'nj_glo\' values !")  
     121               << " check the \'ni_glo\' et \'nj_glo\' values !") 
    122122      } 
    123123      checkLocalIDomain() ; 
    124124      checkLocalJDomain() ; 
    125        
     125 
    126126     if (i_index.isEmpty()) 
    127127     { 
    128128       i_index.resize(ni,nj) ; 
    129129       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 ; 
    131131     } 
    132       
     132 
    133133     if (j_index.isEmpty()) 
    134134     { 
    135135        j_index.resize(ni,nj) ; 
    136136        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 ; 
    138138     } 
    139   
     139 
    140140   } 
    141141 
     
    211211               << "Domain is wrong defined," 
    212212               << " Check the values : nj, nj_glo, jbegin, jend") ; 
    213                 
     213 
    214214     ibegin_client=ibegin ; iend_client=iend ; ni_client=ni ; 
    215215     jbegin_client=jbegin ; jend_client=jend ; nj_client=nj ; 
     
    221221   { 
    222222      using namespace std; 
    223        
     223 
    224224      int ibegin_mask = 0, 
    225225          jbegin_mask = 0, 
    226226          iend_mask = iend.getValue() - ibegin.getValue(), 
    227227          jend_mask = jend.getValue() - jbegin.getValue(); 
    228        
     228 
    229229      if (!zoom_ibegin.isEmpty()) 
    230230      { 
    231231         int zoom_iend = zoom_ibegin.getValue() + zoom_ni.getValue() - 1; 
    232232         int zoom_jend = zoom_jbegin.getValue() + zoom_nj.getValue() - 1; 
    233           
     233 
    234234         ibegin_mask = max (ibegin.getValue(), zoom_ibegin.getValue()); 
    235235         jbegin_mask = max (jbegin.getValue(), zoom_jbegin.getValue()); 
    236236         iend_mask   = min (iend.getValue(), zoom_iend); 
    237237         jend_mask   = min (jend.getValue(), zoom_jend); 
    238                   
     238 
    239239         ibegin_mask -= ibegin.getValue(); 
    240240         jbegin_mask -= jbegin.getValue(); 
     
    242242         jend_mask   -= jbegin.getValue(); 
    243243      } 
    244        
     244 
    245245 
    246246      if (!mask.isEmpty()) 
     
    251251                  <<"the mask has not the same size than the local domain"<<endl 
    252252                   <<"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)); 
    254254         for (int i = 0; i < ni; i++) 
    255255         { 
     
    283283 
    284284   void CDomain::checkDomainData(void) 
    285    {      
     285   { 
    286286      if (!data_dim.isEmpty() && 
    287287         !(data_dim.getValue() == 1 || data_dim.getValue() == 2)) 
     
    378378            data_i_index.resize(dni) ; 
    379379            data_j_index.resize(dni) ; 
    380              
     380 
    381381            data_n_index.setValue(dni); 
    382              
     382 
    383383            for(int count = 0, j = 0; j  < data_nj.getValue(); j++) 
    384384            { 
     
    394394 
    395395   //---------------------------------------------------------------- 
    396     
     396 
    397397   void CDomain::completeLonLatClient(void) 
    398398   { 
     
    402402      CArray<double,2> bounds_lon_temp(nvertex,ni*nj) ; 
    403403      CArray<double,2> bounds_lat_temp(nvertex,ni*nj) ; 
    404        
     404 
    405405      if (type.isEmpty()) 
    406406      { 
    407         if ( lonvalue.numElements() == ni*nj && latvalue.numElements() == ni*nj )  
     407        if ( lonvalue.numElements() == ni*nj && latvalue.numElements() == ni*nj ) 
    408408        { 
    409409          type.setValue(type_attr::curvilinear) ; 
    410410          isCurvilinear=true ; 
    411411        } 
    412         else if ( lonvalue.numElements() == ni && latvalue.numElements() == nj )  
     412        else if ( lonvalue.numElements() == ni && latvalue.numElements() == nj ) 
    413413        { 
    414414          type.setValue(type_attr::regular) ; 
     
    429429      { 
    430430        for(j=0;j<nj;j++) 
    431           for(i=0;i<ni;i++)  
     431          for(i=0;i<ni;i++) 
    432432          { 
    433433            k=j*ni+i ; 
     
    436436            if (hasBounds) 
    437437            { 
    438               for(int n=0;n<nvertex;n++)  
     438              for(int n=0;n<nvertex;n++) 
    439439              { 
    440440                bounds_lon_temp(n,k)=bounds_lon(n,i) ; 
     
    444444          } 
    445445      } 
    446           
     446 
    447447      StdSize dm = zoom_ni_client * zoom_nj_client; 
    448448 
    449449      lonvalue.resize(dm); 
    450450      latvalue.resize(dm); 
    451           
     451 
    452452      for (int i = 0; i < zoom_ni_client; i++) 
    453453      { 
    454454        for (int j = 0; j < zoom_nj_client; j++) 
    455455        { 
    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 ); 
    457457          latvalue(i + j * zoom_ni_client) = latvalue_temp( (i + zoom_ibegin_client - ibegin)+(j + zoom_jbegin_client - jbegin)*ni ); 
    458458          if (hasBounds) 
    459459          { 
    460             for(int n=0;n<nvertex;n++)  
     460            for(int n=0;n<nvertex;n++) 
    461461            { 
    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 ); 
    463463              bounds_lat(n,i + j * zoom_ni_client) = bounds_lat_temp( n, (i + zoom_ibegin_client - ibegin)+(j + zoom_jbegin_client -jbegin)*ni ); 
    464464            } 
     
    467467      } 
    468468    } 
    469   
     469 
    470470 
    471471   //---------------------------------------------------------------- 
     
    487487            int zoom_iend = zoom_ibegin + zoom_ni - 1; 
    488488            int zoom_jend = zoom_jbegin + zoom_nj - 1; 
    489                  
     489 
    490490            if (zoom_ibegin < 1  || zoom_jbegin < 1 || zoom_iend > ni_glo || zoom_jend > nj_glo) 
    491491               ERROR("CDomain::checkZoom(void)", 
     
    496496      else 
    497497      { 
    498          zoom_ni = ni_glo;  
     498         zoom_ni = ni_glo; 
    499499         zoom_nj = nj_glo; 
    500500         zoom_ibegin = 1; 
    501501         zoom_jbegin = 1; 
    502502      } 
    503        
     503 
    504504      // compute client zoom indices 
    505505 
     
    510510      if (zoom_ni_client<0) zoom_ni_client=0 ; 
    511511 
    512      
     512 
    513513      int zoom_jend=zoom_jbegin+zoom_nj-1 ; 
    514514      zoom_jbegin_client = jbegin_client > zoom_jbegin ? jbegin_client : zoom_jbegin ; 
     
    518518 
    519519   } 
    520     
     520 
    521521   void CDomain::checkBounds(void) 
    522522   { 
     
    524524     { 
    525525       hasBounds=true ; 
    526         
     526 
    527527     } 
    528      else  
     528     else 
    529529     { 
    530530       hasBounds=false; 
     
    532532     } 
    533533   } 
    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(); 
    541542 
    542543      this->checkDomain(); 
    543544      this->checkZoom(); 
    544545      this->checkBounds(); 
    545        
     546 
    546547      if (context->hasClient) 
    547548      { // CÃŽté client uniquement 
     
    550551         this->checkCompression(); 
    551552         this->completeLonLatClient(); 
     553         this->computeConnectedServer() ; 
    552554      } 
    553555      else 
     
    556558// ne sert plus //   this->completeLonLatServer(); 
    557559      } 
    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 
    559602      if (context->hasClient) 
    560603      { 
     
    563606        sendLonLat() ; 
    564607      } 
    565        
     608 
    566609      this->isChecked = true; 
    567610   } 
    568     
     611 
    569612  void CDomain::sendServerAttribut(void) 
    570613  { 
     
    572615    int ibegin_srv=1 ; 
    573616    int iend_srv=ni_glo.getValue() ; 
    574       
     617 
    575618    int nj_srv ; 
    576619    int jbegin_srv ; 
    577620    int jend_srv ; 
    578      
     621 
    579622    CContext* context=CContext::getCurrent() ; 
    580623    CContextClient* client=context->client ; 
    581624    int nbServer=client->serverSize ; 
    582625    int serverRank=client->getServerLeader() ; 
    583      
     626 
    584627    jend_srv=0 ; 
    585628    for(int i=0;i<=serverRank;i++) 
     
    590633      jend_srv=jbegin_srv+nj_srv-1 ; 
    591634    } 
    592      
    593      CEventClient event(getType(),EVENT_ID_SERVER_ATTRIBUT) ;    
     635 
     636     CEventClient event(getType(),EVENT_ID_SERVER_ATTRIBUT) ; 
    594637     if (client->isServerLeader()) 
    595638     { 
     
    606649  { 
    607650    int i,j,i_ind,j_ind ; 
    608      
     651 
    609652    ibegin_client=ibegin ; iend_client=iend ; ni_client=ni ; 
    610653    jbegin_client=jbegin ; jend_client=jend ; nj_client=nj ; 
    611       
     654 
    612655    CContext* context = CContext::getCurrent() ; 
    613656    CContextClient* client=context->client ; 
     
    617660    int zoom_iend=zoom_ibegin+zoom_ni-1 ; 
    618661    int zoom_jend=zoom_jbegin+zoom_nj-1 ; 
    619      
     662 
    620663    int blockSize=nj_glo/nbServer ; 
    621664    int ns=nj_glo%nbServer ; 
    622665    int pos=ns*(blockSize+1) ; 
    623666    int serverNum ; 
    624      
     667 
    625668    mapConnectedServer.resize(ni,nj) ; 
    626669    vector<int> nbData(nbServer,0) ; 
    627670    vector<int> indServer(nbServer,-1) ; 
    628671    vector<bool> IsConnected(nbServer,false) ; 
    629      
     672 
    630673    for(j=0;j<nj;j++) 
    631674      for(i=0;i<ni;i++) 
     
    633676        i_ind=ibegin+i_index(i,j)-1 ; 
    634677        j_ind=jbegin+j_index(i,j)-1 ; 
    635          
     678 
    636679        if (j_ind<pos) serverNum=j_ind/(blockSize+1) ; 
    637680        else serverNum=ns+(j_ind-pos)/blockSize ; 
    638681        IsConnected[serverNum]=true ; 
    639                  
     682 
    640683        if (i_ind >= zoom_ibegin-1 && i_ind <= zoom_iend-1 && j_ind >= zoom_jbegin-1 && j_ind <= zoom_jend-1) 
    641684        { 
     
    647690 
    648691 
    649     for(serverNum=0 ; serverNum<nbServer ; serverNum++)  
     692    for(serverNum=0 ; serverNum<nbServer ; serverNum++) 
    650693      if (IsConnected[serverNum]) 
    651694      { 
     
    655698        nbDataSrv.push_back(nbData[serverNum]) ; 
    656699      } 
    657       
     700 
    658701     i_indSrv.resize(connectedServer.size()) ; 
    659702     j_indSrv.resize(connectedServer.size()) ; 
    660703 
    661704     for(j=0;j<nj;j++) 
    662       for(i=0;i<ni;i++)  
     705      for(i=0;i<ni;i++) 
    663706      { 
    664707        if (mapConnectedServer(i,j)>=0) 
     
    670713        } 
    671714      } 
    672            
     715 
    673716    int nbConnectedServer=connectedServer.size() ; 
    674717 
     
    677720    int* sendBuff=new int[nbConnectedServer] ; 
    678721    valarray<int> nbClient(0,client->serverSize) ; 
    679      
     722 
    680723    for(int n=0;n<nbConnectedServer;n++) sendBuff[n]=connectedServer[n] ; 
    681      
     724 
    682725    // get connected server for everybody 
    683726    MPI_Allgather(&nbConnectedServer,1,MPI_INT,recvCount,1,MPI_INT,client->intraComm) ; 
    684      
     727 
    685728    displ[0]=0 ; 
    686729    for(int n=1;n<client->clientSize;n++) displ[n]=displ[n-1]+recvCount[n-1] ; 
    687730    int recvSize=displ[client->clientSize-1]+recvCount[client->clientSize-1] ; 
    688731    int* recvBuff=new int[recvSize] ; 
    689   
    690      
     732 
     733 
    691734    MPI_Allgatherv(sendBuff,nbConnectedServer,MPI_INT,recvBuff,recvCount,displ,MPI_INT,client->intraComm) ; 
    692735    for(int n=0;n<recvSize;n++) nbClient[recvBuff[n]]++ ; 
    693      
     736 
    694737    for(int n=0;n<nbConnectedServer;n++) nbSenders.push_back(nbClient[connectedServer[n]]) ; 
    695     
     738 
    696739    delete [] recvCount ; 
    697740    delete [] displ ; 
     
    708751    // send lon lat for each connected server 
    709752    CEventClient event(getType(),EVENT_ID_LON_LAT) ; 
    710      
    711     list<shared_ptr<CMessage> > list_msg ;     
     753 
     754    list<shared_ptr<CMessage> > list_msg ; 
    712755    list< CArray<int,1>* > list_indi,list_indj ; 
    713756    list< CArray<double,1>* >list_lon,list_lat ; 
     
    723766      CArray<double,2> boundslon(nvertex,nbData) ; 
    724767      CArray<double,2> boundslat(nvertex,nbData) ; 
    725        
    726       for(n=0;n<nbData;n++)  
     768 
     769      for(n=0;n<nbData;n++) 
    727770      { 
    728771        i=i_indSrv[ns][n] ; 
    729772        j=j_indSrv[ns][n] ; 
    730773        ind=(i-(zoom_ibegin_client-1))+(j-(zoom_jbegin_client-1))*zoom_ni_client ; 
    731          
     774 
    732775        lon(n)=lonvalue(ind) ; 
    733776        lat(n)=latvalue(ind) ; 
     
    743786        indj(n)=jbegin+j_index(i-ibegin+1,j-jbegin+1)-1  ; 
    744787      } 
    745      
     788 
    746789      list_indi.push_back(new CArray<int,1>(indi.copy())) ; 
    747790      list_indj.push_back(new CArray<int,1>(indj.copy())) ; 
     
    761804 
    762805    client->sendEvent(event) ; 
    763      
    764      
     806 
     807 
    765808    for(list<CArray<int,1>* >::iterator it=list_indi.begin();it!=list_indi.end();it++) delete *it; 
    766809    for(list<CArray<int,1>* >::iterator it=list_indj.begin();it!=list_indj.end();it++) delete *it; 
     
    768811    for(list<CArray<double,1>* >::iterator it=list_lat.begin();it!=list_lat.end();it++)   delete *it; 
    769812    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 
    772815  } 
    773    
    774    
     816 
     817 
    775818  bool CDomain::dispatchEvent(CEventServer& event) 
    776819   { 
    777        
     820 
    778821      if (SuperClass::dispatchEvent(event)) return true ; 
    779822      else 
     
    796839      } 
    797840   } 
    798     
     841 
    799842  void CDomain::recvServerAttribut(CEventServer& event) 
    800843  { 
     
    804847    get(domainId)->recvServerAttribut(*buffer) ; 
    805848  } 
    806    
     849 
    807850  void CDomain::recvServerAttribut(CBufferIn& buffer) 
    808851  { 
     
    811854 
    812855     buffer>>ni_srv>>ibegin_srv>>iend_srv>>nj_srv>>jbegin_srv>>jend_srv; 
    813       
    814      
     856 
     857 
    815858    zoom_ibegin_srv = zoom_ibegin.getValue() > ibegin_srv ? zoom_ibegin.getValue() : ibegin_srv ; 
    816859    zoom_iend_srv = zoom_iend < iend_srv ? zoom_iend : iend_srv ; 
    817860    zoom_ni_srv=zoom_iend_srv-zoom_ibegin_srv+1 ; 
    818        
     861 
    819862    zoom_jbegin_srv = zoom_jbegin.getValue() > jbegin_srv ? zoom_jbegin.getValue() : jbegin_srv ; 
    820863    zoom_jend_srv = zoom_jend < jend_srv ? zoom_jend : jend_srv ; 
    821864    zoom_nj_srv=zoom_jend_srv-zoom_jbegin_srv+1 ; 
    822865 
    823     if (zoom_ni_srv<=0 || zoom_nj_srv<=0)  
     866    if (zoom_ni_srv<=0 || zoom_nj_srv<=0) 
    824867    { 
    825868      zoom_ibegin_srv=1 ; zoom_iend_srv=0 ; zoom_ni_srv=0 ; 
     
    830873    latvalue_srv.resize(zoom_ni_srv*zoom_nj_srv) ; 
    831874    latvalue_srv = 0. ; 
    832     if (hasBounds)  
     875    if (hasBounds) 
    833876    { 
    834877      bounds_lon_srv.resize(nvertex,zoom_ni_srv*zoom_nj_srv) ; 
     
    838881    } 
    839882  } 
    840      
     883 
    841884  void CDomain::recvLonLat(CEventServer& event) 
    842885  { 
     
    850893    } 
    851894  } 
    852    
     895 
    853896  void CDomain::recvLonLat(CBufferIn& buffer) 
    854897  { 
     
    859902    CArray<double,2> boundslon ; 
    860903    CArray<double,2> boundslat ; 
    861      
     904 
    862905    int type_int ; 
    863906    buffer>>type_int>>isCurvilinear>>indi>>indj>>lon>>lat ; 
     
    872915      lonvalue_srv(ind_srv)=lon(ind) ; 
    873916      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++) 
    877920        { 
    878921          bounds_lon_srv(nv,ind_srv)=boundslon(nv,ind) ; 
     
    883926  } 
    884927   //---------------------------------------------------------------- 
    885     
    886     
    887     
     928 
     929 
     930 
    888931   ///--------------------------------------------------------------- 
    889932 
  • XIOS/trunk/src/node/domain.hpp

    r501 r509  
    1515 
    1616namespace xios { 
    17     
     17 
    1818   /// ////////////////////// Déclarations ////////////////////// /// 
    1919 
     
    3939           EVENT_ID_SERVER_ATTRIBUT, EVENT_ID_LON_LAT 
    4040         } ; 
    41           
     41 
    4242         /// typedef /// 
    4343         typedef CObjectTemplate<CDomain>   SuperClass; 
     
    5858         void checkAttributes(void); 
    5959 
     60         void checkAttributesOnClient(); 
     61 
     62         void sendCheckedAttributes(); 
     63 
    6064      private : 
    6165 
     
    6872         void checkDomainData(void); 
    6973         void checkCompression(void); 
    70           
     74 
    7175         void checkZoom(void); 
    7276         void checkBounds(void); 
     
    7478 
    7579      public : 
    76        
     80 
    7781         /// Autres /// 
    7882 
     
    8488         bool hasZoom(void) const; 
    8589         bool isEmpty(void) const; 
    86           
    87           
     90 
     91 
    8892         int ni_client,ibegin_client,iend_client ; 
    8993         int zoom_ni_client,zoom_ibegin_client,zoom_iend_client ; 
     
    100104         CArray<double, 1> lonvalue_srv, latvalue_srv ; 
    101105         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 
    105109        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 
    107111        vector< vector<int> > i_indSrv ; // for each server, i global index to send 
    108112        vector< vector<int> > j_indSrv ; // for each server, j global index to send 
    109         
     113 
    110114        CArray<int,2> mapConnectedServer ;  // (ni,nj) => mapped to connected server number, -1 if no server is target 
    111                 
     115 
    112116//        vector<int> ib_srv, ie_srv, in_srv ; 
    113117//        vector<int> jb_srv, je_srv, jn_srv ; 
    114           
     118 
    115119      public : 
    116        
     120 
    117121         /// Mutateur /// 
    118122         void addRelFile(const StdString & filename); 
     
    126130         void recvLonLat(CBufferIn& buffer) ; 
    127131         void recvServerAttribut(CBufferIn& buffer) ; 
    128           
     132 
    129133         /// Destructeur /// 
    130134         virtual ~CDomain(void); 
     
    133137         static StdString GetName(void); 
    134138         static StdString GetDefName(void); 
    135           
     139 
    136140         static ENodeType GetType(void); 
    137141 
     
    144148         bool isChecked; 
    145149         std::set<StdString> relFiles; 
     150         bool isClientChecked; // Verify whether all attributes of domain on the client side is good 
    146151 
    147152   }; // class CDomain 
  • XIOS/trunk/src/node/field.cpp

    r501 r509  
    1414 
    1515namespace xios{ 
    16     
     16 
    1717   /// ////////////////////// Définitions ////////////////////// /// 
    1818 
     
    2626      , foperation(), hasInstantData(false), hasExpression(false) 
    2727      , active(false) , hasOutputFile(false),hasFieldOut(false), slotUpdateDate(NULL) 
    28       , processed(false) 
     28      , processed(false), domAxisIds_("",""), areAllReferenceSolved(false), areAllExpressionBuilt(false) 
    2929      { setVirtualVariableGroup() ; } 
    3030 
     
    3838      , foperation(), hasInstantData(false), hasExpression(false) 
    3939      , active(false), hasOutputFile(false), hasFieldOut(false), slotUpdateDate(NULL) 
    40       , processed(false) 
     40      , processed(false), domAxisIds_("",""), areAllReferenceSolved(false), areAllExpressionBuilt(false) 
    4141   { setVirtualVariableGroup() ; } 
    4242 
     
    4848      if (hasExpression) delete expression ; 
    4949      if (slotUpdateDate!=NULL) delete slotUpdateDate ; 
    50          
     50 
    5151   } 
    5252 
     
    5555 
    5656   void CField::setVirtualVariableGroup(CVariableGroup* newVVariableGroup) 
    57    {  
    58       this->vVariableGroup = newVVariableGroup;  
    59    } 
    60   
     57   { 
     58      this->vVariableGroup = newVVariableGroup; 
     59   } 
     60 
    6161   void CField::setVirtualVariableGroup(void) 
    6262   { 
    6363      this->setVirtualVariableGroup(CVariableGroup::create()); 
    6464   } 
    65    
     65 
    6666   CVariableGroup* CField::getVirtualVariableGroup(void) const 
    6767   { 
     
    6969   } 
    7070 
    71   
     71 
    7272   std::vector<CVariable*> CField::getAllVariables(void) const 
    7373   { 
    7474      return (this->vVariableGroup->getAllChildren()); 
    7575   } 
    76     
     76 
    7777   void CField::solveDescInheritance(bool apply, const CAttributeMap * const parent) 
    7878   { 
     
    8888   { 
    8989      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 
    9292      if (opeDate <= currDate) 
    9393      { 
     
    9595         { 
    9696            this->data.resize(this->grid->storeIndex[0] ->numElements()); 
    97          }   
     97         } 
    9898         CArray<double,1> input(data.numElements()) ; 
    99          this->grid->inputFieldServer(storedClient, input);           
     99         this->grid->inputFieldServer(storedClient, input); 
    100100         (*this->foperation)(input); 
    101101         *last_operation = currDate; 
     
    106106         this->incrementNStep(); 
    107107         *last_Write = writeDate; 
    108          return (true);         
     108         return (true); 
    109109      } 
    110110      return (false); 
    111111   } 
    112     
     112 
    113113   bool CField::dispatchEvent(CEventServer& event) 
    114114  { 
    115       
     115 
    116116    if (SuperClass::dispatchEvent(event)) return true ; 
    117117    else 
     
    128128             return true ; 
    129129             break ; 
    130           
     130 
    131131           case EVENT_ID_ADD_VARIABLE_GROUP : 
    132132             recvAddVariableGroup(event) ; 
    133133             return true ; 
    134              break ;  
    135   
     134             break ; 
     135 
    136136        default : 
    137137          ERROR("bool CField::dispatchEvent(CEventServer& event)",<<"Unknown Event") ; 
     
    140140    } 
    141141  } 
    142    
     142 
    143143  void CField::sendUpdateData(void) 
    144144  { 
    145145    CContext* context = CContext::getCurrent() ; 
    146146    CContextClient* client=context->client ; 
    147      
     147 
    148148    CEventClient event(getType(),EVENT_ID_UPDATE_DATA) ; 
    149      
     149 
    150150    map<int,CArray<int, 1>* >::iterator it ; 
    151151    list<shared_ptr<CMessage> > list_msg ; 
    152152    list< CArray<double,1>* > list_data ; 
    153      
     153 
    154154    for(it=grid->storeIndex_toSrv.begin();it!=grid->storeIndex_toSrv.end();it++) 
    155155    { 
     
    157157      CArray<int,1>& index = *(it->second) ; 
    158158      CArray<double,1> data_tmp(index.numElements()) ; 
    159        
     159 
    160160      for(int n=0;n<data_tmp.numElements();n++) data_tmp(n)=data(index(n)) ; 
    161161      list_msg.push_back(shared_ptr<CMessage>(new CMessage)) ; 
     
    165165    } 
    166166    client->sendEvent(event) ; 
    167      
     167 
    168168    for(list< CArray<double,1>* >::iterator it=list_data.begin();it!=list_data.end();it++) delete *it ; 
    169169  } 
    170    
     170 
    171171  void CField::recvUpdateData(CEventServer& event) 
    172172  { 
    173173    vector<int> ranks ; 
    174174    vector<CBufferIn*> buffers ; 
    175        
     175 
    176176    list<CEventServer::SSubEvent>::iterator it ; 
    177177    string fieldId ; 
     
    185185      buffers.push_back(buffer) ; 
    186186    } 
    187     get(fieldId)->recvUpdateData(ranks,buffers) ;    
    188   } 
    189    
     187    get(fieldId)->recvUpdateData(ranks,buffers) ; 
     188  } 
     189 
    190190  void  CField::recvUpdateData(vector<int>& ranks, vector<CBufferIn*>& buffers) 
    191191  { 
    192      
     192 
    193193    if (data_srv.empty()) 
    194194    { 
     
    205205    const CDate & currDate = context->getCalendar()->getCurrentDate(); 
    206206    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 
    211211    if (opeDate <= currDate) 
    212212    { 
     
    219219      *last_operation_srv = currDate; 
    220220    } 
    221       
     221 
    222222    if (writeDate < (currDate + freq_operation_srv)) 
    223223    { 
     
    226226        this->foperation_srv[ranks[n]]->final(); 
    227227      } 
    228        
     228 
    229229      *last_Write_srv = writeDate; 
    230230      writeField() ; 
     
    232232    } 
    233233  } 
    234    
     234 
    235235  void CField::writeField(void) 
    236236  { 
     
    246246 
    247247   void CField::setRelFile(CFile* _file) 
    248    {  
     248   { 
    249249      this->file = _file; 
    250       hasOutputFile=true ;  
     250      hasOutputFile=true ; 
    251251   } 
    252252 
     
    260260 
    261261   CGrid* CField::getRelGrid(void) const 
    262    {  
    263       return (this->grid);  
     262   { 
     263      return (this->grid); 
    264264   } 
    265265 
     
    267267 
    268268   CFile* CField::getRelFile(void) const 
    269    {  
     269   { 
    270270      return (this->file); 
    271271   } 
    272     
     272 
    273273   StdSize CField::getNStep(void) const 
    274274   { 
    275275      return (this->nstep); 
    276276   } 
    277     
     277 
    278278   void CField::incrementNStep(void) 
    279279   { 
    280280      this->nstep++; 
    281281   } 
    282   
     282 
    283283   void CField::resetNStep(void) 
    284284   { 
     
    288288   //---------------------------------------------------------------- 
    289289 
     290   /*! 
     291   \brief Get pointer to direct field to which the current field refers. 
     292   */ 
    290293   CField* CField::getDirectFieldReference(void) const 
    291294   { 
     
    304307 
    305308   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   { 
    314317      return (refObject); 
    315318   } 
     
    318321 
    319322   const StdString & CField::getBaseFieldId(void) const 
    320    {  
     323   { 
    321324      return (this->getBaseFieldReference()->getId()); 
    322325   } 
    323     
    324    //---------------------------------------------------------------- 
    325     
     326 
     327   //---------------------------------------------------------------- 
     328 
    326329   const CDuration & CField::getFreqOperation(void) const 
    327330   { 
    328331      return (this->freq_operation); 
    329332   } 
    330     
     333 
    331334   //---------------------------------------------------------------- 
    332335   const CDuration & CField::getFreqWrite(void) const 
     
    334337      return (this->freq_write); 
    335338   } 
    336     
    337    //---------------------------------------------------------------- 
    338           
     339 
     340   //---------------------------------------------------------------- 
     341 
    339342   boost::shared_ptr<func::CFunctor> CField::getFieldOperation(void) const 
    340343   { 
     
    345348 
    346349   bool CField::hasDirectFieldReference(void) const 
    347    {  
    348      return (!this->field_ref.isEmpty());  
    349    } 
    350     
     350   { 
     351     return (!this->field_ref.isEmpty()); 
     352   } 
     353 
    351354   bool CField::isActive(void) const 
    352    {  
    353       return (!this->refObject.empty());  
    354    } 
    355    //---------------------------------------------------------------- 
    356     
     355   { 
     356      return (!this->refObject.empty()); 
     357   } 
     358   //---------------------------------------------------------------- 
     359 
    357360   CArray<double, 1> CField::getData(void) const 
    358361   { 
     
    376379   //---------------------------------------------------------------- 
    377380 
    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   */ 
    394443   void CField::solveRefInheritance(bool apply) 
    395444   { 
     
    397446      CField* refer_sptr; 
    398447      CField * refer_ptr = this; 
    399       
     448 
    400449      while (refer_ptr->hasDirectFieldReference()) 
    401450      { 
     
    413462         sset.insert(refer_ptr); 
    414463      } 
    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"); 
    416476   } 
    417477 
     
    421481      CField* refer_sptr; 
    422482      CField * refer_ptr = this; 
    423        
     483 
    424484      if (this->hasDirectFieldReference())  baseRefObject = getDirectFieldReference(); 
    425485      else  baseRefObject = CField::get(this); 
    426        
     486 
    427487      while (refer_ptr->hasDirectFieldReference()) 
    428488      { 
     
    439499         sset.insert(refer_ptr); 
    440500      } 
    441        
     501 
    442502      if (hasDirectFieldReference()) baseRefObject->addReference(this) ; 
    443503   } 
    444     
     504 
    445505   //---------------------------------------------------------------- 
    446506 
     
    448508   { 
    449509      using namespace func; 
    450        
     510 
    451511      if (!hasOutputFile && !hasFieldOut) return ; 
    452        
     512 
    453513      StdString id ; 
    454514      if (hasId()) id=getId(); 
    455515      else if (!name.isEmpty()) id=name ; 
    456516      else if (hasDirectFieldReference()) id=baseRefObject->getId() ; 
    457        
     517 
    458518      CContext* context = CContext::getCurrent(); 
    459        
     519 
    460520      if (freq_op.isEmpty()) freq_op=string("1ts") ; 
    461        
     521 
    462522      if (operation.isEmpty() ) 
    463523      { 
     
    466526               << "Impossible to define an operation for this field !"); 
    467527      } 
    468        
     528 
    469529      CDuration freq_offset_ = NoneDu; 
    470530      if (!freq_offset.isEmpty()) 
     
    475535      { 
    476536         freq_offset.setValue(NoneDu.toString()); 
    477       }   
     537      } 
    478538 
    479539//      if (CXIOSManager::GetStatus() == CXIOSManager::LOC_SERVER) 
    480540      if (context->hasServer) 
    481541      { 
    482          if (hasOutputFile)  
     542         if (hasOutputFile) 
    483543         { 
    484544           this->freq_operation_srv =CDuration::FromString(this->file->output_freq.getValue()); 
     
    493553//         this->foperation_srv     = 
    494554//             boost::shared_ptr<func::CFunctor>(new CInstant(this->data_srv)); 
    495               
    496          if (hasOutputFile)  
     555 
     556         if (hasOutputFile) 
    497557         { 
    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(); 
    499559           *this->last_operation_srv   = *this->last_operation_srv - toffset; 
    500560         } 
    501561      } 
    502        
     562 
    503563//      if (context->hasClient) 
    504 //      {                   
     564//      { 
    505565         this->freq_operation = CDuration::FromString(freq_op.getValue()); 
    506566         if (hasOutputFile) this->freq_write     = CDuration::FromString(this->file->output_freq.getValue()); 
    507          if (hasFieldOut)  
     567         if (hasFieldOut) 
    508568         { 
    509569           this->freq_write = CDuration::FromString(this->fieldOut->freq_op.getValue()); 
     
    513573         this->last_operation = boost::shared_ptr<CDate> 
    514574                        (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 
    519579        if (operation.get()=="once") isOnceOperation=true ; 
    520580        else isOnceOperation=false; 
    521581        isFirstOperation=true; 
    522          
    523            
     582 
     583 
    524584#define DECLARE_FUNCTOR(MType, mtype)              \ 
    525585   if  (operation.getValue().compare(#mtype) == 0) \ 
     
    537597      return;                                      \ 
    538598   } 
    539     
     599 
    540600#include "functor_type.conf" 
    541           
     601 
    542602         ERROR("CField::solveOperation(void)", 
    543603               << "[ operation = " << operation.getValue() << "]" 
    544604               << "The operation is not defined !"); 
    545605//      } 
    546        
    547  
    548    } 
    549     
     606 
     607 
     608   } 
     609 
    550610   //---------------------------------------------------------------- 
    551611/* 
     
    598658                  << grid_ref.getValue() << "\' is wrong"); 
    599659      } 
    600        
     660 
    601661      if (grid_ref.isEmpty() &&  domain_ref.isEmpty()) 
    602662      { 
     
    605665 
    606666     } 
    607       
     667 
    608668     CType<string> goodDomain ; 
    609669     CType<string> goodAxis ; 
     
    615675     if (!domain_ref.isEmpty()) goodDomain=domain_ref ; 
    616676     if (!axis_ref.isEmpty()) goodAxis=axis_ref ; 
    617       
    618       
    619      if (goodDomain.isEmpty())  
     677 
     678 
     679     if (goodDomain.isEmpty()) 
    620680     { 
    621681       ERROR("CField::solveGridReference(void)", << "The horizontal domain for this field is not defined"); 
    622682     } 
    623      else  
     683     else 
    624684     { 
    625685       if (CDomain::has(goodDomain)) domain = CDomain::get(goodDomain) ; 
    626686       else ERROR("CField::solveGridReference(void)",<< "Reference to the domain \'"<<goodDomain.get() << "\' is wrong") ; 
    627687     } 
    628   
     688 
    629689     if (!goodAxis.isEmpty()) 
    630690     { 
     
    632692       else  ERROR("CField::solveGridReference(void)", << "Reference to the axis \'" 
    633693                  << goodAxis.get() <<"\' is wrong") ; 
    634      }  
    635      
     694     } 
     695 
    636696     bool nothingToDo=false ; 
    637       
     697 
    638698     if (!grid_ref.isEmpty()) 
    639699     { 
    640700       if (!grid->domain_ref.isEmpty() && goodDomain.get() == grid->domain_ref.get()) 
    641701         if (goodAxis.isEmpty()) nothingToDo=true ; 
    642          else if (!grid->axis_ref.isEmpty())  
     702         else if (!grid->axis_ref.isEmpty()) 
    643703                 if (grid->axis_ref.get()==goodAxis.get()) nothingToDo=true ; 
    644704     } 
    645       
     705 
    646706     if (!nothingToDo) 
    647707     { 
     
    655715         this->grid = CGrid::createGrid(domain) ; 
    656716         this->grid_ref.setValue(this->grid->getId()); 
    657        }     
     717       } 
    658718     } 
    659719 
    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   } 
    664734 
    665735   ///------------------------------------------------------------------- 
     
    680750 
    681751      std::vector<CField*> allChildren  = group->getAllChildren(); 
    682       std::vector<CField*>::iterator  
     752      std::vector<CField*>::iterator 
    683753         it = allChildren.begin(), end = allChildren.end(); 
    684        
     754 
    685755      for (; it != end; it++) 
    686756      { 
    687757         CField* child = *it; 
    688758         if (child->hasId()) owner->createChild()->field_ref.setValue(child->getId()) ; 
    689              
    690       } 
    691    } 
    692     
     759 
     760      } 
     761   } 
     762 
    693763   void CField::scaleFactorAddOffset(double scaleFactor, double addOffset) 
    694764   { 
     
    696766     for(it=data_srv.begin();it!=data_srv.end();it++) *it->second = (*it->second -addOffset) * 1./scaleFactor  ; 
    697767   } 
    698     
     768 
    699769   void CField::outputField(CArray<double,3>& fieldOut) 
    700770   { 
     
    702772      for(it=data_srv.begin();it!=data_srv.end();it++) 
    703773         grid->outputField(it->first,*it->second, fieldOut) ; 
    704        
    705    } 
    706     
     774 
     775   } 
     776 
    707777   void CField::outputField(CArray<double,2>& fieldOut) 
    708778   { 
     
    719789   { 
    720790      SuperClass::parse(node); 
    721       if (! node.getContent(this->content))  
     791      if (! node.getContent(this->content)) 
    722792      { 
    723793        if (node.goToChildElement()) 
     
    731801      } 
    732802    } 
    733      
     803 
    734804  CArray<double,1>* CField::getInstantData(void) 
    735805  { 
    736     if (!hasInstantData)  
     806    if (!hasInstantData) 
    737807    { 
    738808      instantData.resize(grid->storeIndex_client.numElements()) ; 
     
    741811    return &instantData ; 
    742812  } 
    743    
     813 
    744814  void CField::addReference(CField* field) 
    745815  { 
    746816    refObject.push_back(field) ; 
    747817  } 
    748    
     818 
    749819  void CField::addDependency(CField* field, int slotId) 
    750820  { 
    751821    fieldDependency.push_back(pair<CField*,int>(field,slotId)) ; 
    752822  } 
    753    
     823 
    754824  void CField::buildExpression(void) 
    755825  { 
    756     if (content.size() > 0)  
     826    if (content.size() > 0) 
    757827    { 
    758828      CSimpleNodeExpr* simpleExpr=parseExpr(content+'\0') ; 
     
    762832      map<string,CField*> associatedInstantFieldIds ; 
    763833      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") 
    767837        { 
    768           if (CField::has(*it))  
     838          if (CField::has(*it)) 
    769839          { 
    770840            CField* field=CField::get(*it) ; 
    771             field->processEnabledField() ; 
     841//            field->processEnabledField() ; 
     842            field->buildAllExpressionEnabledField(); 
    772843            associatedInstantFieldIds[*it]=field ; 
    773844          } 
     
    775846        } 
    776847      } 
    777        
     848 
    778849      set<string> averageFieldIds ; 
    779850      map<string,CField*> associatedAverageFieldIds ; 
    780851 
    781852      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)) 
    785856        { 
    786857           CFieldGroup* root=CFieldGroup::get("field_definition") ; 
     
    791862           averageField->fieldOut=instantField ; 
    792863           instantField->freq_op=freq_op ; 
    793            averageField-> processEnabledField() ; 
     864//           averageField-> processEnabledField() ; 
     865           averageField->buildAllExpressionEnabledField(); 
    794866           instantField->SuperClassAttribute::setAttributes(averageField, true); 
    795867           instantField->field_ref.reset() ; 
    796868           instantField->operation.reset() ; 
    797869 
    798            instantField-> processEnabledField() ; 
     870//           instantField-> processEnabledField() ; 
     871           instantField->buildAllExpressionEnabledField(); 
    799872           associatedAverageFieldIds[*it]=instantField  ; 
    800873        } 
     
    810883      expression->getFields(fields) ; 
    811884      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 
    816889  void CField::resetSlots(void) 
    817890  { 
    818891    for(vector<bool>::iterator it=slots.begin();it!=slots.end();++it) *it=false ; 
    819892  } 
    820    
     893 
    821894  bool CField::slotsFull(void) 
    822895  { 
     
    826899  } 
    827900 
    828    
     901 
    829902  void CField::setSlot(int slotId) 
    830903  { 
    831904    CContext* context = CContext::getCurrent() ; 
    832905    const CDate & currDate = context->getCalendar()->getCurrentDate(); 
    833     if (slotUpdateDate==NULL || currDate!=*slotUpdateDate)  
     906    if (slotUpdateDate==NULL || currDate!=*slotUpdateDate) 
    834907    { 
    835908      resetSlots() ; 
     
    841914    { 
    842915      CArray<double,1> expr(expression->compute()) ; 
    843        
    844       if (hasInstantData)  
     916 
     917      if (hasInstantData) 
    845918      { 
    846919        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) 
    848921          if (it->first!=this) it->first->setSlot(it->second) ; 
    849922      } 
    850        
     923 
    851924      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   } 
    857945 
    858946   CVariable* CField::addVariable(const string& id) 
     
    867955 
    868956 
     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 
    869979   void CField::sendAddVariable(const string& id) 
    870980   { 
    871981    CContext* context=CContext::getCurrent() ; 
    872      
     982 
    873983    if (! context->hasServer ) 
    874984    { 
    875985       CContextClient* client=context->client ; 
    876986 
    877        CEventClient event(this->getType(),EVENT_ID_ADD_VARIABLE) ;    
     987       CEventClient event(this->getType(),EVENT_ID_ADD_VARIABLE) ; 
    878988       if (client->isServerLeader()) 
    879989       { 
     
    886996       else client->sendEvent(event) ; 
    887997    } 
    888        
    889    } 
    890   
    891     
     998 
     999   } 
     1000 
     1001 
    8921002   void CField::sendAddVariableGroup(const string& id) 
    8931003   { 
     
    8971007       CContextClient* client=context->client ; 
    8981008 
    899        CEventClient event(this->getType(),EVENT_ID_ADD_VARIABLE_GROUP) ;    
     1009       CEventClient event(this->getType(),EVENT_ID_ADD_VARIABLE_GROUP) ; 
    9001010       if (client->isServerLeader()) 
    9011011       { 
     
    9081018       else client->sendEvent(event) ; 
    9091019    } 
    910        
    911    } 
    912     
     1020 
     1021   } 
     1022 
    9131023   void CField::recvAddVariable(CEventServer& event) 
    9141024   { 
    915        
     1025 
    9161026      CBufferIn* buffer=event.subEvents.begin()->buffer; 
    9171027      string id; 
     
    9191029      get(id)->recvAddVariable(*buffer) ; 
    9201030   } 
    921     
    922     
     1031 
     1032 
    9231033   void CField::recvAddVariable(CBufferIn& buffer) 
    9241034   { 
     
    9301040   void CField::recvAddVariableGroup(CEventServer& event) 
    9311041   { 
    932        
     1042 
    9331043      CBufferIn* buffer=event.subEvents.begin()->buffer; 
    9341044      string id; 
     
    9361046      get(id)->recvAddVariableGroup(*buffer) ; 
    9371047   } 
    938     
    939     
     1048 
     1049 
    9401050   void CField::recvAddVariableGroup(CBufferIn& buffer) 
    9411051   { 
     
    9471057 
    9481058 
    949    
     1059 
    9501060} // namespace xios 
  • XIOS/trunk/src/node/field.hpp

    r501 r509  
    1818 
    1919namespace xios { 
    20     
     20 
    2121   /// ////////////////////// Déclarations ////////////////////// /// 
    2222 
     
    5656           EVENT_ID_UPDATE_DATA, EVENT_ID_ADD_VARIABLE, EVENT_ID_ADD_VARIABLE_GROUP 
    5757         } ; 
    58           
     58 
    5959         /// Constructeurs /// 
    6060         CField(void); 
     
    8383 
    8484         boost::shared_ptr<func::CFunctor> getFieldOperation(void) const; 
    85           
     85 
    8686         CArray<double, 1> getData(void) const; 
    8787 
     
    9595         template <int N> bool updateData(const CArray<double, N>&   data); 
    9696         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 
    9999         bool updateDataServer 
    100100               (const CDate & currDate, 
    101101                const std::deque< CArray<double, 1>* > storedClient); 
    102   
     102 
     103         std::map<int, StdSize> getGridDataSize(); 
     104 
    103105       public : 
    104106 
     
    116118         void solveGridReference(void); 
    117119         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) 
    118125 
    119126//         virtual void fromBinary(StdIStream & is); 
     
    125132         static StdString GetName(void); 
    126133         static StdString GetDefName(void); 
    127           
     134 
    128135         static ENodeType GetType(void); 
    129           
     136 
    130137        template <int N> void setData(const CArray<double, N>& _data) ; 
    131138        static bool dispatchEvent(CEventServer& event) ; 
     
    139146        void parse(xml::CXMLNode & node) ; 
    140147        CArray<double,1>* getInstantData(void)  ; 
    141          
     148 
    142149        void setVirtualVariableGroup(CVariableGroup* newVVariableGroup); 
    143150        void setVirtualVariableGroup(void); 
     
    145152        vector<CVariable*> getAllVariables(void) const; 
    146153        virtual void solveDescInheritance(bool apply, const CAttributeMap * const parent = 0); 
    147   
     154 
    148155        CVariable* addVariable(const string& id="") ; 
    149156        CVariableGroup* addVariableGroup(const string& id="") ; 
     
    154161        static void recvAddVariableGroup(CEventServer& event) ; 
    155162        void recvAddVariableGroup(CBufferIn& buffer) ; 
    156         
     163        void sendAddAllVariables(); 
     164 
     165 
     166        const std::pair<StdString, StdString>& getDomainAxisIds(); 
    157167      public : 
    158168 
    159169         /// Propriétés privées /// 
    160170         CVariableGroup* vVariableGroup ; 
    161                   
     171 
    162172         std::vector<CField*> refObject; 
    163173         CField* baseRefObject; 
     
    172182         boost::shared_ptr<CDate>    last_Write, last_operation; 
    173183         boost::shared_ptr<CDate>    lastlast_Write_srv,last_Write_srv, last_operation_srv; 
    174           
     184 
    175185         boost::shared_ptr<func::CFunctor> foperation; 
    176186         map<int,boost::shared_ptr<func::CFunctor> > foperation_srv; 
    177           
     187 
    178188         CArray<double, 1> data; 
    179189         CArray<double, 1> instantData; 
     
    183193         bool isFirstOperation ; 
    184194         string content ; 
    185           
     195 
    186196         list< pair<CField *,int> > fieldDependency ; 
    187197         void buildExpression(void) ; 
     
    195205         void setSlot(int slotId); 
    196206         bool processed ; 
     207         bool areAllReferenceSolved; 
     208         bool areAllExpressionBuilt; 
     209         std::pair<StdString,StdString> domAxisIds_; 
    197210 
    198211   }; // class CField 
  • XIOS/trunk/src/node/file.cpp

    r501 r509  
    1818 
    1919namespace xios { 
    20     
     20 
    2121   /// ////////////////////// Définitions ////////////////////// /// 
    2222 
     
    2424      : CObjectTemplate<CFile>(), CFileAttributes() 
    2525      , vFieldGroup(), data_out(), enabledFields(), fileComm(MPI_COMM_NULL) 
    26    {  
     26   { 
    2727     setVirtualFieldGroup() ; 
    2828     setVirtualVariableGroup() ; 
     
    3232      : CObjectTemplate<CFile>(id), CFileAttributes() 
    3333      , vFieldGroup(), data_out(), enabledFields(), fileComm(MPI_COMM_NULL) 
    34     {  
     34    { 
    3535      setVirtualFieldGroup() ; 
    3636      setVirtualVariableGroup() ; 
     
    4141 
    4242   ///--------------------------------------------------------------- 
    43  
     43  //! Get name of file 
    4444   StdString CFile::GetName(void)   { return (StdString("file")); } 
    4545   StdString CFile::GetDefName(void){ return (CFile::GetName()); } 
     
    4747 
    4848   //---------------------------------------------------------------- 
    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   */ 
    5055   boost::shared_ptr<CDataOutput> CFile::getDataOutput(void) const 
    5156   { 
     
    5358   } 
    5459 
     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   */ 
    5567   CFieldGroup* CFile::getVirtualFieldGroup(void) const 
    5668   { 
     
    5870   } 
    5971 
     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   */ 
    6079   CVariableGroup* CFile::getVirtualVariableGroup(void) const 
    6180   { 
     
    6382   } 
    6483 
     84   //! Get all fields of a file 
    6585   std::vector<CField*> CFile::getAllFields(void) const 
    6686   { 
    6787      return (this->vFieldGroup->getAllChildren()); 
    6888   } 
    69   
     89 
     90   //! Get all variables of a file 
    7091   std::vector<CVariable*> CFile::getAllVariables(void) const 
    7192   { 
     
    7495 
    7596   //---------------------------------------------------------------- 
    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, 
    78107                                                int default_level, 
    79108                                                bool default_enabled) 
     
    88117 
    89118      std::vector<CField*> newEnabledFields; 
    90        
     119 
    91120      for ( it = this->enabledFields.begin() ; it != this->enabledFields.end(); it++ ) 
    92121      { 
     
    112141//            { it--; this->enabledFields.erase(it+1); continue; } 
    113142         } 
    114   
     143 
    115144//         CField* field_tmp=(*it).get() ; 
    116145//         shared_ptr<CField> sptfield=*it ; 
     
    130159 
    131160   //---------------------------------------------------------------- 
    132  
     161   //! Change virtual field group to a new one 
    133162   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 
    138168   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 
    145175   void CFile::setVirtualFieldGroup(void) 
    146176   { 
     
    148178   } 
    149179 
     180   //! Create virtual variable group, which is done normally on initializing file 
    150181   void CFile::setVirtualVariableGroup(void) 
    151182   { 
     
    168199      return false ; 
    169200    } 
    170      
     201 
     202   //! Initialize a file in order to write into it 
    171203   void CFile::initFile(void) 
    172204   { 
     
    174206      CDate& currentDate=context->calendar->getCurrentDate() ; 
    175207      CContextServer* server=context->server ; 
    176              
     208 
    177209      if (! sync_freq.isEmpty()) syncFreq = CDuration::FromString(sync_freq.getValue()); 
    178210      if (! split_freq.isEmpty()) splitFreq = CDuration::FromString(split_freq.getValue()); 
     
    194226      nbDomain=setDomain.size() ; 
    195227 
    196       // create sub communicator for file   
     228      // create sub communicator for file 
    197229      int color=allDomainEmpty?0:1 ; 
    198230      MPI_Comm_split(server->intraComm,color,server->intraCommRank,&fileComm) ; 
    199231      if (allDomainEmpty) MPI_Comm_free(&fileComm) ; 
    200232      // 
    201        
    202     } 
    203      
     233 
     234    } 
     235 
     236    //! Verify state of a file 
    204237    void CFile::checkFile(void) 
    205238    { 
     
    208241      checkSplit() ; 
    209242    } 
    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    */ 
    212251   bool CFile::checkSync(void) 
    213252   { 
     
    225264      return false ; 
    226265    } 
    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    */ 
    229273    bool CFile::checkSplit(void) 
    230274    { 
     
    235279        if (currentDate > *lastSplit+splitFreq) 
    236280        { 
    237           *lastSplit=*lastSplit+splitFreq ;     
     281          *lastSplit=*lastSplit+splitFreq ; 
    238282          std::vector<CField*>::iterator it, end = this->enabledFields.end(); 
    239283          for (it = this->enabledFields.begin() ;it != end; it++)  (*it)->resetNStep() ; 
     
    244288      return false ; 
    245289    } 
    246      
     290 
     291   /*! 
     292   \brief Create header of netcdf file 
     293   There are some information to fill in header of each netcdf. 
     294   */ 
    247295   void CFile::createHeader(void) 
    248296   { 
    249297      CContext* context = CContext::getCurrent() ; 
    250298      CContextServer* server=context->server ; 
    251       
     299 
    252300      if (!allDomainEmpty) 
    253301      { 
     
    273321           oss<<"_"<<lastSplit->getStr(splitFormat)<<"-"<< (*lastSplit+(splitFreq-1*Second)).getStr(splitFormat); 
    274322         } 
    275             
     323 
    276324         bool multifile=true ; 
    277325         if (!type.isEmpty()) 
     
    280328           else if (type==type_attr::multiple_file) multifile=true ; 
    281329 
    282          }  
     330         } 
    283331#ifndef USING_NETCDF_PAR 
    284332         if (!multifile) 
     
    288336          } 
    289337#endif 
    290          if (multifile)  
     338         if (multifile) 
    291339         { 
    292340            int commSize, commRank ; 
    293341            MPI_Comm_size(fileComm,&commSize) ; 
    294342            MPI_Comm_rank(fileComm,&commRank) ; 
    295              
    296             if (server->intraCommSize > 1)  
     343 
     344            if (server->intraCommSize > 1) 
    297345            { 
    298346              oss << "_"  ; 
    299347              int width=0 ; int n=commSize-1 ; 
    300348              while(n != 0) { n=n/10 ; width++ ;} 
    301               if (!min_digits.isEmpty())  
     349              if (!min_digits.isEmpty()) 
    302350                if (width<min_digits) width=min_digits ; 
    303351              oss.width(width) ; 
     
    314362           if (par_access.getValue()=="independent") isCollective=false ; 
    315363           else if (par_access.getValue()=="collective") isCollective=true ; 
    316            else  
     364           else 
    317365           { 
    318366             ERROR("void Context::createDataOutput(void)", 
     
    332380         } 
    333381         this->data_out->writeTimeDimension(); 
    334           
     382 
    335383         for (it = this->enabledFields.begin() ;it != end; it++) 
    336384         { 
     
    338386            this->data_out->writeField(field); 
    339387         } 
    340           
     388 
    341389         vector<CVariable*> listVars = getAllVariables() ; 
    342390         for (vector<CVariable*>::iterator it = listVars.begin() ;it != listVars.end(); it++) this-> data_out-> writeAttribute(*it) ; 
    343           
     391 
    344392         this->data_out->definition_end(); 
    345393      } 
    346394   } 
    347395 
     396   //! Close file 
    348397   void CFile::close(void) 
    349398   { 
     
    351400     delete lastSplit ; 
    352401     if (!allDomainEmpty) 
    353        if (isOpen)  
     402       if (isOpen) 
    354403       { 
    355404         this->data_out->closeFile(); 
     
    359408   //---------------------------------------------------------------- 
    360409 
     410   /*! 
     411   \brief Parse xml file and write information into file object 
     412   \param [in] node xmld node corresponding in xml file 
     413   */ 
    361414   void CFile::parse(xml::CXMLNode & node) 
    362415   { 
    363416      SuperClass::parse(node); 
    364        
     417 
    365418      if (node.goToChildElement()) 
    366419      { 
     
    376429   //---------------------------------------------------------------- 
    377430 
     431   /*! 
     432   \brief Represent a file in form of string with all its info 
     433   \return String 
     434   */ 
    378435   StdString CFile::toString(void) const 
    379436   { 
     
    391448 
    392449   //---------------------------------------------------------------- 
    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   */ 
    394457   void CFile::solveDescInheritance(bool apply, const CAttributeMap * const parent) 
    395458   { 
    396459      SuperClassAttribute::setAttributes(parent,apply); 
    397       this->getVirtualFieldGroup()->solveDescInheritance(apply, NULL);  
     460      this->getVirtualFieldGroup()->solveDescInheritance(apply, NULL); 
    398461      this->getVirtualVariableGroup()->solveDescInheritance(apply, NULL); 
    399462   } 
     
    401464   //---------------------------------------------------------------- 
    402465 
    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 
    420515   void CFile::solveFieldRefInheritance(bool apply) 
    421516   { 
     
    441536         this->enabledFields[i]->solveOperation(); 
    442537   } 
    443   
     538 
    444539   void CFile::solveEFExpression(void) 
    445540   { 
    446541      for (unsigned int i = 0; i < this->enabledFields.size(); i++) 
    447542         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   */ 
    451553   CField* CFile::addField(const string& id) 
    452554   { 
     
    454556   } 
    455557 
     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   */ 
    456565   CFieldGroup* CFile::addFieldGroup(const string& id) 
    457566   { 
    458567     return vFieldGroup->createChildGroup(id) ; 
    459568   } 
    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   */ 
    461580   CVariable* CFile::addVariable(const string& id) 
    462581   { 
     
    464583   } 
    465584 
     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   */ 
    466592   CVariableGroup* CFile::addVariableGroup(const string& id) 
    467593   { 
    468594     return vVariableGroup->createChildGroup(id) ; 
    469595   } 
    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   */ 
    472601   void CFile::sendAddField(const string& id) 
    473602   { 
    474603    CContext* context=CContext::getCurrent() ; 
    475      
     604 
    476605    if (! context->hasServer ) 
    477606    { 
    478607       CContextClient* client=context->client ; 
    479608 
    480        CEventClient event(this->getType(),EVENT_ID_ADD_FIELD) ;    
     609       CEventClient event(this->getType(),EVENT_ID_ADD_FIELD) ; 
    481610       if (client->isServerLeader()) 
    482611       { 
     
    489618       else client->sendEvent(event) ; 
    490619    } 
    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   */ 
    494627   void CFile::sendAddFieldGroup(const string& id) 
    495628   { 
     
    499632       CContextClient* client=context->client ; 
    500633 
    501        CEventClient event(this->getType(),EVENT_ID_ADD_FIELD_GROUP) ;    
     634       CEventClient event(this->getType(),EVENT_ID_ADD_FIELD_GROUP) ; 
    502635       if (client->isServerLeader()) 
    503636       { 
     
    510643       else client->sendEvent(event) ; 
    511644    } 
    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   */ 
    515652   void CFile::recvAddField(CEventServer& event) 
    516653   { 
    517        
     654 
    518655      CBufferIn* buffer=event.subEvents.begin()->buffer; 
    519656      string id; 
     
    521658      get(id)->recvAddField(*buffer) ; 
    522659   } 
    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   */ 
    525665   void CFile::recvAddField(CBufferIn& buffer) 
    526666   { 
     
    530670   } 
    531671 
     672   /*! 
     673   \brief Receive a message annoucing the creation of a field group on server side 
     674   \param[in] event Received event 
     675   */ 
    532676   void CFile::recvAddFieldGroup(CEventServer& event) 
    533677   { 
    534        
     678 
    535679      CBufferIn* buffer=event.subEvents.begin()->buffer; 
    536680      string id; 
     
    538682      get(id)->recvAddFieldGroup(*buffer) ; 
    539683   } 
    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   */ 
    542689   void CFile::recvAddFieldGroup(CBufferIn& buffer) 
    543690   { 
     
    546693      addFieldGroup(id) ; 
    547694   } 
    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   */ 
    559729   void CFile::sendAddVariable(const string& id) 
    560730   { 
    561731    CContext* context=CContext::getCurrent() ; 
    562      
     732 
    563733    if (! context->hasServer ) 
    564734    { 
    565735       CContextClient* client=context->client ; 
    566736 
    567        CEventClient event(this->getType(),EVENT_ID_ADD_VARIABLE) ;    
     737       CEventClient event(this->getType(),EVENT_ID_ADD_VARIABLE) ; 
    568738       if (client->isServerLeader()) 
    569739       { 
     
    576746       else client->sendEvent(event) ; 
    577747    } 
    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   */ 
    581755   void CFile::sendAddVariableGroup(const string& id) 
    582756   { 
     
    586760       CContextClient* client=context->client ; 
    587761 
    588        CEventClient event(this->getType(),EVENT_ID_ADD_VARIABLE_GROUP) ;    
     762       CEventClient event(this->getType(),EVENT_ID_ADD_VARIABLE_GROUP) ; 
    589763       if (client->isServerLeader()) 
    590764       { 
     
    597771       else client->sendEvent(event) ; 
    598772    } 
    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   */ 
    602780   void CFile::recvAddVariable(CEventServer& event) 
    603781   { 
    604        
     782 
    605783      CBufferIn* buffer=event.subEvents.begin()->buffer; 
    606784      string id; 
     
    608786      get(id)->recvAddVariable(*buffer) ; 
    609787   } 
    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   */ 
    612793   void CFile::recvAddVariable(CBufferIn& buffer) 
    613794   { 
     
    617798   } 
    618799 
     800   /*! 
     801   \brief Receive a message annoucing the creation of a variable group on server side 
     802   \param[in] event Received event 
     803   */ 
    619804   void CFile::recvAddVariableGroup(CEventServer& event) 
    620805   { 
    621        
     806 
    622807      CBufferIn* buffer=event.subEvents.begin()->buffer; 
    623808      string id; 
     
    625810      get(id)->recvAddVariableGroup(*buffer) ; 
    626811   } 
    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   */ 
    629817   void CFile::recvAddVariableGroup(CBufferIn& buffer) 
    630818   { 
     
    634822   } 
    635823 
    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   */ 
    640853   bool CFile::dispatchEvent(CEventServer& event) 
    641854   { 
     
    649862             return true ; 
    650863             break ; 
    651           
     864 
    652865           case EVENT_ID_ADD_FIELD_GROUP : 
    653866             recvAddFieldGroup(event) ; 
    654867             return true ; 
    655              break ;        
    656   
     868             break ; 
     869 
    657870            case EVENT_ID_ADD_VARIABLE : 
    658871             recvAddVariable(event) ; 
    659872             return true ; 
    660873             break ; 
    661           
     874 
    662875           case EVENT_ID_ADD_VARIABLE_GROUP : 
    663876             recvAddVariableGroup(event) ; 
    664877             return true ; 
    665              break ;                
     878             break ; 
    666879           default : 
    667880              ERROR("bool CFile::dispatchEvent(CEventServer& event)", <<"Unknown Event") ; 
     
    670883      } 
    671884   } 
    672     
    673     
    674     
    675     
     885 
     886 
     887 
     888 
    676889   ///--------------------------------------------------------------- 
    677890 
  • XIOS/trunk/src/node/file.hpp

    r501 r509  
    1515 
    1616namespace xios { 
    17     
     17 
    1818   /// ////////////////////// Déclarations ////////////////////// /// 
    1919 
     
    3131   ///-------------------------------------------------------------- 
    3232 
     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   */ 
    3341   class CFile 
    3442      : public CObjectTemplate<CFile> 
     
    3846         typedef CObjectTemplate<CFile>   SuperClass; 
    3947         typedef CFileAttributes SuperClassAttribute; 
    40        
     48 
    4149      public : 
    4250         enum EEventId 
    4351         { 
    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 
    4554         } ; 
    46           
     55 
    4756         typedef CFileAttributes RelAttributes; 
    4857         typedef CFileGroup      RelGroup; 
     
    5463         CFile(const CFile * const file); // Not implemented yet. 
    5564 
     65         /// Destructeur /// 
     66         virtual ~CFile(void); 
     67 
     68      public: 
    5669         /// Accesseurs /// 
    5770         boost::shared_ptr<CDataOutput> getDataOutput(void) const; 
     
    6679 
    6780      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 
    12282         bool isSyncTime(void) ; 
    12383         bool checkSplit(void) ; 
     
    12585         void checkFile(void) ; 
    12686         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 
    127150         CDate* lastSync ; 
    128151         CDate* lastSplit ; 
     
    132155         int nbDomain ; 
    133156         bool isOpen ; 
     157         bool allDomainEmpty ; 
    134158         MPI_Comm fileComm ; 
     159 
    135160      private : 
    136  
    137161         /// Propriétés privées /// 
    138162         CFieldGroup* vFieldGroup; 
     
    140164         boost::shared_ptr<CDataOutput> data_out; 
    141165         std::vector<CField*> enabledFields; 
     166 
     167      public: 
     168        //         virtual void toBinary  (StdOStream & os) const; 
     169        //         virtual void fromBinary(StdIStream & is); 
    142170 
    143171   }; // class CFile 
  • XIOS/trunk/src/node/grid.cpp

    r501 r509  
    1919   CGrid::CGrid(void) 
    2020      : 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) 
    2323   { /* Ne rien faire de plus */ } 
    2424 
    2525   CGrid::CGrid(const StdString & id) 
    2626      : 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) 
    2929   { /* Ne rien faire de plus */ } 
    3030 
    3131   CGrid::~CGrid(void) 
    32    {  
     32   { 
    3333 //     this->axis.reset() ; 
    3434//      this->domain.reset() ; 
    3535    deque< CArray<int, 1>* >::iterator it ; 
    36      
     36 
    3737    for(deque< CArray<int,1>* >::iterator it=storeIndex.begin(); it!=storeIndex.end();it++)  delete *it ; 
    3838    for(deque< CArray<int,1>* >::iterator it=out_i_index.begin();it!=out_i_index.end();it++) delete *it ; 
     
    5555 
    5656   const std::deque< CArray<int,1>* > & CGrid::getStoreIndex(void) const 
    57    {  
     57   { 
    5858      return (this->storeIndex ); 
    5959   } 
     
    6262 
    6363   const std::deque< CArray<int,1>* > & CGrid::getOutIIndex(void)  const 
    64    {  
    65       return (this->out_i_index );  
     64   { 
     65      return (this->out_i_index ); 
    6666   } 
    6767 
     
    6969 
    7070   const std::deque< CArray<int,1>* > & CGrid::getOutJIndex(void)  const 
    71    {  
    72       return (this->out_j_index );  
     71   { 
     72      return (this->out_j_index ); 
    7373   } 
    7474 
     
    7676 
    7777   const std::deque< CArray<int,1>* > & CGrid::getOutLIndex(void)  const 
    78    {  
    79       return (this->out_l_index );  
     78   { 
     79      return (this->out_l_index ); 
    8080   } 
    8181 
     
    8383 
    8484   const CAxis*   CGrid::getRelAxis  (void) const 
    85    {  
    86       return (this->axis );  
     85   { 
     86      return (this->axis ); 
    8787   } 
    8888 
     
    9090 
    9191   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); 
    101101   } 
    102102 
     
    122122*/ 
    123123   //--------------------------------------------------------------- 
    124     
     124 
    125125/* 
    126126   StdSize CGrid::getLocalSize(void) const 
     
    147147   //--------------------------------------------------------------- 
    148148 
    149 /*    
     149/* 
    150150   StdSize CGrid::getGlobalSize(void) const 
    151151   { 
     
    166166   } 
    167167 
    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     } 
    189240//      this->computeIndexServer(); 
    190       this->isChecked = true; 
     241     this->isChecked = true; 
    191242   } 
    192243 
     
    206257             (mask.extent(2) != nlu)) 
    207258             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 
    209260                  <<"Local size is "<<niu<<"x"<<nju<<"x"<<nlu<<endl 
    210261                  <<"Mask size is "<<mask.extent(0)<<"x"<<mask.extent(1)<<"x"<<mask.extent(2)); 
    211262      } 
    212       else  
     263      else 
    213264      { 
    214265        mask.resize(niu,nju,nlu) ; 
    215266        mask=true  ; 
    216267      } 
    217       
     268 
    218269      CArray<bool,2>& domainMask = domain->mask ; 
    219270      for (int l=0; l < nlu ; l++) 
    220271        for (int j=0; j < nju ; j++) 
    221272          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) 
    229315   { 
    230316      if (!domain_ref.isEmpty()) 
     
    233319         { 
    234320            this->domain = CDomain::get(domain_ref.getValue()) ; 
    235             domain->checkAttributes() ; 
     321            if (sendAtt) domain->sendCheckedAttributes(); 
     322            else domain->checkAttributesOnClient() ; 
    236323         } 
    237324         else ERROR("CGrid::solveDomainRef(void)", 
     
    244331   //--------------------------------------------------------------- 
    245332 
    246    void CGrid::solveAxisRef(void) 
     333   void CGrid::solveAxisRef(bool checkAtt) 
    247334   { 
    248335      if (!axis_ref.isEmpty()) 
     
    263350 
    264351   void CGrid::computeIndex(void) 
    265    {     
    266     
     352   { 
     353 
    267354      const int ni   = domain->ni.getValue() , 
    268355                nj   = domain->nj.getValue() , 
     
    280367      CArray<int,1> data_i_index = domain->data_i_index ; 
    281368      CArray<int,1> data_j_index = domain->data_j_index ; 
    282        
     369 
    283370 
    284371      int indexCount = 0; 
     
    302389         } 
    303390      } 
    304        
     391 
    305392      storeIndex[0]  = new CArray<int,1>(indexCount) ; 
    306393      out_i_index[0] = new CArray<int,1>(indexCount) ; 
    307394      out_j_index[0] = new CArray<int,1>(indexCount) ; 
    308395      out_l_index[0] = new CArray<int,1>(indexCount) ; 
    309        
     396 
    310397      storeIndex_client.resize(indexCount) ; 
    311398      out_i_client.resize(indexCount) ; 
    312399      out_j_client.resize(indexCount) ; 
    313400      out_l_client.resize(indexCount) ; 
    314        
    315        
     401 
     402 
    316403      for(int count = 0, indexCount = 0,  l = 0; l < size; l++) 
    317404      { 
     
    334421               (*out_i_index[0])(indexCount) = i ; 
    335422               (*out_j_index[0])(indexCount) = j ; 
    336                 
     423 
    337424               storeIndex_client(indexCount) = count ; 
    338425               out_i_client(indexCount)=i+domain->ibegin_client-1 ; 
     
    343430         } 
    344431      } 
    345       sendIndex() ; 
     432      computeDomConServer(); 
     433//      sendIndex() ; 
    346434 
    347435 
     
    370458   //---------------------------------------------------------------- 
    371459 
    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) 
    373461   { 
    374462      CArray<int,1>& out_i=*out_i_fromClient[rank] ; 
    375463      CArray<int,1>& out_j=*out_j_fromClient[rank] ; 
    376464      CArray<int,1>& out_l=*out_l_fromClient[rank] ; 
    377        
     465 
    378466      for(StdSize n = 0; n < stored.numElements(); n++) 
    379467         field(out_i(n), out_j(n), out_l(n)) = stored(n) ; 
    380468   } 
    381469 
    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) 
    383471   { 
    384472      CArray<int,1>& out_i=*out_i_fromClient[rank] ; 
    385473      CArray<int,1>& out_j=*out_j_fromClient[rank] ; 
    386        
     474 
    387475      for(StdSize n = 0; n < stored.numElements(); n++) 
    388476         field(out_i(n), out_j(n)) = stored(n) ;   } 
     
    393481   { 
    394482      CArray<int,1>& out_i=*out_i_fromClient[rank] ; 
    395   
     483 
    396484      for(StdSize n = 0; n < stored.numElements(); n++) 
    397485         field(out_i(n)) = stored(n) ; 
     
    399487 
    400488   //---------------------------------------------------------------- 
    401    
     489 
    402490 
    403491   void CGrid::storeField_arr 
     
    409497      for(StdSize i = 0; i < size; i++) stored(i) = data[storeIndex_client(i)] ; 
    410498   } 
    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  } 
    413592 
    414593  void CGrid::sendIndex(void) 
     
    416595    CContext* context = CContext::getCurrent() ; 
    417596    CContextClient* client=context->client ; 
    418      
     597 
    419598    CEventClient event(getType(),EVENT_ID_INDEX) ; 
    420599    int rank ; 
    421600    list<shared_ptr<CMessage> > list_msg ; 
    422601    list< CArray<int,1>* > list_out_i,list_out_j,list_out_l ; 
    423       
     602 
     603    if (!isDomConServerComputed_) computeDomConServer(); 
     604 
    424605    for(int ns=0;ns<domain->connectedServer.size();ns++) 
    425606    { 
    426607       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; 
    437610       CArray<int,1> storeIndex(nb) ; 
    438611       CArray<int,1> out_i(nb) ; 
    439612       CArray<int,1> out_j(nb) ; 
    440613       CArray<int,1> out_l(nb) ; 
    441   
    442         
     614 
     615       int i, j; 
    443616       nb=0 ; 
    444617       for(int k=0;k<storeIndex_client.numElements();k++) 
     
    450623            storeIndex(nb)=k ; 
    451624            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; 
    453626            out_l(nb)=out_l_client(k) ; 
    454627            nb++ ; 
    455628         } 
    456629       } 
    457         
     630 
    458631       storeIndex_toSrv.insert( pair<int,CArray<int,1>* >(rank,new CArray<int,1>(storeIndex) )) ; 
    459632       nbSenders.insert(pair<int,int>(rank,domain->nbSenders[ns])) ; 
     
    471644    for(list<CArray<int,1>* >::iterator it=list_out_j.begin();it!=list_out_j.end();it++) delete *it ; 
    472645    for(list<CArray<int,1>* >::iterator it=list_out_l.begin();it!=list_out_l.end();it++) delete *it ; 
    473      
     646 
    474647  } 
    475    
     648 
    476649  void CGrid::recvIndex(CEventServer& event) 
    477650  { 
     
    486659    } 
    487660  } 
    488    
     661 
    489662  void CGrid::recvIndex(int rank, CBufferIn& buffer) 
    490663  { 
     
    492665    CArray<int,1> out_j ; 
    493666    CArray<int,1> out_l ; 
    494      
     667 
    495668    buffer>>out_i>>out_j>>out_l ; 
    496      
     669 
    497670    out_i -= domain->zoom_ibegin_srv-1 ; 
    498671    out_j -= domain->zoom_jbegin_srv-1 ; 
    499      
     672 
    500673    out_i_fromClient.insert(pair< int,CArray<int,1>* >(rank,new CArray<int,1>(out_i) )) ; 
    501674    out_j_fromClient.insert(pair< int,CArray<int,1>* >(rank,new CArray<int,1>(out_j) )) ; 
     
    505678  bool CGrid::dispatchEvent(CEventServer& event) 
    506679  { 
    507       
     680 
    508681    if (SuperClass::dispatchEvent(event)) return true ; 
    509682    else 
     
    515688          return true ; 
    516689          break ; 
    517   
     690 
    518691        default : 
    519692          ERROR("bool CDomain::dispatchEvent(CEventServer& event)", 
     
    532705                << "Data from clients are missing!") ; 
    533706      storedServer.resize(storeIndex[0]->numElements()); 
    534           
     707 
    535708      for (StdSize i = 0, n = 0; i < storedClient.size(); i++) 
    536709         for (StdSize j = 0; j < storedClient[i]->numElements(); j++) 
     
    543716     int nb=index.numElements() ; 
    544717     fieldOut.resize(nb) ; 
    545       
     718 
    546719     for(int k=0;k<nb;k++) fieldOut(k)=fieldIn(index(k)) ; 
    547720    } 
  • XIOS/trunk/src/node/grid.hpp

    r501 r509  
    1313 
    1414namespace xios { 
    15     
     15 
    1616   /// ////////////////////// Déclarations ////////////////////// /// 
    1717 
     
    4646           EVENT_ID_INDEX 
    4747         } ; 
    48           
     48 
    4949         /// Constructeurs /// 
    5050         CGrid(void); 
     
    5454 
    5555         /// Traitements /// 
    56          void solveReference(void); 
     56//         void solveReference(void); 
     57 
     58         void solveDomainAxisRef(bool areAttributesChecked); 
     59 
     60         void checkMaskIndex(bool doCalculateIndex); 
    5761 
    5862 //        virtual void toBinary  (StdOStream & os) const; 
     
    7478 
    7579         StdSize getDimension(void) const; 
    76           
     80 
    7781//         StdSize getLocalSize(void) const; 
    7882//         StdSize getGlobalSize(void) const; 
     
    8488         template <int n> 
    8589            void inputField(const CArray<double,n>& field, CArray<double,1>& stored) const; 
    86              
     90 
    8791         void inputFieldServer(const std::deque< CArray<double, 1>* > storedClient, 
    8892                               CArray<double, 1>&  storedServer) const; 
     
    9094         void outputField(int rank, const CArray<double,1>& stored,  CArray<double,3>& field)  ; 
    9195         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 
    9498         /// Destructeur /// 
    9599         virtual ~CGrid(void); 
     
    100104         static StdString GetName(void); 
    101105         static StdString GetDefName(void); 
    102           
     106 
    103107         static ENodeType GetType(void); 
    104108 
     
    115119         void computeIndexServer(void); 
    116120         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); 
    119126 
    120127         static bool dispatchEvent(CEventServer& event) ; 
     
    123130         void recvIndex(int rank, CBufferIn& buffer) ; 
    124131         void sendIndex(void) ; 
    125           
     132 
     133         void computeDomConServer(); 
     134         std::map<int, int> getDomConServerSide(); 
     135         std::map<int, StdSize> getConnectedServerDataSize(); 
    126136      public: 
    127137 
     
    129139         bool withAxis ; 
    130140         bool isChecked; 
     141         bool isDomainAxisChecked; 
    131142 
    132143         CAxis*   axis ; 
     
    137148         std::deque< CArray<int, 1>* > out_j_index ; 
    138149         std::deque< CArray<int, 1>* > out_l_index ; 
    139           
     150 
    140151        CArray<int, 1>  storeIndex_client ; 
    141152        CArray<int, 1>  out_i_client ; 
    142153        CArray<int, 1>  out_j_client ; 
    143154        CArray<int, 1>  out_l_client ; 
    144           
     155 
    145156         map<int, CArray<int, 1>* >  storeIndex_toSrv ; 
    146157         map<int,int> nbSenders ; 
     
    148159//         std::deque<ARRAY(int, 1)> out_j_toSrv ; 
    149160//         std::deque<ARRAY(int, 1)> out_l_toSrv ; 
    150           
     161 
    151162         map<int, CArray<int, 1>* > out_i_fromClient ; 
    152163         map<int, CArray<int, 1>* > out_j_fromClient ; 
    153164         map<int, CArray<int, 1>* > out_l_fromClient ; 
    154165         void checkMask(void) ; 
     166 
     167         std::map<int, int> domConnectedServerSide_; 
     168         bool isDomConServerComputed_; 
    155169   }; // class CGrid 
    156170 
Note: See TracChangeset for help on using the changeset viewer.