diff --git a/.github/workflows/build_documentation.yml b/.github/workflows/build_documentation.yml index a7fd764c4..be3dc4a62 100644 --- a/.github/workflows/build_documentation.yml +++ b/.github/workflows/build_documentation.yml @@ -64,7 +64,7 @@ jobs: cache: 'pip' - name: Install Python Packages - run: pip install sphinx sphinx_rtd_theme breathe pyyaml jinja2 + run: pip install sphinx sphinx_rtd_theme breathe pyyaml jinja2 numpy - name: Build Documentation diff --git a/RELEASE.md b/RELEASE.md index 927793b37..0f1ad4af4 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -41,6 +41,8 @@ Detector.pattern (python) accepts also a pattern object, not only a pattern file added patternstart to python (ctb, xilinx_ctb , mythen3), only the detector class api was exposed (startPattern()) +removed unused function readDataFile/writeDataFile from file_utils.h + 2 On-board Detector Server Compatibility ========================================== diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt index 129ed8e69..25e313d7c 100644 --- a/docs/CMakeLists.txt +++ b/docs/CMakeLists.txt @@ -36,6 +36,7 @@ set(SPHINX_SOURCE_FILES src/consuming.rst src/dependencies.rst src/detector.rst + src/pyctb.rst src/index.rst src/installation.rst src/pydetector.rst @@ -72,6 +73,8 @@ set(SPHINX_SOURCE_FILES src/softwarearchitecture.rst src/configcommands.rst src/Versioning.rst + src/Testing.rst + src/pypower.rst ) foreach(filename ${SPHINX_SOURCE_FILES}) @@ -105,7 +108,7 @@ add_custom_target(docs gendoc COMMAND python gen_server_doc.py COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT} - COMMAND ${SPHINX_EXECUTABLE} -a -b html + COMMAND ${SPHINX_EXECUTABLE} -W -a -b html -Dbreathe_projects.slsDetectorPackage=${CMAKE_CURRENT_BINARY_DIR}/xml -c "${SPHINX_BUILD}" ${SPHINX_BUILD}/src @@ -113,7 +116,7 @@ add_custom_target(docs COMMENT "Generating documentation with Sphinx") add_custom_target(rst - COMMAND ${SPHINX_EXECUTABLE} -a -b html + COMMAND ${SPHINX_EXECUTABLE} -W -a -b html -Dbreathe_projects.slsDetectorPackage=${CMAKE_CURRENT_BINARY_DIR}/xml -c "${SPHINX_BUILD}" ${SPHINX_BUILD}/src diff --git a/docs/conf.py.in b/docs/conf.py.in index 374fc84e0..827d2528c 100644 --- a/docs/conf.py.in +++ b/docs/conf.py.in @@ -48,6 +48,8 @@ templates_path = ['_templates'] # This pattern also affects html_static_path and html_extra_path. exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] +suppress_warnings = ["duplicate_declaration.cpp",] + # -- Options for HTML output ------------------------------------------------- diff --git a/docs/src/Testing.rst b/docs/src/Testing.rst index ad67326d8..99dd202da 100644 --- a/docs/src/Testing.rst +++ b/docs/src/Testing.rst @@ -67,12 +67,14 @@ This runs all tests marked with the tag ``[.detectorintegration]`` for all detec If you want to run them for a specific virtual detector or a specific test use the following command: .. code-block:: console + cd build python bin/test_simulators.py --servers jungfrau --test "[dacs]" You can exclude specific tests by adding the option ``~[]``. Again, we assume that this marker is added to the tests that you want to exclude. .. code-block:: console + cd build python bin/test_simulators.py --servers eiger jungfrau moench --test "[detectorintegration]~[disable_check_data_file]" @@ -98,6 +100,7 @@ If a test requires a detector mark them with the pytest marker ``@pytest.mark.de To run only tests requiring virtual detectors use the following command: .. code-block:: console + #in build python -m pytest -m detectorintegration ../python/tests/ diff --git a/docs/src/dependencies.rst b/docs/src/dependencies.rst index a64d7a219..3e0e7b364 100644 --- a/docs/src/dependencies.rst +++ b/docs/src/dependencies.rst @@ -53,9 +53,9 @@ To build the python module the following dependencies are needed: Refer :ref:`pybind11 notes. ` -------------------------------- +------------------------------------ Dependencies to build documentation -------------------------------- +------------------------------------ To build this documentation that you are reading now the following dependencies are needed: @@ -76,7 +76,7 @@ To build the GUI the following dependencies are needed: Qwt is bundled in libs. One does not need to pre-install it on the system. ------------------------------------------------------- +----------------------------------------------------- Dependencies to build Moench and Jungfrau executables ----------------------------------------------------- diff --git a/docs/src/gendoc.cpp b/docs/src/gendoc.cpp index 2854f6d22..156d04c9b 100644 --- a/docs/src/gendoc.cpp +++ b/docs/src/gendoc.cpp @@ -45,13 +45,16 @@ int main() { for (const auto &cmd : commands) { std::ostringstream os; - std::cout << cmd << '\n'; caller.call(cmd, {}, -1, slsDetectorDefs::HELP_ACTION, os); auto tmp = os.str().erase(0, cmd.size()); auto usage = tmp.substr(0, tmp.find_first_of('\n')); tmp.erase(0, usage.size()); auto help = replace_all(tmp, "\n\t", "\n\t\t| "); + + if (help.back() != '\n') { + help.push_back('\n'); + } fs << '\t' << cmd << usage << help << "\n"; } diff --git a/docs/src/index.rst b/docs/src/index.rst index 035167215..498543384 100644 --- a/docs/src/index.rst +++ b/docs/src/index.rst @@ -48,7 +48,9 @@ slsDetectorPackage pygettingstarted pydetector + pyctb pyenums + pypower pyexamples pyPatternGenerator pattern diff --git a/docs/src/pyctb.rst b/docs/src/pyctb.rst new file mode 100644 index 000000000..a942d253f --- /dev/null +++ b/docs/src/pyctb.rst @@ -0,0 +1,15 @@ +Ctb +===================================================== + +.. py:currentmodule:: slsdet + +.. autoclass:: Ctb + :members: + :undoc-members: + :show-inheritance: + :inherited-members: + + + + + diff --git a/docs/src/pypower.rst b/docs/src/pypower.rst new file mode 100644 index 000000000..095edf637 --- /dev/null +++ b/docs/src/pypower.rst @@ -0,0 +1,12 @@ +Power Supply +=============== + +Helper class to control power supplies on the Chip Test Board (CTB, Xilinx CTB). + +.. py:currentmodule:: slsdet + +.. autoclass:: Power + :members: + :undoc-members: + :show-inheritance: + :inherited-members: \ No newline at end of file diff --git a/patternGenerator/deserializer.cpp b/patternGenerator/deserializer.cpp deleted file mode 100644 index a77fe1077..000000000 --- a/patternGenerator/deserializer.cpp +++ /dev/null @@ -1,110 +0,0 @@ -// SPDX-License-Identifier: LGPL-3.0-or-other -// Copyright (C) 2021 Contributors to the SLS Detector Package - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -int main(int argc, char *argv[]) { - - int iarg; - char fname[10000]; - uint64_t word; - int val[64]; - int bit[64]; - FILE *fdin; - - int nb = 2; - int off = 0; - int ioff = 0; - int dr = 24; - int idr = 0; - int ib = 0; - int iw = 0; - bit[0] = 19; - bit[1] = 8; - // for (iarg=0; iarg 2) - dr = atoi(argv[2]); - if (argc > 3) - off = atoi(argv[3]); - if (argc > 4) { - for (ib = 0; ib < 64; ib++) { - if (argc > 4 + ib) { - bit[ib] = atoi(argv[4 + ib]); - nb++; - } - } - } - - idr = 0; - for (ib = 0; ib < nb; ib++) { - val[ib] = 0; - } - - fdin = fopen(argv[1], "rb"); - if (fdin == NULL) { - printf("Cannot open input file %s for reading\n", argv[1]); - return 200; - } - - while (fread((void *)&word, 8, 1, fdin)) { - // printf("%llx\n",word); - if (ioff < off) - ioff++; - else { - - for (ib = 0; ib < nb; ib++) { - if (word & (1 << bit[ib])) - val[ib] |= (1 << idr); - } - idr++; - if (idr == dr) { - idr = 0; - fprintf(stdout, "%d\t", iw++); - for (ib = 0; ib < nb; ib++) { -#ifdef HEX - fprintf(stdout, "%08llx\t", val[ib]); -#else - fprintf(stdout, "%lld\t", val[ib]); - -#endif - - val[ib] = 0; - } - fprintf(stdout, "\n"); - } - } - } - if (idr != 0) { - fprintf(stdout, "%d\t", iw++); - for (ib = 0; ib < nb; ib++) { -#ifdef HEX - fprintf(stdout, "%08llx\t", val[ib]); -#else - fprintf(stdout, "%lld\t", val[ib]); - -#endif - - val[ib] = 0; - } - fprintf(stdout, "\n"); - } - - fclose(fdin); - - return 0; -} diff --git a/patternGenerator/example_pattern/example_pattern.alias b/patternGenerator/example_pattern/example_pattern.alias deleted file mode 100644 index 9ac446f6d..000000000 --- a/patternGenerator/example_pattern/example_pattern.alias +++ /dev/null @@ -1,4 +0,0 @@ -BIT0 output0 1 -BIT1 output1 1 -BIT2 output2 1 -BIT3 output3 1 \ No newline at end of file diff --git a/patternGenerator/example_pattern/example_pattern.p b/patternGenerator/example_pattern/example_pattern.p deleted file mode 100644 index 809db9456..000000000 --- a/patternGenerator/example_pattern/example_pattern.p +++ /dev/null @@ -1,97 +0,0 @@ -//define signals and directions (Input, outputs, clocks) - - -#define output0 0 -setoutput(output0); - -#define output1 1 -setoutput(output1); - -#define output2 2 -setoutput(output2); - -#define output3 3 -setoutput(output3); - -#define input0 4 -setinput(input0); - -#define input1 5 -setinput(input1); - -#define input2 6 -setinput(input2); - -#define input3 7 -setinput(input3); - - -#define PW pw() -#define SB(x) setbit(x) -#define CB(x) clearbit(x) -#define CLOCK clearbit(CLKBIT); pw();setbit(CLKBIT);pw() -#define LCLOCK clearbit(CLKBIT); pw();setbit(CLKBIT);pw();clearbit(CLKBIT); pw() -#define CLOCKS(x) for (i=0;i -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define MAXLOOPS 6 -#define MAXTIMERS 6 -#define MAXWORDS 8191 - -uint64_t pat = 0; -uint64_t iopat = 0; -uint64_t clkpat = 0; - -unsigned iaddr = 0; -unsigned waitaddr[MAXTIMERS] = {MAXWORDS, MAXWORDS, MAXWORDS, - MAXWORDS, MAXWORDS, MAXWORDS}; -unsigned startloopaddr[MAXLOOPS] = {MAXWORDS, MAXWORDS, MAXWORDS, - MAXWORDS, MAXWORDS, MAXWORDS}; -unsigned stoploopaddr[MAXLOOPS] = {MAXWORDS, MAXWORDS, MAXWORDS, - MAXWORDS, MAXWORDS, MAXWORDS}; -unsigned start = 0, stop = 0; -uint64_t waittime[MAXTIMERS] = {0, 0, 0, 0, 0, 0}; -unsigned nloop[MAXLOOPS] = {0, 0, 0, 0, 0, 0}; - -char infile[10000], outfile[10000]; - -FILE *fd, *fd1; -uint64_t PAT[MAXWORDS]; -int iopat_enable = 0; - -int i, ii, iii, j, jj, jjj, pixx, pixy, memx, memy, muxout, memclk, colclk, - rowclk, muxclk, memcol, memrow, loopcounter; - -void setstart() { start = iaddr; } - -void setstop() { stop = iaddr; } - -void setinput(int bit) { - uint64_t mask = 1; - mask = mask << bit; - iopat &= ~mask; - iopat_enable = 1; -} - -void setoutput(int bit) { - uint64_t mask = 1; - mask = mask << bit; - iopat |= mask; - iopat_enable = 1; -} - -void clearbit(int bit) { - uint64_t mask = 1; - mask = mask << bit; - pat &= ~mask; -} -void setbit(int bit) { - uint64_t mask = 1; - mask = mask << bit; - pat |= mask; -} - -int checkbit(int bit) { - uint64_t mask = 1; - mask = mask << bit; - return (pat & mask) >> bit; -} - -void setstartloop(int iloop) { - if (iloop >= 0 && iloop < MAXLOOPS) { - startloopaddr[iloop] = iaddr; - } -} - -void setstoploop(int iloop) { - if (iloop >= 0 && iloop < MAXLOOPS) { - stoploopaddr[iloop] = iaddr; - } -} - -void setnloop(int iloop, int n) { - if (iloop >= 0 && iloop < MAXLOOPS) { - nloop[iloop] = n; - } -} - -void setwaitpoint(int iloop) { - if (iloop >= 0 && iloop < MAXTIMERS) { - waitaddr[iloop] = iaddr; - } -} - -void setwaittime(int iloop, uint64_t t) { - if (iloop >= 0 && iloop < MAXTIMERS) { - waittime[iloop] = t; - } -} - -void pw() { - if (iaddr < MAXWORDS) { - PAT[iaddr] = pat; - } - fprintf(fd, "patword 0x%04x 0x%016llx\n", iaddr, pat); - iaddr++; - if (iaddr >= MAXWORDS) { - printf("ERROR: too many word in the pattern (%d instead of %d)!", iaddr, - MAXWORDS); - } -} - -int parseCommand(int clk, int cmdbit, int cmd, int length) { - int ibit; - clearbit(clk); - for (ibit = 0; ibit < length; ibit++) { - if (cmd & (1 >> ibit)) { - setbit(cmdbit); - } else { - clearbit(cmdbit); - } - pw(); - /******/ - setbit(clk); - pw(); - /******/ - } -}; - -int main() { - int iloop = 0; - fd = fopen(OUTFILE, "w"); -#include INFILE - - fprintf(fd, "patlimits 0x%04x 0x%04x\n", start, stop); - - if (iopat_enable == 1) { - fprintf(fd, "patioctrl 0x%016llx\n", iopat); - } - - for (iloop = 0; iloop < MAXLOOPS; iloop++) { - if ((startloopaddr[iloop] != MAXWORDS) && - (stoploopaddr[iloop] != MAXWORDS)) { - fprintf(fd, "patloop %d 0x%04x 0x%04x\n", iloop, - startloopaddr[iloop], stoploopaddr[iloop]); - if (stoploopaddr[iloop] <= startloopaddr[iloop]) { - nloop[iloop] = 0; - } - fprintf(fd, "patnloop %d %u\n", iloop, nloop[iloop]); - } - } - - for (iloop = 0; iloop < MAXTIMERS; iloop++) { - if (waitaddr[iloop] != MAXWORDS) { - fprintf(fd, "patwait %d 0x%04x\n", iloop, waitaddr[iloop]); - fprintf(fd, "patwaittime %d %llu\n", iloop, waittime[iloop]); - } - } - - fclose(fd); - fd1 = fopen(OUTFILEBIN, "w"); - fwrite(PAT, sizeof(uint64_t), iaddr, fd1); - fclose(fd1); - - return 0; -} diff --git a/patternGenerator/plotPattern.py b/patternGenerator/plotPattern.py deleted file mode 100755 index 75c0e06b7..000000000 --- a/patternGenerator/plotPattern.py +++ /dev/null @@ -1,610 +0,0 @@ -#!/usr/bin/env python3 - -""" -Created on Wed May 24 09:44:53 2017 - -Plot the pattern for New Chip Test Box (.pat) - -Changes: - - 2017-11-21 Adapt it to python-3 - - 2017-09-25 All can be plotted - - 2017-09-22 Can be plotted but the loop and wait not work yet - -@author: zhang_j1 -""" -import matplotlib.pyplot as plt -from numpy import * -from matplotlib.pyplot import * -from matplotlib.patches import Rectangle -import os -import argparse - -############################################################################### -# COLORS AND LINE STYLES -# alternating colors of the plots (2 needed) -colors_plot = ['tab:blue', 'tab:orange'] - -# Wait colors and line styles (6 needed from 0 to 5) -colors_wait = ['b', 'g', 'r', 'c', 'm', 'y'] -linestyles_wait = ['--', '--', '--', '--', '--', '--'] -alpha_wait = [0.5, 0.5, 0.5, 0.5, 0.5, 0.5] -alpha_wait_rect = [0.2, 0.2, 0.2, 0.2, 0.2, 0.2] - -# Loop colors and line styles (6 needed from 0 to 5) -colors_loop = ['tab:green', 'tab:red', 'tab:purple', 'tab:brown', 'tab:pink', 'tab:grey'] -linestyles_loop = ['-.', '-.', '-.', '-.', '-.', '-.'] -alpha_loop = [0.5, 0.5, 0.5, 0.5, 0.5, 0.5] -alpha_loop_rect = [0.2, 0.2, 0.2, 0.2, 0.2, 0.2] - -# Display the count of clocks -clock_vertical_lines_spacing = 1 -show_clocks_number = True - -############################################################################### - - -# Define a hex to binary function -# global definition -# base = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F] -base = [str(x) for x in range(10)] + [chr(x) for x in range(ord('A'), ord('A')+6)] -# dec2bin - - -def dec2bin(string_num): - num = int(string_num) - mid = [] - while True: - if num == 0: - break - num, rem = divmod(num, 2) - mid.append(base[rem]) - - return ''.join([str(x) for x in mid[::-1]]) - - -# dec2binary: better than dec2bin -def dec2binary(dec_num, width=None): - return binary_repr(int(dec_num), width=width) - - -# hex2dec -def hex2dec(string_num): - return str(int(string_num.upper(), 16)) - - -# hex2bin -def hex2bin(string_num): - return dec2bin(hex2dec(string_num.upper())) - - -# hex2bin -def hex2binary(string_num, width=None): - return dec2binary(hex2dec(string_num.upper()), width=width) - - -parser = argparse.ArgumentParser() - -parser.add_argument('-d', '--directory', required = True, help = "Working directory where the pattern is located") -parser.add_argument('-p', '--pattern', required = True, help = "Pattern name") -parser.add_argument('-a', '--alias', help = "Alias name") -parser.add_argument('-v', '--verbose', action='store_true') - -args = parser.parse_args() - -Folder = args.directory -File_pat = args.pattern -File_alias = args.alias -verbose = args.verbose - -# Look at the alias file and generate the lookup table for pin names -# Create a 64 bit look up table -table = [] -for i in range(64): - # for special bit - if i+1 == 59: - table.append([str(i+1), "external_trigger"]) - elif i+1 == 63: - table.append([str(i+1), "adc_enable"]) - elif i+1 == 62: - table.append([str(i+1), "dbit_enable"]) - else: - table.append([str(i+1), ""]) - -# Loop all lines -try: - with open(Folder + "/" + File_alias + ".alias") as f: - lines = f.readlines() - f.close() - nlines = len(lines) -except: - nlines = 0 - -if nlines > 0: - for i in range(nlines): - # whether the line is bit definition - if lines[i][0:3] == "BIT": - # split words - words = lines[i].split() - bit_num = int(words[0][3:]) - table[bit_num][0] = words[0][3:] - table[bit_num][1] = words[1] -else: - for i in range(64): - table[i][0] = i - table[i][1] = f'BIT#{i}' - -if verbose: - print(table) - -# Load the pattern and get all lines -# Loop all lines -if os.path.exists(Folder + "/" + File_pat + ".pat"): - with open(Folder + "/" + File_pat + ".pat") as f_pat: - lines_pat = f_pat.readlines() -elif os.path.exists(Folder + "/" + File_pat + ".pyat"): - with open(Folder + "/" + File_pat + ".pyat") as f_pat: - lines_pat = f_pat.readlines() -else: - print("No file found - Check it") - exit() -f_pat.close() - -# number of lines for pattern file -nlines_pat = len(lines_pat) -# a counter -cnt = 0 -if verbose: - print("The total number of lines of pattern:", nlines_pat) - -# Loop all lines of pattern -waittime0 = None -waittime1 = None -waittime2 = None -waittime3 = None -waittime4 = None -waittime5 = None - -nloop0 = None -nloop1 = None -nloop2 = None -nloop3 = None -nloop4 = None -nloop5 = None - -for k in range(nlines_pat): - # content of line - words_line = lines_pat[k].split() - if words_line[0] == "patword": - # print words_line from b0 to b63 - bits = hex2binary(words_line[-1], 64)[::-1] - if verbose: - print("The bits for line-", k+1, "is:", bits) - # convert string bits to decimal array - num_bits = array(list(map(str, bits)), dtype="uint16") - if cnt == 0: - mat_pat = num_bits - else: - # add bits to matrix - mat_pat = concatenate((mat_pat, num_bits), axis=0) - cnt = cnt + 1 - # print("The matrix of pattern:", mat_pat.reshape(int(cnt), int(len(num_bits)))) - - # Look at the io: 0 for sending to ASIC, 1 for reading from ASIC - if words_line[0] == "patioctrl": - # print words_line - if verbose: - print(words_line[-1]) - bits = hex2binary(words_line[-1], 64)[::-1] - if verbose: - print(bits) - # convert string bits to decimal array - out_bits = array(list(map(str, bits)), dtype="uint16") - - if verbose: - print(words_line) - # Deal with waiting point - - # ====== WAIT ====== - if words_line[0] == "patwait" and words_line[1] == "0": - wait0 = int(hex2dec(words_line[2])) - if verbose: - print("wait 0 at:", wait0) - if words_line[0] == "patwaittime" and words_line[1] == "0": - waittime0 = int(words_line[2]) - if verbose: - print("wait 0 for:", waittime0) - - if words_line[0] == "patwait" and words_line[1] == "1": - wait1 = int(hex2dec(words_line[2])) - if verbose: - print("wait 1 at:", wait1) - if words_line[0] == "patwaittime" and words_line[1] == "1": - waittime1 = int(words_line[2]) - if verbose: - print("wait 1 for:", waittime1) - - if words_line[0] == "patwait" and words_line[1] == "2": - wait2 = int(hex2dec(words_line[2])) - if verbose: - print("wait 2 at:", wait2) - if words_line[0] == "patwaittime" and words_line[1] == "2": - waittime2 = int(words_line[2]) - if verbose: - print("wait 2 for:", waittime2) - - if words_line[0] == "patwait" and words_line[1] == "3": - wait3 = int(hex2dec(words_line[2])) - if verbose: - print("wait 0 at:", wait3) - if words_line[0] == "patwaittime" and words_line[1] == "3": - waittime3 = int(words_line[2]) - if verbose: - print("wait 0 for:", waittime3) - - if words_line[0] == "patwait" and words_line[1] == "4": - wait4 = int(hex2dec(words_line[2])) - if verbose: - print("wait 1 at:", wait4) - if words_line[0] == "patwaittime" and words_line[1] == "4": - waittime4 = int(words_line[2]) - if verbose: - print("wait 1 for:", waittime4) - - if words_line[0] == "patwait" and words_line[1] == "5": - wait5 = int(hex2dec(words_line[2])) - if verbose: - print("wait 2 at:", wait5) - if words_line[0] == "patwaittime" and words_line[1] == "5": - waittime5 = int(words_line[2]) - if verbose: - print("wait 2 for:", waittime5) - - # ====== LOOPS ====== - if words_line[0] == "patloop" and words_line[1] == "0": - loop0_start = int(hex2dec(words_line[2])) - loop0_end = int(hex2dec(words_line[3])) - if verbose: - print("loop 0 start:", loop0_start, ", end:", loop0_end) - if words_line[0] == "patnloop" and words_line[1] == "0": - nloop0 = int(words_line[2]) - if verbose: - print("loop 0 times:", nloop0) - - if words_line[0] == "patloop" and words_line[1] == "1": - loop1_start = int(hex2dec(words_line[2])) - loop1_end = int(hex2dec(words_line[3])) - if verbose: - print("loop 1 start:", loop1_start, ", end:", loop1_end) - if words_line[0] == "patnloop" and words_line[1] == "1": - nloop1 = int(words_line[2]) - if verbose: - print("loop 1 times:", nloop1) - - if words_line[0] == "patloop" and words_line[1] == "2": - loop2_start = int(hex2dec(words_line[2])) - loop2_end = int(hex2dec(words_line[3])) - if verbose: - print("loop 2 start:", loop2_start, ", end:", loop2_end) - if words_line[0] == "patnloop" and words_line[1] == "2": - nloop2 = int(words_line[2]) - if verbose: - print("loop 2 times:", nloop2) - - if words_line[0] == "patloop" and words_line[1] == "3": - loop3_start = int(hex2dec(words_line[2])) - loop3_end = int(hex2dec(words_line[3])) - if verbose: - print("loop 3 start:", loop3_start, ", end:", loop3_end) - if words_line[0] == "patnloop" and words_line[1] == "3": - nloop3 = int(words_line[2]) - if verbose: - print("loop 3 times:", nloop3) - - if words_line[0] == "patloop" and words_line[1] == "4": - loop4_start = int(hex2dec(words_line[2])) - loop4_end = int(hex2dec(words_line[3])) - if verbose: - print("loop 4 start:", loop4_start, ", end:", loop4_end) - if words_line[0] == "patnloop" and words_line[1] == "4": - nloop4 = int(words_line[2]) - if verbose: - print("loop 4 times:", nloop4) - - if words_line[0] == "patloop" and words_line[1] == "5": - loop5_start = int(hex2dec(words_line[2])) - loop5_end = int(hex2dec(words_line[3])) - if verbose: - print("loop 5 start:", loop5_start, ", end:", loop5_end) - if words_line[0] == "patnloop" and words_line[1] == "5": - nloop5 = int(words_line[2]) - if verbose: - print("loop 5 times:", nloop5) -# print(out_bits) - -# internal counter -avail_index = [] -avail_name = [] -# Remove non-used bits -for i in range(64): - # if out_bits[0][i] == 1: - if out_bits[i] == 1: - avail_index.append(i) - avail_name.append(table[i][1]) -if verbose: - print(avail_index) - print(avail_name) - -# number of effective used bits -nbiteff = len(avail_name) - -# subMat = mat_ext[:,index] -# print(mat_pat.shape) -subMat = mat_pat.reshape(int(cnt), int(len(num_bits)))[0:, avail_index] -# subMat = mat_pat[avail_index] -timing = linspace(0, subMat.shape[0]-1, subMat.shape[0]) -rcParams['figure.figsize'] = 15, 5 - - -# ============= PLOTTING ============= - -rcParams["font.weight"] = "bold" -rcParams["axes.labelweight"] = "bold" -fig2, axs2 = subplots(nbiteff, sharex='all') -subplots_adjust(wspace=0, hspace=0) -# axs2[nbiteff - 1].set(xlabel='Timing [clk]') -for idx, i in enumerate(range(nbiteff)): - - axs2[idx].plot(subMat.T[i], "-", drawstyle="steps-post", linewidth=2.0, color=colors_plot[idx % 2]) - x_additional = range(len(subMat.T[i]) - 1, len(subMat.T[i]) + 2) - additional_stuff = [subMat.T[i][-1]] * 3 - - axs2[idx].plot(x_additional, additional_stuff, - "--", drawstyle="steps-post", linewidth=2.0, color=colors_plot[idx % 2], alpha=0.5) - axs2[idx].yaxis.set_ticks([0.5], minor=False) - axs2[idx].xaxis.set_ticks(arange(0, len(subMat.T[i]) + 10, clock_vertical_lines_spacing)) - - axs2[idx].yaxis.set_ticklabels([avail_name[i]]) - axs2[idx].get_yticklabels()[0].set_color(colors_plot[idx % 2]) - - axs2[idx].grid(1, 'both', 'both', alpha=0.5) - axs2[idx].yaxis.grid(which="both", color=colors_plot[idx % 2], alpha=0.2) - if idx != nbiteff - 1: - if not show_clocks_number: - axs2[idx].xaxis.set_ticklabels([]) - axs2[idx].set(xlabel=' ', ylim=(-0.2, 1.2)) - else: - axs2[idx].set(xlabel='Timing [clk]', ylim=(-0.2, 1.2)) - # axs2[idx].set_xlim(left=0) - axs2[idx].set_xlim(left=0, right=len(subMat.T[i]) + 1) - axs2[idx].spines['top'].set_visible(False) - axs2[idx].spines['right'].set_alpha(0.2) - axs2[idx].spines['right'].set_visible(True) - axs2[idx].spines['bottom'].set_visible(False) - axs2[idx].spines['left'].set_visible(False) - - # ===================================================================================================== - # Plot the wait lines - # Wait 0 - if waittime0 is not None: - if waittime0 == 0: - axs2[idx].plot([wait0, wait0], [-10, 10], - linestyle=linestyles_wait[0], color=colors_wait[0], alpha=alpha_wait[0], linewidth=2.0) - axs2[idx].plot([wait0 + 1, wait0 + 1], [-10, 10], - linestyle=linestyles_wait[0], color=colors_wait[0], linewidth=2.0, alpha=alpha_wait[0]) - axs2[idx].add_patch(Rectangle((wait0, -10), 1, 20, - label="wait 0: skipped" if idx == 0 else "", - facecolor=colors_wait[0], alpha=alpha_wait_rect[0], hatch='\\\\')) - else: - axs2[idx].plot([wait0, wait0], [-10, 10], - linestyle=linestyles_wait[0], color=colors_wait[0], - label="wait 0: " + str(waittime0) + " clk" if idx == 0 else "", - linewidth=2.0, alpha=alpha_wait[0]) - - # Wait 1 - if waittime1 is not None: - if waittime1 == 0: - axs2[idx].plot([wait1, wait1], [-10, 10], - linestyle=linestyles_wait[1], color=colors_wait[1], alpha=alpha_wait[1], linewidth=2.0) - axs2[idx].plot([wait1 + 1, wait1 + 1], [-10, 10], - linestyle=linestyles_wait[1], color=colors_wait[1], linewidth=2.0, alpha=alpha_wait[1]) - axs2[idx].add_patch(Rectangle((wait1, -10), 1, 20, - label="wait 1: skipped" if idx == 0 else "", - facecolor=colors_wait[1], alpha=alpha_wait_rect[1], hatch='\\\\')) - else: - axs2[idx].plot([wait1, wait1], [-10, 10], - linestyle=linestyles_wait[1], color=colors_wait[1], - label="wait 1: " + str(waittime1) + " clk" if idx == 0 else "", - linewidth=2.0, alpha=alpha_wait[1]) - - # Wait 2 - if waittime2 is not None: - if waittime2 == 0: - axs2[idx].plot([wait2, wait2], [-10, 10], - linestyle=linestyles_wait[2], color=colors_wait[2], alpha=alpha_wait[2], linewidth=2.0) - axs2[idx].plot([wait2 + 1, wait2 + 1], [-10, 10], - linestyle=linestyles_wait[2], color=colors_wait[2], linewidth=2.0, alpha=alpha_wait[2]) - axs2[idx].add_patch(Rectangle((wait2, -10), 1, 20, - label="wait 2: skipped" if idx == 0 else "", - facecolor=colors_wait[2], alpha=alpha_wait_rect[2], hatch='\\\\')) - else: - axs2[idx].plot([wait2, wait2], [-10, 10], - linestyle=linestyles_wait[2], color=colors_wait[2], - label="wait 2: " + str(waittime2) + " clk" if idx == 0 else "", - linewidth=2.0, alpha=alpha_wait[2]) - - # Wait 3 - if waittime3 is not None: - if waittime3 == 0: - axs2[idx].plot([wait3, wait3], [-10, 10], - linestyle=linestyles_wait[3], color=colors_wait[3], alpha=alpha_wait[3], linewidth=2.0) - axs2[idx].plot([wait3 + 1, wait3 + 1], [-10, 10], - linestyle=linestyles_wait[3], color=colors_wait[3], linewidth=2.0, alpha=alpha_wait[3]) - axs2[idx].add_patch(Rectangle((wait3, -10), 1, 20, - label="wait 3: skipped" if idx == 0 else "", - facecolor=colors_wait[3], alpha=alpha_wait_rect[3], hatch='\\\\')) - else: - axs2[idx].plot([wait3, wait3], [-10, 10], - linestyle=linestyles_wait[3], color=colors_wait[3], - label="wait 3: " + str(waittime3) + " clk" if idx == 0 else "", - linewidth=2.0, alpha=alpha_wait[3]) - - # Wait 4 - if waittime4 is not None: - if waittime4 == 0: - axs2[idx].plot([wait4, wait4], [-10, 10], - linestyle=linestyles_wait[4], color=colors_wait[4], alpha=alpha_wait[4], linewidth=2.0) - axs2[idx].plot([wait4 + 1, wait4 + 1], [-10, 10], - linestyle=linestyles_wait[4], color=colors_wait[4], linewidth=2.0, alpha=alpha_wait[4]) - axs2[idx].add_patch(Rectangle((wait4, -10), 1, 20, - label="wait 4: skipped" if idx == 0 else "", - facecolor=colors_wait[4], alpha=alpha_wait_rect[4], hatch='\\\\')) - else: - axs2[idx].plot([wait4, wait4], [-10, 10], - linestyle=linestyles_wait[4], color=colors_wait[4], - label="wait 4: " + str(waittime4) + " clk" if idx == 0 else "", - linewidth=2.0, alpha=alpha_wait[4]) - - # Wait 5 - if waittime5 is not None: - if waittime5 == 0: - axs2[idx].plot([wait5, wait5], [-10, 10], - linestyle=linestyles_wait[5], color=colors_wait[5], alpha=alpha_wait[5], linewidth=2.0) - axs2[idx].plot([wait5 + 1, wait5 + 1], [-10, 10], - linestyle=linestyles_wait[5], color=colors_wait[5], linewidth=2.0, alpha=alpha_wait[5]) - axs2[idx].add_patch(Rectangle((wait5, -10), 1, 20, - label="wait 5: skipped" if idx == 0 else "", - facecolor=colors_wait[5], alpha=alpha_wait_rect[5], hatch='\\\\')) - else: - axs2[idx].plot([wait5, wait5], [-10, 10], - linestyle=linestyles_wait[5], color=colors_wait[5], - label="wait 5: " + str(waittime5) + " clk" if idx == 0 else "", - linewidth=2.0, alpha=alpha_wait[5]) - - # ===================================================================================================== - # Plot the loop lines - # Loop 0 - if nloop0 is not None: - if nloop0 == 0: - axs2[idx].plot([loop0_start, loop0_start], [-10, 10], - linestyle=linestyles_loop[0], color=colors_loop[0], - alpha=alpha_loop[0], linewidth=2.0) - axs2[idx].plot([loop0_end + 1, loop0_end + 1], [-10, 10], - linestyle=linestyles_loop[0], color=colors_loop[0], alpha=alpha_loop[0], linewidth=2.0) - axs2[idx].add_patch(Rectangle((loop0_start, -10), loop0_end + 1 - loop0_start, 20, - label="loop 0: skipped" if idx == 0 else "", - facecolor=colors_loop[0], alpha=alpha_loop_rect[0], hatch='//')) - else: - axs2[idx].plot([loop0_start, loop0_start], [-10, 10], - linestyle=linestyles_loop[0], color=colors_loop[0], alpha=alpha_loop[0], - label="loop 0: " + str(nloop0) + " times" if idx == 0 else "", linewidth=2.0) - axs2[idx].plot([loop0_end, loop0_end], [-10, 10], - linestyle=linestyles_loop[0], color=colors_loop[0], alpha=alpha_loop[0], linewidth=2.0) - - # Loop 1 - if nloop1 is not None: - if nloop1 == 0: - axs2[idx].plot([loop1_start, loop1_start], [-10, 10], - linestyle=linestyles_loop[1], color=colors_loop[1], - alpha=alpha_loop[1], linewidth=2.0) - axs2[idx].plot([loop1_end + 1, loop1_end + 1], [-10, 10], - linestyle=linestyles_loop[1], color=colors_loop[1], alpha=alpha_loop[1], linewidth=2.0) - axs2[idx].add_patch(Rectangle((loop1_start, -10), loop1_end + 1 - loop1_start, 20, - label="loop 1: skipped" if idx == 0 else "", - facecolor=colors_loop[1], alpha=alpha_loop_rect[1], hatch='//')) - else: - axs2[idx].plot([loop1_start, loop1_start], [-10, 10], - linestyle=linestyles_loop[1], color=colors_loop[1], alpha=alpha_loop[1], - label="loop 1: " + str(nloop1) + " times" if idx == 0 else "", linewidth=2.0) - axs2[idx].plot([loop1_end, loop1_end], [-10, 10], - linestyle=linestyles_loop[1], color=colors_loop[1], alpha=alpha_loop[1], linewidth=2.0) - - # Loop 2 - if nloop2 is not None: - if nloop2 == 0: - axs2[idx].plot([loop2_start, loop2_start], [-10, 10], - linestyle=linestyles_loop[2], color=colors_loop[2], - alpha=alpha_loop[2], linewidth=2.0) - axs2[idx].plot([loop2_end + 1, loop2_end + 1], [-10, 10], - linestyle=linestyles_loop[2], color=colors_loop[2], alpha=alpha_loop[2], linewidth=2.0) - axs2[idx].add_patch(Rectangle((loop2_start, -10), loop2_end + 1 - loop2_start, 20, - label="loop 2: skipped" if idx == 0 else "", - facecolor=colors_loop[2], alpha=alpha_loop_rect[2], hatch='//')) - else: - axs2[idx].plot([loop2_start, loop2_start], [-10, 10], - linestyle=linestyles_loop[2], color=colors_loop[2], alpha=alpha_loop[2], - label="loop 2: " + str(nloop2) + " times" if idx == 0 else "", linewidth=2.0) - axs2[idx].plot([loop2_end, loop2_end], [-10, 10], - linestyle=linestyles_loop[2], color=colors_loop[2], alpha=alpha_loop[2], linewidth=2.0) - - # Loop 3 - if nloop3 is not None: - if nloop3 == 0: - axs2[idx].plot([loop3_start, loop3_start], [-10, 10], - linestyle=linestyles_loop[3], color=colors_loop[3], - alpha=alpha_loop[3], linewidth=2.0) - axs2[idx].plot([loop3_end + 1, loop3_end + 1], [-10, 10], - linestyle=linestyles_loop[3], color=colors_loop[3], alpha=alpha_loop[3], linewidth=2.0) - axs2[idx].add_patch(Rectangle((loop3_start, -10), loop3_end + 1 - loop3_start, 20, - label="loop 3: skipped" if idx == 0 else "", - facecolor=colors_loop[3], alpha=alpha_loop_rect[3], hatch='//')) - else: - axs2[idx].plot([loop3_start, loop3_start], [-10, 10], - linestyle=linestyles_loop[3], color=colors_loop[3], alpha=alpha_loop[3], - label="loop 3: " + str(nloop3) + " times" if idx == 0 else "", linewidth=2.0) - axs2[idx].plot([loop3_end, loop3_end], [-10, 10], - linestyle=linestyles_loop[3], color=colors_loop[3], alpha=alpha_loop[3], linewidth=2.0) - - # Loop 4 - if nloop4 is not None: - if nloop4 == 0: - axs2[idx].plot([loop4_start, loop4_start], [-10, 10], - linestyle=linestyles_loop[4], color=colors_loop[4], - alpha=alpha_loop[4], linewidth=2.0) - axs2[idx].plot([loop4_end + 1, loop4_end + 1], [-10, 10], - linestyle=linestyles_loop[4], color=colors_loop[4], alpha=alpha_loop[4], linewidth=2.0) - axs2[idx].add_patch(Rectangle((loop4_start, -10), loop4_end + 1 - loop4_start, 20, - label="loop 4: skipped" if idx == 0 else "", - facecolor=colors_loop[4], alpha=alpha_loop_rect[4], hatch='//')) - else: - axs2[idx].plot([loop4_start, loop4_start], [-10, 10], - linestyle=linestyles_loop[4], color=colors_loop[4], alpha=alpha_loop[4], - label="loop 4: " + str(nloop4) + " times" if idx == 0 else "", linewidth=2.0) - axs2[idx].plot([loop4_end, loop4_end], [-10, 10], - linestyle=linestyles_loop[4], color=colors_loop[4], alpha=alpha_loop[4], linewidth=2.0) - - # Loop 5 - if nloop5 is not None: - if nloop5 == 0: - axs2[idx].plot([loop5_start, loop5_start], [-10, 10], - linestyle=linestyles_loop[5], color=colors_loop[5], - alpha=alpha_loop[5], linewidth=2.0) - axs2[idx].plot([loop5_end + 1, loop5_end + 1], [-10, 10], - linestyle=linestyles_loop[5], color=colors_loop[5], alpha=alpha_loop[5], linewidth=2.0) - axs2[idx].add_patch(Rectangle((loop5_start, -10), loop5_end + 1 - loop5_start, 20, - label="loop 5: skipped" if idx == 0 else "", - facecolor=colors_loop[5], alpha=alpha_loop_rect[5], hatch='//')) - else: - axs2[idx].plot([loop5_start, loop5_start], [-10, 10], - linestyle=linestyles_loop[5], color=colors_loop[5], alpha=alpha_loop[5], - label="loop 5: " + str(nloop5) + " times" if idx == 0 else "", linewidth=2.0) - axs2[idx].plot([loop5_end, loop5_end], [-10, 10], - linestyle=linestyles_loop[5], color=colors_loop[5], alpha=alpha_loop[5], linewidth=2.0) - - -n_cols = count_nonzero([waittime0 != 0, waittime1 != 0, waittime2 != 0, waittime3 != 0, waittime4 != 0, waittime5 != 0, - nloop0 != 0, nloop1 != 0, nloop2 != 0, nloop3 != 0, nloop4 != 0, nloop5 != 0]) -if n_cols > 0: - fig2.legend(loc="upper center", ncol=n_cols) -# manager = get_current_fig_manager() -# manager.window.showMaximized() - -figure = plt.gcf() # get current figure -figure.set_size_inches(20, 10) -# when saving, specify the DPI -# tight_layout() -plt.savefig(Folder+"/"+File_pat+".png", dpi=300) - -# Remove the white space around the plot -- only works on Unix (ImageMagick command) -os.system(f'mogrify -trim {Folder}/{File_pat}.png') - -show() diff --git a/python/slsdet/ctb.py b/python/slsdet/ctb.py index eff315da3..1b601356c 100644 --- a/python/slsdet/ctb.py +++ b/python/slsdet/ctb.py @@ -27,10 +27,34 @@ class Ctb(Detector): @property def powers(self): + """ + [Chiptestboard][Xilinx CTB] Power names and values of all power supplies. + + Example + ----------- + >>> # print all powers with DAC and info if enabled + >>> d.powers + >>> # set DAC or enables for power supply VA + >>> d.powers.VA = 1200 + >>> # enable or disable power subbly VA + >>> d.powers.VA.enable() + >>> d.powers.VA.disable() + >>> # get dac value of power supply VA + >>> d.powers.VA.dac + >>> # check if power supply VA is enabled + >>> d.powers.VA.enabled + >>> # print both enabled and dac value of power supply VA + >>> d.powers.VA + """ return self._powers @property def powerlist(self): + """ + List of power supply names on the Chip Test Board. + + :setter: List of custom power supply names to set. + """ return self.getPowerNames() @powerlist.setter diff --git a/python/slsdet/detector.py b/python/slsdet/detector.py index 56e29800f..47ad9220d 100755 --- a/python/slsdet/detector.py +++ b/python/slsdet/detector.py @@ -833,10 +833,10 @@ class Detector(CppDetectorApi): Note ---- Sets up the following for every module:\n - \t\t[Eiger] txdelay_left to (2 * mod_index * n_delay), \n - \t\t[Eiger] txdelay_right to ((2 * mod_index + 1) * n_delay) and \n - \t\t[Eiger] txdelay_frame to (2 *num_modules * n_delay) \n - \t\t[Jungfrau][Moench][Mythen3] txdelay_frame to (num_modules * n_delay)\n\n + \t\t[Eiger] txdelay_left to (2 \* mod_index \* n_delay), \n + \t\t[Eiger] txdelay_right to ((2 \* mod_index + 1) \* n_delay) and \n + \t\t[Eiger] txdelay_frame to (2 \* num_modules \* n_delay) \n + \t\t[Jungfrau][Moench][Mythen3] txdelay_frame to (num_modules \* n_delay)\n\n Please refer txdelay_left, txdelay_right and txdelay_frame for details. """ return self.getTransmissionDelay() @@ -1313,10 +1313,10 @@ class Detector(CppDetectorApi): @property def zmqhwm(self): """ - Client's zmq receive high water mark. Default is the zmq library's default (1000), can also be set here using -1. - This is a high number and can be set to 2 for gui purposes. + Client's zmq receive high water mark. Default is the zmq library's default (1000), can also be set here using -1. + This is a high number and can be set to 2 for gui purposes. One must also set the receiver's send high water mark to similar value. Final effect is sum of them. - Setting it via command line is useful only before zmq enabled (before opening gui). + Setting it via command line is useful only before zmq enabled (before opening gui). """ return self.getClientZmqHwm() @@ -2312,13 +2312,16 @@ class Detector(CppDetectorApi): @property @element def threshold(self): - """[Eiger][Mythen3] Threshold in eV + """ + [Eiger][Mythen3] Threshold in eV Note ---- - To change settings as well or set threshold without trimbits, use setThresholdEnergy. + To change settings as well or set threshold without trimbits, + use setThresholdEnergy. - :setter: It loads trim files from settingspath.\n [Mythen3] An energy of -1 will pick up values from detector. + :setter: It loads trim files from settingspath.\n + [Mythen3] An energy of -1 will pick up values from detector. """ if self.type == detectorType.MYTHEN3: diff --git a/slsDetectorGui/src/qDrawPlot.cpp b/slsDetectorGui/src/qDrawPlot.cpp index e967862a3..86d43dc66 100644 --- a/slsDetectorGui/src/qDrawPlot.cpp +++ b/slsDetectorGui/src/qDrawPlot.cpp @@ -620,11 +620,6 @@ void qDrawPlot::StartAcquisition() { "qDrawPlot::StartAcquisition"); } - // refixing all the zooming - { - std::lock_guard lock(mPlots); - xyRangeChanged = true; - } QtConcurrent::run(this, &qDrawPlot::AcquireThread); diff --git a/slsDetectorServers/matterhornServer/src/MatterhornApp.cpp b/slsDetectorServers/matterhornServer/src/MatterhornApp.cpp index a60b328a7..8c37df196 100644 --- a/slsDetectorServers/matterhornServer/src/MatterhornApp.cpp +++ b/slsDetectorServers/matterhornServer/src/MatterhornApp.cpp @@ -11,7 +11,15 @@ #include // gettid added in glibc 2.30 -#if __GLIBC__ == 2 && __GLIBC_MINOR__ < 30 +#if defined(__APPLE__) +#include +#include +static inline uint64_t gettid() { + uint64_t tid = 0; + pthread_threadid_np(nullptr, &tid); + return tid; +} +#elif __GLIBC__ == 2 && __GLIBC_MINOR__ < 30 #include #define gettid() syscall(SYS_gettid) #endif diff --git a/slsDetectorServers/slsDetectorServer/src/ASIC_Driver.c b/slsDetectorServers/slsDetectorServer/src/ASIC_Driver.c index 562396b16..adc01112d 100644 --- a/slsDetectorServers/slsDetectorServer/src/ASIC_Driver.c +++ b/slsDetectorServers/slsDetectorServer/src/ASIC_Driver.c @@ -11,8 +11,10 @@ #include #include +#ifndef __APPLE__ #include #include +#endif #include #include #include diff --git a/slsDetectorServers/slsDetectorServer/src/common.c b/slsDetectorServers/slsDetectorServer/src/common.c index 2bfc79bb7..cd7adab63 100644 --- a/slsDetectorServers/slsDetectorServer/src/common.c +++ b/slsDetectorServers/slsDetectorServer/src/common.c @@ -11,6 +11,12 @@ #include // stat #include // uname #include // readlink +#ifdef __APPLE__ +#include // PATH_MAX +#include // _NSGetExecutablePath +#include // uint32_t +#include // realpath +#endif extern int executeCommand(char *command, char *result, enum TLogLevel level); @@ -58,12 +64,33 @@ int getAbsPath(char *buf, size_t bufSize, char *fname) { // get path of current binary char path[bufSize]; memset(path, 0, bufSize); +#ifdef __APPLE__ + // macOS has no /proc; use _NSGetExecutablePath and canonicalize with + // realpath (the path returned may contain ".." or symlinks). + char raw[PATH_MAX]; + uint32_t rawSize = sizeof(raw); + if (_NSGetExecutablePath(raw, &rawSize) != 0) { + LOG(logWARNING, + ("Could not get current binary path for %s (buffer too small)\n", + fname)); + return FAIL; + } + char resolved[PATH_MAX]; + const char *src = realpath(raw, resolved) != NULL ? resolved : raw; + if (strlen(src) >= bufSize) { + LOG(logWARNING, + ("Current binary path too long for buffer (%s)\n", fname)); + return FAIL; + } + strcpy(path, src); +#else ssize_t len = readlink("/proc/self/exe", path, bufSize - 1); if (len < 0) { LOG(logWARNING, ("Could not readlink current binary for %s\n", fname)); return FAIL; } path[len] = '\0'; +#endif // get dir path and attach file name char *dir = dirname(path); diff --git a/slsDetectorServers/slsDetectorServer/src/programViaBlackfin.c b/slsDetectorServers/slsDetectorServer/src/programViaBlackfin.c index e5a281875..0f1c12d95 100644 --- a/slsDetectorServers/slsDetectorServer/src/programViaBlackfin.c +++ b/slsDetectorServers/slsDetectorServer/src/programViaBlackfin.c @@ -8,7 +8,9 @@ #include #include +#ifndef __APPLE__ #include +#endif #include // usleep /* global variables */ @@ -309,6 +311,7 @@ int preparetoCopyProgram(char *mess, char *functionType, FILE **fd, } // check available memory to copy program +#ifndef __APPLE__ { struct sysinfo info; sysinfo(&info); @@ -322,6 +325,7 @@ int preparetoCopyProgram(char *mess, char *functionType, FILE **fd, return FAIL; } } +#endif // open file to copy program *fd = fopen(TEMP_PROG_FILE_NAME, "w"); diff --git a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c index f4d9d930f..0359bb467 100644 --- a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c @@ -20,10 +20,24 @@ #include #include #include +#ifndef __APPLE__ #include +#endif #include +#ifdef __APPLE__ +// spidev is Linux-only; provide a minimal stub so virtual builds compile. +// The real ioctl(SPI_IOC_MESSAGE(...)) calls are guarded by detector +// macros (XILINX_CHIPTESTBOARDD) that are never set on macOS. +struct spi_ioc_transfer { + unsigned long tx_buf; + unsigned long rx_buf; + unsigned int len; + unsigned char cs_change; +}; +#else #include +#endif // defined in the detector specific Makefile #ifdef EIGERD @@ -127,6 +141,10 @@ int sendError(int file_des) { } void setMemoryAllocationErrorMessage() { +#ifdef __APPLE__ + sprintf(mess, "Memory allocation error (%s). Please reboot", + getFunctionNameFromEnum((enum detFuncs)fnum)); +#else struct sysinfo info; sysinfo(&info); sprintf( @@ -134,6 +152,7 @@ void setMemoryAllocationErrorMessage() { "Memory allocation error (%s). Available space: %d MB. Please reboot", getFunctionNameFromEnum((enum detFuncs)fnum), (int)(info.freeram / (1024 * 1024))); +#endif #ifdef EIGERD strcat(mess, ".\n"); #else @@ -9784,12 +9803,17 @@ void receive_program_default(int file_des, enum PROGRAM_INDEX index, if (ret == OK) { src = malloc(filesize); if (src == NULL) { +#ifdef __APPLE__ + sprintf(mess, "Could not %s. Memory allocation failure.\n", + functionType); +#else struct sysinfo info; sysinfo(&info); sprintf(mess, "Could not %s. Memory allocation failure. Free " "space: %d MB\n", functionType, (int)(info.freeram / (1024 * 1024))); +#endif LOG(logERROR, (mess)); ret = FAIL; } diff --git a/slsDetectorSoftware/src/CallerSpecial.cpp b/slsDetectorSoftware/src/CallerSpecial.cpp index 50cd1e72d..dc2ae8c6c 100644 --- a/slsDetectorSoftware/src/CallerSpecial.cpp +++ b/slsDetectorSoftware/src/CallerSpecial.cpp @@ -1586,7 +1586,7 @@ std::string Caller::define_bit(int action) { std::string Caller::definelist_reg(int action) { std::ostringstream os; if (action == defs::HELP_ACTION) { - os << "List of user-defined register definitions in shared memory." + os << "\n\t List of user-defined register definitions in shared memory." << '\n'; } else if (action == defs::PUT_ACTION) { throw RuntimeError("cannot put"); @@ -1605,7 +1605,8 @@ std::string Caller::definelist_reg(int action) { std::string Caller::definelist_bit(int action) { std::ostringstream os; if (action == defs::HELP_ACTION) { - os << "List of user-defined bit definitions in shared memory." << '\n'; + os << "\n\t List of user-defined bit definitions in shared memory." + << '\n'; } else if (action == defs::PUT_ACTION) { throw RuntimeError("cannot put"); } else if (action == defs::GET_ACTION) { diff --git a/slsSupportLib/include/sls/file_utils.h b/slsSupportLib/include/sls/file_utils.h index 010fc640c..81aa3d19b 100644 --- a/slsSupportLib/include/sls/file_utils.h +++ b/slsSupportLib/include/sls/file_utils.h @@ -11,37 +11,10 @@ namespace sls { -/** - * @param data array of data values - * @param nch number of channels - * @param offset start channel value - */ -int readDataFile(std::ifstream &infile, short int *data, int nch, - int offset = 0); - -/** - * @param data array of data value - * @param nch number of channels - */ -int readDataFile(std::string fname, short int *data, int nch); std::vector readBinaryFile(const std::string &fname, const std::string &errorPrefix); -/** - * @param nch number of channels - * @param data array of data values - * @param offset start channel number - */ -int writeDataFile(std::ofstream &outfile, int nch, short int *data, - int offset = 0); - -/** - * @param nch number of channels - * @param data array of data values - */ -int writeDataFile(std::string fname, int nch, short int *data); - // mkdir -p path implemented by recursive calls void mkdir_p(const std::string &path, std::string dir = ""); diff --git a/slsSupportLib/src/file_utils.cpp b/slsSupportLib/src/file_utils.cpp index 6751d489d..bc375ba9d 100644 --- a/slsSupportLib/src/file_utils.cpp +++ b/slsSupportLib/src/file_utils.cpp @@ -22,48 +22,6 @@ namespace sls { -int readDataFile(std::ifstream &infile, short int *data, int nch, int offset) { - int ichan, iline = 0; - short int idata; - int interrupt = 0; - std::string str; - while (infile.good() and interrupt == 0) { - getline(infile, str); - std::istringstream ssstr(str); - ssstr >> ichan >> idata; - if (ssstr.fail() || ssstr.bad()) { - interrupt = 1; - break; - } - if (iline < nch) { - if (ichan >= offset) { - data[iline] = idata; - iline++; - } - } else { - interrupt = 1; - break; - } - return iline; - }; - return iline; -} - -int readDataFile(std::string fname, short int *data, int nch) { - std::ifstream infile; - int iline = 0; - std::string str; - infile.open(fname.c_str(), std::ios_base::in); - if (infile.is_open()) { - iline = readDataFile(infile, data, nch, 0); - infile.close(); - } else { - LOG(logERROR) << "Could not read file " << fname; - return -1; - } - return iline; -} - std::vector readBinaryFile(const std::string &fname, const std::string &errorPrefix) { // check if it exists @@ -96,30 +54,6 @@ std::vector readBinaryFile(const std::string &fname, return buffer; } -int writeDataFile(std::ofstream &outfile, int nch, short int *data, - int offset) { - if (data == nullptr) - return slsDetectorDefs::FAIL; - for (int ichan = 0; ichan < nch; ichan++) - outfile << ichan + offset << " " << *(data + ichan) << std::endl; - return slsDetectorDefs::OK; -} - -int writeDataFile(std::string fname, int nch, short int *data) { - std::ofstream outfile; - if (data == nullptr) - return slsDetectorDefs::FAIL; - outfile.open(fname.c_str(), std::ios_base::out); - if (outfile.is_open()) { - writeDataFile(outfile, nch, data, 0); - outfile.close(); - return slsDetectorDefs::OK; - } else { - LOG(logERROR) << "Could not open file " << fname << "for writing"; - return slsDetectorDefs::FAIL; - } -} - void mkdir_p(const std::string &path, std::string dir) { if (path.length() == 0) return;