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

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

securisation

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.9 2003-06-05 02:18:06 aubourg Exp $
6
7#include "piotoirdr.h"
8
9extern void fits_lock();
10extern void fits_unlock();
11
12//char** 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 fits_lock();
30 pioGroup = PIOOpenTOI(const_cast<char*>(group.c_str()), "r");
31 fits_unlock();
32 readBounds();
33 bufferSize = 1000;
34 cout << "PIOTOIReader : opened " << group
35 << " " << snBegin << " - " << snEnd << endl;
36 if (flagdef != "") {
37 cout << " with flagdef = " << flagdef << endl;
38 }
39
40 declareOutput(object);
41}
42
43void PIOTOIReader::readBounds() {
44 PIOSTRING* flgName;
45 PIOINT nbFlg;
46 PIOSTRING* toiType;
47 PIOSTRING* toiName;
48 PIOLONG* beginIndex;
49 PIOLONG* endIndex;
50 PIOINT nbTOI;
51 PIOSTRING ROIGroup;
52
53 fits_lock();
54 PIOInfoTOI(&flgName,
55 &nbFlg,
56 &toiType,
57 &toiName,
58 &beginIndex,
59 &endIndex,
60 &nbTOI,
61 ROIGroup,
62 pioGroup);
63
64 // On recupere un tableau de beginIndex, il faut retrouver celui qui nous concerne
65 for (int i=0; i<nbTOI; i++) {
66 cout << toiName[i] << endl;
67 if (object == toiName[i]) {
68 snBegin = beginIndex[i];
69 snEnd = endIndex[i];
70 cout << snBegin << " " << snEnd << endl;
71 break;
72 }
73 }
74
75 PIOFreeInfoTOI(flgName,
76 toiType,
77 toiName,
78 beginIndex,
79 endIndex);
80 fits_unlock();
81}
82
83void PIOTOIReader::run() {
84 cout << "PIOTOIReader run " << group << "[" << object << "] "
85 << snBegin << " " << snEnd << endl;
86
87 for (int snb = snBegin; snb <= snEnd; snb += bufferSize) {
88 int sne = snb + bufferSize - 1;
89 if (sne > snEnd) sne=snEnd;
90 // TBD : check if PIODOUBLE != double;
91 char command[80];
92 sprintf(command, "Begin=%d; End=%d", snb, sne);
93 double* data = NULL;
94 uint_8* flags = NULL;
95 PIOBYTE* pioflags = NULL;
96 fits_lock();
97 PIOLONG n = PIOReadTOI((void**) &data,
98 const_cast<char*>(object.c_str()),
99 "PIODOUBLE",
100 command,
101 pioGroup);
102 if ( n<0) {
103 cout << " PIOReadTOI : " << n << endl;
104 abort();
105 }
106 if (flagdef != "") {
107 PIOLONG nf = PIOReadFLGObjectMask(&pioflags,
108 const_cast<char*>(flagdef.c_str()),
109 command,
110 pioGroup);
111 if (nf != n) {
112 cerr << "*** PIO Error, inconsistent read, data " << n << " flags "
113 << nf << endl;
114 abort();
115 }
116 flags = new uint_8[nf];
117 for (int i=0; i<nf; i++) flags[i] = (uint_8)pioflags[i];
118 PIODeleteFLG(pioflags, pioGroup);
119 }
120 fits_unlock();
121
122
123 if (flags != NULL) {
124 putData(0, snb, sne-snb+1, data, flags);
125 } else {
126 putData(0, snb, sne-snb+1, data);
127 }
128
129 fits_lock();
130 PIODeleteTOI(data, pioGroup);
131 // if (flags != NULL) PIODeleteFLG(flags, pioGroup); // PB !
132 if (flags != NULL) delete[] flags;
133 fits_unlock();
134 }
135 PIOCloseTOI(pioGroup);
136}
Note: See TracBrowser for help on using the repository browser.