ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
LArCalorimeter
LArBadChannelTool
src
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
5
#include "
LArBadChannelTool/LArBadChannelDecoder.h
"
6
7
#include "
LArRecConditions/LArBadChannelParser.h
"
8
#include "GaudiKernel/MsgStream.h"
9
#include "
LArIdentifier/LArOnlineID_Base.h
"
10
#include "
LArIdentifier/LArOnlID_Exception.h
"
11
12
std::vector<LArBadChannelDecoder::BadChanEntry>
13
LArBadChannelDecoder::readASCII
(
const
std::string& fname,
14
State::CoolChannelEnum
coolChan,
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
45
std::vector<LArBadChannelDecoder::BadFebEntry>
46
LArBadChannelDecoder::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
77
HWIdentifier
LArBadChannelDecoder::constructChannelId
(
const
std::vector<int>& intVec,
78
State::CoolChannelEnum
coolChan,
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
107
std::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
127
HWIdentifier
hwid =
constructSingleFebId
(
vec
, log);
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
138
HWIdentifier
LArBadChannelDecoder::constructSingleFebId
(
const
std::vector<int>& v,
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
156
std::pair<bool,LArBadChannel>
157
LArBadChannelDecoder::constructStatus
(
const
std::vector<std::string>&
vec
, MsgStream& log)
const
158
{
159
LArBadChannel
result;
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
175
std::pair<bool,LArBadFeb>
176
LArBadChannelDecoder::constructFebStatus
(
const
std::vector<std::string>&
vec
,
177
MsgStream& log)
const
178
{
179
LArBadFeb
result;
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
192
MsgStream&
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
202
bool
LArBadChannelDecoder::checkId
(
const
HWIdentifier
&
id
,
int
barrel_ec
,
int
pos_neg
,
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
}
endmsg
#define endmsg
Definition
AnalysisConfig_Ntuple.cxx:54
vec
std::vector< size_t > vec
Definition
CombinationsGeneratorTest.cxx:9
LArBadChannelDecoder.h
LArBadChannelParser.h
LArOnlID_Exception.h
LArOnlineID_Base.h
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
LArBadChannelDecoder::constructSingleFebId
HWIdentifier constructSingleFebId(const std::vector< int > &v, MsgStream &log) const
Definition
LArBadChannelDecoder.cxx:138
LArBadChannelDecoder::readFebASCII
std::vector< BadFebEntry > readFebASCII(const std::string &fname, MsgStream &log) const
Definition
LArBadChannelDecoder.cxx:46
LArBadChannelDecoder::constructFebStatus
std::pair< bool, LArBadFeb > constructFebStatus(const std::vector< std::string > &vec, MsgStream &log) const
Definition
LArBadChannelDecoder.cxx:176
LArBadChannelDecoder::readASCII
std::vector< BadChanEntry > readASCII(const std::string &name, State::CoolChannelEnum coolChan, MsgStream &log) const
Definition
LArBadChannelDecoder.cxx:13
LArBadChannelDecoder::m_SCpacking
LArBadChanSCBitPacking m_SCpacking
Definition
LArBadChannelDecoder.h:44
LArBadChannelDecoder::m_isSC
bool m_isSC
Definition
LArBadChannelDecoder.h:47
LArBadChannelDecoder::constructChannelId
HWIdentifier constructChannelId(const std::vector< int > &intVec, State::CoolChannelEnum coolChan, MsgStream &log) const
Definition
LArBadChannelDecoder.cxx:77
LArBadChannelDecoder::constructStatus
std::pair< bool, LArBadChannel > constructStatus(const std::vector< std::string > &vec, MsgStream &log) const
Definition
LArBadChannelDecoder.cxx:157
LArBadChannelDecoder::m_onlineID
const LArOnlineID_Base * m_onlineID
Definition
LArBadChannelDecoder.h:42
LArBadChannelDecoder::insertExpandedID
static MsgStream & insertExpandedID(const std::vector< int > &intVec, MsgStream &log)
Definition
LArBadChannelDecoder.cxx:192
LArBadChannelDecoder::constructFebId
std::vector< HWIdentifier > constructFebId(const std::vector< int > &intVec, MsgStream &log) const
Definition
LArBadChannelDecoder.cxx:107
LArBadChannelDecoder::barrel_ec
@ barrel_ec
Definition
LArBadChannelDecoder.h:40
LArBadChannelDecoder::channel
@ channel
Definition
LArBadChannelDecoder.h:40
LArBadChannelDecoder::slot
@ slot
Definition
LArBadChannelDecoder.h:40
LArBadChannelDecoder::pos_neg
@ pos_neg
Definition
LArBadChannelDecoder.h:40
LArBadChannelDecoder::feedthrough
@ feedthrough
Definition
LArBadChannelDecoder.h:40
LArBadChannelDecoder::checkId
bool checkId(const HWIdentifier &, int be, int pn, State::CoolChannelEnum) const
Definition
LArBadChannelDecoder.cxx:202
LArBadChannelParser
Definition
LArBadChannelParser.h:12
LArBadChannelState::CoolChannelEnum
CoolChannelEnum
Definition
LArBadChannelState.h:23
LArBadChannelState::MAXCOOLCHAN
@ MAXCOOLCHAN
Definition
LArBadChannelState.h:23
LArBadChannelState::HEC
@ HEC
Definition
LArBadChannelState.h:21
LArBadChannelState::FCAL
@ FCAL
Definition
LArBadChannelState.h:21
LArBadChannelState::EMB
@ EMB
Definition
LArBadChannelState.h:21
LArBadChannelState::EMEC
@ EMEC
Definition
LArBadChannelState.h:21
LArBadChannelState::caloPart
static CaloPartEnum caloPart(CoolChannelEnum chan)
Definition
LArBadChannelState.h:150
LArBadChannelState::coolChannelName
static std::string coolChannelName(CoolChannelEnum chan)
Definition
LArBadChannelState.cxx:40
LArBadChannelState::barrelEndcap
static int barrelEndcap(CoolChannelEnum chan)
Definition
LArBadChannelState.h:145
LArBadChannelState::posNeg
static int posNeg(CoolChannelEnum chan)
Definition
LArBadChannelState.h:154
LArBadChannel
Definition
LArBadChannel.h:10
LArBadFeb
Definition
LArBadFeb.h:10
LArOnlID_Exception
Exception class for LAr online Identifiers.
Definition
LArOnlID_Exception.h:16
Generated on
for ATLAS Offline Software by
1.17.0