From ec0d3bcd64bfd2a38f17c9ed4807a43c7cb595bb Mon Sep 17 00:00:00 2001 From: Ger van Diepen <diepen@astron.nl> Date: Tue, 1 Jul 2008 13:41:03 +0000 Subject: [PATCH] bug 1172: Needed access to a parset file from a script --- LCS/ACC/APS/src/Makefile.am | 6 ++- LCS/ACC/APS/src/getparsetvalue.cc | 69 +++++++++++++++++++++++++ LCS/ACC/APS/test/Makefile.am | 6 ++- LCS/ACC/APS/test/tgetparsetvalue.parset | 2 + LCS/ACC/APS/test/tgetparsetvalue.run | 12 +++++ LCS/ACC/APS/test/tgetparsetvalue.sh | 2 + LCS/ACC/APS/test/tgetparsetvalue.stdout | 8 +++ 7 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 LCS/ACC/APS/src/getparsetvalue.cc create mode 100644 LCS/ACC/APS/test/tgetparsetvalue.parset create mode 100755 LCS/ACC/APS/test/tgetparsetvalue.run create mode 100755 LCS/ACC/APS/test/tgetparsetvalue.sh create mode 100644 LCS/ACC/APS/test/tgetparsetvalue.stdout diff --git a/LCS/ACC/APS/src/Makefile.am b/LCS/ACC/APS/src/Makefile.am index 1f78ee2d82c..023065e6d2f 100644 --- a/LCS/ACC/APS/src/Makefile.am +++ b/LCS/ACC/APS/src/Makefile.am @@ -6,7 +6,11 @@ libaps_la_SOURCES = Package__Version.cc \ ParameterSet.cc \ ParameterSetImpl.cc -bin_PROGRAMS = versionaps +bin_PROGRAMS = getparsetvalue versionaps + +getparsetvalue_SOURCES = getparsetvalue.cc +getparsetvalue_LDADD = libaps.la +getparsetvalue_DEPENDENCIES = libaps.la $(LOFAR_DEPEND) versionaps_SOURCES = versionaps.cc versionaps_LDADD = libaps.la diff --git a/LCS/ACC/APS/src/getparsetvalue.cc b/LCS/ACC/APS/src/getparsetvalue.cc new file mode 100644 index 00000000000..ce8603f00c7 --- /dev/null +++ b/LCS/ACC/APS/src/getparsetvalue.cc @@ -0,0 +1,69 @@ +//# getparsetvalue.cc: Get a value as a string from a parameter set +//# +//# Copyright (C) 2008 +//# 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 +//# +//# $Id$ + +//# Always #include <lofar_config.h> first! +#include <lofar_config.h> + +#include <APS/ParameterSet.h> +#include <Common/LofarLogger.h> +#include <stdexcept> +#include <iostream> + +int main (int argc, const char* argv[]) +{ + try { + if (argc < 3) { + std::cerr << "Run as: getparsetvalue parsetfile parmname [index]" + << " negative index counts from the end (a la python)" + << std::endl; + return 1; + } + int inx = 0; + bool useAll = true; + if (argc > 3) { + std::istringstream iss(argv[3]); + iss >> inx; + useAll = false; + } + LOFAR::ACC::APS::ParameterSet parset(argv[1]); + if (useAll) { + std::string value = parset.getString (argv[2]); + std::cout << value << std::endl; + } else { + std::vector<std::string> values = parset.getStringVector (argv[2]); + // Negative index is + int i = inx; + if (i < 0) { + i += values.size(); + } + ASSERTSTR (i >= 0 && i < int(values.size()), + "Index " << inx + << " exceeds value size " << values.size() + << " of parameter " << argv[2]); + std::cout << values[i] << std::endl; + } + } catch (std::exception &x) { + std::cerr << x.what() << std::endl; + return 1; + } + return 0; +} diff --git a/LCS/ACC/APS/test/Makefile.am b/LCS/ACC/APS/test/Makefile.am index 1618b3a1236..58cbe1067a5 100644 --- a/LCS/ACC/APS/test/Makefile.am +++ b/LCS/ACC/APS/test/Makefile.am @@ -8,7 +8,8 @@ LDADD = ../src/libaps.la DEPENDENCIES = ../src/libaps.la $(LOFAR_DEPEND) TESTSCRIPTS = tKeyPrefix.sh \ - tParameterSet_test.sh + tParameterSet_test.sh \ + tgetparsetvalue.sh TESTS = $(TESTSCRIPTS) @@ -19,6 +20,9 @@ EXTRA_DIST = tParameterSet.in_merge_nocase \ tParameterSet.in_param_normal \ tParameterSet.log_prop \ tParameterSet.stdout \ + tgetparsetvalue.run \ + tgetparsetvalue.parset \ + tgetparsetvalue.stdout \ $(TESTSCRIPTS) include $(top_srcdir)/Makefile.common diff --git a/LCS/ACC/APS/test/tgetparsetvalue.parset b/LCS/ACC/APS/test/tgetparsetvalue.parset new file mode 100644 index 00000000000..60353d89d28 --- /dev/null +++ b/LCS/ACC/APS/test/tgetparsetvalue.parset @@ -0,0 +1,2 @@ +key1 = [1,2,3] +key1.sub1 = [aa, bb] diff --git a/LCS/ACC/APS/test/tgetparsetvalue.run b/LCS/ACC/APS/test/tgetparsetvalue.run new file mode 100755 index 00000000000..8c805325c1c --- /dev/null +++ b/LCS/ACC/APS/test/tgetparsetvalue.run @@ -0,0 +1,12 @@ +#!/bin/sh + +../src/getparsetvalue tgetparsetvalue.parset key1 +../src/getparsetvalue tgetparsetvalue.parset key1 0 +../src/getparsetvalue tgetparsetvalue.parset key1 1 +../src/getparsetvalue tgetparsetvalue.parset key1 2 +../src/getparsetvalue tgetparsetvalue.parset key1 3 +../src/getparsetvalue tgetparsetvalue.parset key1 -1 +../src/getparsetvalue tgetparsetvalue.parset key1 -2 +../src/getparsetvalue tgetparsetvalue.parset key1 -3 +../src/getparsetvalue tgetparsetvalue.parset key1 -4 +../src/getparsetvalue tgetparsetvalue.parset key1.sub1 diff --git a/LCS/ACC/APS/test/tgetparsetvalue.sh b/LCS/ACC/APS/test/tgetparsetvalue.sh new file mode 100755 index 00000000000..3d37aa06c56 --- /dev/null +++ b/LCS/ACC/APS/test/tgetparsetvalue.sh @@ -0,0 +1,2 @@ +#!/bin/sh +$lofar_sharedir/runtest.sh tgetparsetvalue > tgetparsetvalue.log 2>&1 diff --git a/LCS/ACC/APS/test/tgetparsetvalue.stdout b/LCS/ACC/APS/test/tgetparsetvalue.stdout new file mode 100644 index 00000000000..76bda7d2e75 --- /dev/null +++ b/LCS/ACC/APS/test/tgetparsetvalue.stdout @@ -0,0 +1,8 @@ +[1,2,3] +1 +2 +3 +3 +2 +1 +[aa, bb] -- GitLab