source: XIOS/dev/branch_openmp/src/node/file.hpp @ 1460

Last change on this file since 1460 was 1460, checked in by yushan, 6 years ago

branch_openmp merged with XIOS_DEV_CMIP6@1459

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