1 | // ArchTOIPipe (C) CEA/DAPNIA/SPP IN2P3/LAL
|
---|
2 | // Eric Aubourg
|
---|
3 | // Christophe Magneville
|
---|
4 | // Reza Ansari
|
---|
5 | // $Id: piotoirdr.cc,v 1.2 2003-03-09 23:20:30 aubourg Exp $
|
---|
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();
|
---|
29 | pioGroup = PIOOpenTOI(const_cast<char*>(object.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 |
|
---|
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 |
|
---|
63 | // On recupere un tableau de beginIndex, mais si on en croit
|
---|
64 | // la doc, dans un groupe, tout le monde a les memes bornes, donc
|
---|
65 | // on peut lire le premier ?
|
---|
66 |
|
---|
67 | snBegin = beginIndex[0];
|
---|
68 | snEnd = endIndex[0];
|
---|
69 |
|
---|
70 | PIOFreeInfoTOI(flgName,
|
---|
71 | toiType,
|
---|
72 | toiName,
|
---|
73 | beginIndex,
|
---|
74 | endIndex);
|
---|
75 | fits_unlock();
|
---|
76 | }
|
---|
77 |
|
---|
78 | void PIOTOIReader::run() {
|
---|
79 | cout << "PIOTOIReader run " << group << "[" << object << "] "
|
---|
80 | << snBegin << " " << snEnd << endl;
|
---|
81 |
|
---|
82 | for (int snb = snBegin; snb <= snEnd; snb += bufferSize) {
|
---|
83 | int sne = snb + bufferSize - 1;
|
---|
84 | if (sne > snEnd) sne=snEnd;
|
---|
85 | // TBD : check if PIODOUBLE != double;
|
---|
86 | char command[80];
|
---|
87 | sprintf(command, "Begin=%d; End=%d", snb, sne);
|
---|
88 | double* data;
|
---|
89 | uint_8* flags = NULL;
|
---|
90 | fits_lock();
|
---|
91 | PIOLONG n = PIOReadTOI((void**) &data,
|
---|
92 | const_cast<char*>(object.c_str()),
|
---|
93 | "PIODOUBLE",
|
---|
94 | command,
|
---|
95 | pioGroup);
|
---|
96 | if (flagdef != "") {
|
---|
97 | PIOLONG nf = PIOReadFLG((PIOLONG**)&flags, // dangereux ?
|
---|
98 | const_cast<char*>(flagdef.c_str()),
|
---|
99 | command,
|
---|
100 | pioGroup);
|
---|
101 | if (nf != n) {
|
---|
102 | cerr << "*** PIO Error, inconsistent read, data " << n << " flags " << nf << endl;
|
---|
103 | abort();
|
---|
104 | }
|
---|
105 | }
|
---|
106 | fits_unlock();
|
---|
107 |
|
---|
108 |
|
---|
109 | if (flags != NULL) {
|
---|
110 | putData(0, snb, sne-snb+1, data, flags);
|
---|
111 | } else {
|
---|
112 | putData(0, snb, sne-snb+1, data);
|
---|
113 | }
|
---|
114 |
|
---|
115 | fits_lock();
|
---|
116 | PIODeleteTOI(data, pioGroup);
|
---|
117 | if (flags != NULL) PIODeleteFLG(flags, pioGroup);
|
---|
118 | fits_unlock();
|
---|
119 | }
|
---|
120 | PIOCloseTOI(pioGroup);
|
---|
121 | }
|
---|