| [2328] | 1 | // ArchTOIPipe           (C)     CEA/DAPNIA/SPP IN2P3/LAL
 | 
|---|
 | 2 | //                               Eric Aubourg
 | 
|---|
 | 3 | //                               Christophe Magneville
 | 
|---|
 | 4 | //                               Reza Ansari
 | 
|---|
| [2461] | 5 | // $Id: piotoirdr.cc,v 1.12 2003-11-22 21:59:00 aubourg Exp $
 | 
|---|
| [2328] | 6 | 
 | 
|---|
 | 7 | #include "piotoirdr.h"
 | 
|---|
 | 8 | 
 | 
|---|
 | 9 | extern void fits_lock();
 | 
|---|
 | 10 | extern void fits_unlock();
 | 
|---|
 | 11 | 
 | 
|---|
| [2396] | 12 | //char** environ; // For darwin dylibs with piolib
 | 
|---|
| [2392] | 13 | 
 | 
|---|
| [2328] | 14 | PIOTOIReader::PIOTOIReader(string grp, string obj, string flg) {
 | 
|---|
 | 15 |   group = grp;
 | 
|---|
 | 16 |   object = obj;
 | 
|---|
 | 17 |   flagdef = flg;
 | 
|---|
 | 18 |   pioGroup = NULL;
 | 
|---|
 | 19 | 
 | 
|---|
 | 20 | }
 | 
|---|
 | 21 | 
 | 
|---|
 | 22 | PIOTOIReader::~PIOTOIReader() {
 | 
|---|
 | 23 |   if (pioGroup != NULL) {
 | 
|---|
 | 24 |     // ??
 | 
|---|
 | 25 |   }
 | 
|---|
 | 26 | }
 | 
|---|
 | 27 | 
 | 
|---|
 | 28 | void PIOTOIReader::init() {
 | 
|---|
 | 29 |   fits_lock();
 | 
|---|
| [2398] | 30 |   char groupname[128];
 | 
|---|
 | 31 |   strcpy(groupname, group.c_str());
 | 
|---|
 | 32 |   pioGroup = PIOOpenTOI(groupname, "r");
 | 
|---|
 | 33 |   
 | 
|---|
 | 34 |   if (pioGroup == NULL) {
 | 
|---|
 | 35 |     cerr << " ERROR in PIOOpenTOI cannnot open " << groupname << endl;
 | 
|---|
 | 36 |     abort();
 | 
|---|
 | 37 |   }
 | 
|---|
| [2328] | 38 |   fits_unlock();
 | 
|---|
| [2398] | 39 |   cout << "pioGroup : "<< pioGroup << endl;
 | 
|---|
| [2328] | 40 |   readBounds();
 | 
|---|
 | 41 |   bufferSize = 1000;
 | 
|---|
| [2398] | 42 |   cout << "PIOTOIReader : opened " << groupname
 | 
|---|
 | 43 |        << " " <<  snBegin << " - " << snEnd << ": " << pioGroup << endl;
 | 
|---|
| [2328] | 44 |   if (flagdef != "") {
 | 
|---|
 | 45 |     cout << "   with flagdef = " << flagdef << endl;
 | 
|---|
 | 46 |   }
 | 
|---|
 | 47 | 
 | 
|---|
 | 48 |   declareOutput(object);
 | 
|---|
 | 49 | }
 | 
|---|
 | 50 | 
 | 
|---|
 | 51 | void PIOTOIReader::readBounds() {
 | 
|---|
 | 52 |   PIOSTRING* flgName;
 | 
|---|
 | 53 |   PIOINT     nbFlg;
 | 
|---|
 | 54 |   PIOSTRING* toiType;
 | 
|---|
 | 55 |   PIOSTRING* toiName;
 | 
|---|
 | 56 |   PIOLONG*   beginIndex;
 | 
|---|
 | 57 |   PIOLONG*   endIndex;
 | 
|---|
 | 58 |   PIOINT     nbTOI;
 | 
|---|
 | 59 |   PIOSTRING  ROIGroup;
 | 
|---|
 | 60 | 
 | 
|---|
 | 61 |   fits_lock();
 | 
|---|
 | 62 |   PIOInfoTOI(&flgName,
 | 
|---|
 | 63 |              &nbFlg,
 | 
|---|
 | 64 |              &toiType,
 | 
|---|
 | 65 |              &toiName,
 | 
|---|
 | 66 |              &beginIndex,
 | 
|---|
 | 67 |              &endIndex,
 | 
|---|
 | 68 |              &nbTOI,
 | 
|---|
 | 69 |              ROIGroup,
 | 
|---|
 | 70 |              pioGroup);
 | 
|---|
 | 71 | 
 | 
|---|
| [2369] | 72 |   // On recupere un tableau de beginIndex, il faut retrouver celui qui nous concerne
 | 
|---|
 | 73 |   for (int i=0; i<nbTOI; i++) {
 | 
|---|
 | 74 |     cout << toiName[i] << endl;
 | 
|---|
 | 75 |     if (object == toiName[i]) {
 | 
|---|
 | 76 |       snBegin = beginIndex[i];
 | 
|---|
 | 77 |       snEnd   = endIndex[i];
 | 
|---|
 | 78 |       cout << snBegin << " " << snEnd << endl;
 | 
|---|
 | 79 |       break;
 | 
|---|
 | 80 |     }
 | 
|---|
 | 81 |   }
 | 
|---|
| [2328] | 82 | 
 | 
|---|
 | 83 |   PIOFreeInfoTOI(flgName,
 | 
|---|
 | 84 |                  toiType,
 | 
|---|
 | 85 |                  toiName,
 | 
|---|
 | 86 |                  beginIndex,
 | 
|---|
 | 87 |                  endIndex);
 | 
|---|
 | 88 |   fits_unlock();
 | 
|---|
 | 89 | }
 | 
|---|
 | 90 | 
 | 
|---|
 | 91 | void PIOTOIReader::run() {
 | 
|---|
 | 92 |   cout << "PIOTOIReader run " << group << "[" << object << "] " 
 | 
|---|
 | 93 |        << snBegin << " " << snEnd << endl;
 | 
|---|
 | 94 | 
 | 
|---|
| [2448] | 95 |   for (long snb = snBegin; snb <= snEnd; snb += bufferSize) {
 | 
|---|
 | 96 |     long sne = snb + bufferSize - 1;
 | 
|---|
| [2328] | 97 |     if (sne > snEnd) sne=snEnd;
 | 
|---|
 | 98 |     // TBD : check if PIODOUBLE != double;
 | 
|---|
| [2448] | 99 |     char command[128];
 | 
|---|
| [2461] | 100 |     sprintf(command, "Begin=%ld; End=%ld", snb, sne);
 | 
|---|
| [2397] | 101 |     double* data = NULL;
 | 
|---|
| [2328] | 102 |     uint_8*   flags = NULL;
 | 
|---|
| [2396] | 103 |     PIOBYTE*  pioflags = NULL;
 | 
|---|
| [2328] | 104 |     fits_lock();
 | 
|---|
| [2448] | 105 |     char objname[128];
 | 
|---|
 | 106 |     strcpy(objname, object.c_str());
 | 
|---|
| [2328] | 107 |     PIOLONG n = PIOReadTOI((void**) &data,
 | 
|---|
| [2448] | 108 |                            objname,
 | 
|---|
| [2328] | 109 |                            "PIODOUBLE",
 | 
|---|
 | 110 |                            command,
 | 
|---|
 | 111 |                            pioGroup);
 | 
|---|
| [2397] | 112 |     if ( n<0) {
 | 
|---|
| [2461] | 113 |       cout << " PIOReadTOI " << command << ": " << n << endl;
 | 
|---|
| [2397] | 114 |       abort();
 | 
|---|
 | 115 |     }
 | 
|---|
| [2328] | 116 |     if (flagdef != "") {
 | 
|---|
| [2448] | 117 |       char flagname[128];
 | 
|---|
 | 118 |       strcpy(flagname, flagdef.c_str());
 | 
|---|
| [2396] | 119 |       PIOLONG nf = PIOReadFLGObjectMask(&pioflags,
 | 
|---|
| [2448] | 120 |                                         flagname,
 | 
|---|
 | 121 |                                         command,
 | 
|---|
 | 122 |                                         pioGroup);
 | 
|---|
| [2328] | 123 |       if (nf != n) {
 | 
|---|
| [2382] | 124 |         cerr << "*** PIO Error, inconsistent read, data " << n << " flags " 
 | 
|---|
 | 125 |              << nf << endl;
 | 
|---|
| [2328] | 126 |         abort();
 | 
|---|
 | 127 |       }
 | 
|---|
| [2382] | 128 |       flags = new uint_8[nf];
 | 
|---|
| [2386] | 129 |       for (int i=0; i<nf; i++) flags[i] = (uint_8)pioflags[i];
 | 
|---|
| [2382] | 130 |       PIODeleteFLG(pioflags, pioGroup);
 | 
|---|
| [2328] | 131 |     }
 | 
|---|
 | 132 |     fits_unlock();
 | 
|---|
 | 133 |     
 | 
|---|
 | 134 | 
 | 
|---|
 | 135 |     if (flags != NULL) {
 | 
|---|
 | 136 |       putData(0, snb, sne-snb+1, data, flags);
 | 
|---|
 | 137 |     } else {
 | 
|---|
 | 138 |       putData(0, snb, sne-snb+1, data);
 | 
|---|
 | 139 |     }
 | 
|---|
 | 140 |     
 | 
|---|
 | 141 |     fits_lock();
 | 
|---|
 | 142 |     PIODeleteTOI(data, pioGroup);
 | 
|---|
| [2369] | 143 |     //    if (flags != NULL) PIODeleteFLG(flags, pioGroup); // PB !
 | 
|---|
| [2382] | 144 |     if (flags != NULL) delete[] flags;
 | 
|---|
| [2328] | 145 |     fits_unlock();
 | 
|---|
 | 146 |   }
 | 
|---|
| [2332] | 147 |   PIOCloseTOI(pioGroup);
 | 
|---|
| [2328] | 148 | }
 | 
|---|