source: Sophya/trunk/ArchTOIPipe/Kernel/piotoirdr.cc@ 2392

Last change on this file since 2392 was 2392, checked in by aubourg, 22 years ago

divers pio

File size: 3.2 KB
Line 
1// ArchTOIPipe (C) CEA/DAPNIA/SPP IN2P3/LAL
2// Eric Aubourg
3// Christophe Magneville
4// Reza Ansari
5// $Id: piotoirdr.cc,v 1.7 2003-05-28 21:03:19 aubourg Exp $
6
7#include "piotoirdr.h"
8
9extern void fits_lock();
10extern void fits_unlock();
11
12char** environ; // For darwin dylibs with piolib
13
14PIOTOIReader::PIOTOIReader(string grp, string obj, string flg) {
15 group = grp;
16 object = obj;
17 flagdef = flg;
18 pioGroup = NULL;
19
20}
21
22PIOTOIReader::~PIOTOIReader() {
23 if (pioGroup != NULL) {
24 // ??
25 }
26}
27
28void PIOTOIReader::init() {
29 //pioTOI = new PIOObjectTOI(object.c_str(), "r");
30 fits_lock();
31 pioGroup = PIOOpenTOI(const_cast<char*>(group.c_str()), "r");
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
44void 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
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 }
75
76 PIOFreeInfoTOI(flgName,
77 toiType,
78 toiName,
79 beginIndex,
80 endIndex);
81 fits_unlock();
82}
83
84void 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;
96 PIOBYTE** pioflags = NULL;
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 != "") {
104 PIOLONG nf = PIOReadFLGObjectMask(pioflags,
105 const_cast<char*>(flagdef.c_str()),
106 command,
107 pioGroup);
108 if (nf != n) {
109 cerr << "*** PIO Error, inconsistent read, data " << n << " flags "
110 << nf << endl;
111 abort();
112 }
113 flags = new uint_8[nf];
114 for (int i=0; i<nf; i++) flags[i] = (uint_8)pioflags[i];
115 PIODeleteFLG(pioflags, pioGroup);
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);
128 // if (flags != NULL) PIODeleteFLG(flags, pioGroup); // PB !
129 if (flags != NULL) delete[] flags;
130 fits_unlock();
131 }
132 PIOCloseTOI(pioGroup);
133}
Note: See TracBrowser for help on using the repository browser.