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

File:
1 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(); 
Note: See TracChangeset for help on using the changeset viewer.