Isis Developer Reference
Module.h
Go to the documentation of this file.
1 #ifndef Module_h
2 #define Module_h
3 
10 /* SPDX-License-Identifier: CC0-1.0 */
11 
12 #include <iostream>
13 #include <sstream>
14 #include <string>
15 #include <vector>
16 #include <algorithm>
17 
18 #include "HiCalTypes.h"
19 #include "HiCalUtil.h"
20 #include "HiCalConf.h"
21 #include "LoadCSV.h"
22 #include "PvlKeyword.h"
23 #include "PvlGroup.h"
24 #include "IException.h"
25 
26 namespace Isis {
27 
28  class PvlGroup;
29 
39  class Module {
40  public:
41  friend std::ostream &operator<<(std::ostream &o, const Module &c) {
42  c.printOn(o);
43  return (o);
44  }
45 
46  public:
47  // Constructors and Destructor
48  Module() : _name("Module"), _csvFile(""), _data(), _history(),
50  Module(const QString &name) : _name(name), _csvFile(""), _data(),
53  Module(const QString &name, const HiHistory &history) :
54  _name(name), _csvFile(""), _data(), _history(history),
56  Module(const QString &name, const Module &c) : _name(name),
59  Module(const Module &c) : _name(c._name), _csvFile(c._csvFile),
63 
64 
66  virtual ~Module() { }
67 
69  inline QString name() const { return (_name); }
71  inline QString getcsvFile() const { return (_csvFile); }
73  inline int size() const { return (_data.dim()); }
74 
76  virtual void Process(const Module &c) {
77  Process(c.ref());
78  }
79 
81  virtual void Process(const HiVector &v) {
82  _data = v;
83  return;
84  }
85 
101  HiVector loadCsv(const QString &csvBase, const HiCalConf &conf,
102  const DbProfile &prof, const int &elements = 0) {
103  LoadCSV csv(csvBase, conf, prof);
104  _csvFile = csv.filename();
105  if (elements != 0) csv.validateSize(elements, true);
106  csv.History(_history);
107  return (csv.getVector());
108  }
109 
111  const HiVector &ref() const { return (_data); }
113  inline double operator()(int index) const { return (_data[index]);}
114 
116  const HiHistory &History() const { return (_history); }
117 
119  virtual void record(PvlGroup &pvl,
120  const QString keyname = "ModuleHistory")
121  const {
122  pvl += _history.makekey(keyname);
123  return;
124  }
125 
131  void Dump(const QString &fname) const {
132  FileName dumpc(fname);
133  QString dumpcFile = dumpc.expanded();
134  std::ofstream ofile(dumpcFile.toLatin1().data(), std::ios::out);
135  if (!ofile) {
136  QString mess = "Unable to open/create module dump file " +
137  dumpc.expanded();
138  throw IException(IException::User, mess, _FILEINFO_);
139  }
140  ofile << *this;
141  ofile.close();
142  return;
143  }
144 
145 
146  protected:
147  enum { DefaultWidth = 10, DefaultPrecision = 6};
148 
149  QString _name;
150  QString _csvFile;
153  int _fmtWidth;
155 
156 
169  inline QString formatDbl(const double &value) const {
170  std::ostringstream ostr;
171  if (IsSpecial(value)) {
172  ostr << std::setw(_fmtWidth) << PixelToString(value);
173  return (QString(ostr.str().c_str()));
174  }
175  else {
176  // Its not special so format to callers specs
177  ostr << std::setw(_fmtWidth) << std::setprecision(_fmtPrecision) << value;
178  return (QString(ostr.str().c_str()));
179  }
180  }
181 
183  virtual void printOn(std::ostream &o) const {
184  o << "# History = " << _history << std::endl;
185  o << "# Count = " << _data.dim() << std::endl;
186  for (int i = 0 ; i < _data.dim() ; i++) {
187  o << formatDbl(_data[i]) << std::endl;
188  }
189  return;
190  }
191 
192  };
193 
194 } // namespace Isis
195 #endif
Isis::PixelToString
QString PixelToString(double d)
Takes a double pixel value and returns the name of the pixel type as a string.
Definition: SpecialPixel.h:371
Isis::Module::_fmtPrecision
int _fmtPrecision
Default field with of double.
Definition: Module.h:154
Isis::Module::_history
HiHistory _history
Hierarchial component history.
Definition: Module.h:152
Isis::Module::record
virtual void record(PvlGroup &pvl, const QString keyname="ModuleHistory") const
Record history in Pvl group object.
Definition: Module.h:119
Isis::Module::Process
virtual void Process(const Module &c)
Invokes the process method on the Module vector.
Definition: Module.h:76
Isis::Module::_fmtWidth
int _fmtWidth
Default field with of double.
Definition: Module.h:153
Isis::Module::DefaultWidth
@ DefaultWidth
Definition: Module.h:147
Isis::Module
Module manages HiRISE calibration vectors from various sources.
Definition: Module.h:39
Isis::Module::ref
const HiVector & ref() const
Return data via a const reference.
Definition: Module.h:111
Isis::FileName
File name manipulation and expansion.
Definition: FileName.h:100
Isis::HiHistory::makekey
PvlKeyword makekey(const QString &name="History") const
Definition: HiCalTypes.h:67
Isis::LoadCSV::getVector
HiVector getVector() const
Definition: LoadCSV.cpp:196
PvlGroup.h
Isis::LoadCSV::History
void History(HiHistory &history) const
Definition: LoadCSV.cpp:206
Isis::Module::size
int size() const
Returns the size (number of elements) of data array.
Definition: Module.h:73
LoadCSV.h
Isis::Module::History
const HiHistory & History() const
Return recorded history of events.
Definition: Module.h:116
HiCalConf.h
Isis::Module::name
QString name() const
Returns name of component.
Definition: Module.h:69
Isis::Module::_csvFile
QString _csvFile
Fully expanded name of CSV file if present.
Definition: Module.h:150
Isis::Module::DefaultPrecision
@ DefaultPrecision
Definition: Module.h:147
Isis::Module::Process
virtual void Process(const HiVector &v)
Default processing behavior makes a reference copy of data array.
Definition: Module.h:81
Isis::Module::~Module
virtual ~Module()
Destructor.
Definition: Module.h:66
Isis::LoadCSV::filename
QString filename() const
Definition: LoadCSV.cpp:176
Isis::Module::Module
Module(const QString &name, const Module &c)
Definition: Module.h:56
Isis::HiHistory
Definition: HiCalTypes.h:30
Isis::LoadCSV
Provides generalized access to HiRISE calibration CSV files.
Definition: LoadCSV.h:52
Isis::IsSpecial
bool IsSpecial(const double d)
Returns if the input pixel is special.
Definition: SpecialPixel.h:197
Isis::Module::_data
HiVector _data
Data vector.
Definition: Module.h:151
Isis::Module::Module
Module()
Definition: Module.h:48
Isis::Module::formatDbl
QString formatDbl(const double &value) const
Properly format values that could be special pixels.
Definition: Module.h:169
Isis::Module::loadCsv
HiVector loadCsv(const QString &csvBase, const HiCalConf &conf, const DbProfile &prof, const int &elements=0)
Provide generic loading of CSV file for all modules.
Definition: Module.h:101
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::Module::operator()
double operator()(int index) const
Return individual element of the data vector.
Definition: Module.h:113
Isis::PvlGroup
Contains multiple PvlContainers.
Definition: PvlGroup.h:41
_FILEINFO_
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:24
HiCalUtil.h
Isis::Module::operator<<
friend std::ostream & operator<<(std::ostream &o, const Module &c)
Definition: Module.h:41
Isis::DbProfile
A DbProfile is a container for access parameters to a database.
Definition: DbProfile.h:51
HiCalTypes.h
Isis::HiVector
TNT::Array1D< double > HiVector
1-D Buffer
Definition: HiCalTypes.h:27
Isis::Module::Dump
void Dump(const QString &fname) const
Dumps the component to a specified file.
Definition: Module.h:131
Isis::IException
Isis exception class.
Definition: IException.h:91
Isis::Module::_name
QString _name
Name of component.
Definition: Module.h:149
IException.h
Isis::Module::getcsvFile
QString getcsvFile() const
Returns expanded name of last CSV file loaded by loadCsv.
Definition: Module.h:71
PvlKeyword.h
Isis::Module::Module
Module(const Module &c)
Definition: Module.h:59
Isis::Module::printOn
virtual void printOn(std::ostream &o) const
Default printing of data in module.
Definition: Module.h:183
Isis::Module::Module
Module(const QString &name, const HiHistory &history)
Definition: Module.h:53
Isis::Module::Module
Module(const QString &name)
Definition: Module.h:50
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16
Isis::LoadCSV::validateSize
bool validateSize(const int &expected, const bool &throw_on_error=false) const
Definition: LoadCSV.cpp:184
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