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

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

PIOlib I/O

File size: 2.9 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.4 2003-04-24 13:22:26 aubourg Exp $
6
7#include "piotoirdr.h"
8
9extern void fits_lock();
10extern void fits_unlock();
11
12PIOTOIReader::PIOTOIReader(string grp, string obj, string flg) {
13 group = grp;
14 object = obj;
15 flagdef = flg;
16 pioGroup = NULL;
17
18}
19
20PIOTOIReader::~PIOTOIReader() {
21 if (pioGroup != NULL) {
22 // ??
23 }
24}
25
26void 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
42void 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
82void 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 fits_lock();
95 PIOLONG n = PIOReadTOI((void**) &data,
96 const_cast<char*>(object.c_str()),
97 "PIODOUBLE",
98 command,
99 pioGroup);
100 if (flagdef != "") {
101 PIOLONG nf = PIOReadFLG((PIOLONG**)&flags, // dangereux ?
102 const_cast<char*>(flagdef.c_str()),
103 command,
104 pioGroup);
105 if (nf != n) {
106 cerr << "*** PIO Error, inconsistent read, data " << n << " flags " << nf << endl;
107 abort();
108 }
109 }
110 fits_unlock();
111
112
113 if (flags != NULL) {
114 putData(0, snb, sne-snb+1, data, flags);
115 } else {
116 putData(0, snb, sne-snb+1, data);
117 }
118
119 fits_lock();
120 PIODeleteTOI(data, pioGroup);
121 // if (flags != NULL) PIODeleteFLG(flags, pioGroup); // PB !
122 fits_unlock();
123 }
124 PIOCloseTOI(pioGroup);
125}
Note: See TracBrowser for help on using the repository browser.