Skip to content
Snippets Groups Projects
Commit 93e5adf0 authored by Ger van Diepen's avatar Ger van Diepen
Browse files

bug 1207:

Added the ability to hold arbitrary parameters, so extra info (like
that needed for Peter Fridman) can be added
parent 5189780c
No related branches found
No related tags found
No related merge requests found
......@@ -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,,)
......
......@@ -11,6 +11,7 @@
//# Includes
#include <MWCommon/VdsPartDesc.h>
#include <MWCommon/ParameterHandler.h>
#include <casa/Utilities/Regex.h>
namespace LOFAR { namespace CEP {
......
......@@ -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
......@@ -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
......@@ -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()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment