Ignore:
Timestamp:
02/13/12 19:35:25 (12 years ago)
Author:
ymipsl
Message:

nouvelle version de developpement de xios

  • nouvelle interface fortran
  • recodage complet de la couche de communication
  • et bien d'autres choses...

YM

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XMLIO_V2/dev/common/src/node/file.cpp

    r286 r300  
    77#include "object_factory.hpp" 
    88#include "object_factory_impl.hpp" 
     9#include "data_output.hpp" 
     10#include "context.hpp" 
     11#include "context_server.hpp" 
     12#include "nc4_data_output.hpp" 
     13 
    914 
    1015namespace xmlioserver { 
     
    1621      : CObjectTemplate<CFile>(), CFileAttributes() 
    1722      , vFieldGroup(), data_out(), enabledFields() 
    18    { /* Ne rien faire de plus */ } 
     23   { setVirtualFieldGroup() ;} 
    1924 
    2025   CFile::CFile(const StdString & id) 
    2126      : CObjectTemplate<CFile>(id), CFileAttributes() 
    2227      , vFieldGroup(), data_out(), enabledFields() 
    23    { /* Ne rien faire de plus */ } 
     28   { setVirtualFieldGroup() ;} 
    2429 
    2530   CFile::~CFile(void) 
     
    6267      this->enabledFields = this->getAllFields(); 
    6368 
    64       std::cout<<"---> File :"<<this->name.getValue()<<std::endl ; 
     69      std::vector<boost::shared_ptr<CField> > newEnabledFields; 
     70       
    6571      for ( it = this->enabledFields.begin() ; it != this->enabledFields.end(); it++ ) 
    6672      { 
    6773         if (!(*it)->enabled.isEmpty()) // Si l'attribut 'enabled' est défini ... 
    6874         { 
    69             if (! (*it)->enabled.getValue()) 
    70             { it--; this->enabledFields.erase(it+1); continue; } 
     75            if (! (*it)->enabled.getValue()) continue; 
     76//            { it--; this->enabledFields.erase(it+1); continue; } 
    7177         } 
    7278         else // Si l'attribut 'enabled' n'est pas défini ... 
    7379         { 
    74             if (!default_enabled) 
    75             { it--; this->enabledFields.erase(it+1); continue; } 
     80            if (!default_enabled) continue ; 
     81//            { it--; this->enabledFields.erase(it+1); continue; } 
    7682         } 
    7783 
    7884         if (!(*it)->level.isEmpty()) // Si l'attribut 'level' est défini ... 
    7985         { 
    80             if ((*it)->level.getValue() > _outputlevel) 
    81             { it--; this->enabledFields.erase(it+1); continue; } 
     86            if ((*it)->level.getValue() > _outputlevel) continue ; 
     87//            { it--; this->enabledFields.erase(it+1); continue; } 
    8288         } 
    8389         else // Si l'attribut 'level' n'est pas défini ... 
    8490         { 
    85             if (default_level > _outputlevel) 
    86             { it--; this->enabledFields.erase(it+1); continue; } 
    87          } 
    88  
     91            if (default_level > _outputlevel) continue ; 
     92//            { it--; this->enabledFields.erase(it+1); continue; } 
     93         } 
     94  
     95//         CField* field_tmp=(*it).get() ; 
     96//         shared_ptr<CField> sptfield=*it ; 
     97//         field_tmp->refObject.push_back(sptfield) ; 
     98         newEnabledFields.push_back(*it) ; 
    8999         // Le champ est finalement actif, on y ajoute sa propre reference. 
    90100         (*it)->refObject.push_back(*it); 
    91101         // Le champ est finalement actif, on y ajoute la référence au champ de base. 
    92          std::cout<<"    Field Enabled : "<<(*it)->getId()<<std::endl ; 
    93102         (*it)->setRelFile(CObjectFactory::GetObject(this)); 
    94103         (*it)->baseRefObject->refObject.push_back(*it); 
    95104         // A faire, ajouter les references intermediaires... 
    96105      } 
     106      enabledFields=newEnabledFields ; 
    97107 
    98108      return (this->enabledFields); 
     
    108118   //---------------------------------------------------------------- 
    109119 
    110    void CFile::setVirtualFieldGroup(const StdString & newVFieldGroupId) 
     120   void CFile::setVirtualFieldGroup(void) 
    111121   { 
    112122      this->setVirtualFieldGroup 
    113          (CObjectFactory::CreateObject<CFieldGroup>(/*newVFieldGroupId*/)); 
    114    } 
    115  
    116    //---------------------------------------------------------------- 
    117  
    118    void CFile::initializeDataOutput(boost::shared_ptr<io::CDataOutput> dout) 
    119    { 
    120       this->data_out = dout; 
    121       this->data_out->writeFile(CObjectFactory::GetObject<CFile>(this)); 
    122        
     123         (CObjectFactory::CreateObject<CFieldGroup>()); 
     124   } 
     125 
     126   //---------------------------------------------------------------- 
     127 
     128   void CFile::createHeader(void) 
     129   { 
     130     
    123131      std::vector<boost::shared_ptr<CField> >::iterator it, end = this->enabledFields.end(); 
    124132 
     133      AllDomainEmpty=true ; 
    125134      for (it = this->enabledFields.begin() ;it != end; it++) 
    126135      { 
    127136         boost::shared_ptr<CField> field = *it; 
    128          this->data_out->writeFieldGrid(field); 
     137         AllDomainEmpty&=field->grid->domain->isEmpty() ; 
    129138      } 
    130           
    131       for (it = this->enabledFields.begin() ;it != end; it++) 
     139       
     140      if (!AllDomainEmpty ||  type.getValue()=="one_file") 
    132141      { 
    133          boost::shared_ptr<CField> field = *it; 
    134          this->data_out->writeField(field); 
     142         StdString filename = (!name.isEmpty()) ?   name.getValue() : getId(); 
     143         StdOStringStream oss; 
     144//         if (! output_dir.isEmpty()) oss << output_dir.getValue(); 
     145         oss << filename; 
     146         if (!name_suffix.isEmpty()) oss << name_suffix.getValue(); 
     147 
     148         bool multifile=true ; 
     149         if (!type.isEmpty()) 
     150         { 
     151           if (type.getValue()=="one_file") multifile=false ; 
     152           else if (type.getValue()=="multi_file") multifile=true ; 
     153           else ERROR("void Context::createDataOutput(void)", 
     154                      "incorrect file <type> attribut : must be <multi_file> or <one_file>, " 
     155                      <<"having : <"<<type.getValue()<<">") ; 
     156         }  
     157          
     158         shared_ptr<CContext> context=CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId()) ; 
     159         CContextServer* server=context->server ; 
     160 
     161         if (multifile)  
     162         { 
     163            if (server->intraCommSize > 1) oss << "_" << server->intraCommRank; 
     164         } 
     165         oss << ".nc"; 
     166 
     167         data_out=shared_ptr<io::CDataOutput>(new io::CNc4DataOutput(oss.str(), false,server->intraComm,multifile)); 
     168 
     169         data_out->writeFile(CObjectFactory::GetObject<CFile>(this)); 
     170         for (it = this->enabledFields.begin() ;it != end; it++) 
     171         { 
     172            boost::shared_ptr<CField> field = *it; 
     173            this->data_out->writeFieldGrid(field); 
     174         } 
     175          
     176         for (it = this->enabledFields.begin() ;it != end; it++) 
     177         { 
     178            boost::shared_ptr<CField> field = *it; 
     179            this->data_out->writeField(field); 
     180         } 
     181          
     182         this->data_out->definition_end(); 
    135183      } 
    136           
    137       this->data_out->definition_end(); 
    138184   } 
    139185 
    140186   void CFile::close(void) 
    141187   { 
    142      this->data_out->closeFile(); 
     188     if (!AllDomainEmpty ||  type.getValue()=="one_file") 
     189       this->data_out->closeFile(); 
    143190   } 
    144191   //---------------------------------------------------------------- 
     
    150197      { // Si la définition du fichier intégre des champs et si le fichier est identifié. 
    151198         node.goToParentElement(); 
    152          this->setVirtualFieldGroup(this->getId()); 
     199//         this->setVirtualFieldGroup(this->getId()); 
    153200         this->getVirtualFieldGroup()->parse(node, false); 
    154201      } 
     
    234281               << "[ renum = " << renum << "] Bad type !"); 
    235282       
    236       this->setVirtualFieldGroup(this->getId()); 
     283//      this->setVirtualFieldGroup(this->getId()); 
    237284      if (hasVFG)this->getVirtualFieldGroup()->fromBinary(is); 
    238285       
    239286   } 
    240  
     287    
     288   shared_ptr<CField> CFile::addField(const string& id) 
     289   { 
     290     return vFieldGroup->createChild(id) ; 
     291   } 
     292 
     293   shared_ptr<CFieldGroup> CFile::addFieldGroup(const string& id) 
     294   { 
     295     return vFieldGroup->createChildGroup(id) ; 
     296   } 
     297    
     298   
     299   void CFile::sendAddField(const string& id) 
     300   { 
     301    shared_ptr<CContext> context=CContext::current() ; 
     302     
     303    if (! context->hasServer ) 
     304    { 
     305       CContextClient* client=context->client ; 
     306 
     307       CEventClient event(this->getType(),EVENT_ID_ADD_FIELD) ;    
     308       if (client->isServerLeader()) 
     309       { 
     310         CMessage msg ; 
     311         msg<<this->getId() ; 
     312         msg<<id ; 
     313         event.push(client->getServerLeader(),1,msg) ; 
     314         client->sendEvent(event) ; 
     315       } 
     316       else client->sendEvent(event) ; 
     317    } 
     318       
     319   } 
     320    
     321   void CFile::sendAddFieldGroup(const string& id) 
     322   { 
     323    shared_ptr<CContext> context=CContext::current() ; 
     324    if (! context->hasServer ) 
     325    { 
     326       CContextClient* client=context->client ; 
     327 
     328       CEventClient event(this->getType(),EVENT_ID_ADD_FIELD_GROUP) ;    
     329       if (client->isServerLeader()) 
     330       { 
     331         CMessage msg ; 
     332         msg<<this->getId() ; 
     333         msg<<id ; 
     334         event.push(client->getServerLeader(),1,msg) ; 
     335         client->sendEvent(event) ; 
     336       } 
     337       else client->sendEvent(event) ; 
     338    } 
     339       
     340   } 
     341    
     342   void CFile::recvAddField(CEventServer& event) 
     343   { 
     344       
     345      CBufferIn* buffer=event.subEvents.begin()->buffer; 
     346      string id; 
     347      *buffer>>id ; 
     348      get(id)->recvAddField(*buffer) ; 
     349   } 
     350    
     351    
     352   void CFile::recvAddField(CBufferIn& buffer) 
     353   { 
     354      string id ; 
     355      buffer>>id ; 
     356      addField(id) ; 
     357   } 
     358 
     359   void CFile::recvAddFieldGroup(CEventServer& event) 
     360   { 
     361       
     362      CBufferIn* buffer=event.subEvents.begin()->buffer; 
     363      string id; 
     364      *buffer>>id ; 
     365      get(id)->recvAddFieldGroup(*buffer) ; 
     366   } 
     367    
     368    
     369   void CFile::recvAddFieldGroup(CBufferIn& buffer) 
     370   { 
     371      string id ; 
     372      buffer>>id ; 
     373      addFieldGroup(id) ; 
     374   } 
     375    
     376 
     377   bool CFile::dispatchEvent(CEventServer& event) 
     378   { 
     379      if (SuperClass::dispatchEvent(event)) return true ; 
     380      else 
     381      { 
     382        switch(event.type) 
     383        { 
     384           case EVENT_ID_ADD_FIELD : 
     385             recvAddField(event) ; 
     386             return true ; 
     387             break ; 
     388          
     389           case EVENT_ID_ADD_FIELD_GROUP : 
     390             recvAddFieldGroup(event) ; 
     391             return true ; 
     392             break ;        
     393          
     394           default : 
     395              ERROR("bool CFile::dispatchEvent(CEventServer& event)", <<"Unknown Event") ; 
     396           return false ; 
     397        } 
     398      } 
     399   } 
     400    
     401    
     402    
     403    
    241404   ///--------------------------------------------------------------- 
    242405 
Note: See TracChangeset for help on using the changeset viewer.