HiRISE
 Observation

Data_Component.hh
Go to the documentation of this file.
1 /* HiRISE Data Component
2 
3 PIRL CVS ID: Data_Component.hh,v 1.38 2020/02/14 01:17:18 schaller Exp
4 
5 Copyright (C) 2004-2020 Arizona Board of Regents on behalf of the Lunar and
6 Planetary Laboratory at the University of Arizona.
7 
8 Licensed under the Apache License, Version 2.0 (the "License"); you may not use
9 this file except in compliance with the License. You may obtain a copy of the
10 License at
11 
12  http://www.apache.org/licenses/LICENSE-2.0
13 
14 Unless required by applicable law or agreed to in writing, software distributed
15 under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
16 CONDITIONS OF ANY KIND, either express or implied. See the License for the
17 specific language governing permissions and limitations under the License.
18 */
19 
20 #ifndef _HiRISE_Data_Component_
21 #define _HiRISE_Data_Component_
22 
23 #include "Instrument.hh"
24 
25 // PIRL
26 #include "Data_Block.hh"
27 
28 #if defined (INCLUDE_PVL)
29 // idaeim::PVL
30 #include "PVL.hh"
31 #endif
32 
33 #include <iostream>
34 #include <string>
35 #include <vector>
36 
38 namespace UA
39 {
41 namespace HiRISE
42 {
43 /*==============================================================================
44  Types
45 */
46 #ifndef INT_8_TYPE
47 #define INT_8_TYPE char
48 #endif
50 typedef INT_8_TYPE int_8;
51 
52 #ifndef U_INT_8_TYPE
53 #define U_INT_8_TYPE unsigned char
54 #endif
57 
58 #ifndef INT_16_TYPE
59 #define INT_16_TYPE short int
60 #endif
63 
64 #ifndef U_INT_16_TYPE
65 #define U_INT_16_TYPE unsigned short int
66 #endif
69 
70 #ifndef INT_32_TYPE
71 #define INT_32_TYPE int
72 #endif
75 
76 #ifndef U_INT_32_TYPE
77 #define U_INT_32_TYPE unsigned int
78 #endif
81 
82 #ifndef INT_64_TYPE
83 #define INT_64_TYPE long int
84 #endif
87 
88 #ifndef U_INT_64_TYPE
89 #define U_INT_64_TYPE unsigned long int
90 #endif
93 
96 
99 
100 /*******************************************************************************
101  Data_Component
102 */
122 : public Instrument,
123  public PIRL::Data_Block
124 {
125 public:
126 /*==============================================================================
127  Constants:
128 */
130 static const char* const
131  ID;
132 
137 static const int
141 
143 static const char
145 
147 static const int
149 
151 static const char
153 
154 #if defined (INCLUDE_CSPICE)
161 static const char* const
163 
165 static const char* const
167 
169 static const int
171 
172 #endif // INCLUDE_SPICE
173 
174 static const char* const
176 
177 /*==============================================================================
178  Constructors
179 */
201  (
202  const char** names = NULL,
203  unsigned int size = 0,
204  const Index* offsets = NULL,
205  const Index indexed_arrays[][2] = NULL,
206  Data_Order order = Data_Block::MSB
207  );
208 
227 Data_Component (const Data_Component& component, bool data_duplicate = true);
228 
243 Data_Component& operator= (const Data_Component& component);
244 
252 virtual ~Data_Component ();
253 
254 /*==============================================================================
255  Accessors
256 */
267 virtual std::string id () const;
268 
276 virtual const char* name () const = 0;
277 
285 const char* name (Index element) const;
286 
296 virtual u_int_32 get (Index element, Index index = 0) const;
297 
308 virtual Data_Component& put
309  (const u_int_32 value, Index element, Index index = 0);
310 
311 #if defined (INCLUDE_PVL)
312 /*==============================================================================
313  PVL
314 */
323 virtual idaeim::PVL::Aggregate* PVL () const = 0;
324 
325 #endif // defined (INCLUDE_PVL)
326 
327 /*==============================================================================
328  Printing
329 */
353 virtual std::ostream& print
354  (std::ostream& stream = std::cout, bool verbose = false) const = 0;
355 
370 std::ostream& print_element (const Index element, int format = DECIMAL,
371  std::ostream& stream = std::cout, int width = 0) const;
372 
382 std::ostream& print_element (const Index element, std::ostream& stream) const
383  {return print_element (element, DECIMAL, stream, 0);}
384 
415 std::ostream& print_element_location (const Index element,
416  std::ostream& stream = std::cout) const;
417 
432 unsigned int element_location_print_width (Index element) const;
433 
439 unsigned int name_field_width () const;
440 
462 Data_Component& name_field_width (unsigned int width);
463 
464 /*==============================================================================
465  Validation
466 */
471 virtual bool is_valid () const = 0;
472 
473 /*------------------------------------------------------------------------------
474  Data
475 */
501 Data_Block& data (void* const block);
502 
523 Data_Block& attach (void* const block, unsigned int size);
524 
539 Data_Component& resize (unsigned int size);
540 
546 unsigned char* data () const
547  {return PIRL::Data_Block::data ();}
548 
556 unsigned int local_data ()
557  {return Local_Data;}
558 
598 u_int_16 internet_checksum () const;
599 
600 //..............................................................................
601 private:
602 
604 unsigned int
605  Local_Data;
606 
608 const char**
609  Names;
610 
612 unsigned int
613  Max_Name_Length;
614 
616 unsigned int
617  Name_Field_Width;
618 
619 }; // class Data_Component
620 
621 
622 /*==============================================================================
623  Output operator
624 */
632 std::ostream& operator<<
633  (std::ostream& stream, const Data_Component& component);
634 
635 /*******************************************************************************
636  Helpers
637 */
666 std::ostream& print_value (u_int_32 value, int format = Data_Component::DECIMAL,
667  std::ostream& stream = std::cout, int width = 0);
668 
669 #if defined (INCLUDE_PVL)
670 /*------------------------------------------------------------------------------
671  PVL
672 */
675  {
679  };
680 
717  (
718  idaeim::PVL::Aggregate& aggregate,
719  std::string pathname,
720  bool case_sensitive = false,
721  int skip = 0,
722  Parameter_Class_Selection parameter_class = ANY_PARAMETER
723  );
724 
744 std::vector<std::string>
746  (
747  idaeim::PVL::Aggregate& aggregate,
748  std::string pathname,
749  bool case_sensitive = false,
750  int skip = 0
751  );
752 
769 bool
770 PVL_value
771  (
772  idaeim::PVL::Aggregate& aggregate,
773  std::string pathname,
774  unsigned int value,
775  bool case_sensitive = false,
776  int skip = 0
777  );
778 
779 bool
780 PVL_value
781  (
782  idaeim::PVL::Aggregate& aggregate,
783  std::string pathname,
784  int value,
785  bool case_sensitive = false,
786  int skip = 0
787  );
788 
805 bool
806 PVL_value
807  (
808  idaeim::PVL::Aggregate& aggregate,
809  std::string pathname,
810  const std::string& value,
811  bool case_sensitive = false,
812  int skip = 0
813  );
814 
815 #endif // defined (INCLUDE_PVL)
816 
817 /*------------------------------------------------------------------------------
818  Time
819 */
873 std::string UTC_time
874  (double seconds, unsigned int epoch = Instrument::SPACECRAFT_EPOCH);
875 
876 
879  {
881  MRO_Clock
882  };
883 
905 std::string clock_count (double seconds, Clock_Selector clock = HiRISE_Clock);
906 
915 double seconds
916  (const std::string& clock_count, Clock_Selector clock = HiRISE_Clock);
917 
918 /*------------------------------------------------------------------------------
919  Files
920 */
926 bool file_exists (const std::string& filename);
927 
942 std::string pathname (const std::string& filename = "");
943 
956 std::string pathname
957  (
958  const std::string& directory,
959  const std::string& filename,
960  const std::string& extension
961  );
962 
972 std::string filename (const std::string& pathname);
973 
974 /*------------------------------------------------------------------------------
975  Stringy thingies
976 */
991 std::string bits (const unsigned int value, unsigned int count = 0);
992 
1000 unsigned int max_strlen (const char** strings);
1001 
1008 std::string to_upper (const std::string& characters);
1009 
1022 std::string shift (std::string lines, int amount);
1023 
1039 std::string plural (int count);
1040 
1041 /*------------------------------------------------------------------------------
1042  Miscellaneous
1043 */
1048 std::string hostname ();
1049 
1059 bool member_of
1060  (const unsigned int value, const unsigned int *array, int size);
1061 
1071 bool member_of
1072  (const char* const value, const char* const array[], int size);
1073 
1074 
1075 } // namespace HiRISE
1076 } // namespace UA
1077 #endif
#define INT_64_TYPE
Definition: Data_Component.hh:83
#define INT_16_TYPE
Definition: Data_Component.hh:59
#define U_INT_64_TYPE
Definition: Data_Component.hh:89
#define U_INT_8_TYPE
Definition: Data_Component.hh:53
#define U_INT_16_TYPE
Definition: Data_Component.hh:65
#define INT_32_TYPE
Definition: Data_Component.hh:71
#define INT_8_TYPE
Definition: Data_Component.hh:47
#define U_INT_32_TYPE
Definition: Data_Component.hh:77
unsigned char * data() const
unsigned int Index
Index size() const
A Data_Component provides a common, virtual interface for all HiRISE Observation data blocks.
Definition: Data_Component.hh:124
static const char *const INVALID_UTC_TIME
Definition: Data_Component.hh:175
u_int_16 internet_checksum() const
Calculates the Internet Checksum as per RFC 1071.
Definition: Data_Component.cc:503
static const int HEX
Definition: Data_Component.hh:139
Data_Component & operator=(const Data_Component &component)
Assignment operator.
Definition: Data_Component.cc:232
unsigned int local_data()
Gets the size of the local data storage area.
Definition: Data_Component.hh:556
unsigned int element_location_print_width(Index element) const
Gets the width of the Element location printing fields.
Definition: Data_Component.cc:383
static const int MRO_CLOCK_ID
The ID used by NAIF for specifying the MRO clock to CSPICE routines.
Definition: Data_Component.hh:170
virtual const char * name() const =0
Gets the name of the component.
virtual u_int_32 get(Index element, Index index=0) const
Gets a value from a data Element or array entry of the component.
Definition: Data_Component.cc:286
virtual bool is_valid() const =0
Tests if the component data is valid.
static const char PATHNAME_DELIMITER
Host filesystem pathname delimiter.
Definition: Data_Component.hh:144
virtual std::string id() const
Gets the identification of this component.
Definition: Data_Component.cc:269
std::ostream & print_element(const Index element, int format=DECIMAL, std::ostream &stream=std::cout, int width=0) const
Prints an Element description.
Definition: Data_Component.cc:354
virtual ~Data_Component()
Destructor.
Definition: Data_Component.cc:258
static const int DECIMAL
Format specifier.
Definition: Data_Component.hh:138
virtual idaeim::PVL::Aggregate * PVL() const =0
Produces an exhausitive PVL (Parameter Value Language) rendition of the component contents.
static const char SUBSECONDS_DELIMITER
Delimits subseconds from seconds in clock count representations.
Definition: Data_Component.hh:152
unsigned char * data() const
Gets a pointer to the current component storage.
Definition: Data_Component.hh:546
Data_Component(const char **names=NULL, unsigned int size=0, const Index *offsets=NULL, const Index indexed_arrays[][2]=NULL, Data_Order order=Data_Block::MSB)
Constructs a Data_Component using component specifications.
Definition: Data_Component.cc:179
static const char *const SPICE_METAKERNEL_VARIABLE
The name of the environment variable for the SPICE metakernel pathname.
Definition: Data_Component.hh:162
static const int UTC_SECONDS_PRECISION
UTC seconds precision (digits after the decimal point).
Definition: Data_Component.hh:148
std::ostream & print_element(const Index element, std::ostream &stream) const
Prints an Element description.
Definition: Data_Component.hh:382
Data_Block & attach(void *const block, unsigned int size)
Attaches a new block of data to the component.
Definition: Data_Component.cc:428
static const char *const DEFAULT_SPICE_METAKERNEL
The default SPICE metakernal pathname.
Definition: Data_Component.hh:166
std::ostream & print_element_location(const Index element, std::ostream &stream=std::cout) const
Prints the location of an Element in the component.
Definition: Data_Component.cc:325
virtual std::ostream & print(std::ostream &stream=std::cout, bool verbose=false) const =0
Prints a detailed description of the component structure and contents.
virtual Data_Component & put(const u_int_32 value, Index element, Index index=0)
Puts a value into a data Element or array entry of the component.
Definition: Data_Component.cc:295
unsigned int name_field_width() const
Gets the width of the Element name printing field.
Definition: Data_Component.cc:306
Data_Component & resize(unsigned int size)
Resizes the block of local data storage.
Definition: Data_Component.cc:465
static const int BOOLEAN
Definition: Data_Component.hh:140
static const char *const ID
Class identification name with source code version and date.
Definition: Data_Component.hh:131
static const unsigned int SPACECRAFT_EPOCH
INT_8_TYPE int_8
8-bit integer type.
Definition: Data_Component.hh:50
U_INT_16_TYPE u_int_16
16-bit unsigned integer type.
Definition: Data_Component.hh:68
Parameter_Class_Selection
Selects the class of parameter for PVL_parameter to find.
Definition: Data_Component.hh:675
@ ASSIGNMENT_PARAMETER
Definition: Data_Component.hh:678
@ AGGREGATE_PARAMETER
Definition: Data_Component.hh:676
@ ANY_PARAMETER
Definition: Data_Component.hh:677
string shift(std::string lines, int amount)
Shifts (indents) lines of text by the specified number of spaces.
Definition: Data_Component.cc:1209
string plural(int count)
Gets a pluralization string.
Definition: Data_Component.cc:1238
string bits(const unsigned int value, unsigned int count)
Gets the string representation of a value in binary.
Definition: Data_Component.cc:591
unsigned int u_int_32
unsigned int max_strlen(const char **strings)
Finds the length of the longest string in the list.
Definition: Data_Component.cc:617
U_INT_8_TYPE u_int_8
8-bit unsigned integer type.
Definition: Data_Component.hh:56
Parameter * PVL_parameter(idaeim::PVL::Aggregate &aggregate, std::string pathname, bool case_sensitive, int skip, Parameter_Class_Selection parameter_class)
Gets a named PVL Parameter in an aggregate.
Definition: Data_Component.cc:651
string hostname()
Gets the name of the host system.
Definition: Data_Component.cc:1109
INT_32_TYPE int_32
32-bit integer type.
Definition: Data_Component.hh:74
PIRL::Data_Block::Index Index
Data_Block element index type.
Definition: Data_Component.hh:95
std::ostream & print_value(u_int_32 value, int format, std::ostream &stream, int width)
Prints a value in a consistent Data_Component format.
Definition: Data_Component.cc:534
U_INT_64_TYPE u_int_64
64-bit unsigned integer type.
Definition: Data_Component.hh:92
double seconds(const std::string &clock_count, Clock_Selector clock)
Converts a clock count representation to time in seconds.
Definition: Data_Component.cc:1021
Clock_Selector
Used to select a clock.
Definition: Data_Component.hh:879
@ HiRISE_Clock
Definition: Data_Component.hh:880
@ MRO_Clock
Definition: Data_Component.hh:881
std::vector< std::string > PVL_values(idaeim::PVL::Aggregate &aggregate, std::string pathname, bool case_sensitive, int skip)
Gets the values of a named PVL Parameter in an aggregate.
Definition: Data_Component.cc:704
string UTC_time(double seconds, unsigned int epoch)
Converts time in seconds to UTC representation.
Definition: Data_Component.cc:859
INT_16_TYPE int_16
16-bit integer type.
Definition: Data_Component.hh:62
string filename(const std::string &pathname)
Gets the filename portion of a pathname.
Definition: Data_Component.cc:1193
u_int_16 Pixel_type
The type of a generic pixel value.
Definition: Data_Component.hh:98
bool file_exists(const std::string &filename)
Tests if a file exists.
Definition: Data_Component.cc:1120
bool member_of(const unsigned int value, const unsigned int *array, int size)
Tests if a value is a member of an array.
Definition: Data_Component.cc:1079
std::string to_upper(const std::string &characters)
Converts all characters of a string to uppercase.
Definition: Data_Component.cc:634
string pathname(const std::string &filename)
Gets a fully qualified pathname for a filename.
Definition: Data_Component.cc:1132
bool PVL_value(idaeim::PVL::Aggregate &aggregate, std::string pathname, unsigned int value, bool case_sensitive, int skip)
Sets the value of a named PVL parameter in an aggregate.
Definition: Data_Component.cc:741
INT_64_TYPE int_64
64-bit integer type.
Definition: Data_Component.hh:86
string clock_count(double seconds, Clock_Selector clock)
Converts time in seconds to clock count representation.
Definition: Data_Component.cc:989
University of Arizona.