Changeset 300 for XMLIO_V2/dev/common/src/node/field.cpp
- Timestamp:
- 02/13/12 19:35:25 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XMLIO_V2/dev/common/src/node/field.cpp
r286 r300 73 73 return (false); 74 74 } 75 75 76 bool CField::dispatchEvent(CEventServer& event) 77 { 78 79 if (SuperClass::dispatchEvent(event)) return true ; 80 else 81 { 82 switch(event.type) 83 { 84 case EVENT_ID_UPDATE_DATA : 85 recvUpdateData(event) ; 86 return true ; 87 break ; 88 89 default : 90 ERROR("bool CField::dispatchEvent(CEventServer& event)",<<"Unknown Event") ; 91 return false ; 92 } 93 } 94 } 95 96 void CField::sendUpdateData(void) 97 { 98 shared_ptr<CContext> context=CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId()) ; 99 CContextClient* client=context->client ; 100 101 CEventClient event(getType(),EVENT_ID_UPDATE_DATA) ; 102 103 map<int,ARRAY(int, 1)>::iterator it ; 104 list<shared_ptr<CMessage> > list_msg ; 105 list<ARRAY(double,1) > list_data ; 106 107 for(it=grid->storeIndex_toSrv.begin();it!=grid->storeIndex_toSrv.end();it++) 108 { 109 int rank=(*it).first ; 110 ARRAY(int,1) index=(*it).second ; 111 ARRAY_CREATE(data_tmp,double,1,[index->num_elements()]) ; 112 for(int n=0;n<data_tmp->num_elements();n++) (*data_tmp)[n]=(*data)[(*index)[n]] ; 113 list_msg.push_back(shared_ptr<CMessage>(new CMessage)) ; 114 list_data.push_back(data_tmp) ; 115 *list_msg.back()<<getId()<<list_data.back() ; 116 event.push(rank,grid->nbSenders[rank],*list_msg.back()) ; 117 } 118 client->sendEvent(event) ; 119 } 120 121 void CField::recvUpdateData(CEventServer& event) 122 { 123 vector<int> ranks ; 124 vector<CBufferIn*> buffers ; 125 126 list<CEventServer::SSubEvent>::iterator it ; 127 string fieldId ; 128 129 for (it=event.subEvents.begin();it!=event.subEvents.end();++it) 130 { 131 int rank=it->rank; 132 CBufferIn* buffer=it->buffer; 133 *buffer>>fieldId ; 134 ranks.push_back(rank) ; 135 buffers.push_back(buffer) ; 136 } 137 get(fieldId)->recvUpdateData(ranks,buffers) ; 138 } 139 140 void CField::recvUpdateData(vector<int>& ranks, vector<CBufferIn*>& buffers) 141 { 142 143 if (data_srv.empty()) 144 { 145 for(map<int,ARRAY(int, 1)>::iterator it=grid->out_i_fromClient.begin();it!=grid->out_i_fromClient.end();it++) 146 { 147 int rank=it->first ; 148 ARRAY_CREATE(data_tmp,double,1,[it->second->num_elements()]) ; 149 data_srv.insert(pair<int, ARRAY(double,1)>(rank,data_tmp)) ; 150 foperation_srv.insert(pair<int,boost::shared_ptr<func::CFunctor> >(rank,boost::shared_ptr<func::CFunctor>(new func::CInstant(data_srv[rank])))) ; 151 } 152 } 153 154 shared_ptr<CContext> context=CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId()) ; 155 const date::CDate & currDate = context->getCalendar()->getCurrentDate(); 156 const date::CDate opeDate = *last_operation_srv + freq_operation_srv; 157 const date::CDate writeDate = *last_Write_srv + freq_write_srv; 158 159 160 161 if (opeDate <= currDate) 162 { 163 for(int n=0;n<ranks.size();n++) 164 { 165 ARRAY_CREATE(data_tmp,double,1,[0]) ; 166 *buffers[n]>>data_tmp ; 167 (*foperation_srv[ranks[n]])(data_tmp) ; 168 } 169 *last_operation_srv = currDate; 170 } 171 172 if (writeDate < (currDate + freq_operation_srv)) 173 { 174 for(int n=0;n<ranks.size();n++) 175 { 176 this->foperation_srv[ranks[n]]->final(); 177 } 178 179 this->incrementNStep(); 180 *last_Write_srv = writeDate; 181 writeField() ; 182 } 183 } 184 185 void CField::writeField(void) 186 { 187 if (! grid->domain->isEmpty() || getRelFile()->type.getValue()=="one_file") 188 getRelFile()->getDataOutput()->writeFieldData(CObjectFactory::GetObject<CField>(this)); 189 } 76 190 //---------------------------------------------------------------- 77 191 … … 232 346 233 347 StdString id = this->getBaseFieldReference()->getId(); 234 boost::shared_ptr<CContext> _context =348 boost::shared_ptr<CContext> context = 235 349 CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId()); 236 350 … … 252 366 } 253 367 254 if (CXIOSManager::GetStatus() == CXIOSManager::LOC_SERVER) 255 { 256 this->freq_operation = 368 // if (CXIOSManager::GetStatus() == CXIOSManager::LOC_SERVER) 369 if (context->hasServer) 370 { 371 this->freq_operation_srv = 257 372 CDuration::FromString(this->file->output_freq.getValue()); 258 this->freq_write =373 this->freq_write_srv = 259 374 CDuration::FromString(this->file->output_freq.getValue()); 260 this->last_Write = boost::shared_ptr<xmlioserver::date::CDate>261 (new date::CDate( _context->getCalendar()->getInitDate()));262 this->last_operation = boost::shared_ptr<xmlioserver::date::CDate>263 (new date::CDate( _context->getCalendar()->getInitDate()));264 this->foperation=265 boost::shared_ptr<func::CFunctor>(new CInstant(this->data));375 this->last_Write_srv = boost::shared_ptr<xmlioserver::date::CDate> 376 (new date::CDate(context->getCalendar()->getInitDate())); 377 this->last_operation_srv = boost::shared_ptr<xmlioserver::date::CDate> 378 (new date::CDate(context->getCalendar()->getInitDate())); 379 // this->foperation_srv = 380 // boost::shared_ptr<func::CFunctor>(new CInstant(this->data_srv)); 266 381 267 const CDuration toffset = this->freq_operation - freq_offset_ - _context->getCalendar()->getTimeStep(); 268 *this->last_operation = *this->last_operation - toffset; 269 } 270 else 382 const CDuration toffset = this->freq_operation_srv - freq_offset_ - context->getCalendar()->getTimeStep(); 383 *this->last_operation_srv = *this->last_operation_srv - toffset; 384 } 385 386 if (context->hasClient) 271 387 { 272 388 this->freq_operation = CDuration::FromString(freq_op.getValue()); 273 389 this->freq_write = CDuration::FromString(this->file->output_freq.getValue()); 274 390 this->last_Write = boost::shared_ptr<xmlioserver::date::CDate> 275 (new date::CDate( _context->getCalendar()->getInitDate()));391 (new date::CDate(context->getCalendar()->getInitDate())); 276 392 this->last_operation = boost::shared_ptr<xmlioserver::date::CDate> 277 (new date::CDate( _context->getCalendar()->getInitDate()));393 (new date::CDate(context->getCalendar()->getInitDate())); 278 394 279 const CDuration toffset = this->freq_operation - freq_offset_ - _context->getCalendar()->getTimeStep();395 const CDuration toffset = this->freq_operation - freq_offset_ - context->getCalendar()->getTimeStep(); 280 396 *this->last_operation = *this->last_operation - toffset; 281 397 … … 409 525 } 410 526 } 411 527 528 void CField::outputField(ARRAY(double,3) fieldOut) 529 { 530 map<int,ARRAY(double,1)>::iterator it; 531 for(it=data_srv.begin();it!=data_srv.end();it++) 532 grid->outputField(it->first,it->second, fieldOut) ; 533 534 } 535 536 void CField::outputField(ARRAY(double,2) fieldOut) 537 { 538 map<int,ARRAY(double,1)>::iterator it; 539 540 for(it=data_srv.begin();it!=data_srv.end();it++) 541 { 542 grid->outputField(it->first,it->second, fieldOut) ; 543 } 544 } 412 545 ///------------------------------------------------------------------- 413 546
Note: See TracChangeset
for help on using the changeset viewer.