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[ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /externals/g4tools/include/toolx/hdf5/store (Version 11.3.0) and /externals/g4tools/include/toolx/hdf5/store (Version 10.2)


  1 // Copyright (C) 2010, Guy Barrand. All rights    
  2 // See the file tools.license for terms.          
  3                                                   
  4 #ifndef toolx_hdf5_store                          
  5 #define toolx_hdf5_store                          
  6                                                   
  7 #include "pages"                                  
  8                                                   
  9 #include <tools/vmanip>                           
 10 #include <tools/sout>                             
 11                                                   
 12 namespace toolx {                                 
 13 namespace hdf5 {                                  
 14                                                   
 15 class store {                                     
 16 public:                                           
 17   TOOLS_SCLASS(toolx::hdf5::store)                
 18 public:                                           
 19   store(std::ostream& a_out,hid_t a_group,cons    
 20   :m_out(a_out)                                   
 21   ,m_write(a_write)                               
 22   ,m_compress(a_compress) //used at write.        
 23   ,m_group(-1)                                    
 24   {                                               
 25 #ifdef TOOLS_MEM                                  
 26     tools::mem::increment(s_class().c_str());     
 27 #endif                                            
 28     if(m_write) {                                 
 29       if(a_name.empty()) {                        
 30         a_out << "toolx::hdf5::store::store :     
 31         m_group = -1;                             
 32         return;                                   
 33       }                                           
 34       m_group = toolx_H5Gcreate(a_group,a_name    
 35       if(m_group<0) {                             
 36         a_out << "toolx::hdf5::store::store :     
 37         m_group = -1;                             
 38         return;                                   
 39       }                                           
 40       if(!write_atb(m_group,"type","object"))     
 41         m_out << "toolx::hdf5::store::store :     
 42         ::H5Gclose(m_group);                      
 43         m_group = -1;                             
 44         return;                                   
 45       }                                           
 46       if(!write_atb(m_group,"class",s_class())    
 47         m_out << "toolx::hdf5::store::store :     
 48         ::H5Gclose(m_group);                      
 49         m_group = -1;                             
 50         return;                                   
 51       }                                           
 52       int v = 2; //1->2 add "type" atb.           
 53       if(!write_scalar_atb<int>(m_group,"versi    
 54         m_out << "toolx::hdf5::store::store :     
 55         ::H5Gclose(m_group);                      
 56         m_group = -1;                             
 57         return;                                   
 58       }                                           
 59     } else { // to read.                          
 60       m_group = toolx_H5Gopen(a_group,a_name.c    
 61       if(m_group<0) {                             
 62         a_out << "toolx::hdf5::store::store :     
 63         m_group = -1;                             
 64         return;                                   
 65       }                                           
 66       std::vector<std::string> names;             
 67       if(!read_array_string(m_group,s_names(),    
 68         m_out << "toolx::hdf5::store::store :     
 69         ::H5Gclose(m_group);                      
 70         m_group = -1;                             
 71   return;                                         
 72       }                                           
 73       std::vector<std::string> TFORMs;            
 74       if(!read_array_string(m_group,s_forms(),    
 75         m_out << "toolx::hdf5::store::store :     
 76         ::H5Gclose(m_group);                      
 77         m_group = -1;                             
 78   return;                                         
 79       }                                           
 80       if(names.size()!=TFORMs.size()) {           
 81         m_out << "toolx::hdf5::store::store :     
 82         m_out << "names :" << std::endl;          
 83        {tools_vforcit(std::string,names,it) m_    
 84         m_out << "TFORMs :" << std::endl;         
 85        {tools_vforcit(std::string,TFORMs,it) m    
 86         ::H5Gclose(m_group);                      
 87         m_group = -1;                             
 88   return;                                         
 89       }                                           
 90       for(size_t index=0;index<names.size();in    
 91         if(!create_pages(names[index],TFORMs[i    
 92           m_out << "toolx::hdf5::store::store     
 93               << tools::sout(names[index]) <<     
 94           tools::safe_clear(m_pagess);            
 95           ::H5Gclose(m_group);                    
 96           m_group = -1;                           
 97           return;                                 
 98         }                                         
 99       }                                           
100     }                                             
101   }                                               
102   virtual ~store(){                               
103     if(m_write) {                                 
104       tools::uint64 _entries;                     
105       if(!entries(_entries)) {                    
106         m_out << "toolx::hdf5::store::~store :    
107       }                                           
108       if(m_group<0) { //constructor may have f    
109       } else {                                    
110         if(!write_scalar<tools::uint64>(m_grou    
111           m_out << "toolx::hdf5::store::~store    
112         }                                         
113         if(!write_scalar<unsigned int>(m_group    
114           m_out << "toolx::hdf5::store::~store    
115         }                                         
116        {std::vector<std::string> names;           
117         tools_vforcit(pages*,m_pagess,it) name    
118      //{m_out << "debug : write : names :" <<     
119      // tools_vforcit(std::string,names,it) m_    
120         if(!write_array_string(m_group,s_names    
121           m_out << "toolx::hdf5::store::~store    
122         }}                                        
123        {std::vector<std::string> TFORMs;          
124         tools_vforcit(pages*,m_pagess,it) TFOR    
125      //{m_out << "debug : write : TFORMs :" <<    
126      // tools_vforcit(std::string,TFORMs,it) m    
127         if(!write_array_string(m_group,s_forms    
128           m_out << "toolx::hdf5::store::~store    
129         }}                                        
130       }                                           
131     }                                             
132     tools::safe_clear(m_pagess);                  
133     if(m_group<0) { //constructor may have fai    
134     } else {                                      
135       ::H5Gclose(m_group);                        
136     }                                             
137 #ifdef TOOLS_MEM                                  
138     tools::mem::decrement(s_class().c_str());     
139 #endif                                            
140   }                                               
141 protected:                                        
142   store(const store& a_from)                      
143   :m_out(a_from.m_out)                            
144   ,m_name(a_from.m_name)                          
145   ,m_compress(a_from.m_compress)                  
146   ,m_group(-1)                                    
147   {                                               
148 #ifdef TOOLS_MEM                                  
149     tools::mem::increment(s_class().c_str());     
150 #endif                                            
151   }                                               
152   store& operator=(const store&){return *this;    
153 public:                                           
154   std::ostream& out() const {return m_out;}       
155   //bool fill(tools::uint32 &a_n){a_n = 0;retu    
156                                                   
157   bool entries(tools::uint64& a_entries) const    
158     if(m_pagess.empty()) {a_entries = 0;return    
159     a_entries = m_pagess.front()->entries();      
160     tools_vforcit(pages*,m_pagess,it) {           
161       if((*it)->entries()!=a_entries) {           
162         m_out << "toolx::hdf5::store::entries     
163         << " Front " << a_entries << ", it " <    
164         a_entries = 0;                            
165   return false;                                   
166       }                                           
167     }                                             
168     return true;                                  
169   }                                               
170                                                   
171   pages* create_pages(const std::string& a_nam    
172     //::printf("debug : create_pages %s %s\n",    
173     pages* _pages = new pages(m_out,m_group,a_    
174     if(!_pages->is_valid()) {                     
175       m_out << "toolx::hdf5::store::create_col    
176       delete _pages;                              
177       return 0;                                   
178     }                                             
179     m_pagess.push_back(_pages);                   
180     return _pages;                                
181   }                                               
182   /*                                              
183   pages* find_column(unsigned int a_index) {      
184     if(a_index>=m_pagess.size()) {                
185       m_out << "toolx::hdf5::store::find_colum    
186       return 0;                                   
187     }                                             
188     return m_pagess[a_index];                     
189   }                                               
190   const std::vector<pages*>& columns() const {    
191                                                   
192   hid_t group() const {return m_group;}           
193   unsigned int compress_level() const {return     
194 protected:                                        
195   std::ostream& m_out;                            
196   std::string m_name;                             
197   bool m_write;                                   
198   unsigned int m_compress;                        
199   hid_t m_group;                                  
200   std::vector<pages*> m_pagess;                   
201 };                                                
202                                                   
203 }}                                                
204                                                   
205 #endif