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