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