McStas Readout Master 0.3.3
Loading...
Searching...
No Matches
readout_discrete.h
1#ifndef DISCRETER_DISCRETER_C_H
2#define DISCRETER_DISCRETER_C_H
3
4#ifdef _WIN32
5#ifdef DISCRETER_SHARED
6#ifdef DISCRETER_EXPORT
7#define DISCRETER_API __declspec(dllexport)
8#else
9#define DISCRETER_API __declspec(dllimport)
10#endif
11#else
12#define DISCRETER_API
13#endif
14#else
15#define DISCRETER_API
16#endif
17
18#include <stdint.h>
19#include <stddef.h>
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25 struct discreter_object;
26 typedef struct discreter_object discreter_t;
27
28struct array_object;
29typedef struct array_object array_t;
30
31struct index_sampler_object;
32typedef struct index_sampler_object index_sampler_t;
33
34
35
37DISCRETER_API const char *discreter_version(void);
38
40DISCRETER_API int discreter_version_int(void);
41
43DISCRETER_API discreter_t * dr_new_desc(const char * description, const char * name, size_t samples, uint32_t seed);
45DISCRETER_API discreter_t * dr_new_size(size_t object_bytes, const char * name, size_t samples, uint32_t seed);
47DISCRETER_API discreter_t * dr_new(const char * description, size_t object_bytes, const char * name, size_t samples, uint32_t seed);
48
50DISCRETER_API void dr_free(discreter_t *obj);
51
53DISCRETER_API void dr_fit(const discreter_t *obj, const void * src, double weight);
54
56DISCRETER_API int dr_filling(const discreter_t *obj);
57
59DISCRETER_API size_t dr_sample(const discreter_t *obj, double fraction, uint32_t seed);
60
62DISCRETER_API void dr_oversample(const discreter_t *obj);
63
66DISCRETER_API size_t dr_value(const discreter_t *obj, void * buffer, size_t buffer_size);
67
69DISCRETER_API size_t dr_value_index(const discreter_t *obj, size_t index, void * buffer, size_t buffer_size);
70
71
72 // // CollectorStar functions
73 //
74 // /** \brief Create a CollectorStar from a C struct type description string.
75 // *
76 // * The type description should be valid C struct syntax, e.g.:
77 // * "struct { int count; double energy; uint16_t values[10]; }"
78 // * The object size is computed automatically from the parsed description.
79 // *
80 // * \param type_description C struct syntax string describing the data type
81 // * \param dataset_name Name for the HDF5 dataset (must not be NULL or empty)
82 // * \returns Pointer to the new collector, or NULL on parse error (message printed to stderr)
83 // */
84 // DISCRETER_API collector_t* cs_new_desc(const char* type_description, const char* dataset_name);
85 //
86 // /** \brief Create a CollectorStar in opaque mode (no type schema).
87 // *
88 // * Data is stored as raw bytes. HDF5 output will be a 2D uint8 dataset.
89 // *
90 // * \param object_size Size of each object in bytes (e.g. sizeof(struct my_struct))
91 // * \param dataset_name Name for the HDF5 dataset
92 // * \returns Pointer to the new collector, or NULL on error
93 // */
94 // DISCRETER_API collector_t* cs_new_size(size_t object_size, const char* dataset_name);
95 //
96 // /** \brief Create a CollectorStar with both description and size validation.
97 // *
98 // * Parses the type description and verifies that the computed size matches
99 // * the user-provided object_size. Returns NULL and prints an error if they disagree.
100 // *
101 // * \param type_description C struct syntax string
102 // * \param object_size Expected size in bytes (e.g. sizeof(struct my_struct))
103 // * \param dataset_name Name for the HDF5 dataset
104 // * \returns Pointer to the new collector, or NULL on error
105 // */
106 // DISCRETER_API collector_t* cs_new(const char* type_description, size_t object_size, const char* dataset_name);
107 //
108 // /** \brief Destroy a CollectorStar and free its resources */
109 // DISCRETER_API void cs_free(collector_t* cs);
110 //
111 // /** \brief Add an object to the collector by copying object_size bytes from src */
112 // DISCRETER_API void cs_add(const collector_t* cs, const void* src);
113 //
114 // /** \brief Copy the object at the given index into dst (caller provides buffer of object_size bytes) */
115 // DISCRETER_API int cs_get(const collector_t* cs, size_t index, void* dst);
116 //
117 // /** \brief Return the number of collected objects */
118 // DISCRETER_API size_t cs_count(const collector_t* cs);
119 //
120 // /** \brief Return the size of each object in bytes */
121 // DISCRETER_API size_t cs_object_size(const collector_t* cs);
122 //
123 // /** \brief Write all collected data to an HDF5 file */
124 // DISCRETER_API int cs_write_hdf5(const collector_t* cs, const char* filename);
125
126
127DISCRETER_API array_t * new_array(size_t bytes_per_object);
128DISCRETER_API void delete_array(array_t * array);
129DISCRETER_API size_t array_size(const array_t * array);
130DISCRETER_API void array_add(const array_t * array, const void * data);
131DISCRETER_API void array_get(const array_t * array, size_t index, void * dst);
132DISCRETER_API void array_clear(const array_t * array);
133DISCRETER_API const uint8_t * array_data(const array_t * array);
134
135DISCRETER_API index_sampler_t * new_index_sampler(size_t samples, uint32_t seed);
136DISCRETER_API void delete_index_sampler(index_sampler_t * sampler);
137DISCRETER_API void index_sampler_fit(const index_sampler_t * sampler, size_t index, double weight);
138DISCRETER_API int index_sampler_filling(const index_sampler_t * sampler);
139DISCRETER_API void index_sampler_values(const index_sampler_t * sampler, size_t * values);
140DISCRETER_API size_t index_sampler_value(const index_sampler_t * sampler, size_t index);
141
142#ifdef __cplusplus
143}
144#endif
145
146#endif // DISCRETER_DISCRETER_C_H