source: XIOS/trunk/src/node/field.hpp @ 310

Last change on this file since 310 was 310, checked in by ymipsl, 12 years ago

Add xios_field_is_active functionnality

YM

File size: 7.0 KB
Line 
1#ifndef __XMLIO_CField__
2#define __XMLIO_CField__
3
4/// xmlioserver headers ///
5#include "xmlioserver_spl.hpp"
6#include "group_factory.hpp"
7#include "functor.hpp"
8#include "functor_type.hpp"
9#include "duration.hpp"
10#include "date.hpp"
11#include "declare_group.hpp"
12#include "calendar_util.hpp"
13//#include "context.hpp"
14
15
16namespace xmlioserver {
17namespace tree {
18   
19   /// ////////////////////// Déclarations ////////////////////// ///
20
21   class CFieldGroup;
22   class CFieldAttributes;
23   class CField;
24
25   class CFile;
26   class CGrid;
27   class CContext ;
28   ///--------------------------------------------------------------
29
30   // Declare/Define CFieldAttribute
31   BEGIN_DECLARE_ATTRIBUTE_MAP(CField)
32#  include "field_attribute.conf"
33   END_DECLARE_ATTRIBUTE_MAP(CField)
34
35   ///--------------------------------------------------------------
36   class CField
37      : public CObjectTemplate<CField>
38      , public CFieldAttributes
39   {
40         /// friend ///
41         friend class CFile;
42
43         /// typedef ///
44         typedef CObjectTemplate<CField>   SuperClass;
45         typedef CFieldAttributes SuperClassAttribute;
46
47      public :
48
49         typedef CFieldAttributes RelAttributes;
50         typedef CFieldGroup      RelGroup;
51
52         enum EEventId
53         {
54           EVENT_ID_UPDATE_DATA
55         } ;
56         
57         /// Constructeurs ///
58         CField(void);
59         explicit CField(const StdString & id);
60         CField(const CField & field);       // Not implemented yet.
61         CField(const CField * const field); // Not implemented yet.
62
63         /// Accesseurs ///
64               boost::shared_ptr<CField> getDirectFieldReference(void) const;
65         const boost::shared_ptr<CField> getBaseFieldReference(void)   const;
66         const std::vector<boost::shared_ptr<CField> > & getAllReference(void) const;
67
68         boost::shared_ptr<CGrid> getRelGrid(void) const ;
69         boost::shared_ptr<CFile> getRelFile(void) const ;
70
71      public :
72
73         StdSize getNStep(void) const;
74
75         const date::CDuration & getFreqOperation(void) const;
76         const date::CDuration & getFreqWrite(void) const;
77
78         boost::shared_ptr<date::CDate> getLastWriteDate(void) const;
79         boost::shared_ptr<date::CDate> getLastOperationDate(void) const;
80
81         boost::shared_ptr<func::CFunctor> getFieldOperation(void) const;
82         
83         ARRAY(double, 1) getData(void) const;
84
85         const StdString & getBaseFieldId(void) const;
86
87         /// Mutateur ///
88         void setRelFile(const boost::shared_ptr<CFile> _file);
89         void incrementNStep(void);
90
91         template <StdSize N> bool updateData(const ARRAY(double, N)   data);
92         
93         bool updateDataServer
94               (const date::CDate & currDate,
95                const std::deque<ARRAY(double, 1)> storedClient);
96 
97       public :
98
99         /// Test ///
100         bool hasDirectFieldReference(void) const;
101         bool isActive(void) const;
102
103         /// Traitements ///
104         void solveRefInheritance(void);
105         void solveGridReference(void);
106         void solveOperation(void);
107
108         virtual void fromBinary(StdIStream & is);
109
110         /// Destructeur ///
111         virtual ~CField(void);
112
113         /// Accesseurs statiques ///
114         static StdString GetName(void);
115         static StdString GetDefName(void);
116         
117         static ENodeType GetType(void);
118         
119        template <StdSize N> void setData(const ARRAY(double, N) _data) ;
120        static bool dispatchEvent(CEventServer& event) ;
121        void sendUpdateData(void) ;
122        static void recvUpdateData(CEventServer& event) ;
123        void recvUpdateData(vector<int>& ranks, vector<CBufferIn*>& buffers) ;
124        void writeField(void) ;
125        void outputField(ARRAY(double,3) fieldOut) ;
126        void outputField(ARRAY(double,2) fieldOut) ;
127       
128      public :
129
130         /// Propriétés privées ///
131         
132         std::vector<boost::shared_ptr<CField> > refObject;
133         boost::shared_ptr<CField> baseRefObject;
134         boost::shared_ptr<CGrid>  grid ;
135         boost::shared_ptr<CFile>  file;
136
137         date::CDuration freq_operation, freq_write;
138         date::CDuration freq_operation_srv, freq_write_srv;
139
140         StdSize nstep;
141         boost::shared_ptr<date::CDate>    last_Write, last_operation;
142         boost::shared_ptr<date::CDate>    last_Write_srv, last_operation_srv;
143         
144         boost::shared_ptr<func::CFunctor> foperation;
145         map<int,boost::shared_ptr<func::CFunctor> > foperation_srv;
146         
147         ARRAY(double, 1) data;
148         map<int,ARRAY(double,1)> data_srv ;
149
150   }; // class CField
151
152   ///--------------------------------------------------------------
153
154   // Declare/Define CFieldGroup and CFieldDefinition
155   DECLARE_GROUP(CField);
156
157   } // namespace tree
158
159   ///-----------------------------------------------------------------
160
161   template <>
162      void CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void);
163
164   ///-----------------------------------------------------------------
165} // namespace xmlioserver
166
167#include "grid.hpp"
168
169namespace xmlioserver {
170namespace tree {
171
172   template <StdSize N>
173   void CField::setData(const ARRAY(double, N) _data)
174   {
175     const std::vector<boost::shared_ptr<CField> > & refField=getAllReference();
176     std::vector<boost::shared_ptr<CField> >::const_iterator  it = refField.begin(), end = refField.end();
177     
178     for (; it != end; it++) (*it)->updateData(_data) ;
179    }
180   
181   template <StdSize N>
182      bool CField::updateData(const ARRAY(double, N) _data)
183   {       
184      shared_ptr<CContext> context=CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId()) ;
185      const date::CDate & currDate = context->getCalendar()->getCurrentDate();
186      const date::CDate opeDate      = *last_operation + freq_operation;
187      const date::CDate writeDate    = *last_Write     + freq_write;       
188
189   
190      info(50) << "CField::updateData " << currDate <<  " : send data to " << this->getBaseFieldId() << std::endl;
191      info(50) << "Next operation "  << opeDate<<std::endl;
192
193      if (opeDate <= currDate)
194      {
195         if (this->data->num_elements() != this->grid->storeIndex_client->num_elements())
196         {
197            this->data->resize(boost::extents[this->grid->storeIndex_client ->num_elements()]);
198         }
199           
200         ARRAY_CREATE(input, double, 1, [this->data->num_elements()]);
201         this->grid->inputField(_data, input);         
202         (*this->foperation)(input);
203         
204         *last_operation = currDate;
205         info(50) << "(*last_operation = currDate) : " << *last_operation << " = " << currDate << std::endl; 
206      }
207     
208      if (writeDate < (currDate + freq_operation))
209      {
210         this->foperation->final();
211         *last_Write = writeDate;
212         info(50) << "(*last_Write = currDate) : " << *last_Write << " = " << currDate  << std::endl;
213         sendUpdateData() ;
214         return (true);       
215      }
216
217      return (false);
218   }
219
220} // namespace tree
221} // namespace xmlioserver
222
223#endif // __XMLIO_CField__
Note: See TracBrowser for help on using the repository browser.