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