QwAnalysis
QwParameterFile Class Reference

#include <QwParameterFile.h>

Public Member Functions

 QwParameterFile (const std::string &filename)
 
 QwParameterFile (const std::stringstream &stream)
 
virtual ~QwParameterFile ()
 
std::streambuf * rdbuf () const
 Access the streambuf pointer in the same way as on a std::ifstream. More...
 
void SetCommentChars (const std::string value)
 Set various sets of special characters. More...
 
void SetWhitespaceChars (const std::string value)
 
void SetTokenSepChars (const std::string value)
 
void SetSectionChars (const std::string value)
 
void SetModuleChars (const std::string value)
 
Bool_t ReadNextLine ()
 
Bool_t ReadNextLine (std::string &varvalue)
 
Bool_t ReadNextLine_Greedy (std::string &varvalue)
 
Bool_t ReadNextLine_Single (std::string &varvalue)
 
void TrimWhitespace (TString::EStripType head_tail=TString::kBoth)
 
void TrimComment (const char commentchar)
 
void TrimComment (const std::string &commentchars)
 
void TrimComment ()
 
void TrimSectionHeader ()
 
void TrimModuleHeader ()
 
TString LastString (TString in, char *delim)
 
TString GetParameterFileContents ()
 
Bool_t LineIsEmpty ()
 
Bool_t IsEOF ()
 
std::string GetNextToken (const std::string &separatorchars)
 Get next token as a string. More...
 
std::string GetNextToken ()
 
template<typename T >
GetTypedNextToken ()
 Get next token into specific type. More...
 
std::string GetLine ()
 
void AddLine (const std::string &line)
 
void RewindToFileStart ()
 
void RewindToLineStart ()
 
Bool_t HasValue (TString &vname)
 
Bool_t HasVariablePair (const std::string &separatorchars, std::string &varname, std::string &varvalue)
 
Bool_t HasVariablePair (const std::string &separatorchars, TString &varname, TString &varvalue)
 
Bool_t FileHasVariablePair (const std::string &separatorchars, const std::string &varname, std::string &varvalue)
 
Bool_t FileHasVariablePair (const std::string &separatorchars, const TString &varname, TString &varvalue)
 
Bool_t LineHasSectionHeader ()
 
Bool_t LineHasSectionHeader (std::string &secname)
 
Bool_t LineHasSectionHeader (TString &secname)
 
Bool_t LineHasModuleHeader ()
 
Bool_t LineHasModuleHeader (std::string &secname)
 
Bool_t LineHasModuleHeader (TString &secname)
 
Bool_t FileHasSectionHeader (const std::string &secname)
 
Bool_t FileHasSectionHeader (const TString &secname)
 
Bool_t FileHasModuleHeader (const std::string &secname)
 
Bool_t FileHasModuleHeader (const TString &secname)
 
Bool_t SkipSection (std::string secname)
 Skips from the beginning of the section 'secname' until the first section that does not have that name. More...
 
QwParameterFileReadSectionPreamble ()
 Rewinds to the start and read until it finds next section header. More...
 
QwParameterFileReadUntilNextSection (const bool add_current_line=false)
 
QwParameterFileReadNextSection (std::string &secname, const bool keep_header=false)
 
QwParameterFileReadNextSection (TString &secname, const bool keep_header=false)
 
QwParameterFileReadNextSection (const bool keep_header=false)
 
QwParameterFileReadModulePreamble ()
 Rewinds to the start and read until it finds next module header. More...
 
QwParameterFileReadUntilNextModule (const bool add_current_line=false)
 
QwParameterFileReadNextModule (std::string &secname, bool keep_header=false)
 
QwParameterFileReadNextModule (TString &secname, bool keep_header=false)
 
QwParameterFileReadNextModule (const bool keep_header=false)
 
const TString GetParamFilename ()
 
const TString GetParamFilenameAndPath ()
 
const std::pair< TString, TString > GetParamFileNameContents ()
 
void SetParamFilename ()
 
void EnableGreediness ()
 
void DisableGreediness ()
 
void AddBreakpointKeyword (std::string keyname)
 
void Close ()
 
Bool_t HasNewPairs ()
 
template<typename T >
Bool_t ReturnValue (const std::string keyname, T &retvalue)
 
template<typename T >
Bool_t PopValue (const std::string keyname, T &retvalue)
 
template<typename T >
ConvertValue (const std::string &value)
 Convert string value into specific type. More...
 
template<>
UInt_t ConvertValue (const std::string &value)
 
template<>
TString ConvertValue (const std::string &value)
 

Static Public Member Functions

static UInt_t GetUInt (const TString &varvalue)
 
static void AppendToSearchPath (const TString &searchdir)
 Add a directory to the search path. More...
 
static void SetCurrentRunNumber (const UInt_t runnumber)
 Set the current run number for looking up the appropriate parameter file. More...
 
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. More...
 

Protected Member Functions

void Trim (const std::string &chars, std::string &token, TString::EStripType head_tail=TString::kBoth)
 
void TrimWhitespace (std::string &token, TString::EStripType head_tail)
 
Bool_t GetKeyValue (const std::string keyname, std::string &retvalue, Bool_t should_erase=kFALSE)
 Current position in the line. More...
 

Protected Attributes

std::string fCommentChars
 
std::string fWhitespaceChars
 
std::string fTokenSepChars
 
std::string fSectionChars
 
std::string fModuleChars
 
const std::string fFilename
 
std::ifstream fFile
 
std::stringstream fStream
 
std::string fLine
 
size_t fCurrentPos
 Internal line storage. More...
 
Bool_t fBeGreedy
 
std::set< std::string > fBreakpointWords
 
std::map< std::string,
std::string > 
fKeyValuePair
 
Bool_t fHasNewPairs
 

Static Protected Attributes

static std::vector< bfs::path > fSearchPaths
 
static UInt_t fCurrentRunNumber = 0
 
static const std::string kDefaultCommentChars = "#!;"
 
static const std::string kDefaultWhitespaceChars = " \t\r"
 
static const std::string kDefaultTokenSepChars = ", \t"
 
static const std::string kDefaultSectionChars = "[]"
 
static const std::string kDefaultModuleChars = "<>"
 

Private Member Functions

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. More...
 
bool OpenFile (const bfs::path &path_found)
 Open a file. More...
 
 QwParameterFile ()
 
 QwParameterFile (const QwParameterFile &input)
 
void SetEOF ()
 

Private Attributes

TString fBestParamFileName
 
TString fBestParamFileNameAndPath
 

Friends

std::ostream & operator<< (std::ostream &stream, const QwParameterFile &file)
 

Detailed Description

Definition at line 43 of file QwParameterFile.h.

Constructor & Destructor Documentation

QwParameterFile::QwParameterFile ( const std::string &  name)

Constructor

Parameters
nameName of the file to be opened

If file starts with an explicit slash ('/'), it is assumed to be a full path.

Definition at line 111 of file QwParameterFile.cc.

References QwLog::endl(), FindFile(), fSearchPaths, Qw::kGreen, Qw::kNormal, OpenFile(), QwError, QwMessage, QwWarning, and SetEOF().

117  fFilename(name),
118  fBeGreedy(kFALSE)
119 {
120  // Create a file from the name
121  bfs::path file(name);
122 
123  // Immediately try to open absolute paths and return
124  if (name.find("/") == 0) {
125  if (OpenFile(file) == false) {
126  QwWarning << "Could not open absolute path " << name << ". "
127  << "Parameter file will remain empty." << QwLog::endl;
128  SetEOF();
129  return;
130  }
131 
132  // Print file name of file that was used
133  QwMessage << "Parameter file: "
134  << QwColor(Qw::kGreen) << file.string()
136 
137  // Else, loop through search path and files
138  } else {
139 
140 #if BOOST_VERSION >= 104600
141  // Separate file in stem and extension
142  std::string file_stem = file.stem().string();
143  std::string file_ext = file.extension().string();
144 #elif BOOST_VERSION >= 103600
145  // Separate file in stem and extension
146  std::string file_stem = file.stem();
147  std::string file_ext = file.extension();
148 #else
149  // Separate file in stem and extension
150  std::string file_stem = bfs::basename(file);
151  std::string file_ext = bfs::extension(file);
152 #endif
153 
154  // Find the best match
155  Int_t best_score = 0;
156  bfs::path best_path;
157  for (size_t i = 0; i < fSearchPaths.size(); i++) {
158 
159  bfs::path path;
160  Int_t score = FindFile(fSearchPaths[i], file_stem, file_ext, path);
161  if (score > best_score) {
162  // Found file with better score
163  best_score = score;
164  best_path = path;
165  } else if (score == best_score) {
166  // Found file with identical score
167  QwWarning << "Equally likely parameter files encountered: " << best_path.string()
168  << " and " << path.string() << QwLog::endl;
169  QwMessage << "Analysis will use parameter file: " << best_path.string()
170  << QwLog::endl;
171  }
172  } // end of loop over search paths
173 
174  // File not found
175  if (best_score == 0) {
176  QwError << "Could not find any parameter file with name " << name << ". "
177  << "Parameter file will remain empty." << QwLog::endl;
178  SetEOF();
179  exit(-1);
180  return;
181  }
182 
183  // Found but unable to open
184  if (best_score > 0 && OpenFile(best_path) == false) {
185  QwError << "Could not open parameter file " << best_path.string() << ". "
186  << "Parameter file will remain empty." << QwLog::endl;
187  SetEOF();
188  exit(-1);
189  return;
190  }
191 
192  // Print file name of file that was used
193  QwMessage << "Parameter file: "
194  << QwColor(Qw::kGreen) << best_path.string()
196  }
197 }
#define QwMessage
Predefined log drain for regular messages.
Definition: QwLog.h:50
const std::string fFilename
static const std::string kDefaultWhitespaceChars
static const std::string kDefaultSectionChars
std::string fCommentChars
static const std::string kDefaultTokenSepChars
std::string fSectionChars
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.
static const std::string kDefaultCommentChars
A color changing class for the output stream.
Definition: QwColor.h:98
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299
static std::vector< bfs::path > fSearchPaths
std::string fTokenSepChars
bool OpenFile(const bfs::path &path_found)
Open a file.
static const std::string kDefaultModuleChars
#define QwWarning
Predefined log drain for warnings.
Definition: QwLog.h:45
std::string fWhitespaceChars
#define QwError
Predefined log drain for errors.
Definition: QwLog.h:40
std::string fModuleChars

+ Here is the call graph for this function:

QwParameterFile::QwParameterFile ( const std::stringstream &  stream)

Constructor

Parameters
streamString stream for reading

Definition at line 92 of file QwParameterFile.cc.

References fStream.

98  fFilename("stream"),
99  fBeGreedy(kFALSE)
100 {
101  fStream << stream.rdbuf();
102 }
const std::string fFilename
std::stringstream fStream
static const std::string kDefaultWhitespaceChars
static const std::string kDefaultSectionChars
std::string fCommentChars
static const std::string kDefaultTokenSepChars
std::string fSectionChars
static const std::string kDefaultCommentChars
std::string fTokenSepChars
static const std::string kDefaultModuleChars
std::string fWhitespaceChars
std::string fModuleChars
virtual QwParameterFile::~QwParameterFile ( )
inlinevirtual

Definition at line 53 of file QwParameterFile.h.

53 { };
QwParameterFile::QwParameterFile ( )
inlineprivate

Definition at line 332 of file QwParameterFile.h.

Referenced by ReadUntilNextModule(), and ReadUntilNextSection().

338  fFilename("empty"),
339  fCurrentPos(0),
340  fBeGreedy(kFALSE),
341  fHasNewPairs(kFALSE)
342  { };
const std::string fFilename
static const std::string kDefaultWhitespaceChars
static const std::string kDefaultSectionChars
std::string fCommentChars
static const std::string kDefaultTokenSepChars
size_t fCurrentPos
Internal line storage.
std::string fSectionChars
static const std::string kDefaultCommentChars
std::string fTokenSepChars
static const std::string kDefaultModuleChars
std::string fWhitespaceChars
std::string fModuleChars

+ Here is the caller graph for this function:

QwParameterFile::QwParameterFile ( const QwParameterFile input)
inlineprivate

Definition at line 345 of file QwParameterFile.h.

346  : fCommentChars(input.fCommentChars),
350  fModuleChars(input.fModuleChars),
351  fFilename(input.fFilename),
352  fCurrentPos(input.fCurrentPos),
353  fBeGreedy(input.fBeGreedy),
355  { };
const std::string fFilename
std::string fCommentChars
size_t fCurrentPos
Internal line storage.
std::string fSectionChars
std::string fTokenSepChars
std::string fWhitespaceChars
std::string fModuleChars

Member Function Documentation

void QwParameterFile::AddBreakpointKeyword ( std::string  keyname)

Definition at line 876 of file QwParameterFile.cc.

References fBreakpointWords.

876  {
877  std::transform(keyname.begin(), keyname.end(),
878  keyname.begin(), ::tolower);
879  fBreakpointWords.insert(keyname);
880 }
std::set< std::string > fBreakpointWords
void QwParameterFile::AddLine ( const std::string &  line)
inline

Definition at line 136 of file QwParameterFile.h.

References fStream.

Referenced by ReadUntilNextModule(), and ReadUntilNextSection().

136 { fStream << line << std::endl; };
std::stringstream fStream

+ Here is the caller graph for this function:

void QwParameterFile::AppendToSearchPath ( const TString &  searchdir)
static

Add a directory to the search path.

Append a directory to the list of search paths

Parameters
searchdirDirectory to be added

Definition at line 35 of file QwParameterFile.cc.

References fSearchPaths.

Referenced by main().

36 {
37  bfs::path tmppath(searchdir.Data());
38  if( bfs::exists(tmppath) && bfs::is_directory(tmppath)) {
39  std::cout << tmppath.string()
40  << " is a directory; adding it to the search path\n";
41  fSearchPaths.push_back(tmppath);
42  } else if( bfs::exists(tmppath)) {
43  std::cout<<tmppath.string()<<" exists but is not a directory.\n";
44  } else {
45  std::cout<<tmppath.string()<<" doesn't exist.\n";
46  }
47 }
static std::vector< bfs::path > fSearchPaths

+ Here is the caller graph for this function:

void QwParameterFile::Close ( )
inline

Definition at line 205 of file QwParameterFile.h.

References fFile.

205 { fFile.close();};
std::ifstream fFile
template<typename T >
T QwParameterFile::ConvertValue ( const std::string &  value)
inline

Convert string value into specific type.

Definition at line 241 of file QwParameterFile.h.

References Qw::T.

Referenced by QwDetectorInfo::LoadCrosstalkDefinition(), and QwDetectorInfo::LoadGeometryDefinition().

241  {
242  T retvalue;
243  if (value.size() == 0) {
244  retvalue = 0; // and pray
245  } else {
246  std::istringstream stream1;
247  stream1.str(value);
248  stream1 >> retvalue;
249  }
250  return retvalue;
251  }
static const double T
Magnetic field: base unit is T.
Definition: QwUnits.h:111

+ Here is the caller graph for this function:

template<>
UInt_t QwParameterFile::ConvertValue ( const std::string &  value)
inline

Definition at line 369 of file QwParameterFile.h.

369  {
370  return GetUInt(value);
371 }
static UInt_t GetUInt(const TString &varvalue)
template<>
TString QwParameterFile::ConvertValue ( const std::string &  value)
inline

Definition at line 379 of file QwParameterFile.h.

379  {
380  return TString(value.c_str());
381 }
void QwParameterFile::DisableGreediness ( )
inline

Definition at line 201 of file QwParameterFile.h.

References fBeGreedy.

201 {fBeGreedy=kFALSE;};
void QwParameterFile::EnableGreediness ( )
inline

Definition at line 200 of file QwParameterFile.h.

References fBeGreedy.

200 {fBeGreedy=kTRUE;};
Bool_t QwParameterFile::FileHasModuleHeader ( const std::string &  secname)

Definition at line 629 of file QwParameterFile.cc.

References LineHasModuleHeader(), ReadNextLine(), and RewindToFileStart().

Referenced by QwRegressionSubsystem::ConstructBranch(), QwMainCerenkovDetector::ConstructBranch(), QwBeamLine::ConstructBranch(), QwIntegratedRaster::ConstructBranch(), and QwLumi::ConstructBranch().

630 {
632  while (ReadNextLine()) {
633  std::string this_secname;
634  if (LineHasModuleHeader(this_secname)) {
635  if (this_secname == secname) return kTRUE;
636  }
637  }
638  return false;
639 }
Bool_t LineHasModuleHeader()
Bool_t ReadNextLine()

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Bool_t QwParameterFile::FileHasModuleHeader ( const TString &  secname)

Definition at line 617 of file QwParameterFile.cc.

References LineHasModuleHeader(), ReadNextLine(), and RewindToFileStart().

618 {
620  while (ReadNextLine()) {
621  std::string this_secname;
622  if (LineHasModuleHeader(this_secname)) {
623  if (this_secname == secname) return kTRUE;
624  }
625  }
626  return false;
627 }
Bool_t LineHasModuleHeader()
Bool_t ReadNextLine()

+ Here is the call graph for this function:

Bool_t QwParameterFile::FileHasSectionHeader ( const std::string &  secname)

Definition at line 605 of file QwParameterFile.cc.

References LineHasSectionHeader(), ReadNextLine(), and RewindToFileStart().

Referenced by QwSubsystemArray::ConstructBranch().

606 {
608  while (ReadNextLine()) {
609  std::string this_secname;
610  if (LineHasSectionHeader(this_secname)) {
611  if (this_secname == secname) return kTRUE;
612  }
613  }
614  return false;
615 }
Bool_t ReadNextLine()
Bool_t LineHasSectionHeader()

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Bool_t QwParameterFile::FileHasSectionHeader ( const TString &  secname)

Definition at line 593 of file QwParameterFile.cc.

References LineHasSectionHeader(), ReadNextLine(), and RewindToFileStart().

594 {
596  while (ReadNextLine()) {
597  std::string this_secname;
598  if (LineHasSectionHeader(this_secname)) {
599  if (this_secname == secname) return kTRUE;
600  }
601  }
602  return false;
603 }
Bool_t ReadNextLine()
Bool_t LineHasSectionHeader()

+ Here is the call graph for this function:

Bool_t QwParameterFile::FileHasVariablePair ( const std::string &  separatorchars,
const std::string &  varname,
std::string &  varvalue 
)

Definition at line 516 of file QwParameterFile.cc.

References HasVariablePair(), ReadNextLine(), and RewindToFileStart().

Referenced by FileHasVariablePair(), QwDetectorInfo::LoadGeometryDefinition(), and QwSubsystemArray::LoadSubsystemsFromParameterFile().

520 {
522  while (ReadNextLine()) {
523  std::string this_varname;
524  if (HasVariablePair(separatorchars, this_varname, varvalue)) {
525  if (this_varname == varname) return kTRUE;
526  }
527  }
528  return false;
529 }
Bool_t HasVariablePair(const std::string &separatorchars, std::string &varname, std::string &varvalue)
Bool_t ReadNextLine()

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Bool_t QwParameterFile::FileHasVariablePair ( const std::string &  separatorchars,
const TString &  varname,
TString &  varvalue 
)

Definition at line 505 of file QwParameterFile.cc.

References FileHasVariablePair().

509 {
510  std::string tmpval;
511  Bool_t status = FileHasVariablePair(separatorchars, varname.Data(), tmpval);
512  if (status) varvalue = tmpval.c_str();
513  return status;
514 }
Bool_t FileHasVariablePair(const std::string &separatorchars, const std::string &varname, std::string &varvalue)

+ Here is the call graph for this function:

int QwParameterFile::FindFile ( const bfs::path &  directory,
const std::string &  file_stem,
const std::string &  file_ext,
bfs::path &  best_path 
)
private

Find the first file in a directory that conforms to the run label.

Find the file in a directory with highest-scoring run label

Parameters
directoryDirectory to search in
file_stemFile name stem to search for
file_extFile name extensions to search for
best_path(returns) Path to the highest-scoring file
Returns
Score of file

Definition at line 267 of file QwParameterFile.cc.

References QwLog::endl(), fCurrentRunNumber, ParseIntRange(), QwError, and QwWarning.

Referenced by QwParameterFile().

272 {
273  // Return false if the directory does not exist
274  if (! bfs::exists(directory)) return false;
275 
276  // Default score indicates no match found
277  int best_score = -1;
278  int score = -1;
279  // Multiple overlapping open-ended ranges
280  int open_ended_latest_start = 0;
281  int open_ended_range_score = 0;
282 
283  // Loop over all files in the directory
284  // note: default iterator constructor yields past-the-end
285  bfs::directory_iterator end_iterator;
286  for (bfs::directory_iterator file_iterator(directory);
287  file_iterator != end_iterator;
288  file_iterator++) {
289 
290  // Match the stem and extension
291  // note: filename() returns only the file name, not the path
292 #if BOOST_VERSION >= 104600
293  std::string file_name = file_iterator->path().filename().string();
294 #elif BOOST_VERSION >= 103600
295  std::string file_name = file_iterator->filename();
296 #else
297  std::string file_name = file_iterator->leaf();
298 #endif
299  // stem
300  size_t pos_stem = file_name.find(file_stem);
301  if (pos_stem != 0) continue;
302  // extension (reverse find)
303  size_t pos_ext = file_name.rfind(file_ext);
304  if (pos_ext != file_name.length() - file_ext.length()) continue;
305 
306  // Scores (from low to high)
307  const int score_no_run_label = 1;
308  // Open run range:
309  // score increments each time a higher-starting range is found
310  // difference between min and max gives maximum number of open ranges
311  const int score_open_ended_run_range_min = 1000;
312  const int score_open_ended_run_range_max = 9000;
313  // Close run range:
314  // score decremented from max by size of run range, small range -> high score
315  // difference between min and max gives maximum number of runs in closed range
316  const int score_closed_run_range_min = 10000;
317  const int score_closed_run_range_max = 90000;
318  // Single run label will always have maximum score
319  const int score_single_run_label = INT_MAX;
320 
321  // Determine run label length
322  size_t label_length = pos_ext - file_stem.length();
323  // no run label
324  if (label_length == 0) {
325  score = score_no_run_label;
326  } else {
327  // run label starts after dot ('.') and that dot is included in the label length
328  if (file_name.at(pos_stem + file_stem.length()) == '.') {
329  std::string label = file_name.substr(pos_stem + file_stem.length() + 1, label_length - 1);
330  std::pair<int,int> range = ParseIntRange("-",label);
331  int run = fCurrentRunNumber;
332  if ((range.first <= run) && (run <= range.second)) {
333 
334  // run is in single-value range
335  if (range.first == range.second) {
336  score = score_single_run_label;
337 
338  // run is in double-value range
339  } else if (range.second < INT_MAX) {
340  int number_of_runs = abs(range.second - range.first);
341  score = score_closed_run_range_max - number_of_runs;
342  if (score < score_closed_run_range_min) {
343  score = score_closed_run_range_min;
344  QwError << "Too many runs in closed run range for " << file_stem << QwLog::endl;
345  QwWarning << "Range is from " << range.first << " to " << range.second << QwLog::endl;
346  }
347 
348  // run is in open-ended range
349  } else if (range.second == INT_MAX) {
350  // each matching open-ended range
351  if (range.first > open_ended_latest_start) {
352  open_ended_latest_start = range.first;
353  open_ended_range_score++;
354  score = score_open_ended_run_range_min + open_ended_range_score;
355  if (score > score_open_ended_run_range_max) {
356  score = score_open_ended_run_range_max;
357  QwError << "Too many open ended run ranges for " << file_stem << QwLog::endl;
358  }
359 
360  } else score = score_open_ended_run_range_min;
361  }
362  } else
363  // run not in range
364  score = -1;
365  } else
366  // run label does not start with a dot (i.e. partial match of stem)
367  score = -1;
368  }
369 
370  // Look for the match with highest score
371  if (score > best_score) {
372  best_path = *file_iterator;
373  best_score = score;
374  }
375  }
376  return best_score;
377 }
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.
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299
#define QwWarning
Predefined log drain for warnings.
Definition: QwLog.h:45
#define QwError
Predefined log drain for errors.
Definition: QwLog.h:40

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Bool_t QwParameterFile::GetKeyValue ( const std::string  keyname,
std::string &  retvalue,
Bool_t  should_erase = kFALSE 
)
inlineprotected

Current position in the line.

Definition at line 308 of file QwParameterFile.h.

References fKeyValuePair.

Referenced by PopValue(), and ReturnValue().

309  {
310  Bool_t status = kFALSE;
311  std::map<std::string,std::string>::iterator it;
312  it = fKeyValuePair.find(keyname);
313  if (it != fKeyValuePair.end()) {
314  status = kTRUE;
315  retvalue = (*it).second;
316  if (should_erase){
317  fKeyValuePair.erase(it);
318  }
319  }
320  return status;
321  }
std::map< std::string, std::string > fKeyValuePair

+ Here is the caller graph for this function:

std::string QwParameterFile::GetLine ( )
inline

Definition at line 135 of file QwParameterFile.h.

References fLine.

Referenced by QwEventBuffer::GetNextRunRange(), HasValue(), QwHistogramHelper::LoadTreeParamsFromFile(), QwEventBuffer::ProcessOptions(), ReadUntilNextModule(), and ReadUntilNextSection().

135 { return fLine; };
std::string fLine

+ Here is the caller graph for this function:

std::string QwParameterFile::GetNextToken ( const std::string &  separatorchars)

Get next token as a string.

Definition at line 762 of file QwParameterFile.cc.

References fCurrentPos, fLine, and TrimWhitespace().

Referenced by QwRegression::LoadChannelMap(), and QwMainCerenkovDetector::LoadChannelMap().

763 {
764  std::string tmpstring = "";
765  if (fCurrentPos != std::string::npos){
766  size_t pos1 = fCurrentPos;
767  size_t pos2 = fLine.find_first_of(separatorchars.c_str(), pos1);
768  if (pos2 == std::string::npos){
769  fCurrentPos = pos2;
770  tmpstring = fLine.substr(pos1);
771  } else {
772  fCurrentPos = fLine.find_first_not_of(separatorchars.c_str(), pos2);
773  tmpstring = fLine.substr(pos1,pos2-pos1);
774  }
775  }
776  TrimWhitespace(tmpstring,TString::kBoth);
777  return tmpstring;
778 }
std::string fLine
size_t fCurrentPos
Internal line storage.
void TrimWhitespace(TString::EStripType head_tail=TString::kBoth)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string QwParameterFile::GetNextToken ( )
inline

Definition at line 127 of file QwParameterFile.h.

References fTokenSepChars, and GetNextToken().

Referenced by GetNextToken(), and GetTypedNextToken().

127 { return GetNextToken(fTokenSepChars); };
std::string GetNextToken()
std::string fTokenSepChars

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

TString QwParameterFile::GetParameterFileContents ( )

Definition at line 861 of file QwParameterFile.cc.

References fBestParamFileNameAndPath, and Qw::ms.

Referenced by GetParamFileNameContents().

862 {
863  TMacro *fParameterFile = new TMacro(fBestParamFileNameAndPath);
864  TString ms;
865  TList *list = fParameterFile->GetListOfLines();
866  for(Int_t i=0; i < list->GetSize(); i++) {
867  ms += list->At(i)->GetName();
868  ms += "\n";
869  }
870  delete fParameterFile;
871  fParameterFile = NULL;
872  return ms;
873 }
static const double ms
Time units: base unit is ms.
Definition: QwUnits.h:72
TString fBestParamFileNameAndPath

+ Here is the caller graph for this function:

const TString QwParameterFile::GetParamFilename ( )
inline

Definition at line 191 of file QwParameterFile.h.

References fBestParamFileName.

Referenced by GetParamFileNameContents().

191 {return fBestParamFileName;};
TString fBestParamFileName

+ Here is the caller graph for this function:

const TString QwParameterFile::GetParamFilenameAndPath ( )
inline

Definition at line 192 of file QwParameterFile.h.

References fBestParamFileNameAndPath.

192 {return fBestParamFileNameAndPath;};
TString fBestParamFileNameAndPath
const std::pair<TString, TString> QwParameterFile::GetParamFileNameContents ( )
inline

Definition at line 194 of file QwParameterFile.h.

References GetParameterFileContents(), and GetParamFilename().

Referenced by VQwSubsystemTracking::LoadCrosstalkDefinition(), and VQwSubsystemTracking::LoadGeometryDefinition().

194  {
195  return std::pair<TString, TString>(GetParamFilename(), GetParameterFileContents());
196  };
TString GetParameterFileContents()
const TString GetParamFilename()

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename T >
T QwParameterFile::GetTypedNextToken ( )
inline

Get next token into specific type.

Definition at line 131 of file QwParameterFile.h.

References GetNextToken().

Referenced by QwBeamLine::AssignGeometry(), QwHistogramHelper::GetHistParamsFromLine(), QwBeamLine::LoadChannelMap(), and QwBeamDetectorID::QwBeamDetectorID().

131  {
132  return ConvertValue<T>(GetNextToken());
133  }
std::string GetNextToken()

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

UInt_t QwParameterFile::GetUInt ( const TString &  varvalue)
static

Convert a string number value to an unsigned integer

Parameters
varvalueString with decimal or hexadecimal number
Returns
Unsigned integer

Definition at line 54 of file QwParameterFile.cc.

Referenced by QwDriftChamberHDC::LoadChannelMap(), QwDriftChamberVDC::LoadChannelMap(), QwSciFiDetector::LoadChannelMap(), QwScaler::LoadChannelMap(), QwTriggerScintillator::LoadChannelMap(), QwRaster::LoadChannelMap(), QwMainDetector::LoadChannelMap(), QwHelicity::LoadChannelMap(), QwComptonPhotonDetector::LoadChannelMap(), QwMainCerenkovDetector::LoadChannelMap(), QwIntegratedRaster::LoadChannelMap(), QwMollerDetector::LoadChannelMap(), QwLumi::LoadChannelMap(), QwComptonElectronDetector::LoadChannelMap(), QwScanner::LoadChannelMap(), VQwSubsystem::LoadDetectorMaps(), QwBeamLine::LoadEventCuts(), QwMainCerenkovDetector::LoadEventCuts(), QwIntegratedRaster::LoadEventCuts(), QwBeamMod::LoadEventCuts(), QwLumi::LoadEventCuts(), and QwHelicity::ProcessOptions().

55 {
56  UInt_t value = 0;
57  if (varvalue.IsDigit()){
58  value = varvalue.Atoi();
59  } else if (varvalue.BeginsWith("0x") || varvalue.BeginsWith("0X")
60  || varvalue.BeginsWith("x") || varvalue.BeginsWith("X")
61  || varvalue.IsHex()){
62  //any whitespace ?
63  Int_t end = varvalue.Index(" ");
64  std::istringstream stream1;
65  if (end == -1){
66  stream1.str(varvalue.Data());
67  } else {
68  //make temporary string, removing whitespace
69  Int_t start = 0;
70  TString tmp;
71  //loop over all whitespace
72  while (end > -1) {
73  tmp += varvalue(start, end-start);
74  start = end+1;
75  end = varvalue.Index(" ", start);
76  }
77  //finally add part from last whitespace to end of string
78  end = varvalue.Length();
79  tmp += varvalue(start, end-start);
80  stream1.str(tmp.Data());
81  }
82  stream1 >> std::hex >> value;
83  }
84  return value;
85 }

+ Here is the caller graph for this function:

Bool_t QwParameterFile::HasNewPairs ( )
inline

Definition at line 207 of file QwParameterFile.h.

References fHasNewPairs.

207  {
208  Bool_t status = fHasNewPairs;
209  if (fHasNewPairs) fHasNewPairs=kFALSE;
210  return status;
211  };
Bool_t QwParameterFile::HasValue ( TString &  vname)

Definition at line 447 of file QwParameterFile.cc.

References QwLog::endl(), GetLine(), QwMessage, ReadNextLine(), RewindToFileStart(), and TrimWhitespace().

Referenced by QwEnergyCalculator::ConstructBranch(), QwHaloMonitor::ConstructBranch(), QwIntegratedRasterChannel< T >::ConstructBranch(), QwClock< T >::ConstructBranch(), QwCombinedPMT::ConstructBranch(), QwQPD::ConstructBranch(), QwBPMCavity::ConstructBranch(), QwLinearDiodeArray::ConstructBranch(), QwCombinedBPM< T >::ConstructBranch(), QwBPMStripline< T >::ConstructBranch(), VQwHardwareChannel::ConstructBranch(), QwIntegrationPMT::ConstructBranch(), and QwBCM< T >::ConstructBranch().

448 {
449  Bool_t status=kFALSE;
450  TString vline;
451 
453  while (ReadNextLine()){
454  TrimWhitespace();
455  vline=(GetLine()).c_str();
456 
457  vline.ToLower();
458  TRegexp regexp(vline);
459  vname.ToLower();
460  if (vname.Contains(regexp)){
461  QwMessage <<" QwParameterFile::HasValue "<<vline<<" "<<vname<<QwLog::endl;
462  status=kTRUE;
463  break;
464  }
465  }
466 
467  return status;
468 }
#define QwMessage
Predefined log drain for regular messages.
Definition: QwLog.h:50
std::string GetLine()
Bool_t ReadNextLine()
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299
void TrimWhitespace(TString::EStripType head_tail=TString::kBoth)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Bool_t QwParameterFile::HasVariablePair ( const std::string &  separatorchars,
std::string &  varname,
std::string &  varvalue 
)

Definition at line 485 of file QwParameterFile.cc.

References fLine, and TrimWhitespace().

Referenced by QwEPICSEvent::ExtractEPICSValues(), FileHasVariablePair(), HasVariablePair(), QwDetectorInfo::LoadCrosstalkDefinition(), VQwSubsystem::LoadDetectorMaps(), ReadNextLine_Greedy(), and ReadNextLine_Single().

489 {
490  Bool_t status = kFALSE;
491  size_t equiv_pos1 = fLine.find_first_of(separatorchars);
492  if (equiv_pos1 != std::string::npos){
493  size_t equiv_pos2 = fLine.find_first_not_of(separatorchars,equiv_pos1);
494  if (equiv_pos2 != std::string::npos){
495  varname = fLine.substr(0,equiv_pos1);
496  varvalue = fLine.substr(equiv_pos2);
497  TrimWhitespace(varname, TString::kBoth);
498  TrimWhitespace(varvalue, TString::kBoth);
499  status = kTRUE;
500  }
501  }
502  return status;
503 }
std::string fLine
void TrimWhitespace(TString::EStripType head_tail=TString::kBoth)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Bool_t QwParameterFile::HasVariablePair ( const std::string &  separatorchars,
TString &  varname,
TString &  varvalue 
)

Definition at line 471 of file QwParameterFile.cc.

References HasVariablePair().

475 {
476  std::string tmpvar, tmpval;
477  Bool_t status = HasVariablePair(separatorchars, tmpvar, tmpval);
478  if (status){
479  varname = tmpvar.c_str();
480  varvalue = tmpval.c_str();
481  }
482  return status;
483 }
Bool_t HasVariablePair(const std::string &separatorchars, std::string &varname, std::string &varvalue)

+ Here is the call graph for this function:

Bool_t QwParameterFile::IsEOF ( )
inline

Definition at line 123 of file QwParameterFile.h.

References fStream.

Referenced by QwEventBuffer::GetNextEventRange(), QwEventBuffer::GetNextRunRange(), ReadNextModule(), and ReadNextSection().

123 { return fStream.eof();};
std::stringstream fStream

+ Here is the caller graph for this function:

TString QwParameterFile::LastString ( TString  in,
char *  delim 
)

Definition at line 853 of file QwParameterFile.cc.

Referenced by SetParamFilename().

854 {
855  TObjArray* all_strings = in.Tokenize(delim);
856  TObjString* last_string = (TObjString*) all_strings->Last();
857  return last_string->GetString();
858 };
static const double in
Definition: QwUnits.h:66

+ Here is the caller graph for this function:

Bool_t QwParameterFile::LineHasModuleHeader ( )

Definition at line 562 of file QwParameterFile.cc.

Referenced by FileHasModuleHeader(), LineHasModuleHeader(), ReadNextModule(), and ReadUntilNextModule().

563 {
564  std::string secname;
565  return LineHasModuleHeader(secname);
566 }
Bool_t LineHasModuleHeader()

+ Here is the caller graph for this function:

Bool_t QwParameterFile::LineHasModuleHeader ( std::string &  secname)

Definition at line 576 of file QwParameterFile.cc.

References fLine, fModuleChars, TrimComment(), and TrimWhitespace().

577 {
578  TrimComment();
579  Bool_t status = kFALSE;
580  size_t equiv_pos1 = fLine.find_first_of(fModuleChars[0]);
581  if (equiv_pos1 != std::string::npos) {
582  size_t equiv_pos2 = fLine.find_first_of(fModuleChars[1],equiv_pos1);
583  if (equiv_pos2 != std::string::npos && equiv_pos2 - equiv_pos1 > 1) {
584  secname = fLine.substr(equiv_pos1 + 1, equiv_pos2 - equiv_pos1 - 1);
585  TrimWhitespace(secname, TString::kBoth);
586  status = kTRUE;
587  }
588  }
589  return status;
590 }
std::string fLine
void TrimWhitespace(TString::EStripType head_tail=TString::kBoth)
std::string fModuleChars

+ Here is the call graph for this function:

Bool_t QwParameterFile::LineHasModuleHeader ( TString &  secname)

Definition at line 568 of file QwParameterFile.cc.

References LineHasModuleHeader().

569 {
570  std::string secname_tmp = secname.Data();
571  Bool_t status = LineHasModuleHeader(secname_tmp);
572  secname = secname_tmp;
573  return status;
574 }
Bool_t LineHasModuleHeader()

+ Here is the call graph for this function:

Bool_t QwParameterFile::LineHasSectionHeader ( )

Definition at line 532 of file QwParameterFile.cc.

Referenced by FileHasSectionHeader(), LineHasSectionHeader(), QwRegression::LoadChannelMap(), ReadNextSection(), ReadUntilNextSection(), and SkipSection().

533 {
534  std::string secname;
535  return LineHasSectionHeader(secname);
536 }
Bool_t LineHasSectionHeader()

+ Here is the caller graph for this function:

Bool_t QwParameterFile::LineHasSectionHeader ( std::string &  secname)

Definition at line 546 of file QwParameterFile.cc.

References fLine, TrimComment(), and TrimWhitespace().

547 {
548  TrimComment();
549  Bool_t status = kFALSE;
550  size_t equiv_pos1 = fLine.find_first_of('[');
551  if (equiv_pos1 != std::string::npos) {
552  size_t equiv_pos2 = fLine.find_first_of(']',equiv_pos1);
553  if (equiv_pos2 != std::string::npos && equiv_pos2 - equiv_pos1 > 1) {
554  secname = fLine.substr(equiv_pos1 + 1, equiv_pos2 - equiv_pos1 - 1);
555  TrimWhitespace(secname, TString::kBoth);
556  status = kTRUE;
557  }
558  }
559  return status;
560 }
std::string fLine
void TrimWhitespace(TString::EStripType head_tail=TString::kBoth)

+ Here is the call graph for this function:

Bool_t QwParameterFile::LineHasSectionHeader ( TString &  secname)

Definition at line 538 of file QwParameterFile.cc.

References LineHasSectionHeader().

539 {
540  std::string secname_tmp = secname.Data();
541  Bool_t status = LineHasSectionHeader(secname_tmp);
542  secname = secname_tmp;
543  return status;
544 }
Bool_t LineHasSectionHeader()

+ Here is the call graph for this function:

Bool_t QwParameterFile::LineIsEmpty ( )
inline

Definition at line 122 of file QwParameterFile.h.

References fLine.

Referenced by QwEventBuffer::GetNextEventRange(), QwRegression::LoadChannelMap(), QwHistogramHelper::LoadHistParamsFromFile(), QwHistogramHelper::LoadTreeParamsFromFile(), and ReadNextLine_Greedy().

122 {return fLine.empty();};
std::string fLine

+ Here is the caller graph for this function:

bool QwParameterFile::OpenFile ( const bfs::path &  file)
private

Open a file.

Open a file at the specified location

Parameters
filePath to file to be opened
Returns
False if the file could not be opened

Definition at line 205 of file QwParameterFile.cc.

References QwLog::endl(), fBestParamFileNameAndPath, fFile, fStream, QwError, and SetParamFilename().

Referenced by QwParameterFile().

206 {
207  Bool_t local_debug = false;
208 
209  Bool_t status = false;
210 
211  Bool_t check_whether_path_exists_and_is_a_regular_file = false;
212 
213  // Check whether path exists and is a regular file
214 #if BOOST_VERSION >= 103600
215  check_whether_path_exists_and_is_a_regular_file = bfs::exists(file) && bfs::is_regular_file(file);
216 #elif BOOST_VERSION >= 103400
217  check_whether_path_exists_and_is_a_regular_file = bfs::exists(file) && bfs::is_regular(file);
218 #else
219  check_whether_path_exists_and_is_a_regular_file = bfs::exists(file); /* pray */
220 #endif
221 
222  if (check_whether_path_exists_and_is_a_regular_file) {
223 
224  fBestParamFileNameAndPath = file.string();
225  this->SetParamFilename();
226 
227  // Connect stream (fFile) to file
228  fFile.open(file.string().c_str());
229  if (! fFile.good())
230  QwError << "QwParameterFile::OpenFile Unable to read parameter file "
231  << file.string() << QwLog::endl;
232  // Load into stream
233  fStream << fFile.rdbuf();
234  status = true;
235  if(local_debug) {
236  std::cout << "------before close------------" << std::endl;
237  std::cout << fStream.str() << std::endl;
238  }
239 
240  // fFile.clear();
241  // fFile.close(); // disconnet file
242  // this->Test();
243  } else {
244 
245  // File does not exist or is not a regular file
246  QwError << "QwParameterFile::OpenFile Unable to open parameter file "
247  << file.string() << QwLog::endl;
248  status = false;
249  }
250  if(local_debug) {
251  std::cout << "-------after close ----------" << std::endl;
252  std::cout << fStream.str() << std::endl;
253  }
254 
255  return status;
256 }
std::stringstream fStream
std::ifstream fFile
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299
TString fBestParamFileNameAndPath
#define QwError
Predefined log drain for errors.
Definition: QwLog.h:40

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::pair< int, int > QwParameterFile::ParseIntRange ( const std::string &  separatorchars,
const std::string &  range 
)
static

Parse a range of integers as #:# where either can be missing.

Separate a separated range of integers into a pair of values.

Parameters
separatorcharsString with possible separator characters to consider.
rangeString containing two integers separated by a separator character, or a single value. If the string begins with the separator character, the first value is taken as zero. If the string ends with the separator character, the second value is taken as kMaxInt.
Returns
Pair of integers of the first and last values of the range. If the range contains a single value, the two integers will be identical.

Definition at line 802 of file QwParameterFile.cc.

References QwLog::endl(), QwError, and QwVerbose.

Referenced by FindFile(), QwOptions::GetIntValuePair(), QwEventBuffer::GetNextEventRange(), and QwEventBuffer::GetNextRunRange().

803 {
804  std::pair<int,int> mypair;
805  size_t pos = range.find_first_of(separatorchars);
806  if (pos == std::string::npos) {
807  // Separator not found.
808  mypair.first = atoi(range.substr(0,range.length()).c_str());
809  mypair.second = mypair.first;
810  } else {
811  size_t end = range.length() - pos - 1;
812  if (pos == 0) {
813  // Separator is the first character
814  mypair.first = 0;
815  mypair.second = atoi(range.substr(pos+1, end).c_str());
816  } else if (pos == range.length() - 1) {
817  // Separator is the last character
818  mypair.first = atoi(range.substr(0,pos).c_str());
819  mypair.second = INT_MAX;
820  } else {
821  mypair.first = atoi(range.substr(0,pos).c_str());
822  mypair.second = atoi(range.substr(pos+1, end).c_str());
823  }
824  }
825 
826  // Check the values for common errors.
827  if (mypair.first < 0){
828  QwError << "The first value must not be negative!" << QwLog::endl;
829  return std::pair<int,int>(INT_MAX,INT_MAX);
830  } else if (mypair.first > mypair.second){
831  QwError << "The first value must not be larger than the second value"
832  << QwLog::endl;
833  return std::pair<int,int>(INT_MAX,INT_MAX);
834  }
835 
836  // Print the contents of the pair for debugging.
837  QwVerbose << "The range goes from " << mypair.first
838  << " to " << mypair.second << QwLog::endl;
839 
840  return mypair;
841 }
#define QwVerbose
Predefined log drain for verbose messages.
Definition: QwLog.h:55
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299
#define QwError
Predefined log drain for errors.
Definition: QwLog.h:40

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename T >
Bool_t QwParameterFile::PopValue ( const std::string  keyname,
T &  retvalue 
)
inline

Definition at line 223 of file QwParameterFile.h.

References GetKeyValue().

223  {
224  std::string value;
225  Bool_t status = GetKeyValue(keyname, value, kTRUE);
226  if (status){
227  retvalue = ConvertValue<T>(value);
228  }
229  return status;
230  };
Bool_t GetKeyValue(const std::string keyname, std::string &retvalue, Bool_t should_erase=kFALSE)
Current position in the line.

+ Here is the call graph for this function:

std::streambuf* QwParameterFile::rdbuf ( ) const
inline

Access the streambuf pointer in the same way as on a std::ifstream.

Definition at line 56 of file QwParameterFile.h.

References fStream.

Referenced by QwOptions::ParseConfigFile().

56 {return fStream.rdbuf(); };
std::stringstream fStream

+ Here is the caller graph for this function:

QwParameterFile * QwParameterFile::ReadModulePreamble ( )

Rewinds to the start and read until it finds next module header.

Read the lines until the first header

Returns
Pointer to the parameter stream until first module

Definition at line 736 of file QwParameterFile.cc.

References ReadUntilNextModule(), and RewindToFileStart().

737 {
739  return ReadUntilNextModule();
740 }
QwParameterFile * ReadUntilNextModule(const bool add_current_line=false)

+ Here is the call graph for this function:

Bool_t QwParameterFile::ReadNextLine ( std::string &  varvalue)
inline

Definition at line 76 of file QwParameterFile.h.

References fBeGreedy, ReadNextLine_Greedy(), and ReadNextLine_Single().

76  {
77  Bool_t status = kFALSE;
78  if (fBeGreedy) status = ReadNextLine_Greedy(varvalue);
79  else status = ReadNextLine_Single(varvalue);
80  return status;
81  }
Bool_t ReadNextLine_Single(std::string &varvalue)
Bool_t ReadNextLine_Greedy(std::string &varvalue)

+ Here is the call graph for this function:

Bool_t QwParameterFile::ReadNextLine_Greedy ( std::string &  varvalue)

Definition at line 882 of file QwParameterFile.cc.

References fBreakpointWords, fHasNewPairs, fKeyValuePair, HasVariablePair(), LineIsEmpty(), ReadNextLine_Single(), RewindToLineStart(), TrimComment(), and TrimWhitespace().

Referenced by ReadNextLine().

883 {
884  // Keep reading until a non-comment, non-empty,
885  // non-keyword-value-pair line has been found.
886  Bool_t status;
887  std::string tmpname, tmpvalue;
888  while ((status = ReadNextLine_Single(varvalue))){
889  TrimComment();
890  TrimWhitespace();
891  if (LineIsEmpty()) continue;
892  if (HasVariablePair("=",tmpname,tmpvalue)){
893  std::transform(tmpname.begin(), tmpname.end(),
894  tmpname.begin(), ::tolower);
895  if (fBreakpointWords.count(tmpname)==1){
897  break;
898  } else {
899  fKeyValuePair[tmpname] = tmpvalue;
900  fHasNewPairs = kTRUE;
901  continue;
902  }
903  }
904  break;
905  }
906  return status;
907 }
Bool_t HasVariablePair(const std::string &separatorchars, std::string &varname, std::string &varvalue)
std::map< std::string, std::string > fKeyValuePair
Bool_t ReadNextLine_Single(std::string &varvalue)
std::set< std::string > fBreakpointWords
void TrimWhitespace(TString::EStripType head_tail=TString::kBoth)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Bool_t QwParameterFile::ReadNextLine_Single ( std::string &  varvalue)
inline

Definition at line 83 of file QwParameterFile.h.

References fCurrentPos, fLine, fStream, HasVariablePair(), and ReadNextLine().

Referenced by ReadNextLine(), and ReadNextLine_Greedy().

83  {
84  fCurrentPos = 0;
85  if (! getline(fStream, fLine))
86  // No next line
87  return 0;
88  else {
89  // Copy next line
90  varvalue = fLine;
91  // Allow 'append'
92  std::string tmpname, tmpvalue;
93  if (HasVariablePair(" ",tmpname,tmpvalue)) {
94  if (tmpname == "append") {
95  // Test for recursion in file nesting
96  static int nested_depth = 0;
97  if (nested_depth++ > 5) {
98  std::cout << "Parameter file recursion not allowed!" << std::endl;
99  return 0;
100  }
101  // Stream nested file into this file
102  QwParameterFile nested_file(tmpvalue.c_str());
103  fStream << nested_file.rdbuf();
104  // Read line from appended file
105  return ReadNextLine(varvalue);
106  }
107  }
108  return 1;
109  }
110  };
std::stringstream fStream
Bool_t HasVariablePair(const std::string &separatorchars, std::string &varname, std::string &varvalue)
std::string fLine
size_t fCurrentPos
Internal line storage.
Bool_t ReadNextLine()

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

QwParameterFile * QwParameterFile::ReadNextModule ( std::string &  secname,
bool  keep_header = false 
)

Read the lines of the next module

Parameters
secnameName of the next module (returns)
keep_headerFlag to keep header of module
Returns
Pointer to the parameter stream of the next module

Definition at line 748 of file QwParameterFile.cc.

References IsEOF(), LineHasModuleHeader(), ReadNextLine(), and ReadUntilNextModule().

Referenced by VQwSubsystemTracking::LoadGeometryDefinition(), QwHistogramHelper::LoadTreeParamsFromFile(), and ReadNextModule().

749 {
750  if (IsEOF()) return 0;
751  while (! LineHasModuleHeader(secname) && ReadNextLine()); // skip until header
752  return ReadUntilNextModule(keep_header);
753 }
Bool_t LineHasModuleHeader()
Bool_t ReadNextLine()
QwParameterFile * ReadUntilNextModule(const bool add_current_line=false)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

QwParameterFile * QwParameterFile::ReadNextModule ( TString &  secname,
bool  keep_header = false 
)

Definition at line 755 of file QwParameterFile.cc.

References IsEOF(), LineHasModuleHeader(), ReadNextLine(), and ReadUntilNextModule().

756 {
757  if (IsEOF()) return 0;
758  while (! LineHasModuleHeader(secname) && ReadNextLine()); // skip until header
759  return ReadUntilNextModule(keep_header);
760 }
Bool_t LineHasModuleHeader()
Bool_t ReadNextLine()
QwParameterFile * ReadUntilNextModule(const bool add_current_line=false)

+ Here is the call graph for this function:

QwParameterFile* QwParameterFile::ReadNextModule ( const bool  keep_header = false)
inline

Definition at line 183 of file QwParameterFile.h.

References ReadNextModule().

183  {
184  std::string dummy;
185  return ReadNextModule(dummy, keep_header);
186  };
QwParameterFile * ReadNextModule(std::string &secname, bool keep_header=false)

+ Here is the call graph for this function:

QwParameterFile * QwParameterFile::ReadNextSection ( std::string &  secname,
const bool  keep_header = false 
)

Read the lines of the next section

Parameters
secnameName of the next section (returns)
keep_headerKeep the header inside the section
Returns
Pointer to the parameter stream of the next section

Definition at line 717 of file QwParameterFile.cc.

References IsEOF(), LineHasSectionHeader(), ReadNextLine(), and ReadUntilNextSection().

Referenced by QwEventBuffer::GetNextRunRange(), QwRegression::LoadChannelMap(), QwBeamLine::LoadChannelMap(), QwMainCerenkovDetector::LoadChannelMap(), QwBeamMod::LoadChannelMap(), VQwSubsystemTracking::LoadCrosstalkDefinition(), VQwSubsystemTracking::LoadGeometryDefinition(), QwSubsystemArray::LoadSubsystemsFromParameterFile(), QwHistogramHelper::LoadTreeParamsFromFile(), and ReadNextSection().

718 {
719  if (IsEOF()) return 0;
720  while (! LineHasSectionHeader(secname) && ReadNextLine()); // skip until header
721  return ReadUntilNextSection(keep_header);
722 }
QwParameterFile * ReadUntilNextSection(const bool add_current_line=false)
Bool_t ReadNextLine()
Bool_t LineHasSectionHeader()

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

QwParameterFile * QwParameterFile::ReadNextSection ( TString &  secname,
const bool  keep_header = false 
)

Definition at line 724 of file QwParameterFile.cc.

References IsEOF(), LineHasSectionHeader(), ReadNextLine(), and ReadUntilNextSection().

725 {
726  if (IsEOF()) return 0;
727  while (! LineHasSectionHeader(secname) && ReadNextLine()); // skip until header
728  return ReadUntilNextSection(keep_header);
729 }
QwParameterFile * ReadUntilNextSection(const bool add_current_line=false)
Bool_t ReadNextLine()
Bool_t LineHasSectionHeader()

+ Here is the call graph for this function:

QwParameterFile* QwParameterFile::ReadNextSection ( const bool  keep_header = false)
inline

Definition at line 173 of file QwParameterFile.h.

References ReadNextSection().

173  {
174  std::string dummy;
175  return ReadNextSection(dummy, keep_header);
176  };
QwParameterFile * ReadNextSection(std::string &secname, const bool keep_header=false)

+ Here is the call graph for this function:

QwParameterFile * QwParameterFile::ReadSectionPreamble ( )

Rewinds to the start and read until it finds next section header.

Read the lines until the first header

Returns
Pointer to the parameter stream until first section

Definition at line 705 of file QwParameterFile.cc.

References ReadUntilNextSection(), and RewindToFileStart().

Referenced by QwSubsystemArray::ConstructBranch(), VQwSubsystemTracking::LoadCrosstalkDefinition(), VQwSubsystemTracking::LoadGeometryDefinition(), and QwSubsystemArray::LoadSubsystemsFromParameterFile().

706 {
708  return ReadUntilNextSection();
709 }
QwParameterFile * ReadUntilNextSection(const bool add_current_line=false)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

QwParameterFile * QwParameterFile::ReadUntilNextModule ( const bool  add_current_line = false)

Read from current position until next module header

Returns
Pointer to the parameter stream until next module

Definition at line 660 of file QwParameterFile.cc.

References AddLine(), GetLine(), LineHasModuleHeader(), QwParameterFile(), and ReadNextLine().

Referenced by QwRegressionSubsystem::ConstructBranch(), QwMainCerenkovDetector::ConstructBranch(), QwBeamLine::ConstructBranch(), QwIntegratedRaster::ConstructBranch(), QwLumi::ConstructBranch(), ReadModulePreamble(), and ReadNextModule().

661 {
662  std::string nextheader; // dummy
663  QwParameterFile* section = new QwParameterFile();
664  if (add_current_line) section->AddLine(GetLine()); // add current line
665  while (ReadNextLine() && ! LineHasModuleHeader(nextheader)) {
666  section->AddLine(GetLine());
667  }
668  return section;
669 }
Bool_t LineHasModuleHeader()
std::string GetLine()
Bool_t ReadNextLine()
void AddLine(const std::string &line)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

QwParameterFile * QwParameterFile::ReadUntilNextSection ( const bool  add_current_line = false)

Read from current position until next section header

Returns
Pointer to the parameter stream until next section

Definition at line 645 of file QwParameterFile.cc.

References AddLine(), GetLine(), LineHasSectionHeader(), QwParameterFile(), and ReadNextLine().

Referenced by QwSubsystemArray::ConstructBranch(), ReadNextSection(), and ReadSectionPreamble().

646 {
647  std::string nextheader; // dummy
648  QwParameterFile* section = new QwParameterFile();
649  if (add_current_line) section->AddLine(GetLine()); // add current line
650  while (ReadNextLine() && ! LineHasSectionHeader(nextheader)) {
651  section->AddLine(GetLine());
652  }
653  return section;
654 }
std::string GetLine()
Bool_t ReadNextLine()
Bool_t LineHasSectionHeader()
void AddLine(const std::string &line)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename T >
Bool_t QwParameterFile::ReturnValue ( const std::string  keyname,
T &  retvalue 
)
inline

Definition at line 214 of file QwParameterFile.h.

References GetKeyValue().

Referenced by VQwScaler_Channel::LoadChannelParameters(), and QwVQWK_Channel::LoadChannelParameters().

214  {
215  std::string value;
216  Bool_t status = GetKeyValue(keyname, value);
217  if (status){
218  retvalue = ConvertValue<T>(value);
219  }
220  return status;
221  }
Bool_t GetKeyValue(const std::string keyname, std::string &retvalue, Bool_t should_erase=kFALSE)
Current position in the line.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void QwParameterFile::RewindToLineStart ( )
inline

Definition at line 139 of file QwParameterFile.h.

References fCurrentPos.

Referenced by ReadNextLine_Greedy().

139 { fCurrentPos = 0; };
size_t fCurrentPos
Internal line storage.

+ Here is the caller graph for this function:

void QwParameterFile::SetCommentChars ( const std::string  value)
inline

Set various sets of special characters.

Definition at line 65 of file QwParameterFile.h.

References fCommentChars.

65 { fCommentChars = value; };
std::string fCommentChars
static void QwParameterFile::SetCurrentRunNumber ( const UInt_t  runnumber)
inlinestatic

Set the current run number for looking up the appropriate parameter file.

Definition at line 62 of file QwParameterFile.h.

References fCurrentRunNumber.

Referenced by main().

62 { fCurrentRunNumber = runnumber; };
static UInt_t fCurrentRunNumber

+ Here is the caller graph for this function:

void QwParameterFile::SetEOF ( )
inlineprivate

Definition at line 358 of file QwParameterFile.h.

References fStream.

Referenced by QwParameterFile().

358 { fStream.setstate(std::ios::eofbit); };
std::stringstream fStream

+ Here is the caller graph for this function:

void QwParameterFile::SetModuleChars ( const std::string  value)
inline

Definition at line 69 of file QwParameterFile.h.

References fModuleChars.

69 { fModuleChars = value; };
std::string fModuleChars
void QwParameterFile::SetParamFilename ( )

Definition at line 845 of file QwParameterFile.cc.

References fBestParamFileName, fBestParamFileNameAndPath, and LastString().

Referenced by OpenFile().

846 {
847  Char_t delimiters[] = "/";
849  return;
850 };
TString fBestParamFileName
TString LastString(TString in, char *delim)
TString fBestParamFileNameAndPath

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void QwParameterFile::SetSectionChars ( const std::string  value)
inline

Definition at line 68 of file QwParameterFile.h.

References fSectionChars.

68 { fSectionChars = value; };
std::string fSectionChars
void QwParameterFile::SetTokenSepChars ( const std::string  value)
inline

Definition at line 67 of file QwParameterFile.h.

References fTokenSepChars.

67 { fTokenSepChars = value; };
std::string fTokenSepChars
void QwParameterFile::SetWhitespaceChars ( const std::string  value)
inline

Definition at line 66 of file QwParameterFile.h.

References fWhitespaceChars.

66 { fWhitespaceChars = value; };
std::string fWhitespaceChars
Bool_t QwParameterFile::SkipSection ( std::string  secname)

Skips from the beginning of the section 'secname' until the first section that does not have that name.

Definition at line 671 of file QwParameterFile.cc.

References QwLog::endl(), LineHasSectionHeader(), QwDebug, and ReadNextLine().

672 {
673  // If the current line begins the section to be skipped,
674  // just keep reading until we get to the next section.
675  // Recurse, just in case the next section is the same
676  // section name.
677  Bool_t status = kTRUE;
678  std::string tmpname;
679  if (LineHasSectionHeader(tmpname)){
680  if (tmpname == secname){
681  QwDebug << "QwParameterFile::SkipSection: "
682  << "Begin skipping section " << tmpname << QwLog::endl;
683  while ((status=ReadNextLine()) && ! LineHasSectionHeader(tmpname)) {
684  // Do nothing for each line.
685  }
686  QwDebug << "QwParameterFile::SkipSection: "
687  << "Reached the end of the section."
688  << QwLog::endl;
689  if (status){
690  // Recurse, in case the next section has the same
691  // section name, but only if we found a new section
692  // header.
693  status = SkipSection(secname);
694  }
695  }
696  }
697  return status;
698 }
#define QwDebug
Predefined log drain for debugging output.
Definition: QwLog.h:60
Bool_t ReadNextLine()
Bool_t LineHasSectionHeader()
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299
Bool_t SkipSection(std::string secname)
Skips from the beginning of the section &#39;secname&#39; until the first section that does not have that nam...

+ Here is the call graph for this function:

void QwParameterFile::Trim ( const std::string &  chars,
std::string &  token,
TString::EStripType  head_tail = TString::kBoth 
)
protected

Definition at line 388 of file QwParameterFile.cc.

Referenced by TrimModuleHeader(), TrimSectionHeader(), and TrimWhitespace().

392 {
393  // If the first bit is set, this routine removes leading chars from the
394  // line. If the second bit is set, this routine removes trailing chars
395  // from the line. The default behavior is to remove both.
396  size_t mypos;
397  // Remove leading chars. If this first test returns "npos", it means
398  // this line is all chars, so get rid of it all.
399  // If we're not removing leading chars, lines which are all chars
400  // will not be removed.
401  mypos = token.find_first_not_of(chars);
402  if (head_tail & TString::kLeading) token.erase(0,mypos);
403  // Remove trailing spaces
404  mypos = token.find_last_not_of(chars);
405  mypos = token.find_first_of(chars,mypos);
406  if (mypos != std::string::npos && (head_tail & TString::kTrailing)){
407  token.erase(mypos);
408  }
409 }

+ Here is the caller graph for this function:

void QwParameterFile::TrimComment ( const char  commentchar)
void QwParameterFile::TrimComment ( const std::string &  commentchars)

Definition at line 425 of file QwParameterFile.cc.

References fLine.

426 {
427  // Remove everything after the comment character
428  size_t mypos = fLine.find_first_of(commentchars);
429  if (mypos != std::string::npos){
430  fLine.erase(mypos);
431  }
432 }
std::string fLine
void QwParameterFile::TrimComment ( )
inline

Definition at line 115 of file QwParameterFile.h.

References fCommentChars, and TrimComment().

Referenced by LineHasModuleHeader(), LineHasSectionHeader(), ReadNextLine_Greedy(), and TrimComment().

std::string fCommentChars

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void QwParameterFile::TrimModuleHeader ( )

Definition at line 440 of file QwParameterFile.cc.

References fLine, fModuleChars, and Trim().

441 {
442  // Trim module delimiter character on both sides
443  Trim(fModuleChars,fLine,TString::kBoth);
444 }
std::string fLine
void Trim(const std::string &chars, std::string &token, TString::EStripType head_tail=TString::kBoth)
std::string fModuleChars

+ Here is the call graph for this function:

void QwParameterFile::TrimSectionHeader ( )

Definition at line 434 of file QwParameterFile.cc.

References fLine, fSectionChars, and Trim().

Referenced by QwRegression::LoadChannelMap().

435 {
436  // Trim section delimiter character on both sides
437  Trim(fSectionChars,fLine,TString::kBoth);
438 }
std::string fLine
std::string fSectionChars
void Trim(const std::string &chars, std::string &token, TString::EStripType head_tail=TString::kBoth)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void QwParameterFile::TrimWhitespace ( TString::EStripType  head_tail = TString::kBoth)

Definition at line 380 of file QwParameterFile.cc.

References fLine.

Referenced by QwEPICSEvent::ExtractEPICSValues(), QwEventBuffer::GetNextEventRange(), GetNextToken(), HasValue(), HasVariablePair(), LineHasModuleHeader(), LineHasSectionHeader(), QwRegression::LoadChannelMap(), QwBeamLine::LoadChannelMap(), QwMainCerenkovDetector::LoadChannelMap(), QwDetectorInfo::LoadCrosstalkDefinition(), VQwSubsystemTracking::LoadCrosstalkDefinition(), VQwSubsystem::LoadDetectorMaps(), QwDetectorInfo::LoadGeometryDefinition(), VQwSubsystemTracking::LoadGeometryDefinition(), QwHistogramHelper::LoadHistParamsFromFile(), QwHistogramHelper::LoadTreeParamsFromFile(), and ReadNextLine_Greedy().

381 {
382  // If the first bit is set, this routine removes leading spaces from the
383  // line. If the second bit is set, this routine removes trailing spaces
384  // from the line. The default behavior is to remove both.
385  TrimWhitespace(fLine, head_tail);
386 }
std::string fLine
void TrimWhitespace(TString::EStripType head_tail=TString::kBoth)

+ Here is the caller graph for this function:

void QwParameterFile::TrimWhitespace ( std::string &  token,
TString::EStripType  head_tail 
)
protected

Definition at line 411 of file QwParameterFile.cc.

References fWhitespaceChars, and Trim().

414 {
415  Trim(fWhitespaceChars,token,head_tail);
416 }
std::string fWhitespaceChars
void Trim(const std::string &chars, std::string &token, TString::EStripType head_tail=TString::kBoth)

+ Here is the call graph for this function:

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  stream,
const QwParameterFile file 
)
friend
Todo:
TODO (wdc) operator<< on QwParameterFile requires RewindToFileStart

Definition at line 780 of file QwParameterFile.cc.

781 {
782  /// \todo TODO (wdc) operator<< on QwParameterFile requires RewindToFileStart
783  std::string line;
784  stream << file.fStream.rdbuf();
785  return stream;
786 }
std::stringstream fStream

Field Documentation

Bool_t QwParameterFile::fBeGreedy
protected

Definition at line 324 of file QwParameterFile.h.

Referenced by DisableGreediness(), EnableGreediness(), and ReadNextLine().

TString QwParameterFile::fBestParamFileName
private

Definition at line 265 of file QwParameterFile.h.

Referenced by GetParamFilename(), and SetParamFilename().

TString QwParameterFile::fBestParamFileNameAndPath
private
std::set<std::string> QwParameterFile::fBreakpointWords
protected

Definition at line 325 of file QwParameterFile.h.

Referenced by AddBreakpointKeyword(), and ReadNextLine_Greedy().

std::string QwParameterFile::fCommentChars
protected

Definition at line 290 of file QwParameterFile.h.

Referenced by SetCommentChars(), and TrimComment().

size_t QwParameterFile::fCurrentPos
protected

Internal line storage.

Definition at line 304 of file QwParameterFile.h.

Referenced by GetNextToken(), ReadNextLine(), ReadNextLine_Single(), and RewindToLineStart().

UInt_t QwParameterFile::fCurrentRunNumber = 0
staticprotected

Definition at line 280 of file QwParameterFile.h.

Referenced by FindFile(), and SetCurrentRunNumber().

std::ifstream QwParameterFile::fFile
protected

Definition at line 299 of file QwParameterFile.h.

Referenced by Close(), and OpenFile().

const std::string QwParameterFile::fFilename
protected

Definition at line 298 of file QwParameterFile.h.

Bool_t QwParameterFile::fHasNewPairs
protected

Definition at line 327 of file QwParameterFile.h.

Referenced by HasNewPairs(), and ReadNextLine_Greedy().

std::map<std::string, std::string> QwParameterFile::fKeyValuePair
protected

Definition at line 326 of file QwParameterFile.h.

Referenced by GetKeyValue(), and ReadNextLine_Greedy().

std::string QwParameterFile::fModuleChars
protected

Definition at line 294 of file QwParameterFile.h.

Referenced by LineHasModuleHeader(), SetModuleChars(), and TrimModuleHeader().

std::vector< bfs::path > QwParameterFile::fSearchPaths
staticprotected

Definition at line 277 of file QwParameterFile.h.

Referenced by AppendToSearchPath(), and QwParameterFile().

std::string QwParameterFile::fSectionChars
protected

Definition at line 293 of file QwParameterFile.h.

Referenced by SetSectionChars(), and TrimSectionHeader().

std::stringstream QwParameterFile::fStream
protected
std::string QwParameterFile::fTokenSepChars
protected

Definition at line 292 of file QwParameterFile.h.

Referenced by GetNextToken(), and SetTokenSepChars().

std::string QwParameterFile::fWhitespaceChars
protected

Definition at line 291 of file QwParameterFile.h.

Referenced by SetWhitespaceChars(), and TrimWhitespace().

const std::string QwParameterFile::kDefaultCommentChars = "#!;"
staticprotected

Definition at line 283 of file QwParameterFile.h.

const std::string QwParameterFile::kDefaultModuleChars = "<>"
staticprotected

Definition at line 287 of file QwParameterFile.h.

const std::string QwParameterFile::kDefaultSectionChars = "[]"
staticprotected

Definition at line 286 of file QwParameterFile.h.

const std::string QwParameterFile::kDefaultTokenSepChars = ", \t"
staticprotected

Definition at line 285 of file QwParameterFile.h.

const std::string QwParameterFile::kDefaultWhitespaceChars = " \t\r"
staticprotected

Definition at line 284 of file QwParameterFile.h.


The documentation for this class was generated from the following files: