Isis 3 Programmer Reference
Module.h
Go to the documentation of this file.
1 #ifndef Module_h
2 #define Module_h
3 
27 #include <iostream>
28 #include <sstream>
29 #include <string>
30 #include <vector>
31 #include <algorithm>
32 
33 #include "HiCalTypes.h"
34 #include "HiCalUtil.h"
35 #include "HiCalConf.h"
36 #include "LoadCSV.h"
37 #include "PvlKeyword.h"
38 #include "PvlGroup.h"
39 #include "IException.h"
40 
41 namespace Isis {
42 
43  class PvlGroup;
44 
54  class Module {
55  public:
56  friend std::ostream &operator<<(std::ostream &o, const Module &c) {
57  c.printOn(o);
58  return (o);
59  }
60 
61  public:
62  // Constructors and Destructor
63  Module() : _name("Module"), _csvFile(""), _data(), _history(),
64  _fmtWidth(DefaultWidth), _fmtPrecision(DefaultPrecision) { }
65  Module(const QString &name) : _name(name), _csvFile(""), _data(),
66  _history(),_fmtWidth(DefaultWidth),
67  _fmtPrecision(DefaultPrecision) { }
68  Module(const QString &name, const HiHistory &history) :
69  _name(name), _csvFile(""), _data(), _history(history),
70  _fmtWidth(DefaultWidth), _fmtPrecision(DefaultPrecision) { }
71  Module(const QString &name, const Module &c) : _name(name),
74  Module(const Module &c) : _name(c._name), _csvFile(c._csvFile),
78 
79 
81  virtual ~Module() { }
82 
84  inline QString name() const { return (_name); }
86  inline QString getcsvFile() const { return (_csvFile); }
88  inline int size() const { return (_data.dim()); }
89 
91  virtual void Process(const Module &c) {
92  Process(c.ref());
93  }
94 
96  virtual void Process(const HiVector &v) {
97  _data = v;
98  return;
99  }
100 
116  HiVector loadCsv(const QString &csvBase, const HiCalConf &conf,
117  const DbProfile &prof, const int &elements = 0) {
118  LoadCSV csv(csvBase, conf, prof);
119  _csvFile = csv.filename();
120  if (elements != 0) csv.validateSize(elements, true);
121  csv.History(_history);
122  return (csv.getVector());
123  }
124 
126  const HiVector &ref() const { return (_data); }
128  inline double operator()(int index) const { return (_data[index]);}
129 
131  const HiHistory &History() const { return (_history); }
132 
134  virtual void record(PvlGroup &pvl,
135  const QString keyname = "ModuleHistory")
136  const {
137  pvl += _history.makekey(keyname);
138  return;
139  }
140 
146  void Dump(const QString &fname) const {
147  FileName dumpc(fname);
148  QString dumpcFile = dumpc.expanded();
149  std::ofstream ofile(dumpcFile.toLatin1().data(), std::ios::out);
150  if (!ofile) {
151  QString mess = "Unable to open/create module dump file " +
152  dumpc.expanded();
153  throw IException(IException::User, mess, _FILEINFO_);
154  }
155  ofile << *this;
156  ofile.close();
157  return;
158  }
159 
160 
161  protected:
162  enum { DefaultWidth = 10, DefaultPrecision = 6};
163 
164  QString _name;
165  QString _csvFile;
168  int _fmtWidth;
170 
171 
184  inline QString formatDbl(const double &value) const {
185  std::ostringstream ostr;
186  if (IsSpecial(value)) {
187  ostr << std::setw(_fmtWidth) << PixelToString(value);
188  return (QString(ostr.str().c_str()));
189  }
190  else {
191  // Its not special so format to callers specs
192  ostr << std::setw(_fmtWidth) << std::setprecision(_fmtPrecision) << value;
193  return (QString(ostr.str().c_str()));
194  }
195  }
196 
198  virtual void printOn(std::ostream &o) const {
199  o << "# History = " << _history << std::endl;
200  o << "# Count = " << _data.dim() << std::endl;
201  for (int i = 0 ; i < _data.dim() ; i++) {
202  o << formatDbl(_data[i]) << std::endl;
203  }
204  return;
205  }
206 
207  };
208 
209 } // namespace Isis
210 #endif
const HiVector & ref() const
Return data via a const reference.
Definition: Module.h:126
File name manipulation and expansion.
Definition: FileName.h:116
int _fmtWidth
Default field with of double.
Definition: Module.h:168
virtual void printOn(std::ostream &o) const
Default printing of data in module.
Definition: Module.h:198
HiVector _data
Data vector.
Definition: Module.h:166
virtual void Process(const HiVector &v)
Default processing behavior makes a reference copy of data array.
Definition: Module.h:96
HiHistory _history
Hierarchial component history.
Definition: Module.h:167
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:116
double operator()(int index) const
Return individual element of the data vector.
Definition: Module.h:128
virtual void Process(const Module &c)
Invokes the process method on the Module vector.
Definition: Module.h:91
virtual ~Module()
Destructor.
Definition: Module.h:81
QString _csvFile
Fully expanded name of CSV file if present.
Definition: Module.h:165
A DbProfile is a container for access parameters to a database.
Definition: DbProfile.h:65
const HiHistory & History() const
Return recorded history of events.
Definition: Module.h:131
QString formatDbl(const double &value) const
Properly format values that could be special pixels.
Definition: Module.h:184
void Dump(const QString &fname) const
Dumps the component to a specified file.
Definition: Module.h:146
QString name() const
Returns name of component.
Definition: Module.h:84
Contains multiple PvlContainers.
Definition: PvlGroup.h:57
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
Module manages HiRISE calibration vectors from various sources.
Definition: Module.h:54
A type of error that could only have occurred due to a mistake on the user&#39;s part (e...
Definition: IException.h:142
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
Definition: FileName.cpp:212
bool IsSpecial(const double d)
Returns if the input pixel is special.
Definition: SpecialPixel.h:212
$Revision $Date$ $Id$
Provides generalized access to HiRISE calibration CSV files.
Definition: LoadCSV.h:66
QString _name
Name of component.
Definition: Module.h:164
int _fmtPrecision
Default field with of double.
Definition: Module.h:169
virtual void record(PvlGroup &pvl, const QString keyname="ModuleHistory") const
Record history in Pvl group object.
Definition: Module.h:134
QString PixelToString(double d)
Takes a double pixel value and returns the name of the pixel type as a string.
Definition: SpecialPixel.h:386
Isis exception class.
Definition: IException.h:107
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
QString getcsvFile() const
Returns expanded name of last CSV file loaded by loadCsv.
Definition: Module.h:86
int size() const
Returns the size (number of elements) of data array.
Definition: Module.h:88
TNT::Array1D< double > HiVector
1-D Buffer
Definition: HiCalTypes.h:40