[1984] | 1 | //////////////////////////
|
---|
| 2 | // gph425_ring.cc //
|
---|
| 3 | //////////////////////////
|
---|
| 4 |
|
---|
| 5 | //*******************************************************
|
---|
| 6 |
|
---|
| 7 | #include <iostream.h>
|
---|
| 8 | #include <stdlib.h>
|
---|
| 9 | //#include <strstream.h>
|
---|
| 10 | #include <string>
|
---|
| 11 | #include <stdio.h>
|
---|
| 12 | #include <vector>
|
---|
| 13 |
|
---|
| 14 | #include "toi.h"
|
---|
| 15 | #include "toisegment.h"
|
---|
| 16 | //#include "toiseqbuff.h"
|
---|
| 17 | #include "nooppr.h"
|
---|
| 18 | #include "toiprocessor.h"
|
---|
| 19 | #include "fitstoirdr.h"
|
---|
| 20 | #include "fitstoiwtr.h"
|
---|
| 21 | #include "toimanager.h"
|
---|
| 22 | #include "datacards.h"
|
---|
| 23 | #include "fitsfile.h"
|
---|
| 24 | #include "sophyainit.h"
|
---|
| 25 | #include "toiseqbuff.h"
|
---|
| 26 | #include "timing.h"
|
---|
| 27 | #include "sambainit.h"
|
---|
| 28 | #include "fitsspherehealpix.h"
|
---|
| 29 | #include "ring33.h"
|
---|
| 30 | #include "Bolos2ring.h"
|
---|
| 31 | #include "PSB2ring.h"
|
---|
| 32 |
|
---|
| 33 | #include <stdexcept>
|
---|
| 34 |
|
---|
| 35 | int main(int argc, char* argv[])
|
---|
| 36 | {
|
---|
| 37 | cout << "Starting Simple Ring Making ..." << endl;
|
---|
| 38 |
|
---|
| 39 | try {
|
---|
| 40 |
|
---|
| 41 | SophyaInit();
|
---|
| 42 | InitTim();
|
---|
| 43 |
|
---|
| 44 | char str[80];
|
---|
| 45 |
|
---|
| 46 | TOIManager* mgr = TOIManager::getManager();
|
---|
| 47 | int wsize = 512; /// Segment size for TOISegmented
|
---|
| 48 |
|
---|
| 49 | /// One command line argument: the filename of the datacard.
|
---|
| 50 | if( argc < 2 )
|
---|
| 51 | {
|
---|
| 52 | cout << "Need a parameter file!! " << endl;
|
---|
| 53 | exit(-1);
|
---|
| 54 | }
|
---|
| 55 | DataCards param(argv[1]);
|
---|
| 56 |
|
---|
| 57 |
|
---|
| 58 | int_8 PSB = param.IParam("METHOD_PSB_diff");
|
---|
| 59 | int_8 COMBI = param.IParam("METHOD_BOLOS_combi");
|
---|
| 60 |
|
---|
| 61 | if ((PSB + COMBI <= 0) || (PSB + COMBI >= 2))
|
---|
| 62 | {
|
---|
| 63 | cout << "METHOD should be PSB_DIFF or BOLOS_COMBI" << endl;
|
---|
| 64 | exit(-1);
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | cout << endl << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
|
---|
| 68 | if(PSB==1) cout << "!!!!!!!!!!!!!! METHOD PSB_DIFF !!!!!!!!!!!!!!!!!" << endl;
|
---|
| 69 | else cout << "!!!!!!!!!!!!!! METHOD BOLOS_combi !!!!!!!!!!!!!!" << endl;
|
---|
| 70 | cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl << endl;
|
---|
| 71 |
|
---|
| 72 | int_4 Bolos_OK[4];
|
---|
| 73 | int nbbolos_ok=0;
|
---|
| 74 |
|
---|
| 75 | if (PSB==0) {
|
---|
| 76 | for(int i=0; i<4; i++) {
|
---|
| 77 | sprintf(str,"BOLOS_OK_%d",i);
|
---|
| 78 | Bolos_OK[i] = param.IParam(str);
|
---|
| 79 | if (Bolos_OK[i] >=1 ) nbbolos_ok ++;
|
---|
| 80 | }
|
---|
| 81 | if (nbbolos_ok <3) {
|
---|
| 82 | cout << "At least 3 Bolos must be used : " << Bolos_OK [0] << " "
|
---|
| 83 | << Bolos_OK[1] << " "<< Bolos_OK[2] << " "<< Bolos_OK[3] << " "<< endl;
|
---|
| 84 | exit(-1);
|
---|
| 85 | } else
|
---|
| 86 | cout << nbbolos_ok << " Bolos OK : " << Bolos_OK[0] << " "
|
---|
| 87 | << Bolos_OK[1] << " "<< Bolos_OK[2] << " "<< Bolos_OK[3] << " "<< endl;
|
---|
| 88 |
|
---|
| 89 | } else Bolos_OK[0]=Bolos_OK[1]=Bolos_OK[2]=Bolos_OK[3]=1;
|
---|
| 90 |
|
---|
| 91 |
|
---|
| 92 | /// Nside : parameter for HEALPix ring
|
---|
| 93 | int_4 Nside = param.IParam("Nside", 0, 128);
|
---|
| 94 |
|
---|
| 95 | /// The rings to create (Q,U and weight ring)
|
---|
| 96 | SphereHEALPix<r_8>* ringQ = new SphereHEALPix<r_8>(Nside);
|
---|
| 97 | SphereHEALPix<r_8>* ringU = new SphereHEALPix<r_8>(Nside);
|
---|
| 98 | SphereHEALPix<r_8>* ringQW = new SphereHEALPix<r_8>(Nside);
|
---|
| 99 | SphereHEALPix<r_8>* ringUW = new SphereHEALPix<r_8>(Nside);
|
---|
| 100 |
|
---|
| 101 | int_8 snb = param.IParam("SN_Start", 0);
|
---|
| 102 | int_8 sne = param.IParam("SN_End", 0);
|
---|
| 103 |
|
---|
| 104 | /// Define start and end sample number to treat
|
---|
| 105 | mgr->setRequestedSample(snb,sne);
|
---|
| 106 | cout << "SampleNumbers from " << snb << " to " << sne << endl;
|
---|
| 107 |
|
---|
| 108 | vector<string> file_pointing(2);
|
---|
| 109 | vector<string> theta_pointing(2);
|
---|
| 110 | vector<string> phi_pointing(2);
|
---|
| 111 | vector<string> file_bolo(4);
|
---|
| 112 | vector<string> name_bolo(4);
|
---|
| 113 | vector<r_8> table_angle(4);
|
---|
| 114 | string toiqfile = param.SParam("FILE_TOI_Q",0,"toiQ.fits");
|
---|
| 115 | string toiufile = param.SParam("FILE_TOI_U",0,"toiU.fits");
|
---|
| 116 | string ringqfile = param.SParam("FILE_RING_Q",0,"ringQ.fits");
|
---|
| 117 | string ringufile = param.SParam("FILE_RING_U",0,"ringU.fits");
|
---|
| 118 | string ringqwfile = param.SParam("FILE_RING_WQ",0,"ringQW.fits");
|
---|
| 119 | string ringuwfile = param.SParam("FILE_RING_WU",0,"ringUW.fits");
|
---|
| 120 | if (PSB == 1) cout << "Output toi files " << toiqfile << " " << toiufile <<endl;
|
---|
| 121 | cout << "Output ring files " << ringqfile << " " << ringufile <<endl;
|
---|
| 122 | cout << "Output weights files " << ringqwfile << " " << ringuwfile <<endl;
|
---|
| 123 |
|
---|
| 124 |
|
---|
| 125 | int i,j;
|
---|
| 126 | for(i=0; i<2; i++ ) {
|
---|
| 127 | sprintf(str,"FILE_POINT_%d",i);
|
---|
| 128 | file_pointing[i] = param.SParam(str, 0);
|
---|
| 129 | cout << "Pointing file " << i << ": " << file_pointing[i] << endl;
|
---|
| 130 |
|
---|
| 131 | sprintf(str,"NAME_POINT_%d_theta",i);
|
---|
| 132 | theta_pointing[i] = param.SParam(str, 0);
|
---|
| 133 | cout << "Pointing theta " << i << ": " << theta_pointing[i] << endl;
|
---|
| 134 |
|
---|
| 135 | sprintf(str,"NAME_POINT_%d_phi",i);
|
---|
| 136 | phi_pointing[i] = param.SParam(str, 0);
|
---|
| 137 | cout << "Pointing phi " << i << ": " << phi_pointing[i] << endl;
|
---|
| 138 |
|
---|
| 139 | for(j=0; j<2; j++ ) if (Bolos_OK[2*i+j]) {
|
---|
| 140 |
|
---|
| 141 | sprintf(str,"FILE_PSB%d_BOLO%d",i,j);
|
---|
| 142 | file_bolo[i*2+j] = param.SParam(str, 0);
|
---|
| 143 | cout << "bolo file " << i*2+j << ": " << file_bolo[i*2+j] << endl;
|
---|
| 144 |
|
---|
| 145 | sprintf(str,"NAME_PSB%d_BOLO%d",i,j);
|
---|
| 146 | name_bolo[i*2+j] = param.SParam(str, 0);
|
---|
| 147 | cout << "bolo name " << i*2+j << ": " << name_bolo[i*2+j] << endl;
|
---|
| 148 |
|
---|
| 149 | sprintf(str,"ANGLE_PSB%d_BOLO%d",i,j);
|
---|
| 150 | table_angle[i*2+j] = param.DParam(str, 0);
|
---|
| 151 | cout << "Angle " << i*2+j << ": " << table_angle[i*2+j] << endl;
|
---|
| 152 | }
|
---|
| 153 | }
|
---|
| 154 |
|
---|
| 155 | PSB2ring psb2ring(ringQ, ringU, ringQW, ringUW, table_angle, wsize);
|
---|
| 156 | Bolos2ring bolos2ring(ringQ, ringU, ringQW, ringUW, table_angle, Bolos_OK, wsize);
|
---|
| 157 |
|
---|
| 158 | // 1- pointage
|
---|
| 159 | vector<FITSTOIReader*> pt(2);
|
---|
| 160 | for(i=0; i<2; i++)
|
---|
| 161 | {
|
---|
| 162 | pt[i] = new FITSTOIReader(file_pointing[i]);
|
---|
| 163 | pt[i]->setImplicitSN(long(0));
|
---|
| 164 | cout << "Opening pointing file " << file_pointing[i] << endl;
|
---|
| 165 | }
|
---|
| 166 | // 2- les Bolos
|
---|
| 167 | vector<FITSTOIReader*> bolo(4);
|
---|
| 168 | for(i=0; i<4; i++) if (Bolos_OK[i])
|
---|
| 169 | {
|
---|
| 170 | bolo[i] = new FITSTOIReader(file_bolo[i]);
|
---|
| 171 | bolo[i]->setImplicitSN(long(0));
|
---|
| 172 | cout << "Opening bolometer signal file " << file_bolo[i] << endl;
|
---|
| 173 | }
|
---|
| 174 |
|
---|
| 175 | // Creation des tubes:
|
---|
| 176 | // 1- du pointage vers Bolos2ringQU
|
---|
| 177 | // chaque fichier de pointage envoie 2 donnees au processor
|
---|
| 178 | vector<TOI*> toi_pt_theta(2);
|
---|
| 179 | vector<TOI*> toi_pt_phi(2);
|
---|
| 180 | for(i=0; i<2; i++)
|
---|
| 181 | {
|
---|
| 182 | cout << "Creation des pipes pour Pointage " << i << endl;
|
---|
| 183 |
|
---|
| 184 | sprintf(str,"toi_theta_%d",i);
|
---|
| 185 | toi_pt_theta[i] = new TOISegmented(str,wsize);
|
---|
| 186 |
|
---|
| 187 | sprintf(str,"toi_phi_%d",i);
|
---|
| 188 | toi_pt_phi[i] = new TOISegmented(str,wsize);
|
---|
| 189 |
|
---|
| 190 | pt[i]->addOutput(theta_pointing[i], toi_pt_theta[i]);
|
---|
| 191 | pt[i]->addOutput(phi_pointing[i], toi_pt_phi[i]);
|
---|
| 192 |
|
---|
| 193 | sprintf(str,"theta_pointing%d",i);
|
---|
| 194 | if (PSB == 1) psb2ring.addInput(str, toi_pt_theta[i]);
|
---|
| 195 | else bolos2ring.addInput(str, toi_pt_theta[i]);
|
---|
| 196 | sprintf(str,"phi_pointing%d",i);
|
---|
| 197 | if (PSB == 1) psb2ring.addInput(str, toi_pt_phi[i]);
|
---|
| 198 | else bolos2ring.addInput(str, toi_pt_phi[i]);
|
---|
| 199 | }
|
---|
| 200 | // 2- les Bolos
|
---|
| 201 | vector<TOI*> toi_bolo(4);
|
---|
| 202 | for(i=0; i<4; i++) {
|
---|
| 203 |
|
---|
| 204 | sprintf(str,"toi_%d",i);
|
---|
| 205 |
|
---|
| 206 | if (Bolos_OK[i]) {
|
---|
| 207 | toi_bolo[i] = new TOISegmented(str,wsize); // creation des tuyaux
|
---|
| 208 | bolo[i]->addOutput(name_bolo[i], toi_bolo[i]); // assemblage sortie de Bolos
|
---|
| 209 |
|
---|
| 210 | } else {
|
---|
| 211 | NoOpProcessor noop;
|
---|
| 212 | noop.addOutput(name_bolo[i],toi_bolo[i] );
|
---|
| 213 | }
|
---|
| 214 |
|
---|
| 215 | sprintf(str,"Bolo%d",i);
|
---|
| 216 | if (PSB == 1) psb2ring.addInput(str, toi_bolo[i]); // assemblage entree de Bolos2ringQU
|
---|
| 217 | else bolos2ring.addInput(str, toi_bolo[i]);
|
---|
| 218 | }
|
---|
| 219 |
|
---|
| 220 | // Maintenant, le traitement est termine, et on doit avoir recupere
|
---|
| 221 | // les cartes de Q et U dans ringQ et ringU.
|
---|
| 222 | // Il n'y a plus qu'a ecrire ces cartes sur le disque:
|
---|
| 223 |
|
---|
| 224 | // TOI
|
---|
| 225 | FITSTOIWriter wtoiU(toiufile),wtoiQ(toiqfile);
|
---|
| 226 | wtoiU.setImplicitSN();
|
---|
| 227 | wtoiQ.setImplicitSN();
|
---|
| 228 | cout << "fits toi writer created" << endl;
|
---|
| 229 |
|
---|
| 230 | TOISegmented * toioutQ = new TOISegmented("toi_outQ",wsize);
|
---|
| 231 | TOISegmented * toioutU = new TOISegmented("toi_outU",wsize);
|
---|
| 232 | if (PSB == 1) {
|
---|
| 233 | psb2ring.addOutput("out_toiQ",toioutQ);
|
---|
| 234 | psb2ring.addOutput("out_toiU",toioutU);
|
---|
| 235 | wtoiQ.addInput("power",toioutQ);
|
---|
| 236 | wtoiU.addInput("power",toioutU);
|
---|
| 237 | cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
|
---|
| 238 |
|
---|
| 239 | }
|
---|
| 240 |
|
---|
| 241 |
|
---|
| 242 |
|
---|
| 243 | // L'assemblage est termine : il reste a lancer les Processors
|
---|
| 244 | cout << "Starting all processors..." << endl;
|
---|
| 245 |
|
---|
| 246 | for(i=0; i<2; i++) pt[i]->start();
|
---|
| 247 | for(i=0; i<4; i++) bolo[i]->start();
|
---|
| 248 | if (PSB == 1) {
|
---|
| 249 | psb2ring.start();
|
---|
| 250 | wtoiU.start();
|
---|
| 251 | wtoiQ.start();
|
---|
| 252 | }
|
---|
| 253 | else bolos2ring.start();
|
---|
| 254 |
|
---|
| 255 | cout << "Joining ..." << endl;
|
---|
| 256 | mgr->joinAll();
|
---|
| 257 | PrtTim("End threads");
|
---|
| 258 |
|
---|
| 259 |
|
---|
| 260 | // Write rings in FITS files
|
---|
| 261 | FitsOutFile qfits(ringqfile,FitsFile::clear);
|
---|
| 262 | cout<<"gph524_ring: Creating sphere fits file "<<ringqfile<<endl;
|
---|
| 263 | qfits << *ringQ;
|
---|
| 264 | FitsOutFile ufits(ringufile,FitsFile::clear);
|
---|
| 265 | cout<<"gph524_ring: Creating sphere fits file "<<ringufile<<endl;
|
---|
| 266 | ufits << *ringU;
|
---|
| 267 |
|
---|
| 268 | FitsOutFile qwfits(ringqwfile,FitsFile::clear);
|
---|
| 269 | cout<<"gph524_ring: Creating sphere fits file "<<ringqwfile<<endl;
|
---|
| 270 | qwfits << *ringQW;
|
---|
| 271 | FitsOutFile uwfits(ringuwfile,FitsFile::clear);
|
---|
| 272 | cout<<"gph524_ring: Creating sphere fits file "<<ringuwfile<<endl;
|
---|
| 273 | uwfits << *ringUW;
|
---|
| 274 |
|
---|
| 275 | // Nettoyage
|
---|
| 276 | cout << "gph524_ring: cleanup " << endl;
|
---|
| 277 | delete ringQ; delete ringU;
|
---|
| 278 | delete ringQW; delete ringUW;
|
---|
| 279 |
|
---|
| 280 | return(0);
|
---|
| 281 | }
|
---|
| 282 | catch(PThrowable & exc )
|
---|
| 283 | {
|
---|
| 284 | cerr << " Catched Exception " << (string)typeid(exc).name()
|
---|
| 285 | << " - Msg= " << exc.Msg() << endl;
|
---|
| 286 | }
|
---|
| 287 | catch(...)
|
---|
| 288 | {
|
---|
| 289 | cerr << " Catched another exception..." << endl ;
|
---|
| 290 | }
|
---|
| 291 |
|
---|
| 292 | }
|
---|
| 293 |
|
---|
| 294 |
|
---|
| 295 |
|
---|
| 296 |
|
---|