ATLAS Offline Software
Loading...
Searching...
No Matches
LArBadChannelParser2.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7#include "GaudiKernel/MsgStream.h"
8#include <iostream>
9
10LArBadChannelParser2::LArBadChannelParser2(const std::string& file, MsgStream* const 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
23
25{
26 return m_fin.good();
27}
28
29std::vector< LArBadChannelParser2::ISLine>
30LArBadChannelParser2::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
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}
52
53bool 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
76bool 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}
#define endmsg
bool parseLine(std::string &readLine, ISLine &parsedLine, int nint, int minString, int firstWildcard)
bool stringToInt(int &theInt, const std::string &theStr) const
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...
bool interpretLine(const std::vector< std::string > &command, ISLine &parsedLine, int nint, int minString, int firstWildcard)
const std::string m_filename
LArBadChannelParser2(const std::string &filename, MsgStream *const messager)
A parser object must be initialized with the filename that it is to parse.
bool fileStatusGood() const
You can use this function to check whether the file was successfully opened for reading.
std::vector< std::string > stringVec
TFile * file