Belle II Software development
PXDPostErrorCheckerModule.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <pxd/modules/pxdUnpacking/PXDPostErrorCheckerModule.h>
10
11using namespace Belle2;
12using namespace Belle2::PXD;
13using namespace Belle2::PXD::PXDError;
14
15//-----------------------------------------------------------------
16// Register the Module
17//-----------------------------------------------------------------
18REG_MODULE(PXDPostErrorChecker);
19
20//-----------------------------------------------------------------
21// Implementation
22//-----------------------------------------------------------------
23
25{
26 //Set module properties
27 setDescription("PXD: Check Post Unpacking for DAQ errors");
29
30 addParam("PXDDAQEvtStatsName", m_PXDDAQEvtStatsName, "The name of the StoreObjPtr of input PXDDAQEvtStats", std::string(""));
31 addParam("PXDRawHitsName", m_PXDRawHitsName, "The name of the StoreArray of input PXDRawHits", std::string(""));
32 addParam("PXDRawAdcsName", m_PXDRawAdcsName, "The name of the StoreArray of input PXDRawAdcs", std::string(""));
33 addParam("PXDRawROIsName", m_PXDRawROIsName, "The name of the StoreArray of input PXDRawROIs", std::string(""));
34 addParam("CriticalErrorMask", m_criticalErrorMaskParam,
35 "Set error mask for which data is removed (0=none, 1=default, other undefined yet)", 1);
36 addParam("IgnoreTriggerGate", m_ignoreTriggerGate, "Ignore different triggergate between DHEs", true);
37 addParam("IgnoreDHPFrame", m_ignoreDHPFrame, "Ignore different dhp frame between DHEs", true);
38}
39
41{
42 if (m_criticalErrorMaskParam == 0) {
44 B2INFO("Disabling critical error mask");
45 } else if (m_criticalErrorMaskParam == 1) {
46 PXDError::PXDErrorFlags defaulterrormask;
47 defaulterrormask[c_nrEVENT_STRUCT ] = 1;
48 defaulterrormask[c_nrFRAME_TNR_MM ] = 1;
49 defaulterrormask[c_nrMETA_MM ] = 1;
50 defaulterrormask[c_nrONSEN_TRG_FIRST ] = 1;
51 //
52 defaulterrormask[c_nrDHC_END_MISS ] = 1;
53 defaulterrormask[c_nrNR_FRAMES_TO_SMALL ] = 1;
54 // defaulterrormask[c_nrROI_PACKET_INV_SIZE ] = 1; // does not affect pixel data
55 defaulterrormask[c_nrDATA_OUTSIDE ] = 1;
56 //
57 defaulterrormask[c_nrDHC_START_SECOND ] = 1;
58 // defaulterrormask[c_nrDHE_WRONG_ID_SEQ ] = 1; // until this is fixed in FW, we have to live with this
59 defaulterrormask[c_nrFIX_SIZE ] = 1;
60 defaulterrormask[c_nrDHE_CRC ] = 1;
61 //
62 defaulterrormask[c_nrDHC_UNKNOWN ] = 1;
63 defaulterrormask[c_nrHEADERTYPE_INV ] = 1;
64 defaulterrormask[c_nrPACKET_SIZE ] = 1;
65 defaulterrormask[c_nrMAGIC ] = 1;
66 //
67 defaulterrormask[c_nrFRAME_NR ] = 1;
68 defaulterrormask[c_nrFRAME_SIZE ] = 1;
69 defaulterrormask[c_nrHLTROI_MAGIC ] = 1;
70 defaulterrormask[c_nrMERGER_TRIGNR ] = 1;
71 //
72 defaulterrormask[c_nrDHP_SIZE ] = 1;
73 defaulterrormask[c_nrDHE_DHP_DHEID ] = 1;
74 defaulterrormask[c_nrDHE_DHP_PORT ] = 1;
75 // defaulterrormask[c_nrDHP_PIX_WO_ROW ] = 1; // FIXME this should not be needed
76 //
77 defaulterrormask[c_nrDHE_START_END_ID ] = 1;
78 defaulterrormask[c_nrDHE_START_ID ] = 1;
79 defaulterrormask[c_nrDHE_START_WO_END ] = 1;
80 // defaulterrormask[c_nrNO_PXD ] = 1; // THEN we anyway have no data
81 //
82 // defaulterrormask[c_nrNO_DATCON ] = 1; // does not affect pixel data
83 // defaulterrormask[c_nrFAKE_NO_DATA_TRIG ] = 1; // this will trigger always!!!!
84 defaulterrormask[c_nrDHE_ACTIVE ] = 1;
85 // defaulterrormask[c_nrDHP_ACTIVE ] = 1; // GHOST problem ... bit always set
86 //
87 defaulterrormask[c_nrSENDALL_TYPE ] = 1;
88 defaulterrormask[c_nrNOTSENDALL_TYPE ] = 1;
89 defaulterrormask[c_nrDHP_DBL_HEADER ] = 1;
90 defaulterrormask[c_nrHEADER_ERR ] = 1;
91 //
92 defaulterrormask[c_nrHEADER_ERR_GHOST ] = 1;
93 defaulterrormask[c_nrSUSP_PADDING ] = 1;
94 defaulterrormask[c_nrDHC_WIE ] = 1;
95 defaulterrormask[c_nrDHE_WIE ] = 1;
96 //
97 defaulterrormask[c_nrROW_OVERFLOW ] = 1;
98 // defaulterrormask[c_nrDHP_NOT_CONT ] = 1; // GHOST problem
99 defaulterrormask[c_nrDHP_DHP_FRAME_DIFFER ] = 1;
100 defaulterrormask[c_nrDHP_DHE_FRAME_DIFFER ] = 1;
101 //
102 defaulterrormask[c_nrDHE_ID_INVALID ] = 1;
103 defaulterrormask[c_nrDHC_DHCID_START_END_MM ] = 1;
104 defaulterrormask[c_nrDHE_END_WO_START ] = 1;
105 defaulterrormask[c_nrDHC_END_DBL ] = 1;
106 //
107 defaulterrormask[c_nrMETA_MM_DHC ] = 1;
108 defaulterrormask[c_nrMETA_MM_DHE ] = 1;
109 // defaulterrormask[c_nrCOL_OVERFLOW ] = 1; // we might get that for unconnected lines -> "DHPT fix"
110 defaulterrormask[c_nrUNEXPECTED_FRAME_TYPE ] = 1;
111 //
112 defaulterrormask[c_nrMETA_MM_DHC_ERS ] = 1;
113 // defaulterrormask[c_nrMETA_MM_DHC_TT ] = 1; // time tag is not set correctly in EvtMeta
114 defaulterrormask[c_nrMETA_MM_ONS_HLT ] = 1;
115 // defaulterrormask[c_nrMETA_MM_ONS_DC ] = 1; // problem with NO-DATCON
116 //
117 // defaulterrormask[c_nrEVT_TRG_GATE_DIFFER ] = 1; // still a bug in DHE FW
118 // defaulterrormask[c_nrEVT_TRG_FRM_NR_DIFFER ] = 1; // still a bug in DHE FW
119 // defaulterrormask[c_nrDHP_ROW_WO_PIX ] = 1; // still a bug in DHE FW?
120 defaulterrormask[c_nrDHE_START_THIRD ] = 1;
121 //
122 defaulterrormask[c_nrFAKE_NO_FAKE_DATA ] = 1;
123 // other bits not used yet
124 m_criticalErrorMask = defaulterrormask;
125 } else {
126 B2FATAL("Undefined value for criticalErrorMaskSet");
127 }
128
129 m_storeDAQEvtStats.isRequired();
130
131 // Needed if we need to Clear them on detected Error
134 m_storeROIs.isOptional(m_PXDRawROIsName);
135
136 B2DEBUG(25, "The set error mask is $" << std::hex << m_criticalErrorMask);
137}
138
140{
152 bool had_dhe = false;
153 unsigned short triggergate = 0;
154 unsigned short dheframenr = 0;
155 std::map <int, int> found_dhe;
156 PXDErrorFlags mask{};// construct to no error
157 B2DEBUG(25, "Iterate PXD Packets for this Event");
158 for (auto& pkt : *m_storeDAQEvtStats) {
159 B2DEBUG(25, "Iterate DHC in Pkt " << pkt.getPktIndex());
160 for (auto& dhc : pkt) {
161 B2DEBUG(25, "Iterate DHE in DHC " << dhc.getDHCID());
162 for (auto& dhe : dhc) {
163 B2DEBUG(25, "Iterate DHP in DHE " << dhe.getDHEID() << " TrigGate " << dhe.getTriggerGate() << " FrameNr " << dhe.getFrameNr());
164 found_dhe[dhe.getDHEID()]++;
165 if (had_dhe) {
166 if (dhe.getTriggerGate() != triggergate) {
167 if (!m_ignoreTriggerGate) B2WARNING("Trigger Gate of DHEs not identical" << LogVar("Triggergate 1",
168 triggergate) << LogVar("TriggerGate 2", dhe.getTriggerGate()));
169 mask [c_nrEVT_TRG_GATE_DIFFER] = true;
170 }
171 if (dhe.getFrameNr() != dheframenr) {
172 if (!m_ignoreDHPFrame) B2WARNING("Frame Nr of DHEs not identical" << LogVar("FrameNr 1", dheframenr) << LogVar("FrameNr 2",
173 dhe.getFrameNr()));
174 mask [c_nrEVT_TRG_FRM_NR_DIFFER] = true;
175 }
176 } else {
177 triggergate = dhe.getTriggerGate();
178 dheframenr = dhe.getFrameNr();
179 had_dhe = true;
180 }
181 for (auto& dhp : dhe) {
182 B2DEBUG(25, "DHP " << dhp.getChipID() << " Framenr " << dhp.getFrameNr());
183 // TODO check against other DHP (full bits) and DHE (limited bits)
184 // TODO We know that this will fail with current firmware and most likely will not be fixed...
185 }
186 bool error = false;
187 for (auto it = dhe.cm_begin(); it < dhe.cm_end(); ++it) {
188 if (std::get<2>(*it) == 63) {
189 // TODO Check that we dont have CM=63 indicating fifo overflow, check and set bits
190 // mask |= c_DHH_MISC_ERROR; // unpacker should set this already, anyway we would want it set only on the DHP/DHE level...
191 B2DEBUG(25, "DHP data loss (CM=63) in " << LogVar("DHE", dhe.getDHEID()) << LogVar("DHP", int(std::get<0>(*it))) << LogVar("Row",
192 std::get<1>(*it)));
193 error = true;
194 }
195 }
196 if (error) B2WARNING("DHP data loss (CM=63) in " << LogVar("DHE", dhe.getDHEID()));
197 }
198 }
199 }
200
203 for (auto& a : found_dhe) {
204 if (a.second > 1) B2WARNING("More than one packet for same DHE ID " << a.first);
205 }
207// for (auto& a : found_dhe) {
208// if (!m_dhe_expected[a.first]) B2ERROR("This DHE ID was not expected " << a.first);
209// }
210// for (auto& a : m_dhe_expected) {
211// if (a.second) {
212// if (found_dhe[a.first] == 0) B2ERROR("DHE packet missing for DHE ID " << a.first);
213// } else {
214// if (found_dhe[a.first] > 0) B2ERROR("This DHE ID was not expected " << a.first);
215// }
216// }
217 m_storeDAQEvtStats->addErrorMask(mask);
218 m_storeDAQEvtStats->setCritErrorMask(m_criticalErrorMask);
219 m_storeDAQEvtStats->Decide();
220 if (!m_storeDAQEvtStats->isUsable()) {
221 // Clear all PXD related data but Raw and DaqEvtStats!
222 m_storeRawHits.clear();
223 m_storeROIs.clear();
224 m_storeRawAdc.clear();
225 setReturnValue(false); // allows special processing in case
226 } else {
227 // setReturnValue(true); // default, it is not needed
228 }
229}
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
void setReturnValue(int value)
Sets the return value for this module as integer.
Definition: Module.cc:220
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition: Module.h:80
std::string m_PXDRawHitsName
The name of the StoreArray of PXDRawHits to be modified.
void initialize() override final
Initialize.
StoreObjPtr< PXDDAQStatus > m_storeDAQEvtStats
Input array for DAQ Status.
std::string m_PXDDAQEvtStatsName
The name of the StoreObjPtr of PXDDAQStatus to be read and modified.
StoreArray< PXDRawROIs > m_storeROIs
In/Output array for Raw ROIs.
bool m_ignoreDHPFrame
Flag: Ignore different dhp frame between DHEs.
PXDPostErrorCheckerModule()
Constructor defining the parameters.
StoreArray< PXDRawAdc > m_storeRawAdc
In/Output array for Raw Adcs.
int m_criticalErrorMaskParam
Module parameter for setting the critical error mask.
bool m_ignoreTriggerGate
TODO another mask for DHE Level if we want to clean ONLY modules?
std::string m_PXDRawAdcsName
The name of the StoreArray of PXDRawAdcs to be modified.
PXDError::PXDErrorFlags m_criticalErrorMask
Critical error mask which defines when data should be trashed, whole event only!
StoreArray< PXDRawHit > m_storeRawHits
In/Output array for Raw Hits.
std::string m_PXDRawROIsName
The name of the StoreArray of PXDRawROIs to be modified.
Class to store variables with their name which were sent to the logging service.
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Namespace to encapsulate code needed for simulation and reconstrucion of the PXD.
Abstract base class for different kinds of events.