source: XIOS/dev/dev_trunk_omp/src/node/field.hpp @ 1669

Last change on this file since 1669 was 1669, checked in by yushan, 5 years ago

MARK: branch merged with trunk @1663. static graph OK with EP

  • Property copyright set to
    Software name : XIOS (Xml I/O Server)
    http://forge.ipsl.jussieu.fr/ioserver
    Creation date : January 2009
    Licence : CeCCIL version2
    see license file in root directory : Licence_CeCILL_V2-en.txt
    or http://www.cecill.info/licences/Licence_CeCILL_V2-en.html
    Holder : CEA/LSCE (Laboratoire des Sciences du CLimat et de l'Environnement)
    CNRS/IPSL (Institut Pierre Simon Laplace)
    Project Manager : Yann Meurdesoif
    yann.meurdesoif@cea.fr
  • Property svn:executable set to *
File size: 10.5 KB
Line 
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 "filter.hpp"
10#include "duration.hpp"
11#include "date.hpp"
12#include "declare_group.hpp"
13#include "calendar_util.hpp"
14#include "array_new.hpp"
15#include "attribute_array.hpp"
16#include "declare_ref_func.hpp"
17#include "transformation_enum.hpp"
18#include "variable.hpp"
19#include "context_client.hpp"
20
21
22namespace xios {
23
24   /// ////////////////////// Déclarations ////////////////////// ///
25
26   class CFieldGroup;
27   class CFieldAttributes;
28   class CField;
29
30   class CFile;
31   class CGrid;
32   class CContext;
33   class CGenericFilter;
34
35   class CGarbageCollector;
36   class COutputPin;
37   class CSourceFilter;
38   class CStoreFilter;
39   class CFileWriterFilter;
40   class CFileServerWriterFilter;
41
42   ///--------------------------------------------------------------
43
44   // Declare/Define CFieldAttribute
45   BEGIN_DECLARE_ATTRIBUTE_MAP(CField)
46#  include "field_attribute.conf"
47   END_DECLARE_ATTRIBUTE_MAP(CField)
48
49   ///--------------------------------------------------------------
50   class CField
51      : public CObjectTemplate<CField>
52      , public CFieldAttributes
53   {
54         /// friend ///
55         friend class CFile;
56
57         /// typedef ///
58         typedef CObjectTemplate<CField>   SuperClass;
59         typedef CFieldAttributes SuperClassAttribute;
60
61         enum EReadField
62         {
63           RF_NODATA, RF_EOF, RF_DATA
64         };
65         
66      public:
67
68         typedef CFieldAttributes RelAttributes;
69         typedef CFieldGroup      RelGroup;
70
71         enum EEventId
72         {
73           EVENT_ID_UPDATE_DATA, EVENT_ID_READ_DATA, EVENT_ID_READ_DATA_READY,
74           EVENT_ID_ADD_VARIABLE, EVENT_ID_ADD_VARIABLE_GROUP
75         };
76
77         /// Constructeurs ///
78         CField(void);
79         explicit CField(const StdString& id);
80         CField(const CField& field);       // Not implemented yet.
81         CField(const CField* const field); // Not implemented yet.
82
83         /// Accesseurs ///
84
85         CGrid* getRelGrid(void) const;
86         CFile* getRelFile(void) const;
87
88         func::CFunctor::ETimeType getOperationTimeType() const;
89
90      public:
91         const StdString& getOId(void);
92
93         int getNStep(void) const;
94
95         template <int N> void getData(CArray<double, N>& _data) const;
96
97         std::shared_ptr<COutputPin> getInstantDataFilter();
98
99         /// Mutateur ///
100         void setRelFile(CFile* _file);
101         void incrementNStep(void);
102         void resetNStep(int nstep = 0);
103         void resetNStepMax();
104
105         std::map<int, StdSize> getGridAttributesBufferSize(CContextClient* client, bool bufferForWriting = false);
106         // Grid data buffer size for each connection of contextclient
107         std::map<int, StdSize> getGridDataBufferSize(CContextClient* client, bool bufferForWriting = false);
108
109         void setContextClient(CContextClient* newContextClient);
110         CContextClient* getContextClient();
111
112       public:
113         bool isActive(bool atCurrentTimestep = false) const;
114         bool hasOutputFile;
115
116         bool wasWritten() const;
117         void setWritten();
118
119         bool getUseCompressedOutput() const;
120         void setUseCompressedOutput();
121
122         /// Traitements ///
123         void solveGridReference(void);
124         void solveServerOperation(void);
125         void solveCheckMaskIndex(bool doSendingIndex);
126         void solveAllReferenceEnabledField(bool doSending2Server);
127         void solveOnlyReferenceEnabledField(bool doSending2Server);
128         void generateNewTransformationGridDest();
129         void updateRef(CGrid* grid);
130         void buildGridTransformationGraph();
131         void solveGridDomainAxisRef(bool checkAtt);
132         void solveTransformedGrid();
133         void solveGenerateGrid();
134         void solveGridDomainAxisBaseRef();
135
136         void solveAllEnabledFieldsAndTransform();
137         void checkGridOfEnabledFields();
138         void sendGridOfEnabledFields();
139         void sendGridComponentOfEnabledFields();
140
141         /// Vérifications ///
142         void checkTimeAttributes(CDuration* freqOp=NULL);
143
144         void buildFilterGraph(CGarbageCollector& gc, bool enableOutput);
145         size_t getGlobalWrittenSize(void) ;
146         
147         
148         std::shared_ptr<COutputPin> getFieldReference(CGarbageCollector& gc);
149         std::shared_ptr<COutputPin> getSelfReference(CGarbageCollector& gc);
150         std::shared_ptr<COutputPin> getTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq);
151         std::shared_ptr<COutputPin> getSelfTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq);
152
153//         virtual void fromBinary(StdIStream& is);
154
155         /// Destructeur ///
156         virtual ~CField(void);
157
158         /// Accesseurs statiques ///
159         static StdString GetName(void);
160         static StdString GetDefName(void);
161
162         static ENodeType GetType(void);
163
164        template <int N> void setData(const CArray<double, N>& _data);
165        static bool dispatchEvent(CEventServer& event);
166        void sendAllAttributesToServer(CContextClient* client) ; 
167        void sendUpdateData(const CArray<double,1>& data);
168        void sendUpdateData(const CArray<double,1>& data, CContextClient* client);
169        static void recvUpdateData(CEventServer& event);
170        void recvUpdateData(std::map<int,CBufferIn*>& rankBuffers);
171        void writeField(void);
172        bool sendReadDataRequest(const CDate& tsDataRequested);
173        bool sendReadDataRequestIfNeeded(void);
174        static void recvReadDataRequest(CEventServer& event);
175        void recvReadDataRequest(void);
176        EReadField readField(void);
177        static void recvReadDataReady(CEventServer& event);
178        void recvReadDataReady(vector<int> ranks, vector<CBufferIn*> buffers);
179        void checkForLateDataFromServer(void);
180        void checkIfMustAutoTrigger(void);
181        void autoTriggerIfNeeded(void);
182        void outputField(CArray<double,3>& fieldOut);
183        void outputField(CArray<double,2>& fieldOut);
184        void outputField(CArray<double,1>& fieldOut);
185        void inputField(CArray<double,3>& fieldOut);
186        void inputField(CArray<double,2>& fieldOut);
187        void inputField(CArray<double,1>& fieldOut);
188        void outputCompressedField(CArray<double, 1>& fieldOut);
189        void scaleFactorAddOffset(double scaleFactor, double addOffset);
190        void invertScaleFactorAddOffset(double scaleFactor, double addOffset);
191        void parse(xml::CXMLNode& node);
192
193        void setVirtualVariableGroup(CVariableGroup* newVVariableGroup);
194        CVariableGroup* getVirtualVariableGroup(void) const;
195        vector<CVariable*> getAllVariables(void) const;
196        virtual void solveDescInheritance(bool apply, const CAttributeMap* const parent = 0);
197
198        CVariable* addVariable(const string& id = "");
199        CVariableGroup* addVariableGroup(const string& id = "");       
200        void sendAddVariable(const string& id, CContextClient* client);
201        void sendAddVariableGroup(const string& id, CContextClient* client);
202        static void recvAddVariable(CEventServer& event);
203        void recvAddVariable(CBufferIn& buffer);
204        static void recvAddVariableGroup(CEventServer& event);
205        void recvAddVariableGroup(CBufferIn& buffer);       
206        void sendAddAllVariables(CContextClient* client);
207        void writeUpdateData(const CArray<double,1>& data);
208
209        const std::vector<StdString>& getRefDomainAxisIds();
210
211        const string& getExpression(void);
212        bool hasExpression(void) const;
213
214        bool hasGridMask(void) const;
215
216      public:
217         /// Propriétés privées ///
218         CVariableGroup* vVariableGroup;
219
220         CGrid*  grid;
221         CFile*  file;
222
223         CDuration freq_operation_srv, freq_write_srv;
224
225         bool written; //<! Was the field written at least once
226         int nstep, nstepMax;
227         bool isEOF;
228         CDate lastlast_Write_srv, last_Write_srv, last_operation_srv;
229         CDate lastDataRequestedFromServer, lastDataReceivedFromServer, dateEOF;
230         bool wasDataRequestedFromServer, wasDataAlreadyReceivedFromServer;
231         bool mustAutoTrigger;
232
233         map<int,std::shared_ptr<func::CFunctor> > foperation_srv;
234
235         // map<int, CArray<double,1> > data_srv;
236         CArray<double,1> recvDataSrv;
237         
238         std::shared_ptr<func::CFunctor> recvFoperationSrv;
239         string content;
240
241         std::vector<StdString> domAxisScalarIds_;
242         bool useCompressedOutput;
243
244         // Two variables to identify the time_counter meta data written in file, which has no time_counter
245         bool hasTimeInstant;
246         bool hasTimeCentered;
247
248
249         DECLARE_REF_FUNC(Field,field)
250
251      private:
252         CContextClient* client;
253
254         bool areAllReferenceSolved;
255         bool isReferenceSolved;
256         bool isReferenceSolvedAndTransformed;
257         bool isGridChecked;
258         bool nstepMaxRead;
259
260      private:
261         //! The type of operation attached to the field
262         func::CFunctor::ETimeType operationTimeType;
263
264         //! The output pin of the filter providing the instant data for the field
265         std::shared_ptr<COutputPin> instantDataFilter;
266         //! The output pin of the filters providing the result of the field's temporal operation
267         std::map<CDuration, std::shared_ptr<COutputPin>, DurationFakeLessComparator> temporalDataFilters;
268         //! The output pin of the filter providing the instant data for self references
269         std::shared_ptr<COutputPin> selfReferenceFilter;
270         //! The source filter for data provided by the client
271         std::shared_ptr<CSourceFilter> clientSourceFilter;
272         //! The source filter for data provided by the server
273         std::shared_ptr<CSourceFilter> serverSourceFilter;
274         //! The terminal filter which stores the instant data
275         std::shared_ptr<CStoreFilter> storeFilter;
276         //! The terminal filter which writes the data to file
277         std::shared_ptr<CFileWriterFilter> fileWriterFilter;
278         //! The terminal filter which writes data to file
279         std::shared_ptr<CFileServerWriterFilter> fileServerWriterFilter;
280   }; // class CField
281
282   ///--------------------------------------------------------------
283
284   // Declare/Define CFieldGroup and CFieldDefinition
285   DECLARE_GROUP(CField);
286
287   ///-----------------------------------------------------------------
288
289   template <>
290      void CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void);
291
292   ///-----------------------------------------------------------------
293} // namespace xios
294
295
296#endif // __XIOS_CField__
Note: See TracBrowser for help on using the repository browser.