8 #ifndef __QWPARAMETERFILE__
9 #define __QWPARAMETERFILE__
25 #include "TObjArray.h"
26 #include "TObjString.h"
31 #include "boost/lexical_cast.hpp"
32 #include "boost/filesystem/operations.hpp"
33 #include "boost/filesystem/convenience.hpp"
34 #include "boost/filesystem/path.hpp"
35 namespace bfs = boost::filesystem;
36 using boost::lexical_cast;
47 static UInt_t
GetUInt(
const TString &varvalue);
77 Bool_t status = kFALSE;
92 std::string tmpname, tmpvalue;
94 if (tmpname ==
"append") {
96 static int nested_depth = 0;
97 if (nested_depth++ > 5) {
98 std::cout <<
"Parameter file recursion not allowed!" << std::endl;
103 fStream << nested_file.rdbuf();
112 void TrimWhitespace(TString::EStripType head_tail = TString::kBoth);
126 std::string
GetNextToken(
const std::string& separatorchars);
130 template <
typename T>
143 Bool_t
HasVariablePair(
const std::string& separatorchars, std::string& varname, std::string& varvalue);
144 Bool_t
HasVariablePair(
const std::string& separatorchars, TString& varname, TString& varvalue);
146 Bool_t
FileHasVariablePair(
const std::string& separatorchars,
const std::string& varname, std::string& varvalue);
147 Bool_t
FileHasVariablePair(
const std::string& separatorchars,
const TString& varname, TString& varvalue);
213 template <
typename T>
218 retvalue = ConvertValue<T>(value);
222 template <
typename T>
223 Bool_t
PopValue(
const std::string keyname,
T &retvalue){
225 Bool_t status =
GetKeyValue(keyname, value, kTRUE);
227 retvalue = ConvertValue<T>(value);
235 void Trim(
const std::string& chars, std::string& token, TString::EStripType head_tail = TString::kBoth);
236 void TrimWhitespace(std::string &token, TString::EStripType head_tail);
240 template <
typename T>
243 if (value.size() == 0) {
246 std::istringstream stream1;
256 int FindFile(
const bfs::path& dir_path,
257 const std::string& file_stem,
258 const std::string& file_ext,
259 bfs::path& path_found);
262 bool OpenFile(
const bfs::path& path_found);
271 static std::pair<int,int>
ParseIntRange(
const std::string& separatorchars,
const std::string& range);
308 Bool_t
GetKeyValue(
const std::string keyname, std::string &retvalue,
309 Bool_t should_erase = kFALSE){
310 Bool_t status = kFALSE;
311 std::map<std::string,std::string>::iterator it;
315 retvalue = (*it).second;
364 inline std::string QwParameterFile::GetTypedNextToken<std::string>(){
365 return GetNextToken();
369 inline UInt_t QwParameterFile::ConvertValue<UInt_t>(
const std::string& value) {
370 return GetUInt(value);
374 inline std::string QwParameterFile::ConvertValue<std::string>(
const std::string& value) {
379 inline TString QwParameterFile::ConvertValue<TString>(
const std::string& value) {
380 return TString(value.c_str());
383 #endif // __QWPARAMETERFILE__
TString fBestParamFileName
const std::string fFilename
static void AppendToSearchPath(const TString &searchdir)
Add a directory to the search path.
std::stringstream fStream
Bool_t LineHasModuleHeader()
void SetCommentChars(const std::string value)
Set various sets of special characters.
const TString GetParamFilenameAndPath()
std::streambuf * rdbuf() const
Access the streambuf pointer in the same way as on a std::ifstream.
TString GetParameterFileContents()
Bool_t ReadNextLine(std::string &varvalue)
static UInt_t GetUInt(const TString &varvalue)
static const std::string kDefaultWhitespaceChars
friend std::ostream & operator<<(std::ostream &stream, const QwParameterFile &file)
Bool_t FileHasSectionHeader(const std::string &secname)
static const std::string kDefaultSectionChars
static void SetCurrentRunNumber(const UInt_t runnumber)
Set the current run number for looking up the appropriate parameter file.
std::string GetNextToken()
Bool_t HasVariablePair(const std::string &separatorchars, std::string &varname, std::string &varvalue)
std::string fCommentChars
Bool_t PopValue(const std::string keyname, T &retvalue)
const TString GetParamFilename()
static const std::string kDefaultTokenSepChars
std::map< std::string, std::string > fKeyValuePair
Bool_t ReturnValue(const std::string keyname, T &retvalue)
const std::pair< TString, TString > GetParamFileNameContents()
QwParameterFile * ReadNextSection(std::string &secname, const bool keep_header=false)
TString LastString(TString in, char *delim)
QwParameterFile * ReadNextModule(std::string &secname, bool keep_header=false)
Bool_t HasValue(TString &vname)
virtual ~QwParameterFile()
Bool_t FileHasModuleHeader(const std::string &secname)
A logfile class, based on an identical class in the Hermes analyzer.
void SetSectionChars(const std::string value)
size_t fCurrentPos
Internal line storage.
QwParameterFile * ReadUntilNextSection(const bool add_current_line=false)
void SetTokenSepChars(const std::string value)
Bool_t ReadNextLine_Single(std::string &varvalue)
QwParameterFile * ReadNextSection(const bool keep_header=false)
QwParameterFile * ReadNextModule(const bool keep_header=false)
std::string fSectionChars
static const double T
Magnetic field: base unit is T.
QwParameterFile(const QwParameterFile &input)
Bool_t GetKeyValue(const std::string keyname, std::string &retvalue, Bool_t should_erase=kFALSE)
Current position in the line.
static UInt_t fCurrentRunNumber
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.
void AddBreakpointKeyword(std::string keyname)
int FindFile(const bfs::path &dir_path, const std::string &file_stem, const std::string &file_ext, bfs::path &path_found)
Find the first file in a directory that conforms to the run label.
Bool_t FileHasVariablePair(const std::string &separatorchars, const std::string &varname, std::string &varvalue)
static const std::string kDefaultCommentChars
void SetWhitespaceChars(const std::string value)
Bool_t LineHasSectionHeader()
QwParameterFile * ReadSectionPreamble()
Rewinds to the start and read until it finds next section header.
static std::vector< bfs::path > fSearchPaths
std::string fTokenSepChars
T GetTypedNextToken()
Get next token into specific type.
std::set< std::string > fBreakpointWords
bool OpenFile(const bfs::path &path_found)
Open a file.
void TrimWhitespace(TString::EStripType head_tail=TString::kBoth)
static const std::string kDefaultModuleChars
Bool_t ReadNextLine_Greedy(std::string &varvalue)
QwParameterFile * ReadModulePreamble()
Rewinds to the start and read until it finds next module header.
TString fBestParamFileNameAndPath
std::string fWhitespaceChars
void SetModuleChars(const std::string value)
void AddLine(const std::string &line)
T ConvertValue(const std::string &value)
Convert string value into specific type.
QwParameterFile * ReadUntilNextModule(const bool add_current_line=false)
void Trim(const std::string &chars, std::string &token, TString::EStripType head_tail=TString::kBoth)
Bool_t SkipSection(std::string secname)
Skips from the beginning of the section 'secname' until the first section that does not have that nam...