From 4021a191909aeeb72364fa0ce4310ef31bbdb257 Mon Sep 17 00:00:00 2001
From: Martin Gels <gels@astron.nl>
Date: Wed, 24 Oct 2007 11:22:09 +0000
Subject: [PATCH] BugID:1005

Checked in first version of the file scripts.

Modified consist of integration with SAS/MAC.
---
 .../src/CS1_DelayCompensation.log_prop        |  29 +++--
 .../CS1_DelayCompensation/src/DelayAppl.sh    | 119 ++++++++++++++++++
 .../src/prepare_CS1_DelayCompensation.py      | 114 +++++++++++++++++
 .../CS1/CS1_DelayCompensation/src/startAP.sh  |  24 ++++
 .../CS1/CS1_DelayCompensation/src/stopAP.sh   |  10 ++
 5 files changed, 284 insertions(+), 12 deletions(-)
 create mode 100755 Appl/CEP/CS1/CS1_DelayCompensation/src/DelayAppl.sh
 create mode 100755 Appl/CEP/CS1/CS1_DelayCompensation/src/prepare_CS1_DelayCompensation.py
 create mode 100755 Appl/CEP/CS1/CS1_DelayCompensation/src/startAP.sh
 create mode 100755 Appl/CEP/CS1/CS1_DelayCompensation/src/stopAP.sh

diff --git a/Appl/CEP/CS1/CS1_DelayCompensation/src/CS1_DelayCompensation.log_prop b/Appl/CEP/CS1/CS1_DelayCompensation/src/CS1_DelayCompensation.log_prop
index c622a5b0d7b..f3544f42d99 100644
--- a/Appl/CEP/CS1/CS1_DelayCompensation/src/CS1_DelayCompensation.log_prop
+++ b/Appl/CEP/CS1/CS1_DelayCompensation/src/CS1_DelayCompensation.log_prop
@@ -1,20 +1,25 @@
-# add your custom loggers and appenders here
-#
 
-log4cplus.rootLogger=DEBUG, STDOUT, FILE
-
-log4cplus.logger.TRC=DEBUG
-log4cplus.additivity.TRC=false
+# Configure the loggers
+log4cplus.rootLogger=INFO, STDOUT, FILE
+#log4cplus.logger.TRC=INFO
+log4cplus.logger.TRC=INFO
+log4cplus.logger.LCS.Common=FATAL, STDOUT, FILE
 
+# Define the appenders
 log4cplus.appender.STDOUT=log4cplus::ConsoleAppender
 log4cplus.appender.STDOUT.layout=log4cplus::PatternLayout
-log4cplus.appender.STDOUT.layout.ConversionPattern=%D{%d-%m-%y %H:%M:%S.%q} %-5p %c{9} - %m [%.25l]%n
-log4cplus.appender.STDOUT.logToStdErr=false
+log4cplus.appender.STDOUT.layout.ConversionPattern=%D{%d-%m %H:%M:%S.%q} %-5p %c{9} - %m [%.25l]%n
+
+log4cplus.appender.STDERR=log4cplus::ConsoleAppender
+log4cplus.appender.STDERR.layout=log4cplus::PatternLayout
+log4cplus.appender.STDERR.layout.ConversionPattern=%D{%d-%m %H:%M:%S.%q} %-5p %c{3} - %m [%.25l]%n
+log4cplus.appender.STDERR.logToStdErr=true
 
 log4cplus.appender.FILE=log4cplus::RollingFileAppender
-log4cplus.appender.FILE.File=/dev/null
-log4cplus.appender.FILE.MaxFileSize=5MB
-log4cplus.appender.FILE.MaxBackupIndex=5
+log4cplus.appender.FILE.File=../log/%filename.log
+log4cplus.appender.FILE.MaxFileSize=10MB
+log4cplus.appender.FILE.MaxBackupIndex=2
 log4cplus.appender.FILE.layout=log4cplus::PatternLayout
-log4cplus.appender.FILE.layout.ConversionPattern=%D{%d-%m-%y %H:%M:%S.%q} %-5p %c{3} - %m [%.25l]%n
+log4cplus.appender.FILE.layout.ConversionPattern=%x %D{%d-%m %H:%M:%S.%q} %-5p %c{3} - %m [%.25l]%n
 
+log4cplus.appender.DUMP=log4cplus::NullAppender
diff --git a/Appl/CEP/CS1/CS1_DelayCompensation/src/DelayAppl.sh b/Appl/CEP/CS1/CS1_DelayCompensation/src/DelayAppl.sh
new file mode 100755
index 00000000000..aab7e243e2f
--- /dev/null
+++ b/Appl/CEP/CS1/CS1_DelayCompensation/src/DelayAppl.sh
@@ -0,0 +1,119 @@
+#!/bin/bash
+#
+# /DelayAppl: a start/stop/status script for swlevel
+#
+# Copyright (C) 2007
+# ASTRON (Netherlands Foundation for Research in Astronomy)
+# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+#
+# Syntax: DelayAppl start|stop|status
+#
+# $Id$
+#
+
+#
+# SyntaxError msg
+#
+SyntaxError()
+{
+	Msg=$1
+
+	[ -z "${Msg}" ] || echo "ERROR: ${Msg}"
+	echo ""
+	echo "Syntax: $(basename $0) start | stop | status"
+	echo ""
+	exit 1
+}
+
+#
+# Start the program when it exists
+#
+start_prog()
+{
+	# put here your code to start your program
+	echo 'start_prog()'
+}
+
+#
+# Stop the program when it is running
+#
+stop_prog()
+{
+	# put here your code to stop your program
+	ps -ef | grep -v grep | grep -v ACDaemon[^\ ] | grep ACDaemon 2>&1 >/dev/null
+	if [ $? -ne 0 ]; then
+	  if [ -f ../etc/ACD.admin ]; then 	
+	    rm ../etc/ACD.admin
+	  fi
+	fi  
+	cexec killall -9 CS1_DelayCompensation 
+}
+
+#
+# show status of program
+#
+# arg1 = levelnr
+#
+status_prog()
+{
+	levelnr=$1
+
+	# put here code to figure out the status of your program and
+	# fill the variables prog and pid with the right information
+
+	# e.g.
+	prog=DelayAppl
+	pid=DOWN
+	cexec 'ps -ef | grep -v grep '| grep CS1_DelayCompensation| grep -v bash 2>$1 1>/dev/null
+	if [ $? -eq 0 ]; then
+	  cexec 'ps -ef | grep -v grep | grep CS1_DelayCompensation'| grep -v bash | awk -v levelnr=${levelnr} '{
+          if (substr($1,1,3) == "---") {
+            machine = substr($2,1,7)
+          }
+          else {
+            if (substr($1,1,3) != "***") {
+              fullname="DelayAppl@"machine
+              printf "%s : %-25.25s %s\n", levelnr,fullname,$2
+            }
+          }
+        }'
+	else
+          # this line should be left in, it shows the status in the right format
+	  echo ${levelnr} ${prog} ${pid} | awk '{ printf "%s : %-25s %s\n", $1, $2, $3 }'
+	fi
+}
+
+#
+# MAIN
+#
+
+# when no argument is given show syntax error.
+if [ -z "$1" ]; then
+	SyntaxError
+fi
+
+# first power down to this level
+case $1 in
+	start)	start_prog
+			;;
+	stop)	stop_prog
+			;;
+	status)	status_prog $2
+			;;
+	*)		SyntaxError
+			;;
+esac
diff --git a/Appl/CEP/CS1/CS1_DelayCompensation/src/prepare_CS1_DelayCompensation.py b/Appl/CEP/CS1/CS1_DelayCompensation/src/prepare_CS1_DelayCompensation.py
new file mode 100755
index 00000000000..5b842c9f97d
--- /dev/null
+++ b/Appl/CEP/CS1/CS1_DelayCompensation/src/prepare_CS1_DelayCompensation.py
@@ -0,0 +1,114 @@
+#!/usr/bin/env python
+
+import math
+import time
+import datetime
+import os
+import sys
+import copy
+
+class CS1_Parset(object):
+
+    def __init__(self):
+        self.stationList = list()
+	self.parameters = dict()
+
+    def readFromFile(self, fileName):
+        lastline = ''
+        for line in open(fileName, 'r').readlines():
+            lastline = lastline + line.split('#')[0]
+            lastline = lastline.rstrip()
+            if len(lastline) > 0 and lastline[-1] == '\\':
+                lastline = lastline[:-1]
+            elif '=' in lastline:
+                key, value = lastline.split('=')
+                self.parameters[key.strip()] = value.strip()
+                lastline = ''
+
+    def writeToFile(self, fileName):
+        outf = open(fileName, 'w')
+        for key, value in sorted(self.parameters.iteritems()):
+            outf.write(key + ' = ' + str(value) + '\n')
+        outf.close()
+
+    def __contains__(self, key):
+        return key in self.parameters
+        
+    def __setitem__(self, key, value):
+        self.parameters[key] = value
+
+    def __getitem__(self, key):
+        return self.parameters[key]
+
+    def getInt32Vector(self, key):
+        ln = self.parameters[key]
+	ln_tmp = ln.split('[')
+        line = 	ln_tmp[1].split(']')
+        return [int(lp) for lp in line[0].split(',')]
+
+    def getInt32(self, key):
+        return int(self.parameters[key])
+
+    def getStringVector(self, key):
+        line = self.parameters[key]
+        line.strip('[').strip(']')
+        return line.split(',')
+
+    def getString(self, key):
+        return self.parameters[key]
+
+    def getFloat(self, key):
+        return float(self.parameters[key])
+
+	
+if __name__ == '__main__':
+
+    # create the parset
+    parset = CS1_Parset() 
+    stationList = list()
+    
+    if os.path.exists("../share/DelayCompensation.parset"):
+       
+        #read keys from parset file: Transpose.parset
+        parset.readFromFile('../share/DelayCompensation.parset')
+
+        '''
+        if parset.getString('OLAP.OLAP_Conn.station_Input_Transport') == 'NULL':
+            # Read from memory!
+            parset['Observation.startTime'] = datetime.datetime.fromtimestamp(1)
+        else:
+            start=int(time.time() + 90)
+            parset['Observation.startTime'] = datetime.datetime.fromtimestamp(start)
+	
+	duration = 300
+
+        parset['Observation.stopTime'] = datetime.datetime.fromtimestamp(start + duration) 
+        '''
+
+	if parset.getString('OLAP.OLAP_Conn.input_DelayComp_Transport') == 'Null':
+	    parset['OLAP.OLAP_Conn.input_DelayComp_Transport']	 = 'NULL'
+	    
+	if parset.getString('OLAP.OLAP_Conn.input_BGLProc_Transport') == 'Null':
+	    parset['OLAP.OLAP_Conn.input_BGLProc_Transport']	 = 'NULL'
+	    
+	if parset.getString('OLAP.OLAP_Conn.station_Input_Transport') == 'Null':
+	    parset['OLAP.OLAP_Conn.station_Input_Transport']	 = 'NULL'
+
+	if parset.getString('OLAP.OLAP_Conn.BGLProc_Storage_Transport') == 'Null':
+	    parset['OLAP.OLAP_Conn.BGLProc_Storage_Transport']	 = 'NULL'
+	
+	#get the stations
+	stationList = parset.getStringVector('OLAP.storageStationNames')
+	parset['OLAP.nrRSPboards'] = len(stationList)
+	
+        if parset.getInt32('Observation.sampleClock') == 160:
+	    parset['OLAP.BGLProc.integrationSteps'] = 608
+        elif parset.getInt32('Observation.sampleClock') == 200:
+	    parset['OLAP.BGLProc.integrationSteps'] = 768
+	
+	parset.writeToFile('../share/DelayCompensation.parset')
+	    
+    else:
+        print '../share/DelayCompensation.parset does not exist!'
+        sys.exit(0) 	
+	
diff --git a/Appl/CEP/CS1/CS1_DelayCompensation/src/startAP.sh b/Appl/CEP/CS1/CS1_DelayCompensation/src/startAP.sh
new file mode 100755
index 00000000000..660c2173320
--- /dev/null
+++ b/Appl/CEP/CS1/CS1_DelayCompensation/src/startAP.sh
@@ -0,0 +1,24 @@
+# startAP.sh nodename procID executable paramfile
+#
+# $1 jobName             identifier for this job
+# $2 machinefile         procID.machinefile
+# $3 executable          processname
+# $4 parameterfile       procID.ps
+# $5 numberOfNodes
+#
+# start the given executable and creates a corresponding pid file for stopping the process.
+#
+
+# now all ACC processes expect to be started with "ACC" as first parameter
+
+./prepare_$3.py
+
+# start process
+# TODO: in future something like: rsh $1 start_script $2 $3 $4
+./$3 ACC $4 $1>>/opt/lofar/log/$3.log 2>&1 & 
+
+# get its pid
+pid=`echo $!`
+
+# construct pid file for stop shell
+echo "$pid" > $2.pid
diff --git a/Appl/CEP/CS1/CS1_DelayCompensation/src/stopAP.sh b/Appl/CEP/CS1/CS1_DelayCompensation/src/stopAP.sh
new file mode 100755
index 00000000000..60b2cd7bfea
--- /dev/null
+++ b/Appl/CEP/CS1/CS1_DelayCompensation/src/stopAP.sh
@@ -0,0 +1,10 @@
+# stopAP.sh nodename procID 
+#
+# nodename		    hostname[.domain]
+# procID			processname<nr>
+#
+# Stops the given process by killing the process whose pid is in the
+# proces.pid file.
+
+kill -9 `cat $2.pid`
+rm -f $2.pid $2.ps
-- 
GitLab