Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -Wno-deprecated -O3")
#####################################
# Link SPT3g Libraries
#####################################
set(SPT3G_DIR $ENV{SPT3G_SOFTWARE_PATH})
set(SPT3G_DIR $ENV{SPT3G_DIR})
set(SO3G_DIR $ENV{SO3G_DIR})
link_directories(${SPT3G_DIR}/build/spt3g)

find_package(Spt3g REQUIRED)

#####################################
# Find Rogue & Support Libraries
#####################################
Expand Down Expand Up @@ -68,15 +70,16 @@ find_package(Boost COMPONENTS thread)
# #####################################
# set(DO_PYTHON 0)
#
find_package(PythonInterp 3.6 REQUIRED)
find_package(PythonLibs 3.6 REQUIRED)
find_package(PythonInterp 3 REQUIRED)
find_package(PythonLibs 3 REQUIRED)

find_package (Python3 COMPONENTS Interpreter Development)

#####################################
# Setup build
#####################################
include_directories(/usr/local/include/)
include_directories(${PROJECT_SOURCE_DIR}/include/)

# Include files
include_directories(${ROGUE_INCLUDE_DIRS})
Expand All @@ -87,10 +90,6 @@ include_directories(${SPT3G_DIR}/core/include)
include_directories(${SPT3G_DIR}/core/src)
include_directories(${SO3G_DIR}/include)


include_directories(/usr/local/include/)
include_directories(${PROJECT_SOURCE_DIR}/include/)

# Create rogue python library
AUX_SOURCE_DIRECTORY(src SRC_FILES)
add_library(SmurfStreamer SHARED ${SRC_FILES})
Expand All @@ -102,5 +101,5 @@ set_target_properties(SmurfStreamer PROPERTIES OUTPUT_NAME "sosmurfcore")

# Link to rogue core
TARGET_LINK_LIBRARIES(SmurfStreamer LINK_PUBLIC ${ROGUE_LIBRARIES} ${SMURF_LIBRARIES})
TARGET_LINK_LIBRARIES(SmurfStreamer LINK_PUBLIC ${SPT3G_DIR}/build/spt3g/_libcore.so)
TARGET_LINK_LIBRARIES(SmurfStreamer LINK_PUBLIC spt3g::core)
TARGET_LINK_LIBRARIES(SmurfStreamer LINK_PUBLIC ${SO3G_DIR}/build/so3g/libso3g.so)
2 changes: 0 additions & 2 deletions include/smurf_streamer_numpy_init.h

This file was deleted.

15 changes: 6 additions & 9 deletions meta_registers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ root.FpgaTopLevel.AppTop.AppCore:
lmsGain: 1
lmsFreqHz: 1
CryoChannels: # Cryo root
centerFrequencyArray: 1
amplitudeScaleArray: 1
etaMagArray: 1
etaPhaseArray: 1
feedbackEnableArray: 1
centerFrequency: 1
amplitudeScale: 1
etaMag: 1
etaPhase: 1
feedbackEnable: 1
RtmCryoDet:
RampMaxCnt: 1
EnableRampTrigger: 1
Expand Down Expand Up @@ -60,7 +60,7 @@ root.SmurfProcessor:
B: 1
Downsampler:
Disable: 1
Factor: 1
InternalFactor: 1
DownsamplerMode: [3, 30]
PostDataEmulator:
Disable: 1
Expand All @@ -71,9 +71,6 @@ root.SmurfProcessor:
FileWriter:
IsOpen: [3, 5]
DataFile: 3
BandPhaseFeedback[{{range(8)}}]:
Tau: 1
Theta: 1
SOStream:
TransmitterDataDropCnt: 2
TransmitterMetaDropCnt: 2
Expand Down
17 changes: 13 additions & 4 deletions python/sosmurf/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from spt3g import core
import yaml
import re
import sys
import json

class stream_dumper:
"""Simple dump module that ignores flow-control keep_alive frames"""
Expand Down Expand Up @@ -74,10 +76,19 @@ def setup_server(cfg, slot):

print("-"*60)

# parse the script output
for line in proc.stdout.decode().split('\n'):
# look for marker
lsplit = line.split('=')
if lsplit[0] == 'NEW_ARGS':
args = ''.join(lsplit[1:])
if lsplit[0] == 'OUTPUT':
out = json.loads(lsplit[1])
# get the arguments
args = out.get("NEW_ARGS", "")
# get the updated pythonpath
if "PYTHONPATH" in out:
new_path = out["PYTHONPATH"]
print(f"updating path with {new_path}.")
sys.path += new_path.split(":")

if lane is not None:
args += f' -l {lane}'
Expand Down Expand Up @@ -209,7 +220,6 @@ def get_kwargs(args, dev_type, **extra_kwargs):
elif dev_type=="cmb_pcie":
kwargs = {
'config_file' : args.config_file,
'epics_prefix' : args.epics_prefix,
'polling_en' : args.polling_en,
'pv_dump_file' : args.pv_dump_file,
'disable_bay0' : args.disable_bay0,
Expand All @@ -224,7 +234,6 @@ def get_kwargs(args, dev_type, **extra_kwargs):
kwargs = {
'ip_addr': args.ip_addr,
'config_file': args.config_file,
'epics_prefix': args.epics_prefix,
'polling_en': args.polling_en,
'pv_dump_file': args.pv_dump_file,
'disable_bay0': args.disable_bay0,
Expand Down
4 changes: 1 addition & 3 deletions scripts/emulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ def main():

# Import the root device after the python path is updated
from pysmurf.core.roots.EmulationRoot import EmulationRoot
args.epics_prefix = 'emulator'

with EmulationRoot ( config_file = args.config_file,
epics_prefix = args.epics_prefix,
polling_en = args.polling_en,
pv_dump_file = args.pv_dump_file,
disable_bay0 = args.disable_bay0,
Expand All @@ -55,6 +53,6 @@ def main():
VariableGroups = vgs.data) as root:
print("Loaded Emulation root", flush=True)
pipe.Run(profile=True)

if __name__ == '__main__':
main()
2 changes: 1 addition & 1 deletion scripts/setup_server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ initialize extra_args

args+=" ${extra_args}"

echo "NEW_ARGS=${args}"
echo "OUTPUT={\"NEW_ARGS\": \"${args}\", \"PYTHONPATH\": \"${PYTHONPATH}\"}"
18 changes: 6 additions & 12 deletions scripts/stream.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from spt3g import core

import rogue
import pyrogue.gui
import pyrogue
import argparse
import sosmurf
import sys
Expand Down Expand Up @@ -50,15 +49,6 @@ def main() -> None:
print(f"Stream id: {args.stream_id}")
os.environ['SMURFPUB_ID'] = f"STREAMER:{args.stream_id}"

# Sets some reasonable defaults
if not args.epics_prefix:
if args.emulate:
args.epics_prefix = f"smurf_emulator_s{slot}"
args.server_port = 9000 + 2*slot
else:
args.epics_prefix = f"smurf_server_s{slot}"
print(f"Using epics root {args.epics_prefix}")

if args.config_file is None:
args.config_file = slot_cfg.get('rogue_defaults')
print(f"Using config_file {args.config_file}")
Expand All @@ -67,6 +57,10 @@ def main() -> None:
args.pcie_rssi_lane = slot - 2
print(f"Using pcie lane {args.pcie_rssi_lane}")

# make sure that server port maps to slot
# if left undefined, will default to use PCIE lane number to infer slot
args.server_port = 9000 + slot * 3

stream_root = sosmurf.StreamBase(
"SOStream", debug_meta=False, debug_data=False, agg_time=2.0
)
Expand Down Expand Up @@ -98,7 +92,7 @@ def main() -> None:
}
root_kwargs = {
'config_file': args.config_file, 'server_port': args.server_port,
'epics_prefix': args.epics_prefix, 'polling_en': args.polling_en,
'polling_en': args.polling_en,
'pv_dump_file': args.pv_dump_file, 'disable_bay0': args.disable_bay0,
'disable_bay1': args.disable_bay1, 'configure': args.configure,
'txDevice': stream_root, 'enable_pwri2c': args.enable_em22xx,
Expand Down
10 changes: 2 additions & 8 deletions scripts/stream_devboard.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from spt3g import core

import pyrogue.gui
import pysmurf.core.devices
import pysmurf.core.server_scripts.Common as pysmurf_common

Expand Down Expand Up @@ -53,13 +52,8 @@ def main():
print("got pysmurf root", flush=True)
if args.use_gui:
print("Starting GUI...")
app_top = pyrogue.gui.application(sys.argv)
gui_top = pyrogue.gui.GuiTop(incGroups=None,excGroups=None)
gui_top.setWindowTitle(args.windows_title)
gui_top.addTree(root)
gui_top.resize(800,1000)
app_top.exec_()

import pyrogue.pydm
pyrogue.pydm.runPyDM(serverList=root.zmqServer.address, title=args.windows_title)
else:
# pyrogue.waitCntrlC()
print("Starting G3Pipeline", flush=True)
Expand Down
10 changes: 2 additions & 8 deletions scripts/stream_pcie.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from spt3g import core

import pyrogue.gui
import argparse
import sosmurf
import sys
Expand Down Expand Up @@ -69,13 +68,8 @@ def main():
print("got pysmurf root", flush=True)
if args.use_gui:
print("Starting GUI...")
app_top = pyrogue.gui.application(sys.argv)
gui_top = pyrogue.gui.GuiTop(incGroups=None,excGroups=None)
gui_top.setWindowTitle(args.windows_title)
gui_top.addTree(root)
gui_top.resize(800,1000)
app_top.exec_()

import pyrogue.pydm
pyrogue.pydm.runPyDM(serverList=root.zmqServer.address, title=args.windows_title)
else:
# pyrogue.waitCntrlC()
print("Starting G3Pipeline", flush=True)
Expand Down
23 changes: 9 additions & 14 deletions scripts/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

#%%
class Registers:
_root = 'AMCc:'
_processor = _root + "SmurfProcessor:"
_sostream = _processor + "SOStream:"
_sofilewriter = _sostream + 'SOFileWriter:'
_source_root = _root + 'StreamDataSource:'
_root = 'AMCc.'
_processor = _root + "SmurfProcessor."
_sostream = _processor + "SOStream."
_sofilewriter = _sostream + 'SOFileWriter.'
_source_root = _root + 'StreamDataSource.'
pysmurf_action = _sostream + 'pysmurf_action'
pysmurf_action_timestamp = _sostream + "pysmurf_action_timestamp"
stream_tag = _sostream + "stream_tag"
Expand All @@ -26,22 +26,19 @@ class Registers:
agg_time = _sostream + 'AggTime'

def set_reg(S: SmurfControl, reg, val):
print(S.epics_root, reg)
_reg = ':'.join([S._epics_root, reg])
return S._caput(_reg, val)
print(f"crate{S.crate_id}slot{S.slot_number}", reg)
return S._caput(reg, val)

def get_reg(S: SmurfControl, reg):
_reg = ':'.join([S._epics_root, reg])
return S._caget(_reg, use_monitor=False)
return S._caget(reg, use_monitor=False)

#%%

epics_root="emulator"
cfg_file = '/usr/local/src/pysmurf/cfg_files/template/template.cfg'
os.makedirs('/data/smurf_data', exist_ok=True)
os.makedirs('/data/smurf_data/tune', exist_ok=True)
os.makedirs('/data/smurf_data/status', exist_ok=True)
S = SmurfControl(epics_root=epics_root, cfg_file=cfg_file)
S = SmurfControl(cfg_file=cfg_file, server_port=9000)

#%%
set_reg(S, Registers.debug_builder, 1)
Expand All @@ -56,8 +53,6 @@ def get_reg(S: SmurfControl, reg):
S.set_postdata_emulator_type('Noise')

#%%
from epics import caget, caput
#%%
set_reg(S, Registers.agg_time, 10)

# %%
21 changes: 15 additions & 6 deletions scripts/test_emulator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from spt3g import core

import rogue
import pyrogue.gui
import argparse
import sosmurf
import sys
Expand All @@ -13,13 +12,15 @@
import shlex
from pysmurf.core.roots.EmulationRoot import EmulationRoot

g3_dir = "/tmp"
stream_rate = 500.0 # Hz

print(f"PID: {os.getpid()}")

stream_root = sosmurf.StreamBase(
"SOStream", debug_meta=False, debug_data=False, agg_time=2.0
"SOStream", debug_meta=True, debug_data=False, agg_time=2.0
)
file_writer = sosmurf.SOFileWriter("SOFileWriter", g3_dir, file_dur=10*60)
file_writer = sosmurf.SOFileWriter("SOFileWriter", g3_dir, file_dur=10)
stream_root.add(file_writer)

pipe = core.G3Pipeline()
Expand All @@ -29,7 +30,15 @@
pipe.Add(file_writer.rotator)


with EmulationRoot():
with EmulationRoot(server_port=9000, txDevice=stream_root) as root:
print(f' Streaming data at {stream_rate} Hz... ', end='')
root.StreamDataSource.SourceEnable.set(True)
root.StreamDataSource.Period.set(1/stream_rate)
# Open the output data file
print(' Opening the FileWriter output file... ', end='')
root.SmurfProcessor.FileWriter.DataFile.set('/tmp/test_emu.dat')
root.SmurfProcessor.FileWriter.Open()

pipe.Run()
print("HERE")

print("HERE")
2 changes: 1 addition & 1 deletion src/SmurfBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ G3FramePtr SmurfBuilder::FrameFromSamples(

// Creates channel names if needed
if (nchans > chan_names_.size()){
char name[10];
char name[13];
for (int i = chan_names_.size(); i < nchans; i++){
sprintf(name, "r%04d", i);
chan_names_.push_back(name);
Expand Down
2 changes: 1 addition & 1 deletion src/python.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define NPY_API_SYMBOL_ATTRIBUTE
#include "SmurfTransmitter.h"
#include "SmurfBuilder.h"
#include "so3g_numpy.h"
Expand All @@ -13,7 +14,6 @@ BOOST_PYTHON_MODULE(sosmurfcore){
bp::import("rogue");
bp::import("spt3g.core");

PyEval_InitThreads();
_sosmurf_import_array();

SmurfTransmitter::setup_python();
Expand Down