source: XIOS/trunk/src/node/context.hpp @ 640

Last change on this file since 640 was 640, checked in by rlacroix, 9 years ago

Start using the filter infrastructure to read and write fields.

Note that currently only the simple cases are working. References and all types of operations are disabled.

  • 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.0 KB
Line 
1#ifndef __XIOS_CContext__
2#define __XIOS_CContext__
3
4/// XIOS headers ///
5#include "xios_spl.hpp"
6//#include "node_type.hpp"
7#include "calendar_wrapper.hpp"
8
9#include "declare_group.hpp"
10//#include "context_client.hpp"
11//#include "context_server.hpp"
12#include "data_output.hpp"
13#include "garbage_collector.hpp"
14
15#include "mpi.hpp"
16
17
18namespace xios {
19   class CContextClient;
20   class CContextServer;
21
22
23   /// ////////////////////// Déclarations ////////////////////// ///
24   class CContextGroup;
25   class CContextAttributes;
26   class CContext;
27   class CFile;
28   ///--------------------------------------------------------------
29
30   // Declare/Define CFileAttribute
31   BEGIN_DECLARE_ATTRIBUTE_MAP(CContext)
32#  include "context_attribute.conf"
33   END_DECLARE_ATTRIBUTE_MAP(CContext)
34
35   ///--------------------------------------------------------------
36  /*!
37  \class CContext
38   This class corresponds to the concrete presentation of context in xml file and in play an essential role in XIOS
39   Each object of this class contains all root definition of elements: files, fiels, domains, axis, etc, ... from which
40   we can have access to each element.
41   In fact, every thing must a be inside a particuliar context. After the xml file (iodef.xml) is parsed,
42   object of the class is created and its contains all information of other elements in the xml file.
43  */
44   class CContext
45      : public CObjectTemplate<CContext>
46      , public CContextAttributes
47   {
48         public :
49         enum EEventId
50         {
51           EVENT_ID_CLOSE_DEFINITION,EVENT_ID_UPDATE_CALENDAR,
52           EVENT_ID_CREATE_FILE_HEADER,EVENT_ID_CONTEXT_FINALIZE,
53           EVENT_ID_POST_PROCESS
54         };
55
56         /// typedef ///
57         typedef CObjectTemplate<CContext>   SuperClass;
58         typedef CContextAttributes SuperClassAttribute;
59
60      public :
61
62         typedef CContextAttributes RelAttributes;
63         typedef CContext           RelGroup;
64
65         //---------------------------------------------------------
66
67      public :
68
69         /// Constructeurs ///
70         CContext(void);
71         explicit CContext(const StdString & id);
72         CContext(const CContext & context);       // Not implemented yet.
73         CContext(const CContext * const context); // Not implemented yet.
74
75         /// Destructeur ///
76         virtual ~CContext(void);
77
78         //---------------------------------------------------------
79
80      public :
81
82         /// Mutateurs ///
83         void setCalendar(boost::shared_ptr<CCalendar> newCalendar);
84
85         /// Accesseurs ///
86         boost::shared_ptr<CCalendar>      getCalendar(void) const;
87
88      public :
89         // Initialize server or client
90         void initServer(MPI_Comm intraComm, MPI_Comm interComm, CContext* cxtClient = 0);
91         void initClient(MPI_Comm intraComm, MPI_Comm interComm, CContext* cxtServer = 0);
92         bool isInitialized(void);
93
94         // Put sever or client into loop state
95         bool eventLoop(void);
96
97         bool checkBuffersAndListen(void);
98
99         // Finalize a context
100         void finalize(void);
101         void closeDefinition(void);
102
103         // Some functions to process context
104         void findAllEnabledFields(void);
105         void processEnabledFiles(void);
106         void solveAllInheritance(bool apply=true);
107         void findEnabledFiles(void);
108         void findEnabledReadModeFiles(void);
109         void closeAllFile(void);
110         void updateCalendar(int step);
111         void createFileHeader(void );
112         void solveAllRefOfEnabledFields(bool sendToServer);
113         void buildAllExpressionOfEnabledFields();
114         void buildFilterGraphOfEnabledFields();
115         void startPrefetchingOfEnabledReadModeFiles();
116         void checkPrefetchingOfEnabledReadModeFiles();
117         void findFieldsWithReadAccess(void);
118         void solveAllRefOfFieldsWithReadAccess();
119         void buildAllExpressionOfFieldsWithReadAccess();
120         void buildFilterGraphOfFieldsWithReadAccess();
121         void postProcessing();
122
123         std::map<int, StdSize>& getDataSize();
124         void setClientServerBuffer();
125
126         // Send context close definition
127         void sendCloseDefinition(void);
128         // There are something to send on closing context defintion
129         void sendUpdateCalendar(int step);
130         void sendCreateFileHeader(void);
131         void sendEnabledFiles();
132         void sendEnabledFields();
133         void sendRefDomainsAxis();
134         void sendRefGrid();
135         void sendPostProcessing();
136
137         const StdString& getIdServer();
138
139         // Client side: Receive and process messages
140         static void recvUpdateCalendar(CEventServer& event);
141         void recvUpdateCalendar(CBufferIn& buffer);
142         static void recvCloseDefinition(CEventServer& event);
143         static void recvCreateFileHeader(CEventServer& event);
144         void recvCreateFileHeader(CBufferIn& buffer);
145         static void recvSolveInheritanceContext(CEventServer& event);
146         void recvSolveInheritanceContext(CBufferIn& buffer);
147         static void recvPostProcessing(CEventServer& event);
148         void recvPostProcessing(CBufferIn& buffer);
149
150         // dispatch event
151         static bool dispatchEvent(CEventServer& event);
152
153      public:
154        // Get current context
155        static CContext* getCurrent(void);
156
157        // Get context root
158        static CContextGroup* getRoot(void);
159
160        // Set current context
161        static void setCurrent(const string& id);
162
163        // Create new context
164        static CContext* create(const string& id = "");
165
166        /// Accesseurs statiques ///
167        static StdString GetName(void);
168        static StdString GetDefName(void);
169        static ENodeType GetType(void);
170
171        static CContextGroup* GetContextGroup(void);
172
173        // Some functions to visualize structure of current context
174        static void ShowTree(StdOStream & out = std::clog);
175        static void CleanTree(void);
176
177      public :
178         // Parse xml node and write all info into context
179         virtual void parse(xml::CXMLNode & node);
180
181         // Visualize a context
182         virtual StdString toString(void) const;
183
184
185         // Solve all inheritance relation in current context
186         virtual void solveDescInheritance(bool apply, const CAttributeMap * const parent = 0);
187
188         // Verify if all root definition in a context have children
189         virtual bool hasChild(void) const;
190
191      public :
192         // Calendar of context
193         boost::shared_ptr<CCalendar>   calendar;
194
195         // List of all enabled files (files on which fields are written or read)
196         std::vector<CFile*> enabledFiles;
197         // List of all enabled files in read mode (files on which fields are read)
198         std::vector<CFile*> enabledReadModeFiles;
199
200         // List of all fields whose instant data is accessible from the public API
201         std::vector<CField*> fieldsWithReadAccess;
202
203         // Context root
204         static shared_ptr<CContextGroup> root;
205
206         // Determine context on client or not
207         bool hasClient;
208
209         // Determine context on server or not
210         bool hasServer;
211
212         // Concrete context server
213         CContextServer* server;
214
215         // Concrete contex client
216         CContextClient* client;
217
218      private:
219         bool isPostProcessed;
220         bool finalized;
221         std::map<int, StdSize> dataSize_;
222         StdString idServer_;
223         CGarbageCollector garbageCollector;
224
225
226      public: // Some function maybe removed in the near future
227        // virtual void toBinary  (StdOStream & os) const;
228        // virtual void fromBinary(StdIStream & is);
229        // void solveAllGridRef(void);
230        // void solveAllOperation(void);
231        // void solveAllExpression(void);
232        // void solveFieldRefInheritance(bool apply);
233
234   }; // class CContext
235
236   ///--------------------------------------------------------------
237
238   // Declare/Define CContextGroup and CContextDefinition
239   DECLARE_GROUP(CContext);
240
241   ///--------------------------------------------------------------
242
243} // namespace xios
244
245#endif // __XIOS_CContext__
Note: See TracBrowser for help on using the repository browser.