diff --git a/CEP/Tools/Generator/include/Generator/AH_Generator.h b/CEP/Tools/Generator/include/Generator/AH_Generator.h new file mode 100644 index 0000000000000000000000000000000000000000..098f1e48275b17bd592a35a2391de03696f96b7b --- /dev/null +++ b/CEP/Tools/Generator/include/Generator/AH_Generator.h @@ -0,0 +1,60 @@ +//# AH_Generator.h: Application that generates data (and emulates an RSP board) +//# +//# 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_GENERATOR_AH_GENERATOR_H +#define LOFAR_GENERATOR_AH_GENERATOR_H + +// \file +// Data generator + +//# Never #include <config.h> or #include <lofar_config.h> in a header file! + +//# Includes +#include <CEPFrame/ApplicationHolder.h> +#include <Transport/TransportHolder.h> + +namespace LOFAR +{ + namespace Generator + { + + // \addtogroup Generator + // @{ + + class AH_Generator: public LOFAR::ApplicationHolder + { + public: + AH_Generator(); + virtual ~AH_Generator(); + virtual void undefine(); + virtual void define (const LOFAR::KeyValueMap&); + virtual void run (int nsteps); + private: + vector<TransportHolder*> itsTHs; + }; + + // @} + + } // namespace Generator +} // namespace LOFAR + +#endif diff --git a/CEP/Tools/Generator/include/Generator/AH_Recorder.h b/CEP/Tools/Generator/include/Generator/AH_Recorder.h new file mode 100644 index 0000000000000000000000000000000000000000..a1005d86638db4f404414ef805681cfeebc35a5d --- /dev/null +++ b/CEP/Tools/Generator/include/Generator/AH_Recorder.h @@ -0,0 +1,60 @@ +//# AH_Recorder.h: Application that records data +//# +//# 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_GENERATOR_AH_RECORDER_H +#define LOFAR_GENERATOR_AH_RECORDER_H + +// \file +// Application that records data + +//# Never #include <config.h> or #include <lofar_config.h> in a header file! + +//# Includes +#include <CEPFrame/ApplicationHolder.h> +#include <Transport/TransportHolder.h> + +namespace LOFAR +{ + namespace Generator + { + + // \addtogroup Generator + // @{ + + class AH_Recorder: public LOFAR::ApplicationHolder + { + public: + AH_Recorder(); + virtual ~AH_Recorder(); + virtual void undefine(); + virtual void define (const LOFAR::KeyValueMap&); + virtual void run (int nsteps); + private: + vector<TransportHolder*> itsTHs; + }; + + // @} + + } // namespace Generator +} // namespace LOFAR + +#endif diff --git a/CEP/Tools/Generator/include/Generator/DH_RSP.h b/CEP/Tools/Generator/include/Generator/DH_RSP.h new file mode 100644 index 0000000000000000000000000000000000000000..24f7fdf9477f29e0a3c9cb7b12757674faa3b2e9 --- /dev/null +++ b/CEP/Tools/Generator/include/Generator/DH_RSP.h @@ -0,0 +1,86 @@ +//# DH_RSP.h: This DataHolders holds the data a RSP-board will output +//# +//# 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_GENERATOR_DH_RSP_H +#define LOFAR_GENERATOR_DH_RSP_H + +// \file +// This DataHolders holds the data a RSP-board will output + +//# Never #include <config.h> or #include <lofar_config.h> in a header file! + +//# Includes +#include <APS/ParameterSet.h> +#include <Transport/DataHolder.h> +#include <Generator/RSPEthFrame.h> + +namespace LOFAR +{ + namespace Generator + { + + // \addtogroup Generator + // @{ + + //# Forward Declarations + //class forward; + + + // Description of class. + class DH_RSP : public DataHolder + { + public: + typedef u16complex DataType; + + explicit DH_RSP(const string& name, + const ACC::APS::ParameterSet& pset); + + DH_RSP(const DH_RSP&); + + virtual ~DH_RSP(); + + DataHolder* clone() const; + + /// Allocate the buffers. + virtual void init(); + + // Access methods + Frame* getFrame() const { return itsFrame;}; + + private: + // forbid assignment + DH_RSP& operator= (const DH_RSP& that); + + // Fill the pointers (itsBuffer) to the data in the blob. + virtual void fillDataPointers(); + //# Datamembers + + Frame* itsFrame; + ACC::APS::ParameterSet itsPSet; + }; + + // @} + + } // namespace Generator +} // namespace LOFAR + +#endif diff --git a/CEP/Tools/Generator/include/Generator/Makefile.am b/CEP/Tools/Generator/include/Generator/Makefile.am index 1404614163a8707ff09fb85a8856ddb0aa33bd17..4def80df528a65b68e417b03710cb80542ca6f46 100644 --- a/CEP/Tools/Generator/include/Generator/Makefile.am +++ b/CEP/Tools/Generator/include/Generator/Makefile.am @@ -2,7 +2,8 @@ # SUBDIRS = shmem . # endif -INSTHDRS = RSPTimeStamp.h \ +INSTHDRS = Signals.h \ + RSPTimeStamp.h \ WH_FakeStation.h \ WH_Signal.h \ WH_Wrap.h \ diff --git a/CEP/Tools/Generator/include/Generator/RSPEthFrame.h b/CEP/Tools/Generator/include/Generator/RSPEthFrame.h new file mode 100644 index 0000000000000000000000000000000000000000..5670d33d24de673e3df7bd336359214450bb3102 --- /dev/null +++ b/CEP/Tools/Generator/include/Generator/RSPEthFrame.h @@ -0,0 +1,155 @@ +//# RSPEthFrame.h: classes to hold the data from a station +//# +//# 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_GENERATOR_RSPETHFRAME_H +#define LOFAR_GENERATOR_RSPETHFRAME_H + +// \file +// classes to hold the data from a station + +//# Never #include <config.h> or #include <lofar_config.h> in a header file! + +//# Includes +#include <Common/lofar_complex.h> +#include <APS/ParameterSet.h> +#include <Generator/RSPTimeStamp.h> + +namespace LOFAR +{ + namespace Generator + { + + // \addtogroup Generator + // @{ + + //# Forward Declarations + //class forward; + + typedef i16complex RSPDataType; + + // Header is the class that represents the header data of the epa packet + // it contains the following fields: + // protocol(int32) + // stationId(int32) + // sequenceId(int32) + // blockId(int32) + // This class can only be used on little endian machines because the RSPdata is little endian + class Header + { + public: + explicit Header(char* bufferSpace, const int size) { + ASSERTSTR(size == theirSize, "Header did not receive the right amount of memory"); + itsBufferp = bufferSpace; + itsProtp = reinterpret_cast<int*>(itsBufferp); + itsStationIDp = reinterpret_cast<int*>(itsBufferp + theirStatIDOffset); + itsSeqIDp = reinterpret_cast<int*>(itsBufferp + theirSeqIDOffset); + itsBlockIDp = reinterpret_cast<int*>(itsBufferp + theirBlockIDOffset); + }; + ~Header() {}; + + int32 getProtocol() const { return *itsProtp;}; + void setProtocol(int32 newProt) { *itsProtp = newProt;}; + int32 getStationId() const { return *itsStationIDp;}; + void setStationId(int32 newSid) { *itsStationIDp = newSid;}; + int32 getSeqId() const { return *itsSeqIDp;}; + int32 getBlockId() const { return *itsBlockIDp;}; + void setSeqId(int32 newSeqId) { *itsSeqIDp = newSeqId;}; + void setBlockId(int32 newBlockId) { *itsBlockIDp = newBlockId;}; + static int getSize() { return theirSize;}; + protected: + char* itsBufferp; + int* itsProtp; + int* itsStationIDp; + int* itsSeqIDp; + int* itsBlockIDp; + + static const int theirSize = 16; + static const int theirStatIDOffset = 4; + static const int theirSeqIDOffset = 8; + static const int theirBlockIDOffset = 12; + }; + + class Data + { + public: + explicit Data(RSPDataType* bufferSpace, const unsigned int size, const ACC::APS::ParameterSet& ps) { + itsNPol = ps.getInt32("NPolarisations"); + itsNSubbands = ps.getInt32("NSubbands"); + itsNTimes = ps.getInt32("NTimesPerFrame"); + ASSERTSTR(itsNPol * itsNSubbands * itsNTimes * sizeof(RSPDataType) == size, "Data did not receive the right amount of memory"); + itsBeamlets = bufferSpace; + }; + ~Data() {}; + + RSPDataType& getBeamlet(int seq, int subband, int pol) const { return itsBeamlets[pol + subband * itsNPol + seq * itsNPol * itsNSubbands]; }; + void clear() { memset(itsBeamlets, 0, itsNPol * itsNSubbands * itsNTimes * sizeof(RSPDataType));}; + int getNPols() const {return itsNPol;}; + int getNSubbands() const {return itsNSubbands;}; + int getNTimes() const {return itsNTimes;}; + + static int getSize(const ACC::APS::ParameterSet& ps) { + return ps.getInt32("NPolarisations") + * ps.getInt32("NSubbands") + * ps.getInt32("NTimesPerFrame") + * sizeof(RSPDataType); }; + + protected: + RSPDataType* itsBeamlets; + + int itsNPol; + int itsNSubbands; + int itsNTimes; + }; + + class Frame + { + public: + Frame(char* bufferP, + const int size, + const ACC::APS::ParameterSet& ps) : + itsHeader(bufferP, Header::getSize()), + itsData(reinterpret_cast<RSPDataType*>(bufferP + Header::getSize()), + size - Header::getSize(), + ps) + {}; + ~Frame() {}; + + Data* getData() { return &itsData;}; + Header* getHeader() { return &itsHeader;}; + char* getBufferp() { return itsBufferp; }; + int getSize() { return itsSize;}; + + static int getSize(const ACC::APS::ParameterSet& ps) { return Header::getSize() + Data::getSize(ps);}; + + private: + Header itsHeader; + Data itsData; + char* itsBufferp; + int itsSize; + }; + + // @} + + } // namespace Generator +} // namespace LOFAR + +#endif diff --git a/CEP/Tools/Generator/include/Generator/RSPTimeStamp.h b/CEP/Tools/Generator/include/Generator/RSPTimeStamp.h new file mode 100644 index 0000000000000000000000000000000000000000..3e2b4db0f556938596c8602c9d9731794f7c5a80 --- /dev/null +++ b/CEP/Tools/Generator/include/Generator/RSPTimeStamp.h @@ -0,0 +1,158 @@ +//# RSPTimeStamp.h: Small class to hold the timestamps from RSP +//# +//# 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_GENERATOR_RSPTIMESTAMP_H +#define LOFAR_GENERATOR_RSPTIMESTAMP_H + +// \file +// Small class to hold the timestamps from RSP + +//# Never #include <config.h> or #include <lofar_config.h> in a header file! + +//# Includes + +namespace LOFAR +{ + namespace Generator + { + + // \addtogroup Generator + // @{ + + class TimeStamp { + public: + TimeStamp(const int seqId = 0, const int blockId = 0); + + // set the Stamp + void setStamp(const int seqId, const int blockId); + // get sequence ID + const int getSeqId () const; + // get block ID + const int getBlockId () const; + static int getMaxBlockId() {return theirMaxBlockId; }; + static void setMaxBlockId(int nMBID) {theirMaxBlockId = nMBID; }; + + // the blockId restarts at zero at some point. Check if we are there yet + void checkOverflow(); + + // increase the value of the stamp + void operator+= (const TimeStamp& other); + void operator+= (int increment); + void operator++ (int); + + TimeStamp operator+ (int other) const; + long long operator- (const TimeStamp& other) const; + TimeStamp operator- (int other) const; + bool operator> (const TimeStamp& other) const; + bool operator< (const TimeStamp& other) const; + bool operator>= (const TimeStamp& other) const; + bool operator<= (const TimeStamp& other) const; + bool operator== (const TimeStamp& other) const; + + friend ostream& operator<<(ostream& os, const TimeStamp& ss); + + private: + int itsSeqId; + int itsBlockId; + + static int theirMaxBlockId; + }; + + typedef TimeStamp timestamp_t; + + inline void TimeStamp::setStamp(const int seqId, const int blockId) + { itsSeqId = seqId; itsBlockId = blockId; checkOverflow(); }; + + inline const int TimeStamp::getSeqId () const + { return itsSeqId; } + + inline const int TimeStamp::getBlockId () const + { return itsBlockId; } + + inline void TimeStamp::operator += (const TimeStamp& other) + { + itsBlockId += other.itsBlockId; + checkOverflow(); + itsSeqId += other.itsSeqId; + } + inline void TimeStamp::operator += (int increment) + { + itsBlockId += increment; + checkOverflow(); + } + + inline void TimeStamp::operator ++ (int) + { + itsBlockId ++; + checkOverflow(); + } + + inline TimeStamp TimeStamp::operator+ (int increment) const + { + // check overflow is done in the constructor + return TimeStamp(itsSeqId, itsBlockId + increment); + } + inline TimeStamp TimeStamp::operator- (int decrement) const + { + // check overflow is done in the constructor + return TimeStamp(itsSeqId, itsBlockId - decrement); + } + + inline long long TimeStamp::operator- (const TimeStamp& other) const + { + long long seqdecr = itsSeqId - other.itsSeqId; + int blockdecr = itsBlockId - other.itsBlockId; + + return (seqdecr*theirMaxBlockId) + blockdecr; + } + + inline bool TimeStamp::operator > (const TimeStamp& other) const + { + if (itsSeqId > other.itsSeqId) return true; + if (itsSeqId < other.itsSeqId) return false; + if (itsBlockId > other.itsBlockId) return true; + return false; + } + inline bool TimeStamp::operator >= (const TimeStamp& other) const + { return !operator<(other); } + + inline bool TimeStamp::operator < (const TimeStamp& other) const + { + if (itsSeqId < other.itsSeqId) return true; + if (itsSeqId > other.itsSeqId) return false; + if (itsBlockId < other.itsBlockId) return true; + return false; + } + inline bool TimeStamp::operator <= (const TimeStamp& other) const + { return !operator>(other); } + + inline bool TimeStamp::operator == (const TimeStamp& other) const + { + return ((itsSeqId == other.itsSeqId) && (itsBlockId == other.itsBlockId)); + } + + // @} + + } // namespace Generator +} // namespace LOFAR + +#endif diff --git a/CEP/Tools/Generator/include/Generator/Signals.h b/CEP/Tools/Generator/include/Generator/Signals.h new file mode 100644 index 0000000000000000000000000000000000000000..6b2e42531b95d1d37432b1547d7d2afdb38294bc --- /dev/null +++ b/CEP/Tools/Generator/include/Generator/Signals.h @@ -0,0 +1,117 @@ +//# Signals.h: contains several signal generators +//# +//# 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_GENERATOR_SIGNALS_H +#define LOFAR_GENERATOR_SIGNALS_H + +// \file +// Signal generators (several classes) + +//# Never #include <config.h> or #include <lofar_config.h> in a header file! + +//# Includes +#include <Generator/RSPEthFrame.h> + +namespace LOFAR +{ + namespace Generator + { + + // Description of class. + class Signal + { + public: + typedef float SignalTime; + Signal() + {}; + virtual ~Signal() {}; + + virtual void fillNext(Data* dataptr) = 0; + + private: + // Copying is not allowed + Signal (const Signal& that); + Signal& operator= (const Signal that); + + //# Datamembers + }; + + // This signal only produces zeros + class Sig_Zero : public Signal + { + public: + Sig_Zero() + {}; + ~Sig_Zero() {}; + + void fillNext(Data* dataptr); + }; + + // This signal only produces random numbers + class Sig_Random : public Signal + { + public: + Sig_Random() + {}; + ~Sig_Random() {}; + + int16 randint16() { + int32 value = rand() - RAND_MAX / 2; + // we need to return a int16 with 12 used bits + // so divide by 2^20 + return value / 1048576 ; + }; + + void fillNext(Data* dataptr); + }; + + // This signal produces the sum of several monochrome signals + // It is only written in the first subband + class Sig_MultiChrome : public Signal + { + public: + struct SignalInfo{ + public: + double amplitude; + double frequency; + double phase; + }; + + Sig_MultiChrome(vector<SignalInfo> info, double deltaT) : + itsSignals(info), + itsDeltaPhase(2 * M_PI * deltaT) + {}; + ~Sig_MultiChrome() {}; + + void fillNext(Data* dataptr); + + private: + vector<SignalInfo> itsSignals; + double itsDeltaPhase; // This is 2*pi*deltaT + }; + + // @} + + } // namespace Generator +} // namespace LOFAR + +#endif diff --git a/CEP/Tools/Generator/include/Generator/WH_FakeStation.h b/CEP/Tools/Generator/include/Generator/WH_FakeStation.h new file mode 100644 index 0000000000000000000000000000000000000000..18dc8f8d6d5e9500af490d1eda46476a92a0a3eb --- /dev/null +++ b/CEP/Tools/Generator/include/Generator/WH_FakeStation.h @@ -0,0 +1,85 @@ +//# WH_FakeStation.h: Emulate a station +//# +//# 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_GENERATOR_WH_FAKESTATION_H +#define LOFAR_GENERATOR_WH_FAKESTATION_H + +// \file +// Emulate a station + +//# Never #include <config.h> or #include <lofar_config.h> in a header file! + +//# Includes +#include <tinyCEP/WorkHolder.h> +#include <APS/ParameterSet.h> +#include <Transport/TransportHolder.h> +#include <Generator/RSPEthFrame.h> + +namespace LOFAR +{ + namespace Generator + { + + // \addtogroup Generator + // @{ + + using ACC::APS::ParameterSet; + + class WH_FakeStation: public WorkHolder + { + public: + + explicit WH_FakeStation(const string& name, + const ParameterSet ps, + const int StationID, + const int delay, + TransportHolder* th); + virtual ~WH_FakeStation(); + + static WorkHolder* construct(const string& name, + const ParameterSet ps, + const int StationID, + const int delay, + TransportHolder* th); + virtual WH_FakeStation* make(const string& name); + + virtual void preprocess(); + virtual void process(); + + private: + /// forbid copy constructor + WH_FakeStation (const WH_FakeStation&); + /// forbid assignment + WH_FakeStation& operator= (const WH_FakeStation&); + + ParameterSet itsPS; + int itsStationId; + int itsDelay; + TransportHolder* itsTH; + }; + + // @} + + } // namespace Generator +} // namespace LOFAR + +#endif diff --git a/CEP/Tools/Generator/include/Generator/WH_Signal.h b/CEP/Tools/Generator/include/Generator/WH_Signal.h new file mode 100644 index 0000000000000000000000000000000000000000..b2c0b2a31e8208962377e3d548c6f19a4c3b5317 --- /dev/null +++ b/CEP/Tools/Generator/include/Generator/WH_Signal.h @@ -0,0 +1,90 @@ +//# WH_Signal.h: Create a signal +//# +//# 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_GENERATOR_WH_SIGNAL_H +#define LOFAR_GENERATOR_WH_SIGNAL_H + +// \file +// Create a signal + +//# Never #include <config.h> or #include <lofar_config.h> in a header file! + +//# Includes +#include <tinyCEP/WorkHolder.h> +#include <APS/ParameterSet.h> +#include <Transport/TransportHolder.h> +#include <Generator/DH_RSP.h> +#include <Generator/Signals.h> + +namespace LOFAR +{ + namespace Generator + { + + // \addtogroup Generator + // @{ + + using ACC::APS::ParameterSet; + + class WH_Signal: public WorkHolder + { + public: + + explicit WH_Signal(const string& name, + const int noOutputs, + const ParameterSet ps); + virtual ~WH_Signal(); + + static WorkHolder* construct(const string& name, + const int noOutputs, + const ParameterSet ps); + virtual WH_Signal* make(const string& name); + + virtual void preprocess(); + virtual void process(); + virtual void postprocess(); + + //handle timer alarm + static void timerSignal(int signal); + + private: + /// forbid copy constructor + WH_Signal (const WH_Signal&); + /// forbid assignment + WH_Signal& operator= (const WH_Signal&); + + ParameterSet itsPS; + double itsFrequency; + TimeStamp itsStamp; + Signal* itsSignal; + + static int theirNoRunningWHs; + static int theirNoAlarms; + static bool theirTimerSet; + }; + + // @} + + } // namespace Generator +} // namespace LOFAR + +#endif diff --git a/CEP/Tools/Generator/src/AH_Generator.cc b/CEP/Tools/Generator/src/AH_Generator.cc new file mode 100644 index 0000000000000000000000000000000000000000..672bb52336e4a43e009afd8585040af806b4eb48 --- /dev/null +++ b/CEP/Tools/Generator/src/AH_Generator.cc @@ -0,0 +1,139 @@ +//# AH_Generator.cc: one line description +//# +//# 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> + +//# Includes +#include <Common/LofarLogger.h> +#include <Generator/AH_Generator.h> +#include <Common/lofar_iostream.h> +#include <APS/ParameterSet.h> +#include <CEPFrame/Step.h> + +// Transporters +#include <Transport/TH_Mem.h> +#include <Transport/TH_File.h> +#include <Transport/TH_Ethernet.h> +// Workholders +#include <tinyCEP/WorkHolder.h> +#include <Generator/WH_Signal.h> +#include <Generator/WH_FakeStation.h> + +namespace LOFAR { + namespace Generator { + + AH_Generator::AH_Generator() + { + } + + AH_Generator::~AH_Generator() + { + this->undefine(); + } + + void AH_Generator::undefine() { + vector<TransportHolder*>::iterator tit = itsTHs.begin(); + for (; tit!=itsTHs.end(); tit++) { + delete *tit; + } + itsTHs.clear(); + } + + void AH_Generator::define(const LOFAR::KeyValueMap&) { + LOG_TRACE_FLOW_STR("Start of AH_Generator::define()"); + undefine(); + + LOG_TRACE_FLOW_STR("Create the top-level composite"); + Composite comp(0, 0, "topComposite"); + setComposite(comp); // tell the ApplicationHolder this is the top-level compisite + + LOG_TRACE_FLOW_STR("Create output side interface stubs"); + // todo: define this input interface; although there are no + // connection involved, we do have to define the port/IP numbering schemes + + int NRSP = itsParamSet.getInt32("Data.NStations"); + int WH_DH_NameSize = 40; + char WH_DH_Name[WH_DH_NameSize]; + bool useEth = itsParamSet.getBool("Generator.UseEth"); + vector<string> outFileNames = itsParamSet.getStringVector("Generator.OutputFiles"); + vector<string> interfaces = itsParamSet.getStringVector("Generator.Interfaces"); + vector<string> dstMacs = itsParamSet.getStringVector("Input.DestinationMacs"); + vector<string> srcMacs = itsParamSet.getStringVector("Input.SourceMacs"); + vector<int32> stationIds = itsParamSet.getInt32Vector("Generator.StationIds"); + vector<int32> delays = itsParamSet.getInt32Vector("Generator.StationDelays"); + + snprintf(WH_DH_Name, WH_DH_NameSize, "Signal"); + + Step signalStep(new WH_Signal(WH_DH_Name, + NRSP, + itsParamSet), + WH_DH_Name); + comp.addBlock(signalStep); + + for (int s=0; s<NRSP; s++) { + snprintf(WH_DH_Name, WH_DH_NameSize, "FakeStation_%d_of_%d", s, NRSP); + if (useEth) { + // cout<<"interface: "<<interfaces[s]<<" remote: "<<dstMacs[s]<<" own: "<<srcMacs[s]<<endl; + itsTHs.push_back(new TH_Ethernet(interfaces[s], + dstMacs[s], + srcMacs[s])); + } else { + itsTHs.push_back(new TH_File(outFileNames[s], TH_File::Write)); + } + ASSERTSTR(itsTHs.back()->init(), "Could not init TransportHolder"); + Step stationStep(new WH_FakeStation(WH_DH_Name, + itsParamSet, + stationIds[s], + delays[s], + itsTHs.back()), + WH_DH_Name); + // share input and output DH, no cyclic buffer + stationStep.setInBufferingProperties(0, true, true); + + comp.addBlock(stationStep); + stationStep.connect(0, &signalStep, s, 1, + new TH_Mem(), + false); + + snprintf(WH_DH_Name, WH_DH_NameSize, "Strip_%d_of_%d", s, NRSP); + }; + +#ifdef HAVE_MPI + // TODO How do we want to distribute the steps across the nodes? + // ASSERTSTR (lastFreeNode == TH_MPI::getNumberOfNodes(), lastFreeNode << " nodes needed, "<<TH_MPI::getNumberOfNodes()<<" available"); +#endif + + LOG_TRACE_FLOW_STR("Finished defineGenerator()"); + } + + void AH_Generator::run(int steps) { + LOG_TRACE_FLOW_STR("Start AH_Generator::run() " ); + for (int i = 0; i < steps; i++) { + LOG_TRACE_LOOP_STR("processing run " << i ); + getComposite().process(); + } + LOG_TRACE_FLOW_STR("Finished AH_Generator::run() " ); + } + + } // namespace Generator +} // namespace LOFAR diff --git a/CEP/Tools/Generator/src/AH_Recorder.cc b/CEP/Tools/Generator/src/AH_Recorder.cc new file mode 100644 index 0000000000000000000000000000000000000000..a7e2e1208fdd7db1fd84d45b7c742b4b51385b79 --- /dev/null +++ b/CEP/Tools/Generator/src/AH_Recorder.cc @@ -0,0 +1,154 @@ +//# AH_Recorder.cc: one line description +//# +//# 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> + +//# Includes +#include <Common/LofarLogger.h> +#include <Generator/AH_Recorder.h> +#include <Common/lofar_iostream.h> +#include <APS/ParameterSet.h> +#include <CEPFrame/Step.h> + +// Transporters +#include <Transport/TH_Mem.h> +#include <Transport/TH_MPI.h> +#include <Transport/TH_File.h> +#include <Transport/TH_Null.h> +#include <Transport/TH_Ethernet.h> +// Workholders +#include <tinyCEP/WorkHolder.h> +#include <Generator/WH_Signal.h> +#include <Generator/WH_FakeStation.h> + +namespace LOFAR { + namespace Generator { + + AH_Recorder::AH_Recorder() + { + } + + AH_Recorder::~AH_Recorder() + { + this->undefine(); + } + + void AH_Recorder::undefine() { + vector<TransportHolder*>::iterator tit = itsTHs.begin(); + for (; tit!=itsTHs.end(); tit++) { + delete *tit; + } + itsTHs.clear(); + } + + void AH_Recorder::define(const LOFAR::KeyValueMap&) { + LOG_TRACE_FLOW_STR("Start of AH_Recorder::define()"); + undefine(); + + LOG_TRACE_FLOW_STR("Create the top-level composite"); + Composite comp(0, 0, "topComposite"); + setComposite(comp); // tell the ApplicationHolder this is the top-level compisite + + int lastFreeNode = 0; +#ifdef HAVE_MPICH + // mpich tries to run the first process on the local node + // this is necessary if you want to use totalview + // scampi run the first process on the first node in the machinefile + lastFreeNode = 1; +#endif + + int NRSP = itsParamSet.getInt32("Data.NStations"); + int WH_DH_NameSize = 40; + char WH_DH_Name[WH_DH_NameSize]; + vector<string> outFileNames = itsParamSet.getStringVector("Generator.OutputFiles"); + vector<string> interfaces = itsParamSet.getStringVector("Input.Interfaces"); + vector<string> dstMacs = itsParamSet.getStringVector("Input.DestinationMacs"); + vector<string> srcMacs = itsParamSet.getStringVector("Input.SourceMacs"); + int bufferSize = itsParamSet.getInt32("Generator.RecordBufferSize"); + + snprintf(WH_DH_Name, WH_DH_NameSize, "Signal"); + +#if 0 + for (int s=0; s<NRSP; s++) { + //itsTHs.push_back(new TH_File("Generator1.in", TH_File::Read)); + cout<<"Creating TH_Ethernet: "<<srcMacs[s]<<" -> "<<dstMacs[s]<<endl; + +#if 0 + itsTHs.push_back(new TH_Null()); +#else + itsTHs.push_back(new TH_Ethernet(interfaces[s], + srcMacs[s], + dstMacs[s], + 1048576)); +#endif + Step inStep(&WH_Wrap(WH_DH_Name, + *itsTHs.back(), + itsParamSet), + WH_DH_Name); + inStep.setOutBuffer(0, false, bufferSize); + comp.addBlock(inStep); + inStep.runOnNode(lastFreeNode++); + + itsTHs.push_back(new TH_File(outFileNames[s], TH_File::Write)); + + Step outStep(&WH_Strip(WH_DH_Name, + *itsTHs.back(), + itsParamSet), + WH_DH_Name); + comp.addBlock(outStep); + outStep.runOnNode(lastFreeNode++); + +#ifdef HAVE_MPI + // this needs to be done with MPI, so if we don't have MPI do nothing + outStep.connect(0, inStep, 0, 1, + TH_MPI(inStep->getNode(), + outStep->getNode()), + true); +#else + ASSERTSTR(false, "This application is supposed to be run with MPI"); +#endif + } +#endif + // This program was written to run with MPI. All workholders run in their own process. + // The machinefile should contain every node name twice, so WH_Wrap and WH_Strip run on + // the same physical host. +#ifdef HAVE_MPI + ASSERTSTR (lastFreeNode == TH_MPI::getNumberOfNodes(), lastFreeNode << " nodes needed, "<<TH_MPI::getNumberOfNodes()<<" available"); +#else + ASSERTSTR(false, "This application is supposed to be run with MPI"); +#endif + + LOG_TRACE_FLOW_STR("Finished defineRecorder()"); + } + + void AH_Recorder::run(int steps) { + LOG_TRACE_FLOW_STR("Start AH_Recorder::run() " ); + for (int i = 0; i < steps; i++) { + LOG_TRACE_LOOP_STR("processing run " << i ); + getComposite().process(); + } + LOG_TRACE_FLOW_STR("Finished AH_Recorder::run() " ); + } + + } // namespace Generator +} // namespace LOFAR diff --git a/CEP/Tools/Generator/src/DH_RSP.cc b/CEP/Tools/Generator/src/DH_RSP.cc new file mode 100644 index 0000000000000000000000000000000000000000..571b58e149673ac7cbdf0847f68e4dda40c6d070 --- /dev/null +++ b/CEP/Tools/Generator/src/DH_RSP.cc @@ -0,0 +1,69 @@ +//# DH_RSP.cc: one line description +//# +//# 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> + +//# Includes +#include <Common/LofarLogger.h> +#include <Generator/DH_RSP.h> + +namespace LOFAR { + namespace Generator { + + DH_RSP::DH_RSP (const string& name, + const ACC::APS::ParameterSet& pset) + : DataHolder (name, "DH_RSP"), + itsFrame (0), + itsPSet (pset) + {} + + DH_RSP::DH_RSP(const DH_RSP& that) + : DataHolder (that), + itsFrame (0), + itsPSet (that.itsPSet) + {} + + DH_RSP::~DH_RSP() + {} + + DataHolder* DH_RSP::clone() const + { + return new DH_RSP(*this); + } + + void DH_RSP::init() + { + // Add the fields to the data definition. + addField ("Frame", BlobField<char>(1, Frame::getSize(itsPSet))); + // Create the data blob + createDataBlock(); + } + + void DH_RSP::fillDataPointers() + { + itsFrame = new Frame(getData<char>("Frame"), Frame::getSize(itsPSet), itsPSet); + itsFrame->getData()->clear(); + } + + } // namespace Generator +} // namespace LOFAR diff --git a/CEP/Tools/Generator/src/Generator_main.cc b/CEP/Tools/Generator/src/Generator_main.cc new file mode 100644 index 0000000000000000000000000000000000000000..dc943f2f5410dd3aad1b8037f9db185a25889ac9 --- /dev/null +++ b/CEP/Tools/Generator/src/Generator_main.cc @@ -0,0 +1,37 @@ +//# Generator_main.cc: +//# +//# 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$ + +#include <lofar_config.h> + +#include <PLC/ACCmain.h> +#include <Common/LofarLogger.h> +#include <tinyCEP/ApplicationHolderController.h> +#include <Generator/AH_Generator.h> + +using namespace LOFAR; +using namespace LOFAR::Generator; + +int main(int argc, char **argv) { + INIT_LOGGER("Generator"); + + AH_Generator myAH; + ApplicationHolderController myAHController(myAH); + return ACC::PLC::ACCmain(argc, argv, &myAHController); +} diff --git a/CEP/Tools/Generator/src/Makefile.am b/CEP/Tools/Generator/src/Makefile.am index d9264476df2b6a66973767010a33040807b22e09..75ff09e0baa5035e450cfb0c0316aaea7d76b6dd 100644 --- a/CEP/Tools/Generator/src/Makefile.am +++ b/CEP/Tools/Generator/src/Makefile.am @@ -1,14 +1,13 @@ lib_LTLIBRARIES = libgenerator.la -libgenerator_la_SOURCES = RSPTimeStamp.cc \ - WH_FakeStation.cc \ - WH_Signal.cc \ - WH_Wrap.cc \ - WH_Strip.cc \ - AH_Recorder.cc \ - AH_Generator.cc \ - DH_RSP.cc +libgenerator_la_SOURCES = Signals.cc \ + RSPTimeStamp.cc \ + WH_FakeStation.cc \ + WH_Signal.cc \ + AH_Recorder.cc \ + AH_Generator.cc \ + DH_RSP.cc bin_PROGRAMS = Recorder Generator diff --git a/CEP/Tools/Generator/src/RSPTimeStamp.cc b/CEP/Tools/Generator/src/RSPTimeStamp.cc new file mode 100644 index 0000000000000000000000000000000000000000..0bc7f4c08476b7736f008b07c10286d36b73d4ba --- /dev/null +++ b/CEP/Tools/Generator/src/RSPTimeStamp.cc @@ -0,0 +1,60 @@ +//# RSPTimeStamp.cc: Small class to hold the timestamps from RSP +//# +//# 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> + +//# Includes +#include <Common/LofarLogger.h> +#include <Generator/RSPTimeStamp.h> + +namespace LOFAR { + namespace Generator { + + int TimeStamp::theirMaxBlockId = 156250; + + TimeStamp::TimeStamp(const int seqId, const int blockId) + :itsSeqId(seqId), + itsBlockId(blockId) + { + checkOverflow(); + } + + void TimeStamp::checkOverflow() { + if (itsBlockId >= theirMaxBlockId) { + int newBlockId = itsBlockId % theirMaxBlockId; + itsSeqId += itsBlockId / theirMaxBlockId; + itsBlockId = newBlockId; + } else if (itsBlockId < 0) { + int newBlockId = (itsBlockId % theirMaxBlockId) + theirMaxBlockId; + itsSeqId += -1 + itsBlockId / theirMaxBlockId; + itsBlockId = newBlockId; + }; + } + + ostream& operator<<(ostream& os, const TimeStamp& ss){ + os<<ss.itsSeqId<<" s: "<<ss.itsBlockId; + return os; + } + + } // namespace Generator +} // namespace LOFAR diff --git a/CEP/Tools/Generator/src/Recorder_main.cc b/CEP/Tools/Generator/src/Recorder_main.cc new file mode 100644 index 0000000000000000000000000000000000000000..98136a53b8c500b944eafaf5a05dd41eed22a962 --- /dev/null +++ b/CEP/Tools/Generator/src/Recorder_main.cc @@ -0,0 +1,37 @@ +//# Recorder_main.cc: +//# +//# 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$ + +#include <lofar_config.h> + +#include <PLC/ACCmain.h> +#include <Common/LofarLogger.h> +#include <tinyCEP/ApplicationHolderController.h> +#include <Generator/AH_Recorder.h> + +using namespace LOFAR; +using namespace LOFAR::Generator; + +int main(int argc, char **argv) { + INIT_LOGGER("Recorder"); + + AH_Recorder myAH; + ApplicationHolderController myAHController(myAH); + return ACC::PLC::ACCmain(argc, argv, &myAHController); +} diff --git a/CEP/Tools/Generator/src/Signals.cc b/CEP/Tools/Generator/src/Signals.cc new file mode 100644 index 0000000000000000000000000000000000000000..6caeb2ff54726a61df6486a005437a2035ba8aa3 --- /dev/null +++ b/CEP/Tools/Generator/src/Signals.cc @@ -0,0 +1,66 @@ +//# Signals.cc: one line description +//# +//# 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> + +//# Includes +#include <Common/LofarLogger.h> +#include <Generator/Signals.h> + +namespace LOFAR { + namespace Generator { + + void Sig_Zero::fillNext(Data* dataptr) + { + memset(&dataptr->getBeamlet(0, 0, 0), + 0, + dataptr->getNTimes() * dataptr->getNPols() * dataptr->getNSubbands() * sizeof(RSPDataType)); + } + + void Sig_Random::fillNext(Data* dataptr) + { + RSPDataType* p = &dataptr->getBeamlet(0, 0, 0); + for (int i = 0; i < dataptr->getNTimes() * dataptr->getNSubbands() * dataptr->getNPols(); i ++) { + p[i] = makei16complex(randint16(), randint16()); + } + } + + void Sig_MultiChrome::fillNext(Data* dataptr) + { + for (int time = 0; time < dataptr->getNTimes(); time++) { + double totSinus = 0; + double totCosinus = 0; + vector<SignalInfo>::iterator sig; + for (sig = itsSignals.begin(); sig != itsSignals.end(); sig++) { + sig->phase += itsDeltaPhase * sig->frequency; + double s, c; + sincos(sig->phase, &s, &c); + totSinus += sig->amplitude * s; + totCosinus += sig->amplitude * c; + } + dataptr->getBeamlet(time, 0, 0) = makei16complex(static_cast<int>(totCosinus), static_cast<int>(totSinus)); + } + } + + } // namespace Generator +} // namespace LOFAR diff --git a/CEP/Tools/Generator/src/WH_FakeStation.cc b/CEP/Tools/Generator/src/WH_FakeStation.cc new file mode 100644 index 0000000000000000000000000000000000000000..117b5161d0edf1a533459b17e73d5573bf1bd1c1 --- /dev/null +++ b/CEP/Tools/Generator/src/WH_FakeStation.cc @@ -0,0 +1,101 @@ +//# WH_FakeStation.cc: Emulate a station +//# +//# 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> + +//# Includes +#include <Common/LofarLogger.h> +#include <Transport/TransportHolder.h> +#include <Generator/WH_FakeStation.h> +#include <Generator/DH_RSP.h> +#include <Generator/RSPTimeStamp.h> + +// This WH can be used with CEPFrame or tinyCEP, but to be able +// to test if we are in CEPFrame, we need to include DataManager.h +#include <CEPFrame/DataManager.h> + +namespace LOFAR { + namespace Generator { + + WH_FakeStation::WH_FakeStation(const string& name, + const ParameterSet ps, + const int stationID, + const int delay, + TransportHolder* th) + : WorkHolder (1, 1, + name, + "WH_FakeStation"), + itsPS(ps), + itsDelay(delay), + itsTH(th) + { + itsStationId = stationID; + getDataManager().addInDataHolder(0, new DH_RSP("incoming_DH_RSP", itsPS)); + getDataManager().addOutDataHolder(0, new DH_RSP("outgoing_DH_RSP", itsPS)); + } + + WH_FakeStation::~WH_FakeStation() { + } + + WorkHolder* WH_FakeStation::construct(const string& name, + const ParameterSet ps, + const int stationID, + const int delay, + TransportHolder* th) + { + return new WH_FakeStation(name, ps, stationID, delay, th); + } + + WH_FakeStation* WH_FakeStation::make(const string& name) + { + return new WH_FakeStation(name, itsPS, itsStationId, itsDelay, itsTH); + } + + void WH_FakeStation::preprocess() { + DataManager* dm = dynamic_cast<DataManager*> (&getDataManager()); + ASSERTSTR(dm, "WH_FakeStation only works in CEPFrame, not tinyCEP. This is because we need shared input and output DHs."); + itsTH->init(); + } + + void WH_FakeStation::process() + { + Frame& myEthFrame = *((DH_RSP*)getDataManager().getInHolder(0))->getFrame(); + TimeStamp myStamp; + + Header& myHeader = *myEthFrame.getHeader(); + myHeader.setStationId(itsStationId); + // get the stamp + myStamp.setStamp(myHeader.getSeqId(), myHeader.getBlockId()); + // add the delay + myStamp += itsDelay; + // set the stamp + myHeader.setSeqId(myStamp.getSeqId()); + myHeader.setBlockId(myStamp.getBlockId()); + + if (itsTH != 0) { + itsTH->sendBlocking(myEthFrame.getBufferp(), myEthFrame.getSize(), 0); + } + } + + } // namespace Generator +} // namespace LOFAR diff --git a/CEP/Tools/Generator/src/WH_Signal.cc b/CEP/Tools/Generator/src/WH_Signal.cc new file mode 100644 index 0000000000000000000000000000000000000000..adac895f8d65150085490a4db3369413daa956e6 --- /dev/null +++ b/CEP/Tools/Generator/src/WH_Signal.cc @@ -0,0 +1,183 @@ +//# WH_Signal.cc: Create a signal +//# +//# 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> + +//# Includes +#include <Common/LofarLogger.h> +#include <Generator/WH_Signal.h> +// for timer +#include <signal.h> +#include <sys/time.h> +// for sleep (yield) +#include <boost/thread.hpp> + +namespace LOFAR { + namespace Generator { + + int WH_Signal::theirNoRunningWHs = 0; + int WH_Signal::theirNoAlarms = 0; + bool WH_Signal::theirTimerSet = 0; + + WH_Signal::WH_Signal(const string& name, + const int noOutputs, + const ParameterSet ps) + : WorkHolder (0, noOutputs, + name, + "WH_Signal"), + itsPS(ps), + itsSignal(0) + { + itsFrequency = ps.getDouble("Generator.OutputRate") / ps.getInt32("Input.NPacketsInFrame"); + double deltaT = 1 / ps.getDouble("Generator.SampleFreq"); + + string signalType = ps.getString("Generator.SignalType"); + if (signalType == "RANDOM") { + itsSignal = new Sig_Random(); + } else if (signalType == "MULTICHROME") { + int noFreqs = ps.getInt32("Generator.NFreqs"); + vector<Sig_MultiChrome::SignalInfo> signals; + char key[60]; + for (int f = 0; f < noFreqs; f++) + { + Sig_MultiChrome::SignalInfo s; + snprintf(key, 60, "Generator.Signals.%d.Amplitude", f); + s.amplitude = ps.getDouble(key); + snprintf(key, 60, "Generator.Signals.%d.Frequency", f); + s.frequency = ps.getDouble(key); + snprintf(key, 60, "Generator.Signals.%d.Phase", f); + s.phase = ps.getDouble(key); + signals.push_back(s); + } + + itsSignal = new Sig_MultiChrome(signals, deltaT); + } else { + // send zeros by default + itsSignal = new Sig_Zero(); + } + + for (int outDH = 0; outDH < noOutputs; outDH++) { + getDataManager().addOutDataHolder(outDH, new DH_RSP("signal_out", itsPS)); + } + } + + WH_Signal::~WH_Signal() { + delete itsSignal; + } + + WorkHolder* WH_Signal::construct(const string& name, + const int noOutputs, + const ParameterSet ps) + { + return new WH_Signal(name, noOutputs, ps); + } + + WH_Signal* WH_Signal::make(const string& name) + { + return new WH_Signal(name, itsNoutputs, itsPS); + } + + void WH_Signal::preprocess() + { + if (itsFrequency == 0) { + // frequency was set to zero, which means output should go as fast as possible + // we do that by setting theirNoAlarms to the number of runs + theirNoAlarms += itsPS.getInt32("Generator.NoRuns"); + } else { + if (!theirTimerSet) { + sighandler_t ret = signal(SIGALRM, *WH_Signal::timerSignal); + ASSERTSTR(ret != SIG_ERR, "WH_Signal couldn't set signal handler for timer"); + struct itimerval value; + memset (&value, 0, sizeof(itimerval)); + + double time = 1/itsFrequency; + time_t secs = static_cast<time_t>(floor(time)); + time_t usecs = static_cast<time_t>(1e6 * (time - secs)); + // this means 1MHz is the highest frequency + if (secs + usecs == 0) usecs = 1; + value.it_interval.tv_sec = secs; + value.it_interval.tv_usec = usecs; + value.it_value.tv_sec = secs; + value.it_value.tv_usec = usecs; + cout << "Setting timer interval to " << secs << "secs and " << usecs << "ms" << endl; + + setitimer(ITIMER_REAL, &value, 0); + + theirTimerSet = true; + } + } + theirNoRunningWHs++; + } + + + void WH_Signal::process() + { + Frame& myEthFrame = *((DH_RSP*)getDataManager().getOutHolder(0))->getFrame(); + //myEthFrame.reset(); + Header& header = *myEthFrame.getHeader(); + header.setProtocol(0xAAAB); + header.setSeqId(itsStamp.getSeqId()); + header.setBlockId(itsStamp.getBlockId()); + + itsSignal->fillNext(myEthFrame.getData()); + + int timerCount = 0; + while (theirNoAlarms == 0) + { + timerCount ++; + // wait for alarm to go off + boost::thread::yield(); + }; + cout<<"yield was called "<< timerCount << " times"<<endl; + + // we handled one alarm, so decrease it + theirNoAlarms--; + itsStamp += myEthFrame.getData()->getNTimes(); + } + + void WH_Signal::postprocess() + { + theirNoRunningWHs--; + if (theirNoRunningWHs == 0) + { + theirTimerSet = false; + if (itsFrequency != 0) { + // unset timer + struct itimerval value; + memset (&value, 0, sizeof(itimerval)); + setitimer(ITIMER_REAL, &value, 0); + // remove sig handler + sighandler_t ret = signal(SIGALRM, SIG_DFL); + ASSERTSTR(ret != SIG_ERR, "WH_Signal couldn't unset signal handler for timer"); + } + } + } + + void WH_Signal::timerSignal(int sig) + { + // set the number of frames that can be sent + theirNoAlarms += theirNoRunningWHs; + } + + } // namespace Generator +} // namespace LOFAR