ATLAS Offline Software
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  ) :
14  m_linenumber(0), m_filename(file), m_log(log),
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 
24 {
25  m_fin.close();
26 }
27 
28 std::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 
49 int upper(int c) {
50  return std::toupper((unsigned char)c);
51 }
52 
53 
54 std::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 }
LArBadChannelParser::m_log
MsgStream *const m_log
Definition: LArBadChannelParser.h:65
get_generator_info.result
result
Definition: get_generator_info.py:21
collListGuids.line
string line
Definition: collListGuids.py:77
LArBadChannelParser::~LArBadChannelParser
virtual ~LArBadChannelParser()
Definition: LArBadChannelParser.cxx:23
upper
int upper(int c)
Definition: LArBadChannelParser.cxx:49
LArBadChannelParser::m_filename
const std::string m_filename
Definition: LArBadChannelParser.h:64
LArBadChannelParser::getIdFields
std::vector< int > getIdFields(const std::vector< std::string > &words)
Definition: LArBadChannelParser.cxx:54
LArBadChannelParser::parseLine
std::vector< std::string > parseLine(std::string &line) const
Definition: LArBadChannelParser.cxx:28
lumiFormat.i
int i
Definition: lumiFormat.py:85
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
Amg::transform
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
Definition: GeoPrimitivesHelpers.h:156
file
TFile * file
Definition: tile_monitor.h:29
LArBadChannelParser::m_numInts
const unsigned int m_numInts
Definition: LArBadChannelParser.h:67
LArBadChannelParser::LArBadChannelParser
LArBadChannelParser()
PlotCalibFromCool.words
words
Definition: PlotCalibFromCool.py:51
LArBadChannelParser::m_linenumber
unsigned int m_linenumber
Definition: LArBadChannelParser.h:63
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
LArBadChannelParser::m_fin
std::ifstream m_fin
Definition: LArBadChannelParser.h:62
LArBadChannelParser.h
python.IoTestsLib.w
def w
Definition: IoTestsLib.py:200
python.compressB64.c
def c
Definition: compressB64.py:93
LArBadChannelParser::m_firstWildcard
const unsigned int m_firstWildcard
Definition: LArBadChannelParser.h:69