1 | #ifndef __XIOS_CField__ |
---|
2 | #define __XIOS_CField__ |
---|
3 | |
---|
4 | /// XIOS headers /// |
---|
5 | #include "xios_spl.hpp" |
---|
6 | #include "group_factory.hpp" |
---|
7 | #include "functor.hpp" |
---|
8 | #include "functor_type.hpp" |
---|
9 | #include "duration.hpp" |
---|
10 | #include "date.hpp" |
---|
11 | #include "declare_group.hpp" |
---|
12 | #include "calendar_util.hpp" |
---|
13 | #include "array_new.hpp" |
---|
14 | #include "attribute_array.hpp" |
---|
15 | #include "expr_node.hpp" |
---|
16 | #include "declare_ref_func.hpp" |
---|
17 | |
---|
18 | |
---|
19 | namespace xios { |
---|
20 | |
---|
21 | /// ////////////////////// Déclarations ////////////////////// /// |
---|
22 | |
---|
23 | class CFieldGroup; |
---|
24 | class CFieldAttributes; |
---|
25 | class CField; |
---|
26 | |
---|
27 | class CFile; |
---|
28 | class CGrid; |
---|
29 | class CContext ; |
---|
30 | ///-------------------------------------------------------------- |
---|
31 | |
---|
32 | // Declare/Define CFieldAttribute |
---|
33 | BEGIN_DECLARE_ATTRIBUTE_MAP(CField) |
---|
34 | # include "field_attribute.conf" |
---|
35 | END_DECLARE_ATTRIBUTE_MAP(CField) |
---|
36 | |
---|
37 | ///-------------------------------------------------------------- |
---|
38 | class CField |
---|
39 | : public CObjectTemplate<CField> |
---|
40 | , public CFieldAttributes |
---|
41 | { |
---|
42 | /// friend /// |
---|
43 | friend class CFile; |
---|
44 | |
---|
45 | /// typedef /// |
---|
46 | typedef CObjectTemplate<CField> SuperClass; |
---|
47 | typedef CFieldAttributes SuperClassAttribute; |
---|
48 | |
---|
49 | public : |
---|
50 | |
---|
51 | typedef CFieldAttributes RelAttributes; |
---|
52 | typedef CFieldGroup RelGroup; |
---|
53 | |
---|
54 | enum EEventId |
---|
55 | { |
---|
56 | EVENT_ID_UPDATE_DATA, EVENT_ID_READ_DATA, EVENT_ID_READ_DATA_READY, |
---|
57 | EVENT_ID_ADD_VARIABLE, EVENT_ID_ADD_VARIABLE_GROUP |
---|
58 | } ; |
---|
59 | |
---|
60 | /// Constructeurs /// |
---|
61 | CField(void); |
---|
62 | explicit CField(const StdString & id); |
---|
63 | CField(const CField & field); // Not implemented yet. |
---|
64 | CField(const CField * const field); // Not implemented yet. |
---|
65 | |
---|
66 | /// Accesseurs /// |
---|
67 | |
---|
68 | CGrid* getRelGrid(void) const ; |
---|
69 | CFile* getRelFile(void) const ; |
---|
70 | |
---|
71 | public : |
---|
72 | |
---|
73 | StdSize getNStep(void) const; |
---|
74 | |
---|
75 | const CDuration & getFreqOperation(void) const; |
---|
76 | const CDuration & getFreqWrite(void) const; |
---|
77 | |
---|
78 | boost::shared_ptr<CDate> getLastWriteDate(void) const; |
---|
79 | boost::shared_ptr<CDate> getLastOperationDate(void) const; |
---|
80 | |
---|
81 | boost::shared_ptr<func::CFunctor> getFieldOperation(void) const; |
---|
82 | |
---|
83 | CArray<double, 1> getData(void) const; |
---|
84 | template <int N> void getData(CArray<double, N>& _data) const; |
---|
85 | |
---|
86 | |
---|
87 | /// Mutateur /// |
---|
88 | void setRelFile(CFile* _file); |
---|
89 | void incrementNStep(void); |
---|
90 | void resetNStep() ; |
---|
91 | |
---|
92 | template <int N> bool updateData(const CArray<double, N>& data); |
---|
93 | bool updateDataFromExpression(const CArray<double, 1>& data); |
---|
94 | void setDataFromExpression(const CArray<double, 1>& _data) ; |
---|
95 | |
---|
96 | bool updateDataServer |
---|
97 | (const CDate & currDate, |
---|
98 | const std::deque< CArray<double, 1>* > storedClient); |
---|
99 | |
---|
100 | std::map<int, StdSize> getGridDataSize(); |
---|
101 | |
---|
102 | public : |
---|
103 | bool isActive(void) const; |
---|
104 | bool active ; |
---|
105 | bool hasOutputFile ; |
---|
106 | bool hasFieldOut ; |
---|
107 | |
---|
108 | /// Traitements /// |
---|
109 | void processEnabledField(void) ; |
---|
110 | |
---|
111 | void solveGridReference(void); |
---|
112 | void solveOperation(void); |
---|
113 | void solveCheckMaskIndex(bool doSendingIndex); |
---|
114 | void solveAllReferenceEnabledField(bool doSending2Sever); |
---|
115 | void buildAllExpressionEnabledField(); |
---|
116 | void solveGridDomainAxisRef(bool checkAtt); |
---|
117 | |
---|
118 | |
---|
119 | // virtual void fromBinary(StdIStream & is); |
---|
120 | |
---|
121 | /// Destructeur /// |
---|
122 | virtual ~CField(void); |
---|
123 | |
---|
124 | /// Accesseurs statiques /// |
---|
125 | static StdString GetName(void); |
---|
126 | static StdString GetDefName(void); |
---|
127 | |
---|
128 | static ENodeType GetType(void); |
---|
129 | |
---|
130 | template <int N> void setData(const CArray<double, N>& _data) ; |
---|
131 | static bool dispatchEvent(CEventServer& event) ; |
---|
132 | void sendUpdateData(void) ; |
---|
133 | static void recvUpdateData(CEventServer& event) ; |
---|
134 | void recvUpdateData(vector<int>& ranks, vector<CBufferIn*>& buffers) ; |
---|
135 | void writeField(void) ; |
---|
136 | void sendReadDataRequest(void); |
---|
137 | bool sendReadDataRequestIfNeeded(void); |
---|
138 | static void recvReadDataRequest(CEventServer& event); |
---|
139 | void recvReadDataRequest(void); |
---|
140 | static void recvReadDataReady(CEventServer& event); |
---|
141 | void recvReadDataReady(vector<int> ranks, vector<CBufferIn*> buffers); |
---|
142 | void outputField(CArray<double,3>& fieldOut) ; |
---|
143 | void outputField(CArray<double,2>& fieldOut) ; |
---|
144 | void outputField(CArray<double,1>& fieldOut) ; |
---|
145 | void scaleFactorAddOffset(double scaleFactor, double addOffset) ; |
---|
146 | void parse(xml::CXMLNode & node) ; |
---|
147 | CArray<double,1>* getInstantData(void) ; |
---|
148 | |
---|
149 | void setVirtualVariableGroup(CVariableGroup* newVVariableGroup); |
---|
150 | void setVirtualVariableGroup(void); |
---|
151 | CVariableGroup* getVirtualVariableGroup(void) const; |
---|
152 | vector<CVariable*> getAllVariables(void) const; |
---|
153 | virtual void solveDescInheritance(bool apply, const CAttributeMap * const parent = 0); |
---|
154 | |
---|
155 | CVariable* addVariable(const string& id="") ; |
---|
156 | CVariableGroup* addVariableGroup(const string& id="") ; |
---|
157 | void sendAddVariable(const string& id="") ; |
---|
158 | void sendAddVariableGroup(const string& id="") ; |
---|
159 | static void recvAddVariable(CEventServer& event) ; |
---|
160 | void recvAddVariable(CBufferIn& buffer) ; |
---|
161 | static void recvAddVariableGroup(CEventServer& event) ; |
---|
162 | void recvAddVariableGroup(CBufferIn& buffer) ; |
---|
163 | void sendAddAllVariables(); |
---|
164 | |
---|
165 | |
---|
166 | const std::pair<StdString, StdString>& getRefDomainAxisIds(); |
---|
167 | public : |
---|
168 | /// Propriétés privées /// |
---|
169 | CVariableGroup* vVariableGroup ; |
---|
170 | |
---|
171 | CGrid* grid ; |
---|
172 | CFile* file; |
---|
173 | CField* fieldOut ; |
---|
174 | |
---|
175 | CDuration freq_operation, freq_write; |
---|
176 | CDuration freq_operation_srv, freq_write_srv; |
---|
177 | |
---|
178 | StdSize nstep; |
---|
179 | boost::shared_ptr<CDate> last_Write, last_operation; |
---|
180 | boost::shared_ptr<CDate> lastlast_Write_srv,last_Write_srv, last_operation_srv; |
---|
181 | CDate lastDataRequestedFromServer; |
---|
182 | |
---|
183 | boost::shared_ptr<func::CFunctor> foperation; |
---|
184 | map<int,boost::shared_ptr<func::CFunctor> > foperation_srv; |
---|
185 | |
---|
186 | CArray<double, 1> data; |
---|
187 | CArray<double, 1> instantData; |
---|
188 | bool hasInstantData ; |
---|
189 | map<int, CArray<double,1>* > data_srv ; |
---|
190 | bool isOnceOperation ; |
---|
191 | bool isFirstOperation ; |
---|
192 | string content ; |
---|
193 | |
---|
194 | list< pair<CField *,int> > fieldDependency ; |
---|
195 | void buildExpression(void) ; |
---|
196 | void addDependency(CField* field, int slotId) ; |
---|
197 | void resetSlots(void) ; |
---|
198 | vector<bool> slots ; |
---|
199 | CDate* slotUpdateDate ; |
---|
200 | CFieldNode * expression ; |
---|
201 | bool hasExpression ; |
---|
202 | bool slotsFull(void) ; |
---|
203 | void setSlot(int slotId); |
---|
204 | bool processed ; |
---|
205 | bool areAllReferenceSolved; |
---|
206 | bool areAllExpressionBuilt; |
---|
207 | std::pair<StdString,StdString> domAxisIds_; |
---|
208 | bool isReadDataRequestPending; |
---|
209 | DECLARE_REF_FUNC(Field,field) |
---|
210 | // public: |
---|
211 | // bool hasDirectFieldReference(void) const; |
---|
212 | // CField* getDirectFieldReference(void) const; |
---|
213 | // CField* getBaseFieldReference(void) const; |
---|
214 | // void addReference(CField* field); |
---|
215 | // const std::vector<CField*> & getAllReference(void) const; |
---|
216 | //void solveRefInheritance(bool apply); |
---|
217 | //void solveBaseReference(void); |
---|
218 | // void removeRefInheritance(); |
---|
219 | // const StdString & getBaseFieldId(void) const; |
---|
220 | // |
---|
221 | // std::vector<CField*> refObject; |
---|
222 | // CField* baseRefObject; |
---|
223 | |
---|
224 | |
---|
225 | }; // class CField |
---|
226 | |
---|
227 | ///-------------------------------------------------------------- |
---|
228 | |
---|
229 | // Declare/Define CFieldGroup and CFieldDefinition |
---|
230 | DECLARE_GROUP(CField); |
---|
231 | |
---|
232 | ///----------------------------------------------------------------- |
---|
233 | |
---|
234 | template <> |
---|
235 | void CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void); |
---|
236 | |
---|
237 | ///----------------------------------------------------------------- |
---|
238 | } // namespace xios |
---|
239 | |
---|
240 | |
---|
241 | #endif // __XIOS_CField__ |
---|