[219] | 1 | #include "file.hpp" |
---|
| 2 | |
---|
[352] | 3 | #include "attribute_template.hpp" |
---|
| 4 | #include "object_template.hpp" |
---|
| 5 | #include "group_template.hpp" |
---|
[219] | 6 | #include "object_factory.hpp" |
---|
[300] | 7 | #include "context.hpp" |
---|
| 8 | #include "context_server.hpp" |
---|
| 9 | #include "nc4_data_output.hpp" |
---|
[599] | 10 | #include "nc4_data_input.hpp" |
---|
[318] | 11 | #include "calendar_util.hpp" |
---|
| 12 | #include "date.hpp" |
---|
[352] | 13 | #include "message.hpp" |
---|
| 14 | #include "type.hpp" |
---|
[591] | 15 | #include "xios_spl.hpp" |
---|
[352] | 16 | #include "context_client.hpp" |
---|
[382] | 17 | #include "mpi.hpp" |
---|
[219] | 18 | |
---|
[335] | 19 | namespace xios { |
---|
[509] | 20 | |
---|
[219] | 21 | /// ////////////////////// Définitions ////////////////////// /// |
---|
| 22 | |
---|
| 23 | CFile::CFile(void) |
---|
| 24 | : CObjectTemplate<CFile>(), CFileAttributes() |
---|
[379] | 25 | , vFieldGroup(), data_out(), enabledFields(), fileComm(MPI_COMM_NULL) |
---|
[509] | 26 | { |
---|
[472] | 27 | setVirtualFieldGroup() ; |
---|
| 28 | setVirtualVariableGroup() ; |
---|
| 29 | } |
---|
[219] | 30 | |
---|
| 31 | CFile::CFile(const StdString & id) |
---|
| 32 | : CObjectTemplate<CFile>(id), CFileAttributes() |
---|
[379] | 33 | , vFieldGroup(), data_out(), enabledFields(), fileComm(MPI_COMM_NULL) |
---|
[509] | 34 | { |
---|
[472] | 35 | setVirtualFieldGroup() ; |
---|
| 36 | setVirtualVariableGroup() ; |
---|
| 37 | } |
---|
[219] | 38 | |
---|
| 39 | CFile::~CFile(void) |
---|
| 40 | { /* Ne rien faire de plus */ } |
---|
| 41 | |
---|
| 42 | ///--------------------------------------------------------------- |
---|
[509] | 43 | //! Get name of file |
---|
[219] | 44 | StdString CFile::GetName(void) { return (StdString("file")); } |
---|
| 45 | StdString CFile::GetDefName(void){ return (CFile::GetName()); } |
---|
| 46 | ENodeType CFile::GetType(void) { return (eFile); } |
---|
| 47 | |
---|
| 48 | //---------------------------------------------------------------- |
---|
[509] | 49 | /*! |
---|
[599] | 50 | \brief Get data writer object. |
---|
[509] | 51 | Each enabled file in xml represents a physical netcdf file. |
---|
[599] | 52 | This function allows to access the data writer object. |
---|
| 53 | \return data writer object. |
---|
[509] | 54 | */ |
---|
[337] | 55 | boost::shared_ptr<CDataOutput> CFile::getDataOutput(void) const |
---|
[219] | 56 | { |
---|
[599] | 57 | return data_out; |
---|
[219] | 58 | } |
---|
| 59 | |
---|
[509] | 60 | /*! |
---|
[599] | 61 | \brief Get data reader object. |
---|
| 62 | Each enabled file in xml represents a physical netcdf file. |
---|
| 63 | This function allows to access the data reader object. |
---|
| 64 | \return data reader object. |
---|
| 65 | */ |
---|
| 66 | boost::shared_ptr<CDataInput> CFile::getDataInput(void) const |
---|
| 67 | { |
---|
| 68 | return data_in; |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | /*! |
---|
[509] | 72 | \brief Get virtual field group |
---|
| 73 | In each file, there always exists a field group which is the ancestor of all |
---|
| 74 | fields in the file. This is considered be virtual because it is created automatically during |
---|
| 75 | file initialization and it normally doesn't appear on xml file |
---|
| 76 | \return Pointer to field group |
---|
| 77 | */ |
---|
[347] | 78 | CFieldGroup* CFile::getVirtualFieldGroup(void) const |
---|
[219] | 79 | { |
---|
| 80 | return (this->vFieldGroup); |
---|
| 81 | } |
---|
| 82 | |
---|
[509] | 83 | /*! |
---|
| 84 | \brief Get virtual variable group |
---|
| 85 | In each file, there always exists a variable group which is the ancestor of all |
---|
| 86 | variable in the file. This is considered be virtual because it is created automatically during |
---|
| 87 | file initialization and it normally doesn't appear on xml file |
---|
| 88 | \return Pointer to variable group |
---|
| 89 | */ |
---|
[472] | 90 | CVariableGroup* CFile::getVirtualVariableGroup(void) const |
---|
| 91 | { |
---|
| 92 | return (this->vVariableGroup); |
---|
| 93 | } |
---|
| 94 | |
---|
[509] | 95 | //! Get all fields of a file |
---|
[347] | 96 | std::vector<CField*> CFile::getAllFields(void) const |
---|
[219] | 97 | { |
---|
| 98 | return (this->vFieldGroup->getAllChildren()); |
---|
| 99 | } |
---|
[509] | 100 | |
---|
| 101 | //! Get all variables of a file |
---|
[472] | 102 | std::vector<CVariable*> CFile::getAllVariables(void) const |
---|
| 103 | { |
---|
| 104 | return (this->vVariableGroup->getAllChildren()); |
---|
| 105 | } |
---|
[219] | 106 | |
---|
| 107 | //---------------------------------------------------------------- |
---|
[509] | 108 | /*! |
---|
| 109 | \brief Get all enabled fields of file |
---|
| 110 | A field is considered to be enabled if it fullfil these conditions: it is enabled, inside a enabled file |
---|
| 111 | and its own level is not larger than file output level. |
---|
| 112 | \param [in] default_outputlevel default value output level of file |
---|
| 113 | \param [in] default_level default value level of field |
---|
| 114 | \param [in] default_enabled flag determine by default if field is enabled |
---|
| 115 | \return Vector of pointers of enabled fields |
---|
| 116 | */ |
---|
| 117 | std::vector<CField*> CFile::getEnabledFields(int default_outputlevel, |
---|
[347] | 118 | int default_level, |
---|
| 119 | bool default_enabled) |
---|
[219] | 120 | { |
---|
| 121 | if (!this->enabledFields.empty()) |
---|
| 122 | return (this->enabledFields); |
---|
| 123 | |
---|
| 124 | const int _outputlevel = |
---|
| 125 | (!output_level.isEmpty()) ? output_level.getValue() : default_outputlevel; |
---|
[347] | 126 | std::vector<CField*>::iterator it; |
---|
[219] | 127 | this->enabledFields = this->getAllFields(); |
---|
| 128 | |
---|
[347] | 129 | std::vector<CField*> newEnabledFields; |
---|
[509] | 130 | |
---|
[219] | 131 | for ( it = this->enabledFields.begin() ; it != this->enabledFields.end(); it++ ) |
---|
| 132 | { |
---|
| 133 | if (!(*it)->enabled.isEmpty()) // Si l'attribut 'enabled' est défini ... |
---|
| 134 | { |
---|
[300] | 135 | if (! (*it)->enabled.getValue()) continue; |
---|
| 136 | // { it--; this->enabledFields.erase(it+1); continue; } |
---|
[219] | 137 | } |
---|
| 138 | else // Si l'attribut 'enabled' n'est pas défini ... |
---|
| 139 | { |
---|
[300] | 140 | if (!default_enabled) continue ; |
---|
| 141 | // { it--; this->enabledFields.erase(it+1); continue; } |
---|
[219] | 142 | } |
---|
| 143 | |
---|
| 144 | if (!(*it)->level.isEmpty()) // Si l'attribut 'level' est défini ... |
---|
| 145 | { |
---|
[300] | 146 | if ((*it)->level.getValue() > _outputlevel) continue ; |
---|
| 147 | // { it--; this->enabledFields.erase(it+1); continue; } |
---|
[219] | 148 | } |
---|
| 149 | else // Si l'attribut 'level' n'est pas défini ... |
---|
| 150 | { |
---|
[300] | 151 | if (default_level > _outputlevel) continue ; |
---|
| 152 | // { it--; this->enabledFields.erase(it+1); continue; } |
---|
[219] | 153 | } |
---|
[509] | 154 | |
---|
[300] | 155 | // CField* field_tmp=(*it).get() ; |
---|
| 156 | // shared_ptr<CField> sptfield=*it ; |
---|
| 157 | // field_tmp->refObject.push_back(sptfield) ; |
---|
| 158 | newEnabledFields.push_back(*it) ; |
---|
[286] | 159 | // Le champ est finalement actif, on y ajoute sa propre reference. |
---|
[459] | 160 | // (*it)->refObject.push_back(*it); |
---|
[286] | 161 | // Le champ est finalement actif, on y ajoute la référence au champ de base. |
---|
[346] | 162 | (*it)->setRelFile(CFile::get(this)); |
---|
[459] | 163 | // (*it)->baseRefObject->refObject.push_back(*it); |
---|
[286] | 164 | // A faire, ajouter les references intermediaires... |
---|
[219] | 165 | } |
---|
[300] | 166 | enabledFields=newEnabledFields ; |
---|
[219] | 167 | |
---|
| 168 | return (this->enabledFields); |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | //---------------------------------------------------------------- |
---|
[509] | 172 | //! Change virtual field group to a new one |
---|
[347] | 173 | void CFile::setVirtualFieldGroup(CFieldGroup* newVFieldGroup) |
---|
[509] | 174 | { |
---|
| 175 | this->vFieldGroup = newVFieldGroup; |
---|
[219] | 176 | } |
---|
| 177 | |
---|
[509] | 178 | //! Change virtual variable group to new one |
---|
[472] | 179 | void CFile::setVirtualVariableGroup(CVariableGroup* newVVariableGroup) |
---|
[509] | 180 | { |
---|
| 181 | this->vVariableGroup = newVVariableGroup; |
---|
[472] | 182 | } |
---|
| 183 | |
---|
[219] | 184 | //---------------------------------------------------------------- |
---|
[509] | 185 | //! Create virtual field group, which is done normally on initializing file |
---|
[300] | 186 | void CFile::setVirtualFieldGroup(void) |
---|
[219] | 187 | { |
---|
[346] | 188 | this->setVirtualFieldGroup(CFieldGroup::create()); |
---|
[219] | 189 | } |
---|
| 190 | |
---|
[509] | 191 | //! Create virtual variable group, which is done normally on initializing file |
---|
[472] | 192 | void CFile::setVirtualVariableGroup(void) |
---|
| 193 | { |
---|
| 194 | this->setVirtualVariableGroup(CVariableGroup::create()); |
---|
| 195 | } |
---|
| 196 | |
---|
[219] | 197 | //---------------------------------------------------------------- |
---|
[318] | 198 | bool CFile::isSyncTime(void) |
---|
| 199 | { |
---|
[347] | 200 | CContext* context = CContext::getCurrent() ; |
---|
[561] | 201 | const CDate& currentDate = context->calendar->getCurrentDate() ; |
---|
[538] | 202 | if (!sync_freq.isEmpty()) |
---|
[318] | 203 | { |
---|
[538] | 204 | if (*lastSync + sync_freq.getValue() < currentDate) |
---|
[318] | 205 | { |
---|
| 206 | *lastSync=currentDate ; |
---|
| 207 | return true ; |
---|
| 208 | } |
---|
| 209 | } |
---|
| 210 | return false ; |
---|
| 211 | } |
---|
[509] | 212 | |
---|
| 213 | //! Initialize a file in order to write into it |
---|
[321] | 214 | void CFile::initFile(void) |
---|
| 215 | { |
---|
[347] | 216 | CContext* context = CContext::getCurrent() ; |
---|
[561] | 217 | const CDate& currentDate = context->calendar->getCurrentDate() ; |
---|
[379] | 218 | CContextServer* server=context->server ; |
---|
[509] | 219 | |
---|
[343] | 220 | lastSync=new CDate(currentDate) ; |
---|
| 221 | lastSplit=new CDate(currentDate) ; |
---|
[321] | 222 | isOpen=false ; |
---|
[379] | 223 | |
---|
| 224 | allDomainEmpty=true ; |
---|
[567] | 225 | |
---|
[609] | 226 | set<CAxis*> setAxis; |
---|
| 227 | set<CDomain*> setDomains; |
---|
[379] | 228 | |
---|
| 229 | std::vector<CField*>::iterator it, end = this->enabledFields.end(); |
---|
[609] | 230 | for (it = this->enabledFields.begin(); it != end; it++) |
---|
[379] | 231 | { |
---|
| 232 | CField* field = *it; |
---|
[609] | 233 | allDomainEmpty &= !field->grid->doGridHaveDataToWrite(); |
---|
| 234 | std::vector<CAxis*> vecAxis = field->grid->getAxis(); |
---|
| 235 | for (size_t i = 0; i < vecAxis.size(); ++i) |
---|
| 236 | setAxis.insert(vecAxis[i]); |
---|
| 237 | std::vector<CDomain*> vecDomains = field->grid->getDomains(); |
---|
| 238 | for (size_t i = 0; i < vecDomains.size(); ++i) |
---|
| 239 | setDomains.insert(vecDomains[i]); |
---|
[379] | 240 | } |
---|
[609] | 241 | nbAxis = setAxis.size(); |
---|
| 242 | nbDomains = setDomains.size(); |
---|
[379] | 243 | |
---|
[509] | 244 | // create sub communicator for file |
---|
[379] | 245 | int color=allDomainEmpty?0:1 ; |
---|
| 246 | MPI_Comm_split(server->intraComm,color,server->intraCommRank,&fileComm) ; |
---|
| 247 | if (allDomainEmpty) MPI_Comm_free(&fileComm) ; |
---|
| 248 | // |
---|
[509] | 249 | |
---|
[321] | 250 | } |
---|
[509] | 251 | |
---|
| 252 | //! Verify state of a file |
---|
[321] | 253 | void CFile::checkFile(void) |
---|
| 254 | { |
---|
[599] | 255 | if (mode.isEmpty() || mode.getValue() == mode_attr::write) |
---|
| 256 | { |
---|
| 257 | if (!isOpen) createHeader(); |
---|
| 258 | checkSync(); |
---|
| 259 | } |
---|
| 260 | else |
---|
| 261 | { |
---|
| 262 | if (!isOpen) openInReadMode(); |
---|
| 263 | } |
---|
| 264 | checkSplit(); |
---|
[321] | 265 | } |
---|
[509] | 266 | |
---|
| 267 | /*! |
---|
| 268 | \brief Verify if synchronisation should be done |
---|
| 269 | If syn option is enabled, syn frequence and current time will be used to |
---|
| 270 | calculate the moment to syn file(s) |
---|
| 271 | \return True if it is the moment to synchronize file, otherwise false |
---|
| 272 | */ |
---|
[321] | 273 | bool CFile::checkSync(void) |
---|
| 274 | { |
---|
[347] | 275 | CContext* context = CContext::getCurrent() ; |
---|
[561] | 276 | const CDate& currentDate = context->calendar->getCurrentDate() ; |
---|
[538] | 277 | if (!sync_freq.isEmpty()) |
---|
[321] | 278 | { |
---|
[538] | 279 | if (*lastSync + sync_freq.getValue() <= currentDate) |
---|
[321] | 280 | { |
---|
| 281 | *lastSync=currentDate ; |
---|
| 282 | data_out->syncFile() ; |
---|
| 283 | return true ; |
---|
| 284 | } |
---|
| 285 | } |
---|
| 286 | return false ; |
---|
| 287 | } |
---|
[509] | 288 | |
---|
| 289 | /*! |
---|
| 290 | \brief Verify if splitting should be done |
---|
| 291 | If split option is enabled, split frequence and current time will be used to |
---|
| 292 | calculate the moment to split file |
---|
| 293 | \return True if it is the moment to split file, otherwise false |
---|
| 294 | */ |
---|
[321] | 295 | bool CFile::checkSplit(void) |
---|
| 296 | { |
---|
[347] | 297 | CContext* context = CContext::getCurrent() ; |
---|
[561] | 298 | const CDate& currentDate = context->calendar->getCurrentDate() ; |
---|
[538] | 299 | if (!split_freq.isEmpty()) |
---|
[321] | 300 | { |
---|
[538] | 301 | if (currentDate > *lastSplit + split_freq.getValue()) |
---|
[321] | 302 | { |
---|
[538] | 303 | *lastSplit = *lastSplit + split_freq.getValue(); |
---|
[347] | 304 | std::vector<CField*>::iterator it, end = this->enabledFields.end(); |
---|
[599] | 305 | for (it = this->enabledFields.begin(); it != end; it++) |
---|
| 306 | { |
---|
| 307 | (*it)->resetNStep(); |
---|
| 308 | (*it)->resetNStepMax(); |
---|
| 309 | } |
---|
| 310 | if (mode.isEmpty() || mode.getValue() == mode_attr::write) |
---|
| 311 | createHeader() ; |
---|
| 312 | else |
---|
| 313 | openInReadMode(); |
---|
[321] | 314 | return true ; |
---|
| 315 | } |
---|
| 316 | } |
---|
| 317 | return false ; |
---|
| 318 | } |
---|
[509] | 319 | |
---|
| 320 | /*! |
---|
| 321 | \brief Create header of netcdf file |
---|
| 322 | There are some information to fill in header of each netcdf. |
---|
| 323 | */ |
---|
[300] | 324 | void CFile::createHeader(void) |
---|
[219] | 325 | { |
---|
[347] | 326 | CContext* context = CContext::getCurrent() ; |
---|
[379] | 327 | CContextServer* server=context->server ; |
---|
[509] | 328 | |
---|
[379] | 329 | if (!allDomainEmpty) |
---|
[219] | 330 | { |
---|
[300] | 331 | StdString filename = (!name.isEmpty()) ? name.getValue() : getId(); |
---|
| 332 | StdOStringStream oss; |
---|
| 333 | oss << filename; |
---|
| 334 | if (!name_suffix.isEmpty()) oss << name_suffix.getValue(); |
---|
[538] | 335 | |
---|
[431] | 336 | if (!split_freq.isEmpty()) |
---|
| 337 | { |
---|
| 338 | string splitFormat ; |
---|
| 339 | if (split_freq_format.isEmpty()) |
---|
| 340 | { |
---|
[538] | 341 | if (split_freq.getValue().second != 0) splitFormat = "%y%mo%d%h%mi%s"; |
---|
| 342 | else if (split_freq.getValue().minute != 0) splitFormat = "%y%mo%d%h%mi"; |
---|
| 343 | else if (split_freq.getValue().hour != 0) splitFormat = "%y%mo%d%h"; |
---|
| 344 | else if (split_freq.getValue().day != 0) splitFormat = "%y%mo%d"; |
---|
| 345 | else if (split_freq.getValue().month != 0) splitFormat = "%y%mo"; |
---|
| 346 | else splitFormat = "%y"; |
---|
[431] | 347 | } |
---|
| 348 | else splitFormat=split_freq_format ; |
---|
[538] | 349 | oss << "_" << lastSplit->getStr(splitFormat) |
---|
[589] | 350 | << "-" << (*lastSplit + split_freq.getValue() - 1 * Second).getStr(splitFormat); |
---|
[431] | 351 | } |
---|
[509] | 352 | |
---|
[528] | 353 | bool append = !this->append.isEmpty() && this->append.getValue(); |
---|
[567] | 354 | |
---|
[517] | 355 | bool useClassicFormat = !format.isEmpty() && format == format_attr::netcdf4_classic; |
---|
| 356 | |
---|
[300] | 357 | bool multifile=true ; |
---|
| 358 | if (!type.isEmpty()) |
---|
| 359 | { |
---|
[369] | 360 | if (type==type_attr::one_file) multifile=false ; |
---|
| 361 | else if (type==type_attr::multiple_file) multifile=true ; |
---|
[379] | 362 | |
---|
[509] | 363 | } |
---|
[379] | 364 | #ifndef USING_NETCDF_PAR |
---|
| 365 | if (!multifile) |
---|
| 366 | { |
---|
| 367 | info(0)<<"!!! Warning -> Using non parallel version of netcdf, switching in multiple_file mode for file : "<<filename<<" ..."<<endl ; |
---|
| 368 | multifile=true ; |
---|
| 369 | } |
---|
| 370 | #endif |
---|
[509] | 371 | if (multifile) |
---|
[300] | 372 | { |
---|
[379] | 373 | int commSize, commRank ; |
---|
| 374 | MPI_Comm_size(fileComm,&commSize) ; |
---|
| 375 | MPI_Comm_rank(fileComm,&commRank) ; |
---|
[509] | 376 | |
---|
| 377 | if (server->intraCommSize > 1) |
---|
[375] | 378 | { |
---|
| 379 | oss << "_" ; |
---|
[379] | 380 | int width=0 ; int n=commSize-1 ; |
---|
[375] | 381 | while(n != 0) { n=n/10 ; width++ ;} |
---|
[509] | 382 | if (!min_digits.isEmpty()) |
---|
[391] | 383 | if (width<min_digits) width=min_digits ; |
---|
[375] | 384 | oss.width(width) ; |
---|
| 385 | oss.fill('0') ; |
---|
[379] | 386 | oss<<right<< commRank; |
---|
[375] | 387 | } |
---|
[300] | 388 | } |
---|
| 389 | oss << ".nc"; |
---|
| 390 | |
---|
[526] | 391 | bool isCollective = par_access.isEmpty() || par_access == par_access_attr::collective; |
---|
| 392 | |
---|
| 393 | if (isOpen) data_out->closeFile(); |
---|
| 394 | |
---|
[528] | 395 | data_out = shared_ptr<CDataOutput>(new CNc4DataOutput(oss.str(), append, useClassicFormat, |
---|
| 396 | fileComm, multifile, isCollective)); |
---|
| 397 | isOpen = true; |
---|
[300] | 398 | |
---|
[528] | 399 | data_out->writeFile(CFile::get(this)); |
---|
| 400 | |
---|
| 401 | // Do not recreate the file structure if opening an existing file |
---|
| 402 | if (!data_out->IsInAppendMode()) |
---|
| 403 | { |
---|
| 404 | std::vector<CField*>::iterator it, end = this->enabledFields.end(); |
---|
| 405 | for (it = this->enabledFields.begin(); it != end; it++) |
---|
| 406 | { |
---|
[347] | 407 | CField* field = *it; |
---|
[300] | 408 | this->data_out->writeFieldGrid(field); |
---|
[528] | 409 | } |
---|
| 410 | this->data_out->writeTimeDimension(); |
---|
[509] | 411 | |
---|
[528] | 412 | for (it = this->enabledFields.begin(); it != end; it++) |
---|
| 413 | { |
---|
[347] | 414 | CField* field = *it; |
---|
[300] | 415 | this->data_out->writeField(field); |
---|
[528] | 416 | } |
---|
[509] | 417 | |
---|
[528] | 418 | vector<CVariable*> listVars = getAllVariables() ; |
---|
| 419 | for (vector<CVariable*>::iterator it = listVars.begin(); it != listVars.end(); it++) |
---|
| 420 | this->data_out->writeAttribute(*it); |
---|
[509] | 421 | |
---|
[528] | 422 | this->data_out->definition_end(); |
---|
| 423 | } |
---|
[219] | 424 | } |
---|
| 425 | } |
---|
| 426 | |
---|
[599] | 427 | /*! |
---|
| 428 | \brief Open an existing NetCDF file in read-only mode |
---|
| 429 | */ |
---|
| 430 | void CFile::openInReadMode(void) |
---|
| 431 | { |
---|
| 432 | CContext* context = CContext::getCurrent(); |
---|
| 433 | CContextServer* server=context->server; |
---|
| 434 | |
---|
| 435 | if (!allDomainEmpty) |
---|
| 436 | { |
---|
| 437 | StdString filename = (!name.isEmpty()) ? name.getValue() : getId(); |
---|
| 438 | StdOStringStream oss; |
---|
| 439 | oss << filename; |
---|
| 440 | if (!name_suffix.isEmpty()) oss << name_suffix.getValue(); |
---|
| 441 | |
---|
| 442 | if (!split_freq.isEmpty()) |
---|
| 443 | { |
---|
| 444 | string splitFormat; |
---|
| 445 | if (split_freq_format.isEmpty()) |
---|
| 446 | { |
---|
| 447 | if (split_freq.getValue().second != 0) splitFormat = "%y%mo%d%h%mi%s"; |
---|
| 448 | else if (split_freq.getValue().minute != 0) splitFormat = "%y%mo%d%h%mi"; |
---|
| 449 | else if (split_freq.getValue().hour != 0) splitFormat = "%y%mo%d%h"; |
---|
| 450 | else if (split_freq.getValue().day != 0) splitFormat = "%y%mo%d"; |
---|
| 451 | else if (split_freq.getValue().month != 0) splitFormat = "%y%mo"; |
---|
| 452 | else splitFormat = "%y"; |
---|
| 453 | } |
---|
| 454 | else splitFormat=split_freq_format; |
---|
| 455 | oss << "_" << lastSplit->getStr(splitFormat) |
---|
| 456 | << "-" << (*lastSplit + split_freq.getValue() - 1 * Second).getStr(splitFormat); |
---|
| 457 | } |
---|
| 458 | |
---|
| 459 | bool multifile = true; |
---|
| 460 | if (!type.isEmpty()) |
---|
| 461 | { |
---|
| 462 | if (type == type_attr::one_file) multifile = false; |
---|
| 463 | else if (type == type_attr::multiple_file) multifile = true; |
---|
| 464 | } |
---|
| 465 | #ifndef USING_NETCDF_PAR |
---|
| 466 | if (!multifile) |
---|
| 467 | { |
---|
| 468 | info(0) << "!!! Warning -> Using non parallel version of netcdf, switching in multiple_file mode for file : " << filename << " ..." << endl; |
---|
| 469 | multifile = true; |
---|
| 470 | } |
---|
| 471 | #endif |
---|
| 472 | if (multifile) |
---|
| 473 | { |
---|
| 474 | int commSize, commRank; |
---|
| 475 | MPI_Comm_size(fileComm, &commSize); |
---|
| 476 | MPI_Comm_rank(fileComm, &commRank); |
---|
| 477 | |
---|
| 478 | if (server->intraCommSize > 1) |
---|
| 479 | { |
---|
| 480 | oss << "_" ; |
---|
| 481 | int width = 0, n = commSize - 1; |
---|
| 482 | while (n != 0) { n = n / 10; width++; } |
---|
| 483 | if (!min_digits.isEmpty() && width < min_digits) |
---|
| 484 | width = min_digits; |
---|
| 485 | oss.width(width); |
---|
| 486 | oss.fill('0'); |
---|
| 487 | oss << right << commRank; |
---|
| 488 | } |
---|
| 489 | } |
---|
| 490 | oss << ".nc"; |
---|
| 491 | |
---|
| 492 | bool isCollective = par_access.isEmpty() || par_access == par_access_attr::collective; |
---|
| 493 | |
---|
| 494 | if (isOpen) data_out->closeFile(); |
---|
| 495 | |
---|
| 496 | data_in = shared_ptr<CDataInput>(new CNc4DataInput(oss.str(), fileComm, multifile, isCollective)); |
---|
| 497 | isOpen = true; |
---|
| 498 | } |
---|
| 499 | } |
---|
| 500 | |
---|
[509] | 501 | //! Close file |
---|
[286] | 502 | void CFile::close(void) |
---|
| 503 | { |
---|
[321] | 504 | delete lastSync ; |
---|
| 505 | delete lastSplit ; |
---|
[379] | 506 | if (!allDomainEmpty) |
---|
[509] | 507 | if (isOpen) |
---|
[321] | 508 | { |
---|
[599] | 509 | if (mode.isEmpty() || mode.getValue() == mode_attr::write) |
---|
| 510 | this->data_out->closeFile(); |
---|
| 511 | else |
---|
| 512 | this->data_in->closeFile(); |
---|
[321] | 513 | } |
---|
[379] | 514 | if (fileComm != MPI_COMM_NULL) MPI_Comm_free(&fileComm) ; |
---|
[286] | 515 | } |
---|
[219] | 516 | //---------------------------------------------------------------- |
---|
| 517 | |
---|
[509] | 518 | /*! |
---|
| 519 | \brief Parse xml file and write information into file object |
---|
| 520 | \param [in] node xmld node corresponding in xml file |
---|
| 521 | */ |
---|
[219] | 522 | void CFile::parse(xml::CXMLNode & node) |
---|
| 523 | { |
---|
| 524 | SuperClass::parse(node); |
---|
[509] | 525 | |
---|
[472] | 526 | if (node.goToChildElement()) |
---|
| 527 | { |
---|
| 528 | do |
---|
| 529 | { |
---|
| 530 | if (node.getElementName()=="field" || node.getElementName()=="field_group") this->getVirtualFieldGroup()->parseChild(node); |
---|
| 531 | else if (node.getElementName()=="variable" || node.getElementName()=="variable_group") this->getVirtualVariableGroup()->parseChild(node); |
---|
| 532 | } while (node.goToNextElement()) ; |
---|
| 533 | node.goToParentElement(); |
---|
[219] | 534 | } |
---|
[472] | 535 | |
---|
[219] | 536 | } |
---|
| 537 | //---------------------------------------------------------------- |
---|
| 538 | |
---|
[509] | 539 | /*! |
---|
| 540 | \brief Represent a file in form of string with all its info |
---|
| 541 | \return String |
---|
| 542 | */ |
---|
[219] | 543 | StdString CFile::toString(void) const |
---|
| 544 | { |
---|
| 545 | StdOStringStream oss; |
---|
| 546 | |
---|
| 547 | oss << "<" << CFile::GetName() << " "; |
---|
| 548 | if (this->hasId()) |
---|
| 549 | oss << " id=\"" << this->getId() << "\" "; |
---|
| 550 | oss << SuperClassAttribute::toString() << ">" << std::endl; |
---|
[347] | 551 | if (this->getVirtualFieldGroup() != NULL) |
---|
[219] | 552 | oss << *this->getVirtualFieldGroup() << std::endl; |
---|
| 553 | oss << "</" << CFile::GetName() << " >"; |
---|
| 554 | return (oss.str()); |
---|
| 555 | } |
---|
| 556 | |
---|
| 557 | //---------------------------------------------------------------- |
---|
[509] | 558 | |
---|
| 559 | /*! |
---|
| 560 | \brief Find all inheritace among objects in a file. |
---|
| 561 | \param [in] apply (true) write attributes of parent into ones of child if they are empty |
---|
| 562 | (false) write attributes of parent into a new container of child |
---|
| 563 | \param [in] parent |
---|
| 564 | */ |
---|
[445] | 565 | void CFile::solveDescInheritance(bool apply, const CAttributeMap * const parent) |
---|
[219] | 566 | { |
---|
[445] | 567 | SuperClassAttribute::setAttributes(parent,apply); |
---|
[509] | 568 | this->getVirtualFieldGroup()->solveDescInheritance(apply, NULL); |
---|
[472] | 569 | this->getVirtualVariableGroup()->solveDescInheritance(apply, NULL); |
---|
[219] | 570 | } |
---|
| 571 | |
---|
| 572 | //---------------------------------------------------------------- |
---|
| 573 | |
---|
[509] | 574 | // void CFile::processEnabledFile(void) |
---|
| 575 | // { |
---|
| 576 | // if (output_freq.isEmpty()) ERROR("void CFile::processEnabledFile(void)", |
---|
| 577 | // <<"File attribute <<output_freq>> is undefined"); |
---|
| 578 | // solveFieldRefInheritance(true) ; |
---|
| 579 | // getEnabledFields() ; |
---|
| 580 | // processEnabledFields() ; |
---|
| 581 | // } |
---|
| 582 | |
---|
| 583 | // void CFile::processEnabledFields(void) |
---|
| 584 | // { |
---|
| 585 | // for (unsigned int i = 0; i < this->enabledFields.size(); i++) |
---|
| 586 | // { |
---|
| 587 | // this->enabledFields[i]->processEnabledField() ; |
---|
| 588 | // } |
---|
| 589 | // } |
---|
| 590 | |
---|
| 591 | /*! |
---|
| 592 | \brief Resolve all reference of active fields. |
---|
| 593 | In order to know exactly which data each active field has, a search for all its |
---|
| 594 | reference to find its parents or/and its base reference object must be done. Moreover |
---|
| 595 | during this search, there are some information that can only be sent to server AFTER |
---|
| 596 | all information of active fields are created on server side, e.g: checking mask or index |
---|
| 597 | \param [in] sendToServer: Send all info to server (true) or only a part of it (false) |
---|
| 598 | */ |
---|
| 599 | void CFile::solveAllRefOfEnabledFields(bool sendToServer) |
---|
[459] | 600 | { |
---|
[509] | 601 | int size = this->enabledFields.size(); |
---|
| 602 | for (int i = 0; i < size; ++i) |
---|
| 603 | { |
---|
| 604 | this->enabledFields[i]->solveAllReferenceEnabledField(sendToServer); |
---|
| 605 | } |
---|
[459] | 606 | } |
---|
[509] | 607 | |
---|
| 608 | /*! |
---|
| 609 | \brief Contruct all expression related to active fields. |
---|
| 610 | Each field can do some expressions which appear on the xml file, and itself can be |
---|
| 611 | a result of an expression among some other fields. This function builds all possible expression |
---|
| 612 | relating to active fields. |
---|
| 613 | */ |
---|
| 614 | void CFile::buildAllExpressionOfEnabledFields() |
---|
[459] | 615 | { |
---|
[509] | 616 | int size = this->enabledFields.size(); |
---|
| 617 | for (int i = 0; i < size; ++i) |
---|
| 618 | { |
---|
| 619 | this->enabledFields[i]->buildAllExpressionEnabledField(); |
---|
| 620 | } |
---|
| 621 | } |
---|
| 622 | |
---|
[598] | 623 | /*! |
---|
| 624 | Prefetching the data for enabled fields read from file. |
---|
| 625 | */ |
---|
| 626 | void CFile::prefetchEnabledReadModeFields(void) |
---|
| 627 | { |
---|
| 628 | if (mode.isEmpty() || mode.getValue() != mode_attr::read) |
---|
| 629 | return; |
---|
| 630 | |
---|
| 631 | int size = this->enabledFields.size(); |
---|
| 632 | for (int i = 0; i < size; ++i) |
---|
| 633 | this->enabledFields[i]->sendReadDataRequest(); |
---|
| 634 | } |
---|
| 635 | |
---|
| 636 | /*! |
---|
| 637 | Prefetching the data for enabled fields read from file whose data is out-of-date. |
---|
| 638 | */ |
---|
| 639 | void CFile::prefetchEnabledReadModeFieldsIfNeeded(void) |
---|
| 640 | { |
---|
| 641 | if (mode.isEmpty() || mode.getValue() != mode_attr::read) |
---|
| 642 | return; |
---|
| 643 | |
---|
| 644 | int size = this->enabledFields.size(); |
---|
| 645 | for (int i = 0; i < size; ++i) |
---|
| 646 | this->enabledFields[i]->sendReadDataRequestIfNeeded(); |
---|
| 647 | } |
---|
| 648 | |
---|
[445] | 649 | void CFile::solveFieldRefInheritance(bool apply) |
---|
[219] | 650 | { |
---|
| 651 | // Résolution des héritages par référence de chacun des champs contenus dans le fichier. |
---|
[347] | 652 | std::vector<CField*> allF = this->getAllFields(); |
---|
[219] | 653 | for (unsigned int i = 0; i < allF.size(); i++) |
---|
[445] | 654 | allF[i]->solveRefInheritance(apply); |
---|
[219] | 655 | } |
---|
| 656 | |
---|
| 657 | //---------------------------------------------------------------- |
---|
| 658 | |
---|
| 659 | void CFile::solveEFGridRef(void) |
---|
| 660 | { |
---|
| 661 | for (unsigned int i = 0; i < this->enabledFields.size(); i++) |
---|
| 662 | this->enabledFields[i]->solveGridReference(); |
---|
| 663 | } |
---|
| 664 | |
---|
| 665 | //---------------------------------------------------------------- |
---|
| 666 | |
---|
| 667 | void CFile::solveEFOperation(void) |
---|
| 668 | { |
---|
| 669 | for (unsigned int i = 0; i < this->enabledFields.size(); i++) |
---|
| 670 | this->enabledFields[i]->solveOperation(); |
---|
| 671 | } |
---|
[509] | 672 | |
---|
[459] | 673 | void CFile::solveEFExpression(void) |
---|
[219] | 674 | { |
---|
[459] | 675 | for (unsigned int i = 0; i < this->enabledFields.size(); i++) |
---|
| 676 | this->enabledFields[i]->buildExpression(); |
---|
[509] | 677 | } |
---|
[369] | 678 | |
---|
[509] | 679 | /*! |
---|
| 680 | \brief Add a field into file. |
---|
| 681 | A field is added into file and it will be written out if the file is enabled and |
---|
| 682 | level of this field is smaller than level_output. A new field won't be created if one |
---|
| 683 | with id has already existed |
---|
| 684 | \param [in] id String identity of new field |
---|
| 685 | \return Pointer to added (or already existed) field |
---|
| 686 | */ |
---|
[347] | 687 | CField* CFile::addField(const string& id) |
---|
[300] | 688 | { |
---|
| 689 | return vFieldGroup->createChild(id) ; |
---|
| 690 | } |
---|
[219] | 691 | |
---|
[509] | 692 | /*! |
---|
| 693 | \brief Add a field group into file. |
---|
| 694 | A field group is added into file and it will play a role as parents for fields. |
---|
| 695 | A new field group won't be created if one with id has already existed |
---|
| 696 | \param [in] id String identity of new field group |
---|
| 697 | \return Pointer to added (or already existed) field group |
---|
| 698 | */ |
---|
[347] | 699 | CFieldGroup* CFile::addFieldGroup(const string& id) |
---|
[300] | 700 | { |
---|
| 701 | return vFieldGroup->createChildGroup(id) ; |
---|
| 702 | } |
---|
[509] | 703 | |
---|
| 704 | /*! |
---|
| 705 | \brief Add a variable into file. |
---|
| 706 | A variable is added into file and if one with id has already existed, pointer to |
---|
| 707 | it will be returned. |
---|
| 708 | Variable as long as attributes are information container of file. |
---|
| 709 | However, whereas attributes are "fixed" information, variables provides a more flexible way to user |
---|
| 710 | to fill in (extra) information for a file. |
---|
| 711 | \param [in] id String identity of new variable |
---|
| 712 | \return Pointer to added (or already existed) variable |
---|
| 713 | */ |
---|
[472] | 714 | CVariable* CFile::addVariable(const string& id) |
---|
| 715 | { |
---|
| 716 | return vVariableGroup->createChild(id) ; |
---|
| 717 | } |
---|
| 718 | |
---|
[509] | 719 | /*! |
---|
| 720 | \brief Add a variable group into file. |
---|
| 721 | A variable group is added into file and it will play a role as parents for variables. |
---|
| 722 | A new variable group won't be created if one with id has already existed |
---|
| 723 | \param [in] id String identity of new variable group |
---|
| 724 | \return Pointer to added (or already existed) variable group |
---|
| 725 | */ |
---|
[472] | 726 | CVariableGroup* CFile::addVariableGroup(const string& id) |
---|
| 727 | { |
---|
| 728 | return vVariableGroup->createChildGroup(id) ; |
---|
| 729 | } |
---|
[509] | 730 | |
---|
| 731 | /*! |
---|
| 732 | \brief Send a message to create a field on server side |
---|
| 733 | \param[in] id String identity of field that will be created on server |
---|
| 734 | */ |
---|
[300] | 735 | void CFile::sendAddField(const string& id) |
---|
| 736 | { |
---|
[347] | 737 | CContext* context=CContext::getCurrent() ; |
---|
[509] | 738 | |
---|
[300] | 739 | if (! context->hasServer ) |
---|
| 740 | { |
---|
| 741 | CContextClient* client=context->client ; |
---|
| 742 | |
---|
[509] | 743 | CEventClient event(this->getType(),EVENT_ID_ADD_FIELD) ; |
---|
[300] | 744 | if (client->isServerLeader()) |
---|
| 745 | { |
---|
| 746 | CMessage msg ; |
---|
| 747 | msg<<this->getId() ; |
---|
| 748 | msg<<id ; |
---|
[595] | 749 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
| 750 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 751 | event.push(*itRank,1,msg); |
---|
[300] | 752 | client->sendEvent(event) ; |
---|
| 753 | } |
---|
| 754 | else client->sendEvent(event) ; |
---|
| 755 | } |
---|
[509] | 756 | |
---|
[300] | 757 | } |
---|
[509] | 758 | |
---|
| 759 | /*! |
---|
| 760 | \brief Send a message to create a field group on server side |
---|
| 761 | \param[in] id String identity of field group that will be created on server |
---|
| 762 | */ |
---|
[300] | 763 | void CFile::sendAddFieldGroup(const string& id) |
---|
| 764 | { |
---|
[347] | 765 | CContext* context=CContext::getCurrent() ; |
---|
[300] | 766 | if (! context->hasServer ) |
---|
| 767 | { |
---|
| 768 | CContextClient* client=context->client ; |
---|
| 769 | |
---|
[509] | 770 | CEventClient event(this->getType(),EVENT_ID_ADD_FIELD_GROUP) ; |
---|
[300] | 771 | if (client->isServerLeader()) |
---|
| 772 | { |
---|
| 773 | CMessage msg ; |
---|
| 774 | msg<<this->getId() ; |
---|
| 775 | msg<<id ; |
---|
[595] | 776 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
| 777 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 778 | event.push(*itRank,1,msg); |
---|
[300] | 779 | client->sendEvent(event) ; |
---|
| 780 | } |
---|
| 781 | else client->sendEvent(event) ; |
---|
| 782 | } |
---|
[509] | 783 | |
---|
[300] | 784 | } |
---|
[509] | 785 | |
---|
| 786 | /*! |
---|
| 787 | \brief Receive a message annoucing the creation of a field on server side |
---|
| 788 | \param[in] event Received event |
---|
| 789 | */ |
---|
[300] | 790 | void CFile::recvAddField(CEventServer& event) |
---|
| 791 | { |
---|
[509] | 792 | |
---|
[300] | 793 | CBufferIn* buffer=event.subEvents.begin()->buffer; |
---|
| 794 | string id; |
---|
| 795 | *buffer>>id ; |
---|
| 796 | get(id)->recvAddField(*buffer) ; |
---|
| 797 | } |
---|
[509] | 798 | |
---|
| 799 | /*! |
---|
| 800 | \brief Receive a message annoucing the creation of a field on server side |
---|
| 801 | \param[in] buffer Buffer containing message |
---|
| 802 | */ |
---|
[300] | 803 | void CFile::recvAddField(CBufferIn& buffer) |
---|
| 804 | { |
---|
| 805 | string id ; |
---|
| 806 | buffer>>id ; |
---|
| 807 | addField(id) ; |
---|
| 808 | } |
---|
| 809 | |
---|
[509] | 810 | /*! |
---|
| 811 | \brief Receive a message annoucing the creation of a field group on server side |
---|
| 812 | \param[in] event Received event |
---|
| 813 | */ |
---|
[300] | 814 | void CFile::recvAddFieldGroup(CEventServer& event) |
---|
| 815 | { |
---|
[509] | 816 | |
---|
[300] | 817 | CBufferIn* buffer=event.subEvents.begin()->buffer; |
---|
| 818 | string id; |
---|
| 819 | *buffer>>id ; |
---|
| 820 | get(id)->recvAddFieldGroup(*buffer) ; |
---|
| 821 | } |
---|
[509] | 822 | |
---|
| 823 | /*! |
---|
| 824 | \brief Receive a message annoucing the creation of a field group on server side |
---|
| 825 | \param[in] buffer Buffer containing message |
---|
| 826 | */ |
---|
[300] | 827 | void CFile::recvAddFieldGroup(CBufferIn& buffer) |
---|
| 828 | { |
---|
| 829 | string id ; |
---|
| 830 | buffer>>id ; |
---|
| 831 | addFieldGroup(id) ; |
---|
| 832 | } |
---|
| 833 | |
---|
[509] | 834 | /*! |
---|
| 835 | \brief Send messages to duplicate all variables on server side |
---|
| 836 | Because each variable has also its attributes. So first thing to do is replicate |
---|
| 837 | all these attributes on server side. Because variable can have a value, the second thing |
---|
| 838 | is to duplicate this value on server, too. |
---|
| 839 | */ |
---|
| 840 | void CFile::sendAddAllVariables() |
---|
| 841 | { |
---|
| 842 | if (!getAllVariables().empty()) |
---|
| 843 | { |
---|
| 844 | // Firstly, it's necessary to add virtual variable group |
---|
| 845 | sendAddVariableGroup(getVirtualVariableGroup()->getId()); |
---|
[472] | 846 | |
---|
[509] | 847 | // Okie, now we can add to this variable group |
---|
| 848 | std::vector<CVariable*> allVar = getAllVariables(); |
---|
| 849 | std::vector<CVariable*>::const_iterator it = allVar.begin(); |
---|
| 850 | std::vector<CVariable*>::const_iterator itE = allVar.end(); |
---|
[472] | 851 | |
---|
[509] | 852 | for (; it != itE; ++it) |
---|
| 853 | { |
---|
| 854 | this->sendAddVariable((*it)->getId()); |
---|
| 855 | (*it)->sendAllAttributesToServer(); |
---|
| 856 | (*it)->sendValue(); |
---|
| 857 | } |
---|
| 858 | } |
---|
| 859 | } |
---|
[472] | 860 | |
---|
[509] | 861 | /*! |
---|
| 862 | \brief Send a message to create a variable on server side |
---|
| 863 | A variable always belongs to a variable group |
---|
| 864 | \param[in] id String identity of variable that will be created on server |
---|
| 865 | */ |
---|
[472] | 866 | void CFile::sendAddVariable(const string& id) |
---|
| 867 | { |
---|
| 868 | CContext* context=CContext::getCurrent() ; |
---|
[509] | 869 | |
---|
[472] | 870 | if (! context->hasServer ) |
---|
| 871 | { |
---|
| 872 | CContextClient* client=context->client ; |
---|
| 873 | |
---|
[509] | 874 | CEventClient event(this->getType(),EVENT_ID_ADD_VARIABLE) ; |
---|
[472] | 875 | if (client->isServerLeader()) |
---|
| 876 | { |
---|
| 877 | CMessage msg ; |
---|
| 878 | msg<<this->getId() ; |
---|
| 879 | msg<<id ; |
---|
[595] | 880 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
| 881 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 882 | event.push(*itRank,1,msg); |
---|
[472] | 883 | client->sendEvent(event) ; |
---|
| 884 | } |
---|
| 885 | else client->sendEvent(event) ; |
---|
| 886 | } |
---|
[509] | 887 | |
---|
[472] | 888 | } |
---|
[509] | 889 | |
---|
| 890 | /*! |
---|
| 891 | \brief Send a message to create a variable group on server side |
---|
| 892 | \param[in] id String identity of variable group that will be created on server |
---|
| 893 | */ |
---|
[472] | 894 | void CFile::sendAddVariableGroup(const string& id) |
---|
| 895 | { |
---|
| 896 | CContext* context=CContext::getCurrent() ; |
---|
| 897 | if (! context->hasServer ) |
---|
| 898 | { |
---|
| 899 | CContextClient* client=context->client ; |
---|
| 900 | |
---|
[509] | 901 | CEventClient event(this->getType(),EVENT_ID_ADD_VARIABLE_GROUP) ; |
---|
[472] | 902 | if (client->isServerLeader()) |
---|
| 903 | { |
---|
| 904 | CMessage msg ; |
---|
| 905 | msg<<this->getId() ; |
---|
| 906 | msg<<id ; |
---|
[595] | 907 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
| 908 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 909 | event.push(*itRank,1,msg); |
---|
[472] | 910 | client->sendEvent(event) ; |
---|
| 911 | } |
---|
| 912 | else client->sendEvent(event) ; |
---|
| 913 | } |
---|
[509] | 914 | |
---|
[472] | 915 | } |
---|
[509] | 916 | |
---|
| 917 | /*! |
---|
| 918 | \brief Receive a message annoucing the creation of a variable on server side |
---|
| 919 | \param[in] event Received event |
---|
| 920 | */ |
---|
[472] | 921 | void CFile::recvAddVariable(CEventServer& event) |
---|
| 922 | { |
---|
[509] | 923 | |
---|
[472] | 924 | CBufferIn* buffer=event.subEvents.begin()->buffer; |
---|
| 925 | string id; |
---|
| 926 | *buffer>>id ; |
---|
| 927 | get(id)->recvAddVariable(*buffer) ; |
---|
| 928 | } |
---|
[509] | 929 | |
---|
| 930 | /*! |
---|
| 931 | \brief Receive a message annoucing the creation of a variable on server side |
---|
| 932 | \param[in] buffer Buffer containing message |
---|
| 933 | */ |
---|
[472] | 934 | void CFile::recvAddVariable(CBufferIn& buffer) |
---|
| 935 | { |
---|
| 936 | string id ; |
---|
| 937 | buffer>>id ; |
---|
| 938 | addVariable(id) ; |
---|
| 939 | } |
---|
| 940 | |
---|
[509] | 941 | /*! |
---|
| 942 | \brief Receive a message annoucing the creation of a variable group on server side |
---|
| 943 | \param[in] event Received event |
---|
| 944 | */ |
---|
[472] | 945 | void CFile::recvAddVariableGroup(CEventServer& event) |
---|
| 946 | { |
---|
[509] | 947 | |
---|
[472] | 948 | CBufferIn* buffer=event.subEvents.begin()->buffer; |
---|
| 949 | string id; |
---|
| 950 | *buffer>>id ; |
---|
| 951 | get(id)->recvAddVariableGroup(*buffer) ; |
---|
| 952 | } |
---|
[509] | 953 | |
---|
| 954 | /*! |
---|
| 955 | \brief Receive a message annoucing the creation of a variable group on server side |
---|
| 956 | \param[in] buffer Buffer containing message |
---|
| 957 | */ |
---|
[472] | 958 | void CFile::recvAddVariableGroup(CBufferIn& buffer) |
---|
| 959 | { |
---|
| 960 | string id ; |
---|
| 961 | buffer>>id ; |
---|
| 962 | addVariableGroup(id) ; |
---|
| 963 | } |
---|
| 964 | |
---|
[509] | 965 | /*! |
---|
| 966 | \brief Sending all active (enabled) fields from client to server. |
---|
| 967 | Each field is identified uniquely by its string identity. Not only should we |
---|
| 968 | send the id to server but also we need to send ids of reference domain and reference axis. |
---|
| 969 | With these two id, it's easier to make reference to grid where all data should be written. |
---|
| 970 | Remark: This function must be called AFTER all active (enabled) files have been created on the server side |
---|
| 971 | */ |
---|
| 972 | void CFile::sendEnabledFields() |
---|
| 973 | { |
---|
| 974 | int size = this->enabledFields.size(); |
---|
| 975 | CField* fieldPtr(0); |
---|
| 976 | for (int i = 0; i < size; ++i) |
---|
| 977 | { |
---|
| 978 | fieldPtr = this->enabledFields[i]; |
---|
| 979 | if (fieldPtr->name.isEmpty()) fieldPtr->name.setValue(fieldPtr->getBaseFieldReference()->getId()); |
---|
| 980 | this->sendAddField(fieldPtr->getId()); |
---|
| 981 | fieldPtr->sendAllAttributesToServer(); |
---|
| 982 | fieldPtr->sendAddAllVariables(); |
---|
| 983 | } |
---|
| 984 | } |
---|
[472] | 985 | |
---|
[509] | 986 | /*! |
---|
| 987 | \brief Dispatch event received from client |
---|
| 988 | Whenever a message is received in buffer of server, it will be processed depending on |
---|
| 989 | its event type. A new event type should be added in the switch list to make sure |
---|
| 990 | it processed on server side. |
---|
| 991 | \param [in] event: Received message |
---|
| 992 | */ |
---|
[300] | 993 | bool CFile::dispatchEvent(CEventServer& event) |
---|
| 994 | { |
---|
| 995 | if (SuperClass::dispatchEvent(event)) return true ; |
---|
| 996 | else |
---|
| 997 | { |
---|
| 998 | switch(event.type) |
---|
| 999 | { |
---|
| 1000 | case EVENT_ID_ADD_FIELD : |
---|
| 1001 | recvAddField(event) ; |
---|
| 1002 | return true ; |
---|
| 1003 | break ; |
---|
[509] | 1004 | |
---|
[300] | 1005 | case EVENT_ID_ADD_FIELD_GROUP : |
---|
| 1006 | recvAddFieldGroup(event) ; |
---|
| 1007 | return true ; |
---|
[509] | 1008 | break ; |
---|
| 1009 | |
---|
[472] | 1010 | case EVENT_ID_ADD_VARIABLE : |
---|
| 1011 | recvAddVariable(event) ; |
---|
| 1012 | return true ; |
---|
| 1013 | break ; |
---|
[509] | 1014 | |
---|
[472] | 1015 | case EVENT_ID_ADD_VARIABLE_GROUP : |
---|
| 1016 | recvAddVariableGroup(event) ; |
---|
| 1017 | return true ; |
---|
[509] | 1018 | break ; |
---|
[300] | 1019 | default : |
---|
| 1020 | ERROR("bool CFile::dispatchEvent(CEventServer& event)", <<"Unknown Event") ; |
---|
| 1021 | return false ; |
---|
| 1022 | } |
---|
| 1023 | } |
---|
| 1024 | } |
---|
[509] | 1025 | |
---|
| 1026 | |
---|
| 1027 | |
---|
| 1028 | |
---|
[219] | 1029 | ///--------------------------------------------------------------- |
---|
| 1030 | |
---|
[335] | 1031 | } // namespace xios |
---|