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

Last change on this file since 2326 was 2326, checked in by ymipsl, 2 years ago

Fix Deadlock from reading phase.
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.8 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_COLLECTIVE=100,
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           EVENT_ID_NO_COLLECTIVE=1000,
58         };
59
60         typedef CFileAttributes RelAttributes;
61         typedef CFileGroup      RelGroup;
62
63         /// Constructeurs ///
64         CFile(void);
65         explicit CFile(const StdString& id);
66         CFile(const CFile& file);       // Not implemented yet.
67         CFile(const CFile* const file); // Not implemented yet.
68
69         /// Destructeur ///
70         virtual ~CFile(void);
71
72      public:
73         /// Accesseurs ///
74         const StdString getFileOutputName(void) const;
75         std::shared_ptr<CDataOutput> getDataOutput(void) const;
76         std::shared_ptr<CDataInput> getDataInput(void) const;
77         CFieldGroup* getVirtualFieldGroup(void) const;
78         CVariableGroup* getVirtualVariableGroup(void) const;
79         std::vector<CField*> getAllFields(void) const;
80         std::vector<CVariable*> getAllVariables(void) const;
81
82         std::vector<CField* > getEnabledFields(int default_outputlevel = 5,
83                                                int default_level = 1,
84                                                bool default_enabled = true);
85
86         StdString dumpClassAttributes(void);
87
88      public :
89         // Some functions to verify state of file
90         bool isSyncTime(void);
91         bool checkSplit(void);
92         bool checkSync(void);
93         void checkWriteFile(void);
94         void checkReadFile(void);
95         void initWrite(void);
96         void initRead(void);
97         bool isEmptyZone();
98
99         /// Mutateurs ///
100         // Set some root definitions in a file
101         void setVirtualFieldGroup(CFieldGroup* newVFieldGroup);
102         void setVirtualVariableGroup(CVariableGroup* newVVariableGroup);
103
104         void createHeader(void);
105         void openInReadMode(void);
106         void close(void);
107         void readAttributesOfEnabledFieldsInReadMode();
108         void readFieldAttributesMetaData(CField* field) ;
109         void readFieldAttributesValues(CField* field) ;
110         // Some processing on file
111         void solveFieldRefInheritance(bool apply);
112         void processEnabledFile(void);
113         
114         void postProcessFilterGraph();
115         void prefetchEnabledReadModeFields();
116         void doPreTimestepOperationsForEnabledReadModeFields();
117         void doPostTimestepOperationsForEnabledReadModeFields();
118
119         void checkGridOfEnabledFields();
120         void sendGridOfEnabledFields();
121         void sendGridComponentOfEnabledFields();
122
123         void sortEnabledFieldsForUgrid();
124
125         // Add component into file
126         CField* addField(const string& id = "");
127         CFieldGroup* addFieldGroup(const string& id = "");
128         CVariable* addVariable(const string& id = "");
129         CVariableGroup* addVariableGroup(const string& id = "");
130         void setContextClient(CContextClient* newContextClient);
131         CContextClient* getContextClient();
132
133         void setReadContextClient(CContextClient* newContextClient);
134         CContextClient* getReadContextClient();
135
136         // Send info to server         
137         void sendEnabledFields(CContextClient* client);         
138         void sendAddField(const string& id, CContextClient* client);         
139         void sendAddFieldGroup(const string& id, CContextClient* client);                           
140         void sendAddVariable(const string& id, CContextClient* client);
141         void sendAddVariableGroup(const string& id, CContextClient* client);
142         void sendAddAllVariables(CContextClient* client);
143      public:
144         void sendFileToFileServer(CContextClient* client) ;
145      private:
146         std::set<CContextClient*> sendFileToFileServer_done_ ;
147
148      public:
149         // Receive info from client
150         static void recvAddField(CEventServer& event);
151         void recvAddField(CBufferIn& buffer);
152         static void recvAddFieldGroup(CEventServer& event);
153         void recvAddFieldGroup(CBufferIn& buffer);
154         static void recvAddVariable(CEventServer& event);
155         void recvAddVariable(CBufferIn& buffer);
156         static void recvAddVariableGroup(CEventServer& event);
157         void recvAddVariableGroup(CBufferIn& buffer);
158
159         // Dispatch event
160         static bool dispatchEvent(CEventServer& event);
161
162      public:
163         /// Accesseurs statiques ///
164         static StdString GetName(void);
165         static StdString GetDefName(void);
166
167         static ENodeType GetType(void);
168      public:
169         /// Traitements ///
170         virtual void solveDescInheritance(bool apply, const CAttributeMap* const parent = 0);
171
172          /// Autres ///
173         virtual void parse(xml::CXMLNode& node);
174         virtual StdString toString(void) const;
175      public:
176
177         CDate lastSync;
178         CDate lastSplit;
179         
180         const CDate& getLastSplit(void) { return lastSplit ; }
181       
182         int nbAxis, nbDomains;
183         bool isOpen;         
184         MPI_Comm fileComm;
185
186      private:
187         void createSubComFile();
188         bool checkRead;
189         bool allZoneEmpty;
190         
191      private :
192         /// Propriétés privées ///
193         CContextClient* client;
194         CContextClient* read_client; // Context client for reading (channel between server 1 and client)
195         CFieldGroup* vFieldGroup;
196         CVariableGroup* vVariableGroup;
197         std::shared_ptr<CDataOutput> data_out;
198         std::shared_ptr<CDataInput> data_in;
199         std::vector<CField*> enabledFields;
200
201       private: 
202         bool isClientSide_ ; // the file is on client side or on server side ?
203       public:
204         bool isClientSide(void) { return isClientSide_ ;}
205         bool isServerSide(void) { return !isClientSide_ ;}
206         void setClientSide(void) { isClientSide_=true ;}
207         void setServerSide(void) { isClientSide_=false ;}
208       
209       private:
210
211
212      public:
213        //         virtual void toBinary  (StdOStream& os) const;
214        //         virtual void fromBinary(StdIStream& is);
215
216   }; // class CFile
217
218   ///--------------------------------------------------------------
219
220   // Declare/Define CFileGroup and CFileDefinition
221   DECLARE_GROUP(CFile);
222
223   ///--------------------------------------------------------------
224
225} // namespace xios
226
227#endif // __XIOS_CFile__
Note: See TracBrowser for help on using the repository browser.