| 1 | #include "branap.h"
 | 
|---|
| 2 | #include "minifits.h"
 | 
|---|
| 3 | #include "strutilxx.h"
 | 
|---|
| 4 | #include "sopnamsp.h"
 | 
|---|
| 5 | 
 | 
|---|
| 6 | //--------------------------------------------------------------
 | 
|---|
| 7 | // Projet BAORadio - (C) LAL/IRFU  2008-2010
 | 
|---|
| 8 | // Classe de gestion des parametres programmes d'analyse 
 | 
|---|
| 9 | //--------------------------------------------------------------
 | 
|---|
| 10 | 
 | 
|---|
| 11 | /* --Methode-- */
 | 
|---|
| 12 | BRAnaParam::BRAnaParam(uint_4 nmean, uint_4 nzon, uint_4 npaqz)
 | 
|---|
| 13 | {
 | 
|---|
| 14 |   outpath_="./";
 | 
|---|
| 15 |   nmean_=nmean;
 | 
|---|
| 16 |   nbloc_=1;
 | 
|---|
| 17 |   imin_=imax_=0;
 | 
|---|
| 18 |   istep_=1;
 | 
|---|
| 19 |   freqmin_=freqmax_=0;
 | 
|---|
| 20 |   nbinfreq_=1;  
 | 
|---|
| 21 |   paqsize_=16424;
 | 
|---|
| 22 |   nzones_=nzon;
 | 
|---|
| 23 |   npaqinzone_=npaqz;
 | 
|---|
| 24 |   prtlevel_=0;
 | 
|---|
| 25 | }
 | 
|---|
| 26 | 
 | 
|---|
| 27 | /* --Methode-- */
 | 
|---|
| 28 | int BRAnaParam::DecodeArgs(int narg, char* arg[])
 | 
|---|
| 29 | {
 | 
|---|
| 30 |   if ((narg>1)&&(strcmp(arg[1],"-h")==0))  return Usage(false);
 | 
|---|
| 31 |   if (narg<5) return Usage(true);
 | 
|---|
| 32 | 
 | 
|---|
| 33 |   bool okarg=false;
 | 
|---|
| 34 |   int ka=1;
 | 
|---|
| 35 |   while (ka<(narg-1)) {
 | 
|---|
| 36 |     if (strcmp(arg[ka],"-act")==0) {
 | 
|---|
| 37 |       action_=arg[ka+1];
 | 
|---|
| 38 |       ka+=2;
 | 
|---|
| 39 |     }
 | 
|---|
| 40 |     else if (strcmp(arg[ka],"-out")==0) {
 | 
|---|
| 41 |       outpath_=arg[ka+1];
 | 
|---|
| 42 |       size_t lenp=outpath_.size();
 | 
|---|
| 43 |       if ((lenp>0)&&(outpath_[lenp-1]!='/'))  outpath_+='/';
 | 
|---|
| 44 |       ka+=2;
 | 
|---|
| 45 |     }
 | 
|---|
| 46 |     else if (strcmp(arg[ka],"-nmean")==0) {
 | 
|---|
| 47 |       nmean_=atoi(arg[ka+1]);
 | 
|---|
| 48 |       ka+=2;
 | 
|---|
| 49 |     }
 | 
|---|
| 50 |     else if (strcmp(arg[ka],"-nbloc")==0) {
 | 
|---|
| 51 |       nbloc_=atoi(arg[ka+1]);
 | 
|---|
| 52 |       ka+=2;
 | 
|---|
| 53 |     }
 | 
|---|
| 54 |     else if (strcmp(arg[ka],"-freq")==0) {
 | 
|---|
| 55 |       sscanf(arg[ka+1],"%d,%d,%d",&freqmin_,&freqmax_,&nbinfreq_);  
 | 
|---|
| 56 |       ka+=2;
 | 
|---|
| 57 |     }
 | 
|---|
| 58 |     else if (strcmp(arg[ka],"-zones")==0) {
 | 
|---|
| 59 |       int nzon=4;
 | 
|---|
| 60 |       int npaqz=128;
 | 
|---|
| 61 |       sscanf(arg[ka+1],"%d,%d",&nzon,&npaqz);
 | 
|---|
| 62 |       nzones_=nzon;  npaqinzone_=npaqz;
 | 
|---|
| 63 |       ka+=2;
 | 
|---|
| 64 |     }
 | 
|---|
| 65 |     else if (strcmp(arg[ka],"-prtlev")==0) {
 | 
|---|
| 66 |       prtlevel_=atoi(arg[ka+1]);
 | 
|---|
| 67 |       ka+=2;
 | 
|---|
| 68 |     }
 | 
|---|
| 69 |     else if (strcmp(arg[ka],"-in")==0) {
 | 
|---|
| 70 |       if ((narg-ka)<4)  {
 | 
|---|
| 71 |         cout << " BRAnaParam::DecodeArgs() / Argument error " << endl;
 | 
|---|
| 72 |         return Usage(true);
 | 
|---|
| 73 |       }
 | 
|---|
| 74 |       sscanf(arg[ka+1],"%d,%d,%d",&imin_,&imax_,&istep_);  ka+=2;
 | 
|---|
| 75 |       while(ka<(narg-1)) {
 | 
|---|
| 76 |         string inpath = arg[ka]; 
 | 
|---|
| 77 |         size_t lenp=inpath.size();
 | 
|---|
| 78 |         if (lenp<1)  inpath="./";
 | 
|---|
| 79 |         if ((lenp>0)&&(inpath[lenp-1]!='/'))  inpath+='/';
 | 
|---|
| 80 |         vector<string> fiblist;
 | 
|---|
| 81 |         string sa1 = arg[ka+1]; 
 | 
|---|
| 82 |         FillVStringFrString(sa1, fiblist, ',');
 | 
|---|
| 83 |         char dbuff[32];
 | 
|---|
| 84 |         for(size_t i=0; i<fiblist.size(); i++) {
 | 
|---|
| 85 |           sprintf(dbuff,"Fiber%d/",(int)atoi(fiblist[i].c_str()));
 | 
|---|
| 86 |           dirlist_.push_back(inpath+dbuff);
 | 
|---|
| 87 |         }
 | 
|---|
| 88 |         ka += 2;
 | 
|---|
| 89 |       }
 | 
|---|
| 90 |       okarg=true;
 | 
|---|
| 91 |     }
 | 
|---|
| 92 |     else ka++;
 | 
|---|
| 93 |   }
 | 
|---|
| 94 | 
 | 
|---|
| 95 |   if (!okarg) {
 | 
|---|
| 96 |     cout << " BRAnaParam::DecodeArgs() / Argument error " << endl;
 | 
|---|
| 97 |     return Usage(true);
 | 
|---|
| 98 |   }
 | 
|---|
| 99 |   return 0;
 | 
|---|
| 100 | }
 | 
|---|
| 101 | 
 | 
|---|
| 102 | /* --Methode-- */
 | 
|---|
| 103 | int BRAnaParam::Usage(bool fgshort)
 | 
|---|
| 104 | {
 | 
|---|
| 105 |   cout << " --- BRAnaParam : Reading/Processing BAORadio FITS files parameters " << endl;
 | 
|---|
| 106 |   cout << " Usage:  prgname [-act ACT] [-out OutPath] [-nmean NMean] [-zones NZones,nPaqinZone] \n" 
 | 
|---|
| 107 |        << "                 [-nbloc NBloc] [-freq NumFreqMin,NumFreqMax,NBinFreq] [-prtlev lev] \n" 
 | 
|---|
| 108 |        << "         -in Imin,Imax,Istep InPath FiberList [InPath2 FiberList2 InPath3 FiberList3 ...] \n" << endl; 
 | 
|---|
| 109 |   if (fgshort) {
 | 
|---|
| 110 |     cout << " prgname -h for detailed instructions" << endl;
 | 
|---|
| 111 |     return 5;
 | 
|---|
| 112 |   }
 | 
|---|
| 113 |   cout << " -act Action: cube3d or vis   \n"
 | 
|---|
| 114 |        << " -out OutPath: Output directory name \n"
 | 
|---|
| 115 |        << " -nmean NMean: Number of packet used for spectra/visibility computation \n"
 | 
|---|
| 116 |        << " -nbloc NBloc: Number of MemMgr blocs in output file\n"
 | 
|---|
| 117 |        << " -zones NZones,NbPaqinZone : Number of Zones and number of paquets in one zone \n" 
 | 
|---|
| 118 |        << " -freq NumFreqMin,NumFreqMax,NBinFreq : Frequency zone and number of bins \n" 
 | 
|---|
| 119 |        << " -prtlev lev : Print level (0,1,2...) \n" 
 | 
|---|
| 120 |        << " -in : input files/directory definition : \n"
 | 
|---|
| 121 |        << "       Imin,Imax,Istep: fits files signalII.fits Imin<=II<=Imax Istep=increment \n" 
 | 
|---|
| 122 |        << "       InPath: Input directerory fits files in InPath/FiberJJ directory \n"
 | 
|---|
| 123 |        << "       FiberList: List of fiber numbers (JJ - Ex: 2,1,4 )  \n" << endl;
 | 
|---|
| 124 |   return 1;
 | 
|---|
| 125 | }
 | 
|---|
| 126 | 
 | 
|---|
| 127 | /* --Fonction-- */
 | 
|---|
| 128 | int BRAnaParam::PaqSizeFromFits()
 | 
|---|
| 129 | {
 | 
|---|
| 130 |   uint_4 paqsz, npaqf;
 | 
|---|
| 131 |   char flnm[1024];
 | 
|---|
| 132 |   sprintf(flnm,"%s/signal%d.fits",dirlist_[0].c_str(),imin_);
 | 
|---|
| 133 |   return DecodeMiniFitsHeader(flnm,paqsize_, npaqf); 
 | 
|---|
| 134 | }
 | 
|---|
| 135 | 
 | 
|---|
| 136 | /* --Fonction-- */
 | 
|---|
| 137 | ostream& BRAnaParam::Print(ostream& os)
 | 
|---|
| 138 | {
 | 
|---|
| 139 |   os << " BRAnaParam::Print() dirlist_.size()=" << dirlist_.size() << " Input directories: " << endl;
 | 
|---|
| 140 |   for(size_t k=0; k< dirlist_.size(); k++) 
 | 
|---|
| 141 |     cout << k+1 << " :  " << dirlist_[k] << endl;
 | 
|---|
| 142 |   cout << " IMin= " << imin_ << " IMax= " << imax_ << " IStep= " << istep_ << endl;
 | 
|---|
| 143 |   cout << " OutPath= " << outpath_ << endl;
 | 
|---|
| 144 |   cout << " Action=" << action_ << "  NMean=" << nmean_ << " NBloc=" << nbloc_ << endl;
 | 
|---|
| 145 |   cout << " FreqMin= " << freqmin_ << " FreqMax= " << freqmax_ << " NBinFreq= " << nbinfreq_ << endl;
 | 
|---|
| 146 |   cout << " PaqSize=" << paqsize_ << "  -  NZones=" << nzones_ << " NPaqZone=" << npaqinzone_ 
 | 
|---|
| 147 |        << " PrtLevel=" << prtlevel_ << endl;
 | 
|---|
| 148 |   return os;
 | 
|---|
| 149 | }
 | 
|---|
| 150 | 
 | 
|---|
| 151 | /* --Fonction-- */
 | 
|---|
| 152 | int BRAnaParam::DecodeMiniFitsHeader(const char* filename, uint_4& paqsz, uint_4& npaq) 
 | 
|---|
| 153 | {
 | 
|---|
| 154 |   cout << " DecodeMiniFitsHeader - Opening file: " << filename << endl;
 | 
|---|
| 155 |   MiniFITSFile mff(filename, MF_Read);
 | 
|---|
| 156 |   cout << "DecodeMiniFitsHeader()... Type=" << mff.DataTypeToString() << " NAxis1=" << mff.NAxis1() 
 | 
|---|
| 157 |        << " NAxis2=" << mff.NAxis2() << endl;
 | 
|---|
| 158 |   paqsz = mff.NAxis1();
 | 
|---|
| 159 |   npaq = mff.NAxis2();
 | 
|---|
| 160 |   return 0;
 | 
|---|
| 161 | }
 | 
|---|
| 162 | 
 | 
|---|