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