LCOV - code coverage report
Current view: top level - alma/ASDMBinaries - SDMBinData.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 1115 2202 50.6 %
Date: 2024-11-06 17:42:47 Functions: 25 42 59.5 %

          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          78 :   SDMBinData::SDMBinData( ASDM* const datasetPtr, string execBlockDir){
      44             :     // Are we going to be verbose ?
      45          78 :     verbose_ = getenv("ASDM_DEBUG") != NULL;
      46             : 
      47             :     DIR *dir;
      48          78 :     dir = opendir( execBlockDir.c_str());
      49          78 :     if(!dir)
      50           0 :       Error(FATAL, "In SDMBinData::SDMBinData( ASDM* const datasetPtr, string execBlockDir) : Directory " + execBlockDir + " not present present");
      51          78 :     closedir(dir);
      52          78 :     dir = NULL;
      53             : 
      54          78 :     string xmlfile = execBlockDir + "/Main.xml"; //cout << "xmlfile="<< xmlfile<<endl;
      55             :     FILE *pFile;
      56          78 :     pFile = fopen( xmlfile.c_str(),"r");
      57          78 :     if(!pFile)
      58           0 :       Error(FATAL, string("In SDMBinData::SDMBinData( ASDM* const datasetPtr, string execBlockDir) : Main table not present in the SDM dataset"));
      59          78 :     fclose(pFile);
      60          78 :     pFile = NULL;
      61             : 
      62          78 :     execBlockDir_ = execBlockDir;
      63          78 :     mainRowPtr_   = NULL;
      64          78 :     datasetPtr_   = datasetPtr;
      65          78 :     dataOID_      = "";
      66          78 :     canSelect_    = true;
      67          78 :     es_si_.flip();              // default: accept any scan
      68          78 :     es_pt_.flip();              // default: accept any processor type when selecting the rows to be processed
      69          78 :     es_cm_.flip();              // default: accept any correlation mode when selecting the rows to be processed
      70          78 :     es_srt_.flip();             // default: accept any spectral resolution type when selecting the rows to be processed
      71          78 :     es_ts_.flip();              // default: accept any time sampling when selecting the rows to be processed
      72          78 :     e_qcm_.set(CROSS_AND_AUTO); // default: select all data present in the BLOB (the HLA enum model being not set-based...)
      73          78 :     es_qapc_.flip();            // default: select all the full APC axis in the BLOB
      74          78 :     ddfirst_=false;
      75             : 
      76          78 :     bdfMemoryMapped = getenv("BDF_MEMORY_MAPPED") != NULL;
      77          78 :   }
      78             : 
      79          78 :   SDMBinData::~SDMBinData(){
      80          78 :     if(coutDeleteInfo_)cout<<"Destructor SSDMBinData"<<endl;
      81             : 
      82      913024 :     for(unsigned int n=0; n<v_msDataPtr_.size();  n++) {
      83      912946 :       if(v_msDataPtr_[n]){deleteMsData(v_msDataPtr_[n]);}
      84             :     }
      85          78 :     v_msDataPtr_.clear();
      86             : 
      87          78 :     for(unsigned int n=0; n<v_sdmDataPtr_.size(); n++){
      88           0 :       if(v_sdmDataPtr_[n]){delete v_sdmDataPtr_[n]; }
      89             :     }
      90          78 :     v_sdmDataPtr_.clear();
      91             : 
      92          78 :     if(vmsDataPtr_) {
      93          47 :       delete vmsDataPtr_;
      94          47 :       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          78 :       it,
     113          78 :       itrb=v_dataDump_.rbegin(),
     114          78 :       itre=v_dataDump_.rend();
     115        2637 :     for(it=itrb; it!=itre; it++){
     116        2559 :       delete *it;
     117             :     }
     118          78 :     v_dataDump_.clear();
     119             : 
     120         184 :     for (map<Tag,BaselinesSet*>::iterator it=m_cdId_baselinesSet_.begin();it!=m_cdId_baselinesSet_.end();++it) {
     121         106 :       if (it->second != NULL) delete(it->second);
     122             :     }
     123          78 :     m_cdId_baselinesSet_.clear();
     124             : 
     125          78 :     if(coutDeleteInfo_)cout<<"FIN: SSDMBinData object deleted"<<endl;
     126          78 :   }
     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          78 :   void SDMBinData::select( EnumSet<CorrelationMode>        es_cm,
     164             :                            EnumSet<SpectralResolutionType> es_srt,
     165             :                            EnumSet<TimeSampling>           es_ts){
     166          78 :     if(canSelect_){
     167          78 :       es_cm_  = es_cm;
     168          78 :       es_srt_ = es_srt;
     169          78 :       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          78 :   }
     174             : 
     175          78 :   void SDMBinData::selectDataSubset(  Enum<CorrelationMode> e_qcm, EnumSet<AtmPhaseCorrection> es_qapc){
     176          78 :     if(canSelect_){
     177          78 :       e_qcm_   = e_qcm;
     178          78 :       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          78 :   }
     183             : 
     184        5145 :   string SDMBinData::reasonToReject(MainRow* const mainRowPtr){
     185             : 
     186             :     //bool                  coutest=false;
     187             :     bool                  ok;
     188        5145 :     string                reason = "";
     189        5145 :     ConfigDescriptionRow* cdr    = mainRowPtr->getConfigDescriptionUsingConfigDescriptionId();
     190             :     ScanRow*              sr;
     191             : 
     192        5145 :     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        5145 :     sr = datasetPtr_->getScan().getRowByKey( mainRowPtr->getExecBlockUsingExecBlockId()->getExecBlockId(),
     202             :                                              mainRowPtr->getScanNumber() );
     203        5145 :     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        5145 :     vector<ScanIntent> v_si=sr->getScanIntent();
     210        5145 :     ok=false;
     211       15245 :     for(unsigned int n=0 ; n<v_si.size(); n++)if(es_si_[v_si[n]])ok=true;
     212        5145 :     if(!ok){
     213           0 :       reason += " no overlap with the scan intent set {"+es_si_.str()+"}";
     214             :     }
     215             : 
     216             :     // the processor type:
     217        5145 :     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        5145 :     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        5145 :     vector<SpectralResolutionType>  v_srt;
     228        5145 :     if (cdr->isAssocNatureExists()) v_srt=cdr->getAssocNature();
     229        5145 :     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        5145 :     ok=false;
     233        5145 :     EnumSet<SpectralResolutionType> es_srt; es_srt.set(v_srt); v_srt = es_srt.flip().toEnumType();
     234        5145 :     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       16159 :     for(unsigned int n=0; n<v_srt.size(); n++)if(es_srt_[v_srt[n]])ok=true;
     238        5145 :     if(!ok) {
     239           0 :       reason += " no overlap with the spectral resolution type set {"+es_srt_.str()+"}";
     240             :     }
     241             : 
     242             :     // the time sampling:
     243        5145 :     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        5145 :     if(e_qcm_[CROSS_ONLY] && cdr->getCorrelationMode()==AUTO_ONLY) {
     249          40 :       reason += " no cross correlations";
     250             :     }
     251             : 
     252        5145 :     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        5145 :     if (processorType(mainRowPtr) != RADIOMETER) {
     261        1663 :       EnumSet<AtmPhaseCorrection> es_apc;
     262        1663 :       vector<AtmPhaseCorrection>  v_apc=cdr->getAtmPhaseCorrection();
     263        1663 :       ok=false;
     264        3326 :       for(unsigned int n=0; n<v_apc.size(); n++)if(es_qapc_[v_apc[n]])ok=true;
     265        1663 :       if(!ok) {
     266           0 :         reason += " no overlap with the APC set {"+es_qapc_.str()+"}";
     267             :       }
     268        1663 :     }
     269             : 
     270        5145 :     if(verbose_){
     271           0 :       cout << "SDMBinData::reasonToReject(MainRow* const mainRowPtr) : exiting." << endl;
     272             :     }
     273       10290 :     return reason;
     274        5145 :   }
     275             : 
     276          78 :   void SDMBinData::setPriorityDataDescription(){
     277          78 :     ddfirst_=true;
     278          78 :   }
     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         571 :   bool SDMBinData::openMainRow( MainRow* const mainRowPtr){
     294         571 :     if (verbose_) cout << "SDMBinData::openMainRow : entering" << endl;
     295             : 
     296         571 :     if( reasonToReject(mainRowPtr).length() )return false;
     297             : 
     298         571 :     ConfigDescriptionRow* cdr  = mainRowPtr->getConfigDescriptionUsingConfigDescriptionId();
     299             : 
     300             : 
     301             :     // proceed, the row having been accepted:
     302             :     // -------------------------------------
     303             : 
     304         571 :     mainRowPtr_ = mainRowPtr;
     305             : 
     306             : 
     307             :     // process the config description (if not yet done) for this row:
     308         571 :     Tag cdId = cdr->getConfigDescriptionId();                       if(verbose_)cout<< "ici 1"<<cdId.toString() <<endl;
     309             :     set<Tag>::iterator
     310         571 :       itcdIdf=s_cdId_.find(cdId),
     311         571 :       itcdIde=s_cdId_.end();
     312         571 :     if(itcdIdf==itcdIde){
     313             :       DataDescriptionsSet dataDescriptionsSet( datasetPtr_,
     314         170 :                                                cdr->getSwitchCycleId(),
     315          85 :                                                cdr->getDataDescriptionId(),
     316             :                                                cdr->getCorrelationMode(),
     317         255 :                                                cdr->getAtmPhaseCorrection());                    if(verbose_)cout << "ici 3"<<endl;
     318             : 
     319          85 :       unsigned int numAnt=cdr->getNumAntenna();
     320        1849 :       vector<int>  v_phasedArrayList;  for(unsigned int na=0; na<numAnt; na++)v_phasedArrayList.push_back(0);
     321        1849 :       vector<bool> v_antennaUsedArray; for(unsigned int na=0; na<numAnt; na++)v_antennaUsedArray.push_back(true);
     322          85 :       BaselinesSet* baselinesSetPtr = new BaselinesSet( cdr->getAntennaId(),
     323          85 :                                                         cdr->getFeedId(),
     324             :                                                         v_phasedArrayList,
     325             :                                                         v_antennaUsedArray,
     326         170 :                                                         dataDescriptionsSet);  if(verbose_)cout << "ici 4"<<endl;
     327          85 :       m_cdId_baselinesSet_.insert(make_pair(cdId,baselinesSetPtr));
     328          85 :       s_cdId_.insert(cdId);
     329          85 :     }else{
     330         486 :       if(verbose_)cout<<"reuse cdId="<<cdId.toString()<<endl;
     331             :     }
     332             : 
     333         571 :     if(verbose_)cout << "ici 4 dataOID="<<mainRowPtr->getDataUID().getEntityId().toString()<<endl;
     334             : 
     335         571 :     int iostat = openStreamDataObject(mainRowPtr->getDataUID().getEntityId().toString());
     336         571 :     if(iostat==0){
     337         571 :       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         571 :     if (verbose_) cout << "SDMBinData::openMainRow : exiting" << endl;
     345         571 :     return true;
     346         571 :   }
     347             : 
     348    12003253 :   ProcessorType SDMBinData::processorType(MainRow* const mainRowPtr) const {
     349    12003253 :     if (verbose_) cout << "SDMBinData::processorType(MainRow* const mainRowPtr) : entering" << endl;
     350    12003253 :     Tag cdId = mainRowPtr->getConfigDescriptionId();
     351    12003253 :     ConfigDescriptionTable& cT = mainRowPtr->getTable().getContainer().getConfigDescription();
     352    12003253 :     ConfigDescriptionRow* cR = cT.getRowByKey(cdId);
     353    12003253 :     Tag pId = cR->getProcessorId();
     354             :     
     355             :     
     356    12003253 :     ProcessorType processorType =  mainRowPtr->getTable().getContainer().getProcessor().getRowByKey(pId)->getProcessorType();
     357             : 
     358    12003253 :     if (verbose_) cout << "SDMBinData::processorType(MainRow* const mainRowPtr) : exiting" << endl;
     359    12003253 :     return processorType;
     360    12003253 :   }
     361             : 
     362         202 :   bool SDMBinData::acceptMainRow( MainRow* const mainRowPtr){
     363             : 
     364             :     //bool coutest=false;
     365             : 
     366         202 :     if (verbose_) cout << "SDMBinData::acceptMainRow( MainRow* const mainRowPtr) : entering." << endl;
     367             : 
     368         202 :     string whyToReject = reasonToReject(mainRowPtr);
     369         202 :     if( whyToReject.length() ){
     370          20 :       if (verbose_) {
     371           0 :         cout << "Main row rejected , reason : " << whyToReject << endl;
     372           0 :         cout << "SDMBinData::acceptMainRow( MainRow* const mainRowPtr) : exiting." << endl;
     373             :       }
     374          20 :       return false;
     375             :     }
     376             : 
     377         182 :     ConfigDescriptionRow* cdr  = mainRowPtr->getConfigDescriptionUsingConfigDescriptionId();
     378             : 
     379             : 
     380             :     // proceed, the row having been accepted:
     381             :     // -------------------------------------
     382             : 
     383         182 :     mainRowPtr_ = mainRowPtr;
     384             : 
     385             : 
     386             :     // process the config description (if not yet done) for this row:
     387         182 :     Tag cdId = cdr->getConfigDescriptionId();                       if(verbose_)cout<< "ici 1"<<cdId.toString() <<endl;
     388             :     set<Tag>::iterator
     389         182 :       itcdIdf=s_cdId_.find(cdId),
     390         182 :       itcdIde=s_cdId_.end();
     391         182 :     if(itcdIdf==itcdIde){
     392             :       DataDescriptionsSet dataDescriptionsSet( datasetPtr_,
     393          42 :                                                cdr->getSwitchCycleId(),
     394          21 :                                                cdr->getDataDescriptionId(),
     395             :                                                cdr->getCorrelationMode(),
     396          63 :                                                cdr->getAtmPhaseCorrection());                    if(verbose_)cout << "ici 3"<<endl;
     397             : 
     398          21 :       unsigned int numAnt=cdr->getNumAntenna();
     399         361 :       vector<int>  v_phasedArrayList;  for(unsigned int na=0; na<numAnt; na++)v_phasedArrayList.push_back(0);
     400         361 :       vector<bool> v_antennaUsedArray; for(unsigned int na=0; na<numAnt; na++)v_antennaUsedArray.push_back(true);
     401          21 :       BaselinesSet* baselinesSetPtr = new BaselinesSet( cdr->getAntennaId(),
     402          21 :                                                         cdr->getFeedId(),
     403             :                                                         v_phasedArrayList,
     404             :                                                         v_antennaUsedArray,
     405          42 :                                                         dataDescriptionsSet);  if(verbose_)cout << "ici 4"<<endl;
     406          21 :       m_cdId_baselinesSet_.insert(make_pair(cdId,baselinesSetPtr));
     407          21 :       s_cdId_.insert(cdId);
     408          21 :     }else{
     409         161 :       if(verbose_)cout<<"reuse cdId="<<cdId.toString()<<endl;
     410             :     }
     411             : 
     412         182 :     if(verbose_)cout << "ici 4 dataOID="<<mainRowPtr->getDataUID().getEntityId().toString()<<endl;
     413             : 
     414         182 :     int iostat = 0;
     415         182 :     if (bdfMemoryMapped) {
     416           0 :       iostat = attachDataObject(mainRowPtr->getDataUID().getEntityId().toString());
     417             :     }
     418             :     else {  
     419         182 :       iostat = attachStreamDataObject(mainRowPtr->getDataUID().getEntityId().toString());
     420             :     }
     421         182 :     if(iostat==0){
     422         182 :       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         182 :     if (verbose_) cout << "SDMBinData::acceptMainRow( MainRow* const mainRowPtr) : exiting." << endl;
     434         182 :     return true;
     435         202 :   }
     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         571 :   int SDMBinData::openStreamDataObject(const string& dataOID) {
     984         571 :     if (verbose_) cout << "SDMBinData::openStreamDataObject : entering" << endl;
     985             :     
     986         571 :     sdmdosr.close();
     987             : 
     988         571 :     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         571 :     string filename=dataOID;
     992             :     string::size_type np;
     993         571 :     np=filename.find("/",0);
     994        3471 :     while(np!=string::npos){ np=filename.find("/",np); if(np!=string::npos){ filename.replace(np,1,"_"); np++; } }
     995         571 :     np=filename.find(":",0);
     996        1713 :     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         571 :     ostringstream dir; dir<<execBlockDir_<<"/ASDMBinary";
    1001         571 :     dirp = opendir(dir.str().c_str());
    1002         571 :     if(!dirp)
    1003           0 :       Error(FATAL,(char *) "Could not open directory %s",dir.str().c_str());
    1004         571 :     closedir(dirp);
    1005         571 :     filename=dir.str()+"/"+filename;
    1006         571 :     if(verbose_)cout<<"filename="<<filename<<endl;
    1007             : 
    1008             :     
    1009         571 :     sdmdosr.open(filename);
    1010         571 :     dataOID_ = dataOID;
    1011         571 :     if(verbose_){
    1012           0 :       cout<<"============================"<<endl;
    1013           0 :       cout<< sdmdosr.toString()<<endl;
    1014           0 :       cout<<"============================"<<endl;
    1015             :     }
    1016         571 :     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         571 :   }
    1156             : 
    1157         182 :   int SDMBinData::attachStreamDataObject(const string& dataOID ){
    1158             :     
    1159         182 :     if(verbose_)cout<<"SDMBinData::attachStreamDataObject(const string& dataOID ): entering"<<endl;
    1160             :     
    1161         182 :     sdmdosr.close();
    1162             : 
    1163         182 :     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         182 :     string filename=dataOID;
    1167             :     string::size_type np;
    1168         182 :     np=filename.find("/",0);
    1169        1092 :     while(np!=string::npos){ np=filename.find("/",np); if(np!=string::npos){ filename.replace(np,1,"_"); np++; } }
    1170         182 :     np=filename.find(":",0);
    1171         546 :     while(np!=string::npos){ np=filename.find(":",np); if(np!=string::npos){ filename.replace(np,1,"_"); np++; } }
    1172         182 :     if(verbose_)cout<<"filename="<<filename<<" execBlockDir_="<<execBlockDir_<<endl;
    1173             :     static DIR* dirp;
    1174             : //     ostringstream dir; dir<<execBlockDir_<<"/SDMBinaries";
    1175         182 :     ostringstream dir; dir<<execBlockDir_<<"/ASDMBinary";
    1176         182 :     dirp = opendir(dir.str().c_str());
    1177         182 :     if(!dirp)
    1178           0 :       Error(FATAL,(char *) "Could not open directory %s",dir.str().c_str());
    1179         182 :     closedir(dirp);
    1180         182 :     filename=dir.str()+"/"+filename;
    1181         182 :     if(verbose_)cout<<"filename="<<filename<<endl;
    1182             : 
    1183             :     try {
    1184         182 :       sdmdosr.open(filename);
    1185         182 :       dataOID_ = dataOID;
    1186         182 :       if(verbose_){
    1187           0 :         cout<<"============================"<<endl;
    1188           0 :         cout<< sdmdosr.toString()<<endl;
    1189           0 :         cout<<"============================"<<endl;
    1190             :       }
    1191             : 
    1192         182 :       Enum<CorrelationMode>            e_cm;
    1193         182 :       Enum<ProcessorType>              e_pt;
    1194         182 :       Enum<CorrelatorType>             e_ct;
    1195             : 
    1196         182 :       unsigned int                     numTime=0;
    1197             : 
    1198         182 :       unsigned int                     numAnt              = sdmdosr.numAntenna();
    1199         182 :       CorrelationMode                  correlationMode     = sdmdosr.correlationMode(); e_cm=correlationMode;
    1200         182 :       ProcessorType                    processorType       = sdmdosr.processorType();   e_pt=processorType;
    1201             :       CorrelatorType                   correlatorType;
    1202             : 
    1203         182 :       const SDMDataObject::DataStruct& dataStruct          = sdmdosr.dataStruct();
    1204             : 
    1205         182 :       vector<AtmPhaseCorrection>       v_apc               = dataStruct.apc();
    1206         182 :       vector<SDMDataObject::Baseband>  v_baseband          = dataStruct.basebands();
    1207         182 :       SDMDataObject::ZeroLagsBinaryPart               zeroLagsParameters;
    1208             : 
    1209             : //      bool                             normalized=false;
    1210         182 :       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         182 :       unsigned int                     numApc              = v_apc.size();
    1222         182 :       unsigned int                     numBaseband         = v_baseband.size();
    1223             : 
    1224         182 :       vector< vector< unsigned int > > vv_numAutoPolProduct;
    1225         182 :       vector< vector< unsigned int > > vv_numCrossPolProduct;
    1226         182 :       vector< vector< unsigned int > > vv_numSpectralPoint;
    1227         182 :       vector< vector< unsigned int > > vv_numBin;
    1228         182 :       vector< vector< float > >        vv_scaleFactor;
    1229         182 :       vector< unsigned int >           v_numSpectralWindow;
    1230         182 :       vector< vector< Enum<NetSideband> > > vv_e_sideband;
    1231         182 :       vector< vector< SDMDataObject::SpectralWindow* > > vv_image;
    1232             : 
    1233         182 :       if(verbose_)cout<<"e_cm="<<e_cm.str()<<endl;
    1234             : 
    1235         364 :       for(unsigned int nbb=0; nbb<v_baseband.size(); nbb++){
    1236         182 :         vector<SDMDataObject::SpectralWindow>  v_spw = v_baseband[nbb].spectralWindows(); v_numSpectralWindow.push_back(v_spw.size());
    1237         182 :         vector<SDMDataObject::SpectralWindow*> v_image;
    1238         182 :         vector< unsigned int > v_numBin;
    1239         182 :         vector< unsigned int > v_numSpectralPoint;
    1240         182 :         vector< unsigned int > v_numSdPolProduct;
    1241         182 :         vector< unsigned int > v_numCrPolProduct;
    1242         182 :         vector< Enum<NetSideband> >  v_e_sideband;
    1243         182 :         vector<float>          v_scaleFactor;
    1244         364 :         for(unsigned int nspw=0; nspw<v_spw.size(); nspw++){
    1245         182 :           v_e_sideband.push_back(Enum<NetSideband>(v_spw[nspw].sideband()));
    1246         182 :           v_image.push_back(NULL);                                   // TODO waiting for implementation
    1247         182 :           v_numBin.push_back(v_spw[nspw].numBin());
    1248         182 :           if(verbose_)cout<<"v_spw["<<nspw<<"].numSpectralPoint()="<<v_spw[nspw].numSpectralPoint()<<endl;
    1249         182 :           v_numSpectralPoint.push_back(v_spw[nspw].numSpectralPoint());
    1250         182 :           if(e_cm[AUTO_ONLY])
    1251         182 :             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         182 :         if(e_cm[CROSS_ONLY]==false)vv_numAutoPolProduct.push_back(v_numSdPolProduct);
    1260         182 :         if(e_cm[AUTO_ONLY]==false) vv_numCrossPolProduct.push_back(v_numCrPolProduct);
    1261         182 :         vv_numSpectralPoint.push_back(v_numSpectralPoint);
    1262         182 :         vv_e_sideband.push_back(v_e_sideband);
    1263         182 :         vv_image.push_back(v_image);
    1264         182 :         vv_numBin.push_back(v_numBin);
    1265         182 :         vv_scaleFactor.push_back(v_scaleFactor);
    1266         182 :       }
    1267         182 :       if(e_cm[AUTO_ONLY])vv_numCrossPolProduct.clear();
    1268         182 :       if(e_cm[CROSS_ONLY])vv_numAutoPolProduct.clear();
    1269             : 
    1270         182 :       complexData_=false;
    1271         182 :       if(vv_numAutoPolProduct.size()){
    1272         364 :         for(unsigned int nbb=0; nbb<vv_numAutoPolProduct.size(); nbb++){
    1273         364 :           for(unsigned int nspw=0; nspw<vv_numAutoPolProduct[nbb].size(); nspw++)
    1274         182 :             if(vv_numAutoPolProduct[nbb][nspw]>2)complexData_=true;
    1275             :         }
    1276             :       }
    1277         182 :       if(vv_numCrossPolProduct.size())complexData_=true;
    1278             : 
    1279         182 :       EnumSet<AxisName>         es_axisNames;
    1280             :       DataContent               dataContent;
    1281         182 :       SDMDataObject::BinaryPart binaryPart;
    1282         182 :       map<DataContent,pair<unsigned int,EnumSet<AxisName> > > m_dc_sizeAndAxes;
    1283             : 
    1284         182 :       dataContent = FLAGS;
    1285         182 :       binaryPart  = dataStruct.flags();
    1286         182 :       es_axisNames.set(binaryPart.axes(),true);
    1287         182 :       if(es_axisNames.count())m_dc_sizeAndAxes.insert(make_pair(dataContent,make_pair(binaryPart.size(),es_axisNames)));
    1288             : 
    1289         182 :       dataContent = ACTUAL_DURATIONS;
    1290         182 :       binaryPart  = dataStruct.actualDurations();
    1291         182 :       es_axisNames.set(binaryPart.axes(),true);
    1292         182 :       if(es_axisNames.count())m_dc_sizeAndAxes.insert(make_pair(dataContent,make_pair(binaryPart.size(),es_axisNames)));
    1293             : 
    1294         182 :       dataContent = ACTUAL_TIMES;
    1295         182 :       binaryPart  = dataStruct.actualTimes();
    1296         182 :       es_axisNames.set(binaryPart.axes(),true);
    1297         182 :       if(es_axisNames.count())m_dc_sizeAndAxes.insert(make_pair(dataContent,make_pair(binaryPart.size(),es_axisNames)));
    1298             : 
    1299         182 :       dataContent = AUTO_DATA;
    1300         182 :       binaryPart  = dataStruct.autoData();
    1301         182 :       es_axisNames.set(binaryPart.axes(),true);
    1302         182 :       if(es_axisNames.count())m_dc_sizeAndAxes.insert(make_pair(dataContent,make_pair(binaryPart.size(),es_axisNames)));
    1303             : 
    1304         182 :       if(es_axisNames[TIM])numTime=sdmdosr.numTime();
    1305             : 
    1306         182 :       dataContent = CROSS_DATA;
    1307         182 :       binaryPart  = dataStruct.crossData();
    1308         182 :       es_axisNames.set(binaryPart.axes(),true);
    1309         182 :       if(es_axisNames.count())m_dc_sizeAndAxes.insert(make_pair(dataContent,make_pair(binaryPart.size(),es_axisNames)));
    1310             : 
    1311         182 :       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         182 :       if(es_axisNames[TIM])numTime=sdmdosr.numTime();
    1319             : 
    1320             :       map<DataContent,pair<unsigned int,EnumSet<AxisName> > >::iterator
    1321         182 :         itf=m_dc_sizeAndAxes.find(AUTO_DATA),
    1322         182 :         ite=m_dc_sizeAndAxes.end();
    1323         182 :       if(itf==ite)itf=m_dc_sizeAndAxes.find(CROSS_DATA);
    1324         182 :       if(itf==ite)Error(FATAL,(char *) "BLOB %s has no declaration for observational data",dataOID.c_str());
    1325             : 
    1326             : 
    1327         182 :       if(coutDeleteInfo_)cout<<"delete  v_dataDump_"<<endl;
    1328        3816 :       for(unsigned int n=0; n<v_dataDump_.size(); n++)delete v_dataDump_[n];
    1329         182 :       v_dataDump_.clear();
    1330             : 
    1331         182 :       if(verbose_)cout<<"numTime="<<numTime<<endl;
    1332             : 
    1333         182 :       if(numTime){  // MIME content with a structure of dimensionality 0
    1334             : 
    1335         182 :         const SDMDataSubset&     dataSubset         = sdmdosr.getSubset();
    1336         182 :         uint64_t                 obsDuration        = dataSubset.interval();
    1337             : 
    1338         182 :         int64_t                  interval           = (int64_t)obsDuration/(int64_t)numTime;
    1339             :         int64_t                  exposure;
    1340         182 :         int64_t                  timeOfDump         = (int64_t)dataSubset.time()-(int64_t)obsDuration/2LL-interval/2LL; // mutable
    1341         182 :         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         182 :         const unsigned int*      flagsPtr           = NULL;  unsigned int long numFlags=0; // mcaillat 
    1345         182 :         const int64_t*         actualTimesPtr     = NULL;  unsigned int long numActualTimes=0;
    1346         182 :         const int64_t*         actualDurationsPtr = NULL;  unsigned int long numActualDurations=0;
    1347         182 :         const float*             zeroLagsPtr        = NULL;  unsigned int long numZeroLags=0;
    1348         182 :         const float*             autoDataPtr        = NULL;  unsigned int long numAutoData=0;
    1349         182 :         const short int*         crossShortDataPtr  = NULL;  unsigned int long numCrossData=0;
    1350         182 :         const int*               crossIntDataPtr    = NULL;
    1351         182 :         const float*             crossFloatDataPtr  = NULL;
    1352             : 
    1353             : 
    1354             :         // size (in nb pdt value per dump) and list of axes using the dataStruct declarations:
    1355         182 :         unsigned int flagsSize=0;           EnumSet<AxisName> es_flagsAxes;
    1356         182 :         unsigned int actualTimesSize=0;     EnumSet<AxisName> es_actualTimesAxes;
    1357         182 :         unsigned int actualDurationsSize=0; EnumSet<AxisName> es_actualDurationsAxes;
    1358         182 :         unsigned int zeroLagsSize=0;        EnumSet<AxisName> es_zeroLagsAxes;
    1359         182 :         unsigned int autoDataSize=0;        EnumSet<AxisName> es_autoDataAxes;
    1360         182 :         unsigned int crossDataSize=0;       EnumSet<AxisName> es_crossDataAxes;
    1361             : 
    1362         182 :         if((itf=m_dc_sizeAndAxes.find(FLAGS))!=ite){
    1363         112 :           if(verbose_)cout<<"Flags have been declared in the main header"<<endl;
    1364         112 :           flagsSize    = itf->second.first;
    1365         112 :           es_flagsAxes = itf->second.second;
    1366         112 :           numFlags     = dataSubset.flags( flagsPtr );
    1367         112 :           if(numFlags!=flagsSize)
    1368           0 :             Error(FATAL, (char *) "Size of flags, %d, not compatible with the declared size of %d",
    1369             :                   numFlags,flagsSize);
    1370         112 :           flagsSize   /= numTime;
    1371             :         }
    1372             : 
    1373         182 :         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         182 :         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         182 :         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         182 :         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         182 :         if((itf=m_dc_sizeAndAxes.find(AUTO_DATA))!=ite){
    1433         182 :           if(verbose_)cout<<"AutoData have been declared in the main header"<<endl;
    1434         182 :           autoDataSize    = itf->second.first;
    1435         182 :           es_autoDataAxes = itf->second.second;
    1436         182 :           numAutoData     = dataSubset.autoData( autoDataPtr );
    1437         182 :           if(numAutoData){
    1438         182 :             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         182 :           autoDataSize /= numTime;
    1447             :         }
    1448             : 
    1449        4273 :         for(unsigned int nt=0; nt<numTime; nt++){
    1450             : 
    1451        4091 :           timeOfDump   += interval;
    1452        4091 :           timeCentroid =  timeOfDump;   // TODO
    1453        4091 :           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        4091 :                                                );
    1470        4091 :           if(e_cm[CROSS_ONLY]    )dataDumpPtr->setScaleFactor(vv_scaleFactor);
    1471        4091 :           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        4091 :           if(flagsPtr)           dataDumpPtr->attachFlags(           flagsSize, es_flagsAxes,
    1477        1067 :                                                                      numFlags,  flagsPtr + nt*flagsSize);
    1478             : 
    1479        4091 :           if(actualTimesPtr)     dataDumpPtr->attachActualTimes(     actualTimesSize, es_actualTimesAxes,
    1480           0 :                                                                      numActualTimes,  actualTimesPtr + nt*actualTimesSize);
    1481             : 
    1482        4091 :           if(actualDurationsPtr) dataDumpPtr->attachActualDurations( actualDurationsSize, es_actualDurationsAxes,
    1483           0 :                                                                      numActualDurations, actualDurationsPtr + nt*actualDurationsSize);
    1484             : 
    1485        4091 :           if(zeroLagsPtr)        dataDumpPtr->attachZeroLags(        zeroLagsSize, es_zeroLagsAxes,
    1486           0 :                                                                      numZeroLags, zeroLagsPtr + nt*zeroLagsSize);
    1487             : 
    1488        4091 :           if(crossShortDataPtr)  dataDumpPtr->attachCrossData(       crossDataSize, es_crossDataAxes,
    1489           0 :                                                                      numCrossData, crossShortDataPtr + nt*crossDataSize);
    1490             : 
    1491        4091 :           if(crossIntDataPtr)    dataDumpPtr->attachCrossData(       crossDataSize, es_crossDataAxes,
    1492           0 :                                                                      numCrossData, crossIntDataPtr + nt*crossDataSize);
    1493             : 
    1494        4091 :           if(crossFloatDataPtr)  dataDumpPtr->attachCrossData(       crossDataSize, es_crossDataAxes,
    1495           0 :                                                                      numCrossData, crossFloatDataPtr + nt*crossDataSize);
    1496             : 
    1497        4091 :           if(autoDataPtr)        dataDumpPtr->attachAutoData(        autoDataSize, es_autoDataAxes,
    1498        4091 :                                                                      numAutoData, autoDataPtr + nt*autoDataSize);
    1499             : 
    1500             : 
    1501        4091 :           dataDumpPtr->setContextUsingProjectPath(dataSubset.projectPath());
    1502             : 
    1503        4091 :           if(verbose_)cout<<"store dataDump"<<endl;
    1504        4091 :           v_dataDump_.push_back(dataDumpPtr);
    1505        4091 :           if(verbose_)cout<<"v_dataDumpPtr_.size()="<< v_dataDump_.size()<<endl;
    1506             :         }
    1507         182 :         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         182 :       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         182 :       return 0;
    1688         182 :     }
    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         182 : }
    1698             : 
    1699         364 :   void SDMBinData::detachDataObject(){
    1700             : //     if(dataOID_.length())cout<<"detachDataObject() using done()"<<endl;
    1701         364 :     bool coutest = false;
    1702         364 :     if (coutest) cout << "SDMBinData::detachDataObject: entering" << endl;
    1703         364 :     if (bdfMemoryMapped) {
    1704           0 :       if(dataOID_.length())blob_r_.done();
    1705           0 :       dataOID_="";
    1706             :     }
    1707             :     else 
    1708         364 :       sdmdosr.close();
    1709         364 :     if (coutest) cout << "SDMBinData::detachDataObject: exiting" << endl;
    1710         364 :     return;
    1711             :   }
    1712             : 
    1713           0 :   vector<SDMData*> SDMBinData::getData(){
    1714             : 
    1715           0 :     detachDataObject();
    1716           0 :     return  v_sdmDataPtr_;
    1717             : 
    1718             :   }
    1719             : 
    1720         182 :   vector<MSData*>  SDMBinData::getData( Enum<CorrelationMode> e_qcm, EnumSet<AtmPhaseCorrection> es_qapc){
    1721             :     
    1722         182 :     if (verbose_) cout << "SDMBinData::getData( Enum<CorrelationMode> e_qcm, EnumSet<AtmPhaseCorrection> es_qapc): entering" << endl;
    1723         182 :     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         182 :     MSData* msDataPtr_ = 0;
    1730             : 
    1731         182 :     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         182 :     ConfigDescriptionRow*       cdPtr = mainRowPtr_->getConfigDescriptionUsingConfigDescriptionId();
    1740         182 :     vector<AtmPhaseCorrection>  v_apc = cdPtr->getAtmPhaseCorrection();
    1741         182 :     Enum<CorrelationMode>       e_cm; e_cm = cdPtr->getCorrelationMode();
    1742             : 
    1743         182 :     EnumSet<AtmPhaseCorrection> es_qapc_uncorrected, es_qapc_old;
    1744             : ;
    1745         182 :     es_qapc_uncorrected.fromString("AP_UNCORRECTED");
    1746         182 :     if (processorType(mainRowPtr_) == RADIOMETER) {
    1747         182 :       es_qapc_old = es_qapc_;
    1748         182 :       es_qapc_ = es_qapc_uncorrected;
    1749             :     }
    1750             :     
    1751         182 :     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         182 :     if(canSelect_){
    1759             : 
    1760             :       // set the new defaults
    1761           0 :       e_qcm_   = e_qcm;
    1762           0 :       es_qapc_ = es_qapc;
    1763             : 
    1764             :     }
    1765             : 
    1766         182 :     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         182 :     if(e_qcm_[CROSS_ONLY]) if(e_cm[AUTO_ONLY])  return v_msDataPtr_;
    1775         182 :     if(e_qcm_[AUTO_ONLY])  if(e_cm[CROSS_ONLY]) return v_msDataPtr_;
    1776             : 
    1777             : 
    1778         182 :     vector<unsigned int>       v_selected_napc;
    1779         182 :     vector<AtmPhaseCorrection> v_selected_apc;
    1780         364 :     for(unsigned int n=0; n<v_apc.size(); n++){
    1781         182 :       if(es_qapc_[v_apc[n]]){
    1782         182 :         v_selected_napc.push_back(n);
    1783         182 :         v_selected_apc.push_back(v_apc[n]);
    1784             :       }
    1785             :     }
    1786         182 :     if(!v_selected_napc.size())return v_msDataPtr_;
    1787             : 
    1788         182 :     Tag configDescriptionId = mainRowPtr_->getConfigDescriptionId();
    1789             : 
    1790             : 
    1791             :     std::set<Tag>::iterator
    1792         182 :       itsf=s_cdId_.find(configDescriptionId),
    1793         182 :       itse=s_cdId_.end();
    1794         182 :     if(itsf==itse)
    1795           0 :       Error(FATAL,"Tree hierarchy not present for configDescId " + configDescriptionId.toString());
    1796             :     std::map<Tag,BaselinesSet*>::iterator
    1797         182 :       itf(m_cdId_baselinesSet_.find(configDescriptionId)),
    1798         182 :       ite(m_cdId_baselinesSet_.end());
    1799         182 :     if(itf==ite)
    1800           0 :       Error(FATAL,"Tree hierarchy not present for configDescId " + configDescriptionId.toString());
    1801         182 :     baselinesSet_=itf->second;
    1802             : 
    1803         182 :     if(verbose_)cout<<configDescriptionId.toString()<<endl;
    1804             : 
    1805             : 
    1806             : 
    1807             :     unsigned int               stateId;
    1808         182 :     vector<StateRow*>          v_statePtr = mainRowPtr_->getStatesUsingStateId();
    1809             : 
    1810         182 :     vector<int>                v_feedSet  = cdPtr->getFeedId();
    1811         182 :     vector<Tag>                v_antSet   = cdPtr->getAntennaId();
    1812         182 :     vector<Tag>                v_ddList   = cdPtr->getDataDescriptionId();
    1813             : 
    1814             : 
    1815         182 :     unsigned int               numFeed    = v_feedSet.size()/v_antSet.size();
    1816             :     unsigned int               numBin;
    1817             :     unsigned int               numPol;
    1818         182 :     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         182 :     ArrayTime                  timeOfDump;
    1825         182 :     ArrayTime                  timeCentroidOfDump;
    1826             : 
    1827         182 :     int                        fieldId    = mainRowPtr_->getFieldUsingFieldId()->getFieldId().getTagValue();
    1828         182 :     vector<vector<Angle> >     phaseDir   = mainRowPtr_->getFieldUsingFieldId()->getPhaseDir();
    1829             : 
    1830             : 
    1831         182 :     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         182 :     if(verbose_)cout <<"ici AA: e_qcm_="<<e_qcm_.str()<<endl;
    1839             : 
    1840        2578 :     for(unsigned int na=0; na<v_antSet.size(); na++)
    1841        2396 :       v_stateId.push_back(v_statePtr[na]->getStateId());
    1842             : 
    1843         182 :     vector<vector<float> >                      vv_t; // dummy empty vector would there be no tsysSpectrum for a given syscal row
    1844         182 :     SysCalTable&                                sct = datasetPtr_->getSysCal();
    1845         182 :     vector<Tag>                                 v_spwid;
    1846         182 :     vector<pair<bool,vector<vector<float> > > > v_tsys;
    1847         182 :     vector<vector<pair<bool,vector<vector<float> > > > > vv_tsys;
    1848             : 
    1849             : 
    1850         182 :     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         182 :     if(e_cm[CROSS_ONLY]==false && e_qcm_[CROSS_ONLY]==false ){       // retrieve only AUTO_DATA
    1887        4273 :       for(unsigned int nt=0; nt<v_dataDump_.size(); nt++){
    1888        4091 :         timeOfDump        = ArrayTime((int64_t)v_dataDump_[nt]->time());               if(verbose_)cout<<timeOfDump<<" ns"<<endl;
    1889        4091 :         timeCentroidOfDump= ArrayTime((int64_t)v_dataDump_[nt]->timeCentroid());       if(verbose_)cout<<timeCentroidOfDump.toString()<<" ns"<<endl;
    1890        4091 :         timeMJD           = timeOfDump.getMJD();                              if(verbose_)cout<<timeMJD<<" h = "<<86400.*timeMJD<<" s"<<endl;
    1891        4091 :         interval          = (double)v_dataDump_[nt]->interval()/1000000000LL; if(verbose_)cout<<interval<<" s"<<endl;
    1892        4091 :         timeCentroidMJD   = timeCentroidOfDump.getMJD();                      if(verbose_)cout<< timeCentroidMJD<<endl;
    1893        4091 :         exposure          = (double)v_dataDump_[nt]->exposure()/1000000000LL;
    1894        4091 :         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        4091 :         if(verbose_)cout <<"ici BB"<<endl;
    1915             : 
    1916        4091 :         vector<AtmPhaseCorrection> v_uapc; v_uapc.push_back(AP_UNCORRECTED);
    1917             : 
    1918        4091 :         unsigned int scn=0;
    1919       42187 :         for(unsigned int na=0; na<v_antSet.size(); na++){
    1920       38096 :           stateId = v_statePtr[na]->getStateId().getTagValue();
    1921       76192 :           for(unsigned int nfe=0; nfe<numFeed; nfe++){
    1922       76192 :             for(unsigned int ndd=0; ndd<v_ddList.size(); ndd++){
    1923       38096 :               numBin = baselinesSet_->numBin(ndd);
    1924       38096 :               numPol = baselinesSet_->numPol(baselinesSet_->getBasebandIndex(ndd));
    1925       38096 :               if(numPol==4)numPol=3;                                 // if XX,XY,YX,YY then auto XX,XY,YY 
    1926       38096 :               if(verbose_)cout<<"numPol="<<numPol
    1927           0 :                              <<"  na="  <<na
    1928           0 :                              <<" ant="  <<v_antSet[na].getTagValue()
    1929           0 :                              <<endl;
    1930       38096 :               v_dataShape[0]=numPol;
    1931             :               //              if(complexData_)v_dataShape[0]*=2;
    1932       38096 :               v_dataShape[1]=baselinesSet_->numChan(ndd);
    1933       38096 :               v_dataShape[2]=1;                                      // auto-correlation never atm phase corrected
    1934       76192 :               for(unsigned int nbi=0; nbi<numBin; nbi++){
    1935             :                 // the data and binary meta-data
    1936       38096 :                 if(SDMBinData::syscal_)
    1937           0 :                   msDataPtr_ = getCalibratedData( na, nfe,
    1938             :                                                   ndd, nbi, 
    1939           0 :                                                   vv_tsys[nt][scn]);
    1940             :                 else
    1941       38096 :                   msDataPtr_ = getData( na, nfe,
    1942             :                                         ndd, nbi);
    1943       38096 :                 scn++;
    1944       38096 :                 msDataPtr_->timeCentroid   = 86400.*timeCentroidMJD; // default value would there be no bin actualTimes
    1945       38096 :                 msDataPtr_->exposure       = exposure;               // default value would there be no bin actualDurations
    1946       38096 :                 msDataPtr_->flag           = 0;                      // default value is "false"  would there be no bin flags
    1947             :                 // calibrate and associate SDM meta-data
    1948       38096 :                 if(msDataPtr_->numData>0){
    1949       38096 :                   msDataPtr_->processorId        = cdPtr->getProcessorId().getTagValue();
    1950       38096 :                   msDataPtr_->antennaId1         = v_antSet[na].getTagValue();
    1951       38096 :                   msDataPtr_->antennaId2         = v_antSet[na].getTagValue();
    1952       38096 :                   msDataPtr_->feedId1            = v_feedSet[na*numFeed+nfe];
    1953       38096 :                   msDataPtr_->feedId2            = v_feedSet[na*numFeed+nfe];
    1954       38096 :                   if(e_cm[CROSS_AND_AUTO])
    1955           0 :                     msDataPtr_->dataDescId       = baselinesSet_->getAutoDataDescriptionId(v_ddList[ndd]).getTagValue();
    1956             :                   else
    1957       38096 :                     msDataPtr_->dataDescId       = v_ddList[ndd].getTagValue();
    1958       38096 :                   msDataPtr_->phaseDir           = phaseDir;                     // TODO Apply the polynomial formula
    1959       38096 :                   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       38096 :                   msDataPtr_->v_dataShape        = v_dataShape;
    1966       38096 :                   msDataPtr_->time               = 86400.*timeMJD;
    1967       38096 :                   msDataPtr_->interval           = interval;
    1968       38096 :                   msDataPtr_->v_atmPhaseCorrection = v_uapc;         // It is assumed that this is always the uncorrected case
    1969       38096 :                   msDataPtr_->binNum             = nbi+1;
    1970       38096 :                   msDataPtr_->fieldId            = fieldId;
    1971       38096 :                   vector<unsigned int> v_projectNodes;
    1972       38096 :                   if(v_dataDump_[nt]->integrationNum())v_projectNodes.push_back(v_dataDump_[nt]->integrationNum());
    1973       38096 :                   if(v_dataDump_[nt]->subintegrationNum())v_projectNodes.push_back(v_dataDump_[nt]->subintegrationNum());
    1974       38096 :                   msDataPtr_->projectPath        = v_projectNodes;
    1975             :                   // this pointer ends up in v_msDataPtr_ and is deleted from there
    1976       38096 :                   v_msDataPtr_.push_back(msDataPtr_);                      // store in vector for export
    1977       38096 :                 }
    1978       38096 :                 if(verbose_)cout << "B/ msDataPtr_->numData=" <<msDataPtr_->numData << endl;
    1979             :               }
    1980             :             }
    1981             :           }
    1982             :         }
    1983        4091 :       }
    1984             :     }
    1985             : 
    1986         182 :     if(verbose_)cout <<"ici CC: "<<e_qcm_.str()<<endl;
    1987         182 :     vector<AtmPhaseCorrection> v_atmPhaseCorrection = cdPtr->getAtmPhaseCorrection();
    1988         182 :     bool queryCrossData = false;
    1989         182 :     if(e_qcm_[CROSS_ONLY])     queryCrossData=true;
    1990         182 :     if(e_qcm_[CROSS_AND_AUTO]) queryCrossData=true;
    1991             : 
    1992         182 :     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         182 :     detachDataObject();
    2114         182 :     if (processorType(mainRowPtr_) == RADIOMETER) {
    2115         182 :       es_qapc_ = es_qapc_old;
    2116             :     }
    2117             : 
    2118         182 :     if (verbose_) cout << "SDMBinData::getData( Enum<CorrelationMode> e_qcm, EnumSet<AtmPhaseCorrection> es_qapc): exiting" << endl;
    2119         182 :     return v_msDataPtr_;
    2120         182 :   }
    2121             : 
    2122      447664 :   MSData* SDMBinData::getData( unsigned int na, unsigned int nfe,
    2123             :                                unsigned int ndd, unsigned int nbin)
    2124             :   {
    2125      447664 :     if (verbose_) cout << "SDMBinData::getData : entering" << endl;
    2126      447664 :     unsigned int numBin = baselinesSet_->numBin(ndd);                  if(verbose_)cout << "numBin=" << numBin << endl;
    2127      447664 :     if((nbin+1)>numBin)return 0;
    2128             : 
    2129             : 
    2130      447664 :     msDataPtr_ = new MSData;
    2131             : 
    2132             : 
    2133      447664 :     msDataPtr_->numData =  baselinesSet_->numAutoData(ndd)/numBin;  // number of measurements (NOT nb values)
    2134      447664 :     msDataPtr_->v_data.resize(1);                                   // autoData have always an APC axis of 1
    2135             : 
    2136             :     
    2137      447664 :     if(verbose_)cout << "About to retrieve " <<  msDataPtr_->numData
    2138           0 :                     << " auto-correlation measurements (auto correlations) encoded in floats" << endl;
    2139      447664 :     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      447664 :     const float* autoData =  &floatDataDumpPtr_[baselinesSet_->transferId(na,ndd,nbin)];
    2143      447664 :     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      447664 :     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      447664 :     if(verbose_)cout << "numData=" << msDataPtr_->numData << endl;
    2166      447664 :     if(verbose_)cout << "numSdPol("<<ndd<<")="<<baselinesSet_->numSdPol(ndd)<<endl;
    2167      447664 :     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      447664 :     }else if(forceComplex_){                  // original was 100% real data, transform shape in complex to have shape of visibilities
    2190      352936 :       msDataPtr_->v_data[0] = new float[2*msDataPtr_->numData];
    2191    50852672 :       for(int n=0; n<msDataPtr_->numData; n++){
    2192    50499736 :         msDataPtr_->v_data[0][2*n]   = autoData[n];
    2193    50499736 :         msDataPtr_->v_data[0][2*n+1] = 0.0;
    2194             :       }
    2195      352936 :       if(verbose_)cout << "1st auto: r " << msDataPtr_->v_data[0][0] << " i " << msDataPtr_->v_data[0][1] << endl;
    2196             :     }else{
    2197       94728 :       msDataPtr_->v_data[0] = new float[msDataPtr_->numData];
    2198   113902440 :       for(int n=0; n<msDataPtr_->numData; n++)msDataPtr_->v_data[0][n]=autoData[n];
    2199       94728 :       if(verbose_)cout << "1st auto: " <<(int) msDataPtr_->v_data[0][0] << " (a real value)" << endl;
    2200             :     }
    2201             : 
    2202      447664 :     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      447664 :     if (verbose_) cout << "SDMBinData::getData : exiting for SD" << endl;
    2222      447664 :     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    11550156 :   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    11550156 :     unsigned int nfe=nfe1;                                  // TODO multi-beam
    2348             : 
    2349    11550156 :     unsigned int numBin = baselinesSet_->numBin(ndd);                            
    2350    11550156 :     if((nbin+1)>numBin)return 0;
    2351             : 
    2352    11550156 :     unsigned int numApc = baselinesSet_->numApc();                               
    2353    23100312 :     for(unsigned int i=0; i<v_napc.size(); i++){
    2354    11550156 :       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    11550156 :     msDataPtr_ = new MSData;
    2361             : 
    2362    11550156 :     msDataPtr_->numData = baselinesSet_->numCrossData(ndd)/(numBin*numApc);  
    2363             : 
    2364    11550156 :     msDataPtr_->v_data.resize(v_napc.size());
    2365             : 
    2366             :     // the data (visibilities)
    2367             : 
    2368    23100312 :     for(unsigned int n=0; n<v_napc.size(); n++)
    2369    11550156 :       msDataPtr_->v_data[n] = new float[2*msDataPtr_->numData];               // a complex is composed of 2 floats
    2370             :     //float oneOverSF = 1./scaleFactor;
    2371    11550156 :     int base = 0;
    2372             : 
    2373    11550156 :     if(shortDataPtr_){ // case short ints 2 bytes
    2374     7494408 :       for(unsigned int i=0; i<v_napc.size(); i++){
    2375     3747204 :         base = baselinesSet_->transferId(na1,na2,nfe,ndd,nbin,v_napc[i]);
    2376   361352748 :         for(int n=0; n<2*msDataPtr_->numData; n++)
    2377   357605544 :           msDataPtr_->v_data[i][n] = shortDataPtr_[base+n]/scaleFactor; //oneOverSF * (float)shortDataPtr_[base+n];
    2378             :       }
    2379             :     }
    2380             : 
    2381     7802952 :     else if (longDataPtr_){   // case ints 4 bytes
    2382     3654000 :       for(unsigned int i=0; i<v_napc.size(); i++){
    2383     1827000 :         base = baselinesSet_->transferId(na1,na2,nfe,ndd,nbin,v_napc[i]);
    2384   937251000 :         for(int n=0; n<2*msDataPtr_->numData; n++)
    2385   935424000 :           msDataPtr_->v_data[i][n] = longDataPtr_[base+n]/scaleFactor; //oneOverSF * (float)longDataPtr_[base+n];
    2386             :       }
    2387             :     }
    2388             :     else{       // case floats
    2389    11951904 :       for(unsigned int i=0; i<v_napc.size(); i++){
    2390     5975952 :         base = baselinesSet_->transferId(na1,na2,nfe,ndd,nbin,v_napc[i]);
    2391  3061274256 :         for(int n=0; n<2*msDataPtr_->numData; n++){
    2392  3055298304 :           msDataPtr_->v_data[i][n] = floatDataPtr_[base+n]/scaleFactor; //oneOverSF * floatDataPtr_[base+n];
    2393             :         }
    2394             :       }
    2395             :     }
    2396             :   
    2397    11550156 :     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         771 :   vector<pair<unsigned int,double> > SDMBinData::timeSequence()const{
    2508         771 :     return v_tci_;
    2509             :   }
    2510             : 
    2511         182 :   const VMSData* SDMBinData::getDataCols(Enum<CorrelationMode> e_qcm, EnumSet<AtmPhaseCorrection> es_qapc){
    2512             : 
    2513         182 :     if (verbose_) cout << "SDMBinData::getDataCols(Enum<CorrelationMode> e_qcm, EnumSet<AtmPhaseCorrection> es_qapc) : entering." << endl;
    2514             : 
    2515         182 :     if(v_msDataPtr_.size()>0){
    2516         174 :       if(coutDeleteInfo_)cout << "delete v_msDataPtr_[n]->xData" << endl;
    2517     2460718 :       for(vector<MSData*>::reverse_iterator it=v_msDataPtr_.rbegin(); it!=v_msDataPtr_.rend(); ++it)deleteMsData(*it);
    2518             :       
    2519         174 :       if(vmsDataPtr_){
    2520         174 :         if(coutDeleteInfo_)cout<<"about to delete vmsDataPtr_"<<endl;
    2521     2460718 :         for(unsigned int n=0; n<vmsDataPtr_->v_m_data.size(); n++)vmsDataPtr_->v_m_data[n].clear();
    2522         174 :         vmsDataPtr_->v_m_data.clear();    // a priori inutile
    2523         174 :         delete vmsDataPtr_;
    2524         174 :         vmsDataPtr_=NULL;
    2525             :       }
    2526             :     }
    2527             : 
    2528         182 :     v_msDataPtr_.clear();
    2529         182 :     v_msDataPtr_ = getData( e_qcm, es_qapc );
    2530             : 
    2531         182 :     int numRows=v_msDataPtr_.size();
    2532         182 :     if(verbose_)cout<<"Number of MS row for this SDM BLOB: " << numRows <<endl;
    2533             : 
    2534         182 :     if(coutDeleteInfo_&&vmsDataPtr_!=0)cout << "delete vmsDataPtr_" << endl;
    2535         182 :     if(vmsDataPtr_!=0)delete vmsDataPtr_;
    2536         182 :     vmsDataPtr_ = new VMSData;
    2537             : 
    2538             :     //VMSData* vmsDataPtr_ = new VMSData;
    2539         182 :     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         182 :     if(numRows){
    2545         182 :       vmsDataPtr_->processorId          = v_msDataPtr_[0]->processorId;
    2546         182 :       vmsDataPtr_->binNum               = v_msDataPtr_[0]->binNum;
    2547             :     }
    2548             : 
    2549         182 :     unsigned int numApcMax=0;
    2550       38278 :     for(int n=0; n<numRows; n++){
    2551       38096 :       if(v_msDataPtr_[n]->v_atmPhaseCorrection.size()>numApcMax)
    2552         182 :         numApcMax=v_msDataPtr_[n]->v_atmPhaseCorrection.size();
    2553             :     }
    2554         182 :     if(verbose_)cout<<"numApcMax="<<numApcMax<<endl;
    2555             : 
    2556         182 :     multimap<int,unsigned int> mm_dd;
    2557         182 :     if (ddfirst_) {
    2558         182 :       vector<int> ddId_v;
    2559         182 :       vector<int>::iterator ddId_i;
    2560         182 :       int ddIdOld = -1;
    2561         182 :       int ddIndex = -1;
    2562             :  
    2563       38278 :       for(unsigned int n=0; n<v_msDataPtr_.size(); n++) {
    2564       38096 :         if (v_msDataPtr_[n]->dataDescId != ddIdOld) {
    2565         182 :           ddIdOld = v_msDataPtr_[n]->dataDescId ;
    2566         182 :           ddId_i = find(ddId_v.begin(), ddId_v.end(),ddIdOld);
    2567         182 :           if (ddId_i == ddId_v.end()) {
    2568         182 :             ddId_v.push_back(ddIdOld);
    2569         182 :             ddIndex = ddId_v.size()-1;
    2570             :           }
    2571             :           else 
    2572           0 :             ddIndex = ddId_i - ddId_v.begin();
    2573             :         }
    2574       38096 :         mm_dd.insert(make_pair(ddIndex,n));       
    2575             :       }
    2576         182 :     }
    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         182 :     v_tci_.clear();  
    2587         182 :     v_tci_.resize(numRows);
    2588             : 
    2589         182 :     if(ddfirst_){   // the dataDescription/time/baseline expansion
    2590             : 
    2591         182 :       unsigned int n, i=0;
    2592         182 :       multimap<int,unsigned int>::const_iterator it;
    2593       38278 :       for(it=mm_dd.begin(); it!=mm_dd.end(); ++it){
    2594       38096 :         n=it->second;
    2595       38096 :         vmsDataPtr_->v_time.push_back(v_msDataPtr_[n]->time);
    2596       38096 :         vmsDataPtr_->v_fieldId.push_back(v_msDataPtr_[n]->fieldId);
    2597       38096 :         vmsDataPtr_->v_interval.push_back(v_msDataPtr_[0]->interval);
    2598       38096 :         vmsDataPtr_->v_antennaId1.push_back(v_msDataPtr_[n]->antennaId1);
    2599       38096 :         vmsDataPtr_->v_antennaId2.push_back(v_msDataPtr_[n]->antennaId2);
    2600       38096 :         vmsDataPtr_->v_feedId1.push_back(v_msDataPtr_[n]->feedId1);
    2601       38096 :         vmsDataPtr_->v_feedId2.push_back(v_msDataPtr_[n]->feedId2);
    2602       38096 :         vmsDataPtr_->v_dataDescId.push_back(v_msDataPtr_[n]->dataDescId);
    2603       38096 :         vmsDataPtr_->v_timeCentroid.push_back(v_msDataPtr_[n]->timeCentroid);
    2604       38096 :         vmsDataPtr_->v_exposure.push_back(v_msDataPtr_[n]->exposure);
    2605       38096 :         vmsDataPtr_->v_numData.push_back(v_msDataPtr_[n]->numData);
    2606       38096 :         vmsDataPtr_->vv_dataShape.push_back(v_msDataPtr_[n]->v_dataShape);
    2607       38096 :         vmsDataPtr_->v_phaseDir.push_back(v_msDataPtr_[n]->phaseDir);
    2608       38096 :         vmsDataPtr_->v_stateId.push_back(v_msDataPtr_[n]->stateId);
    2609       38096 :         vmsDataPtr_->v_msState.push_back(v_msDataPtr_[n]->msState);
    2610       38096 :         vmsDataPtr_->v_flag.push_back(v_msDataPtr_[n]->flag);
    2611             : 
    2612       38096 :         vmsDataPtr_->v_atmPhaseCorrection = v_msDataPtr_[n]->v_atmPhaseCorrection;
    2613       38096 :         map<AtmPhaseCorrection,float*> m_vdata;
    2614       76192 :         for(unsigned int napc=0; napc<vmsDataPtr_->v_atmPhaseCorrection.size(); napc++){
    2615       38096 :           float* d=v_msDataPtr_[n]->v_data[napc];
    2616       38096 :           m_vdata.insert(make_pair(vmsDataPtr_->v_atmPhaseCorrection[napc],d));
    2617             :         }
    2618       38096 :         vmsDataPtr_->v_m_data.push_back(m_vdata);
    2619             :         //cout<<"dataDescriptionId="<<it->first<<" row="<<it->second<<endl;
    2620             : 
    2621       38096 :         pair<unsigned int,double> p=make_pair(i++,v_msDataPtr_[n]->timeCentroid);
    2622       38096 :         v_tci_[n]=p;
    2623       38096 :       }
    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         182 :     detachDataObject();
    2662         182 :     if (verbose_) cout << "SDMBinData::getDataCols(Enum<CorrelationMode> e_qcm, EnumSet<AtmPhaseCorrection> es_qapc) : exiting." << endl;
    2663         182 :     return vmsDataPtr_;
    2664         182 :   }
    2665             : 
    2666             : 
    2667         182 :   const VMSData* SDMBinData::getDataCols(){
    2668         182 :     if (verbose_) cout << "SDMBinData::getDataCols() : entering." << endl; 
    2669         182 :     Enum<CorrelationMode>       e_qcm;
    2670         182 :     EnumSet<AtmPhaseCorrection> es_qapc;
    2671         182 :     if(canSelect_){
    2672             :       //cout<<"INFORM: context allow to select"<<endl;
    2673           0 :       e_qcm   = e_qcm_;
    2674           0 :       es_qapc = es_qapc_;
    2675             :     }
    2676         182 :     const VMSData* result = getDataCols( e_qcm, es_qapc );
    2677         182 :     if (verbose_) cout << "SDMBinData::getDataCols() : exiting." << endl; 
    2678         182 :     return result;
    2679             :   }
    2680             : 
    2681    11997820 :   void  SDMBinData::deleteMsData(MSData* msDataPtr){
    2682    11997820 :     if(msDataPtr){
    2683    23995640 :       for(unsigned int i=0; i<msDataPtr->v_data.size(); i++){
    2684    11997820 :         if(msDataPtr->v_data[i]){
    2685    11997820 :           delete[] msDataPtr->v_data[i];
    2686             :           //if(coutDeleteInfo_)cout << "data in MS data object deleted" << endl;
    2687    11997820 :           msDataPtr->v_data[i] = 0;
    2688             :         }
    2689             :       }
    2690             : 
    2691    11997820 :       delete msDataPtr;   //  if(coutDeleteInfo_)cout<<"MS data object deleted"<<endl;
    2692    11997820 :       msDataPtr=0;
    2693             :     }
    2694    11997820 :     return;
    2695             :   }
    2696             : 
    2697         589 :   const VMSData* SDMBinData::getNextMSMainCols(unsigned int nDataSubset) {
    2698         589 :     Enum<CorrelationMode>       e_qcm;
    2699         589 :     EnumSet<AtmPhaseCorrection> es_qapc;
    2700         589 :     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        1178 :     return getNextMSMainCols( e_qcm, es_qapc, nDataSubset);
    2706             :   }
    2707             : 
    2708         589 :   const VMSData* SDMBinData::getNextMSMainCols(Enum<CorrelationMode> e_qcm, EnumSet<AtmPhaseCorrection> es_qapc, unsigned int nDataSubset) {
    2709         589 :     if (verbose_) cout << "SDMBinData::getNextMSMainCols : entering" << endl;
    2710             : 
    2711             :     // Delete the content of v_msDataPtr if any
    2712         589 :     if ( v_msDataPtr_.size() > 0 ){
    2713         550 :       if(verbose_)cout << "delete v_msDataPtr_[n]->xData" << endl;
    2714     8624880 :       for(vector<MSData*>::reverse_iterator it=v_msDataPtr_.rbegin(); it!=v_msDataPtr_.rend(); ++it)deleteMsData(*it);
    2715             :       
    2716         550 :       if(vmsDataPtr_){
    2717         550 :         if(verbose_)cout<<"about to delete vmsDataPtr_"<<endl;
    2718     8624880 :         for(unsigned int n=0; n<vmsDataPtr_->v_m_data.size(); n++)
    2719     8624330 :           vmsDataPtr_->v_m_data[n].clear();
    2720         550 :         vmsDataPtr_->v_m_data.clear();    // a priori inutile
    2721         550 :         delete vmsDataPtr_;
    2722         550 :         vmsDataPtr_=NULL;
    2723             :       }
    2724             :     }
    2725             : 
    2726         589 :     v_msDataPtr_.clear(); // I doubt this is really useful ... (MC 08/12/2011)
    2727             :     
    2728             :     // No more data available... then return empty content.
    2729         589 :     if  (!sdmdosr.hasSubset()) {
    2730           0 :       return NULL;
    2731             :     }
    2732             : 
    2733         589 :     v_msDataPtr_ = getMSDataFromBDFData(e_qcm, es_qapc, nDataSubset);
    2734         589 :     int numRows = v_msDataPtr_.size();
    2735         589 :     if (verbose_) cout << "Number of MS Main rows for this block of " << nDataSubset << " [sub]integrations in '" << sdmdosr.dataOID() << "' = " << numRows << endl; 
    2736             : 
    2737         589 :     if(verbose_&&vmsDataPtr_!=0) cout << "delete vmsDataPtr_" << endl;
    2738         589 :     if(vmsDataPtr_!=0)delete vmsDataPtr_;
    2739         589 :     vmsDataPtr_ = new VMSData;
    2740             : 
    2741         589 :     if(!vmsDataPtr_)
    2742           0 :       Error(FATAL, string("Fail to allocate memory for a new VMSData type structure"));
    2743             : 
    2744         589 :    if(numRows){
    2745         589 :       vmsDataPtr_->processorId          = v_msDataPtr_[0]->processorId;
    2746         589 :       vmsDataPtr_->binNum               = v_msDataPtr_[0]->binNum;
    2747             :     }
    2748             : 
    2749         589 :     unsigned int numApcMax=0;
    2750    11960313 :     for(int n=0; n<numRows; n++){
    2751    11959724 :       if(v_msDataPtr_[n]->v_atmPhaseCorrection.size()>numApcMax)
    2752         589 :         numApcMax=v_msDataPtr_[n]->v_atmPhaseCorrection.size();
    2753             :     }
    2754         589 :     if(verbose_)cout<<"numApcMax="<<numApcMax<<endl;
    2755             : 
    2756         589 :     multimap<int,unsigned int> mm_dd;
    2757         589 :     if (ddfirst_) {
    2758         589 :       vector<int> ddId_v;
    2759         589 :       vector<int>::iterator ddId_i;
    2760         589 :       int ddIdOld = -1;
    2761         589 :       int ddIndex = -1;
    2762             :  
    2763    11960313 :       for(unsigned int n=0; n<v_msDataPtr_.size(); n++) {
    2764    11959724 :         if (v_msDataPtr_[n]->dataDescId != ddIdOld) {
    2765    11907970 :           ddIdOld = v_msDataPtr_[n]->dataDescId ;
    2766    11907970 :           if ((ddId_i = find(ddId_v.begin(), ddId_v.end(),ddIdOld)) == ddId_v.end()) {
    2767        2866 :             ddId_v.push_back(ddIdOld);
    2768        2866 :             ddIndex = ddId_v.size()-1;
    2769             :           }
    2770             :           else 
    2771    11905104 :             ddIndex = ddId_i - ddId_v.begin();
    2772             :         }
    2773    11959724 :         mm_dd.insert(make_pair(ddIndex,n));       
    2774             :       }
    2775         589 :     }
    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         589 :     v_tci_.clear();  
    2784         589 :     v_tci_.resize(numRows);
    2785             : 
    2786         589 :     if(ddfirst_){   // the dataDescription/time/baseline expansion
    2787             : 
    2788         589 :       unsigned int n, i=0;
    2789         589 :       multimap<int,unsigned int>::const_iterator it;
    2790    11960313 :       for(it=mm_dd.begin(); it!=mm_dd.end(); ++it){
    2791    11959724 :         n=it->second;
    2792    11959724 :         vmsDataPtr_->v_time.push_back(v_msDataPtr_[n]->time);
    2793    11959724 :         vmsDataPtr_->v_fieldId.push_back(v_msDataPtr_[n]->fieldId);
    2794    11959724 :         vmsDataPtr_->v_interval.push_back(v_msDataPtr_[0]->interval);
    2795    11959724 :         vmsDataPtr_->v_antennaId1.push_back(v_msDataPtr_[n]->antennaId1);
    2796    11959724 :         vmsDataPtr_->v_antennaId2.push_back(v_msDataPtr_[n]->antennaId2);
    2797    11959724 :         vmsDataPtr_->v_feedId1.push_back(v_msDataPtr_[n]->feedId1);
    2798    11959724 :         vmsDataPtr_->v_feedId2.push_back(v_msDataPtr_[n]->feedId2);
    2799    11959724 :         vmsDataPtr_->v_dataDescId.push_back(v_msDataPtr_[n]->dataDescId);
    2800    11959724 :         vmsDataPtr_->v_timeCentroid.push_back(v_msDataPtr_[n]->timeCentroid);
    2801    11959724 :         vmsDataPtr_->v_exposure.push_back(v_msDataPtr_[n]->exposure);
    2802    11959724 :         vmsDataPtr_->v_numData.push_back(v_msDataPtr_[n]->numData);
    2803    11959724 :         vmsDataPtr_->vv_dataShape.push_back(v_msDataPtr_[n]->v_dataShape);
    2804    11959724 :         vmsDataPtr_->v_phaseDir.push_back(v_msDataPtr_[n]->phaseDir);
    2805    11959724 :         vmsDataPtr_->v_stateId.push_back(v_msDataPtr_[n]->stateId);
    2806    11959724 :         vmsDataPtr_->v_msState.push_back(v_msDataPtr_[n]->msState);
    2807    11959724 :         vmsDataPtr_->v_flag.push_back(v_msDataPtr_[n]->flag);
    2808             : 
    2809    11959724 :         vmsDataPtr_->v_atmPhaseCorrection = v_msDataPtr_[n]->v_atmPhaseCorrection;
    2810    11959724 :         map<AtmPhaseCorrection,float*> m_vdata;
    2811    23919448 :         for(unsigned int napc=0; napc<vmsDataPtr_->v_atmPhaseCorrection.size(); napc++){
    2812    11959724 :           float* d=v_msDataPtr_[n]->v_data[napc];
    2813    11959724 :           m_vdata.insert(make_pair(vmsDataPtr_->v_atmPhaseCorrection[napc],d));
    2814             :         }
    2815    11959724 :         vmsDataPtr_->v_m_data.push_back(m_vdata);
    2816             :         //cout<<"dataDescriptionId="<<it->first<<" row="<<it->second<<endl;
    2817             : 
    2818    11959724 :         pair<unsigned int,double> p=make_pair(i++,v_msDataPtr_[n]->timeCentroid);
    2819    11959724 :         v_tci_[n]=p;
    2820    11959724 :       }
    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         589 :     if (verbose_) cout << "SDMBinData::getNextMSMainCols : exiting" << endl; 
    2856         589 :     return vmsDataPtr_;
    2857         589 :   }
    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         589 :   vector<MSData*> SDMBinData::getMSDataFromBDFData(Enum<CorrelationMode> e_qcm, EnumSet<AtmPhaseCorrection> es_qapc, unsigned int nDataSubsets) {
    3011         589 :     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         589 :     MSData* msDataPtr_ = (MSData *) NULL;
    3018             :     
    3019         589 :     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         589 :     ConfigDescriptionRow*       cdPtr = mainRowPtr_->getConfigDescriptionUsingConfigDescriptionId();
    3028         589 :     vector<AtmPhaseCorrection>  v_apc = cdPtr->getAtmPhaseCorrection();
    3029         589 :     Enum<CorrelationMode>       e_cm; e_cm = cdPtr->getCorrelationMode();
    3030             : 
    3031         589 :     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         589 :     if(canSelect_){
    3037             :       // set the new defaults
    3038           0 :       e_qcm_   = e_qcm;
    3039           0 :       es_qapc_ = es_qapc;
    3040             :     }
    3041             : 
    3042         589 :     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         589 :     if(e_qcm_[CROSS_ONLY]) if(e_cm[AUTO_ONLY])  return v_msDataPtr_;
    3051         589 :     if(e_qcm_[AUTO_ONLY])  if(e_cm[CROSS_ONLY]) return v_msDataPtr_;
    3052             : 
    3053         589 :     vector<unsigned int>       v_selected_napc;
    3054         589 :     vector<AtmPhaseCorrection> v_selected_apc;
    3055        1178 :     for(unsigned int n=0; n<v_apc.size(); n++){
    3056         589 :       if(es_qapc_[v_apc[n]]){
    3057         589 :         v_selected_napc.push_back(n);
    3058         589 :         v_selected_apc.push_back(v_apc[n]);
    3059             :       }
    3060             :     }
    3061         589 :     if(!v_selected_napc.size())return v_msDataPtr_;
    3062             : 
    3063         589 :     Tag configDescriptionId = mainRowPtr_->getConfigDescriptionId();
    3064             :     std::set<Tag>::iterator
    3065         589 :       itsf=s_cdId_.find(configDescriptionId),
    3066         589 :       itse=s_cdId_.end();
    3067         589 :     if(itsf==itse)
    3068           0 :       Error(FATAL, string("Tree hierarchy not present for configDescId ") + configDescriptionId.toString());
    3069             :     std::map<Tag,BaselinesSet*>::iterator
    3070         589 :       itf(m_cdId_baselinesSet_.find(configDescriptionId)),
    3071         589 :       ite(m_cdId_baselinesSet_.end());
    3072         589 :     if(itf==ite)
    3073           0 :       Error(FATAL, string("Tree hierarchy not present for configDescId ") + configDescriptionId.toString());
    3074         589 :     baselinesSet_=itf->second;
    3075             : 
    3076         589 :     if (verbose_) cout<<"ConfigDescriptionId = " << configDescriptionId.toString()<<endl;
    3077             : //    unsigned int               stateId;
    3078         589 :     vector<StateRow*>          v_statePtr = mainRowPtr_->getStatesUsingStateId();
    3079             : 
    3080         589 :     vector<int>                v_feedSet  = cdPtr->getFeedId();
    3081         589 :     vector<Tag>                v_antSet   = cdPtr->getAntennaId();
    3082         589 :     vector<Tag>                v_ddList   = cdPtr->getDataDescriptionId();
    3083             : 
    3084             : 
    3085         589 :     unsigned int               numFeed    = v_feedSet.size()/v_antSet.size();
    3086             :     unsigned int               numBin;
    3087             :     unsigned int               numPol;
    3088         589 :     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         589 :     ArrayTime                  timeOfDump;
    3095         589 :     ArrayTime                  timeCentroidOfDump;
    3096             : 
    3097         589 :     int                        fieldId    = mainRowPtr_->getFieldUsingFieldId()->getFieldId().getTagValue();
    3098         589 :     vector<vector<Angle> >     phaseDir   = mainRowPtr_->getFieldUsingFieldId()->getPhaseDir();
    3099             : 
    3100             :     
    3101         589 :     vector<Tag>                v_stateId;
    3102             : 
    3103         589 :     if ( verbose_ ) cout <<"ici AA: e_qcm_="<<e_qcm_.str()<<endl;
    3104             : 
    3105        9643 :     for(unsigned int na=0; na<v_antSet.size(); na++)
    3106        9054 :       v_stateId.push_back(v_statePtr[na]->getStateId());
    3107             : 
    3108         589 :     vector<vector<float> >                      vv_t; // dummy empty vector would there be no tsysSpectrum for a given syscal row
    3109         589 :     SysCalTable&                                sct = datasetPtr_->getSysCal();
    3110         589 :     vector<Tag>                                 v_spwid;
    3111         589 :     vector<pair<bool,vector<vector<float> > > > v_tsys;
    3112         589 :     vector<vector<pair<bool,vector<vector<float> > > > > vv_tsys;
    3113             : 
    3114         589 :     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         589 :     getNextDataDumps(nDataSubsets);
    3152             : 
    3153             :     // And now use what's in v_dataDump.
    3154         589 :     if(e_cm[CROSS_ONLY]==false && e_qcm_[CROSS_ONLY]==false ){       // retrieve only AUTO_DATA
    3155       17184 :       for(unsigned int nt=0; nt<v_dataDump_.size(); nt++){
    3156       16772 :         timeOfDump        = ArrayTime((int64_t)v_dataDump_[nt]->time());               if(verbose_)cout<<timeOfDump<<" ns"<<endl;
    3157       16772 :         timeCentroidOfDump= ArrayTime((int64_t)v_dataDump_[nt]->timeCentroid());       if(verbose_)cout<<timeCentroidOfDump.toString()<<" ns"<<endl;
    3158       16772 :         timeMJD           = timeOfDump.getMJD();                              if(verbose_)cout<<timeMJD<<" h = "<<86400.*timeMJD<<" s"<<endl;
    3159       16772 :         interval          = (double)v_dataDump_[nt]->interval()/1000000000LL; if(verbose_)cout<<interval<<" s"<<endl;
    3160       16772 :         timeCentroidMJD   = timeCentroidOfDump.getMJD();                      if(verbose_)cout<< timeCentroidMJD<<endl;
    3161       16772 :         exposure          = (double)v_dataDump_[nt]->exposure()/1000000000LL;
    3162       16772 :         floatDataDumpPtr_ = v_dataDump_[nt]->autoData();             // used by getData(na, nfe, ndd, nbi)
    3163             :         
    3164       16772 :         if(verbose_)cout <<"ici BB"<<endl;
    3165             :         
    3166       16772 :         vector<AtmPhaseCorrection> v_uapc; v_uapc.push_back(AP_UNCORRECTED);
    3167             :         
    3168       16772 :         unsigned int scn=0;
    3169      135256 :         for(unsigned int na=0; na<v_antSet.size(); na++){
    3170             : //        stateId = v_statePtr[na]->getStateId().getTagValue();
    3171      236968 :           for(unsigned int nfe=0; nfe<numFeed; nfe++){
    3172      528052 :             for(unsigned int ndd=0; ndd<v_ddList.size(); ndd++){
    3173      409568 :               numBin = baselinesSet_->numBin(ndd);
    3174      409568 :               numPol = baselinesSet_->numPol(baselinesSet_->getBasebandIndex(ndd));
    3175      409568 :               if(numPol==4)numPol=3;                                 // if XX,XY,YX,YY then auto XX,XY,YY 
    3176      409568 :               if(verbose_)cout<<"numPol="<<numPol
    3177           0 :                              <<"  na="  <<na
    3178           0 :                              <<" ant="  <<v_antSet[na].getTagValue()
    3179           0 :                              <<endl;
    3180      409568 :               v_dataShape[0]=numPol;
    3181             :               //              if(complexData_)v_dataShape[0]*=2;
    3182      409568 :               v_dataShape[1]=baselinesSet_->numChan(ndd);
    3183      409568 :               v_dataShape[2]=1;                                     // auto-correlation never atm phase corrected
    3184      409568 :               if (verbose_) cout << "CC" << endl;
    3185      819136 :               for(unsigned int nbi=0; nbi<numBin; nbi++){
    3186             :                 // the data and binary meta-data
    3187      409568 :                 if(SDMBinData::syscal_)
    3188           0 :                   msDataPtr_ = getCalibratedData( na, nfe,
    3189             :                                                   ndd, nbi, 
    3190           0 :                                                   vv_tsys[nt][scn]);
    3191             :                 else
    3192      409568 :                   msDataPtr_ = getData( na, nfe,
    3193             :                                         ndd, nbi);
    3194      409568 :                 scn++;
    3195      409568 :                 msDataPtr_->timeCentroid   = 86400.*timeCentroidMJD; // default value would there be no bin actualTimes
    3196      409568 :                 msDataPtr_->exposure       = exposure;               // default value would there be no bin actualDurations
    3197      409568 :                 msDataPtr_->flag           = 0;                      // default value is "false"  would there be no bin flags
    3198             :                 // calibrate and associate SDM meta-data
    3199      409568 :                 if(msDataPtr_->numData>0){
    3200      409568 :                   msDataPtr_->processorId        = cdPtr->getProcessorId().getTagValue();
    3201      409568 :                   msDataPtr_->antennaId1         = v_antSet[na].getTagValue();
    3202      409568 :                   msDataPtr_->antennaId2         = v_antSet[na].getTagValue();
    3203      409568 :                   msDataPtr_->feedId1            = v_feedSet[na*numFeed+nfe];
    3204      409568 :                   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      409568 :                   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      409568 :                   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      409568 :                   msDataPtr_->v_dataShape        = v_dataShape;
    3228      409568 :                   msDataPtr_->time               = 86400.*timeMJD;
    3229      409568 :                   msDataPtr_->interval           = interval;
    3230      409568 :                   msDataPtr_->v_atmPhaseCorrection = v_uapc;         // It is assumed that this is always the uncorrected case
    3231      409568 :                   msDataPtr_->binNum             = nbi+1;
    3232      409568 :                   msDataPtr_->fieldId            = fieldId;
    3233      409568 :                   vector<unsigned int> v_projectNodes;
    3234      409568 :                   if(v_dataDump_[nt]->integrationNum())v_projectNodes.push_back(v_dataDump_[nt]->integrationNum());
    3235      409568 :                   if(v_dataDump_[nt]->subintegrationNum())v_projectNodes.push_back(v_dataDump_[nt]->subintegrationNum());
    3236      409568 :                   msDataPtr_->projectPath        = v_projectNodes;
    3237      409568 :                   v_msDataPtr_.push_back(msDataPtr_);                      // store in vector for export
    3238      409568 :                 }
    3239      409568 :                 if(verbose_)cout << "B/ msDataPtr_->numData=" <<msDataPtr_->numData << endl;
    3240             :               }
    3241             :             }
    3242             :           }
    3243             :         }
    3244       16772 :       }
    3245             :     }
    3246         589 :     if(verbose_)cout <<"ici CC: "<<e_qcm_.str()<<endl;
    3247         589 :     vector<AtmPhaseCorrection> v_atmPhaseCorrection = cdPtr->getAtmPhaseCorrection();
    3248         589 :     bool queryCrossData = false;
    3249         589 :     if(e_qcm_[CROSS_ONLY])     queryCrossData=true;
    3250         589 :     if(e_qcm_[CROSS_AND_AUTO]) queryCrossData=true;
    3251             : 
    3252         589 :     if(e_cm[AUTO_ONLY]==false && queryCrossData ){
    3253             :       
    3254             :       // select the queried apc
    3255         373 :       vector<unsigned int> v_napc;
    3256         373 :       EnumSet<AtmPhaseCorrection> es_apc; es_apc.set(v_atmPhaseCorrection);    if(verbose_)cout<<es_apc.str()<<endl;
    3257         373 :       if(verbose_)cout <<"es_apc from BLOB: " << es_apc.str()   << endl;
    3258         373 :       if(verbose_)cout <<"es_qapc_ queried: " << es_qapc_.str() << endl;
    3259         746 :       for(unsigned int napc=0; napc<v_atmPhaseCorrection.size(); napc++)
    3260         373 :         if(es_qapc_[v_atmPhaseCorrection[napc]])v_napc.push_back(napc);
    3261         373 :       if(verbose_)for(unsigned int n=0; n<v_napc.size(); n++)cout<<"v_napc["<<n<<"]="<<v_napc[n]<<endl;
    3262             :       
    3263         373 :       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         373 :       if(verbose_)cout<<"ici DD"<<endl;
    3270             :       
    3271             :       
    3272       16664 :       for(unsigned int nt=0; nt<v_dataDump_.size(); nt++){
    3273       16291 :         timeOfDump        = ArrayTime((int64_t)v_dataDump_[nt]->time());                if(verbose_)cout<<timeOfDump<<endl;
    3274       16291 :         timeCentroidOfDump= ArrayTime((int64_t)v_dataDump_[nt]->timeCentroid());        if(verbose_)cout<< timeCentroidOfDump.toString() <<endl;
    3275       16291 :         timeMJD           = timeOfDump.getMJD();                               if(verbose_)cout<<timeMJD<<" h"<<endl;
    3276       16291 :         interval          = (double)v_dataDump_[nt]->interval()/1000000000LL;
    3277       16291 :         timeCentroidMJD   = timeCentroidOfDump.getMJD();                       if(verbose_)cout<< timeCentroidMJD<<" h"<<endl;
    3278       16291 :         exposure          = (double)v_dataDump_[nt]->exposure()/1000000000LL;;
    3279       16291 :         if(verbose_)cout<<"ici DD 1"<<endl;
    3280       16291 :         shortDataPtr_ = NULL;
    3281       16291 :         longDataPtr_  = NULL;
    3282       16291 :         floatDataPtr_ = NULL;
    3283       16291 :         if(v_dataDump_[nt]->crossDataShort())
    3284       13989 :           shortDataPtr_   = v_dataDump_[nt]->crossDataShort();       // used by getData(na, na2, nfe, ndd, nbi, napc)
    3285        2302 :         else if(v_dataDump_[nt]->crossDataLong())
    3286        1050 :           longDataPtr_    = v_dataDump_[nt]->crossDataLong();
    3287        1252 :         else if(v_dataDump_[nt]->crossDataFloat())
    3288        1252 :           floatDataPtr_    = v_dataDump_[nt]->crossDataFloat();
    3289             :         else
    3290           0 :           Error(FATAL, string("Cross data typed float not yet supported"));
    3291       16291 :         if(verbose_)cout<<"ici DD 2"<<endl;
    3292       16291 :         unsigned int scn=0;
    3293      167773 :         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     1904745 :           for(unsigned int na2=na1+1; na2<v_antSet.size(); na2++){
    3297     3506526 :             for(unsigned int nfe=0; nfe<numFeed; nfe++){
    3298    13303419 :               for(unsigned int ndd=0; ndd<v_ddList.size(); ndd++){
    3299    11550156 :                 if(verbose_)cout<<"ici DD 3   numApc="<<baselinesSet_->numApc()<<endl;
    3300    11550156 :                 numBin = baselinesSet_->numBin(ndd);
    3301    11550156 :                 numPol = baselinesSet_->numPol(baselinesSet_->getBasebandIndex(ndd));   // nb of pol product (max is 4)
    3302    11550156 :                 if(verbose_)cout<<"ici DD 4   numBin="<<numBin<<"  numPol="<<numPol<<endl;
    3303    11550156 :                 v_dataShape[0]=baselinesSet_->numPol(ndd);
    3304    11550156 :                 v_dataShape[1]=baselinesSet_->numChan(ndd);
    3305    11550156 :                 v_dataShape[2]=baselinesSet_->numApc();
    3306    11550156 :                 v_dataShape[2]=1;               // qapc being not an EnumSet (MS limitation for floatData column)
    3307    23100312 :                 for(unsigned int nbi=0; nbi<numBin; nbi++){
    3308    11550156 :                   if(verbose_){
    3309           0 :                     cout<<"timeCentroidMJD="<<timeCentroidMJD<<endl;
    3310             :                   }
    3311             :                   // the data and binary meta-data
    3312    11550156 :                   if (verbose_) {
    3313           0 :                     cout << "nt = " << nt << endl;
    3314           0 :                     cout << "size of v_dataDump_ = " << v_dataDump_.size() << endl;
    3315             :                   }
    3316             :                   
    3317    11550156 :                   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    11550156 :                     msDataPtr_ = getData( na1, nfe, na2, nfe,
    3325             :                                           ndd,  nbi, v_napc,
    3326    11550156 :                                           v_dataDump_[nt]->scaleFactor(ndd));
    3327             :                   }
    3328             :                   
    3329    11550156 :                   msDataPtr_->timeCentroid  = 86400.*timeCentroidMJD; // default value would there be no bin actualTimes
    3330    11550156 :                   msDataPtr_->exposure      = exposure;               // default value would there be no bin actualDurations
    3331    11550156 :                   msDataPtr_->flag          = 0;                      // default value is "false"  would there be no bin flags
    3332    11550156 :                   if(verbose_)cout<<"ici DD 7 msDataPtr_->numData="<<msDataPtr_->numData<<endl;
    3333             :                   // the associated SDM meta-data
    3334    11550156 :                   if(msDataPtr_->numData>0){
    3335    11550156 :                     msDataPtr_->processorId          = cdPtr->getProcessorId().getTagValue();
    3336    11550156 :                     msDataPtr_->time                 = 86400.*timeMJD;
    3337    11550156 :                     msDataPtr_->antennaId1           = v_antSet[na1].getTagValue();
    3338    11550156 :                     msDataPtr_->antennaId2           = v_antSet[na2].getTagValue();
    3339    11550156 :                     msDataPtr_->feedId1              = v_feedSet[na1*numFeed+nfe];
    3340    11550156 :                     msDataPtr_->feedId2              = v_feedSet[na2*numFeed+nfe];
    3341    11550156 :                     msDataPtr_->dataDescId           = v_ddList[ndd].getTagValue();
    3342    11550156 :                     msDataPtr_->fieldId              = fieldId;
    3343    11550156 :                     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    11550156 :                     msDataPtr_->v_dataShape          = v_dataShape;
    3351    11550156 :                     msDataPtr_->interval             = interval;
    3352    11550156 :                     msDataPtr_->v_atmPhaseCorrection = v_selected_apc;
    3353    11550156 :                     msDataPtr_->binNum               = nbi+1;              // a number is one-based.
    3354    11550156 :                     vector<unsigned int> v_projectNodes;
    3355    11550156 :                     if(v_dataDump_[nt]->integrationNum())v_projectNodes.push_back(v_dataDump_[nt]->integrationNum());
    3356    11550156 :                     if(v_dataDump_[nt]->subintegrationNum())v_projectNodes.push_back(v_dataDump_[nt]->subintegrationNum());
    3357    11550156 :                     msDataPtr_->projectPath          = v_projectNodes;
    3358    11550156 :                   }
    3359             :                   // store in vector for export
    3360    11550156 :                   if(msDataPtr_->numData>0)v_msDataPtr_.push_back(msDataPtr_);
    3361    11550156 :                   if(verbose_)cout << "A/ msDataPtr_->numData=" << msDataPtr_->numData << endl;
    3362    11550156 :                   scn++;
    3363             :                 }
    3364             :               }
    3365             :             }
    3366             :           }
    3367             :         }
    3368             :       }
    3369         373 :       if(verbose_)cout<<"v_msDataPtr_.size()="<< v_msDataPtr_.size() << endl;
    3370         373 :     }
    3371         589 :     if (verbose_) cout << "SDMBinData::getMSDataFromBDFData: exiting" << endl;
    3372         589 :     return v_msDataPtr_;
    3373         589 :   }
    3374             : 
    3375         589 :   void SDMBinData::getNextDataDumps(unsigned int nDataSubsets) {
    3376         589 :     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         589 :     vector<DataDump*>::reverse_iterator it, itrb=v_dataDump_.rbegin(), itre=v_dataDump_.rend();
    3383       17261 :     for(it=itrb; it!=itre; it++){
    3384       16672 :       delete *it;
    3385             :     }
    3386         589 :     v_dataDump_.clear();
    3387             : 
    3388         589 :     Enum<CorrelationMode>            e_cm;
    3389         589 :     Enum<ProcessorType>              e_pt;
    3390         589 :     Enum<CorrelatorType>             e_ct;
    3391             :  
    3392         589 :     if (verbose_) cout << "*" << endl;
    3393             : //    unsigned int                     numTime=0;
    3394             :  
    3395         589 :     unsigned int                     numAnt              = sdmdosr.numAntenna();   
    3396         589 :     CorrelationMode                  correlationMode     = sdmdosr.correlationMode(); e_cm=correlationMode;
    3397         589 :     ProcessorType                    processorType       = sdmdosr.processorType();   e_pt=processorType;
    3398             :     CorrelatorType                   correlatorType;
    3399             :     
    3400         589 :     const SDMDataObject::DataStruct& dataStruct          = sdmdosr.dataStruct();
    3401             :     
    3402         589 :     const vector<AtmPhaseCorrection>&       v_apc               = dataStruct.apc();
    3403         589 :     const vector<SDMDataObject::Baseband>&  v_baseband          = dataStruct.basebands();
    3404         589 :     SDMDataObject::ZeroLagsBinaryPart               zeroLagsParameters;
    3405             :     
    3406             : //    bool                             normalized=false;
    3407         589 :     if(e_pt[ProcessorTypeMod::CORRELATOR]){
    3408             : //      if(e_cm[CorrelationModeMod::CROSS_ONLY])
    3409             : //      normalized =  dataStruct.autoData().normalized();
    3410         589 :       if(dataStruct.zeroLags().size()){
    3411         200 :         zeroLagsParameters = dataStruct.zeroLags();
    3412         200 :         correlatorType = zeroLagsParameters.correlatorType(); e_ct=correlatorType;
    3413             :       }
    3414             :     }
    3415             :  
    3416         589 :     unsigned int                     numApc              = v_apc.size();
    3417         589 :     unsigned int                     numBaseband         = v_baseband.size();
    3418             :    
    3419         589 :     vector< vector< unsigned int > > vv_numAutoPolProduct;
    3420         589 :     vector< vector< unsigned int > > vv_numCrossPolProduct;
    3421         589 :     vector< vector< unsigned int > > vv_numSpectralPoint;
    3422         589 :     vector< vector< unsigned int > > vv_numBin;
    3423         589 :     vector< vector< float > >        vv_scaleFactor;
    3424         589 :     vector< unsigned int >           v_numSpectralWindow;
    3425         589 :     vector< vector< Enum<NetSideband> > > vv_e_sideband;
    3426         589 :     vector< vector< SDMDataObject::SpectralWindow* > > vv_image;
    3427             :     
    3428         589 :     if(verbose_)cout<<"e_cm="<<e_cm.str()<<endl;
    3429             :     
    3430        2510 :     for(unsigned int nbb=0; nbb<v_baseband.size(); nbb++){
    3431        1921 :       vector<SDMDataObject::SpectralWindow>  v_spw = v_baseband[nbb].spectralWindows(); v_numSpectralWindow.push_back(v_spw.size());
    3432        1921 :       vector<SDMDataObject::SpectralWindow*> v_image;
    3433        1921 :       vector< unsigned int > v_numBin;
    3434        1921 :       vector< unsigned int > v_numSpectralPoint;
    3435        1921 :       vector< unsigned int > v_numSdPolProduct;
    3436        1921 :       vector< unsigned int > v_numCrPolProduct;
    3437        1921 :       vector< Enum<NetSideband> >  v_e_sideband;
    3438        1921 :       vector<float>          v_scaleFactor;
    3439        4787 :       for(unsigned int nspw=0; nspw<v_spw.size(); nspw++){
    3440        2866 :         v_e_sideband.push_back(Enum<NetSideband>(v_spw[nspw].sideband()));
    3441        2866 :         v_image.push_back(NULL);                                   // TODO waiting for implementation
    3442        2866 :         v_numBin.push_back(v_spw[nspw].numBin());
    3443        2866 :         if(verbose_)cout<<"v_spw["<<nspw<<"].numSpectralPoint()="<<v_spw[nspw].numSpectralPoint()<<endl;
    3444        2866 :         v_numSpectralPoint.push_back(v_spw[nspw].numSpectralPoint());
    3445        2866 :         if(e_cm[AUTO_ONLY])
    3446         688 :           v_numSdPolProduct.push_back(v_spw[nspw].sdPolProducts().size());
    3447             :         else{
    3448        2178 :           v_numCrPolProduct.push_back(v_spw[nspw].crossPolProducts().size());
    3449        2178 :           v_scaleFactor.push_back(v_spw[nspw].scaleFactor());
    3450        2178 :           if(e_cm[CROSS_AND_AUTO])
    3451        2104 :             v_numSdPolProduct.push_back(v_spw[nspw].sdPolProducts().size());
    3452             :         }
    3453             :       }
    3454        1921 :       if(e_cm[CROSS_ONLY]==false)vv_numAutoPolProduct.push_back(v_numSdPolProduct);
    3455        1921 :       if(e_cm[AUTO_ONLY]==false) vv_numCrossPolProduct.push_back(v_numCrPolProduct);
    3456        1921 :       vv_numSpectralPoint.push_back(v_numSpectralPoint);
    3457        1921 :       vv_e_sideband.push_back(v_e_sideband);
    3458        1921 :       vv_image.push_back(v_image);
    3459        1921 :       vv_numBin.push_back(v_numBin);
    3460        1921 :       vv_scaleFactor.push_back(v_scaleFactor);
    3461        1921 :     }
    3462         589 :     if(e_cm[AUTO_ONLY])vv_numCrossPolProduct.clear();
    3463         589 :     if(e_cm[CROSS_ONLY])vv_numAutoPolProduct.clear();
    3464             :     
    3465         589 :     complexData_=false;
    3466         589 :     if(vv_numAutoPolProduct.size()){
    3467        2362 :       for(unsigned int nbb=0; nbb<vv_numAutoPolProduct.size(); nbb++){
    3468        4639 :         for(unsigned int nspw=0; nspw<vv_numAutoPolProduct[nbb].size(); nspw++)
    3469        2792 :           if(vv_numAutoPolProduct[nbb][nspw]>2)complexData_=true;
    3470             :       }
    3471             :     }
    3472         589 :     if(vv_numCrossPolProduct.size())complexData_=true;
    3473             :     
    3474         589 :     EnumSet<AxisName>         es_axisNames;
    3475             :     DataContent               dataContent;
    3476         589 :     SDMDataObject::BinaryPart binaryPart;
    3477         589 :     map<DataContent,pair<unsigned int,EnumSet<AxisName> > > m_dc_sizeAndAxes;
    3478             :     
    3479         589 :     dataContent = FLAGS;
    3480         589 :     binaryPart  = dataStruct.flags();
    3481         589 :     es_axisNames.set(binaryPart.axes(),true);
    3482         589 :     if(es_axisNames.count())m_dc_sizeAndAxes.insert(make_pair(dataContent,make_pair(binaryPart.size(),es_axisNames)));
    3483             :     
    3484         589 :     dataContent = ACTUAL_DURATIONS;
    3485         589 :     binaryPart  = dataStruct.actualDurations();
    3486         589 :     es_axisNames.set(binaryPart.axes(),true);
    3487         589 :     if(es_axisNames.count())m_dc_sizeAndAxes.insert(make_pair(dataContent,make_pair(binaryPart.size(),es_axisNames)));
    3488             :     
    3489         589 :     dataContent = ACTUAL_TIMES;
    3490         589 :     binaryPart  = dataStruct.actualTimes();
    3491         589 :     es_axisNames.set(binaryPart.axes(),true);
    3492         589 :     if(es_axisNames.count())m_dc_sizeAndAxes.insert(make_pair(dataContent,make_pair(binaryPart.size(),es_axisNames)));
    3493             :     
    3494         589 :     dataContent = AUTO_DATA;
    3495         589 :     binaryPart  = dataStruct.autoData();
    3496         589 :     es_axisNames.set(binaryPart.axes(),true);
    3497         589 :     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         589 :     dataContent = CROSS_DATA;
    3502         589 :     binaryPart  = dataStruct.crossData();
    3503         589 :     es_axisNames.set(binaryPart.axes(),true);
    3504         589 :     if(es_axisNames.count())m_dc_sizeAndAxes.insert(make_pair(dataContent,make_pair(binaryPart.size(),es_axisNames)));
    3505             :     
    3506         589 :     if(binaryPart.size()){
    3507         417 :       dataContent = ZERO_LAGS;
    3508         417 :       binaryPart  = dataStruct.zeroLags();
    3509         417 :       es_axisNames.set(binaryPart.axes(),true);
    3510         417 :       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         589 :       itf=m_dc_sizeAndAxes.find(AUTO_DATA),
    3517         589 :       ite=m_dc_sizeAndAxes.end();
    3518         589 :     if(itf==ite)itf=m_dc_sizeAndAxes.find(CROSS_DATA);
    3519         589 :     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         589 :     unsigned int nread = 0 ;
    3523             :     int64_t                    interval;
    3524             :     int64_t                    exposure;
    3525             :     int64_t                    timeOfInteg;
    3526             :     int64_t                    timeCentroid;
    3527         589 :     const vector<SDMDataSubset>& sdmDataSubsets = sdmdosr.nextSubsets(nDataSubsets);
    3528             : 
    3529       19363 :     for (vector<SDMDataSubset>::const_iterator iter = sdmDataSubsets.begin(); iter != sdmDataSubsets.end(); iter++) {
    3530       18774 :       const SDMDataSubset& currentSubset = *iter;
    3531       18774 :       nread++; 
    3532             :       
    3533       18774 :       timeOfInteg  = currentSubset.time();        
    3534       18774 :       timeCentroid = currentSubset.time();        
    3535       18774 :       interval     = currentSubset.interval();    
    3536       18774 :       exposure     = interval;
    3537       18774 :       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       18774 :                                             );
    3566       18774 :       if(e_cm[CROSS_ONLY]    )dataDumpPtr->setScaleFactor(vv_scaleFactor);
    3567       18774 :       if(e_cm[CROSS_AND_AUTO])dataDumpPtr->setScaleFactor(vv_scaleFactor);
    3568             : 
    3569       18774 :       if(verbose_)cout<<"m_dc_sizeAndAxes.size()="<< m_dc_sizeAndAxes.size() << endl;
    3570       18774 :       if((itf=m_dc_sizeAndAxes.find(FLAGS))!=ite){
    3571       18774 :         if(verbose_)cout<<"Flags have been declared in the main header"<<endl;
    3572             :         const unsigned int* flagsPtr;
    3573       18774 :         unsigned int long numFlags = currentSubset.flags( flagsPtr );
    3574       18774 :         if(verbose_)cout<<numFlags<<" "<<itf->second.first<<endl;
    3575       18774 :         if(numFlags)dataDumpPtr->attachFlags( itf->second.first, itf->second.second,
    3576             :                                               numFlags, flagsPtr);
    3577             :       }
    3578             : 
    3579       18774 :       if((itf=m_dc_sizeAndAxes.find(ACTUAL_TIMES))!=ite){
    3580       18662 :         if(verbose_)cout<<"ActualTimes have been declared in the main header"<<endl;
    3581             :         const int64_t* actualTimesPtr;
    3582       18662 :         unsigned long int numActualTimes = currentSubset.actualTimes( actualTimesPtr );
    3583       18662 :         if(verbose_)cout<<numActualTimes<<" "<<itf->second.first<<endl;
    3584       18662 :         if(numActualTimes)dataDumpPtr->attachActualTimes( itf->second.first, itf->second.second,
    3585             :                                                           numActualTimes, actualTimesPtr);
    3586             :       }
    3587             : 
    3588       18774 :       if((itf=m_dc_sizeAndAxes.find(ACTUAL_DURATIONS))!=ite){
    3589       18662 :         if(verbose_)cout<<"ActualDurations have been declared in the main header"<<endl;
    3590             :         const int64_t* actualDurationsPtr;
    3591       18662 :         unsigned long int numActualDurations = currentSubset.actualDurations( actualDurationsPtr );
    3592       18662 :         if(verbose_)cout<<numActualDurations<<" "<<itf->second.first<<endl;
    3593       18662 :         if(numActualDurations)dataDumpPtr->attachActualDurations( itf->second.first, itf->second.second,
    3594             :                                                                   numActualDurations, actualDurationsPtr);
    3595             :       }
    3596             : 
    3597       18774 :       if((itf=m_dc_sizeAndAxes.find(ZERO_LAGS))!=ite){
    3598       13890 :         if(verbose_)cout<<"ZeroLags have been declared in the main header"<<endl;
    3599             :         const float* zeroLagsPtr;
    3600       13890 :         unsigned long int numZeroLags = currentSubset.zeroLags( zeroLagsPtr );
    3601       13890 :         if(verbose_)cout<<numZeroLags<<" "<<itf->second.first<<endl;
    3602       13890 :         if(numZeroLags)dataDumpPtr->attachZeroLags( itf->second.first, itf->second.second,
    3603             :                                                     numZeroLags, zeroLagsPtr);
    3604             :       }
    3605             : 
    3606       18774 :       if((itf=m_dc_sizeAndAxes.find(CROSS_DATA))!=ite){
    3607       16954 :         if(verbose_)cout<<"CrossData have been declared in the main header ";
    3608             :         unsigned long int numCrossData;
    3609       16954 :         switch(currentSubset.crossDataType()){
    3610       14502 :         case INT16_TYPE:
    3611             :           { const short int* crossDataPtr;
    3612       14502 :             numCrossData = currentSubset.crossData( crossDataPtr );
    3613       14502 :             if(numCrossData)dataDumpPtr->attachCrossData( itf->second.first, itf->second.second,
    3614             :                                                           numCrossData, crossDataPtr);
    3615             :           }
    3616       14502 :           if(verbose_)cout<<"SHORT_TYPE"<<endl;
    3617       14502 :           if(verbose_)cout<<"crossData attached,  const pointer:"<<dataDumpPtr->crossDataShort()<<endl;
    3618       16954 :           break;
    3619        1200 :         case INT32_TYPE:
    3620             :           { const int* crossDataPtr;
    3621        1200 :             numCrossData = currentSubset.crossData( crossDataPtr );
    3622        1200 :             if(numCrossData)dataDumpPtr->attachCrossData( itf->second.first, itf->second.second,
    3623             :                                                           numCrossData, crossDataPtr);
    3624             :           }
    3625        1200 :           if(verbose_)cout<<"INT_TYPE"<<endl;
    3626        1200 :           if(verbose_)cout<<"crossData attached,  const pointer:"<<dataDumpPtr->crossDataLong()<<endl;
    3627        1200 :           break;
    3628        1252 :         case FLOAT32_TYPE:
    3629             :           { const float* crossDataPtr;
    3630        1252 :             numCrossData = currentSubset.crossData( crossDataPtr );
    3631        1252 :             if(numCrossData)dataDumpPtr->attachCrossData( itf->second.first, itf->second.second,
    3632             :                                                           numCrossData, crossDataPtr);
    3633             :           }
    3634        1252 :           if(verbose_)cout<<"FLOAT_TYPE"<<endl;
    3635        1252 :           if(verbose_)cout<<"crossData attached,  const pointer:"<<dataDumpPtr->crossDataFloat()<<endl;
    3636        1252 :           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       18774 :       if((itf=m_dc_sizeAndAxes.find(AUTO_DATA))!=ite){
    3645       18662 :         if(verbose_)cout<<"AutoData have been declared in the main header"<<endl;
    3646       18662 :         const float*      floatDataPtr=NULL;
    3647       18662 :         unsigned long int numFloatData = currentSubset.autoData( floatDataPtr );
    3648       18662 :         if(verbose_)cout<<numFloatData<<" "<<itf->second.first<<"  "<<floatDataPtr<<endl;
    3649       18662 :         if(numFloatData){
    3650       18662 :           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       18662 :           dataDumpPtr->attachAutoData( itf->second.first, itf->second.second,
    3654             :                                        numFloatData, floatDataPtr);
    3655       18662 :           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       18774 :       if (verbose_) cout << "About to setContextUsingProjectPath" << endl;
    3665       18774 :       dataDumpPtr->setContextUsingProjectPath(currentSubset.projectPath());
    3666       18774 :       if (verbose_) cout << "Back from setContextUsingProjectPath" << endl;
    3667       18774 :       const unsigned int* bptr=dataDumpPtr->flags(); if(bptr==NULL)if(verbose_)cout<<"No flags"<<endl;
    3668       18774 :       if(verbose_)cout<<"store dataDump"<<endl;
    3669       18774 :       v_dataDump_.push_back(dataDumpPtr);
    3670       18774 :       if(verbose_)cout<<"v_dataDumpPtr_.size()="<< v_dataDump_.size()<<endl;
    3671             :     }
    3672         589 :     if(verbose_)cout<<"v_dataDumpPtr_.size()="<< v_dataDump_.size()<<endl;
    3673         589 :     if (verbose_) cout << "SDMBinData::getNextDataDumps : exiting" << endl;
    3674        1178 :     return;
    3675         589 :   }
    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          78 :   bool  SDMBinData::isComplexData(){
    3810             :   
    3811          78 :     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          78 :       canSelect_    = false;
    3832          78 :       forceComplex_ = true;
    3833             : 
    3834          78 :       if (e_qcm_[CROSS_ONLY] && es_cm_[CROSS_ONLY]) return forceComplex_;
    3835             : 
    3836          60 :       vector<MainRow*>            v_mr = datasetPtr_->getMain().get();
    3837          60 :       vector<DataDescriptionRow*> v_ddr;
    3838             :       ConfigDescriptionRow*       cdr;
    3839          60 :       Enum<CorrelationMode>       e_cm;
    3840        4368 :       for(unsigned int n=0; n<v_mr.size(); n++){
    3841        4352 :         if(!reasonToReject(v_mr[n]).length()){
    3842        4352 :           cdr  = v_mr[n]->getConfigDescriptionUsingConfigDescriptionId();
    3843        4352 :           e_cm = cdr->getCorrelationMode();
    3844        4352 :           if(e_cm[AUTO_ONLY]){
    3845        4196 :             v_ddr = cdr->getDataDescriptionsUsingDataDescriptionId();
    3846       11200 :             for(unsigned int ndd=0; ndd<v_ddr.size(); ndd++)
    3847        7004 :               if(v_ddr[ndd]->getPolarizationUsingPolOrHoloId()->getCorrType().size()>2)return forceComplex_;
    3848             :           }
    3849         156 :           else if(e_cm[CROSS_AND_AUTO]){
    3850         154 :             if(e_qcm_[CROSS_AND_AUTO]){
    3851          42 :               return true;
    3852             :             }else{
    3853         112 :               v_ddr = cdr->getDataDescriptionsUsingDataDescriptionId();
    3854         560 :               for(unsigned int ndd=0; ndd<v_ddr.size(); ndd++)
    3855         448 :                 if(v_ddr[ndd]->getPolarizationUsingPolOrHoloId()->getCorrType().size()>2)return forceComplex_;
    3856             :             }
    3857             :           }
    3858           2 :           else if (e_cm[CROSS_ONLY]) {
    3859           2 :             return true;
    3860             :           }
    3861             :         }
    3862             :       }
    3863          16 :       forceComplex_ = false;
    3864          16 :       return forceComplex_;
    3865          60 :     }
    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         771 :   pair<bool,bool> SDMBinData::dataOrder(){
    3877         771 :     pair<bool,bool> p=make_pair( baselineReverse_, autoTrailing_ );
    3878         771 :     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