Belle II Software development
SVDUnpackerModule.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 <framework/datastore/StoreArray.h>
13#include <framework/datastore/StoreObjPtr.h>
14#include <framework/database/DBObjPtr.h>
15#include <framework/database/PayloadFile.h>
16#include <framework/dbobjects/HardwareClockSettings.h>
17
18#include <svd/geometry/SensorInfo.h>
19#include <vxd/dataobjects/VxdID.h>
20#include <rawdata/dataobjects/RawSVD.h>
21#include <svd/dataobjects/SVDShaperDigit.h>
22#include <svd/dataobjects/SVDTransparentDigit.h>
23#include <svd/dataobjects/SVDDAQDiagnostic.h>
24#include <svd/dataobjects/SVDEventInfo.h>
25#include <svd/dataobjects/SVDTriggerType.h>
26#include <svd/dbobjects/SVDGlobalConfigParameters.h>
27#include <svd/online/SVDOnlineToOfflineMap.h>
28#include <svd/online/SVDStripNoiseMap.h>
29#include <framework/dataobjects/EventMetaData.h>
30
31#include <cstdint>
32#include <memory>
33#include <utility>
34#include <vector>
35
36namespace Belle2::SVD {
37
42 class SVDUnpackerModule : public Module {
43
44 public:
49
53 virtual ~SVDUnpackerModule() override;
54
58 virtual void initialize() override;
59 virtual void beginRun() override;
60 virtual void event() override;
61 virtual void endRun() override;
62
63 private:
64
66 std::string m_rawSVDListName;
67
70
73
75 std::string m_svdEventInfoName;
76
77 int m_wrongFTBcrc = 0;
78
80 unsigned short nFADCboards = 0;
81
83 std::unordered_multimap<unsigned char, unsigned char>* APVmap = 0;
84
86 std::unique_ptr<SVDOnlineToOfflineMap> m_map;
87
89 static std::string m_xmlFileName;
90
93
96
99
101 static void printB2Debug(const uint32_t* data32, const uint32_t* data32_min, const uint32_t* data32_max, int nWords);
102
103 // The following assumes i386 byte order: MSB comes last!
104
106 struct FTBHeader {
107 unsigned int errorsField : 8;
108 unsigned int eventNumber : 24;
109 };
110
112 struct MainHeader {
113 unsigned int trgNumber : 8;
114 unsigned int trgType : 4;
115 unsigned int trgTiming : 2;
116 unsigned int xTalk : 2;
117 unsigned int FADCnum : 8;
118 unsigned int DAQType : 1;
119 unsigned int DAQMode : 2;
120 unsigned int runType : 2;
121 unsigned int check : 3;
122 };
123
125 struct APVHeader {
126 unsigned int CMC1 : 8;
127 unsigned int CMC2 : 4;
128 unsigned int apvErr : 4;
129 unsigned int pipelineAddr : 8;
130 unsigned int APVnum : 6;
131 unsigned int check : 2;
132 };
133
135 struct data_A {
136 unsigned int sample1 : 8;
137 unsigned int sample2 : 8;
138 unsigned int sample3 : 8;
139 unsigned int stripNum : 7;
140 unsigned int check : 1;
141 };
142
144 struct data_B {
145 unsigned int sample4 : 8;
146 unsigned int sample5 : 8;
147 unsigned int sample6 : 8;
148 unsigned int stripNum : 7;
149 unsigned int check : 1;
150 };
151
153 struct FADCTrailer {
154 unsigned int FTBFlags: 16;
155 unsigned int APVdataSizeCut: 1;
156 unsigned int FADCdataSizeCut: 1;
157 unsigned int DummyAPVHeader: 1;
158 unsigned int PiplAddrMismatch: 1;
159 unsigned int nullDigits: 4;
160 unsigned int apvErrOR : 4;
161 unsigned int check : 4;
162 };
163
165 struct FTBTrailer {
166 unsigned int crc16 : 16;
167 unsigned int controlWord : 16;
168 };
169
170 union { // The 4 byte words of the stream can be interpreted as:
171 uint32_t m_data32 = 0;
179 };
180
184
188
191
198
202 bool m_killUpsetDigits = false;
203
211 bool m_silentAppend = false;
212
216 bool m_badMappingFatal = false;
217
220
224 int m_errorRate{1000};
225
227 unsigned short seenHeadersAndTrailers: 4;
228
237 int nAPVErrors = 0;
240
242 std::map<std::pair<unsigned short, unsigned short>, std::pair<std::size_t, std::size_t> > m_missingAPVs;
243
245 std::map<std::pair<unsigned short, unsigned short>, std::pair<std::size_t, std::size_t> > m_upsetAPVs;
247 std::map<std::pair<unsigned short, unsigned short>, std::pair<std::size_t, std::size_t> > m_seuRecMap;
248
250 std::vector<SVDDAQDiagnostic> m_diagnostics;
251
253 std::vector<std::pair<SVDShaperDigit, std::size_t> > m_digitsWithDiag;
254
257 std::vector<uint64_t> m_digitSortKeys;
258
260 std::vector<uint32_t> m_apvsByPipeline;
261
263 0;
264
266
267 };//end class declaration
268
269}
Class for accessing objects in the database.
Definition DBObjPtr.h:21
Module()
Constructor.
Definition Module.cc:30
Class to store SVD mode information.
Definition SVDModeByte.h:69
Class to store Trigger Type information.
int m_wrongFTBcrc
FTB CRC no-Match counter.
StoreArray< SVDDAQDiagnostic > m_storeDAQDiagnostics
SVDDAQDiagnostic array.
unsigned short seenHeadersAndTrailers
this 4-bits value should be 1111 if no headers/trailers are missing
int m_shutUpFTBError
regulates the number of "Event number mismatch" errors reported
MainHeader m_MainHeader
Implementation of FADC Header.
StoreArray< RawSVD > m_rawSVD
output for RawSVD
FADCTrailer m_FADCTrailer
Implementation of FADC Trailer.
StoreObjPtr< SVDEventInfo > m_svdEventInfoPtr
SVDEventInfo output per event.
virtual void initialize() override
Initializes the Module.
std::vector< uint64_t > m_digitSortKeys
Event-local sort keys of the digits: (sensorID, side, strip, insertion index) packed so that sorting ...
StoreArray< SVDShaperDigit > m_storeShaperDigits
SVDShaperDigit array.
virtual void event() override
event
SVDUnpackerModule()
Constructor of the module.
int nAPVErrors
counter of APV errors
FTBHeader m_FTBHeader
Implementation of FTB Header.
virtual void endRun() override
end run
std::string m_rawSVDListName
RawSVD StoreArray name.
std::vector< SVDDAQDiagnostic > m_diagnostics
Event-local buffer of diagnostics; moved to the StoreArray once per event.
DBObjPtr< PayloadFile > m_mapping
pointer to the payload with the mapping
int nFADCMatchErrors
counter of FADC boards =/= n of RawData objects errors
bool m_killUpsetDigits
Optionally, we can kill digits coming from upset APVs right in the unpacker.
data_B m_data_B
Implementation of 2nd data word.
int m_FADCTriggerNumberOffset
FADC Trigger Offset.
std::map< std::pair< unsigned short, unsigned short >, std::pair< std::size_t, std::size_t > > m_missingAPVs
Map to store a list of missing APVs.
int nMissingAPVsErrors
counter of missing APVs errors
static std::string m_xmlFileName
XML filename.
int nEventMatchErrors
counter of Event match errors
FTBTrailer m_FTBTrailer
Implementation of FTB Trailer.
int m_errorRate
The parameter that indicates what fraction of B2ERRORs messages should be suppressed to not overload ...
APVHeader m_APVHeader
Implementation of APV Header.
int nUpsetAPVsErrors
counter of upset APV errors
virtual void beginRun() override
begin run
std::string m_svdShaperDigitListName
SVDShaperDigit StoreArray name.
DBObjPtr< HardwareClockSettings > m_hwClock
system clock
std::vector< uint32_t > m_apvsByPipeline
Event-local list of (pipeline address << 16 | FADC << 8 | APV) words.
std::string m_svdEventInfoName
SVDEventInfo name.
DBObjPtr< SVDGlobalConfigParameters > m_svdGlobalConfig
SVDGlobal Configuration payload.
bool m_printRaw
Optionally we can get printout of Raw Data words.
int nEventInfoMatchErrors
counter of inconsistencies in SVDEventInfo within an event
bool m_badMappingFatal
Optionally we can stop the unpacking if there is a missing APV/FADC combination in the mapping -> wro...
int nErrorFieldErrors
counter of event mismatch errors in FTB's ErrorField
std::map< std::pair< unsigned short, unsigned short >, std::pair< std::size_t, std::size_t > > m_seuRecMap
Map to store a list of APVs for special data for SEU recovery.
data_A m_data_A
Implementation of 1st data word.
uint32_t m_data32
Input 32-bit data word.
StoreObjPtr< EventMetaData > m_eventMetaDataPtr
Required input for EventMetaData.
bool m_silentAppend
Silently append new SVDShaperDigits to a pre-existing non-empty SVDShaperDigits storeArray.
std::unordered_multimap< unsigned char, unsigned char > * APVmap
pointer to APVforFADCmap filled by mapping procedure
SVDTriggerType m_SVDTriggerType
SVDTriggerType object.
SVDModeByte m_SVDModeByte
instance of SVDModeByte for the event
virtual ~SVDUnpackerModule() override
Destructor of the module.
std::unique_ptr< SVDOnlineToOfflineMap > m_map
Pointer to online-to-offline map.
int m_relativeTimeShift
latency difference between the 3- and 6-sample acquired events in units of APV clock / 4,...
std::map< std::pair< unsigned short, unsigned short >, std::pair< std::size_t, std::size_t > > m_upsetAPVs
Map to store a list of upset APVs.
int nFTBFlagsErrors
counter of errors in FTBFlags variable
int nSEURecoveryCase
counter of SEU Special Recovery data cases
bool m_emulatePipelineAddress
Software emulation of pipeline address This is a replacement of hardware pipeline address emulation.
std::vector< std::pair< SVDShaperDigit, std::size_t > > m_digitsWithDiag
Event-local buffer of digits, each with the index of its diagnostic in m_diagnostics.
std::string m_svdDAQDiagnosticsListName
SVDDAQDiagnostic StoreArray name.
int nTriggerMatchErrors
counters for specific ERRORS produced by the Unpacker
static void printB2Debug(const uint32_t *data32, const uint32_t *data32_min, const uint32_t *data32_max, int nWords)
additional function that prints raw data words
unsigned short nFADCboards
how many FADCs we have
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
Namespace to encapsulate code needed for simulation and reconstrucion of the SVD.
unsigned int pipelineAddr
Pipeline Address.
unsigned int CMC1
Common Mode Noise w/o masking out particle signals.
unsigned int check
MSB "10" - for APV Header identification.
unsigned int CMC2
Common Mode Noise after masking out particle signals.
unsigned int PiplAddrMismatch
Pipeline address mismatch detection flag.
unsigned int apvErrOR
APV Errors Field OR.
unsigned int DummyAPVHeader
Dummy APV Header included flag.
unsigned int check
MSB "1110" - for FADC Trailer identification.
unsigned int APVdataSizeCut
APV data-size cut flag.
unsigned int FADCdataSizeCut
FADC data-size cut flag.
unsigned int errorsField
FTB error fields.
unsigned int eventNumber
FTB event number.
unsigned int controlWord
MSB "ff55" - FADC Trailer ID.
unsigned int crc16
FTB CRC16 Checksum.
unsigned int DAQType
(from 2020c) Event type(0): "0"…3 or …6 acquisition mode, "1"…3-mixed-6 acquisition mode
unsigned int check
MSB "110" - for FADC Header identification.
unsigned int DAQMode
Event type(2:1): "00"…1-sample, "01"…3-sample, "10"…6-sample.
implementation of the first data word
unsigned int check
MSB "1" - for Data word identification.
implementation of the second data word
unsigned int check
MSB "1" - for Data word identification.