20namespace fs = std::filesystem;
27#include "TObjString.h"
32#include "boost/lexical_cast.hpp"
33using boost::lexical_cast;
53 static UInt_t
GetUInt(
const TString &varvalue);
83 Bool_t status = kFALSE;
98 std::string tmpname, tmpvalue;
100 if (tmpname ==
"append") {
102 static int nested_depth = 0;
103 if (nested_depth++ > 5) {
104 std::cout <<
"Parameter file recursion not allowed!" << std::endl;
118 void TrimWhitespace(TString::EStripType head_tail = TString::kBoth);
132 std::string
GetNextToken(
const std::string& separatorchars);
136 template <
typename T>
149 Bool_t
HasVariablePair(
const std::string& separatorchars, std::string& varname, std::string& varvalue);
150 Bool_t
HasVariablePair(
const std::string& separatorchars, TString& varname, TString& varvalue);
152 Bool_t
FileHasVariablePair(
const std::string& separatorchars,
const std::string& varname, std::string& varvalue);
153 Bool_t
FileHasVariablePair(
const std::string& separatorchars,
const TString& varname, TString& varvalue);
154 template <
typename T>
156 std::string strvalue;
186 std::unique_ptr<QwParameterFile>
ReadNextSection(std::string &secname,
const bool keep_header =
false);
187 std::unique_ptr<QwParameterFile>
ReadNextSection(TString &secname,
const bool keep_header =
false);
196 std::unique_ptr<QwParameterFile>
ReadNextModule(std::string &secname,
const bool keep_header =
false);
197 std::unique_ptr<QwParameterFile>
ReadNextModule(TString &secname,
const bool keep_header =
false);
198 std::unique_ptr<QwParameterFile>
ReadNextModule(
const bool keep_header =
false) {
228 template <
typename T>
237 template <
typename T>
238 Bool_t
PopValue(
const std::string keyname, T &retvalue){
240 Bool_t status =
GetKeyValue(keyname, value, kTRUE);
250 void Trim(
const std::string& chars, std::string& token, TString::EStripType head_tail = TString::kBoth);
251 void TrimWhitespace(std::string &token, TString::EStripType head_tail);
255 template <
typename T>
258 if (value.size() == 0) {
261 std::istringstream stream1;
271 int FindFile(
const fs::path& dir_path,
272 const std::string& file_stem,
273 const std::string& file_ext,
274 fs::path& path_found);
277 bool OpenFile(
const fs::path& path_found);
286 static std::pair<int,int>
ParseIntRange(
const std::string& separatorchars,
const std::string& range);
289 static int ParseInt(
const std::string& value);
325 Bool_t
GetKeyValue(
const std::string keyname, std::string &retvalue,
326 Bool_t should_erase = kFALSE){
327 Bool_t status = kFALSE;
328 std::map<std::string,std::string>::iterator it;
332 retvalue = (*it).second;
382 return GetNextToken();
398 std::string str(value);
399 std::transform(str.begin(), str.end(), str.begin(), ::tolower);
400 std::istringstream stream1(str);
402 stream1 >> std::boolalpha >> retvalue;
410 return TString(value.c_str());
A logfile class, based on an identical class in the Hermes analyzer.
Configuration file parser with flexible tokenization and search capabilities.
size_t fCurrentPos
Internal line storage.
Bool_t LineHasSectionHeader()
void SetWhitespaceChars(const std::string value)
const TString GetParamFilenameAndPath()
static const std::string kDefaultWhitespaceChars
const TString GetParamFilename()
void SetTokenSepChars(const std::string value)
Bool_t ReadNextLine_Single(std::string &varvalue)
std::string GetNextToken()
std::map< std::string, std::string > fKeyValuePair
std::unique_ptr< QwParameterFile > ReadNextSection(const bool keep_header=false)
static int ParseInt(const std::string &value)
Parse an integer as #[kM] with optional metric scale factor.
std::stringstream fStream
static const std::string kDefaultTokenSepChars
Bool_t LineHasModuleHeader()
static void AppendToSearchPath(const TString &searchdir)
Add a directory to the search path.
T GetTypedNextToken()
Get next token into specific type.
TString GetParameterFileContents()
bool OpenFile(const fs::path &path_found)
Open a file.
virtual ~QwParameterFile()
TString fBestParamFileName
Bool_t HasValue(TString &vname)
void SetModuleChars(const std::string value)
std::unique_ptr< QwParameterFile > ReadUntilNextModule(const bool add_current_line=false)
static void SetCurrentRunNumber(const UInt_t runnumber)
Set the current run number for looking up the appropriate parameter file.
Bool_t PopValue(const std::string keyname, T &retvalue)
static const std::string kDefaultSectionChars
QwParameterFile(const QwParameterFile &input)
Bool_t ReadNextLine_Greedy(std::string &varvalue)
std::unique_ptr< QwParameterFile > ReadNextModule(std::string &secname, const bool keep_header=false)
void SetSectionChars(const std::string value)
Bool_t FileHasSectionHeader(const std::string &secname)
void TrimWhitespace(TString::EStripType head_tail=TString::kBoth)
Bool_t HasVariablePair(const std::string &separatorchars, std::string &varname, std::string &varvalue)
std::set< std::string > fBreakpointWords
int FindFile(const fs::path &dir_path, const std::string &file_stem, const std::string &file_ext, fs::path &path_found)
Find the first file in a directory that conforms to the run label.
void SetCommentChars(const std::string value)
Set various sets of special characters.
TString LastString(TString in, char *delim)
std::streambuf * rdbuf() const
Access the streambuf pointer in the same way as on a std::ifstream.
Bool_t SkipSection(std::string secname)
Skips from the beginning of the section 'secname' until the first section that does not have that nam...
void AddLine(const std::string &line)
static std::pair< int, int > ParseIntRange(const std::string &separatorchars, const std::string &range)
Parse a range of integers as #:# where either can be missing.
std::string fSectionChars
std::string fWhitespaceChars
void AddBreakpointKeyword(std::string keyname)
QwParameterFile(const std::string &filename)
static UInt_t fCurrentRunNumber
static const std::string kDefaultCommentChars
TString fBestParamFileNameAndPath
static UInt_t GetUInt(const TString &varvalue)
const std::pair< TString, TString > GetParamFileNameContents()
friend std::ostream & operator<<(std::ostream &stream, const QwParameterFile &file)
Bool_t FileHasModuleHeader(const std::string &secname)
std::string fTokenSepChars
const std::string fFilename
std::unique_ptr< QwParameterFile > ReadModulePreamble()
Rewinds to the start and read until it finds next module header.
std::unique_ptr< QwParameterFile > ReadNextModule(const bool keep_header=false)
Bool_t FileHasVariablePair(const std::string &separatorchars, const std::string &varname, T &varvalue)
Bool_t ReadNextLine(std::string &varvalue)
void Trim(const std::string &chars, std::string &token, TString::EStripType head_tail=TString::kBoth)
std::string fCommentChars
std::unique_ptr< QwParameterFile > ReadUntilNextSection(const bool add_current_line=false)
Bool_t ReturnValue(const std::string keyname, T &retvalue)
T ConvertValue(const std::string &value)
Convert string value into specific type.
Bool_t GetKeyValue(const std::string keyname, std::string &retvalue, Bool_t should_erase=kFALSE)
Current position in the line.
static const std::string kDefaultModuleChars
std::unique_ptr< QwParameterFile > ReadSectionPreamble()
Rewinds to the start and read until it finds next section header.
Bool_t FileHasVariablePair(const std::string &separatorchars, const std::string &varname, std::string &varvalue)
static std::vector< fs::path > fSearchPaths
std::unique_ptr< QwParameterFile > ReadNextSection(std::string &secname, const bool keep_header=false)