[1497] | 1 | /* Test de GenWindowTOIProcessor (generic processor with window)
|
---|
| 2 |
|
---|
| 3 | ---------------- Exemple d'appel ---------------------
|
---|
| 4 | csh> time ./tgenw -intoi bolo -start 1 -end 50000 -wgen 128,1,256 \
|
---|
| 5 | bols.fits xx.fits
|
---|
| 6 | // CMV tester wgen 16,64,...
|
---|
| 7 | */
|
---|
| 8 |
|
---|
| 9 |
|
---|
| 10 |
|
---|
| 11 | #include "machdefs.h"
|
---|
| 12 | #include <math.h>
|
---|
| 13 | #include "array.h"
|
---|
| 14 | #include <unistd.h>
|
---|
| 15 | #include <stdexcept>
|
---|
| 16 | #include "toi.h"
|
---|
| 17 | #include "toiprocessor.h"
|
---|
| 18 | #include "fitstoirdr.h"
|
---|
| 19 | #include "fitstoiwtr.h"
|
---|
| 20 | #include "toimanager.h"
|
---|
| 21 | #include "genwproc.h"
|
---|
| 22 | #include "toiseqbuff.h"
|
---|
| 23 | #include "timing.h"
|
---|
| 24 | #include "sambainit.h"
|
---|
| 25 |
|
---|
| 26 | // ----- Classe de test heritant de GenWindowTOIProcessor -----
|
---|
| 27 | class TGenWProc : public GenWindowTOIProcessor {
|
---|
| 28 | public:
|
---|
| 29 | TGenWProc(int wsz, int step, int wt);
|
---|
| 30 | virtual void UserInit(int_8 kstart);
|
---|
| 31 | virtual void UserProc(int_8 ks);
|
---|
| 32 | virtual void UserEnd(int_8 kend);
|
---|
| 33 |
|
---|
| 34 | };
|
---|
| 35 |
|
---|
| 36 | TGenWProc::TGenWProc(int wsz, int step, int wt)
|
---|
| 37 | : GenWindowTOIProcessor(1,1,wsz,step,wt)
|
---|
| 38 | {
|
---|
| 39 | }
|
---|
| 40 | void TGenWProc::UserInit(int_8 kstart)
|
---|
| 41 | {
|
---|
| 42 | cout << "TGenWProc::UserInit(" << kstart << ")" << endl;
|
---|
| 43 | }
|
---|
| 44 | void TGenWProc::UserEnd(int_8 kend)
|
---|
| 45 | {
|
---|
| 46 | cout << "TGenWProc::UserEnd(" << kend << ")" << endl;
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | void TGenWProc::UserProc(int_8 ks)
|
---|
| 50 | {
|
---|
| 51 | if ( (ks == StartSampleNum()) || (ks >= EndSampleNum()-1) || (ks%1000 == 0) )
|
---|
| 52 | cout << "TGenWProc::UserProc(" << ks << ") CenterSample=" << GetCenterSample() << endl;
|
---|
| 53 | if (GetWStep() > 1) {
|
---|
| 54 | TVector<r_8> data;
|
---|
| 55 | TVector<int_8> flag;
|
---|
| 56 | data = GetWData()(Range(GetWSize()/2,0,GetWStep()));
|
---|
| 57 | flag = GetWFlag()(Range(GetWSize()/2,0,GetWStep()));
|
---|
| 58 | PutWData(GetCenterSample(), data, flag);
|
---|
| 59 | }
|
---|
| 60 | else {
|
---|
| 61 | // PutWData(GetCenterSample(), GetWData()(GetWSize()/2), GetWFlag()(GetWSize()/2));
|
---|
| 62 | r_8 data;
|
---|
| 63 | int_8 flag;
|
---|
| 64 | GetData(GetCenterSample(), data, flag);
|
---|
| 65 | PutWData(GetCenterSample(), data, flag);
|
---|
| 66 | }
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | void Usage(bool fgerr)
|
---|
| 70 | {
|
---|
| 71 | cout << endl;
|
---|
| 72 | if (fgerr) {
|
---|
| 73 | cout << " tgenw : Argument Error ! tgenw -h for usage " << endl;
|
---|
| 74 | exit(1);
|
---|
| 75 | }
|
---|
| 76 | else {
|
---|
| 77 | cout << "\n Usage : tgenw [-dbg] [-start snb] [-end sne] [-intoi name] \n"
|
---|
| 78 | << " [-wtoi sz] [-wgen sz,step,szt] inFitsName outFitsName \n"
|
---|
| 79 | << " -dbg : sets TOISeqBuffered debug level to 1 \n"
|
---|
| 80 | << " -start snb : sets the start sample num \n"
|
---|
| 81 | << " -end sne : sets the end sample num \n"
|
---|
| 82 | << " -intoi toiName : select input TOI name (def boloMuV_27)\n"
|
---|
| 83 | << " -wtoi sz : sets TOISeqBuff buffer size (def= 8192)\n"
|
---|
| 84 | << " -wgen sz,step,szt : sets GenWProc window size, step total size \n"
|
---|
| 85 | << endl;
|
---|
| 86 | exit(0);
|
---|
| 87 | }
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | int main(int narg, char** arg) {
|
---|
| 91 |
|
---|
| 92 | if ((narg > 1) && (strcmp(arg[1],"-h") == 0) ) Usage(false);
|
---|
| 93 |
|
---|
| 94 | cout << "tgenw starting - Decoding arguments " << " narg=" << narg << endl;
|
---|
| 95 |
|
---|
| 96 | bool fgdbg = false;
|
---|
| 97 | bool fgsetstart = false;
|
---|
| 98 | int wtoi = 8192;
|
---|
| 99 | int wgen = 16;
|
---|
| 100 | int stepgen = 1;
|
---|
| 101 | int wtotgen = 0;
|
---|
| 102 | int istart = 0;
|
---|
| 103 | int iend = 0;
|
---|
| 104 | string infile;
|
---|
| 105 | string outfile;
|
---|
| 106 | string outppfname;
|
---|
| 107 | string intoi = "boloMuV_27";
|
---|
| 108 |
|
---|
| 109 | if (narg < 3) Usage(true);
|
---|
| 110 | int ko=1;
|
---|
| 111 | // decoding arguments
|
---|
| 112 | for(int ia=1; ia<narg; ia++) {
|
---|
| 113 | if (strcmp(arg[ia],"-start") == 0) {
|
---|
| 114 | if (ia == narg-1) Usage(true); // -start est suivi d'un argument
|
---|
| 115 | istart = atoi(arg[ia+1]); ia++;
|
---|
| 116 | fgsetstart = true;
|
---|
| 117 | }
|
---|
| 118 | else if (strcmp(arg[ia],"-end") == 0) {
|
---|
| 119 | if (ia == narg-1) Usage(true);
|
---|
| 120 | iend = atoi(arg[ia+1]); ia++;
|
---|
| 121 | }
|
---|
| 122 | else if (strcmp(arg[ia],"-wtoi") == 0) {
|
---|
| 123 | if (ia == narg-1) Usage(true);
|
---|
| 124 | wtoi = atoi(arg[ia+1]); ia++;
|
---|
| 125 | }
|
---|
| 126 | else if (strcmp(arg[ia],"-wgen") == 0) {
|
---|
| 127 | if (ia == narg-1) Usage(true);
|
---|
| 128 | sscanf(arg[ia+1],"%d,%d,%d",&wgen,&stepgen,&wtotgen); ia++;
|
---|
| 129 | }
|
---|
| 130 | else if (strcmp(arg[ia],"-intoi") == 0) {
|
---|
| 131 | if (ia == narg-1) Usage(true);
|
---|
| 132 | intoi = arg[ia+1]; ia++;
|
---|
| 133 | }
|
---|
| 134 | else if (strcmp(arg[ia],"-dbg") == 0) fgdbg = true;
|
---|
| 135 |
|
---|
| 136 | else { ko = ia; break; } // Debut des noms
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | if (iend < istart) iend = istart+wtoi*10;
|
---|
| 140 | if ((narg-ko) < 2) Usage(true);
|
---|
| 141 | infile = arg[ko];
|
---|
| 142 | outfile = arg[ko+1];
|
---|
| 143 | // outppfname = arg[ko+2];
|
---|
| 144 |
|
---|
| 145 | cout << " Initializing SOPHYA ... " << endl;
|
---|
| 146 | SophyaInit();
|
---|
| 147 | InitTim();
|
---|
| 148 |
|
---|
| 149 | cout << ">> tgenw: Infile= " << infile << " outFile="
|
---|
| 150 | << outfile << endl;
|
---|
| 151 | cout << ">>> Window Size WTOI= " << wtoi << " WGenSz= " << wgen
|
---|
| 152 | << " StepGen=" << stepgen << " WTot=" << wtotgen << endl;
|
---|
| 153 | cout << ">>>> InTOIName= " << intoi
|
---|
| 154 | << " iStart= " << istart << " iEnd= " << iend << endl;
|
---|
| 155 |
|
---|
| 156 | try {
|
---|
| 157 | TOIManager* mgr = TOIManager::getManager();
|
---|
| 158 |
|
---|
| 159 | // mgr->setRequestedSample(11680920,11710584);
|
---|
| 160 | // mgr->setRequestedSample(104121000, 104946120);
|
---|
| 161 | if (fgsetstart)
|
---|
| 162 | mgr->setRequestedSample(istart, iend);
|
---|
| 163 |
|
---|
| 164 | FITSTOIReader r(infile);
|
---|
| 165 | cout << "reader created" << endl;
|
---|
| 166 | FITSTOIWriter w(outfile);
|
---|
| 167 | cout << "fits writer created" << endl;
|
---|
| 168 |
|
---|
| 169 |
|
---|
| 170 | TOISeqBuffered * toiin = new TOISeqBuffered("f2in", wtoi);
|
---|
| 171 | if (fgdbg) toiin->setDebugLevel(1);
|
---|
| 172 |
|
---|
| 173 | cout << " Connecting to FitsReader ... " << endl;
|
---|
| 174 | r.addOutput(intoi, toiin);
|
---|
| 175 |
|
---|
| 176 | TOISeqBuffered * toiout = new TOISeqBuffered("genout", wtoi);
|
---|
| 177 | if (fgdbg) toiout->setDebugLevel(1);
|
---|
| 178 | TGenWProc tgenp(wgen, stepgen, wtotgen);
|
---|
| 179 |
|
---|
| 180 | cout << " Connecting TGenWProc ... " << endl;
|
---|
| 181 | tgenp.addInput("in0",toiin);
|
---|
| 182 | tgenp.addOutput("out0",toiout);
|
---|
| 183 |
|
---|
| 184 | cout << tgenp;
|
---|
| 185 |
|
---|
| 186 | w.addInput("genout", toiout);
|
---|
| 187 |
|
---|
| 188 | PrtTim("starting threads");
|
---|
| 189 | r.start();
|
---|
| 190 | tgenp.start();
|
---|
| 191 | w.start();
|
---|
| 192 |
|
---|
| 193 |
|
---|
| 194 | /*
|
---|
| 195 | for(int jj=0; jj<3; jj++) {
|
---|
| 196 | cout << *toiin;
|
---|
| 197 | cout << *toiout;
|
---|
| 198 | sleep(1);
|
---|
| 199 | }
|
---|
| 200 | */
|
---|
| 201 |
|
---|
| 202 |
|
---|
| 203 |
|
---|
| 204 |
|
---|
| 205 | mgr->joinAll();
|
---|
| 206 | PrtTim("End threads");
|
---|
| 207 |
|
---|
| 208 | // cout << " ------ FITSReaderTOI::PrintStatus() : ----- " << endl;
|
---|
| 209 | // r.PrintStatus(cout);
|
---|
| 210 | // cout << "----- FITSWriterTOI::PrintStatus() : ----- " << endl;
|
---|
| 211 | // w.PrintStatus(cout);
|
---|
| 212 |
|
---|
| 213 | cout << " ------ toiin, toiout Status information ------- " << endl;
|
---|
| 214 | cout << *toiin;
|
---|
| 215 | cout << *toiout;
|
---|
| 216 |
|
---|
| 217 | cout << tgenp;
|
---|
| 218 |
|
---|
| 219 | }
|
---|
| 220 | catch (PThrowable & exc) {
|
---|
| 221 | cerr << "\n tgenw: Catched Exception \n" << (string)typeid(exc).name()
|
---|
| 222 | << " - Msg= " << exc.Msg() << endl;
|
---|
| 223 | }
|
---|
| 224 | catch (const std::exception & sex) {
|
---|
| 225 | cerr << "\n tgenw: Catched std::exception \n"
|
---|
| 226 | << (string)typeid(sex).name() << endl;
|
---|
| 227 | }
|
---|
| 228 | catch (...) {
|
---|
| 229 | cerr << "\n tgenw: some other exception was caught ! " << endl;
|
---|
| 230 | }
|
---|
| 231 |
|
---|
| 232 | return(0);
|
---|
| 233 | }
|
---|