Isis 3 Programmer Reference
ObservationNumberList.cpp
2 
3 #include "FileName.h"
4 #include "IException.h"
5 #include "Pvl.h"
6 #include "SerialNumberList.h"
7 
8 using namespace std;
9 namespace Isis {
10 
20  ObservationNumberList::ObservationNumberList(const QString &listfile, bool checkTarget) :
21  SerialNumberList(listfile, checkTarget) {
22  init(this);
23  }
24 
25 
32  SerialNumberList(*snlist) {
33  init(snlist);
34  }
35 
36 
46 
47  if (snlist->size() == 0) {
48  QString msg = "Serial number list is empty";
50  }
51 
52  map<QString, int> observationMap;
53  QString observationNumber;
54  int currentIndex = 0;
55  int observationIndex;
56 
57  // Fill the temporary map to generate observation sets
58  for (int isn = 0; isn < snlist->size(); isn++) {
59  observationNumber = snlist->observationNumber(isn);
60 
61  if (observationMap.find(observationNumber) == observationMap.end()) {
62  observationMap.insert(pair<QString, int>(observationNumber, currentIndex));
63  observationIndex = currentIndex++;
64  }
65  else {
66  observationIndex = observationMap.find(observationNumber)->second;
67  }
68 
69  add(isn, observationIndex, observationNumber);
70  }
71  m_numberObservations = currentIndex;
72  }
73 
74 
79  }
80 
81 
90 
91  if (snlist->size() == 0) {
92  QString msg = "Cannot remove, serial number list is empty";
94  }
95 
96  m_sets.clear();
97  m_indexMap.clear();
98 
99  map<QString, int> observationMap;
100  QString observationNumber;
101  int currentIndex = 0;
102  int observationIndex;
103 
104  // Fill the temporary map to generate observation sets
105  for (int isn = 0; isn < this->size(); isn++) {
106  if ( (snlist->hasSerialNumber(this->serialNumber(isn))) ) {
107  continue;
108  }
109 
111 
112  if (observationMap.find(observationNumber) == observationMap.end()) {
113  observationMap.insert(pair<QString, int>(observationNumber, currentIndex));
114  observationIndex = currentIndex++;
115  }
116  else {
117  observationIndex = observationMap.find(observationNumber)->second;
118  }
119 
120  add(isn, observationIndex, observationNumber);
121  }
122  m_numberObservations = currentIndex;
123  }
124 
125 
131  void ObservationNumberList::remove(const QString &listfile) {
132  SerialNumberList snlist(listfile);
133  remove(&snlist);
134  }
135 
136 
148  void ObservationNumberList::add(const int isn, const int observationIndex,
149  QString observationNumber) {
150 
151  ObservationSet nextset;
152  nextset.serialNumberIndex = isn;
153  nextset.observationNumberIndex = observationIndex;
154  nextset.observationNumber = observationNumber;
155 
156  m_sets.push_back(nextset);
157  m_indexMap.insert(pair<int, int>(isn, observationIndex));
158  }
159 
160 
167  return m_numberObservations;
168  }
169 
170 
180  for (unsigned index = 0; index < m_pairs.size(); index++) {
181  if (m_pairs[index].observationNumber == on) {
182  return true;
183  }
184  }
185  return false;
186  }
187 
188 
199  // if (serialNumberIndex >= 0 && serialNumberIndex < (int) m_indexMap.size()) {
200  if (serialNumberIndex >= 0) {
201  return m_indexMap.find(serialNumberIndex)->second;
202  }
203  else {
204  QString msg = "Serial Number Index [" + toString(serialNumberIndex) + "] is invalid";
206  }
207  }
208 
209 
220  QString ObservationNumberList::observationNumber(const QString &filename) {
221  if (m_fileMap.find(FileName(filename).expanded()) == m_fileMap.end()) {
222  QString msg = "Requested filename [" + FileName(filename).expanded() + "] ";
223  msg += "does not exist in the list";
225  }
226  int index = fileNameIndex(filename);
227  return m_pairs[index].observationNumber;
228  }
229 
230 
241  if (index >= 0 && index < (int) m_pairs.size()) {
242  return m_pairs[index].observationNumber;
243  }
244  else {
245  QString msg = "Index [" + toString(index) + "] is invalid";
247  }
248  }
249 
250 
261  vector<QString> ObservationNumberList::possibleFileNames(const QString &on) {
262  vector<QString> filenames;
263  for (unsigned index = 0; index < m_pairs.size(); index++) {
264  if (m_pairs[index].observationNumber == on) {
265  filenames.push_back(m_pairs[index].filename);
266  }
267  }
268  if (filenames.size() > 0) {
269  return filenames;
270  }
271  else {
272  QString msg = "Requested observation number [" + on + "] ";
273  msg += "does not exist in the list";
275  }
276  }
277 
278 }
void init(SerialNumberList *snlist)
Initiates the ObservationNumberList.
int observationSize() const
How many unique observations are in the list?
int serialNumberIndex(const QString &sn)
Return a list index given a serial number.
QString observationNumber(const QString &filename)
Return an observation number given a filename.
bool hasSerialNumber(QString sn)
Determines whether or not the requested serial number exists in the list.
File name manipulation and expansion.
Definition: FileName.h:116
An observation consiting of a serial number index to the ObservationNumberList, an observation number...
Namespace for the standard library.
std::map< QString, int > m_fileMap
Maps filenames to their positions in the list.
int fileNameIndex(const QString &filename)
Return a list index given a filename.
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:226
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:162
std::multimap< int, int > m_indexMap
Maps serial number index to observation number index.
std::vector< Pair > m_pairs
List of serial number Pair entities.
int m_numberObservations
Count of observations in the observation number list.
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
A type of error that could only have occurred due to a mistake on the user&#39;s part (e...
Definition: IException.h:142
ObservationNumberList(const QString &list, bool checkTarget=true)
Creates an ObservationNumberList from a filename.
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
Definition: FileName.cpp:212
int observationNumberMapIndex(const int serialNumberIndex)
Return a observation index given a serial number index.
int size() const
How many serial number / filename combos are in the list.
QString observationNumber(int index)
Return a observation number given an index.
std::vector< ObservationSet > m_sets
List of observation sets.
Isis exception class.
Definition: IException.h:107
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
std::vector< QString > possibleFileNames(const QString &on)
Return possible filenames given an observation number.
Serial Number list generator.
bool hasObservationNumber(const QString &on)
Determines whether or not the requested observation number exists in the list.
void add(int isn, const int observationIndex, QString observationNumber)
Adds a new serial number index / observation number index / observation number to the SerialNumberLis...
void remove(SerialNumberList *snlist)
Removes all of the listed serial numbers from the observation.