ATLAS Offline Software
LArBadEventCatcher.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 
13 
14 LArBadEventCatcher::LArBadEventCatcher(const std::string & name, ISvcLocator * pSvcLocator) :
15  AthAlgorithm(name,pSvcLocator),
16  m_onlineID(0),
17  m_thisSize(0)
18 {
19  m_keyList.push_back("HIGH");
20  m_keyList.push_back("MEDIUM");
21  m_keyList.push_back("LOW");
22 
23  declareProperty("CheckDigitCont",m_checkDigits=false);
24  declareProperty("CheckAccCalibDigitCont",m_checkAccCalibDigits=false);
25  declareProperty("CheckFebHeader",m_checkFebHeaders=false);
26  declareProperty("CheckBSErrors",m_checkBSErrors=false);
27  declareProperty("KeyList",m_keyList);
28  declareProperty("StopOnError",m_stopOnError=true);
29 
30 
31  m_nDigits=0;
33  m_nFebheaders=0;
34  m_nEvent=0;
36  m_stopJob=false;
37  m_thisSize=0;
38 }
39 
40 
42 }
43 
44 
46 
48  ATH_MSG_WARNING ("All checks switched off ?!");
49 
50  ATH_MSG_INFO ("LArBadEventChacher initialized");
51 
52 
54 
56  StatusCode sc = detStore()->retrieve(m_onlineID, "LArOnlineID");
57  if (sc.isFailure()) {
58  ATH_MSG_ERROR ("Could not get LArOnlineID helper !");
59  return StatusCode::FAILURE;
60  }
61 
62  return StatusCode::SUCCESS;
63 }
64 
66 
68  m_thisSize=0;
69  else
70  m_thisSize=1; //Assume non-empty event if no event-container is checked
71 
72  if (m_checkDigits) {
73  for (size_t i=0;i<m_keyList.size();++i) {
74  if (evtStore()->contains<LArDigitContainer>(m_keyList[i])) {
75  const LArDigitContainer* cont;
76  StatusCode sc=evtStore()->retrieve(cont,m_keyList[i]);
77  if (sc.isFailure()) {
78  ATH_MSG_ERROR ("Can't retrieve LArDigitContainer with key " << m_keyList[i]);
79  return StatusCode::FAILURE;
80  }
81  const size_t currSize=cont->size();
82  m_thisSize=currSize;
83  if (currSize>0) { //We ignore emtpy containers
84  if (m_nDigits==0) m_nDigits=currSize; //Apparently the first event with an non-empty container
85  if (m_nDigits!=currSize) {
86  ATH_MSG_FATAL (eventDetails() <<"Mismatch in size of LArDigitContainer: Have " << currSize << " elements, expected " << m_nDigits);
87  m_stopJob=true;
88  if (m_stopOnError)
89  return StatusCode::FAILURE;
90  } //end if have mismatch
91  }//end if currSize>0
92  }//end if storeGate->contains
93  }//end loop over keys
94  }//end if m_checkDigits
95 
96 
97  if (m_checkFebHeaders) {
98  for (size_t i=0;i<m_keyList.size();++i) {
99  if (evtStore()->contains<LArFebHeaderContainer>(m_keyList[i])) {
100  const LArFebHeaderContainer* cont;
101  StatusCode sc=evtStore()->retrieve(cont,m_keyList[i]);
102  if (sc.isFailure()) {
103  ATH_MSG_ERROR ("Can't retrieve LArFebHeaderContainer with key " << m_keyList[i]);
104  return StatusCode::FAILURE;
105  }
106  const size_t currSize=cont->size();
107  if (currSize>0) { //We ignore emtpy containers
108  if (m_nFebheaders==0) m_nFebheaders=currSize; //Apparently the first event with an non-empty container
109  if (m_nFebheaders!=currSize) {
110  ATH_MSG_FATAL (eventDetails() << "Mismatch in size of LArFebHeaderContainer: Have " << currSize << " elements, expected " << m_nFebheaders);
111  m_stopJob=true;
112  if (m_stopOnError)
113  return StatusCode::FAILURE;
114  } //end if have mismatch
115  }//end if currSize>0
116  }//end if storeGate->contains
117  }//end loop over keys
118  }//end if m_checkFebHeaders
119 
120 
121 
122  if (m_checkAccCalibDigits) {
123  for (size_t i=0;i<m_keyList.size();++i) {
124  if (evtStore()->contains<LArAccumulatedCalibDigitContainer>(m_keyList[i])) {
126  StatusCode sc=evtStore()->retrieve(cont,m_keyList[i]);
127  if (sc.isFailure()) {
128  ATH_MSG_ERROR ("Can't retrieve LArAccumulatedCalibDigitContainer with key " << m_keyList[i]);
129  return StatusCode::FAILURE;
130  }
131  const size_t currSize=cont->size();
132  m_thisSize=currSize;
133  if (currSize>0) { //We ignore emtpy containers
134  if (m_nAccCalibDigits==0) m_nAccCalibDigits=currSize; //Apparently the first event with an non-empty container
135  if (m_nAccCalibDigits!=currSize) {
136  ATH_MSG_FATAL (eventDetails() << "Mismatch in size of LArAccCalibDigitContainer: Have " << currSize << " elements, expected " << m_nAccCalibDigits);
137  m_stopJob=true;
138  if (m_stopOnError)
139  return StatusCode::FAILURE;
140  } //end if have mismatch
141  }//end if currSize>0
142  }//end if storeGate->contains
143  }//end loop over keys
144  }//end if m_checkAccCalibDigits
145 
146 
147  if (m_checkBSErrors) {
148  const LArFebErrorSummary* febErrSum = nullptr;
149  StatusCode sc=evtStore()->retrieve(febErrSum);
150  if (sc.isFailure()) {
151  ATH_MSG_ERROR ("Can't retrieve LArFEBErrorSummary");
152  return sc;
153  }
154 
155  const std::map<unsigned int,uint16_t>& allFebErrs=febErrSum->get_all_febs();
156  std::map<unsigned int,uint16_t>::const_iterator it=allFebErrs.begin();
157  std::map<unsigned int,uint16_t>::const_iterator it_e=allFebErrs.end();
158  for(;it!=it_e;++it) {
159  if (it->second & 0xEFFF) { //FIXME all events have missing header ???
160  //std::cout << std::hex << "Feb: 0x" << it->first << " Err 0x"
161  // << it->second << std::endl;
162  MSG::Level msglvl=MSG::WARNING;
163  if ((it->second & m_BSErrFailMask) && (m_thisSize>0)) {
164  m_stopJob=true;
165  if (m_stopOnError) msglvl=MSG::FATAL; else msglvl=MSG::ERROR;
166  }
167  const HWIdentifier fId(it->first);
168  msg() << msglvl << eventDetails() << "FEB 0x" << std::hex << it->first << " reports the following error(s): "
169  << decipherFebError(it->second) << endmsg;
170  msg() << msglvl << "Feb location: " << m_onlineID->channel_name(fId) << endmsg;
171 
172  if (m_thisSize>0) msg() << msglvl << "This event carries data" << endmsg;
173 
174  if (m_stopJob && m_stopOnError)
175  return StatusCode::FAILURE;
176  }//end if error
177  }//end loop over FEBs
178  }//end if check BS Errs
179 
180 
181  m_nEvent++;
182  return StatusCode::SUCCESS;
183 }
184 
185 
186 std::string LArBadEventCatcher::eventDetails() const {
187  std::stringstream result;
188 
189  const xAOD::EventInfo* eventInfo;
190  StatusCode sc = evtStore()->retrieve(eventInfo);
191  if (sc.isFailure())
192  result << "[No EventInfo]";
193  else {
194  unsigned int evtNum = eventInfo->eventNumber();
195  unsigned int runNum = eventInfo->runNumber();
196  result << "Run " << runNum << ", Evt " << evtNum;
197  }
198  result << ", Idx " << m_nEvent << ": ";
199  return result.str();
200 }
201 
202 
204  if (m_stopJob && m_stopOnError) {
205  ATH_MSG_FATAL ("Fatal error found during execute");
206  return StatusCode::FAILURE;
207  }
208  else
209  return StatusCode::SUCCESS;
210 }
211 
212 
213 std::string LArBadEventCatcher::decipherFebError(const uint32_t errword) const {
214 
215  std::string result;
216 
217  if (errword & (0x1U << LArFebErrorSummary::Parity))
218  result+="Parity Error, ";
219  if (errword & (0x1U << LArFebErrorSummary::BCID))
220  result+="BCID Mismatch, ";
221  if (errword & (0x1U << LArFebErrorSummary::SampleHeader))
222  result+="Sample Header Error, ";
223  if (errword & (0x1U << LArFebErrorSummary::EVTID))
224  result+="EVTID Error, ";
225  if (errword & (0x1U << LArFebErrorSummary::ScacStatus))
226  result+="SCAC Status, ";
227  if (errword & (0x1U << LArFebErrorSummary::ScaOutOfRange))
228  result+="SCA out of range, ";
229  if (errword & (0x1U << LArFebErrorSummary::GainMismatch))
230  result+="Gain Mismatch, ";
231  if (errword & (0x1U << LArFebErrorSummary::TypeMismatch))
232  result+="Type Mismatch ";
233  if (errword & (0x1U << LArFebErrorSummary::NumOfSamples))
234  result+="Number of Samples Mismatch, ";
235  if (errword & (0x1U << LArFebErrorSummary::EmptyDataBlock))
236  result+="Empty Data Block, ";
237  if (errword & (0x1U << LArFebErrorSummary::DspBlockSize))
238  result+="DSP Block Size, ";
239  if (errword & (0x1U << LArFebErrorSummary::CheckSum))
240  result+="Checksum error, ";
241  if (errword & (0x1U << LArFebErrorSummary::MissingHeader))
242  result+="Missing Header, ";
243 
244  if (result.size()<2)
245  result="Unknown error";
246  else
247  result.erase(result.end()-2,result.end());
248 
249  return result;
250 }
251 
252 
253 
LArFebErrorSummary::CheckSum
@ CheckSum
Definition: LArFebErrorSummary.h:28
LArBadEventCatcher::m_BSErrFailMask
uint16_t m_BSErrFailMask
Definition: LArBadEventCatcher.h:73
LArBadEventCatcher::m_checkBSErrors
bool m_checkBSErrors
Definition: LArBadEventCatcher.h:70
LArBadEventCatcher::m_checkDigits
bool m_checkDigits
Definition: LArBadEventCatcher.h:67
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
LArFebErrorSummary::get_all_febs
const std::map< unsigned int, uint16_t > & get_all_febs() const
get all febs with error
Definition: LArFebErrorSummary.cxx:47
get_generator_info.result
result
Definition: get_generator_info.py:21
python.Constants.FATAL
int FATAL
Definition: Control/AthenaCommon/python/Constants.py:19
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
xAOD::EventInfo_v1::eventNumber
uint64_t eventNumber() const
The current event's event number.
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
LArBadEventCatcher::m_nAccCalibDigits
std::size_t m_nAccCalibDigits
Definition: LArBadEventCatcher.h:76
LArBadEventCatcher::stop
StatusCode stop()
Definition: LArBadEventCatcher.cxx:203
LArBadEventCatcher::initialize
StatusCode initialize()
Definition: LArBadEventCatcher.cxx:45
LArBadEventCatcher::eventDetails
std::string eventDetails() const
Definition: LArBadEventCatcher.cxx:186
skel.it
it
Definition: skel.GENtoEVGEN.py:423
LArBadEventCatcher::execute
StatusCode execute()
Definition: LArBadEventCatcher.cxx:65
LArBadEventCatcher::LArBadEventCatcher
LArBadEventCatcher(const std::string &name, ISvcLocator *pSvcLocator)
Definition: LArBadEventCatcher.cxx:14
skel.runNum
runNum
Definition: skel.ABtoEVGEN.py:137
HWIdentifier
Definition: HWIdentifier.h:13
xAOD::EventInfo_v1::runNumber
uint32_t runNumber() const
The current event's run number.
LArBadEventCatcher.h
Algorithm to catch corrupt events and stop the job.
LArBadEventCatcher::~LArBadEventCatcher
~LArBadEventCatcher()
Definition: LArBadEventCatcher.cxx:41
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
AthCommonDataStore< AthCommonMsg< Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
LArBadEventCatcher::m_nDigits
std::size_t m_nDigits
Definition: LArBadEventCatcher.h:76
LArFebErrorSummary::TypeMismatch
@ TypeMismatch
Definition: LArFebErrorSummary.h:28
TrigConf::MSGTC::Level
Level
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:21
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:92
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
LArFebErrorSummary::ScacStatus
@ ScacStatus
Definition: LArFebErrorSummary.h:27
LArAccumulatedCalibDigitContainer.h
LArBadEventCatcher::m_checkAccCalibDigits
bool m_checkAccCalibDigits
Definition: LArBadEventCatcher.h:68
AthAlgorithm
Definition: AthAlgorithm.h:47
LArFebHeaderContainer.h
LArBadEventCatcher::m_nFebheaders
std::size_t m_nFebheaders
Definition: LArBadEventCatcher.h:76
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
LArFebErrorSummary::EmptyDataBlock
@ EmptyDataBlock
Definition: LArFebErrorSummary.h:28
LArFebErrorSummary::EVTID
@ EVTID
Definition: LArFebErrorSummary.h:27
LArDigitContainer.h
LArBadEventCatcher::m_stopJob
bool m_stopJob
Definition: LArBadEventCatcher.h:80
EventInfo.h
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
LArFebErrorSummary::DspBlockSize
@ DspBlockSize
Definition: LArFebErrorSummary.h:28
LArFebErrorSummary::Parity
@ Parity
Definition: LArFebErrorSummary.h:27
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
LArFebErrorSummary
Holds information from the FEB Error Summary.
Definition: LArFebErrorSummary.h:23
LArBadEventCatcher::decipherFebError
std::string decipherFebError(const uint32_t errword) const
Definition: LArBadEventCatcher.cxx:213
AthCommonMsg< Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
LArBadEventCatcher::m_nEvent
unsigned m_nEvent
Definition: LArBadEventCatcher.h:74
LArBadEventCatcher::m_thisSize
std::size_t m_thisSize
Definition: LArBadEventCatcher.h:77
LArDigitContainer
Container class for LArDigit.
Definition: LArDigitContainer.h:24
LArBadEventCatcher::m_keyList
std::vector< std::string > m_keyList
Definition: LArBadEventCatcher.h:78
LArFebHeaderContainer
Container class for LArFebHeader.
Definition: LArFebHeaderContainer.h:20
LArFebErrorSummary::SampleHeader
@ SampleHeader
Definition: LArFebErrorSummary.h:27
LArFebErrorSummary.h
LArFebErrorSummary::ScaOutOfRange
@ ScaOutOfRange
Definition: LArFebErrorSummary.h:27
LArFebErrorSummary::BCID
@ BCID
Definition: LArFebErrorSummary.h:27
LArBadEventCatcher::m_checkFebHeaders
bool m_checkFebHeaders
Definition: LArBadEventCatcher.h:69
LArOnlineID_Base::channel_name
std::string channel_name(const HWIdentifier id) const
Return a string corresponding to a feedthrough name given an identifier.
Definition: LArOnlineID_Base.cxx:218
LArAccumulatedCalibDigitContainer
Container class for LArAccumulatedCalibDigit.
Definition: LArAccumulatedCalibDigitContainer.h:25
LArBadEventCatcher::m_onlineID
const LArOnlineID * m_onlineID
Definition: LArBadEventCatcher.h:63
LArFebErrorSummary::NumOfSamples
@ NumOfSamples
Definition: LArFebErrorSummary.h:28
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
LArBadEventCatcher::m_stopOnError
bool m_stopOnError
Definition: LArBadEventCatcher.h:81
LArOnlineID.h
LArFebErrorSummary::MissingHeader
@ MissingHeader
Definition: LArFebErrorSummary.h:28
LArFebErrorSummary::GainMismatch
@ GainMismatch
Definition: LArFebErrorSummary.h:28