diff --git a/LCS/ApplCommon/configure.in b/LCS/ApplCommon/configure.in index 9b4c9a1da4cdc51221098b65be537d99362afbba..c0b1ad29c979cac882bbc6d49f8e05178f1d59fc 100644 --- a/LCS/ApplCommon/configure.in +++ b/LCS/ApplCommon/configure.in @@ -53,7 +53,7 @@ dnl lofar_GENERAL lofar_MPI lofar_INTERNAL(LCS/Common, Common, , 1, Common/LofarTypes.h,,) -lofar_EXTERNAL(boost,1,boost/date_time/date.hpp, boost_date_time) +lofar_EXTERNAL(boost,1,boost/date_time/date.hpp, "boost_date_time boost_regex") lofar_EXTERNAL(BLITZ,1,blitz/blitz.h,,,,'gnu3:-Wno-unused gnu3:-ftemplate-depth-30',,-lm) dnl diff --git a/LCS/ApplCommon/include/ApplCommon/Makefile.am b/LCS/ApplCommon/include/ApplCommon/Makefile.am index 529d14d1201f61350cb823273be9db056573138a..5e9587e170e7397141ce3bdca616be7fa375ef83 100644 --- a/LCS/ApplCommon/include/ApplCommon/Makefile.am +++ b/LCS/ApplCommon/include/ApplCommon/Makefile.am @@ -3,7 +3,8 @@ pkginclude_HEADERS = Package__Version.h \ Observation.h \ CableAttenuation.h \ RCUCables.h \ - StationConfig.h + StationConfig.h \ + StationInfo.h noinst_HEADERS = diff --git a/LCS/ApplCommon/include/ApplCommon/StationInfo.h b/LCS/ApplCommon/include/ApplCommon/StationInfo.h new file mode 100644 index 0000000000000000000000000000000000000000..60ba3c18b6271c7385e109981098b7641cc9985d --- /dev/null +++ b/LCS/ApplCommon/include/ApplCommon/StationInfo.h @@ -0,0 +1,67 @@ +//# StationInfo.h: Several 'deployment' related routines. +//# +//# Copyright (C) 2006 +//# 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$ + +#ifndef LOFAR_DEPLOYMENT_STATIONINFO_H +#define LOFAR_DEPLOYMENT_STATIONINFO_H + +// \file StationInfo +// Several 'deployment' related routines + +//# Never #include <config.h> or #include <lofar_config.h> in a header file! +//# Includes + +//# Avoid 'using namespace' in headerfiles + +namespace LOFAR { + +// \addtogroup ApplCommon +// @{ + +#define LOFAR_BASE_LOCATION "/opt/lofar" +#define LOFAR_BIN_LOCATION "/opt/lofar/bin" +#define LOFAR_CONFIG_LOCATION "/opt/lofar/etc" +#define LOFAR_SHARE_LOCATION "/opt/lofar/share" +#define LOFAR_LOG_LOCATION "/opt/lofar/log" + +// +// Nameconventions dictate that the hostname has the following syntax: +// +// Syntax of hostname: <stationType><arm><ring><CUtype> +// with: stationType = CS | RS | ES<countrycode> +// arm = 1..5 [ 1 digit ] +// ring = 1..9 [ 2 digits ] +// CUType = C | W +// +int16 stationTypeValue(); // 0..2 : for resp. error, CS, RS, ES +string stationTypeStr(); // CS, RS, ES +string stationRingName(); // Core, Remote, Europe +string PVSSDatabaseName(const string& someName = ""); // hostname w/o CUtype +string realHostname(const string& someName); // adds 'C' when it is missing. + +string PVSS2SASname(const string& PVSSname); // convert PVSS DPname to SAS DPname +string SAS2PVSSname(const string& SASname); // convert SAS DPname to PVSS DPname + + +// @} +} // namespace LOFAR + +#endif diff --git a/LCS/ApplCommon/src/Makefile.am b/LCS/ApplCommon/src/Makefile.am index b0d3e1f61f5c97dd047cc20c9d7a3cc5b5df714f..78de71c2edddf874993ca347d8e65f236c4be970 100644 --- a/LCS/ApplCommon/src/Makefile.am +++ b/LCS/ApplCommon/src/Makefile.am @@ -5,7 +5,8 @@ libapplcommon_la_SOURCES = Package__Version.cc \ Observation.cc \ CableAttenuation.cc \ RCUCables.cc \ - StationConfig.cc + StationConfig.cc \ + StationInfo.cc BUILT_SOURCES = diff --git a/LCS/ApplCommon/src/StationInfo.cc b/LCS/ApplCommon/src/StationInfo.cc new file mode 100644 index 0000000000000000000000000000000000000000..0586596f910ffe8bf163a83925486a3fb7166531 --- /dev/null +++ b/LCS/ApplCommon/src/StationInfo.cc @@ -0,0 +1,219 @@ +//# StationInfo.cc: Several 'deployment' related functions +//# +//# Copyright (C) 2006 +//# 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 <Common/lofar_string.h> +#include <Common/LofarTypes.h> +#include <Common/StringUtil.h> +#include <Common/SystemUtil.h> +#include <ApplCommon/StationInfo.h> + +#include <boost/config.hpp> +#include <boost/lexical_cast.hpp> +#include <boost/regex.hpp> +using namespace boost; + +namespace LOFAR { + +static char* stationTypeTable[] = { "CS", "RS", "ES" }; +static char* ringTypeTable[] = { "Core", "Remote", "Europe" }; + +// +// stationTypeValue() +// +// Returns the stationType (0..2) of the current machine. +// The the returned value is an index in the stationTypeTable or ringTypeTable. +// +int16 stationTypeValue() +{ + string stsType(toUpper(myHostname(false).substr(0,2))); // RS, CS, xx + if (stsType == "CS") { + return (0); + } + if (stsType == "RS") { + return (1); + } + + return (2); +} + + +// +// stationTypeStr() +// +// Returns the unified stationtype (CS | RS | ES). +// +string stationTypeStr() +{ + return (stationTypeTable[stationTypeValue()]); +} + + +// +// stationRingName() +// +// Returns the name of the ring the station belongs to. +// +string stationRingName() +{ + return (ringTypeTable[stationTypeValue()]); +} + +// +// PVSSDatabaseName +// +string PVSSDatabaseName(const string& someName) +{ + string hostname(someName); + if (hostname.empty()) { + hostname = myHostname(false); + } + + // hostname is like <stationtype><arm><ring><CUtype> + // where CUtype = C or W + // strip off CUtype is any to get the PVSS database name + rtrim(hostname, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"); + + return (toUpper(hostname)); +} + +// +// realHostname +// +// In SAS the stationnames are used as hostnames so the last 'C' or 'T' is missing. +// This routine tries to find out if it has to add the C or T to the given hostname. +// +string realHostname(const string& someName) +{ + // if given name ends in a char assume the name is correct. + char someLastChar(*(--(someName.end()))); + if (someLastChar == 'C' || someLastChar == 'T') { + return (someName); + } + + // leaves us with ABC999 and XY999 formats + // when 3rd character is not a digit the name refers to a CEP machine + if (!isdigit(someName[2])) { + return (someName); + } + + // given name must be a stationname. When myhostname ends in a T + // add the T else assume production and add the C + string hostname(toUpper(myHostname(false))); + char myLastChar(*(--(hostname.end()))); + if (myLastChar == 'T') { + return (string(someName+'T')); + } + return (someName+'C'); +} + +// +// PVSS2SASname(PVSSname) +// +// Converts a name of a SAS datapoint to the corresponding PVSS DPname +// +// SAS : LOFAR.PIC.<RING>.<SYSTEM>.xxx +// PVSS: <SYSTEM>:LOFAR_PIC_xxx +// ^ ^ ^ +// | | +-- locationPos + locationLen +// | +-- colon +// +-- systemLen +// +// NOTE: instead of PIC the DPname may contain PermSW or ObsSW_Observation<n> +// +string PVSS2SASname(const string& PVSSname) +{ + const char* structure_match = "(([A-Z]{2,3}[0-9]{3}[A-Z]?):LOFAR_(PIC|PermSW)_)|" // 1,2,3 + "(([A-Z]{2,3}[0-9]{3}[A-Z]?):LOFAR_(PIC|PermSW)\\.)"; // 4,5,6 + const char* location_match = "(RCU[0-9]{3})|" // 1 + "_(CS[0-9]{3}[A-Z]?)_|" // 2 CS999 + "_(RS[0-9]{3}[A-Z]?)_|" // 3 RS999 + "_([ABD-QS-Z][A-Z][0-9]{3}[A-Z]?)_|" // 4 XX999 + "_([A-Z]{3}[0-9]{3}[A-Z]?)_"; // 5 XXX999 + const char* separator_match = "(_)|(\\.)"; + const char* boundary_match = "(^([^_]+)_)"; + + const char* structure_repl = "(?1LOFAR_$3_$2_)" // LOFAR_PIC_RS002 + "(?4LOFAR_$6.)"; // LOFAR_PIC + const char* location_repl = "(?1$&)" // ignore RCU999 + "(?2_Core$&)" + "(?3_Remote$&)" + "(?4_Europe$&)" + "(?5_Control$&)"; + const char* separator_repl = "(?1.)(?2_)"; // swap separators + const char* boundary_repl = "$2."; // reverse separator on object-field edge + + boost::regex strexp, locexp, sepexp, bndexp; + locexp.assign(location_match); + strexp.assign(structure_match); + sepexp.assign(separator_match); + bndexp.assign(boundary_match); + + return (boost::regex_replace( + boost::regex_replace( + boost::regex_replace( + boost::regex_replace( + PVSSname, strexp, structure_repl, boost::match_default | boost::format_all), + locexp, location_repl, boost::match_default | boost::format_all), + sepexp, separator_repl, boost::match_default | boost::format_all), + bndexp, boundary_repl, boost::match_default)); +} + +// +// SAS2PVSSname(SASname) +// +// Converts a name of a SAS datapoint to the corresponding PVSS DPname +// +// PVSS: <SYSTEM>:LOFAR_PIC_xxx +// SAS : LOFAR.PIC.<RING>.<SYSTEM>.xxx +// ^ ^ ^ +// | | +-- systemPos + systemLen +// | +-- ringPos +// +-- locationPos + locationLen +// +// NOTE: instead of PIC the DPname may contain PermSW +// +string SAS2PVSSname(const string& SASname) +{ + const char* structure_match = "(LOFAR\\.(PIC|PermSW)\\.(Core|Remote|Europe|Control)\\.([A-Z]{2}[0-9]{3})\\.)"; // 1,2,3 + const char* separator_match = "(_)|(\\.)"; + const char* boundary_match = "(\\.([^\\.]+))$"; + + const char* structure_repl = "(?1$4\\:LOFAR\\.$2\\.)"; // RS002:LOFAR_PIC + const char* separator_repl = "(?1.)(?2_)"; // swap separators + const char* boundary_repl = "_$2"; // reverse separator on object-field edge + + boost::regex strexp, sepexp, bndexp; + strexp.assign(structure_match); + sepexp.assign(separator_match); + bndexp.assign(boundary_match); + + return (boost::regex_replace( + boost::regex_replace( + boost::regex_replace( + SASname, strexp, structure_repl, boost::match_default | boost::format_all), + bndexp, boundary_repl, boost::match_default), + sepexp, separator_repl, boost::match_default | boost::format_all)); + } + +} // namespace LOFAR diff --git a/LCS/ApplCommon/test/Makefile.am b/LCS/ApplCommon/test/Makefile.am index 3f08691b8cd27014e69e22770fa8574ee588ac77..2e12f1d874ae0a98b62f2dc34a8579f4b83369c8 100755 --- a/LCS/ApplCommon/test/Makefile.am +++ b/LCS/ApplCommon/test/Makefile.am @@ -1,4 +1,4 @@ -check_PROGRAMS = tObservation tCableAttenuation tRCUCables +check_PROGRAMS = tObservation tCableAttenuation tRCUCables tStationInfo TESTSCRIPTS = tObservation.sh tCableAttenuation.sh tRCUCables.sh @@ -16,6 +16,10 @@ tRCUCables_SOURCES = tRCUCables.cc tRCUCables_LDADD = ../src/libapplcommon.la $(LOFAR_DEPEND) tRCUCables_DEPENCIES = ../src/libapplcommon.la $(LOFAR_DEPEND) +tStationInfo_SOURCES = tStationInfo.cc +tStationInfo_LDADD = ../src/libapplcommon.la $(LOFAR_DEPEND) +tStationInfo_DEPENCIES = ../src/libapplcommon.la $(LOFAR_DEPEND) + EXTRA_DIST = tObservation.log_prop tObservation.parset \ tObservation.stdout \ $(TESTSCRIPTS) diff --git a/LCS/ApplCommon/test/tStationInfo.cc b/LCS/ApplCommon/test/tStationInfo.cc new file mode 100644 index 0000000000000000000000000000000000000000..aa6bae37cf0858356547f17fe148dd55e549772e --- /dev/null +++ b/LCS/ApplCommon/test/tStationInfo.cc @@ -0,0 +1,72 @@ +//# tStationInfo.cc +//# +//# Copyright (C) 2002-2004 +//# 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> + +//# Includes +#include <Common/LofarLogger.h> +#include <Common/SystemUtil.h> +#include <ApplCommon/StationInfo.h> +#include <boost/regex.hpp> + +using namespace LOFAR; + +int main (int argc, char* argv[]) +{ + INIT_LOGGER(argv[0]); + + LOG_INFO_STR("myHostname(short) = " << myHostname(false)); + LOG_INFO_STR("myHostname(long) = " << myHostname(true)); + LOG_INFO_STR("ringName = " << stationRingName()); + LOG_INFO_STR("PVSSDBname = " << PVSSDatabaseName()); + LOG_INFO_STR("hostname of CS010 = " << realHostname("CS010")); + LOG_INFO_STR("hostname of CS010C = " << realHostname("CS010C")); + LOG_INFO_STR("hostname of CS010T = " << realHostname("CS010T")); + + LOG_INFO_STR("PVSS==>SAS(RS002:LOFAR_PIC_Cabinet0_Subrack0.status.state) = " << + PVSS2SASname("RS002:LOFAR_PIC_Cabinet0_Subrack0.status.state")); + LOG_INFO_STR("PVSS==>SAS(MCU001:LOFAR_PermSW.status.state) = " << + PVSS2SASname("MCU001:LOFAR_PermSW.status.state")); + LOG_INFO_STR("PVSS==>SAS(RS002:LOFAR_PermSW.status.state) = " << + PVSS2SASname("RS002:LOFAR_PermSW.status.state")); + LOG_INFO_STR("PVSS==>SAS(MCU001:LOFAR_PermSW_MACScheduler.status.state) = " << + PVSS2SASname("MCU001:LOFAR_PermSW_MACScheduler.status.state")); + LOG_INFO_STR("PVSS==>SAS(MCU001:LOFAR_ObsSW_Observation5_ObservationControl.status.state) = " << + PVSS2SASname("MCU001:LOFAR_ObsSW_Observation5_ObservationControl.status.state")); + LOG_INFO_STR("PVSS==>SAS(RS002:LOFAR_ObsSW_Observation5.antennaArray) = " << + PVSS2SASname("RS002:LOFAR_ObsSW_Observation5.antennaArray")); + LOG_INFO_STR("PVSS==>SAS(RS002:LOFAR_ObsSW_Observation5_BeamControl.status.state) = " << + PVSS2SASname("RS002:LOFAR_ObsSW_Observation5_BeamControl.status.state")); + + LOG_INFO_STR("SAS==>PVSS(LOFAR.PIC.Remote.RS002.Cabinet0.Subrack0.status_state) = " << + SAS2PVSSname("LOFAR.PIC.Remote.RS002.Cabinet0.Subrack0.status_state")); + LOG_INFO_STR("SAS==>PVSS(LOFAR.PermSW.Remote.RS002.ServiceBroker.status_state) = " << + SAS2PVSSname("LOFAR.PermSW.Remote.RS002.ServiceBroker.status_state")); + LOG_INFO_STR("SAS==>PVSS(LOFAR.PermSW.Control.MCU001.MACScheduler.status_state) = " << + SAS2PVSSname("LOFAR.PermSW.Control.MCU001.MACScheduler.status_state")); + LOG_INFO_STR("SAS==>PVSS(LOFAR.ObsSW.Observation.VirtualInstrument.stationList) = " << + SAS2PVSSname("LOFAR.ObsSW.Observation.VirtualInstrument.stationList")); + + return (0); +} + diff --git a/MAC/Deployment/configure.in b/MAC/Deployment/configure.in index 5d816952d196fd34e9958c9c59b1ccc1654d8b9d..f15f09a3d9e58ab1db4240162d2ac72becb0b9fd 100644 --- a/MAC/Deployment/configure.in +++ b/MAC/Deployment/configure.in @@ -52,9 +52,9 @@ dnl Check for LOFAR general things dnl lofar_GENERAL lofar_INTERNAL(LCS/Common,Common,,1,Common/LofarTypedefs.h,,) +lofar_INTERNAL(LCS/ApplCommon,ApplCommon,,1,ApplCommon/Observation.h,,) lofar_INTERNAL(SAS/OTDB,OTDB,,1,OTDB/OTDBtypes.h,,) -lofar_INTERNAL(MAC/APL/APLCommon,APLCommon,,1,APL/APLCommon/StationInfo.h,,) -lofar_EXTERNAL(boost,1,boost/date_time/date.hpp, boost_date_time) +lofar_EXTERNAL(boost,1,boost/date_time/date.hpp, "boost_date_time boost_regex") lofar_EXTERNAL(pqxx,2.5.5,pqxx/pqxx, pqxx) lofar_EXTERNAL(pq,,libpq-fe.h, pq, /usr/local/pgsql) diff --git a/MAC/Deployment/data/bin/PVSS2SAS.cc b/MAC/Deployment/data/bin/PVSS2SAS.cc index 6219b3ce6fa9d3e5261c4c708b77413900889bb1..8f071d6447c883eab77bffeb374f473095cb4cc5 100644 --- a/MAC/Deployment/data/bin/PVSS2SAS.cc +++ b/MAC/Deployment/data/bin/PVSS2SAS.cc @@ -27,9 +27,9 @@ #include <ostream> using namespace std; #include <Common/LofarTypes.h> -#include <APL/APLCommon/StationInfo.h> +#include <ApplCommon/StationInfo.h> -using namespace LOFAR::APLCommon; +using namespace LOFAR; int main (int argc, char* argv[]) { string input;