File failed to load: https://isis.astrogeology.usgs.gov/6.0.0/Object/assets/jax/output/NativeMML/config.js
Isis 3 Programmer Reference
ObservationNumberList.cpp
1 
6 /* SPDX-License-Identifier: CC0-1.0 */
7 #include "ObservationNumberList.h"
8 
9 #include "FileName.h"
10 #include "IException.h"
11 #include "Pvl.h"
12 #include "SerialNumberList.h"
13 
14 using namespace std;
15 namespace Isis {
16 
26  ObservationNumberList::ObservationNumberList(const QString &listfile, bool checkTarget) :
27  SerialNumberList(listfile, checkTarget) {
28  init(this);
29  }
30 
31 
38  SerialNumberList(*snlist) {
39  init(snlist);
40  }
41 
42 
52 
53  if (snlist->size() == 0) {
54  QString msg = "Serial number list is empty";
55  throw IException(IException::User, msg, _FILEINFO_);
56  }
57 
58  map<QString, int> observationMap;
59  QString observationNumber;
60  int currentIndex = 0;
61  int observationIndex;
62 
63  // Fill the temporary map to generate observation sets
64  for (int isn = 0; isn < snlist->size(); isn++) {
65  observationNumber = snlist->observationNumber(isn);
66 
67  if (observationMap.find(observationNumber) == observationMap.end()) {
68  observationMap.insert(pair<QString, int>(observationNumber, currentIndex));
69  observationIndex = currentIndex++;
70  }
71  else {
72  observationIndex = observationMap.find(observationNumber)->second;
73  }
74 
75  add(isn, observationIndex, observationNumber);
76  }
77  m_numberObservations = currentIndex;
78  }
79 
80 
85  }
86 
87 
96 
97  if (snlist->size() == 0) {
98  QString msg = "Cannot remove, serial number list is empty";
99  throw IException(IException::User, msg, _FILEINFO_);
100  }
101 
102  m_sets.clear();
103  m_indexMap.clear();
104 
105  map<QString, int> observationMap;
106  QString observationNumber;
107  int currentIndex = 0;
108  int observationIndex;
109 
110  // Fill the temporary map to generate observation sets
111  for (int isn = 0; isn < this->size(); isn++) {
112  if ( (snlist->hasSerialNumber(this->serialNumber(isn))) ) {
113  continue;
114  }
115 
117 
118  if (observationMap.find(observationNumber) == observationMap.end()) {
119  observationMap.insert(pair<QString, int>(observationNumber, currentIndex));
120  observationIndex = currentIndex++;
121  }
122  else {
123  observationIndex = observationMap.find(observationNumber)->second;
124  }
125 
126  add(isn, observationIndex, observationNumber);
127  }
128  m_numberObservations = currentIndex;
129  }
130 
131 
137  void ObservationNumberList::remove(const QString &listfile) {
138  SerialNumberList snlist(listfile);
139  remove(&snlist);
140  }
141 
142 
154  void ObservationNumberList::add(const int isn, const int observationIndex,
155  QString observationNumber) {
156 
157  ObservationSet nextset;
158  nextset.serialNumberIndex = isn;
159  nextset.observationNumberIndex = observationIndex;
160  nextset.observationNumber = observationNumber;
161 
162  m_sets.push_back(nextset);
163  m_indexMap.insert(pair<int, int>(isn, observationIndex));
164  }
165 
166 
173  return m_numberObservations;
174  }
175 
176 
186  for (unsigned index = 0; index < m_pairs.size(); index++) {
187  if (m_pairs[index].observationNumber == on) {
188  return true;
189  }
190  }
191  return false;
192  }
193 
194 
205  // if (serialNumberIndex >= 0 && serialNumberIndex < (int) m_indexMap.size()) {
206  if (serialNumberIndex >= 0) {
207  return m_indexMap.find(serialNumberIndex)->second;
208  }
209  else {
210  QString msg = "Serial Number Index [" + toString(serialNumberIndex) + "] is invalid";
211  throw IException(IException::Programmer, msg, _FILEINFO_);
212  }
213  }
214 
215 
226  QString ObservationNumberList::observationNumber(const QString &filename) {
227  if (m_fileMap.find(FileName(filename).expanded()) == m_fileMap.end()) {
228  QString msg = "Requested filename [" + FileName(filename).expanded() + "] ";
229  msg += "does not exist in the list";
230  throw IException(IException::Programmer, msg, _FILEINFO_);
231  }
232  int index = fileNameIndex(filename);
233  return m_pairs[index].observationNumber;
234  }
235 
236 
247  if (index >= 0 && index < (int) m_pairs.size()) {
248  return m_pairs[index].observationNumber;
249  }
250  else {
251  QString msg = "Index [" + toString(index) + "] is invalid";
252  throw IException(IException::Programmer, msg, _FILEINFO_);
253  }
254  }
255 
256 
267  vector<QString> ObservationNumberList::possibleFileNames(const QString &on) {
268  vector<QString> filenames;
269  for (unsigned index = 0; index < m_pairs.size(); index++) {
270  if (m_pairs[index].observationNumber == on) {
271  filenames.push_back(m_pairs[index].filename);
272  }
273  }
274  if (filenames.size() > 0) {
275  return filenames;
276  }
277  else {
278  QString msg = "Requested observation number [" + on + "] ";
279  msg += "does not exist in the list";
280  throw IException(IException::Programmer, msg, _FILEINFO_);
281  }
282  }
283 
284 }
Isis::ObservationNumberList::observationSize
int observationSize() const
How many unique observations are in the list?
Definition: ObservationNumberList.cpp:172
Isis::ObservationNumberList::possibleFileNames
std::vector< QString > possibleFileNames(const QString &on)
Return possible filenames given an observation number.
Definition: ObservationNumberList.cpp:267
Isis::SerialNumberList::observationNumber
QString observationNumber(int index)
Return a observation number given an index.
Definition: SerialNumberList.cpp:468
Isis::SerialNumberList::size
int size() const
How many serial number / filename combos are in the list.
Definition: SerialNumberList.cpp:384
Isis::SerialNumberList::serialNumberIndex
int serialNumberIndex(const QString &sn)
Return a list index given a serial number.
Definition: SerialNumberList.cpp:490
Isis::FileName
File name manipulation and expansion.
Definition: FileName.h:100
Isis::ObservationNumberList::ObservationSet
An observation consiting of a serial number index to the ObservationNumberList, an observation number...
Definition: ObservationNumberList.h:68
Isis::ObservationNumberList::observationNumber
QString observationNumber(const QString &filename)
Return an observation number given a filename.
Definition: ObservationNumberList.cpp:226
Isis::toString
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:211
Isis::SerialNumberList
Serial Number list generator.
Definition: SerialNumberList.h:64
Isis::ObservationNumberList::remove
void remove(SerialNumberList *snlist)
Removes all of the listed serial numbers from the observation.
Definition: ObservationNumberList.cpp:95
Isis::SerialNumberList::m_fileMap
std::map< QString, int > m_fileMap
Maps filenames to their positions in the list.
Definition: SerialNumberList.h:106
Isis::ObservationNumberList::m_numberObservations
int m_numberObservations
Count of observations in the observation number list.
Definition: ObservationNumberList.h:77
Isis::FileName::expanded
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
Definition: FileName.cpp:196
Isis::ObservationNumberList::observationNumberMapIndex
int observationNumberMapIndex(const int serialNumberIndex)
Return a observation index given a serial number index.
Definition: ObservationNumberList.cpp:204
Isis::SerialNumberList::fileNameIndex
int fileNameIndex(const QString &filename)
Return a list index given a filename.
Definition: SerialNumberList.cpp:517
Isis::ObservationNumberList::~ObservationNumberList
~ObservationNumberList()
Destructor.
Definition: ObservationNumberList.cpp:84
Isis::ObservationNumberList::init
void init(SerialNumberList *snlist)
Initiates the ObservationNumberList.
Definition: ObservationNumberList.cpp:51
Isis::ObservationNumberList::hasObservationNumber
bool hasObservationNumber(const QString &on)
Determines whether or not the requested observation number exists in the list.
Definition: ObservationNumberList.cpp:185
Isis::IException
Isis exception class.
Definition: IException.h:91
Isis::SerialNumberList::m_pairs
std::vector< Pair > m_pairs
List of serial number Pair entities.
Definition: SerialNumberList.h:104
Isis::ObservationNumberList::m_indexMap
std::multimap< int, int > m_indexMap
Maps serial number index to observation number index.
Definition: ObservationNumberList.h:76
Isis::ObservationNumberList::add
void add(int isn, const int observationIndex, QString observationNumber)
Adds a new serial number index / observation number index / observation number to the SerialNumberLis...
Definition: ObservationNumberList.cpp:154
Isis::IException::Programmer
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:146
std
Namespace for the standard library.
Isis::ObservationNumberList::m_sets
std::vector< ObservationSet > m_sets
List of observation sets.
Definition: ObservationNumberList.h:78
Isis::SerialNumberList::hasSerialNumber
bool hasSerialNumber(QString sn)
Determines whether or not the requested serial number exists in the list.
Definition: SerialNumberList.cpp:373
Isis::ObservationNumberList::ObservationNumberList
ObservationNumberList(const QString &list, bool checkTarget=true)
Creates an ObservationNumberList from a filename.
Definition: ObservationNumberList.cpp:26
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16
Isis::IException::User
@ User
A type of error that could only have occurred due to a mistake on the user's part (e....
Definition: IException.h:126

U.S. Department of the Interior | U.S. Geological Survey
ISIS | Privacy & Disclaimers | Astrogeology Research Program
To contact us, please post comments and questions on the USGS Astrogeology Discussion Board
To report a bug, or suggest a feature go to: ISIS Github
File Modified: 07/13/2023 15:16:58