source: XIOS/dev/dev_ym/XIOS_SERVICES/src/node/context.hpp @ 1761

Last change on this file since 1761 was 1761, checked in by ymipsl, 5 years ago

implementing first guess for service functionnalities.

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: 12.2 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 "data_output.hpp"
11#include "garbage_collector.hpp"
12#include "registry.hpp"
13#include "mpi.hpp"
14#include "services_manager.hpp"
15#include "server_context.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(std::shared_ptr<CCalendar> newCalendar);
86
87         /// Accesseurs ///
88         std::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 init(CServerContext* parentServerContext, MPI_Comm intraComm, int serviceType);
94         void initClient(MPI_Comm intraComm, int serviceType);
95         
96         void initServer(MPI_Comm intraComm, MPI_Comm interComm, CContext* cxtClient = 0);
97         void initServer(MPI_Comm intraComm, int serviceType );
98         void createClientInterComm(MPI_Comm interCommClient, MPI_Comm interCommServer)  ;
99         void createServerInterComm(void)  ;
100
101         bool isInitialized(void);
102
103         StdString dumpClassAttributes(void);
104
105         // Put sever or client into loop state
106         bool checkBuffersAndListen(bool enableEventsProcessing=true);
107         bool eventLoop(bool enableEventsProcessing=true);
108
109         // Finalize a context
110         void finalize(void);
111         void finalize_old(void);
112         bool isFinalized(void);
113
114         void closeDefinition(void);
115
116         // Some functions to process context
117         void findAllEnabledFieldsInFiles(const std::vector<CFile*>& activeFiles);
118         // void findAllEnabledFields(void);
119         // void findAllEnabledFieldsInReadModeFiles(void);
120         void readAttributesOfEnabledFieldsInReadModeFiles();
121         void solveAllInheritance(bool apply=true);
122         void findEnabledFiles(void);
123         void findEnabledWriteModeFiles(void);
124         void findEnabledReadModeFiles(void);
125         void closeAllFile(void);
126         void updateCalendar(int step);
127         void createFileHeader(void);
128         void initReadFiles(void);
129         void checkAxisDomainsGridsEligibilityForCompressedOutput();
130         void prepareTimeseries(void);
131         void solveOnlyRefOfEnabledFields(bool sendToServer);         
132         void buildFilterGraphOfEnabledFields();
133         void postProcessFilterGraph();
134         void startPrefetchingOfEnabledReadModeFiles();
135         void doPreTimestepOperationsForEnabledReadModeFiles();
136         void doPostTimestepOperationsForEnabledReadModeFiles();
137         void findFieldsWithReadAccess(void);
138         void solveAllRefOfFieldsWithReadAccess();
139         void buildFilterGraphOfFieldsWithReadAccess();
140         void postProcessing();
141         void postProcessingGlobalAttributes();         
142
143         void solveAllRefOfEnabledFieldsAndTransform(bool sendToServer);
144         void checkGridEnabledFields();
145         void checkGridEnabledFieldsInFiles(const std::vector<CFile*>& activeFiles);
146         void sendGridEnabledFieldsInFiles(const std::vector<CFile*>& activeFiles); 
147         void sendGridComponentEnabledFieldsInFiles(const std::vector<CFile*>& activeFiles)       ;
148
149         std::map<int, StdSize> getAttributesBufferSize(std::map<int, StdSize>& maxEventSize, CContextClient* contextClient, bool bufferForWriting = false);
150         std::map<int, StdSize> getDataBufferSize(std::map<int, StdSize>& maxEventSize, CContextClient* contextClient, bool bufferForWriting = false);
151         void setClientServerBuffer(CContextClient* contextClient, bool bufferForWriting = false);
152
153         // Distribute files (in write mode) among secondary-server pools according to the estimated data flux
154         void distributeFiles(void);
155         void distributeFileOverBandwith() ;
156         void distributeFileOverMemoryBandwith() ;
157         
158         // Send context close definition
159         void sendCloseDefinition(void);
160         // There are something to send on closing context defintion
161         void sendUpdateCalendar(int step);
162         void sendCreateFileHeader(void);
163         void sendEnabledFiles(const std::vector<CFile*>& activeFiles);
164         void sendEnabledFieldsInFiles(const std::vector<CFile*>& activeFiles);
165         void sendRefDomainsAxisScalars(const std::vector<CFile*>& activeFiles);
166         void sendRefGrid(const std::vector<CFile*>& activeFiles);
167         void sendPostProcessing();
168         void sendPostProcessingGlobalAttributes();
169         void sendProcessingGridOfEnabledFields();
170         //!< after be gathered to the root process of the context, merged registry is sent to the root process of the servers
171         void sendRegistry(void) ;
172
173         const StdString& getIdServer();
174         void setIdServer(const StdString& idServer);
175         const StdString& getIdServer(const int srvPoolNb);
176         std::string getContextId() {return contextId_;}
177
178         // Client side: Receive and process messages
179         static void recvUpdateCalendar(CEventServer& event);
180         void recvUpdateCalendar(CBufferIn& buffer);
181         static void recvCloseDefinition(CEventServer& event);
182         static void recvCreateFileHeader(CEventServer& event);
183         void recvCreateFileHeader(CBufferIn& buffer);
184         static void recvSolveInheritanceContext(CEventServer& event);
185         void recvSolveInheritanceContext(CBufferIn& buffer);
186         static void recvPostProcessing(CEventServer& event);
187         void recvPostProcessing(CBufferIn& buffer);
188         static void recvProcessingGridOfEnabledFields(CEventServer& event);
189         static void recvPostProcessingGlobalAttributes(CEventServer& event);
190         void recvPostProcessingGlobalAttributes(CBufferIn& buffer);
191         static void recvRegistry(CEventServer& event) ;
192         void recvRegistry(CBufferIn& buffer) ; //!< registry is received by the servers
193
194         void freeComms(void);                  //!< Free internally allcoated communicators
195         void releaseClientBuffers(void);       //! Deallocate buffers allocated by clientContexts
196
197         // dispatch event
198         static bool dispatchEvent(CEventServer& event);
199
200      public:
201        // Get current context
202        static CContext* getCurrent(void);
203
204        // Get context root
205        static CContextGroup* getRoot(void);
206
207        // Set current context
208        static void setCurrent(const string& id);
209
210        // Create new context
211        static CContext* create(const string& id = "");
212
213        /// Accesseurs statiques ///
214        static StdString GetName(void);
215        static StdString GetDefName(void);
216        static ENodeType GetType(void);
217
218        static CContextGroup* GetContextGroup(void);
219
220        // Some functions to visualize structure of current context
221        static void ShowTree(StdOStream & out = std::clog);
222        static void CleanTree(void);
223        int getServiceType(void) {return serviceType_;}
224
225      public :
226         // Parse xml node and write all info into context
227         virtual void parse(xml::CXMLNode & node);
228
229         // Visualize a context
230         virtual StdString toString(void) const;
231
232
233         // Solve all inheritance relation in current context
234         virtual void solveDescInheritance(bool apply, const CAttributeMap * const parent = 0);
235
236         // Verify if all root definition in a context have children
237         virtual bool hasChild(void) const;
238
239         bool isProcessingEvent(void) {return isProcessingEvent_;}
240         bool setProcessingEvent(void) {isProcessingEvent_=true ;}
241         bool unsetProcessingEvent(void) {isProcessingEvent_=false ;}
242
243      public :
244         // Calendar of context
245         std::shared_ptr<CCalendar>   calendar;
246
247         // List of all enabled files (files on which fields are written or read)
248         std::vector<CFile*> enabledFiles;
249         // List of all enabled files in read mode (files on which fields are read)
250         std::vector<CFile*> enabledReadModeFiles;
251         // List of all enabled files in write mode
252         std::vector<CFile*> enabledWriteModeFiles;
253
254         // List of all enabled fields whose instant data is accessible from the public API
255         // but which are not part of a file
256         std::vector<CField*> fieldsWithReadAccess;
257
258         // Context root
259         static std::shared_ptr<CContextGroup> root;
260
261         // Determine context on client or not
262         bool hasClient;
263
264         // Determine context on server or not
265         bool hasServer;
266
267         CContextServer* server;    //!< Concrete context server
268         CContextClient* client;    //!< Concrete contex client
269         std::vector<CContextServer*> serverPrimServer;
270         std::vector<CContextClient*> clientPrimServer;
271         std::vector<std::string> primServerId_;
272
273         CRegistry* registryIn ;    //!< input registry which is read from file
274         CRegistry* registryOut ;   //!< output registry which will be written into file at the finalize
275
276
277        MPI_Comm intraComm_ ; //! context intra communicator
278
279      private:
280         bool isPostProcessed;
281         bool allProcessed;
282         bool finalized;
283         int countChildCtx_;        //!< Counter of child contexts (for now it is the number of secondary server pools)
284         StdString idServer_;
285         CGarbageCollector garbageCollector;
286         std::list<MPI_Comm> comms; //!< Communicators allocated internally
287
288         int serviceType_;  //!< service associated to the context
289         string contextId_ ; //!< context client id for the servers. For clients this is same as getId()
290         bool isProcessingEvent_ ;
291         CServerContext* parentServerContext_ ;
292
293      public: // Some function maybe removed in the near future
294        // virtual void toBinary  (StdOStream & os) const;
295        // virtual void fromBinary(StdIStream & is);
296   }; // class CContext
297
298   ///--------------------------------------------------------------
299
300   // Declare/Define CContextGroup and CContextDefinition
301   DECLARE_GROUP(CContext);
302
303   ///--------------------------------------------------------------
304
305} // namespace xios
306
307#endif // __XIOS_CContext__
Note: See TracBrowser for help on using the repository browser.