Skip to content
Snippets Groups Projects
Commit 37c04c7a authored by Ruud Overeem's avatar Ruud Overeem
Browse files

Bug 827: Moved StationInfo.h from MAC/APL/APLCommon to LCS/ApplCommon so that...

Bug 827: Moved StationInfo.h from MAC/APL/APLCommon to LCS/ApplCommon so that MAC/Deployment has less dependancies.
parent 39260f80
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -3,7 +3,8 @@ pkginclude_HEADERS = Package__Version.h \
Observation.h \
CableAttenuation.h \
RCUCables.h \
StationConfig.h
StationConfig.h \
StationInfo.h
noinst_HEADERS =
......
//# 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
......@@ -5,7 +5,8 @@ libapplcommon_la_SOURCES = Package__Version.cc \
Observation.cc \
CableAttenuation.cc \
RCUCables.cc \
StationConfig.cc
StationConfig.cc \
StationInfo.cc
BUILT_SOURCES =
......
//# 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
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)
......
//# 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);
}
......@@ -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)
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment