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 | |
---|
13 | namespace 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 | typedef typename boost::multi_array<double, N>::size_type sizetp; |
---|
96 | std::vector<sizetp> shape; |
---|
97 | const sizetp * shapearr = data->shape(); |
---|
98 | |
---|
99 | shape.assign(shapearr, shapearr + N); |
---|
100 | ARRAY_CREATE(datad, double, N, [shape]); |
---|
101 | datad->assign(data->begin(), data->end()); |
---|
102 | |
---|
103 | this->write_data(fieldId, datad); |
---|
104 | } |
---|
105 | |
---|
106 | template <StdSize N> |
---|
107 | void CDataTreatment::write_data |
---|
108 | (const StdString & fieldId, const ARRAY(double, N) & data) |
---|
109 | { |
---|
110 | const date::CDate & currDate = |
---|
111 | this->currentContext->getCalendar()->getCurrentDate(); |
---|
112 | const std::vector<boost::shared_ptr<CField> > & refField= |
---|
113 | CObjectFactory::GetObject<CField>(fieldId)->getAllReference(); |
---|
114 | std::vector<boost::shared_ptr<CField> >::const_iterator |
---|
115 | it = refField.begin(), end = refField.end(); |
---|
116 | |
---|
117 | for (; it != end; it++) |
---|
118 | { |
---|
119 | boost::shared_ptr<CField> field = *it; |
---|
120 | boost::shared_ptr<CFile> file = field->getRelFile(); |
---|
121 | if (field->updateData(currDate, data)) |
---|
122 | { |
---|
123 | if (CXIOSManager::GetStatus() == CXIOSManager::LOC_CLIENT) |
---|
124 | { |
---|
125 | boost::shared_ptr<comm::CClient> client = comm::CClient::GetClient(); |
---|
126 | client->sendData(fieldId, file->getId(), field->getData()); |
---|
127 | } |
---|
128 | else |
---|
129 | { |
---|
130 | file->getDataOutput()->writeFieldData(field); |
---|
131 | } |
---|
132 | } |
---|
133 | return; |
---|
134 | } |
---|
135 | |
---|
136 | } |
---|
137 | |
---|
138 | } // namespace data |
---|
139 | |
---|
140 | } // namespace xmlioserver |
---|
141 | |
---|
142 | #endif // __XMLIO_CDataTreatment__ |
---|