| 1 | /* Lecteur Fits de bolometre */
 | 
|---|
| 2 | #include "sopnamsp.h"
 | 
|---|
| 3 | #include "machdefs.h"
 | 
|---|
| 4 | #include <stdlib.h>
 | 
|---|
| 5 | #include <stdio.h>
 | 
|---|
| 6 | #include "pexceptions.h"
 | 
|---|
| 7 | #include "fboloread.h"
 | 
|---|
| 8 | 
 | 
|---|
| 9 | #define _NCOL_BOLO_MIN_ 5
 | 
|---|
| 10 | 
 | 
|---|
| 11 | /*!
 | 
|---|
| 12 |   \class SOPHYA::FitsBoloRead
 | 
|---|
| 13 |   \ingroup FitsIOServer
 | 
|---|
| 14 |   Class for defining a bolometer by connecting columns out FITS files
 | 
|---|
| 15 |   \verbatim
 | 
|---|
| 16 |   -- Exemple:
 | 
|---|
| 17 |   FitsBoloRead fbr(blen,bsens);
 | 
|---|
| 18 |   fbr.SetDebug(2);
 | 
|---|
| 19 | 
 | 
|---|
| 20 |   fbr.SetBolo("bolomuv","bolo.fits",0);
 | 
|---|
| 21 |   fbr.SetFlag("flag");
 | 
|---|
| 22 |   fbr.SetSNum("samplenum");
 | 
|---|
| 23 |   fbr.SetAlpha("alpha","alpha.fits",0);
 | 
|---|
| 24 |   fbr.SetDelta("delta");
 | 
|---|
| 25 |   int col1 = fbr.AddCol("altitude","other_file.fits");
 | 
|---|
| 26 |   fbr.Print(2);
 | 
|---|
| 27 |   cout<<"NRows= "<<fbr.GetNbLine()<<endl;
 | 
|---|
| 28 | 
 | 
|---|
| 29 |   cout<<"Reading element by elements"<<endl;
 | 
|---|
| 30 |   for(LONGLONG i=0; i<fbr.GetNbLine(); i++) {
 | 
|---|
| 31 |     double a = fbr.GetAlpha(i);
 | 
|---|
| 32 |     double d = fbr.GetDelta(i);
 | 
|---|
| 33 |     double b = fbr.GetBolo(i);
 | 
|---|
| 34 |     double s = fbr.GetSNum(i);
 | 
|---|
| 35 |     double f = fbr.GetFlag(i);
 | 
|---|
| 36 |     double c1 = fbr.GetCol(col1,i);
 | 
|---|
| 37 |     cout<<i<<" s="<<(long long)s<<" b="<<b<<" f="<<f
 | 
|---|
| 38 |         <<" a="<<a<<" d="<<d<<" c1="c1<<endl;
 | 
|---|
| 39 |   }
 | 
|---|
| 40 | 
 | 
|---|
| 41 |   cout<<"Reading with vectors"<<endl;
 | 
|---|
| 42 |   TVector<double> Va,Vd,Vb,Vf;
 | 
|---|
| 43 |   TVector<float> Vc1;
 | 
|---|
| 44 |   TVector<int_4> Vs;
 | 
|---|
| 45 |   for(LONGLONG i=0, istep=1000; i<fbr.GetNbLine(); i+=istep) {
 | 
|---|
| 46 |     LONGLONG i2=i+istep-1; if(i2>=fbr.GetNbLine()) i2=fbr.GetNbLine()-1;
 | 
|---|
| 47 |     fbr.GetSNum(i,i2,Vs);
 | 
|---|
| 48 |     fbr.GetBolo(i,i2,Vb);
 | 
|---|
| 49 |     fbr.GetFlag(i,i2,Vf);
 | 
|---|
| 50 |     fbr.GetAlpha(i,i2,Va);
 | 
|---|
| 51 |     fbr.GetDelta(i,i2,Vd);
 | 
|---|
| 52 |     fbr.GetCol(col1,i,i2,Vc1);
 | 
|---|
| 53 |   }
 | 
|---|
| 54 |   \endverbatim
 | 
|---|
| 55 | */
 | 
|---|
| 56 | 
 | 
|---|
| 57 | //////////////////////////////////////////////////////////////
 | 
|---|
| 58 | /*!
 | 
|---|
| 59 |   Constructor. Define the structure of the bolometer columns connector.
 | 
|---|
| 60 |   \param blen : read buffer length
 | 
|---|
| 61 |   \param bsens : buffer reading direction
 | 
|---|
| 62 |   \verbatim
 | 
|---|
| 63 |   - bsens>0    read forward
 | 
|---|
| 64 |     bsens<0    read backward
 | 
|---|
| 65 |     bsens==0   read centered
 | 
|---|
| 66 |   \endverbatim
 | 
|---|
| 67 | */
 | 
|---|
| 68 | FitsBoloRead::FitsBoloRead(long blen,long bsens)
 | 
|---|
| 69 |   : NBline(0), DbgLevel(0), BuffLen(blen), BuffSens(bsens)
 | 
|---|
| 70 | {
 | 
|---|
| 71 |   for(int i=0;i<_NCOL_BOLO_MIN_;i++) {
 | 
|---|
| 72 |     mFName.push_back("");
 | 
|---|
| 73 |     mLabel.push_back("");
 | 
|---|
| 74 |     mHDU.push_back(0);
 | 
|---|
| 75 |     mFABT.push_back(NULL);
 | 
|---|
| 76 |   }
 | 
|---|
| 77 | }
 | 
|---|
| 78 | 
 | 
|---|
| 79 | /*! Destructor */
 | 
|---|
| 80 | FitsBoloRead::~FitsBoloRead(void)
 | 
|---|
| 81 | {
 | 
|---|
| 82 |  for(int i=0; i<(int)mFABT.size(); i++)
 | 
|---|
| 83 |    if(mFABT[i]!=NULL) {delete mFABT[i]; mFABT[i]=NULL;}
 | 
|---|
| 84 |  // NBline=0; mFABT.resize(_NCOL_BOLO_MIN_);
 | 
|---|
| 85 | }
 | 
|---|
| 86 | 
 | 
|---|
| 87 | //////////////////////////////////////////////////////////////
 | 
|---|
| 88 | /*!
 | 
|---|
| 89 |  Add the column number "col" to the bolometer connector.
 | 
|---|
| 90 |  Protected method. Do not use directly but read the doc.
 | 
|---|
| 91 |  \param col : number of the column to be added
 | 
|---|
| 92 |  \param label : label of the column
 | 
|---|
| 93 |  \param fname : FITS file name containing the column
 | 
|---|
| 94 |  \param ihdu : FITS HDU containing the column
 | 
|---|
| 95 |  \verbatim
 | 
|---|
| 96 |  - col<0     : add a new column
 | 
|---|
| 97 |    col<size  : fill a new column
 | 
|---|
| 98 |    col>=size : throw exception
 | 
|---|
| 99 |  - The method also set the number of rows of the Bolometer connector
 | 
|---|
| 100 |    as the smallest number of rows of the connected columns.
 | 
|---|
| 101 |    That could be changed by using the SetNbLine() method.
 | 
|---|
| 102 |  -----------------------------------------------------------------
 | 
|---|
| 103 |  It is very boring to define all the fits file names and hdu for
 | 
|---|
| 104 |    the predefined TOI SNum,Bolo,Flag,Alpha,Delta as some of them
 | 
|---|
| 105 |    are in the same FITS file (and HDU).
 | 
|---|
| 106 |  The connector pre-defined a logic as follow:
 | 
|---|
| 107 |  ... if fname_Bolo=="" try fname_SNum
 | 
|---|
| 108 |  ... if fname_SNum=="" try fname_Bolo
 | 
|---|
| 109 |  ... if fname_Flag=="" try fname_Bolo first
 | 
|---|
| 110 |  ...                       fname_SNum second.
 | 
|---|
| 111 |  ... if fname_Alpha=="" try fname_Delta first
 | 
|---|
| 112 |  ...                        fname_Bolo second
 | 
|---|
| 113 |  ...                        fname_SNum third
 | 
|---|
| 114 |  ... if fname_Delta=="" try fname_Alpha first
 | 
|---|
| 115 |  ...                        fname_Bolo second
 | 
|---|
| 116 |  ...                        fname_SNum third
 | 
|---|
| 117 |  Of course, the decision differs depending on the order
 | 
|---|
| 118 |    of calling the addcol() method.
 | 
|---|
| 119 |  -----------------------------------------------------------------
 | 
|---|
| 120 |  \endverbatim
 | 
|---|
| 121 |  \warning ihdu[1,nhdu], col=[0,nrow-1]
 | 
|---|
| 122 |  \return The number of the column added in the FitsBoloRead connector.
 | 
|---|
| 123 | */
 | 
|---|
| 124 | int FitsBoloRead::addcol(int col,const char *label,const char* fname,int ihdu)
 | 
|---|
| 125 | {
 | 
|---|
| 126 |  if(col>=(int)mFABT.size()) // Not an existing column
 | 
|---|
| 127 |    throw ParmError("FitsBoloRead::addcol: column number not existing\n");
 | 
|---|
| 128 | 
 | 
|---|
| 129 |  if(col>=0) {  // Already filled column
 | 
|---|
| 130 |    if(mFABT[col]!=NULL) {delete mFABT[col]; mFABT[col]=NULL;}
 | 
|---|
| 131 |  } else {      // Prepare for new column
 | 
|---|
| 132 |    col=mFABT.size();
 | 
|---|
| 133 |    mFName.push_back("");
 | 
|---|
| 134 |    mLabel.push_back("");
 | 
|---|
| 135 |    mHDU.push_back(0);
 | 
|---|
| 136 |    mFABT.push_back(NULL);
 | 
|---|
| 137 |  }
 | 
|---|
| 138 | 
 | 
|---|
| 139 |  if(fname) mFName[col] = fname; else mFName[col] = "";
 | 
|---|
| 140 |  mLabel[col] = label;
 | 
|---|
| 141 |  mHDU[col]   = ihdu;
 | 
|---|
| 142 |  // Try to guess the fname and ihdu if not defined
 | 
|---|
| 143 |  Gess_If_Not_Define(col);
 | 
|---|
| 144 | 
 | 
|---|
| 145 |  mFABT[col] =
 | 
|---|
| 146 |    new FitsABTColRead(mFName[col].c_str(),mLabel[col].c_str()
 | 
|---|
| 147 |                      ,mHDU[col],BuffLen,BuffSens,(int)DbgLevel);
 | 
|---|
| 148 | 
 | 
|---|
| 149 |  // Set the number of rows as the smallest of for connected columns
 | 
|---|
| 150 |  LONGLONG nrows = mFABT[col]->GetNbLine();
 | 
|---|
| 151 |  if(NBline==0) NBline = nrows;
 | 
|---|
| 152 |  else if(nrows<NBline) NBline = nrows;
 | 
|---|
| 153 | 
 | 
|---|
| 154 |  return col;
 | 
|---|
| 155 | }
 | 
|---|
| 156 | 
 | 
|---|
| 157 | /*!
 | 
|---|
| 158 |   Guess what are the File name and HDU if they are not explicitly defined.
 | 
|---|
| 159 |   (See addcol() doc)
 | 
|---|
| 160 | */
 | 
|---|
| 161 | void FitsBoloRead::Gess_If_Not_Define(int col)
 | 
|---|
| 162 | {
 | 
|---|
| 163 |  if(col<0 || col>=_NCOL_BOLO_MIN_) return; // Pas une colonne predefinie
 | 
|---|
| 164 |  if(mFName[col].size()>0) return; // definition explicite
 | 
|---|
| 165 | 
 | 
|---|
| 166 |  if(col==ColSNum) {            // Cas du Sample Number
 | 
|---|
| 167 |    if(mFName[ColBolo].size()>0)
 | 
|---|
| 168 |      {mFName[col]=mFName[ColBolo]; mHDU[col]=mHDU[ColBolo]; return;}
 | 
|---|
| 169 | 
 | 
|---|
| 170 |  } else if(col==ColBolo) {     // Cas du Bolo
 | 
|---|
| 171 |    if(mFName[ColSNum].size()>0)
 | 
|---|
| 172 |      {mFName[col]=mFName[ColSNum]; mHDU[col]=mHDU[ColSNum]; return;}
 | 
|---|
| 173 | 
 | 
|---|
| 174 |  } else if(col==ColFlag) {     // Cas du Flag
 | 
|---|
| 175 |    if(mFName[ColBolo].size()>0)
 | 
|---|
| 176 |      {mFName[col]=mFName[ColBolo]; mHDU[col]=mHDU[ColBolo]; return;}
 | 
|---|
| 177 |    if(mFName[ColSNum].size()>0)
 | 
|---|
| 178 |      {mFName[col]=mFName[ColSNum]; mHDU[col]=mHDU[ColSNum]; return;}
 | 
|---|
| 179 | 
 | 
|---|
| 180 |  } else if(col==ColAlpha) {    // Cas du Alpha
 | 
|---|
| 181 |    if(mFName[ColDelta].size()>0)
 | 
|---|
| 182 |      {mFName[col]=mFName[ColDelta]; mHDU[col]=mHDU[ColDelta]; return;}
 | 
|---|
| 183 |    if(mFName[ColBolo].size()>0)
 | 
|---|
| 184 |      {mFName[col]=mFName[ColBolo]; mHDU[col]=mHDU[ColBolo]; return;}
 | 
|---|
| 185 |    if(mFName[ColSNum].size()>0)
 | 
|---|
| 186 |      {mFName[col]=mFName[ColSNum]; mHDU[col]=mHDU[ColSNum]; return;}
 | 
|---|
| 187 | 
 | 
|---|
| 188 |  } else if(col==ColDelta) {    // Cas du Delta
 | 
|---|
| 189 |    if(mFName[ColAlpha].size()>0)
 | 
|---|
| 190 |      {mFName[col]=mFName[ColAlpha]; mHDU[col]=mHDU[ColAlpha]; return;}
 | 
|---|
| 191 |    if(mFName[ColBolo].size()>0)
 | 
|---|
| 192 |      {mFName[col]=mFName[ColBolo]; mHDU[col]=mHDU[ColBolo]; return;}
 | 
|---|
| 193 |    if(mFName[ColSNum].size()>0)
 | 
|---|
| 194 |      {mFName[col]=mFName[ColSNum]; mHDU[col]=mHDU[ColSNum]; return;}
 | 
|---|
| 195 |  }
 | 
|---|
| 196 | }
 | 
|---|
| 197 | 
 | 
|---|
| 198 | //////////////////////////////////////////////////////////////
 | 
|---|
| 199 | /*! Set the number of rows for that class, choosing column "col"
 | 
|---|
| 200 |   \param col : number of the column giving the number of rows
 | 
|---|
| 201 |   \verbatim
 | 
|---|
| 202 |   col : <0         set nrows to the smallest of all connected columns
 | 
|---|
| 203 |   col : [0,ncol-1] set nrows to the number of rows of column "col"
 | 
|---|
| 204 |   col : >=ncol     trow exception
 | 
|---|
| 205 |   \endverbatim
 | 
|---|
| 206 |   \warning By default, the number of rows is set to the smallest of all connected columns
 | 
|---|
| 207 | */
 | 
|---|
| 208 | void FitsBoloRead::SetNbLine(int col)
 | 
|---|
| 209 | {
 | 
|---|
| 210 |   if(col>=(int)mFABT.size())  // Bad column number
 | 
|---|
| 211 |    throw ParmError("FitsBoloRead::SetNbLine: bad column number\n");
 | 
|---|
| 212 | 
 | 
|---|
| 213 |  if(col>=0) {  // existing column, return its NbLine
 | 
|---|
| 214 |    if(mFABT[col]==NULL)
 | 
|---|
| 215 |      throw NullPtrError("FitsBoloRead::SetNbLine: column not connected\n");
 | 
|---|
| 216 |    NBline = mFABT[col]->GetNbLine();
 | 
|---|
| 217 |    return;
 | 
|---|
| 218 |  }
 | 
|---|
| 219 | 
 | 
|---|
| 220 |  // take the smallest NbLine for all columns
 | 
|---|
| 221 |  NBline = 0;
 | 
|---|
| 222 |  for(col=0; col<(int)mFABT.size(); col++) {
 | 
|---|
| 223 |    if(mFABT[col]==NULL) continue;
 | 
|---|
| 224 |    LONGLONG nbl = mFABT[col]->GetNbLine();
 | 
|---|
| 225 |    if(nbl==0) continue;
 | 
|---|
| 226 |    if(NBline==0 || nbl<NBline) NBline = nbl;
 | 
|---|
| 227 |  }
 | 
|---|
| 228 | }
 | 
|---|
| 229 | 
 | 
|---|
| 230 | //////////////////////////////////////////////////////////////
 | 
|---|
| 231 | /*! Print */
 | 
|---|
| 232 | void FitsBoloRead::Print(ostream& os,int lp) const
 | 
|---|
| 233 | {
 | 
|---|
| 234 |  os<<"FitsBoloRead::Print: NBline="<<NBline<<" NCol="<<GetNbCol()<<endl;
 | 
|---|
| 235 |  for(int i=0; i<(int)mFABT.size(); i++) {
 | 
|---|
| 236 |    if(mFABT[i]==NULL) {
 | 
|---|
| 237 |       cout<<"...Col "<<i<<" not connected"<<endl;
 | 
|---|
| 238 |       continue;
 | 
|---|
| 239 |    } else {
 | 
|---|
| 240 |      cout<<"--> Col "<<i<<" label="<<mLabel[i]<<" hdu="<<mHDU[i]
 | 
|---|
| 241 |          <<"        FName="<<mFName[i]<<endl;
 | 
|---|
| 242 |      if(lp>0) mFABT[i]->Print(os,lp);
 | 
|---|
| 243 |    }
 | 
|---|
| 244 |  }
 | 
|---|
| 245 | }
 | 
|---|
| 246 | 
 | 
|---|
| 247 | #undef _NCOL_BOLO_MIN_
 | 
|---|