g4tools  5.4.0
htoc
Go to the documentation of this file.
1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
2 // See the file tools.license for terms.
3 
4 #ifndef tools_histo_htoc
5 #define tools_histo_htoc
6 
7 struct caxis_dui { //d=double, ui=unsigned int
8  typedef double TC;
9  typedef unsigned int TO;
10  typedef unsigned int bn_t;
11 
16  unsigned char m_fixed;
18  unsigned int m_number_of_edges;
19  TC* m_edges; //[m_number_of_edges]
20 };
21 
22 struct chisto_duiuid {
23  typedef double TC;
24  typedef unsigned int TO;
25  typedef unsigned int TN;
26  typedef double TW;
27  typedef unsigned int dim_t;
28 
29  // General :
30  char* m_title;
32  // Bins :
34  TN* m_bin_entries; //[m_bin_number]
35  TW* m_bin_Sw; //[m_bin_number]
36  TW* m_bin_Sw2; //[m_bin_number]
37  TC** m_bin_Sxw; //[m_bin_number][m_dimension]
38  TC** m_bin_Sx2w; //[m_bin_number][m_dimension]
39  // Axes :
40  caxis_dui** m_axes; //[m_dimension]
41  // etc :
42  TC* m_in_range_plane_Sxyw; //(dim,size) (1,0) (2,1) (3,3)
44  char** m_annotations; //[m_number_of_annotations]
45  // fast getters :
46  TN m_all_entries; //used if reading from a ROOT file.
50  TC* m_in_range_Sxw; //[m_dimension]
51  TC* m_in_range_Sx2w; //[m_dimension]
52 };
53 
55  typedef double TV;
56 
58 
59  unsigned char m_is_profile;
60  TV* m_bin_Svw; //[m_bin_number]
61  TV* m_bin_Sv2w; //[m_bin_number]
62  unsigned char m_cut_v;
65 };
66 
67 #include "histo_data"
68 
69 #include "../cstr"
70 #include "../cmemT"
71 #include "../vdata"
72 #include "../forit"
73 
74 namespace tools {
75 namespace histo {
76 
80 
82  caxis_dui* a_cp = cmem_alloc<caxis_dui>(1);
83  if(!a_cp) return NULL;
84 
85  caxis_dui& a_c = *a_cp;
86 
87  typedef double TC;
88 
89  a_c.m_offset = a_axis.m_offset;
91  a_c.m_minimum_value = a_axis.m_minimum_value;
92  a_c.m_maximum_value = a_axis.m_maximum_value;
93  a_c.m_fixed = a_axis.m_fixed?1:0;
94  a_c.m_bin_width = a_axis.m_bin_width;
95  a_c.m_number_of_edges = (unsigned int)a_axis.m_edges.size();
96  a_c.m_edges = cmem_alloc_copy<TC>(vec_data(a_axis.m_edges),a_axis.m_edges.size());
97 
98  return a_cp;
99 }
100 
101 inline void caxis_dui_free(caxis_dui*& a_cp) {
102  if(!a_cp) return;
103  caxis_dui& a_c = *a_cp;
104 
105  cmem_free(a_c.m_edges);
106 
107  a_c.m_offset = 0;
108  a_c.m_number_of_bins = 0;
109  a_c.m_minimum_value = 0;
110  a_c.m_maximum_value = 0;
111  a_c.m_fixed = 1;
112  a_c.m_bin_width = 0;
113  a_c.m_number_of_edges = 0;
114 
115  cmem_free(a_cp);
116 }
117 
119  typedef double TC;
120  typedef unsigned int TN;
121  typedef double TW;
122 
123  a_c.m_title = str_dup(a_hd.m_title.c_str());
124  a_c.m_dimension = a_hd.m_dimension;
125  a_c.m_bin_number = a_hd.m_bin_number;
126  a_c.m_bin_entries = cmem_alloc_copy<TN>(vec_data(a_hd.m_bin_entries),a_hd.m_bin_number);
127  a_c.m_bin_Sw = cmem_alloc_copy<TW>(vec_data(a_hd.m_bin_Sw),a_hd.m_bin_number);
128  a_c.m_bin_Sw2 = cmem_alloc_copy<TW>(vec_data(a_hd.m_bin_Sw2),a_hd.m_bin_number);
129 
130  {a_c.m_bin_Sxw = cmem_alloc<TC*>(a_hd.m_bin_number);
131  for(unsigned int ibin=0;ibin<a_hd.m_bin_number;ibin++) {
132  a_c.m_bin_Sxw[ibin] = cmem_alloc_copy<TC>(vec_data(a_hd.m_bin_Sxw[ibin]),a_hd.m_dimension);
133  }}
134  {a_c.m_bin_Sx2w = cmem_alloc<TC*>(a_hd.m_bin_number);
135  for(unsigned int ibin=0;ibin<a_hd.m_bin_number;ibin++) {
136  a_c.m_bin_Sx2w[ibin] = cmem_alloc_copy<TC>(vec_data(a_hd.m_bin_Sx2w[ibin]),a_hd.m_dimension);
137  }}
138 
139  // Axes :
140  {a_c.m_axes = cmem_alloc<caxis_dui*>(a_hd.m_dimension);
141  for(unsigned int iaxis=0;iaxis<a_hd.m_dimension;iaxis++) {
142  a_c.m_axes[iaxis] = caxis_dui_alloc(a_hd.m_axes[iaxis]);
143  }}
144 
145  // etc :
146  a_c.m_in_range_plane_Sxyw = cmem_alloc_copy<TC>(vec_data(a_hd.m_in_range_plane_Sxyw),dim_planes(a_hd.m_dimension));
147  {a_c.m_number_of_annotations = (unsigned int)a_hd.m_annotations.size();
148  a_c.m_annotations = cmem_alloc<char*>(2*a_hd.m_annotations.size());
149  unsigned int index = 0;
150  tools_mforcit(std::string,std::string,a_hd.m_annotations,it) {
151  a_c.m_annotations[index] = str_dup((*it).first.c_str());index++;
152  a_c.m_annotations[index] = str_dup((*it).second.c_str());index++;
153  }}
154  // fast getters :
155  a_c.m_all_entries = a_hd.m_all_entries;
157  a_c.m_in_range_Sw = a_hd.m_in_range_Sw;
158  a_c.m_in_range_Sw2 = a_hd.m_in_range_Sw2;
159  a_c.m_in_range_Sxw = cmem_alloc_copy<TC>(vec_data(a_hd.m_in_range_Sxw),a_hd.m_dimension);
160  a_c.m_in_range_Sx2w = cmem_alloc_copy<TC>(vec_data(a_hd.m_in_range_Sx2w),a_hd.m_dimension);
161 
162  //FIXME : should check all sub pointers.
163  //if(to_del {cmem_free(a_cp);return NULL;}
164 }
165 
167  chisto_duiuid* a_cp = cmem_alloc<chisto_duiuid>(1);
168  if(!a_cp) return NULL;
169  chisto_duiuid_assign(*a_cp,a_hd);
170  return a_cp;
171 }
172 
174  str_del(a_c.m_title);
175 
177  cmem_free(a_c.m_bin_Sw);
178  cmem_free(a_c.m_bin_Sw2);
179 
180  {for(unsigned int ibin=0;ibin<a_c.m_bin_number;ibin++) cmem_free(a_c.m_bin_Sxw[ibin]);
181  cmem_free(a_c.m_bin_Sxw);}
182  {for(unsigned int ibin=0;ibin<a_c.m_bin_number;ibin++) cmem_free(a_c.m_bin_Sx2w[ibin]);
183  cmem_free(a_c.m_bin_Sx2w);}
184 
186 
187  {for(unsigned int iaxis=0;iaxis<a_c.m_dimension;iaxis++) caxis_dui_free(a_c.m_axes[iaxis]);
188  cmem_free(a_c.m_axes);}
189 
190  {for(unsigned int i=0;i<(2*a_c.m_number_of_annotations);i++) str_del(a_c.m_annotations[i]);
191  cmem_free(a_c.m_annotations);}
192 
195 
196  a_c.m_dimension = 0;
197  a_c.m_bin_number = 0;
198  a_c.m_number_of_annotations = 0;
199 
200  a_c.m_all_entries = 0;
201  a_c.m_in_range_entries = 0;
202  a_c.m_in_range_Sw = 0;
203  a_c.m_in_range_Sw2 = 0;
204 }
205 
206 inline void chisto_duiuid_free(chisto_duiuid*& a_cp) {
207  if(!a_cp) return;
208  chisto_duiuid_clear(*a_cp);
209  cmem_free(a_cp);
210 }
211 
215 
216 template <class T>
217 inline void vec_assign(std::vector<T>& a_v,unsigned int a_number,const T* a_c) {
218  a_v.resize(a_number);
219  for(unsigned int i=0;i<a_number;i++) a_v[i] = a_c[i];
220 }
221 
222 inline void axis_dui_assign(axis<double,unsigned int>& a_axis,const caxis_dui& a_c) {
223  a_axis.m_offset = a_c.m_offset;
224  a_axis.m_number_of_bins = a_c.m_number_of_bins;
225  a_axis.m_minimum_value = a_c.m_minimum_value;
226  a_axis.m_maximum_value = a_c.m_maximum_value;
227  a_axis.m_fixed = a_c.m_fixed==1?true:false;
228  a_axis.m_bin_width = a_c.m_bin_width;
230 }
231 
233  a_hd.m_title = std::string(a_c.m_title);
234  a_hd.m_dimension = a_c.m_dimension;
235  a_hd.m_bin_number = a_c.m_bin_number;
239 
240  {a_hd.m_bin_Sxw.resize(a_c.m_bin_number);
241  for(unsigned int ibin=0;ibin<a_c.m_bin_number;ibin++) {
242  vec_assign(a_hd.m_bin_Sxw[ibin],a_c.m_dimension,a_c.m_bin_Sxw[ibin]);
243  }}
244  {a_hd.m_bin_Sx2w.resize(a_c.m_bin_number);
245  for(unsigned int ibin=0;ibin<a_c.m_bin_number;ibin++) {
246  vec_assign(a_hd.m_bin_Sx2w[ibin],a_c.m_dimension,a_c.m_bin_Sx2w[ibin]);
247  }}
248 
249  {a_hd.m_axes.resize(a_c.m_dimension);
250  for(unsigned int iaxis=0;iaxis<a_c.m_dimension;iaxis++) {
251  axis_dui_assign(a_hd.m_axes[iaxis],*(a_c.m_axes[iaxis]));
252  }}
254 
255  {a_hd.m_annotations.clear();
256  for(unsigned int i=0;i<a_c.m_number_of_annotations;i++) {
257  a_hd.m_annotations[a_c.m_annotations[2*i+0]] = a_c.m_annotations[2*i+1];
258  }}
259 
260  a_hd.m_all_entries = a_c.m_all_entries;
262  a_hd.m_in_range_Sw = a_c.m_in_range_Sw;
263  a_hd.m_in_range_Sw2 = a_c.m_in_range_Sw2;
266 }
267 
268 }}
269 
270 #include "profile_data"
271 
272 namespace tools {
273 namespace histo {
274 
278 
280  cprofile_duiuidd* a_cp = cmem_alloc<cprofile_duiuidd>(1);
281  if(!a_cp) return NULL;
282 
283  cprofile_duiuidd& a_c = *a_cp;
284 
285  chisto_duiuid_assign(a_c.m_histo,a_pd);
286 
287  typedef double TV;
288 
289  // profile part :
290  a_c.m_is_profile = a_pd.m_is_profile?1:0;
291  a_c.m_bin_Svw = cmem_alloc_copy<TV>(vec_data(a_pd.m_bin_Svw),a_pd.m_bin_number);
292  a_c.m_bin_Sv2w = cmem_alloc_copy<TV>(vec_data(a_pd.m_bin_Sv2w),a_pd.m_bin_number);
293  a_c.m_cut_v = a_pd.m_cut_v?1:0;
294  a_c.m_min_v = a_pd.m_min_v;
295  a_c.m_max_v = a_pd.m_max_v;
296 
297  return a_cp;
298 }
299 
301  if(!a_cp) return;
302 
303  cprofile_duiuidd& a_c = *a_cp;
304 
306 
307  cmem_free(a_c.m_bin_Svw);
308  cmem_free(a_c.m_bin_Sv2w);
309 
310  a_c.m_is_profile = 1;
311  a_c.m_cut_v = 0;
312  a_c.m_min_v = 0;
313  a_c.m_max_v = 0;
314 
315  cmem_free(a_cp);
316 }
317 
321 
324  a_pd.m_is_profile = a_c.m_is_profile==1?true:false;
327  a_pd.m_cut_v = a_c.m_cut_v==1?true:false;
328  a_pd.m_min_v = a_c.m_min_v;
329  a_pd.m_max_v = a_c.m_max_v;
330 }
331 
332 }}
333 
334 #endif
335 
336 
337 
338 
cprofile_duiuidd::m_bin_Sv2w
TV * m_bin_Sv2w
Definition: htoc:61
cprofile_duiuidd::m_cut_v
unsigned char m_cut_v
Definition: htoc:62
tools::histo::axis::m_edges
std::vector< TC > m_edges
Definition: axis:272
cprofile_duiuidd::m_min_v
TV m_min_v
Definition: htoc:63
tools::histo::histo_data::m_in_range_Sw2
TW m_in_range_Sw2
Definition: histo_data:189
chisto_duiuid::m_in_range_plane_Sxyw
TC * m_in_range_plane_Sxyw
Definition: htoc:42
tools::histo::profile_data::m_is_profile
bool m_is_profile
Definition: profile_data:73
cprofile_duiuidd
Definition: htoc:54
tools::histo::histo_data::m_annotations
std::map< std::string, std::string > m_annotations
Definition: histo_data:184
cprofile_duiuidd::TV
double TV
Definition: htoc:55
chisto_duiuid::m_number_of_annotations
unsigned int m_number_of_annotations
Definition: htoc:43
tools::histo::axis_dui_assign
void axis_dui_assign(axis< double, unsigned int > &a_axis, const caxis_dui &a_c)
Definition: htoc:222
tools::histo::axis::m_maximum_value
TC m_maximum_value
Definition: axis:267
tools::histo::axis::m_offset
TO m_offset
Definition: axis:264
chisto_duiuid::TC
double TC
Definition: htoc:23
tools::histo::histo_data::m_bin_Sx2w
std::vector< std::vector< TC > > m_bin_Sx2w
Definition: histo_data:179
chisto_duiuid::m_annotations
char ** m_annotations
Definition: htoc:44
tools::histo::histo_data::m_in_range_Sxw
std::vector< TC > m_in_range_Sxw
Definition: histo_data:190
tools::histo::vec_assign
void vec_assign(std::vector< T > &a_v, unsigned int a_number, const T *a_c)
C struct to hist_data ///////////////////////////////////////////////////.
Definition: htoc:217
chisto_duiuid::m_bin_Sw
TW * m_bin_Sw
Definition: htoc:35
tools::histo::axis< double, unsigned int >
chisto_duiuid::m_title
char * m_title
Definition: htoc:30
tools::vec_data
const T * vec_data(const std::vector< T > &a_vec)
Definition: vdata:18
chisto_duiuid::m_all_entries
TN m_all_entries
Definition: htoc:46
tools::cmem_free
void cmem_free(T *&a_p)
Definition: cmemT:16
tools::histo::profile_data_duiuidd_assign
void profile_data_duiuidd_assign(profile_data< double, unsigned int, unsigned int, double, double > &a_pd, const cprofile_duiuidd &a_c)
C struct to profile_data ////////////////////////////////////////////////.
Definition: htoc:322
tools::histo::histo_data::m_bin_entries
std::vector< TN > m_bin_entries
Definition: histo_data:175
tools::histo::chisto_duiuid_assign
void chisto_duiuid_assign(chisto_duiuid &a_c, const histo_data< double, unsigned int, unsigned int, double > &a_hd)
Definition: htoc:118
tools::histo::chisto_duiuid_free
void chisto_duiuid_free(chisto_duiuid *&a_cp)
Definition: htoc:206
caxis_dui::m_minimum_value
TC m_minimum_value
Definition: htoc:14
chisto_duiuid::m_bin_Sw2
TW * m_bin_Sw2
Definition: htoc:36
caxis_dui::m_bin_width
TC m_bin_width
Definition: htoc:17
tools::histo::histo_data::m_bin_Sw
std::vector< TW > m_bin_Sw
Definition: histo_data:176
tools::histo::profile_data::m_bin_Sv2w
std::vector< TV > m_bin_Sv2w
Definition: profile_data:75
tools::histo::cprofile_duiuidd_free
void cprofile_duiuidd_free(cprofile_duiuidd *&a_cp)
Definition: htoc:300
chisto_duiuid::m_bin_Sxw
TC ** m_bin_Sxw
Definition: htoc:37
chisto_duiuid
Definition: htoc:22
chisto_duiuid::m_in_range_Sxw
TC * m_in_range_Sxw
Definition: htoc:50
tools::histo::cprofile_duiuidd_alloc
cprofile_duiuidd * cprofile_duiuidd_alloc(const profile_data< double, unsigned int, unsigned int, double, double > &a_pd)
profile_data to C struct ////////////////////////////////////////////////
Definition: htoc:279
tools::histo::profile_data::m_min_v
TV m_min_v
Definition: profile_data:77
tools::histo::histo_data::m_in_range_entries
TN m_in_range_entries
Definition: histo_data:187
tools::histo::profile_data::m_cut_v
bool m_cut_v
Definition: profile_data:76
tools::histo::axis::m_bin_width
TC m_bin_width
Definition: axis:270
tools::histo::histo_data::m_in_range_Sx2w
std::vector< TC > m_in_range_Sx2w
Definition: histo_data:191
tools::histo::histo_data::m_title
std::string m_title
Definition: histo_data:171
tools::histo::profile_data
Definition: profile_data:13
caxis_dui::m_offset
TO m_offset
Definition: htoc:12
tools::histo::profile_data::m_bin_Svw
std::vector< TV > m_bin_Svw
Definition: profile_data:74
tools::histo::dim_planes
unsigned int dim_planes(unsigned int a_dim)
Definition: histo_data:17
chisto_duiuid::m_axes
caxis_dui ** m_axes
Definition: htoc:40
caxis_dui::TC
double TC
Definition: htoc:8
chisto_duiuid::TN
unsigned int TN
Definition: htoc:25
caxis_dui::m_maximum_value
TC m_maximum_value
Definition: htoc:15
cprofile_duiuidd::m_max_v
TV m_max_v
Definition: htoc:64
tools::histo::histo_data::m_bin_Sxw
std::vector< std::vector< TC > > m_bin_Sxw
Definition: histo_data:178
profile_data
cprofile_duiuidd::m_bin_Svw
TV * m_bin_Svw
Definition: htoc:60
tools::histo::histo_data< double, unsigned int, unsigned int, double >
tools::histo::histo_data::m_axes
std::vector< axis_t > m_axes
Definition: histo_data:181
tools::histo::axis::m_minimum_value
TC m_minimum_value
Definition: axis:266
tools::histo::caxis_dui_free
void caxis_dui_free(caxis_dui *&a_cp)
Definition: htoc:101
tools
inlined C code : ///////////////////////////////////
Definition: aida_ntuple:26
chisto_duiuid::m_in_range_Sx2w
TC * m_in_range_Sx2w
Definition: htoc:51
caxis_dui::bn_t
unsigned int bn_t
Definition: htoc:10
tools_mforcit
#define tools_mforcit(a__K, a__V, a__m, a__it)
Definition: forit:49
tools::histo::axis::m_number_of_bins
bn_t m_number_of_bins
Definition: axis:265
tools::histo::histo_data::m_bin_Sw2
std::vector< TW > m_bin_Sw2
Definition: histo_data:177
tools::str_del
void str_del(char *&a_cstr)
Definition: cstr:66
tools::histo::histo_data::m_all_entries
TN m_all_entries
Definition: histo_data:186
tools::histo::histo_data::m_in_range_Sw
TW m_in_range_Sw
Definition: histo_data:188
tools::histo::chisto_duiuid_clear
void chisto_duiuid_clear(chisto_duiuid &a_c)
Definition: htoc:173
tools::str_dup
char * str_dup(const char *a_cstr)
Definition: cstr:30
chisto_duiuid::m_in_range_Sw2
TW m_in_range_Sw2
Definition: htoc:49
caxis_dui::m_number_of_edges
unsigned int m_number_of_edges
Definition: htoc:18
caxis_dui::m_number_of_bins
bn_t m_number_of_bins
Definition: htoc:13
chisto_duiuid::TO
unsigned int TO
Definition: htoc:24
tools::histo::histo_data_duiuid_assign
void histo_data_duiuid_assign(histo_data< double, unsigned int, unsigned int, double > &a_hd, const chisto_duiuid &a_c)
Definition: htoc:232
chisto_duiuid::m_bin_entries
TN * m_bin_entries
Definition: htoc:34
cprofile_duiuidd::m_histo
chisto_duiuid m_histo
Definition: htoc:57
caxis_dui::m_edges
TC * m_edges
Definition: htoc:19
tools::histo::histo_data::m_bin_number
TO m_bin_number
Definition: histo_data:174
caxis_dui::m_fixed
unsigned char m_fixed
Definition: htoc:16
histo_data
chisto_duiuid::m_in_range_entries
TN m_in_range_entries
Definition: htoc:47
cprofile_duiuidd::m_is_profile
unsigned char m_is_profile
Definition: htoc:59
tools::histo::axis::m_fixed
bool m_fixed
Definition: axis:268
tools::histo::histo_data::m_in_range_plane_Sxyw
std::vector< TC > m_in_range_plane_Sxyw
Definition: histo_data:183
tools::histo::profile_data::m_max_v
TV m_max_v
Definition: profile_data:78
tools::histo::histo_data::m_dimension
dim_t m_dimension
Definition: histo_data:172
chisto_duiuid::TW
double TW
Definition: htoc:26
chisto_duiuid::dim_t
unsigned int dim_t
Definition: htoc:27
caxis_dui::TO
unsigned int TO
Definition: htoc:9
chisto_duiuid::m_dimension
dim_t m_dimension
Definition: htoc:31
tools::histo::caxis_dui_alloc
caxis_dui * caxis_dui_alloc(const axis< double, unsigned int > &a_axis)
hist_data to C struct ///////////////////////////////////////////////////
Definition: htoc:81
chisto_duiuid::m_bin_Sx2w
TC ** m_bin_Sx2w
Definition: htoc:38
chisto_duiuid::m_bin_number
TO m_bin_number
Definition: htoc:33
caxis_dui
Definition: htoc:7
chisto_duiuid::m_in_range_Sw
TW m_in_range_Sw
Definition: htoc:48
tools::histo::chisto_duiuid_alloc
chisto_duiuid * chisto_duiuid_alloc(const histo_data< double, unsigned int, unsigned int, double > &a_hd)
Definition: htoc:166