source: XMLIO_V2/dev/common/src/xmlio/data_treatment.hpp @ 219

Last change on this file since 219 was 219, checked in by hozdoba, 13 years ago

Préparation nouvelle arborescence

File size: 4.8 KB
Line 
1#ifndef __XMLIO_CDataTreatment__
2#define __XMLIO_CDataTreatment__
3
4/// xmlioserver headers ///
5#include "xmlioserver_spl.hpp"
6#include "node_type.hpp"
7#include "mpi_manager.hpp"
8#include "data_output.hpp"
9#include "duration.hpp"
10#include "client.hpp"
11#include "xios_manager.hpp"
12
13namespace xmlioserver
14{
15   namespace data
16   {
17      /// ////////////////////// Déclarations ////////////////////// ///
18      class CDataTreatment
19      {
20         public :
21
22            /// Construteurs ///
23            CDataTreatment
24               (boost::shared_ptr<CContext> _ctxt =
25                  CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId()));
26
27            CDataTreatment(const CDataTreatment & data_treatment);       // Not implemented yet.
28            CDataTreatment(const CDataTreatment * const data_treatment); // Not implemented yet.
29
30            /// Accesseurs ///
31            const boost::shared_ptr<CContext> getCurrentContext(void) const;
32            const std::vector<boost::shared_ptr<CFile> > & getEnabledFiles  (void) const;
33
34            /// Ecriture et mise à jour du calendrier ///
35            void write_data(const StdString & fieldId,
36                            const StdString & fileId,
37                            const std::deque<ARRAY(double, 1)> & data);
38
39            template <StdSize N>
40               void write_data(const StdString & fieldId, const ARRAY(double, N) & data);
41
42            template <StdSize N>
43               void write_data(const StdString & fieldId, const ARRAY(float, N) & data);
44
45            void update_calendar(int step);
46            void set_timestep(const date::CDuration & duration);
47
48            /// Création des sorties ///
49            template <class T> void createDataOutput(void);
50
51            /// Destructeur ///
52            ~CDataTreatment(void);
53
54         private :
55
56            /// Traitements ///
57            void doTreatment(void);
58
59            void findAllEnabledFields(void);
60            void solveAllGridRef(void);
61            void solveAllOperation(void);
62            void solveAllInheritance(void) const;
63            void findEnabledFiles(void);
64
65            /// Propriétés privées ///
66            boost::shared_ptr<CContext> currentContext;
67            std::vector<boost::shared_ptr<CFile> > enabledFiles;
68
69      }; // CDataTreatment
70
71      //----------------------------------------------------------------
72
73      template <class T>
74         void CDataTreatment::createDataOutput(void)
75      {
76         std::vector<boost::shared_ptr<CFile> >::const_iterator
77            it = this->enabledFiles.begin(), end = this->enabledFiles.end();
78         
79         for (; it != end; it++)
80         {
81            boost::shared_ptr<CFile> file = *it;
82            StdString filename = (!file->name.isEmpty())
83                               ? file->name.getValue() : file->getId();
84            StdOStringStream oss;
85            oss << "wk/data/" << filename << "_node" << comm::CMPIManager::GetCommRank() << ".nc";
86            boost::shared_ptr<io::CDataOutput> dout(new T(oss.str(), false));
87            file->initializeDataOutput(dout);
88         }
89      }
90
91      template <StdSize N>
92         void CDataTreatment::write_data
93            (const StdString & fieldId, const ARRAY(float, N) & data)
94      {
95         std::vector<boost::multi_array<double, N>::size_type shape() > shape;
96         const size_type *      shapearr = data->shape();
97
98         shape.assign(shapearr, shapearr + N);
99         ARRAY_CREATE(datad, double, N, shape);
100         datad->assign(data->begin(), data->end());
101
102         this->write_data(fieldId, datad);
103      }
104
105      template <StdSize N>
106         void CDataTreatment::write_data
107            (const StdString & fieldId, const ARRAY(double, N) & data)
108      {
109         const date::CDate & currDate =
110                this->currentContext->getCalendar()->getCurrentDate();
111         const std::vector<boost::shared_ptr<CField> > & refField=
112               CObjectFactory::GetObject<CField>(fieldId)->getAllReference();
113         std::vector<boost::shared_ptr<CField> >::const_iterator
114               it = refField.begin(), end = refField.end();
115
116         for (; it != end; it++)
117         {
118            boost::shared_ptr<CField> field = *it;
119            boost::shared_ptr<CFile>  file  = field->getRelFile();
120            if (field->updateData(currDate, data))
121            {
122               if (CXIOSManager::GetStatus() == CXIOSManager::LOC_CLIENT)
123               { 
124                   boost::shared_ptr<comm::CClient> client = comm::CClient::GetClient();
125                   client.sendData(fieldId, file->getId(), field->getData());
126               }
127               else
128               {
129                  file->getDataOutput()->writeFieldData(field);
130               }
131            }
132            return;
133         }
134
135      }
136
137   } // namespace data
138
139} // namespace xmlioserver
140
141#endif // __XMLIO_CDataTreatment__
Note: See TracBrowser for help on using the repository browser.