source: XIOS3/dev/XIOS_ATTACHED/src/node/file.hpp @ 2482

Last change on this file since 2482 was 2482, checked in by ymipsl, 15 months ago

First guess in supression of attached mode replaced by online reader and write filters

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: 8.3 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         void replaceEnabledFields(CField* fieldIn, CField* fieldOut) ;
86
87         StdString dumpClassAttributes(void);
88
89      public :
90         // Some functions to verify state of file
91         bool isSyncTime(void);
92         bool checkSplit(void);
93         bool checkSync(void);
94         void checkWriteFile(void);
95         void checkReadFile(void);
96         void initWrite(void);
97         void initRead(void);
98         bool isEmptyZone();
99
100         /// Mutateurs ///
101         // Set some root definitions in a file
102         void setVirtualFieldGroup(CFieldGroup* newVFieldGroup);
103         void setVirtualVariableGroup(CVariableGroup* newVVariableGroup);
104
105         void createHeader(void);
106         void openInReadMode(void);
107         void close(void);
108         void readAttributesOfEnabledFieldsInReadMode();
109         void readFieldAttributesMetaData(CField* field) ;
110         void readFieldAttributesValues(CField* field) ;
111         // Some processing on file
112         void solveFieldRefInheritance(bool apply);
113         void processEnabledFile(void);
114         
115         void prefetchEnabledReadModeFields();
116         void doPostTimestepOperationsForEnabledReadModeFields();
117
118         void checkGridOfEnabledFields();
119         void sendGridOfEnabledFields();
120         void sendGridComponentOfEnabledFields();
121
122         void sortEnabledFieldsForUgrid();
123
124         // Add component into file
125         CField* addField(const string& id = "");
126         CFieldGroup* addFieldGroup(const string& id = "");
127         CVariable* addVariable(const string& id = "");
128         CVariableGroup* addVariableGroup(const string& id = "");
129         
130         
131         void getWriterServicesId(bool defaultUsingServer2_, const string& defaultPoolWriterId_, const string& defaultWriterId_, const string& defaultPoolGathererId_, const string& defaultGathererId_,
132                                  bool& usingServer2, string& poolWriterId, string& writerId, string& poolGathererId, string& gathererId) ;
133         void getReaderServicesId(const string& defaultPoolReaderId_, const string& defaultReaderId_, string& poolReaderId, string& readerId) ;
134 
135
136         void setContextClient(const string& defaultPoolId, const string& defaultServiceId, int partitionId) ;
137         void setContextClient(CContextClient* newContextClient);
138         CContextClient* getContextClient();
139
140         // Send info to server         
141         void sendEnabledFields(CContextClient* client);         
142         void sendAddField(const string& id, CContextClient* client);         
143         void sendAddFieldGroup(const string& id, CContextClient* client);                           
144         void sendAddVariable(const string& id, CContextClient* client);
145         void sendAddVariableGroup(const string& id, CContextClient* client);
146         void sendAddAllVariables(CContextClient* client);
147      public:
148         void sendFileToFileServer(CContextClient* client) ;
149      private:
150         std::set<CContextClient*> sendFileToFileServer_done_ ;
151
152      public:
153         // Receive info from client
154         static void recvAddField(CEventServer& event);
155         void recvAddField(CBufferIn& buffer);
156         static void recvAddFieldGroup(CEventServer& event);
157         void recvAddFieldGroup(CBufferIn& buffer);
158         static void recvAddVariable(CEventServer& event);
159         void recvAddVariable(CBufferIn& buffer);
160         static void recvAddVariableGroup(CEventServer& event);
161         void recvAddVariableGroup(CBufferIn& buffer);
162
163         // Dispatch event
164         static bool dispatchEvent(CEventServer& event);
165
166      public:
167         /// Accesseurs statiques ///
168         static StdString GetName(void);
169         static StdString GetDefName(void);
170
171         static ENodeType GetType(void);
172      public:
173         /// Traitements ///
174         virtual void solveDescInheritance(bool apply, const CAttributeMap* const parent = 0);
175
176          /// Autres ///
177         virtual void parse(xml::CXMLNode& node);
178         virtual StdString toString(void) const;
179      public:
180
181         CDate lastSync;
182         CDate lastSplit;
183         
184         const CDate& getLastSplit(void) { return lastSplit ; }
185       
186         int nbAxis, nbDomains;
187         bool isOpen;         
188         MPI_Comm fileComm;
189
190      private:
191         void createSubComFile();
192         bool checkRead;
193         bool allZoneEmpty;
194         
195      private :
196         /// Propriétés privées ///
197         CContextClient* client;
198         CFieldGroup* vFieldGroup;
199         CVariableGroup* vVariableGroup;
200         std::shared_ptr<CDataOutput> data_out;
201         std::shared_ptr<CDataInput> data_in;
202         std::vector<CField*> enabledFields;
203
204       private: 
205         bool isClientSide_ ; // the file is on client side or on server side ?
206       public:
207         bool isClientSide(void) { return isClientSide_ ;}
208         bool isServerSide(void) { return !isClientSide_ ;}
209         void setClientSide(void) { isClientSide_=true ;}
210         void setServerSide(void) { isClientSide_=false ;}
211       
212       private:
213         bool isOnline_=false;
214       public:
215         bool isOnline(void) { return isOnline_ ;}
216         void setOnline(bool online=true) { isOnline_=online ;} 
217      public:
218        //         virtual void toBinary  (StdOStream& os) const;
219        //         virtual void fromBinary(StdIStream& is);
220
221   }; // class CFile
222
223   ///--------------------------------------------------------------
224
225   // Declare/Define CFileGroup and CFileDefinition
226   DECLARE_GROUP(CFile);
227
228   ///--------------------------------------------------------------
229
230} // namespace xios
231
232#endif // __XIOS_CFile__
Note: See TracBrowser for help on using the repository browser.