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