Ignore:
Timestamp:
Sep 22, 2011, 10:32:01 AM (13 years ago)
Author:
campagne
Message:

add dump; sort input file list; correct input opts treatment bug (jec)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • BAORadio/AmasNancay/analyse.cc

    r514 r523  
    8383}
    8484//-----
     85//JEC 22/9/11 comparison, not case sensitive to sort File liste START
     86bool stringCompare( const string &left, const string &right ){
     87   if( left.size() < right.size() )
     88      return true;
     89   return false;
     90   for( string::const_iterator lit = left.begin(), rit = right.begin(); lit != left.end() && rit != right.end(); ++lit, ++rit )
     91      if( tolower( *lit ) < tolower( *rit ) )
     92         return true;
     93      else if( tolower( *lit ) > tolower( *rit ) )
     94         return false;
     95}//JEC 22/9/11 comparison, not case sensitive to sort File liste END
     96//-----
    8597list<string> ListOfFileInDir(string dir, string filePettern) throw(string) {
    8698  list<string> theList;
     
    89101  DIR *dip;
    90102  struct dirent *dit;
    91   string msg;
    92   string fileName;
     103  string msg;  string fileName;
    93104  string fullFileName;
    94105  size_t found;
     
    111122    throw msg;
    112123  }
     124 
     125  //JEC 22/9/11 START
     126  theList.sort(stringCompare);
     127  //JEC 22/9/11 END
     128
    113129  return theList;
    114130}
     
    290306      ka+=2;
    291307    }
    292     if (strcmp(arg[ka],"-act")==0) {
     308    else if (strcmp(arg[ka],"-act")==0) {
    293309      action=arg[ka+1];
    294310      ka+=2;
    295311    }
    296     if (strcmp(arg[ka],"-inPath")==0) {
     312    else if (strcmp(arg[ka],"-inPath")==0) {
    297313      inputPath=arg[ka+1];
    298314      ka+=2;
    299315    }
    300     if (strcmp(arg[ka],"-outPath")==0) {
     316    else if (strcmp(arg[ka],"-outPath")==0) {
    301317      outputPath=arg[ka+1];
    302318      ka+=2;
     
    346362
    347363
     364  //JEC 21/9/11 Give the input parameters START
     365  cout << " action " << action << "\n"
     366       << " inputPath = " << inputPath << "\n"
     367       << " outputPath = " << outputPath << "\n"
     368       << " sourceName = " << sourceName << "\n"
     369       << " scaFile = " << scaFile << "\n"
     370       << " dateOfRun = " << dateOfRun << "\n"
     371       << " spectraDirectory = " << spectraDirectory << "\n"
     372       << " freqBAOCalib = " << freqBAOCalib  << "\n"
     373       << " bandWidthBAOCalib = " << bandWidthBAOCalib << "\n"
     374       << " debuglev = "  << debuglev  << "\n"
     375       << " mode = " << mode << "\n"
     376       << " numcycle = " << numcycle << "\n"
     377       << " calibrationOpt = " << calibrationOpt << endl;
     378  //JEC 21/9/11 Give the input parameters END
     379
    348380
    349381  try {
     
    356388    }
    357389   
     390
     391
     392
    358393
    359394    //
     
    671706         iSpectre != iSpectreEnd ; ++iSpectre, ++id) {
    672707      tag = "specRaw";
     708
     709      //JEC 20/9/11 modif tag to take into account Mode and Cycle number START
     710//       stringstream sid;
     711//       sid << id;
     712//       tag += sid.str();
     713      tag += (iSpectre->first).first;
    673714      stringstream sid;
    674       sid << id;
     715      sid << (iSpectre->first).second;
    675716      tag += sid.str();
     717      if(debuglev_>9) {
     718        cout << "save tag<" << tag << ">" << endl;
     719      }
     720      //JEC 20/9/11 modif tag to take into account Mode and Cycle number END
     721
    676722      fos << PPFNameTag(tag) << iSpectre->second;
    677723    }
     
    687733    //------------------------------------------
    688734    //Read BAO calibration files
    689     TMatrix<r_4> calibBAOfactors;
    690735    sa_size_t nr,nc; //values read
    691     bool first = true;
    692 
    693     for (sa_size_t iCh=0;iCh<NUMBER_OF_CHANNELS;++iCh){
    694       string calibFileName = "./" + sourceName_ + "/"
    695         + dateOfRun_ + StringToLower(sourceName_) + "-" + mode + "-" + freqBAOCalibration_ + "MHz";
    696       stringstream channel;
    697       channel << iCh;
    698       calibFileName += "-Ch" + channel.str() + "Cycles.txt";
    699       if(debuglev_>0) cout << "Read file " << calibFileName << endl;
    700       ifstream ifs(calibFileName.c_str());
    701       if ( ! ifs.is_open() ) {
    702         rc = 999;
    703         throw calibFileName + " cannot be opened...";
    704       }
    705       TVector<r_4> aCalib;
    706       aCalib.ReadASCII(ifs,nr,nc);
    707       if(first){
    708         first = false;
    709         calibBAOfactors.SetSize(NUMBER_OF_CHANNELS,nr);
    710       }
    711       calibBAOfactors( Range(iCh), Range::all() ) = aCalib.Transpose();
    712       ifs.close();
    713     }//end of loop on channels
    714 
     736//JEC 20/9/11 use mean calibration coeff upon all cycles START
     737//    bool first = true;
     738//    TMatrix<r_4> calibBAOfactors;
     739//     for (sa_size_t iCh=0;iCh<NUMBER_OF_CHANNELS;++iCh){
     740//       string calibFileName = inputPath_+ "/"
     741//      + sourceName_ + "/" + dateOfRun_ + StringToLower(sourceName_)
     742//      + "/calib_" + dateOfRun_ + "_" + StringToLower(sourceName_) + "_"
     743//      + mode + "_" + freqBAOCalibration_ + "MHz";
     744//       stringstream channel;
     745//       channel << iCh;
     746//       calibFileName += "-Ch" + channel.str() + "Cycles.txt";
     747//       if(debuglev_>0) cout << "Read file " << calibFileName << endl;
     748//       ifstream ifs(calibFileName.c_str());
     749//       if ( ! ifs.is_open() ) {
     750//      rc = 999;
     751//      throw calibFileName + " cannot be opened...";
     752//       }     
     753//       TVector<r_4> aCalib;
     754//       if(debuglev_>9) cout << "Debug 1" << endl;
     755//       aCalib.ReadASCII(ifs,nr,nc);
     756//       if(debuglev_>9) cout << "Debug 2" << endl;
     757//       if(first){
     758//      first = false;
     759//      if(debuglev_>9) cout << "Debug 3" << endl;
     760//      calibBAOfactors.SetSize(NUMBER_OF_CHANNELS,nr);
     761//      if(debuglev_>9) cout << "Debug 4" << endl;
     762//       }
     763//       calibBAOfactors( Range(iCh), Range::all() ) = aCalib.Transpose();
     764//       if(debuglev_>9) cout << "Debug 5" << endl;
     765//       ifs.close();
     766//     }//end of loop on channels
     767
     768   
     769    string calibFileName = inputPath_+ "/"
     770      + sourceName_ + "/" + dateOfRun_ + StringToLower(sourceName_)
     771      + "/calib_" + dateOfRun_ + "_" + StringToLower(sourceName_) + "_"
     772      + mode + "_" + freqBAOCalibration_ + "MHz-All.txt";
     773
     774    if(debuglev_>0) cout << "Read file " << calibFileName << endl;
     775    ifstream ifs(calibFileName.c_str());
     776    if ( ! ifs.is_open() ) {
     777      rc = 999;
     778      throw calibFileName + " cannot be opened...";
     779    }   
     780    TVector<r_4> calibBAOfactors;
     781    if(debuglev_>9) cout << "Debug 1" << endl;
     782    calibBAOfactors.ReadASCII(ifs,nr,nc);
     783    if(debuglev_>9){
     784      cout << "Debug 2: (nr,nc): "<< nr << "," << nc << endl;
     785      calibBAOfactors.Print(cout);
     786    }
     787
     788//JEC 20/9/11 use mean calibration coeff upon all cycles END
    715789
    716790    //
    717791    //spectra corrected by BAO calibration factor
    718     //make it different on Channels and Cycles (1/06/2011)
     792    //-----make it different on Channels and Cycles (1/06/2011) OBSOLETE
     793    //use mean calibration coeff upon all cycles (20/6/11)
    719794    //warning cycles are numbered from 1,...,N
    720795    //
     
    724799     
    725800      for (sa_size_t iCh=0;iCh<NUMBER_OF_CHANNELS;++iCh){
    726         specmtx( Range(iCh), Range::all() ) /= calibBAOfactors(iCh,icycle-1);
     801        //JEC 20/9/11 use mean calibration coeff upon all cycles START
     802
     803        //      specmtx( Range(iCh), Range::all() ) /= calibBAOfactors(iCh,icycle-1);
     804        specmtx( Range(iCh), Range::all() ) /= calibBAOfactors(iCh);
     805        //JEC 20/9/11 use mean calibration coeff upon all cycles END
    727806      }
    728807    }
     
    739818    id=0;
    740819    for (iSpectre = spectreCollect.begin();iSpectre != iSpectreEnd ; ++iSpectre, ++id) {
     820
    741821      tag = "specBAOCalib";
     822      //JEC 20/9/11 modif tag to take into account Mode and Cycle number START
     823//       stringstream sid;
     824//       sid << id;
     825//       tag += sid.str();
     826      tag += (iSpectre->first).first;
    742827      stringstream sid;
    743       sid << id;
     828      sid << (iSpectre->first).second;
    744829      tag += sid.str();
    745       fos << PPFNameTag(tag) << (*iSpectre).second;
     830      if(debuglev_>9) {
     831        cout << "save tag<" << tag << ">" << endl;
     832      }
     833      //JEC 20/9/11 modif tag to take into account Mode and Cycle number END
     834
     835      fos << PPFNameTag(tag) << iSpectre->second;
    746836    }
    747837  }//end of save fits
     
    775865    for (iSpectre = spectreCollect.begin();iSpectre != iSpectreEnd ; ++iSpectre, ++id) {
    776866      tag = "specBAORTCalib";
     867      //JEC 20/9/11 modif tag to take into account Mode and Cycle number START
     868//       stringstream sid;
     869//       sid << id;
     870//       tag += sid.str();
     871      tag += (iSpectre->first).first;
    777872      stringstream sid;
    778       sid << id;
     873      sid << (iSpectre->first).second;
    779874      tag += sid.str();
    780       fos << PPFNameTag(tag) << (*iSpectre).second;
     875      if(debuglev_>9) {
     876        cout << "save tag<" << tag << ">" << endl;
     877      }
     878      //JEC 20/9/11 modif tag to take into account Mode and Cycle number END
     879      fos << PPFNameTag(tag) << iSpectre->second;
    781880    }
    782881  }//end of save fits
     
    821920      tag = "specONOFF";
    822921      stringstream sid;
    823       sid << id;
     922      //JEC 20/9/11      sid << id;
     923      sid << iDiff->first;
    824924      tag += sid.str();
    825       fos << PPFNameTag(tag) << (*iDiff).second;
     925      if(debuglev_>9) {
     926        cout << "save tag<" << tag << ">" << endl;
     927      }
     928      fos << PPFNameTag(tag) << iDiff->second;
    826929    }
    827930    //save the mean also
     
    869972  iFileEnd = listOfSpecFiles.end();
    870973  map<string, r_4> meanpowerCollect;
     974  //JEC 21/9/11 add meanpower for each Channels START
     975  map<string, r_4> meanPowerPerChanCollect;
     976  //JEC 21/9/11 add meanpower for each Channels END
     977
    871978  map<string, r_4>::const_iterator iMeanPow, iMeanPowEnd;
    872979
     
    876983    aSpectrum >> spectre;
    877984    meanpowerCollect[*iFile] = spectre.Sum()/spectre.Size();
     985    //JEC 21/9/11 add meanpower for each Channels START
     986    for (sa_size_t iCh=0; iCh<NUMBER_OF_CHANNELS; ++iCh) {
     987      TVector<r_4> specChan(NUMBER_OF_FREQ);
     988      specChan = spectre.Row(iCh).Transpose();
     989      stringstream tmp;
     990      tmp << iCh;
     991      string tag = *iFile + "_" + tmp.str();
     992      meanPowerPerChanCollect[tag] = specChan.Sum()/specChan.Size();
     993    }
     994    //JEC 21/9/11 add meanpower for each Channels END
    878995  }//end of for files
    879996  pair<string, r_4> minelement = *min_element(meanpowerCollect.begin(),meanpowerCollect.end(),compare);
     
    9291046  {
    9301047    vector<r_4> tmp;
     1048    //JEC 21/9/11 add meanpower for each Channels START
     1049    vector<r_4> tmpCh0; //for Chan 0
     1050    vector<r_4> tmpCh1; //for Chan 1
     1051    //JEC 21/9/11 add meanpower for each Channels END
    9311052    for (iFile = listOfSpecFiles.begin(); iFile != iFileEnd; ++iFile) {
     1053      if (debuglev_>9) {
     1054        cout << "Gain: save mean power of file: " << *iFile << endl;
     1055      }
    9321056      tmp.push_back(meanpowerCollect[*iFile]);
     1057      //JEC 21/9/11 add meanpower for each Channels START 
     1058      stringstream tmp0;
     1059      tmp0 << (sa_size_t)0;
     1060      string tag0 = *iFile + "_" + tmp0.str();
     1061      tmpCh0.push_back(meanPowerPerChanCollect[tag0]);
     1062      if (NUMBER_OF_CHANNELS>1){
     1063        stringstream tmp1;
     1064        tmp1 << (sa_size_t)1;
     1065        string tag1 = *iFile + "_" + tmp1.str();
     1066        tmpCh1.push_back(meanPowerPerChanCollect[tag1]);
     1067      }
     1068      //JEC 21/9/11 add meanpower for each Channels END
    9331069    }
    9341070    string fileName;
     
    9371073    POutPersist fos(fileName);
    9381074    TVector<r_4> tvtmp(tmp);
    939     fos.PutObject(tvtmp,"gainmoni");
    940   }
    941  
    942 
     1075    fos.PutObject(tvtmp,"gainmoni"); //Attention initialement le tag etait "monitor"...
     1076    //JEC 21/9/11 add meanpower for each Channels START 
     1077    TVector<r_4> tvtmp0(tmpCh0);
     1078    fos.PutObject(tvtmp0,"gainmoni0");
     1079    if (NUMBER_OF_CHANNELS>1){
     1080      TVector<r_4> tvtmp1(tmpCh1);
     1081      fos.PutObject(tvtmp1,"gainmoni1");
     1082    }
     1083    //JEC 21/9/11 add meanpower for each Channels END
     1084  }
     1085 
    9431086  cout << "OK gain finished" <<endl;
    9441087   return rc;
Note: See TracChangeset for help on using the changeset viewer.