Changeset 300 for XMLIO_V2/dev/common/src/node/file.cpp
- Timestamp:
- 02/13/12 19:35:25 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XMLIO_V2/dev/common/src/node/file.cpp
r286 r300 7 7 #include "object_factory.hpp" 8 8 #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 9 14 10 15 namespace xmlioserver { … … 16 21 : CObjectTemplate<CFile>(), CFileAttributes() 17 22 , vFieldGroup(), data_out(), enabledFields() 18 { /* Ne rien faire de plus */}23 { setVirtualFieldGroup() ;} 19 24 20 25 CFile::CFile(const StdString & id) 21 26 : CObjectTemplate<CFile>(id), CFileAttributes() 22 27 , vFieldGroup(), data_out(), enabledFields() 23 { /* Ne rien faire de plus */}28 { setVirtualFieldGroup() ;} 24 29 25 30 CFile::~CFile(void) … … 62 67 this->enabledFields = this->getAllFields(); 63 68 64 std::cout<<"---> File :"<<this->name.getValue()<<std::endl ; 69 std::vector<boost::shared_ptr<CField> > newEnabledFields; 70 65 71 for ( it = this->enabledFields.begin() ; it != this->enabledFields.end(); it++ ) 66 72 { 67 73 if (!(*it)->enabled.isEmpty()) // Si l'attribut 'enabled' est défini ... 68 74 { 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; } 71 77 } 72 78 else // Si l'attribut 'enabled' n'est pas défini ... 73 79 { 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; } 76 82 } 77 83 78 84 if (!(*it)->level.isEmpty()) // Si l'attribut 'level' est défini ... 79 85 { 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; } 82 88 } 83 89 else // Si l'attribut 'level' n'est pas défini ... 84 90 { 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) ; 89 99 // Le champ est finalement actif, on y ajoute sa propre reference. 90 100 (*it)->refObject.push_back(*it); 91 101 // 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 ;93 102 (*it)->setRelFile(CObjectFactory::GetObject(this)); 94 103 (*it)->baseRefObject->refObject.push_back(*it); 95 104 // A faire, ajouter les references intermediaires... 96 105 } 106 enabledFields=newEnabledFields ; 97 107 98 108 return (this->enabledFields); … … 108 118 //---------------------------------------------------------------- 109 119 110 void CFile::setVirtualFieldGroup( const StdString & newVFieldGroupId)120 void CFile::setVirtualFieldGroup(void) 111 121 { 112 122 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 123 131 std::vector<boost::shared_ptr<CField> >::iterator it, end = this->enabledFields.end(); 124 132 133 AllDomainEmpty=true ; 125 134 for (it = this->enabledFields.begin() ;it != end; it++) 126 135 { 127 136 boost::shared_ptr<CField> field = *it; 128 this->data_out->writeFieldGrid(field);137 AllDomainEmpty&=field->grid->domain->isEmpty() ; 129 138 } 130 131 for (it = this->enabledFields.begin() ;it != end; it++)139 140 if (!AllDomainEmpty || type.getValue()=="one_file") 132 141 { 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(); 135 183 } 136 137 this->data_out->definition_end();138 184 } 139 185 140 186 void CFile::close(void) 141 187 { 142 this->data_out->closeFile(); 188 if (!AllDomainEmpty || type.getValue()=="one_file") 189 this->data_out->closeFile(); 143 190 } 144 191 //---------------------------------------------------------------- … … 150 197 { // Si la définition du fichier intégre des champs et si le fichier est identifié. 151 198 node.goToParentElement(); 152 this->setVirtualFieldGroup(this->getId());199 // this->setVirtualFieldGroup(this->getId()); 153 200 this->getVirtualFieldGroup()->parse(node, false); 154 201 } … … 234 281 << "[ renum = " << renum << "] Bad type !"); 235 282 236 this->setVirtualFieldGroup(this->getId());283 // this->setVirtualFieldGroup(this->getId()); 237 284 if (hasVFG)this->getVirtualFieldGroup()->fromBinary(is); 238 285 239 286 } 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 241 404 ///--------------------------------------------------------------- 242 405
Note: See TracChangeset
for help on using the changeset viewer.