Index: BAORadio/AmasNancay/trunk/analyse.cc
===================================================================
--- BAORadio/AmasNancay/trunk/analyse.cc	(revision 584)
+++ BAORadio/AmasNancay/trunk/analyse.cc	(revision 593)
@@ -204,5 +204,5 @@
 };
 
-//JEC 22/9/11 Make ON-OFF analysis WO any calibration START
+
 //------------
 //Process ON/OFF Raw data
@@ -216,5 +216,17 @@
   virtual int processCmd() throw(string);
 };
-//JEC 22/9/11 Make ON-OFF analysis WO any calibration END
+
+//------------
+//Process ON/OFF data treated with the mspec (specmfib) => no filtering at all: paquets & freq.
+//------------
+class ProcessONOFFMeanData : public ProcessBase {
+
+public:
+  ProcessONOFFMeanData(){}
+  virtual ~ProcessONOFFMeanData(){}
+  
+  virtual int processCmd() throw(string);
+};
+
 
 //------------
@@ -279,7 +291,6 @@
   //Init process types
   map<string,IProcess*> process;
-  //JEC 22/9/11 Make ON-OFF analysis WO any calibration START
-  process["rawOnOff"] = new ProcessONOFFRawData();
-  //JEC 22/9/11 Make ON-OFF analysis WO any calibration END
+  process["meanONOFF"] = new ProcessONOFFMeanData(); //JEC 27/10/11
+  process["rawOnOff"]  = new ProcessONOFFRawData();  
   process["dataOnOff"] = new ProcessONOFFData();
   process["gain"]      = new ProcessGain();
@@ -391,4 +402,5 @@
        << " dateOfRun = " << dateOfRun << "\n"
        << " spectraDirectory = " << spectraDirectory << "\n"
+       << " spectraName = " << typeOfFile << "\n"
        << " freqBAOCalib = " << freqBAOCalib  << "\n"
        << " bandWidthBAOCalib = " << bandWidthBAOCalib << "\n"
@@ -572,5 +584,5 @@
 int Usage(bool flag) {
   cout << "Analyse.cc usage...." << endl;
-  cout << "analyse  -act <action_type>: dataOnOff, rawOnOff, gain, calib\n"
+  cout << "analyse  -act <action_type>: meanONOFF,dataOnOff, rawOnOff, gain, calib\n"
        << "         -inPath <path for input files: default='.'>\n"
        << "         -outPath <path for output files: default='.'>\n"
@@ -590,5 +602,5 @@
        << "         -calibopt <option>:\n"
        << "            valid for act=calib: indiv OR mean (NOT USED)"
-       << "         -debuglev <number> [0=default]\n"
+       << "         -debug <number> [0=default]\n"
        << "           1: normal print\n"
        << "           2: save intermediate spectra\n"
@@ -649,4 +661,110 @@
   return rc;
 }
+//----------------------------------------------
+//JEC 27/10/11
+//Process the files that are output of the specmfib -act = mspec (mean+sigma of signal files)
+//----------------------------------------------
+int ProcessONOFFMeanData::processCmd() throw(string) {
+  int rc = 0;
+  try {
+    rc = ProcessBase::processCmd();
+  } 
+  catch (string s) {
+    throw s;
+  }
+
+  if(debuglev_>0)cout << "Process Data" << endl;
+  vector<string> modeList;
+  modeList.push_back("On");
+  modeList.push_back("Off");
+  vector<string>::const_iterator iMode;
+  
+  uint_4 id; 
+  string tag;
+
+  map< pair<string, sa_size_t>, TMatrix<r_4> > spectreCollect;
+  map< pair<string, sa_size_t>, TMatrix<r_4> >::iterator iSpectre, iSpectreEnd;
+  
+  for (iMode = modeList.begin(); iMode != modeList.end(); ++iMode) {
+    string mode = *iMode;
+    if(debuglev_>0)cout << "Process Mean-mspec Mode " << mode << endl;
+
+    //------------------------------------------
+    //Produce mean of the mean spectra per cycle
+    //------------------------------------------
+
+    string directoryName;
+    list<string> listOfSpecFiles;
+    list<string>::const_iterator iFile, iFileEnd;
+   
+        
+    //
+    //loop on cycles
+    //
+    for (sa_size_t icycle = ifirstCycle_; icycle <= ilastCycle_; icycle++) {
+      directoryName = inputPath_ + "/" 
+	+ sourceName_ + "/" + dateOfRun_ + StringToLower(sourceName_) + "/"
+	+ mode + "/";
+      stringstream sicycle;
+      sicycle << icycle;
+      directoryName += spectraDirectory_ + sicycle.str() + "/";
+
+      //read directory
+      listOfSpecFiles = ListOfFileInDir(directoryName,typeOfFile_);
+      
+
+      //compute mean of spectra created in a cycle
+      if(debuglev_>0)cout << "compute mean for cycle " << icycle << endl;
+      TMatrix<r_4> spectreMean(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ); //implicit init to 0
+      iFileEnd = listOfSpecFiles.end();
+      r_4 nSpectres  = 0;
+      for (iFile = listOfSpecFiles.begin(); iFile != iFileEnd; ++iFile) {
+	FitsInOutFile aSpectrum(*iFile,FitsInOutFile::Fits_RO);
+	TMatrix<r_4> spectre(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ);
+	aSpectrum >> spectre;
+	spectreMean += spectre;
+	nSpectres++;
+      }// end of for files 
+      if(nSpectres>0) spectreMean /= nSpectres;
+      
+      //save mean spectrum
+      spectreCollect.insert( pair< pair<string,sa_size_t>, TMatrix<r_4> >(make_pair(mode,icycle),TMatrix<r_4>(spectreMean,false) ));
+    }//end of for cycles
+  }//end loop on mode for raw preocess
+
+  if(debuglev_>1) {//save mean spectra on file 
+    cout << "Save mean spectra" << endl;
+    string fileName;
+
+    fileName = "./dataMean_" + dateOfRun_ + "_" + StringToLower(sourceName_) + ".ppf";
+
+    POutPersist fos(fileName);
+    id=0;
+    iSpectreEnd = spectreCollect.end();
+    for (iSpectre = spectreCollect.begin();
+	 iSpectre != iSpectreEnd ; ++iSpectre, ++id) {
+      tag = "specMean";
+
+      tag += (iSpectre->first).first;
+      stringstream sid;
+      sid << (iSpectre->first).second;
+      tag += sid.str();
+      if(debuglev_>9) {
+ 	cout << "save tag<" << tag << ">" << endl;
+      }
+
+      fos << PPFNameTag(tag) << iSpectre->second;
+    }
+  }//end of save fits
+  
+
+
+
+
+  cout << "OK ProcessONOFFMeanData finished" <<endl;
+  return rc;
+}
+//----------------------------------------------
+
 //JEC 22/9/11 Make ON-OFF analysis WO any calibration START
 //----------------------------------------------
@@ -693,5 +811,7 @@
     //
     for (sa_size_t icycle = ifirstCycle_; icycle <= ilastCycle_; icycle++) {
-      directoryName = "./" + mode + "/";
+      directoryName = inputPath_ + "/" 
+	+ sourceName_ + "/" + dateOfRun_ + StringToLower(sourceName_) + "/"
+	+ mode + "/";
       stringstream sicycle;
       sicycle << icycle;
@@ -884,5 +1004,5 @@
     throw s;
   }
-   if(debuglev_>0)cout << "Process Data" << endl;
+  if(debuglev_>0)cout << "Process Data" << endl;
   vector<string> modeList;
   modeList.push_back("On");
