[1437] | 1 | #include <unistd.h>
|
---|
[1439] | 2 | #include <stdexcept>
|
---|
[1437] | 3 | #include "toi.h"
|
---|
| 4 | #include "toiprocessor.h"
|
---|
| 5 | #include "fitstoirdr.h"
|
---|
| 6 | #include "fitstoiwtr.h"
|
---|
| 7 | #include "toisqfilter.h"
|
---|
| 8 | #include "toimanager.h"
|
---|
| 9 | #include "rztoi.h"
|
---|
| 10 | #include "toiseqbuff.h"
|
---|
| 11 | #include "timing.h"
|
---|
| 12 | #include "sambainit.h"
|
---|
| 13 |
|
---|
| 14 | void Usage(bool fgerr)
|
---|
| 15 | {
|
---|
| 16 | cout << endl;
|
---|
| 17 | if (fgerr) {
|
---|
| 18 | cout << " tstrztoi : Argument Error ! tstrztoi -h for usage " << endl;
|
---|
| 19 | exit(1);
|
---|
| 20 | }
|
---|
| 21 | else {
|
---|
| 22 | cout << "\n Usage : tstrztoi [-sproc] [-rwtoi] [-dbg] [-start snb] [-end sne] \n"
|
---|
| 23 | << " [-w1 sz] [-w2 sz] inFitsName outFitsName ppfFileName \n"
|
---|
| 24 | << " -sproc : Run RzSimpleTOIProc (default RzTOIProc) \n"
|
---|
| 25 | << " -rwtoi : Use Regular Window TOI (default TOISeqBuffered) \n"
|
---|
| 26 | << " -dbg : sets TOISeqBuffered debug level to 1 \n"
|
---|
| 27 | << " -start snb : sets the start sample num \n"
|
---|
| 28 | << " -end sne : sets the end sample num \n"
|
---|
| 29 | << " -w1 sz : sets main data window size (def= 8192)\n"
|
---|
| 30 | << " -w2 sz : sets secondary window size (def= 512) \n"
|
---|
| 31 | << endl;
|
---|
| 32 | exit(0);
|
---|
| 33 | }
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | int main(int narg, char** arg) {
|
---|
| 37 |
|
---|
| 38 | if ((narg > 1) && (strcmp(arg[1],"-h") == 0) ) Usage(false);
|
---|
| 39 |
|
---|
| 40 | cout << "tstrztoi starting - Decoding arguments " << " narg=" << narg << endl;
|
---|
| 41 |
|
---|
| 42 | bool fgsimple = false;
|
---|
| 43 | bool fgrwtoi = false;
|
---|
| 44 | bool fgdbg = false;
|
---|
| 45 | int w1 = 8192;
|
---|
| 46 | int w2 = 512;
|
---|
| 47 | int nmax = 10;
|
---|
| 48 | int istart = 104121000+w1*5;
|
---|
| 49 | int iend = 0;
|
---|
| 50 | string infile;
|
---|
| 51 | string outfile;
|
---|
| 52 | string ppffile;
|
---|
| 53 |
|
---|
| 54 | if (narg < 4) Usage(true);
|
---|
| 55 | int ko=1;
|
---|
| 56 | // decoding arguments
|
---|
| 57 | for(int ia=1; ia<narg; ia++) {
|
---|
| 58 | if (strcmp(arg[ia],"-start") == 0) {
|
---|
| 59 | if (ia == narg-1) Usage(true); // -start est suivi d'un argument
|
---|
| 60 | istart = atoi(arg[ia+1]); ia++;
|
---|
| 61 | }
|
---|
| 62 | else if (strcmp(arg[ia],"-end") == 0) {
|
---|
| 63 | if (ia == narg-1) Usage(true);
|
---|
| 64 | iend = atoi(arg[ia+1]); ia++;
|
---|
| 65 | }
|
---|
| 66 | else if (strcmp(arg[ia],"-w1") == 0) {
|
---|
| 67 | if (ia == narg-1) Usage(true);
|
---|
| 68 | w1 = atoi(arg[ia+1]); ia++;
|
---|
| 69 | }
|
---|
| 70 | else if (strcmp(arg[ia],"-w2") == 0) {
|
---|
| 71 | if (ia == narg-1) Usage(true);
|
---|
| 72 | w2 = atoi(arg[ia+1]); ia++;
|
---|
| 73 | }
|
---|
| 74 | else if (strcmp(arg[ia],"-sproc") == 0) fgsimple = true;
|
---|
| 75 | else if (strcmp(arg[ia],"-rwtoi") == 0) fgrwtoi = true;
|
---|
| 76 | else if (strcmp(arg[ia],"-dbg") == 0) fgdbg = true;
|
---|
| 77 |
|
---|
| 78 | else { ko = ia; break; } // Debut des noms
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | if (iend < istart) iend = istart+w1*(nmax+5);
|
---|
| 82 | if ((narg-ko) < 3) Usage(true);
|
---|
| 83 | infile = arg[ko];
|
---|
| 84 | outfile = arg[ko+1];
|
---|
| 85 | ppffile = arg[ko+2];
|
---|
| 86 |
|
---|
| 87 | cout << " Initializing SOPHYA ... " << endl;
|
---|
| 88 | SophyaInit();
|
---|
| 89 | InitTim();
|
---|
| 90 |
|
---|
| 91 | cout << ">>>> tstrztoi: Infile= " << infile << " outFile=" << outfile
|
---|
| 92 | << " ppfFile= " << ppffile << endl;
|
---|
| 93 | cout << ">>>> Window Size W1= " << w1 << " W2= " << w2
|
---|
| 94 | << " iStart= " << istart << " iEnd= " << iend << endl;
|
---|
| 95 | try {
|
---|
| 96 | TOIManager* mgr = TOIManager::getManager();
|
---|
| 97 |
|
---|
| 98 | // mgr->setRequestedSample(11680920,11710584);
|
---|
| 99 | // mgr->setRequestedSample(104121000, 104946120);
|
---|
| 100 |
|
---|
| 101 | mgr->setRequestedSample(istart, iend);
|
---|
| 102 |
|
---|
| 103 | // FITSTOIReader r("/data/Archeops/bolo11.fits);
|
---|
| 104 | FITSTOIReader r(infile);
|
---|
| 105 | cout << "reader created" << endl;
|
---|
| 106 | // FITSTOIWriter w("/data/Archeops/rz.fits");
|
---|
| 107 | FITSTOIWriter w(outfile);
|
---|
| 108 | cout << "fits writer created" << endl;
|
---|
| 109 |
|
---|
| 110 |
|
---|
| 111 | char * colname[5] = {"MJD", "UTC","boloMuV_11","magnFlux","pivot"};
|
---|
[1439] | 112 | char * toiname[5] = {"MJD", "UTC","bolo11","magneto","pivot"};
|
---|
[1437] | 113 | TOI* toitab[5];
|
---|
| 114 | TOI* toi2;
|
---|
| 115 | int kk;
|
---|
| 116 | if (fgrwtoi) {
|
---|
| 117 | cout << " Using TOIRegularWindow TOI's ... " << endl;
|
---|
| 118 | for(kk=0; kk<5; kk++) {
|
---|
[1439] | 119 | toitab[kk] = new TOIRegularWindow(toiname[kk]);
|
---|
[1437] | 120 | }
|
---|
| 121 | toi2 = new TOIRegularWindow("t2");
|
---|
| 122 | }
|
---|
| 123 | else {
|
---|
| 124 | cout << " Using TOISeqBuffered TOI's ... " << endl;
|
---|
| 125 | for(kk=0; kk<5; kk++) {
|
---|
[1439] | 126 | TOISeqBuffered * toisb = new TOISeqBuffered(toiname[kk], w1);
|
---|
[1437] | 127 | toitab[kk] = toisb;
|
---|
| 128 | if (fgdbg) toisb->setDebugLevel(1);
|
---|
| 129 | }
|
---|
| 130 | TOISeqBuffered * toisb = new TOISeqBuffered("t2", w1);
|
---|
| 131 | if (fgdbg) toisb->setDebugLevel(1);
|
---|
| 132 | toi2 = toisb;
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | // Connecting TOI to FITSTOIReader Processor
|
---|
| 136 | // for(kk=0; kk<5; kk++) {
|
---|
| 137 | // r.addOutput(colname[kk], toitab[kk]);
|
---|
| 138 | // }
|
---|
| 139 |
|
---|
| 140 | kk = 2;
|
---|
| 141 | TOI* toi = toitab[kk];
|
---|
| 142 | r.addOutput(colname[kk], toi);
|
---|
| 143 | // toi->dbg=true;
|
---|
| 144 | // r.addOutput("boloMuV_11", toi);
|
---|
| 145 | cout << " connecting in/out to RzTOIProcessor ... " << endl;
|
---|
| 146 |
|
---|
| 147 | // TOIProcessor * filt = NULL;
|
---|
| 148 |
|
---|
| 149 | cout << " Creating Rz TOIProcessors: RzTOIProc () " << endl;
|
---|
| 150 | RzSimpleTOIProc rzs(2., 1000);
|
---|
| 151 | RzTOIProc rzp(w1, w2, nmax);
|
---|
| 152 | if (fgsimple) {
|
---|
| 153 | cout << " Using Simple TOIProcessor: RzSimpleTOIProc () " << endl;
|
---|
| 154 | rzs.addInput("signal", toi);
|
---|
| 155 | rzs.addOutput("sfout", toi2);
|
---|
| 156 | }
|
---|
| 157 | else {
|
---|
| 158 | cout << " Using Rz TOIProcessor: RzTOIProc () " << endl;
|
---|
| 159 | // rzp.setOutPPF("/data/Archeops/toto.ppf");
|
---|
| 160 | rzp.setOutPPF(ppffile);
|
---|
| 161 | rzp.addInput("signal", toi);
|
---|
| 162 | rzp.addOutput("sfout", toi2);
|
---|
| 163 | }
|
---|
| 164 |
|
---|
| 165 |
|
---|
[1439] | 166 | w.setOutFlags(true);
|
---|
| 167 | w.addInput("bolodrift", toi2);
|
---|
[1437] | 168 |
|
---|
[1439] | 169 | cout << " ------ FITSReaderTOI::PrintStatus() : ----- " << endl;
|
---|
| 170 | r.PrintStatus(cout);
|
---|
| 171 | cout << "----- FITSWriterTOI::PrintStatus() : ----- " << endl;
|
---|
| 172 | w.PrintStatus(cout);
|
---|
| 173 |
|
---|
[1437] | 174 | PrtTim("starting threads");
|
---|
| 175 | r.start();
|
---|
| 176 | if (fgsimple) rzs.start();
|
---|
| 177 | else rzp.start();
|
---|
| 178 | w.start();
|
---|
| 179 |
|
---|
[1439] | 180 | // for(int jj=0; jj<3; jj++) {
|
---|
| 181 | // sleep(2);
|
---|
| 182 | // cout << *toi;
|
---|
| 183 | // }
|
---|
[1437] | 184 |
|
---|
| 185 | mgr->joinAll();
|
---|
| 186 | PrtTim("End threads");
|
---|
[1439] | 187 |
|
---|
| 188 | // cout << " ------ FITSReaderTOI::PrintStatus() : ----- " << endl;
|
---|
| 189 | // r.PrintStatus(cout);
|
---|
| 190 | // cout << "----- FITSWriterTOI::PrintStatus() : ----- " << endl;
|
---|
| 191 | // w.PrintStatus(cout);
|
---|
| 192 |
|
---|
[1437] | 193 | cout << " ------ toi and toi2 Status information ------- " << endl;
|
---|
| 194 | cout << *toi;
|
---|
| 195 | cout << *toi2;
|
---|
| 196 | }
|
---|
| 197 | catch (PThrowable & exc) {
|
---|
[1439] | 198 | cerr << "\nrztsttoi: Catched Exception \n" << (string)typeid(exc).name()
|
---|
[1437] | 199 | << " - Msg= " << exc.Msg() << endl;
|
---|
| 200 | }
|
---|
[1439] | 201 | catch (const std::exception & sex) {
|
---|
| 202 | cerr << "\nrztsttoi: Catched std::exception \n"
|
---|
| 203 | << (string)typeid(sex).name() << endl;
|
---|
| 204 | }
|
---|
[1437] | 205 | catch (...) {
|
---|
[1439] | 206 | cerr << "\nrztsttoi: some other exception was caught ! " << endl;
|
---|
[1437] | 207 | }
|
---|
| 208 |
|
---|
| 209 | return(0);
|
---|
| 210 | }
|
---|