Belle II Software  release-05-02-19
PXDPostErrorCheckerModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2017 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Bjoern Spruck *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <pxd/modules/pxdUnpacking/PXDPostErrorCheckerModule.h>
12 
13 using namespace Belle2;
14 using namespace Belle2::PXD;
15 using namespace Belle2::PXD::PXDError;
16 
17 //-----------------------------------------------------------------
18 // Register the Module
19 //-----------------------------------------------------------------
20 REG_MODULE(PXDPostErrorChecker)
21 
22 //-----------------------------------------------------------------
23 // Implementation
24 //-----------------------------------------------------------------
25 
27 {
28  //Set module properties
29  setDescription("PXD: Check Post Unpacking for DAQ errors");
30  setPropertyFlags(c_ParallelProcessingCertified);
31 
32  constexpr uint64_t defaulterrormask =
33  c_EVENT_STRUCT |
34  c_FRAME_TNR_MM |
35  c_META_MM |
36  c_ONSEN_TRG_FIRST |
37  //
38  c_DHC_END_MISS |
39  c_NR_FRAMES_TO_SMALL |
40 // c_ROI_PACKET_INV_SIZE | // does not affect pixel data
41  c_DATA_OUTSIDE |
42  //
43  c_DHC_START_SECOND |
44 // c_DHE_WRONG_ID_SEQ | // until this is fixed in FW, we have to live with this
45  c_FIX_SIZE |
46  c_DHE_CRC |
47  //
48  c_DHC_UNKNOWN |
49  c_HEADERTYPE_INV |
50  c_PACKET_SIZE |
51  c_MAGIC |
52  //
53  c_FRAME_NR |
54  c_FRAME_SIZE |
55  c_HLTROI_MAGIC |
56  c_MERGER_TRIGNR |
57  //
58  c_DHP_SIZE |
59  c_DHE_DHP_DHEID |
60  c_DHE_DHP_PORT |
61 // c_DHP_PIX_WO_ROW | // FIXME this should not be needed
62  //
63  c_DHE_START_END_ID |
64  c_DHE_START_ID |
65  c_DHE_START_WO_END |
66 // c_NO_PXD | // THEN we anyway have no data
67  //
68 // c_NO_DATCON | // does not affect pixel data
69 // c_FAKE_NO_DATA_TRIG | // this will trigger always!!!!
70  c_DHE_ACTIVE |
71 // c_DHP_ACTIVE | // GHOST problem ... bit always set
72  //
73  c_SENDALL_TYPE |
74  c_NOTSENDALL_TYPE |
75  c_DHP_DBL_HEADER |
76  c_HEADER_ERR |
77  //
78  c_HEADER_ERR_GHOST |
79  c_SUSP_PADDING |
80  c_DHC_WIE |
81  c_DHE_WIE |
82  //
83  c_ROW_OVERFLOW |
84 // c_DHP_NOT_CONT | // GHOST problem
85  c_DHP_DHP_FRAME_DIFFER |
86  c_DHP_DHE_FRAME_DIFFER |
87  //
88  c_DHE_ID_INVALID |
89  c_DHC_DHCID_START_END_MM |
90  c_DHE_END_WO_START |
91  c_DHC_END_DBL |
92  //
93  c_META_MM_DHC |
94  c_META_MM_DHE |
95 // c_COL_OVERFLOW | // we might get that for unconnected lines -> "DHPT fix"
96  c_UNEXPECTED_FRAME_TYPE |
97  //
98  c_META_MM_DHC_ERS |
99 // c_META_MM_DHC_TT | // time tag is not set correctly in EvtMeta
100  c_META_MM_ONS_HLT |
101 // c_META_MM_ONS_DC | // problem with NO-DATCON
102  //
103 // c_EVT_TRG_GATE_DIFFER | // still a bug in DHE FW
104 // c_EVT_TRG_FRM_NR_DIFFER | // still a bug in DHE FW
105 // c_DHP_ROW_WO_PIX | // still a bug in DHE FW?
106  c_DHE_START_THIRD |
107  //
108  c_FAKE_NO_FAKE_DATA ;
109 
110  // other bits not used yet
111 
112  addParam("PXDDAQEvtStatsName", m_PXDDAQEvtStatsName, "The name of the StoreObjPtr of input PXDDAQEvtStats", std::string(""));
113  addParam("PXDRawHitsName", m_PXDRawHitsName, "The name of the StoreArray of input PXDRawHits", std::string(""));
114  addParam("PXDRawAdcsName", m_PXDRawAdcsName, "The name of the StoreArray of input PXDRawAdcs", std::string(""));
115  addParam("PXDRawROIsName", m_PXDRawROIsName, "The name of the StoreArray of input PXDRawROIs", std::string(""));
116 
117  addParam("CriticalErrorMask", m_criticalErrorMask, "Set error mask for which data is removed", defaulterrormask);
118  B2DEBUG(25, "The default error mask is $" << std::hex << defaulterrormask);
119 
120  addParam("IgnoreTriggerGate", m_ignoreTriggerGate, "Ignore different triggergate between DHEs", true);
121  addParam("IgnoreDHPFrame", m_ignoreDHPFrame, "Ignore different dhp frame between DHEs", true);
122 
123 
124 }
125 
127 {
128  m_storeDAQEvtStats.isRequired();
129 
130  // Needed if we need to Clear them on detected Error
131  m_storeRawHits.isOptional(m_PXDRawHitsName);
132  m_storeRawAdc.isOptional(m_PXDRawAdcsName);
133  m_storeROIs.isOptional(m_PXDRawROIsName);
134 
135  B2DEBUG(25, "The set error mask is $" << std::hex << m_criticalErrorMask);
136 }
137 
139 {
151  bool had_dhe = false;
152  unsigned short triggergate = 0;
153  unsigned short dheframenr = 0;
154  PXDErrorFlags mask = EPXDErrMask::c_NO_ERROR;
155  B2DEBUG(25, "Iterate PXD Packets for this Event");
156  for (auto& pkt : *m_storeDAQEvtStats) {
157  B2DEBUG(25, "Iterate DHC in Pkt " << pkt.getPktIndex());
158  for (auto& dhc : pkt) {
159  B2DEBUG(25, "Iterate DHE in DHC " << dhc.getDHCID());
160  for (auto& dhe : dhc) {
161  B2DEBUG(25, "Iterate DHP in DHE " << dhe.getDHEID() << " TrigGate " << dhe.getTriggerGate() << " FrameNr " << dhe.getFrameNr());
162  if (had_dhe) {
163  if (dhe.getTriggerGate() != triggergate) {
164  if (!m_ignoreTriggerGate) B2WARNING("Trigger Gate of DHEs not identical" << LogVar("Triggergate 1",
165  triggergate) << LogVar("TriggerGate 2", dhe.getTriggerGate()));
166  mask |= EPXDErrMask::c_EVT_TRG_GATE_DIFFER;
167  }
168  if (dhe.getFrameNr() != dheframenr) {
169  if (!m_ignoreDHPFrame) B2WARNING("Frame Nr of DHEs not identical" << LogVar("FrameNr 1", dheframenr) << LogVar("FrameNr 2",
170  dhe.getFrameNr()));
171  mask |= EPXDErrMask::c_EVT_TRG_FRM_NR_DIFFER;
172  }
173  } else {
174  triggergate = dhe.getTriggerGate();
175  dheframenr = dhe.getFrameNr();
176  had_dhe = true;
177  }
178  for (auto& dhp : dhe) {
179  B2DEBUG(25, "DHP " << dhp.getChipID() << " Framenr " << dhp.getFrameNr());
180  // TODO check against other DHP (full bits) and DHE (limited bits)
181  // TODO We know that this will fail with current firmware and most likely will not be fixed...
182  }
183  bool error = false;
184  for (auto it = dhe.cm_begin(); it < dhe.cm_end(); ++it) {
185  if (std::get<2>(*it) == 63) {
186  // TODO Check that we dont have CM=63 indicating fifo overflow, check and set bits
187  // mask |= c_DHH_MISC_ERROR; // unpacker should set this already, anyway we would want it set only on the DHP/DHE level...
188  B2DEBUG(25, "DHP data loss (CM=63) in " << LogVar("DHE", dhe.getDHEID()) << LogVar("DHP", int(std::get<0>(*it))) << LogVar("Row",
189  std::get<1>(*it)));
190  error = true;
191  }
192  }
193  if (error) B2WARNING("DHP data loss (CM=63) in " << LogVar("DHE", dhe.getDHEID()));
194  }
195  }
196  }
197  m_storeDAQEvtStats->addErrorMask(mask);
198  m_storeDAQEvtStats->setCritErrorMask(m_criticalErrorMask);
199  m_storeDAQEvtStats->Decide();
200  if (!m_storeDAQEvtStats->isUsable()) {
201  // Clear all PXD related data but Raw and DaqEvtStats!
202  m_storeRawHits.clear();
203  m_storeROIs.clear();
204  m_storeRawAdc.clear();
205  setReturnValue(false); // allows special processing in case
206  } else {
207  // setReturnValue(true); // default, it is not needed
208  }
209 }
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::PXD::PXDPostErrorCheckerModule::initialize
void initialize() override final
Initialize the Module.
Definition: PXDPostErrorCheckerModule.cc:126
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::PXD
Namespace to encapsulate code needed for simulation and reconstrucion of the PXD.
Definition: PXDCalibrationUtilities.h:28
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
LogVar
Class to store variables with their name which were sent to the logging service.
Definition: LogVariableStream.h:24
Belle2::PXD::PXDPostErrorCheckerModule
The PXD DAQ Post Unpacking Error Check.
Definition: PXDPostErrorCheckerModule.h:50
Belle2::PXD::PXDPostErrorCheckerModule::event
void event() override final
This method is the core of the module.
Definition: PXDPostErrorCheckerModule.cc:138