Belle II Software  release-08-01-10
PXDPackerErrModule.h
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 #pragma once
10 
11 #include <framework/core/Module.h>
12 #include <vxd/dataobjects/VxdID.h>
13 #include <framework/datastore/StoreArray.h>
14 #include <framework/datastore/StoreObjPtr.h>
15 #include <rawdata/dataobjects/RawPXD.h>
16 #include <pxd/dataobjects/PXDDAQStatus.h>
17 #include <pxd/dataobjects/PXDErrorFlags.h>
18 
19 namespace Belle2 {
25  namespace PXD {
26 
37  class PXDPackerErrModule : public Module {
38  enum {PACKER_NUM_ROWS = 768};
39  enum {PACKER_NUM_COLS = 250};
40 
42  enum myerrormasks : __uint128_t {
43  c_NO_ERROR = __uint128_t(0),
44  c_ALL_ERROR = ~ c_NO_ERROR,
45  //
46  c_EVENT_STRUCT = __uint128_t(1) << Belle2::PXD::PXDError::c_nrEVENT_STRUCT,
47  c_FRAME_TNR_MM = __uint128_t(1) << Belle2::PXD::PXDError::c_nrFRAME_TNR_MM,
48  c_META_MM = __uint128_t(1) << Belle2::PXD::PXDError::c_nrMETA_MM,
49  c_ONSEN_TRG_FIRST = __uint128_t(1) << Belle2::PXD::PXDError::c_nrONSEN_TRG_FIRST,
50  //
51  c_DHC_END_MISS = __uint128_t(1) << Belle2::PXD::PXDError::c_nrDHC_END_MISS,
52  c_NR_FRAMES_TO_SMALL = __uint128_t(1) << Belle2::PXD::PXDError::c_nrNR_FRAMES_TO_SMALL,
53  c_ROI_PACKET_INV_SIZE = __uint128_t(1) << Belle2::PXD::PXDError::c_nrROI_PACKET_INV_SIZE,
54  c_DATA_OUTSIDE = __uint128_t(1) << Belle2::PXD::PXDError::c_nrDATA_OUTSIDE,
55  //
56  c_DHC_START_SECOND = __uint128_t(1) << Belle2::PXD::PXDError::c_nrDHC_START_SECOND,
57  c_DHE_WRONG_ID_SEQ = __uint128_t(1) << Belle2::PXD::PXDError::c_nrDHE_WRONG_ID_SEQ,
58  c_FIX_SIZE = __uint128_t(1) << Belle2::PXD::PXDError::c_nrFIX_SIZE,
59  c_DHE_CRC = __uint128_t(1) << Belle2::PXD::PXDError::c_nrDHE_CRC,
60  //
61  c_DHC_UNKNOWN = __uint128_t(1) << Belle2::PXD::PXDError::c_nrDHC_UNKNOWN,
62  c_HEADERTYPE_INV = __uint128_t(1) << Belle2::PXD::PXDError::c_nrHEADERTYPE_INV,
63  c_PACKET_SIZE = __uint128_t(1) << Belle2::PXD::PXDError::c_nrPACKET_SIZE,
64  c_MAGIC = __uint128_t(1) << Belle2::PXD::PXDError::c_nrMAGIC,
65  //
66  c_FRAME_NR = __uint128_t(1) << Belle2::PXD::PXDError::c_nrFRAME_NR,
67  c_FRAME_SIZE = __uint128_t(1) << Belle2::PXD::PXDError::c_nrFRAME_SIZE,
68  c_HLTROI_MAGIC = __uint128_t(1) << Belle2::PXD::PXDError::c_nrHLTROI_MAGIC,
69  c_MERGER_TRIGNR = __uint128_t(1) << Belle2::PXD::PXDError::c_nrMERGER_TRIGNR,
70  //
71  c_DHP_SIZE = __uint128_t(1) << Belle2::PXD::PXDError::c_nrDHP_SIZE,
72  c_DHE_DHP_DHEID = __uint128_t(1) << Belle2::PXD::PXDError::c_nrDHE_DHP_DHEID,
73  c_DHE_DHP_PORT = __uint128_t(1) << Belle2::PXD::PXDError::c_nrDHE_DHP_PORT,
74  c_DHP_PIX_WO_ROW = __uint128_t(1) << Belle2::PXD::PXDError::c_nrDHP_PIX_WO_ROW,
75  //
76  c_DHE_START_END_ID = __uint128_t(1) << Belle2::PXD::PXDError::c_nrDHE_START_END_ID,
77  c_DHE_START_ID = __uint128_t(1) << Belle2::PXD::PXDError::c_nrDHE_START_ID,
78  c_DHE_START_WO_END = __uint128_t(1) << Belle2::PXD::PXDError::c_nrDHE_START_WO_END,
79  c_NO_PXD = __uint128_t(1) << Belle2::PXD::PXDError::c_nrNO_PXD,
80  //
81  c_NO_DATCON = __uint128_t(1) << Belle2::PXD::PXDError::c_nrNO_DATCON,
82  c_FAKE_NO_DATA_TRIG = __uint128_t(1) << Belle2::PXD::PXDError::c_nrFAKE_NO_DATA_TRIG,
83  c_DHE_ACTIVE = __uint128_t(1) << Belle2::PXD::PXDError::c_nrDHE_ACTIVE,
84  c_DHP_ACTIVE = __uint128_t(1) << Belle2::PXD::PXDError::c_nrDHP_ACTIVE,
85  //
86  c_SENDALL_TYPE = __uint128_t(1) << Belle2::PXD::PXDError::c_nrSENDALL_TYPE,
87  c_NOTSENDALL_TYPE = __uint128_t(1) << Belle2::PXD::PXDError::c_nrNOTSENDALL_TYPE,
88  c_DHP_DBL_HEADER = __uint128_t(1) << Belle2::PXD::PXDError::c_nrDHP_DBL_HEADER,
89  c_HEADER_ERR = __uint128_t(1) << Belle2::PXD::PXDError::c_nrHEADER_ERR,
90  //
91  c_HEADER_ERR_GHOST = __uint128_t(1) << Belle2::PXD::PXDError::c_nrHEADER_ERR_GHOST,
92  c_SUSP_PADDING = __uint128_t(1) << Belle2::PXD::PXDError::c_nrSUSP_PADDING,
93  c_DHC_WIE = __uint128_t(1) << Belle2::PXD::PXDError::c_nrDHC_WIE,
94  c_DHE_WIE = __uint128_t(1) << Belle2::PXD::PXDError::c_nrDHE_WIE,
95  //
96  c_ROW_OVERFLOW = __uint128_t(1) << Belle2::PXD::PXDError::c_nrROW_OVERFLOW,
97  c_DHP_NOT_CONT = __uint128_t(1) << Belle2::PXD::PXDError::c_nrDHP_NOT_CONT,
98  c_DHP_DHP_FRAME_DIFFER = __uint128_t(1) << Belle2::PXD::PXDError::c_nrDHP_DHP_FRAME_DIFFER,
99  c_DHP_DHE_FRAME_DIFFER = __uint128_t(1) << Belle2::PXD::PXDError::c_nrDHP_DHE_FRAME_DIFFER,
100  //
101  c_DHE_ID_INVALID = __uint128_t(1) << Belle2::PXD::PXDError::c_nrDHE_ID_INVALID,
102  c_DHC_DHCID_START_END_MM = __uint128_t(1) << Belle2::PXD::PXDError::c_nrDHC_DHCID_START_END_MM,
103  c_DHE_END_WO_START = __uint128_t(1) << Belle2::PXD::PXDError::c_nrDHE_END_WO_START,
104  c_DHC_END_DBL = __uint128_t(1) << Belle2::PXD::PXDError::c_nrDHC_END_DBL,
105  //
106  c_META_MM_DHC = __uint128_t(1) << Belle2::PXD::PXDError::c_nrMETA_MM_DHC,
107  c_META_MM_DHE = __uint128_t(1) << Belle2::PXD::PXDError::c_nrMETA_MM_DHE,
108  c_COL_OVERFLOW = __uint128_t(1) << Belle2::PXD::PXDError::c_nrCOL_OVERFLOW,
109  c_UNEXPECTED_FRAME_TYPE = __uint128_t(1) << Belle2::PXD::PXDError::c_nrUNEXPECTED_FRAME_TYPE,
110  //
111  c_META_MM_DHC_ERS = __uint128_t(1) << Belle2::PXD::PXDError::c_nrMETA_MM_DHC_ERS,
112  c_META_MM_DHC_TT = __uint128_t(1) << Belle2::PXD::PXDError::c_nrMETA_MM_DHC_TT,
113  c_META_MM_ONS_HLT = __uint128_t(1) << Belle2::PXD::PXDError::c_nrMETA_MM_ONS_HLT,
114  c_META_MM_ONS_DC = __uint128_t(1) << Belle2::PXD::PXDError::c_nrMETA_MM_ONS_DC,
115  //
116  c_EVT_TRG_GATE_DIFFER = __uint128_t(1) << Belle2::PXD::PXDError::c_nrEVT_TRG_GATE_DIFFER,
117  c_EVT_TRG_FRM_NR_DIFFER = __uint128_t(1) << Belle2::PXD::PXDError::c_nrEVT_TRG_FRM_NR_DIFFER,
118  c_DHP_ROW_WO_PIX = __uint128_t(1) << Belle2::PXD::PXDError::c_nrDHP_ROW_WO_PIX,
119  c_DHE_START_THIRD = __uint128_t(1) << Belle2::PXD::PXDError::c_nrDHE_START_THIRD,
120  //
121  c_FAKE_NO_FAKE_DATA = __uint128_t(1) << Belle2::PXD::PXDError::c_nrFAKE_NO_FAKE_DATA,
122  c_UNUSABLE_DATA = __uint128_t(1) << Belle2::PXD::PXDError::c_nrUNUSABLE_DATA,
123  c_DHH_END_ERRORBITS = __uint128_t(1) << Belle2::PXD::PXDError::c_nrDHH_END_ERRORBITS,
124  c_DHH_MISC_ERROR = __uint128_t(1) << Belle2::PXD::PXDError::c_nrDHH_MISC_ERROR,
125  //
126  };
127 
128  public:
131 
132  private:
134  void initialize() override final;
136  void event() override final;
138  void terminate() override final;
139 
140  std::string m_RawPXDsName;
144  bool m_Check;
145  std::string m_PXDDAQEvtStatsName;
148  std::vector< std::vector<int >> m_dhe_to_dhc;
149 
151  std::map <int, std::vector <int>> m_dhc_mapto_dhe;
152 
154  unsigned int m_packed_events{0};
156  unsigned int m_real_trigger_nr{0};
158  unsigned int m_trigger_nr{0};
160  unsigned short m_run_nr_word1{0};
162  unsigned short m_run_nr_word2{0};
164  unsigned long long int m_meta_time{0};
165 
167  unsigned int m_trigger_dhp_framenr{0};
169  unsigned int m_trigger_dhe_gate{0};
170 
172  bool m_found_fatal {false};
173 
175  std::vector <unsigned int> m_onsen_header;
176 
178  std::vector <std::vector <unsigned char>> m_onsen_payload;
179 
181  std::vector <unsigned char> m_current_frame;
182 
185 
188 
191  void pack_event(void);
192 
195  void pack_dhc(int dhc_id, int dhe_mask, int* dhe_ids, bool send_all = true, bool send_roi = false);
196 
199  void pack_dhe(int dhe_id, int dhp_mask);
200 
203  void pack_dhp(int dhp_id, int dhe_id, int dhe_reformat);
204 
207  /* cppcheck-suppress unusedPrivateFunction */
208  void pack_dhp_raw(int dhp_id, int dhe_id);
209 
210  void start_frame(void);
211  void append_int8(unsigned char w);
212  void append_int16(unsigned short w);
213  void append_int32(unsigned int w);
214  void add_frame_to_payload(void);
215 
217  void do_the_reverse_mapping(unsigned int& row, unsigned int& col, unsigned short layer, unsigned short sensor);
218 
220  bool isErrorIn(uint32_t enr);
221 
223  std::map <VxdID, int> startOfVxdID;
224 
226  unsigned char halfladder_pixmap[PACKER_NUM_ROWS][PACKER_NUM_COLS] = {{0}};
227 
228  unsigned int dhe_byte_count{0};
229  unsigned int dhc_byte_count{0};
231  bool CheckErrorMaskInEvent(unsigned int eventnr, PXDError::PXDErrorFlags mask);
232 
234  static std::vector <PXDErrorFlags> m_errors;
235 
236  };//end class declaration
237 
238 
239  } //end PXD namespace;
241 } // end namespace Belle2
Base class for Modules.
Definition: Module.h:72
The PXDPackerErr module.
void do_the_reverse_mapping(unsigned int &row, unsigned int &col, unsigned short layer, unsigned short sensor)
function still to be implemented
std::vector< std::vector< unsigned char > > m_onsen_payload
For one DHC event, we utilize one payload for all DHE/DHP frames.
void initialize() override final
Initialize the module.
bool m_Check
false=Pack Raw Data, true=Check unpacked result
void add_frame_to_payload(void)
Add Frame to Event payload.
unsigned short m_run_nr_word2
Exp+Run Nr.
std::string m_PXDDAQEvtStatsName
The name of the StoreObjPtr of PXDDAQStatus to be read.
std::map< VxdID, int > startOfVxdID
Store start of Vxd Detector related digits.
void append_int16(unsigned short w)
cat 16bit value to frame
StoreObjPtr< PXDDAQStatus > m_daqStatus
Output array for RawPxds.
void pack_dhe(int dhe_id, int dhp_mask)
Pack one DHE (several DHP) to buffer.
bool m_found_fatal
flag if we found one test failing
myerrormasks
enumeration of the error masks
void pack_dhp_raw(int dhp_id, int dhe_id)
Pack one DHP RAW to buffer.
std::string m_RawPXDsName
The name of the StoreArray of generated RawPXDs.
bool CheckErrorMaskInEvent(unsigned int eventnr, PXDError::PXDErrorFlags mask)
void pack_event(void)
Pack one event (several DHC) stored in seperate RawPXD object.
void terminate() override final
Terminate the module.
void event() override final
do the packing
PXDPackerErrModule()
Constructor defining the parameters.
unsigned int dhc_byte_count
Byte count in current DHC package.
std::vector< std::vector< int > > m_dhe_to_dhc
Parameter dhc<->dhe list, mapping from steering file.
bool m_Clusterize
Use clusterizer (FCE format)
unsigned short m_run_nr_word1
Run+Subrun Nr.
bool isErrorIn(uint32_t enr)
Check if we want this type of error in this event.
std::vector< unsigned int > m_onsen_header
For one DHC event, we utilize one header (writing out, beware of endianess!)
unsigned int m_real_trigger_nr
Real Trigger Nr.
void append_int32(unsigned int w)
cat 32value value to frame
StoreArray< RawPXD > m_storeRaws
Output array for RawPxds.
unsigned int m_trigger_dhp_framenr
DHP Readout Frame Nr for DHP and DHE headers.
unsigned int dhe_byte_count
Byte count in current DHE package.
static std::vector< PXDErrorFlags > m_errors
The pxd error flags.
void pack_dhp(int dhp_id, int dhe_id, int dhe_reformat)
Pack one DHP to buffer.
std::map< int, std::vector< int > > m_dhc_mapto_dhe
mapping calculated from m_dhe_to_dhc for easier handling
void start_frame(void)
Start with a new Frame.
void append_int8(unsigned char w)
cat 8bit value to frame
unsigned int m_trigger_dhe_gate
DHE Trigger Gate for DHE headers.
unsigned int m_packed_events
Event counter.
bool m_InvertMapping
Flag if we invert mapping to DHP row/col or use premapped coordinates.
unsigned long long int m_meta_time
Time(Tag) from MetaInfo.
std::vector< unsigned char > m_current_frame
For current processed frames.
unsigned char halfladder_pixmap[PACKER_NUM_ROWS][PACKER_NUM_COLS]
temporary hitmap buffer for pixel to raw data conversion
unsigned int m_trigger_nr
Trigger Nr.
void pack_dhc(int dhc_id, int dhe_mask, int *dhe_ids, bool send_all=true, bool send_roi=false)
Pack one DHC (several DHE) stored in one RawPXD object.
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
Abstract base class for different kinds of events.