From 5840d2667800760b159c5a8b351279b70f2da940 Mon Sep 17 00:00:00 2001
From: Jan David Mol <mol@astron.nl>
Date: Fri, 6 Feb 2015 15:29:14 +0000
Subject: [PATCH] Task #7352: Moved self.parset,usage(),go() to control

---
 .../framework/lofarpipe/support/control.py    | 45 ++++++++++++++++---
 .../recipes/sip/bin/calibration_pipeline.py   | 30 -------------
 .../recipes/sip/bin/imaging_pipeline.py       | 26 -----------
 .../recipes/sip/bin/long_baseline_pipeline.py | 25 -----------
 .../sip/bin/msss_calibrator_pipeline.py       | 30 -------------
 .../recipes/sip/bin/msss_imager_pipeline.py   | 25 -----------
 .../recipes/sip/bin/msss_target_pipeline.py   | 31 -------------
 .../recipes/sip/bin/preprocessing_pipeline.py | 30 -------------
 .../recipes/sip/bin/pulsar_pipeline.py        | 23 ----------
 CEP/Pipeline/recipes/sip/bin/startPython.sh   |  3 +-
 10 files changed, 39 insertions(+), 229 deletions(-)

diff --git a/CEP/Pipeline/framework/lofarpipe/support/control.py b/CEP/Pipeline/framework/lofarpipe/support/control.py
index 60e62d9144c..59eff3b488a 100644
--- a/CEP/Pipeline/framework/lofarpipe/support/control.py
+++ b/CEP/Pipeline/framework/lofarpipe/support/control.py
@@ -34,6 +34,18 @@ class control(StatefulRecipe):
     """
     inputs = {}
 
+    def __init__(self):
+      self.parset = parameterset()
+      self.momID = 0
+      self.sasID = 0
+
+    def usage(self):
+        """
+        Display usage information
+        """
+        print >> sys.stderr, "Usage: %s <parset-file>  [options]" % sys.argv[0]
+        return 1
+
     def send_feedback_processing(self, feedback):
         """
         Send processing feedback information back to LOFAR.
@@ -46,8 +58,8 @@ class control(StatefulRecipe):
           "lofarpipe.support.control",
           "",
           "Processing feedback from the pipeline framework",
-          momID,
-          sasID,
+          self.momID,
+          self.sasID,
           feedback)
 
         bus.sendmsg(msg.qpidMsg())
@@ -64,13 +76,13 @@ class control(StatefulRecipe):
           "lofarpipe.support.control",
           "",
           "Dataproduct feedback from the pipeline framework",
-          momID,
-          sasID,
+          self.momID,
+          self.sasID,
           feedback)
 
         bus.sendmsg(msg.qpidMsg())
 
-    def _send_feedback_status(self, status):
+    def _send_feedback_status(self, momID, sasID, status):
         """
         Send status information back to LOFAR.
 
@@ -83,8 +95,8 @@ class control(StatefulRecipe):
           "lofarpipe.support.control",
           "",
           "Status feedback from the pipeline framework",
-          momID,
-          sasID,
+          self.momID,
+          self.sasID,
           status == 0)
 
         bus.sendmsg(msg.qpidMsg())
@@ -97,6 +109,25 @@ class control(StatefulRecipe):
 
     def go(self):
         super(control, self).go()
+
+        # Read the parset-file that was given as input argument
+        try:
+            parset_file = os.path.abspath(self.inputs['args'][0])
+        except IndexError:
+            return self.usage()
+        self.parset.adoptFile(parset_file)
+        # Set job-name to basename of parset-file w/o extension, if it's not
+        # set on the command-line with '-j' or '--job-name'
+        if not 'job_name' in self.inputs:
+            self.inputs['job_name'] = (
+                os.path.splitext(os.path.basename(parset_file))[0]
+            )
+
+        # Pull several parameters from the parset
+        self.momID = self.parset.getString("Observation.momID", "")
+        self.sasID = self.parset.getString("Observation.ObsID", "")
+
+        # Start the pipeline
         self.logger.info("LOFAR Pipeline (%s) starting." % self.name)
         try:
             self.pipeline_logic()
diff --git a/CEP/Pipeline/recipes/sip/bin/calibration_pipeline.py b/CEP/Pipeline/recipes/sip/bin/calibration_pipeline.py
index 96adf1a2146..733c5dd90cb 100755
--- a/CEP/Pipeline/recipes/sip/bin/calibration_pipeline.py
+++ b/CEP/Pipeline/recipes/sip/bin/calibration_pipeline.py
@@ -36,19 +36,10 @@ class calibration_pipeline(control):
 
     def __init__(self):
         super(calibration_pipeline, self).__init__()
-        self.parset = parameterset()
         self.input_data = {}
         self.output_data = {}
 
 
-    def usage(self):
-        """
-        Display usage
-        """
-        print >> sys.stderr, "Usage: %s [options] <parset-file>" % sys.argv[0]
-        return 1
-
-
     def _get_io_product_specs(self):
         """
         Get input- and output-data product specifications from the
@@ -97,27 +88,6 @@ class calibration_pipeline(control):
             )
 
 
-    def go(self):
-        """
-        Read the parset-file that was given as input argument, and set the
-        jobname before calling the base-class's `go()` method.
-        """
-        try:
-            parset_file = os.path.abspath(self.inputs['args'][0])
-        except IndexError:
-            return self.usage()
-        self.parset.adoptFile(parset_file)
-
-        # Set job-name to basename of parset-file w/o extension, if it's not
-        # set on the command-line with '-j' or '--job-name'
-        if not self.inputs.has_key('job_name'):
-            self.inputs['job_name'] = (
-                os.path.splitext(os.path.basename(parset_file))[0])
-
-        # Call the base-class's `go()` method.
-        return super(calibration_pipeline, self).go()
-
-
     @mail_log_on_exception
     def pipeline_logic(self):
         """
diff --git a/CEP/Pipeline/recipes/sip/bin/imaging_pipeline.py b/CEP/Pipeline/recipes/sip/bin/imaging_pipeline.py
index 7301851da03..269bea6a107 100755
--- a/CEP/Pipeline/recipes/sip/bin/imaging_pipeline.py
+++ b/CEP/Pipeline/recipes/sip/bin/imaging_pipeline.py
@@ -97,7 +97,6 @@ class imaging_pipeline(control):
         Initialize member variables and call superclass init function
         """
         control.__init__(self)
-        self.parset = parameterset()
         self.input_data = DataMap()
         self.target_data = DataMap()
         self.output_data = DataMap()
@@ -105,31 +104,6 @@ class imaging_pipeline(control):
         self.parset_dir = None
         self.mapfile_dir = None
 
-    def usage(self):
-        """
-        Display usage information
-        """
-        print >> sys.stderr, "Usage: %s <parset-file>  [options]" % sys.argv[0]
-        return 1
-
-    def go(self):
-        """
-        Read the parset-file that was given as input argument, and set the
-        jobname before calling the base-class's `go()` method.
-        """
-        try:
-            parset_file = os.path.abspath(self.inputs['args'][0])
-        except IndexError:
-            return self.usage()
-        self.parset.adoptFile(parset_file)
-        # Set job-name to basename of parset-file w/o extension, if it's not
-        # set on the command-line with '-j' or '--job-name'
-        if not 'job_name' in self.inputs:
-            self.inputs['job_name'] = (
-                os.path.splitext(os.path.basename(parset_file))[0]
-            )
-        return super(imaging_pipeline, self).go()
-
     @mail_log_on_exception
     def pipeline_logic(self):
         """
diff --git a/CEP/Pipeline/recipes/sip/bin/long_baseline_pipeline.py b/CEP/Pipeline/recipes/sip/bin/long_baseline_pipeline.py
index c082eeb4b79..9cd14bb78c6 100644
--- a/CEP/Pipeline/recipes/sip/bin/long_baseline_pipeline.py
+++ b/CEP/Pipeline/recipes/sip/bin/long_baseline_pipeline.py
@@ -64,7 +64,6 @@ class msss_imager_pipeline(control):
         Initialize member variables and call superclass init function
         """
         control.__init__(self)
-        self.parset = parameterset()
         self.input_data = DataMap()
         self.target_data = DataMap()
         self.output_data = DataMap()
@@ -72,30 +71,6 @@ class msss_imager_pipeline(control):
         self.parset_dir = None
         self.mapfile_dir = None
 
-    def usage(self):
-        """
-        Display usage information
-        """
-        print >> sys.stderr, "Usage: %s <parset-file>  [options]" % sys.argv[0]
-        return 1
-
-    def go(self):
-        """
-        Read the parset-file that was given as input argument, and set the
-        jobname before calling the base-class's `go()` method.
-        """
-        try:
-            parset_file = os.path.abspath(self.inputs['args'][0])
-        except IndexError:
-            return self.usage()
-        self.parset.adoptFile(parset_file)
-        # Set job-name to basename of parset-file w/o extension, if it's not
-        # set on the command-line with '-j' or '--job-name'
-        if not 'job_name' in self.inputs:
-            self.inputs['job_name'] = (
-                os.path.splitext(os.path.basename(parset_file))[0]
-            )
-        return super(msss_imager_pipeline, self).go()
 
     @mail_log_on_exception
     def pipeline_logic(self):
diff --git a/CEP/Pipeline/recipes/sip/bin/msss_calibrator_pipeline.py b/CEP/Pipeline/recipes/sip/bin/msss_calibrator_pipeline.py
index 20f192fe6cc..893c16ff402 100755
--- a/CEP/Pipeline/recipes/sip/bin/msss_calibrator_pipeline.py
+++ b/CEP/Pipeline/recipes/sip/bin/msss_calibrator_pipeline.py
@@ -48,19 +48,10 @@ class msss_calibrator_pipeline(control):
 
     def __init__(self):
         control.__init__(self)
-        self.parset = parameterset()
         self.input_data = {}
         self.output_data = {}
 
 
-    def usage(self):
-        """
-        Display usage
-        """
-        print >> sys.stderr, "Usage: %s [options] <parset-file>" % sys.argv[0]
-        return 1
-
-
     def _get_io_product_specs(self):
         """
         Get input- and output-data product specifications from the
@@ -109,27 +100,6 @@ class msss_calibrator_pipeline(control):
             )
 
 
-    def go(self):
-        """
-        Read the parset-file that was given as input argument, and set the
-        jobname before calling the base-class's `go()` method.
-        """
-        try:
-            parset_file = os.path.abspath(self.inputs['args'][0])
-        except IndexError:
-            return self.usage()
-        self.parset.adoptFile(parset_file)
-
-        # Set job-name to basename of parset-file w/o extension, if it's not
-        # set on the command-line with '-j' or '--job-name'
-        if not self.inputs.has_key('job_name'):
-            self.inputs['job_name'] = (
-                os.path.splitext(os.path.basename(parset_file))[0])
-
-        # Call the base-class's `go()` method.
-        return super(msss_calibrator_pipeline, self).go()
-
-
     @mail_log_on_exception
     def pipeline_logic(self):
         """
diff --git a/CEP/Pipeline/recipes/sip/bin/msss_imager_pipeline.py b/CEP/Pipeline/recipes/sip/bin/msss_imager_pipeline.py
index 111d759f1f4..29d05237a0f 100755
--- a/CEP/Pipeline/recipes/sip/bin/msss_imager_pipeline.py
+++ b/CEP/Pipeline/recipes/sip/bin/msss_imager_pipeline.py
@@ -93,7 +93,6 @@ class msss_imager_pipeline(control):
         Initialize member variables and call superclass init function
         """
         control.__init__(self)
-        self.parset = parameterset()
         self.input_data = DataMap()
         self.target_data = DataMap()
         self.output_data = DataMap()
@@ -101,30 +100,6 @@ class msss_imager_pipeline(control):
         self.parset_dir = None
         self.mapfile_dir = None
 
-    def usage(self):
-        """
-        Display usage information
-        """
-        print >> sys.stderr, "Usage: %s <parset-file>  [options]" % sys.argv[0]
-        return 1
-
-    def go(self):
-        """
-        Read the parset-file that was given as input argument, and set the
-        jobname before calling the base-class's `go()` method.
-        """
-        try:
-            parset_file = os.path.abspath(self.inputs['args'][0])
-        except IndexError:
-            return self.usage()
-        self.parset.adoptFile(parset_file)
-        # Set job-name to basename of parset-file w/o extension, if it's not
-        # set on the command-line with '-j' or '--job-name'
-        if not 'job_name' in self.inputs:
-            self.inputs['job_name'] = (
-                os.path.splitext(os.path.basename(parset_file))[0]
-            )
-        return super(msss_imager_pipeline, self).go()
 
     @mail_log_on_exception
     def pipeline_logic(self):
diff --git a/CEP/Pipeline/recipes/sip/bin/msss_target_pipeline.py b/CEP/Pipeline/recipes/sip/bin/msss_target_pipeline.py
index 57911053e74..2cf67ccc934 100755
--- a/CEP/Pipeline/recipes/sip/bin/msss_target_pipeline.py
+++ b/CEP/Pipeline/recipes/sip/bin/msss_target_pipeline.py
@@ -48,19 +48,10 @@ class msss_target_pipeline(control):
 
     def __init__(self):
         control.__init__(self)
-        self.parset = parameterset()
         self.input_data = {}
         self.output_data = {}
 
 
-    def usage(self):
-        """
-        Display usage information
-        """
-        print >> sys.stderr, "Usage: %s [options] <parset-file>" % sys.argv[0]
-        return 1
-
-
     def _get_io_product_specs(self):
         """
         Get input- and output-data product specifications from the
@@ -170,28 +161,6 @@ class msss_target_pipeline(control):
             )
 
 
-    def go(self):
-        """
-        Read the parset-file that was given as input argument, and set the
-        jobname before calling the base-class's `go()` method.
-        """
-        try:
-            parset_file = os.path.abspath(self.inputs['args'][0])
-        except IndexError:
-            return self.usage()
-        self.parset.adoptFile(parset_file)
-        
-        # Set job-name to basename of parset-file w/o extension, if it's not
-        # set on the command-line with '-j' or '--job-name'
-        if not self.inputs.has_key('job_name'):
-            self.inputs['job_name'] = (
-                os.path.splitext(os.path.basename(parset_file))[0]
-            )
-
-        # Call the base-class's `go()` method.
-        return super(msss_target_pipeline, self).go()
-
-
     @mail_log_on_exception
     def pipeline_logic(self):
         """
diff --git a/CEP/Pipeline/recipes/sip/bin/preprocessing_pipeline.py b/CEP/Pipeline/recipes/sip/bin/preprocessing_pipeline.py
index 3d6f02ff011..a5f8a75db9e 100755
--- a/CEP/Pipeline/recipes/sip/bin/preprocessing_pipeline.py
+++ b/CEP/Pipeline/recipes/sip/bin/preprocessing_pipeline.py
@@ -30,20 +30,11 @@ class preprocessing_pipeline(control):
 
     def __init__(self):
         super(preprocessing_pipeline, self).__init__()
-        self.parset = parameterset()
         self.input_data = []
         self.output_data = []
         self.io_data_mask = []
 
 
-    def usage(self):
-        """
-        Display usage
-        """
-        print >> sys.stderr, "Usage: %s [options] <parset-file>" % sys.argv[0]
-        return 1
-
-
     def _get_io_product_specs(self):
         """
         Get input- and output-data product specifications from the
@@ -108,27 +99,6 @@ class preprocessing_pipeline(control):
 #                )
 #            )
 
-    def go(self):
-        """
-        Read the parset-file that was given as input argument;
-        set jobname, and input/output data products before calling the
-        base-class's `go()` method.
-        """
-        try:
-            parset_file = os.path.abspath(self.inputs['args'][0])
-        except IndexError:
-            return self.usage()
-        self.parset.adoptFile(parset_file)
-
-        # Set job-name to basename of parset-file w/o extension, if it's not
-        # set on the command-line with '-j' or '--job-name'
-        if not self.inputs.has_key('job_name'):
-            self.inputs['job_name'] = (
-                os.path.splitext(os.path.basename(parset_file))[0])
-
-        # Call the base-class's `go()` method.
-        return super(preprocessing_pipeline, self).go()
-
 
     @mail_log_on_exception
     def pipeline_logic(self):
diff --git a/CEP/Pipeline/recipes/sip/bin/pulsar_pipeline.py b/CEP/Pipeline/recipes/sip/bin/pulsar_pipeline.py
index 98c9e0ca78d..6fd900c3ab7 100755
--- a/CEP/Pipeline/recipes/sip/bin/pulsar_pipeline.py
+++ b/CEP/Pipeline/recipes/sip/bin/pulsar_pipeline.py
@@ -34,31 +34,8 @@ class pulsar_pipeline(control):
 
     def __init__(self):
         super(pulsar_pipeline, self).__init__()
-        self.parset = parameterset()
         self.input_data = {}
         self.output_data = {}
-
-
-    def go(self):
-        """
-        Read the parset-file that was given as input argument;
-        set jobname, and input/output data products before calling the
-        base-class's `go()` method.
-        """
-        try:
-            parset_file = os.path.abspath(self.inputs['args'][0])
-        except IndexError:
-            return self.usage()
-        self.parset.adoptFile(parset_file)
-
-        # Set job-name to basename of parset-file w/o extension, if it's not
-        # set on the command-line with '-j' or '--job-name'
-        if not self.inputs.has_key('job_name'):
-            self.inputs['job_name'] = (
-                os.path.splitext(os.path.basename(parset_file))[0])
-                
-        # Call the base-class's `go()` method.
-        return super(pulsar_pipeline, self).go()
   
 
     def _get_io_product_specs(self):
diff --git a/CEP/Pipeline/recipes/sip/bin/startPython.sh b/CEP/Pipeline/recipes/sip/bin/startPython.sh
index ca3a0327cca..05559079b97 100755
--- a/CEP/Pipeline/recipes/sip/bin/startPython.sh
+++ b/CEP/Pipeline/recipes/sip/bin/startPython.sh
@@ -27,8 +27,7 @@ logFile=/opt/lofar/var/log/startPython.log
 
 usage()
 {
-  echo "Usage: $0 <pythonProgram> <parsetname> <MAC-Python-control-host> \\"
-  echo "         <MAC-Python-control-listener> <MAC-Python-control-server>"
+  echo "Usage: $0 <pythonProgram> <parsetname>"
   exit 1
 }
 
-- 
GitLab