source: XIOS/dev/dev_olga/src/node/context.hpp @ 1071

Last change on this file since 1071 was 1071, checked in by oabramkina, 7 years ago

dev: test for secondary servers added.

  • 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: 9.5 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#include "registry.hpp"
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, EVENT_ID_SEND_REGISTRY,
54           EVENT_ID_POST_PROCESS_GLOBAL_ATTRIBUTES,
55           EVENT_ID_PROCESS_GRID_ENABLED_FIELDS
56         };
57
58         /// typedef ///
59         typedef CObjectTemplate<CContext>   SuperClass;
60         typedef CContextAttributes SuperClassAttribute;
61
62      public :
63
64         typedef CContextAttributes RelAttributes;
65         typedef CContext           RelGroup;
66
67         //---------------------------------------------------------
68
69      public :
70
71         /// Constructeurs ///
72         CContext(void);
73         explicit CContext(const StdString & id);
74         CContext(const CContext & context);       // Not implemented yet.
75         CContext(const CContext * const context); // Not implemented yet.
76
77         /// Destructeur ///
78         virtual ~CContext(void);
79
80         //---------------------------------------------------------
81
82      public :
83
84         /// Mutateurs ///
85         void setCalendar(boost::shared_ptr<CCalendar> newCalendar);
86
87         /// Accesseurs ///
88         boost::shared_ptr<CCalendar>      getCalendar(void) const;
89
90      public :
91         // Initialize server or client
92         void initClient(MPI_Comm intraComm, MPI_Comm interComm, CContext* cxtServer = 0);
93         void initServer(MPI_Comm intraComm, MPI_Comm interComm, CContext* cxtClient = 0);
94         bool isInitialized(void);
95
96         // Put sever or client into loop state
97         bool checkBuffersAndListen(void);
98
99         // Finalize a context
100         void finalize(void);
101         void closeDefinition(void);
102         bool isFinalized(void);
103
104         // Some functions to process context
105         void findAllEnabledFields(void);
106         void findAllEnabledFieldsInReadModeFiles(void);
107         void readAttributesOfEnabledFieldsInReadModeFiles();
108         void solveAllInheritance(bool apply=true);
109         void findEnabledFiles(void);
110         void findEnabledReadModeFiles(void);
111         void closeAllFile(void);
112         void updateCalendar(int step);
113         void createFileHeader(void );
114         void checkAxisDomainsGridsEligibilityForCompressedOutput();
115         void prepareTimeseries(void);
116         void solveOnlyRefOfEnabledFields(bool sendToServer);
117         void solveAllRefOfEnabledFields(bool sendToServer);
118         void buildFilterGraphOfEnabledFields();
119         void startPrefetchingOfEnabledReadModeFiles();
120         void checkPrefetchingOfEnabledReadModeFiles();
121         void findFieldsWithReadAccess(void);
122         void solveAllRefOfFieldsWithReadAccess();
123         void buildFilterGraphOfFieldsWithReadAccess();
124         void postProcessing();
125         void postProcessingGlobalAttributes();         
126
127         void solveAllEnabledFields();
128         void processGridEnabledFields();
129
130         std::map<int, StdSize> getAttributesBufferSize(std::map<int, StdSize>& maxEventSize);
131         std::map<int, StdSize> getDataBufferSize(std::map<int, StdSize>& maxEventSize);
132         void setClientServerBuffer();
133
134         // Send context close definition
135         void sendCloseDefinition(void);
136         // There are something to send on closing context defintion
137         void sendUpdateCalendar(int step);
138         void sendCreateFileHeader(void);
139         void sendEnabledFiles();
140         void sendEnabledFields();
141         void sendRefDomainsAxis();
142         void sendRefGrid();
143         void sendPostProcessing();
144         void sendPostProcessingGlobalAttributes();
145         void sendProcessingGridOfEnabledFields();
146         //!< after be gathered to the root process of the context, merged registry is sent to the root process of the servers
147         void sendRegistry(void) ;
148
149         const StdString& getIdServer();
150         const StdString& getIdServer(const int srvPoolNb);
151
152         // Client side: Receive and process messages
153         static void recvUpdateCalendar(CEventServer& event);
154         void recvUpdateCalendar(CBufferIn& buffer);
155         static void recvCloseDefinition(CEventServer& event);
156         static void recvCreateFileHeader(CEventServer& event);
157         void recvCreateFileHeader(CBufferIn& buffer);
158         static void recvSolveInheritanceContext(CEventServer& event);
159         void recvSolveInheritanceContext(CBufferIn& buffer);
160         static void recvPostProcessing(CEventServer& event);
161         void recvPostProcessing(CBufferIn& buffer);
162         static void recvProcessingGridOfEnabledFields(CEventServer& event);
163         static void recvPostProcessingGlobalAttributes(CEventServer& event);
164         void recvPostProcessingGlobalAttributes(CBufferIn& buffer);
165         static void recvRegistry(CEventServer& event) ;
166         void recvRegistry(CBufferIn& buffer) ; //!< registry is received by the servers
167
168         void freeComms(void); //!< Free internally allcoated communicators
169
170         // dispatch event
171         static bool dispatchEvent(CEventServer& event);
172
173      public:
174        // Get current context
175        static CContext* getCurrent(void);
176
177        // Get context root
178        static CContextGroup* getRoot(void);
179
180        // Set current context
181        static void setCurrent(const string& id);
182
183        // Create new context
184        static CContext* create(const string& id = "");
185
186        /// Accesseurs statiques ///
187        static StdString GetName(void);
188        static StdString GetDefName(void);
189        static ENodeType GetType(void);
190
191        static CContextGroup* GetContextGroup(void);
192
193        // Some functions to visualize structure of current context
194        static void ShowTree(StdOStream & out = std::clog);
195        static void CleanTree(void);
196
197      public :
198         // Parse xml node and write all info into context
199         virtual void parse(xml::CXMLNode & node);
200
201         // Visualize a context
202         virtual StdString toString(void) const;
203
204
205         // Solve all inheritance relation in current context
206         virtual void solveDescInheritance(bool apply, const CAttributeMap * const parent = 0);
207
208         // Verify if all root definition in a context have children
209         virtual bool hasChild(void) const;
210
211
212      public :
213         // Calendar of context
214         boost::shared_ptr<CCalendar>   calendar;
215
216         // List of all enabled files (files on which fields are written or read)
217         std::vector<CFile*> enabledFiles;
218         // List of all enabled files in read mode (files on which fields are read)
219         std::vector<CFile*> enabledReadModeFiles;
220
221         // List of all enabled fields whose instant data is accessible from the public API
222         // but which are not part of a file
223         std::vector<CField*> fieldsWithReadAccess;
224
225         // Context root
226         static shared_ptr<CContextGroup> root;
227
228         // Determine context on client or not
229         bool hasClient;
230
231         // Determine context on server or not
232         bool hasServer;
233
234         CContextServer* server;  //!< Concrete context server
235         CContextClient* client;  //!< Concrete contex client
236         std::vector<CContextServer*> serverPrimServer;
237         std::vector<CContextClient*> clientPrimServer;
238
239         CRegistry* registryIn ;  //!< input registry which is read from file
240         CRegistry* registryOut ; //!< output registry which will be wrote on file at the finalize
241
242      private:
243         bool isPostProcessed;
244         bool allProcessed;
245         bool finalized;
246         StdString idServer_;
247         CGarbageCollector garbageCollector;
248         std::list<MPI_Comm> comms; //!< Communicators allocated internally
249
250      public: // Some function maybe removed in the near future
251        // virtual void toBinary  (StdOStream & os) const;
252        // virtual void fromBinary(StdIStream & is);
253   }; // class CContext
254
255   ///--------------------------------------------------------------
256
257   // Declare/Define CContextGroup and CContextDefinition
258   DECLARE_GROUP(CContext);
259
260   ///--------------------------------------------------------------
261
262} // namespace xios
263
264#endif // __XIOS_CContext__
Note: See TracBrowser for help on using the repository browser.