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