#include <LArBadChannelParser.h>
|
| | LArBadChannelParser (const std::string &filename, MsgStream *const log, unsigned int numInts, int numStrings, unsigned int firstWildcard=0) |
| | A parser object must be initialized with the filename that it is to parse.
|
| virtual | ~LArBadChannelParser () |
| bool | fileStatusGood () const |
| | You can use this function to check whether file-reading will succeed.
|
| template<typename T> |
| std::vector< std::pair< std::vector< int >, std::vector< T > > > | parseFile () |
| | Parse the file using the following format for each line: First, exactly numInts integers are required.
|
| template<> |
| bool | convertStrings (std::vector< std::string > &result, const std::vector< std::string >::const_iterator begin, const std::vector< std::string >::const_iterator end) const |
Definition at line 11 of file LArBadChannelParser.h.
◆ LArBadChannelParser() [1/2]
| LArBadChannelParser::LArBadChannelParser |
( |
const std::string & | filename, |
|
|
MsgStream *const | log, |
|
|
unsigned int | numInts, |
|
|
int | numStrings, |
|
|
unsigned int | firstWildcard = 0 ) |
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 LArBadChannelParser.cxx.
13 :
17{
20 std::cerr << "ERROR \t LArBadChannelParser was given a NULL MsgStream pointer!" << std::endl;
21}
const unsigned int m_firstWildcard
const unsigned int m_numInts
unsigned int m_linenumber
const std::string m_filename
◆ ~LArBadChannelParser()
| LArBadChannelParser::~LArBadChannelParser |
( |
| ) |
|
|
virtual |
◆ LArBadChannelParser() [2/2]
| LArBadChannelParser::LArBadChannelParser |
( |
| ) |
|
|
private |
◆ convertStrings() [1/2]
template<>
| bool LArBadChannelParser::convertStrings |
( |
std::vector< std::string > & | result, |
|
|
const std::vector< std::string >::const_iterator | begin, |
|
|
const std::vector< std::string >::const_iterator | end ) const |
|
inline |
◆ convertStrings() [2/2]
template<typename T>
| bool LArBadChannelParser::convertStrings |
( |
std::vector< T > & | result, |
|
|
const std::vector< std::string >::const_iterator | begin, |
|
|
const std::vector< std::string >::const_iterator | end ) const |
|
inlineprivate |
Definition at line 142 of file LArBadChannelParser.h.
144{
146 result.reserve(
static_cast<unsigned int>(end - begin));
147 for(std::vector<std::string>::const_iterator iter = begin;
iter !=
end; ++
iter)
148 {
151 result.push_back(element);
152 else
153 {
154 (*m_log) << MSG::WARNING <<
"LArBadChannelParser REJECTED line " <<
m_linenumber \
155 <<
" -\t failed to extract status." <<
endmsg;
156 return false;
157 }
158 }
159 return true;
160}
bool stringToNumber(T &theNumber, const std::string &theStr) const
◆ fileStatusGood()
| bool LArBadChannelParser::fileStatusGood |
( |
| ) |
const |
|
inline |
You can use this function to check whether file-reading will succeed.
If false, parseFile() will return an empty vector.
Definition at line 74 of file LArBadChannelParser.h.
◆ getIdFields()
| std::vector< int > LArBadChannelParser::getIdFields |
( |
const std::vector< std::string > & | words | ) |
|
|
private |
Definition at line 54 of file LArBadChannelParser.cxx.
55{
59 {
61
62
63 if (i==0) {
64 std::transform(
w.begin(),
w.end(),
w.begin(),
upper);
65
66 if (
w.compare(0,3,
"EMB")==0 || w[0]==
'B')
68 else if (w[0]=='E')
70 }
71 else if (i==1) {
72 if (w=="A" || w=="a")
74 else if (w=="C" || w=="c")
76 }
77
78 int idComponent(0);
80 if(canBeWildcard && w == "*")
83 result.push_back(idComponent);
84 else
85 {
86 (*m_log) << MSG::WARNING <<
"LArBadChannelParser REJECTED line " <<
m_linenumber \
87 <<
" -\t word " <<
i + 1 <<
" must be a non-negative integer " \
88 << (canBeWildcard ? "or " : "and not " ) \
89 <<
"a wildcard: " << words[i] <<
endmsg;
92 }
93 }
95}
◆ parseFile()
template<typename T>
| std::vector< std::pair< std::vector< int >, std::vector< T > > > LArBadChannelParser::parseFile |
( |
| ) |
|
|
inline |
Parse the file using the following format for each line: First, exactly numInts integers are required.
Then, if numString is negative, at least std::abs(numString) strings are required, otherwise exactly numString strings are required. These strings are converted to a vector<T>. A vector of all successfully parsed lines is returned. The integer part of a line may contain wildcards, starting from position firstWildcard (where counting begins from 1); firstWildcard = 0 means wildcards are not allowed. The wildcard character in the input file is "*", it is replaced by -1 in the parsed output. Comments in the ASCII file are demarcated with the '#' character. Lines that fail to parse are skipped, with diagnostic messages sent to the message stream.
Definition at line 80 of file LArBadChannelParser.h.
81{
82 typedef std::pair< std::vector<int>, std::vector<T> > LineData;
83 std::vector<LineData>
result;
84
86 {
87 (*m_log) << MSG::ERROR <<
"LArBadChannelParser - Could not open file: " <<
m_filename <<
endmsg;
89 }
90
91 while(true)
92 {
94 std::getline(
m_fin, line);
96 break;
99
101 {
102 if(
input.size() != 0)
103 {(*m_log) << MSG::WARNING <<
"LArBadChannelParser REJECTED line " <<
m_linenumber \
104 <<
" -\t not enough parameters given: " <<
input.size() <<
endmsg;}
105 continue;
106 }
107
108 LineData parsedData;
109
111 if(parsedData.first.size() == 0)
112 continue;
113
115 const std::vector<std::string>::const_iterator
stop = \
116 (m_numStrings < 0) ? static_cast<const std::vector<std::string>::const_iterator>(
input.end()) : (start +
m_numStrings);
117
118 if(stop > start)
119 {
121 continue;
122 }
123
124 if(stop <
input.end())
125 (*
m_log) << MSG::WARNING <<
"LArBadChannelParser IGNORED unexpected input on line " <<
m_linenumber <<
"." <<
endmsg;
126
127 result.push_back(std::move(parsedData));
129 }
130
133}
std::vector< int > getIdFields(const std::vector< std::string > &words)
bool fileStatusGood() const
You can use this function to check whether file-reading will succeed.
std::vector< std::string > parseLine(std::string &line) const
bool convertStrings(std::vector< T > &result, const std::vector< std::string >::const_iterator begin, const std::vector< std::string >::const_iterator end) const
◆ parseLine()
| std::vector< std::string > LArBadChannelParser::parseLine |
( |
std::string & | line | ) |
const |
|
private |
Definition at line 28 of file LArBadChannelParser.cxx.
29{
30 std::string::size_type commentPosition =
line.find(
'#');
31 if(commentPosition != std::string::npos)
32 line.erase(commentPosition);
33
34
35 std::vector<std::string>
result;
36 std::string readWord;
37 std::istringstream stringIn(line);
38
39 stringIn >> readWord;
40 while(stringIn)
41 {
42 result.push_back(readWord);
43 stringIn >> readWord;
44 }
46}
◆ stringToNumber()
template<typename T>
| bool LArBadChannelParser::stringToNumber |
( |
T & | theNumber, |
|
|
const std::string & | theStr ) const |
|
inlineprivate |
Definition at line 173 of file LArBadChannelParser.h.
174{
175 std::istringstream iss(theString);
176
177 return !(iss >> std::dec >> theNumber).
fail();
178
179}
◆ m_filename
| const std::string LArBadChannelParser::m_filename |
|
private |
◆ m_fin
| std::ifstream LArBadChannelParser::m_fin |
|
private |
◆ m_firstWildcard
| const unsigned int LArBadChannelParser::m_firstWildcard |
|
private |
◆ m_linenumber
| unsigned int LArBadChannelParser::m_linenumber |
|
private |
◆ m_log
| MsgStream* const LArBadChannelParser::m_log |
|
private |
◆ m_numInts
| const unsigned int LArBadChannelParser::m_numInts |
|
private |
◆ m_numStrings
| const int LArBadChannelParser::m_numStrings |
|
private |
The documentation for this class was generated from the following files: