| 1 | // ArchTOIPipe           (C)     CEA/DAPNIA/SPP IN2P3/LAL | 
|---|
| 2 | //                               Eric Aubourg | 
|---|
| 3 | //                               Christophe Magneville | 
|---|
| 4 | //                               Reza Ansari | 
|---|
| 5 | // $Id: mesovh.cc,v 1.6 2002-05-08 21:25:15 ansari Exp $ | 
|---|
| 6 | /*   mesure de performance de l'architecture | 
|---|
| 7 |  | 
|---|
| 8 | ----------------   Exemple d'appel  --------------------- | 
|---|
| 9 | csh> mesovh -start 104385384 -end 104399964 | 
|---|
| 10 | -intoi boloMuV_27 -wtoi 8192 -wnoop 4096 inputbolo.fits | 
|---|
| 11 | */ | 
|---|
| 12 |  | 
|---|
| 13 |  | 
|---|
| 14 |  | 
|---|
| 15 | #include "machdefs.h" | 
|---|
| 16 | #include <math.h> | 
|---|
| 17 | #include "array.h" | 
|---|
| 18 | #include <unistd.h> | 
|---|
| 19 | #include "toi.h" | 
|---|
| 20 | #include "toiprocessor.h" | 
|---|
| 21 | #include "fitstoirdr.h" | 
|---|
| 22 | #include "fitstoiwtr.h" | 
|---|
| 23 | #include "toimanager.h" | 
|---|
| 24 | #include "nooppr.h" | 
|---|
| 25 | #include "toiseqbuff.h" | 
|---|
| 26 | #include "timing.h" | 
|---|
| 27 | // #include "sambainit.h" | 
|---|
| 28 | #include <stdexcept> | 
|---|
| 29 |  | 
|---|
| 30 | void Usage(bool fgerr) | 
|---|
| 31 | { | 
|---|
| 32 | cout << endl; | 
|---|
| 33 | if (fgerr) { | 
|---|
| 34 | cout << " mesovh : Argument Error ! mesovh -h for usage " << endl; | 
|---|
| 35 | exit(1); | 
|---|
| 36 | } | 
|---|
| 37 | else { | 
|---|
| 38 | cout << "\n Usage : mesovh [-dbg] [-start snb] [-end sne] \n" | 
|---|
| 39 | << "         [-intoi name] [-wtoi sz] [-wnoop sz] [-bipro] \n" | 
|---|
| 40 | << "         [-intoi2 name] [-prstat] inFitsName \n" | 
|---|
| 41 | << "   -dbg : sets TOISeqBuffered debug level to 1 \n" | 
|---|
| 42 | << "   -start snb : sets the start sample num \n" | 
|---|
| 43 | << "   -end sne : sets the end sample num \n" | 
|---|
| 44 | << "   -intoi toiName : select input TOI name (def boloMuV_27)\n" | 
|---|
| 45 | << "   -wtoi sz : sets TOISeqBuff buffer size (def= 8192)\n" | 
|---|
| 46 | << "   -wnoop sz : sets NoOpProcessor window size \n" | 
|---|
| 47 | << "   -bipro : chain 2 processors \n" | 
|---|
| 48 | << "   -intoi2 toiName : chaine 2 procs with toi2->in2\n" | 
|---|
| 49 | << "   -prstat : PrintStat with ProcSampleCounter \n" | 
|---|
| 50 | << endl; | 
|---|
| 51 | exit(0); | 
|---|
| 52 | } | 
|---|
| 53 | } | 
|---|
| 54 |  | 
|---|
| 55 | int main(int narg, char** arg) { | 
|---|
| 56 |  | 
|---|
| 57 | if ((narg > 1) && (strcmp(arg[1],"-h") == 0) ) Usage(false); | 
|---|
| 58 |  | 
|---|
| 59 | cout << "mesovh starting - Decoding arguments " << " narg=" << narg << endl; | 
|---|
| 60 |  | 
|---|
| 61 | bool fgdbg = false; | 
|---|
| 62 | bool fgbipro = false; | 
|---|
| 63 | bool fgsetstart = false; | 
|---|
| 64 | bool fgprstat = false; | 
|---|
| 65 | int wtoi = 8192; | 
|---|
| 66 | int wnoop = 0; | 
|---|
| 67 | int keepfft = 0; | 
|---|
| 68 | int nmax = 10; | 
|---|
| 69 | int istart = 0; | 
|---|
| 70 | int iend = 0; | 
|---|
| 71 | string infile; | 
|---|
| 72 | string outfile; | 
|---|
| 73 | string outppfname; | 
|---|
| 74 | string intoi = "boloMuV_27"; | 
|---|
| 75 | bool fgtoi2 = false; | 
|---|
| 76 | string intoi2; | 
|---|
| 77 |  | 
|---|
| 78 | if (narg < 4) Usage(true); | 
|---|
| 79 | int ko=1; | 
|---|
| 80 | // decoding arguments | 
|---|
| 81 | for(int ia=1; ia<narg; ia++) { | 
|---|
| 82 | if (strcmp(arg[ia],"-start") == 0) { | 
|---|
| 83 | if (ia == narg-1) Usage(true);  // -start est suivi d'un argument | 
|---|
| 84 | istart = atoi(arg[ia+1]); ia++; | 
|---|
| 85 | fgsetstart = true; | 
|---|
| 86 | } | 
|---|
| 87 | else if (strcmp(arg[ia],"-end") == 0) { | 
|---|
| 88 | if (ia == narg-1) Usage(true); | 
|---|
| 89 | iend = atoi(arg[ia+1]); ia++; | 
|---|
| 90 | } | 
|---|
| 91 | else if (strcmp(arg[ia],"-wtoi") == 0) { | 
|---|
| 92 | if (ia == narg-1) Usage(true); | 
|---|
| 93 | wtoi = atoi(arg[ia+1]); ia++; | 
|---|
| 94 | } | 
|---|
| 95 | else if (strcmp(arg[ia],"-wnoop") == 0) { | 
|---|
| 96 | if (ia == narg-1) Usage(true); | 
|---|
| 97 | wnoop = atoi(arg[ia+1]); ia++; | 
|---|
| 98 | } | 
|---|
| 99 | else if (strcmp(arg[ia],"-intoi") == 0) { | 
|---|
| 100 | if (ia == narg-1) Usage(true); | 
|---|
| 101 | intoi = arg[ia+1]; ia++; | 
|---|
| 102 | } | 
|---|
| 103 | else if (strcmp(arg[ia],"-intoi2") == 0) { | 
|---|
| 104 | if (ia == narg-1) Usage(true); | 
|---|
| 105 | fgbipro = fgtoi2 = true; | 
|---|
| 106 | intoi2 = arg[ia+1]; ia++; | 
|---|
| 107 | } | 
|---|
| 108 | else if (strcmp(arg[ia],"-bipro") == 0)  fgbipro = true; | 
|---|
| 109 | else if (strcmp(arg[ia],"-dbg") == 0)  fgdbg = true; | 
|---|
| 110 | else if (strcmp(arg[ia],"-prstat") == 0)  fgprstat = true; | 
|---|
| 111 |  | 
|---|
| 112 | else { ko = ia; break; }  // Debut des noms | 
|---|
| 113 | } | 
|---|
| 114 |  | 
|---|
| 115 | if (iend < istart) iend = istart+wtoi*(nmax+5); | 
|---|
| 116 | if ((narg-ko) < 1)  Usage(true); | 
|---|
| 117 | infile = arg[ko]; | 
|---|
| 118 | //  outfile = arg[ko+1]; | 
|---|
| 119 | //  outppfname = arg[ko+2]; | 
|---|
| 120 |  | 
|---|
| 121 | //  cout << " Initializing SOPHYA ... " << endl; | 
|---|
| 122 | //  SophyaInit(); | 
|---|
| 123 | InitTim(); | 
|---|
| 124 |  | 
|---|
| 125 | cout << ">>>> mesovh: Infile= " << infile << " outFile=" | 
|---|
| 126 | << outfile << endl; | 
|---|
| 127 | cout << ">>>> Window Size WTOI= " << wtoi << " WNOOP= " << wnoop | 
|---|
| 128 | << "  iStart= " << istart << " iEnd= " << iend << endl; | 
|---|
| 129 | cout << ">>>> InTOIName= " << intoi << endl; | 
|---|
| 130 |  | 
|---|
| 131 | try { | 
|---|
| 132 | TOIManager* mgr = TOIManager::getManager(); | 
|---|
| 133 |  | 
|---|
| 134 | //  mgr->setRequestedSample(11680920,11710584); | 
|---|
| 135 | //  mgr->setRequestedSample(104121000, 104946120); | 
|---|
| 136 | if (fgsetstart) | 
|---|
| 137 | mgr->setRequestedSample(istart, iend); | 
|---|
| 138 |  | 
|---|
| 139 | //    FITSTOIReader r("/data/Archeops/bolo11.fits); | 
|---|
| 140 | FITSTOIReader r(infile); | 
|---|
| 141 | cout << "reader created" << endl; | 
|---|
| 142 | //    FITSTOIWriter w("/data/Archeops/rz.fits"); | 
|---|
| 143 | //    FITSTOIWriter w(outfile); | 
|---|
| 144 | //    cout << "fits writer created" << endl; | 
|---|
| 145 |  | 
|---|
| 146 |  | 
|---|
| 147 | int w1 = wtoi; | 
|---|
| 148 | TOISeqBuffered * toiin = new TOISeqBuffered("f2in", w1); | 
|---|
| 149 | if (fgdbg) toiin->setDebugLevel(1); | 
|---|
| 150 | //    TOISeqBuffered * toiout = new TOISeqBuffered("out", w1); | 
|---|
| 151 | //    if (fgdbg) toiout->setDebugLevel(1); | 
|---|
| 152 | //    TOISeqBuffered * toiincopie = new TOISeqBuffered("incopie", w1); | 
|---|
| 153 | //    if (fgdbg) toiincopie->setDebugLevel(1); | 
|---|
| 154 |  | 
|---|
| 155 |  | 
|---|
| 156 | cout << " Connecting to FitsReader ... " << endl; | 
|---|
| 157 | r.addOutput(intoi, toiin); | 
|---|
| 158 |  | 
|---|
| 159 | TOISeqBuffered * toi2 = NULL; | 
|---|
| 160 | if (fgtoi2) { | 
|---|
| 161 | int w2 = (wnoop > 0) ? w1+wnoop : w1; | 
|---|
| 162 | toi2 = new TOISeqBuffered("toi2", w2); | 
|---|
| 163 | r.addOutput(intoi2, toi2); | 
|---|
| 164 | } | 
|---|
| 165 |  | 
|---|
| 166 | NoOpProcessor noop(wnoop); | 
|---|
| 167 | NoOpProcessor noop2(wnoop); | 
|---|
| 168 | cout << " Connecting NoOpProcessor ... " << endl; | 
|---|
| 169 | noop.addInput("in",toiin); | 
|---|
| 170 |  | 
|---|
| 171 | TOISeqBuffered * toi3 = NULL; | 
|---|
| 172 | if (fgbipro) { | 
|---|
| 173 | toi3 = new TOISeqBuffered("toi3", w1); | 
|---|
| 174 | noop.addOutput("out", toi3); | 
|---|
| 175 | noop2.addInput("in",toi3); | 
|---|
| 176 | if (fgtoi2) { | 
|---|
| 177 | noop2.addInput("in2",toi2); | 
|---|
| 178 | } | 
|---|
| 179 | } | 
|---|
| 180 |  | 
|---|
| 181 | PrtTim("starting threads"); | 
|---|
| 182 | r.start(); | 
|---|
| 183 | noop.start(); | 
|---|
| 184 | if (fgbipro)  noop2.start(); | 
|---|
| 185 | /* | 
|---|
| 186 | for(int jj=0; jj<3; jj++) { | 
|---|
| 187 | cout << *toiin; | 
|---|
| 188 | cout << *toiout; | 
|---|
| 189 | cout << *toiincopie; | 
|---|
| 190 | sleep(1); | 
|---|
| 191 | } | 
|---|
| 192 | */ | 
|---|
| 193 |  | 
|---|
| 194 | if (fgprstat) { | 
|---|
| 195 | // --------------- Impression continu de stat ------------------- | 
|---|
| 196 | ProcSampleCounter<NoOpProcessor> stats(noop); | 
|---|
| 197 | stats.InfoMessage() = "mesovh/Info"; | 
|---|
| 198 | stats.PrintStats(); | 
|---|
| 199 | // -------------------------------------------------------------- | 
|---|
| 200 | } | 
|---|
| 201 |  | 
|---|
| 202 |  | 
|---|
| 203 | mgr->joinAll(); | 
|---|
| 204 | PrtTim("End threads"); | 
|---|
| 205 |  | 
|---|
| 206 | //    cout << " ------ FITSReaderTOI::PrintStatus() : ----- " << endl; | 
|---|
| 207 | //    r.PrintStatus(cout); | 
|---|
| 208 | //    cout << "----- FITSWriterTOI::PrintStatus() : ----- " << endl; | 
|---|
| 209 | //    w.PrintStatus(cout); | 
|---|
| 210 |  | 
|---|
| 211 | cout << " ------ toiin, toi2 and toi3 Status information ------- " << endl; | 
|---|
| 212 | cout << *toiin; | 
|---|
| 213 | if (toi2) cout << *toi2; | 
|---|
| 214 | if (toi3) cout << *toi3; | 
|---|
| 215 | cout << noop ; | 
|---|
| 216 | if (fgbipro) cout << noop2 ; | 
|---|
| 217 | } | 
|---|
| 218 | catch (PThrowable & exc) { | 
|---|
| 219 | cerr << "\n mesovh: Catched Exception \n" << (string)typeid(exc).name() | 
|---|
| 220 | << " - Msg= " << exc.Msg() << endl; | 
|---|
| 221 | } | 
|---|
| 222 | catch (const std::exception & sex) { | 
|---|
| 223 | cerr << "\n mesovh: Catched std::exception \n" | 
|---|
| 224 | << (string)typeid(sex).name() << endl; | 
|---|
| 225 | } | 
|---|
| 226 | catch (...) { | 
|---|
| 227 | cerr << "\n mesovh: some other exception was caught ! " << endl; | 
|---|
| 228 | } | 
|---|
| 229 |  | 
|---|
| 230 | return(0); | 
|---|
| 231 | } | 
|---|