source: XIOS/dev/dev_ym/XIOS_COUPLING/src/node/file.hpp @ 1930

Last change on this file since 1930 was 1871, checked in by ymipsl, 4 years ago

Some update on XIOS_COUPLING branch...

YM

  • 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
File size: 7.9 KB
Line 
1#ifndef __XIOS_CFile__
2#define __XIOS_CFile__
3
4/// XIOS headers ///
5#include "xios_spl.hpp"
6#include "field.hpp"
7#include "data_output.hpp"
8#include "data_input.hpp"
9#include "declare_group.hpp"
10#include "date.hpp"
11#include "attribute_enum.hpp"
12#include "attribute_enum_impl.hpp"
13#include "context_client.hpp"
14#include "mpi.hpp"
15
16namespace xios {
17
18   /// ////////////////////// Déclarations ////////////////////// ///
19
20   class CFileGroup;
21   class CFileAttributes;
22   class CFile;
23
24   class CGarbageCollector;
25
26   ///--------------------------------------------------------------
27
28   // Declare/Define CFileAttribute
29   BEGIN_DECLARE_ATTRIBUTE_MAP(CFile)
30#  include "file_attribute.conf"
31   END_DECLARE_ATTRIBUTE_MAP(CFile)
32
33   ///--------------------------------------------------------------
34
35   /*!
36   \class CFile
37   This class corresponds to file component of the xml.
38   The class contains all the nessceary information to write data into a netcdf file: The most important thing
39   is the field(s) which will be written into file. Besides, there are some options to write
40   data into file, e.g: writting into only one file or multiple file; splitting a running into several files.
41   Moreover, there are some other attributes of netcdf file which are also stored in this class
42   */
43   class CFile
44      : public CObjectTemplate<CFile>
45      , public CFileAttributes
46   {
47         /// typedef ///
48         typedef CObjectTemplate<CFile>   SuperClass;
49         typedef CFileAttributes SuperClassAttribute;
50
51      public :
52         enum EEventId
53         {
54           EVENT_ID_ADD_FIELD, EVENT_ID_ADD_FIELD_GROUP, EVENT_ID_ADD_VARIABLE,
55           EVENT_ID_ADD_VARIABLE_GROUP, EVENT_ID_CREATE_ENABLED_FIELDS
56         };
57
58         typedef CFileAttributes RelAttributes;
59         typedef CFileGroup      RelGroup;
60
61         /// Constructeurs ///
62         CFile(void);
63         explicit CFile(const StdString& id);
64         CFile(const CFile& file);       // Not implemented yet.
65         CFile(const CFile* const file); // Not implemented yet.
66
67         /// Destructeur ///
68         virtual ~CFile(void);
69
70      public:
71         /// Accesseurs ///
72         const StdString getFileOutputName(void) const;
73         std::shared_ptr<CDataOutput> getDataOutput(void) const;
74         std::shared_ptr<CDataInput> getDataInput(void) const;
75         CFieldGroup* getVirtualFieldGroup(void) const;
76         CVariableGroup* getVirtualVariableGroup(void) const;
77         std::vector<CField*> getAllFields(void) const;
78         std::vector<CVariable*> getAllVariables(void) const;
79
80         std::vector<CField* > getEnabledFields(int default_outputlevel = 5,
81                                                int default_level = 1,
82                                                bool default_enabled = true);
83
84         StdString dumpClassAttributes(void);
85
86      public :
87         // Some functions to verify state of file
88         bool isSyncTime(void);
89         bool checkSplit(void);
90         bool checkSync(void);
91         void checkWriteFile(void);
92         void checkReadFile(void);
93         void initWrite(void);
94         void initRead(void);
95         bool isEmptyZone();
96
97         /// Mutateurs ///
98         // Set some root definitions in a file
99         void setVirtualFieldGroup(CFieldGroup* newVFieldGroup);
100         void setVirtualVariableGroup(CVariableGroup* newVVariableGroup);
101
102         void createHeader(void);
103         void openInReadMode(void);
104         void close(void);
105         void readAttributesOfEnabledFieldsInReadMode();
106         void readFieldAttributesMetaData(CField* field) ;
107         void readFieldAttributesValues(CField* field) ;
108         // Some processing on file
109         void solveFieldRefInheritance(bool apply);
110         void processEnabledFile(void);
111         void solveOnlyRefOfEnabledFields(void);
112         void generateNewTransformationGridDest();
113         
114         void buildFilterGraphOfEnabledFields(CGarbageCollector& gc);
115         void postProcessFilterGraph();
116         void prefetchEnabledReadModeFields();
117         void doPreTimestepOperationsForEnabledReadModeFields();
118         void doPostTimestepOperationsForEnabledReadModeFields();
119
120         void solveAllRefOfEnabledFieldsAndTransform(void);
121         void checkGridOfEnabledFields();
122         void sendGridOfEnabledFields();
123         void sendGridComponentOfEnabledFields();
124
125         void sortEnabledFieldsForUgrid();
126
127         // Add component into file
128         CField* addField(const string& id = "");
129         CFieldGroup* addFieldGroup(const string& id = "");
130         CVariable* addVariable(const string& id = "");
131         CVariableGroup* addVariableGroup(const string& id = "");
132         void setContextClient(CContextClient* newContextClient);
133         CContextClient* getContextClient();
134
135         void setReadContextClient(CContextClient* newContextClient);
136         CContextClient* getReadContextClient();
137
138         // Send info to server         
139         void sendEnabledFields(CContextClient* client);         
140         void sendAddField(const string& id, CContextClient* client);         
141         void sendAddFieldGroup(const string& id, CContextClient* client);                           
142         void sendAddVariable(const string& id, CContextClient* client);
143         void sendAddVariableGroup(const string& id, CContextClient* client);
144         void sendAddAllVariables(CContextClient* client);
145      public:
146         void sendFileToFileServer(CContextClient* client) ;
147      private:
148         std::set<CContextClient*> sendFileToFileServer_done_ ;
149
150      public:
151         // Receive info from client
152         static void recvAddField(CEventServer& event);
153         void recvAddField(CBufferIn& buffer);
154         static void recvAddFieldGroup(CEventServer& event);
155         void recvAddFieldGroup(CBufferIn& buffer);
156         static void recvAddVariable(CEventServer& event);
157         void recvAddVariable(CBufferIn& buffer);
158         static void recvAddVariableGroup(CEventServer& event);
159         void recvAddVariableGroup(CBufferIn& buffer);
160
161         // Dispatch event
162         static bool dispatchEvent(CEventServer& event);
163
164      public:
165         /// Accesseurs statiques ///
166         static StdString GetName(void);
167         static StdString GetDefName(void);
168
169         static ENodeType GetType(void);
170      public:
171         /// Traitements ///
172         virtual void solveDescInheritance(bool apply, const CAttributeMap* const parent = 0);
173
174          /// Autres ///
175         virtual void parse(xml::CXMLNode& node);
176         virtual StdString toString(void) const;
177      public:
178
179         CDate lastSync;
180         CDate lastSplit;
181         int nbAxis, nbDomains;
182         bool isOpen;         
183         MPI_Comm fileComm;
184
185      private:
186         void createSubComFile();
187         bool checkRead;
188         bool allZoneEmpty;
189         
190      private :
191         /// Propriétés privées ///
192         CContextClient* client;
193         CContextClient* read_client; // Context client for reading (channel between server 1 and client)
194         CFieldGroup* vFieldGroup;
195         CVariableGroup* vVariableGroup;
196         std::shared_ptr<CDataOutput> data_out;
197         std::shared_ptr<CDataInput> data_in;
198         std::vector<CField*> enabledFields;
199
200       private: 
201         bool isClientSide_ ; // the file is on client side or on server side ?
202       public:
203         bool isClientSide(void) { return isClientSide_ ;}
204         bool isServerSide(void) { return !isClientSide_ ;}
205         void setClientSide(void) { isClientSide_=true ;}
206         void setServerSide(void) { isClientSide_=false ;}
207       
208       private:
209
210
211      public:
212        //         virtual void toBinary  (StdOStream& os) const;
213        //         virtual void fromBinary(StdIStream& is);
214
215   }; // class CFile
216
217   ///--------------------------------------------------------------
218
219   // Declare/Define CFileGroup and CFileDefinition
220   DECLARE_GROUP(CFile);
221
222   ///--------------------------------------------------------------
223
224} // namespace xios
225
226#endif // __XIOS_CFile__
Note: See TracBrowser for help on using the repository browser.