ATLAS Offline Software
Loading...
Searching...
No Matches
LArBadChannelParser.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7#include <sstream>
8#include <algorithm>
9
11 const std::string& file, MsgStream* const log,
12 unsigned int numInts, int numStrings, unsigned int firstWildcard
13 ) :
15 m_numInts(numInts), m_numStrings(numStrings),
16 m_firstWildcard(firstWildcard)
17{
18 m_fin.open(m_filename.c_str());
19 if(!m_log)
20 std::cerr << "ERROR \t LArBadChannelParser was given a NULL MsgStream pointer!" << std::endl;
21}
22
27
28std::vector<std::string> LArBadChannelParser::parseLine(std::string& line) const
29{
30 std::string::size_type commentPosition = line.find('#');
31 if(commentPosition != std::string::npos) //if a comment is found
32 line.erase(commentPosition); //trim off the comment
33 // notice that the input parameter can be changed as a side-effect
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 }
45 return result;
46}
47
48
49int upper(int c) {
50 return std::toupper((unsigned char)c);
51}
52
53
54std::vector<int> LArBadChannelParser::getIdFields(const std::vector<std::string>& words)
55{
56 std::vector<int> result;
57 std::string w;
58 for(unsigned int i = 0; i < m_numInts; ++i)
59 {
60 w=words[i]; //Copy to non-const string
61
62 //Allow 'B' or 'EMB' for Barrel or 'E' for Endcap in first field
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')
67 w=std::string("0"); //Replace for barrel
68 else if (w[0]=='E')
69 w=std::string("1"); //Replace for endcap
70 }
71 else if (i==1) { //Allow 'A' and 'C' do describe side in second field
72 if (w=="A" || w=="a")
73 w=std::string("1"); //Replace for positive side
74 else if (w=="C" || w=="c")
75 w=std::string("0"); //Replace for negative side
76 }
77
78 int idComponent(0);
79 bool canBeWildcard(m_firstWildcard > 0 && i + 1 >= m_firstWildcard);
80 if(canBeWildcard && w == "*")
81 result.push_back(-1); // -1 signifies wildcard
82 else if(stringToNumber<int>(idComponent, w) && idComponent >= 0)
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;
90 result.clear();
91 return result; // return empty vector on error
92 }
93 }
94 return result;
95}
#define endmsg
int upper(int c)
std::vector< int > getIdFields(const std::vector< std::string > &words)
const unsigned int m_firstWildcard
std::vector< std::string > parseLine(std::string &line) const
bool stringToNumber(T &theNumber, const std::string &theStr) const
const unsigned int m_numInts
const std::string m_filename
TFile * file