├── .gitignore ├── reference ├── henke.xdr └── maps_standardinfo.txt ├── test ├── 2_ID_E_dataset │ ├── mda │ │ ├── axo_std.mda │ │ ├── 2xfm_0010.mda │ │ └── 2xfm_0011.mda │ ├── flyXRF.h5 │ │ └── 2xfm_0011_2xfm3__0.h5 │ └── maps_standardinfo.txt ├── config.json ├── Test_2_ID_E.py └── test_fit.py ├── src ├── support │ ├── mdautils-1.4.1 │ │ ├── doc │ │ │ ├── mda-ls.pdf │ │ │ ├── mda-dump.pdf │ │ │ ├── mda-info.pdf │ │ │ ├── mda-load.pdf │ │ │ ├── mda2ascii.pdf │ │ │ ├── mdatree2ascii.pdf │ │ │ ├── mda-dump.1 │ │ │ ├── mda-info.1 │ │ │ ├── mda-ls.1 │ │ │ └── mdatree2ascii.1 │ │ ├── xdr_hack.h │ │ ├── Makefile │ │ ├── LICENSE │ │ ├── mdatree2ascii │ │ ├── xdr_hack.c │ │ ├── README.txt │ │ ├── mda-load.h │ │ └── Changelog.txt │ └── nnls │ │ └── README ├── stats │ └── correlation_coefficient.h ├── core │ ├── mem_info.h │ ├── command_line_parser.h │ └── mem_info.cpp ├── io │ ├── file │ │ ├── aps │ │ │ ├── aps_fit_params_import.cpp │ │ │ └── aps_roi.cpp │ │ └── netcdf_io.h │ └── net │ │ └── basic_serializer.h ├── workflow │ ├── pipeline.cpp │ ├── xrf │ │ ├── integrated_spectra_source.h │ │ ├── detector_sum_spectra_source.h │ │ ├── spectra_net_source.h │ │ ├── spectra_net_streamer.h │ │ ├── spectra_file_source.h │ │ └── spectra_stream_saver.h │ ├── pipeline.h │ ├── threadpool.h │ ├── source.h │ └── distributor.h ├── data_struct │ ├── spectra_line.h │ ├── spectra_volume.h │ ├── scaler_lookup.h │ ├── spectra_line.cpp │ ├── stream_block.h │ ├── element_quant.h │ └── detector.h ├── fitting │ ├── routines │ │ ├── roi_fit_routine.h │ │ ├── svd_fit_routine.h │ │ ├── hybrid_param_nnls_fit_routine.h │ │ ├── nnls_fit_routine.h │ │ ├── base_fit_routine.h │ │ └── param_optimized_fit_routine.h │ └── optimizers │ │ ├── optimizer.cpp │ │ └── nlopt_optimizer.h └── quantification │ └── models │ └── quantification_model.h ├── .gitmodules ├── docs ├── custom_optimizer_presets.md └── README.md ├── Compile.md ├── azure-pipelines.yml ├── LICENSE ├── .github └── workflows │ └── cmake.yml └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .vscode 3 | -------------------------------------------------------------------------------- /reference/henke.xdr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdvancedPhotonSource/XRF-Maps/HEAD/reference/henke.xdr -------------------------------------------------------------------------------- /test/2_ID_E_dataset/mda/axo_std.mda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdvancedPhotonSource/XRF-Maps/HEAD/test/2_ID_E_dataset/mda/axo_std.mda -------------------------------------------------------------------------------- /test/2_ID_E_dataset/mda/2xfm_0010.mda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdvancedPhotonSource/XRF-Maps/HEAD/test/2_ID_E_dataset/mda/2xfm_0010.mda -------------------------------------------------------------------------------- /test/2_ID_E_dataset/mda/2xfm_0011.mda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdvancedPhotonSource/XRF-Maps/HEAD/test/2_ID_E_dataset/mda/2xfm_0011.mda -------------------------------------------------------------------------------- /src/support/mdautils-1.4.1/doc/mda-ls.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdvancedPhotonSource/XRF-Maps/HEAD/src/support/mdautils-1.4.1/doc/mda-ls.pdf -------------------------------------------------------------------------------- /src/support/mdautils-1.4.1/doc/mda-dump.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdvancedPhotonSource/XRF-Maps/HEAD/src/support/mdautils-1.4.1/doc/mda-dump.pdf -------------------------------------------------------------------------------- /src/support/mdautils-1.4.1/doc/mda-info.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdvancedPhotonSource/XRF-Maps/HEAD/src/support/mdautils-1.4.1/doc/mda-info.pdf -------------------------------------------------------------------------------- /src/support/mdautils-1.4.1/doc/mda-load.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdvancedPhotonSource/XRF-Maps/HEAD/src/support/mdautils-1.4.1/doc/mda-load.pdf -------------------------------------------------------------------------------- /src/support/mdautils-1.4.1/doc/mda2ascii.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdvancedPhotonSource/XRF-Maps/HEAD/src/support/mdautils-1.4.1/doc/mda2ascii.pdf -------------------------------------------------------------------------------- /src/support/mdautils-1.4.1/doc/mdatree2ascii.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdvancedPhotonSource/XRF-Maps/HEAD/src/support/mdautils-1.4.1/doc/mdatree2ascii.pdf -------------------------------------------------------------------------------- /test/2_ID_E_dataset/flyXRF.h5/2xfm_0011_2xfm3__0.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdvancedPhotonSource/XRF-Maps/HEAD/test/2_ID_E_dataset/flyXRF.h5/2xfm_0011_2xfm3__0.h5 -------------------------------------------------------------------------------- /test/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "redis_host": "hyrule", 3 | "node_name": "invid", 4 | "xrf_param_override": 5 | { 6 | "dataset_dir": "/home/beams/AGLOWACKI/mdata/2idd_luxi", 7 | "detector_num": 0 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "src/support/eigen-git-mirror"] 2 | path = src/support/eigen-git-mirror 3 | url = https://gitlab.com/libeigen/eigen.git 4 | [submodule "src/support/pybind11"] 5 | path = src/support/pybind11 6 | url = https://github.com/pybind/pybind11.git 7 | [submodule "vcpkg"] 8 | path = vcpkg 9 | url = https://github.com/Microsoft/vcpkg 10 | -------------------------------------------------------------------------------- /test/2_ID_E_dataset/maps_standardinfo.txt: -------------------------------------------------------------------------------- 1 | This file describes arbitrary standard reference materials 2 | please put the filename that contains the measured standard next. if it was acquired using a multi element detector, please list just the mca0 file 3 | FILENAME: axo_std.mda 4 | please put the comma seperated list of elements in the standard 5 | ELEMENTS_IN_STANDARD: Ca, Fe, Cu 6 | please put the weight (area density) in ug/cm2 for each of the elements above 7 | WEIGHT: 1.931, 0.504, 0.284 8 | -------------------------------------------------------------------------------- /reference/maps_standardinfo.txt: -------------------------------------------------------------------------------- 1 | This file describes arbitrary standard reference materials 2 | please put the filename that contains the measured standard next. if it was acquired using a multi element detector, please list just the mca0 file 3 | FILENAME: axo_std.mca 4 | Disable Ka for quantification and only fit Kb. 1 = on 0 = off (normally 0) 5 | DISABLE_KA: 0 6 | Disable La for quantification and only fit Lb- Ln. 1 = on 0 = off (normally 0) 7 | DISABLE_LA: 0 8 | please put the comma seperated list of elements in the standard 9 | ELEMENTS_IN_STANDARD: Ca, Fe, Cu 10 | please put the weight (area density) in ug/cm2 for each of the elements above 11 | WEIGHT: 1.931, 0.504, 0.284 12 | -------------------------------------------------------------------------------- /src/support/mdautils-1.4.1/xdr_hack.h: -------------------------------------------------------------------------------- 1 | #ifdef XDR_HACK 2 | #if defined XDR_LE || defined XDR_BE 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | #define XDR FILE 10 | #define xdr_getpos(a) ftell(a) 11 | #define xdr_setpos(a,b) !fseek(a,b,SEEK_SET) 12 | #define xdrproc_t int (*)(FILE *, void *) 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | int xdr_int8_t( FILE *fptr, int8_t *my_int8); 19 | int xdr_int16_t( FILE *fptr, int16_t *my_int16); 20 | int xdr_int32_t( FILE *fptr, int32_t *my_int32); 21 | int xdr_float( FILE *fptr, float *my_float); 22 | int xdr_double( FILE *fptr, double *my_double); 23 | int xdr_vector( FILE *fptr, char *buffer, uint16_t size, 24 | uint16_t type_size, int (*proc)(FILE *fptr, void *data) ); 25 | int xdr_counted_string( FILE *fptr, char **p); 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif 32 | #endif 33 | -------------------------------------------------------------------------------- /src/support/mdautils-1.4.1/doc/mda-dump.1: -------------------------------------------------------------------------------- 1 | .TH MDA-DUMP 1 "August 2016" "MDA Utilities" "MDA Utilities" 2 | 3 | .SH NAME 4 | mda-dump \- dumps entire contents of MDA files to standard output 5 | 6 | .SH SYNOPSIS 7 | .B mda-dump 8 | .RB [ \-hv ] 9 | .I "file" 10 | 11 | .SH DESCRIPTION 12 | .B mda-dump 13 | is a utility for dumping the entire contents of binary MDA data files, 14 | which are created by 15 | .BR saveData \ in 16 | .BR EPICS . 17 | The output format is odd, but it follows exactly the format of the 18 | file itself. Unless one of the options is used, 19 | .B mda-dump 20 | needs only 21 | .IR "file" , 22 | the name of the MDA file. 23 | .PP 24 | This program is useful for debugging other programs that interact with 25 | MDA files. 26 | 27 | .SH OPTIONS 28 | .TP 29 | .B \-h 30 | Show the help screen. 31 | .TP 32 | .B \-v 33 | Show the version information. 34 | 35 | .SH AUTHOR 36 | Dohn A. Arms 37 | 38 | .SH "SEE ALSO" 39 | .BR mda2ascii (1), \ mda-info (1), \ mda-ls (1) 40 | 41 | -------------------------------------------------------------------------------- /src/support/mdautils-1.4.1/doc/mda-info.1: -------------------------------------------------------------------------------- 1 | .TH MDA-INFO 1 "August 2016" "MDA Utilities" "MDA Utilities" 2 | 3 | .SH NAME 4 | mda-info \- prints out information about a MDA file 5 | 6 | .SH SYNOPSIS 7 | .B mda-info 8 | .RB [ \-hvs ] 9 | .I "file" 10 | 11 | .SH DESCRIPTION 12 | .B mda-info 13 | is a utility for seeing certain information about MDA files, which are 14 | created by 15 | .BR saveData \ in 16 | .BR EPICS . 17 | Things such as scan time, dimensionality, positioners, detectors, and 18 | triggers are shown. For each trigger, positioner, and detector there 19 | is both a number and, located in parentheses, the PV field number used 20 | in saveData. Unless one of the options is used, 21 | .B mda-info 22 | needs only 23 | .IR "file" , 24 | the name of the MDA file. If a file is irregular, it is stated as 25 | such and the actual overall scan size is shown, taken from the individual 26 | scans themselves. 27 | .PP 28 | The program by default will check the validity of the entire file, but 29 | minimal checking can be enabled to save time. 30 | 31 | .SH OPTIONS 32 | .TP 33 | .B \-h 34 | Show the help screen. 35 | .TP 36 | .B \-v 37 | Show the version information. 38 | .TP 39 | .B \-s 40 | Use the simpler error checking, instead of checking the entire 41 | file. 42 | 43 | .SH AUTHOR 44 | Dohn A. Arms 45 | 46 | .SH "SEE ALSO" 47 | .BR mda2ascii (1), \ mda-dump (1), \ mda-ls (1) 48 | 49 | -------------------------------------------------------------------------------- /docs/custom_optimizer_presets.md: -------------------------------------------------------------------------------- 1 | # XRF-Maps 2 | 3 | ## Running integrated spectra with custom preset 4 | 5 | ## 6 | ``` 7 | --optimize-fit-override-params 0 8 | ``` 9 | Note that 0 means user specified custom preset from the override file 10 | 11 | ### Override file 12 | For each fit parameter you can add the following 13 | 14 | fit_param_name + the following 15 | ``` 16 | fit_param_name + _MIN 17 | fit_param_name + _MAX 18 | fit_param_name + _STEPSIZE 19 | fit_param_name + _FITTING 20 | ``` 21 | 22 | ### _FITTING 23 | ``` 24 | fixed : do not fit this parameters 25 | limit_lo_hi : If using mpfit, limit to the _MIN and _MAX ranges 26 | limit_lo : If using mpfit, limit to the _MIN range 27 | limit_hi : If using mpfit, limit to the _MAX range 28 | fit : Fit this parameters with out an constraints. 29 | ``` 30 | 31 | ### Example 32 | #### Energy offset fit it with limits 33 | ``` 34 | CAL_OFFSET_[E_OFFSET]: -0.0054764490 35 | CAL_OFFSET_[E_OFFSET]_MAX: 0.50000000 36 | CAL_OFFSET_[E_OFFSET]_MIN: -0.50000000 37 | CAL_OFFSET_[E_OFFSET]_STEPSIZE: 0.001 38 | CAL_OFFSET_[E_OFFSET]_FITTING: limit_lo_hi 39 | ``` 40 | 41 | #### F_TAIL_OFFSET set limits but don't use them since we set FITTING to fit, will use step size if calling mpfit 42 | ``` 43 | F_TAIL_OFFSET: 0.003 44 | F_TAIL_OFFSET_MAX: 0.100 45 | F_TAIL_OFFSET_MIN: 0.00001 46 | F_TAIL_OFFSET_STEPSIZE: 0.00001 47 | F_TAIL_OFFSET_FITTING: fit 48 | ``` -------------------------------------------------------------------------------- /src/stats/correlation_coefficient.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------- 2 | * Copyright (c) 2023, UChicago Argonne, LLC 3 | * See LICENSE file. 4 | *---------------------------------------------------------------------------*/ 5 | 6 | #ifndef Correlation_Coefficient_H 7 | #define Correlation_Coefficient_H 8 | 9 | #include 10 | 11 | /*---------------------------------------------------------------------------*/ 12 | /*---------------------------------------------------------------------------*/ 13 | 14 | template 15 | _T find_coefficient(const Eigen::Array<_T, Eigen::Dynamic, Eigen::RowMajor>& x_arr, const Eigen::Array<_T, Eigen::Dynamic, Eigen::RowMajor>& y_arr) 16 | { 17 | Eigen::Array<_T, Eigen::Dynamic, Eigen::RowMajor> xy_arr = x_arr * y_arr; 18 | Eigen::Array<_T, Eigen::Dynamic, Eigen::RowMajor> xx_arr = x_arr * x_arr; 19 | Eigen::Array<_T, Eigen::Dynamic, Eigen::RowMajor> yy_arr = y_arr * y_arr; 20 | _T sum_x = x_arr.sum(); 21 | _T sum_y = y_arr.sum(); 22 | _T sum_xy = xy_arr.sum(); 23 | _T sqsum_x = xx_arr.sum(); 24 | _T sqsum_y = yy_arr.sum(); 25 | _T n = (_T)x_arr.size(); 26 | _T corr = (n * sum_xy - sum_x * sum_y) / sqrt((n * sqsum_x - sum_x * sum_x) * (n * sqsum_y - sum_y * sum_y)); 27 | return corr; 28 | } 29 | 30 | /*---------------------------------------------------------------------------*/ 31 | 32 | #endif 33 | 34 | /*---------------------------------------------------------------------------*/ 35 | -------------------------------------------------------------------------------- /Compile.md: -------------------------------------------------------------------------------- 1 | # XRF-Maps Compiling 2 | ## Windows 3 | ### MSVC 4 | 5 | #### Prepare environment 6 | * git clone --recurse-submodules https://github.com/advancedphotonsource/XRF-Maps.git 7 | * download and install cmake https://cmake.org/download/ 8 | * download and install netcdf 3 library https://cmake.org/download/ 9 | * download and install hdf5 library https://support.hdfgroup.org/HDF5/release/obtain5.html 10 | * (optional) git clone https://github.com/zeromq/libzmq.git 11 | 12 | 13 | ## Linux 14 | ### No Streaming 15 | * mkdir build 16 | * cd build 17 | * CC=icc CXX=icpc cmake ../ 18 | * cmake --build . --config Release 19 | 20 | ### Streaming 21 | * mkdir build 22 | * cd build 23 | * CC=icc CXX=icpc cmake -DBUILD_WITH_ZMQ -DZeroMQ_INCLUDE_DIR=/libs/zmq/include/ -DZeroMQ_STATIC_LIBRARY=/libs/zmq/lib/libzmq.a -DEIGEN3_INCLUDES=/usr/common/software/eigen3/3.3.3/include/eigen3/ ../ 24 | * cmake --build . --config Release 25 | 26 | ## Linux HPC 27 | ### Nersc Cori 28 | #### Intel Phi 29 | * module swap craype-haswell craype-mic-knl 30 | * module add gcc/9.3.0 31 | * module add netcdf/4.6.1 32 | * module add hdf5/1.10.1 33 | * mkdir build 34 | * cd build 35 | * CC=icc CXX=icpc cmake -DBUILD_FOR_PHI=ON -DEIGEN3_INCLUDES=/usr/common/software/eigen3/3.3.3/include/eigen3/ ../ 36 | * cmake --build . --config Release 37 | ### ALCF Theta 38 | #### Intel Phi 39 | * module add cmake/3.18.0 40 | * module add cray-hdf5-parallel/1.10.6.0 41 | * module add cray-netcdf-hdf5parallel/4.7.3.3 42 | * mkdir build 43 | * cd build 44 | * cmake -DBUILD_FOR_PHI=ON ../ 45 | * cmake --build . --config Release 46 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # XRF-Maps 2 | 3 | ## About 4 | 5 | ## Fitting Routines 6 | ``` 7 | --fit 8 | ``` 9 | ### ROI 10 | #### Description 11 | ROI fitting 12 | 13 | ### Non-Negative Least Squares (NNLS) 14 | 15 | ### Singualr Value Decomposition (SVD) 16 | 17 | ### Per Pixel (MATRIX) 18 | 19 | ## Quantification 20 | ### Option 21 | ``` 22 | --quantify-with 23 | ``` 24 | ### Standard file definition: 25 | 26 | ### Example: 27 | ``` 28 | --quantify-with maps_standardinfo.txt 29 | ``` 30 | 31 | ## Exchange Format 32 | 33 | ## MISC Command line 34 | 35 | ### Number of Threads 36 | ``` 37 | --nthreads 38 | ``` 39 | #### Desc: 40 | Specifiy the max number of threads to use. If you do not specifiy --nthreads, it will query the cpu for the max number of threads and use them all. 41 | 42 | #### Example: Use only 4 threads 43 | ``` 44 | --nthreads 4 45 | ``` 46 | 47 | ### Detectors to fit 48 | ``` 49 | --detectors 50 | ``` 51 | or 52 | ``` 53 | --detector-range n:m 54 | ``` 55 | #### Desc: 56 | Specifiy the detector elements to fit. If you do not specifiy this option, it will default to 7 elements but will only process ones that exist. 57 | 58 | #### Example: Use 4 detectors 59 | ``` 60 | --detectors 0,1,2,3 61 | ``` 62 | or 63 | ``` 64 | --detector-range 0:3 65 | ``` 66 | #### Example: Fit all detectors except for the 3rd detector 67 | ``` 68 | --detectors 0,1,3 69 | ``` 70 | 71 | 72 | ### Generate Average H5 file 73 | ``` 74 | --generate-avg-h5 75 | ``` 76 | #### Desc: 77 | Will average all detectors specified by --detectors or --detector-range option into h5 file. 78 | 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /test/Test_2_ID_E.py: -------------------------------------------------------------------------------- 1 | 2 | #Don't forget to append XRF-Maps/bin directory to PYTHONPATH 3 | 4 | import pyxrfmaps as px 5 | import os 6 | 7 | if os.name == 'nt': 8 | os_end_char = '\\' 9 | else: 10 | os_end_char = '/' 11 | 12 | element_csv_filename = "../reference/xrf_library.csv" 13 | element_henke_filename = "../reference/henke.xdr" 14 | 15 | def load_spectra_vol_and_print(): 16 | dataset_dir = '2_ID_E_dataset' + os_end_char 17 | dataset_file = 'axo_std.mda' 18 | detector_num = 0 19 | sv = px.Spectra_Volume() 20 | po = px.ParamsOverride() 21 | if False == px.load_override_params(dataset_dir, detector_num, po): 22 | # if we can't find maps_fit_parameters_override.txt[detector_num] then try to load the averaged maps_fit_parameters_override.txt 23 | print(px.load_override_params(dataset_dir, -1, po)) 24 | print (px.load_spectra_volume(dataset_dir, dataset_file, detector_num, sv, po, False, False)) 25 | spectra = sv[0][0] 26 | for i in spectra: 27 | print (i) 28 | 29 | 30 | def run_analysis(): 31 | px.load_element_info(element_henke_filename, element_csv_filename) 32 | job = px.AnalysisJob() 33 | job.dataset_directory = '2_ID_E_dataset' + os_end_char 34 | job.dataset_files = px.find_all_dataset_files(job.dataset_directory + "mda/", ".mda") 35 | job.optimize_dataset_files = job.dataset_files 36 | job.detector_num_arr = [0,1,2,3] 37 | job.quick_and_dirty = False 38 | job.fitting_routines = [px.FittingRoutines.ROI, px.FittingRoutines.SVD, px.FittingRoutines.MATRIX, px.FittingRoutines.NNLS] 39 | job.quantification_standard_filename = 'maps_standardinfo.txt' 40 | px.check_and_create_dirs(job.dataset_directory) 41 | px.populate_netcdf_hdf5_files(job.dataset_directory) 42 | px.init_analysis_job_detectors(job) 43 | px.generate_optimal_params(job) 44 | px.perform_quantification(job) 45 | px.process_dataset_files(job) 46 | print('done') 47 | 48 | if __name__ == '__main__': 49 | run_analysis() 50 | -------------------------------------------------------------------------------- /src/support/mdautils-1.4.1/doc/mda-ls.1: -------------------------------------------------------------------------------- 1 | .TH MDA-LS 1 "August 2016" "MDA Utilities" "MDA Utilities" 2 | 3 | .SH NAME 4 | mda-ls \- displays basic properties of EPICS MDA files in a directory 5 | 6 | .SH SYNOPSIS 7 | .B mda-ls 8 | .RB [ \-hvfs ] 9 | .RB [ \-p\c 10 | .IR "\ positioner" ] 11 | .RB [ \-d\c 12 | .IR "\ detector" ] 13 | .RB [ \-t\c 14 | .IR "\ trigger" ] 15 | .RI [ "directory" ] 16 | 17 | .SH DESCRIPTION 18 | .B mda-ls 19 | is a utility for displaying the basic properties of EPICS MDA files in 20 | a directory. By default, the following are shown: name of the file, 21 | overall dimensionality of the file, and positioners with their 22 | dimensionalties shown. If the file was not completed, the highest 23 | dimensionality is represented by the completed number of points, 24 | followed by the requested number in parentheses. If the file 25 | generates an error while loading, its status will be shown as 26 | .I Invalid. 27 | By default, the validity of the entire files will be checked, but 28 | minimal checking can be enabled to save time. There is an option for 29 | showing the fuller 30 | .B mda-ls 31 | listing, which shows the time of the beginning of the scan; to see 32 | more information about a certain file, use 33 | .BR mda-info . 34 | It is possible to filter listing to those containing the PV for a 35 | certain positioner, detector, or trigger. 36 | .PP 37 | By default, 38 | .B mda-ls 39 | displays the properties of files in the current directory, but a 40 | different directory can be specified. It doesn't accept file names 41 | as arguments. 42 | 43 | .SH OPTIONS 44 | .TP 45 | .B \-h 46 | Show the help screen. 47 | .TP 48 | .B \-v 49 | Show the version information. 50 | .TP 51 | .B \-f 52 | Show the fuller listing, which includes the time of the beginning of the 53 | scan. 54 | .TP 55 | .B \-s 56 | Use the simpler error checking, instead of checking the entire 57 | file. 58 | .TP 59 | .BI \-p \ positioner 60 | File are selected that use the specified 61 | .IR positioner . 62 | .TP 63 | .BI \-d \ detector 64 | File are selected that use the specified 65 | .IR detector . 66 | .TP 67 | .BI \-t \ trigger 68 | File are selected that use the specified 69 | .IR trigger . 70 | 71 | .SH AUTHOR 72 | Dohn A. Arms 73 | 74 | .SH "SEE ALSO" 75 | .BR mda2ascii (1), \ mda-dump (1), \ mda-info (1) 76 | 77 | -------------------------------------------------------------------------------- /src/support/mdautils-1.4.1/doc/mdatree2ascii.1: -------------------------------------------------------------------------------- 1 | .TH MDATREE2ASCII 1 "August 2016" "MDA Utilities" "MDA Utilities" 2 | 3 | .SH NAME 4 | mdatree2ascii \- convert directories of EPICS MDA files to ASCII format 5 | 6 | .SH SYNOPSIS 7 | .B mdatree2ascii 8 | .RB [ \-h ] 9 | .RB [ \-v ] 10 | .RB [ \-d ] 11 | .RB [ \-f ] 12 | .RB [ \-s ] 13 | .RB [ \-x\c 14 | .IR "\ extension" ] 15 | .I "source" "destination" 16 | .RI [ "mda2ascii_options" ] 17 | 18 | .SH DESCRIPTION 19 | .B mdatree2ascii 20 | is a script utility for converting directory trees of binary MDA data 21 | files (which are created by 22 | .BR saveData \ in 23 | .BR EPICS ) 24 | into newly created directory trees containing the ASCII output. The 25 | source and destination trees share the same layout, except that 26 | directories in the source tree that contain no MDA files will not be 27 | created in the destination tree. The program 28 | .B mda2ascii 29 | is run on each found file, using the options provided by the user. 30 | The program will show the directory that is currently being converted, 31 | and there is an option for showing the current file as well. Any 32 | errors that 33 | .B mda2ascii 34 | generates will appear, but they will not stop the conversion process. 35 | .PP 36 | By default, the utility will ignore symbolic links, but there are 37 | switches for enabling following directory symbolic links and converting 38 | MDA file symbolic links. There is also an option to change the extension 39 | that is searched, from the default "mda". 40 | .PP 41 | While the utility will use the 42 | .I mda2ascii 43 | that is found in the 44 | .IR PATH , 45 | explicit location for the executable can be used by setting the 46 | environment variable 47 | .I MDA2ASCII 48 | to the location of 49 | .IR mda2ascii . 50 | 51 | .SH OPTIONS 52 | .TP 53 | .B \-h 54 | Show the help screen. 55 | .TP 56 | .B \-v 57 | Show the version information. 58 | .TP 59 | .B \-d 60 | Display the name of the current MDA file being converted. 61 | .TP 62 | .B \-f 63 | Follow directory symbolic links while searching the tree. 64 | .TP 65 | .B \-s 66 | Convert MDA files that are actually symbolic links. 67 | .TP 68 | .BI \-x \ extension 69 | Change the extension used while searching for files, from the default 70 | "mda". 71 | 72 | .SH AUTHOR 73 | Dohn A. Arms 74 | 75 | .SH "SEE ALSO" 76 | .BR mda2ascii (1), \ mda-dump (1), \ mda-info (1), \ mda-ls (1) 77 | 78 | -------------------------------------------------------------------------------- /azure-pipelines.yml: -------------------------------------------------------------------------------- 1 | trigger: 2 | - master 3 | variables: 4 | buildPlatform: 'x64' 5 | buildConfiguration: 'Release' 6 | VCPKG_DEFAULT_TRIPLET: 'x64-windows' 7 | VCPKG_CONFIG_CACHE: D:/a/1/s/vcpkg/installed 8 | jobs: 9 | - job: Default 10 | timeoutInMinutes: 360 11 | cancelTimeoutInMinutes: 180 12 | pool: 13 | vmImage: 'windows-latest' 14 | steps: 15 | - checkout: self 16 | submodules: true 17 | - script: .\vcpkg\bootstrap-vcpkg.bat 18 | - task: Cache@2 19 | inputs: 20 | key: 'version2 | vcpkg-cache | "$(Agent.OS)"' 21 | restoreKeys: | 22 | vcpkg-cache | $(Agent.OS) 23 | vcpkg-cache 24 | path: $(VCPKG_CONFIG_CACHE) 25 | cacheHitVar: CACHE_RESTORED 26 | displayName: Cache vcpkg packages 27 | - script: .\vcpkg\vcpkg.exe install hdf5 netcdf-c yaml-cpp zeromq cppzmq jsoncpp nlopt --triplet x64-windows 28 | condition: ne(variables.CACHE_RESTORED, 'true') 29 | - script: mkdir build 30 | - task: CMake@1 31 | inputs: 32 | workingDirectory: 'build' 33 | cmakeArgs: '-G "Visual Studio 17 2022" -A x64 -DCMAKE_TOOLCHAIN_FILE=../vcpkg/scripts/buildsystems/vcpkg.cmake -DBUILD_WITH_QT=OFF -DBUILD_WITH_ZMQ=ON -DAVX2=ON ..' 34 | - task: MSBuild@1 35 | inputs: 36 | solution: 'build/ALL_BUILD.vcxproj' 37 | configuration: Release 38 | maximumCpuCount: true 39 | platform: 'x64' 40 | #- script: new-item -itemtype file -path $(System.DefaultWorkingDirectory)/install -name "version.json" -force -value '{\"buildNumber\":\"$(Build.BuildNumber)\",\"buildId\":\"$(Build.BuildId)\",\"branchName\":\"$(Build.SourceBranchName)\",\"commitHash\":\"$(Build.SourceVersion)\"}' 41 | - task: CopyFiles@2 42 | displayName: 'Copy bin Files to install' 43 | inputs: 44 | SourceFolder: $(System.DefaultWorkingDirectory)/bin 45 | TargetFolder: $(System.DefaultWorkingDirectory)/install/bin 46 | - task: CopyFiles@2 47 | displayName: 'Copy ref Files to install' 48 | inputs: 49 | SourceFolder: $(System.DefaultWorkingDirectory)/reference 50 | TargetFolder: $(System.DefaultWorkingDirectory)/install/reference 51 | - task: PublishPipelineArtifact@1 52 | inputs: 53 | targetPath: $(System.DefaultWorkingDirectory)/install/ 54 | artifactName: XRF-Maps_Windows_x64_AVX2 55 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016, UChicago Argonne, LLC. All rights reserved. 2 | 3 | Copyright 2016. UChicago Argonne, LLC. This software was produced 4 | under U.S. Government contract DE-AC02-06CH11357 for Argonne National 5 | Laboratory (ANL), which is operated by UChicago Argonne, LLC for the 6 | U.S. Department of Energy. The U.S. Government has rights to use, 7 | reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR 8 | UChicago Argonne, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 9 | ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is 10 | modified to produce derivative works, such modified software should 11 | be clearly marked, so as not to confuse it with the version available 12 | from ANL. 13 | 14 | Additionally, redistribution and use in source and binary forms, with 15 | or without modification, are permitted provided that the following 16 | conditions are met: 17 | 18 | * Redistributions of source code must retain the above copyright 19 | notice, this list of conditions and the following disclaimer. 20 | 21 | * Redistributions in binary form must reproduce the above copyright 22 | notice, this list of conditions and the following disclaimer in 23 | the documentation and/or other materials provided with the 24 | distribution. 25 | 26 | * Neither the name of UChicago Argonne, LLC, Argonne National 27 | Laboratory, ANL, the U.S. Government, nor the names of its 28 | contributors may be used to endorse or promote products derived 29 | from this software without specific prior written permission. 30 | 31 | THIS SOFTWARE IS PROVIDED BY UChicago Argonne, LLC AND CONTRIBUTORS 32 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 34 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UChicago 35 | Argonne, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 36 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 37 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 38 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 39 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 40 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 41 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /src/support/nnls/README: -------------------------------------------------------------------------------- 1 | The is the README file for the NNLS software 2 | 3 | 4 | If you use this software please include in your paper the following citation: 5 | 6 | [1] D. Kim, S. Sra, and I. Dhillon. A Non-monotonic method for large-scale 7 | nonnegative least-squares problems. Optimization Methods and Software, 2012. 8 | 9 | OR for your convenience, include the following data in your .bib file 10 | 11 | @Article{kiSrDh12, 12 | author = {D. Kim and S. Sra and I. S. Dhillon}, 13 | title = {{A Non-monotonic method for large-scale nonnegative least-squares problems}}, 14 | journal = {Optimization Methods and Software}, 15 | year = 2012, 16 | month = {Jan}, 17 | } 18 | 19 | 20 | ******* BUILD INSTRUCTIONS ********* 21 | 22 | 1. type 'make' on the command line 23 | 2. Ideally it should succeed, and build nnls out of the box 24 | 25 | 3. If it complains about stuff related to CBLAS, BLAS, ATLAS, FORTRAN, etc. 26 | edit the 'makefile', and comment out the line that says 27 | 28 | USEBLAS = -D_HAVE_CBLAS 29 | 30 | Additionally, set the variable to the blank value 31 | 32 | LIBS = 33 | 34 | Now it should compile without problems. 35 | 36 | 37 | ****** USAGE ******* 38 | 39 | The distribution includes a driver program, nnlsDriver.cc (which is the file 40 | that is compiled by make to yield 'nnls'); this driver illustrates how to use 41 | libnnls to solve an nnls problem. This driver is very rudimentary, but serves 42 | the purpose. 43 | 44 | The NNLS driver has a very simple interface. Usage is: 45 | 46 | nnls [dDsS] A b maxit 47 | 48 | d -- dense matrix A, text mode files A and b 49 | D -- dense matrix A, binary mode files A and b 50 | s -- sparse matrix A, text mode CCS files A_* and b 51 | S -- sparse matrix A, binary mode files A and b 52 | 53 | the rhs vector 'b' is always stored as an m x 1 dense matrix. Sparse format 54 | for 'b' is not supported, and not really worth it. 55 | 56 | As an explicit example, imagine you have a dense matrix, stored in a text-file 57 | called 'A' (without the quotes of course) as follows 58 | 59 | m n 60 | a11 a12 ... a1n 61 | a21 a22 ... a2n 62 | .. .. ... .. 63 | am1 am2 ... amn 64 | 65 | Further assume that you have a textfile called 'b' stored as 66 | m 1 67 | b1 68 | b2 69 | .. 70 | bm 71 | 72 | Then invoke nnls as: ./nnls d A b 10 73 | 74 | In the util/ subdirectory, there are scripts saveMatlabMatrix.m and 75 | loadCmatrix.m that allow you to load and save matlab matrices as files that 76 | the NNLS driver can read and use (both dense and sparse matrices are 77 | supported). 78 | -------------------------------------------------------------------------------- /src/core/mem_info.h: -------------------------------------------------------------------------------- 1 | /*** 2 | Copyright (c) 2019, UChicago Argonne, LLC. All rights reserved. 3 | 4 | Copyright 2016. UChicago Argonne, LLC. This software was produced 5 | under U.S. Government contract DE-AC02-06CH11357 for Argonne National 6 | Laboratory (ANL), which is operated by UChicago Argonne, LLC for the 7 | U.S. Department of Energy. The U.S. Government has rights to use, 8 | reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR 9 | UChicago Argonne, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 10 | ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is 11 | modified to produce derivative works, such modified software should 12 | be clearly marked, so as not to confuse it with the version available 13 | from ANL. 14 | 15 | Additionally, redistribution and use in source and binary forms, with 16 | or without modification, are permitted provided that the following 17 | conditions are met: 18 | 19 | * Redistributions of source code must retain the above copyright 20 | notice, this list of conditions and the following disclaimer. 21 | 22 | * Redistributions in binary form must reproduce the above copyright 23 | notice, this list of conditions and the following disclaimer in 24 | the documentation and/or other materials provided with the 25 | distribution. 26 | 27 | * Neither the name of UChicago Argonne, LLC, Argonne National 28 | Laboratory, ANL, the U.S. Government, nor the names of its 29 | contributors may be used to endorse or promote products derived 30 | from this software without specific prior written permission. 31 | 32 | THIS SOFTWARE IS PROVIDED BY UChicago Argonne, LLC AND CONTRIBUTORS 33 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 34 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 35 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UChicago 36 | Argonne, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 37 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 38 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 39 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 40 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 41 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 42 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | ***/ 45 | 46 | /// Initial Author <2019>: Arthur Glowacki 47 | #ifndef __MEM_HELPER__ 48 | #define __MEM_HELPER__ 49 | 50 | 51 | #if defined _WIN32 || defined __CYGWIN__ 52 | #include "windows.h" 53 | #elif defined(__APPLE__) 54 | #include 55 | #include 56 | #else 57 | #include "sys/types.h" 58 | #include "sys/sysinfo.h" 59 | #endif 60 | 61 | long long get_available_mem(); 62 | 63 | long long get_total_mem(); 64 | 65 | #endif 66 | 67 | -------------------------------------------------------------------------------- /src/io/file/aps/aps_fit_params_import.cpp: -------------------------------------------------------------------------------- 1 | /*** 2 | Copyright (c) 2016, UChicago Argonne, LLC. All rights reserved. 3 | 4 | Copyright 2016. UChicago Argonne, LLC. This software was produced 5 | under U.S. Government contract DE-AC02-06CH11357 for Argonne National 6 | Laboratory (ANL), which is operated by UChicago Argonne, LLC for the 7 | U.S. Department of Energy. The U.S. Government has rights to use, 8 | reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR 9 | UChicago Argonne, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 10 | ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is 11 | modified to produce derivative works, such modified software should 12 | be clearly marked, so as not to confuse it with the version available 13 | from ANL. 14 | 15 | Additionally, redistribution and use in source and binary forms, with 16 | or without modification, are permitted provided that the following 17 | conditions are met: 18 | 19 | * Redistributions of source code must retain the above copyright 20 | notice, this list of conditions and the following disclaimer. 21 | 22 | * Redistributions in binary form must reproduce the above copyright 23 | notice, this list of conditions and the following disclaimer in 24 | the documentation and/or other materials provided with the 25 | distribution. 26 | 27 | * Neither the name of UChicago Argonne, LLC, Argonne National 28 | Laboratory, ANL, the U.S. Government, nor the names of its 29 | contributors may be used to endorse or promote products derived 30 | from this software without specific prior written permission. 31 | 32 | THIS SOFTWARE IS PROVIDED BY UChicago Argonne, LLC AND CONTRIBUTORS 33 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 34 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 35 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UChicago 36 | Argonne, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 37 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 38 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 39 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 40 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 41 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 42 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | ***/ 45 | 46 | /// Initial Author <2016>: Arthur Glowacki 47 | 48 | 49 | #include "aps_fit_params_import.h" 50 | 51 | namespace io 52 | { 53 | namespace file 54 | { 55 | namespace aps 56 | { 57 | 58 | 59 | //----------------------------------------------------------------------------- 60 | //----------------------------------------------------------------------------- 61 | 62 | 63 | 64 | //----------------------------------------------------------------------------- 65 | //----------------------------------------------------------------------------- 66 | 67 | 68 | } //end namespace aps 69 | } //end namespace file 70 | }// end namespace io 71 | -------------------------------------------------------------------------------- /src/support/mdautils-1.4.1/Makefile: -------------------------------------------------------------------------------- 1 | OSTYPE := $(shell uname -s) 2 | 3 | EXT_O= 4 | 5 | ifeq ($(OSTYPE),SunOS) 6 | EXT_LIB=-lnsl 7 | else 8 | EXT_LIB= 9 | endif 10 | 11 | ifeq ($(OSTYPE),Darwin) 12 | EXT_CFLAGS=-D DARWIN 13 | else 14 | EXT_CFLAGS= 15 | endif 16 | 17 | #### Windows ################################################ 18 | # For Windows, you need to uncomment XDR LE support (below), 19 | # as well as the following line (for allowing backslashes). 20 | # EXT_CFLAGS=-D WINDOWS 21 | ############################################################### 22 | 23 | CC = gcc 24 | AR = ar 25 | CFLAGS = -Wall -O2 $(EXT_CFLAGS) 26 | #CFLAGS += -g 27 | 28 | #### XDR ############################################################## 29 | # To use routines included for XDR decoding, uncomment next two lines, 30 | # and one (and only one) of the last two lines. 31 | # Only use this if your OS doesn't provide XDR functions! 32 | #CFLAGS += -D XDR_HACK 33 | #EXT_O = xdr_hack.o 34 | # Sets endianess: BE = big-endian, LE = little-endian 35 | #CFLAGS += -D XDR_BE 36 | #CFLAGS += -D XDR_LE 37 | ######################################################################### 38 | 39 | TARGETS = libmda-load.a mda2ascii mda-dump mda-info mda-ls 40 | 41 | all: $(TARGETS) 42 | 43 | libmda-load.a: mda-load.h mda_loader.o $(EXT_O) 44 | $(AR) rcs libmda-load.a mda_loader.o $(EXT_O) 45 | 46 | mda2ascii: mda_ascii.o libmda-load.a mda-load.h 47 | $(CC) mda_ascii.o libmda-load.a -o mda2ascii $(EXT_LIB) 48 | 49 | mda-dump: mda_dump.o $(EXT_O) 50 | $(CC) mda_dump.o -o mda-dump $(EXT_LIB) $(EXT_O) 51 | 52 | mda-info: mda_info.o libmda-load.a mda-load.h 53 | $(CC) mda_info.o libmda-load.a -o mda-info $(EXT_LIB) 54 | 55 | mda-ls: mda_ls.o libmda-load.a mda-load.h 56 | $(CC) mda_ls.o libmda-load.a -o mda-ls $(EXT_LIB) 57 | 58 | 59 | mda_dump.o: 60 | mda_loader.o: mda-load.h 61 | mda_ascii.o: mda-load.h 62 | mda_info.o: mda-load.h 63 | mda_ls.o: mda-load.h 64 | xdr_hack.o: xdr_hack.h 65 | 66 | 67 | .PHONY : clean 68 | clean: 69 | -rm *.o $(TARGETS) 70 | 71 | 72 | prefix = /usr/local 73 | bindir = $(prefix)/bin 74 | mandir = $(prefix)/man/man1 75 | includedir = $(prefix)/include 76 | libdir = $(prefix)/lib 77 | 78 | INSTALL_MKDIR = mkdir -p 79 | INSTALL_EXE = install -c -m 0755 80 | INSTALL_OTHER = install -c -m 0644 81 | 82 | install : all 83 | $(INSTALL_MKDIR) $(DESTDIR)$(bindir) 84 | $(INSTALL_MKDIR) $(DESTDIR)$(libdir) 85 | $(INSTALL_MKDIR) $(DESTDIR)$(includedir) 86 | $(INSTALL_MKDIR) $(DESTDIR)$(mandir) 87 | $(INSTALL_EXE) mda-ls $(DESTDIR)$(bindir)/ 88 | $(INSTALL_EXE) mda-info $(DESTDIR)$(bindir)/ 89 | $(INSTALL_EXE) mda-dump $(DESTDIR)$(bindir)/ 90 | $(INSTALL_EXE) mda2ascii $(DESTDIR)$(bindir)/ 91 | $(INSTALL_EXE) mdatree2ascii $(DESTDIR)$(bindir)/ 92 | $(INSTALL_OTHER) libmda-load.a $(DESTDIR)$(libdir)/ 93 | $(INSTALL_OTHER) mda-load.h $(DESTDIR)$(includedir)/ 94 | $(INSTALL_OTHER) doc/mda-ls.1 $(DESTDIR)$(mandir)/ 95 | $(INSTALL_OTHER) doc/mda-info.1 $(DESTDIR)$(mandir)/ 96 | $(INSTALL_OTHER) doc/mda-dump.1 $(DESTDIR)$(mandir)/ 97 | $(INSTALL_OTHER) doc/mda2ascii.1 $(DESTDIR)$(mandir)/ 98 | $(INSTALL_OTHER) doc/mdatree2ascii.1 $(DESTDIR)$(mandir)/ 99 | 100 | -------------------------------------------------------------------------------- /test/test_fit.py: -------------------------------------------------------------------------------- 1 | from numpy.lib.shape_base import column_stack 2 | import pyxrfmaps as px 3 | import h5py 4 | import matplotlib.pyplot as plt 5 | import numpy as np 6 | 7 | element_csv_filename = "../reference/xrf_library.csv" 8 | element_henke_filename = "../reference/henke.xdr" 9 | detector_num = 0 10 | dataset_dir = 'D:/bnp/MinghettiTi_fly49_XRFMaps/' 11 | dataset = 'bnp_fly0049.mda.h50' 12 | full_path = dataset_dir + 'img.dat/' + dataset 13 | 14 | def load_dataset(filename): 15 | # Load integreated spectra from dataset 16 | df = h5py.File(filename) 17 | if not df == None: 18 | if '/MAPS/Spectra/Integrated_Spectra/Spectra' in df: 19 | return df['/MAPS/Spectra/Integrated_Spectra/Spectra'][...] 20 | elif '/MAPS/int_spec' in df: 21 | return df['/MAPS/int_spec'][...] 22 | else: 23 | print('Failed to open') 24 | return None 25 | 26 | def plot_results(int_spec, fit_spec): 27 | i_ax = np.linspace(0,int_spec.size-1, int_spec.size) 28 | f_ax = np.linspace(0,fit_spec.size-1, fit_spec.size) 29 | fig, axs = plt.subplots(2,3) 30 | axs[0,0].plot(i_ax, int_spec) 31 | axs[0,1].plot(i_ax, int_spec) 32 | axs[0,1].set_yscale('log') 33 | 34 | fft_spec = np.fft.fft(int_spec) 35 | freq = np.fft.fftfreq(fft_spec.size) 36 | axs[0,2].plot(freq, fft_spec.real**2 + fft_spec.imag**2) 37 | 38 | axs[0,0].plot(f_ax, fit_spec) 39 | axs[0,1].plot(f_ax, fit_spec) 40 | #axs[0,1].set_yscale('log') 41 | 42 | fft_fit_spec = np.fft.fft(fit_spec) 43 | axs[0,2].plot(freq, fft_fit_spec.real**2 + fft_fit_spec.imag**2) 44 | 45 | diff_spec = np.abs(int_spec - fit_spec) 46 | axs[1,0].plot(i_ax, diff_spec) 47 | axs[1,1].plot(i_ax, diff_spec) 48 | axs[1,1].set_yscale('log') 49 | #print(fft_fit_spec.imag) 50 | ffdiff = fft_spec - fft_fit_spec 51 | axs[1,2].plot(freq, ffdiff.real**2+ ffdiff.imag**2) 52 | 53 | 54 | plt.show() 55 | 56 | if __name__ == '__main__': 57 | # initialize element info 58 | px.load_element_info(element_henke_filename, element_csv_filename) 59 | 60 | # Select fitting routine 61 | #fit_rout = px.fitting.routines.nnls() 62 | #fit_rout = px.fitting.routines.svd() 63 | ### opt = px.fitting.optimizers.mpfit() 64 | fit_rout = px.fitting.routines.matrix() 65 | fit_rout.set_optimizer(opt) 66 | #fit_rout = px.fitting.routines.roi() 67 | 68 | # Use Gausian Model 69 | model = px.fitting.models.GaussModel() 70 | 71 | # Load fit parameters 72 | po = px.load_override_params(dataset_dir, detector_num, True) 73 | 74 | # Load dataset 75 | int_spec = load_dataset(full_path) 76 | 77 | # Initialize model and fit routine with fit parameters 78 | energy_range = px.get_energy_range(int_spec.size, po.fit_params) 79 | model.update_fit_params_values(po.fit_params) 80 | fit_rout.initialize(model, po.elements_to_fit, energy_range) 81 | 82 | # Fit element counts 83 | counts = fit_rout.fit_counts(model, int_spec, po.elements_to_fit) 84 | print(counts) 85 | 86 | # Get Fit Spectra 87 | fit_spec = fit_rout.fit_spectra(model, int_spec, po.elements_to_fit) 88 | 89 | # Resize int_spec to match fit_spec 90 | int_spec = int_spec[energy_range.min:energy_range.max+1] 91 | 92 | # Plot both 93 | plot_results(int_spec, fit_spec) -------------------------------------------------------------------------------- /src/workflow/pipeline.cpp: -------------------------------------------------------------------------------- 1 | /*** 2 | Copyright (c) 2016, UChicago Argonne, LLC. All rights reserved. 3 | 4 | Copyright 2016. UChicago Argonne, LLC. This software was produced 5 | under U.S. Government contract DE-AC02-06CH11357 for Argonne National 6 | Laboratory (ANL), which is operated by UChicago Argonne, LLC for the 7 | U.S. Department of Energy. The U.S. Government has rights to use, 8 | reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR 9 | UChicago Argonne, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 10 | ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is 11 | modified to produce derivative works, such modified software should 12 | be clearly marked, so as not to confuse it with the version available 13 | from ANL. 14 | 15 | Additionally, redistribution and use in source and binary forms, with 16 | or without modification, are permitted provided that the following 17 | conditions are met: 18 | 19 | * Redistributions of source code must retain the above copyright 20 | notice, this list of conditions and the following disclaimer. 21 | 22 | * Redistributions in binary form must reproduce the above copyright 23 | notice, this list of conditions and the following disclaimer in 24 | the documentation and/or other materials provided with the 25 | distribution. 26 | 27 | * Neither the name of UChicago Argonne, LLC, Argonne National 28 | Laboratory, ANL, the U.S. Government, nor the names of its 29 | contributors may be used to endorse or promote products derived 30 | from this software without specific prior written permission. 31 | 32 | THIS SOFTWARE IS PROVIDED BY UChicago Argonne, LLC AND CONTRIBUTORS 33 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 34 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 35 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UChicago 36 | Argonne, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 37 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 38 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 39 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 40 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 41 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 42 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | ***/ 45 | 46 | /// Initial Author <2017>: Arthur Glowacki 47 | 48 | 49 | 50 | #include "pipeline.h" 51 | 52 | namespace workflow 53 | { 54 | 55 | //----------------------------------------------------------------------------- 56 | /* 57 | Pipeline::Pipeline() 58 | { 59 | 60 | 61 | } 62 | 63 | //----------------------------------------------------------------------------- 64 | 65 | Pipeline::~Pipeline() 66 | { 67 | 68 | } 69 | 70 | bool Pipeline::append_distributor(Distributor* distributor) 71 | { 72 | _distributor_list.push_back(distributor); 73 | return true; 74 | } 75 | 76 | bool Pipeline::set_producer(Producer* producer) 77 | { 78 | _producer = producer; 79 | return true; 80 | } 81 | 82 | bool Pipeline::set_sink(Sink* sink) 83 | { 84 | _sink = sink; 85 | return true; 86 | } 87 | 88 | void Pipeline::run() 89 | { 90 | if(_producer != nullptr) 91 | { 92 | _producer->run(); 93 | } 94 | } 95 | */ 96 | //----------------------------------------------------------------------------- 97 | 98 | } //namespace workflow 99 | -------------------------------------------------------------------------------- /src/workflow/xrf/integrated_spectra_source.h: -------------------------------------------------------------------------------- 1 | /*** 2 | Copyright (c) 2016, UChicago Argonne, LLC. All rights reserved. 3 | 4 | Copyright 2016. UChicago Argonne, LLC. This software was produced 5 | under U.S. Government contract DE-AC02-06CH11357 for Argonne National 6 | Laboratory (ANL), which is operated by UChicago Argonne, LLC for the 7 | U.S. Department of Energy. The U.S. Government has rights to use, 8 | reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR 9 | UChicago Argonne, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 10 | ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is 11 | modified to produce derivative works, such modified software should 12 | be clearly marked, so as not to confuse it with the version available 13 | from ANL. 14 | 15 | Additionally, redistribution and use in source and binary forms, with 16 | or without modification, are permitted provided that the following 17 | conditions are met: 18 | 19 | * Redistributions of source code must retain the above copyright 20 | notice, this list of conditions and the following disclaimer. 21 | 22 | * Redistributions in binary form must reproduce the above copyright 23 | notice, this list of conditions and the following disclaimer in 24 | the documentation and/or other materials provided with the 25 | distribution. 26 | 27 | * Neither the name of UChicago Argonne, LLC, Argonne National 28 | Laboratory, ANL, the U.S. Government, nor the names of its 29 | contributors may be used to endorse or promote products derived 30 | from this software without specific prior written permission. 31 | 32 | THIS SOFTWARE IS PROVIDED BY UChicago Argonne, LLC AND CONTRIBUTORS 33 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 34 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 35 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UChicago 36 | Argonne, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 37 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 38 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 39 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 40 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 41 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 42 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | ***/ 45 | 46 | /// Initial Author <2017>: Arthur Glowacki 47 | 48 | 49 | 50 | #ifndef Integrated_Spectra_Source_H 51 | #define Integrated_Spectra_Source_H 52 | 53 | #include "core/defines.h" 54 | 55 | #include "workflow/xrf/spectra_file_source.h" 56 | 57 | namespace workflow 58 | { 59 | namespace xrf 60 | { 61 | 62 | //----------------------------------------------------------------------------- 63 | template 64 | class DLL_EXPORT Integrated_Spectra_Source : public Spectra_File_Source 65 | { 66 | 67 | public: 68 | 69 | Integrated_Spectra_Source(data_struct::Analysis_Job* analysis_job); 70 | 71 | virtual ~Integrated_Spectra_Source(); 72 | 73 | virtual void cb_load_spectra_data(size_t row, size_t col, size_t height, size_t width, size_t detector_num, data_struct::Spectra* spectra, void* user_data); 74 | 75 | protected: 76 | 77 | std::map*> _stream_block_list; 78 | 79 | }; 80 | 81 | } //namespace xrf 82 | } //namespace workflow 83 | 84 | #endif // Integrated_Spectra_Source_H 85 | -------------------------------------------------------------------------------- /src/data_struct/spectra_line.h: -------------------------------------------------------------------------------- 1 | /*** 2 | Copyright (c) 2016, UChicago Argonne, LLC. All rights reserved. 3 | 4 | Copyright 2016. UChicago Argonne, LLC. This software was produced 5 | under U.S. Government contract DE-AC02-06CH11357 for Argonne National 6 | Laboratory (ANL), which is operated by UChicago Argonne, LLC for the 7 | U.S. Department of Energy. The U.S. Government has rights to use, 8 | reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR 9 | UChicago Argonne, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 10 | ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is 11 | modified to produce derivative works, such modified software should 12 | be clearly marked, so as not to confuse it with the version available 13 | from ANL. 14 | 15 | Additionally, redistribution and use in source and binary forms, with 16 | or without modification, are permitted provided that the following 17 | conditions are met: 18 | 19 | * Redistributions of source code must retain the above copyright 20 | notice, this list of conditions and the following disclaimer. 21 | 22 | * Redistributions in binary form must reproduce the above copyright 23 | notice, this list of conditions and the following disclaimer in 24 | the documentation and/or other materials provided with the 25 | distribution. 26 | 27 | * Neither the name of UChicago Argonne, LLC, Argonne National 28 | Laboratory, ANL, the U.S. Government, nor the names of its 29 | contributors may be used to endorse or promote products derived 30 | from this software without specific prior written permission. 31 | 32 | THIS SOFTWARE IS PROVIDED BY UChicago Argonne, LLC AND CONTRIBUTORS 33 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 34 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 35 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UChicago 36 | Argonne, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 37 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 38 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 39 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 40 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 41 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 42 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | ***/ 45 | 46 | /// Initial Author <2016>: Arthur Glowacki 47 | 48 | 49 | 50 | #ifndef SPECTRALINE_H 51 | #define SPECTRALINE_H 52 | 53 | #include "data_struct/spectra.h" 54 | #include 55 | 56 | namespace data_struct 57 | { 58 | 59 | /** 60 | * @brief The Spectra_Line class : A row of spectras 61 | */ 62 | template 63 | class DLL_EXPORT Spectra_Line 64 | { 65 | public: 66 | Spectra_Line(); 67 | 68 | ~Spectra_Line(); 69 | 70 | Spectra& operator [](std::size_t row) { return _data_line[row]; } 71 | 72 | const Spectra& operator [](std::size_t row) const { return _data_line[row]; } 73 | 74 | void resize_and_zero(size_t cols, size_t samples); 75 | 76 | void resize_samples(size_t samples); 77 | 78 | void alloc_row_size(size_t n); 79 | 80 | void recalc_elapsed_livetime(); 81 | 82 | auto size() const { return _data_line.size(); } 83 | 84 | private: 85 | 86 | 87 | void _alloc_spectra_size(size_t n); 88 | 89 | std::vector > _data_line; 90 | 91 | }; 92 | 93 | } //namespace data_struct 94 | 95 | #endif // SPECTRALINE_H 96 | -------------------------------------------------------------------------------- /src/workflow/xrf/detector_sum_spectra_source.h: -------------------------------------------------------------------------------- 1 | /*** 2 | Copyright (c) 2016, UChicago Argonne, LLC. All rights reserved. 3 | 4 | Copyright 2016. UChicago Argonne, LLC. This software was produced 5 | under U.S. Government contract DE-AC02-06CH11357 for Argonne National 6 | Laboratory (ANL), which is operated by UChicago Argonne, LLC for the 7 | U.S. Department of Energy. The U.S. Government has rights to use, 8 | reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR 9 | UChicago Argonne, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 10 | ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is 11 | modified to produce derivative works, such modified software should 12 | be clearly marked, so as not to confuse it with the version available 13 | from ANL. 14 | 15 | Additionally, redistribution and use in source and binary forms, with 16 | or without modification, are permitted provided that the following 17 | conditions are met: 18 | 19 | * Redistributions of source code must retain the above copyright 20 | notice, this list of conditions and the following disclaimer. 21 | 22 | * Redistributions in binary form must reproduce the above copyright 23 | notice, this list of conditions and the following disclaimer in 24 | the documentation and/or other materials provided with the 25 | distribution. 26 | 27 | * Neither the name of UChicago Argonne, LLC, Argonne National 28 | Laboratory, ANL, the U.S. Government, nor the names of its 29 | contributors may be used to endorse or promote products derived 30 | from this software without specific prior written permission. 31 | 32 | THIS SOFTWARE IS PROVIDED BY UChicago Argonne, LLC AND CONTRIBUTORS 33 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 34 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 35 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UChicago 36 | Argonne, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 37 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 38 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 39 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 40 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 41 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 42 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | ***/ 45 | 46 | /// Initial Author <2017>: Arthur Glowacki 47 | 48 | 49 | 50 | #ifndef Detector_Sum_Spectra_Source_H 51 | #define Detector_Sum_Spectra_Source_H 52 | 53 | #include "core/defines.h" 54 | 55 | #include "workflow/xrf/spectra_file_source.h" 56 | 57 | namespace workflow 58 | { 59 | namespace xrf 60 | { 61 | 62 | //----------------------------------------------------------------------------- 63 | template 64 | class DLL_EXPORT Detector_Sum_Spectra_Source : public Spectra_File_Source 65 | { 66 | 67 | public: 68 | 69 | Detector_Sum_Spectra_Source(); 70 | 71 | Detector_Sum_Spectra_Source(data_struct::Analysis_Job* analysis_job); 72 | 73 | virtual ~Detector_Sum_Spectra_Source(); 74 | 75 | virtual void cb_load_spectra_data(size_t row, size_t col, size_t height, size_t width, size_t detector_num, data_struct::Spectra* spectra, void* user_data); 76 | 77 | protected: 78 | 79 | std::vector _detector_num_arr; 80 | data_struct::Spectra* _spectra; 81 | }; 82 | 83 | } //namespace xrf 84 | } //namespace workflow 85 | 86 | #endif // Detector_Sum_Spectra_Source_H 87 | -------------------------------------------------------------------------------- /src/core/command_line_parser.h: -------------------------------------------------------------------------------- 1 | /*** 2 | Copyright (c) 2016, UChicago Argonne, LLC. All rights reserved. 3 | 4 | Copyright 2016. UChicago Argonne, LLC. This software was produced 5 | under U.S. Government contract DE-AC02-06CH11357 for Argonne National 6 | Laboratory (ANL), which is operated by UChicago Argonne, LLC for the 7 | U.S. Department of Energy. The U.S. Government has rights to use, 8 | reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR 9 | UChicago Argonne, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 10 | ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is 11 | modified to produce derivative works, such modified software should 12 | be clearly marked, so as not to confuse it with the version available 13 | from ANL. 14 | 15 | Additionally, redistribution and use in source and binary forms, with 16 | or without modification, are permitted provided that the following 17 | conditions are met: 18 | 19 | * Redistributions of source code must retain the above copyright 20 | notice, this list of conditions and the following disclaimer. 21 | 22 | * Redistributions in binary form must reproduce the above copyright 23 | notice, this list of conditions and the following disclaimer in 24 | the documentation and/or other materials provided with the 25 | distribution. 26 | 27 | * Neither the name of UChicago Argonne, LLC, Argonne National 28 | Laboratory, ANL, the U.S. Government, nor the names of its 29 | contributors may be used to endorse or promote products derived 30 | from this software without specific prior written permission. 31 | 32 | THIS SOFTWARE IS PROVIDED BY UChicago Argonne, LLC AND CONTRIBUTORS 33 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 34 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 35 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UChicago 36 | Argonne, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 37 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 38 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 39 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 40 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 41 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 42 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | ***/ 45 | 46 | /// Initial Author <2016>: Arthur Glowacki 47 | 48 | #ifndef Command_Line_Parser_H 49 | #define Command_Line_Parser_H 50 | 51 | #include 52 | #include 53 | #include 54 | 55 | 56 | class Command_Line_Parser 57 | { 58 | public: 59 | Command_Line_Parser (int &argc, char **argv) 60 | { 61 | for (int i=1; i < argc; ++i) 62 | { 63 | this->tokens.push_back(std::string(argv[i])); 64 | } 65 | } 66 | 67 | std::string get_option(const std::string &option) const 68 | { 69 | std::vector::const_iterator itr; 70 | itr = std::find(this->tokens.begin(), this->tokens.end(), option); 71 | if (itr != this->tokens.end() && ++itr != this->tokens.end()) 72 | { 73 | return *itr; 74 | } 75 | return ""; 76 | } 77 | 78 | bool option_exists(const std::string &option) const 79 | { 80 | return std::find(this->tokens.begin(), this->tokens.end(), option) != this->tokens.end(); 81 | } 82 | 83 | private: 84 | std::vector tokens; 85 | }; 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /src/support/mdautils-1.4.1/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 UChicago Argonne, LLC. All rights reserved. 2 | 3 | MDA Utilities are distributed subject to the following license conditions: 4 | 5 | SOFTWARE LICENSE AGREEMENT 6 | Software: MDA Utilities 7 | 8 | 1. The "Software", below, refers to MDA Utilities (in either source 9 | code, or binary form and accompanying documentation). Each licensee 10 | is addressed as "you" or "Licensee." 11 | 12 | 2. The copyright holders shown above and their third-party licensors 13 | hereby grant Licensee a royalty-free nonexclusive license, subject to 14 | the limitations stated herein and U.S. Government license rights. 15 | 16 | 3. You may modify and make a copy or copies of the Software for use 17 | within your organization, if you meet the following conditions: 18 | a. Copies in source code must include the copyright notice and this 19 | Software License Agreement. 20 | b. Copies in binary form must include the copyright notice and this 21 | Software License Agreement in the documentation and/or other 22 | materials provided with the copy. 23 | 24 | 4. You may modify a copy or copies of the Software or any portion of it, 25 | thus forming a work based on the Software, and distribute copies of 26 | such work outside your organization, if you meet all of the following 27 | conditions: 28 | a. Copies in source code must include the copyright notice and this 29 | Software License Agreement; 30 | b. Copies in binary form must include the copyright notice and this 31 | Software License Agreement in the documentation and/or other 32 | materials provided with the copy; 33 | c. Modified copies and works based on the Software must carry 34 | prominent notices stating that you changed specified portions of 35 | the Software. 36 | 37 | 5. Portions of the Software resulted from work developed under a U.S. 38 | Government contract and are subject to the following license: the 39 | Government is granted for itself and others acting on its behalf a 40 | paid-up, nonexclusive, irrevocable worldwide license in this computer 41 | software to reproduce, prepare derivative works, and perform publicly 42 | and display publicly. 43 | 44 | 6. WARRANTY DISCLAIMER. THE SOFTWARE IS SUPPLIED "AS IS" WITHOUT WARRANTY 45 | OF ANY KIND. THE COPYRIGHT HOLDERS, THEIR THIRD PARTY LICENSORS, THE 46 | UNITED STATES, THE UNITED STATES DEPARTMENT OF ENERGY, AND THEIR 47 | EMPLOYEES: (1) DISCLAIM ANY WARRANTIES, EXPRESS OR IMPLIED, INCLUDING 48 | BUT NOT LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 49 | FOR A PARTICULAR PURPOSE, TITLE OR NON-INFRINGEMENT, (2) DO NOT ASSUME 50 | ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, 51 | OR USEFULNESS OF THE SOFTWARE, (3) DO NOT REPRESENT THAT USE OF THE 52 | SOFTWARE WOULD NOT INFRINGE PRIVATELY OWNED RIGHTS, (4) DO NOT WARRANT 53 | THAT THE SOFTWARE WILL FUNCTION UNINTERRUPTED, THAT IT IS ERROR-FREE 54 | OR THAT ANY ERRORS WILL BE CORRECTED. 55 | 56 | 7. LIMITATION OF LIABILITY. IN NO EVENT WILL THE COPYRIGHT HOLDERS, THEIR 57 | THIRD PARTY LICENSORS, THE UNITED STATES, THE UNITED STATES DEPARTMENT 58 | OF ENERGY, OR THEIR EMPLOYEES: BE LIABLE FOR ANY INDIRECT, INCIDENTAL, 59 | CONSEQUENTIAL, SPECIAL OR PUNITIVE DAMAGES OF ANY KIND OR NATURE, 60 | INCLUDING BUT NOT LIMITED TO LOSS OF PROFITS OR LOSS OF DATA, FOR ANY 61 | REASON WHATSOEVER, WHETHER SUCH LIABILITY IS ASSERTED ON THE BASIS OF 62 | CONTRACT, TORT (INCLUDING NEGLIGENCE OR STRICT LIABILITY), OR 63 | OTHERWISE, EVEN IF ANY OF SAID PARTIES HAS BEEN WARNED OF THE 64 | POSSIBILITY OF SUCH LOSS OR DAMAGES. 65 | 66 | -------------------------------------------------------------------------------- /src/workflow/xrf/spectra_net_source.h: -------------------------------------------------------------------------------- 1 | /*** 2 | Copyright (c) 2016, UChicago Argonne, LLC. All rights reserved. 3 | 4 | Copyright 2016. UChicago Argonne, LLC. This software was produced 5 | under U.S. Government contract DE-AC02-06CH11357 for Argonne National 6 | Laboratory (ANL), which is operated by UChicago Argonne, LLC for the 7 | U.S. Department of Energy. The U.S. Government has rights to use, 8 | reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR 9 | UChicago Argonne, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 10 | ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is 11 | modified to produce derivative works, such modified software should 12 | be clearly marked, so as not to confuse it with the version available 13 | from ANL. 14 | 15 | Additionally, redistribution and use in source and binary forms, with 16 | or without modification, are permitted provided that the following 17 | conditions are met: 18 | 19 | * Redistributions of source code must retain the above copyright 20 | notice, this list of conditions and the following disclaimer. 21 | 22 | * Redistributions in binary form must reproduce the above copyright 23 | notice, this list of conditions and the following disclaimer in 24 | the documentation and/or other materials provided with the 25 | distribution. 26 | 27 | * Neither the name of UChicago Argonne, LLC, Argonne National 28 | Laboratory, ANL, the U.S. Government, nor the names of its 29 | contributors may be used to endorse or promote products derived 30 | from this software without specific prior written permission. 31 | 32 | THIS SOFTWARE IS PROVIDED BY UChicago Argonne, LLC AND CONTRIBUTORS 33 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 34 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 35 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UChicago 36 | Argonne, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 37 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 38 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 39 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 40 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 41 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 42 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | ***/ 45 | 46 | /// Initial Author <2017>: Arthur Glowacki 47 | 48 | 49 | 50 | #ifndef Spectra_Net_Source_H 51 | #define Spectra_Net_Source_H 52 | 53 | #include "core/defines.h" 54 | 55 | #include "workflow/source.h" 56 | #include "data_struct/stream_block.h" 57 | #include "io/net/basic_serializer.h" 58 | #include "data_struct/analysis_job.h" 59 | #ifdef _BUILD_WITH_ZMQ 60 | #include 61 | #endif 62 | namespace workflow 63 | { 64 | namespace xrf 65 | { 66 | 67 | //----------------------------------------------------------------------------- 68 | template 69 | class DLL_EXPORT Spectra_Net_Source : public Source*> 70 | { 71 | 72 | public: 73 | 74 | Spectra_Net_Source(data_struct::Analysis_Job* analysis_job, std::string ip_addr="127.0.0.1", std::string port = "43434"); 75 | 76 | virtual ~Spectra_Net_Source(); 77 | 78 | virtual void run(); 79 | 80 | protected: 81 | 82 | bool _running; 83 | 84 | std::string _conn_str; 85 | 86 | io::net::Basic_Serializer _serializer; 87 | 88 | data_struct::Analysis_Job* _analysis_job; 89 | 90 | #ifdef _BUILD_WITH_ZMQ 91 | zmq::context_t *_context; 92 | 93 | zmq::socket_t *_zmq_socket; 94 | #endif 95 | }; 96 | 97 | } //namespace xrf 98 | } //namespace workflow 99 | 100 | #endif // Spectra_Net_Source_H 101 | -------------------------------------------------------------------------------- /src/fitting/routines/roi_fit_routine.h: -------------------------------------------------------------------------------- 1 | /*** 2 | Copyright (c) 2016, UChicago Argonne, LLC. All rights reserved. 3 | 4 | Copyright 2016. UChicago Argonne, LLC. This software was produced 5 | under U.S. Government contract DE-AC02-06CH11357 for Argonne National 6 | Laboratory (ANL), which is operated by UChicago Argonne, LLC for the 7 | U.S. Department of Energy. The U.S. Government has rights to use, 8 | reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR 9 | UChicago Argonne, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 10 | ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is 11 | modified to produce derivative works, such modified software should 12 | be clearly marked, so as not to confuse it with the version available 13 | from ANL. 14 | 15 | Additionally, redistribution and use in source and binary forms, with 16 | or without modification, are permitted provided that the following 17 | conditions are met: 18 | 19 | * Redistributions of source code must retain the above copyright 20 | notice, this list of conditions and the following disclaimer. 21 | 22 | * Redistributions in binary form must reproduce the above copyright 23 | notice, this list of conditions and the following disclaimer in 24 | the documentation and/or other materials provided with the 25 | distribution. 26 | 27 | * Neither the name of UChicago Argonne, LLC, Argonne National 28 | Laboratory, ANL, the U.S. Government, nor the names of its 29 | contributors may be used to endorse or promote products derived 30 | from this software without specific prior written permission. 31 | 32 | THIS SOFTWARE IS PROVIDED BY UChicago Argonne, LLC AND CONTRIBUTORS 33 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 34 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 35 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UChicago 36 | Argonne, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 37 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 38 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 39 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 40 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 41 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 42 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | ***/ 45 | 46 | /// Initial Author <2016>: Arthur Glowacki 47 | 48 | 49 | 50 | #ifndef ROI_Fit_Routine_H 51 | #define ROI_Fit_Routine_H 52 | 53 | #include "fitting/routines/base_fit_routine.h" 54 | 55 | namespace fitting 56 | { 57 | namespace routines 58 | { 59 | 60 | using namespace data_struct; 61 | 62 | template 63 | class DLL_EXPORT ROI_Fit_Routine: public Base_Fit_Routine 64 | { 65 | public: 66 | ROI_Fit_Routine(); 67 | 68 | virtual ~ROI_Fit_Routine(); 69 | 70 | virtual optimizers::OPTIMIZER_OUTCOME fit_spectra(const models::Base_Model* const model, 71 | const Spectra* const spectra, 72 | const Fit_Element_Map_Dict* const elements_to_fit, 73 | std::unordered_map& out_counts); 74 | 75 | 76 | virtual std::string get_name() { return STR_FIT_ROI; } 77 | 78 | virtual void initialize(models::Base_Model* const model, 79 | const Fit_Element_Map_Dict* const elements_to_fit, 80 | const struct Range energy_range, 81 | ArrayTr* custom_background); 82 | 83 | void set_fit_separate_shells(bool val) { _separate_shells = val;} 84 | protected: 85 | 86 | bool _separate_shells; 87 | 88 | 89 | private: 90 | 91 | }; 92 | 93 | } //namespace routines 94 | 95 | } //namespace fitting 96 | 97 | #endif // ROI_Fit_Routine_H 98 | -------------------------------------------------------------------------------- /src/workflow/xrf/spectra_net_streamer.h: -------------------------------------------------------------------------------- 1 | /*** 2 | Copyright (c) 2016, UChicago Argonne, LLC. All rights reserved. 3 | 4 | Copyright 2016. UChicago Argonne, LLC. This software was produced 5 | under U.S. Government contract DE-AC02-06CH11357 for Argonne National 6 | Laboratory (ANL), which is operated by UChicago Argonne, LLC for the 7 | U.S. Department of Energy. The U.S. Government has rights to use, 8 | reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR 9 | UChicago Argonne, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 10 | ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is 11 | modified to produce derivative works, such modified software should 12 | be clearly marked, so as not to confuse it with the version available 13 | from ANL. 14 | 15 | Additionally, redistribution and use in source and binary forms, with 16 | or without modification, are permitted provided that the following 17 | conditions are met: 18 | 19 | * Redistributions of source code must retain the above copyright 20 | notice, this list of conditions and the following disclaimer. 21 | 22 | * Redistributions in binary form must reproduce the above copyright 23 | notice, this list of conditions and the following disclaimer in 24 | the documentation and/or other materials provided with the 25 | distribution. 26 | 27 | * Neither the name of UChicago Argonne, LLC, Argonne National 28 | Laboratory, ANL, the U.S. Government, nor the names of its 29 | contributors may be used to endorse or promote products derived 30 | from this software without specific prior written permission. 31 | 32 | THIS SOFTWARE IS PROVIDED BY UChicago Argonne, LLC AND CONTRIBUTORS 33 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 34 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 35 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UChicago 36 | Argonne, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 37 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 38 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 39 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 40 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 41 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 42 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | ***/ 45 | 46 | /// Initial Author <2017>: Arthur Glowacki 47 | 48 | 49 | 50 | #ifndef Spectra_Net_Streamer_H 51 | #define Spectra_Net_Streamer_H 52 | 53 | #include "core/defines.h" 54 | 55 | #include "workflow/sink.h" 56 | #include "data_struct/stream_block.h" 57 | #include "io/net/basic_serializer.h" 58 | #ifdef _BUILD_WITH_ZMQ 59 | #include 60 | #endif 61 | namespace workflow 62 | { 63 | namespace xrf 64 | { 65 | 66 | //----------------------------------------------------------------------------- 67 | template 68 | class DLL_EXPORT Spectra_Net_Streamer : public Sink* > 69 | { 70 | 71 | public: 72 | 73 | Spectra_Net_Streamer(std::string port = "43434"); 74 | 75 | virtual ~Spectra_Net_Streamer(); 76 | 77 | void stream(data_struct::Stream_Block* stream_block); 78 | 79 | void set_send_counts(bool val) {_send_counts = val;} 80 | 81 | void set_send_spectra(bool val) {_send_spectra = val;} 82 | 83 | void set_verbose(bool val) {_verbose = val;} 84 | protected: 85 | #ifdef _BUILD_WITH_ZMQ 86 | zmq::context_t *_context; 87 | 88 | zmq::socket_t *_zmq_socket; 89 | #endif 90 | io::net::Basic_Serializer _serializer; 91 | 92 | bool _send_counts; 93 | 94 | bool _send_spectra; 95 | 96 | bool _verbose; 97 | }; 98 | 99 | //----------------------------------------------------------------------------- 100 | 101 | } //namespace xrf 102 | } //namespace workflow 103 | 104 | #endif // Spectra_Net_Streamer_H 105 | -------------------------------------------------------------------------------- /src/data_struct/spectra_volume.h: -------------------------------------------------------------------------------- 1 | /*** 2 | Copyright (c) 2016, UChicago Argonne, LLC. All rights reserved. 3 | 4 | Copyright 2016. UChicago Argonne, LLC. This software was produced 5 | under U.S. Government contract DE-AC02-06CH11357 for Argonne National 6 | Laboratory (ANL), which is operated by UChicago Argonne, LLC for the 7 | U.S. Department of Energy. The U.S. Government has rights to use, 8 | reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR 9 | UChicago Argonne, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 10 | ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is 11 | modified to produce derivative works, such modified software should 12 | be clearly marked, so as not to confuse it with the version available 13 | from ANL. 14 | 15 | Additionally, redistribution and use in source and binary forms, with 16 | or without modification, are permitted provided that the following 17 | conditions are met: 18 | 19 | * Redistributions of source code must retain the above copyright 20 | notice, this list of conditions and the following disclaimer. 21 | 22 | * Redistributions in binary form must reproduce the above copyright 23 | notice, this list of conditions and the following disclaimer in 24 | the documentation and/or other materials provided with the 25 | distribution. 26 | 27 | * Neither the name of UChicago Argonne, LLC, Argonne National 28 | Laboratory, ANL, the U.S. Government, nor the names of its 29 | contributors may be used to endorse or promote products derived 30 | from this software without specific prior written permission. 31 | 32 | THIS SOFTWARE IS PROVIDED BY UChicago Argonne, LLC AND CONTRIBUTORS 33 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 34 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 35 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UChicago 36 | Argonne, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 37 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 38 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 39 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 40 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 41 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 42 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | ***/ 45 | 46 | /// Initial Author <2016>: Arthur Glowacki 47 | 48 | 49 | 50 | #ifndef SPECTRAVOLUME_H 51 | #define SPECTRAVOLUME_H 52 | 53 | #include "data_struct/spectra_line.h" 54 | #include "scan_info.h" 55 | 56 | namespace data_struct 57 | { 58 | 59 | /** 60 | * @brief The Spectra_Volume class : A volume of spectras 61 | */ 62 | template 63 | class DLL_EXPORT Spectra_Volume 64 | { 65 | public: 66 | Spectra_Volume(); 67 | 68 | ~Spectra_Volume(); 69 | 70 | Spectra_Line& operator [](std::size_t row) { return _data_vol[row]; } 71 | 72 | const Spectra_Line& operator [](std::size_t row) const { return _data_vol[row]; } 73 | 74 | void resize_and_zero(size_t rows, size_t cols, size_t samples); 75 | 76 | void resize_samples(size_t samples); 77 | 78 | Spectra integrate(); 79 | 80 | bool integrate_polar(Spectra &lhs, Spectra &rhs); 81 | 82 | void generate_scaler_maps(std::vector>* scaler_maps); 83 | 84 | size_t cols() const { if (_data_vol.size() > 0) return _data_vol[0].size(); else return 0; } 85 | 86 | size_t rows() const { return _data_vol.size(); } 87 | 88 | void recalc_elapsed_livetime(); 89 | 90 | size_t samples_size() const { if (_data_vol.size() > 0) return _data_vol[0][0].size(); else return 0; } 91 | 92 | int rank() { return 3; } 93 | 94 | private: 95 | 96 | std::vector > _data_vol; 97 | 98 | }; 99 | 100 | } //namespace data_struct 101 | 102 | #endif // SpectraVolume_H 103 | -------------------------------------------------------------------------------- /src/workflow/pipeline.h: -------------------------------------------------------------------------------- 1 | /*** 2 | Copyright (c) 2016, UChicago Argonne, LLC. All rights reserved. 3 | 4 | Copyright 2016. UChicago Argonne, LLC. This software was produced 5 | under U.S. Government contract DE-AC02-06CH11357 for Argonne National 6 | Laboratory (ANL), which is operated by UChicago Argonne, LLC for the 7 | U.S. Department of Energy. The U.S. Government has rights to use, 8 | reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR 9 | UChicago Argonne, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 10 | ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is 11 | modified to produce derivative works, such modified software should 12 | be clearly marked, so as not to confuse it with the version available 13 | from ANL. 14 | 15 | Additionally, redistribution and use in source and binary forms, with 16 | or without modification, are permitted provided that the following 17 | conditions are met: 18 | 19 | * Redistributions of source code must retain the above copyright 20 | notice, this list of conditions and the following disclaimer. 21 | 22 | * Redistributions in binary form must reproduce the above copyright 23 | notice, this list of conditions and the following disclaimer in 24 | the documentation and/or other materials provided with the 25 | distribution. 26 | 27 | * Neither the name of UChicago Argonne, LLC, Argonne National 28 | Laboratory, ANL, the U.S. Government, nor the names of its 29 | contributors may be used to endorse or promote products derived 30 | from this software without specific prior written permission. 31 | 32 | THIS SOFTWARE IS PROVIDED BY UChicago Argonne, LLC AND CONTRIBUTORS 33 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 34 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 35 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UChicago 36 | Argonne, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 37 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 38 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 39 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 40 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 41 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 42 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | ***/ 45 | 46 | /// Initial Author <2017>: Arthur Glowacki 47 | 48 | 49 | 50 | #ifndef Pipeline_H 51 | #define Pipeline_H 52 | 53 | #include "core/defines.h" 54 | #include "workflow/source.h" 55 | #include "workflow/distributor.h" 56 | #include "workflow/sink.h" 57 | 58 | namespace workflow 59 | { 60 | 61 | //----------------------------------------------------------------------------- 62 | template 63 | class DLL_EXPORT Simple_Pipeline 64 | { 65 | 66 | public: 67 | 68 | Simple_Pipeline(int num_threads) 69 | { 70 | _distributor = new Distributor<_T, _T>(num_threads); 71 | 72 | _producer.connect(_distributor->get_callback_func()); 73 | _distributor->connect(_sink.get_job_queue()); 74 | } 75 | 76 | ~Simple_Pipeline() 77 | { 78 | delete _distributor; 79 | } 80 | 81 | void set_producer_func(std::function<_T (void*)> func) 82 | { 83 | _producer.set_function(func); 84 | } 85 | 86 | void set_distributor_func(std::function<_T (_T)> func) 87 | { 88 | _distributor->set_function(func); 89 | } 90 | 91 | void set_sink_func(std::function func) 92 | { 93 | _sink.set_function(func); 94 | } 95 | 96 | void run() 97 | { 98 | _sink.start(); 99 | _producer.run(); 100 | _sink.wait_and_stop(); 101 | } 102 | 103 | protected: 104 | 105 | Source<_T> _producer; 106 | Distributor<_T, _T> *_distributor; 107 | Sink<_T> _sink; 108 | 109 | }; 110 | 111 | } //namespace workflow 112 | 113 | #endif // Pipeline_H 114 | -------------------------------------------------------------------------------- /src/support/mdautils-1.4.1/mdatree2ascii: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # mdatree2ascii 4 | 5 | # Copyright (c) 2016 UChicago Argonne, LLC, 6 | # as Operator of Argonne National Laboratory. 7 | # This file is distributed subject to a Software License Agreement 8 | # found in file LICENSE that is included with this distribution. 9 | 10 | # Written by Dohn A. Arms, Argonne National Laboratory 11 | # Send comments to dohnarms@anl.gov 12 | 13 | # 1.3.0 -- February 2013 14 | # Initial version 15 | # 1.3.1 -- February 2014 16 | # 1.4.0 -- July 2016 17 | # 1.4.1 -- August 2016 18 | 19 | 20 | VERBOSE=0; 21 | FOPT="-H"; 22 | SOPT="-type f"; 23 | EXT="mda"; 24 | while [ 1 ]; do 25 | case $1 in 26 | -v) VERSION=1;; 27 | -h) HELP=1;; 28 | -d) VERBOSE=1;; 29 | -f) FOPT="-L";; 30 | -s) SOPT="-xtype f";; 31 | -x) EXT=$2; shift;; 32 | *) break;; 33 | esac 34 | shift; 35 | done 36 | 37 | if (( VERSION == 1 )) ; then 38 | echo "mdatree2ascii 1.4.1 (August 2016)"; 39 | echo ""; 40 | echo "Copyright (c) 2016 UChicago Argonne, LLC,"; 41 | echo "as Operator of Argonne National Laboratory."; 42 | echo ""; 43 | echo "Written by Dohn Arms, dohnarms@anl.gov."; 44 | exit 0 45 | fi 46 | 47 | if (( HELP == 1 )) ; then 48 | echo "Usage: mdatree2ascii [-h] [-v] [-d] [-f] [-s] [-x EXTENSION]"; 49 | echo " SOURCE_DIR OUTPUT_DIR [MDA2ASCII_OPTIONS]"; 50 | echo ""; 51 | echo "This script will recursively search the source directory for MDA files, and"; 52 | echo "create a parallel output directory populated by mda2ascii translated files."; 53 | echo "It will display the directory currently processing, and any errors that"; 54 | echo "'mda2ascii' encounters will be displayed, but the script will continue." 55 | echo "Options for 'mda2ascii' can be specified, except for -d and -o."; 56 | echo ""; 57 | echo "-h This help text."; 58 | echo "-v Show version information." 59 | echo "-d Display the name of the current MDA file being converted."; 60 | echo "-f Follow symbolic links to directories while searching the tree."; 61 | echo "-s Convert MDA files that are actually symbolic links."; 62 | echo "-x Change extension for searching for MDA files to something other than \"mda\"."; 63 | echo ""; 64 | echo "It runs the copy of 'mda2ascii' found in the PATH, but an explicit location can"; 65 | echo "be used by setting the variable MDA2ASCII to the location of 'mda2ascii'."; 66 | exit 0 67 | fi 68 | 69 | 70 | if [ ${#@} -lt 2 ]; then 71 | echo "For help, type: mdatree2ascii -h" 72 | exit 0 73 | fi 74 | 75 | 76 | if [ -z "$MDA2ASCII" ] ; then 77 | MDA2ASCII="mda2ascii" 78 | fi 79 | MY_MDA2ASCII=$(type -P $MDA2ASCII) 80 | if (( $? != 0 )) ; then 81 | echo "Can't find/execute command \"$MDA2ASCII\"."; 82 | exit; 83 | fi 84 | 85 | 86 | if [ ! -d "$1" ] ; then 87 | echo "The argument in the source directory position is not a directory."; 88 | exit 0; 89 | fi 90 | 91 | # force tilde expansion 92 | SRCDIR=`echo $1` 93 | DESTDIR=`echo $2` 94 | shift 2 95 | 96 | OLD_OUTDIR="" 97 | LEVEL=0 98 | SRCS=($( find $FOPT $SRCDIR -name "*.$EXT" $SOPT )) 99 | echo "Searching directory tree \"$SRCDIR\" for files." 100 | ALEN=${#SRCS[@]} 101 | for((i=0; i<${ALEN}; i++)); do 102 | OUT=$(echo ${SRCS[i]} | sed -e "s:$SRCDIR::" -e "s:^/::" -e "s:.$EXT::"); 103 | OUTDIR=${DESTDIR}/$(dirname ${OUT}) 104 | # if this is the first file for a directory, do this 105 | if [ "$OUTDIR" != "$OLD_OUTDIR" ] ; then 106 | mkdir -p $OUTDIR 107 | if (( $? != 0 )) ; then 108 | echo "Exiting! Can't create directory \"$OUTDIR\"."; 109 | exit; 110 | fi 111 | OLD_OUTDIR=${OUTDIR} 112 | PROC_DIR=$(dirname ${SRCS[i]}); 113 | echo "Processing: $PROC_DIR" 114 | fi 115 | if (( VERBOSE == 1 )) ; then 116 | echo ${SRCS[i]}; 117 | fi 118 | $MY_MDA2ASCII ${@} -o ${DESTDIR}/${OUT} ${SRCS[i]} 119 | done 120 | -------------------------------------------------------------------------------- /src/fitting/routines/svd_fit_routine.h: -------------------------------------------------------------------------------- 1 | /*** 2 | Copyright (c) 2016, UChicago Argonne, LLC. All rights reserved. 3 | 4 | Copyright 2016. UChicago Argonne, LLC. This software was produced 5 | under U.S. Government contract DE-AC02-06CH11357 for Argonne National 6 | Laboratory (ANL), which is operated by UChicago Argonne, LLC for the 7 | U.S. Department of Energy. The U.S. Government has rights to use, 8 | reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR 9 | UChicago Argonne, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 10 | ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is 11 | modified to produce derivative works, such modified software should 12 | be clearly marked, so as not to confuse it with the version available 13 | from ANL. 14 | 15 | Additionally, redistribution and use in source and binary forms, with 16 | or without modification, are permitted provided that the following 17 | conditions are met: 18 | 19 | * Redistributions of source code must retain the above copyright 20 | notice, this list of conditions and the following disclaimer. 21 | 22 | * Redistributions in binary form must reproduce the above copyright 23 | notice, this list of conditions and the following disclaimer in 24 | the documentation and/or other materials provided with the 25 | distribution. 26 | 27 | * Neither the name of UChicago Argonne, LLC, Argonne National 28 | Laboratory, ANL, the U.S. Government, nor the names of its 29 | contributors may be used to endorse or promote products derived 30 | from this software without specific prior written permission. 31 | 32 | THIS SOFTWARE IS PROVIDED BY UChicago Argonne, LLC AND CONTRIBUTORS 33 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 34 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 35 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UChicago 36 | Argonne, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 37 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 38 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 39 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 40 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 41 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 42 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | ***/ 45 | 46 | /// Initial Author <2016>: Arthur Glowacki 47 | 48 | 49 | 50 | #ifndef SVD_Fit_Routine_H 51 | #define SVD_Fit_Routine_H 52 | 53 | #include "fitting/routines/matrix_optimized_fit_routine.h" 54 | 55 | #include 56 | 57 | namespace fitting 58 | { 59 | namespace routines 60 | { 61 | 62 | using namespace data_struct; 63 | 64 | template 65 | class DLL_EXPORT SVD_Fit_Routine: public Matrix_Optimized_Fit_Routine 66 | { 67 | public: 68 | 69 | SVD_Fit_Routine(); 70 | 71 | virtual ~SVD_Fit_Routine(); 72 | 73 | virtual optimizers::OPTIMIZER_OUTCOME fit_spectra(const models::Base_Model* const model, 74 | const Spectra* const spectra, 75 | const Fit_Element_Map_Dict* const elements_to_fit, 76 | std::unordered_map& out_counts); 77 | 78 | 79 | virtual std::string get_name() { return STR_FIT_SVD; } 80 | 81 | virtual void initialize(models::Base_Model* const model, 82 | const Fit_Element_Map_Dict* const elements_to_fit, 83 | const struct Range energy_range, 84 | ArrayTr* custom_background); 85 | 86 | protected: 87 | 88 | void _generate_fitmatrix(); 89 | 90 | private: 91 | 92 | Eigen::Matrix _fitmatrix; 93 | 94 | std::unordered_map _element_row_index; 95 | 96 | }; 97 | 98 | } //namespace routines 99 | 100 | } //namespace fitting 101 | 102 | #endif // SVD_Fit_Routine_H 103 | -------------------------------------------------------------------------------- /src/workflow/threadpool.h: -------------------------------------------------------------------------------- 1 | /*** 2 | 3 | From https://github.com/progschj/ThreadPool 4 | 5 | Copyright (c) 2012 Jakob Progsch, Václav Zeman 6 | 7 | This software is provided 'as-is', without any express or implied 8 | warranty. In no event will the authors be held liable for any damages 9 | arising from the use of this software. 10 | 11 | Permission is granted to anyone to use this software for any purpose, 12 | including commercial applications, and to alter it and redistribute it 13 | freely, subject to the following restrictions: 14 | 15 | 1. The origin of this software must not be misrepresented; you must not 16 | claim that you wrote the original software. If you use this software 17 | in a product, an acknowledgment in the product documentation would be 18 | appreciated but is not required. 19 | 20 | 2. Altered source versions must be plainly marked as such, and must not be 21 | misrepresented as being the original software. 22 | 23 | 3. This notice may not be removed or altered from any source 24 | distribution. 25 | 26 | ***/ 27 | 28 | #ifndef THREAD_POOL_H 29 | #define THREAD_POOL_H 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #if defined _WIN32 || defined __CYGWIN__ 42 | #include 43 | #else 44 | #include 45 | #endif 46 | 47 | class ThreadPool { 48 | public: 49 | ThreadPool(size_t); 50 | template 51 | auto enqueue(F&& f, Args&&... args) 52 | -> std::future >; 53 | 54 | ~ThreadPool(); 55 | private: 56 | // need to keep track of threads so we can join them 57 | std::vector< std::thread > workers; 58 | // the task queue 59 | std::queue< std::function > tasks; 60 | 61 | // synchronization 62 | std::mutex queue_mutex; 63 | std::condition_variable condition; 64 | bool stop; 65 | }; 66 | 67 | // the constructor just launches some amount of workers 68 | inline ThreadPool::ThreadPool(size_t threads) 69 | : stop(false) 70 | { 71 | for(size_t i = 0;i task; 78 | 79 | { 80 | std::unique_lock lock(this->queue_mutex); 81 | this->condition.wait(lock, 82 | [this]{ return this->stop || !this->tasks.empty(); }); 83 | if(this->stop && this->tasks.empty()) 84 | return; 85 | task = std::move(this->tasks.front()); 86 | this->tasks.pop(); 87 | } 88 | task(); 89 | } 90 | } 91 | ); 92 | } 93 | 94 | // add new work item to the pool 95 | template 96 | auto ThreadPool::enqueue(F&& f, Args&&... args) 97 | -> std::future > 98 | { 99 | using return_type = std::invoke_result_t; 100 | 101 | auto task = std::make_shared< std::packaged_task >( 102 | std::bind(std::forward(f), std::forward(args)...) 103 | ); 104 | 105 | std::future res = task->get_future(); 106 | { 107 | std::unique_lock lock(queue_mutex); 108 | 109 | // don't allow enqueueing after stopping the pool 110 | if(stop) 111 | throw std::runtime_error("enqueue on stopped ThreadPool"); 112 | 113 | tasks.emplace([task](){ (*task)(); }); 114 | } 115 | condition.notify_one(); 116 | return res; 117 | } 118 | 119 | // the destructor joins all threads 120 | inline ThreadPool::~ThreadPool() 121 | { 122 | { 123 | std::unique_lock lock(queue_mutex); 124 | stop = true; 125 | } 126 | condition.notify_all(); 127 | for(std::thread &worker: workers) 128 | worker.join(); 129 | } 130 | 131 | #endif 132 | -------------------------------------------------------------------------------- /.github/workflows/cmake.yml: -------------------------------------------------------------------------------- 1 | name: CMake 2 | 3 | on: [push] 4 | 5 | env: 6 | # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) 7 | BUILD_TYPE: Release 8 | 9 | jobs: 10 | build: 11 | strategy: 12 | matrix: 13 | os: [macos-latest, ubuntu-latest] 14 | compiler: [g++-10] 15 | # The CMake configure and build commands are platform agnostic and should work equally 16 | # well on Windows or Mac. You can convert this to a matrix build if you need 17 | # cross-platform coverage. 18 | # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix 19 | runs-on: ${{ matrix.os }} 20 | 21 | steps: 22 | - uses: actions/checkout@v2 23 | with: 24 | submodules: 'recursive' 25 | - name: Gen vcpkg 26 | run: ./vcpkg/bootstrap-vcpkg.sh 27 | - name: Restore cached vcpkg 28 | id: cache-vcpkg-restore 29 | uses: actions/cache/restore@v3 30 | with: 31 | path: vcpkg/installed 32 | key: ${{ runner.os }}-vcpkg 33 | - name: Run vcpkg 34 | if: ${{ steps.cache-vcpkg-restore.outputs.cache-hit != 'true' }} 35 | run: ./vcpkg/vcpkg install hdf5 netcdf-c yaml-cpp zeromq cppzmq jsoncpp nlopt 36 | - name: Install libtirpc-dev 37 | if: ${{ matrix.os == 'ubuntu-latest' }} 38 | run: sudo apt update && sudo apt install -y libtirpc-dev 39 | - name: Save vcpkg cache 40 | id: cache-vcpkg-save 41 | uses: actions/cache/save@v3 42 | with: 43 | path: vcpkg/installed 44 | key: ${{ runner.os }}-vcpkg 45 | - name: Create Build Environment 46 | # Some projects don't allow in-source building, so create a separate build directory 47 | # We'll use this as our working directory for all subsequent commands 48 | run: cmake -E make_directory ${{github.workspace}}/build 49 | - name: Configure CMake 50 | # Use a bash shell so we can use the same syntax for environment variable 51 | # access regardless of the host operating system 52 | shell: bash 53 | working-directory: ${{github.workspace}}/build 54 | # Note the current convention is to use the -S and -B options here to specify source 55 | # and build directories, but this is only available with CMake 3.13 and higher. 56 | # The CMake binaries on the Github Actions machines are (as of this writing) 3.12 57 | run: | 58 | if [ "$RUNNER_OS" == "macOS" ]; then 59 | cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake -DBUILD_WITH_ZMQ=ON 60 | else 61 | cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake -DBUILD_WITH_ZMQ=ON -DBUILD_WITH_TIRPC=ON 62 | fi 63 | - name: Build 64 | working-directory: ${{github.workspace}}/build 65 | shell: bash 66 | # Execute the build. You can specify a specific target with "--target " 67 | run: cmake --build . --config $BUILD_TYPE 68 | - name: Test 69 | working-directory: ${{github.workspace}}/bin 70 | shell: bash 71 | # Execute tests defined by the CMake configuration. 72 | # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail 73 | run: | 74 | if [ "$RUNNER_OS" == "macOS" ]; then 75 | ls -lh ${{github.workspace}}/vcpkg/installed/arm64-osx/lib 76 | #export DYLD_LIBRARY_PATH=${{github.workspace}}/vcpkg/installed/arm64-osx/bin 77 | ./xrf_maps 78 | else 79 | ls -lh ${{github.workspace}}/vcpkg/installed/x64-linux/lib 80 | ./xrf_maps --dir ${{github.workspace}}/test/2_ID_E_dataset --nthreads 2 --fit roi --detectors 0 81 | fi 82 | - name: Cp Ref to Install 83 | working-directory: ${{github.workspace}} 84 | shell: bash 85 | # Execute tests defined by the CMake configuration. 86 | # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail 87 | run: | 88 | mkdir install 89 | rsync -RavzP reference install 90 | rsync -RavzP bin install 91 | cd install 92 | echo '{"branchName":"${{ github.ref }}","commitHash":"${{ github.sha }}"}' >> version.json 93 | - uses: actions/upload-artifact@v4 94 | with: 95 | name: XRF-Maps_${{ matrix.os }}_x86_64 96 | path: ${{github.workspace}}/install/ 97 | -------------------------------------------------------------------------------- /src/core/mem_info.cpp: -------------------------------------------------------------------------------- 1 | /*** 2 | Copyright (c) 2019, UChicago Argonne, LLC. All rights reserved. 3 | 4 | Copyright 2016. UChicago Argonne, LLC. This software was produced 5 | under U.S. Government contract DE-AC02-06CH11357 for Argonne National 6 | Laboratory (ANL), which is operated by UChicago Argonne, LLC for the 7 | U.S. Department of Energy. The U.S. Government has rights to use, 8 | reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR 9 | UChicago Argonne, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 10 | ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is 11 | modified to produce derivative works, such modified software should 12 | be clearly marked, so as not to confuse it with the version available 13 | from ANL. 14 | 15 | Additionally, redistribution and use in source and binary forms, with 16 | or without modification, are permitted provided that the following 17 | conditions are met: 18 | 19 | * Redistributions of source code must retain the above copyright 20 | notice, this list of conditions and the following disclaimer. 21 | 22 | * Redistributions in binary form must reproduce the above copyright 23 | notice, this list of conditions and the following disclaimer in 24 | the documentation and/or other materials provided with the 25 | distribution. 26 | 27 | * Neither the name of UChicago Argonne, LLC, Argonne National 28 | Laboratory, ANL, the U.S. Government, nor the names of its 29 | contributors may be used to endorse or promote products derived 30 | from this software without specific prior written permission. 31 | 32 | THIS SOFTWARE IS PROVIDED BY UChicago Argonne, LLC AND CONTRIBUTORS 33 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 34 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 35 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UChicago 36 | Argonne, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 37 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 38 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 39 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 40 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 41 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 42 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | ***/ 45 | 46 | /// Initial Author <2019>: Arthur Glowacki 47 | #include "mem_info.h" 48 | #include 49 | 50 | long long get_available_mem() 51 | { 52 | #if defined _WIN32 || defined __CYGWIN__ 53 | MEMORYSTATUSEX memInfo; 54 | memInfo.dwLength = sizeof(MEMORYSTATUSEX); 55 | GlobalMemoryStatusEx(&memInfo); 56 | return memInfo.ullAvailPhys; 57 | #elif defined __APPLE__ 58 | int mib[2]; 59 | int64_t one_gig = 1024 * 1024 * 1024; 60 | int64_t physical_memory; 61 | int64_t fraction = 4; 62 | size_t length; 63 | // Get the Physical memory size 64 | mib[0] = CTL_HW; 65 | mib[1] = HW_MEMSIZE; 66 | length = sizeof(int64_t); 67 | sysctl(mib, 2, &physical_memory, &length, NULL, 0); 68 | // HACK: 80% of physical mem 69 | if (physical_memory < one_gig) 70 | { 71 | return one_gig; 72 | } 73 | return physical_memory / fraction; 74 | #else 75 | struct sysinfo memInfo; 76 | 77 | sysinfo(&memInfo); 78 | long long totalVirtualMem = memInfo.totalram; 79 | //Add other values in next statement to avoid int overflow on right hand side... 80 | totalVirtualMem += memInfo.totalswap; 81 | totalVirtualMem *= memInfo.mem_unit; 82 | return totalVirtualMem; 83 | #endif 84 | } 85 | 86 | 87 | long long get_total_mem() 88 | { 89 | #if defined _WIN32 || defined __CYGWIN__ 90 | MEMORYSTATUSEX memInfo; 91 | memInfo.dwLength = sizeof(MEMORYSTATUSEX); 92 | GlobalMemoryStatusEx(&memInfo); 93 | return memInfo.ullTotalPhys; 94 | #elif defined __APPLE__ 95 | int mib[2]; 96 | int64_t physical_memory; 97 | size_t length; 98 | // Get the Physical memory size 99 | mib[0] = CTL_HW; 100 | mib[1] = HW_MEMSIZE; 101 | length = sizeof(int64_t); 102 | sysctl(mib, 2, &physical_memory, &length, NULL, 0); 103 | return physical_memory; 104 | #else 105 | struct sysinfo memInfo; 106 | 107 | sysinfo(&memInfo); 108 | long long totalPhysMem = memInfo.totalram; 109 | //Multiply in next statement to avoid int overflow on right hand side... 110 | totalPhysMem *= memInfo.mem_unit; 111 | return totalPhysMem; 112 | #endif 113 | } 114 | -------------------------------------------------------------------------------- /src/fitting/routines/hybrid_param_nnls_fit_routine.h: -------------------------------------------------------------------------------- 1 | /*** 2 | Copyright (c) 2016, UChicago Argonne, LLC. All rights reserved. 3 | 4 | Copyright 2016. UChicago Argonne, LLC. This software was produced 5 | under U.S. Government contract DE-AC02-06CH11357 for Argonne National 6 | Laboratory (ANL), which is operated by UChicago Argonne, LLC for the 7 | U.S. Department of Energy. The U.S. Government has rights to use, 8 | reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR 9 | UChicago Argonne, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 10 | ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is 11 | modified to produce derivative works, such modified software should 12 | be clearly marked, so as not to confuse it with the version available 13 | from ANL. 14 | 15 | Additionally, redistribution and use in source and binary forms, with 16 | or without modification, are permitted provided that the following 17 | conditions are met: 18 | 19 | * Redistributions of source code must retain the above copyright 20 | notice, this list of conditions and the following disclaimer. 21 | 22 | * Redistributions in binary form must reproduce the above copyright 23 | notice, this list of conditions and the following disclaimer in 24 | the documentation and/or other materials provided with the 25 | distribution. 26 | 27 | * Neither the name of UChicago Argonne, LLC, Argonne National 28 | Laboratory, ANL, the U.S. Government, nor the names of its 29 | contributors may be used to endorse or promote products derived 30 | from this software without specific prior written permission. 31 | 32 | THIS SOFTWARE IS PROVIDED BY UChicago Argonne, LLC AND CONTRIBUTORS 33 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 34 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 35 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UChicago 36 | Argonne, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 37 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 38 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 39 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 40 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 41 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 42 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | ***/ 45 | 46 | /// Initial Author <2022>: Arthur Glowacki 47 | 48 | 49 | 50 | #ifndef Hybrid_Param_NNLS_Fit_Routine_H 51 | #define Hybrid_Param_NNLS_Fit_Routine_H 52 | 53 | #include "fitting/routines/nnls_fit_routine.h" 54 | 55 | namespace fitting 56 | { 57 | namespace routines 58 | { 59 | 60 | using namespace data_struct; 61 | using namespace fitting::optimizers; 62 | 63 | template 64 | class DLL_EXPORT Hybrid_Param_NNLS_Fit_Routine: public NNLS_Fit_Routine 65 | { 66 | public: 67 | Hybrid_Param_NNLS_Fit_Routine(); 68 | 69 | virtual ~Hybrid_Param_NNLS_Fit_Routine(); 70 | 71 | virtual OPTIMIZER_OUTCOME fit_spectra_parameters(const models::Base_Model* const model, 72 | const Spectra* const spectra, 73 | const Fit_Element_Map_Dict* const elements_to_fit, 74 | bool use_weights, 75 | Fit_Parameters& out_fit_params, 76 | Callback_Func_Status_Def* status_callback = nullptr); 77 | 78 | virtual std::string get_name() { return STR_FIT_GAUSS_NNLS_TAILS; } 79 | 80 | virtual void model_spectrum(const models::Base_Model* const model, 81 | const Fit_Parameters* const fit_params, 82 | const struct Range* const energy_range, 83 | Spectra* spectra_model, 84 | Callback_Func_Status_Def* status_callback); 85 | 86 | protected: 87 | 88 | private: 89 | size_t _cur_iter; 90 | 91 | models::Base_Model* _model; 92 | ArrayTr _background; 93 | const Fit_Element_Map_Dict* _elements_to_fit; 94 | const data_struct::Spectra* _spectra; 95 | 96 | }; 97 | 98 | } //namespace routines 99 | 100 | } //namespace fitting 101 | 102 | #endif // Hybrid_Param_NNLS_Fit_Routine_H 103 | -------------------------------------------------------------------------------- /src/quantification/models/quantification_model.h: -------------------------------------------------------------------------------- 1 | /*** 2 | Copyright (c) 2016, UChicago Argonne, LLC. All rights reserved. 3 | 4 | Copyright 2016. UChicago Argonne, LLC. This software was produced 5 | under U.S. Government contract DE-AC02-06CH11357 for Argonne National 6 | Laboratory (ANL), which is operated by UChicago Argonne, LLC for the 7 | U.S. Department of Energy. The U.S. Government has rights to use, 8 | reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR 9 | UChicago Argonne, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 10 | ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is 11 | modified to produce derivative works, such modified software should 12 | be clearly marked, so as not to confuse it with the version available 13 | from ANL. 14 | 15 | Additionally, redistribution and use in source and binary forms, with 16 | or without modification, are permitted provided that the following 17 | conditions are met: 18 | 19 | * Redistributions of source code must retain the above copyright 20 | notice, this list of conditions and the following disclaimer. 21 | 22 | * Redistributions in binary form must reproduce the above copyright 23 | notice, this list of conditions and the following disclaimer in 24 | the documentation and/or other materials provided with the 25 | distribution. 26 | 27 | * Neither the name of UChicago Argonne, LLC, Argonne National 28 | Laboratory, ANL, the U.S. Government, nor the names of its 29 | contributors may be used to endorse or promote products derived 30 | from this software without specific prior written permission. 31 | 32 | THIS SOFTWARE IS PROVIDED BY UChicago Argonne, LLC AND CONTRIBUTORS 33 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 34 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 35 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UChicago 36 | Argonne, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 37 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 38 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 39 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 40 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 41 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 42 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | ***/ 45 | 46 | /// Initial Author <2016>: Arthur Glowacki 47 | 48 | 49 | 50 | #ifndef Quantification_Model_H 51 | #define Quantification_Model_H 52 | 53 | #include "core/defines.h" 54 | 55 | #include 56 | #include 57 | 58 | #include "data_struct/element_info.h" 59 | #include "data_struct/element_quant.h" 60 | 61 | namespace quantification 62 | { 63 | namespace models 64 | { 65 | 66 | using namespace data_struct; 67 | 68 | 69 | 70 | 71 | //----------------------------------------------------------------------------- 72 | 73 | /// 74 | /// \brief The Quantification_Model class: 75 | /// 76 | template 77 | class DLL_EXPORT Quantification_Model 78 | { 79 | 80 | public: 81 | Quantification_Model(); 82 | 83 | ~Quantification_Model(); 84 | 85 | void init_element_quant(Element_Quant& out_quant, 86 | T_real incident_energy, 87 | Element_Info* detector_element, 88 | data_struct::Electron_Shell shell, 89 | T_real airpath, 90 | T_real detector_chip_thickness, 91 | T_real beryllium_window_thickness, 92 | T_real germanium_dead_layer, 93 | int z_number); 94 | 95 | T_real transmission(T_real thickness, T_real beta, T_real llambda) const; 96 | 97 | T_real absorption(T_real thickness, T_real beta, T_real llambda, T_real shell_factor=1) const; 98 | 99 | std::unordered_map model_calibrationcurve(std::unordered_map> quant_map, T_real p); 100 | 101 | void model_calibrationcurve(std::vector>* quant_vec, T_real p); 102 | 103 | protected: 104 | 105 | }; 106 | 107 | //----------------------------------------------------------------------------- 108 | 109 | 110 | 111 | } //namespace models 112 | 113 | } //namespace quantification 114 | 115 | #endif // Quantification_Model_H 116 | -------------------------------------------------------------------------------- /src/support/mdautils-1.4.1/xdr_hack.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************\ 2 | * Copyright (c) 2016 UChicago Argonne, LLC, 3 | * as Operator of Argonne National Laboratory. 4 | * This file is distributed subject to a Software License Agreement 5 | * found in file LICENSE that is included with this distribution. 6 | \*************************************************************************/ 7 | 8 | 9 | /* 10 | 11 | Written by Dohn A. Arms, Argonne National Laboratory 12 | Send comments to dohnarms@anl.gov 13 | 14 | 1.3.1 -- February 2014 15 | Initial Version 16 | 1.4.0 -- July 2016 17 | Minor fixes 18 | */ 19 | 20 | /* 21 | This code is an XDR hack! 22 | 23 | It contains routines for decoding XDR data types for systems of 24 | either little or big endianness. It is meant for Windows (which is 25 | little-endian on x86 architectures), which has no native XDR 26 | library. If your system has an XDR library, USE IT! 27 | 28 | The only routines that are provided are those needed by the MDA format, 29 | and they only decode, not encode. 30 | */ 31 | 32 | // the hack has to be enabled, and the endianness has to be specified 33 | #ifdef XDR_HACK 34 | #if defined XDR_LE || defined XDR_BE 35 | 36 | #include "xdr_hack.h" 37 | 38 | int xdr_int8_t( FILE *fptr, int8_t *my_int8) 39 | { 40 | if( fseek( fptr, 3, SEEK_CUR) ) 41 | return 0; 42 | if( !fread( my_int8, 1, 1, fptr) ) 43 | return 0; 44 | return 1; 45 | } 46 | 47 | int xdr_int16_t( FILE *fptr, int16_t *my_int16) 48 | { 49 | #ifdef XDR_LE 50 | union 51 | { 52 | char b[2]; 53 | int16_t d; 54 | } data; 55 | #endif 56 | 57 | if( fseek( fptr, 2, SEEK_CUR) ) 58 | return 0; 59 | #ifdef XDR_LE 60 | int i; 61 | for( i = 1; i >= 0; i--) 62 | if( !fread( data.b + i, 1, 1, fptr) ) 63 | return 0; 64 | *my_int16 = data.d; 65 | #else 66 | if( !fread( my_int16, 2, 1, fptr) ) 67 | return 0; 68 | #endif 69 | 70 | return 1; 71 | } 72 | 73 | int xdr_int32_t( FILE *fptr, int32_t *my_int32) 74 | { 75 | #ifdef XDR_LE 76 | union 77 | { 78 | char b[4]; 79 | int32_t d; 80 | } data; 81 | 82 | int i; 83 | 84 | for( i = 3; i >= 0; i--) 85 | if( !fread( data.b + i, 1, 1, fptr) ) 86 | return 0; 87 | *my_int32 = data.d; 88 | #else 89 | if( !fread( my_int32, 4, 1, fptr) ) 90 | return 0; 91 | #endif 92 | 93 | return 1; 94 | } 95 | 96 | 97 | int xdr_float( FILE *fptr, float *my_float) 98 | { 99 | #ifdef XDR_LE 100 | union 101 | { 102 | char b[4]; 103 | float d; 104 | } data; 105 | 106 | int i; 107 | 108 | for( i = 3; i >= 0; i--) 109 | if( !fread( data.b + i, 1, 1, fptr) ) 110 | return 0; 111 | *my_float = data.d; 112 | #else 113 | if( !fread( my_float, 4, 1, fptr) ) 114 | return 0; 115 | #endif 116 | 117 | return 1; 118 | } 119 | 120 | int xdr_double( FILE *fptr, double *my_double) 121 | { 122 | #ifdef XDR_LE 123 | union 124 | { 125 | char b[8]; 126 | double d; 127 | } data; 128 | 129 | int i; 130 | 131 | for( i = 7; i >= 0; i--) 132 | if( !fread( data.b + i, 1, 1, fptr) ) 133 | return 0; 134 | *my_double = data.d; 135 | #else 136 | if( !fread( my_double, 8, 1, fptr) ) 137 | return 0; 138 | #endif 139 | 140 | return 1; 141 | } 142 | 143 | 144 | int xdr_vector( FILE *fptr, char *buffer, uint16_t size, 145 | uint16_t type_size, int (*proc)(FILE *fptr, void *data) ) 146 | { 147 | uint16_t i; 148 | 149 | for( i = 0; i < size; i++) 150 | { 151 | if( !proc(fptr, &buffer[i*type_size]) ) 152 | return 0; 153 | } 154 | 155 | return 1; 156 | } 157 | 158 | 159 | int xdr_counted_string( FILE *fptr, char **p) 160 | { 161 | int32_t length, rlength; 162 | 163 | if( !xdr_int32_t( fptr, &length) ) 164 | return 0; 165 | if( !length) 166 | { 167 | *p = (char *) malloc( sizeof(char) ); 168 | (*p)[0] = '\0'; 169 | return 1; 170 | } 171 | 172 | if( !xdr_int32_t( fptr, &length) ) 173 | return 0; 174 | 175 | // round length up to multiple of 4, how data is stored 176 | rlength = length + ( (length%4) == 0 ? 0 : 4 - (length%4) ); 177 | 178 | *p = (char *) malloc( (length + 1) * sizeof(char) ); 179 | if( fread( *p, 1, length, fptr) != length) 180 | { 181 | free( *p); 182 | return 0; 183 | } 184 | (*p)[length] = '\0'; /* Null termination using string length */ 185 | 186 | if( rlength > length) 187 | if( fseek( fptr, rlength-length, SEEK_CUR) ) 188 | return 0; 189 | 190 | return 1; 191 | } 192 | 193 | #endif 194 | #endif 195 | -------------------------------------------------------------------------------- /src/workflow/source.h: -------------------------------------------------------------------------------- 1 | /*** 2 | Copyright (c) 2016, UChicago Argonne, LLC. All rights reserved. 3 | 4 | Copyright 2016. UChicago Argonne, LLC. This software was produced 5 | under U.S. Government contract DE-AC02-06CH11357 for Argonne National 6 | Laboratory (ANL), which is operated by UChicago Argonne, LLC for the 7 | U.S. Department of Energy. The U.S. Government has rights to use, 8 | reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR 9 | UChicago Argonne, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 10 | ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is 11 | modified to produce derivative works, such modified software should 12 | be clearly marked, so as not to confuse it with the version available 13 | from ANL. 14 | 15 | Additionally, redistribution and use in source and binary forms, with 16 | or without modification, are permitted provided that the following 17 | conditions are met: 18 | 19 | * Redistributions of source code must retain the above copyright 20 | notice, this list of conditions and the following disclaimer. 21 | 22 | * Redistributions in binary form must reproduce the above copyright 23 | notice, this list of conditions and the following disclaimer in 24 | the documentation and/or other materials provided with the 25 | distribution. 26 | 27 | * Neither the name of UChicago Argonne, LLC, Argonne National 28 | Laboratory, ANL, the U.S. Government, nor the names of its 29 | contributors may be used to endorse or promote products derived 30 | from this software without specific prior written permission. 31 | 32 | THIS SOFTWARE IS PROVIDED BY UChicago Argonne, LLC AND CONTRIBUTORS 33 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 34 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 35 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UChicago 36 | Argonne, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 37 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 38 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 39 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 40 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 41 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 42 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | ***/ 45 | 46 | /// Initial Author <2017>: Arthur Glowacki 47 | 48 | 49 | 50 | #ifndef Source_H 51 | #define Source_H 52 | 53 | #include "core/defines.h" 54 | #include 55 | #include "workflow/distributor.h" 56 | #include "workflow/sink.h" 57 | 58 | namespace workflow 59 | { 60 | 61 | //----------------------------------------------------------------------------- 62 | template 63 | class DLL_EXPORT Source 64 | { 65 | 66 | typedef std::function Callback_Func_Def; 67 | // typedef std::function Source_Func_Def; 68 | 69 | public: 70 | 71 | Source() 72 | { 73 | _output_callback_func = nullptr; 74 | } 75 | 76 | virtual ~Source() 77 | { 78 | 79 | } 80 | 81 | template 82 | void connect(Distributor *distributor) 83 | { 84 | _output_callback_func = std::bind(&Distributor::distribute, distributor, std::placeholders::_1); 85 | } 86 | 87 | void connect(Sink *sink) 88 | { 89 | _output_callback_func = std::bind(&Sink::sink_function, sink, std::placeholders::_1); 90 | } 91 | 92 | template 93 | void connect_distributor(Distributor *distributor) 94 | { 95 | connect(distributor); 96 | } 97 | 98 | void connect_sink(Sink *sink) 99 | { 100 | connect(sink); 101 | } 102 | 103 | /* 104 | void connect( Callback_Func_Def out_callback_func) 105 | { 106 | _output_callback_func = out_callback_func; 107 | } 108 | 109 | void set_function(Source_Func_Def func) 110 | { 111 | _prod_func = func; 112 | } 113 | */ 114 | virtual void run() = 0; 115 | 116 | /* 117 | template 118 | virtual void run(Args&&... args) 119 | { 120 | 121 | auto task = std::make_shared< std::packaged_task >( 122 | std::bind(std::forward(_prod_func), std::forward(args)...) 123 | ); 124 | 125 | task(); 126 | } 127 | */ 128 | protected: 129 | 130 | Callback_Func_Def _output_callback_func; 131 | 132 | }; 133 | 134 | } //namespace workflow 135 | 136 | #endif // Source_H 137 | -------------------------------------------------------------------------------- /src/io/net/basic_serializer.h: -------------------------------------------------------------------------------- 1 | /*** 2 | Copyright (c) 2016, UChicago Argonne, LLC. All rights reserved. 3 | 4 | Copyright 2016. UChicago Argonne, LLC. This software was produced 5 | under U.S. Government contract DE-AC02-06CH11357 for Argonne National 6 | Laboratory (ANL), which is operated by UChicago Argonne, LLC for the 7 | U.S. Department of Energy. The U.S. Government has rights to use, 8 | reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR 9 | UChicago Argonne, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 10 | ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is 11 | modified to produce derivative works, such modified software should 12 | be clearly marked, so as not to confuse it with the version available 13 | from ANL. 14 | 15 | Additionally, redistribution and use in source and binary forms, with 16 | or without modification, are permitted provided that the following 17 | conditions are met: 18 | 19 | * Redistributions of source code must retain the above copyright 20 | notice, this list of conditions and the following disclaimer. 21 | 22 | * Redistributions in binary form must reproduce the above copyright 23 | notice, this list of conditions and the following disclaimer in 24 | the documentation and/or other materials provided with the 25 | distribution. 26 | 27 | * Neither the name of UChicago Argonne, LLC, Argonne National 28 | Laboratory, ANL, the U.S. Government, nor the names of its 29 | contributors may be used to endorse or promote products derived 30 | from this software without specific prior written permission. 31 | 32 | THIS SOFTWARE IS PROVIDED BY UChicago Argonne, LLC AND CONTRIBUTORS 33 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 34 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 35 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UChicago 36 | Argonne, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 37 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 38 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 39 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 40 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 41 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 42 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | ***/ 45 | 46 | /// Initial Author <2017>: Arthur Glowacki 47 | 48 | 49 | 50 | #ifndef BASIC_SERIALIZER_H 51 | #define BASIC_SERIALIZER_H 52 | 53 | #include "core/defines.h" 54 | #include "data_struct/stream_block.h" 55 | 56 | namespace io 57 | { 58 | namespace net 59 | { 60 | 61 | template 62 | class DLL_EXPORT Basic_Serializer 63 | { 64 | public: 65 | 66 | Basic_Serializer(); 67 | 68 | ~Basic_Serializer(); 69 | 70 | std::string encode_counts(data_struct::Stream_Block* in_stream_block); 71 | 72 | data_struct::Stream_Block* decode_counts(char* message, size_t message_len); 73 | 74 | std::string encode_spectra(data_struct::Stream_Block* in_stream_block); 75 | 76 | data_struct::Stream_Block* decode_spectra(char* message, size_t message_len); 77 | 78 | std::string encode_counts_and_spectra(data_struct::Stream_Block* in_stream_block); 79 | 80 | data_struct::Stream_Block* decode_counts_and_spectra(char* message, size_t message_len); 81 | 82 | protected: 83 | template 84 | void _convert_var_to_bytes(std::string * str, char* bytes_temp, T variable, size_t size) 85 | { 86 | memcpy(bytes_temp, (char*)(&variable), size); 87 | for (size_t i = 0; i < size; i++) 88 | *str += bytes_temp[i]; 89 | } 90 | 91 | void _encode_meta(data_struct::Stream_Block* stream_block, std::string& raw_msg); 92 | 93 | void _encode_counts(data_struct::Stream_Block* stream_block, std::string& raw_msg); 94 | 95 | void _encode_spectra(data_struct::Stream_Block* stream_block, std::string& raw_msg); 96 | 97 | data_struct::Stream_Block* _decode_meta(char* message, size_t message_len, size_t& idx); 98 | 99 | void _decode_counts(char* message, size_t message_len, size_t& idx, data_struct::Stream_Block* out_stream_block); 100 | 101 | void _decode_spectra(char* message, size_t message_len, size_t& idx, data_struct::Stream_Block* out_stream_block); 102 | 103 | char *_tmp_real; 104 | char *_tmp_uint; 105 | char *_tmp_size_t; 106 | char *_tmp_ushort; 107 | 108 | }; 109 | 110 | }// end namespace net 111 | }// end namespace io 112 | 113 | #endif // Basic_Serializer_H 114 | -------------------------------------------------------------------------------- /src/fitting/optimizers/optimizer.cpp: -------------------------------------------------------------------------------- 1 | /*** 2 | Copyright (c) 2016, UChicago Argonne, LLC. All rights reserved. 3 | 4 | Copyright 2016. UChicago Argonne, LLC. This software was produced 5 | under U.S. Government contract DE-AC02-06CH11357 for Argonne National 6 | Laboratory (ANL), which is operated by UChicago Argonne, LLC for the 7 | U.S. Department of Energy. The U.S. Government has rights to use, 8 | reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR 9 | UChicago Argonne, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 10 | ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is 11 | modified to produce derivative works, such modified software should 12 | be clearly marked, so as not to confuse it with the version available 13 | from ANL. 14 | 15 | Additionally, redistribution and use in source and binary forms, with 16 | or without modification, are permitted provided that the following 17 | conditions are met: 18 | 19 | * Redistributions of source code must retain the above copyright 20 | notice, this list of conditions and the following disclaimer. 21 | 22 | * Redistributions in binary form must reproduce the above copyright 23 | notice, this list of conditions and the following disclaimer in 24 | the documentation and/or other materials provided with the 25 | distribution. 26 | 27 | * Neither the name of UChicago Argonne, LLC, Argonne National 28 | Laboratory, ANL, the U.S. Government, nor the names of its 29 | contributors may be used to endorse or promote products derived 30 | from this software without specific prior written permission. 31 | 32 | THIS SOFTWARE IS PROVIDED BY UChicago Argonne, LLC AND CONTRIBUTORS 33 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 34 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 35 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UChicago 36 | Argonne, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 37 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 38 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 39 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 40 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 41 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 42 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | ***/ 45 | 46 | /// Initial Author <2016>: Arthur Glowacki 47 | 48 | 49 | 50 | #include "optimizer.h" 51 | 52 | 53 | namespace fitting 54 | { 55 | namespace optimizers 56 | { 57 | 58 | // ---------------------------------------------------------------------------- 59 | 60 | std::string optimizer_outcome_to_str(OPTIMIZER_OUTCOME outcome) 61 | { 62 | switch (outcome) 63 | { 64 | case fitting::optimizers::OPTIMIZER_OUTCOME::CONVERGED: 65 | return "Converged"; 66 | case fitting::optimizers::OPTIMIZER_OUTCOME::F_TOL_LT_TOL: 67 | return "Ftol less than TOL"; 68 | case fitting::optimizers::OPTIMIZER_OUTCOME::X_TOL_LT_TOL: 69 | return "XTol less than TOL"; 70 | case fitting::optimizers::OPTIMIZER_OUTCOME::G_TOL_LT_TOL: 71 | return "GTol less than TOL"; 72 | case fitting::optimizers::OPTIMIZER_OUTCOME::EXHAUSTED: 73 | return "EXHAUSTED"; 74 | case fitting::optimizers::OPTIMIZER_OUTCOME::CRASHED: 75 | return "CRASHED"; 76 | case fitting::optimizers::OPTIMIZER_OUTCOME::EXPLODED: 77 | return "Exploded"; 78 | case fitting::optimizers::OPTIMIZER_OUTCOME::FAILED: 79 | return "FAILED"; 80 | case fitting::optimizers::OPTIMIZER_OUTCOME::FOUND_NAN: 81 | return "Found NAN"; 82 | case fitting::optimizers::OPTIMIZER_OUTCOME::FOUND_ZERO: 83 | return "Found Zero"; 84 | case fitting::optimizers::OPTIMIZER_OUTCOME::STOPPED: 85 | return "Stopped"; 86 | case fitting::optimizers::OPTIMIZER_OUTCOME::TRAPPED: 87 | return "Trapped"; 88 | } 89 | return ""; 90 | } 91 | 92 | // ---------------------------------------------------------------------------- 93 | 94 | 95 | TEMPLATE_STRUCT_DLL_EXPORT User_Data; 96 | TEMPLATE_STRUCT_DLL_EXPORT User_Data; 97 | TEMPLATE_STRUCT_DLL_EXPORT Gen_User_Data; 98 | TEMPLATE_STRUCT_DLL_EXPORT Gen_User_Data; 99 | TEMPLATE_STRUCT_DLL_EXPORT Quant_User_Data; 100 | TEMPLATE_STRUCT_DLL_EXPORT Quant_User_Data; 101 | TEMPLATE_CLASS_DLL_EXPORT Optimizer; 102 | TEMPLATE_CLASS_DLL_EXPORT Optimizer; 103 | 104 | } //namespace optimizers 105 | } //namespace fitting 106 | -------------------------------------------------------------------------------- /src/data_struct/scaler_lookup.h: -------------------------------------------------------------------------------- 1 | /*** 2 | Copyright (c) 2016, UChicago Argonne, LLC. All rights reserved. 3 | 4 | Copyright 2016. UChicago Argonne, LLC. This software was produced 5 | under U.S. Government contract DE-AC02-06CH11357 for Argonne National 6 | Laboratory (ANL), which is operated by UChicago Argonne, LLC for the 7 | U.S. Department of Energy. The U.S. Government has rights to use, 8 | reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR 9 | UChicago Argonne, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 10 | ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is 11 | modified to produce derivative works, such modified software should 12 | be clearly marked, so as not to confuse it with the version available 13 | from ANL. 14 | 15 | Additionally, redistribution and use in source and binary forms, with 16 | or without modification, are permitted provided that the following 17 | conditions are met: 18 | 19 | * Redistributions of source code must retain the above copyright 20 | notice, this list of conditions and the following disclaimer. 21 | 22 | * Redistributions in binary form must reproduce the above copyright 23 | notice, this list of conditions and the following disclaimer in 24 | the documentation and/or other materials provided with the 25 | distribution. 26 | 27 | * Neither the name of UChicago Argonne, LLC, Argonne National 28 | Laboratory, ANL, the U.S. Government, nor the names of its 29 | contributors may be used to endorse or promote products derived 30 | from this software without specific prior written permission. 31 | 32 | THIS SOFTWARE IS PROVIDED BY UChicago Argonne, LLC AND CONTRIBUTORS 33 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 34 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 35 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UChicago 36 | Argonne, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 37 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 38 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 39 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 40 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 41 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 42 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | ***/ 45 | 46 | /// Initial Author <2021>: Arthur Glowacki 47 | 48 | 49 | 50 | #ifndef Scaler_Lookup_H 51 | #define Scaler_Lookup_H 52 | 53 | #include 54 | #include 55 | #include 56 | #include 57 | #include "core/defines.h" 58 | 59 | namespace data_struct 60 | { 61 | struct Summed_Scaler 62 | { 63 | std::string scaler_name; 64 | std::vector scalers_to_sum; 65 | }; 66 | 67 | //singleton 68 | class DLL_EXPORT Scaler_Lookup 69 | { 70 | public: 71 | 72 | static Scaler_Lookup* inst(); 73 | 74 | ~Scaler_Lookup(); 75 | 76 | void clear(); 77 | 78 | void add_beamline_scaler(const std::string& beamline, const std::string& scaler_label, const std::string& scaler_pv, bool is_time_normalized); 79 | 80 | void add_timing_info(const std::string& beamline, const std::string& time_pv, double clock); 81 | 82 | void add_summed_scaler(const std::string& beamline, const std::string& scaler_label, const std::vector& scaler_list); 83 | 84 | bool search_for_timing_info(const std::vector& pv_list, std::string& out_pv, double& out_clock, std::string& out_beamline); 85 | 86 | bool search_for_timing_info(const std::unordered_map& pv_map, std::string& out_pv, double& out_clock, std::string& out_beamline); 87 | 88 | bool search_pv(const std::string& pv, std::string& out_label, bool& out_is_time_normalized, std::string& out_beamline); 89 | 90 | const std::vector* get_summed_scaler_list(std::string beamline) const; 91 | 92 | private: 93 | 94 | Scaler_Lookup(); 95 | 96 | static Scaler_Lookup *_this_inst; 97 | 98 | struct BeamLine 99 | { 100 | // PV Label 101 | std::map< std::string, std::string > scaler_pv_label_map; 102 | // PV Label 103 | std::map< std::string, std::string > time_normalized_scaler_pv_label_map; 104 | // Time_PV Clock 105 | std::map< std::string, double > timing_info; 106 | // beamline summed scalers 107 | std::vector summed_scalers; 108 | }; 109 | 110 | // beamline Label 111 | std::map< std::string, struct BeamLine > _beamline_map; 112 | 113 | }; 114 | 115 | } //namespace data_struct 116 | 117 | #endif // Scaler_Lookup_H 118 | -------------------------------------------------------------------------------- /src/fitting/routines/nnls_fit_routine.h: -------------------------------------------------------------------------------- 1 | /*** 2 | Copyright (c) 2016, UChicago Argonne, LLC. All rights reserved. 3 | 4 | Copyright 2016. UChicago Argonne, LLC. This software was produced 5 | under U.S. Government contract DE-AC02-06CH11357 for Argonne National 6 | Laboratory (ANL), which is operated by UChicago Argonne, LLC for the 7 | U.S. Department of Energy. The U.S. Government has rights to use, 8 | reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR 9 | UChicago Argonne, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 10 | ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is 11 | modified to produce derivative works, such modified software should 12 | be clearly marked, so as not to confuse it with the version available 13 | from ANL. 14 | 15 | Additionally, redistribution and use in source and binary forms, with 16 | or without modification, are permitted provided that the following 17 | conditions are met: 18 | 19 | * Redistributions of source code must retain the above copyright 20 | notice, this list of conditions and the following disclaimer. 21 | 22 | * Redistributions in binary form must reproduce the above copyright 23 | notice, this list of conditions and the following disclaimer in 24 | the documentation and/or other materials provided with the 25 | distribution. 26 | 27 | * Neither the name of UChicago Argonne, LLC, Argonne National 28 | Laboratory, ANL, the U.S. Government, nor the names of its 29 | contributors may be used to endorse or promote products derived 30 | from this software without specific prior written permission. 31 | 32 | THIS SOFTWARE IS PROVIDED BY UChicago Argonne, LLC AND CONTRIBUTORS 33 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 34 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 35 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UChicago 36 | Argonne, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 37 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 38 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 39 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 40 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 41 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 42 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | ***/ 45 | 46 | /// Initial Author <2016>: Arthur Glowacki 47 | 48 | 49 | 50 | #ifndef NNLS_Fit_Routine_H 51 | #define NNLS_Fit_Routine_H 52 | 53 | #include "fitting/routines/matrix_optimized_fit_routine.h" 54 | 55 | #include "support/nnls/nnls.hpp" 56 | 57 | namespace fitting 58 | { 59 | namespace routines 60 | { 61 | 62 | using namespace data_struct; 63 | 64 | template 65 | class DLL_EXPORT NNLS_Fit_Routine : public Matrix_Optimized_Fit_Routine 66 | { 67 | public: 68 | 69 | NNLS_Fit_Routine(); 70 | 71 | NNLS_Fit_Routine(size_t max_iter); 72 | 73 | virtual ~NNLS_Fit_Routine(); 74 | 75 | virtual OPTIMIZER_OUTCOME fit_spectra(const models::Base_Model* const model, 76 | const Spectra* const spectra, 77 | const Fit_Element_Map_Dict* const elements_to_fit, 78 | std::unordered_map& out_counts); 79 | 80 | // similar to fit_spectra but want to return model instead of counts 81 | void fit_spectrum_model(const Spectra* const spectra, 82 | const ArrayTr* const background, 83 | const Fit_Element_Map_Dict* const elements_to_fit, 84 | Spectra* spectra_model); 85 | 86 | virtual std::string get_name() { return STR_FIT_NNLS; } 87 | 88 | virtual void initialize(models::Base_Model* const model, 89 | const Fit_Element_Map_Dict* const elements_to_fit, 90 | const struct Range energy_range, 91 | ArrayTr* custom_background); 92 | 93 | void initialize_mp(models::Base_Model* const model, 94 | const Fit_Element_Map_Dict* const elements_to_fit, 95 | const struct Range energy_range); 96 | 97 | protected: 98 | 99 | void _generate_fitmatrix(); 100 | 101 | size_t _max_iter; 102 | 103 | private: 104 | 105 | Eigen::Matrix _fitmatrix; 106 | 107 | std::unordered_map _element_row_index; 108 | 109 | }; 110 | 111 | } //namespace routines 112 | 113 | } //namespace fitting 114 | 115 | #endif // NNLS_Fit_Routine_H 116 | -------------------------------------------------------------------------------- /src/workflow/distributor.h: -------------------------------------------------------------------------------- 1 | /*** 2 | Copyright (c) 2016, UChicago Argonne, LLC. All rights reserved. 3 | 4 | Copyright 2016. UChicago Argonne, LLC. This software was produced 5 | under U.S. Government contract DE-AC02-06CH11357 for Argonne National 6 | Laboratory (ANL), which is operated by UChicago Argonne, LLC for the 7 | U.S. Department of Energy. The U.S. Government has rights to use, 8 | reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR 9 | UChicago Argonne, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 10 | ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is 11 | modified to produce derivative works, such modified software should 12 | be clearly marked, so as not to confuse it with the version available 13 | from ANL. 14 | 15 | Additionally, redistribution and use in source and binary forms, with 16 | or without modification, are permitted provided that the following 17 | conditions are met: 18 | 19 | * Redistributions of source code must retain the above copyright 20 | notice, this list of conditions and the following disclaimer. 21 | 22 | * Redistributions in binary form must reproduce the above copyright 23 | notice, this list of conditions and the following disclaimer in 24 | the documentation and/or other materials provided with the 25 | distribution. 26 | 27 | * Neither the name of UChicago Argonne, LLC, Argonne National 28 | Laboratory, ANL, the U.S. Government, nor the names of its 29 | contributors may be used to endorse or promote products derived 30 | from this software without specific prior written permission. 31 | 32 | THIS SOFTWARE IS PROVIDED BY UChicago Argonne, LLC AND CONTRIBUTORS 33 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 34 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 35 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UChicago 36 | Argonne, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 37 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 38 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 39 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 40 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 41 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 42 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | ***/ 45 | 46 | /// Initial Author <2017>: Arthur Glowacki 47 | 48 | 49 | 50 | #ifndef Distributor_H 51 | #define Distributor_H 52 | 53 | #include "core/defines.h" 54 | #include "threadpool.h" 55 | #include 56 | 57 | namespace workflow 58 | { 59 | 60 | //----------------------------------------------------------------------------- 61 | template 62 | class DLL_EXPORT Distributor 63 | { 64 | 65 | public: 66 | 67 | Distributor(size_t num_threads) 68 | { 69 | _thread_pool = new ThreadPool(num_threads); 70 | _callback_func = std::bind(&Distributor::distribute, this, std::placeholders::_1); 71 | } 72 | 73 | Distributor(const Distributor &) 74 | { 75 | 76 | } 77 | 78 | Distributor& operator=(const Distributor&) 79 | { 80 | return *this; 81 | } 82 | 83 | virtual ~Distributor() 84 | { 85 | delete _thread_pool; 86 | } 87 | 88 | void distribute(T_IN input) 89 | { 90 | std::unique_lock lock(_queue_mutex); 91 | _job_queue.emplace( _thread_pool->enqueue(_dist_func, input) ); 92 | } 93 | 94 | std::function get_callback_func() 95 | { 96 | return _callback_func; 97 | } 98 | 99 | void set_function(std::function dist_func) 100 | { 101 | _dist_func = dist_func; 102 | } 103 | 104 | inline bool is_queue_empty() { return _job_queue.empty(); } 105 | 106 | T_OUT front_pop() 107 | { 108 | std::unique_lock lock(_queue_mutex); 109 | auto ret = std::move(_job_queue.front()); 110 | _job_queue.pop(); 111 | return ret.get(); 112 | } 113 | 114 | void front_chunk(std::queue > *queue) 115 | { 116 | std::unique_lock lock(_queue_mutex); 117 | while(! _job_queue.empty() ) 118 | { 119 | queue->emplace( std::move(_job_queue.front()) ); 120 | _job_queue.pop(); 121 | } 122 | } 123 | 124 | protected: 125 | 126 | std::function _callback_func; 127 | 128 | std::function _dist_func; 129 | 130 | ThreadPool *_thread_pool; 131 | 132 | std::mutex _queue_mutex; 133 | 134 | std::queue > _job_queue; 135 | 136 | }; 137 | 138 | } //namespace workflow 139 | 140 | #endif // Distributor_H 141 | -------------------------------------------------------------------------------- /src/support/mdautils-1.4.1/README.txt: -------------------------------------------------------------------------------- 1 | MDA Utilities v1.4.1 2 | August 2016 3 | 4 | Written by Dohn A. Arms, Argonne National Laboratory 5 | Send comments to dohnarms@anl.gov 6 | 7 | See LICENSE file for licensing of these programs and code. 8 | 9 | The location of these utilities on the Internet is: 10 | http://www.aps.anl.gov/bcda/mdautils/ 11 | 12 | -------------------------------------------------------------- 13 | 14 | 15 | These utilities are used for accessing MDA files generated by the 16 | saveData routine in EPICS, and can handles MDA files of any dimension. 17 | The MDA file versions handled with this code are 1.2, 1.3, and 1.4. 18 | 19 | The command line utilities all give help with the "-h" option, and 20 | show version information with the "-v" option. Documentation is also 21 | included in the "doc" subdirectory. Each utility has a man page (with 22 | a PDF version included), while the library comes with a manual in PDF 23 | form. 24 | 25 | 26 | Utilities: 27 | ----------- 28 | 29 | 1) mda2ascii - This program converts MDA files to ASCII files, with 30 | various options, so the data can be read directly into a 31 | plotting/fitting program. 32 | 33 | 2) mda-info - This program will print to the screen information about 34 | an MDA file. It shows things such as the time, the dimensionality, 35 | positioners, detectors, and triggers used. 36 | 37 | 3) mda-ls - This program print to the screen a listing of all the MDA 38 | files in the current or a specified directory. It shows the name, 39 | dimensionality, positioners, and optionally the time for each file. 40 | It is possible to filter the listing to those files including a 41 | certain positioner, detector, or trigger. 42 | 43 | 4) mda-dump - This program will dump to the screen the entire contents 44 | of an MDA file, exactly as how they appear in the file. This program 45 | can be useful for debugging purposes, as it prints out information 46 | immediately after loading it. It does not use the mda-load library, 47 | instead using direct functions for reading the file. 48 | 49 | 5) mdatree2ascii - This script converts a directory tree of MDA files 50 | into a new parallel directory tree populated by ASCII files, ignoring 51 | all non-MDA files. It uses the program mda2ascii to do the actual 52 | conversion. 53 | 54 | 6) mda-load library - This is the engine used for reading the MDA 55 | files. The library functions are relatively simple, as there are very 56 | few. Accessing the data -- due to the arbitrary dimensional nature of 57 | the MDA files -- can be complicated, and familiarity with structures 58 | and pointers in C is a must. The manual for it is mda-load.pdf, and 59 | reading mda-load.h can be helpful. It could be built as a shared 60 | library, but since it is rather small and different systems utilize 61 | shared libraries differently, this isn't enabled. 62 | 63 | Requirements: 64 | ------------- 65 | 66 | MDA Utilities can be compiled using a C99-compatible compiler (such as 67 | gcc), make, and ar (if the library is to be made). C99 compatiblity 68 | is needed only so far as . MDA Utilities have been 69 | successfully compiled on Linux and Mac OS X, while it can also be 70 | compiled on Solaris and Windows (I use MinGW). 71 | 72 | The only extra library requirement is access to the standard XDR 73 | routines. With Linux and Mac OS X, they're part of the standard C 74 | library; with Solaris, they're part of the standard Networking 75 | Services Library (nsl). No extra packages should have to be installed 76 | with these systems. 77 | 78 | Windows does not come standard with XDR routines. Either an extra 79 | library has be used, or an included XDR reading hack can be enabled 80 | (using the xdr_hack code). Either way, the Makefile has to be modified 81 | to make this all work. 82 | 83 | The program mdatree2ascii is a script, and needs the following 84 | programs (other than mda2ascii): bash, find, and sed. These programs 85 | are very standard (other than on Windows), and should already be 86 | installed on your system. 87 | 88 | 89 | 90 | Compiling: 91 | ---------- 92 | 93 | If building from source code, except for Windows, all you need to do 94 | is type "make" when in the source directory, and the executables and 95 | library should be made. 96 | 97 | With Windows, the Makefile has to be edited. The line in the Windows 98 | comment block has to be uncommented. If using the included XDR 99 | support, the first two lines of the XDR block as well as the 100 | little-endian (LE) line have to be uncommented. The names of the 101 | resulting executables need to be renamed to inlude the .exe suffix as 102 | well. The GCC and AR definitions might have to be changed. 103 | 104 | 105 | 106 | Installing: 107 | ----------- 108 | 109 | To install the utilities in "/usr/local", simply run "make install". 110 | If you want the files in a different directory, change the "prefix" 111 | variable in the file Makefile, then run "make install". Otherwise, 112 | you can copy the files wherever you like. 113 | 114 | -------------------------------------------------------------------------------- /src/support/mdautils-1.4.1/mda-load.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************\ 2 | * Copyright (c) 2016 UChicago Argonne, LLC, 3 | * as Operator of Argonne National Laboratory. 4 | * This file is distributed subject to a Software License Agreement 5 | * found in file LICENSE that is included with this distribution. 6 | \*************************************************************************/ 7 | 8 | 9 | /* 10 | Written by Dohn A. Arms, Argonne National Laboratory 11 | Send comments to dohnarms@anl.gov 12 | 13 | 0.1 -- July 2005 14 | 0.1.1 -- December 2006 15 | Added support for files that have more than 32k points 16 | 0.2.0 -- October 2007 17 | Added several new functions for accessing scans or the extra PV's 18 | without loading the entire file. 19 | 0.2.1 -- March 2009 20 | 1.0 -- October 2009 21 | Renamed structures. 22 | 1.1 -- November 2010 23 | 1.1.1 -- December 2010 24 | 1.2 -- March 2011 25 | Fixed integer issues by tying short to int16_t, long to int32_t, 26 | and char to int8_t 27 | 1.2.1 -- January 2012 28 | 1.2.2 -- June 2012 29 | Added preprocessor commands for c++ compatibility 30 | 1.3.0 -- February 2013 31 | 1.3.1 -- February 2014 32 | 1.4.0 -- July 2016 33 | */ 34 | 35 | 36 | /****************** mda_load.h **************/ 37 | 38 | #ifndef MDA_LOAD_H 39 | #define MDA_LOAD_H 1 40 | 41 | #ifdef __cplusplus 42 | extern "C" { 43 | #endif 44 | 45 | #include 46 | #include 47 | 48 | struct mda_header 49 | { 50 | float version; 51 | int32_t scan_number; 52 | int16_t data_rank; 53 | int32_t *dimensions; 54 | int16_t regular; 55 | int32_t extra_pvs_offset; 56 | }; 57 | 58 | 59 | struct mda_positioner 60 | { 61 | int16_t number; 62 | char *name; 63 | char *description; 64 | char *step_mode; 65 | char *unit; 66 | char *readback_name; 67 | char *readback_description; 68 | char *readback_unit; 69 | }; 70 | 71 | 72 | struct mda_detector 73 | { 74 | int16_t number; 75 | char *name; 76 | char *description; 77 | char *unit; 78 | }; 79 | 80 | 81 | struct mda_trigger 82 | { 83 | int16_t number; 84 | char *name; 85 | float command; 86 | }; 87 | 88 | 89 | struct mda_scan 90 | { 91 | int16_t scan_rank; 92 | int32_t requested_points; 93 | int32_t last_point; 94 | int32_t *offsets; 95 | char *name; 96 | char *time; 97 | int16_t number_positioners; 98 | int16_t number_detectors; 99 | int16_t number_triggers; 100 | 101 | struct mda_positioner **positioners; 102 | struct mda_detector **detectors; 103 | struct mda_trigger **triggers; 104 | double **positioners_data; 105 | float **detectors_data; 106 | 107 | struct mda_scan **sub_scans; 108 | }; 109 | 110 | enum PV_TYPES { EXTRA_PV_STRING=0, EXTRA_PV_INT8=32, EXTRA_PV_INT16=29, 111 | EXTRA_PV_INT32=33, EXTRA_PV_FLOAT=30, EXTRA_PV_DOUBLE=34 }; 112 | 113 | struct mda_pv 114 | { 115 | char *name; 116 | char *description; 117 | int16_t type; 118 | int16_t count; 119 | char *unit; 120 | char *values; 121 | }; 122 | 123 | 124 | struct mda_extra 125 | { 126 | int16_t number_pvs; 127 | struct mda_pv **pvs; 128 | }; 129 | 130 | 131 | struct mda_file 132 | { 133 | struct mda_header *header; 134 | struct mda_scan *scan; 135 | struct mda_extra *extra; 136 | }; 137 | 138 | 139 | /*****************************************************/ 140 | 141 | struct mda_scaninfo 142 | { 143 | int16_t scan_rank; /* redundant */ 144 | int32_t requested_points; /* redundant */ 145 | char *name; 146 | int16_t number_positioners; 147 | int16_t number_detectors; 148 | int16_t number_triggers; 149 | 150 | struct mda_positioner **positioners; 151 | struct mda_detector **detectors; 152 | struct mda_trigger **triggers; 153 | }; 154 | 155 | struct mda_fileinfo 156 | { 157 | float version; 158 | int32_t scan_number; 159 | int16_t data_rank; 160 | int32_t *dimensions; 161 | int16_t regular; 162 | int32_t last_topdim_point; 163 | char *time; 164 | struct mda_scaninfo **scaninfos; 165 | }; 166 | 167 | /******************************************************/ 168 | 169 | struct mda_file *mda_load( FILE *fptr); 170 | struct mda_header *mda_header_load( FILE *fptr); 171 | struct mda_scan *mda_scan_load( FILE *fptr); 172 | struct mda_scan *mda_subscan_load( FILE *fptr, int depth, int *indices, 173 | int recursive); 174 | struct mda_extra *mda_extra_load( FILE *fptr); 175 | struct mda_file *mda_update( FILE *fptr, struct mda_file *previous_mda); 176 | 177 | void mda_unload( struct mda_file *mda); 178 | void mda_header_unload( struct mda_header *header); 179 | void mda_scan_unload( struct mda_scan *scan); 180 | void mda_extra_unload( struct mda_extra *extra); 181 | 182 | 183 | int mda_test( FILE *fptr); 184 | struct mda_fileinfo *mda_info_load( FILE *fptr); 185 | void mda_info_unload( struct mda_fileinfo *fileinfo); 186 | 187 | 188 | #ifdef __cplusplus 189 | } 190 | #endif 191 | 192 | #endif /* MDA_LOAD_H */ 193 | -------------------------------------------------------------------------------- /src/workflow/xrf/spectra_file_source.h: -------------------------------------------------------------------------------- 1 | /*** 2 | Copyright (c) 2016, UChicago Argonne, LLC. All rights reserved. 3 | 4 | Copyright 2016. UChicago Argonne, LLC. This software was produced 5 | under U.S. Government contract DE-AC02-06CH11357 for Argonne National 6 | Laboratory (ANL), which is operated by UChicago Argonne, LLC for the 7 | U.S. Department of Energy. The U.S. Government has rights to use, 8 | reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR 9 | UChicago Argonne, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 10 | ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is 11 | modified to produce derivative works, such modified software should 12 | be clearly marked, so as not to confuse it with the version available 13 | from ANL. 14 | 15 | Additionally, redistribution and use in source and binary forms, with 16 | or without modification, are permitted provided that the following 17 | conditions are met: 18 | 19 | * Redistributions of source code must retain the above copyright 20 | notice, this list of conditions and the following disclaimer. 21 | 22 | * Redistributions in binary form must reproduce the above copyright 23 | notice, this list of conditions and the following disclaimer in 24 | the documentation and/or other materials provided with the 25 | distribution. 26 | 27 | * Neither the name of UChicago Argonne, LLC, Argonne National 28 | Laboratory, ANL, the U.S. Government, nor the names of its 29 | contributors may be used to endorse or promote products derived 30 | from this software without specific prior written permission. 31 | 32 | THIS SOFTWARE IS PROVIDED BY UChicago Argonne, LLC AND CONTRIBUTORS 33 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 34 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 35 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UChicago 36 | Argonne, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 37 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 38 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 39 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 40 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 41 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 42 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | ***/ 45 | 46 | /// Initial Author <2017>: Arthur Glowacki 47 | 48 | 49 | 50 | #ifndef Spectra_File_Source_H 51 | #define Spectra_File_Source_H 52 | 53 | #include "core/defines.h" 54 | 55 | #include "workflow/source.h" 56 | #include "data_struct/stream_block.h" 57 | #include "data_struct/analysis_job.h" 58 | #include "io/file/hl_file_io.h" 59 | #include 60 | #include 61 | #include 62 | 63 | namespace workflow 64 | { 65 | namespace xrf 66 | { 67 | 68 | //----------------------------------------------------------------------------- 69 | 70 | template 71 | class DLL_EXPORT Spectra_File_Source : public Source*> 72 | { 73 | 74 | public: 75 | 76 | Spectra_File_Source(); 77 | 78 | //used with run function to process job 79 | Spectra_File_Source(data_struct::Analysis_Job* analysis_job); 80 | 81 | virtual ~Spectra_File_Source(); 82 | 83 | virtual void cb_load_spectra_data(size_t row, size_t col, size_t height, size_t width, size_t detector_num, data_struct::Spectra* spectra, void* user_data); 84 | 85 | virtual void run(); 86 | 87 | bool load_netcdf_line(std::string dirpath, 88 | std::string filename, 89 | const std::vector& detector_num_arr, 90 | size_t row, 91 | size_t row_size, 92 | size_t col_size); 93 | 94 | void set_init_fitting_routines(bool val) {_init_fitting_routines = val;} 95 | 96 | protected: 97 | 98 | virtual bool _load_spectra_volume_with_callback(std::string dataset_directory, 99 | std::string dataset_file, 100 | const std::vector& detector_num_arr, 101 | data_struct::IO_Callback_Func_Def callback_fun); 102 | 103 | 104 | data_struct::Stream_Block* _alloc_stream_block(int detector, size_t row, size_t col, size_t height, size_t width, size_t spectra_size); 105 | 106 | int _max_num_stream_blocks; 107 | int _allocated_stream_blocks; 108 | 109 | std::string *_current_dataset_directory; 110 | std::string *_current_dataset_name; 111 | 112 | data_struct::Analysis_Job* _analysis_job; 113 | 114 | std::vector _netcdf_files; 115 | 116 | std::vector _bnp_netcdf_files; 117 | 118 | std::vector _hdf_files; 119 | 120 | std::function *, void*)> _cb_function; 121 | 122 | bool _init_fitting_routines; 123 | 124 | }; 125 | 126 | } //namespace xrf 127 | } //namespace workflow 128 | 129 | #endif // Spectra_File_Source_H 130 | -------------------------------------------------------------------------------- /src/data_struct/spectra_line.cpp: -------------------------------------------------------------------------------- 1 | /*** 2 | Copyright (c) 2016, UChicago Argonne, LLC. All rights reserved. 3 | 4 | Copyright 2016. UChicago Argonne, LLC. This software was produced 5 | under U.S. Government contract DE-AC02-06CH11357 for Argonne National 6 | Laboratory (ANL), which is operated by UChicago Argonne, LLC for the 7 | U.S. Department of Energy. The U.S. Government has rights to use, 8 | reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR 9 | UChicago Argonne, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 10 | ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is 11 | modified to produce derivative works, such modified software should 12 | be clearly marked, so as not to confuse it with the version available 13 | from ANL. 14 | 15 | Additionally, redistribution and use in source and binary forms, with 16 | or without modification, are permitted provided that the following 17 | conditions are met: 18 | 19 | * Redistributions of source code must retain the above copyright 20 | notice, this list of conditions and the following disclaimer. 21 | 22 | * Redistributions in binary form must reproduce the above copyright 23 | notice, this list of conditions and the following disclaimer in 24 | the documentation and/or other materials provided with the 25 | distribution. 26 | 27 | * Neither the name of UChicago Argonne, LLC, Argonne National 28 | Laboratory, ANL, the U.S. Government, nor the names of its 29 | contributors may be used to endorse or promote products derived 30 | from this software without specific prior written permission. 31 | 32 | THIS SOFTWARE IS PROVIDED BY UChicago Argonne, LLC AND CONTRIBUTORS 33 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 34 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 35 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UChicago 36 | Argonne, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 37 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 38 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 39 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 40 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 41 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 42 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | ***/ 45 | 46 | /// Initial Author <2016>: Arthur Glowacki 47 | 48 | 49 | 50 | #include "spectra_line.h" 51 | 52 | namespace data_struct 53 | { 54 | 55 | // ---------------------------------------------------------------------------- 56 | 57 | template 58 | Spectra_Line::Spectra_Line() 59 | { 60 | 61 | } 62 | 63 | // ---------------------------------------------------------------------------- 64 | 65 | template 66 | Spectra_Line::~Spectra_Line() 67 | { 68 | /* 69 | for(auto spec : _data_line) 70 | { 71 | delete spec; 72 | } 73 | _data_line.clear(); 74 | */ 75 | } 76 | 77 | // ---------------------------------------------------------------------------- 78 | 79 | /* 80 | void Spectra_Line::append_spectra(Spectra* spectra) 81 | { 82 | _data_line.push_back(spectra); 83 | } 84 | */ 85 | 86 | // ---------------------------------------------------------------------------- 87 | 88 | template 89 | void Spectra_Line::resize_and_zero(size_t cols, size_t samples) 90 | { 91 | alloc_row_size(cols); 92 | _alloc_spectra_size(samples); 93 | } 94 | 95 | // ---------------------------------------------------------------------------- 96 | 97 | template 98 | void Spectra_Line::resize_samples(size_t samples) 99 | { 100 | _alloc_spectra_size(samples); 101 | } 102 | 103 | // ---------------------------------------------------------------------------- 104 | 105 | template 106 | void Spectra_Line::alloc_row_size(size_t n) 107 | { 108 | _data_line.resize(n); 109 | } 110 | 111 | // ---------------------------------------------------------------------------- 112 | 113 | template 114 | void Spectra_Line::_alloc_spectra_size(size_t n) 115 | { 116 | for(size_t i=0; i<_data_line.size(); i++) 117 | { 118 | _data_line[i].resize(n); 119 | _data_line[i].setZero(n); 120 | } 121 | /* 122 | for(Spectra s : _data_line) 123 | { 124 | s.alloc_buffer(n); 125 | }*/ 126 | //_data_line.resize(n); 127 | } 128 | 129 | // ---------------------------------------------------------------------------- 130 | 131 | template 132 | void Spectra_Line::recalc_elapsed_livetime() 133 | { 134 | for(size_t i=0; i<_data_line.size(); i++) 135 | { 136 | _data_line[i].recalc_elapsed_livetime(); 137 | } 138 | } 139 | 140 | // ---------------------------------------------------------------------------- 141 | // ---------------------------------------------------------------------------- 142 | 143 | TEMPLATE_CLASS_DLL_EXPORT Spectra_Line; 144 | TEMPLATE_CLASS_DLL_EXPORT Spectra_Line; 145 | 146 | } //namespace data_struct 147 | -------------------------------------------------------------------------------- /src/fitting/optimizers/nlopt_optimizer.h: -------------------------------------------------------------------------------- 1 | /*** 2 | Copyright (c) 2024, UChicago Argonne, LLC. All rights reserved. 3 | 4 | Copyright 2024. UChicago Argonne, LLC. This software was produced 5 | under U.S. Government contract DE-AC02-06CH11357 for Argonne National 6 | Laboratory (ANL), which is operated by UChicago Argonne, LLC for the 7 | U.S. Department of Energy. The U.S. Government has rights to use, 8 | reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR 9 | UChicago Argonne, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 10 | ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is 11 | modified to produce derivative works, such modified software should 12 | be clearly marked, so as not to confuse it with the version available 13 | from ANL. 14 | 15 | Additionally, redistribution and use in source and binary forms, with 16 | or without modification, are permitted provided that the following 17 | conditions are met: 18 | 19 | * Redistributions of source code must retain the above copyright 20 | notice, this list of conditions and the following disclaimer. 21 | 22 | * Redistributions in binary form must reproduce the above copyright 23 | notice, this list of conditions and the following disclaimer in 24 | the documentation and/or other materials provided with the 25 | distribution. 26 | 27 | * Neither the name of UChicago Argonne, LLC, Argonne National 28 | Laboratory, ANL, the U.S. Government, nor the names of its 29 | contributors may be used to endorse or promote products derived 30 | from this software without specific prior written permission. 31 | 32 | THIS SOFTWARE IS PROVIDED BY UChicago Argonne, LLC AND CONTRIBUTORS 33 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 34 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 35 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UChicago 36 | Argonne, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 37 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 38 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 39 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 40 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 41 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 42 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | ***/ 45 | 46 | /// Initial Author <2016>: Arthur Glowacki 47 | 48 | 49 | 50 | #ifndef NLOPT_Optimizer_H 51 | #define NLOPT_Optimizer_H 52 | 53 | #include "fitting/optimizers/optimizer.h" 54 | #include 55 | #include 56 | 57 | namespace fitting 58 | { 59 | namespace optimizers 60 | { 61 | 62 | using namespace data_struct; 63 | 64 | template 65 | class DLL_EXPORT NLOPT_Optimizer: public Optimizer 66 | { 67 | public: 68 | NLOPT_Optimizer(); 69 | 70 | virtual ~NLOPT_Optimizer() {} 71 | 72 | virtual OPTIMIZER_OUTCOME minimize(Fit_Parameters*fit_params, 73 | const Spectra* const spectra, 74 | const Fit_Element_Map_Dict* const elements_to_fit, 75 | const Base_Model* const model, 76 | const Range energy_range, 77 | const ArrayTr * const background, 78 | bool use_weights, 79 | Callback_Func_Status_Def* status_callback = nullptr); 80 | 81 | virtual OPTIMIZER_OUTCOME minimize_func(const Base_Model* const model, 82 | Fit_Parameters*fit_params, 83 | const Spectra* const spectra, 84 | const Range energy_range, 85 | const ArrayTr* background, 86 | Gen_Func_Def gen_func, 87 | bool use_weights); 88 | 89 | virtual OPTIMIZER_OUTCOME minimize_quantification(Fit_Parameters*fit_params, 90 | std::unordered_map*> * quant_map, 91 | quantification::models::Quantification_Model* quantification_model); 92 | 93 | virtual std::vector get_algorithm_list(); 94 | 95 | virtual bool set_algorithm(std::string name); 96 | 97 | virtual std::unordered_map get_options(); 98 | 99 | virtual void set_options(std::unordered_map opt); 100 | 101 | virtual std::string detailed_outcome(int outcome); 102 | 103 | private: 104 | std::unordered_map _algorithms; 105 | 106 | std::unordered_map _options; 107 | 108 | nlopt::algorithm _algo; 109 | 110 | }; 111 | 112 | } //namespace optimizers 113 | 114 | } //namespace fitting 115 | 116 | #endif // NLOPT_Optimizer_H 117 | -------------------------------------------------------------------------------- /src/data_struct/stream_block.h: -------------------------------------------------------------------------------- 1 | /*** 2 | Copyright (c) 2016, UChicago Argonne, LLC. All rights reserved. 3 | 4 | Copyright 2016. UChicago Argonne, LLC. This software was produced 5 | under U.S. Government contract DE-AC02-06CH11357 for Argonne National 6 | Laboratory (ANL), which is operated by UChicago Argonne, LLC for the 7 | U.S. Department of Energy. The U.S. Government has rights to use, 8 | reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR 9 | UChicago Argonne, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 10 | ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is 11 | modified to produce derivative works, such modified software should 12 | be clearly marked, so as not to confuse it with the version available 13 | from ANL. 14 | 15 | Additionally, redistribution and use in source and binary forms, with 16 | or without modification, are permitted provided that the following 17 | conditions are met: 18 | 19 | * Redistributions of source code must retain the above copyright 20 | notice, this list of conditions and the following disclaimer. 21 | 22 | * Redistributions in binary form must reproduce the above copyright 23 | notice, this list of conditions and the following disclaimer in 24 | the documentation and/or other materials provided with the 25 | distribution. 26 | 27 | * Neither the name of UChicago Argonne, LLC, Argonne National 28 | Laboratory, ANL, the U.S. Government, nor the names of its 29 | contributors may be used to endorse or promote products derived 30 | from this software without specific prior written permission. 31 | 32 | THIS SOFTWARE IS PROVIDED BY UChicago Argonne, LLC AND CONTRIBUTORS 33 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 34 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 35 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UChicago 36 | Argonne, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 37 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 38 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 39 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 40 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 41 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 42 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | ***/ 45 | 46 | /// Initial Author <2017>: Arthur Glowacki 47 | 48 | 49 | 50 | #ifndef Stream_Block_H 51 | #define Stream_Block_H 52 | 53 | #include "core/defines.h" 54 | #include "data_struct/element_info.h" 55 | #include "fitting/routines/base_fit_routine.h" 56 | 57 | namespace data_struct 58 | { 59 | 60 | //----------------------------------------------------------------------------- 61 | 62 | /// 63 | /// \brief The Stream_Fitting_Block struct 64 | /// 65 | template 66 | struct Stream_Fitting_Block 67 | { 68 | fitting::routines::Base_Fit_Routine* fit_routine; 69 | std::unordered_map fit_counts; 70 | }; 71 | 72 | //----------------------------------------------------------------------------- 73 | 74 | /// 75 | /// \brief The Stream_Block class 76 | /// 77 | template 78 | class DLL_EXPORT Stream_Block 79 | { 80 | 81 | public: 82 | 83 | Stream_Block(); 84 | 85 | Stream_Block(int detector, size_t row, size_t col, size_t height, size_t width); 86 | 87 | Stream_Block(int detector, size_t row, size_t col, size_t height, size_t width, std::string dir_name, std::string dset_name); 88 | 89 | Stream_Block(const Stream_Block& stream_block); 90 | 91 | Stream_Block& operator=(const Stream_Block&); 92 | 93 | ~Stream_Block(); 94 | 95 | void init_fitting_blocks(std::unordered_map*> *fit_routines, Fit_Element_Map_Dict* elements_to_fit_); 96 | 97 | const size_t& row() { return _row; } 98 | 99 | const size_t& col() { return _col; } 100 | 101 | const size_t& height() { return _height; } 102 | 103 | const size_t& width() { return _width; } 104 | 105 | const int& detector_number() { return _detector; } 106 | 107 | inline bool is_end_of_row() { return (_col == _width - (size_t)1); } 108 | 109 | inline bool is_end_block() { return (_detector == (int)-1 && _row == (size_t)-1 && _height == (size_t)-1 && _col == (size_t)-1 && _width == (size_t)-1); } 110 | 111 | 112 | //by Fitting_Routines 113 | std::unordered_map> fitting_blocks; 114 | 115 | size_t dataset_hash(); 116 | 117 | std::string *dataset_directory; 118 | 119 | std::string *dataset_name; 120 | 121 | Spectra* spectra; 122 | 123 | Fit_Element_Map_Dict * elements_to_fit; 124 | //data_struct::Params_Override *fit_params_override_dict; 125 | 126 | fitting::models::Fit_Params_Preset optimize_fit_params_preset; 127 | 128 | fitting::models::Base_Model * model; 129 | 130 | float theta; 131 | 132 | bool del_str_ptr; 133 | 134 | protected: 135 | 136 | size_t _row; 137 | 138 | size_t _col; 139 | 140 | size_t _height; 141 | 142 | size_t _width; 143 | 144 | int _detector; 145 | }; 146 | 147 | } //namespace data_struct 148 | 149 | #endif // Stream_Block_H 150 | -------------------------------------------------------------------------------- /src/fitting/routines/base_fit_routine.h: -------------------------------------------------------------------------------- 1 | /*** 2 | Copyright (c) 2016, UChicago Argonne, LLC. All rights reserved. 3 | 4 | Copyright 2016. UChicago Argonne, LLC. This software was produced 5 | under U.S. Government contract DE-AC02-06CH11357 for Argonne National 6 | Laboratory (ANL), which is operated by UChicago Argonne, LLC for the 7 | U.S. Department of Energy. The U.S. Government has rights to use, 8 | reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR 9 | UChicago Argonne, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 10 | ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is 11 | modified to produce derivative works, such modified software should 12 | be clearly marked, so as not to confuse it with the version available 13 | from ANL. 14 | 15 | Additionally, redistribution and use in source and binary forms, with 16 | or without modification, are permitted provided that the following 17 | conditions are met: 18 | 19 | * Redistributions of source code must retain the above copyright 20 | notice, this list of conditions and the following disclaimer. 21 | 22 | * Redistributions in binary form must reproduce the above copyright 23 | notice, this list of conditions and the following disclaimer in 24 | the documentation and/or other materials provided with the 25 | distribution. 26 | 27 | * Neither the name of UChicago Argonne, LLC, Argonne National 28 | Laboratory, ANL, the U.S. Government, nor the names of its 29 | contributors may be used to endorse or promote products derived 30 | from this software without specific prior written permission. 31 | 32 | THIS SOFTWARE IS PROVIDED BY UChicago Argonne, LLC AND CONTRIBUTORS 33 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 34 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 35 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UChicago 36 | Argonne, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 37 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 38 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 39 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 40 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 41 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 42 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | ***/ 45 | 46 | /// Initial Author <2016>: Arthur Glowacki 47 | 48 | 49 | #ifndef Base_Fit_Routine_H 50 | #define Base_Fit_Routine_H 51 | 52 | #include 53 | 54 | #include "fitting/optimizers/optimizer.h" 55 | #include "data_struct/spectra.h" 56 | #include "fitting/models/base_model.h" 57 | #include "data_struct/fit_element_map.h" 58 | 59 | namespace fitting 60 | { 61 | namespace routines 62 | { 63 | 64 | using namespace data_struct; 65 | 66 | 67 | /** 68 | * @brief The Base_Fit_Routine class: base class for modeling spectra and fitting elements 69 | */ 70 | template 71 | class DLL_EXPORT Base_Fit_Routine 72 | { 73 | public: 74 | /** 75 | * @brief Base_Fit_Routine : Constructor 76 | */ 77 | Base_Fit_Routine() {} 78 | 79 | /** 80 | * @brief ~Base_Fit_Routine : Destructor 81 | */ 82 | virtual ~Base_Fit_Routine() {} 83 | 84 | /** 85 | * @brief fit_spectra : Fit a single specra ( typically 2048 in size ) 86 | * @param fit_params : Fitting parameters required by the routine 87 | * @param spectra : Pointer to the spectra we are fitting to 88 | * @param calibration : Energy calibration 89 | * @param elements_to_fit : List of elemetns to fit to the spectra. This is an out variable also. Must be allocated to saved fitted value to using row_idx and col_idx 90 | * @param row_idx : row index used to save the fitted value back into elements_to_fit class 91 | * @param col_idx : column index used to save the fitted value back into elements_to_fit class 92 | */ 93 | virtual optimizers::OPTIMIZER_OUTCOME fit_spectra(const models::Base_Model * const model, 94 | const Spectra* const spectra, 95 | const Fit_Element_Map_Dict * const elements_to_fit, 96 | std::unordered_map& out_counts) = 0; 97 | 98 | /** 99 | * @brief get_name : Returns fit routine name 100 | * @return 101 | */ 102 | virtual std::string get_name() = 0; 103 | 104 | /** 105 | * @brief initialize : Initialize the model 106 | * @param fit_params 107 | * @param calibration 108 | * @param elements_to_fit 109 | * @param energy_range 110 | */ 111 | virtual void initialize(models::Base_Model* const model, 112 | const Fit_Element_Map_Dict * const elements_to_fit, 113 | const struct Range energy_range, 114 | ArrayTr* custom_background) = 0; 115 | 116 | 117 | protected: 118 | 119 | 120 | private: 121 | 122 | 123 | }; 124 | 125 | TEMPLATE_CLASS_DLL_EXPORT Base_Fit_Routine; 126 | TEMPLATE_CLASS_DLL_EXPORT Base_Fit_Routine; 127 | 128 | } //namespace routines 129 | 130 | } //namespace fitting 131 | 132 | #endif // Base_Fit_Routine_H 133 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Actions Status](https://github.com/aglowacki/XRF-Maps/workflows/CMake/badge.svg)](https://github.com/aglowacki/XRF-Maps/actions) 2 | [![Build Status](https://dev.azure.com/aglow/XRF-Maps/_apis/build/status/aglowacki.XRF-Maps?branchName=master)](https://dev.azure.com/aglow/XRF-Maps/_build/latest?definitionId=2&branchName=master) 3 | 4 | # XRF-Maps 5 | 6 | X-ray fluorescence (XRF) imaging typically involves the creation and analysis of 3D data sets, where at each scan position a full energy dispersive x-ray spectrum is recorded. This allows one to later process the data in a variety of different approaches, e.g., by spectral region of interest (ROI) summation with or without background subtraction, principal component analysis, or fitting. XRF-Maps is a C++ open source software package that implements these functions to provide a tool set for the analysis of XRF data sets. It is based on the MAPS software http://www.aps.anl.gov/Xray_Science_Division/Xray_Microscopy_and_Imaging/Software_and_Tools/maps.html 7 | 8 | # Compiling 9 | 10 | ## Requires 11 | 12 | Visual Studio 2015 or greater (Windows build) 13 | GCC 6.0 or greater (Linux build) 14 | Cmake 3.5 or greater 15 | 16 | ## Libraries 17 | 18 | HDF5 : https://www.hdfgroup.org/downloads/ 19 | NetCDF : http://www.unidata.ucar.edu/downloads/netcdf/index.jsp (Download http://www.unidata.ucar.edu/software/netcdf/docs/winbin.html) 20 | Eigen : http://eigen.tuxfamily.org/index.php?title=Main_Page (submodule in src/support) 21 | 22 | ## Optional Libraries 23 | 24 | QT : https://www.qt.io/download 25 | ZeroMQ : http://zeromq.org/area:download 26 | 27 | ## Compile Default 28 | 29 | 1) git clone --recurse-submodules https://github.com/AdvancedPhotonSource/XRF-Maps.git 30 | 2) cd XRF-Maps 31 | 3) mkdir build 32 | 4) cd vcpkg 33 | 5) vcpkg set Linux 34 | 1) ./bootstrap-vcpkg.sh 35 | 2) ./vcpkg install hdf5 netcdf-c yaml-cpp cppzmq nlopt jsoncpp 36 | 6) vcpkg setup windows 37 | 1) .\bootstrap-vcpkg.bat 38 | 2) .\vcpkg install hdf5 netcdf-c yaml-cpp cppzmq nlopt jsoncpp --triplet x64-windows 39 | 7) cd ../build 40 | 8) cmake `-DCMAKE_TOOLCHAIN_FILE=../vcpkg/scripts/buildsystems/vcpkg.cmake -DBUILD_WITH_ZMQ=ON ..` 41 | 9) make 42 | 43 | ## Building optional features 44 | 45 | ### QT support 46 | 47 | -DBUILD_WITH_QT=ON 48 | 49 | ### Streaming support with ZeroMQ 50 | 51 | -DBUILD_WITH_ZMQ=ON 52 | 53 | ### Python bindings (NOTE: this may interfere with QT options if QT lib version is different than python qt lib version as with anaconda python) 54 | 55 | -DBUILD_WITH_PYBIND11=ON 56 | -DPYTHON_EXECUTABLE={path to python.exe if not found} 57 | 58 | # Data Analysis 59 | 60 | ## General 61 | Run from bin directory. The software looks for references one directory up ( ../references ). 62 | ```bash 63 | Help: 64 | Usage: xrf_maps [Options] --dir [dataset directory] 65 | 66 | Options: 67 | --nthreads : number of threads to use (default is all system threads) 68 | --quantify-with : File to use as quantification standard 69 | --detectors : Detectors to process, Defaults to 0,1,2,3 for 4 detector 70 | --generate-avg-h5 : Generate .h5 file which is the average of all detectors .h50 - h.53 or range specified. 71 | --add-v9layout : Generate .h5 file which has v9 layout able to open in IDL MAPS software. 72 | --add-exchange : Add exchange group into hdf5 file with normalized data. 73 | --export-csv : Export Integrated spec, fitted, background to csv file. 74 | --update-theta : Update the theta dataset value using theta_pv_string as new pv string ref. 75 | --update-amps ,: Updates upstream and downstream amps if they changed inbetween scans. 76 | --update-quant-amps ,: Updates upstream and downstream amps for quantification if they changed inbetween scans. 77 | --quick-and-dirty : Integrate the detector range into 1 spectra. 78 | --optimize-fit-override-params : Integrate the 8 largest mda datasets and fit with multiple params. 79 | 1 = matrix batch fit 80 | 2 = batch fit without tails 81 | 3 = batch fit with tails 82 | 4 = batch fit with free E, everything else fixed 83 | --optimizer : Choose which optimizer to use for --optimize-fit-override-params or matrix fit routine 84 | Fitting Routines: 85 | --fit comma seperated 86 | roi : element energy region of interest 87 | roi_plus : SVD method 88 | nnls : Non-Negative Least Squares 89 | tails : Fit with multiple parameters 90 | matrix : Fit with locked parameters 91 | 92 | Dataset: 93 | --dir : Dataset directory 94 | --files : Dataset files: comma (',') separated if multiple 95 | Network: 96 | --streamin [source ip] : Accept a ZMQ stream of spectra to process. Source ip defaults to localhost (must compile with -DBUILD_WITH_ZMQ option) 97 | --streamout : Streams the analysis counts over a ZMQ stream (must compile with -DBUILD_WITH_ZMQ option) 98 | 99 | Examples: 100 | Perform roi and matrix analysis on the directory /data/dataset1 101 | xrf_maps --fit roi,matrix --dir /data/dataset1 102 | Perform roi and matrix analysis on the directory /data/dataset1 but only process scan1 and scan2 103 | xrf_maps --fit roi,matrix --dir /data/dataset1 --files scan1.mda,scan2.mda 104 | Perform roi, matrix, and nnls analysis on the directory /data/dataset1, use maps_standard.txt information for quantification 105 | xrf_maps --fit roi,matrix,nnls --quantify-with maps_standard.txt --dir /data/dataset1 106 | ``` -------------------------------------------------------------------------------- /src/io/file/aps/aps_roi.cpp: -------------------------------------------------------------------------------- 1 | /*** 2 | Copyright (c) 2016, UChicago Argonne, LLC. All rights reserved. 3 | 4 | Copyright 2016. UChicago Argonne, LLC. This software was produced 5 | under U.S. Government contract DE-AC02-06CH11357 for Argonne National 6 | Laboratory (ANL), which is operated by UChicago Argonne, LLC for the 7 | U.S. Department of Energy. The U.S. Government has rights to use, 8 | reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR 9 | UChicago Argonne, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 10 | ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is 11 | modified to produce derivative works, such modified software should 12 | be clearly marked, so as not to confuse it with the version available 13 | from ANL. 14 | 15 | Additionally, redistribution and use in source and binary forms, with 16 | or without modification, are permitted provided that the following 17 | conditions are met: 18 | 19 | * Redistributions of source code must retain the above copyright 20 | notice, this list of conditions and the following disclaimer. 21 | 22 | * Redistributions in binary form must reproduce the above copyright 23 | notice, this list of conditions and the following disclaimer in 24 | the documentation and/or other materials provided with the 25 | distribution. 26 | 27 | * Neither the name of UChicago Argonne, LLC, Argonne National 28 | Laboratory, ANL, the U.S. Government, nor the names of its 29 | contributors may be used to endorse or promote products derived 30 | from this software without specific prior written permission. 31 | 32 | THIS SOFTWARE IS PROVIDED BY UChicago Argonne, LLC AND CONTRIBUTORS 33 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 34 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 35 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UChicago 36 | Argonne, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 37 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 38 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 39 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 40 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 41 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 42 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | ***/ 45 | 46 | /// Initial Author <2022>: Arthur Glowacki 47 | 48 | 49 | 50 | #include "aps_roi.h" 51 | #include 52 | 53 | namespace io 54 | { 55 | namespace file 56 | { 57 | namespace aps 58 | { 59 | 60 | union Num 61 | { 62 | char buffer[4]; 63 | unsigned int num; 64 | } num; 65 | 66 | void swapChars(char* pChar1, char* pChar2) 67 | { 68 | char temp = *pChar1; 69 | *pChar1 = *pChar2; 70 | *pChar2 = temp; 71 | } 72 | 73 | int swapOrder(Num num1) 74 | { 75 | swapChars(&num1.buffer[0], &num1.buffer[3]); 76 | swapChars(&num1.buffer[1], &num1.buffer[2]); 77 | 78 | return num1.num; 79 | } 80 | 81 | bool load_v9_rois(std::string path, std::map>& rois) 82 | { 83 | std::ifstream fileStream; 84 | 85 | logI << "Loading: " << path << "\n"; 86 | Num val; 87 | unsigned int width; 88 | unsigned int height; 89 | unsigned int mask; 90 | std::vector myData; 91 | 92 | try 93 | { 94 | fileStream.exceptions(fileStream.failbit); 95 | fileStream.open(path, std::ios::in | std::ios::binary); 96 | if (fileStream.is_open()) 97 | { 98 | fileStream.read((char*)&val, sizeof(Num)); 99 | width = swapOrder(val); 100 | fileStream.read((char*)&val, sizeof(Num)); 101 | height = swapOrder(val); 102 | 103 | myData.resize(width * height); 104 | fileStream.read((char*)myData.data(), (width * height) * sizeof(unsigned int)); 105 | fileStream.close(); 106 | 107 | unsigned long i = 0; 108 | for (unsigned int y = 0; y < height; y++) 109 | { 110 | for (unsigned int x = 0; x < width; x++) 111 | { 112 | if (myData[i]) 113 | { 114 | val.num = myData[i]; 115 | mask = swapOrder(val); 116 | unsigned int m = 1; 117 | for (int idx = 1; idx < 12; idx++) 118 | { 119 | if ((m & mask) == m) 120 | { 121 | rois[std::to_string(idx - 1)].push_back(int_point(x, y)); 122 | } 123 | m = m << 1; 124 | } 125 | 126 | } 127 | i++; 128 | } 129 | } 130 | } 131 | else 132 | { 133 | return false; 134 | } 135 | 136 | } 137 | catch (const std::ios_base::failure& e) 138 | { 139 | logE << "Caught an ios_base::failure.\n" 140 | << "Explanatory string: " << e.what() << '\n' 141 | << "Error code: " << e.code() << '\n'; 142 | return false; 143 | } 144 | return true; 145 | 146 | } 147 | 148 | 149 | 150 | 151 | 152 | } //end namespace aps 153 | } //end namespace file 154 | }// end namespace io 155 | -------------------------------------------------------------------------------- /src/fitting/routines/param_optimized_fit_routine.h: -------------------------------------------------------------------------------- 1 | /*** 2 | Copyright (c) 2016, UChicago Argonne, LLC. All rights reserved. 3 | 4 | Copyright 2016. UChicago Argonne, LLC. This software was produced 5 | under U.S. Government contract DE-AC02-06CH11357 for Argonne National 6 | Laboratory (ANL), which is operated by UChicago Argonne, LLC for the 7 | U.S. Department of Energy. The U.S. Government has rights to use, 8 | reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR 9 | UChicago Argonne, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 10 | ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is 11 | modified to produce derivative works, such modified software should 12 | be clearly marked, so as not to confuse it with the version available 13 | from ANL. 14 | 15 | Additionally, redistribution and use in source and binary forms, with 16 | or without modification, are permitted provided that the following 17 | conditions are met: 18 | 19 | * Redistributions of source code must retain the above copyright 20 | notice, this list of conditions and the following disclaimer. 21 | 22 | * Redistributions in binary form must reproduce the above copyright 23 | notice, this list of conditions and the following disclaimer in 24 | the documentation and/or other materials provided with the 25 | distribution. 26 | 27 | * Neither the name of UChicago Argonne, LLC, Argonne National 28 | Laboratory, ANL, the U.S. Government, nor the names of its 29 | contributors may be used to endorse or promote products derived 30 | from this software without specific prior written permission. 31 | 32 | THIS SOFTWARE IS PROVIDED BY UChicago Argonne, LLC AND CONTRIBUTORS 33 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 34 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 35 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UChicago 36 | Argonne, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 37 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 38 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 39 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 40 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 41 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 42 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | ***/ 45 | 46 | /// Initial Author <2016>: Arthur Glowacki 47 | 48 | 49 | 50 | #ifndef Param_Optimized_Fit_Routine_H 51 | #define Param_Optimized_Fit_Routine_H 52 | 53 | #include "fitting/routines/base_fit_routine.h" 54 | #include "fitting/optimizers/optimizer.h" 55 | #include "data_struct/fit_parameters.h" 56 | 57 | namespace fitting 58 | { 59 | namespace routines 60 | { 61 | 62 | using namespace data_struct; 63 | using namespace fitting::optimizers; 64 | 65 | template 66 | class DLL_EXPORT Param_Optimized_Fit_Routine: public Base_Fit_Routine 67 | { 68 | public: 69 | Param_Optimized_Fit_Routine(); 70 | 71 | virtual ~Param_Optimized_Fit_Routine(); 72 | 73 | virtual OPTIMIZER_OUTCOME fit_spectra(const models::Base_Model* const model, 74 | const Spectra* const spectra, 75 | const Fit_Element_Map_Dict* const elements_to_fit, 76 | std::unordered_map& out_counts); 77 | 78 | virtual OPTIMIZER_OUTCOME fit_spectra_parameters(const models::Base_Model* const model, 79 | const Spectra* const spectra, 80 | const Fit_Element_Map_Dict* const elements_to_fit, 81 | bool use_weights, 82 | Fit_Parameters& out_fit_params, 83 | Callback_Func_Status_Def* status_callback = nullptr); 84 | 85 | virtual std::string get_name() { return STR_FIT_GAUSS_TAILS; } 86 | 87 | virtual void initialize(models::Base_Model* const model, 88 | const Fit_Element_Map_Dict* const elements_to_fit, 89 | const struct Range energy_range, 90 | ArrayTr* custom_background); 91 | 92 | void set_optimizer(Optimizer *optimizer); 93 | 94 | void set_update_coherent_amplitude_on_fit(bool val) {_update_coherent_amplitude_on_fit = val;} 95 | 96 | const Range& energy_range() { return _energy_range; } 97 | 98 | protected: 99 | 100 | void _add_elements_to_fit_parameters(Fit_Parameters* fit_params, 101 | const Spectra* const spectra, 102 | const Fit_Element_Map_Dict* const elements_to_fit); 103 | 104 | void _calc_and_update_coherent_amplitude(Fit_Parameters* fitp, 105 | const Spectra* const spectra); 106 | 107 | Optimizer* _optimizer; 108 | 109 | Range _energy_range; 110 | 111 | ArrayTr * _custom_background; 112 | 113 | bool _update_coherent_amplitude_on_fit; 114 | 115 | private: 116 | 117 | 118 | }; 119 | 120 | } //namespace routines 121 | 122 | } //namespace fitting 123 | 124 | #endif // Param_Optimized_Fit_Routine_H 125 | -------------------------------------------------------------------------------- /src/data_struct/element_quant.h: -------------------------------------------------------------------------------- 1 | /*** 2 | Copyright (c) 2016, UChicago Argonne, LLC. All rights reserved. 3 | 4 | Copyright 2016. UChicago Argonne, LLC. This software was produced 5 | under U.S. Government contract DE-AC02-06CH11357 for Argonne National 6 | Laboratory (ANL), which is operated by UChicago Argonne, LLC for the 7 | U.S. Department of Energy. The U.S. Government has rights to use, 8 | reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR 9 | UChicago Argonne, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 10 | ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is 11 | modified to produce derivative works, such modified software should 12 | be clearly marked, so as not to confuse it with the version available 13 | from ANL. 14 | 15 | Additionally, redistribution and use in source and binary forms, with 16 | or without modification, are permitted provided that the following 17 | conditions are met: 18 | 19 | * Redistributions of source code must retain the above copyright 20 | notice, this list of conditions and the following disclaimer. 21 | 22 | * Redistributions in binary form must reproduce the above copyright 23 | notice, this list of conditions and the following disclaimer in 24 | the documentation and/or other materials provided with the 25 | distribution. 26 | 27 | * Neither the name of UChicago Argonne, LLC, Argonne National 28 | Laboratory, ANL, the U.S. Government, nor the names of its 29 | contributors may be used to endorse or promote products derived 30 | from this software without specific prior written permission. 31 | 32 | THIS SOFTWARE IS PROVIDED BY UChicago Argonne, LLC AND CONTRIBUTORS 33 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 34 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 35 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UChicago 36 | Argonne, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 37 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 38 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 39 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 40 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 41 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 42 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | ***/ 45 | 46 | /// Initial Author <2016>: Arthur Glowacki 47 | 48 | 49 | 50 | #ifndef Element_Quant_H 51 | #define Element_Quant_H 52 | 53 | #include "core/defines.h" 54 | #include 55 | 56 | namespace data_struct 57 | { 58 | 59 | //----------------------------------------------------------------------------- 60 | 61 | template 62 | struct DLL_EXPORT Element_Quant 63 | { 64 | Element_Quant() 65 | { 66 | zero(); 67 | } 68 | 69 | Element_Quant(int Z) 70 | { 71 | zero(); 72 | this->Z = Z; 73 | } 74 | 75 | Element_Quant(const Element_Quant& e) : 76 | weight(e.weight), 77 | absorption(e.absorption), 78 | transmission_Be(e.transmission_Be), 79 | transmission_Ge(e.transmission_Ge), 80 | yield(e.yield), 81 | transmission_through_Si_detector(e.transmission_through_Si_detector), 82 | transmission_through_air(e.transmission_through_air), 83 | Z(e.Z), 84 | e_cal_ratio(e.e_cal_ratio), 85 | calib_curve_val(e.calib_curve_val), 86 | name(e.name) 87 | { 88 | } 89 | 90 | Element_Quant(Element_Quant&& e) noexcept: 91 | weight(std::exchange(e.weight, 0.0)), 92 | absorption(std::exchange(e.absorption, 0.0)), 93 | transmission_Be(std::exchange(e.transmission_Be, 0.0)), 94 | transmission_Ge(std::exchange(e.transmission_Ge, 0.0)), 95 | yield(std::exchange(e.yield, 0.0)), 96 | transmission_through_Si_detector(std::exchange(e.transmission_through_Si_detector, 0.0)), 97 | transmission_through_air(std::exchange(e.transmission_through_air, 0.0)), 98 | Z(std::exchange(e.Z, 0)), 99 | e_cal_ratio(std::exchange(e.e_cal_ratio, 0.0)), 100 | calib_curve_val(std::exchange(e.calib_curve_val, 0.0)), 101 | name(std::move(e.name)) 102 | { 103 | } 104 | 105 | Element_Quant& operator=(const Element_Quant&) = default; 106 | 107 | void zero() 108 | { 109 | weight = 0.0; 110 | absorption = 0.0; 111 | transmission_Be = 0.0; 112 | transmission_Ge = 0.0; // or Si dead layer 113 | yield = 0.0; 114 | transmission_through_Si_detector = 0.0; 115 | transmission_through_air = 0.0;// (N2) 116 | e_cal_ratio = 0.0; 117 | Z = 0; 118 | name = ""; 119 | calib_curve_val = 0; 120 | } 121 | 122 | T_real weight; // in ug/cm2 123 | T_real absorption; 124 | T_real transmission_Be; 125 | T_real transmission_Ge; // or Si dead layer 126 | T_real yield; 127 | T_real transmission_through_Si_detector; 128 | T_real transmission_through_air;// (N2) 129 | int Z; 130 | T_real e_cal_ratio; 131 | T_real calib_curve_val; 132 | std::string name; 133 | 134 | }; 135 | 136 | TEMPLATE_STRUCT_DLL_EXPORT Element_Quant; 137 | TEMPLATE_STRUCT_DLL_EXPORT Element_Quant; 138 | 139 | //----------------------------------------------------------------------------- 140 | 141 | } //namespace data_struct 142 | 143 | #endif // Element_Quant_H 144 | -------------------------------------------------------------------------------- /src/workflow/xrf/spectra_stream_saver.h: -------------------------------------------------------------------------------- 1 | /*** 2 | Copyright (c) 2016, UChicago Argonne, LLC. All rights reserved. 3 | 4 | Copyright 2016. UChicago Argonne, LLC. This software was produced 5 | under U.S. Government contract DE-AC02-06CH11357 for Argonne National 6 | Laboratory (ANL), which is operated by UChicago Argonne, LLC for the 7 | U.S. Department of Energy. The U.S. Government has rights to use, 8 | reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR 9 | UChicago Argonne, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 10 | ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is 11 | modified to produce derivative works, such modified software should 12 | be clearly marked, so as not to confuse it with the version available 13 | from ANL. 14 | 15 | Additionally, redistribution and use in source and binary forms, with 16 | or without modification, are permitted provided that the following 17 | conditions are met: 18 | 19 | * Redistributions of source code must retain the above copyright 20 | notice, this list of conditions and the following disclaimer. 21 | 22 | * Redistributions in binary form must reproduce the above copyright 23 | notice, this list of conditions and the following disclaimer in 24 | the documentation and/or other materials provided with the 25 | distribution. 26 | 27 | * Neither the name of UChicago Argonne, LLC, Argonne National 28 | Laboratory, ANL, the U.S. Government, nor the names of its 29 | contributors may be used to endorse or promote products derived 30 | from this software without specific prior written permission. 31 | 32 | THIS SOFTWARE IS PROVIDED BY UChicago Argonne, LLC AND CONTRIBUTORS 33 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 34 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 35 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UChicago 36 | Argonne, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 37 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 38 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 39 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 40 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 41 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 42 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | ***/ 45 | 46 | /// Initial Author <2017>: Arthur Glowacki 47 | 48 | 49 | 50 | #ifndef Spectra_Stream_Saver_H 51 | #define Spectra_Stream_Saver_H 52 | 53 | #include "core/defines.h" 54 | 55 | #include "workflow/sink.h" 56 | #include "data_struct/stream_block.h" 57 | #include "io/file/mda_io.h" 58 | #include "io/file/hdf5_io.h" 59 | #include 60 | 61 | namespace workflow 62 | { 63 | namespace xrf 64 | { 65 | 66 | //----------------------------------------------------------------------------- 67 | template 68 | class DLL_EXPORT Spectra_Stream_Saver : public Sink* > 69 | { 70 | 71 | public: 72 | 73 | Spectra_Stream_Saver(); 74 | 75 | virtual ~Spectra_Stream_Saver(); 76 | 77 | //void save_stream(data_struct::Stream_Block* stream_block); 78 | 79 | virtual void set_function([[maybe_unused]] std::function*)> func) { } 80 | 81 | protected: 82 | 83 | class Detector_Save 84 | { 85 | public: 86 | Detector_Save(size_t width) 87 | { 88 | last_row = -1; 89 | spectra_line.resize(width); 90 | for(size_t i=0;i integrated_spectra; 102 | std::vector< data_struct::Spectra* > spectra_line; 103 | }; 104 | 105 | class Dataset_Save 106 | { 107 | public: 108 | Dataset_Save(){} 109 | ~Dataset_Save() 110 | { 111 | if (dataset_directory != nullptr) 112 | { 113 | delete dataset_directory; 114 | } 115 | dataset_directory = nullptr; 116 | if (dataset_name != nullptr) 117 | { 118 | delete dataset_name; 119 | } 120 | dataset_name = nullptr; 121 | for(auto& itr : detector_map) 122 | { 123 | if (itr.second != nullptr) 124 | { 125 | delete itr.second; 126 | } 127 | } 128 | detector_map.clear(); 129 | } 130 | 131 | std::string *dataset_directory; 132 | std::string *dataset_name; 133 | //by detector_num 134 | std::map detector_map; 135 | }; 136 | 137 | void _new_dataset(size_t d_hash, data_struct::Stream_Block* stream_block); 138 | 139 | void _new_detector(Dataset_Save *dataset, data_struct::Stream_Block* stream_block); 140 | 141 | //void _finalize_dataset(Dataset_Save *dataset); 142 | 143 | //by detector_dir + dataset hash 144 | std::map _dataset_map; 145 | 146 | }; 147 | 148 | //----------------------------------------------------------------------------- 149 | 150 | } //namespace xrf 151 | } //namespace workflow 152 | 153 | #endif // Spectra_Stream_Saver_H 154 | -------------------------------------------------------------------------------- /src/io/file/netcdf_io.h: -------------------------------------------------------------------------------- 1 | /*** 2 | Copyright (c) 2016, UChicago Argonne, LLC. All rights reserved. 3 | 4 | Copyright 2016. UChicago Argonne, LLC. This software was produced 5 | under U.S. Government contract DE-AC02-06CH11357 for Argonne National 6 | Laboratory (ANL), which is operated by UChicago Argonne, LLC for the 7 | U.S. Department of Energy. The U.S. Government has rights to use, 8 | reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR 9 | UChicago Argonne, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 10 | ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is 11 | modified to produce derivative works, such modified software should 12 | be clearly marked, so as not to confuse it with the version available 13 | from ANL. 14 | 15 | Additionally, redistribution and use in source and binary forms, with 16 | or without modification, are permitted provided that the following 17 | conditions are met: 18 | 19 | * Redistributions of source code must retain the above copyright 20 | notice, this list of conditions and the following disclaimer. 21 | 22 | * Redistributions in binary form must reproduce the above copyright 23 | notice, this list of conditions and the following disclaimer in 24 | the documentation and/or other materials provided with the 25 | distribution. 26 | 27 | * Neither the name of UChicago Argonne, LLC, Argonne National 28 | Laboratory, ANL, the U.S. Government, nor the names of its 29 | contributors may be used to endorse or promote products derived 30 | from this software without specific prior written permission. 31 | 32 | THIS SOFTWARE IS PROVIDED BY UChicago Argonne, LLC AND CONTRIBUTORS 33 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 34 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 35 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UChicago 36 | Argonne, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 37 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 38 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 39 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 40 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 41 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 42 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | ***/ 45 | 46 | /// Initial Author <2016>: Arthur Glowacki 47 | 48 | 49 | 50 | #ifndef NetCDF_IO_H 51 | #define NetCDF_IO_H 52 | 53 | #include "data_struct/spectra_volume.h" 54 | #include "data_struct/params_override.h" 55 | #include 56 | #include 57 | 58 | namespace io 59 | { 60 | namespace file 61 | { 62 | 63 | enum class E_load_type { LINE = 0, CALLBACKF = 1, INTEGRATED = 2 }; 64 | 65 | template 66 | class DLL_EXPORT NetCDF_IO 67 | { 68 | public: 69 | 70 | static NetCDF_IO* inst(); 71 | 72 | ~NetCDF_IO() {}; 73 | 74 | /** 75 | * @brief load_spectra_line 76 | * @param path 77 | * @param detector 78 | * @param spec_line 79 | * @return the number of spectra loaded. 0 if fail. 80 | */ 81 | size_t load_spectra_line(const std::string& path, size_t detector, data_struct::Spectra_Line* spec_line); 82 | 83 | bool load_spectra_line_with_callback(const std::string& path, 84 | const std::vector& detector_num_arr, 85 | int row, 86 | size_t max_rows, 87 | size_t max_cols, 88 | data_struct::IO_Callback_Func_Def callback_fun, 89 | void* user_data); 90 | 91 | size_t load_spectra_line_integrated(const std::string& path, size_t detector, size_t line_size, data_struct::Spectra* spectra); 92 | 93 | // tetramm scalers netcdf file 94 | size_t load_scalers_line(const std::string& path, std::string tag, size_t row, data_struct::Scan_Info* scan_info, data_struct::Params_Override * params_override); 95 | 96 | private: 97 | NetCDF_IO(); 98 | 99 | int _nc_get_vars_real(int ncid, int varid, const size_t* startp, const size_t* countp, const ptrdiff_t* stridep, T_real* ip) 100 | { 101 | if (std::is_same::value) 102 | { 103 | return nc_get_vars_float(ncid, varid, startp, countp, stridep, (float*)ip); 104 | } 105 | else if (std::is_same::value) 106 | { 107 | return nc_get_vars_double(ncid, varid, startp, countp, stridep, (double*)ip); 108 | } 109 | 110 | return -1; 111 | 112 | } 113 | 114 | size_t _load_spectra(E_load_type ltype, 115 | const std::string& path, 116 | size_t detector, 117 | data_struct::Spectra_Line* spec_line, 118 | size_t line_size, 119 | data_struct::Spectra* spectra, 120 | size_t cur_row, 121 | size_t max_rows, 122 | data_struct::IO_Callback_Func_Def *callback_fun, 123 | void* user_data); 124 | 125 | static NetCDF_IO *_this_inst; 126 | 127 | static std::mutex _mutex; 128 | 129 | T_real _data_in[1][1][1050000]; 130 | 131 | }; 132 | 133 | }// end namespace file 134 | }// end namespace io 135 | 136 | #endif // NetCDF_IO_H 137 | -------------------------------------------------------------------------------- /src/support/mdautils-1.4.1/Changelog.txt: -------------------------------------------------------------------------------- 1 | MDA Utilities Version Changelog 2 | 3 | 4 | From 1.4.0 to 1.4.1 5 | 6 | mda2ascii: 7 | Changed way scan tree is traversed for multidimensional files. 8 | Instead of trusting the header dimensions array for scan sizes, 9 | use the sizes in the scans themselves. Allows correct conversion 10 | for irregular files, or files that have bad values in the 11 | dimensions array (technically the file is damaged then). 12 | mda-info: 13 | Simply state that a scan is irregular, as previous output was 14 | misleading. 15 | 16 | 17 | From 1.3.1 to 1.4.0 18 | 19 | mda-load library: 20 | Added mda_check(), to have an easy way to check the validity of a 21 | file. Added mda_update() function that will load an updated MDA 22 | file, attempting to use the previously loaded and supplied MDA 23 | data. Completed error handling, made sure to release all memory on 24 | error. Check for MDA file structural errors (like negative number 25 | of positioners). 26 | mda-ls: 27 | Enabled entire file checking by default, allow this to be turned off 28 | with -s switch. 29 | mda-info: 30 | Enabled entire file checking by default, allow this to be turned off 31 | with -s switch. 32 | 33 | 34 | From 1.3.0 to 1.3.1 35 | 36 | mda-load library: 37 | Added another check for corrupted files. 38 | mda2ascii: 39 | When processing multiple files, the program will now skip an 40 | invalid file instead of stopping execution. 41 | mda-ls: 42 | The program will no longer halt when it encounters an invalid 43 | file. 44 | xdr_hack: 45 | To help Windows users, added code for faking enough of the XDR 46 | routines that are needed for decoding the MDA format (which 47 | Windows lacks). This code should NOT be used if there is native 48 | support, and has to be manually enabled in the Makefile. There is 49 | support for both big- and little-endian systems. 50 | 51 | 52 | From 1.2.2 to 1.3.0 53 | 54 | mda-load library: 55 | Added another check for corrupted files. 56 | mda2ascii: 57 | Refactored the code behind -f option to be more efficient. 58 | mdatree2ascii 59 | Added new script utility for converting entire directory trees of 60 | files into new corresponding trees containing the output. 61 | 62 | 63 | From 1.2.1 to 1.2.2 64 | 65 | mda-load library: 66 | Fixed a bug that would cause an MDA file to not load if there was 67 | an Extra PV that was of the char type. Also added preprocessor 68 | commands to mda-load.h in order to make the library C++ compatible 69 | (Michael Hu). 70 | 71 | 72 | From 1.2 to 1.2.1 73 | 74 | mda2ascii: 75 | There was a bug when using the -f flag, which can cause a 76 | positioner column to show a printf format instead of the data 77 | (it's fairly obvious when this does happen). This only occurred 78 | when the all the values for a positioner were integers. 79 | mda-ls, mda-info, and mda2ascii: 80 | Many instances of repetitive deep pointer dereferencing were 81 | removed from the code. It makes the code slightly faster, and also 82 | easier to understand. 83 | Makefile: 84 | Added DESTDIR variable for making distribution packages simpler 85 | (J. Lewis Muir). 86 | Documentation: 87 | Added Changelog.txt file. Fixed typos in various files (some from 88 | J. Lewis Muir). 89 | 90 | 91 | From 1.1 to 1.2 92 | 93 | mda-load library: 94 | Changed from generic int types to fixed length int types, as it is 95 | more portable in the long term, and fixes problems with MacOS 96 | compiling. Look for occasional over-allocations of memory for 97 | strings (which tend to be severe, but don't cause failures) and 98 | then reduce memory consumption. Remove warning when building on 99 | MacOS (J. Lewis Muir). 100 | mda-dump: 101 | Fixed the behavior of not releasing memory allocated for strings; 102 | this is not a critical issue, it just lets the program run with an 103 | even smaller memory footprint. 104 | Makefile: 105 | Fixed the install option, especially regarding documentation 106 | (J. Lewis Muir). Added detection of MacOS X to work around 107 | missing xdr function. 108 | 109 | 110 | From 1.0 to 1.1 111 | 112 | mda2ascii: 113 | Added option to print out all existing scans in a file, even if 114 | they are incomplete due to an abort of the scan, and marks them. 115 | mda-dump: 116 | Shows the offset of scans as they are read, as well as the offset 117 | of extra PV information. 118 | mda-info: 119 | Shows the saveData numbering in parentheses for detectors, 120 | positioners, and triggers. 121 | mda-load library: 122 | Added check for a certain type of corrupt MDA file, leading to 123 | fewer crashes of the utilities. 124 | Makefile: 125 | Added install option. 126 | 127 | 128 | From 0.3 to 1.0: 129 | 130 | mda2ascii: 131 | New options created, such as create scan files for scan dimensions 132 | higher than 1, output a friendlier representation of the data (at 133 | the expense of a larger file), and put extra PV information in a 134 | separate file. 135 | mda-dump: 136 | Rewritten to display data immediately as it is read to help track 137 | file errors. 138 | mda-info: 139 | Now shows all the information on positioners, detectors, and 140 | triggers. 141 | mda-ls: 142 | New utility that gives a brief description of the scans contained 143 | in MDA files in a directory. 144 | mda-load library: 145 | Memory leaks fixed, functions added for loading parts of an MDA 146 | file as needed. 147 | 148 | -------------------------------------------------------------------------------- /src/data_struct/detector.h: -------------------------------------------------------------------------------- 1 | /*** 2 | Copyright (c) 2016, UChicago Argonne, LLC. All rights reserved. 3 | 4 | Copyright 2016. UChicago Argonne, LLC. This software was produced 5 | under U.S. Government contract DE-AC02-06CH11357 for Argonne National 6 | Laboratory (ANL), which is operated by UChicago Argonne, LLC for the 7 | U.S. Department of Energy. The U.S. Government has rights to use, 8 | reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR 9 | UChicago Argonne, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 10 | ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is 11 | modified to produce derivative works, such modified software should 12 | be clearly marked, so as not to confuse it with the version available 13 | from ANL. 14 | 15 | Additionally, redistribution and use in source and binary forms, with 16 | or without modification, are permitted provided that the following 17 | conditions are met: 18 | 19 | * Redistributions of source code must retain the above copyright 20 | notice, this list of conditions and the following disclaimer. 21 | 22 | * Redistributions in binary form must reproduce the above copyright 23 | notice, this list of conditions and the following disclaimer in 24 | the documentation and/or other materials provided with the 25 | distribution. 26 | 27 | * Neither the name of UChicago Argonne, LLC, Argonne National 28 | Laboratory, ANL, the U.S. Government, nor the names of its 29 | contributors may be used to endorse or promote products derived 30 | from this software without specific prior written permission. 31 | 32 | THIS SOFTWARE IS PROVIDED BY UChicago Argonne, LLC AND CONTRIBUTORS 33 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 34 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 35 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UChicago 36 | Argonne, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 37 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 38 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 39 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 40 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 41 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 42 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | ***/ 45 | 46 | /// Initial Author <2017>: Arthur Glowacki 47 | 48 | 49 | 50 | #ifndef DETECTOR_H 51 | #define DETECTOR_H 52 | 53 | #include "core/defines.h" 54 | #include "data_struct/element_info.h" 55 | #include "fitting/routines/base_fit_routine.h" 56 | #include 57 | #include 58 | #include "data_struct/quantification_standard.h" 59 | #include "data_struct/params_override.h" 60 | #include "fitting/optimizers/optimizer.h" 61 | 62 | namespace data_struct 63 | { 64 | 65 | 66 | //----------------------------------------------------------------------------- 67 | 68 | /// 69 | /// \brief The Detector class 70 | /// 71 | template 72 | class DLL_EXPORT Detector 73 | { 74 | public: 75 | Detector(unsigned int detector_num = -1); 76 | 77 | ~Detector(); 78 | 79 | void append_element(Fitting_Routines routine, std::string name, std::string quant_scaler, T_real weight); 80 | 81 | void update_element_quants(Fitting_Routines routine, 82 | std::string quantifier_scaler, 83 | Quantification_Standard* standard, 84 | Quantification_Model* quantification_model, 85 | T_real ic_quantifier); 86 | 87 | void avg_element_quants(Fitting_Routines routine, 88 | std::string quantifier_scaler, 89 | std::unordered_map& element_amt_dict); 90 | 91 | void update_calibration_curve(Fitting_Routines routine, 92 | std::string quantifier_scaler, 93 | Quantification_Model* quantification_model, 94 | T_real val); 95 | 96 | void update_from_fit_paramseters(); 97 | 98 | void generage_avg_quantification_scalers(); 99 | 100 | unsigned int number() { return _number; } 101 | 102 | // Fitting routines map 103 | std::unordered_map *> fit_routines; 104 | 105 | // Fitting model 106 | fitting::models::Base_Model* model; 107 | 108 | // Quantification 109 | std::map> quantification_standards; 110 | 111 | std::unordered_map > fitting_quant_map; 112 | 113 | // proc_type quantifier element quant_prop 114 | std::map*>>> all_element_quants; 115 | 116 | // Fit Parameters Override for model 117 | Params_Override fit_params_override_dict; 118 | 119 | T_real beryllium_window_thickness; 120 | T_real germanium_dead_layer; 121 | T_real detector_chip_thickness; 122 | T_real incident_energy; 123 | T_real airpath; 124 | data_struct::Element_Info* detector_element; 125 | 126 | // SR_CURRENT, US_IC, DS_IC : average if we have multiple standards 127 | std::unordered_map avg_quantification_scaler_map; 128 | 129 | private: 130 | unsigned int _number; 131 | 132 | }; 133 | 134 | } //namespace data_struct 135 | 136 | #endif // DETECTOR_H 137 | --------------------------------------------------------------------------------