| 1 | // ArchTOIPipe           (C)     CEA/DAPNIA/SPP IN2P3/LAL | 
|---|
| 2 | //                               Eric Aubourg | 
|---|
| 3 | //                               Christophe Magneville | 
|---|
| 4 | //                               Reza Ansari | 
|---|
| 5 | // $Id: toi2ring.cc,v 1.6 2003-04-17 13:47:34 cecile Exp $ | 
|---|
| 6 |  | 
|---|
| 7 | #include "toimanager.h" | 
|---|
| 8 | #include "pexceptions.h" | 
|---|
| 9 | #include "ctimer.h" | 
|---|
| 10 | #include "toi2ring.h" | 
|---|
| 11 | // La valeur "Pi" doit etre celle de smathconst.h a cause du test sur theta | 
|---|
| 12 | #include "smathconst.h" | 
|---|
| 13 |  | 
|---|
| 14 | //////////////////////////////////////////////////////////////////////// | 
|---|
| 15 | Toi2RING::Toi2RING(long n) | 
|---|
| 16 | :totnscount(0), nRings(0) | 
|---|
| 17 | { | 
|---|
| 18 | setNSamples(n); | 
|---|
| 19 | } | 
|---|
| 20 |  | 
|---|
| 21 | Toi2RING::~Toi2RING() | 
|---|
| 22 | { | 
|---|
| 23 | } | 
|---|
| 24 |  | 
|---|
| 25 |  | 
|---|
| 26 | //////////////////////////////////////////////////////////////////////// | 
|---|
| 27 | void Toi2RING::Print(::ostream & os) | 
|---|
| 28 | { | 
|---|
| 29 | } | 
|---|
| 30 |  | 
|---|
| 31 | //////////////////////////////////////////////////////////////////////// | 
|---|
| 32 | void Toi2RING::init() { | 
|---|
| 33 | cout << "Toi2RING::init" << endl; | 
|---|
| 34 | declareInput("Theta");     // input  index 0 | 
|---|
| 35 | declareInput("Phi");       // input  index 1 | 
|---|
| 36 | declareInput("Phase");     // input  index 2 | 
|---|
| 37 | declareInput("Value");     // input  index 3 | 
|---|
| 38 | declareOutput("Rvalue");   // output index 0 | 
|---|
| 39 | declareOutput("WRvalue");  // output index 1 | 
|---|
| 40 | } | 
|---|
| 41 |  | 
|---|
| 42 | //////////////////////////////////////////////////////////////////////// | 
|---|
| 43 | void Toi2RING::run() { | 
|---|
| 44 |  | 
|---|
| 45 | long snb = getMinIn(); | 
|---|
| 46 | long sne = getMaxIn(); | 
|---|
| 47 | if(snb>sne) { | 
|---|
| 48 | cout<<"Toi2RING::run() - Bad sample interval"<<snb<<" , "<<sne<<endl; | 
|---|
| 49 | throw ParmError("Toi2RING::run() - Bad sample interval"); | 
|---|
| 50 | } | 
|---|
| 51 |  | 
|---|
| 52 | //--------------------------------------------------------- | 
|---|
| 53 | try { | 
|---|
| 54 |  | 
|---|
| 55 |  | 
|---|
| 56 | uint_4 mSnRead=0, mSnFilled=0, BadCoorRange=0; | 
|---|
| 57 | int_8 Nrings=0,i; | 
|---|
| 58 |  | 
|---|
| 59 | double phi_prec=-1.,ctheta_prec,cphi_prec; | 
|---|
| 60 | double phi,val,ctheta,cphi; | 
|---|
| 61 |  | 
|---|
| 62 | double* r = new double[Nsamples]; | 
|---|
| 63 | double* wr = new double[Nsamples]; | 
|---|
| 64 | for(i=0;i<Nsamples;i++) { | 
|---|
| 65 | wr[i]=0; | 
|---|
| 66 | r[i]=0; | 
|---|
| 67 | } | 
|---|
| 68 |  | 
|---|
| 69 | cout << "loop " << snb << " " << sne << endl; | 
|---|
| 70 |  | 
|---|
| 71 | for(int k=snb;k<=sne;k++) { | 
|---|
| 72 |  | 
|---|
| 73 | uint_8 flg = 0; | 
|---|
| 74 | ctheta = getData(0,k); | 
|---|
| 75 | cphi = getData(1,k); | 
|---|
| 76 | phi = getData(2,k); | 
|---|
| 77 | val = getData(3,k); | 
|---|
| 78 | mSnRead++; | 
|---|
| 79 |  | 
|---|
| 80 | i=(int)(phi*Nsamples/360.); | 
|---|
| 81 | r[i]+= val; | 
|---|
| 82 | wr[i]++; | 
|---|
| 83 |  | 
|---|
| 84 |  | 
|---|
| 85 | if(phi < phi_prec || k == sne){ | 
|---|
| 86 |  | 
|---|
| 87 | //  if (k==sne) { wfits.setNRings(Nrings); wwfits.setNRings(Nrings);} | 
|---|
| 88 |  | 
|---|
| 89 | putData(0,Nrings*(Nsamples+2)+0,ctheta_prec); | 
|---|
| 90 | putData(1,Nrings*(Nsamples+2)+0,ctheta_prec); | 
|---|
| 91 | putData(0,Nrings*(Nsamples+2)+1,cphi_prec); | 
|---|
| 92 | putData(1,Nrings*(Nsamples+2)+1,cphi_prec); | 
|---|
| 93 | cout << Nsamples << " !@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" << endl; | 
|---|
| 94 | for(i=0;i<Nsamples;i++) { | 
|---|
| 95 | if(wr[i] == 0) r[i] = -999999.; | 
|---|
| 96 | else r[i] /= wr[i]; | 
|---|
| 97 |  | 
|---|
| 98 | putData(0,Nrings*(Nsamples+2)+2+i,r[i]); | 
|---|
| 99 | putData(1,Nrings*(Nsamples+2)+2+i,wr[i]); | 
|---|
| 100 | wr[i]=0; | 
|---|
| 101 | r[i]=0.; | 
|---|
| 102 |  | 
|---|
| 103 | } | 
|---|
| 104 |  | 
|---|
| 105 | Nrings++; | 
|---|
| 106 | cout <<" Ring "<< Nrings << " written " << endl; | 
|---|
| 107 | } | 
|---|
| 108 | phi_prec=phi; | 
|---|
| 109 | ctheta_prec=ctheta; | 
|---|
| 110 | cphi_prec=cphi; | 
|---|
| 111 | totnscount++; | 
|---|
| 112 | } | 
|---|
| 113 |  | 
|---|
| 114 | cout<<"RING2Toi::run: Samples Read "<<mSnRead | 
|---|
| 115 | <<" Filled "<<mSnFilled | 
|---|
| 116 | <<" BadCoorRange="<<BadCoorRange<<endl; | 
|---|
| 117 |  | 
|---|
| 118 | //--------------------------------------------------------- | 
|---|
| 119 | } catch (PException & exc) { | 
|---|
| 120 | cout<<"Toi2RING: Catched Exception "<<(string)typeid(exc).name() | 
|---|
| 121 | <<"\n .... Msg= "<<exc.Msg()<<endl; | 
|---|
| 122 | } | 
|---|
| 123 |  | 
|---|
| 124 | return; | 
|---|
| 125 | } | 
|---|