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
RevLine 
[591]1#ifndef __XIOS_CContext__
2#define __XIOS_CContext__
[219]3
[591]4/// XIOS headers ///
5#include "xios_spl.hpp"
[352]6//#include "node_type.hpp"
[549]7#include "calendar_wrapper.hpp"
[219]8
9#include "declare_group.hpp"
[300]10#include "data_output.hpp"
[639]11#include "garbage_collector.hpp"
[697]12#include "registry.hpp"
[382]13#include "mpi.hpp"
[1761]14#include "services_manager.hpp"
15#include "server_context.hpp"
[300]16
[219]17
[335]18namespace xios {
[549]19   class CContextClient;
20   class CContextServer;
[509]21
22
[219]23   /// ////////////////////// Déclarations ////////////////////// ///
24   class CContextGroup;
25   class CContextAttributes;
26   class CContext;
[352]27   class CFile;
[219]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   ///--------------------------------------------------------------
[509]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  */
[219]44   class CContext
45      : public CObjectTemplate<CContext>
46      , public CContextAttributes
47   {
[300]48         public :
49         enum EEventId
50         {
51           EVENT_ID_CLOSE_DEFINITION,EVENT_ID_UPDATE_CALENDAR,
[509]52           EVENT_ID_CREATE_FILE_HEADER,EVENT_ID_CONTEXT_FINALIZE,
[1025]53           EVENT_ID_POST_PROCESS, EVENT_ID_SEND_REGISTRY,
54           EVENT_ID_POST_PROCESS_GLOBAL_ATTRIBUTES,
55           EVENT_ID_PROCESS_GRID_ENABLED_FIELDS
[549]56         };
[509]57
[219]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 :
[509]83
[219]84         /// Mutateurs ///
[1542]85         void setCalendar(std::shared_ptr<CCalendar> newCalendar);
[509]86
[219]87         /// Accesseurs ///
[1542]88         std::shared_ptr<CCalendar>      getCalendar(void) const;
[219]89
90      public :
[509]91         // Initialize server or client
[1639]92         void initClient(MPI_Comm intraComm, MPI_Comm interComm, CContext* cxtServer = 0);
[1761]93         void init(CServerContext* parentServerContext, MPI_Comm intraComm, int serviceType);
94         void initClient(MPI_Comm intraComm, int serviceType);
95         
[1639]96         void initServer(MPI_Comm intraComm, MPI_Comm interComm, CContext* cxtClient = 0);
[1761]97         void initServer(MPI_Comm intraComm, int serviceType );
98         void createClientInterComm(MPI_Comm interCommClient, MPI_Comm interCommServer)  ;
99         void createServerInterComm(void)  ;
100
[549]101         bool isInitialized(void);
[219]102
[1622]103         StdString dumpClassAttributes(void);
104
[509]105         // Put sever or client into loop state
[1378]106         bool checkBuffersAndListen(bool enableEventsProcessing=true);
[1761]107         bool eventLoop(bool enableEventsProcessing=true);
[597]108
[509]109         // Finalize a context
[549]110         void finalize(void);
[1761]111         void finalize_old(void);
[1071]112         bool isFinalized(void);
[509]113
[1130]114         void closeDefinition(void);
115
[509]116         // Some functions to process context
[1232]117         void findAllEnabledFieldsInFiles(const std::vector<CFile*>& activeFiles);
118         // void findAllEnabledFields(void);
119         // void findAllEnabledFieldsInReadModeFiles(void);
[775]120         void readAttributesOfEnabledFieldsInReadModeFiles();
[549]121         void solveAllInheritance(bool apply=true);
[300]122         void findEnabledFiles(void);
[1232]123         void findEnabledWriteModeFiles(void);
[598]124         void findEnabledReadModeFiles(void);
[549]125         void closeAllFile(void);
126         void updateCalendar(int step);
[1232]127         void createFileHeader(void);
128         void initReadFiles(void);
[676]129         void checkAxisDomainsGridsEligibilityForCompressedOutput();
[711]130         void prepareTimeseries(void);
[1129]131         void solveOnlyRefOfEnabledFields(bool sendToServer);         
[640]132         void buildFilterGraphOfEnabledFields();
[1358]133         void postProcessFilterGraph();
[598]134         void startPrefetchingOfEnabledReadModeFiles();
[1358]135         void doPreTimestepOperationsForEnabledReadModeFiles();
[1318]136         void doPostTimestepOperationsForEnabledReadModeFiles();
[593]137         void findFieldsWithReadAccess(void);
138         void solveAllRefOfFieldsWithReadAccess();
[640]139         void buildFilterGraphOfFieldsWithReadAccess();
[509]140         void postProcessing();
[1025]141         void postProcessingGlobalAttributes();         
[509]142
[1129]143         void solveAllRefOfEnabledFieldsAndTransform(bool sendToServer);
[1099]144         void checkGridEnabledFields();
[1232]145         void checkGridEnabledFieldsInFiles(const std::vector<CFile*>& activeFiles);
[1239]146         void sendGridEnabledFieldsInFiles(const std::vector<CFile*>& activeFiles); 
147         void sendGridComponentEnabledFieldsInFiles(const std::vector<CFile*>& activeFiles)       ;
[1025]148
[1330]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);
[509]152
[1212]153         // Distribute files (in write mode) among secondary-server pools according to the estimated data flux
[1208]154         void distributeFiles(void);
[1349]155         void distributeFileOverBandwith() ;
156         void distributeFileOverMemoryBandwith() ;
157         
[509]158         // Send context close definition
[549]159         void sendCloseDefinition(void);
[509]160         // There are something to send on closing context defintion
[549]161         void sendUpdateCalendar(int step);
162         void sendCreateFileHeader(void);
[1232]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);
[509]167         void sendPostProcessing();
[1025]168         void sendPostProcessingGlobalAttributes();
169         void sendProcessingGridOfEnabledFields();
[983]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
[511]173         const StdString& getIdServer();
[1761]174         void setIdServer(const StdString& idServer);
[1009]175         const StdString& getIdServer(const int srvPoolNb);
[1761]176         std::string getContextId() {return contextId_;}
[511]177
[509]178         // Client side: Receive and process messages
[549]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);
[509]184         static void recvSolveInheritanceContext(CEventServer& event);
185         void recvSolveInheritanceContext(CBufferIn& buffer);
186         static void recvPostProcessing(CEventServer& event);
187         void recvPostProcessing(CBufferIn& buffer);
[1025]188         static void recvProcessingGridOfEnabledFields(CEventServer& event);
189         static void recvPostProcessingGlobalAttributes(CEventServer& event);
190         void recvPostProcessingGlobalAttributes(CBufferIn& buffer);
[697]191         static void recvRegistry(CEventServer& event) ;
[983]192         void recvRegistry(CBufferIn& buffer) ; //!< registry is received by the servers
[509]193
[1130]194         void freeComms(void);                  //!< Free internally allcoated communicators
195         void releaseClientBuffers(void);       //! Deallocate buffers allocated by clientContexts
[1054]196
[509]197         // dispatch event
[549]198         static bool dispatchEvent(CEventServer& event);
[509]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);
[1761]223        int getServiceType(void) {return serviceType_;}
[509]224
[219]225      public :
[509]226         // Parse xml node and write all info into context
[219]227         virtual void parse(xml::CXMLNode & node);
228
[509]229         // Visualize a context
[219]230         virtual StdString toString(void) const;
[509]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
[1761]239         bool isProcessingEvent(void) {return isProcessingEvent_;}
240         bool setProcessingEvent(void) {isProcessingEvent_=true ;}
241         bool unsetProcessingEvent(void) {isProcessingEvent_=false ;}
[1054]242
[300]243      public :
[509]244         // Calendar of context
[1542]245         std::shared_ptr<CCalendar>   calendar;
[509]246
[598]247         // List of all enabled files (files on which fields are written or read)
[347]248         std::vector<CFile*> enabledFiles;
[598]249         // List of all enabled files in read mode (files on which fields are read)
250         std::vector<CFile*> enabledReadModeFiles;
[1208]251         // List of all enabled files in write mode
252         std::vector<CFile*> enabledWriteModeFiles;
[509]253
[740]254         // List of all enabled fields whose instant data is accessible from the public API
255         // but which are not part of a file
[593]256         std::vector<CField*> fieldsWithReadAccess;
257
[509]258         // Context root
[1542]259         static std::shared_ptr<CContextGroup> root;
[219]260
[509]261         // Determine context on client or not
[549]262         bool hasClient;
[300]263
[509]264         // Determine context on server or not
[549]265         bool hasServer;
[509]266
[1130]267         CContextServer* server;    //!< Concrete context server
268         CContextClient* client;    //!< Concrete contex client
[1071]269         std::vector<CContextServer*> serverPrimServer;
270         std::vector<CContextClient*> clientPrimServer;
[1761]271         std::vector<std::string> primServerId_;
[1071]272
[1130]273         CRegistry* registryIn ;    //!< input registry which is read from file
274         CRegistry* registryOut ;   //!< output registry which will be written into file at the finalize
[775]275
[1761]276
277        MPI_Comm intraComm_ ; //! context intra communicator
278
[509]279      private:
280         bool isPostProcessed;
[1025]281         bool allProcessed;
[1139]282         bool finalized;
[1130]283         int countChildCtx_;        //!< Counter of child contexts (for now it is the number of secondary server pools)
[511]284         StdString idServer_;
[639]285         CGarbageCollector garbageCollector;
[1639]286         std::list<MPI_Comm> comms; //!< Communicators allocated internally
[509]287
[1761]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
[509]293      public: // Some function maybe removed in the near future
294        // virtual void toBinary  (StdOStream & os) const;
295        // virtual void fromBinary(StdIStream & is);
[219]296   }; // class CContext
297
298   ///--------------------------------------------------------------
299
300   // Declare/Define CContextGroup and CContextDefinition
301   DECLARE_GROUP(CContext);
302
303   ///--------------------------------------------------------------
304
[335]305} // namespace xios
[219]306
[591]307#endif // __XIOS_CContext__
Note: See TracBrowser for help on using the repository browser.