LCOV - code coverage report
Current view: top level - alma/ASDMBinaries - SDMBinData.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 2202 0.0 %
Date: 2024-10-04 18:58:15 Functions: 0 42 0.0 %

          Line data    Source code
       1             : #include <dirent.h>
       2             : #include <stdio.h>
       3             : 
       4             : #include <vector>
       5             : #include <map>
       6             : #include <iostream>
       7             : #include <string>
       8             : 
       9             : #include <alma/ASDMBinaries/SDMBinData.h>
      10             : #include <alma/ASDMBinaries/Error.h>
      11             : #include <alma/ASDMBinaries/DataDescriptionsSet.h>
      12             : 
      13             : #include <alma/Enumtcl/AxisName.h>
      14             : #include <alma/Enumtcl/DataContent.h>
      15             : #include <alma/Enumtcl/NetSideband.h>
      16             : #include <alma/Enumtcl/PrimitiveDataType.h>
      17             : #include <alma/Enumtcl/CalibrationDevice.h>
      18             : 
      19             : using namespace asdm;
      20             : using namespace asdmbinaries;
      21             : using namespace std;
      22             : 
      23             : using namespace AtmPhaseCorrectionMod;
      24             : using namespace AxisNameMod;
      25             : using namespace CalibrationDeviceMod;
      26             : using namespace CorrelationModeMod;
      27             : using namespace CorrelatorTypeMod;
      28             : using namespace DataContentMod;
      29             : using namespace NetSidebandMod;
      30             : using namespace PrimitiveDataTypeMod;
      31             : using namespace ProcessorTypeMod;
      32             : using namespace ScanIntentMod;
      33             : using namespace SpectralResolutionTypeMod;
      34             : using namespace TimeSamplingMod;
      35             : 
      36             : namespace sdmbin {
      37             : 
      38             : //   SDMBinData::SDMBinData(){
      39             : //     datasetPtr_   = Singleton<ASDM>::instance();
      40             : //     execBlockDir_ = Singleton<ExecBlockDir>::instance()->dir();
      41             : //   }
      42             : 
      43           0 :   SDMBinData::SDMBinData( ASDM* const datasetPtr, string execBlockDir){
      44             :     // Are we going to be verbose ?
      45           0 :     verbose_ = getenv("ASDM_DEBUG") != NULL;
      46             : 
      47             :     DIR *dir;
      48           0 :     dir = opendir( execBlockDir.c_str());
      49           0 :     if(!dir)
      50           0 :       Error(FATAL, "In SDMBinData::SDMBinData( ASDM* const datasetPtr, string execBlockDir) : Directory " + execBlockDir + " not present present");
      51           0 :     closedir(dir);
      52           0 :     dir = NULL;
      53             : 
      54           0 :     string xmlfile = execBlockDir + "/Main.xml"; //cout << "xmlfile="<< xmlfile<<endl;
      55             :     FILE *pFile;
      56           0 :     pFile = fopen( xmlfile.c_str(),"r");
      57           0 :     if(!pFile)
      58           0 :       Error(FATAL, string("In SDMBinData::SDMBinData( ASDM* const datasetPtr, string execBlockDir) : Main table not present in the SDM dataset"));
      59           0 :     fclose(pFile);
      60           0 :     pFile = NULL;
      61             : 
      62           0 :     execBlockDir_ = execBlockDir;
      63           0 :     mainRowPtr_   = NULL;
      64           0 :     datasetPtr_   = datasetPtr;
      65           0 :     dataOID_      = "";
      66           0 :     canSelect_    = true;
      67           0 :     es_si_.flip();              // default: accept any scan
      68           0 :     es_pt_.flip();              // default: accept any processor type when selecting the rows to be processed
      69           0 :     es_cm_.flip();              // default: accept any correlation mode when selecting the rows to be processed
      70           0 :     es_srt_.flip();             // default: accept any spectral resolution type when selecting the rows to be processed
      71           0 :     es_ts_.flip();              // default: accept any time sampling when selecting the rows to be processed
      72           0 :     e_qcm_.set(CROSS_AND_AUTO); // default: select all data present in the BLOB (the HLA enum model being not set-based...)
      73           0 :     es_qapc_.flip();            // default: select all the full APC axis in the BLOB
      74           0 :     ddfirst_=false;
      75             : 
      76           0 :     bdfMemoryMapped = getenv("BDF_MEMORY_MAPPED") != NULL;
      77           0 :   }
      78             : 
      79           0 :   SDMBinData::~SDMBinData(){
      80           0 :     if(coutDeleteInfo_)cout<<"Destructor SSDMBinData"<<endl;
      81             : 
      82           0 :     for(unsigned int n=0; n<v_msDataPtr_.size();  n++) {
      83           0 :       if(v_msDataPtr_[n]){deleteMsData(v_msDataPtr_[n]);}
      84             :     }
      85           0 :     v_msDataPtr_.clear();
      86             : 
      87           0 :     for(unsigned int n=0; n<v_sdmDataPtr_.size(); n++){
      88           0 :       if(v_sdmDataPtr_[n]){delete v_sdmDataPtr_[n]; }
      89             :     }
      90           0 :     v_sdmDataPtr_.clear();
      91             : 
      92           0 :     if(vmsDataPtr_) {
      93           0 :       delete vmsDataPtr_;
      94           0 :       vmsDataPtr_ = NULL;
      95             :     }
      96             : 
      97             :     // msDataPtr_ is used to pass things around
      98             :     // the pointers to be deleted are handled where they are found - usually in v_msDataPtr_
      99             :     // if(msDataPtr_ ) {
     100             :     //   deleteMsData(msDataPtr_);
     101             :     //   msDataPtr_ = NULL;
     102             :     // }
     103             : 
     104             :     // sdmDataPtr_ appears to not be used here, unsure what it is or where it comes from
     105             :     // if(sdmDataPtr_) {
     106             :     //   delete sdmDataPtr_;
     107             :     //   sdmDataPtr_ = NULL;
     108             :     // }
     109             : 
     110             :     // v_dataDump_
     111             :     vector<DataDump*>::reverse_iterator
     112           0 :       it,
     113           0 :       itrb=v_dataDump_.rbegin(),
     114           0 :       itre=v_dataDump_.rend();
     115           0 :     for(it=itrb; it!=itre; it++){
     116           0 :       delete *it;
     117             :     }
     118           0 :     v_dataDump_.clear();
     119             : 
     120           0 :     for (map<Tag,BaselinesSet*>::iterator it=m_cdId_baselinesSet_.begin();it!=m_cdId_baselinesSet_.end();++it) {
     121           0 :       if (it->second != NULL) delete(it->second);
     122             :     }
     123           0 :     m_cdId_baselinesSet_.clear();
     124             : 
     125           0 :     if(coutDeleteInfo_)cout<<"FIN: SSDMBinData object deleted"<<endl;
     126           0 :   }
     127             : 
     128           0 :   void SDMBinData::select( EnumSet<ScanIntent> es_si){
     129           0 :     if(canSelect_)
     130           0 :       es_si_ = es_si;
     131             :     else
     132           0 :       Error(WARNING,string("Selecting a subset of rows in the Main table at this stage is forbidden"));
     133           0 :   }
     134             : 
     135           0 :   void SDMBinData::select( EnumSet<ProcessorType> es_pt){
     136           0 :     if(canSelect_)
     137           0 :       es_pt_ = es_pt;
     138             :     else
     139           0 :       Error(WARNING,string("Selecting a subset of rows in the Main table at this stage is forbidden"));
     140           0 :   }
     141             : 
     142           0 :   void SDMBinData::select( EnumSet<CorrelationMode> es_cm){
     143           0 :     if(canSelect_)
     144           0 :       es_cm_ = es_cm;
     145             :     else
     146           0 :       Error(WARNING,string("Selecting a subset of rows in the Main table at this stage is forbidden"));
     147           0 :   }
     148             : 
     149           0 :   void SDMBinData::select( EnumSet<SpectralResolutionType> es_srt){
     150           0 :     if(canSelect_)
     151           0 :       es_srt_ = es_srt;
     152             :     else
     153           0 :       Error(WARNING,string("Selecting a subset of rows in the Main table at this stage is forbidden"));
     154           0 :   }
     155             : 
     156           0 :   void SDMBinData::SDMBinData::select( EnumSet<TimeSampling> es_ts){
     157           0 :     if(canSelect_)
     158           0 :       es_ts_ = es_ts;
     159             :     else
     160           0 :       Error(WARNING,string("Selecting a subset of rows in the Main table at this stage is forbidden"));
     161           0 :   }
     162             : 
     163           0 :   void SDMBinData::select( EnumSet<CorrelationMode>        es_cm,
     164             :                            EnumSet<SpectralResolutionType> es_srt,
     165             :                            EnumSet<TimeSampling>           es_ts){
     166           0 :     if(canSelect_){
     167           0 :       es_cm_  = es_cm;
     168           0 :       es_srt_ = es_srt;
     169           0 :       es_ts_  = es_ts;
     170             :     }else{
     171           0 :       Error(WARNING,string("Selecting a subset of rows in the Main table at this stage is forbidden"));
     172             :     }
     173           0 :   }
     174             : 
     175           0 :   void SDMBinData::selectDataSubset(  Enum<CorrelationMode> e_qcm, EnumSet<AtmPhaseCorrection> es_qapc){
     176           0 :     if(canSelect_){
     177           0 :       e_qcm_   = e_qcm;
     178           0 :       es_qapc_ = es_qapc;
     179             :     }else{
     180           0 :       Error(WARNING,string("Selecting a subset of data in the BLOB(s) at this stage is forbidden"));
     181             :     }
     182           0 :   }
     183             : 
     184           0 :   string SDMBinData::reasonToReject(MainRow* const mainRowPtr){
     185             : 
     186             :     //bool                  coutest=false;
     187             :     bool                  ok;
     188           0 :     string                reason = "";
     189           0 :     ConfigDescriptionRow* cdr    = mainRowPtr->getConfigDescriptionUsingConfigDescriptionId();
     190             :     ScanRow*              sr;
     191             : 
     192           0 :     if(verbose_){
     193           0 :       cout << "SDMBinData::reasonToReject(MainRow* const mainRowPtr) : entering." << endl;
     194           0 :       cout<<cdr->getConfigDescriptionId().toString()<<endl;
     195           0 :       vector<DataDescriptionRow*> v_ddr=cdr->getDataDescriptionsUsingDataDescriptionId();
     196           0 :       for(unsigned int n=0; n<v_ddr.size(); n++)cout<<v_ddr[n]->getDataDescriptionId().toString()<<" ";
     197           0 :       cout<<endl;
     198           0 :     }
     199             : 
     200             :     // the scan intent:
     201           0 :     sr = datasetPtr_->getScan().getRowByKey( mainRowPtr->getExecBlockUsingExecBlockId()->getExecBlockId(),
     202             :                                              mainRowPtr->getScanNumber() );
     203           0 :     if (sr == (ScanRow*) 0) {
     204           0 :       ostringstream oss;
     205           0 :       oss << "There is no row in the Scan table with 'execBlockId==" << mainRowPtr->getExecBlockId().toString()
     206           0 :           << "' and 'scanNumber==" << mainRowPtr->getScanNumber() << "'.";
     207           0 :       Error(FATAL, oss.str());
     208           0 :     }
     209           0 :     vector<ScanIntent> v_si=sr->getScanIntent();
     210           0 :     ok=false;
     211           0 :     for(unsigned int n=0 ; n<v_si.size(); n++)if(es_si_[v_si[n]])ok=true;
     212           0 :     if(!ok){
     213           0 :       reason += " no overlap with the scan intent set {"+es_si_.str()+"}";
     214             :     }
     215             : 
     216             :     // the processor type:
     217           0 :     if(!es_pt_[cdr->getProcessorUsingProcessorId()->getProcessorType()]) {  
     218           0 :       reason +=  " no overlap with the processor type set {"+es_pt_.str()+"}";
     219             :     }
     220             : 
     221             :     // the correlation mode:
     222           0 :     if(!es_cm_[cdr->getCorrelationMode()]) {
     223           0 :       reason += "no overlap with the corretion mode set {"+es_cm_.str()+"}";
     224             :     }
     225             : 
     226             :     // the spectral resolution type:
     227           0 :     vector<SpectralResolutionType>  v_srt;
     228           0 :     if (cdr->isAssocNatureExists()) v_srt=cdr->getAssocNature();
     229           0 :     if(verbose_)
     230           0 :       for(unsigned int n=0; n<v_srt.size(); n++)
     231           0 :         cout<<"v_srt["<<n<<"]="<<Enum<SpectralResolutionType>(v_srt[n]).str()<<endl;
     232           0 :     ok=false;
     233           0 :     EnumSet<SpectralResolutionType> es_srt; es_srt.set(v_srt); v_srt = es_srt.flip().toEnumType();
     234           0 :     if(verbose_)
     235           0 :       for(unsigned int n=0; n<v_srt.size(); n++)
     236           0 :         cout<<"v_srt["<<n<<"].flip()="<<Enum<SpectralResolutionType>(v_srt[n]).str()<<endl;
     237           0 :     for(unsigned int n=0; n<v_srt.size(); n++)if(es_srt_[v_srt[n]])ok=true;
     238           0 :     if(!ok) {
     239           0 :       reason += " no overlap with the spectral resolution type set {"+es_srt_.str()+"}";
     240             :     }
     241             : 
     242             :     // the time sampling:
     243           0 :     if(!es_ts_[mainRowPtr->getTimeSampling()]) {
     244           0 :         reason += " no overlap with the time sampling set {"+es_ts_.str()+"}";
     245             :     }
     246             : 
     247             :     // the correlation mode data subset
     248           0 :     if(e_qcm_[CROSS_ONLY] && cdr->getCorrelationMode()==AUTO_ONLY) {
     249           0 :       reason += " no cross correlations";
     250             :     }
     251             : 
     252           0 :     if(e_qcm_[AUTO_ONLY] && cdr->getCorrelationMode()==CROSS_ONLY) {
     253           0 :       reason += " no auto correlations";
     254             :     }
     255             : 
     256             : 
     257             :     // the apc axis
     258             :     // We pay attention to it if and only if the processor is not a radiometer.
     259             :     //
     260           0 :     if (processorType(mainRowPtr) != RADIOMETER) {
     261           0 :       EnumSet<AtmPhaseCorrection> es_apc;
     262           0 :       vector<AtmPhaseCorrection>  v_apc=cdr->getAtmPhaseCorrection();
     263           0 :       ok=false;
     264           0 :       for(unsigned int n=0; n<v_apc.size(); n++)if(es_qapc_[v_apc[n]])ok=true;
     265           0 :       if(!ok) {
     266           0 :         reason += " no overlap with the APC set {"+es_qapc_.str()+"}";
     267             :       }
     268           0 :     }
     269             : 
     270           0 :     if(verbose_){
     271           0 :       cout << "SDMBinData::reasonToReject(MainRow* const mainRowPtr) : exiting." << endl;
     272             :     }
     273           0 :     return reason;
     274           0 :   }
     275             : 
     276           0 :   void SDMBinData::setPriorityDataDescription(){
     277           0 :     ddfirst_=true;
     278           0 :   }
     279             : 
     280           0 :   bool SDMBinData::dataDescriptionFirst()const{
     281           0 :     return ddfirst_;
     282             :   }
     283             : 
     284           0 :   void SDMBinData::applySysCal(){
     285           0 :     syscal_=true;
     286           0 :     return;
     287             :   }
     288             : 
     289           0 :   bool SDMBinData::sysCalApplied() const{
     290           0 :     return syscal_;
     291             :   }
     292             : 
     293           0 :   bool SDMBinData::openMainRow( MainRow* const mainRowPtr){
     294           0 :     if (verbose_) cout << "SDMBinData::openMainRow : entering" << endl;
     295             : 
     296           0 :     if( reasonToReject(mainRowPtr).length() )return false;
     297             : 
     298           0 :     ConfigDescriptionRow* cdr  = mainRowPtr->getConfigDescriptionUsingConfigDescriptionId();
     299             : 
     300             : 
     301             :     // proceed, the row having been accepted:
     302             :     // -------------------------------------
     303             : 
     304           0 :     mainRowPtr_ = mainRowPtr;
     305             : 
     306             : 
     307             :     // process the config description (if not yet done) for this row:
     308           0 :     Tag cdId = cdr->getConfigDescriptionId();                       if(verbose_)cout<< "ici 1"<<cdId.toString() <<endl;
     309             :     set<Tag>::iterator
     310           0 :       itcdIdf=s_cdId_.find(cdId),
     311           0 :       itcdIde=s_cdId_.end();
     312           0 :     if(itcdIdf==itcdIde){
     313             :       DataDescriptionsSet dataDescriptionsSet( datasetPtr_,
     314           0 :                                                cdr->getSwitchCycleId(),
     315           0 :                                                cdr->getDataDescriptionId(),
     316             :                                                cdr->getCorrelationMode(),
     317           0 :                                                cdr->getAtmPhaseCorrection());                    if(verbose_)cout << "ici 3"<<endl;
     318             : 
     319           0 :       unsigned int numAnt=cdr->getNumAntenna();
     320           0 :       vector<int>  v_phasedArrayList;  for(unsigned int na=0; na<numAnt; na++)v_phasedArrayList.push_back(0);
     321           0 :       vector<bool> v_antennaUsedArray; for(unsigned int na=0; na<numAnt; na++)v_antennaUsedArray.push_back(true);
     322           0 :       BaselinesSet* baselinesSetPtr = new BaselinesSet( cdr->getAntennaId(),
     323           0 :                                                         cdr->getFeedId(),
     324             :                                                         v_phasedArrayList,
     325             :                                                         v_antennaUsedArray,
     326           0 :                                                         dataDescriptionsSet);  if(verbose_)cout << "ici 4"<<endl;
     327           0 :       m_cdId_baselinesSet_.insert(make_pair(cdId,baselinesSetPtr));
     328           0 :       s_cdId_.insert(cdId);
     329           0 :     }else{
     330           0 :       if(verbose_)cout<<"reuse cdId="<<cdId.toString()<<endl;
     331             :     }
     332             : 
     333           0 :     if(verbose_)cout << "ici 4 dataOID="<<mainRowPtr->getDataUID().getEntityId().toString()<<endl;
     334             : 
     335           0 :     int iostat = openStreamDataObject(mainRowPtr->getDataUID().getEntityId().toString());
     336           0 :     if(iostat==0){
     337           0 :       if(verbose_){
     338           0 :         cout << "Successfully opened Stream Data Object" << endl;
     339             :       }
     340             :     }else{
     341           0 :       Error(WARNING,string("No data retrieving for this SDM mainTable row"));
     342           0 :       return false;
     343             :     }
     344           0 :     if (verbose_) cout << "SDMBinData::openMainRow : exiting" << endl;
     345           0 :     return true;
     346           0 :   }
     347             : 
     348           0 :   ProcessorType SDMBinData::processorType(MainRow* const mainRowPtr) const {
     349           0 :     if (verbose_) cout << "SDMBinData::processorType(MainRow* const mainRowPtr) : entering" << endl;
     350           0 :     Tag cdId = mainRowPtr->getConfigDescriptionId();
     351           0 :     ConfigDescriptionTable& cT = mainRowPtr->getTable().getContainer().getConfigDescription();
     352           0 :     ConfigDescriptionRow* cR = cT.getRowByKey(cdId);
     353           0 :     Tag pId = cR->getProcessorId();
     354             :     
     355             :     
     356           0 :     ProcessorType processorType =  mainRowPtr->getTable().getContainer().getProcessor().getRowByKey(pId)->getProcessorType();
     357             : 
     358           0 :     if (verbose_) cout << "SDMBinData::processorType(MainRow* const mainRowPtr) : exiting" << endl;
     359           0 :     return processorType;
     360           0 :   }
     361             : 
     362           0 :   bool SDMBinData::acceptMainRow( MainRow* const mainRowPtr){
     363             : 
     364             :     //bool coutest=false;
     365             : 
     366           0 :     if (verbose_) cout << "SDMBinData::acceptMainRow( MainRow* const mainRowPtr) : entering." << endl;
     367             : 
     368           0 :     string whyToReject = reasonToReject(mainRowPtr);
     369           0 :     if( whyToReject.length() ){
     370           0 :       if (verbose_) {
     371           0 :         cout << "Main row rejected , reason : " << whyToReject << endl;
     372           0 :         cout << "SDMBinData::acceptMainRow( MainRow* const mainRowPtr) : exiting." << endl;
     373             :       }
     374           0 :       return false;
     375             :     }
     376             : 
     377           0 :     ConfigDescriptionRow* cdr  = mainRowPtr->getConfigDescriptionUsingConfigDescriptionId();
     378             : 
     379             : 
     380             :     // proceed, the row having been accepted:
     381             :     // -------------------------------------
     382             : 
     383           0 :     mainRowPtr_ = mainRowPtr;
     384             : 
     385             : 
     386             :     // process the config description (if not yet done) for this row:
     387           0 :     Tag cdId = cdr->getConfigDescriptionId();                       if(verbose_)cout<< "ici 1"<<cdId.toString() <<endl;
     388             :     set<Tag>::iterator
     389           0 :       itcdIdf=s_cdId_.find(cdId),
     390           0 :       itcdIde=s_cdId_.end();
     391           0 :     if(itcdIdf==itcdIde){
     392             :       DataDescriptionsSet dataDescriptionsSet( datasetPtr_,
     393           0 :                                                cdr->getSwitchCycleId(),
     394           0 :                                                cdr->getDataDescriptionId(),
     395             :                                                cdr->getCorrelationMode(),
     396           0 :                                                cdr->getAtmPhaseCorrection());                    if(verbose_)cout << "ici 3"<<endl;
     397             : 
     398           0 :       unsigned int numAnt=cdr->getNumAntenna();
     399           0 :       vector<int>  v_phasedArrayList;  for(unsigned int na=0; na<numAnt; na++)v_phasedArrayList.push_back(0);
     400           0 :       vector<bool> v_antennaUsedArray; for(unsigned int na=0; na<numAnt; na++)v_antennaUsedArray.push_back(true);
     401           0 :       BaselinesSet* baselinesSetPtr = new BaselinesSet( cdr->getAntennaId(),
     402           0 :                                                         cdr->getFeedId(),
     403             :                                                         v_phasedArrayList,
     404             :                                                         v_antennaUsedArray,
     405           0 :                                                         dataDescriptionsSet);  if(verbose_)cout << "ici 4"<<endl;
     406           0 :       m_cdId_baselinesSet_.insert(make_pair(cdId,baselinesSetPtr));
     407           0 :       s_cdId_.insert(cdId);
     408           0 :     }else{
     409           0 :       if(verbose_)cout<<"reuse cdId="<<cdId.toString()<<endl;
     410             :     }
     411             : 
     412           0 :     if(verbose_)cout << "ici 4 dataOID="<<mainRowPtr->getDataUID().getEntityId().toString()<<endl;
     413             : 
     414           0 :     int iostat = 0;
     415           0 :     if (bdfMemoryMapped) {
     416           0 :       iostat = attachDataObject(mainRowPtr->getDataUID().getEntityId().toString());
     417             :     }
     418             :     else {  
     419           0 :       iostat = attachStreamDataObject(mainRowPtr->getDataUID().getEntityId().toString());
     420             :     }
     421           0 :     if(iostat==0){
     422           0 :       if(verbose_){
     423           0 :         cout<<"Summary of the data object properties at URI: "<<dataOID_<<endl;
     424           0 :         cout<<"v_dataDump_.size()="<<v_dataDump_.size()<<endl;
     425           0 :         v_dataDump_[0]->summary();
     426             :       }
     427             :     }else{
     428           0 :       Error(WARNING,string("No data retrieving for this SDM mainTable row"));
     429           0 :       if (verbose_) cout << "SDMBinData::acceptMainRow( MainRow* const mainRowPtr) : exiting." << endl;
     430           0 :       return false;
     431             :     }
     432             : 
     433           0 :     if (verbose_) cout << "SDMBinData::acceptMainRow( MainRow* const mainRowPtr) : exiting." << endl;
     434           0 :     return true;
     435           0 :   }
     436             : 
     437           0 :   int SDMBinData::attachDataObject(string dataOID ){
     438             : 
     439           0 :     bool coutest=false;
     440             : 
     441           0 :     if(coutest)cout<<"Entree dans attachDataObject"<<endl;
     442             : 
     443           0 :     if(dataOID_.length()){
     444           0 :       cout << "dataOID_ = " << dataOID_ << ", dataOID = " << dataOID <<  endl;
     445             :       //Error(WARNING,"Not assumed to have more than one BLOB open read-only");
     446             :       //if(coutest)
     447           0 :       cout<<"Close "<<dataOID_<<" before opening "<<dataOID<<endl;
     448           0 :       detachDataObject();
     449             :     }
     450             :     
     451           0 :     if(coutest)cout<<"attach BLOB "<<dataOID<<endl;
     452             : 
     453             : 
     454             :     // transforme le dataOID en file name (re-utilise code ds la methode beginWithMimeHeader de SDMBLOBs)  TODO
     455           0 :     string filename=dataOID;
     456             :     string::size_type np;
     457           0 :     np=filename.find("/",0);
     458           0 :     while(np!=string::npos){ np=filename.find("/",np); if(np!=string::npos){ filename.replace(np,1,"_"); np++; } }
     459           0 :     np=filename.find(":",0);
     460           0 :     while(np!=string::npos){ np=filename.find(":",np); if(np!=string::npos){ filename.replace(np,1,"_"); np++; } }
     461           0 :     if(coutest)cout<<"filename="<<filename<<" execBlockDir_="<<execBlockDir_<<endl;
     462             :     static DIR* dirp;
     463             : //     ostringstream dir; dir<<execBlockDir_<<"/SDMBinaries";
     464           0 :     ostringstream dir; dir<<execBlockDir_<<"/ASDMBinary";
     465           0 :     dirp = opendir(dir.str().c_str());
     466           0 :     if(!dirp)
     467           0 :       Error(FATAL,(char *) "Could not open directory %s",dir.str().c_str());
     468           0 :     closedir(dirp);
     469           0 :     filename=dir.str()+"/"+filename;
     470           0 :     if(coutest)cout<<"filename="<<filename<<endl;
     471             : 
     472             :     try {
     473           0 :       const SDMDataObject& dataObject = blob_r_.read(filename);
     474           0 :       dataOID_ = dataOID;
     475           0 :       if(coutest){
     476           0 :         cout<<"============================"<<endl;
     477           0 :         cout<< dataObject.toString()<<endl;
     478           0 :         cout<<"============================"<<endl;
     479             :       }
     480             : //       dataObject.execBlockUID();
     481             : //       dataObject.execBlockNum();
     482             : //       dataObject.scanNum();
     483             : //       dataObject.subscanNum();
     484             : 
     485           0 :       Enum<CorrelationMode>            e_cm;
     486           0 :       Enum<ProcessorType>              e_pt;
     487           0 :       Enum<CorrelatorType>             e_ct;
     488             : 
     489           0 :       unsigned int                     numTime=0;
     490             : 
     491           0 :       unsigned int                     numAnt              = dataObject.numAntenna();
     492           0 :       CorrelationMode                  correlationMode     = dataObject.correlationMode(); e_cm=correlationMode;
     493           0 :       ProcessorType                    processorType       = dataObject.processorType();   e_pt=processorType;
     494             :       CorrelatorType                   correlatorType;
     495             : 
     496           0 :       const SDMDataObject::DataStruct& dataStruct          = dataObject.dataStruct();
     497             : 
     498           0 :       vector<AtmPhaseCorrection>       v_apc               = dataStruct.apc();
     499           0 :       vector<SDMDataObject::Baseband>  v_baseband          = dataStruct.basebands();
     500           0 :       SDMDataObject::ZeroLagsBinaryPart               zeroLagsParameters;
     501             : 
     502             : //      bool                             normalized=false;
     503           0 :       if(e_pt[ProcessorTypeMod::CORRELATOR]){
     504             : //      if(e_cm[CorrelationModeMod::CROSS_ONLY])
     505             : //        normalized =  dataStruct.autoData().normalized();
     506           0 :         if(dataStruct.zeroLags().size()){
     507           0 :           zeroLagsParameters = dataStruct.zeroLags();
     508           0 :           correlatorType = zeroLagsParameters.correlatorType(); e_ct=correlatorType;
     509             :         }
     510             :       }
     511             :         
     512           0 :       unsigned int                     numApc              = v_apc.size();
     513           0 :       unsigned int                     numBaseband         = v_baseband.size();
     514             : 
     515           0 :       vector< vector< unsigned int > > vv_numAutoPolProduct;
     516           0 :       vector< vector< unsigned int > > vv_numCrossPolProduct;
     517           0 :       vector< vector< unsigned int > > vv_numSpectralPoint;
     518           0 :       vector< vector< unsigned int > > vv_numBin;
     519           0 :       vector< vector< float > >        vv_scaleFactor;
     520           0 :       vector< unsigned int >           v_numSpectralWindow;
     521           0 :       vector< vector< Enum<NetSideband> > > vv_e_sideband;
     522           0 :       vector< vector< SDMDataObject::SpectralWindow* > > vv_image;
     523             : 
     524           0 :       if(coutest)cout<<"e_cm="<<e_cm.str()<<endl;
     525             : 
     526           0 :       for(unsigned int nbb=0; nbb<v_baseband.size(); nbb++){
     527           0 :         vector<SDMDataObject::SpectralWindow>  v_spw = v_baseband[nbb].spectralWindows(); v_numSpectralWindow.push_back(v_spw.size());
     528           0 :         vector<SDMDataObject::SpectralWindow*> v_image;
     529           0 :         vector< unsigned int > v_numBin;
     530           0 :         vector< unsigned int > v_numSpectralPoint;
     531           0 :         vector< unsigned int > v_numSdPolProduct;
     532           0 :         vector< unsigned int > v_numCrPolProduct;
     533           0 :         vector< Enum<NetSideband> >  v_e_sideband;
     534           0 :         vector<float>          v_scaleFactor;
     535           0 :         for(unsigned int nspw=0; nspw<v_spw.size(); nspw++){
     536           0 :           v_e_sideband.push_back(Enum<NetSideband>(v_spw[nspw].sideband()));
     537           0 :           v_image.push_back(NULL);                                   // TODO waiting for implementation
     538           0 :           v_numBin.push_back(v_spw[nspw].numBin());
     539           0 :           if(coutest)cout<<"v_spw["<<nspw<<"].numSpectralPoint()="<<v_spw[nspw].numSpectralPoint()<<endl;
     540           0 :           v_numSpectralPoint.push_back(v_spw[nspw].numSpectralPoint());
     541           0 :           if(e_cm[AUTO_ONLY])
     542           0 :             v_numSdPolProduct.push_back(v_spw[nspw].sdPolProducts().size());
     543             :           else{
     544           0 :             v_numCrPolProduct.push_back(v_spw[nspw].crossPolProducts().size());
     545           0 :             v_scaleFactor.push_back(v_spw[nspw].scaleFactor());
     546           0 :             if(e_cm[CROSS_AND_AUTO])
     547           0 :               v_numSdPolProduct.push_back(v_spw[nspw].sdPolProducts().size());
     548             :           }
     549             :         }
     550           0 :         if(e_cm[CROSS_ONLY]==false)vv_numAutoPolProduct.push_back(v_numSdPolProduct);
     551           0 :         if(e_cm[AUTO_ONLY]==false) vv_numCrossPolProduct.push_back(v_numCrPolProduct);
     552           0 :         vv_numSpectralPoint.push_back(v_numSpectralPoint);
     553           0 :         vv_e_sideband.push_back(v_e_sideband);
     554           0 :         vv_image.push_back(v_image);
     555           0 :         vv_numBin.push_back(v_numBin);
     556           0 :         vv_scaleFactor.push_back(v_scaleFactor);
     557           0 :       }
     558           0 :       if(e_cm[AUTO_ONLY])vv_numCrossPolProduct.clear();
     559           0 :       if(e_cm[CROSS_ONLY])vv_numAutoPolProduct.clear();
     560             : 
     561           0 :       complexData_=false;
     562           0 :       if(vv_numAutoPolProduct.size()){
     563           0 :         for(unsigned int nbb=0; nbb<vv_numAutoPolProduct.size(); nbb++){
     564           0 :           for(unsigned int nspw=0; nspw<vv_numAutoPolProduct[nbb].size(); nspw++)
     565           0 :             if(vv_numAutoPolProduct[nbb][nspw]>2)complexData_=true;
     566             :         }
     567             :       }
     568           0 :       if(vv_numCrossPolProduct.size())complexData_=true;
     569             : 
     570           0 :       EnumSet<AxisName>         es_axisNames;
     571             :       DataContent               dataContent;
     572           0 :       SDMDataObject::BinaryPart binaryPart;
     573           0 :       map<DataContent,pair<unsigned int,EnumSet<AxisName> > > m_dc_sizeAndAxes;
     574             : 
     575           0 :       dataContent = FLAGS;
     576           0 :       binaryPart  = dataStruct.flags();
     577           0 :       es_axisNames.set(binaryPart.axes(),true);
     578           0 :       if(es_axisNames.count())m_dc_sizeAndAxes.insert(make_pair(dataContent,make_pair(binaryPart.size(),es_axisNames)));
     579             : 
     580           0 :       dataContent = ACTUAL_DURATIONS;
     581           0 :       binaryPart  = dataStruct.actualDurations();
     582           0 :       es_axisNames.set(binaryPart.axes(),true);
     583           0 :       if(es_axisNames.count())m_dc_sizeAndAxes.insert(make_pair(dataContent,make_pair(binaryPart.size(),es_axisNames)));
     584             : 
     585           0 :       dataContent = ACTUAL_TIMES;
     586           0 :       binaryPart  = dataStruct.actualTimes();
     587           0 :       es_axisNames.set(binaryPart.axes(),true);
     588           0 :       if(es_axisNames.count())m_dc_sizeAndAxes.insert(make_pair(dataContent,make_pair(binaryPart.size(),es_axisNames)));
     589             : 
     590           0 :       dataContent = AUTO_DATA;
     591           0 :       binaryPart  = dataStruct.autoData();
     592           0 :       es_axisNames.set(binaryPart.axes(),true);
     593           0 :       if(es_axisNames.count())m_dc_sizeAndAxes.insert(make_pair(dataContent,make_pair(binaryPart.size(),es_axisNames)));
     594             : 
     595           0 :       if(es_axisNames[TIM])numTime=dataObject.numTime();
     596             : 
     597           0 :       dataContent = CROSS_DATA;
     598           0 :       binaryPart  = dataStruct.crossData();
     599           0 :       es_axisNames.set(binaryPart.axes(),true);
     600           0 :       if(es_axisNames.count())m_dc_sizeAndAxes.insert(make_pair(dataContent,make_pair(binaryPart.size(),es_axisNames)));
     601             : 
     602           0 :       if(binaryPart.size()){
     603           0 :         dataContent = ZERO_LAGS;
     604           0 :         binaryPart  = dataStruct.zeroLags();
     605           0 :         es_axisNames.set(binaryPart.axes(),true);
     606           0 :         if(es_axisNames.count())m_dc_sizeAndAxes.insert(make_pair(dataContent,make_pair(binaryPart.size(),es_axisNames)));
     607             :       }
     608             : 
     609           0 :       if(es_axisNames[TIM])numTime=dataObject.numTime();
     610             : 
     611             :       map<DataContent,pair<unsigned int,EnumSet<AxisName> > >::iterator
     612           0 :         itf=m_dc_sizeAndAxes.find(AUTO_DATA),
     613           0 :         ite=m_dc_sizeAndAxes.end();
     614           0 :       if(itf==ite)itf=m_dc_sizeAndAxes.find(CROSS_DATA);
     615           0 :       if(itf==ite)Error(FATAL,(char *) "BLOB %s has no declaration for observational data",dataOID.c_str());
     616             : 
     617             : 
     618           0 :       if(coutDeleteInfo_)cout<<"delete  v_dataDump_"<<endl;
     619           0 :       for(unsigned int n=0; n<v_dataDump_.size(); n++)delete v_dataDump_[n];
     620           0 :       v_dataDump_.clear();
     621             : 
     622           0 :       if(coutest)cout<<"numTime="<<numTime<<endl;
     623             : 
     624           0 :       if(numTime){  // MIME content with a structure of dimensionality 0
     625             : 
     626           0 :         const SDMDataSubset      dataSubset         = dataObject.tpDataSubset();
     627           0 :         uint64_t                 obsDuration        = dataSubset.interval();
     628             : 
     629           0 :         int64_t                  interval           = (int64_t)obsDuration/(int64_t)numTime;
     630             :         int64_t                  exposure;
     631           0 :         int64_t                  timeOfDump         = (int64_t)dataSubset.time()-(int64_t)obsDuration/2LL-interval/2LL; // mutable
     632           0 :         int64_t                  timeCentroid       = timeOfDump;         // default value for the first dump
     633             : 
     634             :         // actual pointer to the data blocks and nb of pdt values found in these blocks:
     635           0 :         const unsigned int*      flagsPtr           = NULL;  unsigned int long numFlags=0; // mcaillat 
     636           0 :         const int64_t*         actualTimesPtr     = NULL;  unsigned int long numActualTimes=0;
     637           0 :         const int64_t*         actualDurationsPtr = NULL;  unsigned int long numActualDurations=0;
     638           0 :         const float*             zeroLagsPtr        = NULL;  unsigned int long numZeroLags=0;
     639           0 :         const float*             autoDataPtr        = NULL;  unsigned int long numAutoData=0;
     640           0 :         const short int*         crossShortDataPtr  = NULL;  unsigned int long numCrossData=0;
     641           0 :         const int*               crossIntDataPtr    = NULL;
     642           0 :         const float*             crossFloatDataPtr  = NULL;
     643             : 
     644             : 
     645             :         // size (in nb pdt value per dump) and list of axes using the dataStruct declarations:
     646           0 :         unsigned int flagsSize=0;           EnumSet<AxisName> es_flagsAxes;
     647           0 :         unsigned int actualTimesSize=0;     EnumSet<AxisName> es_actualTimesAxes;
     648           0 :         unsigned int actualDurationsSize=0; EnumSet<AxisName> es_actualDurationsAxes;
     649           0 :         unsigned int zeroLagsSize=0;        EnumSet<AxisName> es_zeroLagsAxes;
     650           0 :         unsigned int autoDataSize=0;        EnumSet<AxisName> es_autoDataAxes;
     651           0 :         unsigned int crossDataSize=0;       EnumSet<AxisName> es_crossDataAxes;
     652             : 
     653           0 :         if((itf=m_dc_sizeAndAxes.find(FLAGS))!=ite){
     654           0 :           if(coutest)cout<<"Flags have been declared in the main header"<<endl;
     655           0 :           flagsSize    = itf->second.first;
     656           0 :           es_flagsAxes = itf->second.second;
     657           0 :           numFlags     = dataSubset.flags( flagsPtr );
     658           0 :           if(numFlags!=flagsSize)
     659           0 :             Error(FATAL, (char *) "Size of flags, %d, not compatible with the declared size of %d",
     660             :                   numFlags,flagsSize);
     661           0 :           flagsSize   /= numTime;
     662             :         }
     663             : 
     664           0 :         if((itf=m_dc_sizeAndAxes.find(ACTUAL_TIMES))!=ite){
     665           0 :           if(coutest)cout<<"ActualTimes have been declared in the main header"<<endl;
     666           0 :           actualTimesSize    = itf->second.first;
     667           0 :           es_actualTimesAxes = itf->second.second;
     668           0 :           numActualTimes     = dataSubset.actualTimes( actualTimesPtr );
     669           0 :           if(numActualTimes!=actualTimesSize)
     670           0 :             Error(FATAL, (char *) "Size of actualTimes, %d, not compatible with the declared size of %d",
     671             :                   numActualTimes,actualTimesSize);
     672           0 :           actualTimesSize   /= numTime;
     673             :         }
     674             : 
     675           0 :         if((itf=m_dc_sizeAndAxes.find(ACTUAL_DURATIONS))!=ite){
     676           0 :           if(coutest)cout<<"ActualDurations have been declared in the main header"<<endl;
     677           0 :           actualDurationsSize    = itf->second.first;
     678           0 :           es_actualDurationsAxes = itf->second.second;
     679           0 :           numActualDurations     = dataSubset.actualDurations( actualDurationsPtr );
     680           0 :           if(numActualDurations!=actualDurationsSize)
     681           0 :             Error(FATAL, (char *) "Size of actualDurations, %d, not compatible with the declared size of %d",
     682             :                   numActualDurations,actualDurationsSize);
     683           0 :           actualDurationsSize   /= numTime;
     684             :         }
     685             : 
     686           0 :         if((itf=m_dc_sizeAndAxes.find(CROSS_DATA))!=ite){
     687           0 :           if(coutest)cout<<"CrossData have been declared in the main header"<<endl;
     688           0 :           crossDataSize    = itf->second.first;
     689           0 :           es_crossDataAxes = itf->second.second;
     690           0 :           switch(dataSubset.crossDataType()){
     691           0 :           case INT16_TYPE:
     692           0 :             numCrossData = dataSubset.crossData( crossShortDataPtr );
     693           0 :             break;
     694           0 :           case INT32_TYPE:
     695           0 :             numCrossData = dataSubset.crossData( crossIntDataPtr );
     696           0 :             break;
     697           0 :           case FLOAT32_TYPE:
     698           0 :             numCrossData = dataSubset.crossData( crossFloatDataPtr );
     699           0 :             break;
     700           0 :           default:
     701           0 :             Enum<PrimitiveDataType> e_pdt=dataSubset.crossDataType();
     702           0 :             Error(FATAL, (char *) "Cross data with the primitive data type %s are not supported",
     703           0 :                   e_pdt.str().c_str());
     704             :           }
     705           0 :           if(numCrossData!=crossDataSize)
     706           0 :             Error(FATAL, (char *) "Size of crossData, %d, not compatible with the declared size of %d",
     707             :                   numCrossData,crossDataSize);
     708           0 :           crossDataSize /= numTime;
     709             : 
     710             :         }
     711             : 
     712           0 :         if((itf=m_dc_sizeAndAxes.find(ZERO_LAGS))!=ite && crossDataSize ){
     713           0 :           if(coutest)cout<<"ZeroLags have been declared in the main header"<<endl;
     714           0 :           zeroLagsSize = itf->second.first;
     715           0 :           es_zeroLagsAxes = itf->second.second;
     716           0 :           numZeroLags = dataSubset.zeroLags( zeroLagsPtr );
     717           0 :           if(numZeroLags != zeroLagsSize)
     718           0 :             Error(FATAL,(char *) "Size of zeroLags, %d, not compatible with the declared size of %d",
     719             :                     numZeroLags,zeroLagsSize);
     720           0 :           zeroLagsSize /= numTime;
     721             :         }
     722             : 
     723           0 :         if((itf=m_dc_sizeAndAxes.find(AUTO_DATA))!=ite){
     724           0 :           if(coutest)cout<<"AutoData have been declared in the main header"<<endl;
     725           0 :           autoDataSize    = itf->second.first;
     726           0 :           es_autoDataAxes = itf->second.second;
     727           0 :           numAutoData     = dataSubset.autoData( autoDataPtr );
     728           0 :           if(numAutoData){
     729           0 :             if(numAutoData != autoDataSize)
     730           0 :               Error(FATAL,(char *) "Size of autoData, %d, not compatible with the declared size of %d",
     731           0 :                     numAutoData,itf->second.first);
     732           0 :           }else if(numAutoData==0){
     733           0 :             if(!e_cm[CROSS_ONLY])
     734           0 :               Error(WARNING,string("No autoData! may happen when a subscan is aborted"));
     735           0 :             return 0;
     736             :           }
     737           0 :           autoDataSize /= numTime;
     738             :         }
     739             : 
     740           0 :         for(unsigned int nt=0; nt<numTime; nt++){
     741             : 
     742           0 :           timeOfDump   += interval;
     743           0 :           timeCentroid =  timeOfDump;   // TODO
     744           0 :           exposure     =  interval;     // TODO
     745             : 
     746             :           DataDump* dataDumpPtr = new DataDump( vv_numCrossPolProduct,
     747             :                                                 vv_numAutoPolProduct,
     748             :                                                 vv_numSpectralPoint,
     749             :                                                 vv_numBin,
     750             :                                                 vv_e_sideband,
     751             :                                                 numApc,
     752             :                                                 v_numSpectralWindow,
     753             :                                                 numBaseband,
     754             :                                                 numAnt,
     755             :                                                 correlationMode,
     756             :                                                 timeOfDump,
     757             :                                                 timeCentroid,
     758             :                                                 interval,
     759             :                                                 exposure
     760           0 :                                                );
     761           0 :           if(e_cm[CROSS_ONLY]    )dataDumpPtr->setScaleFactor(vv_scaleFactor);
     762           0 :           if(e_cm[CROSS_AND_AUTO])dataDumpPtr->setScaleFactor(vv_scaleFactor);
     763             : 
     764             : 
     765             :           // TODO update timeCentroid and exposure would the actualTimes and actualDurations binary blocks be provided.
     766             : 
     767           0 :           if(flagsPtr)           dataDumpPtr->attachFlags(           flagsSize, es_flagsAxes,
     768           0 :                                                                      numFlags,  flagsPtr + nt*flagsSize);
     769             : 
     770           0 :           if(actualTimesPtr)     dataDumpPtr->attachActualTimes(     actualTimesSize, es_actualTimesAxes,
     771           0 :                                                                      numActualTimes,  actualTimesPtr + nt*actualTimesSize);
     772             : 
     773           0 :           if(actualDurationsPtr) dataDumpPtr->attachActualDurations( actualDurationsSize, es_actualDurationsAxes,
     774           0 :                                                                      numActualDurations, actualDurationsPtr + nt*actualDurationsSize);
     775             : 
     776           0 :           if(zeroLagsPtr)        dataDumpPtr->attachZeroLags(        zeroLagsSize, es_zeroLagsAxes,
     777           0 :                                                                      numZeroLags, zeroLagsPtr + nt*zeroLagsSize);
     778             : 
     779           0 :           if(crossShortDataPtr)  dataDumpPtr->attachCrossData(       crossDataSize, es_crossDataAxes,
     780           0 :                                                                      numCrossData, crossShortDataPtr + nt*crossDataSize);
     781             : 
     782           0 :           if(crossIntDataPtr)    dataDumpPtr->attachCrossData(       crossDataSize, es_crossDataAxes,
     783           0 :                                                                      numCrossData, crossIntDataPtr + nt*crossDataSize);
     784             : 
     785           0 :           if(crossFloatDataPtr)  dataDumpPtr->attachCrossData(       crossDataSize, es_crossDataAxes,
     786           0 :                                                                      numCrossData, crossFloatDataPtr + nt*crossDataSize);
     787             : 
     788           0 :           if(autoDataPtr)        dataDumpPtr->attachAutoData(        autoDataSize, es_autoDataAxes,
     789           0 :                                                                      numAutoData, autoDataPtr + nt*autoDataSize);
     790             : 
     791             : 
     792           0 :           dataDumpPtr->setContextUsingProjectPath(dataSubset.projectPath());
     793             : 
     794           0 :           if(coutest)cout<<"store dataDump"<<endl;
     795           0 :           v_dataDump_.push_back(dataDumpPtr);
     796           0 :           if(coutest)cout<<"v_dataDumpPtr_.size()="<< v_dataDump_.size()<<endl;
     797             :         }
     798           0 :         if(coutest)cout<<"v_dataDumpPtr_.size()="<< v_dataDump_.size()<<endl;
     799             : 
     800           0 :       }else{
     801             : 
     802           0 :         const vector<SDMDataSubset>& v_dataSubset    = dataObject.corrDataSubsets();
     803             : //      uint_64           startTime       = dataObject.startTime();
     804             :         int64_t                    interval;
     805             :         int64_t                    exposure;
     806             :         int64_t                    timeOfInteg;
     807             :         int64_t                    timeCentroid;
     808             : //      unsigned int                 dumpNum;
     809             : 
     810             : //      interval_    = interval;
     811             : //      exposure     = interval_;
     812             : //      timeOfInteg  = midIntervalTime;
     813             : //      timeCentroid = time_;
     814             : //      dumpNum      = integNumCounter_++;
     815             : 
     816           0 :         if(coutest)cout<<"ici 0 v_dataSubset.size()="<<v_dataSubset.size()<<endl;
     817           0 :         for(unsigned int nt=0; nt<v_dataSubset.size(); nt++){
     818             : 
     819           0 :           if(coutest){
     820           0 :             cout<<"filename="<<filename<<endl;
     821           0 :             cout << v_dataSubset[nt].toString();
     822           0 :             cout<<"ici 1"<<endl;
     823             :           }
     824             : 
     825             : //        dumpNum     = nt+1;
     826             : 
     827           0 :           timeOfInteg  = v_dataSubset[nt].time();        if(coutest)cout<<"attachDataObject: "<<timeOfInteg<<endl;
     828           0 :           timeCentroid = v_dataSubset[nt].time();        if(coutest)cout<<"attachDataObject: "<<timeCentroid<<endl;
     829           0 :           interval     = v_dataSubset[nt].interval();    if(coutest)cout<<"attachDataObject: "<<interval<<endl;
     830           0 :           exposure     = interval;
     831           0 :           if(coutest){
     832           0 :             for(unsigned int i=0; i<v_numSpectralWindow.size(); i++){
     833           0 :               for(unsigned int j=0; j<v_numSpectralWindow[i]; j++)
     834           0 :                 cout<<"vv_numSpectralPoint[i][j]="<<vv_numSpectralPoint[i][j]<<endl;
     835             :             }
     836           0 :             for(unsigned int i=0; i<vv_numAutoPolProduct.size(); i++){
     837           0 :               for(unsigned int j=0; j<vv_numAutoPolProduct[i].size(); j++)
     838           0 :                 cout<<"vv_numAutoPolProduct[i][j]="<<vv_numAutoPolProduct[i][j]<<endl;
     839             :             }
     840           0 :             for(unsigned int i=0; i<vv_numCrossPolProduct.size(); i++){
     841           0 :               for(unsigned int j=0; j<vv_numCrossPolProduct[i].size(); j++)
     842           0 :                 cout<<"vv_numCrossPolProduct[i][j]="<<vv_numCrossPolProduct[i][j]<<endl;
     843             :             }
     844             :           }
     845             :           DataDump* dataDumpPtr = new DataDump( vv_numCrossPolProduct,
     846             :                                                 vv_numAutoPolProduct,
     847             :                                                 vv_numSpectralPoint,
     848             :                                                 vv_numBin,
     849             :                                                 vv_e_sideband,
     850             :                                                 numApc,
     851             :                                                 v_numSpectralWindow,
     852             :                                                 numBaseband,
     853             :                                                 numAnt,
     854             :                                                 correlationMode,
     855             :                                                 timeOfInteg,
     856             :                                                 timeCentroid,
     857             :                                                 interval,
     858             :                                                 exposure
     859           0 :                                                );
     860           0 :           if(e_cm[CROSS_ONLY]    )dataDumpPtr->setScaleFactor(vv_scaleFactor);
     861           0 :           if(e_cm[CROSS_AND_AUTO])dataDumpPtr->setScaleFactor(vv_scaleFactor);
     862             : 
     863           0 :           if(coutest)cout<<"m_dc_sizeAndAxes.size()="<< m_dc_sizeAndAxes.size() << endl;
     864           0 :           if((itf=m_dc_sizeAndAxes.find(FLAGS))!=ite){
     865           0 :             if(coutest)cout<<"Flags have been declared in the main header"<<endl;
     866             :             const unsigned int* flagsPtr;
     867           0 :             unsigned int long numFlags = v_dataSubset[nt].flags( flagsPtr );
     868           0 :             if(coutest)cout<<numFlags<<" "<<itf->second.first<<endl;
     869           0 :             if(numFlags)dataDumpPtr->attachFlags( itf->second.first, itf->second.second,
     870             :                                                   numFlags, flagsPtr);
     871             :           }
     872             : 
     873           0 :           if((itf=m_dc_sizeAndAxes.find(ACTUAL_TIMES))!=ite){
     874           0 :             if(coutest)cout<<"ActualTimes have been declared in the main header"<<endl;
     875             :             const int64_t* actualTimesPtr;
     876           0 :             unsigned long int numActualTimes = v_dataSubset[nt].actualTimes( actualTimesPtr );
     877           0 :             if(coutest)cout<<numActualTimes<<" "<<itf->second.first<<endl;
     878           0 :             if(numActualTimes)dataDumpPtr->attachActualTimes( itf->second.first, itf->second.second,
     879             :                                                               numActualTimes, actualTimesPtr);
     880             :           }
     881             : 
     882           0 :           if((itf=m_dc_sizeAndAxes.find(ACTUAL_DURATIONS))!=ite){
     883           0 :             if(coutest)cout<<"ActualDurations have been declared in the main header"<<endl;
     884             :             const int64_t* actualDurationsPtr;
     885           0 :             unsigned long int numActualDurations = v_dataSubset[nt].actualDurations( actualDurationsPtr );
     886           0 :             if(coutest)cout<<numActualDurations<<" "<<itf->second.first<<endl;
     887           0 :             if(numActualDurations)dataDumpPtr->attachActualDurations( itf->second.first, itf->second.second,
     888             :                                                                       numActualDurations, actualDurationsPtr);
     889             :           }
     890             : 
     891           0 :           if((itf=m_dc_sizeAndAxes.find(ZERO_LAGS))!=ite){
     892           0 :             if(coutest)cout<<"ZeroLags have been declared in the main header"<<endl;
     893             :             const float* zeroLagsPtr;
     894           0 :             unsigned long int numZeroLags = v_dataSubset[nt].zeroLags( zeroLagsPtr );
     895           0 :             if(coutest)cout<<numZeroLags<<" "<<itf->second.first<<endl;
     896           0 :             if(numZeroLags)dataDumpPtr->attachZeroLags( itf->second.first, itf->second.second,
     897             :                                                         numZeroLags, zeroLagsPtr);
     898             :           }
     899             : 
     900           0 :           if((itf=m_dc_sizeAndAxes.find(CROSS_DATA))!=ite){
     901           0 :             if(coutest)cout<<"CrossData have been declared in the main header ";
     902             :             unsigned long int numCrossData;
     903           0 :             switch(v_dataSubset[nt].crossDataType()){
     904           0 :             case INT16_TYPE:
     905             :               { const short int* crossDataPtr;
     906           0 :                 numCrossData = v_dataSubset[nt].crossData( crossDataPtr );
     907           0 :                 if(numCrossData)dataDumpPtr->attachCrossData( itf->second.first, itf->second.second,
     908             :                                                               numCrossData, crossDataPtr);
     909             :               }
     910           0 :               if(coutest)cout<<"SHORT_TYPE"<<endl;
     911           0 :               if(coutest)cout<<"crossData attached,  const pointer:"<<dataDumpPtr->crossDataShort()<<endl;
     912           0 :               break;
     913           0 :             case INT32_TYPE:
     914             :               { const int* crossDataPtr;
     915           0 :                 numCrossData = v_dataSubset[nt].crossData( crossDataPtr );
     916           0 :                 if(numCrossData)dataDumpPtr->attachCrossData( itf->second.first, itf->second.second,
     917             :                                                               numCrossData, crossDataPtr);
     918             :               }
     919           0 :               if(coutest)cout<<"INT_TYPE"<<endl;
     920           0 :               if(coutest)cout<<"crossData attached,  const pointer:"<<dataDumpPtr->crossDataLong()<<endl;
     921           0 :               break;
     922           0 :             case FLOAT32_TYPE:
     923             :               { const float* crossDataPtr;
     924           0 :                 numCrossData = v_dataSubset[nt].crossData( crossDataPtr );
     925           0 :                 if(numCrossData)dataDumpPtr->attachCrossData( itf->second.first, itf->second.second,
     926             :                                                               numCrossData, crossDataPtr);
     927             :               }
     928           0 :               if(coutest)cout<<"FLOAT_TYPE"<<endl;
     929           0 :               if(coutest)cout<<"crossData attached,  const pointer:"<<dataDumpPtr->crossDataFloat()<<endl;
     930           0 :               break;
     931           0 :             default:
     932           0 :               Enum<PrimitiveDataType> e_pdt=v_dataSubset[nt].crossDataType();
     933           0 :               Error(FATAL, (char *) "Cross data with the primitive data type %s are not supported",
     934           0 :                     e_pdt.str().c_str());
     935             :             }
     936             :           }
     937             : 
     938           0 :           if((itf=m_dc_sizeAndAxes.find(AUTO_DATA))!=ite){
     939           0 :             if(coutest)cout<<"AutoData have been declared in the main header"<<endl;
     940           0 :             const float*      floatDataPtr=NULL;
     941           0 :             unsigned long int numFloatData = v_dataSubset[nt].autoData( floatDataPtr );
     942           0 :             if(coutest)cout<<numFloatData<<" "<<itf->second.first<<"  "<<floatDataPtr<<endl;
     943           0 :             if(numFloatData){
     944           0 :               if(numFloatData!=itf->second.first)
     945           0 :                 Error(FATAL,(char *) "Size of autoData, %d, not compatible with the declared size of %d",
     946           0 :                       numFloatData,itf->second.first);
     947           0 :               dataDumpPtr->attachAutoData( itf->second.first, itf->second.second,
     948             :                                            numFloatData, floatDataPtr);
     949           0 :               if(coutest)cout<<"autoData attached,  const pointer:"<<dataDumpPtr->autoData()<<endl;
     950             : //            const long unsigned int* aptr=dataDumpPtr->flags();
     951           0 :             }else if(numFloatData==0){
     952           0 :                if(!e_cm[CROSS_ONLY])
     953           0 :                  Error(WARNING,string("No autoData! may happen when a subscan is aborted"));
     954           0 :               break;
     955             :             }
     956             :           }
     957             : 
     958           0 :           if (coutest) cout << "About to setContextUsingProjectPath" << endl;
     959           0 :           dataDumpPtr->setContextUsingProjectPath(v_dataSubset[nt].projectPath());
     960           0 :           if (coutest) cout << "Back from setContextUsingProjectPath" << endl;
     961           0 :           const unsigned int* bptr=dataDumpPtr->flags(); if(bptr==NULL)if(coutest)cout<<"No flags"<<endl;
     962           0 :           if(coutest)cout<<"store dataDump"<<endl;
     963           0 :           v_dataDump_.push_back(dataDumpPtr);
     964           0 :           if(coutest)cout<<"v_dataDumpPtr_.size()="<< v_dataDump_.size()<<endl;
     965             :         }
     966           0 :         if(coutest)cout<<"v_dataDumpPtr_.size()="<< v_dataDump_.size()<<endl;
     967             :       }
     968           0 :       if(coutest)cout<<"numTime="<<numTime<<", about to return 0"<<endl;
     969             : 
     970             : //       for (unsigned long int nt = 0; nt <v_dataSubset.size(); nt++) {
     971             : //      if(coutest)cout << v_dataSubset[nt].toString();
     972             : //       }
     973           0 :       return 0;
     974           0 :     }
     975           0 :     catch (SDMDataObjectReaderException e) { cout << e.getMessage()          << endl; }
     976           0 :     catch (SDMDataObjectParserException e) { cout << e.getMessage()          << endl; }
     977           0 :     catch (SDMDataObjectException e)       { cout << e.getMessage()          << endl; }
     978           0 :     catch (std::exception e)                    { cout << e.what()                << endl; }
     979           0 :     catch (...)                            { cout << "Unexpected exception." << endl; }
     980           0 :     return 1;
     981           0 :   }
     982             : 
     983           0 :   int SDMBinData::openStreamDataObject(const string& dataOID) {
     984           0 :     if (verbose_) cout << "SDMBinData::openStreamDataObject : entering" << endl;
     985             :     
     986           0 :     sdmdosr.close();
     987             : 
     988           0 :     if(verbose_)cout<<"open a BDF and consumes its global header. "<<dataOID<<endl;
     989             : 
     990             :     // transforme le dataOID en file name (re-utilise code ds la methode beginWithMimeHeader de SDMBLOBs)  TODO
     991           0 :     string filename=dataOID;
     992             :     string::size_type np;
     993           0 :     np=filename.find("/",0);
     994           0 :     while(np!=string::npos){ np=filename.find("/",np); if(np!=string::npos){ filename.replace(np,1,"_"); np++; } }
     995           0 :     np=filename.find(":",0);
     996           0 :     while(np!=string::npos){ np=filename.find(":",np); if(np!=string::npos){ filename.replace(np,1,"_"); np++; } }
     997             : 
     998             :     static DIR* dirp;
     999             : //     ostringstream dir; dir<<execBlockDir_<<"/SDMBinaries";
    1000           0 :     ostringstream dir; dir<<execBlockDir_<<"/ASDMBinary";
    1001           0 :     dirp = opendir(dir.str().c_str());
    1002           0 :     if(!dirp)
    1003           0 :       Error(FATAL,(char *) "Could not open directory %s",dir.str().c_str());
    1004           0 :     closedir(dirp);
    1005           0 :     filename=dir.str()+"/"+filename;
    1006           0 :     if(verbose_)cout<<"filename="<<filename<<endl;
    1007             : 
    1008             :     
    1009           0 :     sdmdosr.open(filename);
    1010           0 :     dataOID_ = dataOID;
    1011           0 :     if(verbose_){
    1012           0 :       cout<<"============================"<<endl;
    1013           0 :       cout<< sdmdosr.toString()<<endl;
    1014           0 :       cout<<"============================"<<endl;
    1015             :     }
    1016           0 :     return 0;
    1017             : 
    1018             :     /*    
    1019             :       Enum<CorrelationMode>            e_cm;
    1020             :       Enum<ProcessorType>              e_pt;
    1021             :       Enum<CorrelatorType>             e_ct;
    1022             : 
    1023             :       unsigned int                     numTime=0;
    1024             : 
    1025             :       CorrelationMode                  correlationMode     = sdmdosr.correlationMode(); e_cm=correlationMode;
    1026             :       ProcessorType                    processorType       = sdmdosr.processorType();   e_pt=processorType;
    1027             :       CorrelatorType                   correlatorType;
    1028             : 
    1029             :       const SDMDataObject::DataStruct& dataStruct          = sdmdosr.dataStruct();
    1030             : 
    1031             :       vector<AtmPhaseCorrection>       v_apc               = dataStruct.apc();
    1032             :       vector<SDMDataObject::Baseband>  v_baseband          = dataStruct.basebands();
    1033             :       SDMDataObject::ZeroLagsBinaryPart               zeroLagsParameters;
    1034             : 
    1035             :       bool                             normalized=false;
    1036             :       if(e_pt[ProcessorTypeMod::CORRELATOR]){
    1037             :         if(e_cm[CorrelationModeMod::CROSS_ONLY])
    1038             :           normalized =  dataStruct.autoData().normalized();
    1039             :         if(dataStruct.zeroLags().size()){
    1040             :           zeroLagsParameters = dataStruct.zeroLags();
    1041             :           correlatorType = zeroLagsParameters.correlatorType(); e_ct=correlatorType;
    1042             :         }
    1043             :       }
    1044             :         
    1045             :       vector< vector< unsigned int > > vv_numAutoPolProduct;
    1046             :       vector< vector< unsigned int > > vv_numCrossPolProduct;
    1047             :       vector< vector< unsigned int > > vv_numSpectralPoint;
    1048             :       vector< vector< unsigned int > > vv_numBin;
    1049             :       vector< vector< float > >        vv_scaleFactor;
    1050             :       vector< unsigned int >           v_numSpectralWindow;
    1051             :       vector< vector< Enum<NetSideband> > > vv_e_sideband;
    1052             :       vector< vector< SDMDataObject::SpectralWindow* > > vv_image;
    1053             : 
    1054             :       if(verbose_)cout<<"e_cm="<<e_cm.str()<<endl;
    1055             : 
    1056             :       for(unsigned int nbb=0; nbb<v_baseband.size(); nbb++){
    1057             :         vector<SDMDataObject::SpectralWindow>  v_spw = v_baseband[nbb].spectralWindows(); v_numSpectralWindow.push_back(v_spw.size());
    1058             :         vector<SDMDataObject::SpectralWindow*> v_image;
    1059             :         vector< unsigned int > v_numBin;
    1060             :         vector< unsigned int > v_numSpectralPoint;
    1061             :         vector< unsigned int > v_numSdPolProduct;
    1062             :         vector< unsigned int > v_numCrPolProduct;
    1063             :         vector< Enum<NetSideband> >  v_e_sideband;
    1064             :         vector<float>          v_scaleFactor;
    1065             :         for(unsigned int nspw=0; nspw<v_spw.size(); nspw++){
    1066             :           v_e_sideband.push_back(Enum<NetSideband>(v_spw[nspw].sideband()));
    1067             :           v_image.push_back(NULL);                                   // TODO waiting for implementation
    1068             :           v_numBin.push_back(v_spw[nspw].numBin());
    1069             :           if(verbose_)cout<<"v_spw["<<nspw<<"].numSpectralPoint()="<<v_spw[nspw].numSpectralPoint()<<endl;
    1070             :           v_numSpectralPoint.push_back(v_spw[nspw].numSpectralPoint());
    1071             :           if(e_cm[AUTO_ONLY])
    1072             :             v_numSdPolProduct.push_back(v_spw[nspw].sdPolProducts().size());
    1073             :           else{
    1074             :             v_numCrPolProduct.push_back(v_spw[nspw].crossPolProducts().size());
    1075             :             v_scaleFactor.push_back(v_spw[nspw].scaleFactor());
    1076             :             if(e_cm[CROSS_AND_AUTO])
    1077             :               v_numSdPolProduct.push_back(v_spw[nspw].sdPolProducts().size());
    1078             :           }
    1079             :         }
    1080             :         if(e_cm[CROSS_ONLY]==false)vv_numAutoPolProduct.push_back(v_numSdPolProduct);
    1081             :         if(e_cm[AUTO_ONLY]==false) vv_numCrossPolProduct.push_back(v_numCrPolProduct);
    1082             :         vv_numSpectralPoint.push_back(v_numSpectralPoint);
    1083             :         vv_e_sideband.push_back(v_e_sideband);
    1084             :         vv_image.push_back(v_image);
    1085             :         vv_numBin.push_back(v_numBin);
    1086             :         vv_scaleFactor.push_back(v_scaleFactor);
    1087             :       }
    1088             :       if(e_cm[AUTO_ONLY])vv_numCrossPolProduct.clear();
    1089             :       if(e_cm[CROSS_ONLY])vv_numAutoPolProduct.clear();
    1090             : 
    1091             :       complexData_=false;
    1092             :       if(vv_numAutoPolProduct.size()){
    1093             :         for(unsigned int nbb=0; nbb<vv_numAutoPolProduct.size(); nbb++){
    1094             :           for(unsigned int nspw=0; nspw<vv_numAutoPolProduct[nbb].size(); nspw++)
    1095             :             if(vv_numAutoPolProduct[nbb][nspw]>2)complexData_=true;
    1096             :         }
    1097             :       }
    1098             :       if(vv_numCrossPolProduct.size())complexData_=true;
    1099             : 
    1100             :       EnumSet<AxisName>         es_axisNames;
    1101             :       DataContent               dataContent;
    1102             :       SDMDataObject::BinaryPart binaryPart;
    1103             :       map<DataContent,pair<unsigned int,EnumSet<AxisName> > > m_dc_sizeAndAxes;
    1104             : 
    1105             :       dataContent = FLAGS;
    1106             :       binaryPart  = dataStruct.flags();
    1107             :       es_axisNames.set(binaryPart.axes(),true);
    1108             :       if(es_axisNames.count())m_dc_sizeAndAxes.insert(make_pair(dataContent,make_pair(binaryPart.size(),es_axisNames)));
    1109             : 
    1110             :       dataContent = ACTUAL_DURATIONS;
    1111             :       binaryPart  = dataStruct.actualDurations();
    1112             :       es_axisNames.set(binaryPart.axes(),true);
    1113             :       if(es_axisNames.count())m_dc_sizeAndAxes.insert(make_pair(dataContent,make_pair(binaryPart.size(),es_axisNames)));
    1114             : 
    1115             :       dataContent = ACTUAL_TIMES;
    1116             :       binaryPart  = dataStruct.actualTimes();
    1117             :       es_axisNames.set(binaryPart.axes(),true);
    1118             :       if(es_axisNames.count())m_dc_sizeAndAxes.insert(make_pair(dataContent,make_pair(binaryPart.size(),es_axisNames)));
    1119             : 
    1120             :       dataContent = AUTO_DATA;
    1121             :       binaryPart  = dataStruct.autoData();
    1122             :       es_axisNames.set(binaryPart.axes(),true);
    1123             :       if(es_axisNames.count())m_dc_sizeAndAxes.insert(make_pair(dataContent,make_pair(binaryPart.size(),es_axisNames)));
    1124             : 
    1125             :       if(es_axisNames[TIM])numTime=sdmdosr.numTime();
    1126             : 
    1127             :       dataContent = CROSS_DATA;
    1128             :       binaryPart  = dataStruct.crossData();
    1129             :       es_axisNames.set(binaryPart.axes(),true);
    1130             :       if(es_axisNames.count())m_dc_sizeAndAxes.insert(make_pair(dataContent,make_pair(binaryPart.size(),es_axisNames)));
    1131             : 
    1132             :       if(binaryPart.size()){
    1133             :         dataContent = ZERO_LAGS;
    1134             :         binaryPart  = dataStruct.zeroLags();
    1135             :         es_axisNames.set(binaryPart.axes(),true);
    1136             :         if(es_axisNames.count())m_dc_sizeAndAxes.insert(make_pair(dataContent,make_pair(binaryPart.size(),es_axisNames)));
    1137             :       }
    1138             : 
    1139             :       if(es_axisNames[TIM])numTime=sdmdosr.numTime();
    1140             : 
    1141             :       map<DataContent,pair<unsigned int,EnumSet<AxisName> > >::iterator
    1142             :         itf=m_dc_sizeAndAxes.find(AUTO_DATA),
    1143             :         ite=m_dc_sizeAndAxes.end();
    1144             :       if(itf==ite)itf=m_dc_sizeAndAxes.find(CROSS_DATA);
    1145             :       if(itf==ite)Error(FATAL,"BLOB %s has no declaration for observational data",dataOID.c_str());
    1146             :     }
    1147             :     catch (SDMDataObjectStreamReaderException e) { cout << e.getMessage()          << endl; }
    1148             :     catch (SDMDataObjectReaderException e) { cout << e.getMessage()          << endl; }
    1149             :     catch (SDMDataObjectParserException e) { cout << e.getMessage()          << endl; }
    1150             :     catch (SDMDataObjectException e)       { cout << e.getMessage()          << endl; }
    1151             :     catch (std::exception e)                    { cout << e.what()                << endl; }
    1152             :     catch (...)                            { cout << "Unexpected exception." << endl; }
    1153             :     if (verbose_) cout << "SDMBinData::openStreamDataObject : exiting" << endl;
    1154             :     return 0;*/
    1155           0 :   }
    1156             : 
    1157           0 :   int SDMBinData::attachStreamDataObject(const string& dataOID ){
    1158             :     
    1159           0 :     if(verbose_)cout<<"SDMBinData::attachStreamDataObject(const string& dataOID ): entering"<<endl;
    1160             :     
    1161           0 :     sdmdosr.close();
    1162             : 
    1163           0 :     if(verbose_)cout<<"attach BLOB "<<dataOID<<endl;
    1164             : 
    1165             :     // transforme le dataOID en file name (re-utilise code ds la methode beginWithMimeHeader de SDMBLOBs)  TODO
    1166           0 :     string filename=dataOID;
    1167             :     string::size_type np;
    1168           0 :     np=filename.find("/",0);
    1169           0 :     while(np!=string::npos){ np=filename.find("/",np); if(np!=string::npos){ filename.replace(np,1,"_"); np++; } }
    1170           0 :     np=filename.find(":",0);
    1171           0 :     while(np!=string::npos){ np=filename.find(":",np); if(np!=string::npos){ filename.replace(np,1,"_"); np++; } }
    1172           0 :     if(verbose_)cout<<"filename="<<filename<<" execBlockDir_="<<execBlockDir_<<endl;
    1173             :     static DIR* dirp;
    1174             : //     ostringstream dir; dir<<execBlockDir_<<"/SDMBinaries";
    1175           0 :     ostringstream dir; dir<<execBlockDir_<<"/ASDMBinary";
    1176           0 :     dirp = opendir(dir.str().c_str());
    1177           0 :     if(!dirp)
    1178           0 :       Error(FATAL,(char *) "Could not open directory %s",dir.str().c_str());
    1179           0 :     closedir(dirp);
    1180           0 :     filename=dir.str()+"/"+filename;
    1181           0 :     if(verbose_)cout<<"filename="<<filename<<endl;
    1182             : 
    1183             :     try {
    1184           0 :       sdmdosr.open(filename);
    1185           0 :       dataOID_ = dataOID;
    1186           0 :       if(verbose_){
    1187           0 :         cout<<"============================"<<endl;
    1188           0 :         cout<< sdmdosr.toString()<<endl;
    1189           0 :         cout<<"============================"<<endl;
    1190             :       }
    1191             : 
    1192           0 :       Enum<CorrelationMode>            e_cm;
    1193           0 :       Enum<ProcessorType>              e_pt;
    1194           0 :       Enum<CorrelatorType>             e_ct;
    1195             : 
    1196           0 :       unsigned int                     numTime=0;
    1197             : 
    1198           0 :       unsigned int                     numAnt              = sdmdosr.numAntenna();
    1199           0 :       CorrelationMode                  correlationMode     = sdmdosr.correlationMode(); e_cm=correlationMode;
    1200           0 :       ProcessorType                    processorType       = sdmdosr.processorType();   e_pt=processorType;
    1201             :       CorrelatorType                   correlatorType;
    1202             : 
    1203           0 :       const SDMDataObject::DataStruct& dataStruct          = sdmdosr.dataStruct();
    1204             : 
    1205           0 :       vector<AtmPhaseCorrection>       v_apc               = dataStruct.apc();
    1206           0 :       vector<SDMDataObject::Baseband>  v_baseband          = dataStruct.basebands();
    1207           0 :       SDMDataObject::ZeroLagsBinaryPart               zeroLagsParameters;
    1208             : 
    1209             : //      bool                             normalized=false;
    1210           0 :       if(e_pt[ProcessorTypeMod::CORRELATOR]){
    1211             : //      if(e_cm[CorrelationModeMod::CROSS_ONLY])
    1212             : //        normalized =  dataStruct.autoData().normalized();
    1213           0 :         if(dataStruct.zeroLags().size()){
    1214           0 :           zeroLagsParameters = dataStruct.zeroLags();
    1215           0 :           correlatorType = zeroLagsParameters.correlatorType(); e_ct=correlatorType;
    1216             :         }
    1217             :       }
    1218             :         
    1219             :       
    1220             : 
    1221           0 :       unsigned int                     numApc              = v_apc.size();
    1222           0 :       unsigned int                     numBaseband         = v_baseband.size();
    1223             : 
    1224           0 :       vector< vector< unsigned int > > vv_numAutoPolProduct;
    1225           0 :       vector< vector< unsigned int > > vv_numCrossPolProduct;
    1226           0 :       vector< vector< unsigned int > > vv_numSpectralPoint;
    1227           0 :       vector< vector< unsigned int > > vv_numBin;
    1228           0 :       vector< vector< float > >        vv_scaleFactor;
    1229           0 :       vector< unsigned int >           v_numSpectralWindow;
    1230           0 :       vector< vector< Enum<NetSideband> > > vv_e_sideband;
    1231           0 :       vector< vector< SDMDataObject::SpectralWindow* > > vv_image;
    1232             : 
    1233           0 :       if(verbose_)cout<<"e_cm="<<e_cm.str()<<endl;
    1234             : 
    1235           0 :       for(unsigned int nbb=0; nbb<v_baseband.size(); nbb++){
    1236           0 :         vector<SDMDataObject::SpectralWindow>  v_spw = v_baseband[nbb].spectralWindows(); v_numSpectralWindow.push_back(v_spw.size());
    1237           0 :         vector<SDMDataObject::SpectralWindow*> v_image;
    1238           0 :         vector< unsigned int > v_numBin;
    1239           0 :         vector< unsigned int > v_numSpectralPoint;
    1240           0 :         vector< unsigned int > v_numSdPolProduct;
    1241           0 :         vector< unsigned int > v_numCrPolProduct;
    1242           0 :         vector< Enum<NetSideband> >  v_e_sideband;
    1243           0 :         vector<float>          v_scaleFactor;
    1244           0 :         for(unsigned int nspw=0; nspw<v_spw.size(); nspw++){
    1245           0 :           v_e_sideband.push_back(Enum<NetSideband>(v_spw[nspw].sideband()));
    1246           0 :           v_image.push_back(NULL);                                   // TODO waiting for implementation
    1247           0 :           v_numBin.push_back(v_spw[nspw].numBin());
    1248           0 :           if(verbose_)cout<<"v_spw["<<nspw<<"].numSpectralPoint()="<<v_spw[nspw].numSpectralPoint()<<endl;
    1249           0 :           v_numSpectralPoint.push_back(v_spw[nspw].numSpectralPoint());
    1250           0 :           if(e_cm[AUTO_ONLY])
    1251           0 :             v_numSdPolProduct.push_back(v_spw[nspw].sdPolProducts().size());
    1252             :           else{
    1253           0 :             v_numCrPolProduct.push_back(v_spw[nspw].crossPolProducts().size());
    1254           0 :             v_scaleFactor.push_back(v_spw[nspw].scaleFactor());
    1255           0 :             if(e_cm[CROSS_AND_AUTO])
    1256           0 :               v_numSdPolProduct.push_back(v_spw[nspw].sdPolProducts().size());
    1257             :           }
    1258             :         }
    1259           0 :         if(e_cm[CROSS_ONLY]==false)vv_numAutoPolProduct.push_back(v_numSdPolProduct);
    1260           0 :         if(e_cm[AUTO_ONLY]==false) vv_numCrossPolProduct.push_back(v_numCrPolProduct);
    1261           0 :         vv_numSpectralPoint.push_back(v_numSpectralPoint);
    1262           0 :         vv_e_sideband.push_back(v_e_sideband);
    1263           0 :         vv_image.push_back(v_image);
    1264           0 :         vv_numBin.push_back(v_numBin);
    1265           0 :         vv_scaleFactor.push_back(v_scaleFactor);
    1266           0 :       }
    1267           0 :       if(e_cm[AUTO_ONLY])vv_numCrossPolProduct.clear();
    1268           0 :       if(e_cm[CROSS_ONLY])vv_numAutoPolProduct.clear();
    1269             : 
    1270           0 :       complexData_=false;
    1271           0 :       if(vv_numAutoPolProduct.size()){
    1272           0 :         for(unsigned int nbb=0; nbb<vv_numAutoPolProduct.size(); nbb++){
    1273           0 :           for(unsigned int nspw=0; nspw<vv_numAutoPolProduct[nbb].size(); nspw++)
    1274           0 :             if(vv_numAutoPolProduct[nbb][nspw]>2)complexData_=true;
    1275             :         }
    1276             :       }
    1277           0 :       if(vv_numCrossPolProduct.size())complexData_=true;
    1278             : 
    1279           0 :       EnumSet<AxisName>         es_axisNames;
    1280             :       DataContent               dataContent;
    1281           0 :       SDMDataObject::BinaryPart binaryPart;
    1282           0 :       map<DataContent,pair<unsigned int,EnumSet<AxisName> > > m_dc_sizeAndAxes;
    1283             : 
    1284           0 :       dataContent = FLAGS;
    1285           0 :       binaryPart  = dataStruct.flags();
    1286           0 :       es_axisNames.set(binaryPart.axes(),true);
    1287           0 :       if(es_axisNames.count())m_dc_sizeAndAxes.insert(make_pair(dataContent,make_pair(binaryPart.size(),es_axisNames)));
    1288             : 
    1289           0 :       dataContent = ACTUAL_DURATIONS;
    1290           0 :       binaryPart  = dataStruct.actualDurations();
    1291           0 :       es_axisNames.set(binaryPart.axes(),true);
    1292           0 :       if(es_axisNames.count())m_dc_sizeAndAxes.insert(make_pair(dataContent,make_pair(binaryPart.size(),es_axisNames)));
    1293             : 
    1294           0 :       dataContent = ACTUAL_TIMES;
    1295           0 :       binaryPart  = dataStruct.actualTimes();
    1296           0 :       es_axisNames.set(binaryPart.axes(),true);
    1297           0 :       if(es_axisNames.count())m_dc_sizeAndAxes.insert(make_pair(dataContent,make_pair(binaryPart.size(),es_axisNames)));
    1298             : 
    1299           0 :       dataContent = AUTO_DATA;
    1300           0 :       binaryPart  = dataStruct.autoData();
    1301           0 :       es_axisNames.set(binaryPart.axes(),true);
    1302           0 :       if(es_axisNames.count())m_dc_sizeAndAxes.insert(make_pair(dataContent,make_pair(binaryPart.size(),es_axisNames)));
    1303             : 
    1304           0 :       if(es_axisNames[TIM])numTime=sdmdosr.numTime();
    1305             : 
    1306           0 :       dataContent = CROSS_DATA;
    1307           0 :       binaryPart  = dataStruct.crossData();
    1308           0 :       es_axisNames.set(binaryPart.axes(),true);
    1309           0 :       if(es_axisNames.count())m_dc_sizeAndAxes.insert(make_pair(dataContent,make_pair(binaryPart.size(),es_axisNames)));
    1310             : 
    1311           0 :       if(binaryPart.size()){
    1312           0 :         dataContent = ZERO_LAGS;
    1313           0 :         binaryPart  = dataStruct.zeroLags();
    1314           0 :         es_axisNames.set(binaryPart.axes(),true);
    1315           0 :         if(es_axisNames.count())m_dc_sizeAndAxes.insert(make_pair(dataContent,make_pair(binaryPart.size(),es_axisNames)));
    1316             :       }
    1317             : 
    1318           0 :       if(es_axisNames[TIM])numTime=sdmdosr.numTime();
    1319             : 
    1320             :       map<DataContent,pair<unsigned int,EnumSet<AxisName> > >::iterator
    1321           0 :         itf=m_dc_sizeAndAxes.find(AUTO_DATA),
    1322           0 :         ite=m_dc_sizeAndAxes.end();
    1323           0 :       if(itf==ite)itf=m_dc_sizeAndAxes.find(CROSS_DATA);
    1324           0 :       if(itf==ite)Error(FATAL,(char *) "BLOB %s has no declaration for observational data",dataOID.c_str());
    1325             : 
    1326             : 
    1327           0 :       if(coutDeleteInfo_)cout<<"delete  v_dataDump_"<<endl;
    1328           0 :       for(unsigned int n=0; n<v_dataDump_.size(); n++)delete v_dataDump_[n];
    1329           0 :       v_dataDump_.clear();
    1330             : 
    1331           0 :       if(verbose_)cout<<"numTime="<<numTime<<endl;
    1332             : 
    1333           0 :       if(numTime){  // MIME content with a structure of dimensionality 0
    1334             : 
    1335           0 :         const SDMDataSubset&     dataSubset         = sdmdosr.getSubset();
    1336           0 :         uint64_t                 obsDuration        = dataSubset.interval();
    1337             : 
    1338           0 :         int64_t                  interval           = (int64_t)obsDuration/(int64_t)numTime;
    1339             :         int64_t                  exposure;
    1340           0 :         int64_t                  timeOfDump         = (int64_t)dataSubset.time()-(int64_t)obsDuration/2LL-interval/2LL; // mutable
    1341           0 :         int64_t                  timeCentroid       = timeOfDump;         // default value for the first dump
    1342             : 
    1343             :         // actual pointer to the data blocks and nb of pdt values found in these blocks:
    1344           0 :         const unsigned int*      flagsPtr           = NULL;  unsigned int long numFlags=0; // mcaillat 
    1345           0 :         const int64_t*         actualTimesPtr     = NULL;  unsigned int long numActualTimes=0;
    1346           0 :         const int64_t*         actualDurationsPtr = NULL;  unsigned int long numActualDurations=0;
    1347           0 :         const float*             zeroLagsPtr        = NULL;  unsigned int long numZeroLags=0;
    1348           0 :         const float*             autoDataPtr        = NULL;  unsigned int long numAutoData=0;
    1349           0 :         const short int*         crossShortDataPtr  = NULL;  unsigned int long numCrossData=0;
    1350           0 :         const int*               crossIntDataPtr    = NULL;
    1351           0 :         const float*             crossFloatDataPtr  = NULL;
    1352             : 
    1353             : 
    1354             :         // size (in nb pdt value per dump) and list of axes using the dataStruct declarations:
    1355           0 :         unsigned int flagsSize=0;           EnumSet<AxisName> es_flagsAxes;
    1356           0 :         unsigned int actualTimesSize=0;     EnumSet<AxisName> es_actualTimesAxes;
    1357           0 :         unsigned int actualDurationsSize=0; EnumSet<AxisName> es_actualDurationsAxes;
    1358           0 :         unsigned int zeroLagsSize=0;        EnumSet<AxisName> es_zeroLagsAxes;
    1359           0 :         unsigned int autoDataSize=0;        EnumSet<AxisName> es_autoDataAxes;
    1360           0 :         unsigned int crossDataSize=0;       EnumSet<AxisName> es_crossDataAxes;
    1361             : 
    1362           0 :         if((itf=m_dc_sizeAndAxes.find(FLAGS))!=ite){
    1363           0 :           if(verbose_)cout<<"Flags have been declared in the main header"<<endl;
    1364           0 :           flagsSize    = itf->second.first;
    1365           0 :           es_flagsAxes = itf->second.second;
    1366           0 :           numFlags     = dataSubset.flags( flagsPtr );
    1367           0 :           if(numFlags!=flagsSize)
    1368           0 :             Error(FATAL, (char *) "Size of flags, %d, not compatible with the declared size of %d",
    1369             :                   numFlags,flagsSize);
    1370           0 :           flagsSize   /= numTime;
    1371             :         }
    1372             : 
    1373           0 :         if((itf=m_dc_sizeAndAxes.find(ACTUAL_TIMES))!=ite){
    1374           0 :           if(verbose_)cout<<"ActualTimes have been declared in the main header"<<endl;
    1375           0 :           actualTimesSize    = itf->second.first;
    1376           0 :           es_actualTimesAxes = itf->second.second;
    1377           0 :           numActualTimes     = dataSubset.actualTimes( actualTimesPtr );
    1378           0 :           if(numActualTimes!=actualTimesSize)
    1379           0 :             Error(FATAL, (char *) "Size of actualTimes, %d, not compatible with the declared size of %d",
    1380             :                   numActualTimes,actualTimesSize);
    1381           0 :           actualTimesSize   /= numTime;
    1382             :         }
    1383             : 
    1384           0 :         if((itf=m_dc_sizeAndAxes.find(ACTUAL_DURATIONS))!=ite){
    1385           0 :           if(verbose_)cout<<"ActualDurations have been declared in the main header"<<endl;
    1386           0 :           actualDurationsSize    = itf->second.first;
    1387           0 :           es_actualDurationsAxes = itf->second.second;
    1388           0 :           numActualDurations     = dataSubset.actualDurations( actualDurationsPtr );
    1389           0 :           if(numActualDurations!=actualDurationsSize)
    1390           0 :             Error(FATAL, (char *) "Size of actualDurations, %d, not compatible with the declared size of %d",
    1391             :                   numActualDurations,actualDurationsSize);
    1392           0 :           actualDurationsSize   /= numTime;
    1393             :         }
    1394             : 
    1395           0 :         if((itf=m_dc_sizeAndAxes.find(CROSS_DATA))!=ite){
    1396           0 :           if(verbose_)cout<<"CrossData have been declared in the main header"<<endl;
    1397           0 :           crossDataSize    = itf->second.first;
    1398           0 :           es_crossDataAxes = itf->second.second;
    1399           0 :           switch(dataSubset.crossDataType()){
    1400           0 :           case INT16_TYPE:
    1401           0 :             numCrossData = dataSubset.crossData( crossShortDataPtr );
    1402           0 :             break;
    1403           0 :           case INT32_TYPE:
    1404           0 :             numCrossData = dataSubset.crossData( crossIntDataPtr );
    1405           0 :             break;
    1406           0 :           case FLOAT32_TYPE:
    1407           0 :             numCrossData = dataSubset.crossData( crossFloatDataPtr );
    1408           0 :             break;
    1409           0 :           default:
    1410           0 :             Enum<PrimitiveDataType> e_pdt=dataSubset.crossDataType();
    1411           0 :             Error(FATAL, (char *) "Cross data with the primitive data type %s are not supported",
    1412           0 :                   e_pdt.str().c_str());
    1413             :           }
    1414           0 :           if(numCrossData!=crossDataSize)
    1415           0 :             Error(FATAL, (char *) "Size of crossData, %d, not compatible with the declared size of %d",
    1416             :                   numCrossData,crossDataSize);
    1417           0 :           crossDataSize /= numTime;
    1418             : 
    1419             :         }
    1420             : 
    1421           0 :         if((itf=m_dc_sizeAndAxes.find(ZERO_LAGS))!=ite && crossDataSize ){
    1422           0 :           if(verbose_)cout<<"ZeroLags have been declared in the main header"<<endl;
    1423           0 :           zeroLagsSize = itf->second.first;
    1424           0 :           es_zeroLagsAxes = itf->second.second;
    1425           0 :           numZeroLags = dataSubset.zeroLags( zeroLagsPtr );
    1426           0 :           if(numZeroLags != zeroLagsSize)
    1427           0 :             Error(FATAL,(char *) "Size of zeroLags, %d, not compatible with the declared size of %d",
    1428             :                     numZeroLags,zeroLagsSize);
    1429           0 :           zeroLagsSize /= numTime;
    1430             :         }
    1431             : 
    1432           0 :         if((itf=m_dc_sizeAndAxes.find(AUTO_DATA))!=ite){
    1433           0 :           if(verbose_)cout<<"AutoData have been declared in the main header"<<endl;
    1434           0 :           autoDataSize    = itf->second.first;
    1435           0 :           es_autoDataAxes = itf->second.second;
    1436           0 :           numAutoData     = dataSubset.autoData( autoDataPtr );
    1437           0 :           if(numAutoData){
    1438           0 :             if(numAutoData != autoDataSize)
    1439           0 :               Error(FATAL,(char *) "Size of autoData, %d, not compatible with the declared size of %d",
    1440           0 :                     numAutoData,itf->second.first);
    1441           0 :           }else if(numAutoData==0){
    1442           0 :             if(!e_cm[CROSS_ONLY])
    1443           0 :               Error(WARNING,string("No autoData! may happen when a subscan is aborted"));
    1444           0 :             return 0;
    1445             :           }
    1446           0 :           autoDataSize /= numTime;
    1447             :         }
    1448             : 
    1449           0 :         for(unsigned int nt=0; nt<numTime; nt++){
    1450             : 
    1451           0 :           timeOfDump   += interval;
    1452           0 :           timeCentroid =  timeOfDump;   // TODO
    1453           0 :           exposure     =  interval;     // TODO
    1454             : 
    1455             :           DataDump* dataDumpPtr = new DataDump( vv_numCrossPolProduct,
    1456             :                                                 vv_numAutoPolProduct,
    1457             :                                                 vv_numSpectralPoint,
    1458             :                                                 vv_numBin,
    1459             :                                                 vv_e_sideband,
    1460             :                                                 numApc,
    1461             :                                                 v_numSpectralWindow,
    1462             :                                                 numBaseband,
    1463             :                                                 numAnt,
    1464             :                                                 correlationMode,
    1465             :                                                 timeOfDump,
    1466             :                                                 timeCentroid,
    1467             :                                                 interval,
    1468             :                                                 exposure
    1469           0 :                                                );
    1470           0 :           if(e_cm[CROSS_ONLY]    )dataDumpPtr->setScaleFactor(vv_scaleFactor);
    1471           0 :           if(e_cm[CROSS_AND_AUTO])dataDumpPtr->setScaleFactor(vv_scaleFactor);
    1472             : 
    1473             : 
    1474             :           // TODO update timeCentroid and exposure would the actualTimes and actualDurations binary blocks be provided.
    1475             : 
    1476           0 :           if(flagsPtr)           dataDumpPtr->attachFlags(           flagsSize, es_flagsAxes,
    1477           0 :                                                                      numFlags,  flagsPtr + nt*flagsSize);
    1478             : 
    1479           0 :           if(actualTimesPtr)     dataDumpPtr->attachActualTimes(     actualTimesSize, es_actualTimesAxes,
    1480           0 :                                                                      numActualTimes,  actualTimesPtr + nt*actualTimesSize);
    1481             : 
    1482           0 :           if(actualDurationsPtr) dataDumpPtr->attachActualDurations( actualDurationsSize, es_actualDurationsAxes,
    1483           0 :                                                                      numActualDurations, actualDurationsPtr + nt*actualDurationsSize);
    1484             : 
    1485           0 :           if(zeroLagsPtr)        dataDumpPtr->attachZeroLags(        zeroLagsSize, es_zeroLagsAxes,
    1486           0 :                                                                      numZeroLags, zeroLagsPtr + nt*zeroLagsSize);
    1487             : 
    1488           0 :           if(crossShortDataPtr)  dataDumpPtr->attachCrossData(       crossDataSize, es_crossDataAxes,
    1489           0 :                                                                      numCrossData, crossShortDataPtr + nt*crossDataSize);
    1490             : 
    1491           0 :           if(crossIntDataPtr)    dataDumpPtr->attachCrossData(       crossDataSize, es_crossDataAxes,
    1492           0 :                                                                      numCrossData, crossIntDataPtr + nt*crossDataSize);
    1493             : 
    1494           0 :           if(crossFloatDataPtr)  dataDumpPtr->attachCrossData(       crossDataSize, es_crossDataAxes,
    1495           0 :                                                                      numCrossData, crossFloatDataPtr + nt*crossDataSize);
    1496             : 
    1497           0 :           if(autoDataPtr)        dataDumpPtr->attachAutoData(        autoDataSize, es_autoDataAxes,
    1498           0 :                                                                      numAutoData, autoDataPtr + nt*autoDataSize);
    1499             : 
    1500             : 
    1501           0 :           dataDumpPtr->setContextUsingProjectPath(dataSubset.projectPath());
    1502             : 
    1503           0 :           if(verbose_)cout<<"store dataDump"<<endl;
    1504           0 :           v_dataDump_.push_back(dataDumpPtr);
    1505           0 :           if(verbose_)cout<<"v_dataDumpPtr_.size()="<< v_dataDump_.size()<<endl;
    1506             :         }
    1507           0 :         if(verbose_)cout<<"v_dataDumpPtr_.size()="<< v_dataDump_.size()<<endl;
    1508             : 
    1509             :       }else{
    1510             : 
    1511             : 
    1512             : 
    1513             :         int64_t                    interval;
    1514             :         int64_t                    exposure;
    1515             :         int64_t                    timeOfInteg;
    1516             :         int64_t                    timeCentroid;
    1517             : //      unsigned int                 dumpNum;
    1518             : 
    1519             : //      interval_    = interval;
    1520             : //      exposure     = interval_;
    1521             : //      timeOfInteg  = midIntervalTime;
    1522             : //      timeCentroid = time_;
    1523             : //      dumpNum      = integNumCounter_++;
    1524             : 
    1525           0 :         const vector<SDMDataSubset>& v_dataSubset = sdmdosr.allRemainingSubsets();    
    1526           0 :         if(verbose_)cout<<"ici 0 v_dataSubset.size()="<<v_dataSubset.size()<<endl;
    1527           0 :         for(unsigned int nt=0; nt<v_dataSubset.size(); nt++){
    1528             : 
    1529             :           //int nt = 0;
    1530             :           //while (sdmdosr.hasSubset() ) {
    1531             :           //const SDMDataSubset& currentSubset = sdmdosr.getSubset();
    1532           0 :           const SDMDataSubset& currentSubset = v_dataSubset[nt];
    1533           0 :           if(verbose_){
    1534           0 :             cout<<"filename="<<filename<<endl;
    1535           0 :             cout << currentSubset.toString();
    1536           0 :             cout<<"ici 1"<<endl;
    1537             :           }
    1538             : 
    1539             : //        dumpNum     = nt+1;  //nt++;
    1540             : 
    1541           0 :           timeOfInteg  = currentSubset.time();        if(verbose_)cout<<"attachDataObject: "<<timeOfInteg<<endl;
    1542           0 :           timeCentroid = currentSubset.time();        if(verbose_)cout<<"attachDataObject: "<<timeCentroid<<endl;
    1543           0 :           interval     = currentSubset.interval();    if(verbose_)cout<<"attachDataObject: "<<interval<<endl;
    1544           0 :           exposure     = interval;
    1545           0 :           if(verbose_){
    1546           0 :             for(unsigned int i=0; i<v_numSpectralWindow.size(); i++){
    1547           0 :               for(unsigned int j=0; j<v_numSpectralWindow[i]; j++)
    1548           0 :                 cout<<"vv_numSpectralPoint[i][j]="<<vv_numSpectralPoint[i][j]<<endl;
    1549             :             }
    1550           0 :             for(unsigned int i=0; i<vv_numAutoPolProduct.size(); i++){
    1551           0 :               for(unsigned int j=0; j<vv_numAutoPolProduct[i].size(); j++)
    1552           0 :                 cout<<"vv_numAutoPolProduct[i][j]="<<vv_numAutoPolProduct[i][j]<<endl;
    1553             :             }
    1554           0 :             for(unsigned int i=0; i<vv_numCrossPolProduct.size(); i++){
    1555           0 :               for(unsigned int j=0; j<vv_numCrossPolProduct[i].size(); j++)
    1556           0 :                 cout<<"vv_numCrossPolProduct[i][j]="<<vv_numCrossPolProduct[i][j]<<endl;
    1557             :             }
    1558             :           }
    1559             :           DataDump* dataDumpPtr = new DataDump( vv_numCrossPolProduct,
    1560             :                                                 vv_numAutoPolProduct,
    1561             :                                                 vv_numSpectralPoint,
    1562             :                                                 vv_numBin,
    1563             :                                                 vv_e_sideband,
    1564             :                                                 numApc,
    1565             :                                                 v_numSpectralWindow,
    1566             :                                                 numBaseband,
    1567             :                                                 numAnt,
    1568             :                                                 correlationMode,
    1569             :                                                 timeOfInteg,
    1570             :                                                 timeCentroid,
    1571             :                                                 interval,
    1572             :                                                 exposure
    1573           0 :                                                );
    1574           0 :           if(e_cm[CROSS_ONLY]    )dataDumpPtr->setScaleFactor(vv_scaleFactor);
    1575           0 :           if(e_cm[CROSS_AND_AUTO])dataDumpPtr->setScaleFactor(vv_scaleFactor);
    1576             : 
    1577           0 :           if(verbose_)cout<<"m_dc_sizeAndAxes.size()="<< m_dc_sizeAndAxes.size() << endl;
    1578           0 :           if((itf=m_dc_sizeAndAxes.find(FLAGS))!=ite){
    1579           0 :             if(verbose_)cout<<"Flags have been declared in the main header"<<endl;
    1580             :             const unsigned int* flagsPtr;
    1581           0 :             unsigned int long numFlags = currentSubset.flags( flagsPtr );
    1582           0 :             if(verbose_)cout<<numFlags<<" "<<itf->second.first<<endl;
    1583           0 :             if(numFlags)dataDumpPtr->attachFlags( itf->second.first, itf->second.second,
    1584             :                                                   numFlags, flagsPtr);
    1585             :           }
    1586             : 
    1587           0 :           if((itf=m_dc_sizeAndAxes.find(ACTUAL_TIMES))!=ite){
    1588           0 :             if(verbose_)cout<<"ActualTimes have been declared in the main header"<<endl;
    1589             :             const int64_t* actualTimesPtr;
    1590           0 :             unsigned long int numActualTimes = currentSubset.actualTimes( actualTimesPtr );
    1591           0 :             if(verbose_)cout<<numActualTimes<<" "<<itf->second.first<<endl;
    1592           0 :             if(numActualTimes)dataDumpPtr->attachActualTimes( itf->second.first, itf->second.second,
    1593             :                                                               numActualTimes, actualTimesPtr);
    1594             :           }
    1595             : 
    1596           0 :           if((itf=m_dc_sizeAndAxes.find(ACTUAL_DURATIONS))!=ite){
    1597           0 :             if(verbose_)cout<<"ActualDurations have been declared in the main header"<<endl;
    1598             :             const int64_t* actualDurationsPtr;
    1599           0 :             unsigned long int numActualDurations = currentSubset.actualDurations( actualDurationsPtr );
    1600           0 :             if(verbose_)cout<<numActualDurations<<" "<<itf->second.first<<endl;
    1601           0 :             if(numActualDurations)dataDumpPtr->attachActualDurations( itf->second.first, itf->second.second,
    1602             :                                                                       numActualDurations, actualDurationsPtr);
    1603             :           }
    1604             : 
    1605           0 :           if((itf=m_dc_sizeAndAxes.find(ZERO_LAGS))!=ite){
    1606           0 :             if(verbose_)cout<<"ZeroLags have been declared in the main header"<<endl;
    1607             :             const float* zeroLagsPtr;
    1608           0 :             unsigned long int numZeroLags = currentSubset.zeroLags( zeroLagsPtr );
    1609           0 :             if(verbose_)cout<<numZeroLags<<" "<<itf->second.first<<endl;
    1610           0 :             if(numZeroLags)dataDumpPtr->attachZeroLags( itf->second.first, itf->second.second,
    1611             :                                                         numZeroLags, zeroLagsPtr);
    1612             :           }
    1613             : 
    1614           0 :           if((itf=m_dc_sizeAndAxes.find(CROSS_DATA))!=ite){
    1615           0 :             if(verbose_)cout<<"CrossData have been declared in the main header ";
    1616             :             unsigned long int numCrossData;
    1617           0 :             switch(currentSubset.crossDataType()){
    1618           0 :             case INT16_TYPE:
    1619             :               { const short int* crossDataPtr;
    1620           0 :                 numCrossData = currentSubset.crossData( crossDataPtr );
    1621           0 :                 if(numCrossData)dataDumpPtr->attachCrossData( itf->second.first, itf->second.second,
    1622             :                                                               numCrossData, crossDataPtr);
    1623             :               }
    1624           0 :               if(verbose_)cout<<"SHORT_TYPE"<<endl;
    1625           0 :               if(verbose_)cout<<"crossData attached,  const pointer:"<<dataDumpPtr->crossDataShort()<<endl;
    1626           0 :               break;
    1627           0 :             case INT32_TYPE:
    1628             :               { const int* crossDataPtr;
    1629           0 :                 numCrossData = currentSubset.crossData( crossDataPtr );
    1630           0 :                 if(numCrossData)dataDumpPtr->attachCrossData( itf->second.first, itf->second.second,
    1631             :                                                               numCrossData, crossDataPtr);
    1632             :               }
    1633           0 :               if(verbose_)cout<<"INT_TYPE"<<endl;
    1634           0 :               if(verbose_)cout<<"crossData attached,  const pointer:"<<dataDumpPtr->crossDataLong()<<endl;
    1635           0 :               break;
    1636           0 :             case FLOAT32_TYPE:
    1637             :               { const float* crossDataPtr;
    1638           0 :                 numCrossData = currentSubset.crossData( crossDataPtr );
    1639           0 :                 if(numCrossData)dataDumpPtr->attachCrossData( itf->second.first, itf->second.second,
    1640             :                                                               numCrossData, crossDataPtr);
    1641             :               }
    1642           0 :               if(verbose_)cout<<"FLOAT_TYPE"<<endl;
    1643           0 :               if(verbose_)cout<<"crossData attached,  const pointer:"<<dataDumpPtr->crossDataFloat()<<endl;
    1644           0 :               break;
    1645           0 :             default:
    1646           0 :               Enum<PrimitiveDataType> e_pdt=currentSubset.crossDataType();
    1647           0 :               Error(FATAL, (char *) "Cross data with the primitive data type %s are not supported",
    1648           0 :                     e_pdt.str().c_str());
    1649             :             }
    1650             :           }
    1651             : 
    1652           0 :           if((itf=m_dc_sizeAndAxes.find(AUTO_DATA))!=ite){
    1653           0 :             if(verbose_)cout<<"AutoData have been declared in the main header"<<endl;
    1654           0 :             const float*      floatDataPtr=NULL;
    1655           0 :             unsigned long int numFloatData = currentSubset.autoData( floatDataPtr );
    1656           0 :             if(verbose_)cout<<numFloatData<<" "<<itf->second.first<<"  "<<floatDataPtr<<endl;
    1657           0 :             if(numFloatData){
    1658           0 :               if(numFloatData!=itf->second.first)
    1659           0 :                 Error(FATAL,(char *) "Size of autoData, %d, not compatible with the declared size of %d",
    1660           0 :                       numFloatData,itf->second.first);
    1661           0 :               dataDumpPtr->attachAutoData( itf->second.first, itf->second.second,
    1662             :                                            numFloatData, floatDataPtr);
    1663           0 :               if(verbose_)cout<<"autoData attached,  const pointer:"<<dataDumpPtr->autoData()<<endl;
    1664             : //            const long unsigned int* aptr=dataDumpPtr->flags();
    1665           0 :             }else if(numFloatData==0){
    1666           0 :                if(!e_cm[CROSS_ONLY])
    1667           0 :                  Error(WARNING,string("No autoData! may happen when a subscan is aborted"));
    1668           0 :               break;
    1669             :             }
    1670             :           }
    1671             : 
    1672           0 :           if (verbose_) cout << "About to setContextUsingProjectPath" << endl;
    1673           0 :           dataDumpPtr->setContextUsingProjectPath(currentSubset.projectPath());
    1674           0 :           if (verbose_) cout << "Back from setContextUsingProjectPath" << endl;
    1675           0 :           const unsigned int* bptr=dataDumpPtr->flags(); if(bptr==NULL)if(verbose_)cout<<"No flags"<<endl;
    1676           0 :           if(verbose_)cout<<"store dataDump"<<endl;
    1677           0 :           v_dataDump_.push_back(dataDumpPtr);
    1678           0 :           if(verbose_)cout<<"v_dataDumpPtr_.size()="<< v_dataDump_.size()<<endl;
    1679             :         }
    1680           0 :         if(verbose_)cout<<"v_dataDumpPtr_.size()="<< v_dataDump_.size()<<endl;
    1681             :       }
    1682           0 :       if(verbose_)cout<<"numTime="<<numTime<<", about to return 0"<<endl;
    1683             : 
    1684             : //       for (unsigned long int nt = 0; nt <v_dataSubset.size(); nt++) {
    1685             : //      if(verbose_)cout << currentSubset.toString();
    1686             : //       }
    1687           0 :       return 0;
    1688           0 :     }
    1689           0 :     catch (SDMDataObjectStreamReaderException e) { throw; } // Rethrow the exception, it'll be handled at a higher level.
    1690           0 :     catch (SDMDataObjectReaderException e) {  cout << e.getMessage()          << endl; }  
    1691           0 :     catch (SDMDataObjectParserException e) { cout << e.getMessage()          << endl; }
    1692           0 :     catch (SDMDataObjectException e)       { cout << e.getMessage()          << endl; }
    1693           0 :     catch (std::exception e)                    { cout << e.what()                << endl; }
    1694           0 :     catch (...)                            { cout << "Unexpected exception." << endl; }
    1695           0 :     if(verbose_)cout<<"SDMBinData::attachStreamDataObject(const string& dataOID ): exiting"<<endl;
    1696           0 :     return 1;
    1697           0 : }
    1698             : 
    1699           0 :   void SDMBinData::detachDataObject(){
    1700             : //     if(dataOID_.length())cout<<"detachDataObject() using done()"<<endl;
    1701           0 :     bool coutest = false;
    1702           0 :     if (coutest) cout << "SDMBinData::detachDataObject: entering" << endl;
    1703           0 :     if (bdfMemoryMapped) {
    1704           0 :       if(dataOID_.length())blob_r_.done();
    1705           0 :       dataOID_="";
    1706             :     }
    1707             :     else 
    1708           0 :       sdmdosr.close();
    1709           0 :     if (coutest) cout << "SDMBinData::detachDataObject: exiting" << endl;
    1710           0 :     return;
    1711             :   }
    1712             : 
    1713           0 :   vector<SDMData*> SDMBinData::getData(){
    1714             : 
    1715           0 :     detachDataObject();
    1716           0 :     return  v_sdmDataPtr_;
    1717             : 
    1718             :   }
    1719             : 
    1720           0 :   vector<MSData*>  SDMBinData::getData( Enum<CorrelationMode> e_qcm, EnumSet<AtmPhaseCorrection> es_qapc){
    1721             :     
    1722           0 :     if (verbose_) cout << "SDMBinData::getData( Enum<CorrelationMode> e_qcm, EnumSet<AtmPhaseCorrection> es_qapc): entering" << endl;
    1723           0 :     if(verbose_)
    1724           0 :       cout<<"Enter in method getData(e_qcm="<<e_qcm.str()
    1725           0 :           <<",es_qapc="<<es_qapc.str()<<")"
    1726           0 :           << endl;
    1727             : 
    1728             :     // note, this is a LOCAL msDataPtr_ here
    1729           0 :     MSData* msDataPtr_ = 0;
    1730             : 
    1731           0 :     if(v_msDataPtr_.size()>0){
    1732           0 :       if(coutDeleteInfo_)cout<<"About to delete "<<v_msDataPtr_.size()<<" msDataPtr objects"<<endl;
    1733           0 :       for(vector<MSData*>::reverse_iterator it=v_msDataPtr_.rbegin(); it!=v_msDataPtr_.rend(); ++it)
    1734           0 :         deleteMsData(*it);
    1735             :       
    1736           0 :       v_msDataPtr_.clear();    if(coutDeleteInfo_)cout<<"v_msDataPtr_ cleared"<<endl;
    1737             :     }
    1738             : 
    1739           0 :     ConfigDescriptionRow*       cdPtr = mainRowPtr_->getConfigDescriptionUsingConfigDescriptionId();
    1740           0 :     vector<AtmPhaseCorrection>  v_apc = cdPtr->getAtmPhaseCorrection();
    1741           0 :     Enum<CorrelationMode>       e_cm; e_cm = cdPtr->getCorrelationMode();
    1742             : 
    1743           0 :     EnumSet<AtmPhaseCorrection> es_qapc_uncorrected, es_qapc_old;
    1744             : ;
    1745           0 :     es_qapc_uncorrected.fromString("AP_UNCORRECTED");
    1746           0 :     if (processorType(mainRowPtr_) == RADIOMETER) {
    1747           0 :       es_qapc_old = es_qapc_;
    1748           0 :       es_qapc_ = es_qapc_uncorrected;
    1749             :     }
    1750             :     
    1751           0 :     if(!canSelect_ && (e_qcm.count() || es_qapc.count()) ){
    1752             : 
    1753           0 :       Error(FATAL,string("This method cannot be used in this context!\n Use the method with no argument getData()"));
    1754           0 :       return v_msDataPtr_;
    1755             : 
    1756             :     }
    1757             : 
    1758           0 :     if(canSelect_){
    1759             : 
    1760             :       // set the new defaults
    1761           0 :       e_qcm_   = e_qcm;
    1762           0 :       es_qapc_ = es_qapc;
    1763             : 
    1764             :     }
    1765             : 
    1766           0 :     if(verbose_){
    1767           0 :       cout<<"e_qcm=  "<<e_qcm.str()  <<" e_qcm_=  "<<e_qcm_.str()  <<" e_cm="<<e_cm.str()<<endl;
    1768           0 :       cout<<"es_qapc="<<es_qapc.str()<<" es_qapc_="<<es_qapc_.str();
    1769           0 :       for(unsigned int n=0; n<v_apc.size(); n++)
    1770           0 :         cout<<" v_apc["<<n<<"]="<<Enum<AtmPhaseCorrection>(v_apc[n]).str()<<" ";
    1771           0 :       cout<<endl;
    1772             :     }
    1773             : 
    1774           0 :     if(e_qcm_[CROSS_ONLY]) if(e_cm[AUTO_ONLY])  return v_msDataPtr_;
    1775           0 :     if(e_qcm_[AUTO_ONLY])  if(e_cm[CROSS_ONLY]) return v_msDataPtr_;
    1776             : 
    1777             : 
    1778           0 :     vector<unsigned int>       v_selected_napc;
    1779           0 :     vector<AtmPhaseCorrection> v_selected_apc;
    1780           0 :     for(unsigned int n=0; n<v_apc.size(); n++){
    1781           0 :       if(es_qapc_[v_apc[n]]){
    1782           0 :         v_selected_napc.push_back(n);
    1783           0 :         v_selected_apc.push_back(v_apc[n]);
    1784             :       }
    1785             :     }
    1786           0 :     if(!v_selected_napc.size())return v_msDataPtr_;
    1787             : 
    1788           0 :     Tag configDescriptionId = mainRowPtr_->getConfigDescriptionId();
    1789             : 
    1790             : 
    1791             :     std::set<Tag>::iterator
    1792           0 :       itsf=s_cdId_.find(configDescriptionId),
    1793           0 :       itse=s_cdId_.end();
    1794           0 :     if(itsf==itse)
    1795           0 :       Error(FATAL,"Tree hierarchy not present for configDescId " + configDescriptionId.toString());
    1796             :     std::map<Tag,BaselinesSet*>::iterator
    1797           0 :       itf(m_cdId_baselinesSet_.find(configDescriptionId)),
    1798           0 :       ite(m_cdId_baselinesSet_.end());
    1799           0 :     if(itf==ite)
    1800           0 :       Error(FATAL,"Tree hierarchy not present for configDescId " + configDescriptionId.toString());
    1801           0 :     baselinesSet_=itf->second;
    1802             : 
    1803           0 :     if(verbose_)cout<<configDescriptionId.toString()<<endl;
    1804             : 
    1805             : 
    1806             : 
    1807             :     unsigned int               stateId;
    1808           0 :     vector<StateRow*>          v_statePtr = mainRowPtr_->getStatesUsingStateId();
    1809             : 
    1810           0 :     vector<int>                v_feedSet  = cdPtr->getFeedId();
    1811           0 :     vector<Tag>                v_antSet   = cdPtr->getAntennaId();
    1812           0 :     vector<Tag>                v_ddList   = cdPtr->getDataDescriptionId();
    1813             : 
    1814             : 
    1815           0 :     unsigned int               numFeed    = v_feedSet.size()/v_antSet.size();
    1816             :     unsigned int               numBin;
    1817             :     unsigned int               numPol;
    1818           0 :     vector<unsigned int>       v_dataShape;  v_dataShape.resize(3);  // POL.SPP.APC 3D
    1819             : 
    1820             :     double                     timeMJD;
    1821             :     double                     timeCentroidMJD;
    1822             :     double                     interval;
    1823             :     double                     exposure;
    1824           0 :     ArrayTime                  timeOfDump;
    1825           0 :     ArrayTime                  timeCentroidOfDump;
    1826             : 
    1827           0 :     int                        fieldId    = mainRowPtr_->getFieldUsingFieldId()->getFieldId().getTagValue();
    1828           0 :     vector<vector<Angle> >     phaseDir   = mainRowPtr_->getFieldUsingFieldId()->getPhaseDir();
    1829             : 
    1830             : 
    1831           0 :     vector<Tag>                v_stateId;
    1832             : 
    1833             : //     unsigned int nd;
    1834             : 
    1835             : //     vector<unsigned int> v_dataShape;
    1836             : //     v_msDataPtr_[n]->v_dataShape = v_dataShape;
    1837             : 
    1838           0 :     if(verbose_)cout <<"ici AA: e_qcm_="<<e_qcm_.str()<<endl;
    1839             : 
    1840           0 :     for(unsigned int na=0; na<v_antSet.size(); na++)
    1841           0 :       v_stateId.push_back(v_statePtr[na]->getStateId());
    1842             : 
    1843           0 :     vector<vector<float> >                      vv_t; // dummy empty vector would there be no tsysSpectrum for a given syscal row
    1844           0 :     SysCalTable&                                sct = datasetPtr_->getSysCal();
    1845           0 :     vector<Tag>                                 v_spwid;
    1846           0 :     vector<pair<bool,vector<vector<float> > > > v_tsys;
    1847           0 :     vector<vector<pair<bool,vector<vector<float> > > > > vv_tsys;
    1848             : 
    1849             : 
    1850           0 :     if(SDMBinData::syscal_){
    1851           0 :       v_tsys.resize(v_antSet.size()*v_ddList.size()*numFeed);
    1852           0 :       for(unsigned int nt=0; nt<v_dataDump_.size(); nt++){
    1853           0 :         vector<pair<bool,vector<vector<float> > > > v_tsys;
    1854           0 :         timeCentroidOfDump= ArrayTime((int64_t)v_dataDump_[nt]->timeCentroid());
    1855           0 :         unsigned int scn=0;
    1856           0 :         for(unsigned int na=0; na<v_antSet.size(); na++){
    1857           0 :           for(unsigned int nfe=0; nfe<numFeed; nfe++){
    1858           0 :             for(unsigned int nsw=0; nsw<v_ddList.size(); nsw++){
    1859           0 :               SysCalRow* scr = sct.getRowByKey( v_antSet[na],
    1860           0 :                                                 baselinesSet_->getSpwId(nsw),
    1861           0 :                                                 ArrayTimeInterval(timeCentroidOfDump),
    1862           0 :                                                 v_feedSet[na*numFeed+nfe]
    1863             :                                                 );
    1864           0 :               if(scr->isTsysSpectrumExists()){
    1865           0 :                 vector<vector<float> > vv_flt;
    1866           0 :                 v_tsys[scn].first  = scr->getTsysFlag();
    1867           0 :                 vector<vector<Temperature> > vv=scr->getTsysSpectrum();
    1868           0 :                 for(unsigned int np=0; np<vv.size(); np++){
    1869           0 :                   vector<float> v;
    1870           0 :                   for(unsigned int ns=0; ns<vv[np].size(); ns++)v.push_back(vv[np][ns].get());
    1871           0 :                   vv_flt.push_back(v);
    1872           0 :                 }
    1873           0 :                 v_tsys[scn].second = vv_flt;
    1874           0 :               }else{
    1875           0 :                 v_tsys[scn].first  = false;
    1876           0 :                 v_tsys[scn].second = vv_t;
    1877             :               }
    1878           0 :               scn++;
    1879             :             }
    1880             :           }
    1881             :         }
    1882           0 :         vv_tsys.push_back(v_tsys);
    1883           0 :       }
    1884             :     }
    1885             : 
    1886           0 :     if(e_cm[CROSS_ONLY]==false && e_qcm_[CROSS_ONLY]==false ){       // retrieve only AUTO_DATA
    1887           0 :       for(unsigned int nt=0; nt<v_dataDump_.size(); nt++){
    1888           0 :         timeOfDump        = ArrayTime((int64_t)v_dataDump_[nt]->time());               if(verbose_)cout<<timeOfDump<<" ns"<<endl;
    1889           0 :         timeCentroidOfDump= ArrayTime((int64_t)v_dataDump_[nt]->timeCentroid());       if(verbose_)cout<<timeCentroidOfDump.toString()<<" ns"<<endl;
    1890           0 :         timeMJD           = timeOfDump.getMJD();                              if(verbose_)cout<<timeMJD<<" h = "<<86400.*timeMJD<<" s"<<endl;
    1891           0 :         interval          = (double)v_dataDump_[nt]->interval()/1000000000LL; if(verbose_)cout<<interval<<" s"<<endl;
    1892           0 :         timeCentroidMJD   = timeCentroidOfDump.getMJD();                      if(verbose_)cout<< timeCentroidMJD<<endl;
    1893           0 :         exposure          = (double)v_dataDump_[nt]->exposure()/1000000000LL;
    1894           0 :         floatDataDumpPtr_ = v_dataDump_[nt]->autoData();             // used by getData(na, nfe, ndd, nbi)
    1895             :         //cout << "floatDataDumpPtr_ = " << floatDataDumpPtr_ << endl;
    1896             :         //cout << "nt = " << nt << endl;
    1897             :         //cout<<"1st & 2nd data for nt="<<nt<<": "<<floatDataDumpPtr_[0]<<" "<<floatDataDumpPtr_[1]<<endl;
    1898             : 
    1899             : 
    1900             : //      for(unsigned int n=0; n<v_integrationPtr_.size();n++){
    1901             : //        nd = v_integrationPtr_[n]->numData();
    1902             : //        float* toto=v_integrationPtr_[n]->floatData();
    1903             : //        cout<<"ET LA with nt="<<nt
    1904             : //            <<" toto[0]="<<toto[0]
    1905             : //            <<" toto[1]="<<toto[1]
    1906             : //            <<" toto["<<nd-1<<"]="<<toto[nd-1]<<endl;
    1907             : //        cout<<"ET LA with nt="<<nt
    1908             : //            <<" &toto[0]="<<&toto[0]
    1909             : //            <<" &toto[1]="<<&toto[1]
    1910             : //            <<" &toto["<<nd-1<<"]="<<&toto[nd-1]<<endl;
    1911             : //      }
    1912             : 
    1913             : 
    1914           0 :         if(verbose_)cout <<"ici BB"<<endl;
    1915             : 
    1916           0 :         vector<AtmPhaseCorrection> v_uapc; v_uapc.push_back(AP_UNCORRECTED);
    1917             : 
    1918           0 :         unsigned int scn=0;
    1919           0 :         for(unsigned int na=0; na<v_antSet.size(); na++){
    1920           0 :           stateId = v_statePtr[na]->getStateId().getTagValue();
    1921           0 :           for(unsigned int nfe=0; nfe<numFeed; nfe++){
    1922           0 :             for(unsigned int ndd=0; ndd<v_ddList.size(); ndd++){
    1923           0 :               numBin = baselinesSet_->numBin(ndd);
    1924           0 :               numPol = baselinesSet_->numPol(baselinesSet_->getBasebandIndex(ndd));
    1925           0 :               if(numPol==4)numPol=3;                                 // if XX,XY,YX,YY then auto XX,XY,YY 
    1926           0 :               if(verbose_)cout<<"numPol="<<numPol
    1927           0 :                              <<"  na="  <<na
    1928           0 :                              <<" ant="  <<v_antSet[na].getTagValue()
    1929           0 :                              <<endl;
    1930           0 :               v_dataShape[0]=numPol;
    1931             :               //              if(complexData_)v_dataShape[0]*=2;
    1932           0 :               v_dataShape[1]=baselinesSet_->numChan(ndd);
    1933           0 :               v_dataShape[2]=1;                                      // auto-correlation never atm phase corrected
    1934           0 :               for(unsigned int nbi=0; nbi<numBin; nbi++){
    1935             :                 // the data and binary meta-data
    1936           0 :                 if(SDMBinData::syscal_)
    1937           0 :                   msDataPtr_ = getCalibratedData( na, nfe,
    1938             :                                                   ndd, nbi, 
    1939           0 :                                                   vv_tsys[nt][scn]);
    1940             :                 else
    1941           0 :                   msDataPtr_ = getData( na, nfe,
    1942             :                                         ndd, nbi);
    1943           0 :                 scn++;
    1944           0 :                 msDataPtr_->timeCentroid   = 86400.*timeCentroidMJD; // default value would there be no bin actualTimes
    1945           0 :                 msDataPtr_->exposure       = exposure;               // default value would there be no bin actualDurations
    1946           0 :                 msDataPtr_->flag           = 0;                      // default value is "false"  would there be no bin flags
    1947             :                 // calibrate and associate SDM meta-data
    1948           0 :                 if(msDataPtr_->numData>0){
    1949           0 :                   msDataPtr_->processorId        = cdPtr->getProcessorId().getTagValue();
    1950           0 :                   msDataPtr_->antennaId1         = v_antSet[na].getTagValue();
    1951           0 :                   msDataPtr_->antennaId2         = v_antSet[na].getTagValue();
    1952           0 :                   msDataPtr_->feedId1            = v_feedSet[na*numFeed+nfe];
    1953           0 :                   msDataPtr_->feedId2            = v_feedSet[na*numFeed+nfe];
    1954           0 :                   if(e_cm[CROSS_AND_AUTO])
    1955           0 :                     msDataPtr_->dataDescId       = baselinesSet_->getAutoDataDescriptionId(v_ddList[ndd]).getTagValue();
    1956             :                   else
    1957           0 :                     msDataPtr_->dataDescId       = v_ddList[ndd].getTagValue();
    1958           0 :                   msDataPtr_->phaseDir           = phaseDir;                     // TODO Apply the polynomial formula
    1959           0 :                   msDataPtr_->stateId            = stateId;
    1960             :                   /* This part is now done in the filler itself -  MC 23 Jul 2012
    1961             :                     msDataPtr_->msState            = getMSState( subscanNum, v_stateId,
    1962             :                                                                v_antSet, v_feedSet, v_ddList,
    1963             :                                                                na, nfe, ndd, timeOfDump);
    1964             :                   */
    1965           0 :                   msDataPtr_->v_dataShape        = v_dataShape;
    1966           0 :                   msDataPtr_->time               = 86400.*timeMJD;
    1967           0 :                   msDataPtr_->interval           = interval;
    1968           0 :                   msDataPtr_->v_atmPhaseCorrection = v_uapc;         // It is assumed that this is always the uncorrected case
    1969           0 :                   msDataPtr_->binNum             = nbi+1;
    1970           0 :                   msDataPtr_->fieldId            = fieldId;
    1971           0 :                   vector<unsigned int> v_projectNodes;
    1972           0 :                   if(v_dataDump_[nt]->integrationNum())v_projectNodes.push_back(v_dataDump_[nt]->integrationNum());
    1973           0 :                   if(v_dataDump_[nt]->subintegrationNum())v_projectNodes.push_back(v_dataDump_[nt]->subintegrationNum());
    1974           0 :                   msDataPtr_->projectPath        = v_projectNodes;
    1975             :                   // this pointer ends up in v_msDataPtr_ and is deleted from there
    1976           0 :                   v_msDataPtr_.push_back(msDataPtr_);                      // store in vector for export
    1977           0 :                 }
    1978           0 :                 if(verbose_)cout << "B/ msDataPtr_->numData=" <<msDataPtr_->numData << endl;
    1979             :               }
    1980             :             }
    1981             :           }
    1982             :         }
    1983           0 :       }
    1984             :     }
    1985             : 
    1986           0 :     if(verbose_)cout <<"ici CC: "<<e_qcm_.str()<<endl;
    1987           0 :     vector<AtmPhaseCorrection> v_atmPhaseCorrection = cdPtr->getAtmPhaseCorrection();
    1988           0 :     bool queryCrossData = false;
    1989           0 :     if(e_qcm_[CROSS_ONLY])     queryCrossData=true;
    1990           0 :     if(e_qcm_[CROSS_AND_AUTO]) queryCrossData=true;
    1991             : 
    1992           0 :     if(e_cm[AUTO_ONLY]==false && queryCrossData ){
    1993             : 
    1994             :       // select the queried apc
    1995           0 :       vector<unsigned int> v_napc;
    1996           0 :       EnumSet<AtmPhaseCorrection> es_apc; es_apc.set(v_atmPhaseCorrection);    if(verbose_)cout<<es_apc.str()<<endl;
    1997           0 :       if(verbose_)cout <<"es_apc from BLOB: " << es_apc.str()   << endl;
    1998           0 :       if(verbose_)cout <<"es_qapc_ queried: " << es_qapc_.str() << endl;
    1999           0 :       for(unsigned int napc=0; napc<v_atmPhaseCorrection.size(); napc++)
    2000           0 :         if(es_qapc_[v_atmPhaseCorrection[napc]])v_napc.push_back(napc);
    2001           0 :       if(verbose_)for(unsigned int n=0; n<v_napc.size(); n++)cout<<"v_napc["<<n<<"]="<<v_napc[n]<<endl;
    2002             : 
    2003           0 :       if(!v_napc.size()){
    2004           0 :         Error(WARNING,(char *) "No visibilities with AtmPhaseCorrection in the set {%s}",
    2005           0 :               es_qapc_.str().c_str());
    2006           0 :         return v_msDataPtr_;
    2007             :       }
    2008             : 
    2009           0 :       if(verbose_)cout<<"ici DD"<<endl;
    2010             : 
    2011             : 
    2012           0 :       for(unsigned int nt=0; nt<v_dataDump_.size(); nt++){
    2013           0 :         timeOfDump        = ArrayTime((int64_t)v_dataDump_[nt]->time());                if(verbose_)cout<<timeOfDump<<endl;
    2014           0 :         timeCentroidOfDump= ArrayTime((int64_t)v_dataDump_[nt]->timeCentroid());        if(verbose_)cout<< timeCentroidOfDump.toString() <<endl;
    2015           0 :         timeMJD           = timeOfDump.getMJD();                               if(verbose_)cout<<timeMJD<<" h"<<endl;
    2016           0 :         interval          = (double)v_dataDump_[nt]->interval()/1000000000LL;
    2017           0 :         timeCentroidMJD   = timeCentroidOfDump.getMJD();                       if(verbose_)cout<< timeCentroidMJD<<" h"<<endl;
    2018           0 :         exposure          = (double)v_dataDump_[nt]->exposure()/1000000000LL;;
    2019           0 :         if(verbose_)cout<<"ici DD 1"<<endl;
    2020           0 :         shortDataPtr_ = NULL;
    2021           0 :         longDataPtr_  = NULL;
    2022           0 :         floatDataPtr_ = NULL;
    2023           0 :         if(v_dataDump_[nt]->crossDataShort())
    2024           0 :           shortDataPtr_   = v_dataDump_[nt]->crossDataShort();       // used by getData(na, na2, nfe, ndd, nbi, napc)
    2025           0 :         else if(v_dataDump_[nt]->crossDataLong())
    2026           0 :           longDataPtr_    = v_dataDump_[nt]->crossDataLong();
    2027           0 :         else if(v_dataDump_[nt]->crossDataFloat())
    2028           0 :           floatDataPtr_    = v_dataDump_[nt]->crossDataFloat();
    2029             :         else
    2030           0 :           Error(FATAL, string("Cross data typed float not yet supported"));
    2031           0 :         if(verbose_)cout<<"ici DD 2"<<endl;
    2032           0 :         unsigned int scn=0;
    2033           0 :         for(unsigned int na1=0; na1<v_antSet.size(); na1++){
    2034             :           // we will assume that na2 has the same stateId (perhaps we should return a vector?)!
    2035           0 :           stateId = v_statePtr[na1]->getStateId().getTagValue();
    2036           0 :           for(unsigned int na2=na1+1; na2<v_antSet.size(); na2++){
    2037           0 :             for(unsigned int nfe=0; nfe<numFeed; nfe++){
    2038           0 :               for(unsigned int ndd=0; ndd<v_ddList.size(); ndd++){
    2039           0 :                 if(verbose_)cout<<"ici DD 3   numApc="<<baselinesSet_->numApc()<<endl;
    2040           0 :                 numBin = baselinesSet_->numBin(ndd);
    2041           0 :                 numPol = baselinesSet_->numPol(baselinesSet_->getBasebandIndex(ndd));   // nb of pol product (max is 4)
    2042           0 :                 if(verbose_)cout<<"ici DD 4   numBin="<<numBin<<"  numPol="<<numPol<<endl;
    2043           0 :                 v_dataShape[0]=baselinesSet_->numPol(ndd);
    2044           0 :                 v_dataShape[1]=baselinesSet_->numChan(ndd);
    2045           0 :                 v_dataShape[2]=baselinesSet_->numApc();
    2046           0 :                 v_dataShape[2]=1;               // qapc being not an EnumSet (MS limitation for floatData column)
    2047           0 :                 for(unsigned int nbi=0; nbi<numBin; nbi++){
    2048           0 :                   if(verbose_){
    2049           0 :                     cout<<"timeCentroidMJD="<<timeCentroidMJD<<endl;
    2050             :                   }
    2051             :                   // the data and binary meta-data
    2052           0 :                   if (verbose_) {
    2053           0 :                     cout << "nt = " << nt << endl;
    2054           0 :                     cout << "size of v_dataDump_ = " << v_dataDump_.size() << endl;
    2055             :                   }
    2056             : 
    2057           0 :                   if(SDMBinData::syscal_) {
    2058           0 :                     msDataPtr_ = getCalibratedData( na1, nfe, na2, nfe,
    2059             :                                           ndd,  nbi, v_napc,
    2060           0 :                                           v_dataDump_[nt]->scaleFactor(ndd),
    2061           0 :                                           vv_tsys[nt][scn]);
    2062             :                   }
    2063             :                   else {
    2064           0 :                     msDataPtr_ = getData( na1, nfe, na2, nfe,
    2065             :                                           ndd,  nbi, v_napc,
    2066           0 :                                           v_dataDump_[nt]->scaleFactor(ndd));
    2067             :                   }
    2068             : 
    2069           0 :                   msDataPtr_->timeCentroid  = 86400.*timeCentroidMJD; // default value would there be no bin actualTimes
    2070           0 :                   msDataPtr_->exposure      = exposure;               // default value would there be no bin actualDurations
    2071           0 :                   msDataPtr_->flag          = 0;                      // default value is "false"  would there be no bin flags
    2072           0 :                   if(verbose_)cout<<"ici DD 7 msDataPtr_->numData="<<msDataPtr_->numData<<endl;
    2073             :                   // the associated SDM meta-data
    2074           0 :                   if(msDataPtr_->numData>0){
    2075           0 :                     msDataPtr_->processorId          = cdPtr->getProcessorId().getTagValue();
    2076           0 :                     msDataPtr_->time                 = 86400.*timeMJD;
    2077           0 :                     msDataPtr_->antennaId1           = v_antSet[na1].getTagValue();
    2078           0 :                     msDataPtr_->antennaId2           = v_antSet[na2].getTagValue();
    2079           0 :                     msDataPtr_->feedId1              = v_feedSet[na1*numFeed+nfe];
    2080           0 :                     msDataPtr_->feedId2              = v_feedSet[na2*numFeed+nfe];
    2081           0 :                     msDataPtr_->dataDescId           = v_ddList[ndd].getTagValue();
    2082           0 :                     msDataPtr_->fieldId              = fieldId;
    2083           0 :                     msDataPtr_->phaseDir             = phaseDir;
    2084             :                     /* This part is now done in the filler itself -  MC 23 Jul 2012
    2085             :                     msDataPtr_->msState              = getMSState( subscanNum, v_stateId,
    2086             :                                                                    v_antSet, v_feedSet, v_ddList,
    2087             :                                                                    na1, nfe, ndd, timeOfDump);
    2088             :                     */
    2089             :                      // TODO Apply the polynomial formula
    2090           0 :                     msDataPtr_->v_dataShape          = v_dataShape;
    2091           0 :                     msDataPtr_->interval             = interval;
    2092           0 :                     msDataPtr_->v_atmPhaseCorrection = v_selected_apc;
    2093           0 :                     msDataPtr_->binNum               = nbi+1;              // a number is one-based.
    2094           0 :                     vector<unsigned int> v_projectNodes;
    2095           0 :                     if(v_dataDump_[nt]->integrationNum())v_projectNodes.push_back(v_dataDump_[nt]->integrationNum());
    2096           0 :                     if(v_dataDump_[nt]->subintegrationNum())v_projectNodes.push_back(v_dataDump_[nt]->subintegrationNum());
    2097           0 :                     msDataPtr_->projectPath          = v_projectNodes;
    2098           0 :                   }
    2099             :                   // store in vector for export
    2100             :                   // this point is put into v_msDataPtr_ and should be deleted from there
    2101           0 :                   if(msDataPtr_->numData>0)v_msDataPtr_.push_back(msDataPtr_);
    2102           0 :                   if(verbose_)cout << "A/ msDataPtr_->numData=" << msDataPtr_->numData << endl;
    2103           0 :                   scn++;
    2104             :                 }
    2105             :               }
    2106             :             }
    2107             :           }
    2108             :         }
    2109             :       }
    2110           0 :       if(verbose_)cout<<"v_msDataPtr_.size()="<< v_msDataPtr_.size() << endl;
    2111           0 :     }
    2112             : 
    2113           0 :     detachDataObject();
    2114           0 :     if (processorType(mainRowPtr_) == RADIOMETER) {
    2115           0 :       es_qapc_ = es_qapc_old;
    2116             :     }
    2117             : 
    2118           0 :     if (verbose_) cout << "SDMBinData::getData( Enum<CorrelationMode> e_qcm, EnumSet<AtmPhaseCorrection> es_qapc): exiting" << endl;
    2119           0 :     return v_msDataPtr_;
    2120           0 :   }
    2121             : 
    2122           0 :   MSData* SDMBinData::getData( unsigned int na, unsigned int nfe,
    2123             :                                unsigned int ndd, unsigned int nbin)
    2124             :   {
    2125           0 :     if (verbose_) cout << "SDMBinData::getData : entering" << endl;
    2126           0 :     unsigned int numBin = baselinesSet_->numBin(ndd);                  if(verbose_)cout << "numBin=" << numBin << endl;
    2127           0 :     if((nbin+1)>numBin)return 0;
    2128             : 
    2129             : 
    2130           0 :     msDataPtr_ = new MSData;
    2131             : 
    2132             : 
    2133           0 :     msDataPtr_->numData =  baselinesSet_->numAutoData(ndd)/numBin;  // number of measurements (NOT nb values)
    2134           0 :     msDataPtr_->v_data.resize(1);                                   // autoData have always an APC axis of 1
    2135             : 
    2136             :     
    2137           0 :     if(verbose_)cout << "About to retrieve " <<  msDataPtr_->numData
    2138           0 :                     << " auto-correlation measurements (auto correlations) encoded in floats" << endl;
    2139           0 :     if(verbose_)cout<<"SDMBinaryData::getData: Query for na="<<na<<" nfe="<<nfe<<" ndd="<<ndd<<" nbin="<<nbin<<endl;
    2140             : 
    2141             :     // ff    const float* autoData =  &floatDataDumpPtr_[baselinesSet_->transferId(na,ndd,nbin)/sizeof(float)];
    2142           0 :     const float* autoData =  &floatDataDumpPtr_[baselinesSet_->transferId(na,ndd,nbin)];
    2143           0 :     if(verbose_)cout <<"transferId(na,ndd,nbin)="<<baselinesSet_->transferId(na,ndd,nbin);
    2144             :     //if(baselinesSet_->numAutoData(ndd)>2){
    2145             :       
    2146             :     //   if(verbose_)
    2147             :     //  cout <<" up to "<<baselinesSet_->transferId(na,ndd,nbin)+(4*msDataPtr_->numData)/3<<" float values"<<endl;
    2148             :     // }else{
    2149             :     //   if(verbose_)
    2150             :     //  cout <<" up to "<<baselinesSet_->transferId(na,ndd,nbin)+msDataPtr_->numData<<" float values"<<endl;
    2151             :     // }
    2152             : //     if(baselinesSet_->transferId(na,ndd,nbin)+msDataPtr_->numData*sizeof(float)>autoCorrContainerSize_){
    2153             : //       Error(FATAL,"TOO MANY DATA for the Container");
    2154             : //       return 0;
    2155             : //     }
    2156             : 
    2157           0 :     if (baselinesSet_->numSdPol(ndd)>2)  msDataPtr_->numData =  (msDataPtr_->numData / 3 ) * 4; // Attention !!! the value of numData returned by baselinesSet_->numAutoData
    2158             :                                                                                                 // is equal to the size of sdPolProducts, e.g. 3 in the case of "XX XY YX",
    2159             :                                                                                                 // But the number of values to be retrieved in that specific case is 4
    2160             :                                                                                                 // since XX and YY are encoded as simple reals while XY is encoded as a complex.
    2161             :                                                                                                 // Hence this calculation. This tricky detail was discovered while I was working
    2162             :                                                                                                 // on CAS-6935 and ICT-3617.
    2163             :                                                                                                 // Michel Caillat - 24/09/2014
    2164             :                                                                
    2165           0 :     if(verbose_)cout << "numData=" << msDataPtr_->numData << endl;
    2166           0 :     if(verbose_)cout << "numSdPol("<<ndd<<")="<<baselinesSet_->numSdPol(ndd)<<endl;
    2167           0 :     if(baselinesSet_->numSdPol(ndd)>2){        // shape in complex to have the same shape as the visibilities
    2168           0 :       int nmax = msDataPtr_->numData / 4 * 6;  // Attention we assume that the auto data are stored on 1 float + 1 complex + 1 float
    2169             :                                                // (e.g. XX on one float, XY on 1 complex and YY on one float)
    2170             :                                                // and the idea is to reshape all this in three complexes.
    2171           0 :       msDataPtr_->v_data[0] = new float[nmax];
    2172           0 :       int k=0;
    2173           0 :       for (int n = 0; n < msDataPtr_->numData; n = n + 4) {
    2174           0 :         msDataPtr_->v_data[0][k++]=autoData[n];        // XX real
    2175           0 :         msDataPtr_->v_data[0][k++]=0.0;                // XX imaginary
    2176           0 :         msDataPtr_->v_data[0][k++]=autoData[n+1];      // XY real
    2177           0 :         msDataPtr_->v_data[0][k++]=autoData[n+2];      // XY imaginary
    2178           0 :         msDataPtr_->v_data[0][k++]=autoData[n+3];      // YY real
    2179           0 :         msDataPtr_->v_data[0][k++]=0.0;                // YY imaginary
    2180             :       }
    2181           0 :       if(verbose_){
    2182           0 :         cout << "1st auto: r " << msDataPtr_->v_data[0][0] << " i " << msDataPtr_->v_data[0][1] << endl;
    2183           0 :         cout << "2nd auto: r " << msDataPtr_->v_data[0][2] << " i " << msDataPtr_->v_data[0][3] << endl;
    2184           0 :         cout << "3rd auto: r " << msDataPtr_->v_data[0][4] << " i " << msDataPtr_->v_data[0][5] << endl;
    2185             :       }
    2186             : 
    2187           0 :       msDataPtr_->numData = nmax;
    2188           0 :       if(verbose_)cout << "k=" << k << endl;
    2189           0 :     }else if(forceComplex_){                  // original was 100% real data, transform shape in complex to have shape of visibilities
    2190           0 :       msDataPtr_->v_data[0] = new float[2*msDataPtr_->numData];
    2191           0 :       for(int n=0; n<msDataPtr_->numData; n++){
    2192           0 :         msDataPtr_->v_data[0][2*n]   = autoData[n];
    2193           0 :         msDataPtr_->v_data[0][2*n+1] = 0.0;
    2194             :       }
    2195           0 :       if(verbose_)cout << "1st auto: r " << msDataPtr_->v_data[0][0] << " i " << msDataPtr_->v_data[0][1] << endl;
    2196             :     }else{
    2197           0 :       msDataPtr_->v_data[0] = new float[msDataPtr_->numData];
    2198           0 :       for(int n=0; n<msDataPtr_->numData; n++)msDataPtr_->v_data[0][n]=autoData[n];
    2199           0 :       if(verbose_)cout << "1st auto: " <<(int) msDataPtr_->v_data[0][0] << " (a real value)" << endl;
    2200             :     }
    2201             : 
    2202           0 :     if(verbose_)
    2203           0 :       cout << " na="   << na
    2204           0 :            << " ndd="  << ndd
    2205           0 :            << " nbin=" << nbin
    2206           0 :            << endl;
    2207             : 
    2208             :     /*
    2209             :       This following in this method one needs is the location where one retrieve from the
    2210             :       the actualTimes and actualDurations the timeCentroid and exposure.
    2211             :       In the current design of the TotalPower binary there is no way to know that these
    2212             :       container are not present. Idem for the baselineFlags. Hence we drop this part but this
    2213             :       will have to be recovered when we will support both total power and correlator data in
    2214             :       this method.
    2215             :       In this context, timeCentroid and exposure are set equal to time and interval; they are
    2216             :       retrieved from v_integration.
    2217             :       NB: fieldId is now retrieved in getData(queryCorrmode)
    2218             :           interval: idem, from v_integration_
    2219             :     */
    2220             : 
    2221           0 :     if (verbose_) cout << "SDMBinData::getData : exiting for SD" << endl;
    2222           0 :     return msDataPtr_;
    2223             :   }
    2224             : 
    2225             : 
    2226           0 :   MSData* SDMBinData::getCalibratedData( unsigned int na, unsigned int nfe,
    2227             :                                          unsigned int ndd, unsigned int nbin,
    2228             :                                          pair<bool,vector<vector<float> > > p_tsys)
    2229             :   {
    2230           0 :     bool coutest=false;
    2231           0 :     unsigned int numBin = baselinesSet_->numBin(ndd);                  if(coutest)cout << "numBin=" << numBin << endl;
    2232           0 :     if((nbin+1)>numBin)return 0;
    2233             : 
    2234             : 
    2235           0 :     msDataPtr_ = new MSData;
    2236             : 
    2237             : 
    2238           0 :     msDataPtr_->numData =  baselinesSet_->numAutoData(ndd)/numBin;  // number of measurements (NOT nb values)
    2239           0 :     msDataPtr_->v_data.resize(1);                                   // autoData have always an APC axis of 1
    2240             : 
    2241           0 :     if(coutest)cout << "About to retrieve " <<  msDataPtr_->numData
    2242           0 :                     << " auto-correlation measurements (auto correlations) encoded in floats" << endl;
    2243           0 :     if(coutest)cout<<"SDMBinaryData::getData: Query for na="<<na<<" nfe="<<nfe<<" ndd="<<ndd<<" nbin="<<nbin<<endl;
    2244             : 
    2245             :     // ff    const float* autoData =  &floatDataDumpPtr_[baselinesSet_->transferId(na,ndd,nbin)/sizeof(float)];
    2246           0 :     const float* autoData =  &floatDataDumpPtr_[baselinesSet_->transferId(na,ndd,nbin)];
    2247           0 :     if(coutest)cout <<"transferId(na,ndd,nbin)="<<baselinesSet_->transferId(na,ndd,nbin);
    2248           0 :     if(baselinesSet_->numAutoData(ndd)>2){
    2249           0 :       if(coutest)
    2250           0 :         cout <<" up to "<<baselinesSet_->transferId(na,ndd,nbin)+(4*msDataPtr_->numData)/3<<" float values"<<endl;
    2251             :     }else{
    2252           0 :       if(coutest)
    2253           0 :         cout <<" up to "<<baselinesSet_->transferId(na,ndd,nbin)+msDataPtr_->numData<<" float values"<<endl;
    2254             :     }
    2255             : //     if(baselinesSet_->transferId(na,ndd,nbin)+msDataPtr_->numData*sizeof(float)>autoCorrContainerSize_){
    2256             : //       Error(FATAL,"TOO MANY DATA for the Container");
    2257             : //       return 0;
    2258             : //     }
    2259             : 
    2260           0 :     unsigned int numSdPol=baselinesSet_->numSdPol(ndd);
    2261           0 :     if(coutest)cout << "numData=" << msDataPtr_->numData << endl;
    2262           0 :     if(coutest)cout << "numSdPol("<<ndd<<")="<<baselinesSet_->numAutoData(ndd)<<endl;
    2263           0 :     if(numSdPol>2){        // shape in complex to have the same shape as the visibilities
    2264           0 :       int nmax=msDataPtr_->numData*2;     // {[(numdata*4)/3]*6}/4=numData*6/3=numData*2
    2265           0 :       msDataPtr_->v_data[0] = new float[nmax];
    2266           0 :       int k=0;
    2267           0 :       nmax=(msDataPtr_->numData*4)/3;
    2268           0 :       unsigned int nsp=0;
    2269           0 :       for(int n=0; n<nmax; n=n+4){
    2270           0 :         msDataPtr_->v_data[0][k++] = p_tsys.second[0][nsp]*autoData[n];                                // XX real
    2271           0 :         msDataPtr_->v_data[0][k++] = 0.0;                                                              // XX imaginary
    2272           0 :         msDataPtr_->v_data[0][k++] = sqrtf(p_tsys.second[0][nsp]*p_tsys.second[1][nsp])*autoData[n+1]; // XY real
    2273           0 :         msDataPtr_->v_data[0][k++] = sqrtf(p_tsys.second[0][nsp]*p_tsys.second[1][nsp])*autoData[n+2]; // XY imaginary
    2274           0 :         msDataPtr_->v_data[0][k++] = p_tsys.second[1][nsp]*autoData[n+3];                              // YY real
    2275           0 :         msDataPtr_->v_data[0][k++] = 0.0;                                                              // YY imaginary
    2276           0 :         nsp++;
    2277             :       }
    2278           0 :       if(coutest){
    2279           0 :         cout << "1st auto: r " << msDataPtr_->v_data[0][0] << " i " << msDataPtr_->v_data[0][1] << endl;
    2280           0 :         cout << "2nd auto: r " << msDataPtr_->v_data[0][2] << " i " << msDataPtr_->v_data[0][3] << endl;
    2281           0 :         cout << "3rd auto: r " << msDataPtr_->v_data[0][4] << " i " << msDataPtr_->v_data[0][5] << endl;
    2282           0 :         cout << "4th auto: r " << msDataPtr_->v_data[0][6] << " i " << msDataPtr_->v_data[0][7] << endl;
    2283           0 :         cout << "5th auto: r " << msDataPtr_->v_data[0][8] << " i " << msDataPtr_->v_data[0][9] << endl;
    2284           0 :         cout << "6th auto: r " << msDataPtr_->v_data[0][10]<< " i " << msDataPtr_->v_data[0][11]<< endl;
    2285             :       }
    2286           0 :       if(coutest)cout << "k=" << k << endl;
    2287           0 :     }else if(forceComplex_){                  // original was 100% real data, transform shape in complex to have shape of visibilities
    2288           0 :       msDataPtr_->v_data[0] = new float[2*msDataPtr_->numData];
    2289           0 :       if(numSdPol==1){
    2290           0 :         for(int n=0; n<msDataPtr_->numData; n++){
    2291           0 :           msDataPtr_->v_data[0][2*n]   = p_tsys.second[0][n]*autoData[n];
    2292           0 :           msDataPtr_->v_data[0][2*n+1] = 0.0;
    2293             :         }
    2294             :       }else{
    2295           0 :         for(int n=0; n<msDataPtr_->numData; n=n+2){
    2296           0 :           msDataPtr_->v_data[0][2*n]   = p_tsys.second[0][n]*autoData[n];
    2297           0 :           msDataPtr_->v_data[0][2*n+1] = 0.0;
    2298           0 :           msDataPtr_->v_data[0][2*n+2] = p_tsys.second[1][n]*autoData[n+1];
    2299           0 :           msDataPtr_->v_data[0][2*n+3] = 0.0;
    2300             :         }
    2301             :       }
    2302           0 :       if(coutest)cout << "1st auto: r " << msDataPtr_->v_data[0][0] << " i " << msDataPtr_->v_data[0][1] << endl;
    2303             :     }else{
    2304           0 :       msDataPtr_->v_data[0] = new float[msDataPtr_->numData];
    2305           0 :       if(numSdPol==1){
    2306           0 :         for(int n=0; n<msDataPtr_->numData; n++)
    2307           0 :           msDataPtr_->v_data[0][n] = p_tsys.second[0][n]*autoData[n];
    2308             :       }else{
    2309           0 :         for(int n=0; n<msDataPtr_->numData; n+=2){
    2310           0 :           msDataPtr_->v_data[0][n]   = p_tsys.second[0][n]*autoData[n];
    2311           0 :           msDataPtr_->v_data[0][n+1] = p_tsys.second[1][n]*autoData[n+1];
    2312             :         }
    2313             :       }
    2314           0 :       if(coutest)cout << "1st auto: " <<(int) msDataPtr_->v_data[0][0] << " (a calibrated real value)" << endl;
    2315             :     }
    2316             : 
    2317           0 :     if(coutest)
    2318           0 :       cout << " na="   << na
    2319           0 :            << " ndd="  << ndd
    2320           0 :            << " nbin=" << nbin
    2321           0 :            << endl;
    2322             : 
    2323             :     /*
    2324             :       This following in this method one needs is the location where one retrieve from the
    2325             :       the actualTimes and actualDurations the timeCentroid and exposure.
    2326             :       In the current design of the TotalPower binary ther is no way to know that these
    2327             :       container are not present. Idem for the baselineFlags. Hence we drop this part but this
    2328             :       will have to be recovered when we will support both total power and correlator data in
    2329             :       this method.
    2330             :       In this context, timeCentroid and exposure are set equal to time and interval; they are
    2331             :       retrieve from v_integration.
    2332             :       NB: fieldId is now retrieved in getData(queryCorrmode)
    2333             :           interval: idem, from v_integration_
    2334             :     */
    2335             : 
    2336             : 
    2337             : 
    2338           0 :     if(coutest)cout << "Exit getData for SD" << endl;
    2339             : 
    2340           0 :     return msDataPtr_;
    2341             :   }
    2342             : 
    2343             : 
    2344           0 :   MSData* SDMBinData::getData( unsigned int na1, unsigned int nfe1, unsigned int na2, unsigned int /*nfe2*/, // comment to avoid the unused parameter warning.
    2345             :                                unsigned int ndd, unsigned int nbin, vector<unsigned int> v_napc,
    2346             :                                float scaleFactor){
    2347           0 :     unsigned int nfe=nfe1;                                  // TODO multi-beam
    2348             : 
    2349           0 :     unsigned int numBin = baselinesSet_->numBin(ndd);                            
    2350           0 :     if((nbin+1)>numBin)return 0;
    2351             : 
    2352           0 :     unsigned int numApc = baselinesSet_->numApc();                               
    2353           0 :     for(unsigned int i=0; i<v_napc.size(); i++){
    2354           0 :       if((v_napc[i]+1)>numApc){
    2355           0 :         Error(FATAL,(char *) "error in the program: apc index exceeds  %d",numApc);
    2356           0 :         return 0;
    2357             :       }
    2358             :     }
    2359             : 
    2360           0 :     msDataPtr_ = new MSData;
    2361             : 
    2362           0 :     msDataPtr_->numData = baselinesSet_->numCrossData(ndd)/(numBin*numApc);  
    2363             : 
    2364           0 :     msDataPtr_->v_data.resize(v_napc.size());
    2365             : 
    2366             :     // the data (visibilities)
    2367             : 
    2368           0 :     for(unsigned int n=0; n<v_napc.size(); n++)
    2369           0 :       msDataPtr_->v_data[n] = new float[2*msDataPtr_->numData];               // a complex is composed of 2 floats
    2370             :     //float oneOverSF = 1./scaleFactor;
    2371           0 :     int base = 0;
    2372             : 
    2373           0 :     if(shortDataPtr_){ // case short ints 2 bytes
    2374           0 :       for(unsigned int i=0; i<v_napc.size(); i++){
    2375           0 :         base = baselinesSet_->transferId(na1,na2,nfe,ndd,nbin,v_napc[i]);
    2376           0 :         for(int n=0; n<2*msDataPtr_->numData; n++)
    2377           0 :           msDataPtr_->v_data[i][n] = shortDataPtr_[base+n]/scaleFactor; //oneOverSF * (float)shortDataPtr_[base+n];
    2378             :       }
    2379             :     }
    2380             : 
    2381           0 :     else if (longDataPtr_){   // case ints 4 bytes
    2382           0 :       for(unsigned int i=0; i<v_napc.size(); i++){
    2383           0 :         base = baselinesSet_->transferId(na1,na2,nfe,ndd,nbin,v_napc[i]);
    2384           0 :         for(int n=0; n<2*msDataPtr_->numData; n++)
    2385           0 :           msDataPtr_->v_data[i][n] = longDataPtr_[base+n]/scaleFactor; //oneOverSF * (float)longDataPtr_[base+n];
    2386             :       }
    2387             :     }
    2388             :     else{       // case floats
    2389           0 :       for(unsigned int i=0; i<v_napc.size(); i++){
    2390           0 :         base = baselinesSet_->transferId(na1,na2,nfe,ndd,nbin,v_napc[i]);
    2391           0 :         for(int n=0; n<2*msDataPtr_->numData; n++){
    2392           0 :           msDataPtr_->v_data[i][n] = floatDataPtr_[base+n]/scaleFactor; //oneOverSF * floatDataPtr_[base+n];
    2393             :         }
    2394             :       }
    2395             :     }
    2396             :   
    2397           0 :     return msDataPtr_;
    2398             :   }
    2399             : 
    2400           0 :   MSData* SDMBinData::getCalibratedData( unsigned int /*na1*/, unsigned int /*nfe1*/, unsigned int /*na2*/, unsigned int /*nfe2*/,
    2401             :                                          unsigned int /*ndd*/, unsigned int /*nbin*/, vector<unsigned int> /*v_napc*/,
    2402             :                                          float /*scaleFactor*/,
    2403             :                                          pair<bool,vector<vector<float> > > /*p_tsys*/){  // comment to avoid the unused parameter warning.
    2404             : #if 1
    2405           0 :     return 0;
    2406             : #else
    2407             :     bool coutest=false;                                   // temporary: to check
    2408             : 
    2409             :     if(coutest)cout<<"scaleFactor="<<scaleFactor<<endl;
    2410             : 
    2411             :     // cout<<"v_napc.size()="<<v_napc.size()<<endl;
    2412             : 
    2413             :     unsigned int nfe=nfe1;                                  // TODO multi-beam
    2414             : 
    2415             :     unsigned int numBin = baselinesSet_->numBin(ndd);                            if(coutest)cout << "numBin=" << numBin << endl;
    2416             :     if((nbin+1)>numBin)return 0;
    2417             : 
    2418             :     unsigned int numApc = baselinesSet_->numApc();                               if(coutest)cout << "numApc=" << numApc << endl;
    2419             :     for(unsigned int i=0; i<v_napc.size(); i++){
    2420             :       if((v_napc[i]+1)>numApc){
    2421             :         Error(FATAL,"error in the program: apc index exceeds  %d",numApc);
    2422             :         return 0;
    2423             :       }
    2424             :     }
    2425             : 
    2426             : 
    2427             :     msDataPtr_ = new MSData;
    2428             : 
    2429             :     msDataPtr_->numData = baselinesSet_->numCrossData(ndd)/(numBin*numApc);  if(coutest)cout << "numCrossData="
    2430             :                                                                                              << baselinesSet_->numCrossData(ndd) << endl;
    2431             :     msDataPtr_->v_data.resize(v_napc.size());
    2432             :     // the data (visibilities)
    2433             :     if(coutest)cout << "About to retrieve " <<  msDataPtr_->numData << " visibilities per dump"<< endl;
    2434             : 
    2435             : 
    2436             :     for(unsigned int n=0; n<v_napc.size(); n++)
    2437             :       msDataPtr_->v_data[n] = new float[2*msDataPtr_->numData];               // a complex is composed of 2 floats
    2438             : 
    2439             :     if(shortDataPtr_){                                                        // case 2 bytes
    2440             :       for(unsigned int i=0; i<v_napc.size(); i++){
    2441             :         if(coutest){
    2442             :           cout << "2 bytes case: baselinesSet_->transferId(na1="<<na1
    2443             :                <<",na2="<<na2<<",ndd="<<ndd<<",nbin="<<nbin<<",napc="<<v_napc[i]<<")="
    2444             :                << baselinesSet_->transferId(na1,na2,ndd,nbin,v_napc[i])
    2445             :                << endl;
    2446             :           cout<<"msDataPtr_->numData="<<msDataPtr_->numData<<" scaleFactor="<<scaleFactor<<endl;
    2447             :         }
    2448             :         int np=0;
    2449             :         for(int n=0; n<2*msDataPtr_->numData; n++){
    2450             :           msDataPtr_->v_data[i][n] = p_tsys.second[np%numPol][] *
    2451             :             (1./scaleFactor) * (float)shortDataPtr_[baselinesSet_->transferId(na1,na2,nfe,ndd,nbin,v_napc[i])+n];
    2452             :         }
    2453             :       }
    2454             :     }else{   // case 4 bytes
    2455             :       for(unsigned int i=0; i<v_napc.size(); i++){
    2456             :         if(coutest)
    2457             :           cout << "4 bytes case: baselinesSet_->transferId(na="<<na1<<",na2="<<na2
    2458             :                <<",ndd="<<ndd<<",nbin="<<nbin<<",napc="<<v_napc[i]<<")="
    2459             :                << baselinesSet_->transferId(na1,na2,ndd,nbin,v_napc[i])
    2460             :                << endl;
    2461             :         if(longDataPtr_){
    2462             :           for(int n=0; n<2*msDataPtr_->numData; n++){
    2463             :             msDataPtr_->v_data[i][n] =
    2464             :               (1./scaleFactor) * (float)longDataPtr_[baselinesSet_->transferId(na1,na2,nfe,ndd,nbin,v_napc[i])+n];
    2465             :           }
    2466             :         }else{
    2467             :           for(int n=0; n<2*msDataPtr_->numData; n++){
    2468             :             msDataPtr_->v_data[i][n] =
    2469             :               (1./scaleFactor) * floatDataPtr_[baselinesSet_->transferId(na1,na2,nfe,ndd,nbin,v_napc[i])+n];
    2470             :           }
    2471             :         }
    2472             :       }
    2473             :     }
    2474             :     if(coutest){
    2475             :       cout << "numData=" << msDataPtr_->numData << endl;
    2476             :       for(unsigned int i=0; i<v_napc.size(); i++)
    2477             :         cout << "1st vis apc=v_napc[i]: re " << msDataPtr_->v_data[i][0]
    2478             :              << " im " <<  msDataPtr_->v_data[i][1] << endl;
    2479             :       cout << " na1=" << na1
    2480             :            << " na2=" << na2
    2481             :            << " ndd=" << ndd
    2482             :            << " napc="; for(unsigned int i=0; i< v_napc.size(); i++)cout<<v_napc[i]<<" ";
    2483             :       cout << " nbin=" << nbin
    2484             :            << endl;
    2485             :     }
    2486             :     return msDataPtr_;
    2487             : #endif
    2488             :   }
    2489             : 
    2490             : 
    2491             : 
    2492           0 :   MSData*          SDMBinData::getData( Tag /*antId*/, int /*feedId*/,
    2493             :                                         Tag /*dataDescId*/,
    2494             :                                         AtmPhaseCorrection /*apc*/,
    2495             :                                         unsigned int  /*binNum*/){ // comment to avoid the unused parameter warning.
    2496           0 :     return msDataPtr_;
    2497             :   }
    2498             : 
    2499           0 :   MSData*          SDMBinData::getData( Tag /*antId1*/, int /*feedId1*/,
    2500             :                                         Tag /*antId2*/, int /*feedId2*/,
    2501             :                                         Tag /*dataDescId*/,
    2502             :                                         vector<AtmPhaseCorrection> /*v_apc*/,
    2503             :                                         unsigned int  /*binNum*/){
    2504           0 :     return msDataPtr_;
    2505             :   }
    2506             : 
    2507           0 :   vector<pair<unsigned int,double> > SDMBinData::timeSequence()const{
    2508           0 :     return v_tci_;
    2509             :   }
    2510             : 
    2511           0 :   const VMSData* SDMBinData::getDataCols(Enum<CorrelationMode> e_qcm, EnumSet<AtmPhaseCorrection> es_qapc){
    2512             : 
    2513           0 :     if (verbose_) cout << "SDMBinData::getDataCols(Enum<CorrelationMode> e_qcm, EnumSet<AtmPhaseCorrection> es_qapc) : entering." << endl;
    2514             : 
    2515           0 :     if(v_msDataPtr_.size()>0){
    2516           0 :       if(coutDeleteInfo_)cout << "delete v_msDataPtr_[n]->xData" << endl;
    2517           0 :       for(vector<MSData*>::reverse_iterator it=v_msDataPtr_.rbegin(); it!=v_msDataPtr_.rend(); ++it)deleteMsData(*it);
    2518             :       
    2519           0 :       if(vmsDataPtr_){
    2520           0 :         if(coutDeleteInfo_)cout<<"about to delete vmsDataPtr_"<<endl;
    2521           0 :         for(unsigned int n=0; n<vmsDataPtr_->v_m_data.size(); n++)vmsDataPtr_->v_m_data[n].clear();
    2522           0 :         vmsDataPtr_->v_m_data.clear();    // a priori inutile
    2523           0 :         delete vmsDataPtr_;
    2524           0 :         vmsDataPtr_=NULL;
    2525             :       }
    2526             :     }
    2527             : 
    2528           0 :     v_msDataPtr_.clear();
    2529           0 :     v_msDataPtr_ = getData( e_qcm, es_qapc );
    2530             : 
    2531           0 :     int numRows=v_msDataPtr_.size();
    2532           0 :     if(verbose_)cout<<"Number of MS row for this SDM BLOB: " << numRows <<endl;
    2533             : 
    2534           0 :     if(coutDeleteInfo_&&vmsDataPtr_!=0)cout << "delete vmsDataPtr_" << endl;
    2535           0 :     if(vmsDataPtr_!=0)delete vmsDataPtr_;
    2536           0 :     vmsDataPtr_ = new VMSData;
    2537             : 
    2538             :     //VMSData* vmsDataPtr_ = new VMSData;
    2539           0 :     if(!vmsDataPtr_)
    2540           0 :       Error(FATAL,string("Fail to allocate memory for a new VMSData type structure"));
    2541             : 
    2542             : 
    2543             :     // the fields of the SDM key shared by all MS rows for this SDM Main entry:
    2544           0 :     if(numRows){
    2545           0 :       vmsDataPtr_->processorId          = v_msDataPtr_[0]->processorId;
    2546           0 :       vmsDataPtr_->binNum               = v_msDataPtr_[0]->binNum;
    2547             :     }
    2548             : 
    2549           0 :     unsigned int numApcMax=0;
    2550           0 :     for(int n=0; n<numRows; n++){
    2551           0 :       if(v_msDataPtr_[n]->v_atmPhaseCorrection.size()>numApcMax)
    2552           0 :         numApcMax=v_msDataPtr_[n]->v_atmPhaseCorrection.size();
    2553             :     }
    2554           0 :     if(verbose_)cout<<"numApcMax="<<numApcMax<<endl;
    2555             : 
    2556           0 :     multimap<int,unsigned int> mm_dd;
    2557           0 :     if (ddfirst_) {
    2558           0 :       vector<int> ddId_v;
    2559           0 :       vector<int>::iterator ddId_i;
    2560           0 :       int ddIdOld = -1;
    2561           0 :       int ddIndex = -1;
    2562             :  
    2563           0 :       for(unsigned int n=0; n<v_msDataPtr_.size(); n++) {
    2564           0 :         if (v_msDataPtr_[n]->dataDescId != ddIdOld) {
    2565           0 :           ddIdOld = v_msDataPtr_[n]->dataDescId ;
    2566           0 :           ddId_i = find(ddId_v.begin(), ddId_v.end(),ddIdOld);
    2567           0 :           if (ddId_i == ddId_v.end()) {
    2568           0 :             ddId_v.push_back(ddIdOld);
    2569           0 :             ddIndex = ddId_v.size()-1;
    2570             :           }
    2571             :           else 
    2572           0 :             ddIndex = ddId_i - ddId_v.begin();
    2573             :         }
    2574           0 :         mm_dd.insert(make_pair(ddIndex,n));       
    2575             :       }
    2576           0 :     }
    2577             : 
    2578             :     /*
    2579             :     multimap<int,unsigned int> mm_dd;
    2580             :     if(ddfirst_){
    2581             :       for(unsigned int n=0; n<v_msDataPtr_.size(); n++)
    2582             :         mm_dd.insert(make_pair(v_msDataPtr_[n]->dataDescId,n));
    2583             :     }
    2584             :     */
    2585             : 
    2586           0 :     v_tci_.clear();  
    2587           0 :     v_tci_.resize(numRows);
    2588             : 
    2589           0 :     if(ddfirst_){   // the dataDescription/time/baseline expansion
    2590             : 
    2591           0 :       unsigned int n, i=0;
    2592           0 :       multimap<int,unsigned int>::const_iterator it;
    2593           0 :       for(it=mm_dd.begin(); it!=mm_dd.end(); ++it){
    2594           0 :         n=it->second;
    2595           0 :         vmsDataPtr_->v_time.push_back(v_msDataPtr_[n]->time);
    2596           0 :         vmsDataPtr_->v_fieldId.push_back(v_msDataPtr_[n]->fieldId);
    2597           0 :         vmsDataPtr_->v_interval.push_back(v_msDataPtr_[0]->interval);
    2598           0 :         vmsDataPtr_->v_antennaId1.push_back(v_msDataPtr_[n]->antennaId1);
    2599           0 :         vmsDataPtr_->v_antennaId2.push_back(v_msDataPtr_[n]->antennaId2);
    2600           0 :         vmsDataPtr_->v_feedId1.push_back(v_msDataPtr_[n]->feedId1);
    2601           0 :         vmsDataPtr_->v_feedId2.push_back(v_msDataPtr_[n]->feedId2);
    2602           0 :         vmsDataPtr_->v_dataDescId.push_back(v_msDataPtr_[n]->dataDescId);
    2603           0 :         vmsDataPtr_->v_timeCentroid.push_back(v_msDataPtr_[n]->timeCentroid);
    2604           0 :         vmsDataPtr_->v_exposure.push_back(v_msDataPtr_[n]->exposure);
    2605           0 :         vmsDataPtr_->v_numData.push_back(v_msDataPtr_[n]->numData);
    2606           0 :         vmsDataPtr_->vv_dataShape.push_back(v_msDataPtr_[n]->v_dataShape);
    2607           0 :         vmsDataPtr_->v_phaseDir.push_back(v_msDataPtr_[n]->phaseDir);
    2608           0 :         vmsDataPtr_->v_stateId.push_back(v_msDataPtr_[n]->stateId);
    2609           0 :         vmsDataPtr_->v_msState.push_back(v_msDataPtr_[n]->msState);
    2610           0 :         vmsDataPtr_->v_flag.push_back(v_msDataPtr_[n]->flag);
    2611             : 
    2612           0 :         vmsDataPtr_->v_atmPhaseCorrection = v_msDataPtr_[n]->v_atmPhaseCorrection;
    2613           0 :         map<AtmPhaseCorrection,float*> m_vdata;
    2614           0 :         for(unsigned int napc=0; napc<vmsDataPtr_->v_atmPhaseCorrection.size(); napc++){
    2615           0 :           float* d=v_msDataPtr_[n]->v_data[napc];
    2616           0 :           m_vdata.insert(make_pair(vmsDataPtr_->v_atmPhaseCorrection[napc],d));
    2617             :         }
    2618           0 :         vmsDataPtr_->v_m_data.push_back(m_vdata);
    2619             :         //cout<<"dataDescriptionId="<<it->first<<" row="<<it->second<<endl;
    2620             : 
    2621           0 :         pair<unsigned int,double> p=make_pair(i++,v_msDataPtr_[n]->timeCentroid);
    2622           0 :         v_tci_[n]=p;
    2623           0 :       }
    2624             : 
    2625             :     }else{    // the baseline/dataDescription expansion
    2626             : 
    2627             :       
    2628           0 :       for(int n=0; n<numRows; n++){
    2629             : 
    2630           0 :         vmsDataPtr_->v_time.push_back(v_msDataPtr_[n]->time);
    2631           0 :         vmsDataPtr_->v_fieldId.push_back(v_msDataPtr_[n]->fieldId);
    2632           0 :         vmsDataPtr_->v_interval.push_back(v_msDataPtr_[0]->interval);
    2633           0 :         vmsDataPtr_->v_antennaId1.push_back(v_msDataPtr_[n]->antennaId1);
    2634           0 :         vmsDataPtr_->v_antennaId2.push_back(v_msDataPtr_[n]->antennaId2);
    2635           0 :         vmsDataPtr_->v_feedId1.push_back(v_msDataPtr_[n]->feedId1);
    2636           0 :         vmsDataPtr_->v_feedId2.push_back(v_msDataPtr_[n]->feedId2);
    2637           0 :         vmsDataPtr_->v_dataDescId.push_back(v_msDataPtr_[n]->dataDescId);
    2638           0 :         vmsDataPtr_->v_timeCentroid.push_back(v_msDataPtr_[n]->timeCentroid);
    2639           0 :         vmsDataPtr_->v_exposure.push_back(v_msDataPtr_[n]->exposure);
    2640           0 :         vmsDataPtr_->v_numData.push_back(v_msDataPtr_[n]->numData);
    2641           0 :         vmsDataPtr_->vv_dataShape.push_back(v_msDataPtr_[n]->v_dataShape);
    2642           0 :         vmsDataPtr_->v_phaseDir.push_back(v_msDataPtr_[n]->phaseDir);
    2643           0 :         vmsDataPtr_->v_stateId.push_back(v_msDataPtr_[n]->stateId);
    2644           0 :         vmsDataPtr_->v_msState.push_back(v_msDataPtr_[n]->msState);
    2645           0 :         vmsDataPtr_->v_flag.push_back(v_msDataPtr_[n]->flag);
    2646             : 
    2647           0 :         vmsDataPtr_->v_atmPhaseCorrection = v_msDataPtr_[n]->v_atmPhaseCorrection;
    2648           0 :         map<AtmPhaseCorrection,float*> m_vdata;
    2649           0 :         for(unsigned int napc=0; napc<vmsDataPtr_->v_atmPhaseCorrection.size(); napc++){
    2650           0 :           float* d=v_msDataPtr_[n]->v_data[napc];
    2651           0 :           m_vdata.insert(make_pair(vmsDataPtr_->v_atmPhaseCorrection[napc],d));
    2652             :         }
    2653           0 :         vmsDataPtr_->v_m_data.push_back(m_vdata);
    2654             : 
    2655           0 :         v_tci_[n] = make_pair(n,v_msDataPtr_[n]->timeCentroid);
    2656             : 
    2657           0 :       }
    2658             : 
    2659             :     }
    2660             : 
    2661           0 :     detachDataObject();
    2662           0 :     if (verbose_) cout << "SDMBinData::getDataCols(Enum<CorrelationMode> e_qcm, EnumSet<AtmPhaseCorrection> es_qapc) : exiting." << endl;
    2663           0 :     return vmsDataPtr_;
    2664           0 :   }
    2665             : 
    2666             : 
    2667           0 :   const VMSData* SDMBinData::getDataCols(){
    2668           0 :     if (verbose_) cout << "SDMBinData::getDataCols() : entering." << endl; 
    2669           0 :     Enum<CorrelationMode>       e_qcm;
    2670           0 :     EnumSet<AtmPhaseCorrection> es_qapc;
    2671           0 :     if(canSelect_){
    2672             :       //cout<<"INFORM: context allow to select"<<endl;
    2673           0 :       e_qcm   = e_qcm_;
    2674           0 :       es_qapc = es_qapc_;
    2675             :     }
    2676           0 :     const VMSData* result = getDataCols( e_qcm, es_qapc );
    2677           0 :     if (verbose_) cout << "SDMBinData::getDataCols() : exiting." << endl; 
    2678           0 :     return result;
    2679             :   }
    2680             : 
    2681           0 :   void  SDMBinData::deleteMsData(MSData* msDataPtr){
    2682           0 :     if(msDataPtr){
    2683           0 :       for(unsigned int i=0; i<msDataPtr->v_data.size(); i++){
    2684           0 :         if(msDataPtr->v_data[i]){
    2685           0 :           delete[] msDataPtr->v_data[i];
    2686             :           //if(coutDeleteInfo_)cout << "data in MS data object deleted" << endl;
    2687           0 :           msDataPtr->v_data[i] = 0;
    2688             :         }
    2689             :       }
    2690             : 
    2691           0 :       delete msDataPtr;   //  if(coutDeleteInfo_)cout<<"MS data object deleted"<<endl;
    2692           0 :       msDataPtr=0;
    2693             :     }
    2694           0 :     return;
    2695             :   }
    2696             : 
    2697           0 :   const VMSData* SDMBinData::getNextMSMainCols(unsigned int nDataSubset) {
    2698           0 :     Enum<CorrelationMode>       e_qcm;
    2699           0 :     EnumSet<AtmPhaseCorrection> es_qapc;
    2700           0 :     if(canSelect_){
    2701           0 :       cout<<"INFORM: context allow to select"<<endl;
    2702           0 :       e_qcm   = e_qcm_;
    2703           0 :       es_qapc = es_qapc_;
    2704             :     }
    2705           0 :     return getNextMSMainCols( e_qcm, es_qapc, nDataSubset);
    2706             :   }
    2707             : 
    2708           0 :   const VMSData* SDMBinData::getNextMSMainCols(Enum<CorrelationMode> e_qcm, EnumSet<AtmPhaseCorrection> es_qapc, unsigned int nDataSubset) {
    2709           0 :     if (verbose_) cout << "SDMBinData::getNextMSMainCols : entering" << endl;
    2710             : 
    2711             :     // Delete the content of v_msDataPtr if any
    2712           0 :     if ( v_msDataPtr_.size() > 0 ){
    2713           0 :       if(verbose_)cout << "delete v_msDataPtr_[n]->xData" << endl;
    2714           0 :       for(vector<MSData*>::reverse_iterator it=v_msDataPtr_.rbegin(); it!=v_msDataPtr_.rend(); ++it)deleteMsData(*it);
    2715             :       
    2716           0 :       if(vmsDataPtr_){
    2717           0 :         if(verbose_)cout<<"about to delete vmsDataPtr_"<<endl;
    2718           0 :         for(unsigned int n=0; n<vmsDataPtr_->v_m_data.size(); n++)
    2719           0 :           vmsDataPtr_->v_m_data[n].clear();
    2720           0 :         vmsDataPtr_->v_m_data.clear();    // a priori inutile
    2721           0 :         delete vmsDataPtr_;
    2722           0 :         vmsDataPtr_=NULL;
    2723             :       }
    2724             :     }
    2725             : 
    2726           0 :     v_msDataPtr_.clear(); // I doubt this is really useful ... (MC 08/12/2011)
    2727             :     
    2728             :     // No more data available... then return empty content.
    2729           0 :     if  (!sdmdosr.hasSubset()) {
    2730           0 :       return NULL;
    2731             :     }
    2732             : 
    2733           0 :     v_msDataPtr_ = getMSDataFromBDFData(e_qcm, es_qapc, nDataSubset);
    2734           0 :     int numRows = v_msDataPtr_.size();
    2735           0 :     if (verbose_) cout << "Number of MS Main rows for this block of " << nDataSubset << " [sub]integrations in '" << sdmdosr.dataOID() << "' = " << numRows << endl; 
    2736             : 
    2737           0 :     if(verbose_&&vmsDataPtr_!=0) cout << "delete vmsDataPtr_" << endl;
    2738           0 :     if(vmsDataPtr_!=0)delete vmsDataPtr_;
    2739           0 :     vmsDataPtr_ = new VMSData;
    2740             : 
    2741           0 :     if(!vmsDataPtr_)
    2742           0 :       Error(FATAL, string("Fail to allocate memory for a new VMSData type structure"));
    2743             : 
    2744           0 :    if(numRows){
    2745           0 :       vmsDataPtr_->processorId          = v_msDataPtr_[0]->processorId;
    2746           0 :       vmsDataPtr_->binNum               = v_msDataPtr_[0]->binNum;
    2747             :     }
    2748             : 
    2749           0 :     unsigned int numApcMax=0;
    2750           0 :     for(int n=0; n<numRows; n++){
    2751           0 :       if(v_msDataPtr_[n]->v_atmPhaseCorrection.size()>numApcMax)
    2752           0 :         numApcMax=v_msDataPtr_[n]->v_atmPhaseCorrection.size();
    2753             :     }
    2754           0 :     if(verbose_)cout<<"numApcMax="<<numApcMax<<endl;
    2755             : 
    2756           0 :     multimap<int,unsigned int> mm_dd;
    2757           0 :     if (ddfirst_) {
    2758           0 :       vector<int> ddId_v;
    2759           0 :       vector<int>::iterator ddId_i;
    2760           0 :       int ddIdOld = -1;
    2761           0 :       int ddIndex = -1;
    2762             :  
    2763           0 :       for(unsigned int n=0; n<v_msDataPtr_.size(); n++) {
    2764           0 :         if (v_msDataPtr_[n]->dataDescId != ddIdOld) {
    2765           0 :           ddIdOld = v_msDataPtr_[n]->dataDescId ;
    2766           0 :           if ((ddId_i = find(ddId_v.begin(), ddId_v.end(),ddIdOld)) == ddId_v.end()) {
    2767           0 :             ddId_v.push_back(ddIdOld);
    2768           0 :             ddIndex = ddId_v.size()-1;
    2769             :           }
    2770             :           else 
    2771           0 :             ddIndex = ddId_i - ddId_v.begin();
    2772             :         }
    2773           0 :         mm_dd.insert(make_pair(ddIndex,n));       
    2774             :       }
    2775           0 :     }
    2776             : /*
    2777             :     multimap<int,unsigned int> mm_dd;
    2778             :     if(ddfirst_){
    2779             :       for(unsigned int n=0; n<v_msDataPtr_.size(); n++)
    2780             :         mm_dd.insert(make_pair(v_msDataPtr_[n]->dataDescId,n));
    2781             :     }
    2782             : */
    2783           0 :     v_tci_.clear();  
    2784           0 :     v_tci_.resize(numRows);
    2785             : 
    2786           0 :     if(ddfirst_){   // the dataDescription/time/baseline expansion
    2787             : 
    2788           0 :       unsigned int n, i=0;
    2789           0 :       multimap<int,unsigned int>::const_iterator it;
    2790           0 :       for(it=mm_dd.begin(); it!=mm_dd.end(); ++it){
    2791           0 :         n=it->second;
    2792           0 :         vmsDataPtr_->v_time.push_back(v_msDataPtr_[n]->time);
    2793           0 :         vmsDataPtr_->v_fieldId.push_back(v_msDataPtr_[n]->fieldId);
    2794           0 :         vmsDataPtr_->v_interval.push_back(v_msDataPtr_[0]->interval);
    2795           0 :         vmsDataPtr_->v_antennaId1.push_back(v_msDataPtr_[n]->antennaId1);
    2796           0 :         vmsDataPtr_->v_antennaId2.push_back(v_msDataPtr_[n]->antennaId2);
    2797           0 :         vmsDataPtr_->v_feedId1.push_back(v_msDataPtr_[n]->feedId1);
    2798           0 :         vmsDataPtr_->v_feedId2.push_back(v_msDataPtr_[n]->feedId2);
    2799           0 :         vmsDataPtr_->v_dataDescId.push_back(v_msDataPtr_[n]->dataDescId);
    2800           0 :         vmsDataPtr_->v_timeCentroid.push_back(v_msDataPtr_[n]->timeCentroid);
    2801           0 :         vmsDataPtr_->v_exposure.push_back(v_msDataPtr_[n]->exposure);
    2802           0 :         vmsDataPtr_->v_numData.push_back(v_msDataPtr_[n]->numData);
    2803           0 :         vmsDataPtr_->vv_dataShape.push_back(v_msDataPtr_[n]->v_dataShape);
    2804           0 :         vmsDataPtr_->v_phaseDir.push_back(v_msDataPtr_[n]->phaseDir);
    2805           0 :         vmsDataPtr_->v_stateId.push_back(v_msDataPtr_[n]->stateId);
    2806           0 :         vmsDataPtr_->v_msState.push_back(v_msDataPtr_[n]->msState);
    2807           0 :         vmsDataPtr_->v_flag.push_back(v_msDataPtr_[n]->flag);
    2808             : 
    2809           0 :         vmsDataPtr_->v_atmPhaseCorrection = v_msDataPtr_[n]->v_atmPhaseCorrection;
    2810           0 :         map<AtmPhaseCorrection,float*> m_vdata;
    2811           0 :         for(unsigned int napc=0; napc<vmsDataPtr_->v_atmPhaseCorrection.size(); napc++){
    2812           0 :           float* d=v_msDataPtr_[n]->v_data[napc];
    2813           0 :           m_vdata.insert(make_pair(vmsDataPtr_->v_atmPhaseCorrection[napc],d));
    2814             :         }
    2815           0 :         vmsDataPtr_->v_m_data.push_back(m_vdata);
    2816             :         //cout<<"dataDescriptionId="<<it->first<<" row="<<it->second<<endl;
    2817             : 
    2818           0 :         pair<unsigned int,double> p=make_pair(i++,v_msDataPtr_[n]->timeCentroid);
    2819           0 :         v_tci_[n]=p;
    2820           0 :       }
    2821             : 
    2822             :     }else{    // the baseline/dataDescription expansion
    2823             : 
    2824             :       
    2825           0 :       for(int n=0; n<numRows; n++){
    2826             : 
    2827           0 :         vmsDataPtr_->v_time.push_back(v_msDataPtr_[n]->time);
    2828           0 :         vmsDataPtr_->v_fieldId.push_back(v_msDataPtr_[n]->fieldId);
    2829           0 :         vmsDataPtr_->v_interval.push_back(v_msDataPtr_[0]->interval);
    2830           0 :         vmsDataPtr_->v_antennaId1.push_back(v_msDataPtr_[n]->antennaId1);
    2831           0 :         vmsDataPtr_->v_antennaId2.push_back(v_msDataPtr_[n]->antennaId2);
    2832           0 :         vmsDataPtr_->v_feedId1.push_back(v_msDataPtr_[n]->feedId1);
    2833           0 :         vmsDataPtr_->v_feedId2.push_back(v_msDataPtr_[n]->feedId2);
    2834           0 :         vmsDataPtr_->v_dataDescId.push_back(v_msDataPtr_[n]->dataDescId);
    2835           0 :         vmsDataPtr_->v_timeCentroid.push_back(v_msDataPtr_[n]->timeCentroid);
    2836           0 :         vmsDataPtr_->v_exposure.push_back(v_msDataPtr_[n]->exposure);
    2837           0 :         vmsDataPtr_->v_numData.push_back(v_msDataPtr_[n]->numData);
    2838           0 :         vmsDataPtr_->vv_dataShape.push_back(v_msDataPtr_[n]->v_dataShape);
    2839           0 :         vmsDataPtr_->v_phaseDir.push_back(v_msDataPtr_[n]->phaseDir);
    2840           0 :         vmsDataPtr_->v_stateId.push_back(v_msDataPtr_[n]->stateId);
    2841           0 :         vmsDataPtr_->v_msState.push_back(v_msDataPtr_[n]->msState);
    2842           0 :         vmsDataPtr_->v_flag.push_back(v_msDataPtr_[n]->flag);
    2843             : 
    2844           0 :         vmsDataPtr_->v_atmPhaseCorrection = v_msDataPtr_[n]->v_atmPhaseCorrection;
    2845           0 :         map<AtmPhaseCorrection,float*> m_vdata;
    2846           0 :         for(unsigned int napc=0; napc<vmsDataPtr_->v_atmPhaseCorrection.size(); napc++){
    2847           0 :           float* d=v_msDataPtr_[n]->v_data[napc];
    2848           0 :           m_vdata.insert(make_pair(vmsDataPtr_->v_atmPhaseCorrection[napc],d));
    2849             :         }
    2850           0 :         vmsDataPtr_->v_m_data.push_back(m_vdata);
    2851             : 
    2852           0 :         v_tci_[n] = make_pair(n,v_msDataPtr_[n]->timeCentroid);
    2853           0 :       }
    2854             :     }
    2855           0 :     if (verbose_) cout << "SDMBinData::getNextMSMainCols : exiting" << endl; 
    2856           0 :     return vmsDataPtr_;
    2857           0 :   }
    2858             : 
    2859             :   // shared_ptr not needed by CASA, do not compile this for the WITHOUT_BOOST option
    2860             :   // It may be needed by ALMA code, so do not elimiate it yet.
    2861             : #ifndef WITHOUT_BOOST
    2862             :   void SDMBinData::getNextMSMainCols(unsigned int nDataSubset, boost::shared_ptr<VMSDataWithSharedPtr>& vmsData_p_sp) {
    2863             :     Enum<CorrelationMode>       e_qcm;
    2864             :     EnumSet<AtmPhaseCorrection> es_qapc;
    2865             :     if(canSelect_){
    2866             :       cout<<"INFORM: context allow to select"<<endl;
    2867             :       e_qcm   = e_qcm_;
    2868             :       es_qapc = es_qapc_;
    2869             :     }
    2870             :     getNextMSMainCols( e_qcm, es_qapc, nDataSubset, vmsData_p_sp );
    2871             :   }
    2872             : 
    2873             :   void  SDMBinData::getNextMSMainCols(Enum<CorrelationMode> e_qcm, EnumSet<AtmPhaseCorrection> es_qapc, unsigned int nDataSubset,  boost::shared_ptr<VMSDataWithSharedPtr>& vmsData_p_sp ) {
    2874             :     if (verbose_) cout << "SDMBinData::getNextMSMainCols (with VMSDataSharedPtr) : entering" << endl;
    2875             : 
    2876             :     VMSDataWithSharedPtr* vmsData_p = vmsData_p_sp.get();
    2877             : 
    2878             :     // Delete the content of v_msDataPtr (but do not delete "deeply" i.e. do not delete the visibilities referred to by pointers stored into v_msDataPtr since the 
    2879             :     // memory they occupy is going to be managed by boost::shared_ptr s.
    2880             :     //
    2881             :     if ( v_msDataPtr_.size() > 0 ){
    2882             :       for(vector<MSData*>::reverse_iterator it=v_msDataPtr_.rbegin(); it!=v_msDataPtr_.rend(); ++it) delete (*it);
    2883             :     }
    2884             :     v_msDataPtr_.clear();
    2885             : 
    2886             :     v_msDataPtr_ = getMSDataFromBDFData(e_qcm, es_qapc, nDataSubset);
    2887             :     int numRows = v_msDataPtr_.size();
    2888             :     if (verbose_) cout << "Number of MS Main rows for this block of " << nDataSubset << " [sub]integrations in '" << sdmdosr.dataOID() << "' = " << numRows << endl; 
    2889             : 
    2890             :    if(numRows){
    2891             :       vmsData_p->processorId          = v_msDataPtr_[0]->processorId;
    2892             :       vmsData_p->binNum               = v_msDataPtr_[0]->binNum;
    2893             :     }
    2894             : 
    2895             :     unsigned int numApcMax=0;
    2896             :     for(int n=0; n<numRows; n++){
    2897             :       if(v_msDataPtr_[n]->v_atmPhaseCorrection.size()>numApcMax)
    2898             :         numApcMax=v_msDataPtr_[n]->v_atmPhaseCorrection.size();
    2899             :     }
    2900             :     if(verbose_)cout<<"numApcMax="<<numApcMax<<endl;
    2901             : 
    2902             :     multimap<int,unsigned int> mm_dd;
    2903             :     if (ddfirst_) {
    2904             :       vector<int> ddId_v;
    2905             :       vector<int>::iterator ddId_i;
    2906             :       int ddIdOld = -1;
    2907             :       int ddIndex = -1;
    2908             :  
    2909             :       for(unsigned int n=0; n<v_msDataPtr_.size(); n++) {
    2910             :         if (v_msDataPtr_[n]->dataDescId != ddIdOld) {
    2911             :           ddIdOld = v_msDataPtr_[n]->dataDescId ;
    2912             :           if ((ddId_i = find(ddId_v.begin(), ddId_v.end(),ddIdOld)) == ddId_v.end()) {
    2913             :             ddId_v.push_back(ddIdOld);
    2914             :             ddIndex = ddId_v.size()-1;
    2915             :           }
    2916             :           else 
    2917             :             ddIndex = ddId_i - ddId_v.begin();
    2918             :         }
    2919             :         mm_dd.insert(make_pair(ddIndex,n));       
    2920             :       }
    2921             :     }
    2922             : 
    2923             : 
    2924             :     /*
    2925             :     multimap<int,unsigned int> mm_dd;
    2926             :     if(ddfirst_){
    2927             :       for(unsigned int n=0; n<v_msDataPtr_.size(); n++)
    2928             :         mm_dd.insert(make_pair(v_msDataPtr_[n]->dataDescId,n));
    2929             :     }
    2930             :     */
    2931             : 
    2932             :     v_tci_.clear();  
    2933             :     v_tci_.resize(numRows);
    2934             : 
    2935             :     if(ddfirst_){   // the dataDescription/time/baseline expansion
    2936             : 
    2937             :       unsigned int n, i=0;
    2938             :       multimap<int,unsigned int>::const_iterator it;
    2939             :       for(it=mm_dd.begin(); it!=mm_dd.end(); ++it){
    2940             :         n=it->second;
    2941             :         vmsData_p->v_time.push_back(v_msDataPtr_[n]->time);
    2942             :         vmsData_p->v_fieldId.push_back(v_msDataPtr_[n]->fieldId);
    2943             :         vmsData_p->v_interval.push_back(v_msDataPtr_[0]->interval);
    2944             :         vmsData_p->v_antennaId1.push_back(v_msDataPtr_[n]->antennaId1);
    2945             :         vmsData_p->v_antennaId2.push_back(v_msDataPtr_[n]->antennaId2);
    2946             :         vmsData_p->v_feedId1.push_back(v_msDataPtr_[n]->feedId1);
    2947             :         vmsData_p->v_feedId2.push_back(v_msDataPtr_[n]->feedId2);
    2948             :         vmsData_p->v_dataDescId.push_back(v_msDataPtr_[n]->dataDescId);
    2949             :         vmsData_p->v_timeCentroid.push_back(v_msDataPtr_[n]->timeCentroid);
    2950             :         vmsData_p->v_exposure.push_back(v_msDataPtr_[n]->exposure);
    2951             :         vmsData_p->v_numData.push_back(v_msDataPtr_[n]->numData);
    2952             :         vmsData_p->vv_dataShape.push_back(v_msDataPtr_[n]->v_dataShape);
    2953             :         vmsData_p->v_phaseDir.push_back(v_msDataPtr_[n]->phaseDir);
    2954             :         vmsData_p->v_stateId.push_back(v_msDataPtr_[n]->stateId);
    2955             :         vmsData_p->v_msState.push_back(v_msDataPtr_[n]->msState);
    2956             :         vmsData_p->v_flag.push_back(v_msDataPtr_[n]->flag);
    2957             : 
    2958             :         vmsData_p->v_atmPhaseCorrection = v_msDataPtr_[n]->v_atmPhaseCorrection;
    2959             :         map<AtmPhaseCorrection,boost::shared_array<float> > m_vdata;
    2960             :         for(unsigned int napc=0; napc<vmsData_p->v_atmPhaseCorrection.size(); napc++){
    2961             :           float* d=v_msDataPtr_[n]->v_data[napc];
    2962             :           boost::shared_array<float> d_sp(d);
    2963             :           m_vdata.insert(make_pair(vmsData_p->v_atmPhaseCorrection[napc],d_sp));
    2964             :         }
    2965             :         vmsData_p->v_m_data.push_back(m_vdata);
    2966             :         //cout<<"dataDescriptionId="<<it->first<<" row="<<it->second<<endl;
    2967             : 
    2968             :         pair<unsigned int,double> p=make_pair(i++,v_msDataPtr_[n]->timeCentroid);
    2969             :         v_tci_[n]=p;
    2970             :       }
    2971             : 
    2972             :     }else{    // the baseline/dataDescription expansion
    2973             : 
    2974             :       
    2975             :       for(int n=0; n<numRows; n++){
    2976             : 
    2977             :         vmsData_p->v_time.push_back(v_msDataPtr_[n]->time);
    2978             :         vmsData_p->v_fieldId.push_back(v_msDataPtr_[n]->fieldId);
    2979             :         vmsData_p->v_interval.push_back(v_msDataPtr_[0]->interval);
    2980             :         vmsData_p->v_antennaId1.push_back(v_msDataPtr_[n]->antennaId1);
    2981             :         vmsData_p->v_antennaId2.push_back(v_msDataPtr_[n]->antennaId2);
    2982             :         vmsData_p->v_feedId1.push_back(v_msDataPtr_[n]->feedId1);
    2983             :         vmsData_p->v_feedId2.push_back(v_msDataPtr_[n]->feedId2);
    2984             :         vmsData_p->v_dataDescId.push_back(v_msDataPtr_[n]->dataDescId);
    2985             :         vmsData_p->v_timeCentroid.push_back(v_msDataPtr_[n]->timeCentroid);
    2986             :         vmsData_p->v_exposure.push_back(v_msDataPtr_[n]->exposure);
    2987             :         vmsData_p->v_numData.push_back(v_msDataPtr_[n]->numData);
    2988             :         vmsData_p->vv_dataShape.push_back(v_msDataPtr_[n]->v_dataShape);
    2989             :         vmsData_p->v_phaseDir.push_back(v_msDataPtr_[n]->phaseDir);
    2990             :         vmsData_p->v_stateId.push_back(v_msDataPtr_[n]->stateId);
    2991             :         vmsData_p->v_msState.push_back(v_msDataPtr_[n]->msState);
    2992             :         vmsData_p->v_flag.push_back(v_msDataPtr_[n]->flag);
    2993             : 
    2994             :         vmsData_p->v_atmPhaseCorrection = v_msDataPtr_[n]->v_atmPhaseCorrection;
    2995             :         map<AtmPhaseCorrection, boost::shared_array<float> > m_vdata;
    2996             :         for(unsigned int napc=0; napc<vmsData_p->v_atmPhaseCorrection.size(); napc++){
    2997             :           float* d=v_msDataPtr_[n]->v_data[napc];
    2998             :           boost::shared_array<float> d_sp(d);
    2999             :           m_vdata.insert(make_pair(vmsData_p->v_atmPhaseCorrection[napc],d_sp));
    3000             :         }
    3001             :         vmsData_p->v_m_data.push_back(m_vdata);
    3002             : 
    3003             :         v_tci_[n] = make_pair(n,v_msDataPtr_[n]->timeCentroid);
    3004             :       }
    3005             :     }
    3006             :     if (verbose_) cout << "SDMBinData::getNextMSMainCols : exiting" << endl; 
    3007             :   }
    3008             : #endif
    3009             : 
    3010           0 :   vector<MSData*> SDMBinData::getMSDataFromBDFData(Enum<CorrelationMode> e_qcm, EnumSet<AtmPhaseCorrection> es_qapc, unsigned int nDataSubsets) {
    3011           0 :     if (verbose_) cout << "SDMBinData::getMSDataFromBDFData: entering (e_qcm="<<e_qcm.str()
    3012           0 :                       <<",es_qapc="<<es_qapc.str()
    3013           0 :                       <<", nDataSubsets="<< nDataSubsets 
    3014           0 :                       <<")"
    3015           0 :                       << endl;
    3016             : 
    3017           0 :     MSData* msDataPtr_ = (MSData *) NULL;
    3018             :     
    3019           0 :     if (v_msDataPtr_.size() > 0) {
    3020           0 :       if (verbose_) cout<<"About to delete "<<v_msDataPtr_.size()<<" msDataPtr objects"<<endl;
    3021           0 :       for(vector<MSData*>::reverse_iterator it=v_msDataPtr_.rbegin(); it!=v_msDataPtr_.rend(); ++it)
    3022           0 :         deleteMsData(*it);
    3023             :       
    3024           0 :       v_msDataPtr_.clear();
    3025             :     }
    3026             : 
    3027           0 :     ConfigDescriptionRow*       cdPtr = mainRowPtr_->getConfigDescriptionUsingConfigDescriptionId();
    3028           0 :     vector<AtmPhaseCorrection>  v_apc = cdPtr->getAtmPhaseCorrection();
    3029           0 :     Enum<CorrelationMode>       e_cm; e_cm = cdPtr->getCorrelationMode();
    3030             : 
    3031           0 :     if(!canSelect_ && (e_qcm.count() || es_qapc.count()) ){
    3032           0 :       Error(FATAL, string("This method cannot be used in this context!\n Use the method with no argument getData()"));
    3033           0 :       return v_msDataPtr_;
    3034             :     }
    3035             : 
    3036           0 :     if(canSelect_){
    3037             :       // set the new defaults
    3038           0 :       e_qcm_   = e_qcm;
    3039           0 :       es_qapc_ = es_qapc;
    3040             :     }
    3041             : 
    3042           0 :     if (verbose_) {
    3043           0 :       cout<<"e_qcm=  "<<e_qcm.str()  <<" e_qcm_=  "<<e_qcm_.str()  <<" e_cm="<<e_cm.str()<<endl;
    3044           0 :       cout<<"es_qapc="<<es_qapc.str()<<" es_qapc_="<<es_qapc_.str();
    3045           0 :       for(unsigned int n=0; n<v_apc.size(); n++)
    3046           0 :         cout<<" v_apc["<<n<<"]="<<Enum<AtmPhaseCorrection>(v_apc[n]).str()<<" ";
    3047           0 :       cout<<endl;
    3048             :     }
    3049             : 
    3050           0 :     if(e_qcm_[CROSS_ONLY]) if(e_cm[AUTO_ONLY])  return v_msDataPtr_;
    3051           0 :     if(e_qcm_[AUTO_ONLY])  if(e_cm[CROSS_ONLY]) return v_msDataPtr_;
    3052             : 
    3053           0 :     vector<unsigned int>       v_selected_napc;
    3054           0 :     vector<AtmPhaseCorrection> v_selected_apc;
    3055           0 :     for(unsigned int n=0; n<v_apc.size(); n++){
    3056           0 :       if(es_qapc_[v_apc[n]]){
    3057           0 :         v_selected_napc.push_back(n);
    3058           0 :         v_selected_apc.push_back(v_apc[n]);
    3059             :       }
    3060             :     }
    3061           0 :     if(!v_selected_napc.size())return v_msDataPtr_;
    3062             : 
    3063           0 :     Tag configDescriptionId = mainRowPtr_->getConfigDescriptionId();
    3064             :     std::set<Tag>::iterator
    3065           0 :       itsf=s_cdId_.find(configDescriptionId),
    3066           0 :       itse=s_cdId_.end();
    3067           0 :     if(itsf==itse)
    3068           0 :       Error(FATAL, string("Tree hierarchy not present for configDescId ") + configDescriptionId.toString());
    3069             :     std::map<Tag,BaselinesSet*>::iterator
    3070           0 :       itf(m_cdId_baselinesSet_.find(configDescriptionId)),
    3071           0 :       ite(m_cdId_baselinesSet_.end());
    3072           0 :     if(itf==ite)
    3073           0 :       Error(FATAL, string("Tree hierarchy not present for configDescId ") + configDescriptionId.toString());
    3074           0 :     baselinesSet_=itf->second;
    3075             : 
    3076           0 :     if (verbose_) cout<<"ConfigDescriptionId = " << configDescriptionId.toString()<<endl;
    3077             : //    unsigned int               stateId;
    3078           0 :     vector<StateRow*>          v_statePtr = mainRowPtr_->getStatesUsingStateId();
    3079             : 
    3080           0 :     vector<int>                v_feedSet  = cdPtr->getFeedId();
    3081           0 :     vector<Tag>                v_antSet   = cdPtr->getAntennaId();
    3082           0 :     vector<Tag>                v_ddList   = cdPtr->getDataDescriptionId();
    3083             : 
    3084             : 
    3085           0 :     unsigned int               numFeed    = v_feedSet.size()/v_antSet.size();
    3086             :     unsigned int               numBin;
    3087             :     unsigned int               numPol;
    3088           0 :     vector<unsigned int>       v_dataShape;  v_dataShape.resize(3);  // POL.SPP.APC 3D
    3089             : 
    3090             :     double                     timeMJD;
    3091             :     double                     timeCentroidMJD;
    3092             :     double                     interval;
    3093             :     double                     exposure;
    3094           0 :     ArrayTime                  timeOfDump;
    3095           0 :     ArrayTime                  timeCentroidOfDump;
    3096             : 
    3097           0 :     int                        fieldId    = mainRowPtr_->getFieldUsingFieldId()->getFieldId().getTagValue();
    3098           0 :     vector<vector<Angle> >     phaseDir   = mainRowPtr_->getFieldUsingFieldId()->getPhaseDir();
    3099             : 
    3100             :     
    3101           0 :     vector<Tag>                v_stateId;
    3102             : 
    3103           0 :     if ( verbose_ ) cout <<"ici AA: e_qcm_="<<e_qcm_.str()<<endl;
    3104             : 
    3105           0 :     for(unsigned int na=0; na<v_antSet.size(); na++)
    3106           0 :       v_stateId.push_back(v_statePtr[na]->getStateId());
    3107             : 
    3108           0 :     vector<vector<float> >                      vv_t; // dummy empty vector would there be no tsysSpectrum for a given syscal row
    3109           0 :     SysCalTable&                                sct = datasetPtr_->getSysCal();
    3110           0 :     vector<Tag>                                 v_spwid;
    3111           0 :     vector<pair<bool,vector<vector<float> > > > v_tsys;
    3112           0 :     vector<vector<pair<bool,vector<vector<float> > > > > vv_tsys;
    3113             : 
    3114           0 :     if(SDMBinData::syscal_){
    3115           0 :       v_tsys.resize(v_antSet.size()*v_ddList.size()*numFeed);
    3116           0 :       for(unsigned int nt=0; nt<v_dataDump_.size(); nt++){
    3117           0 :         vector<pair<bool,vector<vector<float> > > > v_tsys;
    3118           0 :         timeCentroidOfDump= ArrayTime((int64_t)v_dataDump_[nt]->timeCentroid());
    3119           0 :         unsigned int scn=0;
    3120           0 :         for(unsigned int na=0; na<v_antSet.size(); na++){
    3121           0 :           for(unsigned int nfe=0; nfe<numFeed; nfe++){
    3122           0 :             for(unsigned int nsw=0; nsw<v_ddList.size(); nsw++){
    3123           0 :               SysCalRow* scr = sct.getRowByKey( v_antSet[na],
    3124           0 :                                                 baselinesSet_->getSpwId(nsw),
    3125           0 :                                                 ArrayTimeInterval(timeCentroidOfDump),
    3126           0 :                                                 v_feedSet[na*numFeed+nfe]
    3127             :                                                 );
    3128           0 :               if(scr->isTsysSpectrumExists()){
    3129           0 :                 vector<vector<float> > vv_flt;
    3130           0 :                 v_tsys[scn].first  = scr->getTsysFlag();
    3131           0 :                 vector<vector<Temperature> > vv=scr->getTsysSpectrum();
    3132           0 :                 for(unsigned int np=0; np<vv.size(); np++){
    3133           0 :                   vector<float> v;
    3134           0 :                   for(unsigned int ns=0; ns<vv[np].size(); ns++)v.push_back(vv[np][ns].get());
    3135           0 :                   vv_flt.push_back(v);
    3136           0 :                 }
    3137           0 :                 v_tsys[scn].second = vv_flt;
    3138           0 :               }else{
    3139           0 :                 v_tsys[scn].first  = false;
    3140           0 :                 v_tsys[scn].second = vv_t;
    3141             :               }
    3142           0 :               scn++;
    3143             :             }
    3144             :           }
    3145             :         }
    3146           0 :         vv_tsys.push_back(v_tsys);
    3147           0 :       }
    3148             :     }
    3149             : 
    3150             :     // Okay now it's time to obtain at most n dataDumps.
    3151           0 :     getNextDataDumps(nDataSubsets);
    3152             : 
    3153             :     // And now use what's in v_dataDump.
    3154           0 :     if(e_cm[CROSS_ONLY]==false && e_qcm_[CROSS_ONLY]==false ){       // retrieve only AUTO_DATA
    3155           0 :       for(unsigned int nt=0; nt<v_dataDump_.size(); nt++){
    3156           0 :         timeOfDump        = ArrayTime((int64_t)v_dataDump_[nt]->time());               if(verbose_)cout<<timeOfDump<<" ns"<<endl;
    3157           0 :         timeCentroidOfDump= ArrayTime((int64_t)v_dataDump_[nt]->timeCentroid());       if(verbose_)cout<<timeCentroidOfDump.toString()<<" ns"<<endl;
    3158           0 :         timeMJD           = timeOfDump.getMJD();                              if(verbose_)cout<<timeMJD<<" h = "<<86400.*timeMJD<<" s"<<endl;
    3159           0 :         interval          = (double)v_dataDump_[nt]->interval()/1000000000LL; if(verbose_)cout<<interval<<" s"<<endl;
    3160           0 :         timeCentroidMJD   = timeCentroidOfDump.getMJD();                      if(verbose_)cout<< timeCentroidMJD<<endl;
    3161           0 :         exposure          = (double)v_dataDump_[nt]->exposure()/1000000000LL;
    3162           0 :         floatDataDumpPtr_ = v_dataDump_[nt]->autoData();             // used by getData(na, nfe, ndd, nbi)
    3163             :         
    3164           0 :         if(verbose_)cout <<"ici BB"<<endl;
    3165             :         
    3166           0 :         vector<AtmPhaseCorrection> v_uapc; v_uapc.push_back(AP_UNCORRECTED);
    3167             :         
    3168           0 :         unsigned int scn=0;
    3169           0 :         for(unsigned int na=0; na<v_antSet.size(); na++){
    3170             : //        stateId = v_statePtr[na]->getStateId().getTagValue();
    3171           0 :           for(unsigned int nfe=0; nfe<numFeed; nfe++){
    3172           0 :             for(unsigned int ndd=0; ndd<v_ddList.size(); ndd++){
    3173           0 :               numBin = baselinesSet_->numBin(ndd);
    3174           0 :               numPol = baselinesSet_->numPol(baselinesSet_->getBasebandIndex(ndd));
    3175           0 :               if(numPol==4)numPol=3;                                 // if XX,XY,YX,YY then auto XX,XY,YY 
    3176           0 :               if(verbose_)cout<<"numPol="<<numPol
    3177           0 :                              <<"  na="  <<na
    3178           0 :                              <<" ant="  <<v_antSet[na].getTagValue()
    3179           0 :                              <<endl;
    3180           0 :               v_dataShape[0]=numPol;
    3181             :               //              if(complexData_)v_dataShape[0]*=2;
    3182           0 :               v_dataShape[1]=baselinesSet_->numChan(ndd);
    3183           0 :               v_dataShape[2]=1;                                     // auto-correlation never atm phase corrected
    3184           0 :               if (verbose_) cout << "CC" << endl;
    3185           0 :               for(unsigned int nbi=0; nbi<numBin; nbi++){
    3186             :                 // the data and binary meta-data
    3187           0 :                 if(SDMBinData::syscal_)
    3188           0 :                   msDataPtr_ = getCalibratedData( na, nfe,
    3189             :                                                   ndd, nbi, 
    3190           0 :                                                   vv_tsys[nt][scn]);
    3191             :                 else
    3192           0 :                   msDataPtr_ = getData( na, nfe,
    3193             :                                         ndd, nbi);
    3194           0 :                 scn++;
    3195           0 :                 msDataPtr_->timeCentroid   = 86400.*timeCentroidMJD; // default value would there be no bin actualTimes
    3196           0 :                 msDataPtr_->exposure       = exposure;               // default value would there be no bin actualDurations
    3197           0 :                 msDataPtr_->flag           = 0;                      // default value is "false"  would there be no bin flags
    3198             :                 // calibrate and associate SDM meta-data
    3199           0 :                 if(msDataPtr_->numData>0){
    3200           0 :                   msDataPtr_->processorId        = cdPtr->getProcessorId().getTagValue();
    3201           0 :                   msDataPtr_->antennaId1         = v_antSet[na].getTagValue();
    3202           0 :                   msDataPtr_->antennaId2         = v_antSet[na].getTagValue();
    3203           0 :                   msDataPtr_->feedId1            = v_feedSet[na*numFeed+nfe];
    3204           0 :                   msDataPtr_->feedId2            = v_feedSet[na*numFeed+nfe];
    3205             :                   // if(e_cm[CROSS_AND_AUTO])
    3206             :                   //   msDataPtr_->dataDescId       = baselinesSet_->getAutoDataDescriptionId(v_ddList[ndd]).getTagValue();
    3207             :                   // else
    3208             :                   //   msDataPtr_->dataDescId       = v_ddList[ndd].getTagValue();
    3209           0 :                   msDataPtr_->dataDescId         = v_ddList[ndd].getTagValue();   // This comes in place of the 4 commented statements above,
    3210             :                                                                                   // in order to avoid that auto data and cross data of one same 
    3211             :                                                                                   // integration appear with different data description id in the 
    3212             :                                                                                   // case when two different data descriptions are declared while
    3213             :                                                                                   // would be enough (typically one for AUTO : XX, XY, YY one for 
    3214             :                                                                                   // CROSS : XX XY YX YY) while in my view CROSS : XX, XY, YX, YY 
    3215             :                                                                                   // *implicitely* means AUTo : XX, XY, YY. 
    3216             :                                                                                   // The motivation for this is to keep as simple as possible
    3217             :                                                                                   // the logic by which CROSS DATA will follow AUTO DATA in the resulting MS
    3218             :                                                                                   // with a UNIQUE (MS) data description id. Michel Caillat 7th of Sep, 2015.
    3219             : 
    3220           0 :                   msDataPtr_->phaseDir           = phaseDir;                     // TODO Apply the polynomial formula
    3221             :                   /*
    3222             :                   msDataPtr_->stateId            = stateId;
    3223             :                   msDataPtr_->msState            = getMSState( subscanNum, v_stateId,
    3224             :                                                                v_antSet, v_feedSet, v_ddList,
    3225             :                                                                na, nfe, ndd, timeOfDump);
    3226             :                   */
    3227           0 :                   msDataPtr_->v_dataShape        = v_dataShape;
    3228           0 :                   msDataPtr_->time               = 86400.*timeMJD;
    3229           0 :                   msDataPtr_->interval           = interval;
    3230           0 :                   msDataPtr_->v_atmPhaseCorrection = v_uapc;         // It is assumed that this is always the uncorrected case
    3231           0 :                   msDataPtr_->binNum             = nbi+1;
    3232           0 :                   msDataPtr_->fieldId            = fieldId;
    3233           0 :                   vector<unsigned int> v_projectNodes;
    3234           0 :                   if(v_dataDump_[nt]->integrationNum())v_projectNodes.push_back(v_dataDump_[nt]->integrationNum());
    3235           0 :                   if(v_dataDump_[nt]->subintegrationNum())v_projectNodes.push_back(v_dataDump_[nt]->subintegrationNum());
    3236           0 :                   msDataPtr_->projectPath        = v_projectNodes;
    3237           0 :                   v_msDataPtr_.push_back(msDataPtr_);                      // store in vector for export
    3238           0 :                 }
    3239           0 :                 if(verbose_)cout << "B/ msDataPtr_->numData=" <<msDataPtr_->numData << endl;
    3240             :               }
    3241             :             }
    3242             :           }
    3243             :         }
    3244           0 :       }
    3245             :     }
    3246           0 :     if(verbose_)cout <<"ici CC: "<<e_qcm_.str()<<endl;
    3247           0 :     vector<AtmPhaseCorrection> v_atmPhaseCorrection = cdPtr->getAtmPhaseCorrection();
    3248           0 :     bool queryCrossData = false;
    3249           0 :     if(e_qcm_[CROSS_ONLY])     queryCrossData=true;
    3250           0 :     if(e_qcm_[CROSS_AND_AUTO]) queryCrossData=true;
    3251             : 
    3252           0 :     if(e_cm[AUTO_ONLY]==false && queryCrossData ){
    3253             :       
    3254             :       // select the queried apc
    3255           0 :       vector<unsigned int> v_napc;
    3256           0 :       EnumSet<AtmPhaseCorrection> es_apc; es_apc.set(v_atmPhaseCorrection);    if(verbose_)cout<<es_apc.str()<<endl;
    3257           0 :       if(verbose_)cout <<"es_apc from BLOB: " << es_apc.str()   << endl;
    3258           0 :       if(verbose_)cout <<"es_qapc_ queried: " << es_qapc_.str() << endl;
    3259           0 :       for(unsigned int napc=0; napc<v_atmPhaseCorrection.size(); napc++)
    3260           0 :         if(es_qapc_[v_atmPhaseCorrection[napc]])v_napc.push_back(napc);
    3261           0 :       if(verbose_)for(unsigned int n=0; n<v_napc.size(); n++)cout<<"v_napc["<<n<<"]="<<v_napc[n]<<endl;
    3262             :       
    3263           0 :       if(!v_napc.size()){
    3264           0 :         Error(WARNING,(char *) "No visibilities with AtmPhaseCorrection in the set {%s}",
    3265           0 :               es_qapc_.str().c_str());
    3266           0 :         return v_msDataPtr_;
    3267             :       }
    3268             :       
    3269           0 :       if(verbose_)cout<<"ici DD"<<endl;
    3270             :       
    3271             :       
    3272           0 :       for(unsigned int nt=0; nt<v_dataDump_.size(); nt++){
    3273           0 :         timeOfDump        = ArrayTime((int64_t)v_dataDump_[nt]->time());                if(verbose_)cout<<timeOfDump<<endl;
    3274           0 :         timeCentroidOfDump= ArrayTime((int64_t)v_dataDump_[nt]->timeCentroid());        if(verbose_)cout<< timeCentroidOfDump.toString() <<endl;
    3275           0 :         timeMJD           = timeOfDump.getMJD();                               if(verbose_)cout<<timeMJD<<" h"<<endl;
    3276           0 :         interval          = (double)v_dataDump_[nt]->interval()/1000000000LL;
    3277           0 :         timeCentroidMJD   = timeCentroidOfDump.getMJD();                       if(verbose_)cout<< timeCentroidMJD<<" h"<<endl;
    3278           0 :         exposure          = (double)v_dataDump_[nt]->exposure()/1000000000LL;;
    3279           0 :         if(verbose_)cout<<"ici DD 1"<<endl;
    3280           0 :         shortDataPtr_ = NULL;
    3281           0 :         longDataPtr_  = NULL;
    3282           0 :         floatDataPtr_ = NULL;
    3283           0 :         if(v_dataDump_[nt]->crossDataShort())
    3284           0 :           shortDataPtr_   = v_dataDump_[nt]->crossDataShort();       // used by getData(na, na2, nfe, ndd, nbi, napc)
    3285           0 :         else if(v_dataDump_[nt]->crossDataLong())
    3286           0 :           longDataPtr_    = v_dataDump_[nt]->crossDataLong();
    3287           0 :         else if(v_dataDump_[nt]->crossDataFloat())
    3288           0 :           floatDataPtr_    = v_dataDump_[nt]->crossDataFloat();
    3289             :         else
    3290           0 :           Error(FATAL, string("Cross data typed float not yet supported"));
    3291           0 :         if(verbose_)cout<<"ici DD 2"<<endl;
    3292           0 :         unsigned int scn=0;
    3293           0 :         for(unsigned int na1=0; na1<v_antSet.size(); na1++){
    3294             :           // we will assume that na2 has the same stateId (perhaps we should return a vector?)!
    3295             :  //       stateId = v_statePtr[na1]->getStateId().getTagValue();
    3296           0 :           for(unsigned int na2=na1+1; na2<v_antSet.size(); na2++){
    3297           0 :             for(unsigned int nfe=0; nfe<numFeed; nfe++){
    3298           0 :               for(unsigned int ndd=0; ndd<v_ddList.size(); ndd++){
    3299           0 :                 if(verbose_)cout<<"ici DD 3   numApc="<<baselinesSet_->numApc()<<endl;
    3300           0 :                 numBin = baselinesSet_->numBin(ndd);
    3301           0 :                 numPol = baselinesSet_->numPol(baselinesSet_->getBasebandIndex(ndd));   // nb of pol product (max is 4)
    3302           0 :                 if(verbose_)cout<<"ici DD 4   numBin="<<numBin<<"  numPol="<<numPol<<endl;
    3303           0 :                 v_dataShape[0]=baselinesSet_->numPol(ndd);
    3304           0 :                 v_dataShape[1]=baselinesSet_->numChan(ndd);
    3305           0 :                 v_dataShape[2]=baselinesSet_->numApc();
    3306           0 :                 v_dataShape[2]=1;               // qapc being not an EnumSet (MS limitation for floatData column)
    3307           0 :                 for(unsigned int nbi=0; nbi<numBin; nbi++){
    3308           0 :                   if(verbose_){
    3309           0 :                     cout<<"timeCentroidMJD="<<timeCentroidMJD<<endl;
    3310             :                   }
    3311             :                   // the data and binary meta-data
    3312           0 :                   if (verbose_) {
    3313           0 :                     cout << "nt = " << nt << endl;
    3314           0 :                     cout << "size of v_dataDump_ = " << v_dataDump_.size() << endl;
    3315             :                   }
    3316             :                   
    3317           0 :                   if(SDMBinData::syscal_) {
    3318           0 :                     msDataPtr_ = getCalibratedData( na1, nfe, na2, nfe,
    3319             :                                                     ndd,  nbi, v_napc,
    3320           0 :                                                     v_dataDump_[nt]->scaleFactor(ndd),
    3321           0 :                                                     vv_tsys[nt][scn]);
    3322             :                   }
    3323             :                   else {
    3324           0 :                     msDataPtr_ = getData( na1, nfe, na2, nfe,
    3325             :                                           ndd,  nbi, v_napc,
    3326           0 :                                           v_dataDump_[nt]->scaleFactor(ndd));
    3327             :                   }
    3328             :                   
    3329           0 :                   msDataPtr_->timeCentroid  = 86400.*timeCentroidMJD; // default value would there be no bin actualTimes
    3330           0 :                   msDataPtr_->exposure      = exposure;               // default value would there be no bin actualDurations
    3331           0 :                   msDataPtr_->flag          = 0;                      // default value is "false"  would there be no bin flags
    3332           0 :                   if(verbose_)cout<<"ici DD 7 msDataPtr_->numData="<<msDataPtr_->numData<<endl;
    3333             :                   // the associated SDM meta-data
    3334           0 :                   if(msDataPtr_->numData>0){
    3335           0 :                     msDataPtr_->processorId          = cdPtr->getProcessorId().getTagValue();
    3336           0 :                     msDataPtr_->time                 = 86400.*timeMJD;
    3337           0 :                     msDataPtr_->antennaId1           = v_antSet[na1].getTagValue();
    3338           0 :                     msDataPtr_->antennaId2           = v_antSet[na2].getTagValue();
    3339           0 :                     msDataPtr_->feedId1              = v_feedSet[na1*numFeed+nfe];
    3340           0 :                     msDataPtr_->feedId2              = v_feedSet[na2*numFeed+nfe];
    3341           0 :                     msDataPtr_->dataDescId           = v_ddList[ndd].getTagValue();
    3342           0 :                     msDataPtr_->fieldId              = fieldId;
    3343           0 :                     msDataPtr_->phaseDir             = phaseDir;
    3344             :                     /* This part is now done in the filler itself -  MC 23 Jul 2012
    3345             :                     msDataPtr_->msState              = getMSState( subscanNum, v_stateId,
    3346             :                                                                    v_antSet, v_feedSet, v_ddList,
    3347             :                                                                    na1, nfe, ndd, timeOfDump);
    3348             :                     */
    3349             :                      // TODO Apply the polynomial formula
    3350           0 :                     msDataPtr_->v_dataShape          = v_dataShape;
    3351           0 :                     msDataPtr_->interval             = interval;
    3352           0 :                     msDataPtr_->v_atmPhaseCorrection = v_selected_apc;
    3353           0 :                     msDataPtr_->binNum               = nbi+1;              // a number is one-based.
    3354           0 :                     vector<unsigned int> v_projectNodes;
    3355           0 :                     if(v_dataDump_[nt]->integrationNum())v_projectNodes.push_back(v_dataDump_[nt]->integrationNum());
    3356           0 :                     if(v_dataDump_[nt]->subintegrationNum())v_projectNodes.push_back(v_dataDump_[nt]->subintegrationNum());
    3357           0 :                     msDataPtr_->projectPath          = v_projectNodes;
    3358           0 :                   }
    3359             :                   // store in vector for export
    3360           0 :                   if(msDataPtr_->numData>0)v_msDataPtr_.push_back(msDataPtr_);
    3361           0 :                   if(verbose_)cout << "A/ msDataPtr_->numData=" << msDataPtr_->numData << endl;
    3362           0 :                   scn++;
    3363             :                 }
    3364             :               }
    3365             :             }
    3366             :           }
    3367             :         }
    3368             :       }
    3369           0 :       if(verbose_)cout<<"v_msDataPtr_.size()="<< v_msDataPtr_.size() << endl;
    3370           0 :     }
    3371           0 :     if (verbose_) cout << "SDMBinData::getMSDataFromBDFData: exiting" << endl;
    3372           0 :     return v_msDataPtr_;
    3373           0 :   }
    3374             : 
    3375           0 :   void SDMBinData::getNextDataDumps(unsigned int nDataSubsets) {
    3376           0 :     if (verbose_) cout << "SDMBinData::getNextDataDumps : entering" << endl;
    3377             : 
    3378             :     /*
    3379             :      * Possibly we must empty the vector of pointers on DataDump objects containing
    3380             :      * elements from a previous call.
    3381             :      */
    3382           0 :     vector<DataDump*>::reverse_iterator it, itrb=v_dataDump_.rbegin(), itre=v_dataDump_.rend();
    3383           0 :     for(it=itrb; it!=itre; it++){
    3384           0 :       delete *it;
    3385             :     }
    3386           0 :     v_dataDump_.clear();
    3387             : 
    3388           0 :     Enum<CorrelationMode>            e_cm;
    3389           0 :     Enum<ProcessorType>              e_pt;
    3390           0 :     Enum<CorrelatorType>             e_ct;
    3391             :  
    3392           0 :     if (verbose_) cout << "*" << endl;
    3393             : //    unsigned int                     numTime=0;
    3394             :  
    3395           0 :     unsigned int                     numAnt              = sdmdosr.numAntenna();   
    3396           0 :     CorrelationMode                  correlationMode     = sdmdosr.correlationMode(); e_cm=correlationMode;
    3397           0 :     ProcessorType                    processorType       = sdmdosr.processorType();   e_pt=processorType;
    3398             :     CorrelatorType                   correlatorType;
    3399             :     
    3400           0 :     const SDMDataObject::DataStruct& dataStruct          = sdmdosr.dataStruct();
    3401             :     
    3402           0 :     const vector<AtmPhaseCorrection>&       v_apc               = dataStruct.apc();
    3403           0 :     const vector<SDMDataObject::Baseband>&  v_baseband          = dataStruct.basebands();
    3404           0 :     SDMDataObject::ZeroLagsBinaryPart               zeroLagsParameters;
    3405             :     
    3406             : //    bool                             normalized=false;
    3407           0 :     if(e_pt[ProcessorTypeMod::CORRELATOR]){
    3408             : //      if(e_cm[CorrelationModeMod::CROSS_ONLY])
    3409             : //      normalized =  dataStruct.autoData().normalized();
    3410           0 :       if(dataStruct.zeroLags().size()){
    3411           0 :         zeroLagsParameters = dataStruct.zeroLags();
    3412           0 :         correlatorType = zeroLagsParameters.correlatorType(); e_ct=correlatorType;
    3413             :       }
    3414             :     }
    3415             :  
    3416           0 :     unsigned int                     numApc              = v_apc.size();
    3417           0 :     unsigned int                     numBaseband         = v_baseband.size();
    3418             :    
    3419           0 :     vector< vector< unsigned int > > vv_numAutoPolProduct;
    3420           0 :     vector< vector< unsigned int > > vv_numCrossPolProduct;
    3421           0 :     vector< vector< unsigned int > > vv_numSpectralPoint;
    3422           0 :     vector< vector< unsigned int > > vv_numBin;
    3423           0 :     vector< vector< float > >        vv_scaleFactor;
    3424           0 :     vector< unsigned int >           v_numSpectralWindow;
    3425           0 :     vector< vector< Enum<NetSideband> > > vv_e_sideband;
    3426           0 :     vector< vector< SDMDataObject::SpectralWindow* > > vv_image;
    3427             :     
    3428           0 :     if(verbose_)cout<<"e_cm="<<e_cm.str()<<endl;
    3429             :     
    3430           0 :     for(unsigned int nbb=0; nbb<v_baseband.size(); nbb++){
    3431           0 :       vector<SDMDataObject::SpectralWindow>  v_spw = v_baseband[nbb].spectralWindows(); v_numSpectralWindow.push_back(v_spw.size());
    3432           0 :       vector<SDMDataObject::SpectralWindow*> v_image;
    3433           0 :       vector< unsigned int > v_numBin;
    3434           0 :       vector< unsigned int > v_numSpectralPoint;
    3435           0 :       vector< unsigned int > v_numSdPolProduct;
    3436           0 :       vector< unsigned int > v_numCrPolProduct;
    3437           0 :       vector< Enum<NetSideband> >  v_e_sideband;
    3438           0 :       vector<float>          v_scaleFactor;
    3439           0 :       for(unsigned int nspw=0; nspw<v_spw.size(); nspw++){
    3440           0 :         v_e_sideband.push_back(Enum<NetSideband>(v_spw[nspw].sideband()));
    3441           0 :         v_image.push_back(NULL);                                   // TODO waiting for implementation
    3442           0 :         v_numBin.push_back(v_spw[nspw].numBin());
    3443           0 :         if(verbose_)cout<<"v_spw["<<nspw<<"].numSpectralPoint()="<<v_spw[nspw].numSpectralPoint()<<endl;
    3444           0 :         v_numSpectralPoint.push_back(v_spw[nspw].numSpectralPoint());
    3445           0 :         if(e_cm[AUTO_ONLY])
    3446           0 :           v_numSdPolProduct.push_back(v_spw[nspw].sdPolProducts().size());
    3447             :         else{
    3448           0 :           v_numCrPolProduct.push_back(v_spw[nspw].crossPolProducts().size());
    3449           0 :           v_scaleFactor.push_back(v_spw[nspw].scaleFactor());
    3450           0 :           if(e_cm[CROSS_AND_AUTO])
    3451           0 :             v_numSdPolProduct.push_back(v_spw[nspw].sdPolProducts().size());
    3452             :         }
    3453             :       }
    3454           0 :       if(e_cm[CROSS_ONLY]==false)vv_numAutoPolProduct.push_back(v_numSdPolProduct);
    3455           0 :       if(e_cm[AUTO_ONLY]==false) vv_numCrossPolProduct.push_back(v_numCrPolProduct);
    3456           0 :       vv_numSpectralPoint.push_back(v_numSpectralPoint);
    3457           0 :       vv_e_sideband.push_back(v_e_sideband);
    3458           0 :       vv_image.push_back(v_image);
    3459           0 :       vv_numBin.push_back(v_numBin);
    3460           0 :       vv_scaleFactor.push_back(v_scaleFactor);
    3461           0 :     }
    3462           0 :     if(e_cm[AUTO_ONLY])vv_numCrossPolProduct.clear();
    3463           0 :     if(e_cm[CROSS_ONLY])vv_numAutoPolProduct.clear();
    3464             :     
    3465           0 :     complexData_=false;
    3466           0 :     if(vv_numAutoPolProduct.size()){
    3467           0 :       for(unsigned int nbb=0; nbb<vv_numAutoPolProduct.size(); nbb++){
    3468           0 :         for(unsigned int nspw=0; nspw<vv_numAutoPolProduct[nbb].size(); nspw++)
    3469           0 :           if(vv_numAutoPolProduct[nbb][nspw]>2)complexData_=true;
    3470             :       }
    3471             :     }
    3472           0 :     if(vv_numCrossPolProduct.size())complexData_=true;
    3473             :     
    3474           0 :     EnumSet<AxisName>         es_axisNames;
    3475             :     DataContent               dataContent;
    3476           0 :     SDMDataObject::BinaryPart binaryPart;
    3477           0 :     map<DataContent,pair<unsigned int,EnumSet<AxisName> > > m_dc_sizeAndAxes;
    3478             :     
    3479           0 :     dataContent = FLAGS;
    3480           0 :     binaryPart  = dataStruct.flags();
    3481           0 :     es_axisNames.set(binaryPart.axes(),true);
    3482           0 :     if(es_axisNames.count())m_dc_sizeAndAxes.insert(make_pair(dataContent,make_pair(binaryPart.size(),es_axisNames)));
    3483             :     
    3484           0 :     dataContent = ACTUAL_DURATIONS;
    3485           0 :     binaryPart  = dataStruct.actualDurations();
    3486           0 :     es_axisNames.set(binaryPart.axes(),true);
    3487           0 :     if(es_axisNames.count())m_dc_sizeAndAxes.insert(make_pair(dataContent,make_pair(binaryPart.size(),es_axisNames)));
    3488             :     
    3489           0 :     dataContent = ACTUAL_TIMES;
    3490           0 :     binaryPart  = dataStruct.actualTimes();
    3491           0 :     es_axisNames.set(binaryPart.axes(),true);
    3492           0 :     if(es_axisNames.count())m_dc_sizeAndAxes.insert(make_pair(dataContent,make_pair(binaryPart.size(),es_axisNames)));
    3493             :     
    3494           0 :     dataContent = AUTO_DATA;
    3495           0 :     binaryPart  = dataStruct.autoData();
    3496           0 :     es_axisNames.set(binaryPart.axes(),true);
    3497           0 :     if(es_axisNames.count())m_dc_sizeAndAxes.insert(make_pair(dataContent,make_pair(binaryPart.size(),es_axisNames)));
    3498             :     
    3499             : //    if(es_axisNames[TIM])numTime=sdmdosr.numTime();
    3500             :     
    3501           0 :     dataContent = CROSS_DATA;
    3502           0 :     binaryPart  = dataStruct.crossData();
    3503           0 :     es_axisNames.set(binaryPart.axes(),true);
    3504           0 :     if(es_axisNames.count())m_dc_sizeAndAxes.insert(make_pair(dataContent,make_pair(binaryPart.size(),es_axisNames)));
    3505             :     
    3506           0 :     if(binaryPart.size()){
    3507           0 :       dataContent = ZERO_LAGS;
    3508           0 :       binaryPart  = dataStruct.zeroLags();
    3509           0 :       es_axisNames.set(binaryPart.axes(),true);
    3510           0 :       if(es_axisNames.count())m_dc_sizeAndAxes.insert(make_pair(dataContent,make_pair(binaryPart.size(),es_axisNames)));
    3511             :     }
    3512             :     
    3513             : //    if(es_axisNames[TIM])numTime=sdmdosr.numTime();
    3514             :     
    3515             :     map<DataContent,pair<unsigned int,EnumSet<AxisName> > >::iterator
    3516           0 :       itf=m_dc_sizeAndAxes.find(AUTO_DATA),
    3517           0 :       ite=m_dc_sizeAndAxes.end();
    3518           0 :     if(itf==ite)itf=m_dc_sizeAndAxes.find(CROSS_DATA);
    3519           0 :     if(itf==ite)Error(FATAL,(char *) "BLOB %s has no declaration for observational data",sdmdosr.dataOID().c_str());
    3520             :     
    3521             :     // Okay then we can start to read.
    3522           0 :     unsigned int nread = 0 ;
    3523             :     int64_t                    interval;
    3524             :     int64_t                    exposure;
    3525             :     int64_t                    timeOfInteg;
    3526             :     int64_t                    timeCentroid;
    3527           0 :     const vector<SDMDataSubset>& sdmDataSubsets = sdmdosr.nextSubsets(nDataSubsets);
    3528             : 
    3529           0 :     for (vector<SDMDataSubset>::const_iterator iter = sdmDataSubsets.begin(); iter != sdmDataSubsets.end(); iter++) {
    3530           0 :       const SDMDataSubset& currentSubset = *iter;
    3531           0 :       nread++; 
    3532             :       
    3533           0 :       timeOfInteg  = currentSubset.time();        
    3534           0 :       timeCentroid = currentSubset.time();        
    3535           0 :       interval     = currentSubset.interval();    
    3536           0 :       exposure     = interval;
    3537           0 :       if(verbose_){
    3538           0 :         for(unsigned int i=0; i<v_numSpectralWindow.size(); i++){
    3539           0 :           for(unsigned int j=0; j<v_numSpectralWindow[i]; j++)
    3540           0 :             cout<<"vv_numSpectralPoint[i][j]="<<vv_numSpectralPoint[i][j]<<endl;
    3541             :         }
    3542           0 :         for(unsigned int i=0; i<vv_numAutoPolProduct.size(); i++){
    3543           0 :           for(unsigned int j=0; j<vv_numAutoPolProduct[i].size(); j++)
    3544           0 :             cout<<"vv_numAutoPolProduct[i][j]="<<vv_numAutoPolProduct[i][j]<<endl;
    3545             :         }
    3546           0 :         for(unsigned int i=0; i<vv_numCrossPolProduct.size(); i++){
    3547           0 :           for(unsigned int j=0; j<vv_numCrossPolProduct[i].size(); j++)
    3548           0 :             cout<<"vv_numCrossPolProduct[i][j]="<<vv_numCrossPolProduct[i][j]<<endl;
    3549             :         }
    3550             :       }
    3551             :       DataDump* dataDumpPtr = new DataDump( vv_numCrossPolProduct,
    3552             :                                             vv_numAutoPolProduct,
    3553             :                                             vv_numSpectralPoint,
    3554             :                                             vv_numBin,
    3555             :                                             vv_e_sideband,
    3556             :                                             numApc,
    3557             :                                             v_numSpectralWindow,
    3558             :                                             numBaseband,
    3559             :                                             numAnt,
    3560             :                                             correlationMode,
    3561             :                                             timeOfInteg,
    3562             :                                             timeCentroid,
    3563             :                                             interval,
    3564             :                                             exposure
    3565           0 :                                             );
    3566           0 :       if(e_cm[CROSS_ONLY]    )dataDumpPtr->setScaleFactor(vv_scaleFactor);
    3567           0 :       if(e_cm[CROSS_AND_AUTO])dataDumpPtr->setScaleFactor(vv_scaleFactor);
    3568             : 
    3569           0 :       if(verbose_)cout<<"m_dc_sizeAndAxes.size()="<< m_dc_sizeAndAxes.size() << endl;
    3570           0 :       if((itf=m_dc_sizeAndAxes.find(FLAGS))!=ite){
    3571           0 :         if(verbose_)cout<<"Flags have been declared in the main header"<<endl;
    3572             :         const unsigned int* flagsPtr;
    3573           0 :         unsigned int long numFlags = currentSubset.flags( flagsPtr );
    3574           0 :         if(verbose_)cout<<numFlags<<" "<<itf->second.first<<endl;
    3575           0 :         if(numFlags)dataDumpPtr->attachFlags( itf->second.first, itf->second.second,
    3576             :                                               numFlags, flagsPtr);
    3577             :       }
    3578             : 
    3579           0 :       if((itf=m_dc_sizeAndAxes.find(ACTUAL_TIMES))!=ite){
    3580           0 :         if(verbose_)cout<<"ActualTimes have been declared in the main header"<<endl;
    3581             :         const int64_t* actualTimesPtr;
    3582           0 :         unsigned long int numActualTimes = currentSubset.actualTimes( actualTimesPtr );
    3583           0 :         if(verbose_)cout<<numActualTimes<<" "<<itf->second.first<<endl;
    3584           0 :         if(numActualTimes)dataDumpPtr->attachActualTimes( itf->second.first, itf->second.second,
    3585             :                                                           numActualTimes, actualTimesPtr);
    3586             :       }
    3587             : 
    3588           0 :       if((itf=m_dc_sizeAndAxes.find(ACTUAL_DURATIONS))!=ite){
    3589           0 :         if(verbose_)cout<<"ActualDurations have been declared in the main header"<<endl;
    3590             :         const int64_t* actualDurationsPtr;
    3591           0 :         unsigned long int numActualDurations = currentSubset.actualDurations( actualDurationsPtr );
    3592           0 :         if(verbose_)cout<<numActualDurations<<" "<<itf->second.first<<endl;
    3593           0 :         if(numActualDurations)dataDumpPtr->attachActualDurations( itf->second.first, itf->second.second,
    3594             :                                                                   numActualDurations, actualDurationsPtr);
    3595             :       }
    3596             : 
    3597           0 :       if((itf=m_dc_sizeAndAxes.find(ZERO_LAGS))!=ite){
    3598           0 :         if(verbose_)cout<<"ZeroLags have been declared in the main header"<<endl;
    3599             :         const float* zeroLagsPtr;
    3600           0 :         unsigned long int numZeroLags = currentSubset.zeroLags( zeroLagsPtr );
    3601           0 :         if(verbose_)cout<<numZeroLags<<" "<<itf->second.first<<endl;
    3602           0 :         if(numZeroLags)dataDumpPtr->attachZeroLags( itf->second.first, itf->second.second,
    3603             :                                                     numZeroLags, zeroLagsPtr);
    3604             :       }
    3605             : 
    3606           0 :       if((itf=m_dc_sizeAndAxes.find(CROSS_DATA))!=ite){
    3607           0 :         if(verbose_)cout<<"CrossData have been declared in the main header ";
    3608             :         unsigned long int numCrossData;
    3609           0 :         switch(currentSubset.crossDataType()){
    3610           0 :         case INT16_TYPE:
    3611             :           { const short int* crossDataPtr;
    3612           0 :             numCrossData = currentSubset.crossData( crossDataPtr );
    3613           0 :             if(numCrossData)dataDumpPtr->attachCrossData( itf->second.first, itf->second.second,
    3614             :                                                           numCrossData, crossDataPtr);
    3615             :           }
    3616           0 :           if(verbose_)cout<<"SHORT_TYPE"<<endl;
    3617           0 :           if(verbose_)cout<<"crossData attached,  const pointer:"<<dataDumpPtr->crossDataShort()<<endl;
    3618           0 :           break;
    3619           0 :         case INT32_TYPE:
    3620             :           { const int* crossDataPtr;
    3621           0 :             numCrossData = currentSubset.crossData( crossDataPtr );
    3622           0 :             if(numCrossData)dataDumpPtr->attachCrossData( itf->second.first, itf->second.second,
    3623             :                                                           numCrossData, crossDataPtr);
    3624             :           }
    3625           0 :           if(verbose_)cout<<"INT_TYPE"<<endl;
    3626           0 :           if(verbose_)cout<<"crossData attached,  const pointer:"<<dataDumpPtr->crossDataLong()<<endl;
    3627           0 :           break;
    3628           0 :         case FLOAT32_TYPE:
    3629             :           { const float* crossDataPtr;
    3630           0 :             numCrossData = currentSubset.crossData( crossDataPtr );
    3631           0 :             if(numCrossData)dataDumpPtr->attachCrossData( itf->second.first, itf->second.second,
    3632             :                                                           numCrossData, crossDataPtr);
    3633             :           }
    3634           0 :           if(verbose_)cout<<"FLOAT_TYPE"<<endl;
    3635           0 :           if(verbose_)cout<<"crossData attached,  const pointer:"<<dataDumpPtr->crossDataFloat()<<endl;
    3636           0 :           break;
    3637           0 :         default:
    3638           0 :           Enum<PrimitiveDataType> e_pdt=currentSubset.crossDataType();
    3639           0 :           Error(FATAL, (char *) "Cross data with the primitive data type %s are not supported",
    3640           0 :                 e_pdt.str().c_str());
    3641             :         }
    3642             :       }
    3643             : 
    3644           0 :       if((itf=m_dc_sizeAndAxes.find(AUTO_DATA))!=ite){
    3645           0 :         if(verbose_)cout<<"AutoData have been declared in the main header"<<endl;
    3646           0 :         const float*      floatDataPtr=NULL;
    3647           0 :         unsigned long int numFloatData = currentSubset.autoData( floatDataPtr );
    3648           0 :         if(verbose_)cout<<numFloatData<<" "<<itf->second.first<<"  "<<floatDataPtr<<endl;
    3649           0 :         if(numFloatData){
    3650           0 :           if(numFloatData!=itf->second.first)
    3651           0 :             Error(FATAL,(char *) "Size of autoData, %d, not compatible with the declared size of %d",
    3652           0 :                   numFloatData,itf->second.first);
    3653           0 :           dataDumpPtr->attachAutoData( itf->second.first, itf->second.second,
    3654             :                                        numFloatData, floatDataPtr);
    3655           0 :           if(verbose_)cout<<"autoData attached,  const pointer:"<<dataDumpPtr->autoData()<<endl;
    3656             :           //          const long unsigned int* aptr=dataDumpPtr->flags();
    3657           0 :         }else if(numFloatData==0){
    3658           0 :           if(!e_cm[CROSS_ONLY])
    3659           0 :             Error(WARNING, string("No autoData! may happen when a subscan is aborted"));
    3660           0 :           break;
    3661             :         }
    3662             :       }
    3663             : 
    3664           0 :       if (verbose_) cout << "About to setContextUsingProjectPath" << endl;
    3665           0 :       dataDumpPtr->setContextUsingProjectPath(currentSubset.projectPath());
    3666           0 :       if (verbose_) cout << "Back from setContextUsingProjectPath" << endl;
    3667           0 :       const unsigned int* bptr=dataDumpPtr->flags(); if(bptr==NULL)if(verbose_)cout<<"No flags"<<endl;
    3668           0 :       if(verbose_)cout<<"store dataDump"<<endl;
    3669           0 :       v_dataDump_.push_back(dataDumpPtr);
    3670           0 :       if(verbose_)cout<<"v_dataDumpPtr_.size()="<< v_dataDump_.size()<<endl;
    3671             :     }
    3672           0 :     if(verbose_)cout<<"v_dataDumpPtr_.size()="<< v_dataDump_.size()<<endl;
    3673           0 :     if (verbose_) cout << "SDMBinData::getNextDataDumps : exiting" << endl;
    3674           0 :     return;
    3675           0 :   }
    3676             : 
    3677           0 :   MSState SDMBinData::getMSState( unsigned int subscanNum,
    3678             :                                   vector<Tag>  v_stateId,
    3679             :                                   vector<Tag>  v_antennaId, vector<int> v_feedId, vector<Tag> v_ddId,
    3680             :                                   unsigned int na, unsigned int nfe, unsigned int nspw, ArrayTime timeOfDump)
    3681             :   {
    3682           0 :     if (verbose_) cout << "SDMBinData::getMSState : entering." << endl;
    3683             :     static unsigned int                                     subscan    = 0;
    3684           0 :     static vector<StateRow*>                                v_sdmState;
    3685           0 :     static vector<vector<vector<vector<CalDeviceRow*> > > > vvvv_calDevice;
    3686           0 :     static vector<Tag>                                      v_spwId;
    3687           0 :     MSState                                                 msState;
    3688             :     //    if(subscan!=subscanNum){
    3689           0 :       StateTable&  sdmStates  = datasetPtr_->getState();
    3690           0 :       v_sdmState.resize(v_stateId.size());
    3691           0 :       for(unsigned int n=0 ; n<v_stateId.size(); n++)
    3692           0 :         v_sdmState[n] = sdmStates.getRowByKey(v_stateId[n]);
    3693             :       //}
    3694           0 :     if(verbose_)cout<<"v_sdmState="<<v_sdmState.size()<<endl;
    3695             : 
    3696           0 :     msState.sig  = v_sdmState[na]->getSig();
    3697           0 :     msState.ref  = v_sdmState[na]->getRef();
    3698           0 :     msState.cal  = 0;
    3699           0 :     msState.load = 0;
    3700             : 
    3701           0 :     if(!v_sdmState[na]->getOnSky()){
    3702           0 :       if(verbose_)cout<<"subscan="<<subscan<<" subscanNum="<<subscanNum<<endl;
    3703             :       //if(subscan!=subscanNum){
    3704           0 :         vector<CalDeviceRow*> v_calDev;
    3705           0 :         vector<CalDeviceRow*>* v_calDevPtr = 0;
    3706           0 :         CalDeviceTable&       calDevices       = datasetPtr_->getCalDevice();
    3707           0 :         DataDescriptionTable& dataDescriptions = datasetPtr_->getDataDescription();
    3708           0 :         for(unsigned int n_d=0; n_d<v_ddId.size(); n_d++)
    3709           0 :           v_spwId.push_back(dataDescriptions.getRowByKey(v_ddId[n_d])->getSpectralWindowId());
    3710             : 
    3711           0 :         vvvv_calDevice.resize(v_antennaId.size());
    3712           0 :         for(unsigned int n_a=0; n_a<v_antennaId.size(); n_a++){
    3713           0 :           vvvv_calDevice[n_a].resize(v_feedId.size());
    3714           0 :           for(unsigned int n_f=0; n_f<v_feedId.size(); n_f++){
    3715           0 :             vvvv_calDevice[n_a][n_f].resize(v_spwId.size());
    3716           0 :             for(unsigned int n_s=0; n_s<v_spwId.size(); n_s++){
    3717           0 :               if(verbose_)cout<<" antId=" << v_antennaId[n_a].toString()
    3718           0 :                              <<" feedId="<< v_feedId[n_f]
    3719           0 :                              <<" spwId=" << v_spwId[n_s].toString()
    3720           0 :                              <<endl;
    3721           0 :               vvvv_calDevice[n_a][n_f][n_s] = v_calDev;
    3722           0 :               if ( (v_calDevPtr = calDevices.getByContext( v_antennaId[n_a],
    3723           0 :                                                            v_spwId[n_s],
    3724           0 :                                                            (int) v_feedId[n_f])) != 0)
    3725           0 :                 vvvv_calDevice[n_a][n_f][n_s] = *v_calDevPtr;
    3726             :               else {
    3727           0 :                 ostringstream oss;
    3728           0 :                 oss << "Could not find a row in the table CalDevice for antennaId = "
    3729           0 :                      << v_antennaId[n_a].getTagValue()
    3730           0 :                      <<", spectralWindowId = "
    3731           0 :                      << v_spwId[n_s].getTagValue()
    3732           0 :                      << ", feedId = "
    3733           0 :                      << v_feedId[n_f]
    3734           0 :                      << endl;
    3735           0 :                 Error(FATAL, oss.str());
    3736           0 :               }
    3737             :             }
    3738             :           }
    3739             :         }
    3740             :         //}
    3741           0 :       int nt=-1;
    3742           0 :       vector<CalDeviceRow*> v_ts=vvvv_calDevice[na][nfe][nspw];   // the time series
    3743           0 :       if(!v_ts.size())Error(FATAL, string("The CalDevice is empty, I can't go further."));
    3744           0 :       for(unsigned int n=0; n<v_ts.size(); n++){
    3745           0 :         if( nt==-1 && v_ts[n]->getTimeInterval().contains(timeOfDump) ){
    3746           0 :           nt=n;
    3747           0 :           break;
    3748             :         }
    3749             :       }
    3750           0 :       if(nt==-1)
    3751           0 :         Error( FATAL,
    3752             :                (char *) "Failed to find the CalDevice row for na=%d nfe=%d nspw=%d at the given time of dump",
    3753             :                na,nfe,nspw);
    3754             : 
    3755           0 :       CalDeviceRow*             caldevr      = vvvv_calDevice[na][nfe][nspw][nt];
    3756           0 :       vector<CalibrationDevice> v_calDevice                                                                 = caldevr->getCalLoadNames();
    3757           0 :       vector<double>            v_noiseCal;        if(caldevr->isNoiseCalExists())        v_noiseCal        = caldevr->getNoiseCal();
    3758           0 :       vector<Temperature>       v_temperatureLoad; if(caldevr->isTemperatureLoadExists()) v_temperatureLoad = caldevr->getTemperatureLoad();
    3759           0 :       vector<vector<float> >    v_calEff;          if(caldevr->isCalEffExists())          v_calEff          = caldevr->getCalEff();
    3760             : 
    3761           0 :       CalibrationDevice         calDevName        = v_sdmState[na]->getCalDeviceName();
    3762           0 :       for(unsigned int n_cd=0; n_cd<v_calDevice.size(); n_cd++){
    3763           0 :         switch(v_calDevice[n_cd]) {
    3764           0 :         case AMBIENT_LOAD:
    3765           0 :           if(v_calDevice[n_cd]==calDevName)
    3766           0 :             msState.load = v_temperatureLoad[n_cd].get();
    3767           0 :           break;
    3768           0 :         case COLD_LOAD:
    3769           0 :           if(v_calDevice[n_cd]==calDevName)
    3770           0 :             msState.load = v_temperatureLoad[n_cd].get();
    3771           0 :           break;
    3772           0 :         case HOT_LOAD:
    3773           0 :           if(v_calDevice[n_cd]==calDevName)
    3774           0 :             msState.load = v_temperatureLoad[n_cd].get();
    3775           0 :           break;
    3776           0 :         case NOISE_TUBE_LOAD:
    3777           0 :           if(v_calDevice[n_cd]==calDevName)
    3778           0 :             msState.cal = v_noiseCal[n_cd];
    3779           0 :           break;
    3780           0 :         case QUARTER_WAVE_PLATE:
    3781           0 :           Error(FATAL, string("QUATER_WAVE_PLATE use-case not yet supported"));
    3782           0 :           break;
    3783           0 :         case SOLAR_FILTER:
    3784           0 :           Error(FATAL, string("SOLAR_FILTER use-case not yet supported"));
    3785           0 :           break;
    3786           0 :         default:
    3787           0 :           Error(FATAL, string("Illegal calibration device name"));
    3788             :         }
    3789             :       }
    3790           0 :     }
    3791           0 :     msState.subscanNum = subscanNum;
    3792             : 
    3793           0 :     if(verbose_){
    3794           0 :       cout<<"State: ";
    3795           0 :       if(msState.sig)cout<<" sig Y"; else cout<<" sig N";
    3796           0 :       if(msState.sig)cout<<" ref Y"; else cout<<" ref N";
    3797           0 :       cout<<" cal="       <<msState.cal
    3798           0 :           <<" load="      <<msState.load
    3799           0 :           <<" subscanNum="<<msState.subscanNum<<endl;
    3800             :     }
    3801             : 
    3802             :     // TODO the OBS_MODE
    3803             : 
    3804           0 :     subscan = subscanNum;
    3805           0 :     if (verbose_) cout << "SDMBinData::getMSState : exiting." << endl;
    3806           0 :     return msState;
    3807           0 :   }
    3808             : 
    3809           0 :   bool  SDMBinData::isComplexData(){
    3810             :   
    3811           0 :     if(mainRowPtr_){
    3812             : 
    3813           0 :       if(canSelect_){
    3814           0 :         return complexData_;    // the state of complexData_ is set in the method acceptMainRow(mainRowPtr)
    3815             :       }else{
    3816             : 
    3817           0 :         cerr<<"Forbidden to use the method isComplexData() in the context of a specific"<<endl;
    3818           0 :         cerr<<"row of the Main table because it was already used in the context of the Main"<<endl;
    3819           0 :         cerr<<"table as a whole"<<endl;
    3820           0 :         Error(FATAL, string("Use-case not valid in the perpective of a filling a MeasurementSet"));
    3821           0 :         return true;  // never pass here
    3822             :       }
    3823             : 
    3824             :     }else{
    3825             :       /*
    3826             :          This part is intended to know if a DATA or FLOAT_DATA column has to be created before
    3827             : 
    3828             :          considering the SDM main table rows one by one when building a MS main table.
    3829             :       */
    3830             : 
    3831           0 :       canSelect_    = false;
    3832           0 :       forceComplex_ = true;
    3833             : 
    3834           0 :       if (e_qcm_[CROSS_ONLY] && es_cm_[CROSS_ONLY]) return forceComplex_;
    3835             : 
    3836           0 :       vector<MainRow*>            v_mr = datasetPtr_->getMain().get();
    3837           0 :       vector<DataDescriptionRow*> v_ddr;
    3838             :       ConfigDescriptionRow*       cdr;
    3839           0 :       Enum<CorrelationMode>       e_cm;
    3840           0 :       for(unsigned int n=0; n<v_mr.size(); n++){
    3841           0 :         if(!reasonToReject(v_mr[n]).length()){
    3842           0 :           cdr  = v_mr[n]->getConfigDescriptionUsingConfigDescriptionId();
    3843           0 :           e_cm = cdr->getCorrelationMode();
    3844           0 :           if(e_cm[AUTO_ONLY]){
    3845           0 :             v_ddr = cdr->getDataDescriptionsUsingDataDescriptionId();
    3846           0 :             for(unsigned int ndd=0; ndd<v_ddr.size(); ndd++)
    3847           0 :               if(v_ddr[ndd]->getPolarizationUsingPolOrHoloId()->getCorrType().size()>2)return forceComplex_;
    3848             :           }
    3849           0 :           else if(e_cm[CROSS_AND_AUTO]){
    3850           0 :             if(e_qcm_[CROSS_AND_AUTO]){
    3851           0 :               return true;
    3852             :             }else{
    3853           0 :               v_ddr = cdr->getDataDescriptionsUsingDataDescriptionId();
    3854           0 :               for(unsigned int ndd=0; ndd<v_ddr.size(); ndd++)
    3855           0 :                 if(v_ddr[ndd]->getPolarizationUsingPolOrHoloId()->getCorrType().size()>2)return forceComplex_;
    3856             :             }
    3857             :           }
    3858           0 :           else if (e_cm[CROSS_ONLY]) {
    3859           0 :             return true;
    3860             :           }
    3861             :         }
    3862             :       }
    3863           0 :       forceComplex_ = false;
    3864           0 :       return forceComplex_;
    3865           0 :     }
    3866             :   }
    3867             : 
    3868           0 :   bool SDMBinData::baselineReverse(){
    3869           0 :     return SDMBinData::baselineReverse_;
    3870             :   }
    3871             : 
    3872           0 :   bool SDMBinData::autoTrailing(){
    3873           0 :     return SDMBinData::autoTrailing_;
    3874             :   }
    3875             : 
    3876           0 :   pair<bool,bool> SDMBinData::dataOrder(){
    3877           0 :     pair<bool,bool> p=make_pair( baselineReverse_, autoTrailing_ );
    3878           0 :     return p;
    3879             :   }
    3880             : 
    3881             :   string           SDMBinData::execBlockDir_  = "";
    3882             :   ASDM*            SDMBinData::datasetPtr_    = 0;
    3883             :   bool             SDMBinData::canSelect_     = true;
    3884             :   bool             SDMBinData::forceComplex_  = false;
    3885             :   MSData*          SDMBinData::msDataPtr_     = 0;
    3886             :   SDMData*         SDMBinData::sdmDataPtr_    = 0;
    3887             :   VMSData*         SDMBinData::vmsDataPtr_    = 0;
    3888             :   vector<MSData*>  SDMBinData::v_msDataPtr_;
    3889             :   vector<SDMData*> SDMBinData::v_sdmDataPtr_;
    3890             :   bool             SDMBinData::coutDeleteInfo_=false;
    3891             :   BaselinesSet*    SDMBinData::baselinesSet_  =0;
    3892             :   bool             SDMBinData::baselineReverse_ = false;
    3893             :   bool             SDMBinData::autoTrailing_    = false;
    3894             :   bool             SDMBinData::syscal_          = false;
    3895             : }

Generated by: LCOV version 1.16