| 1 | /* histogram/ntuple.c |
| 2 | * |
| 3 | * Copyright (C) 2000 Simone Piccardi |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 3 of the License, or (at |
| 8 | * your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 18 | */ |
| 19 | |
| 20 | /* Jan/2001 Modified by Brian Gough. Minor changes for GSL */ |
| 21 | |
| 22 | #include "gsl__config.h"cxx . . $ `<file>/external/gsl/gsl__config.h`/ |
| 23 | #include <errno.h> |
| 24 | #include "gsl_errno.h"cxx . . $ `<file>/external/gsl/gsl_errno.h`/ |
| 25 | #include "gsl_ntuple.h"cxx . . $ `<file>/external/gsl/gsl_ntuple.h`/ |
| 26 | |
| 27 | /* |
| 28 | * gsl_ntuple_open: |
| 29 | * Initialize an ntuple structure and create the related file |
| 30 | */ |
| 31 | |
| 32 | gsl_ntuplecxx . . $ gsl_ntuple# * |
| 33 | gsl_ntuple_createcxx . . $ gsl_ntuple_create(14dfdd3afae9a212). (char *filename, void *ntuple_data, size_t size) |
| 34 | { |
| 35 | gsl_ntuplecxx . . $ gsl_ntuple# *ntuple = (gsl_ntuplecxx . . $ gsl_ntuple# *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (sizeof (gsl_ntuplecxx . . $ gsl_ntuple#)); |
| 36 | |
| 37 | if (ntuple == 0) |
| 38 | { |
| 39 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("failed to allocate space for ntuple struct", |
| 40 | GSL_ENOMEM, 0); |
| 41 | } |
| 42 | |
| 43 | ntuple->ntuple_datacxx . . $ $anonymous_type_8a6acdadd058e990_0#ntuple_data. = ntuple_data; |
| 44 | ntuple->sizecxx . . $ $anonymous_type_8a6acdadd058e990_0#size. = size; |
| 45 | |
| 46 | ntuple->filecxx . . $ $anonymous_type_8a6acdadd058e990_0#file. = fopencxx . . $ fopen(82ec0787cd37e0a3). (filename, "wb"); |
| 47 | |
| 48 | if (ntuple->filecxx . . $ $anonymous_type_8a6acdadd058e990_0#file. == 0) |
| 49 | { |
| 50 | freecxx . . $ free(5d22bdacc48458e8). (ntuple); |
| 51 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("unable to create ntuple file", GSL_EFAILED, 0); |
| 52 | } |
| 53 | |
| 54 | return ntuple; |
| 55 | } |
| 56 | |
| 57 | /* |
| 58 | * gsl_ntuple_open: |
| 59 | * Initialize an ntuple structure and open the related file |
| 60 | */ |
| 61 | |
| 62 | gsl_ntuplecxx . . $ gsl_ntuple# * |
| 63 | gsl_ntuple_opencxx . . $ gsl_ntuple_open(14dfdd3afae9a212). (char *filename, void *ntuple_data, size_t size) |
| 64 | { |
| 65 | gsl_ntuplecxx . . $ gsl_ntuple# *ntuple = (gsl_ntuplecxx . . $ gsl_ntuple# *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (sizeof (gsl_ntuplecxx . . $ gsl_ntuple#)); |
| 66 | |
| 67 | if (ntuple == 0) |
| 68 | { |
| 69 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("failed to allocate space for ntuple struct", |
| 70 | GSL_ENOMEM, 0); |
| 71 | } |
| 72 | |
| 73 | ntuple->ntuple_datacxx . . $ $anonymous_type_8a6acdadd058e990_0#ntuple_data. = ntuple_data; |
| 74 | ntuple->sizecxx . . $ $anonymous_type_8a6acdadd058e990_0#size. = size; |
| 75 | |
| 76 | ntuple->filecxx . . $ $anonymous_type_8a6acdadd058e990_0#file. = fopencxx . . $ fopen(82ec0787cd37e0a3). (filename, "rb"); |
| 77 | |
| 78 | if (ntuple->filecxx . . $ $anonymous_type_8a6acdadd058e990_0#file. == 0) |
| 79 | { |
| 80 | freecxx . . $ free(5d22bdacc48458e8). (ntuple); |
| 81 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("unable to open ntuple file for reading", |
| 82 | GSL_EFAILED, 0); |
| 83 | } |
| 84 | |
| 85 | return ntuple; |
| 86 | } |
| 87 | |
| 88 | /* |
| 89 | * gsl_ntuple_write: |
| 90 | * write to file a data row, must be used in a loop! |
| 91 | */ |
| 92 | |
| 93 | int |
| 94 | gsl_ntuple_writecxx . . $ gsl_ntuple_write(f2b24d9262117a21). (gsl_ntuplecxx . . $ gsl_ntuple# * ntuple) |
| 95 | { |
| 96 | size_t nwrite; |
| 97 | |
| 98 | nwrite = fwritecxx . . $ fwrite(ab0609fa07c47d6e). (ntuple->ntuple_datacxx . . $ $anonymous_type_8a6acdadd058e990_0#ntuple_data., ntuple->sizecxx . . $ $anonymous_type_8a6acdadd058e990_0#size., |
| 99 | 1, ntuple->filecxx . . $ $anonymous_type_8a6acdadd058e990_0#file.); |
| 100 | |
| 101 | if (nwrite != 1) |
| 102 | { |
| 103 | GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`! ("failed to write ntuple entry to file", GSL_EFAILED); |
| 104 | } |
| 105 | |
| 106 | return GSL_SUCCESScxx . . $ GSL_SUCCESS.; |
| 107 | } |
| 108 | |
| 109 | /* the following function is a synonym for gsl_ntuple_write */ |
| 110 | |
| 111 | int |
| 112 | gsl_ntuple_bookdatacxx . . $ gsl_ntuple_bookdata(f2b24d9262117a21). (gsl_ntuplecxx . . $ gsl_ntuple# * ntuple) |
| 113 | { |
| 114 | return gsl_ntuple_writecxx . . $ gsl_ntuple_write(f2b24d9262117a21). (ntuple); |
| 115 | } |
| 116 | |
| 117 | /* |
| 118 | * gsl_ntuple_read: |
| 119 | * read form file a data row, must be used in a loop! |
| 120 | */ |
| 121 | |
| 122 | int |
| 123 | gsl_ntuple_readcxx . . $ gsl_ntuple_read(f2b24d9262117a21). (gsl_ntuplecxx . . $ gsl_ntuple# * ntuple) |
| 124 | { |
| 125 | size_t nread; |
| 126 | |
| 127 | nread = freadcxx . . $ fread(738fc8ac1d711e58). (ntuple->ntuple_datacxx . . $ $anonymous_type_8a6acdadd058e990_0#ntuple_data., ntuple->sizecxx . . $ $anonymous_type_8a6acdadd058e990_0#size., 1, ntuple->filecxx . . $ $anonymous_type_8a6acdadd058e990_0#file.); |
| 128 | |
| 129 | if (nread == 0 && feofcxx . . $ feof(89bc1efcdac0ca22).(ntuple->filecxx . . $ $anonymous_type_8a6acdadd058e990_0#file.)) |
| 130 | { |
| 131 | return GSL_EOFcxx . . $ GSL_EOF.; |
| 132 | } |
| 133 | |
| 134 | if (nread != 1) |
| 135 | { |
| 136 | GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`! ("failed to read ntuple entry from file", GSL_EFAILED); |
| 137 | } |
| 138 | |
| 139 | return GSL_SUCCESScxx . . $ GSL_SUCCESS.; |
| 140 | } |
| 141 | |
| 142 | /* |
| 143 | * gsl_ntuple_project: |
| 144 | * fill an histogram with an ntuple file contents, use |
| 145 | * SelVal and SelFunc user defined functions to get |
| 146 | * the value to book and the selection funtion |
| 147 | */ |
| 148 | |
| 149 | #define EVALcxx . . $ `external/gsl/gsl_ntuple__ntuple.c:149:9`!(f,x) ((*((f)->function))(x,(f)->params)) |
| 150 | |
| 151 | int |
| 152 | gsl_ntuple_projectcxx . . $ gsl_ntuple_project(ede4f48fda7140a8). (gsl_histogramcxx . . $ gsl_histogram# * h, gsl_ntuplecxx . . $ gsl_ntuple# * ntuple, |
| 153 | gsl_ntuple_value_fncxx . . $ gsl_ntuple_value_fn# * value_func, |
| 154 | gsl_ntuple_select_fncxx . . $ gsl_ntuple_select_fn# * select_func) |
| 155 | { |
| 156 | size_t nread; |
| 157 | |
| 158 | do |
| 159 | { |
| 160 | nread = freadcxx . . $ fread(738fc8ac1d711e58). (ntuple->ntuple_datacxx . . $ $anonymous_type_8a6acdadd058e990_0#ntuple_data., ntuple->sizecxx . . $ $anonymous_type_8a6acdadd058e990_0#size., |
| 161 | 1, ntuple->filecxx . . $ $anonymous_type_8a6acdadd058e990_0#file.); |
| 162 | |
| 163 | if (nread == 0 && feofcxx . . $ feof(89bc1efcdac0ca22).(ntuple->filecxx . . $ $anonymous_type_8a6acdadd058e990_0#file.)) |
| 164 | { |
| 165 | break ; |
| 166 | } |
| 167 | |
| 168 | if (nread != 1) |
| 169 | { |
| 170 | GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`! ("failed to read ntuple for projection", GSL_EFAILED); |
| 171 | } |
| 172 | |
| 173 | if (EVALcxx . . $ `external/gsl/gsl_ntuple__ntuple.c:149:9`!(select_func, ntuple->ntuple_data)) |
| 174 | { |
| 175 | gsl_histogram_incrementcxx . . $ gsl_histogram_increment(19dd58896d13d23d). (h, EVALcxx . . $ `external/gsl/gsl_ntuple__ntuple.c:149:9`!(value_func, ntuple->ntuple_data)); |
| 176 | } |
| 177 | } |
| 178 | while (1); |
| 179 | |
| 180 | return GSL_SUCCESScxx . . $ GSL_SUCCESS.; |
| 181 | } |
| 182 | |
| 183 | |
| 184 | /* |
| 185 | * gsl_ntuple_close: |
| 186 | * close the ntuple file and free the memory |
| 187 | */ |
| 188 | |
| 189 | int |
| 190 | gsl_ntuple_closecxx . . $ gsl_ntuple_close(f2b24d9262117a21). (gsl_ntuplecxx . . $ gsl_ntuple# * ntuple) |
| 191 | { |
| 192 | int status = fclosecxx . . $ fclose(89bc1efcdac0ca22). (ntuple->filecxx . . $ $anonymous_type_8a6acdadd058e990_0#file.); |
| 193 | |
| 194 | if (status) |
| 195 | { |
| 196 | GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`! ("failed to close ntuple file", GSL_EFAILED); |
| 197 | } |
| 198 | |
| 199 | freecxx . . $ free(5d22bdacc48458e8). (ntuple); |
| 200 | |
| 201 | return GSL_SUCCESScxx . . $ GSL_SUCCESS.; |
| 202 | } |