diff --git a/CMakeLists.txt b/CMakeLists.txt index 1bd0e74..e76e36b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,6 +58,7 @@ include_directories(${SPT3G_DIR}/core/src) include_directories(${SO3G_DIR}/include) include_directories(/usr/include/python3.10) include_directories(${PROJECT_SOURCE_DIR}/include/) # rfsoc-streamer/include +include_directories(/opt/venv/lib/python3.10/site-packages/numpy/core/include) # Create rfsoc python library set(SRC_FILES ${PROJECT_SOURCE_DIR}/src/RfsocBuilder.cxx ${PROJECT_SOURCE_DIR}/src/RfsocTransmitter.cxx ${PROJECT_SOURCE_DIR}/src/python.cpp) diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b04ed45 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,91 @@ +FROM ubuntu:22.04 + +# Installing needed packages +RUN apt-get update && apt-get install -y gcc \ + g++ make git python3-dev python3-pip \ + python3.10-venv libboost-all-dev \ + libopenblas-openmp-dev libflac-dev \ + bzip2 libbz2-dev libgsl-dev + +# Workaround for build issue with so3g needing specifically the 'python' executable +RUN ln -s /usr/bin/python3.10 /usr/bin/python + +# Make sure files belong to ocs user and group +RUN groupadd -g 9000 ocs && \ + useradd -m -l -u 9000 -g 9000 ocs + +# Setting up virtual environment +RUN python3 -m venv /opt/venv/ +ENV PATH="/opt/venv/bin:$PATH" +RUN python3 -m pip install -U pip +# Installing cmake here instead of with apt-get +# to avoid version issues later with so3g's +# requirements.txt file installing cmake with pip +RUN python3 -m pip install cmake + +# Guaranteeing that there will be a common build directory for socs/spt3g +WORKDIR /usr/local/so3g +WORKDIR /usr/local/src + +ENV SO3G_DIR=/usr/local/src/so3g +ENV SPT3G_DIR=/usr/local/src/spt3g_software +ENV SPT3G_SOFTWARE_PATH=/usr/local/src/spt3g_software +ENV RFSOC_DIR=/usr/local/src/rfsoc-streamer +ENV LD_LIBRARY_PATH=/usr/local/so3g/lib:/usr/local/so3g/so3g +ENV STREAM_CONFIG_DIR=/config +ENV SPT3G_SOFTWARE_BUILD_PATH=${SPT3G_DIR}/build +ENV SO3G_BUILD_PATH=/usr/local/so3g/lib + +# Clone all repos +RUN git clone https://github.com/CMB-S4/spt3g_software.git +RUN git clone https://github.com/simonsobs/so3g.git +#RUN git clone https://github.com/ccatobs/rfsoc-streamer.git +COPY . /usr/local/src/rfsoc-streamer + +# Install spt3g +WORKDIR /usr/local/src/spt3g_software/build + +RUN cmake \ + -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_C_COMPILER="gcc" \ + -DCMAKE_CXX_COMPILER="g++" \ + -DCMAKE_C_FLAGS="-O3 -g -fPIC" \ + -DCMAKE_CXX_FLAGS="-O3 -g -fPIC -std=c++11" \ + -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \ + -DPython_EXECUTABLE:FILEPATH=$(which python3) \ + -DCMAKE_INSTALL_PREFIX="/usr/local/so3g" \ + .. + +RUN make -j 4 +RUN make install + +# Install so3g +WORKDIR /usr/local/src/so3g +RUN pip install -r requirements.txt +WORKDIR /usr/local/src/so3g/build + +RUN cmake \ + -DCMAKE_PREFIX_PATH='/usr/local/src/spt3g_software/build' \ + -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \ + -DPYTHON_INSTALL_DEST="/usr/local/so3g" \ + -DCMAKE_INSTALL_PREFIX="/usr/local/so3g" \ + .. + +RUN make -j 4 +RUN make install + +# Install rfsoc-streamer +WORKDIR /usr/local/src/rfsoc-streamer +RUN cmake . +RUN make + +# There is no PYTHONPATH to start, so no need to append it to the end here +ENV PYTHONPATH="${RFSOC_DIR}/lib:${RFSOC_DIR}/python:$SPT3G_SOFTWARE_BUILD_PATH:$SO3G_BUILD_PATH" +ENV PATH="/usr/local/so3g/bin:${PATH}" + +RUN pip install dumb-init + +# The command to run stream.py will be in the docker-compose.yml file +# for more granular user control +ENTRYPOINT ["dumb-init", /bin/bash] diff --git a/README.md b/README.md index 451a537..1cb95a7 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ cmake \ -DCMAKE_INSTALL_PREFIX="${HOME}/so3g" \ .. -make +make -j 4 make install # cd ~/git/so3g @@ -76,7 +76,7 @@ cmake \ -DCMAKE_INSTALL_PREFIX="${HOME}/so3g" \ .. -make +make -j 4 make install # ``` @@ -93,7 +93,7 @@ cd ~/git/rfsoc-streamer cmake . # this will create multiple cmake-related files and a Makefile make # or "VERBOSE=1 make" if you want more information printed out during make -python test/stream.py +python scripts/stream.py # run this for a little while, then terminate with Ctrl-C # this should produce one more g3 files under ~/data/g3, with timestamp information distinguishing files @@ -101,7 +101,7 @@ python test/stream.py # if you want to either write to a different directory, # or receive packets from a different IP address, # or change the file_dur (file duration before rotating), -# modify the code in test/stream.py and re-run the python code +# modify the code in scripts/stream.py and re-run the python code ``` ### Pure C++ version @@ -111,7 +111,7 @@ cd ~/git/rfsoc-streamer cd src make -cd ../test +cd ../scripts make ./stream_min_example diff --git a/test/.gitignore b/scripts/.gitignore similarity index 100% rename from test/.gitignore rename to scripts/.gitignore diff --git a/test/Makefile b/scripts/Makefile similarity index 100% rename from test/Makefile rename to scripts/Makefile diff --git a/test/inspect_g3.cxx b/scripts/inspect_g3.cxx similarity index 100% rename from test/inspect_g3.cxx rename to scripts/inspect_g3.cxx diff --git a/test/stream.py b/scripts/stream.py similarity index 100% rename from test/stream.py rename to scripts/stream.py diff --git a/test/stream_config.yaml b/scripts/stream_config.yaml similarity index 85% rename from test/stream_config.yaml rename to scripts/stream_config.yaml index b86320b..4e4e5eb 100644 --- a/test/stream_config.yaml +++ b/scripts/stream_config.yaml @@ -1,5 +1,5 @@ -g3_dir: /home/streamer/data/g3/ # path to top level detector file directory -file_rotation_time: 600 #60*10 # time before rotating files in seconds +g3_dir: /data/g3/ # path to top level detector file directory in Docker container +file_rotation_time: 600 # time before rotating files in seconds # Board and drone specific settings for all active RFSoCs # stream IDs must have format rfsoc##_drone# - this is parsed to use in filenames diff --git a/test/stream_min_example.cxx b/scripts/stream_min_example.cxx similarity index 100% rename from test/stream_min_example.cxx rename to scripts/stream_min_example.cxx diff --git a/src/RfsocTransmitter.cxx b/src/RfsocTransmitter.cxx index 6434f12..0a2ca16 100644 --- a/src/RfsocTransmitter.cxx +++ b/src/RfsocTransmitter.cxx @@ -20,8 +20,7 @@ #include #include -#define RECEIVE_IP "192.168.3.40" // The receiving computer IP -//#define CONNECT_IP "192.168.3.58" // The drone IP address from which to receive packets +// The ports are currently hardcoded - the IP addresses differ for different drones #define RECEIVE_PORT 4096 #define CONNECT_PORT 4096 @@ -47,7 +46,6 @@ void RfsocTransmitter::dataTransmit(RfsocPacketPtr rp){ builder_->AsyncDatum(ts.time, rfsoc_sample); } -// borrowing from Ben's code - just listening for anything on network that arrives at BROADCAST_IP int RfsocTransmitter::SetupUDPSocket() { struct sockaddr_in rx_addr; @@ -119,7 +117,6 @@ int RfsocTransmitter::Stop() return (0); } -//Adapted to use Ben's code, but could go back to DfMuxCollectors's recvfrom void RfsocTransmitter::Listen(RfsocTransmitter *transmitter) { ssize_t len;