Framework class for command line application. More...
#include <tsAppMain.h>
Inherited by myDataReductionApp.
Public Types | |
enum | dfm_t { DFM, HDR } |
Public Member Functions | |
virtual void | analyzeData (int argc, char *argv[]) |
virtual std::vector< measures > | process_file (dataFile &data, std::vector< lookupTable > &tables, std::string &fileName)=0 |
virtual double | getSampleTime (std::string fileName)=0 |
virtual int | getByteOrdering ()=0 |
virtual std::vector < TCLAP::SwitchArg > | additionalCmdLineSwitchArgs (void) |
virtual void | parseAdditionalCmdLineSwitchArgs (std::vector< TCLAP::SwitchArg > &switches) |
virtual std::vector< lookupTable > | getLookupTables (void) |
virtual std::string | getLabelFileName (void) |
virtual std::string | sharedDFM (void) |
virtual dfm_t | getDFMType (void) |
Framework class for command line application.
tsCmdLineApp provides a set of methods needed to realize a command-line data reduction application. The class is meant to work as part of a simple application skeleton. The skeleton is provided in the file tsCmdLineMain.cpp:
/* An command line application framework for data reduction using the timeSeries library */ #include "myDataReductionApp.h" using namespace std; #ifdef WIN32 int analysisMain (int argc, char * argv[]) #else int main (int argc, char * argv[]) #endif { tsCmdLineApp* app = new myDataReductionApp(); app->analyzeData(argc, argv); return 0; }
myDataReductionApp
. This derived class must provide definitions for at least three of the member functions:virtual std::vector<measures> process_file(dataFile& data, std::vector<lookupTable>& t, std::string& s)=0; virtual double getSampleTime(std::string)=0; virtual int getByteOrdering()=0;
USAGE: tsCmdLineApp [-n] [--] [-v] [-h] <filename> <filename> ... Where: -n, --new only process new files --, --ignore_rest Ignores the rest of the labeled arguments following this flag. -v, --version Displays version information and exits. -h, --help Displays usage information and exits. <filename> (required) (value required) binary data file name <filename> (accepted multiple times) (value required) additional binary data file names
.bin By default the framework expects that every
.bin file will have a corresponding hdr
or dfm
file. However, if the file format is the same for every data file a singled shared hdr
or dfm
file can be used.data
, the following unix-style commands can process an entire dataset:tsCmdLineApp data/*.bin cat labels.tit data/*.dat > measures.txt
Running in a DOS shell the equivalent commands look like:
tsCmdLineApp data\*.bin copy labels.tit+data\*.dat > measures.txt
measures.txt
file is a labeled, tab-delimited text file that can be imported into Excel, Minitab, Systat or any other statitical analysis code. Adding new data to the dataset is trivial. Just copy the new files into the data directory and use the -n option to suppress processing of files that already have a corrsponding
.dat file present:tsCmdLineApp -n data/*.bin cat labels.tit data/*.bin > measures.txt
enum tsCmdLineApp::dfm_t |
virtual std::vector<TCLAP::SwitchArg> tsCmdLineApp::additionalCmdLineSwitchArgs | ( | void | ) | [inline, virtual] |
specifies additional TCLAP switches
Example:
vector<SwitchArg> myDataReductionApp::additionalCmdLineSwitchArgs(void) { vector<SwitchArg> switches; SwitchArg printStates("s","states","print states",false); switches.push_back(printStates); return switches; }
void tsCmdLineApp::analyzeData | ( | int | argc, | |
char * | argv[] | |||
) | [virtual] |
data analysis main
argc | the number of command line arguments | |
argv | an array of command line parameters |
analyzeData processes the input data files using the following steps:
Exceptions generated by the timeSeries classes are handled as appropriate. analyzeData itself throws no exceptions.
Normally this method should not be overidden by the derived class. However, it is declared virtual in case you think otherwise.
virtual int tsCmdLineApp::getByteOrdering | ( | ) | [pure virtual] |
returns byte order
Another pure virtual function that must be defined in the derived class. This member specifies the byte-ordering used by the computer that created the binary data files. dataFile::BigEndian is appropriate for Motorola style processors such as the PowerPC. dataFile::LittleEndian is appropriate for Intel-style processors.
virtual dfm_t tsCmdLineApp::getDFMType | ( | void | ) | [inline, virtual] |
returns the data definition type
Determines the format of the data definition files. Currently this must be one of HDR for VIRTTEX .hdr file or DFM to specify the more general .dfm format.
The base class returns DFM so you must override this method to process VIRTTEX data.
virtual std::string tsCmdLineApp::getLabelFileName | ( | void | ) | [inline, virtual] |
returns the label file name
The base class define the label file name as "labels.tit" Override this method to change the name.
virtual std::vector<lookupTable> tsCmdLineApp::getLookupTables | ( | void | ) | [inline, virtual] |
reads lookup tables
The base class defines no tables. Override this method to read lookup table data.
Example:
vector<lookupTable> myDataReductionApp::getLookupTables(void) { string subjectTablePath="subject_data.txt"; lookupTable subjectTable(subjectTablePath,"Subject"); vector<lookupTable> tables; tables.push_back(subjectTable); return tables; }
virtual double tsCmdLineApp::getSampleTime | ( | std::string | fileName | ) | [pure virtual] |
defines the sample time in seconds
fileName | the name of the data file including the .bin extension |
Another pure virtual function that must be defined in the derived class. getSampleTime can simply return a constant or it can use the supplied filename to parse a header file or a lookuptable to find the sample time.
virtual void tsCmdLineApp::parseAdditionalCmdLineSwitchArgs | ( | std::vector< TCLAP::SwitchArg > & | switches | ) | [inline, virtual] |
parses additional TCLAP switches
switches | A vector of SwitchArg objects defined ty additionalCmdLineSwitchArgs |
This method is called immediately after the command line is parsed. It returns SwitchArg objects that can be queried to determine their state. The method should take any action required to implement the switches.
Example:
void myDataReductionApp::parseAdditionalCmdLineSwitchArgs(vector<SwitchArg>& switches) { SwitchArg printStates = switches[0]; setPrintState(printStates.getValue()); }
virtual std::vector<measures> tsCmdLineApp::process_file | ( | dataFile & | data, | |
std::vector< lookupTable > & | tables, | |||
std::string & | fileName | |||
) | [pure virtual] |
reduces the data
data | The data object representing the input file | |
tables | A vector of lookup tables for metadata | |
fileName | The input datafile name with .bin extension |
process_file is the major data reduction method. It is a pure virtual method and must be provided by the derived class. The simplest form of the method computes measures for the entire run with no metadata:
vector<measures> myDataReductionApp::process_file(dataFile& data, vector<lookupTable>& tables, string& fileName) { vector<measures> myMeasures; measures meas; timeSeries<float> speed("VMPH",data); meas.entry("speed",speed.mean()); meas.entry("max speed", speed[speed.max()]); myMeasures.push_back(meas); return myMeasures; }
Applications that require metadata tables can simply unpack them from the tables vector and use them as needed:
lookupTable& subjectTable = tables[0]; ostringstream subjectStr; subjectStr << subject; string gender = subjectTable.find<string>(subjectStr.str(),"Gender"); string ageGroup = subjectTable.find<string>(subjectStr.str(),"Age"); cout << "gender = " << gender << endl; cout << "age = " << ageGroup << endl;
When multiple performance intervals are present in the data, a measures object is computed for each one and the complete vector of measures is returned.
virtual std::string tsCmdLineApp::sharedDFM | ( | void | ) | [inline, virtual] |
returns the shared data definition
If sharedDFM returns a non-null file name, that file is parsed as either a valid hdr or dfm file based on the extension. The resulting data definition is then used to interpret all remaining binary files.
The basse class returns sharedDFM=="" which results in the application looking for either a .hdr or .dfm file corresponding to each binary data file.
Override this class if all of your data files have the same format and you wish to avoid re-parsing the data definition for each file.