[2328] | 1 | // ArchTOIPipe (C) CEA/DAPNIA/SPP IN2P3/LAL
|
---|
| 2 | // Eric Aubourg
|
---|
| 3 | // Christophe Magneville
|
---|
| 4 | // Reza Ansari
|
---|
[2386] | 5 | // $Id: piotoirdr.cc,v 1.6 2003-05-20 10:10:08 aubourg Exp $
|
---|
[2328] | 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();
|
---|
[2359] | 29 | pioGroup = PIOOpenTOI(const_cast<char*>(group.c_str()), "r");
|
---|
[2328] | 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 |
|
---|
[2369] | 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 | }
|
---|
[2328] | 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;
|
---|
[2382] | 94 | PIOBYTE** pioflags = NULL;
|
---|
[2328] | 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 != "") {
|
---|
[2382] | 102 | PIOLONG nf = PIOReadFLGObjectMask(pioflags,
|
---|
| 103 | const_cast<char*>(flagdef.c_str()),
|
---|
| 104 | command,
|
---|
| 105 | pioGroup);
|
---|
[2328] | 106 | if (nf != n) {
|
---|
[2382] | 107 | cerr << "*** PIO Error, inconsistent read, data " << n << " flags "
|
---|
| 108 | << nf << endl;
|
---|
[2328] | 109 | abort();
|
---|
| 110 | }
|
---|
[2382] | 111 | flags = new uint_8[nf];
|
---|
[2386] | 112 | for (int i=0; i<nf; i++) flags[i] = (uint_8)pioflags[i];
|
---|
[2382] | 113 | PIODeleteFLG(pioflags, pioGroup);
|
---|
[2328] | 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);
|
---|
[2369] | 126 | // if (flags != NULL) PIODeleteFLG(flags, pioGroup); // PB !
|
---|
[2382] | 127 | if (flags != NULL) delete[] flags;
|
---|
[2328] | 128 | fits_unlock();
|
---|
| 129 | }
|
---|
[2332] | 130 | PIOCloseTOI(pioGroup);
|
---|
[2328] | 131 | }
|
---|