diff --git a/Appl/CEP/CS1/CS1_Storage/include/CS1_Storage/MSWriter.h b/Appl/CEP/CS1/CS1_Storage/include/CS1_Storage/MSWriter.h index 672c583a69393170df291ceff831f473588edda5..0d2d9d4c692169fc87d599294fb2219257f999a6 100644 --- a/Appl/CEP/CS1/CS1_Storage/include/CS1_Storage/MSWriter.h +++ b/Appl/CEP/CS1/CS1_Storage/include/CS1_Storage/MSWriter.h @@ -47,10 +47,9 @@ namespace LOFAR // The WSRT is taken as the center of the array. // Thus antPos must have shape [2,nantennas]. MSWriter (const char* msName, double startTime, double timeStep, - int nChan, int nPol, uint nBeams, uint nAntennas, - const vector<double>& antPos, + int nChan, int nPol, uint nAntennas, const vector<double>& antPos, const vector<std::string>& storageStationNames, - uint timesToIntegrate, uint subbandsPerPset); + uint timesToIntegrate); // Destructor ~MSWriter(); @@ -77,8 +76,7 @@ namespace LOFAR // Add the definition of the next field (i.e. beam). // The angles have to be given in radians. - // <br>It returns the id (0-relative seqnr) of the field. - int addField (double RA, double DEC); + void addField (double RA, double DEC, unsigned beamIndex); // Write a data array for the given band, field and frequency channel. // The data array is a (3D complex) array with axes polarization, @@ -90,9 +88,8 @@ namespace LOFAR // All data will be written with sigma=0 // <br>The number of data points (nrdata) given should match the // number of antennas, bands, and polarizations for this bandId. - void write (int bandId, int fieldId, int channelId, - int nrChannels, int timeCounter, int nrdata, - const fcomplex* data, const bool* flags, + void write (int bandId, int channelId, int nrChannels, int timeCounter, + int nrdata, const fcomplex* data, const bool* flags, const float* weights); // Get the number of antennas. diff --git a/Appl/CEP/CS1/CS1_Storage/include/CS1_Storage/MSWriterImpl.h b/Appl/CEP/CS1/CS1_Storage/include/CS1_Storage/MSWriterImpl.h index 3e2bb9e0a7dc7d52fc2270a39a803c7404832a88..a4a40cd69cb2b0672287a0cccafe82ab8f05d381 100644 --- a/Appl/CEP/CS1/CS1_Storage/include/CS1_Storage/MSWriterImpl.h +++ b/Appl/CEP/CS1/CS1_Storage/include/CS1_Storage/MSWriterImpl.h @@ -62,10 +62,9 @@ namespace LOFAR // relative to the center (which is set to Westerbork). So antPos // must have shape [3,nantennas]. MSWriterImpl (const char* msName, double startTime, double timeStep, - int nfreq, int ncorr, int nbeams, - int nantennas, const vector<double>& antPos, + int nfreq, int ncorr, int nantennas, const vector<double>& antPos, const vector<std::string>& storageStationNames, - int timesToIntegrate, int subbandsPerPset); + int timesToIntegrate); // Destructor ~MSWriterImpl(); @@ -84,14 +83,14 @@ namespace LOFAR // Add the definition of the next field (i.e. beam). // The angles have to be given in radians. - int addField (double RA, double DEC); + void addField (double RA, double DEC, unsigned beamIndex); // Write a data array for the given band, field and frequency channel. // The flag array has the same shape as the data array. Flag==True // means the the corresponding data point is flagged as invalid. // The flag array is optional. If not given, all flags are False. // All data will be written with sigma=0 and weight=1. - void write (int bandId, int fieldId, int channelId, + void write (int bandId, int channelId, int nrChannels, int timeCounter, int nrdata, const fcomplex* data, const bool* flags, const float* weights); @@ -156,11 +155,10 @@ namespace LOFAR int itsNrFreq; ///< Fixed nr of frequencies (channels) int itsNrCorr; ///< Fixed nr of correlations (polar.) int itsNrTimes; ///< nr of exposures - int itsSubbandsPerPset; ///< nr of subbands per Pset double itsTimeStep; ///< duration of each exposure (sec) uint itsTimesToIntegrate; ///< Number of timeSteps to integrate (sec) double itsStartTime; ///< start time of observation (sec) - casa::Block<casa::MDirection> itsField; ///< field (beam) directions + casa::MDirection itsField; ///< field directions casa::Block<casa::Int>* itsNrPol; ///< nr of polarizations for each band casa::Block<casa::Int>* itsNrChan; ///< nr of channels for each band casa::Block<casa::Int>* itsPolnr; ///< rownr in POL subtable for each band diff --git a/Appl/CEP/CS1/CS1_Storage/include/CS1_Storage/WH_SubbandWriter.h b/Appl/CEP/CS1/CS1_Storage/include/CS1_Storage/WH_SubbandWriter.h index d7b746d75e01bc87c0554bdf38216fb1c5d90b26..1baabef12821ab6dcc4be9e2d4a95fa1409c5a38 100644 --- a/Appl/CEP/CS1/CS1_Storage/include/CS1_Storage/WH_SubbandWriter.h +++ b/Appl/CEP/CS1/CS1_Storage/include/CS1_Storage/WH_SubbandWriter.h @@ -88,11 +88,9 @@ namespace LOFAR uint itsNrSubbandsPerPset; uint itsNrSubbandsPerStorage; uint itsNrInputChannelsPerPset; - uint itsNrSubbandsPerMS; vector<uint> itsCurrentInputs; vector<uint> itsBandIDs; ///< MS IDs of the frequency bands - vector<uint> itsFieldIDs; ///< MS IDs of the field, i.e. the beam. uint itsTimeCounter; ///< Counts the time uint itsTimesToIntegrate; ///< Number of timeSteps to integrate bool *itsFlagsBuffers;//[NR_SUBBANDS][NR_BASELINES][NR_SUBBAND_CHANNELS][NR_POLARIZATIONS][NR_POLARIZATIONS]; diff --git a/Appl/CEP/CS1/CS1_Storage/src/AH_Storage.cc b/Appl/CEP/CS1/CS1_Storage/src/AH_Storage.cc index 91380303091726e6174eb0f09311a2ba29e16ad8..7f03b22d0fbd26bdc6ee84b7caa3130da8aa5580 100644 --- a/Appl/CEP/CS1/CS1_Storage/src/AH_Storage.cc +++ b/Appl/CEP/CS1/CS1_Storage/src/AH_Storage.cc @@ -18,6 +18,8 @@ #include <CS1_Storage/WH_SubbandWriter.h> #include <CEPFrame/Step.h> +#include <Common/LofarLocators.h> + namespace LOFAR { namespace CS1 @@ -39,6 +41,8 @@ namespace LOFAR void AH_Storage::define(const LOFAR::KeyValueMap&) { LOG_TRACE_LIFETIME(TRACE_LEVEL_FLOW,""); + + ConfigLocator aCL; LOG_TRACE_FLOW_STR("Create the top-level composite"); Composite comp(0, 0, "topComposite"); @@ -47,8 +51,18 @@ namespace LOFAR setComposite(comp); itsCS1PS = new CS1_Parset(&itsParamSet); - itsCS1PS->adoptFile("OLAP.parset"); + string configFile(aCL.locate("OLAP.parset")); + + if (!configFile.empty()) { + LOG_DEBUG_STR ("Using OLAP.parset file: " << configFile); + itsCS1PS->adoptFile(configFile); + } + else { + LOG_DEBUG_STR ("NO DEFAULT OLAP.PARSET FOUND"); + } + + //itsCS1PS->adoptFile(configFile); itsStub = new Stub_BGL(false, true, "BGLProc_Storage", itsCS1PS); uint nrSubbands = itsCS1PS->nrSubbands(); diff --git a/Appl/CEP/CS1/CS1_Storage/src/CS1_Storage_main.cc b/Appl/CEP/CS1/CS1_Storage/src/CS1_Storage_main.cc index b6b6e509571f6cf7f23471bf02dfeda26e4c9c27..eec6c6b5d95b4840265d1fd29af7930f73a436ed 100644 --- a/Appl/CEP/CS1/CS1_Storage/src/CS1_Storage_main.cc +++ b/Appl/CEP/CS1/CS1_Storage/src/CS1_Storage_main.cc @@ -18,6 +18,7 @@ #include <tinyCEP/ApplicationHolderController.h> #include <CS1_Storage/AH_Storage.h> +#include <CS1_Storage/Package__Version.h> using namespace LOFAR; using namespace LOFAR::CS1; @@ -26,7 +27,10 @@ using namespace LOFAR::CS1; #include <CS1_Storage/ACCmain_Storage.h> int main(int argc, char* argv[]) { - + + std::string type = "brief"; + Version::show<CS1_StorageVersion> (std::cout, "CS1_Storage", type); + ConfigLocator aCL; string progName = basename(argv[0]); string logPropFile(progName + ".log_prop"); diff --git a/Appl/CEP/CS1/CS1_Storage/src/MSWriter.cc b/Appl/CEP/CS1/CS1_Storage/src/MSWriter.cc index 42bf67d200f7ef1303cf1446c6b61bfb93ddf391..a4e7e21884b54f767c968789f1f51f380c087592 100644 --- a/Appl/CEP/CS1/CS1_Storage/src/MSWriter.cc +++ b/Appl/CEP/CS1/CS1_Storage/src/MSWriter.cc @@ -38,19 +38,16 @@ namespace LOFAR using namespace casa; MSWriter::MSWriter (const char* msName, double startTime, double timeStep, - int nChan, int nPol, uint nBeams, - uint nAntennas, const vector<double>& antPos, + int nChan, int nPol, uint nAntennas, const vector<double>& antPos, const vector<string>& storageStationNames, - uint timesToIntegrate, uint subbandsPerPset) + uint timesToIntegrate) : itsWriter (0) { ASSERTSTR(antPos.size() == 3*nAntennas, antPos.size() << " == " << 3*nAntennas << "Antenna position vector does not have the right size!"); try { itsWriter = new MSWriterImpl (msName, startTime, timeStep, nChan, nPol, - nBeams, nAntennas, - antPos, storageStationNames, timesToIntegrate, - subbandsPerPset); + nAntennas, antPos, storageStationNames, timesToIntegrate); } catch (AipsError x) { cerr << "MSWriter exception: " << x.getMesg() << endl; exit(0); @@ -99,11 +96,10 @@ namespace LOFAR return res; } - int MSWriter::addField (double RA, double DEC) + void MSWriter::addField (double RA, double DEC, unsigned beamIndex) { - int res; try { - res = itsWriter->addField (RA, DEC); + itsWriter->addField (RA, DEC, beamIndex); } catch (AipsError x) { cerr << "AIPS exception in MSWriterImpl: " << x.getMesg() << endl; exit(0); @@ -111,16 +107,15 @@ namespace LOFAR cerr << "Unexpected MSWriter exception during addField" << endl; exit(0); } - return res; } - void MSWriter::write (int bandId, int fieldId, int channelId, + void MSWriter::write (int bandId, int channelId, int nrChannels, int timeCounter, int nrdata, const fcomplex* data, const bool* flags, const float* weights) { try { - itsWriter->write (bandId, fieldId, channelId, nrChannels, timeCounter, + itsWriter->write (bandId, channelId, nrChannels, timeCounter, nrdata, data, flags, weights); } catch (AipsError x) { cerr << "AIPS exception in MSWriterImpl: " << x.getMesg() << endl; diff --git a/Appl/CEP/CS1/CS1_Storage/src/MSWriterImpl.cc b/Appl/CEP/CS1/CS1_Storage/src/MSWriterImpl.cc index baf8fc302f0a84be182978f3c8dbf427aa85d912..35c09a30f5a8013d95af1033c151fe7ce9f062fc 100644 --- a/Appl/CEP/CS1/CS1_Storage/src/MSWriterImpl.cc +++ b/Appl/CEP/CS1/CS1_Storage/src/MSWriterImpl.cc @@ -70,21 +70,19 @@ namespace LOFAR using namespace casa; MSWriterImpl::MSWriterImpl (const char* msName, double startTime, double timeStep, - int nfreq, int ncorr, int nbeams, - int nantennas, const vector<double>& antPos, + int nfreq, int ncorr, int nantennas, const vector<double>& antPos, const vector<string>& storageStationNames, - int timesToIntegrate, int subbandsPerPset) + int timesToIntegrate) : itsNrBand (0), itsNrField (0), itsNrAnt (nantennas), itsNrFreq (nfreq), itsNrCorr (ncorr), itsNrTimes (0), - itsSubbandsPerPset(subbandsPerPset), itsTimeStep (timeStep), itsTimesToIntegrate(timesToIntegrate), itsStartTime(0), - itsField(nbeams), + itsField (), itsNrPol (0), itsNrChan (0), itsPolnr (0), @@ -307,7 +305,7 @@ namespace LOFAR msspw.addRow(); msspwCol.numChan().put (rownr, nchannels); #if defined HAVE_MPI - int nrSubband = TH_MPI::getCurrentRank()*itsSubbandsPerPset + (rownr); + int nrSubband = TH_MPI::getCurrentRank() + (rownr); msspwCol.name().put (rownr, "SB-" + String::toString(nrSubband)); #else msspwCol.name().put (rownr, "SB-0"); @@ -366,20 +364,20 @@ namespace LOFAR return rownr; } - int MSWriterImpl::addField (double RA, double DEC) + void MSWriterImpl::addField (double RA, double DEC, unsigned beamIndex) { MVDirection radec (Quantity(RA,"rad"), Quantity(DEC,"rad")); MDirection indir(radec, MDirection::J2000); Vector<MDirection> outdir(1); outdir(0) = indir; - itsField[itsNrField] = indir; + itsField = indir; // Put the direction into the FIELD subtable. { MSField msfield = itsMS->field(); MSFieldColumns msfieldCol(msfield); uInt rownr = msfield.nrow(); msfield.addRow(); - msfieldCol.name().put (rownr, "BEAM_" + String::toString(rownr)); + msfieldCol.name().put (rownr, "BEAM_" + String::toString(beamIndex)); msfieldCol.code().put (rownr, ""); msfieldCol.time().put (rownr, itsStartTime); msfieldCol.numPoly().put (rownr, 0); @@ -409,7 +407,6 @@ namespace LOFAR } } itsNrField++; - return itsNrField-1; } void MSWriterImpl::fillAntenna (const Block<MPosition>& antPos, @@ -571,13 +568,12 @@ namespace LOFAR } } - void MSWriterImpl::write (int bandId, int fieldId, int channelId, + void MSWriterImpl::write (int bandId, int channelId, int nrChannels, int timeCounter, int nrdata, const fcomplex* data, const bool* flags, const float* weights) { ASSERT(bandId >= 0 && bandId < itsNrBand); - ASSERT(fieldId >= 0 && fieldId < itsNrField); ASSERT(data != 0); if (timeCounter >= itsNrTimes) @@ -616,9 +612,9 @@ namespace LOFAR // First store time in frame. Quantity qtime(time, "s"); itsFrame->set (MEpoch(qtime, MEpoch::UTC)); - itsFrame->set (itsField[fieldId]); - - MVDirection MVd = itsField[fieldId].getValue(); + + itsFrame->set (itsField); + MVDirection MVd = itsField.getValue(); Vector<Double> uvw(3); const Cube<Double>& basel = *itsBaselines; @@ -649,7 +645,7 @@ namespace LOFAR itsMSCol->feed2().put (rowNumber, 0); itsMSCol->dataDescId().put (rowNumber, bandId); itsMSCol->processorId().put (rowNumber, 0); - itsMSCol->fieldId().put (rowNumber, fieldId); + itsMSCol->fieldId().put (rowNumber, 0); itsMSCol->interval().put (rowNumber, itsTimeStep); itsMSCol->exposure().put (rowNumber, itsTimeStep); itsMSCol->timeCentroid().put (rowNumber, time); diff --git a/Appl/CEP/CS1/CS1_Storage/src/WH_SubbandWriter.cc b/Appl/CEP/CS1/CS1_Storage/src/WH_SubbandWriter.cc index d042585e76315f67b35e02102732164e5945d555..c62417f9b3aae8e4aa401108616836ab5645eed6 100644 --- a/Appl/CEP/CS1/CS1_Storage/src/WH_SubbandWriter.cc +++ b/Appl/CEP/CS1/CS1_Storage/src/WH_SubbandWriter.cc @@ -78,10 +78,6 @@ namespace LOFAR // itsWeightFactor = the inverse of maximum number of valid samples itsWeightFactor = 1.0 / (pset->BGLintegrationSteps() * pset->IONintegrationSteps() * pset->storageIntegrationSteps()); - vector<double> refFreqs= itsCS1PS->refFreqs(); - unsigned nrSubbands = itsCS1PS->nrSubbands(); - ASSERTSTR(refFreqs.size() >= nrSubbands, "Wrong number of refFreqs specified!"); - itsNVisibilities = itsNBaselines * itsNChannels * itsNPolSquared; char str[32]; @@ -151,33 +147,26 @@ namespace LOFAR LOG_TRACE_VAR_STR("SubbandsPerStorage = " << itsNrSubbandsPerStorage); vector<string> storageStationNames = itsCS1PS->getStringVector("OLAP.storageStationNames"); - itsNrSubbandsPerMS = itsCS1PS->getUint32("OLAP.StorageProc.subbandsPerMS"); - ASSERT(itsCS1PS->nrSubbandsPerPset() * itsCS1PS->nrPsetsPerStorage() % itsNrSubbandsPerMS == 0); - unsigned mssesPerStorage = itsCS1PS->getUint32("OLAP.subbandsPerPset") * itsCS1PS->getUint32("OLAP.psetsPerStorage") / itsNrSubbandsPerMS; + unsigned mssesPerStorage = itsCS1PS->getUint32("OLAP.subbandsPerPset") * itsCS1PS->getUint32("OLAP.psetsPerStorage"); itsWriters.resize(mssesPerStorage); - itsFieldIDs.resize(mssesPerStorage); - + + vector<int32> bl2beams = itsCS1PS->beamlet2beams(); + vector<uint32> sb2Index = itsCS1PS->subband2Index(); + for (unsigned i = 0; i < mssesPerStorage; i ++) { #if defined HAVE_MPI - unsigned firstSubband = (TH_MPI::getCurrentRank() * mssesPerStorage + i) * itsNrSubbandsPerMS; + unsigned currentSubband = (TH_MPI::getCurrentRank() * mssesPerStorage + i); #else - unsigned firstSubband = i * itsNrSubbandsPerMS; + unsigned currentSubband = i; #endif - unsigned lastSubband = firstSubband + itsNrSubbandsPerMS - 1; - itsWriters[i] = new MSWriter( - itsCS1PS->getMSname(firstSubband, lastSubband).c_str(), + itsCS1PS->getMSname(currentSubband).c_str(), startTime, itsCS1PS->storageIntegrationTime(), itsNChannels, - itsNPolSquared, itsNBeams, itsNStations, antPos, - storageStationNames, itsTimesToIntegrate, itsNrSubbandsPerMS); - - //## TODO: add support for more than 1 beam ##// - ASSERT(itsCS1PS->getDoubleVector("Observation.Beam.angle1").size() == itsNBeams); - ASSERT(itsCS1PS->getDoubleVector("Observation.Beam.angle2").size() == itsNBeams); - double RA = itsCS1PS->getDoubleVector("Observation.Beam.angle1")[0]; - double DEC = itsCS1PS->getDoubleVector("Observation.Beam.angle2")[0]; - // For nr of beams - itsFieldIDs[i] = itsWriters[i]->addField(RA, DEC); + itsNPolSquared, itsNStations, antPos, + storageStationNames, itsTimesToIntegrate); + + vector<double> beamDir = itsCS1PS->getBeamDirection(bl2beams[sb2Index[currentSubband]]); + itsWriters[i]->addField(beamDir[0], beamDir[1], bl2beams[sb2Index[currentSubband]]); } vector<double> refFreqs= itsCS1PS->refFreqs(); @@ -191,8 +180,8 @@ namespace LOFAR for (uint sb = 0; sb < itsNrSubbandsPerStorage; ++sb) { // compensate for the half-channel shift introduced by the PPF - double refFreq = refFreqs[itsSubbandIDs[sb]] - chanWidth / 2; - itsBandIDs[sb] = itsWriters[sb / itsNrSubbandsPerMS]->addBand(itsNPolSquared, itsNChannels, refFreq, chanWidth); + double refFreq = refFreqs[sb2Index[itsSubbandIDs[sb]]] - chanWidth / 2; + itsBandIDs[sb] = itsWriters[sb]->addBand(itsNPolSquared, itsNChannels, refFreq, chanWidth); } // Allocate buffers @@ -275,9 +264,8 @@ namespace LOFAR if ((itsTimeCounter + 1) % itsTimesToIntegrate == 0) { itsWriteTimer.start(); - itsWriters[sb / itsNrSubbandsPerMS]->write(itsBandIDs[sb], - itsFieldIDs[sb / itsNrSubbandsPerMS], 0, itsNChannels, - itsTimeCounter, itsNVisibilities, + itsWriters[sb]->write(itsBandIDs[sb], + 0, itsNChannels, itsTimeCounter, itsNVisibilities, &itsVisibilities[sb * itsNVisibilities], &itsFlagsBuffers[sb * itsNVisibilities], &itsWeightsBuffers[sb * itsNBaselines * itsNChannels]); @@ -294,12 +282,9 @@ namespace LOFAR } itsWriteTimer.start(); - itsWriters[sb / itsNrSubbandsPerMS]->write(itsBandIDs[sb], - itsFieldIDs[sb / itsNrSubbandsPerMS], 0, itsNChannels, - itsTimeCounter, itsNVisibilities, - newVis, - itsFlagsBuffers, - itsWeightsBuffers); + itsWriters[sb]->write(itsBandIDs[sb], + 0, itsNChannels, itsTimeCounter, itsNVisibilities, + newVis, itsFlagsBuffers, itsWeightsBuffers); itsWriteTimer.stop(); } #endif