ATLAS Offline Software
Loading...
Searching...
No Matches
LArBadChannelParser2 Class Reference

#include <LArBadChannelParser2.h>

Collaboration diagram for LArBadChannelParser2:

Classes

struct  ISLine

Public Member Functions

 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< ISLineparseISfile (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.

Private Member Functions

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

Private Attributes

std::ifstream m_fin
unsigned int m_linenumber
const std::string m_filename
MsgStream *const m_log

Detailed Description

Definition at line 15 of file LArBadChannelParser2.h.

Constructor & Destructor Documentation

◆ 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{
13 m_fin.open(m_filename.c_str());
14 if(!m_log) {
15 std::cerr << "WARNING \t LArBadChannelParser was given a NULL MsgStream pointer!" << std::endl;
16 }
17}
const std::string m_filename
TFile * file

◆ ~LArBadChannelParser2()

LArBadChannelParser2::~LArBadChannelParser2 ( )

Definition at line 19 of file LArBadChannelParser2.cxx.

20{
21 m_fin.close();
22}

Member Function Documentation

◆ 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.

25{
26 return m_fin.good();
27}

◆ 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 // just copy the remaining words to the string vector
102 parsedLine.stringVec.insert( parsedLine.stringVec.end(), command.begin()+nint, command.end());
103
104 return true;
105}
#define endmsg
bool stringToInt(int &theInt, const std::string &theStr) const

◆ parseISfile()

std::vector< LArBadChannelParser2::ISLine > LArBadChannelParser2::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.

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);
38 if(!m_fin.good()) return result;
39
41 ISLine parsedLine;
42 if (parseLine( readLine, parsedLine, nint, minString, firstWildcard)) {
43 result.push_back(std::move(parsedLine));
44 // (*m_log) << MSG::DEBUG << "LArBadChannelParser ACCEPTED line " << readLine << endmsg;
45 }
46 else {
47 (*m_log) << MSG::WARNING << "LArBadChannelParser REJECTED line " << readLine << endmsg;
48 }
49 }
50 return result;
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) //if a comment is found
58 readLine.erase(commentPosition); //trim off the comment
59
60 std::string readWord;
61 std::vector<std::string> command;
62
63 std::istringstream stringIn(readLine);
64 stringIn >> readWord;
65 while(stringIn) {
66 command.push_back(readWord);
67 stringIn >> readWord;
68 }
69 if(!command.empty()) {
70 bool success = interpretLine( command, parsedLine, nint, minString, firstWildcard);
71 return success;
72 }
73 return false; // empty command
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 //the second condition checks for invalid input of the form "123abc"
69 //return !(iss >> std::dec >> theInt).fail() && (static_cast<int>(theStr.size()) == iss.tellg());
70 iss >> std::dec >> theInt;
71 return !iss.fail() && iss.eof();
72}

Member Data Documentation

◆ m_filename

const std::string LArBadChannelParser2::m_filename
private

Definition at line 52 of file LArBadChannelParser2.h.

◆ m_fin

std::ifstream LArBadChannelParser2::m_fin
private

Definition at line 50 of file LArBadChannelParser2.h.

◆ m_linenumber

unsigned int LArBadChannelParser2::m_linenumber
private

Definition at line 51 of file LArBadChannelParser2.h.

◆ m_log

MsgStream* const LArBadChannelParser2::m_log
private

Definition at line 53 of file LArBadChannelParser2.h.


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