| [1738] | 1 | // ArchTOIPipe           (C)     CEA/DAPNIA/SPP IN2P3/LAL | 
|---|
|  | 2 | //                               Eric Aubourg | 
|---|
|  | 3 | //                               Christophe Magneville | 
|---|
|  | 4 | //                               Reza Ansari | 
|---|
| [1809] | 5 | // $Id: toi2map.cc,v 1.24 2001-12-03 20:38:02 cmv Exp $ | 
|---|
| [1738] | 6 |  | 
|---|
| [1463] | 7 | #include "machdefs.h" | 
|---|
|  | 8 | #include "toimanager.h" | 
|---|
|  | 9 | #include "pexceptions.h" | 
|---|
|  | 10 | #include "ctimer.h" | 
|---|
| [1807] | 11 | #include "toi2map.h" | 
|---|
| [1809] | 12 | // La valeur "Pi" doit etre celle de smathconst.h a cause du test sur theta | 
|---|
|  | 13 | #include "smathconst.h" | 
|---|
| [1463] | 14 |  | 
|---|
|  | 15 | //////////////////////////////////////////////////////////////////////// | 
|---|
| [1806] | 16 | TOI2Map::TOI2Map(PixelMap<r_8>* map,PixelMap<r_8>* wmap) | 
|---|
| [1809] | 17 | : mMap(map), mWMap(wmap), mWMapInternal(false) | 
|---|
| [1463] | 18 | { | 
|---|
| [1516] | 19 | SetEquinox(); | 
|---|
|  | 20 | SetCoorIn(); | 
|---|
| [1809] | 21 | SetCoorMap(); | 
|---|
| [1530] | 22 | SetTestFlag(); | 
|---|
|  | 23 | SetTestMin(); | 
|---|
|  | 24 | SetTestMax(); | 
|---|
| [1516] | 25 |  | 
|---|
| [1804] | 26 | if(mMap->NbPixels()<1) { | 
|---|
| [1806] | 27 | cout<<"TOI2Map::TOI2Map() Bad number of pixels in sphere mMap " | 
|---|
| [1804] | 28 | <<mMap->NbPixels()<<endl; | 
|---|
| [1806] | 29 | throw ParmError("TOI2Map::TOI2Map() - Bad number of pixels in sphere"); | 
|---|
| [1463] | 30 | } | 
|---|
| [1804] | 31 | mMap->SetPixels(0.); | 
|---|
|  | 32 | int nlat = mMap->SizeIndex(); | 
|---|
| [1809] | 33 | string typmap = mMap->TypeOfMap(); | 
|---|
| [1463] | 34 |  | 
|---|
| [1804] | 35 | if(mWMap==NULL) { | 
|---|
|  | 36 | // We would need a cloning function in maps. $$TBD$$ $CHECK$ | 
|---|
|  | 37 | if (typmap == "LOCAL") { | 
|---|
|  | 38 | mWMap = new LocalMap<r_8>(*(LocalMap<r_8>*)mMap); | 
|---|
|  | 39 | } else if (typmap == "RING") { | 
|---|
|  | 40 | mWMap = new SphereHEALPix<r_8>(nlat); | 
|---|
|  | 41 | } else { | 
|---|
| [1806] | 42 | cout << "TOI2Map::TOI2Map() cannot handle map of type " << typmap << endl; | 
|---|
|  | 43 | throw ParmError("TOI2Map::TOI2Map() - bad type of map"); | 
|---|
| [1804] | 44 | } | 
|---|
|  | 45 | mWMapInternal = true; | 
|---|
| [1463] | 46 | } else { | 
|---|
| [1804] | 47 | mWMapInternal = false; | 
|---|
|  | 48 | if(nlat != mWMap->SizeIndex()) { | 
|---|
| [1809] | 49 | cout<<"TOI2Map::TOI2Map() Bad size for sphere mWMap, does not " | 
|---|
|  | 50 | <<"correspond to mMap : "<<mMap->SizeIndex()<<", "<<mWMap->SizeIndex()<<endl; | 
|---|
|  | 51 | if (typmap == "LOCAL") { | 
|---|
|  | 52 | throw ParmError("TOI2Map::TOI2Map() - Different sizes for map and wmap"); | 
|---|
|  | 53 | } else if(typmap == "RING") { | 
|---|
|  | 54 | ((SphereHEALPix<r_8> *)mWMap)->Resize(nlat); | 
|---|
|  | 55 | cout<<"Resize have been done..."<<endl; | 
|---|
|  | 56 | } else { | 
|---|
|  | 57 | cout << "TOI2Map::TOI2Map() cannot handle map of type " << typmap << endl; | 
|---|
|  | 58 | throw ParmError("TOI2Map::TOI2Map() - bad type of map"); | 
|---|
|  | 59 | } | 
|---|
| [1804] | 60 | } | 
|---|
| [1463] | 61 | } | 
|---|
| [1804] | 62 | if(mWMap->NbPixels()<1) { | 
|---|
| [1806] | 63 | cout<<"TOI2Map::TOI2Map() Bad number of pixels in sphere mWMap " | 
|---|
| [1804] | 64 | <<mWMap->NbPixels()<<endl; | 
|---|
| [1806] | 65 | throw ParmError("TOI2Map::TOI2Map() - Bad number of pixels in sphere"); | 
|---|
| [1463] | 66 | } | 
|---|
| [1804] | 67 | mWMap->SetPixels(0); | 
|---|
| [1463] | 68 | } | 
|---|
|  | 69 |  | 
|---|
| [1806] | 70 | TOI2Map::~TOI2Map() | 
|---|
| [1463] | 71 | { | 
|---|
| [1804] | 72 | if(mWMap && mWMapInternal) delete mWMap; | 
|---|
| [1463] | 73 | } | 
|---|
|  | 74 |  | 
|---|
|  | 75 | //////////////////////////////////////////////////////////////////////// | 
|---|
| [1806] | 76 | void TOI2Map::Print(::ostream & os) | 
|---|
| [1530] | 77 | { | 
|---|
| [1809] | 78 | os<<"TOI2Map::Print -- Map type " << mMap->TypeOfMap() << " SizeIndex = "<<mMap->SizeIndex()<<endl | 
|---|
|  | 79 | <<"   - Equinoxe="<<mActualYear<<endl | 
|---|
|  | 80 | <<"   - TypCoorIn:  "<<mTypCoorIn<<" = "<<DecodeTypAstro(mTypCoorIn)<<endl | 
|---|
|  | 81 | <<"   - TypCoorMap: "<<mTypCoorMap<<" = "<<DecodeTypAstro(mTypCoorMap)<<endl | 
|---|
|  | 82 | <<"  - Tests: Flag("<<mTFlag<<") bad="<<mBadFlag | 
|---|
|  | 83 | <<" / Value Min("<<mTMin<<")="<<mValMin | 
|---|
|  | 84 | <<" , Max("<<mTMax<<")="<<mValMax<<endl; | 
|---|
| [1530] | 85 | } | 
|---|
|  | 86 |  | 
|---|
|  | 87 | //////////////////////////////////////////////////////////////////////// | 
|---|
| [1806] | 88 | void TOI2Map::init() { | 
|---|
|  | 89 | cout << "TOI2Map::init" << endl; | 
|---|
| [1498] | 90 | declareInput("Coord1In");     // input index 0 | 
|---|
|  | 91 | declareInput("Coord2In");     // input index 1 | 
|---|
| [1516] | 92 | declareInput("BoloIn");       // input index 2 | 
|---|
| [1463] | 93 | } | 
|---|
|  | 94 |  | 
|---|
|  | 95 | //////////////////////////////////////////////////////////////////////// | 
|---|
| [1746] | 96 | // define SANS_BUFFER | 
|---|
| [1806] | 97 | void TOI2Map::run() | 
|---|
| [1463] | 98 | { | 
|---|
|  | 99 | long snb = getMinIn(); | 
|---|
|  | 100 | long sne = getMaxIn(); | 
|---|
|  | 101 |  | 
|---|
|  | 102 | if(snb>sne) { | 
|---|
| [1806] | 103 | cout<<"TOI2Map::run() - Bad sample interval"<<snb<<" , "<<sne<<endl; | 
|---|
|  | 104 | throw ParmError("TOI2Map::run() - Bad sample interval"); | 
|---|
| [1463] | 105 | } | 
|---|
|  | 106 | if(!checkInputTOIIndex(0) || !checkInputTOIIndex(1) || !checkInputTOIIndex(2)) { | 
|---|
| [1806] | 107 | cout<<"TOI2Map::run() - Input TOI (Coord1In or Coord2In or BoloIn) not connected! "<<endl; | 
|---|
|  | 108 | throw ParmError("TOI2Map::run() Output TOI (Coord1In or Coord2In or BoloIn) not connected!"); | 
|---|
| [1463] | 109 | } | 
|---|
| [1516] | 110 | if( !(mTypCoorIn&TypCoordEq || mTypCoorIn&TypCoordGal) ) { | 
|---|
| [1806] | 111 | cout<<"TOI2Map::run() - Input Coordinates not Eq or Gal! "<<endl; | 
|---|
|  | 112 | throw ParmError("TOI2Map::run() - Input Coordinates not Eq or Gal!"); | 
|---|
| [1516] | 113 | } | 
|---|
| [1809] | 114 | if( !(mTypCoorMap&TypCoordEq || mTypCoorMap&TypCoordGal) ) { | 
|---|
| [1806] | 115 | cout<<"TOI2Map::run() - Output Coordinates not Eq or Gal! "<<endl; | 
|---|
|  | 116 | throw ParmError("TOI2Map::run() - Output Coordinates not Eq or Gal!"); | 
|---|
| [1516] | 117 | } | 
|---|
| [1463] | 118 |  | 
|---|
|  | 119 | //--------------------------------------------------------- | 
|---|
|  | 120 | #define NFILL 25 | 
|---|
|  | 121 | try { | 
|---|
|  | 122 |  | 
|---|
|  | 123 | int ii; | 
|---|
| [1809] | 124 | uint_4 mNSnFill=0, mNpixFill=0, NFill[NFILL], BadCoorRange=0; | 
|---|
| [1463] | 125 | for(ii=0;ii<NFILL;ii++) NFill[ii]=0; | 
|---|
| [1516] | 126 | double mjd = MJDfrYear(mActualYear); | 
|---|
| [1463] | 127 |  | 
|---|
| [1806] | 128 | cout<<"TOI2Map::run() from "<<snb<<" to "<<sne; | 
|---|
| [1746] | 129 | #ifndef SANS_BUFFER | 
|---|
|  | 130 | int bufsz = 100; | 
|---|
|  | 131 | uint_8* bfgbolo = new uint_8[bufsz]; | 
|---|
|  | 132 | double* bbolo   = new double[bufsz]; | 
|---|
|  | 133 | double* bc1     = new double[bufsz]; | 
|---|
|  | 134 | double* bc2     = new double[bufsz]; | 
|---|
|  | 135 | int i0 = -1; | 
|---|
|  | 136 | cout<<" (getData() bufferized)"<<endl; | 
|---|
|  | 137 | #else | 
|---|
|  | 138 | cout<<" (getData() not bufferized)"<<endl; | 
|---|
|  | 139 | #endif | 
|---|
| [1744] | 140 |  | 
|---|
| [1463] | 141 | // Remplissage des spheres | 
|---|
|  | 142 | for(int s=snb;s<=sne;s++) { | 
|---|
| [1536] | 143 | uint_8 fgbolo = 0; | 
|---|
| [1746] | 144 | double bolo,coord1,coord2; | 
|---|
| [1516] | 145 | //              Equatoriales   /   Galactiques | 
|---|
|  | 146 | // coord1,2 =   alpha,delta    /   gLon,gLat | 
|---|
| [1463] | 147 |  | 
|---|
| [1746] | 148 | #ifndef SANS_BUFFER | 
|---|
|  | 149 | if(i0<0 || s<i0 || s>=i0+bufsz) { | 
|---|
|  | 150 | i0 = s; | 
|---|
|  | 151 | int nget = (sne-s+1<bufsz)? nget=sne-s+1: bufsz; | 
|---|
|  | 152 | getData(0,i0,nget,bc1); | 
|---|
|  | 153 | getData(1,i0,nget,bc2); | 
|---|
|  | 154 | getData(2,i0,nget,bbolo,bfgbolo); | 
|---|
|  | 155 | } | 
|---|
|  | 156 | bolo = bbolo[s-i0]; fgbolo = bfgbolo[s-i0]; | 
|---|
|  | 157 | coord1 = bc1[s-i0]; coord2 = bc2[s-i0]; | 
|---|
|  | 158 | #else | 
|---|
|  | 159 | getData(2,s,bolo,fgbolo); | 
|---|
|  | 160 | coord1 = getData(0,s); | 
|---|
|  | 161 | coord2 = getData(1,s); | 
|---|
|  | 162 | #endif | 
|---|
|  | 163 |  | 
|---|
|  | 164 | // Comme il n'y a pas de toi en sortie, il faut dire | 
|---|
|  | 165 | // aux processeur/toi que l'on a plus besoin des donnees. | 
|---|
| [1724] | 166 | if (s%100 == 0) wontNeedBefore(s-1); | 
|---|
| [1530] | 167 | if(mTFlag && fgbolo&mBadFlag) continue; | 
|---|
|  | 168 | if(mTMin && bolo<mValMin) continue; | 
|---|
|  | 169 | if(mTMax && bolo>mValMax) continue; | 
|---|
| [1463] | 170 |  | 
|---|
| [1516] | 171 | // sphere phi   entre [0,2*Pi] en radians | 
|---|
|  | 172 | // sphere theta entre [0,Pi]   en radians | 
|---|
| [1809] | 173 | double phi=-1.; | 
|---|
|  | 174 | CoordConvertToStd(mTypCoorIn,&coord1,&coord2); | 
|---|
| [1786] | 175 |  | 
|---|
| [1809] | 176 | if(mTypCoorIn&TypCoordEq && mTypCoorMap&TypCoordGal) { // Eq -> Gal | 
|---|
| [1516] | 177 | EqtoGal(mjd,coord1,coord2,&coord1,&coord2); | 
|---|
| [1809] | 178 | phi   = coord1 * Pi/180.; | 
|---|
|  | 179 | } else if(mTypCoorIn&TypCoordGal && mTypCoorMap&TypCoordEq) { // Gal -> Eq | 
|---|
| [1516] | 180 | GaltoEq(mjd,coord1,coord2,&coord1,&coord2); | 
|---|
| [1809] | 181 | phi   = coord1 * Pi/12.; | 
|---|
|  | 182 | } else if(mTypCoorMap&TypCoordGal) { // Gal -> Gal | 
|---|
|  | 183 | phi   = coord1 * Pi/180.; | 
|---|
|  | 184 | } else if(mTypCoorMap&TypCoordEq) { // Eq -> Eq | 
|---|
|  | 185 | phi   = coord1 * Pi/12.; | 
|---|
| [1498] | 186 | } | 
|---|
| [1809] | 187 | ToCoLat(&coord2,TypUniteD); | 
|---|
|  | 188 | double theta = coord2 * Pi/180.; | 
|---|
| [1790] | 189 |  | 
|---|
| [1809] | 190 | if(phi<0. | phi>=2*Pi || theta<0. || theta>Pi) | 
|---|
|  | 191 | {BadCoorRange++; continue;} | 
|---|
| [1786] | 192 |  | 
|---|
| [1804] | 193 | int_4 ipix = mMap->PixIndexSph(theta,phi); | 
|---|
|  | 194 | (*mMap)(ipix) += bolo; | 
|---|
|  | 195 | ((*mWMap)(ipix)) += 1; | 
|---|
| [1516] | 196 | mNSnFill++; | 
|---|
| [1463] | 197 | } | 
|---|
|  | 198 |  | 
|---|
| [1806] | 199 | cout<<"TOI2Map::run(): Fin de boucle sur les sampleNum"<<endl; | 
|---|
| [1633] | 200 |  | 
|---|
| [1463] | 201 | // Remplissage des spheres | 
|---|
| [1804] | 202 | for(int_4 i=0;i<mMap->NbPixels();i++) { | 
|---|
|  | 203 | r_8 wf = (*mWMap)(i); | 
|---|
| [1809] | 204 | if(wf>0.) {mNpixFill++; (*mMap)(i) /= wf;} | 
|---|
| [1463] | 205 | int_4 nf = int_4(wf); | 
|---|
|  | 206 | if(nf>=NFILL) nf=NFILL-1; NFill[nf]++; | 
|---|
|  | 207 | } | 
|---|
|  | 208 |  | 
|---|
| [1806] | 209 | cout<<"TOI2Map::run(): mNpixTot="<<mMap->NbPixels() | 
|---|
| [1463] | 210 | <<"  mNpixFill="<<mNpixFill | 
|---|
|  | 211 | <<"  mNSnFill="<<mNSnFill<<endl | 
|---|
| [1804] | 212 | <<"  --> FracSky="<<mNpixFill*100./(double)mMap->NbPixels()<<"%" | 
|---|
| [1516] | 213 | <<"  NFill["<<NFILL<<"] ="<<endl; | 
|---|
|  | 214 | for(ii=0;ii<NFILL;ii++) {cout<<NFill[ii]<<" "; if(ii%10==9) cout<<endl;} | 
|---|
| [1463] | 215 | cout<<endl; | 
|---|
| [1809] | 216 | cout<<"  BadCoorRange="<<BadCoorRange<<endl; | 
|---|
| [1463] | 217 |  | 
|---|
| [1746] | 218 | #ifndef SANS_BUFFER | 
|---|
|  | 219 | delete [] bbolo; delete [] bfgbolo; | 
|---|
|  | 220 | delete [] bc1;   delete [] bc2; | 
|---|
|  | 221 | #endif | 
|---|
|  | 222 |  | 
|---|
| [1463] | 223 | //--------------------------------------------------------- | 
|---|
|  | 224 | } catch (PException & exc) { | 
|---|
| [1806] | 225 | cout<<"TOI2Map: Catched Exception "<<(string)typeid(exc).name() | 
|---|
| [1463] | 226 | <<"\n .... Msg= "<<exc.Msg()<<endl; | 
|---|
|  | 227 | } | 
|---|
|  | 228 |  | 
|---|
|  | 229 | return; | 
|---|
|  | 230 | } | 
|---|