ATLAS Offline Software
LArBadChannelDecoder.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
8 #include "GaudiKernel/MsgStream.h"
10 
11 std::vector<LArBadChannelDecoder::BadChanEntry>
13  State::CoolChannelEnum coolChan,
14  MsgStream& log) const
15 {
16  std::vector<BadChanEntry> result;
17 
18  // set up parsing with exactly 6 ints and >= 1 string, for reading channels
20  if (!parser.fileStatusGood()) {
21  log << MSG::ERROR << "Failed to open file " << fname
22  << " for COOL channel " << State::coolChannelName( coolChan) << endmsg;
23  return result;
24  }
25 
26  typedef std::string ParseType;
27  typedef std::pair<std::vector<int>, std::vector<ParseType> > ParsedLine;
28  std::vector<ParsedLine> parsed = parser.parseFile<ParseType>();
29  log << MSG::INFO << "Parsed " << parsed.size() << " lines from file " << fname << endmsg;
30 
31  for (std::vector<ParsedLine>::const_iterator i=parsed.begin();
32  i != parsed.end(); ++i) {
33  HWIdentifier hwid = constructChannelId( i->first, coolChan, log);
34  if (hwid.is_valid()) {
35  std::pair<bool,LArBadChannel> badCh = constructStatus( i->second, log);
36  if (badCh.first) {
37  result.emplace_back( hwid, badCh.second);
38  }
39  }
40  }
41  return result;
42 }
43 
44 std::vector<LArBadChannelDecoder::BadFebEntry>
46  MsgStream& log) const
47 {
48  std::vector<BadFebEntry> result;
49 
50  // set up a parser to read 4 ints (the 4th of which can be a wildcard) and >=1 strings
51  LArBadChannelParser parser(fname, &log, 4, -1, 4);
52  if (!parser.fileStatusGood()) {
53  log << MSG::ERROR << "Failed to open missing FEBs file " << fname << endmsg;
54  return result;
55  }
56 
57  typedef std::string ParseType;
58  typedef std::pair<std::vector<int>, std::vector<ParseType> > ParsedLine;
59  std::vector<ParsedLine> parsed = parser.parseFile<ParseType>();
60  for (std::vector<ParsedLine>::const_iterator i=parsed.begin();
61  i != parsed.end(); ++i) {
62  std::vector<HWIdentifier> hwid = constructFebId( i->first, log);
63  if (!hwid.empty()) {
64  // BEFORE: result.insert( result.end(), hwid.begin(), hwid.end());
65  std::pair<bool,LArBadFeb> badFeb = constructFebStatus( i->second, log);
66  if (badFeb.first) {
67  for (std::vector<HWIdentifier>::const_iterator i=hwid.begin(); i!=hwid.end(); ++i) {
68  result.emplace_back( *i, badFeb.second);
69  }
70  }
71  }
72  }
73  return result;
74 }
75 
76 HWIdentifier LArBadChannelDecoder::constructChannelId( const std::vector<int>& intVec,
77  State::CoolChannelEnum coolChan,
78  MsgStream& log) const
79 {
80  HWIdentifier invalid;
81  if (intVec.size() < 5) { // redundant error check
82  log << MSG::WARNING << "Failed to produce a channel HWIdentifier for ";
83  for (unsigned int i=0; i<intVec.size(); i++) log << intVec[i] << " ";
84  log << "not enough identifiers" << endmsg;
85  return invalid;
86  }
87  try {
88  HWIdentifier hwid( m_onlineID->channel_Id( intVec[barrel_ec], intVec[pos_neg], intVec[feedthrough],
89  intVec[slot], intVec[channel], true));
90  if (coolChan<LArBadChannelState::MAXCOOLCHAN && !checkId( hwid, intVec[barrel_ec], intVec[pos_neg], coolChan)) {
91  log << MSG::WARNING << "Channel "; insertExpandedID( intVec, log);
92  log << " does not belong to COOL channel " << State::coolChannelName( coolChan)
93  << ". Skipped" << endmsg;
94  return invalid;
95  }
96  log << MSG::DEBUG << "Translating id "; insertExpandedID( intVec, log);
97  log << " to 0x" << MSG::hex << hwid << MSG::dec << endmsg;
98  return hwid;
99  }
100  catch( LArOnlID_Exception& idException) {
101  log << MSG::ERROR << "Failed to produce a HWIdentifier for "; insertExpandedID( intVec, log) << endmsg;
102  }
103  return invalid;
104 }
105 
106 std::vector<HWIdentifier> LArBadChannelDecoder::constructFebId( const std::vector<int>& intVec,
107  MsgStream& log) const
108 {
109  const int maxFebPerFT = 15; // hard-wired number of slots per feed-through
110 
111  std::vector<HWIdentifier> result;
112  if (intVec.size() != 4) { // redundant error check
113  log << MSG::WARNING << "Failed to produce a FEB HWIdentifier for ";
114  for (unsigned int i=0; i<intVec.size(); i++) log << intVec[i] << " ";
115  log << "not enough identifiers" << endmsg;
116  return result;
117  }
118 
119  // expand wildcard
120  if (intVec[slot] == -1) {
121  std::vector<int> vec( intVec); // modifiable copy
122 
123  // FEB slot counting starts at 1
124  for (vec[slot]=1; vec[slot] <= maxFebPerFT; vec[slot]++) {
125 
127  if (hwid.is_valid()) result.push_back( hwid);
128  }
129  }
130  else{
131  HWIdentifier hwid = constructSingleFebId( intVec, log);
132  if (hwid.is_valid()) result.push_back( hwid);
133  }
134  return result;
135 }
136 
138  MsgStream& log) const
139 {
140  HWIdentifier invalid;
141  if (v.size() != 4) return invalid;
142  try {
144  log << MSG::DEBUG << "Translating FEB id "; insertExpandedID( v, log);
145  log << " to 0x" << MSG::hex << hwid << MSG::dec << endmsg;
146  return hwid;
147  }
148  catch( LArOnlID_Exception& idException) {
149  log << MSG::ERROR << "Failed to produce a FEB HWIdentifier for "; insertExpandedID( v, log);
150  log << endmsg;
151  }
152  return invalid;
153 }
154 
155 std::pair<bool,LArBadChannel>
156 LArBadChannelDecoder::constructStatus( const std::vector<std::string>& vec, MsgStream& log) const
157 {
159  for(std::vector<std::string>::const_iterator it = vec.begin(); it != vec.end(); ++it) {
160  bool ok = false;
161  if(m_isSC)
162  ok = m_SCpacking.setBit( *it, result);
163  else
164  ok = m_packing.setBit( *it, result);
165  if (!ok) {
166  log << MSG::WARNING << "LArBadChannelDecoder REJECTED line with "
167  << ":\t unrecognized problem status: " << *it << endmsg;
168  return std::pair<bool,LArBadChannel>(false,result); // exit on error
169  }
170  }
171  return std::pair<bool,LArBadChannel>(true,result);
172 }
173 
174 std::pair<bool,LArBadFeb>
175 LArBadChannelDecoder::constructFebStatus( const std::vector<std::string>& vec,
176  MsgStream& log) const
177 {
179  for(std::vector<std::string>::const_iterator it = vec.begin(); it != vec.end(); ++it) {
180  bool ok = m_febPacking.setBit( *it, result);
181  if (!ok) {
182  log << MSG::WARNING << "LArBadChannelDecoder REJECTED line with "
183  << ":\t unrecognized problem status: " << *it << endmsg;
184  return std::pair<bool,LArBadFeb>(false,result); // exit on error
185  }
186  }
187  return std::pair<bool,LArBadFeb>(true,result);
188 }
189 
190 
191 MsgStream& LArBadChannelDecoder::insertExpandedID( const std::vector<int>& intVec, MsgStream& log)
192 {
193  log << " b/e " << intVec[barrel_ec]
194  << " p/n " << intVec[pos_neg]
195  << " ft " << intVec[feedthrough]
196  << " slot " << intVec[slot];
197  if (intVec.size() >= 5) log << " ch " << intVec[channel]; // no endmsg,
198  return log;
199 }
200 
201 bool LArBadChannelDecoder::checkId( const HWIdentifier& id, int barrel_ec, int pos_neg,
202  State::CoolChannelEnum coolCh) const
203 {
204  if (barrel_ec != State::barrelEndcap(coolCh)) return false; // first check barrel/ec (faster)
205  if (pos_neg != State::posNeg(coolCh)) return false; // then check side (faster)
206  if (m_onlineID->isEMBchannel(id) && State::caloPart(coolCh)==State::EMB) return true;
207  if (m_onlineID->isEMECchannel(id) && State::caloPart(coolCh)==State::EMEC) return true;
208  if (m_onlineID->isHECchannel(id) && State::caloPart(coolCh)==State::HEC) return true;
209  if (m_onlineID->isFCALchannel(id) && State::caloPart(coolCh)==State::FCAL) return true;
210  return false;
211 }
python.CaloScaleNoiseConfig.parser
parser
Definition: CaloScaleNoiseConfig.py:75
get_generator_info.result
result
Definition: get_generator_info.py:21
LArBadChannelState::caloPart
static CaloPartEnum caloPart(CoolChannelEnum chan)
Definition: LArBadChannelState.h:150
LArBadChannelState::HEC
@ HEC
Definition: LArBadChannelState.h:21
LArOnlineID_Base.h
LArG4FSStartPointFilterLegacy.parsed
list parsed
Definition: LArG4FSStartPointFilterLegacy.py:128
skel.it
it
Definition: skel.GENtoEVGEN.py:423
LArBadChannelState::barrelEndcap
static int barrelEndcap(CoolChannelEnum chan)
Definition: LArBadChannelState.h:145
LArBadChannelDecoder.h
LArBadChannelState::posNeg
static int posNeg(CoolChannelEnum chan)
Definition: LArBadChannelState.h:154
LArBadChannelDecoder::slot
@ slot
Definition: LArBadChannelDecoder.h:40
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
LArBadChannelDecoder::insertExpandedID
static MsgStream & insertExpandedID(const std::vector< int > &intVec, MsgStream &log)
Definition: LArBadChannelDecoder.cxx:191
LArBadChannelDecoder::m_SCpacking
LArBadChanSCBitPacking m_SCpacking
Definition: LArBadChannelDecoder.h:44
HWIdentifier
Definition: HWIdentifier.h:13
Identifier::is_valid
bool is_valid() const
Check if id is in a valid state.
LArBadChannelDecoder::m_febPacking
LArBadFebBitPacking m_febPacking
Definition: LArBadChannelDecoder.h:45
LArBadChannelDecoder::m_packing
LArBadChanBitPacking m_packing
Definition: LArBadChannelDecoder.h:43
LArBadChannelParser
Definition: LArBadChannelParser.h:12
LArBadChannelDecoder::m_onlineID
const LArOnlineID_Base * m_onlineID
Definition: LArBadChannelDecoder.h:42
CxxUtils::vec
typename vecDetail::vec_typedef< T, N >::type vec
Define a nice alias for the vectorized type.
Definition: vec.h:207
LArOnlineID_Base::isFCALchannel
bool isFCALchannel(const HWIdentifier id) const
Definition: LArOnlineID_Base.cxx:1657
LArBadChannelState::FCAL
@ FCAL
Definition: LArBadChannelState.h:21
lumiFormat.i
int i
Definition: lumiFormat.py:92
LArBadChannelDecoder::channel
@ channel
Definition: LArBadChannelDecoder.h:40
LArOnlineID_Base::isHECchannel
virtual bool isHECchannel(const HWIdentifier id) const =0
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
LArBadChannelState::EMB
@ EMB
Definition: LArBadChannelState.h:21
LArOnlID_Exception
Exception class for LAr online Identifiers.
Definition: LArOnlID_Exception.h:16
LArBadChannel
Definition: LArBadChannel.h:10
LArBadChannelDecoder::constructSingleFebId
HWIdentifier constructSingleFebId(const std::vector< int > &v, MsgStream &log) const
Definition: LArBadChannelDecoder.cxx:137
LArOnlineID_Base::channel_Id
HWIdentifier channel_Id(int barrel_ec, int pos_neg, int feedthrough, int slot, int channel) const
create channel identifier from fields
Definition: LArOnlineID_Base.cxx:1569
LArBadChannelDecoder::constructChannelId
HWIdentifier constructChannelId(const std::vector< int > &intVec, State::CoolChannelEnum coolChan, MsgStream &log) const
Definition: LArBadChannelDecoder.cxx:76
LArBadFebBitPacking::setBit
void setBit(ProblemType pb, BitWord &word, bool value=true) const
Definition: LArBadFebBitPacking.cxx:58
LArBadChannelDecoder::constructStatus
std::pair< bool, LArBadChannel > constructStatus(const std::vector< std::string > &vec, MsgStream &log) const
Definition: LArBadChannelDecoder.cxx:156
LArBadChannelDecoder::barrel_ec
@ barrel_ec
Definition: LArBadChannelDecoder.h:40
LArOnlineID_Base::feb_Id
HWIdentifier feb_Id(int barrel_ec, int pos_neg, int feedthrough, int slot) const
Create feb_Id from fields.
Definition: LArOnlineID_Base.cxx:1483
LArBadChannelState::coolChannelName
static std::string coolChannelName(CoolChannelEnum chan)
Definition: LArBadChannelState.cxx:40
LArOnlineID_Base::isEMECchannel
virtual bool isEMECchannel(const HWIdentifier id) const =0
LArBadFeb
Definition: LArBadFeb.h:10
LArBadChannelDecoder::checkId
bool checkId(const HWIdentifier &, int be, int pn, State::CoolChannelEnum) const
Definition: LArBadChannelDecoder.cxx:201
LArBadChannelDecoder::constructFebId
std::vector< HWIdentifier > constructFebId(const std::vector< int > &intVec, MsgStream &log) const
Definition: LArBadChannelDecoder.cxx:106
LArBadChannelDecoder::m_isSC
bool m_isSC
Definition: LArBadChannelDecoder.h:47
LArOnlineID_Base::isEMBchannel
bool isEMBchannel(const HWIdentifier id) const
Definition: LArOnlineID_Base.cxx:1652
LArBadChannelDecoder::pos_neg
@ pos_neg
Definition: LArBadChannelDecoder.h:40
python.AthDsoLogger.fname
string fname
Definition: AthDsoLogger.py:67
python.PyAthena.v
v
Definition: PyAthena.py:157
LArBadChannelState::CoolChannelEnum
CoolChannelEnum
Definition: LArBadChannelState.h:23
LArBadChannelDecoder::feedthrough
@ feedthrough
Definition: LArBadChannelDecoder.h:40
LArBadChannelDecoder::readASCII
std::vector< BadChanEntry > readASCII(const std::string &name, State::CoolChannelEnum coolChan, MsgStream &log) const
Definition: LArBadChannelDecoder.cxx:12
LArBadChannelDecoder::readFebASCII
std::vector< BadFebEntry > readFebASCII(const std::string &fname, MsgStream &log) const
Definition: LArBadChannelDecoder.cxx:45
DEBUG
#define DEBUG
Definition: page_access.h:11
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
LArBadChannelDecoder::constructFebStatus
std::pair< bool, LArBadFeb > constructFebStatus(const std::vector< std::string > &vec, MsgStream &log) const
Definition: LArBadChannelDecoder.cxx:175
LArBadChannelParser.h
TLArBadChanBitPackingBase::setBit
void setBit(typename T::ProblemType pb, LArBadChannel::BitWord &word, bool value=true) const
LArBadChannelState::EMEC
@ EMEC
Definition: LArBadChannelState.h:21
LArBadChannelState::MAXCOOLCHAN
@ MAXCOOLCHAN
Definition: LArBadChannelState.h:23