-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGroupTable.cxx
248 lines (187 loc) · 7.16 KB
/
GroupTable.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
// Astrophysics Science Division,
// NASA/ Goddard Space Flight Center
// HEASARC
// http://heasarc.gsfc.nasa.gov
// e-mail: [email protected]
//
// Original author: Kristin Rutkowski
#include "GroupTable.h"
#include "ExtHDU.h"
#include "FITS.h"
#include <vector>
namespace CCfits {
// GroupTable::GroupTable (const GroupTable & right)
// : BinTable(right),
// m_name(right.m_name),
// m_id(right.m_id),
// m_numMembers(right.m_numMembers)
// {
// // +++ deep copy the members
//
// }
// make a new group table
GroupTable::GroupTable (FITS* p, int groupID, const String & groupName)
: BinTable(p, groupID, groupName),
m_name(groupName),
m_id(groupID),
m_numMembers(0)
{
}
GroupTable::~GroupTable()
{
}
HDU * GroupTable::addMember (HDU & newMember)
{
int status = 0;
// add the member object ptr to the container of members
m_members.push_back(&newMember);
// now physically add a new row to the group table for this new member HDU
// the hdupos param is only read if the new member file ptr is null
if ( fits_add_group_member(fitsPointer(), newMember.fitsPointer(), 0, &status) ) throw FitsError(status);
++m_numMembers;
// +++ not sure if this is what I should be doing here. or just return void
return &newMember;
}
HDU * GroupTable::addMember(int memberPosition)
{
int status = 0;
// if using memberPosition, the new member HDU must be in the same file as
// the current grouping table
// +++ add this to documentation
ExtHDU & newMember = parent()->extension(memberPosition);
// +++ so we need to add an HDU * to the vector. what if there is another * to this HDU elsewhere? Does it matter?
// add the member object ptr to the container of members
m_members.push_back(&newMember);
// now physically add a new row to the group table for this new member HDU
// the hdupos param is only read if the new member file ptr is null
if ( fits_add_group_member(fitsPointer(), NULL, memberPosition , &status) ) throw FitsError(status);
++m_numMembers;
// +++ not sure if this is what I should be doing here. or just return void
return &newMember;
}
void GroupTable::listMembers() const
{
std::cout << "Listing " << m_members.size() << " group members: " << std::endl;
std::vector<HDU *>::const_iterator iter;
for (iter = m_members.begin(); iter != m_members.end(); ++iter) {
std::cout << " " << dynamic_cast<ExtHDU *>(*iter)->name() << std::endl;
}
}
//HDU * GroupTable::removeMember(HDU & member, bool deleteHDU)
HDU * GroupTable::removeMember(HDU & member)
{
// +++ deleteHDU must be false for now
bool deleteHDU = false;
int status = 0;
int rmopt = (deleteHDU ? OPT_RM_MBR : OPT_RM_ENTRY);
long toRemove = 0;
HDU * returnHDU = (deleteHDU ? NULL : &member);
// +++ "updates the member's GRPIDn/GRPLCn keywords"
// so I should reread the keywords from this HDU (if it's not deleted),
// to update the datamembers?
// +++ but there's a bug, and fits_remove_member doesn't actually remove the keys
// remove the HDU from the list of group members
// go through the vector of members and look for this one
std::vector<HDU *>::iterator iter;
for (iter = m_members.begin(); iter != m_members.end(); ++iter) {
++toRemove;
if ( (**iter) == member ) {
m_members.erase(iter);
break;
}
}
--m_numMembers;
if (fits_remove_member(fitsPointer(), toRemove, rmopt, &status) ) throw FitsError(status);
// +++ or should I just not return anything?
// if we deleted the HDU, return a null pointer
return returnHDU;
}
//HDU * GroupTable::removeMember(LONGLONG memberNumber, bool deleteHDU)
HDU * GroupTable::removeMember(LONGLONG memberNumber)
{
// +++ deleteHDU must be false for now
bool deleteHDU = false;
int status = 0;
int rmopt = (deleteHDU ? OPT_RM_MBR : OPT_RM_ENTRY);
long toRemove = memberNumber;
HDU * returnHDU = (deleteHDU ? NULL : *(m_members.begin()+memberNumber-1) );
// +++ "updates the member's GRPIDn/GRPLCn keywords"
// so I should reread the keywords from this HDU (if it's not deleted),
// to update the datamembers?
// +++ but there's a bug, and fits_remove_member doesn't actually remove the keys
if ( (memberNumber <= 0) || (memberNumber > m_numMembers) ) {
throw;
// +++ better exception handling
} else {
returnHDU = *(m_members.begin()+memberNumber-1);
m_members.erase(m_members.begin()+memberNumber-1);
}
--m_numMembers;
if (fits_remove_member(fitsPointer(), toRemove, rmopt, &status) ) throw FitsError(status);
// +++ or should I just not return anything?
// if we deleted the HDU, return a null pointer
return returnHDU;
}
// void GroupTable::mergeGroups (GroupTable & other, bool removeOther)
// {
//
// int status = 0;
// int mgopt = (removeOther ? OPT_MRG_MOV : OPT_MRG_COPY);
//
// +++ or have a func const getMembers() ?
// // add all these new members to the current member vector
// std::vector<HDU *>::iterator iter;
// for (iter = other.m_members().begin(); iter != other.m_members().end(); ++iter) {
// addMember(**iter);
// }
//
// if ( fits_merge_groups(other.fitsPointer(), fitsPointer(), mgopt, &status) ) throw FitsError(status);
//
// // " In both cases, the GRPIDn and GRPLCn keywords of the member HDUs are updated accordingly."
// // +++ again, how should we handle the fact that the keywords in all these HDUs are updated?
// // if the HDUs are objects, we should reread the keywords, right?
//
// // +++ if removeOther, then the other HDU is deleted. How should that be handled here?
// // I don't like having extra functionality in a function
//
// }
// void GroupTable::compactGroup(bool deleteSubGroupTables)
// {
//
// int status = 0;
// int cmopt = (deleteSubGroupTables ? OPT_CMT_MBR_DEL : OPT_CMT_MBR);
//
// // first, remove any group tables from the member vector
// // +++ am I basically repeating the processing that is inside fits_compact_group ? Since I don't keep detailed info about my members
//
//
// // +++ this may delete HDUs that could possible have an object somewhere. Do we care?
// if (fits_compact_group(fitsPointer(), cmopt, &status) ) throw FitsError(status);
//
// }
// bool GroupTable::verifyGroup () const
// {
//
// int status = 0;
// long firstFailed = 0;
// bool isVerified = false;
//
// if ( fits_verify_group(fitsPointer(), &firstFailed, &status) ) throw FitsError(status);
//
// // +++ I'm not sure how I want to handle this function
//
// if (firstFailed == 0) {
// isVerified = true;
// } else if (firstFailed > 0) {
// // a member HDU failed
//
// } else {
// // a group link failed
//
//
// }
//
// return isVerified;
//
// }
} // namespace CCfits