source: XIOS/dev/XIOS_DEV_CMIP6/src/node/field.hpp @ 1318

Last change on this file since 1318 was 1318, checked in by rlacroix, 7 years ago

Fix: Handle end-of-file correctly for files in read mode.

Previously desynchronizations between clients could occur, leading to invalid events being received by the server(s).

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