From 47c202222841337abe301728721358e1c4791ef4 Mon Sep 17 00:00:00 2001
From: Guenter Quast <guenter.quast@online.de>
Date: Sun, 9 Jun 2024 20:47:14 +0200
Subject: [PATCH] more conditional imports: mimocorb

---
 redP_mimoCoRB.py |  9 ++-------
 redPoscdaq.py    | 14 ++++++++++++--
 run_daq.py       | 31 +++++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+), 9 deletions(-)
 create mode 100755 run_daq.py

diff --git a/redP_mimoCoRB.py b/redP_mimoCoRB.py
index 6882767..ba9b876 100644
--- a/redP_mimoCoRB.py
+++ b/redP_mimoCoRB.py
@@ -21,14 +21,9 @@ def redP_to_rb(source_list=None, sink_list=None, observe_list=None, config_dict=
 
     :param config_dict: configuration dictionary
 
-      - events_required: number of events to be simulated or 0 for infinite
-      - sleeptime: (mean) time between events
-      - random: random time between events according to a Poission process
+      - events_required: number of events to taken
       - number_of_samples, sample_time_ns, pretrigger_samples and analogue_offset
-        describe the waveform data to be generated (as for oscilloscope setup)
-
-    Internal parameters of the simulated physics process (the decay of a muon)
-    are (presently) not exposed to user.
+      - decimation index, invert fags, trigger mode and trigger direction for RedPitaya
     """
 
     # initialize mimocorb class inside redPoscidaq
diff --git a/redPoscdaq.py b/redPoscdaq.py
index a5155e1..cd0f8ed 100755
--- a/redPoscdaq.py
+++ b/redPoscdaq.py
@@ -52,7 +52,10 @@ import matplotlib
 from matplotlib.figure import Figure
 from multiprocessing import Event
 
-from mimocorb.buffer_control import rbPut
+# !!! for conditional import from npy_append_array !!!
+def import_mimocorb():
+    global rbPut
+    from mimocorb.buffer_control import rbPut
 
 # !!! for conditional import from npy_append_array !!!
 def import_npy_append_array():
@@ -208,7 +211,7 @@ class rpControl(QMainWindow, Ui_MCPHA):
         self.invert2 = 0 if "invert_channel2" not in self.confd else self.confd["invert_channel2"]
         self.readInterval = 1000 # used to control update of oscilloscope display
         # other parameters
-        self.filename = ''  # file name for data export 
+        self.filename = ''  # file name for data export, '' means disable
 
     def parse_args(self):
         parser = argparse.ArgumentParser(description=__doc__)
@@ -246,6 +249,7 @@ class rpControl(QMainWindow, Ui_MCPHA):
         # other parameters
         self.filename = args.file
         if self.filename:
+            # data recording with npy_append_array()
             import_npy_append_array()
 
         
@@ -896,6 +900,8 @@ class redP_consumer():
 class redP_mimocorb():            
     def __init__(self, source_list=None, sink_list=None, observe_list=None, config_dict=None,
                  **rb_info):
+        # import rbPut() from mimoCoRB 
+        import_mimocorb()
         # initialize mimoCoRB interface 
         self.action = rbPut(config_dict=config_dict, sink_list=sink_list, **rb_info)
         self.number_of_channels = len(self.action.sink.dtype)
@@ -917,6 +923,10 @@ class redP_mimocorb():
            sys.exit()
            
 def run_rpControl(callback=None, conf_dict=None):
+    if conf_dict is not None:
+        # need module rbPut() from mimoCoRB, import here 
+        import_mimocorb()
+
     # start redPidaya GUI under Qt5 
     app = QApplication(sys.argv)
     dpi = app.primaryScreen().logicalDotsPerInch()
diff --git a/run_daq.py b/run_daq.py
new file mode 100755
index 0000000..c5a2c3b
--- /dev/null
+++ b/run_daq.py
@@ -0,0 +1,31 @@
+#! /usr/bin/env python3
+"""
+run mimoCoRB data acquisition suite
+"""
+
+import argparse
+import sys, time
+from mimocorb.buffer_control import run_mimoDAQ
+
+# define command line arguments ...
+parser = argparse.ArgumentParser(description=__doc__)
+parser.add_argument('filename', nargs='?', default = "setup.yaml",
+                    help = "configuration file")
+parser.add_argument('-v','--verbose', type=int, default=2,
+                    help="verbosity level (2)")
+parser.add_argument('-d','--debug', action='store_true',
+                    help="switch on debug mode (False)")
+# ... and parse command line input
+args = parser.parse_args()
+
+print("\n*==* script " + sys.argv[0] + " running \n")
+daq = run_mimoDAQ(args.filename, verbose=args.verbose, debug=args.debug)
+
+daq.setup()
+
+daq.run()
+
+# wait for user confirmation (useful if started via GUI)
+# input(30*' '+'Finished, good bye !  Type <ret> to exit -> ')
+
+print("\n*==* script " + sys.argv[0] + " finished " + time.asctime() + "\n")
-- 
GitLab