LCOV - code coverage report
Current view: top level - alma/ASDMBinaries - BaselineMetadata.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 199 0.0 %
Date: 2024-12-11 20:54:31 Functions: 0 27 0.0 %

          Line data    Source code
       1             : #include <vector>
       2             : #include <iostream>
       3             : using namespace std;
       4             : #include <alma/ASDMBinaries/Error.h>
       5             : #include <alma/ASDMBinaries/BaselineMetadata.h>
       6             : using namespace sdmbin;
       7             : 
       8             : // constructors
       9             : 
      10             : // Default onstructor
      11           0 : BaselineMetadata::BaselineMetadata(){
      12             :   //cout << "Constructor vide BaselineMetadata" << endl;
      13           0 : }
      14             : 
      15             : // Destructor
      16           0 : BaselineMetadata::~BaselineMetadata(){}
      17             : 
      18             : 
      19             : // method to instantiate the base of the hierarchy:
      20           0 : void BaselineMetadata::mkBaselineMetadata( vector<int> v_npp, vector<int> v_nbin, int nbb, int nant, int correlationMode)
      21             : {
      22           0 :   correlationMode_ = correlationMode;
      23           0 :   v_numPolProduct_ = v_npp;
      24           0 :   v_numBin_    = v_nbin;
      25           0 :   numBaseband_ = nbb;
      26           0 :   numAnt_      = nant;
      27           0 :   numBaseline_ = 0;
      28           0 :   if(correlationMode!=1)
      29           0 :     numBaseline_ = (nant*(nant-1))/2;
      30             : 
      31           0 :   sizes();
      32           0 : }
      33             : 
      34             : 
      35             : // accessors
      36             : 
      37           0 : int         BaselineMetadata::numBaseband(){ 
      38           0 :   return v_numBin_.size();
      39             : }
      40             : 
      41           0 : int         BaselineMetadata::numPolProduct(int basebandNum) {
      42           0 :   if(wrongBasebandNum(basebandNum))
      43           0 :     return -1; 
      44           0 :   else return v_numPolProduct_[basebandNum-1];
      45             : }
      46             : 
      47           0 : vector<int> BaselineMetadata::numPolProduct(){ 
      48           0 :   return v_numPolProduct_;
      49             : }
      50             : 
      51           0 : int         BaselineMetadata::numBin(int basebandNum) {
      52           0 :   if(wrongBasebandNum(basebandNum))
      53           0 :     return -1; 
      54             :   else 
      55           0 :     return v_numBin_[basebandNum-1];       
      56             : }
      57             : 
      58           0 : vector<int> BaselineMetadata::numBin(){ 
      59           0 :   return v_numBin_; 
      60             : }
      61             : 
      62           0 : int         BaselineMetadata::numBaseline(){ 
      63           0 :   return numBaseline_;
      64             : }
      65             : 
      66           0 : int         BaselineMetadata::correlationMode(){ 
      67           0 :   return correlationMode_; 
      68             : }
      69             : 
      70           0 : vector<int> BaselineMetadata::numAutoPolProduct(){ 
      71           0 :   return v_numAutoPolProduct_;
      72             : }
      73             : 
      74           0 : int         BaselineMetadata::numAutoPolProduct(int basebandNum) {
      75           0 :   if(wrongBasebandNum(basebandNum))return -1; 
      76             :   else 
      77           0 :     return v_numAutoPolProduct_[basebandNum-1];
      78             : }
      79             : 
      80             : 
      81             : // static data member
      82             : int         BaselineMetadata::FLAGLIMIT=0;
      83             : 
      84             : 
      85             : // methods to access a node or sequence of nodes in the tree structure
      86           0 : int BaselineMetadata::at(int pp, int /*bin*/, int bb, int i, int j){  // comment to avoid the unused parameter warning.
      87           0 :   int index=0;
      88           0 :   if(wrongPolProductIndex(pp,bb,i,j))return -1;
      89           0 :   if(i==j){                                                        // metadata for single-dish data
      90           0 :     for(int nbb=0; nbb<bb; nbb++)
      91           0 :       index = index+v_numBin_[nbb]*v_numAutoPolProduct_[nbb];
      92           0 :     return crossSize_ + i*numValPerZeroBaseline_ + index + pp;
      93             : 
      94             :   }else{                                                           // metadata for interferometric data
      95           0 :     for(int nbb=0; nbb<bb; nbb++){
      96           0 :       index = index+v_numBin_[nbb]*v_numPolProduct_[nbb];
      97             :     }
      98           0 :     return (baselineNum(i,j)-1)*numValPerBaseline_ + index + pp;
      99             :   }
     100             : }
     101             : 
     102           0 : vector<int> BaselineMetadata::at(int pp, int bb, int i, int j){
     103           0 :   int         index=0;
     104           0 :   vector<int> v_index;
     105           0 :   if(wrongPolProductIndex(pp,bb,i,j))return v_index;
     106           0 :   if(i==j){                                                        // metadata for single-dish data
     107           0 :     for(int nbb=0; nbb<bb; nbb++)
     108           0 :       index = index+v_numBin_[nbb]*v_numAutoPolProduct_[nbb];
     109           0 :     for(int nbin=0; nbin<v_numBin_[bb]; nbin++)
     110           0 :       v_index.push_back( crossSize_ + 
     111           0 :                          i*index + 
     112           0 :                          nbin*v_numAutoPolProduct_[bb] + pp);
     113           0 :     return v_index;
     114             :   }else{                                                           // metadata for interferometric data
     115           0 :     for(int nbin=0; nbin<v_numBin_[bb]; nbin++)
     116           0 :       v_index.push_back( (baselineNum(i,j)-1)*index +
     117           0 :                          nbin*v_numPolProduct_[bb] + pp);
     118           0 :     return v_index;
     119             :   }
     120           0 : }
     121             : 
     122           0 : vector<int> BaselineMetadata::at(int /*pp*/, int /*bin*/, int /*bb*/){ // comment to avoid the unused parameter warning
     123           0 :   vector<int> v_index;
     124           0 :   Error(WARNING, (char *) " This method has not yet been implemented! contact fviallef@maat.obspm.fr");
     125             :   // TODO
     126           0 :   return v_index;
     127           0 : }
     128             : 
     129             : 
     130           0 : vector<vector<int> > BaselineMetadata::at(int /*nbin*/, int /*nbb*/){ // comment to avoid the unused parameter warning
     131           0 :   vector<vector<int> > vv_index;
     132           0 :   Error(WARNING, (char *) "This method has not yet been implemented! contact fviallef@maat.obspm.fr");
     133             :   // TODO
     134           0 :   return vv_index;
     135           0 : }
     136             : 
     137             : 
     138           0 : vector<vector<vector<int> > > BaselineMetadata::at(bool cross, int antIndex){
     139             : 
     140           0 :   vector<vector<vector<int> > > vvv_index;
     141           0 :   vector<vector<int> >          vv_index;
     142           0 :   vector<int>                   v_index;
     143             : 
     144           0 :   if(wrongAntennaIndex(antIndex))return vvv_index;
     145             : 
     146             :   int                  i,n,k,na,nbb;
     147             :   int                  imax;
     148             : 
     149           0 :   if(cross){
     150             : 
     151           0 :     if(correlationMode_==1){
     152           0 :       Error(WARNING, (char *) "No cross metadata when correlationMode=1");
     153           0 :       return vvv_index;
     154             :     }
     155           0 :     vv_index.resize(numBaseband_);
     156           0 :     for(na=0; na<numAnt_; na++){
     157           0 :       if(na!=antIndex){
     158           0 :         k = (baselineNum(na,antIndex)-1)*numValPerBaseline_;
     159           0 :         n = 0;
     160           0 :         for(nbb=0; nbb<numBaseband_; nbb++){
     161           0 :           imax=v_numBin_[nbb]*v_numPolProduct_[nbb];
     162           0 :           v_index.resize(imax);
     163           0 :           for(i=0;i<imax; i++)v_index[i]=k+n++;
     164           0 :           vv_index[nbb]=v_index;
     165             :         }
     166           0 :         vvv_index.push_back(vv_index);
     167             :       }
     168             :     }
     169             : 
     170             :   }else{
     171             : 
     172             :     /* Since 3APr06 we also have antenna-based metadata when correlationMode=0
     173             :     if(correlationMode_==0){
     174             :       Error(WARNING, "no auto metadata when correlationMode=0");
     175             :       return vvv_index;
     176             :     }
     177             :     */
     178           0 :     vv_index.resize(numBaseband_);
     179           0 :     k = crossSize_ + antIndex*numValPerZeroBaseline_;
     180           0 :     n=0;
     181           0 :     for(nbb=0; nbb<numBaseband_; nbb++){
     182           0 :       imax=v_numBin_[nbb]*v_numAutoPolProduct_[nbb];
     183           0 :       v_index.resize(imax);
     184           0 :       for(i=0;i<imax; i++)v_index[i]=k+n++;
     185           0 :       vv_index[nbb]=v_index;
     186             :     }
     187           0 :     vvv_index.push_back(vv_index);
     188             :   }
     189             : 
     190           0 :   return vvv_index;
     191             : 
     192           0 : }
     193             : 
     194             : 
     195             : // method to get the size (in number of value of a given type)
     196           0 : void BaselineMetadata::sizes(){
     197             : 
     198           0 :   numValPerBaseline_ = 0;
     199           0 :   for(int nbb=0; nbb<numBaseband(); nbb++)
     200           0 :     numValPerBaseline_ = numValPerBaseline_ + v_numBin_[nbb]*v_numPolProduct_[nbb];
     201             : 
     202           0 :   crossSize_ = 0;
     203           0 :   if(numBaseline_!=0){    
     204           0 :     crossSize_ = numBaseline_*numValPerBaseline_;
     205             :   }
     206             : 
     207             :   int numAutoPP;
     208           0 :   numValPerZeroBaseline_ = 0;
     209           0 :   for(int nbb=0; nbb<numBaseband(); nbb++){
     210           0 :     numAutoPP = v_numPolProduct_[nbb];
     211           0 :     if(v_numPolProduct_[nbb]==4){
     212           0 :       numAutoPP=3;
     213           0 :       if(correlationMode_==0)numAutoPP=2;  // exclusively for BaselineMetadata children!
     214             :     }
     215           0 :     v_numAutoPolProduct_.push_back(numAutoPP);
     216           0 :     numValPerZeroBaseline_ = numValPerZeroBaseline_ + v_numBin_[nbb]*numAutoPP;
     217             :   }
     218           0 :   autoSize_  = 0;
     219           0 :   if(correlationMode_==1){
     220           0 :     autoSize_ = numAnt_*numValPerBaseline_;
     221             :   }else{
     222           0 :     autoSize_ = numAnt_*numValPerZeroBaseline_;
     223             :   }
     224             :   //cout << "autoSize_=" << autoSize_ << endl;
     225             :   //cout << "crossSize_=" << crossSize_ << endl;
     226           0 : }
     227             : 
     228           0 : int BaselineMetadata::numValue(){
     229           0 :   return crossSize_+autoSize_;
     230             : }
     231             : 
     232             : 
     233           0 : int BaselineMetadata::baselineNum( int na1, int na2) {
     234           0 :   if(na1==na2){
     235           0 :     return numBaseline_+na1+1;
     236             :   }else{
     237             :     int n;
     238           0 :     if(na1>na2){ n=na2; na2=na1; na1=n; }
     239           0 :     int iNum = na1+1;
     240           0 :     int jNum = na2+1;
     241           0 :     n=iNum; if(jNum>iNum)n=jNum; 
     242           0 :     if( ((n*(n-1))/2)>numBaseline_){
     243           0 :       Error(SERIOUS, 
     244             :             (char *) "Cannot find a baselineNum with the antenna indices %d and %d",
     245             :             na1,na2);
     246           0 :       return -1;
     247             :     }
     248           0 :     int m = 0;
     249           0 :     for(int n=1; n<jNum-1; n++)m=m+n;
     250           0 :     return m+iNum;         // the returned index, a "num", is 1 based.         
     251             :   }          
     252             : }                
     253             : 
     254             : 
     255           0 : bool BaselineMetadata::notFor(bool interfero){
     256           0 :   if(interfero){
     257           0 :     if(correlationMode_==1){
     258           0 :       Error(WARNING,
     259             :             (char *) " The baseline metadata were build for single-dish; queries not expected for interferomtry!");
     260           0 :       return true;
     261             :     }
     262             :   }else{
     263             :     /* There are now, even in this correlation mode 0, antenna-based metadata (since 3Apr06) 
     264             :     if(correlationMode_==0){
     265             :       cout<<"ERROR: shaped for pure interferometric metadata; query failed!"<<endl;
     266             :       return true;
     267             :     }
     268             :     */
     269             :   }
     270           0 :   return false;
     271             : }
     272             : 
     273           0 : bool BaselineMetadata::wrongBasebandNum(int basebandNum){
     274           0 :   if(basebandNum<numBaseband_)return false;
     275             :   else
     276           0 :     Error(SERIOUS,
     277             :           (char *) "The input baseband number, %d, exceeds the number of baseband %d in the configuration",
     278             :           basebandNum,numBaseband_);
     279           0 :   if(basebandNum<1)
     280           0 :     Error(FATAL,
     281             :           (char *) "A baseband number must be one-based");
     282           0 :   return true;
     283             : } 
     284             : 
     285           0 : bool BaselineMetadata::wrongAntennaIndex(int anti){
     286           0 :   if(anti<0){
     287           0 :     Error(WARNING, (char *) "An antenna index must be a non-negative integer!");
     288           0 :     return true;
     289             :   }
     290           0 :   if(anti>=numAnt_){
     291           0 :     Error(WARNING, (char *) "Wrong antenna index; it must be < %d; query failed!",numAnt_);
     292           0 :     return true;
     293             :   }
     294           0 :   return false;
     295             : } 
     296             : 
     297           0 : bool BaselineMetadata::wrongBasebandIndex(int bb){
     298           0 :   if(bb<0){
     299           0 :     Error(WARNING, (char *) "A baseband index must be a non-negative integer!");
     300           0 :     return true;
     301             :   }
     302           0 :   if(bb>=numBaseband_){
     303           0 :     Error(WARNING, (char *) "Wrong baseband index: it must be < %d; query failed!",numBaseband_);
     304           0 :     return true;
     305             :   }
     306           0 :   return false;
     307             : } 
     308             : 
     309           0 : bool BaselineMetadata::wrongPolProductIndex(int pp,int bb,int i,int j){
     310             : 
     311           0 :   if(wrongAntennaIndex(i))return true;
     312           0 :   if(wrongAntennaIndex(j))return true;
     313           0 :   if(wrongBasebandIndex(bb))return true;
     314           0 :   if(pp<0){
     315           0 :     Error(WARNING, (char *) "A polProduct index must be a non-negative integer!");
     316           0 :     return true;
     317             :   }
     318           0 :   if(i==j){
     319           0 :     if(pp>=v_numAutoPolProduct_[bb]){
     320           0 :       Error(WARNING, (char *) "Wrong polProduct index: it must be < %d; query failed!",v_numAutoPolProduct_[bb]);
     321           0 :       return true;
     322             :     }
     323             :   }else{
     324           0 :     if(pp>=v_numPolProduct_[bb]){
     325           0 :       Error(WARNING, (char *) "Wrong polProduct index: it must be < %d; query failed!",v_numPolProduct_[bb]);
     326           0 :       return true;
     327             :     }
     328             :   }
     329           0 :   return false;
     330             : }
     331             : 
     332             : 
     333           0 : void BaselineMetadata::display(){
     334           0 :   if(numAnt_){                        // with single-dish
     335           0 :     for(int n=0; n<numBaseband_; n++)
     336           0 :       cout <<"Baseband num.: "     << n+1
     337           0 :            <<"  Nb pol.: "         << v_numPolProduct_[n] 
     338           0 :            <<"  Nb sd pol.: "      << v_numAutoPolProduct_[n] 
     339           0 :            <<"  Nb bins: "         << v_numBin_[n] 
     340           0 :            <<"  Nb ant.: "         << numAnt_
     341           0 :            <<"  Nb baselines: "    << numBaseline_ << endl;
     342             : 
     343             :   }else{                              // pure interfero
     344           0 :     for(int n=0; n<numBaseband_; n++)
     345           0 :       cout <<"Baseband num.: "     << n+1
     346           0 :            <<"  Nb pol. product: " << v_numPolProduct_[n] 
     347           0 :            <<"  Nb bins: "         << v_numBin_[n] 
     348           0 :            <<"  Nb ant.: "         << numAnt_
     349           0 :            <<"  Nb baselines: "    << numBaseline_ << endl;
     350             :   }  
     351           0 : }

Generated by: LCOV version 1.16