[591] | 1 | #ifndef __XIOS_CFile__ |
---|
| 2 | #define __XIOS_CFile__ |
---|
[219] | 3 | |
---|
[591] | 4 | /// XIOS headers /// |
---|
| 5 | #include "xios_spl.hpp" |
---|
[219] | 6 | #include "field.hpp" |
---|
[300] | 7 | #include "data_output.hpp" |
---|
[599] | 8 | #include "data_input.hpp" |
---|
[219] | 9 | #include "declare_group.hpp" |
---|
[318] | 10 | #include "date.hpp" |
---|
[369] | 11 | #include "attribute_enum.hpp" |
---|
| 12 | #include "attribute_enum_impl.hpp" |
---|
[1021] | 13 | #include "context_client.hpp" |
---|
[382] | 14 | #include "mpi.hpp" |
---|
[219] | 15 | |
---|
[335] | 16 | namespace xios { |
---|
[509] | 17 | |
---|
[219] | 18 | /// ////////////////////// Déclarations ////////////////////// /// |
---|
| 19 | |
---|
| 20 | class CFileGroup; |
---|
| 21 | class CFileAttributes; |
---|
| 22 | class CFile; |
---|
| 23 | |
---|
[640] | 24 | class CGarbageCollector; |
---|
| 25 | |
---|
[219] | 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 | |
---|
[509] | 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 | */ |
---|
[219] | 43 | class CFile |
---|
| 44 | : public CObjectTemplate<CFile> |
---|
| 45 | , public CFileAttributes |
---|
| 46 | { |
---|
| 47 | /// typedef /// |
---|
| 48 | typedef CObjectTemplate<CFile> SuperClass; |
---|
| 49 | typedef CFileAttributes SuperClassAttribute; |
---|
[509] | 50 | |
---|
[219] | 51 | public : |
---|
[300] | 52 | enum EEventId |
---|
| 53 | { |
---|
[651] | 54 | EVENT_ID_ADD_FIELD, EVENT_ID_ADD_FIELD_GROUP, EVENT_ID_ADD_VARIABLE, |
---|
[509] | 55 | EVENT_ID_ADD_VARIABLE_GROUP, EVENT_ID_CREATE_ENABLED_FIELDS |
---|
[651] | 56 | }; |
---|
[509] | 57 | |
---|
[219] | 58 | typedef CFileAttributes RelAttributes; |
---|
| 59 | typedef CFileGroup RelGroup; |
---|
| 60 | |
---|
| 61 | /// Constructeurs /// |
---|
| 62 | CFile(void); |
---|
[651] | 63 | explicit CFile(const StdString& id); |
---|
| 64 | CFile(const CFile& file); // Not implemented yet. |
---|
| 65 | CFile(const CFile* const file); // Not implemented yet. |
---|
[219] | 66 | |
---|
[509] | 67 | /// Destructeur /// |
---|
| 68 | virtual ~CFile(void); |
---|
| 69 | |
---|
| 70 | public: |
---|
[219] | 71 | /// Accesseurs /// |
---|
[1158] | 72 | const StdString getFileOutputName(void) const; |
---|
[1542] | 73 | std::shared_ptr<CDataOutput> getDataOutput(void) const; |
---|
| 74 | std::shared_ptr<CDataInput> getDataInput(void) const; |
---|
[347] | 75 | CFieldGroup* getVirtualFieldGroup(void) const; |
---|
[472] | 76 | CVariableGroup* getVirtualVariableGroup(void) const; |
---|
[347] | 77 | std::vector<CField*> getAllFields(void) const; |
---|
[472] | 78 | std::vector<CVariable*> getAllVariables(void) const; |
---|
[219] | 79 | |
---|
[347] | 80 | std::vector<CField* > getEnabledFields(int default_outputlevel = 5, |
---|
| 81 | int default_level = 1, |
---|
| 82 | bool default_enabled = true); |
---|
[219] | 83 | |
---|
[1622] | 84 | StdString dumpClassAttributes(void); |
---|
| 85 | |
---|
[219] | 86 | public : |
---|
[509] | 87 | // Some functions to verify state of file |
---|
[651] | 88 | bool isSyncTime(void); |
---|
| 89 | bool checkSplit(void); |
---|
| 90 | bool checkSync(void); |
---|
[1136] | 91 | void checkWriteFile(void); |
---|
| 92 | void checkReadFile(void); |
---|
[1232] | 93 | void initWrite(void); |
---|
| 94 | void initRead(void); |
---|
| 95 | bool isEmptyZone(); |
---|
[219] | 96 | |
---|
| 97 | /// Mutateurs /// |
---|
[509] | 98 | // Set some root definitions in a file |
---|
[347] | 99 | void setVirtualFieldGroup(CFieldGroup* newVFieldGroup); |
---|
[472] | 100 | void setVirtualVariableGroup(CVariableGroup* newVVariableGroup); |
---|
[509] | 101 | |
---|
[300] | 102 | void createHeader(void); |
---|
[1232] | 103 | void openInReadMode(void); |
---|
[651] | 104 | void close(void); |
---|
[775] | 105 | void readAttributesOfEnabledFieldsInReadMode(); |
---|
[1871] | 106 | void readFieldAttributesMetaData(CField* field) ; |
---|
| 107 | void readFieldAttributesValues(CField* field) ; |
---|
[509] | 108 | // Some processing on file |
---|
[445] | 109 | void solveFieldRefInheritance(bool apply); |
---|
[651] | 110 | void processEnabledFile(void); |
---|
[1129] | 111 | |
---|
[1358] | 112 | void postProcessFilterGraph(); |
---|
[598] | 113 | void prefetchEnabledReadModeFields(); |
---|
[1358] | 114 | void doPreTimestepOperationsForEnabledReadModeFields(); |
---|
[1318] | 115 | void doPostTimestepOperationsForEnabledReadModeFields(); |
---|
[219] | 116 | |
---|
[1025] | 117 | void checkGridOfEnabledFields(); |
---|
| 118 | void sendGridOfEnabledFields(); |
---|
[1494] | 119 | void sendGridComponentOfEnabledFields(); |
---|
[1025] | 120 | |
---|
[1494] | 121 | void sortEnabledFieldsForUgrid(); |
---|
| 122 | |
---|
[509] | 123 | // Add component into file |
---|
[651] | 124 | CField* addField(const string& id = ""); |
---|
| 125 | CFieldGroup* addFieldGroup(const string& id = ""); |
---|
| 126 | CVariable* addVariable(const string& id = ""); |
---|
| 127 | CVariableGroup* addVariableGroup(const string& id = ""); |
---|
[1021] | 128 | void setContextClient(CContextClient* newContextClient); |
---|
| 129 | CContextClient* getContextClient(); |
---|
[509] | 130 | |
---|
[1232] | 131 | void setReadContextClient(CContextClient* newContextClient); |
---|
| 132 | CContextClient* getReadContextClient(); |
---|
| 133 | |
---|
[1144] | 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); |
---|
[1021] | 138 | void sendAddVariable(const string& id, CContextClient* client); |
---|
[1132] | 139 | void sendAddVariableGroup(const string& id, CContextClient* client); |
---|
[1144] | 140 | void sendAddAllVariables(CContextClient* client); |
---|
[1870] | 141 | public: |
---|
| 142 | void sendFileToFileServer(CContextClient* client) ; |
---|
| 143 | private: |
---|
| 144 | std::set<CContextClient*> sendFileToFileServer_done_ ; |
---|
| 145 | |
---|
| 146 | public: |
---|
[509] | 147 | // Receive info from client |
---|
[651] | 148 | static void recvAddField(CEventServer& event); |
---|
| 149 | void recvAddField(CBufferIn& buffer); |
---|
| 150 | static void recvAddFieldGroup(CEventServer& event); |
---|
| 151 | void recvAddFieldGroup(CBufferIn& buffer); |
---|
| 152 | static void recvAddVariable(CEventServer& event); |
---|
| 153 | void recvAddVariable(CBufferIn& buffer); |
---|
| 154 | static void recvAddVariableGroup(CEventServer& event); |
---|
| 155 | void recvAddVariableGroup(CBufferIn& buffer); |
---|
[509] | 156 | |
---|
| 157 | // Dispatch event |
---|
[651] | 158 | static bool dispatchEvent(CEventServer& event); |
---|
[509] | 159 | |
---|
| 160 | public: |
---|
| 161 | /// Accesseurs statiques /// |
---|
| 162 | static StdString GetName(void); |
---|
| 163 | static StdString GetDefName(void); |
---|
| 164 | |
---|
| 165 | static ENodeType GetType(void); |
---|
| 166 | public: |
---|
| 167 | /// Traitements /// |
---|
[651] | 168 | virtual void solveDescInheritance(bool apply, const CAttributeMap* const parent = 0); |
---|
[509] | 169 | |
---|
| 170 | /// Autres /// |
---|
[651] | 171 | virtual void parse(xml::CXMLNode& node); |
---|
[509] | 172 | virtual StdString toString(void) const; |
---|
| 173 | public: |
---|
| 174 | |
---|
[651] | 175 | CDate lastSync; |
---|
| 176 | CDate lastSplit; |
---|
[1961] | 177 | |
---|
| 178 | const CDate& getLastSplit(void) { return lastSplit ; } |
---|
| 179 | |
---|
[609] | 180 | int nbAxis, nbDomains; |
---|
[1232] | 181 | bool isOpen; |
---|
[1639] | 182 | MPI_Comm fileComm; |
---|
[509] | 183 | |
---|
[1232] | 184 | private: |
---|
| 185 | void createSubComFile(); |
---|
| 186 | bool checkRead; |
---|
| 187 | bool allZoneEmpty; |
---|
| 188 | |
---|
[219] | 189 | private : |
---|
| 190 | /// Propriétés privées /// |
---|
[1054] | 191 | CContextClient* client; |
---|
[1232] | 192 | CContextClient* read_client; // Context client for reading (channel between server 1 and client) |
---|
[347] | 193 | CFieldGroup* vFieldGroup; |
---|
[651] | 194 | CVariableGroup* vVariableGroup; |
---|
[1542] | 195 | std::shared_ptr<CDataOutput> data_out; |
---|
| 196 | std::shared_ptr<CDataInput> data_in; |
---|
[347] | 197 | std::vector<CField*> enabledFields; |
---|
[219] | 198 | |
---|
[1871] | 199 | private: |
---|
| 200 | bool isClientSide_ ; // the file is on client side or on server side ? |
---|
| 201 | public: |
---|
| 202 | bool isClientSide(void) { return isClientSide_ ;} |
---|
| 203 | bool isServerSide(void) { return !isClientSide_ ;} |
---|
| 204 | void setClientSide(void) { isClientSide_=true ;} |
---|
| 205 | void setServerSide(void) { isClientSide_=false ;} |
---|
| 206 | |
---|
| 207 | private: |
---|
[1232] | 208 | |
---|
[1871] | 209 | |
---|
[509] | 210 | public: |
---|
[651] | 211 | // virtual void toBinary (StdOStream& os) const; |
---|
| 212 | // virtual void fromBinary(StdIStream& is); |
---|
[509] | 213 | |
---|
[219] | 214 | }; // class CFile |
---|
| 215 | |
---|
| 216 | ///-------------------------------------------------------------- |
---|
| 217 | |
---|
| 218 | // Declare/Define CFileGroup and CFileDefinition |
---|
| 219 | DECLARE_GROUP(CFile); |
---|
| 220 | |
---|
| 221 | ///-------------------------------------------------------------- |
---|
| 222 | |
---|
[335] | 223 | } // namespace xios |
---|
[219] | 224 | |
---|
[591] | 225 | #endif // __XIOS_CFile__ |
---|