All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PSetUtils.cxx
Go to the documentation of this file.
1 #ifndef __PSET_UTILS_CXX__
2 #define __PSET_UTILS_CXX__
3 
4 #include "PSetUtils.h"
5 #include <sstream>
6 #include <fstream>
7 namespace flashmatch {
8 
9  std::string ConfigFile2String(std::string fname)
10  {
11  std::ifstream filestrm(fname.c_str());
12  std::string contents;
13  std::string line;
14 
15  while(std::getline(filestrm, line)) {
16 
17  if(line.empty()) continue;
18 
19  std::stringstream linestrm(line);
20  std::string valid_line;
21 
22  std::getline(linestrm, valid_line, '#');
23 
24  if(valid_line.empty()) continue;
25 
26  contents += " " + valid_line;
27  }
28  filestrm.close();
29  return contents;
30  }
31 
32  PSet CreatePSetFromFile(std::string fname,std::string cfg_name)
33  {
34  PSet res(cfg_name,ConfigFile2String(fname));
35  return res;
36  }
37 
38 }
39 
40 #endif
PSet CreatePSetFromFile(std::string fname, std::string cfg_name)
Given a configuration file (full path), create and return flashmatch::PSet.
Definition: PSetUtils.cxx:32
string fname
Definition: demo.py:5
std::string ConfigFile2String(std::string fname)
Given a configuration string, format to create flashmatch::PSet.
Definition: PSetUtils.cxx:9
Utility functions in Base/PSet.
A nested configuration parameter set holder for flashmatch framework.
Definition: PSet.h:26