00001
00002
00003 #include "PhysicsTools/StatPatternRecognition/interface/SprExperiment.hh"
00004 #include "PhysicsTools/StatPatternRecognition/interface/SprStringParser.hh"
00005
00006 #include <stdlib.h>
00007
00008 using namespace std;
00009
00010 void SprStringParser::parseToStrings(const char* input,
00011 std::vector<std::vector<std::string> >& output)
00012 {
00013
00014 string s = input;
00015 output.clear();
00016
00017
00018 vector<string> v;
00019 while( !s.empty() ) {
00020 string::size_type pos = s.find_first_of(':');
00021 string s1 = s.substr(0,pos);
00022 if( pos != string::npos )
00023 s = s.substr(pos+1);
00024 else
00025 s.clear();
00026 s1.erase( s1.find_last_not_of(' ') + 1 );
00027 s1.erase( 0, s1.find_first_not_of(' ') );
00028 v.push_back(s1);
00029 }
00030
00031
00032 output.resize(v.size());
00033 for( int i=0;i<v.size();i++ ) {
00034 s = v[i];
00035 while( !s.empty() ) {
00036 string::size_type pos = s.find_first_of(',');
00037 string s1 = s.substr(0,pos);
00038 if( pos != string::npos )
00039 s = s.substr(pos+1);
00040 else
00041 s.clear();
00042 s1.erase( s1.find_last_not_of(' ') + 1 );
00043 s1.erase( 0, s1.find_first_not_of(' ') );
00044 output[i].push_back(s1);
00045 }
00046 }
00047 }
00048
00049
00050 void SprStringParser::parseToInts(const char* input,
00051 std::vector<std::vector<int> >& output)
00052 {
00053 output.clear();
00054 vector<vector<string> > str_output;
00055 SprStringParser::parseToStrings(input,str_output);
00056 output.resize(str_output.size());
00057 for( int i=0;i<str_output.size();i++ ) {
00058 output[i].resize(str_output[i].size());
00059 for( int j=0;j<str_output[i].size();j++ ) {
00060 output[i][j] = atoi(str_output[i][j].c_str());
00061 }
00062 }
00063 }
00064
00065
00066 void SprStringParser::parseToDoubles(const char* input,
00067 std::vector<std::vector<double> >& output)
00068 {
00069 output.clear();
00070 vector<vector<string> > str_output;
00071 SprStringParser::parseToStrings(input,str_output);
00072 output.resize(str_output.size());
00073 for( int i=0;i<str_output.size();i++ ) {
00074 output[i].resize(str_output[i].size());
00075 for( int j=0;j<str_output[i].size();j++ ) {
00076 output[i][j] = atof(str_output[i][j].c_str());
00077 }
00078 }
00079 }