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