source: branches/MarsFixTimeOffsetBranch/mfileio/MMatrix.h@ 18003

Last change on this file since 18003 was 18003, checked in by smueller, 10 years ago
A new generic floating point matrix container. It can parse data from a delimiter seperated text file. This is needed for the ticket #9
File size: 2.1 KB
Line 
1#ifndef MARS_MMatrix
2#define MARS_MMatrix
3
4#ifndef MARS_MParContainer
5#include "MParContainer.h"
6#endif
7
8#include <iostream> // std::cout
9#include <sstream>
10#include <fstream> // std::ifstream
11#include <iomanip>
12#include <algorithm>
13#include <cctype>
14#include <locale>
15#include "MLog.h"
16#include "MLogManip.h"
17
18class MMatrix : public MParContainer
19{
20public:
21 MMatrix(const char *name, const char *title);
22 ~MMatrix();
23
24 Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print=kFALSE);
25 void print()const;
26
27 // The floating point data stored in this object has an arbitrary number of
28 // rows and each row can have a unique number of floating numbers.
29 // M[row i][column j]
30 std::vector< std::vector< double > > fM;
31private:
32 // The deilimiter symbol which seperates the data chunks in the file to be
33 // parsed.
34 char fDelimiter = ',';
35
36 // The data text file to be parsed may have comment lines which are
37 // indicated with the comment character.
38 // Leading whitespaces in front of the comment symbol are fine/ are ignored.
39 char fComment = '#';
40
41 // The fFileName can only be set using ReadFile( filename ). This is to make
42 // sure that the fFileName is always the one of the actual file parsed in.
43 TString fFileName = "";
44
45 // the line number worked on is stored here by the ReadFile( fileneam )
46 // function so that other functions as the pedantic_strtod() can provide
47 // an additional information in case they have to throw exceptions.
48 unsigned int fLineNumber = 0;
49
50 // a more pedantic version of std::strtod()
51 double pedantic_strtod(std::string text)const;
52
53 // deleting all information stored in the Matrix fM
54 void clear();
55
56 // the text file parser
57 void ReadFile(const TString path_to_text_file );
58
59 // text parsing helpers
60 bool is_empty_or_has_only_white_spaces(std::string line)const;
61 bool is_comment(std::string line)const;
62 std::string remove_leading_white_spaces(std::string &s)const;
63 std::string remove_tailing_white_spaces(std::string &s)const;
64
65 ClassDef(MMatrix, 1) // generic parameter container with text file parser
66};
67
68#endif //MMatrix
Note: See TracBrowser for help on using the repository browser.