Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights 1 // Copyright (C) 2010, Guy Barrand. All rights reserved. 2 // See the file tools.license for terms. 2 // See the file tools.license for terms. 3 3 4 #ifndef tools_rroot_THistogram 4 #ifndef tools_rroot_THistogram 5 #define tools_rroot_THistogram 5 #define tools_rroot_THistogram 6 6 7 // to read some files produced with BatchLab ( 7 // to read some files produced with BatchLab (opaw/examples/osc/analysis.root). 8 8 9 #include "../histo/profile_data" 9 #include "../histo/profile_data" 10 10 11 #include "named" 11 #include "named" 12 #include "../vmanip" 12 #include "../vmanip" 13 13 14 namespace tools { 14 namespace tools { 15 namespace rroot { 15 namespace rroot { 16 16 17 //typedef histo::histo_data<double,unsigned in 17 //typedef histo::histo_data<double,unsigned int,double> hd_data; 18 typedef histo::profile_data<double,unsigned in 18 typedef histo::profile_data<double,unsigned int,unsigned int,double,double> pd_data_t; 19 typedef histo::axis<double,unsigned int> axis_ 19 typedef histo::axis<double,unsigned int> axis_t; 20 typedef std::map<std::string,std::string> anno 20 typedef std::map<std::string,std::string> annotations_t; 21 21 22 inline bool Axis_read_v0_v3(buffer& a_buffer,a 22 inline bool Axis_read_v0_v3(buffer& a_buffer,axis_t& a_axis) { 23 int idummy; 23 int idummy; 24 double ddummy; 24 double ddummy; 25 if(!a_buffer.read(a_axis.m_minimum_value)) r 25 if(!a_buffer.read(a_axis.m_minimum_value)) return false; 26 if(!a_buffer.read(a_axis.m_maximum_value)) r 26 if(!a_buffer.read(a_axis.m_maximum_value)) return false; 27 if(!a_buffer.read(a_axis.m_offset)) return f 27 if(!a_buffer.read(a_axis.m_offset)) return false; 28 if(!a_buffer.read(a_axis.m_number_of_bins)) 28 if(!a_buffer.read(a_axis.m_number_of_bins)) return false; 29 if(!a_buffer.read(idummy)) return false; //f 29 if(!a_buffer.read(idummy)) return false; //fOverFlow 30 if(!a_buffer.read(idummy)) return false; //f 30 if(!a_buffer.read(idummy)) return false; //fUnderFlow 31 if(!a_buffer.read(a_axis.m_bin_width)) retur 31 if(!a_buffer.read(a_axis.m_bin_width)) return false; 32 if(!a_buffer.read(ddummy)) return false; //f 32 if(!a_buffer.read(ddummy)) return false; //fSxw 33 if(!a_buffer.read(ddummy)) return false; //f 33 if(!a_buffer.read(ddummy)) return false; //fSx2w 34 a_axis.m_fixed = true; 34 a_axis.m_fixed = true; 35 a_axis.m_edges.clear(); 35 a_axis.m_edges.clear(); 36 return true; 36 return true; 37 } 37 } 38 38 39 inline bool Axis_read_v4_v6(buffer& a_buffer,a 39 inline bool Axis_read_v4_v6(buffer& a_buffer,axis_t& a_axis) { 40 int idummy; 40 int idummy; 41 double ddummy; 41 double ddummy; 42 if(!a_buffer.read(a_axis.m_offset)) return f 42 if(!a_buffer.read(a_axis.m_offset)) return false; 43 if(!a_buffer.read(idummy)) return false; //f 43 if(!a_buffer.read(idummy)) return false; //fOverFlow 44 if(!a_buffer.read(idummy)) return false; //f 44 if(!a_buffer.read(idummy)) return false; //fUnderFlow 45 if(!a_buffer.read(ddummy)) return false; //f 45 if(!a_buffer.read(ddummy)) return false; //fSxw 46 if(!a_buffer.read(ddummy)) return false; //f 46 if(!a_buffer.read(ddummy)) return false; //fSx2w 47 if(!a_buffer.read(a_axis.m_number_of_bins)) 47 if(!a_buffer.read(a_axis.m_number_of_bins)) return false; 48 if(!a_buffer.read(a_axis.m_minimum_value)) r 48 if(!a_buffer.read(a_axis.m_minimum_value)) return false; 49 if(!a_buffer.read(a_axis.m_maximum_value)) r 49 if(!a_buffer.read(a_axis.m_maximum_value)) return false; 50 if(!a_buffer.read(a_axis.m_fixed)) return fa 50 if(!a_buffer.read(a_axis.m_fixed)) return false; 51 if(!a_buffer.read(a_axis.m_bin_width)) retur 51 if(!a_buffer.read(a_axis.m_bin_width)) return false; 52 int edgen; 52 int edgen; 53 if(!a_buffer.read(edgen)) return false; 53 if(!a_buffer.read(edgen)) return false; 54 for(int count=0;count<edgen;count++) { 54 for(int count=0;count<edgen;count++) { 55 double value; 55 double value; 56 if(!a_buffer.read(value)) return false; 56 if(!a_buffer.read(value)) return false; 57 a_axis.m_edges.push_back(value); 57 a_axis.m_edges.push_back(value); 58 } 58 } 59 return true; 59 return true; 60 } 60 } 61 61 62 inline bool Axis_read_v7(buffer& a_buffer,axis 62 inline bool Axis_read_v7(buffer& a_buffer,axis_t& a_axis) { 63 if(!a_buffer.read(a_axis.m_offset)) return f 63 if(!a_buffer.read(a_axis.m_offset)) return false; 64 if(!a_buffer.read(a_axis.m_number_of_bins)) 64 if(!a_buffer.read(a_axis.m_number_of_bins)) return false; 65 if(!a_buffer.read(a_axis.m_minimum_value)) r 65 if(!a_buffer.read(a_axis.m_minimum_value)) return false; 66 if(!a_buffer.read(a_axis.m_maximum_value)) r 66 if(!a_buffer.read(a_axis.m_maximum_value)) return false; 67 if(!a_buffer.read(a_axis.m_fixed)) return fa 67 if(!a_buffer.read(a_axis.m_fixed)) return false; 68 if(!a_buffer.read(a_axis.m_bin_width)) retur 68 if(!a_buffer.read(a_axis.m_bin_width)) return false; 69 int edgen; 69 int edgen; 70 if(!a_buffer.read(edgen)) return false; 70 if(!a_buffer.read(edgen)) return false; 71 for(int count=0;count<edgen;count++) { 71 for(int count=0;count<edgen;count++) { 72 double value; 72 double value; 73 if(!a_buffer.read(value)) return false; 73 if(!a_buffer.read(value)) return false; 74 a_axis.m_edges.push_back(value); 74 a_axis.m_edges.push_back(value); 75 } 75 } 76 return true; 76 return true; 77 } 77 } 78 78 79 inline unsigned int new_bin_number(const std:: 79 inline unsigned int new_bin_number(const std::vector< axis_t >& aAxes) { 80 unsigned int number = 1; 80 unsigned int number = 1; 81 for(unsigned int iaxis=0;iaxis<aAxes.size(); 81 for(unsigned int iaxis=0;iaxis<aAxes.size();iaxis++) 82 number *= (aAxes[iaxis].bins()+2); 82 number *= (aAxes[iaxis].bins()+2); 83 return number; 83 return number; 84 } 84 } 85 85 86 template <class T> 86 template <class T> 87 inline void add_outflow(const std::vector< axi 87 inline void add_outflow(const std::vector< axis_t >& aAxes,std::vector<T>& aVector) { 88 // aAxes[].m_offset contains the offset with 88 // aAxes[].m_offset contains the offset without outflow. 89 std::size_t dim = aAxes.size(); 89 std::size_t dim = aAxes.size(); 90 // new size and offsets : 90 // new size and offsets : 91 std::vector<int> aoff(dim); 91 std::vector<int> aoff(dim); 92 92 93 int newn = 1; 93 int newn = 1; 94 {for(unsigned iaxis=0;iaxis<dim;iaxis++) newn 94 {for(unsigned iaxis=0;iaxis<dim;iaxis++) newn *= (aAxes[iaxis].bins()+2);} 95 95 96 aoff[0] = 1; 96 aoff[0] = 1; 97 {for(unsigned iaxis=1;iaxis<dim;iaxis++) { 97 {for(unsigned iaxis=1;iaxis<dim;iaxis++) { 98 aoff[iaxis] = aoff[iaxis-1] * (aAxes[iaxis 98 aoff[iaxis] = aoff[iaxis-1] * (aAxes[iaxis-1].bins()+2); 99 }} 99 }} 100 // copy : 100 // copy : 101 std::vector<T> tmp = aVector; 101 std::vector<T> tmp = aVector; 102 int oldn = (int)tmp.size(); 102 int oldn = (int)tmp.size(); 103 aVector.resize(newn,0); 103 aVector.resize(newn,0); 104 // Copy : 104 // Copy : 105 std::vector<int> is(dim); 105 std::vector<int> is(dim); 106 int offset; 106 int offset; 107 for(int index=0;index<oldn;index++) { 107 for(int index=0;index<oldn;index++) { 108 // Get new offset of index : 108 // Get new offset of index : 109 offset = index; 109 offset = index; 110 {for(int iaxis=(int)dim-1;iaxis>=0;iaxis--) 110 {for(int iaxis=(int)dim-1;iaxis>=0;iaxis--) { 111 is[iaxis] = offset/aAxes[iaxis].m_offset 111 is[iaxis] = offset/aAxes[iaxis].m_offset; 112 offset -= is[iaxis] * aAxes[iaxis].m_off 112 offset -= is[iaxis] * aAxes[iaxis].m_offset; 113 }} 113 }} 114 // new offset : 114 // new offset : 115 offset = 0; 115 offset = 0; 116 {for(std::size_t iaxis=0;iaxis<dim;iaxis++) 116 {for(std::size_t iaxis=0;iaxis<dim;iaxis++) offset += is[iaxis] * aoff[iaxis];} 117 aVector[offset] = tmp[index]; 117 aVector[offset] = tmp[index]; 118 } 118 } 119 } 119 } 120 120 121 inline void add_outflow(std::vector< axis_t >& 121 inline void add_outflow(std::vector< axis_t >& aAxes) { 122 // Restore new offsets : 122 // Restore new offsets : 123 aAxes[0].m_offset = 1; 123 aAxes[0].m_offset = 1; 124 for(unsigned int iaxis=1;iaxis<aAxes.size(); 124 for(unsigned int iaxis=1;iaxis<aAxes.size();iaxis++) 125 aAxes[iaxis].m_offset = aAxes[iaxis-1].m_o 125 aAxes[iaxis].m_offset = aAxes[iaxis-1].m_offset * (aAxes[iaxis-1].bins()+2); 126 } 126 } 127 127 128 inline bool read_v0(buffer& a_buffer,pd_data_t 128 inline bool read_v0(buffer& a_buffer,pd_data_t& a_data) { 129 int idummy; 129 int idummy; 130 double ddummy; 130 double ddummy; 131 std::string sdummy; 131 std::string sdummy; 132 if(!a_buffer.read(sdummy)) return false; 132 if(!a_buffer.read(sdummy)) return false; 133 if(!a_buffer.read(a_data.m_title)) return fa 133 if(!a_buffer.read(a_data.m_title)) return false; 134 134 135 {int dim; 135 {int dim; 136 if(!a_buffer.read(dim)) return false; 136 if(!a_buffer.read(dim)) return false; 137 a_data.m_dimension = dim;} 137 a_data.m_dimension = dim;} 138 138 139 {int nbin; 139 {int nbin; 140 if(!a_buffer.read(nbin)) return false; 140 if(!a_buffer.read(nbin)) return false; 141 a_data.m_bin_number = nbin;} 141 a_data.m_bin_number = nbin;} 142 142 143 if(!a_buffer.read(idummy)) return false; //f 143 if(!a_buffer.read(idummy)) return false; //fEntries 144 if(!a_buffer.read(idummy)) return false; //f 144 if(!a_buffer.read(idummy)) return false; //fOutFlow 145 if(!a_buffer.read(ddummy)) return false; //f 145 if(!a_buffer.read(ddummy)) return false; //fSw 146 146 147 std::vector<int> vec; 147 std::vector<int> vec; 148 if(!a_buffer.read_array<int>(vec)) return fa 148 if(!a_buffer.read_array<int>(vec)) return false; 149 convert<int,unsigned int>(vec,a_data.m_bin_e 149 convert<int,unsigned int>(vec,a_data.m_bin_entries); 150 150 151 if(a_data.m_bin_entries.size()!=a_data.m_bin 151 if(a_data.m_bin_entries.size()!=a_data.m_bin_number) return false; 152 if(!a_buffer.read_array<double>(a_data.m_bin 152 if(!a_buffer.read_array<double>(a_data.m_bin_Sw)) return false; 153 if(a_data.m_bin_Sw.size()!=a_data.m_bin_numb 153 if(a_data.m_bin_Sw.size()!=a_data.m_bin_number) return false; 154 if(!a_buffer.read_array<double>(a_data.m_bin 154 if(!a_buffer.read_array<double>(a_data.m_bin_Sw2)) return false; 155 if(a_data.m_bin_Sw2.size()!=a_data.m_bin_num 155 if(a_data.m_bin_Sw2.size()!=a_data.m_bin_number) return false; 156 if(a_data.m_dimension>0) { 156 if(a_data.m_dimension>0) { 157 a_data.m_axes.resize(a_data.m_dimension); 157 a_data.m_axes.resize(a_data.m_dimension); 158 for(unsigned int iaxis=0;iaxis<a_data.m_di 158 for(unsigned int iaxis=0;iaxis<a_data.m_dimension;iaxis++) { 159 if(!Axis_read_v0_v3(a_buffer,a_data.m_ax 159 if(!Axis_read_v0_v3(a_buffer,a_data.m_axes[iaxis])) return false; 160 } 160 } 161 } 161 } 162 axis_t axisOfValues; 162 axis_t axisOfValues; 163 if(!Axis_read_v0_v3(a_buffer,axisOfValues)) 163 if(!Axis_read_v0_v3(a_buffer,axisOfValues)) return false; 164 {int dummy; 164 {int dummy; 165 if(!a_buffer.read(dummy)) return false;} //m 165 if(!a_buffer.read(dummy)) return false;} //m_mode 166 166 167 // Add outflow : 167 // Add outflow : 168 a_data.m_bin_number = new_bin_number(a_data. 168 a_data.m_bin_number = new_bin_number(a_data.m_axes); 169 add_outflow<unsigned int>(a_data.m_axes,a_da 169 add_outflow<unsigned int>(a_data.m_axes,a_data.m_bin_entries); 170 add_outflow<double>(a_data.m_axes,a_data.m_b 170 add_outflow<double>(a_data.m_axes,a_data.m_bin_Sw); 171 add_outflow<double>(a_data.m_axes,a_data.m_b 171 add_outflow<double>(a_data.m_axes,a_data.m_bin_Sw2); 172 add_outflow(a_data.m_axes); 172 add_outflow(a_data.m_axes); 173 173 174 // Not here in v0 : 174 // Not here in v0 : 175 std::vector<double> empty; 175 std::vector<double> empty; 176 empty.resize(a_data.m_dimension,0); 176 empty.resize(a_data.m_dimension,0); 177 a_data.m_bin_Sxw.resize(a_data.m_bin_number, 177 a_data.m_bin_Sxw.resize(a_data.m_bin_number,empty); 178 a_data.m_bin_Sx2w.resize(a_data.m_bin_number 178 a_data.m_bin_Sx2w.resize(a_data.m_bin_number,empty); 179 a_data.m_is_profile = false; 179 a_data.m_is_profile = false; 180 a_data.m_bin_Svw.clear(); 180 a_data.m_bin_Svw.clear(); 181 a_data.m_bin_Sv2w.clear(); 181 a_data.m_bin_Sv2w.clear(); 182 182 183 return true; 183 return true; 184 } 184 } 185 185 186 inline bool read_v1(buffer& a_buffer,pd_data_t 186 inline bool read_v1(buffer& a_buffer,pd_data_t& a_data) { 187 int idummy; 187 int idummy; 188 double ddummy; 188 double ddummy; 189 if(!a_buffer.read(a_data.m_title)) return fa 189 if(!a_buffer.read(a_data.m_title)) return false; 190 190 191 {int dim; 191 {int dim; 192 if(!a_buffer.read(dim)) return false; 192 if(!a_buffer.read(dim)) return false; 193 a_data.m_dimension = dim;} 193 a_data.m_dimension = dim;} 194 194 195 {int nbin; 195 {int nbin; 196 if(!a_buffer.read(nbin)) return false; 196 if(!a_buffer.read(nbin)) return false; 197 a_data.m_bin_number = nbin;} 197 a_data.m_bin_number = nbin;} 198 198 199 if(!a_buffer.read(idummy)) return false; //f 199 if(!a_buffer.read(idummy)) return false; //fEntries 200 if(!a_buffer.read(idummy)) return false; //f 200 if(!a_buffer.read(idummy)) return false; //fOutFlow 201 if(!a_buffer.read(ddummy)) return false; //f 201 if(!a_buffer.read(ddummy)) return false; //fSw 202 202 203 std::vector<int> vec; 203 std::vector<int> vec; 204 if(!a_buffer.read_array<int>(vec)) return fa 204 if(!a_buffer.read_array<int>(vec)) return false; 205 convert<int,unsigned int>(vec,a_data.m_bin_e 205 convert<int,unsigned int>(vec,a_data.m_bin_entries); 206 206 207 if(a_data.m_bin_entries.size()!=a_data.m_bin 207 if(a_data.m_bin_entries.size()!=a_data.m_bin_number) return false; 208 if(!a_buffer.read_array<double>(a_data.m_bin 208 if(!a_buffer.read_array<double>(a_data.m_bin_Sw)) return false; 209 if(a_data.m_bin_Sw.size()!=a_data.m_bin_numb 209 if(a_data.m_bin_Sw.size()!=a_data.m_bin_number) return false; 210 if(!a_buffer.read_array<double>(a_data.m_bin 210 if(!a_buffer.read_array<double>(a_data.m_bin_Sw2)) return false; 211 if(a_data.m_bin_Sw2.size()!=a_data.m_bin_num 211 if(a_data.m_bin_Sw2.size()!=a_data.m_bin_number) return false; 212 if(a_data.m_dimension>0) { 212 if(a_data.m_dimension>0) { 213 a_data.m_axes.resize(a_data.m_dimension); 213 a_data.m_axes.resize(a_data.m_dimension); 214 for(unsigned int iaxis=0;iaxis<a_data.m_di 214 for(unsigned int iaxis=0;iaxis<a_data.m_dimension;iaxis++) { 215 if(!Axis_read_v0_v3(a_buffer,a_data.m_ax 215 if(!Axis_read_v0_v3(a_buffer,a_data.m_axes[iaxis])) return false; 216 } 216 } 217 } 217 } 218 axis_t axisOfValues; 218 axis_t axisOfValues; 219 if(!Axis_read_v0_v3(a_buffer,axisOfValues)) 219 if(!Axis_read_v0_v3(a_buffer,axisOfValues)) return false; 220 {int dummy; 220 {int dummy; 221 if(!a_buffer.read(dummy)) return false;} //m 221 if(!a_buffer.read(dummy)) return false;} //m_mode 222 222 223 // Add outflow : 223 // Add outflow : 224 a_data.m_bin_number = new_bin_number(a_data. 224 a_data.m_bin_number = new_bin_number(a_data.m_axes); 225 add_outflow<unsigned int>(a_data.m_axes,a_da 225 add_outflow<unsigned int>(a_data.m_axes,a_data.m_bin_entries); 226 add_outflow<double>(a_data.m_axes,a_data.m_b 226 add_outflow<double>(a_data.m_axes,a_data.m_bin_Sw); 227 add_outflow<double>(a_data.m_axes,a_data.m_b 227 add_outflow<double>(a_data.m_axes,a_data.m_bin_Sw2); 228 add_outflow(a_data.m_axes); 228 add_outflow(a_data.m_axes); 229 229 230 // Not here in v1 : 230 // Not here in v1 : 231 std::vector<double> empty; 231 std::vector<double> empty; 232 empty.resize(a_data.m_dimension,0); 232 empty.resize(a_data.m_dimension,0); 233 a_data.m_bin_Sxw.resize(a_data.m_bin_number, 233 a_data.m_bin_Sxw.resize(a_data.m_bin_number,empty); 234 a_data.m_bin_Sx2w.resize(a_data.m_bin_number 234 a_data.m_bin_Sx2w.resize(a_data.m_bin_number,empty); 235 a_data.m_is_profile = false; 235 a_data.m_is_profile = false; 236 a_data.m_bin_Svw.clear(); 236 a_data.m_bin_Svw.clear(); 237 a_data.m_bin_Sv2w.clear(); 237 a_data.m_bin_Sv2w.clear(); 238 238 239 return true; 239 return true; 240 } 240 } 241 241 242 inline bool read_v2(buffer& a_buffer,pd_data_t 242 inline bool read_v2(buffer& a_buffer,pd_data_t& a_data) { 243 int idummy; 243 int idummy; 244 double ddummy; 244 double ddummy; 245 std::string sdummy; 245 std::string sdummy; 246 if(!a_buffer.read(a_data.m_title)) return fa 246 if(!a_buffer.read(a_data.m_title)) return false; 247 if(!a_buffer.read(sdummy)) return false; 247 if(!a_buffer.read(sdummy)) return false; 248 248 249 {int dim; 249 {int dim; 250 if(!a_buffer.read(dim)) return false; 250 if(!a_buffer.read(dim)) return false; 251 a_data.m_dimension = dim;} 251 a_data.m_dimension = dim;} 252 252 253 {int nbin; 253 {int nbin; 254 if(!a_buffer.read(nbin)) return false; 254 if(!a_buffer.read(nbin)) return false; 255 a_data.m_bin_number = nbin;} 255 a_data.m_bin_number = nbin;} 256 256 257 if(!a_buffer.read(idummy)) return false; //f 257 if(!a_buffer.read(idummy)) return false; //fEntries 258 if(!a_buffer.read(idummy)) return false; //f 258 if(!a_buffer.read(idummy)) return false; //fOutFlow 259 if(!a_buffer.read(ddummy)) return false; //f 259 if(!a_buffer.read(ddummy)) return false; //fSw 260 260 261 std::vector<int> vec; 261 std::vector<int> vec; 262 if(!a_buffer.read_array<int>(vec)) return fa 262 if(!a_buffer.read_array<int>(vec)) return false; 263 convert<int,unsigned int>(vec,a_data.m_bin_e 263 convert<int,unsigned int>(vec,a_data.m_bin_entries); 264 264 265 if(a_data.m_bin_entries.size()!=a_data.m_bin 265 if(a_data.m_bin_entries.size()!=a_data.m_bin_number) return false; 266 if(!a_buffer.read_array<double>(a_data.m_bin 266 if(!a_buffer.read_array<double>(a_data.m_bin_Sw)) return false; 267 if(a_data.m_bin_Sw.size()!=a_data.m_bin_numb 267 if(a_data.m_bin_Sw.size()!=a_data.m_bin_number) return false; 268 if(!a_buffer.read_array<double>(a_data.m_bin 268 if(!a_buffer.read_array<double>(a_data.m_bin_Sw2)) return false; 269 if(a_data.m_bin_Sw2.size()!=a_data.m_bin_num 269 if(a_data.m_bin_Sw2.size()!=a_data.m_bin_number) return false; 270 if(a_data.m_dimension>0) { 270 if(a_data.m_dimension>0) { 271 a_data.m_axes.resize(a_data.m_dimension); 271 a_data.m_axes.resize(a_data.m_dimension); 272 for(unsigned int iaxis=0;iaxis<a_data.m_di 272 for(unsigned int iaxis=0;iaxis<a_data.m_dimension;iaxis++) { 273 if(!Axis_read_v0_v3(a_buffer,a_data.m_ax 273 if(!Axis_read_v0_v3(a_buffer,a_data.m_axes[iaxis])) return false; 274 } 274 } 275 } 275 } 276 axis_t axisOfValues; 276 axis_t axisOfValues; 277 if(!Axis_read_v0_v3(a_buffer,axisOfValues)) 277 if(!Axis_read_v0_v3(a_buffer,axisOfValues)) return false; 278 {int dummy; 278 {int dummy; 279 if(!a_buffer.read(dummy)) return false;} //m 279 if(!a_buffer.read(dummy)) return false;} //m_mode 280 280 281 // Add outflow : 281 // Add outflow : 282 a_data.m_bin_number = new_bin_number(a_data. 282 a_data.m_bin_number = new_bin_number(a_data.m_axes); 283 add_outflow<unsigned int>(a_data.m_axes,a_da 283 add_outflow<unsigned int>(a_data.m_axes,a_data.m_bin_entries); 284 add_outflow<double>(a_data.m_axes,a_data.m_b 284 add_outflow<double>(a_data.m_axes,a_data.m_bin_Sw); 285 add_outflow<double>(a_data.m_axes,a_data.m_b 285 add_outflow<double>(a_data.m_axes,a_data.m_bin_Sw2); 286 add_outflow(a_data.m_axes); 286 add_outflow(a_data.m_axes); 287 287 288 // Not here in v2 : 288 // Not here in v2 : 289 std::vector<double> empty; 289 std::vector<double> empty; 290 empty.resize(a_data.m_dimension,0); 290 empty.resize(a_data.m_dimension,0); 291 a_data.m_bin_Sxw.resize(a_data.m_bin_number, 291 a_data.m_bin_Sxw.resize(a_data.m_bin_number,empty); 292 a_data.m_bin_Sx2w.resize(a_data.m_bin_number 292 a_data.m_bin_Sx2w.resize(a_data.m_bin_number,empty); 293 a_data.m_is_profile = false; 293 a_data.m_is_profile = false; 294 a_data.m_bin_Svw.clear(); 294 a_data.m_bin_Svw.clear(); 295 a_data.m_bin_Sv2w.clear(); 295 a_data.m_bin_Sv2w.clear(); 296 296 297 return true; 297 return true; 298 } 298 } 299 299 300 inline bool read_v3(buffer& a_buffer,pd_data_t 300 inline bool read_v3(buffer& a_buffer,pd_data_t& a_data) { 301 int idummy; 301 int idummy; 302 double ddummy; 302 double ddummy; 303 303 304 int l; 304 int l; 305 if(!a_buffer.read(l)) return false; 305 if(!a_buffer.read(l)) return false; 306 char* str = new char[l+1]; 306 char* str = new char[l+1]; 307 for (int i = 0; i < l; i++) { 307 for (int i = 0; i < l; i++) { 308 if(!a_buffer.read(str[i])) { delete [] str 308 if(!a_buffer.read(str[i])) { delete [] str;return false;} 309 } 309 } 310 str[l] = '\0'; 310 str[l] = '\0'; 311 a_data.m_title = str; 311 a_data.m_title = str; 312 delete [] str; 312 delete [] str; 313 313 314 {int dim; 314 {int dim; 315 if(!a_buffer.read(dim)) return false; 315 if(!a_buffer.read(dim)) return false; 316 a_data.m_dimension = dim;} 316 a_data.m_dimension = dim;} 317 317 318 {int nbin; 318 {int nbin; 319 if(!a_buffer.read(nbin)) return false; 319 if(!a_buffer.read(nbin)) return false; 320 a_data.m_bin_number = nbin;} 320 a_data.m_bin_number = nbin;} 321 321 322 if(!a_buffer.read(idummy)) return false; //f 322 if(!a_buffer.read(idummy)) return false; //fEntries 323 if(!a_buffer.read(idummy)) return false; //f 323 if(!a_buffer.read(idummy)) return false; //fOutFlow 324 if(!a_buffer.read(ddummy)) return false; //f 324 if(!a_buffer.read(ddummy)) return false; //fSw 325 325 326 std::vector<int> vec; 326 std::vector<int> vec; 327 if(!a_buffer.read_array<int>(vec)) return fa 327 if(!a_buffer.read_array<int>(vec)) return false; 328 convert<int,unsigned int>(vec,a_data.m_bin_e 328 convert<int,unsigned int>(vec,a_data.m_bin_entries); 329 329 330 if(a_data.m_bin_entries.size()!=a_data.m_bin 330 if(a_data.m_bin_entries.size()!=a_data.m_bin_number) return false; 331 if(!a_buffer.read_array<double>(a_data.m_bin 331 if(!a_buffer.read_array<double>(a_data.m_bin_Sw)) return false; 332 if(a_data.m_bin_Sw.size()!=a_data.m_bin_numb 332 if(a_data.m_bin_Sw.size()!=a_data.m_bin_number) return false; 333 if(!a_buffer.read_array<double>(a_data.m_bin 333 if(!a_buffer.read_array<double>(a_data.m_bin_Sw2)) return false; 334 if(a_data.m_bin_Sw2.size()!=a_data.m_bin_num 334 if(a_data.m_bin_Sw2.size()!=a_data.m_bin_number) return false; 335 if(a_data.m_dimension>0) { 335 if(a_data.m_dimension>0) { 336 a_data.m_axes.resize(a_data.m_dimension); 336 a_data.m_axes.resize(a_data.m_dimension); 337 for(unsigned int iaxis=0;iaxis<a_data.m_di 337 for(unsigned int iaxis=0;iaxis<a_data.m_dimension;iaxis++) { 338 if(!Axis_read_v0_v3(a_buffer,a_data.m_ax 338 if(!Axis_read_v0_v3(a_buffer,a_data.m_axes[iaxis])) return false; 339 } 339 } 340 } 340 } 341 axis_t axisOfValues; 341 axis_t axisOfValues; 342 if(!Axis_read_v0_v3(a_buffer,axisOfValues)) 342 if(!Axis_read_v0_v3(a_buffer,axisOfValues)) return false; 343 {int dummy; 343 {int dummy; 344 if(!a_buffer.read(dummy)) return false;} //m 344 if(!a_buffer.read(dummy)) return false;} //m_mode 345 345 346 // Add outflow : 346 // Add outflow : 347 a_data.m_bin_number = new_bin_number(a_data. 347 a_data.m_bin_number = new_bin_number(a_data.m_axes); 348 add_outflow<unsigned int>(a_data.m_axes,a_da 348 add_outflow<unsigned int>(a_data.m_axes,a_data.m_bin_entries); 349 add_outflow<double>(a_data.m_axes,a_data.m_b 349 add_outflow<double>(a_data.m_axes,a_data.m_bin_Sw); 350 add_outflow<double>(a_data.m_axes,a_data.m_b 350 add_outflow<double>(a_data.m_axes,a_data.m_bin_Sw2); 351 add_outflow(a_data.m_axes); 351 add_outflow(a_data.m_axes); 352 352 353 // Not here in v3 : 353 // Not here in v3 : 354 std::vector<double> empty; 354 std::vector<double> empty; 355 empty.resize(a_data.m_dimension,0); 355 empty.resize(a_data.m_dimension,0); 356 a_data.m_bin_Sxw.resize(a_data.m_bin_number, 356 a_data.m_bin_Sxw.resize(a_data.m_bin_number,empty); 357 a_data.m_bin_Sx2w.resize(a_data.m_bin_number 357 a_data.m_bin_Sx2w.resize(a_data.m_bin_number,empty); 358 a_data.m_is_profile = false; 358 a_data.m_is_profile = false; 359 a_data.m_bin_Svw.clear(); 359 a_data.m_bin_Svw.clear(); 360 a_data.m_bin_Sv2w.clear(); 360 a_data.m_bin_Sv2w.clear(); 361 361 362 return true; 362 return true; 363 } 363 } 364 364 365 inline bool read_v4(buffer& a_buffer,pd_data_t 365 inline bool read_v4(buffer& a_buffer,pd_data_t& a_data) { 366 int idummy; 366 int idummy; 367 double ddummy; 367 double ddummy; 368 368 369 int l; 369 int l; 370 if(!a_buffer.read(l)) return false; 370 if(!a_buffer.read(l)) return false; 371 char* str = new char[l+1]; 371 char* str = new char[l+1]; 372 for (int i = 0; i < l; i++) { 372 for (int i = 0; i < l; i++) { 373 if(!a_buffer.read(str[i])) { delete [] str 373 if(!a_buffer.read(str[i])) { delete [] str;return false;} 374 } 374 } 375 str[l] = '\0'; 375 str[l] = '\0'; 376 a_data.m_title = str; 376 a_data.m_title = str; 377 delete [] str; 377 delete [] str; 378 378 379 {int dim; 379 {int dim; 380 if(!a_buffer.read(dim)) return false; 380 if(!a_buffer.read(dim)) return false; 381 a_data.m_dimension = dim;} 381 a_data.m_dimension = dim;} 382 382 383 {int nbin; 383 {int nbin; 384 if(!a_buffer.read(nbin)) return false; 384 if(!a_buffer.read(nbin)) return false; 385 a_data.m_bin_number = nbin;} 385 a_data.m_bin_number = nbin;} 386 386 387 if(!a_buffer.read(idummy)) return false; //f 387 if(!a_buffer.read(idummy)) return false; //fEntries 388 if(!a_buffer.read(idummy)) return false; //f 388 if(!a_buffer.read(idummy)) return false; //fOutFlow 389 if(!a_buffer.read(ddummy)) return false; //f 389 if(!a_buffer.read(ddummy)) return false; //fSw 390 390 391 std::vector<int> vec; 391 std::vector<int> vec; 392 if(!a_buffer.read_array<int>(vec)) return fa 392 if(!a_buffer.read_array<int>(vec)) return false; 393 convert<int,unsigned int>(vec,a_data.m_bin_e 393 convert<int,unsigned int>(vec,a_data.m_bin_entries); 394 394 395 if(a_data.m_bin_entries.size()!=a_data.m_bin 395 if(a_data.m_bin_entries.size()!=a_data.m_bin_number) return false; 396 if(!a_buffer.read_array<double>(a_data.m_bin 396 if(!a_buffer.read_array<double>(a_data.m_bin_Sw)) return false; 397 if(a_data.m_bin_Sw.size()!=a_data.m_bin_numb 397 if(a_data.m_bin_Sw.size()!=a_data.m_bin_number) return false; 398 if(!a_buffer.read_array<double>(a_data.m_bin 398 if(!a_buffer.read_array<double>(a_data.m_bin_Sw2)) return false; 399 if(a_data.m_bin_Sw2.size()!=a_data.m_bin_num 399 if(a_data.m_bin_Sw2.size()!=a_data.m_bin_number) return false; 400 if(a_data.m_dimension>0) { 400 if(a_data.m_dimension>0) { 401 a_data.m_axes.resize(a_data.m_dimension); 401 a_data.m_axes.resize(a_data.m_dimension); 402 for(unsigned int iaxis=0;iaxis<a_data.m_di 402 for(unsigned int iaxis=0;iaxis<a_data.m_dimension;iaxis++) { 403 if(!Axis_read_v4_v6(a_buffer,a_data.m_ax 403 if(!Axis_read_v4_v6(a_buffer,a_data.m_axes[iaxis])) return false; 404 } 404 } 405 } 405 } 406 {int dummy; 406 {int dummy; 407 if(!a_buffer.read(dummy)) return false;} //m 407 if(!a_buffer.read(dummy)) return false;} //m_mode 408 408 409 // Add outflow : 409 // Add outflow : 410 a_data.m_bin_number = new_bin_number(a_data. 410 a_data.m_bin_number = new_bin_number(a_data.m_axes); 411 add_outflow<unsigned int>(a_data.m_axes,a_da 411 add_outflow<unsigned int>(a_data.m_axes,a_data.m_bin_entries); 412 add_outflow<double>(a_data.m_axes,a_data.m_b 412 add_outflow<double>(a_data.m_axes,a_data.m_bin_Sw); 413 add_outflow<double>(a_data.m_axes,a_data.m_b 413 add_outflow<double>(a_data.m_axes,a_data.m_bin_Sw2); 414 add_outflow(a_data.m_axes); 414 add_outflow(a_data.m_axes); 415 415 416 // Not here in v4 : 416 // Not here in v4 : 417 std::vector<double> empty; 417 std::vector<double> empty; 418 empty.resize(a_data.m_dimension,0); 418 empty.resize(a_data.m_dimension,0); 419 a_data.m_bin_Sxw.resize(a_data.m_bin_number, 419 a_data.m_bin_Sxw.resize(a_data.m_bin_number,empty); 420 a_data.m_bin_Sx2w.resize(a_data.m_bin_number 420 a_data.m_bin_Sx2w.resize(a_data.m_bin_number,empty); 421 a_data.m_is_profile = false; 421 a_data.m_is_profile = false; 422 a_data.m_bin_Svw.clear(); 422 a_data.m_bin_Svw.clear(); 423 a_data.m_bin_Sv2w.clear(); 423 a_data.m_bin_Sv2w.clear(); 424 424 425 return true; 425 return true; 426 } 426 } 427 427 428 inline bool read_v5(buffer& a_buffer,pd_data_t 428 inline bool read_v5(buffer& a_buffer,pd_data_t& a_data) { 429 int idummy; 429 int idummy; 430 double ddummy; 430 double ddummy; 431 if(!a_buffer.read(a_data.m_title)) return fa 431 if(!a_buffer.read(a_data.m_title)) return false; 432 432 433 {int dim; 433 {int dim; 434 if(!a_buffer.read(dim)) return false; 434 if(!a_buffer.read(dim)) return false; 435 a_data.m_dimension = dim;} 435 a_data.m_dimension = dim;} 436 436 437 {int nbin; 437 {int nbin; 438 if(!a_buffer.read(nbin)) return false; 438 if(!a_buffer.read(nbin)) return false; 439 a_data.m_bin_number = nbin;} 439 a_data.m_bin_number = nbin;} 440 440 441 if(!a_buffer.read(idummy)) return false; //f 441 if(!a_buffer.read(idummy)) return false; //fEntries 442 if(!a_buffer.read(idummy)) return false; //f 442 if(!a_buffer.read(idummy)) return false; //fOutFlow 443 if(!a_buffer.read(ddummy)) return false; //f 443 if(!a_buffer.read(ddummy)) return false; //fSw 444 444 445 std::vector<int> vec; 445 std::vector<int> vec; 446 if(!a_buffer.read_array<int>(vec)) return fa 446 if(!a_buffer.read_array<int>(vec)) return false; 447 convert<int,unsigned int>(vec,a_data.m_bin_e 447 convert<int,unsigned int>(vec,a_data.m_bin_entries); 448 448 449 if(a_data.m_bin_entries.size()!=a_data.m_bin 449 if(a_data.m_bin_entries.size()!=a_data.m_bin_number) return false; 450 if(!a_buffer.read_array<double>(a_data.m_bin 450 if(!a_buffer.read_array<double>(a_data.m_bin_Sw)) return false; 451 if(a_data.m_bin_Sw.size()!=a_data.m_bin_numb 451 if(a_data.m_bin_Sw.size()!=a_data.m_bin_number) return false; 452 if(!a_buffer.read_array<double>(a_data.m_bin 452 if(!a_buffer.read_array<double>(a_data.m_bin_Sw2)) return false; 453 if(a_data.m_bin_Sw2.size()!=a_data.m_bin_num 453 if(a_data.m_bin_Sw2.size()!=a_data.m_bin_number) return false; 454 if(a_data.m_dimension>0) { 454 if(a_data.m_dimension>0) { 455 a_data.m_axes.resize(a_data.m_dimension); 455 a_data.m_axes.resize(a_data.m_dimension); 456 for(unsigned int iaxis=0;iaxis<a_data.m_di 456 for(unsigned int iaxis=0;iaxis<a_data.m_dimension;iaxis++) { 457 if(!Axis_read_v4_v6(a_buffer,a_data.m_ax 457 if(!Axis_read_v4_v6(a_buffer,a_data.m_axes[iaxis])) return false; 458 } 458 } 459 } 459 } 460 {int dummy; 460 {int dummy; 461 if(!a_buffer.read(dummy)) return false;} //m 461 if(!a_buffer.read(dummy)) return false;} //m_mode 462 462 463 // Add outflow : 463 // Add outflow : 464 a_data.m_bin_number = new_bin_number(a_data. 464 a_data.m_bin_number = new_bin_number(a_data.m_axes); 465 add_outflow<unsigned int>(a_data.m_axes,a_da 465 add_outflow<unsigned int>(a_data.m_axes,a_data.m_bin_entries); 466 add_outflow<double>(a_data.m_axes,a_data.m_b 466 add_outflow<double>(a_data.m_axes,a_data.m_bin_Sw); 467 add_outflow<double>(a_data.m_axes,a_data.m_b 467 add_outflow<double>(a_data.m_axes,a_data.m_bin_Sw2); 468 add_outflow(a_data.m_axes); 468 add_outflow(a_data.m_axes); 469 469 470 // Not here in v5 : 470 // Not here in v5 : 471 std::vector<double> empty; 471 std::vector<double> empty; 472 empty.resize(a_data.m_dimension,0); 472 empty.resize(a_data.m_dimension,0); 473 a_data.m_bin_Sxw.resize(a_data.m_bin_number, 473 a_data.m_bin_Sxw.resize(a_data.m_bin_number,empty); 474 a_data.m_bin_Sx2w.resize(a_data.m_bin_number 474 a_data.m_bin_Sx2w.resize(a_data.m_bin_number,empty); 475 a_data.m_is_profile = false; 475 a_data.m_is_profile = false; 476 a_data.m_bin_Svw.clear(); 476 a_data.m_bin_Svw.clear(); 477 a_data.m_bin_Sv2w.clear(); 477 a_data.m_bin_Sv2w.clear(); 478 478 479 return true; 479 return true; 480 } 480 } 481 481 482 inline bool read_v6(buffer& a_buffer,pd_data_t 482 inline bool read_v6(buffer& a_buffer,pd_data_t& a_data) { 483 int idummy; 483 int idummy; 484 double ddummy; 484 double ddummy; 485 if(!a_buffer.read(a_data.m_title)) return fa 485 if(!a_buffer.read(a_data.m_title)) return false; 486 486 487 {int dim; 487 {int dim; 488 if(!a_buffer.read(dim)) return false; 488 if(!a_buffer.read(dim)) return false; 489 a_data.m_dimension = dim;} 489 a_data.m_dimension = dim;} 490 490 491 {int nbin; 491 {int nbin; 492 if(!a_buffer.read(nbin)) return false; 492 if(!a_buffer.read(nbin)) return false; 493 a_data.m_bin_number = nbin;} 493 a_data.m_bin_number = nbin;} 494 494 495 if(!a_buffer.read(idummy)) return false; //f 495 if(!a_buffer.read(idummy)) return false; //fEntries 496 if(!a_buffer.read(idummy)) return false; //f 496 if(!a_buffer.read(idummy)) return false; //fOutFlow 497 if(!a_buffer.read(ddummy)) return false; //f 497 if(!a_buffer.read(ddummy)) return false; //fSw 498 498 499 std::vector<int> vec; 499 std::vector<int> vec; 500 if(!a_buffer.read_array<int>(vec)) return fa 500 if(!a_buffer.read_array<int>(vec)) return false; 501 convert<int,unsigned int>(vec,a_data.m_bin_e 501 convert<int,unsigned int>(vec,a_data.m_bin_entries); 502 502 503 if(a_data.m_bin_entries.size()!=a_data.m_bin 503 if(a_data.m_bin_entries.size()!=a_data.m_bin_number) return false; 504 if(!a_buffer.read_array<double>(a_data.m_bin 504 if(!a_buffer.read_array<double>(a_data.m_bin_Sw)) return false; 505 if(a_data.m_bin_Sw.size()!=a_data.m_bin_numb 505 if(a_data.m_bin_Sw.size()!=a_data.m_bin_number) return false; 506 if(!a_buffer.read_array<double>(a_data.m_bin 506 if(!a_buffer.read_array<double>(a_data.m_bin_Sw2)) return false; 507 if(a_data.m_bin_Sw2.size()!=a_data.m_bin_num 507 if(a_data.m_bin_Sw2.size()!=a_data.m_bin_number) return false; 508 if(a_data.m_dimension>0) { 508 if(a_data.m_dimension>0) { 509 a_data.m_axes.resize(a_data.m_dimension); 509 a_data.m_axes.resize(a_data.m_dimension); 510 for(unsigned int iaxis=0;iaxis<a_data.m_di 510 for(unsigned int iaxis=0;iaxis<a_data.m_dimension;iaxis++) { 511 if(!Axis_read_v4_v6(a_buffer,a_data.m_ax 511 if(!Axis_read_v4_v6(a_buffer,a_data.m_axes[iaxis])) return false; 512 } 512 } 513 } 513 } 514 {int dummy; 514 {int dummy; 515 if(!a_buffer.read(dummy)) return false;} //m 515 if(!a_buffer.read(dummy)) return false;} //m_mode 516 516 517 // Profile : 517 // Profile : 518 if(!a_buffer.read(a_data.m_is_profile)) retu 518 if(!a_buffer.read(a_data.m_is_profile)) return false; 519 if(a_data.m_is_profile) { 519 if(a_data.m_is_profile) { 520 if(!a_buffer.read_array<double>(a_data.m_b 520 if(!a_buffer.read_array<double>(a_data.m_bin_Svw)) return false; 521 if(a_data.m_bin_Svw.size()!=a_data.m_bin_n 521 if(a_data.m_bin_Svw.size()!=a_data.m_bin_number) return false; 522 if(!a_buffer.read(a_data.m_cut_v)) return 522 if(!a_buffer.read(a_data.m_cut_v)) return false; 523 if(!a_buffer.read(a_data.m_min_v)) return 523 if(!a_buffer.read(a_data.m_min_v)) return false; 524 if(!a_buffer.read(a_data.m_max_v)) return 524 if(!a_buffer.read(a_data.m_max_v)) return false; 525 } 525 } 526 526 527 // Add outflow : 527 // Add outflow : 528 a_data.m_bin_number = new_bin_number(a_data. 528 a_data.m_bin_number = new_bin_number(a_data.m_axes); 529 add_outflow<unsigned int>(a_data.m_axes,a_da 529 add_outflow<unsigned int>(a_data.m_axes,a_data.m_bin_entries); 530 add_outflow<double>(a_data.m_axes,a_data.m_b 530 add_outflow<double>(a_data.m_axes,a_data.m_bin_Sw); 531 add_outflow<double>(a_data.m_axes,a_data.m_b 531 add_outflow<double>(a_data.m_axes,a_data.m_bin_Sw2); 532 add_outflow<double>(a_data.m_axes,a_data.m_b 532 add_outflow<double>(a_data.m_axes,a_data.m_bin_Svw); 533 add_outflow(a_data.m_axes); 533 add_outflow(a_data.m_axes); 534 534 535 // Not here in v6 : 535 // Not here in v6 : 536 std::vector<double> empty; 536 std::vector<double> empty; 537 empty.resize(a_data.m_dimension,0); 537 empty.resize(a_data.m_dimension,0); 538 a_data.m_bin_Sxw.resize(a_data.m_bin_number, 538 a_data.m_bin_Sxw.resize(a_data.m_bin_number,empty); //Forget to write in v6 ! 539 a_data.m_bin_Sx2w.resize(a_data.m_bin_number 539 a_data.m_bin_Sx2w.resize(a_data.m_bin_number,empty); 540 if(a_data.m_is_profile) { 540 if(a_data.m_is_profile) { 541 a_data.m_bin_Sv2w.resize(a_data.m_bin_numb 541 a_data.m_bin_Sv2w.resize(a_data.m_bin_number,0); 542 } 542 } 543 543 544 return true; 544 return true; 545 } 545 } 546 546 547 inline bool read_v7(buffer& a_buffer,pd_data_t 547 inline bool read_v7(buffer& a_buffer,pd_data_t& a_data) { 548 if(!a_buffer.read(a_data.m_title)) return fa 548 if(!a_buffer.read(a_data.m_title)) return false; 549 549 550 {int dim; 550 {int dim; 551 if(!a_buffer.read(dim)) return false; 551 if(!a_buffer.read(dim)) return false; 552 a_data.m_dimension = dim;} 552 a_data.m_dimension = dim;} 553 553 554 {int nbin; 554 {int nbin; 555 if(!a_buffer.read(nbin)) return false; 555 if(!a_buffer.read(nbin)) return false; 556 a_data.m_bin_number = nbin;} 556 a_data.m_bin_number = nbin;} 557 557 558 std::vector<int> vec; 558 std::vector<int> vec; 559 if(!a_buffer.read_array<int>(vec)) return fa 559 if(!a_buffer.read_array<int>(vec)) return false; 560 convert<int,unsigned int>(vec,a_data.m_bin_e 560 convert<int,unsigned int>(vec,a_data.m_bin_entries); 561 561 562 if(a_data.m_bin_entries.size()!=a_data.m_bin 562 if(a_data.m_bin_entries.size()!=a_data.m_bin_number) return false; 563 if(!a_buffer.read_array<double>(a_data.m_bin 563 if(!a_buffer.read_array<double>(a_data.m_bin_Sw)) return false; 564 if(a_data.m_bin_Sw.size()!=a_data.m_bin_numb 564 if(a_data.m_bin_Sw.size()!=a_data.m_bin_number) return false; 565 if(!a_buffer.read_array<double>(a_data.m_bin 565 if(!a_buffer.read_array<double>(a_data.m_bin_Sw2)) return false; 566 if(a_data.m_bin_Sw2.size()!=a_data.m_bin_num 566 if(a_data.m_bin_Sw2.size()!=a_data.m_bin_number) return false; 567 if(!a_buffer.read_array2<double>(a_data.m_bi 567 if(!a_buffer.read_array2<double>(a_data.m_bin_Sxw)) return false; 568 if(a_data.m_bin_Sxw.size()!=a_data.m_bin_num 568 if(a_data.m_bin_Sxw.size()!=a_data.m_bin_number) return false; 569 if(!a_buffer.read_array2<double>(a_data.m_bi 569 if(!a_buffer.read_array2<double>(a_data.m_bin_Sx2w)) return false; 570 if(a_data.m_bin_Sx2w.size()!=a_data.m_bin_nu 570 if(a_data.m_bin_Sx2w.size()!=a_data.m_bin_number) return false; 571 if(a_data.m_dimension>0) { 571 if(a_data.m_dimension>0) { 572 a_data.m_axes.resize(a_data.m_dimension); 572 a_data.m_axes.resize(a_data.m_dimension); 573 for(unsigned int iaxis=0;iaxis<a_data.m_di 573 for(unsigned int iaxis=0;iaxis<a_data.m_dimension;iaxis++) { 574 if(!Axis_read_v7(a_buffer,a_data.m_axes[ 574 if(!Axis_read_v7(a_buffer,a_data.m_axes[iaxis])) return false; 575 } 575 } 576 } 576 } 577 {int dummy; 577 {int dummy; 578 if(!a_buffer.read(dummy)) return false;} //m 578 if(!a_buffer.read(dummy)) return false;} //m_mode 579 // Profile : 579 // Profile : 580 if(!a_buffer.read(a_data.m_is_profile)) retu 580 if(!a_buffer.read(a_data.m_is_profile)) return false; 581 if(a_data.m_is_profile) { 581 if(a_data.m_is_profile) { 582 if(!a_buffer.read_array<double>(a_data.m_b 582 if(!a_buffer.read_array<double>(a_data.m_bin_Svw)) return false; 583 if(a_data.m_bin_Svw.size()!=a_data.m_bin_n 583 if(a_data.m_bin_Svw.size()!=a_data.m_bin_number) return false; 584 if(!a_buffer.read_array<double>(a_data.m_b 584 if(!a_buffer.read_array<double>(a_data.m_bin_Sv2w)) return false; 585 if(a_data.m_bin_Sv2w.size()!=a_data.m_bin_ 585 if(a_data.m_bin_Sv2w.size()!=a_data.m_bin_number) return false; 586 if(!a_buffer.read(a_data.m_cut_v)) return 586 if(!a_buffer.read(a_data.m_cut_v)) return false; 587 if(!a_buffer.read(a_data.m_min_v)) return 587 if(!a_buffer.read(a_data.m_min_v)) return false; 588 if(!a_buffer.read(a_data.m_max_v)) return 588 if(!a_buffer.read(a_data.m_max_v)) return false; 589 } 589 } 590 590 591 return true; 591 return true; 592 } 592 } 593 593 594 inline bool read_annotations(buffer& a_buffer, 594 inline bool read_annotations(buffer& a_buffer,annotations_t& a_annotations) { 595 a_annotations.clear(); //reset() does not re 595 a_annotations.clear(); //reset() does not remove sticky items. 596 int number; 596 int number; 597 if(!a_buffer.read(number)) return false; 597 if(!a_buffer.read(number)) return false; 598 for(int index=0;index<number;index++) { 598 for(int index=0;index<number;index++) { 599 std::string key; 599 std::string key; 600 if(!a_buffer.read(key)) return false; 600 if(!a_buffer.read(key)) return false; 601 std::string value; 601 std::string value; 602 if(!a_buffer.read(value)) return false; 602 if(!a_buffer.read(value)) return false; 603 bool sticky; 603 bool sticky; 604 if(!a_buffer.read(sticky)) return false; 604 if(!a_buffer.read(sticky)) return false; 605 //if(!a_annotations.addItem(key,value,stic 605 //if(!a_annotations.addItem(key,value,sticky)) return false; //FIXME : handle sticky ? 606 a_annotations[key] = value; 606 a_annotations[key] = value; 607 } 607 } 608 return true; 608 return true; 609 } 609 } 610 610 611 inline bool read_THistogram(buffer& a_buffer,p 611 inline bool read_THistogram(buffer& a_buffer,pd_data_t& a_data,annotations_t& a_annotations) { 612 612 613 short v; 613 short v; 614 if(!a_buffer.read_version(v)) return false; 614 if(!a_buffer.read_version(v)) return false; 615 615 616 {std::string name,title; 616 {std::string name,title; 617 if(!Named_stream(a_buffer,name,title)) retur 617 if(!Named_stream(a_buffer,name,title)) return false;} 618 618 619 if(v==0) { 619 if(v==0) { 620 if(!read_v0(a_buffer,a_data)) return false 620 if(!read_v0(a_buffer,a_data)) return false; 621 } else if(v==1) { 621 } else if(v==1) { 622 if(!read_v1(a_buffer,a_data)) return false 622 if(!read_v1(a_buffer,a_data)) return false; 623 } else if(v==2) { 623 } else if(v==2) { 624 if(!read_v2(a_buffer,a_data)) return false 624 if(!read_v2(a_buffer,a_data)) return false; 625 } else if(v==3) { 625 } else if(v==3) { 626 if(!read_v3(a_buffer,a_data)) return false 626 if(!read_v3(a_buffer,a_data)) return false; 627 } else if(v==4) { 627 } else if(v==4) { 628 if(!read_v4(a_buffer,a_data)) return false 628 if(!read_v4(a_buffer,a_data)) return false; 629 } else if(v==5) { 629 } else if(v==5) { 630 if(!read_v5(a_buffer,a_data)) return false 630 if(!read_v5(a_buffer,a_data)) return false; 631 } else if(v==6) { 631 } else if(v==6) { 632 if(!read_v6(a_buffer,a_data)) return false 632 if(!read_v6(a_buffer,a_data)) return false; 633 } else if(v==7) { 633 } else if(v==7) { 634 if(!read_v7(a_buffer,a_data)) return false 634 if(!read_v7(a_buffer,a_data)) return false; 635 } else if(v==8) { 635 } else if(v==8) { 636 if(!read_annotations(a_buffer,a_annotation 636 if(!read_annotations(a_buffer,a_annotations)) return false; 637 if(!read_v7(a_buffer,a_data)) return false 637 if(!read_v7(a_buffer,a_data)) return false; 638 } else { 638 } else { 639 return false; 639 return false; 640 } 640 } 641 641 642 //data.m_coords.resize(data.m_dimension,0); 642 //data.m_coords.resize(data.m_dimension,0); 643 //data.m_ints.resize(data.m_dimension,0); 643 //data.m_ints.resize(data.m_dimension,0); 644 644 645 a_data.update_fast_getters(); 645 a_data.update_fast_getters(); 646 646 647 return true; 647 return true; 648 } 648 } 649 649 650 inline const std::string& THistogram_cls(){ 650 inline const std::string& THistogram_cls(){ 651 static const std::string s_v("THistogram"); 651 static const std::string s_v("THistogram"); 652 return s_v; 652 return s_v; 653 } 653 } 654 654 655 }} 655 }} 656 656 657 #include "key" 657 #include "key" 658 658 659 namespace tools { 659 namespace tools { 660 namespace rroot { 660 namespace rroot { 661 661 662 inline bool read_key_THistogram(ifile& a_file, 662 inline bool read_key_THistogram(ifile& a_file,key& a_key,pd_data_t& a_data,annotations_t& a_annotations,bool a_warn = true) { 663 std::ostream& out = a_key.out(); 663 std::ostream& out = a_key.out(); 664 if(a_key.object_class()!=THistogram_cls()) { 664 if(a_key.object_class()!=THistogram_cls()) { 665 if(a_warn) out << "tools::rroot::read_key_ 665 if(a_warn) out << "tools::rroot::read_key_THisogram : key not a THistogram." << std::endl; 666 return 0; 666 return 0; 667 } 667 } 668 unsigned int sz; 668 unsigned int sz; 669 char* buf = a_key.get_object_buffer(a_file,s 669 char* buf = a_key.get_object_buffer(a_file,sz); //we don't have ownership of buf. 670 if(!buf) { 670 if(!buf) { 671 out << "tools::rroot::read_key_THisogram : 671 out << "tools::rroot::read_key_THisogram : can't get data buffer of " << a_key.object_name() << "." << std::endl; 672 return 0; 672 return 0; 673 } 673 } 674 buffer b(out,a_file.byte_swap(),sz,buf,a_key 674 buffer b(out,a_file.byte_swap(),sz,buf,a_key.key_length(),false); 675 return read_THistogram(b,a_data,a_annotation 675 return read_THistogram(b,a_data,a_annotations); 676 } 676 } 677 677 678 }} 678 }} 679 679 680 #include "../histo/h1d" 680 #include "../histo/h1d" 681 #include "../histo/h2d" 681 #include "../histo/h2d" 682 #include "../histo/p1d" 682 #include "../histo/p1d" 683 #include "../histo/p2d" 683 #include "../histo/p2d" 684 684 685 namespace tools { 685 namespace tools { 686 namespace rroot { 686 namespace rroot { 687 687 688 inline histo::h1d* THistogram_to_h1d(const pd_ 688 inline histo::h1d* THistogram_to_h1d(const pd_data_t& a_data) { 689 unsigned int dim = a_data.m_dimension; 689 unsigned int dim = a_data.m_dimension; 690 bool is_profile = a_data.m_is_profile; 690 bool is_profile = a_data.m_is_profile; 691 if(dim!=1) return 0; 691 if(dim!=1) return 0; 692 if(is_profile) return 0; 692 if(is_profile) return 0; 693 histo::h1d* histo = new histo::h1d("",10,0,1 693 histo::h1d* histo = new histo::h1d("",10,0,1); 694 histo->copy_from_data(a_data); 694 histo->copy_from_data(a_data); 695 return histo; 695 return histo; 696 } 696 } 697 697 698 inline histo::h2d* THistogram_to_h2d(const pd_ 698 inline histo::h2d* THistogram_to_h2d(const pd_data_t& a_data) { 699 unsigned int dim = a_data.m_dimension; 699 unsigned int dim = a_data.m_dimension; 700 bool is_profile = a_data.m_is_profile; 700 bool is_profile = a_data.m_is_profile; 701 if(dim!=2) return 0; 701 if(dim!=2) return 0; 702 if(is_profile) return 0; 702 if(is_profile) return 0; 703 histo::h2d* histo = new histo::h2d("",10,0,1 703 histo::h2d* histo = new histo::h2d("",10,0,1,10,0,1); 704 histo->copy_from_data(a_data); 704 histo->copy_from_data(a_data); 705 return histo; 705 return histo; 706 } 706 } 707 707 708 inline histo::p1d* THistogram_to_p1d(const pd_ 708 inline histo::p1d* THistogram_to_p1d(const pd_data_t& a_data) { 709 unsigned int dim = a_data.m_dimension; 709 unsigned int dim = a_data.m_dimension; 710 bool is_profile = a_data.m_is_profile; 710 bool is_profile = a_data.m_is_profile; 711 if(dim!=1) return 0; 711 if(dim!=1) return 0; 712 if(!is_profile) return 0; 712 if(!is_profile) return 0; 713 histo::p1d* histo = new histo::p1d("",10,0,1 713 histo::p1d* histo = new histo::p1d("",10,0,1); 714 histo->copy_from_data(a_data); 714 histo->copy_from_data(a_data); 715 return histo; 715 return histo; 716 } 716 } 717 717 718 inline histo::p2d* THistogram_to_p2d(const pd_ 718 inline histo::p2d* THistogram_to_p2d(const pd_data_t& a_data) { 719 unsigned int dim = a_data.m_dimension; 719 unsigned int dim = a_data.m_dimension; 720 bool is_profile = a_data.m_is_profile; 720 bool is_profile = a_data.m_is_profile; 721 if(dim!=2) return 0; 721 if(dim!=2) return 0; 722 if(!is_profile) return 0; 722 if(!is_profile) return 0; 723 histo::p2d* histo = new histo::p2d("",10,0,1 723 histo::p2d* histo = new histo::p2d("",10,0,1,10,0,1); 724 histo->copy_from_data(a_data); 724 histo->copy_from_data(a_data); 725 return histo; 725 return histo; 726 } 726 } 727 727 728 }} 728 }} 729 729 730 #endif 730 #endif