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

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

Corrections après tests sur titane

File size: 5.5 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            if (!CObjectFactory::GetObject<CContext>
86                (CObjectFactory::GetCurrentContextId())->output_dir.isEmpty())
87                oss << CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId())->output_dir.getValue();
88            oss << filename;
89            if (!file->name_suffix.isEmpty())
90                oss << file->name_suffix.getValue();
91            if (comm::CMPIManager::GetCommSize() > 1)
92                oss << "_node" << comm::CMPIManager::GetCommRank();
93            oss << ".nc";
94            boost::shared_ptr<io::CDataOutput> dout(new T(oss.str(), false));
95            file->initializeDataOutput(dout);
96         }
97      }
98
99      template <StdSize N>
100         void CDataTreatment::write_data
101            (const StdString & fieldId, const ARRAY(float, N) & data)
102      {
103         typedef typename boost::multi_array<double, N>::size_type sizetp;
104         std::vector<sizetp> shape;
105         const sizetp * shapearr = data->shape();
106
107         shape.assign(shapearr, shapearr + N);
108         ARRAY(double, N) datad(new CArray<double, N>(shape));
109         for (StdSize i = 0; i < datad->num_elements(); i++)
110          datad->data()[i] = data->data()[i];
111
112         this->write_data(fieldId, datad);
113      }
114
115      template <StdSize N>
116         void CDataTreatment::write_data
117            (const StdString & fieldId, const ARRAY(double, N) & data)
118      {
119         const date::CDate & currDate =
120                this->currentContext->getCalendar()->getCurrentDate();
121         const date::CDuration & timestep = 
122               this->currentContext->getCalendar()->getTimeStep();
123         const std::vector<boost::shared_ptr<CField> > & refField=
124               CObjectFactory::GetObject<CField>(fieldId)->getAllReference();
125         std::vector<boost::shared_ptr<CField> >::const_iterator
126               it = refField.begin(), end = refField.end();
127//       std::cout << "nb :" << refField.size() << std::endl;
128         for (; it != end; it++)
129         {
130            boost::shared_ptr<CField> field = *it;
131            boost::shared_ptr<CFile>  file  = field->getRelFile();
132//            std::cout << ">> " << fieldId << ", " << file->getId() << std::endl;
133            if (field->updateData(currDate, timestep, data))
134            {
135               if (CXIOSManager::GetStatus() == CXIOSManager::LOC_CLIENT)
136               { 
137                   boost::shared_ptr<comm::CClient> client = comm::CClient::GetClient();
138                   client->sendData(fieldId, file->getId(), field->getData());
139               }
140               else
141               {
142                  file->getDataOutput()->writeFieldData(field);
143               }
144            }
145         }
146
147      }
148
149   } // namespace data
150
151} // namespace xmlioserver
152
153#endif // __XMLIO_CDataTreatment__
Note: See TracBrowser for help on using the repository browser.