#include <LArBadChannelParser2.h>
|
| | LArBadChannelParser2 (const std::string &filename, MsgStream *const messager) |
| | A parser object must be initialized with the filename that it is to parse.
|
| | ~LArBadChannelParser2 () |
| std::vector< ISLine > | parseISfile (int nint, int minString, int firstWildcard=-1) |
| | parse the file using the format "nint consecutive integers and then at least minString strings" and return the result as a vector of all successfully parsed lines.
|
| bool | fileStatusGood () const |
| | You can use this function to check whether the file was successfully opened for reading.
|
|
| bool | parseLine (std::string &readLine, ISLine &parsedLine, int nint, int minString, int firstWildcard) |
| bool | interpretLine (const std::vector< std::string > &command, ISLine &parsedLine, int nint, int minString, int firstWildcard) |
| bool | stringToInt (int &theInt, const std::string &theStr) const |
Definition at line 15 of file LArBadChannelParser2.h.
◆ LArBadChannelParser2()
| LArBadChannelParser2::LArBadChannelParser2 |
( |
const std::string & | filename, |
|
|
MsgStream *const | messager ) |
A parser object must be initialized with the filename that it is to parse.
It must also be given a MsgStream pointer for logging messages.
Definition at line 10 of file LArBadChannelParser2.cxx.
10 :
12{
15 std::cerr << "WARNING \t LArBadChannelParser was given a NULL MsgStream pointer!" << std::endl;
16 }
17}
const std::string m_filename
unsigned int m_linenumber
◆ ~LArBadChannelParser2()
| LArBadChannelParser2::~LArBadChannelParser2 |
( |
| ) |
|
◆ fileStatusGood()
| bool LArBadChannelParser2::fileStatusGood |
( |
| ) |
const |
You can use this function to check whether the file was successfully opened for reading.
Definition at line 24 of file LArBadChannelParser2.cxx.
◆ interpretLine()
| bool LArBadChannelParser2::interpretLine |
( |
const std::vector< std::string > & | command, |
|
|
ISLine & | parsedLine, |
|
|
int | nint, |
|
|
int | minString, |
|
|
int | firstWildcard ) |
|
private |
Definition at line 76 of file LArBadChannelParser2.cxx.
79{
80 if((
int)
command.size() < nint+minString) {
81 (*m_log) << MSG::WARNING <<
"LArBadChannelParser REJECTED line " <<
m_linenumber \
82 <<
":\t not enough parameters given" <<
endmsg;
83 return false;
84 }
85
86 for(
int i=0;
i<nint;
i++) {
87 int nextInt(0);
88 if (firstWildcard >=0 && i>=firstWildcard && command[i] == "*") {
89 parsedLine.intVec.push_back(-1);
90 }
91 else if(
stringToInt(nextInt, command[i]) && nextInt >= 0) {
92 parsedLine.intVec.push_back( nextInt);
93 }
94 else {
95 (*m_log) << MSG::WARNING <<
"LArBadChannelParser REJECTED line " <<
m_linenumber \
96 <<
":\t word " <<
i + 1 <<
" must be a non-negative integer: " <<
command[
i] <<
endmsg;
97 return false;
98 }
99 }
100
101
102 parsedLine.stringVec.insert( parsedLine.stringVec.end(),
command.begin()+nint,
command.end());
103
104 return true;
105}
bool stringToInt(int &theInt, const std::string &theStr) const
◆ parseISfile()
parse the file using the format "nint consecutive integers and then at least minString strings" and return the result as a vector of all successfully parsed lines.
The int part of a line may contain wildcards, starting from position firstWildcard; firstWildcard=-1 means "no wildcards". The wildcard character in the input file is "*", it is replaced by -1 in the parsed output. Lines that failed to parse are skipped, with diagnostic messages sent to the message stream.
Definition at line 30 of file LArBadChannelParser2.cxx.
32{
33 std::vector< LArBadChannelParser2::ISLine>
result;
34
35 while (
m_fin.good()) {
36 std::string readLine;
37 std::getline(
m_fin, readLine);
39
42 if (
parseLine( readLine, parsedLine, nint, minString, firstWildcard)) {
43 result.push_back(std::move(parsedLine));
44
45 }
46 else {
47 (*m_log) << MSG::WARNING <<
"LArBadChannelParser REJECTED line " << readLine <<
endmsg;
48 }
49 }
51}
bool parseLine(std::string &readLine, ISLine &parsedLine, int nint, int minString, int firstWildcard)
◆ parseLine()
| bool LArBadChannelParser2::parseLine |
( |
std::string & | readLine, |
|
|
ISLine & | parsedLine, |
|
|
int | nint, |
|
|
int | minString, |
|
|
int | firstWildcard ) |
|
private |
Definition at line 53 of file LArBadChannelParser2.cxx.
55{
56 std::string::size_type commentPosition = readLine.find('#');
57 if(commentPosition != std::string::npos)
58 readLine.erase(commentPosition);
59
60 std::string readWord;
61 std::vector<std::string>
command;
62
63 std::istringstream stringIn(readLine);
64 stringIn >> readWord;
65 while(stringIn) {
67 stringIn >> readWord;
68 }
70 bool success =
interpretLine( command, parsedLine, nint, minString, firstWildcard);
71 return success;
72 }
73 return false;
74}
bool interpretLine(const std::vector< std::string > &command, ISLine &parsedLine, int nint, int minString, int firstWildcard)
◆ stringToInt()
| bool LArBadChannelParser2::stringToInt |
( |
int & | theInt, |
|
|
const std::string & | theStr ) const |
|
inlineprivate |
Definition at line 65 of file LArBadChannelParser2.h.
66{
67 std::istringstream iss(theStr);
68
69
70 iss >> std::dec >> theInt;
71 return !iss.fail() && iss.eof();
72}
◆ m_filename
| const std::string LArBadChannelParser2::m_filename |
|
private |
◆ m_fin
| std::ifstream LArBadChannelParser2::m_fin |
|
private |
◆ m_linenumber
| unsigned int LArBadChannelParser2::m_linenumber |
|
private |
◆ m_log
| MsgStream* const LArBadChannelParser2::m_log |
|
private |
The documentation for this class was generated from the following files: