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