[152] | 1 | #include "data_treatment.hpp" |
---|
| 2 | |
---|
| 3 | #include "attribute_template_impl.hpp" |
---|
| 4 | #include "object_template_impl.hpp" |
---|
| 5 | #include "group_template_impl.hpp" |
---|
| 6 | #include "object_factory_impl.hpp" |
---|
| 7 | |
---|
[214] | 8 | |
---|
[152] | 9 | namespace xmlioserver |
---|
| 10 | { |
---|
| 11 | namespace data |
---|
| 12 | { |
---|
| 13 | /// ////////////////////// Définitions ////////////////////// /// |
---|
| 14 | CDataTreatment::CDataTreatment (boost::shared_ptr<CContext> _ctxt) |
---|
| 15 | : currentContext(_ctxt), enabledFiles() |
---|
| 16 | { this->doTreatment(); } |
---|
| 17 | |
---|
| 18 | CDataTreatment::~CDataTreatment(void) |
---|
| 19 | { /* Ne rien faire de plus */ } |
---|
| 20 | |
---|
| 21 | ///--------------------------------------------------------------- |
---|
| 22 | |
---|
| 23 | const boost::shared_ptr<CContext> |
---|
| 24 | CDataTreatment::getCurrentContext(void) const |
---|
| 25 | { |
---|
| 26 | return (this->currentContext); |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | const std::vector<boost::shared_ptr<CFile> > & |
---|
| 30 | CDataTreatment::getEnabledFiles (void) const |
---|
| 31 | { |
---|
| 32 | return (this->enabledFiles); |
---|
| 33 | } |
---|
[214] | 34 | //---------------------------------------------------------------- |
---|
[152] | 35 | |
---|
[214] | 36 | void CDataTreatment::update_calendar(int step) |
---|
| 37 | { |
---|
| 38 | // Mise à jour cÎté client |
---|
| 39 | this->currentContext->getCalendar()->update(step); |
---|
| 40 | if (CXIOSManager::GetStatus() == CXIOSManager::LOC_CLIENT) |
---|
| 41 | { // Mise à jour cÎté serveur |
---|
| 42 | boost::shared_ptr<comm::CClient> client = comm::CClient::GetClient(); |
---|
| 43 | client->updateCalendar(step); |
---|
| 44 | } |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | void CDataTreatment::set_timestep(const date::CDuration & duration) |
---|
| 48 | { |
---|
| 49 | // Mise à jour cÎté client |
---|
| 50 | this->currentContext->getCalendar()->setTimeStep(duration); |
---|
| 51 | if (CXIOSManager::GetStatus() == CXIOSManager::LOC_CLIENT) |
---|
| 52 | { // Mise à jour cÎté serveur |
---|
| 53 | boost::shared_ptr<comm::CClient> client = comm::CClient::GetClient(); |
---|
| 54 | client->setTimestep(duration); |
---|
| 55 | } |
---|
| 56 | } |
---|
| 57 | |
---|
[152] | 58 | //---------------------------------------------------------------- |
---|
[214] | 59 | |
---|
| 60 | void CDataTreatment::write_data |
---|
| 61 | (const StdString & fieldId, |
---|
| 62 | const StdString & fileId, |
---|
| 63 | const std::deque<ARRAY(double, 1)> & data) |
---|
| 64 | { |
---|
| 65 | const date::CDate & currDate = |
---|
| 66 | this->currentContext->getCalendar()->getCurrentDate(); |
---|
| 67 | const std::vector<boost::shared_ptr<CField> > & refField= |
---|
| 68 | CObjectFactory::GetObject<CField>(fieldId)->getAllReference(); |
---|
| 69 | std::vector<boost::shared_ptr<CField> >::const_iterator |
---|
| 70 | it = refField.begin(), end = refField.end(); |
---|
[152] | 71 | |
---|
[214] | 72 | for (; it != end; it++) |
---|
| 73 | { |
---|
| 74 | boost::shared_ptr<CField> field = *it; |
---|
| 75 | boost::shared_ptr<CFile> file = field->getRelFile(); |
---|
| 76 | if (file->getId().compare(fileId) == 0) |
---|
| 77 | { |
---|
| 78 | if (field->updateDataServer(currDate, data)) |
---|
| 79 | file->getDataOutput()->writeFieldData(field); |
---|
| 80 | return; |
---|
| 81 | } |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | //---------------------------------------------------------------- |
---|
| 87 | |
---|
[152] | 88 | void CDataTreatment::doTreatment(void) |
---|
[188] | 89 | { |
---|
| 90 | // Résolution du calendrier |
---|
| 91 | this->currentContext->solveCalendar(); |
---|
| 92 | |
---|
[152] | 93 | // Résolution des héritages pour le context actuel. |
---|
| 94 | //std::cout << "(Message temporaire) Résolution des héritages ..." << std::endl; |
---|
| 95 | this->solveAllInheritance(); |
---|
| 96 | |
---|
| 97 | //Initialisation du vecteur 'enabledFiles' contenant la liste des fichiers à sortir. |
---|
| 98 | //std::cout << "(Message temporaire) Initialisation du vecteur enabledFiles ..." << std::endl; |
---|
| 99 | this->findEnabledFiles(); |
---|
| 100 | |
---|
| 101 | //Recherche des champs à sortir (enable à true + niveau de sortie correct) |
---|
| 102 | // pour chaque fichier précédemment listé. |
---|
| 103 | //std::cout << "(Message temporaire) Recherche des champs à sortir ..." << std::endl; |
---|
| 104 | this->findAllEnabledFields(); |
---|
| 105 | |
---|
| 106 | // Résolution des références de grilles pour chacun des champs. |
---|
| 107 | //std::cout << "(Message temporaire) Résolution des références de grilles ..." << std::endl; |
---|
| 108 | this->solveAllGridRef(); |
---|
| 109 | |
---|
| 110 | // Traitement des opérations. |
---|
| 111 | this->solveAllOperation(); |
---|
| 112 | |
---|
[206] | 113 | // Nettoyage de l'arborescence |
---|
| 114 | CContext::CleanTree(); |
---|
| 115 | |
---|
[152] | 116 | //std::cout << "(Message temporaire) fin traitement sorties ..." << std::endl; |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | void CDataTreatment::findAllEnabledFields(void) |
---|
| 120 | { |
---|
| 121 | for (unsigned int i = 0; i < this->enabledFiles.size(); i++) |
---|
| 122 | (void)this->enabledFiles[i]->getEnabledFields(); |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | void CDataTreatment::solveAllGridRef(void) |
---|
| 126 | { |
---|
| 127 | for (unsigned int i = 0; i < this->enabledFiles.size(); i++) |
---|
| 128 | this->enabledFiles[i]->solveEFGridRef(); |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | void CDataTreatment::solveAllOperation(void) |
---|
| 132 | { |
---|
| 133 | for (unsigned int i = 0; i < this->enabledFiles.size(); i++) |
---|
| 134 | this->enabledFiles[i]->solveEFOperation(); |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | void CDataTreatment::solveAllInheritance(void) const |
---|
| 138 | { |
---|
| 139 | // Résolution des héritages descendants (cà d des héritages de groupes) |
---|
| 140 | // pour chacun des contextes. |
---|
| 141 | this->currentContext->solveDescInheritance(); |
---|
| 142 | |
---|
| 143 | // Résolution des héritages par référence au niveau des fichiers. |
---|
| 144 | const std::vector<boost::shared_ptr<CFile> > & allFiles |
---|
| 145 | = CObjectFactory::GetObjectVector<CFile>(); |
---|
| 146 | |
---|
| 147 | for (unsigned int i = 0; i < allFiles.size(); i++) |
---|
| 148 | allFiles[i]->solveFieldRefInheritance(); |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | void CDataTreatment::findEnabledFiles(void) |
---|
| 152 | { |
---|
| 153 | const std::vector<boost::shared_ptr<CFile> > & allFiles |
---|
| 154 | = CObjectFactory::GetObjectVector<CFile>(); |
---|
| 155 | |
---|
| 156 | for (unsigned int i = 0; i < allFiles.size(); i++) |
---|
| 157 | if (!allFiles[i]->enabled.isEmpty()) // Si l'attribut 'enabled' est défini. |
---|
| 158 | if (allFiles[i]->enabled.getValue()) // Si l'attribut 'enabled' est fixé à vrai. |
---|
| 159 | enabledFiles.push_back(allFiles[i]); |
---|
| 160 | |
---|
| 161 | if (enabledFiles.size() == 0) |
---|
| 162 | DEBUG(<<"Aucun fichier ne va être sorti dans le contexte nommé \"" |
---|
| 163 | << this->currentContext->getId() << "\" !"); |
---|
| 164 | } |
---|
| 165 | |
---|
| 166 | ///--------------------------------------------------------------- |
---|
| 167 | |
---|
| 168 | } // namespace data |
---|
| 169 | } // namespace xmlioserver |
---|