diff --git a/CEP/BB/MWCommon/configure.in b/CEP/BB/MWCommon/configure.in index 89d37054d4fa6aab94577ec05932cdcbeba6f1aa..9f392b2db0a904d5ca613b14602b6377e1edae4d 100644 --- a/CEP/BB/MWCommon/configure.in +++ b/CEP/BB/MWCommon/configure.in @@ -51,6 +51,7 @@ dnl dnl Check for LOFAR specific things dnl lofar_GENERAL +lofar_AIPSPP(1,"-lcasa") lofar_INTERNAL(LCS/Blob,Blob,,1,Blob/BlobHeader.h,,) lofar_INTERNAL(LCS/ACC/APS,APS,,1,APS/ParameterSet.h,,) diff --git a/CEP/BB/MWCommon/include/MWCommon/VdsDesc.h b/CEP/BB/MWCommon/include/MWCommon/VdsDesc.h index a90fe750c78951eca6ba01791846ca6e3b263e15..d38901f43d164ebe5e7ad0750db561c81ff29bfd 100644 --- a/CEP/BB/MWCommon/include/MWCommon/VdsDesc.h +++ b/CEP/BB/MWCommon/include/MWCommon/VdsDesc.h @@ -11,6 +11,7 @@ //# Includes #include <MWCommon/VdsPartDesc.h> +#include <MWCommon/ParameterHandler.h> #include <casa/Utilities/Regex.h> namespace LOFAR { namespace CEP { diff --git a/CEP/BB/MWCommon/include/MWCommon/VdsPartDesc.h b/CEP/BB/MWCommon/include/MWCommon/VdsPartDesc.h index 522d29bcad8d9c173d7b6692ee7f92303fbc60be..d04d06f010c5c6f92a843a6e0d7c28090debba01 100644 --- a/CEP/BB/MWCommon/include/MWCommon/VdsPartDesc.h +++ b/CEP/BB/MWCommon/include/MWCommon/VdsPartDesc.h @@ -10,7 +10,9 @@ #define LOFAR_MWCOMMON_VDSPARTDESC_H //# Includes -#include <MWCommon/ParameterHandler.h> +#include <APS/ParameterSet.h> +#include <Blob/BlobOStream.h> +#include <Blob/BlobIStream.h> #include <string> #include <vector> #include <iosfwd> @@ -40,7 +42,7 @@ namespace LOFAR { namespace CEP { {} /// Construct from the given parameterset. - explicit VdsPartDesc (const ParameterSet&); + explicit VdsPartDesc (const ACC::APS::ParameterSet&); /// Set VDS name and file system. void setName (const std::string& name, const std::string& fileSys); @@ -49,9 +51,26 @@ namespace LOFAR { namespace CEP { void setTimes (double startTime, double endTime, double stepTime); /// Add a band. + // <group> void addBand (int nchan, double startFreq, double endFreq); + void addBand (int nchan, const vector<double>& startFreq, + const vector<double>& endFreq); + // </group> - /// Write it in parset format. + // Add an extra parameter. It is added to the subset 'Extra.'. + // If the paramter already exists, it is replaced. + void addParm (const std::string& key, const std::string& value) + { return itsParms.add (key, value); } + + // Get access to the extra parameters. + const ACC::APS::ParameterSet& getParms() const + { return itsParms; } + + // Clear the extra parameters. + void clearParms() + { itsParms.clear(); } + + /// Write the VdsPartDesc object in parset format. void write (std::ostream& os, const std::string& prefix) const; /// Get the values. @@ -76,17 +95,32 @@ namespace LOFAR { namespace CEP { { return itsEndFreqs; } /// @} + // Put/get the object to/from a blob. + // <group> + BlobOStream& toBlob (BlobOStream&) const; + BlobIStream& fromBlob (BlobIStream&); + // </group> + private: std::string itsName; //# full name of the VDS std::string itsFileSys; //# name of file system the VDS resides on double itsStartTime; double itsEndTime; double itsStepTime; - std::vector<int> itsNChan; //# nr of channels per band + std::vector<int32> itsNChan; //# nr of channels per band std::vector<double> itsStartFreqs; //# start freq of each channel std::vector<double> itsEndFreqs; //# end freq of each channel + ACC::APS::ParameterSet itsParms; //# extra parameters }; + // Put/get the object to/from a blob. + // <group> + inline BlobOStream& operator<< (BlobOStream& bs, const VdsPartDesc& vpd) + { return vpd.toBlob (bs); } + inline BlobIStream& operator>> (BlobIStream& bs, VdsPartDesc& vpd) + { return vpd.fromBlob (bs); } + // </group> + }} /// end namespaces #endif diff --git a/CEP/BB/MWCommon/src/VdsPartDesc.cc b/CEP/BB/MWCommon/src/VdsPartDesc.cc index e66201cd7a2bbfabc8797eba6814bb8743acb4b9..9536a1741f6716342fa1395870f9613265dc30a9 100644 --- a/CEP/BB/MWCommon/src/VdsPartDesc.cc +++ b/CEP/BB/MWCommon/src/VdsPartDesc.cc @@ -6,26 +6,39 @@ //# $Id$ #include <MWCommon/VdsPartDesc.h> +#include <MWCommon/ParameterHandler.h> +#include <Blob/BlobArray.h> #include <Common/StreamUtil.h> +#include <Common/LofarLogger.h> +#include <casa/Quanta/MVTime.h> #include <ostream> namespace std { using LOFAR::operator<<; } using namespace std; +using namespace casa; +using LOFAR::ACC::APS::ParameterSet; namespace LOFAR { namespace CEP { VdsPartDesc::VdsPartDesc (const ParameterSet& parset) { - itsName = parset.getString ("Name"); - itsFileSys = parset.getString ("FileSys", ""); - itsStartTime = parset.getDouble ("StartTime"); - itsEndTime = parset.getDouble ("EndTime"); - itsStepTime = parset.getDouble ("StepTime"); - itsNChan = parset.getInt32Vector ("NChan", vector<int32>()); - itsStartFreqs = parset.getDoubleVector ("StartFreqs", vector<double>()); - itsEndFreqs = parset.getDoubleVector ("EndFreqs", vector<double>()); + itsName = parset.getString ("Name"); + itsFileSys = parset.getString ("FileSys", ""); + itsStepTime = parset.getDouble ("StepTime"); + itsNChan = parset.getInt32Vector ("NChan", vector<int32>()); + itsStartFreqs = parset.getDoubleVector ("StartFreqs", vector<double>()); + itsEndFreqs = parset.getDoubleVector ("EndFreqs", vector<double>()); + itsParms = parset.makeSubset ("Extra."); + string timeStr; + Quantity q; + timeStr = parset.getString ("StartTime"); + ASSERT (MVTime::read (q, timeStr, true)); + itsStartTime = q.getValue ("s"); + timeStr = parset.getString ("EndTime"); + ASSERT (MVTime::read (q, timeStr, true)); + itsEndTime = q.getValue ("s"); } void VdsPartDesc::write (std::ostream& os, const std::string& prefix) const @@ -34,14 +47,20 @@ namespace LOFAR { namespace CEP { if (! itsFileSys.empty()) { os << prefix << "FileSys = " << itsFileSys << endl; } - os << prefix << "StartTime = " << itsStartTime << endl; - os << prefix << "EndTime = " << itsEndTime << endl; + os << prefix << "StartTime = " + << MVTime::Format(MVTime::YMD,6) << MVTime(itsStartTime/86400) << endl; + os << prefix << "EndTime = " + << MVTime::Format(MVTime::YMD,6) << MVTime(itsEndTime/86400) << endl; os << prefix << "StepTime = " << itsStepTime << endl; if (! itsNChan.empty()) { os << prefix << "NChan = " << itsNChan << endl; os << prefix << "StartFreqs = " << itsStartFreqs << endl; os << prefix << "EndFreqs = " << itsEndFreqs << endl; } + // Prepend the extra parameters with Extra.. + ParameterSet parms; + parms.adoptCollection (itsParms, prefix+"Extra."); + parms.writeStream (os); } void VdsPartDesc::setName (const std::string& name, @@ -51,7 +70,7 @@ namespace LOFAR { namespace CEP { itsFileSys = fileSys; } - void VdsPartDesc::setTimes (double startTime, double endTime, double stepTime) + void VdsPartDesc::setTimes (double startTime, double endTime, double stepTime) { itsStartTime = startTime; itsEndTime = endTime; @@ -69,4 +88,38 @@ namespace LOFAR { namespace CEP { } } + void VdsPartDesc::addBand (int nchan, const vector<double>& startFreq, + const vector<double>& endFreq) + { + ASSERT (startFreq.size() == endFreq.size()); + ASSERT (int(startFreq.size())==nchan || startFreq.size() == 1); + itsNChan.push_back (nchan); + for (uint i=0; i<startFreq.size(); ++i) { + itsStartFreqs.push_back (startFreq[i]); + itsEndFreqs.push_back (endFreq[i]); + } + } + + BlobOStream& VdsPartDesc::toBlob (BlobOStream& bs) const + { + bs.putStart ("VdsPartDesc", 1); + bs << itsName << itsFileSys + << itsStartTime << itsEndTime << itsStepTime + << itsNChan << itsStartFreqs << itsEndFreqs + << itsParms; + bs.putEnd(); + return bs; + } + + BlobIStream& VdsPartDesc::fromBlob (BlobIStream& bs) + { + bs.getStart ("VdsPartDesc"); + bs >> itsName >> itsFileSys + >> itsStartTime >> itsEndTime >> itsStepTime + >> itsNChan >> itsStartFreqs >> itsEndFreqs + >> itsParms; + bs.getEnd(); + return bs; + } + }} // end namespaces diff --git a/CEP/BB/MWCommon/test/tVdsPartDesc.cc b/CEP/BB/MWCommon/test/tVdsPartDesc.cc index 285917c914218661ac02e2aa6cfd004cf9fb5b71..bcf729f96e4fb5126b551dadce43c33e5088a0ed 100644 --- a/CEP/BB/MWCommon/test/tVdsPartDesc.cc +++ b/CEP/BB/MWCommon/test/tVdsPartDesc.cc @@ -5,10 +5,14 @@ //# $Id$ #include <MWCommon/VdsPartDesc.h> +#include <Blob/BlobString.h> +#include <Blob/BlobOBufString.h> +#include <Blob/BlobIBufString.h> #include <Common/LofarLogger.h> #include <ostream> #include <fstream> +using namespace LOFAR; using namespace LOFAR::CEP; using namespace std; @@ -34,6 +38,8 @@ void check (const VdsPartDesc& vds) ASSERT (vds.getEndFreqs()[2] == 180); ASSERT (vds.getEndFreqs()[3] == 240); ASSERT (vds.getEndFreqs()[4] == 300); + ASSERT (vds.getParms().size() == 1); + ASSERT (vds.getParms().getString("key1") == "value1"); } void doIt() @@ -43,6 +49,7 @@ void doIt() vds.setTimes (0, 1, 0.5); vds.addBand (2, 20, 100); vds.addBand (3, 120, 300); + vds.addParm ("key1", "value1"); check(vds); // Write into parset file. ofstream fos("tVdsPartDesc_tmp.fil"); @@ -53,6 +60,18 @@ void doIt() check(vds2); vds = vds2; check(vds); + // Check writing/reading from/to blob. + BlobString bstr; + BlobOBufString bobs(bstr); + BlobOStream bos(bobs); + bos << vds; + BlobIBufString bibs(bstr); + BlobIStream bis(bibs); + VdsPartDesc vdsb; + bis >> vdsb; + check (vdsb); + vdsb.clearParms(); + ASSERT (vdsb.getParms().size() == 0); } int main()