Index: /trunk/ArchTOIPipe/ProcWSophya/Bolos2ring.cc
===================================================================
--- /trunk/ArchTOIPipe/ProcWSophya/Bolos2ring.cc	(revision 1984)
+++ /trunk/ArchTOIPipe/ProcWSophya/Bolos2ring.cc	(revision 1984)
@@ -0,0 +1,311 @@
+// This may look like C code, but it's really -*- C++ -*-
+
+/////////////////////////////
+//      Bolos2ring.cc       //
+/////////////////////////////
+
+/// This is a processor for ArchTOIPipe using the Sophya Library.
+/// An example of the use of it is in the file gph425_5.cc
+/// 
+/// The goal of this processor is to give Q and U rings
+// computed with either 3 timelines coming from the
+// two channels of 1 PSB and one of the channels of a second PSB,
+// or with the differences of the two channels of each PSB.
+// The first of these two cases can be used if one channel is out
+// or order, the second one is supposed to be better when all channels
+// work fine, since it fully uses the advantage of PSB's.
+//  Both methods should give the same results when the 4 channels work ok.
+
+// Authors CR/NP, rcecile@in2p3.fr, ponthieu@isn.in2p3.fr
+//////////////////////////////////////////////////////////////////////////////////////
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <math.h>
+#include <vector>
+//#include <strstream>
+#include "spherehealpix.h"
+#include "tmatrix.h"
+#include "tvector.h"
+#include "vector3d.h"
+#include "fitsfile.h"
+#include "ctimer.h"
+#include "intflapack.h"
+#include "smathconst.h"
+#include "ring33.h"
+#include "Bolos2ring.h"
+
+#define UNSEEN_HEALPIX (-1.6375e30)
+ 
+// Constructor
+Bolos2ring::Bolos2ring(SphereHEALPix<r_8>* ringQ, 
+		       SphereHEALPix<r_8>* ringU,
+		       SphereHEALPix<r_8>* ringQW,
+		       SphereHEALPix<r_8>* ringUW,
+		       const vector<r_8>& table_angle,
+		       int_4 *bolos_ok,
+		       int_4 wsz)
+  : ringq(ringQ), ringu(ringU), ringqw(ringQW), ringuw(ringUW), TableFP_(table_angle), Bolos_OK(bolos_ok)
+{
+  SetWSize(wsz);
+  totsncount_ = 0;
+  
+  if( ringq->NbPixels()<1) {
+    cout << "Bolos2ring::Bolos2ring  : bad number of pixel in ringQ "
+	 << ringq->NbPixels() << endl;
+    throw ParmError("Bolos2ring::Bolos2ring  : bad number of pixel in ringQ");
+  }
+  if( ringu->NbPixels()<1) {
+    cout << "Bolos2ring::Bolos2ring  : bad number of pixel in ringU "
+	 << ringu->NbPixels()
+	 << endl;
+    throw ParmError("Bolos2ring::Bolos2ring  : bad number of pixel in ringU");
+  }
+
+  if( ringqw->NbPixels()<1) {
+    cout << "Bolos2ring::Bolos2ring  : bad number of pixel in ringQW "
+	 << ringqw->NbPixels() << endl;
+    throw ParmError("Bolos2ring::Bolos2ring  : bad number of pixel in ringQW");
+   }
+  if( ringuw->NbPixels()<1) {
+    cout << "Bolos2ring::Bolos2ring  : bad number of pixel in ringUW "
+	 << ringuw->NbPixels() << endl;
+    throw ParmError("Bolos2ring::Bolos2ring  : bad number of pixel in ringUW");
+   }
+
+  if( ringq->NbPixels() != ringu->NbPixels())
+    throw(ParmError("Bolos2ring::Bolos2ring : rings don't have the same size!!"));
+
+  Npix_ = ringq->NbPixels();
+  int nlat = ringq->SizeIndex();
+  if(nlat != ringqw->SizeIndex()) ringqw->Resize(nlat);
+  if(nlat != ringuw->SizeIndex()) ringuw->Resize(nlat);
+  cout << "RINGS of " <<ringu->NbPixels() << " pixels" << endl;
+  
+  ringq->SetPixels(0.);
+  ringu->SetPixels(0.);
+  ringqw->SetPixels(0);
+  ringuw->SetPixels(0);
+}
+
+// Destructor
+Bolos2ring::~Bolos2ring()
+{
+}
+
+void Bolos2ring::PrintStatus(ostream& os)
+{
+  os << "____________________________________________" << endl
+     << "  Bolos2ring::PrintStatus() - wsize= "<<wsize_<< endl;
+  TOIProcessor::PrintStatus(os);
+  os << "  ProcessedSampleCount=" << ProcessedSampleCount() << endl;
+  os << "____________________________________________" << endl;
+}
+ 
+void Bolos2ring::init()
+{ 
+  cout << "Bolos2ring::init" << endl;
+
+  // on branche les TOIs des 4 bolos (l'un peut etre "vide")
+  for(int i=0; i < 4; i++)
+    {
+      char str[80];
+      sprintf(str,"Bolo%d",i);
+      cout << str << endl;
+      declareInput(str);
+    }
+
+  // on branche le pointage des 2 PSB
+  for(int i=0; i < 2; i++)
+    {
+      char str[80];
+      sprintf(str,"theta_pointing%d",i);
+      cout << str << endl;
+      declareInput(str);
+      sprintf(str,"phi_pointing%d",i);
+      cout << str << endl;
+      declareInput(str);
+    }
+  
+  name = "Bolos2ring";
+}
+
+void Bolos2ring::run()
+{
+  int snb = getMinIn();
+  int sne = getMaxIn();
+
+  if (!checkInputTOIIndex(0) && !checkInputTOIIndex(1)) {
+    cerr << " Bolos2ring::run() - Input TOIs (in1, in2 and in3, in4) not connected! "
+	 << endl;
+    throw ParmError("Bolos2ring::run() Input TOIs (in1, in2 and in3, in4) not connected!");
+  }
+
+  cout << " Bolo2ring::run() SNRange=" << snb << " - " << sne << endl;
+
+  
+  for(int i=0; i<4; i++) 
+    if( !checkInputTOIIndex(i) )
+    {
+      cerr << " Bolos2ring::run() - Input TOIs not connected! ("
+	   << i << ')' << endl;
+      throw ParmError("Bolos2ring::run() - Input TOIs not connected!");
+    }
+  
+  cout << "Bolos2ring::run() - SNRange="<< snb << '-' << sne << endl;
+  
+  try {
+    
+    cout << " *** combine bolometers without computing the difference *** " << endl;    
+
+    double v0, v1, v2, v3; // values of bolometers outputs
+    double l0, b0, l1, b1; // galactic coordinates
+    uint_8 vfg0, vfg1, vfg2, vfg3;
+    double theta0, phi0, theta1, phi1;
+    int_4 pixel0, pixel1; // pour chaque PSB
+       
+    //  Matrix* sts = new Matrix[Npix_]; // matrice de calcul des param Stokes
+    //  Vector* stm = new Vector[Npix_]; // St * vecteur de mesures
+    
+    Matrix stm(Npix_, 3);
+    RingOfMatrix3x3 ring(Npix_);
+    cout << "****************************" << endl;
+    cout << "   Ring declaration done" << endl;
+    cout << "****************************" << endl;
+    
+
+    for(int i =0; i<4; i++) TableFP_[i] *= Pi/180. ;
+
+    for(int s=snb; s<= sne; s++) {
+      
+      getData(0, s, v0, vfg0);
+      getData(1, s, v1, vfg1);
+      getData(2, s, v2, vfg2);
+      getData(3, s, v3, vfg3);
+      l0 = getData(4, s);
+      b0 = getData(5, s);
+      l1 = getData(6, s);
+      b1 = getData(7, s);
+      
+      theta0 = (90. - b0)/180. * Pi;
+      phi0 = l0/180. * Pi;
+      theta1 = (90. - b1)/180. * Pi;
+      phi1 = l1/180. *Pi;
+      
+      pixel0 = ringq->PixIndexSph(theta0, phi0); // Index of the hit pixel
+      pixel1 = ringu->PixIndexSph(theta1, phi1);
+      
+      if ((Bolos_OK[0] == 0) || (vfg0 > 0)) v0 = 0.;
+      if ((Bolos_OK[1] == 0) || (vfg1 > 0)) v1 = 0.;
+      if ((Bolos_OK[2] == 0) || (vfg2 > 0)) v2 = 0.;
+      if ((Bolos_OK[3] == 0) || (vfg3 > 0)) v3 = 0.;
+       
+      // Filling pixel0
+      ring.GetElement(pixel0)(0, 0) += 0.25 * 2;  
+      ring.GetElement(pixel0)(0, 1) += 0.25 *( cos(2*TableFP_[0]) + cos(2*TableFP_[1])); 
+      ring.GetElement(pixel0)(0, 2) += 0.25 *( sin(2*TableFP_[0]) + sin(2*TableFP_[1])); 
+      
+      ring.GetElement(pixel0)(1, 0) += 0.25 *( cos(2*TableFP_[0]) + cos(2*TableFP_[1]));
+      ring.GetElement(pixel0)(1, 1) += 0.125 *( 2 + cos(4*TableFP_[0]) + cos(4*TableFP_[1]));
+      ring.GetElement(pixel0)(1, 2) += 0.125*( sin(4*TableFP_[0]) + sin(4*TableFP_[1]));
+      
+      ring.GetElement(pixel0)(2, 0) += 0.25 *( sin(2*TableFP_[0]) + sin(2*TableFP_[1]));
+      ring.GetElement(pixel0)(2, 1) += 0.125*( sin(4*TableFP_[0]) + sin(4*TableFP_[1]));
+      ring.GetElement(pixel0)(2, 2) += 0.125*( 2 - cos(4*TableFP_[0]) - cos(4*TableFP_[1]));
+     
+      stm(pixel0, 0) += 0.5*(v0 + v1);
+      stm(pixel0, 1) += 0.5*( cos(2*TableFP_[0])*v0 + cos(2*TableFP_[1])*v1);
+      stm(pixel0, 2) += 0.5*( sin(2*TableFP_[0])*v0 + sin(2*TableFP_[1])*v1);
+           
+      if((Bolos_OK[0] == 0) || (Bolos_OK[1] == 0) || (vfg0 >0) || (vfg1 >0))
+      {
+	ringqw->PixVal(pixel0) += 1 ; // nombre de hits dans le pixel
+	ringuw->PixVal(pixel0) += 1 ; 
+      }
+      else 
+      {
+	ringqw->PixVal(pixel0) += 2 ; 
+	ringuw->PixVal(pixel0) += 2 ; 
+      }
+      
+      ring.GetElement(pixel1)(0, 0) += 0.25 * 2; 
+      ring.GetElement(pixel1)(0, 1) += 0.25 *( cos(2*TableFP_[2]) + cos(2*TableFP_[3])); 
+      ring.GetElement(pixel1)(0, 2) += 0.25 *( sin(2*TableFP_[2]) + sin(2*TableFP_[3])); 
+      
+      ring.GetElement(pixel1)(1, 0) += 0.25 *( cos(2*TableFP_[2]) + cos(2*TableFP_[3]));
+      ring.GetElement(pixel1)(1, 1) += 0.125*( 2 + cos(4*TableFP_[2]) + cos(4*TableFP_[3]));
+      ring.GetElement(pixel1)(1, 2) += 0.125*( sin(4*TableFP_[2]) + sin(4*TableFP_[3])); 
+      
+      ring.GetElement(pixel1)(2, 0) += 0.25 *( sin(2*TableFP_[2]) + sin(2*TableFP_[3]));
+      ring.GetElement(pixel1)(2, 1) += 0.125*( sin(4*TableFP_[2]) + sin(4*TableFP_[3]));
+      ring.GetElement(pixel1)(2, 2) += 0.125*( 2 - cos(4*TableFP_[2]) - cos(4*TableFP_[3]));
+      
+      stm(pixel1, 0) += 0.5*( v2 + v3);
+      stm(pixel1, 1) += 0.5*( cos(2*TableFP_[2])*v2 + cos(2*TableFP_[3])*v3);
+      stm(pixel1, 2) += 0.5*( sin(2*TableFP_[2])*v2 + sin(2*TableFP_[3])*v3);
+      
+      if((Bolos_OK[2] == 0) || (Bolos_OK[3] == 0)|| (vfg2 >0) || (vfg3 >0)) 
+      {  	
+	ringqw->PixVal(pixel1) += 1 ; // nombre de hits dans le pixel
+	ringuw->PixVal(pixel1) += 1 ;
+      }
+      else 
+      {
+	ringqw->PixVal(pixel1) += 2 ; 
+	ringuw->PixVal(pixel1) += 2 ; 
+      }
+      
+      
+      if (!(s%10000)) cout << " sample " << s << " ****** filling matrices  ****** " << endl;
+      
+    }// fin de la boucle sur les samplenums qui normalement a rempli
+    // la matrice et le vecteur projete. Y'a plus qu'a inverser...
+    
+    // Ca devrait suffire de definir un ringw seulement dans ce cas la,
+    // mais je garde le ringqw pour pas bugguer l'entree.
+    
+    cout << endl << "Start to fill rings :" << endl;
+	   
+    for(int pix=0 ; pix < Npix_ ; pix++) {// pour chaque pixel
+
+      if( ringqw->PixVal(pix) < 4.0 ) 
+	//pixel pas vu, 4 a cause des 2 PSB ici, a changer
+	ringq->PixVal(pix) = ringu->PixVal(pix) = UNSEEN_HEALPIX; 
+      
+      else{ 
+      
+	Matrix3x3 sts;
+	Matrix stsm1(3, 3);
+	Vector s(3);
+	Vector stokes_param(3);
+	
+	s(0) = stm(pix, 0);
+	s(1) = stm(pix, 1);
+	s(2) = stm(pix, 2);
+	sts = ring.GetElement(pix); // get the sts matrix of pix
+	sts = sts.Inverse();
+
+	// voir si on peut arreter de bricoler pour que Matrix3x3 soit aussi une Matrix
+	for(int r=0; r<=2; r++)
+	  for(int c=0; c<=2; c++)
+	    stsm1(r, c) = sts(r, c);
+
+	stokes_param = stsm1 * s;	
+  	ringq->PixVal(pix) = stokes_param(0);
+  	ringu->PixVal(pix) = stokes_param(2);
+	
+      }
+      
+    }
+    
+  }
+  
+  
+
+  catch( PThrowable& exc )
+  {
+    cerr << " Exception: " << exc.Msg() << endl;
+  }
+  
+  return;
+} 
Index: /trunk/ArchTOIPipe/ProcWSophya/Bolos2ring.h
===================================================================
--- /trunk/ArchTOIPipe/ProcWSophya/Bolos2ring.h	(revision 1984)
+++ /trunk/ArchTOIPipe/ProcWSophya/Bolos2ring.h	(revision 1984)
@@ -0,0 +1,61 @@
+// This may look like C code, but it's really -*- C++ -*-
+
+#if !defined(_Bolos2RING_H_SEEN_)
+#define _Bolos2RING_H_SEEN_
+
+#include <iostream.h>
+#include <string>
+#include "toiprocessor.h"
+#include "spherehealpix.h"
+#include "localmap.h"
+#include "flagtoidef.h"
+
+class Bolos2ring : public TOIProcessor
+{
+public:
+  Bolos2ring(SphereHEALPix<r_8>* ringQ, 
+	     SphereHEALPix<r_8>* ringU,
+	     SphereHEALPix<r_8>* ringQW,
+	     SphereHEALPix<r_8>* ringUW,
+	     const vector<r_8>& table_angle,
+	     int_4 *Bolos_OK,
+	     int_4 wsz=8192);
+
+  virtual ~Bolos2ring();
+  inline void SetWSize(int_4 wsz) { wsize_ = (wsz<4) ? 4 : wsz; }
+  inline int_8 ProcessedSampleCount() const { return totsncount_; }
+  void SetNSide(int_4 nside);
+  virtual void init();  virtual void run();
+  
+  virtual void PrintStatus(ostream& os);
+
+protected:
+  bool Bolos2ringdone;
+
+  SphereHEALPix<r_8>* ringq;   // carte de Q
+  SphereHEALPix<r_8>* ringu;   // carte de U
+  
+
+  SphereHEALPix<r_8>* ringqw;   // carte du nb de hit
+  SphereHEALPix<r_8>* ringuw;
+  vector<r_8> TableFP_;
+  int_4* Bolos_OK;
+
+  int wsize_;
+  int_8 totsncount_;
+  int_8 Npix_; 
+  
+};
+
+#endif
+
+
+
+
+
+
+
+
+
+
+
Index: /trunk/ArchTOIPipe/ProcWSophya/PSB2ring.cc
===================================================================
--- /trunk/ArchTOIPipe/ProcWSophya/PSB2ring.cc	(revision 1984)
+++ /trunk/ArchTOIPipe/ProcWSophya/PSB2ring.cc	(revision 1984)
@@ -0,0 +1,247 @@
+// This may look like C code, but it's really -*- C++ -*-
+
+/////////////////////////////
+//      PSB2ring.cc       //
+/////////////////////////////
+
+/// This is a processor for ArchTOIPipe using the Sophya Library.
+/// An example of the use of it is in the file gph425_5.cc
+/// 
+/// The goal of this processor is to give Q and U rings
+// computed with either 3 timelines coming from the
+// two channels of 1 PSB and one of the channels of a second PSB,
+// or with the differences of the two channels of each PSB.
+// The first of these two cases can be used if one channel is out
+// or order, the second one is supposed to be better when all channels
+// work fine, since it fully uses the advantage of PSB's.
+//  Both methods should give the same results when the 4 channels work ok.
+
+// Authors CR/NP, rcecile@in2p3.fr, ponthieu@isn.in2p3.fr
+//////////////////////////////////////////////////////////////////////////////////////
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <math.h>
+#include <vector>
+//#include <strstream>
+#include "tmatrix.h"
+#include "tvector.h"
+#include "vector3d.h"
+#include "ctimer.h"
+#include "PSB2ring.h"
+
+#define UNSEEN_HEALPIX (-1.6375e30)
+
+
+// Constructor
+PSB2ring::PSB2ring(SphereHEALPix<r_8>* ringQ, 
+		   SphereHEALPix<r_8>* ringU,
+		   SphereHEALPix<r_8>* ringQW,
+		   SphereHEALPix<r_8>* ringUW,
+		   const vector<r_8>& table_angle,
+		   int_4 wsz)
+  : ringq(ringQ), ringu(ringU), ringqw(ringQW), ringuw(ringUW), TableFP_(table_angle)
+{
+  SetWSize(wsz);
+  totsncount_ = 0;
+  
+  if( ringq->NbPixels()<1) {
+    cout << "PSB2ring::PSB2ring  : bad number of pixel in ringQ "
+	 << ringq->NbPixels() << endl;
+    throw ParmError("PSB2ring::PSB2ring  : bad number of pixel in ringQ");
+  }
+  if( ringu->NbPixels()<1) {
+    cout << "PSB2ring::PSB2ring  : bad number of pixel in ringU "
+	 << ringu->NbPixels()
+	 << endl;
+    throw ParmError("PSB2ring::PSB2ring  : bad number of pixel in ringU");
+  }
+
+  if( ringqw->NbPixels()<1) {
+    cout << "PSB2ring::PSB2ring  : bad number of pixel in ringQW "
+	 << ringqw->NbPixels() << endl;
+    throw ParmError("PSB2ring::PSB2ring  : bad number of pixel in ringQW");
+   }
+  if( ringuw->NbPixels()<1) {
+    cout << "PSB2ring::PSB2ring  : bad number of pixel in ringUW "
+	 << ringuw->NbPixels() << endl;
+    throw ParmError("PSB2ring::PSB2ring  : bad number of pixel in ringUW");
+   }
+
+  if( ringq->NbPixels() != ringu->NbPixels())
+    throw(ParmError("PSB2ring::PSB2ring : rings don't have the same size!!"));
+
+  Npix_ = ringq->NbPixels();
+  int nlat = ringq->SizeIndex();
+  if(nlat != ringqw->SizeIndex()) ringqw->Resize(nlat);
+  if(nlat != ringuw->SizeIndex()) ringuw->Resize(nlat);
+  cout << "RINGS of " <<ringu->NbPixels() << " pixels" << endl;
+  
+  ringq->SetPixels(0.);
+  ringu->SetPixels(0.);
+  ringqw->SetPixels(0);
+  ringuw->SetPixels(0);
+}
+
+// Destructor
+PSB2ring::~PSB2ring()
+{
+}
+
+void PSB2ring::PrintStatus(ostream& os)
+{
+  os << "____________________________________________" << endl
+     << "  PSB2ring::PrintStatus() - wsize= "<<wsize_<< endl;
+  TOIProcessor::PrintStatus(os);
+  os << "  ProcessedSampleCount=" << ProcessedSampleCount() << endl;
+  os << "____________________________________________" << endl;
+}
+ 
+void PSB2ring::init()
+{ 
+  cout << "PSB2ring::init" << endl;
+
+  // on branche les TOIs des 4 bolos (l'un peut etre "vide")
+  for(int i=0; i < 4; i++)// if (PSB_ok[i] > 0)
+    {
+      char str[80];
+      sprintf(str,"Bolo%d",i);
+      cout << str << endl;
+      declareInput(str);
+    }
+
+  // on branche le poinatge des 2 PSB
+  for(int i=0; i < 2; i++)// if (PSB_ok[i] > 0)
+    {
+      char str[80];
+      sprintf(str,"theta_pointing%d",i);
+      cout << str << endl;
+      declareInput(str);
+      sprintf(str,"phi_pointing%d",i);
+      cout << str << endl;
+      declareInput(str);
+    }
+
+  declareOutput("out_toiQ");
+  declareOutput("out_toiU");
+ 
+  name = "PSB2ring";
+}
+
+void PSB2ring::run()
+{
+  int snb = getMinIn();
+  int sne = getMaxIn();
+
+  if (!checkInputTOIIndex(0) && !checkInputTOIIndex(1)) {
+    cerr << " PSB2ring::run() - Input TOIs (in1, in2 and in3, in4) not connected! "
+	 << endl;
+    throw ParmError("PSB2ring::run() Input TOIs (in1, in2 and in3, in4) not connected!");
+  }
+
+  cout << " Bolo2ring::run() SNRange=" << snb << " - " << sne << endl;
+  
+  for(int i=0; i<4; i++) //if (PSB_ok[i/2,i%2])
+    if( !checkInputTOIIndex(i) )
+    {
+      cerr << " PSB2ring::run() - Input TOIs not connected! ("
+	   << i << ')' << endl;
+      throw ParmError("PSB2ring::run() - Input TOIs not connected!");
+    }
+  
+  // pas de sortie a verifier
+  
+  cout << "PSB2ring::run() - SNRange="<< snb << '-' << sne << endl;
+  
+  try {
+
+    Timer tm("PSB2ring::run()");
+    cout << "****************************" << endl;
+    cout << "****************************" << endl;  
+    cout << "4 bolos working and ordered" << endl;
+    
+    // Generation des timelines
+    double v0,v1,v2,v3; // values of bolometers outputs
+    double l0, b0, l1, b1; // galactic coordinates
+    uint_8 vfg0,vfg1,vfg2,vfg3;
+    double Q,U;    
+    
+    for(int s=snb;s<=sne;s++) {
+
+      getData(0, s, v0, vfg0);
+      getData(1, s, v1, vfg1);
+      getData(2, s, v2, vfg2);
+      getData(3, s, v3, vfg3);
+
+      l0 = getData(4, s);
+      b0 = getData(5, s);
+      l1 = getData(6, s);
+      b1 = getData(7, s);
+
+      double theta0 = (90. - b0)/180 * 3.14159;
+      double phi0 = l0/180. * 3.14159;
+      double theta1 = (90. - b1)/180 * 3.14159;
+      double phi1 = l1/180 *3.14159;
+
+
+
+      //     cout << " ********** Q(t) and U(t) finished *********** " << endl;
+ 
+      //    cout << " ********** Projection on the ring ********* " << endl;
+      
+      //Projection
+      
+      if((vfg0 == 0) && (vfg1 == 0))
+      {
+	Q = v0 - v1;
+	int_4 pixelQ = ringq->PixIndexSph(theta0, phi0); // numero du pixel touche
+	ringqw->PixVal(pixelQ) += 1 ; // nombre de hits dans le pixel
+	ringq->PixVal(pixelQ)  += Q ;
+      }
+      
+      if((vfg2 == 0) && (vfg3 == 0))
+      {
+	U = v2 - v3;      
+	int_4 pixelU = ringu->PixIndexSph(theta1, phi1);
+	ringuw->PixVal(pixelU) += 1 ;      
+	ringu->PixVal(pixelU)  += U ;
+      }
+      
+      if (!(s%10000)) cout << s << " ****** filling rings  ****** " << endl;
+	
+      putData(0, s, Q);   
+      putData(1, s, U); 
+    }
+
+    // Moyennage des pixels
+    // comme on bosse directement avec des timelines de Q et U
+    // dans ce cas precis, on a juste a prendre la moyenne des valeurs
+    // qui tombent dans un pixel pour avoir la carte
+    // on ne doit inverser de matrice etc que dans le cas
+    // trois bolos.
+
+    for(int pix=0 ; pix < Npix_ ; pix++) {
+
+      if( ringqw->PixVal(pix) < 1.0 ) //pixel pas vu
+	ringq->PixVal(pix) = ringu->PixVal(pix) = UNSEEN_HEALPIX; 
+      else
+	ringq->PixVal(pix) = ringq->PixVal(pix) / ringqw->PixVal(pix);
+      
+      if( ringuw->PixVal(pix) < 1.0 )
+	ringu->PixVal(pix) = ringu->PixVal(pix) = UNSEEN_HEALPIX; 
+      else
+	ringu->PixVal(pix) = ringu->PixVal(pix) / ringuw->PixVal(pix);      
+
+    }
+    cout << " ********** rings filled  ********* " << endl;
+  }
+  
+
+  catch( PThrowable& exc )
+    {
+      cerr << " Exception: " << exc.Msg() << endl;
+    }
+}
+
+
+
Index: /trunk/ArchTOIPipe/ProcWSophya/PSB2ring.h
===================================================================
--- /trunk/ArchTOIPipe/ProcWSophya/PSB2ring.h	(revision 1984)
+++ /trunk/ArchTOIPipe/ProcWSophya/PSB2ring.h	(revision 1984)
@@ -0,0 +1,64 @@
+// This may look like C code, but it's really -*- C++ -*-
+
+#if !defined(_PSB2RING_H_SEEN_)
+#define _PSB2RING_H_SEEN_
+
+#include <iostream.h>
+#include <string>
+#include "toiprocessor.h"
+#include "spherehealpix.h"
+#include "localmap.h"
+#include "flagtoidef.h"
+
+class PSB2ring : public TOIProcessor
+{
+public:
+  PSB2ring(SphereHEALPix<r_8>* ringQ, 
+	   SphereHEALPix<r_8>* ringU,
+	   SphereHEALPix<r_8>* ringQW,
+	   SphereHEALPix<r_8>* ringUW,
+	   const vector<r_8>& table_angle,
+	   int_4 wsz=819);
+
+  virtual ~PSB2ring();
+  inline void SetWSize(int_4 wsz) { wsize_ = (wsz<4) ? 4 : wsz; }
+  inline int_8 ProcessedSampleCount() const { return totsncount_; }
+  void SetNSide(int_4 nside);
+  virtual void init();
+  virtual void run();
+  
+  virtual void PrintStatus(ostream& os);
+
+protected:
+  bool PSB2ringdone;
+
+  SphereHEALPix<r_8>* ringq;   // carte de Q
+  SphereHEALPix<r_8>* ringu;   // carte de U
+  
+  string ringqfile;
+  string ringufile;
+
+  vector<r_8> TableFP_;
+  SphereHEALPix<r_8>* ringqw;   // carte du nb de hit
+  SphereHEALPix<r_8>* ringuw;
+  
+  string ringqwfile;
+  string ringuwfile;
+
+  int wsize_;
+  int_8 totsncount_;
+  int_8 Npix_;
+};
+
+#endif
+
+
+
+
+
+
+
+
+
+
+
Index: /trunk/ArchTOIPipe/ProcWSophya/ring33.cc
===================================================================
--- /trunk/ArchTOIPipe/ProcWSophya/ring33.cc	(revision 1984)
+++ /trunk/ArchTOIPipe/ProcWSophya/ring33.cc	(revision 1984)
@@ -0,0 +1,22 @@
+#include "machdefs.h"
+#include "pexceptions.h"
+#include "ring33.h"
+
+
+// -------------------------------------------------------
+// Classe simple de matrice 3x3 - sans allocation memoire
+// -------------------------------------------------------
+
+// constructor
+RingOfMatrix3x3::RingOfMatrix3x3(int_4 npix)
+{
+  if (npix < 1) throw RangeCheckError("RingOfMatrix3x3::RingMatrix3x3() size < 1 !");
+  size_ = npix;
+  mtxtab_ = new Matrix3x3[npix];
+}
+
+// Destructor
+RingOfMatrix3x3::~RingOfMatrix3x3()
+{
+  delete[] mtxtab_;
+}
Index: /trunk/ArchTOIPipe/ProcWSophya/ring33.h
===================================================================
--- /trunk/ArchTOIPipe/ProcWSophya/ring33.h	(revision 1984)
+++ /trunk/ArchTOIPipe/ProcWSophya/ring33.h	(revision 1984)
@@ -0,0 +1,147 @@
+#include "machdefs.h"
+#include "pexceptions.h"
+
+/*
+#include <math.h>
+#include <iostream.h>
+#include <fstream.h>
+
+#include "tarrinit.h"
+#include "array.h"
+#include "ctimer.h"
+#include "timing.h"
+*/
+
+
+
+// -------------------------------------------------------
+// Classe simple de matrice 3x3 - sans allocation memoire
+// -------------------------------------------------------
+
+class Matrix3x3 {
+public:
+  inline        Matrix3x3(bool raz=true) 
+  { 
+    if (raz) 
+      for(int i=0; i<9; i++) a_[i]=0.; 
+  } 
+  inline	Matrix3x3(const Matrix3x3 & m)
+  { 
+    for(int i=0; i<9; i++)  {a_[i] = m.a_[i]; am1_[i] = m.am1_[i];}
+  }
+
+  inline        ~Matrix3x3() { }
+
+  inline Matrix3x3& Set(const Matrix3x3 & m)
+                   { for(int i=0; i<9; i++) a_[i] = m.a_[i]; return (*this); }
+  inline Matrix3x3& operator = (const Matrix3x3 & a)
+                   { return Set(a); }
+
+  inline double operator()(int r, int c) const 
+                { return a_[r*3+c]; }
+  inline double& operator()(int r, int c) 
+                { return a_[r*3+c]; }
+
+  inline int NRows() const {return 3; }
+  inline int NCols() const {return 3; }
+
+  inline Matrix3x3& AddElt(const Matrix3x3 & m)
+                   { for(int i=0; i<9; i++) a_[i] += m.a_[i]; return (*this); }
+  inline Matrix3x3& MulElt(const Matrix3x3 & m)
+                   { for(int i=0; i<9; i++) a_[i] *= m.a_[i]; return (*this); }
+  
+  // Multiplication de deux Matrix3x3 entre elles  
+/*    inline Matrix3x3& MulMat(const Matrix3x3 & m) */
+/*      { */
+/*        Matrix3x3 c; */
+/*        // c.Set(0.); */
+/*        for(int r=0; r<=2; r++) */
+/*  	for(int c=0; c<=2; c++) */
+/*  	  c.a_[r*3+c] = 0.; */
+      
+/*        for(int r=0; r<=2; r++) */
+/*  	for(int c=0; c<=2; c++) */
+/*  	  for(int k=0; k<=2; k++) */
+/*  	    c.a_[3*r+c] += a_[3*r+k] * m.a_[3*k+c]; */
+      
+/*        a_ = c; */
+/*        return(*this); */
+/*      } */
+
+  inline Matrix3x3& Transpose()
+    {
+      double c;
+      c = a_[1]; a_[1] = a_[3]; a_[3] = c;
+      c = a_[2]; a_[2] = a_[6]; a_[6] = c;
+      c = a_[5]; a_[5] = a_[7]; a_[7] = c;
+      return (*this);
+    }
+
+  inline Matrix3x3& Inverse()
+    {
+      // Calcul du determinant global
+      double determ;
+      determ =  a_[0]*a_[4]*a_[8] + a_[3]*a_[7]*a_[2] + a_[6]*a_[1]*a_[5];
+      determ -= a_[2]*a_[4]*a_[6] + a_[5]*a_[7]*a_[0] + a_[8]*a_[1]*a_[3];
+      // prevoir un break si determ <= threshold
+
+      // Calcul des cofacteurs
+      am1_[0] =  (a_[4]*a_[8] - a_[5]*a_[7])/determ ; 
+      am1_[1] = -(a_[3]*a_[8] - a_[5]*a_[6])/determ ; 
+      am1_[2] =  (a_[3]*a_[7] - a_[4]*a_[6])/determ ; 
+      am1_[3] = -(a_[1]*a_[8] - a_[7]*a_[2])/determ ; 
+      am1_[4] =  (a_[0]*a_[8] - a_[6]*a_[2])/determ ; 
+      am1_[5] = -(a_[0]*a_[7] - a_[6]*a_[1])/determ ; 
+      am1_[6] =  (a_[1]*a_[5] - a_[4]*a_[2])/determ ; 
+      am1_[7] = -(a_[0]*a_[5] - a_[3]*a_[2])/determ ; 
+      am1_[8] =  (a_[0]*a_[4] - a_[3]*a_[1])/determ ; 
+      /****************************************/
+      /* c'est la version qui marche, mais la convention semble 
+         differente de celle de [3*r + c]...? */
+
+
+/*        // Transposition */
+/*        am1_ = am1_.Transpose() ; */
+/*        a_ = am1_; // marche pas bien : "request for member `Transpose' in `Matrix3x3::am1_', */
+/*                   //which is of non-aggregate type 'double[9]' */
+
+      // Calcul de l'inverse avec transpostion incluse
+/*        am1_[0] =  (a_[4]*a_[8] - a_[5]*a_[7])/determ ; */
+/*        am1_[3] = -(a_[3]*a_[8] - a_[5]*a_[6])/determ ; */
+/*        am1_[6] =  (a_[3]*a_[7] - a_[4]*a_[6])/determ ; */
+/*        am1_[1] = -(a_[1]*a_[8] - a_[7]*a_[2])/determ ; */
+/*        am1_[4] =  (a_[0]*a_[8] - a_[6]*a_[2])/determ ; */
+/*        am1_[7] = -(a_[0]*a_[7] - a_[6]*a_[1])/determ ; */
+/*        am1_[2] =  (a_[1]*a_[5] - a_[4]*a_[2])/determ ; */
+/*        am1_[5] = -(a_[0]*a_[5] - a_[3]*a_[2])/determ ; */
+/*        am1_[8] =  (a_[0]*a_[4] - a_[3]*a_[1])/determ ; */
+      a_ = am1_;
+      return (*this);}
+
+
+protected:
+  double a_[9], am1_[9];
+  
+};
+
+
+class RingOfMatrix3x3 {
+public:
+                RingOfMatrix3x3(int_4 npix);
+  virtual      ~RingOfMatrix3x3();
+
+  inline int_4  Size() { return size_; }
+  inline Matrix3x3& GetElement(int_4 n) 
+  {
+    if ((n<0) || (n>=size_))
+      throw RangeCheckError("RingOfMatrix3x3::GetElement() - Out of range index");
+    return mtxtab_[n];
+  }
+  inline Matrix3x3& operator()(int_4 n) { return GetElement(n); }
+
+protected:
+  Matrix3x3 *mtxtab_;
+  int_4 size_;  
+};
+
+
Index: /trunk/ArchTOIPipe/SMakefile
===================================================================
--- /trunk/ArchTOIPipe/SMakefile	(revision 1983)
+++ /trunk/ArchTOIPipe/SMakefile	(revision 1984)
@@ -1,129 +1,157 @@
-# ####################### ArchTOIPipe ###########################
-# ##### LAL (Orsay) / IN2P3-CNRS  DAPNIA/SPP (Saclay) / CEA #####
-# ###############################################################
-#   Top level makefile to build ArchTOIPipe library with SOPHYA
-# Usage : make -f SMakefile mkmf
-#         make -f SMakefile libs
-#         make -f SMakefile slb 
-# ###############################################################
+USERFLAGS = -I$(EXTLIBDIR)/Include/FitsIO -DWITH_SOPHYA
+include $(DPCBASEREP)/Include/MakefileUser.h
 
-# include files defining compiler/linker options 
-include SMakefile.h
-include ${DPCBASEREP}/Include/Makefile.slb
+ALIB := ./$(MACHDIR)/
+AOBJ := ./$(MACHDIR)/
 
-LIBF =  $(MYLIB)libKernel.a $(MYLIB)libProcessors.a $(MYLIB)libProcWSophya.a
+$(AOBJ)%.o:%.cc
+	$(COMPILE.cc) $(USERFLAGS) -o $@ $<
+$(AOBJ)%.o:%.c
+	$(COMPILE.c) $(CFLAGS) $(USERFLAGS) -o $@ $<
 
-defaut: libs
+LIBOLIST := $(AOBJ)asciitoiwtr.o $(AOBJ)fitstoirdr.o $(AOBJ)fitstoiwtr.o \
+            $(AOBJ)toi.o $(AOBJ)toimanager.o $(AOBJ)toiprocessor.o $(AOBJ)genwproc.o \
+            $(AOBJ)toisqfilter.o $(AOBJ)toiregwindow.o $(AOBJ)toiseqbuff.o \
+            $(AOBJ)toisegment.o \
+            $(AOBJ)simtoipr.o $(AOBJ)map2toi.o $(AOBJ)toi2map.o $(AOBJ)nooppr.o \
+            $(AOBJ)ring33.o $(AOBJ)PSB2ring.o $(AOBJ)Bolos2ring.o
+EXEOLIST := $(AOBJ)fits2asc.o $(AOBJ)tsttoi.o $(AOBJ)tsttoi2.o $(AOBJ)simtst.o \
+            $(AOBJ)tstrztoi.o $(AOBJ)rztoi.o $(AOBJ)sfftc.o $(AOBJ)mesovh.o \
+            $(AOBJ)fits2ascii.o $(AOBJ)tgenw.o $(AOBJ)tstmap2toi.o $(AOBJ)tsttoi2map.o \
+            $(AOBJ)tstflag.o $(AOBJ)tstdemopipe.o $(AOBJ)gph425_ring.o
+EXELIST := $(AOBJ)sfftc $(AOBJ)simtst $(AOBJ)mesovh $(AOBJ)tstrztoi $(AOBJ)fits2asc $(AOBJ)tsttoi \
+           $(AOBJ)tsttoi2 $(AOBJ)fits2ascii $(AOBJ)tgenw $(AOBJ)tstmap2toi $(AOBJ)tsttoi2map \
+           $(AOBJ)tstflag $(AOBJ)tstdemopipe $(AOBJ)gph425_ring
 
-all: libs slb
+INCLIST := asciitoiwtr.h fitstoirdr.h fitstoiwtr.h toi.h config.h conf.h \
+           toiprocessor.h genwproc.h toimanager.h toiseqbuff.h toiregwindow.h \
+           simtoipr.h map2toi.h toi2map.h nooppr.h toisegment.h ring33.h PSB2ring.h Bolos2ring.h
+
+all : $(EXELIST) 
+lib : $(LIBOLIST)
+
+clean:
+	rm -f  $(LIBOLIST)
+	rm -f  $(EXEOLIST)
+	rm -f  $(EXELIST)
+
+LIBF =  $(SLB)libsophya.so $(SLB)libextsophya.so 
+LIBS =  -L$(SLB) -lextsophya -lsophya -lpthread -lm
+####ifeq ($(MACHEROS),OSF1)
+####LIBS := $(LIBS) -lfor
+####endif
+
+########################################
+#### Les Executables des Programmes ####
+########################################
+tstrztoi: $(AOBJ)tstrztoi
+	@echo done
+$(AOBJ)tstrztoi: $(AOBJ)tstrztoi.o $(AOBJ)rztoi.o $(LIBOLIST)
+	$(LINK.cc)  -o $@ $^ $(LIBS)
+
+sfftc: $(AOBJ)sfftc
+	@echo done
+$(AOBJ)sfftc: $(AOBJ)sfftc.o  $(LIBOLIST)
+	$(LINK.cc)  -o $@ $^ $(LIBS)
+
+mesovh: $(AOBJ)mesovh
+	@echo done
+$(AOBJ)mesovh: $(AOBJ)mesovh.o  $(LIBOLIST)
+	$(LINK.cc)  -o $@ $^ $(LIBS)
+
+simtst: $(AOBJ)simtst
+	@echo done
+$(AOBJ)simtst: $(AOBJ)simtst.o  $(LIBOLIST)
+	$(LINK.cc)  -o $@ $^ $(LIBS)
+
+fits2asc: $(AOBJ)fits2asc
+	@echo done
+$(AOBJ)fits2asc: $(AOBJ)fits2asc.o $(LIBOLIST)
+	$(LINK.cc)  -o $@ $^ $(LIBS)
+
+tsttoi: $(AOBJ)tsttoi
+	@echo done
+$(AOBJ)tsttoi: $(AOBJ)tsttoi.o $(LIBOLIST)
+	$(LINK.cc)  -o $@ $^ $(LIBS)
+
+tsttoi2: $(AOBJ)tsttoi2
+	@echo done
+$(AOBJ)tsttoi2: $(AOBJ)tsttoi2.o $(LIBOLIST)
+	$(LINK.cc)  -o $@ $^ $(LIBS)
+
+fits2ascii: $(AOBJ)fits2ascii
+	@echo done
+$(AOBJ)fits2ascii: $(AOBJ)fits2ascii.o $(LIBOLIST)
+	$(LINK.cc)  -o $@ $^ $(LIBS)
+
+tgenw: $(AOBJ)tgenw
+	@echo done
+$(AOBJ)tgenw: $(AOBJ)tgenw.o  $(LIBOLIST)
+	$(LINK.cc)  -o $@ $^ $(LIBS)
+
+tstmap2toi: $(AOBJ)tstmap2toi
+	@echo done
+$(AOBJ)tstmap2toi: $(AOBJ)tstmap2toi.o $(LIBOLIST)
+	$(LINK.cc)  -o $@ $^ $(LIBS)
+
+tsttoi2map: $(AOBJ)tsttoi2map
+	@echo done
+$(AOBJ)tsttoi2map: $(AOBJ)tsttoi2map.o $(LIBOLIST)
+	$(LINK.cc)  -o $@ $^ $(LIBS)
+
+tstflag: $(AOBJ)tstflag
+	@echo done
+$(AOBJ)tstflag: $(AOBJ)tstflag.o $(LIBOLIST)
+	$(LINK.cc)  -o $@ $^ $(LIBS)
+
+tstdemopipe: $(AOBJ)tstdemopipe
+	@echo done
+$(AOBJ)tstdemopipe: $(AOBJ)tstdemopipe.o $(LIBOLIST)
+	$(LINK.cc)  -o $@ $^ $(LIBS)
+
+gph425_ring: $(AOBJ)gph425_ring
+	@echo done
+$(AOBJ)gph425_ring: $(AOBJ)gph425_ring.o $(LIBOLIST)
+	$(LINK.cc)  -o $@ $^ $(LIBS)
 
 
-libs: archlibs
-slb: archslb
+################################################
+#### Compilation des Sources des Programmes ####
+################################################
+$(AOBJ)simtst.o: simtst.cc $(INCLIST)
+$(AOBJ)sfftc.o: sfftc.cc $(INCLIST)
+$(AOBJ)mesovh.o: mesovh.cc $(INCLIST)
+$(AOBJ)tstrztoi.o: tstrztoi.cc rztoi.h $(INCLIST)
+$(AOBJ)rztoi.o: rztoi.cc rztoi.h $(INCLIST)
+$(AOBJ)fits2asc.o: fits2asc.cc $(INCLIST)
+$(AOBJ)tsttoi.o: tsttoi.cc $(INCLIST)
+$(AOBJ)tsttoi2.o: tsttoi2.cc $(INCLIST)
+$(AOBJ)fits2ascii.o: fits2ascii.cc $(INCLIST)
+$(AOBJ)tgenw.o: tgenw.cc $(INCLIST)
+$(AOBJ)tstmap2toi.o: tstmap2toi.cc $(INCLIST)
+$(AOBJ)tsttoi2map.o: tsttoi2map.cc $(INCLIST)
+$(AOBJ)tstflag.o: tstflag.cc $(INCLIST)
+$(AOBJ)tstdemopipe.o: tstdemopipe.cc $(INCLIST)
+$(AOBJ)gph425_ring.o: gph425_ring.cc $(INCLIST)
 
-archlibs: Kernel Processors ProcWSophya
-
-#--- Create directory and copy includes for install
-depend:
-ifdef ARCHPDEVREP
-ifdef EROSCXX
-	@echo "ArchTOIPipe will be installed under:"
-	@echo "  $(ARCHPDEVREP)/Include" 
-	@echo "  $(ARCHPDEVREP)/`uname`-$(EROSCXX)" 
-	./crerep_pipe $(ARCHPDEVREP) `uname`-$(EROSCXX); \
-#	./makefileuser.csh; \
-	./mkmflien -copy ; \
-else
-	@echo "Variable EROSCXX must be define with setenv"
-endif
-else
-	@echo "Variable ARCHPDEVREP must be define with setenv"
-endif
-#--------------------------------------------------------------------
-
-#--- Create library module Makefiles
-mkmf:
-	@echo 'Running ./smkmf'
-	./smkmf
-#--------------------------------------------------------------------
-
-.PHONY:  Kernel
-Kernel:
-	if [ -d Kernel ] ; then cd  Kernel ; $(MAKE) ; fi
-
-.PHONY:  Processors
-Processors:
-	if [ -d Processors ] ; then cd  Processors ; $(MAKE) ; fi
-
-.PHONY:  ProcWSophya
-ProcWSophya:
-	if [ -d ProcWSophya ] ; then cd  ProcWSophya ; $(MAKE) ; fi
-
-#  Shared library creation part of the Makefile
- 
-#  List of libraries (.a)
-PSLB =  $(MYLIB)libKernel.a $(MYLIB)libProcessors.a $(MYLIB)libProcWSophya.a
-
-#  List of external library references
-EXTLIBL  = -L$(EXTLIBPATH) -lcfitsio -lfftw -lrfftw -lxastro
-EXTSLBL  = -L$(EXTSLBPATH) -lcfitsio -lfftw -lrfftw -lxastro
-
-# defining the other external libraries needed on different systems
-
-# On Linux   lapack and blas and f2c/g2c ere needed
-ifeq ($(MACHEROS),Linux)
-#EXTLIB = $(EXTLIBL) -llapack -lblas -lf2c
-#EXTSLB = $(EXTSLBL) -llapack -lblas -lf2c
-EXTLIB = $(EXTLIBL) -llapack -lblas -lg2c
-EXTSLB = $(EXTSLBL) -llapack -lblas -lg2c
-endif
-
-# On OSF1 libdxml contains Lapack, but the fortran support library is needed
-ifeq ($(MACHEROS),OSF1)
-EXTLIB = $(EXTLIBL) -ldxml -lfor
-EXTSLB = $(EXTSLBL) -ldxml -lfor
-endif
-
-# On IRIX , complib.sgimath contains Lapack
-ifeq ($(MACHEROS),IRIX64)
-EXTLIB = $(EXTLIBL) -lcomplib.sgimath 
-EXTSLB = $(EXTSLBL) -lcomplib.sgimath 
-endif
-
-
-
-# XPILIBS = $(LIBXPIPATH) $(LIBXPILIST)
-
-# --- Shared lib name (extension) depending on OS 
-SLBNAME = $(MYSLB)libpipe.so
-ifeq ($(MACHEROS),Darwin)
-SLBNAME = $(MYSLB)libpipe.dylib
-endif
-
-#  main dependence list
-archslb : $(SLBNAME) 
- 
-# List of .o files for each module
-# OBJKernel = $(shell echo `cat ./Kernel/objlist.list `)
-# OBJProcessors = $(shell echo `cat ./Processors/objlist.list `)
-# OBJProcWSophya = $(shell echo `cat ./ProcWSophya/objlist.list `)
-OBJKernel = $(shell echo `cat ./Kernel/Kernel.o.list `)
-OBJProcessors = $(shell echo `cat ./Processors/Processors.o.list `)
-OBJProcWSophya = $(shell echo `cat ./ProcWSophya/ProcWSophya.o.list `)
-
-ALLOBJS = $(OBJKernel) $(OBJProcessors) $(OBJProcWSophya) 
-
-# Building ArchTOIPipe shared library
-$(SLBNAME) : $(PSLB)
-	cd  $(OBJ); \
-	$(CMDSHLCXX) -o $(SLBNAME)  \
-	$(FGSHLACXX) $(ALLOBJS)  $(FGSHLNCXX)\
-	-L$(SLB) -lsophya -lextsophya $(EXTLIB) $(LIBLSHL)
- 
- 
-
-clean:
-	if [ -d $(MYLIB) ] ; then cd $(MYLIB)/. ; rm -f *.a  ; fi
-	if [ -d $(MYSLB) ] ; then cd $(MYSLB)/. ; rm -f *.so ; fi
-	if [ -d $(OBJ) ] ; then cd $(OBJ)/. ; rm -f *.o  rm -rf cxxrep* ; fi
-
+################################################
+#### Compilation des Sources des Librairies ####
+################################################
+$(AOBJ)asciitoiwtr.o: asciitoiwtr.cc asciitoiwtr.h toi.h config.h conf.h toiprocessor.h toimanager.h 
+$(AOBJ)fitstoirdr.o: fitstoirdr.cc fitstoirdr.h toiprocessor.h config.h conf.h
+$(AOBJ)fitstoiwtr.o: fitstoiwtr.cc fitstoiwtr.h toi.h config.h conf.h
+$(AOBJ)toi.o: toi.cc toiprocessor.h config.h conf.h toi.h 
+$(AOBJ)toimanager.o: toimanager.cc toimanager.h
+$(AOBJ)toiprocessor.o: toiprocessor.cc toiprocessor.h config.h conf.h toi.h toimanager.h
+$(AOBJ)genwproc.o: genwproc.h toiprocessor.h toimanager.h
+$(AOBJ)toisqfilter.o: toisqfilter.cc toisqfilter.h toiprocessor.h config.h conf.h toi.h toimanager.h
+$(AOBJ)toiseqbuff.o: toiseqbuff.cc toiprocessor.h config.h conf.h toi.h toiseqbuff.h 
+$(AOBJ)toiregwindow.o: toiregwindow.cc toiprocessor.h config.h conf.h toi.h toiregwindow.h 
+$(AOBJ)simtoipr.o: simtoipr.cc toiprocessor.h config.h conf.h toi.h simtoipr.h 
+$(AOBJ)map2toi.o: map2toi.cc map2toi.h 
+$(AOBJ)toi2map.o: toi2map.cc toi2map.h 
+$(AOBJ)nooppr.o: nooppr.cc nooppr.h 
+$(AOBJ)toisegment.o: toisegment.cc toiprocessor.h config.h conf.h toi.h
+$(AOBJ)ring33.o: ring33.cc ring33.h 
+$(AOBJ)PSB2ring.o: PSB2ring.cc PSB2ring.h 
+$(AOBJ)Bolos2ring.o: Bolos2ring.cc Bolos2ring.h 
Index: /trunk/ArchTOIPipe/TestPipes/gph425_ring.cc
===================================================================
--- /trunk/ArchTOIPipe/TestPipes/gph425_ring.cc	(revision 1984)
+++ /trunk/ArchTOIPipe/TestPipes/gph425_ring.cc	(revision 1984)
@@ -0,0 +1,296 @@
+//////////////////////////
+//  gph425_ring.cc         //
+//////////////////////////
+
+//*******************************************************
+
+#include <iostream.h>
+#include <stdlib.h>
+//#include <strstream.h>
+#include <string>
+#include <stdio.h>
+#include <vector>
+
+#include "toi.h"
+#include "toisegment.h"
+//#include "toiseqbuff.h"
+#include "nooppr.h"
+#include "toiprocessor.h"
+#include "fitstoirdr.h"
+#include "fitstoiwtr.h"
+#include "toimanager.h"
+#include "datacards.h"
+#include "fitsfile.h"
+#include "sophyainit.h"
+#include "toiseqbuff.h"
+#include "timing.h"
+#include "sambainit.h"
+#include "fitsspherehealpix.h"
+#include "ring33.h"
+#include "Bolos2ring.h"
+#include "PSB2ring.h"
+
+#include <stdexcept>
+
+int main(int argc, char* argv[])
+{
+  cout << "Starting Simple Ring Making ..." << endl;
+
+  try {
+    
+    SophyaInit();
+    InitTim();
+    
+    char str[80];
+
+  TOIManager* mgr = TOIManager::getManager();
+  int wsize = 512; /// Segment size for TOISegmented
+
+  /// One command line argument: the filename of the datacard.
+  if( argc < 2 )
+    {
+      cout << "Need a parameter file!! " << endl;
+      exit(-1);
+    }
+  DataCards param(argv[1]);
+
+  
+  int_8 PSB = param.IParam("METHOD_PSB_diff");
+  int_8 COMBI = param.IParam("METHOD_BOLOS_combi");  
+
+  if ((PSB + COMBI <= 0) ||  (PSB + COMBI >= 2))
+  {
+    cout << "METHOD should be PSB_DIFF or BOLOS_COMBI" << endl;
+    exit(-1);
+  }
+  
+  cout << endl <<    "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
+  if(PSB==1) cout << "!!!!!!!!!!!!!! METHOD PSB_DIFF !!!!!!!!!!!!!!!!!" << endl;
+  else cout <<       "!!!!!!!!!!!!!! METHOD BOLOS_combi !!!!!!!!!!!!!!" << endl;
+  cout <<            "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl << endl;
+  
+  int_4 Bolos_OK[4];
+  int nbbolos_ok=0;
+  
+  if (PSB==0) {
+    for(int i=0; i<4; i++) {
+      sprintf(str,"BOLOS_OK_%d",i);
+      Bolos_OK[i] = param.IParam(str);
+      if (Bolos_OK[i] >=1 ) nbbolos_ok ++;
+    }
+    if (nbbolos_ok <3) {
+      cout << "At least 3 Bolos must be used : " << Bolos_OK [0] << " "
+	   << Bolos_OK[1] << " "<< Bolos_OK[2] << " "<< Bolos_OK[3] << " "<< endl;
+      exit(-1);
+    } else 
+      cout << nbbolos_ok << " Bolos OK : " << Bolos_OK[0] << " "
+	   << Bolos_OK[1] << " "<< Bolos_OK[2] << " "<< Bolos_OK[3] << " "<< endl;
+
+  } else Bolos_OK[0]=Bolos_OK[1]=Bolos_OK[2]=Bolos_OK[3]=1;
+  
+
+  /// Nside : parameter for HEALPix ring
+  int_4 Nside = param.IParam("Nside", 0, 128);
+
+  /// The rings to create (Q,U and weight ring)
+  SphereHEALPix<r_8>* ringQ = new SphereHEALPix<r_8>(Nside);
+  SphereHEALPix<r_8>* ringU = new SphereHEALPix<r_8>(Nside);
+  SphereHEALPix<r_8>* ringQW = new SphereHEALPix<r_8>(Nside);
+  SphereHEALPix<r_8>* ringUW = new SphereHEALPix<r_8>(Nside);
+
+  int_8 snb = param.IParam("SN_Start", 0);
+  int_8 sne = param.IParam("SN_End", 0);
+
+  /// Define start and end sample number to treat
+  mgr->setRequestedSample(snb,sne);
+  cout << "SampleNumbers from " << snb << " to " << sne << endl;
+
+  vector<string> file_pointing(2);
+  vector<string> theta_pointing(2);
+  vector<string> phi_pointing(2);
+  vector<string> file_bolo(4);
+  vector<string> name_bolo(4);
+  vector<r_8> table_angle(4);
+  string toiqfile = param.SParam("FILE_TOI_Q",0,"toiQ.fits");
+  string toiufile = param.SParam("FILE_TOI_U",0,"toiU.fits");
+  string ringqfile = param.SParam("FILE_RING_Q",0,"ringQ.fits");
+  string ringufile = param.SParam("FILE_RING_U",0,"ringU.fits");
+  string ringqwfile = param.SParam("FILE_RING_WQ",0,"ringQW.fits");
+  string ringuwfile = param.SParam("FILE_RING_WU",0,"ringUW.fits");
+  if (PSB == 1) cout << "Output toi files " << toiqfile << " " << toiufile <<endl;
+  cout << "Output ring files " << ringqfile << " " << ringufile <<endl;
+  cout << "Output weights files " << ringqwfile << " " << ringuwfile <<endl;
+  
+  
+  int i,j;
+  for(i=0; i<2; i++ ) {
+    sprintf(str,"FILE_POINT_%d",i);
+    file_pointing[i] = param.SParam(str, 0);
+    cout << "Pointing file " << i << ": " << file_pointing[i] << endl;
+    
+    sprintf(str,"NAME_POINT_%d_theta",i);
+    theta_pointing[i] = param.SParam(str, 0);
+    cout << "Pointing theta " << i << ": " << theta_pointing[i] << endl;
+    
+    sprintf(str,"NAME_POINT_%d_phi",i);
+    phi_pointing[i] = param.SParam(str, 0);
+    cout << "Pointing phi " << i << ": " << phi_pointing[i] << endl;
+
+    for(j=0; j<2; j++ ) if (Bolos_OK[2*i+j]) {
+    
+      sprintf(str,"FILE_PSB%d_BOLO%d",i,j);
+      file_bolo[i*2+j] = param.SParam(str, 0);
+      cout << "bolo file " << i*2+j << ": " << file_bolo[i*2+j] << endl;
+      
+      sprintf(str,"NAME_PSB%d_BOLO%d",i,j);
+      name_bolo[i*2+j] = param.SParam(str, 0);
+      cout << "bolo name " << i*2+j << ": " << name_bolo[i*2+j] << endl;
+      
+      sprintf(str,"ANGLE_PSB%d_BOLO%d",i,j);
+      table_angle[i*2+j] = param.DParam(str, 0);
+      cout << "Angle " << i*2+j << ": " << table_angle[i*2+j] << endl;
+    }
+  }
+
+  PSB2ring psb2ring(ringQ, ringU, ringQW, ringUW, table_angle, wsize);
+  Bolos2ring bolos2ring(ringQ, ringU, ringQW, ringUW, table_angle, Bolos_OK, wsize);  
+
+  //  1- pointage
+  vector<FITSTOIReader*> pt(2);
+  for(i=0; i<2; i++) 
+    {
+      pt[i] = new FITSTOIReader(file_pointing[i]);
+      pt[i]->setImplicitSN(long(0));
+      cout << "Opening pointing file " << file_pointing[i] << endl;
+    }
+  //  2- les Bolos
+  vector<FITSTOIReader*> bolo(4);
+  for(i=0; i<4; i++) if (Bolos_OK[i])
+    {
+      bolo[i] = new FITSTOIReader(file_bolo[i]);
+      bolo[i]->setImplicitSN(long(0));
+      cout << "Opening bolometer signal file " << file_bolo[i] << endl;
+    }
+
+  // Creation des tubes:
+  //   1- du pointage vers Bolos2ringQU
+  // chaque fichier de pointage envoie 2 donnees au processor
+  vector<TOI*> toi_pt_theta(2);
+  vector<TOI*> toi_pt_phi(2);
+  for(i=0; i<2; i++)
+    {
+      cout << "Creation des pipes pour Pointage " << i << endl;
+
+      sprintf(str,"toi_theta_%d",i);
+      toi_pt_theta[i] = new TOISegmented(str,wsize);
+      
+      sprintf(str,"toi_phi_%d",i);
+      toi_pt_phi[i] = new TOISegmented(str,wsize);
+
+      pt[i]->addOutput(theta_pointing[i], toi_pt_theta[i]);
+      pt[i]->addOutput(phi_pointing[i], toi_pt_phi[i]);
+
+      sprintf(str,"theta_pointing%d",i);
+      if (PSB == 1) psb2ring.addInput(str, toi_pt_theta[i]);
+      else bolos2ring.addInput(str, toi_pt_theta[i]);
+      sprintf(str,"phi_pointing%d",i);
+      if (PSB == 1) psb2ring.addInput(str, toi_pt_phi[i]);
+      else bolos2ring.addInput(str, toi_pt_phi[i]);
+    }
+  //   2- les Bolos 
+  vector<TOI*> toi_bolo(4);
+  for(i=0; i<4; i++) {
+
+    sprintf(str,"toi_%d",i);
+
+    if (Bolos_OK[i]) {
+      toi_bolo[i] = new TOISegmented(str,wsize);   // creation des tuyaux
+      bolo[i]->addOutput(name_bolo[i], toi_bolo[i]);    // assemblage sortie de Bolos
+
+    } else {
+      NoOpProcessor noop;
+      noop.addOutput(name_bolo[i],toi_bolo[i] );
+    }
+
+    sprintf(str,"Bolo%d",i);
+    if (PSB == 1) psb2ring.addInput(str, toi_bolo[i]); // assemblage entree de Bolos2ringQU 
+    else bolos2ring.addInput(str, toi_bolo[i]);
+  }
+
+  // Maintenant, le traitement est termine, et on doit avoir recupere
+  // les cartes de Q et U dans ringQ et ringU.
+  // Il n'y a plus qu'a ecrire ces cartes sur le disque:
+
+  // TOI
+  FITSTOIWriter wtoiU(toiufile),wtoiQ(toiqfile);
+  wtoiU.setImplicitSN();
+  wtoiQ.setImplicitSN();
+  cout << "fits toi writer created" << endl;
+
+  TOISegmented * toioutQ = new TOISegmented("toi_outQ",wsize);
+  TOISegmented * toioutU = new TOISegmented("toi_outU",wsize);
+  if (PSB == 1) {
+    psb2ring.addOutput("out_toiQ",toioutQ);
+    psb2ring.addOutput("out_toiU",toioutU);
+    wtoiQ.addInput("power",toioutQ);
+    wtoiU.addInput("power",toioutU);
+    cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
+    
+  }    
+
+
+ 
+  // L'assemblage est termine : il reste a lancer les Processors
+  cout << "Starting all processors..." << endl;
+  
+  for(i=0; i<2; i++) pt[i]->start();
+  for(i=0; i<4; i++) bolo[i]->start();
+  if (PSB == 1) {
+    psb2ring.start();
+    wtoiU.start(); 
+    wtoiQ.start(); 
+  }
+  else bolos2ring.start(); 
+
+  cout << "Joining ..." << endl;
+  mgr->joinAll();
+  PrtTim("End threads");
+
+  
+  // Write rings in FITS files
+  FitsOutFile qfits(ringqfile,FitsFile::clear);
+  cout<<"gph524_ring: Creating sphere fits file "<<ringqfile<<endl;
+  qfits << *ringQ;
+  FitsOutFile ufits(ringufile,FitsFile::clear);
+  cout<<"gph524_ring: Creating sphere fits file "<<ringufile<<endl;
+  ufits << *ringU;
+  
+  FitsOutFile qwfits(ringqwfile,FitsFile::clear);
+  cout<<"gph524_ring: Creating sphere fits file "<<ringqwfile<<endl;
+  qwfits << *ringQW;
+  FitsOutFile uwfits(ringuwfile,FitsFile::clear);
+  cout<<"gph524_ring: Creating sphere fits file "<<ringuwfile<<endl;
+  uwfits << *ringUW;
+
+ // Nettoyage
+ cout << "gph524_ring: cleanup " << endl;
+ delete ringQ; delete ringU;
+ delete ringQW; delete ringUW;
+ 
+  return(0);
+  }
+  catch(PThrowable & exc )
+    {
+      cerr << " Catched Exception " << (string)typeid(exc).name() 
+	   << " - Msg= " << exc.Msg() << endl;
+    }
+  catch(...)
+    {
+      cerr << " Catched another exception..." << endl ;
+    }
+
+}
+
+
+
+
Index: /trunk/ArchTOIPipe/files_pipes
===================================================================
--- /trunk/ArchTOIPipe/files_pipes	(revision 1983)
+++ /trunk/ArchTOIPipe/files_pipes	(revision 1984)
@@ -19,2 +19,4 @@
 tstnoisecancel.h
 tstnoisecancel.cc
+gph425_ring.cc
+
Index: /trunk/ArchTOIPipe/files_sophya
===================================================================
--- /trunk/ArchTOIPipe/files_sophya	(revision 1983)
+++ /trunk/ArchTOIPipe/files_sophya	(revision 1984)
@@ -16,2 +16,8 @@
 meanvarestim.h
 meanvarestim.cc
+PSB2ring.h
+PSB2ring.cc
+Bolos2ring.h
+Bolos2ring.cc
+ring33.h
+ring33.cc                                                                                                                                                       
