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