ATLAS Offline Software
LArBadChannelParser2.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include "GaudiKernel/MsgStream.h"
8 #include <iostream>
9 
10 LArBadChannelParser2::LArBadChannelParser2(const std::string& file, MsgStream* const log) :
11  m_linenumber(0), m_filename(file), m_log(log)
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 }
18 
20 {
21  m_fin.close();
22 }
23 
25 {
26  return m_fin.good();
27 }
28 
29 std::vector< LArBadChannelParser2::ISLine>
30 LArBadChannelParser2::parseISfile( int nint, int minString,
31  int firstWildcard)
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 
40  ++m_linenumber;
41  ISLine parsedLine;
42  if (parseLine( readLine, parsedLine, nint, minString, firstWildcard)) {
43  result.push_back(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 }
52 
53 bool LArBadChannelParser2::parseLine( std::string& readLine, ISLine& parsedLine,
54  int nint, int minString, int firstWildcard)
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 }
75 
76 bool LArBadChannelParser2::interpretLine( const std::vector<std::string>& command,
77  ISLine& parsedLine,
78  int nint, int minString, int firstWildcard)
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 }
LArBadChannelParser2::interpretLine
bool interpretLine(const std::vector< std::string > &command, ISLine &parsedLine, int nint, int minString, int firstWildcard)
Definition: LArBadChannelParser2.cxx:76
get_generator_info.result
result
Definition: get_generator_info.py:21
LArBadChannelParser2.h
LArBadChannelParser2::stringToInt
bool stringToInt(int &theInt, const std::string &theStr) const
Definition: LArBadChannelParser2.h:65
LArBadChannelParser2::ISLine
Definition: LArBadChannelParser2.h:18
LArBadChannelParser2::m_fin
std::ifstream m_fin
Definition: LArBadChannelParser2.h:50
LArBadChannelParser2::ISLine::intVec
std::vector< int > intVec
Definition: LArBadChannelParser2.h:19
lumiFormat.i
int i
Definition: lumiFormat.py:92
LArBadChannelParser2::fileStatusGood
bool fileStatusGood() const
You can use this function to check whether the file was successfully opened for reading.
Definition: LArBadChannelParser2.cxx:24
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
LArBadChannelParser2::m_filename
const std::string m_filename
Definition: LArBadChannelParser2.h:52
file
TFile * file
Definition: tile_monitor.h:29
LArBadChannelParser2::~LArBadChannelParser2
~LArBadChannelParser2()
Definition: LArBadChannelParser2.cxx:19
LArBadChannelParser2::LArBadChannelParser2
LArBadChannelParser2(const std::string &filename, MsgStream *const messager)
A parser object must be initialized with the filename that it is to parse.
Definition: LArBadChannelParser2.cxx:10
LArBadChannelParser2::m_log
MsgStream *const m_log
Definition: LArBadChannelParser2.h:53
LArBadChannelParser2::m_linenumber
unsigned int m_linenumber
Definition: LArBadChannelParser2.h:51
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
LArBadChannelParser2::parseISfile
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 r...
Definition: LArBadChannelParser2.cxx:30
LArBadChannelParser2::parseLine
bool parseLine(std::string &readLine, ISLine &parsedLine, int nint, int minString, int firstWildcard)
Definition: LArBadChannelParser2.cxx:53
get_generator_info.command
string command
Definition: get_generator_info.py:38
LArBadChannelParser2::ISLine::stringVec
std::vector< std::string > stringVec
Definition: LArBadChannelParser2.h:20