Belle II Software  release-05-02-19
SVDUnpackerModule.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Jarek Wiechczynski, Giulia Casarosa, Eugenio Paoloni *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #ifndef SVDUnpackerModule_H
12 #define SVDUnpackerModule_H
13 
14 #include <framework/core/Module.h>
15 
16 #include <svd/geometry/SensorInfo.h>
17 
18 #include <framework/datastore/StoreArray.h>
19 #include <framework/datastore/StoreObjPtr.h>
20 #include <vxd/dataobjects/VxdID.h>
21 #include <rawdata/dataobjects/RawSVD.h>
22 #include <svd/dataobjects/SVDShaperDigit.h>
23 #include <svd/dataobjects/SVDTransparentDigit.h>
24 #include <svd/dataobjects/SVDDAQDiagnostic.h>
25 #include <svd/dataobjects/SVDEventInfo.h>
26 #include <svd/dataobjects/SVDTriggerType.h>
27 
28 #include <svd/online/SVDOnlineToOfflineMap.h>
29 #include <svd/online/SVDStripNoiseMap.h>
30 #include <framework/dataobjects/EventMetaData.h>
31 #include <memory>
32 #include <framework/database/PayloadFile.h>
33 
34 namespace Belle2 {
40  namespace SVD {
41 
49  class SVDUnpackerModule : public Module {
50 
51  public:
56 
60  virtual ~SVDUnpackerModule();
61 
65  virtual void initialize() override;
66  virtual void beginRun() override;
67  virtual void event() override;
68  virtual void endRun() override;
70  std::string m_rawSVDListName;
71  std::string m_svdShaperDigitListName;
72  std::string m_svdDAQDiagnosticsListName;
73  std::string m_svdEventInfoName;
75  int m_wrongFTBcrc;
78  private:
79 
81  unsigned short nFADCboards;
82 
84  std::unordered_multimap<unsigned char, unsigned char>* APVmap;
85 
87  std::unique_ptr<SVDOnlineToOfflineMap> m_map;
88 
90  static std::string m_xmlFileName;
91 
94 
97 
99  void printB2Debug(uint32_t* data32, uint32_t* data32_min, uint32_t* data32_max, int nWords);
100 
101  // The following assumes i386 byte order: MSB comes last!
102 
104  struct FTBHeader {
105  unsigned int errorsField : 8;
106  unsigned int eventNumber : 24;
107  };
108 
110  struct MainHeader {
111  unsigned int trgNumber : 8;
112  unsigned int trgType : 4;
113  unsigned int trgTiming : 2;
114  unsigned int xTalk : 2;
115  unsigned int FADCnum : 8;
116  unsigned int DAQType : 1;
117  unsigned int DAQMode : 2;
118  unsigned int runType : 2;
119  unsigned int check : 3;
120  };
121 
123  struct APVHeader {
124  unsigned int CMC1 : 8;
125  unsigned int CMC2 : 4;
126  unsigned int apvErr : 4;
127  unsigned int pipelineAddr : 8;
128  unsigned int APVnum : 6;
129  unsigned int check : 2;
130  };
131 
133  struct data_A {
134  unsigned int sample1 : 8;
135  unsigned int sample2 : 8;
136  unsigned int sample3 : 8;
137  unsigned int stripNum : 7;
138  unsigned int check : 1;
139  };
140 
142  struct data_B {
143  unsigned int sample4 : 8;
144  unsigned int sample5 : 8;
145  unsigned int sample6 : 8;
146  unsigned int stripNum : 7;
147  unsigned int check : 1;
148  };
149 
151  struct FADCTrailer {
152  unsigned int FTBFlags: 16;
153  unsigned int dataSizeCut: 1;
154  unsigned int nullDigits: 7;
155  unsigned int apvErrOR : 4;
156  unsigned int check : 4;
157  };
158 
160  struct FTBTrailer {
161  unsigned int crc16 : 16;
162  unsigned int controlWord : 16;
163  };
164 
165 
166  union { // The 4 byte words of the stream can be interpreted as:
167  uint32_t m_data32;
171  data_A m_data_A;
172  data_B m_data_B;
175  };
176 
183  int m_shutUpFTBError;
192 
196  bool m_killUpsetDigits = false;
197 
205  bool m_silentAppend = false;
206 
210  bool m_badMappingFatal = false;
211 
214 
218  int m_errorRate{1000};
219 
221  unsigned short seenHeadersAndTrailers: 4;
222 
224  int nTriggerMatchErrors;
225  int nEventMatchErrors;
227  int nErrorFieldErrors;
228  int nMissingAPVsErrors;
230  int nAPVErrors;
231  int nFTBFlagsErrors;
235  std::map<std::pair<unsigned short, unsigned short>, std::pair<std::size_t, std::size_t> > m_missingAPVs;
236 
238  std::map<std::pair<unsigned short, unsigned short>, std::pair<std::size_t, std::size_t> > m_upsetAPVs;
239 
242  };//end class declaration
243 
244 
245  } //end SVD namespace;
247 } // end namespace Belle2
248 
249 #endif // SVDUnpackerModule_H
250 
Belle2::SVD::SVDUnpackerModule::m_svdShaperDigitListName
std::string m_svdShaperDigitListName
SVDShaperDigit StoreArray name.
Definition: SVDUnpackerModule.h:79
Belle2::SVD::SVDUnpackerModule::APVHeader::check
unsigned int check
MSB "10" - for APV Header identification.
Definition: SVDUnpackerModule.h:137
Belle2::SVD::SVDUnpackerModule::APVHeader::APVnum
unsigned int APVnum
APV chip number.
Definition: SVDUnpackerModule.h:136
Belle2::SVD::SVDUnpackerModule::m_FTBTrailer
FTBTrailer m_FTBTrailer
Implementation of FTB Trailer.
Definition: SVDUnpackerModule.h:182
Belle2::SVD::SVDUnpackerModule::APVHeader::CMC2
unsigned int CMC2
Common Mode Noise after masking out particle signals.
Definition: SVDUnpackerModule.h:133
Belle2::SVD::SVDUnpackerModule::MainHeader::check
unsigned int check
MSB "110" - for FADC Header identification.
Definition: SVDUnpackerModule.h:127
Belle2::DBObjPtr< PayloadFile >
Specialization of DBObjPtr in case of PayloadFiles.
Definition: PayloadFile.h:64
Belle2::SVD::SVDUnpackerModule::data_A::sample2
unsigned int sample2
2nd data sample
Definition: SVDUnpackerModule.h:143
Belle2::SVDTriggerType
Class to store Trigger Type information.
Definition: SVDTriggerType.h:33
Belle2::SVD::SVDUnpackerModule::m_rawSVDListName
std::string m_rawSVDListName
RawSVD StoreArray name.
Definition: SVDUnpackerModule.h:78
Belle2::SVD::SVDUnpackerModule::m_wrongFTBcrc
int m_wrongFTBcrc
FTB CRC no-Match counter.
Definition: SVDUnpackerModule.h:83
Belle2::SVD::SVDUnpackerModule::m_upsetAPVs
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.
Definition: SVDUnpackerModule.h:246
Belle2::SVD::SVDUnpackerModule::data_A
implementation of the first data word
Definition: SVDUnpackerModule.h:141
Belle2::SVD::SVDUnpackerModule::m_FADCTriggerNumberOffset
int m_FADCTriggerNumberOffset
FADC Trigger Offset.
Definition: SVDUnpackerModule.h:192
Belle2::SVD::SVDUnpackerModule::nTriggerMatchErrors
int nTriggerMatchErrors
counters for specific ERRORS produced by the Unpacker
Definition: SVDUnpackerModule.h:232
Belle2::SVD::SVDUnpackerModule::MainHeader
implementation of FADC Header
Definition: SVDUnpackerModule.h:118
Belle2::SVD::SVDUnpackerModule::data_B::sample4
unsigned int sample4
4th data sample
Definition: SVDUnpackerModule.h:151
Belle2::SVD::SVDUnpackerModule::m_missingAPVs
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.
Definition: SVDUnpackerModule.h:243
Belle2::SVD::SVDUnpackerModule::nFADCboards
unsigned short nFADCboards
how many FADCs we have
Definition: SVDUnpackerModule.h:89
Belle2::SVD::SVDUnpackerModule::data_A::sample3
unsigned int sample3
3rd data sample
Definition: SVDUnpackerModule.h:144
Belle2::SVD::SVDUnpackerModule::data_B::sample5
unsigned int sample5
5th data sample
Definition: SVDUnpackerModule.h:152
Belle2::SVD::SVDUnpackerModule::FTBTrailer::crc16
unsigned int crc16
FTB CRC16 Checksum
Definition: SVDUnpackerModule.h:169
Belle2::SVD::SVDUnpackerModule::m_APVHeader
APVHeader m_APVHeader
Implementation of APV Header.
Definition: SVDUnpackerModule.h:178
Belle2::SVD::SVDUnpackerModule::nErrorFieldErrors
int nErrorFieldErrors
counter of event mismatch errors in FTB's ErrorField
Definition: SVDUnpackerModule.h:235
Belle2::SVD::SVDUnpackerModule::FADCTrailer::apvErrOR
unsigned int apvErrOR
APV Errors Field OR.
Definition: SVDUnpackerModule.h:163
Belle2::SVD::SVDUnpackerModule::FADCTrailer::FTBFlags
unsigned int FTBFlags
FTB Flags Field.
Definition: SVDUnpackerModule.h:160
Belle2::SVD::SVDUnpackerModule::APVmap
std::unordered_multimap< unsigned char, unsigned char > * APVmap
pointer to APVforFADCmap filled by mapping procedure
Definition: SVDUnpackerModule.h:92
Belle2::SVD::SVDUnpackerModule::data_A::check
unsigned int check
MSB "1" - for Data word identification.
Definition: SVDUnpackerModule.h:146
Belle2::SVD::SVDUnpackerModule::FADCTrailer::nullDigits
unsigned int nullDigits
"0000000"
Definition: SVDUnpackerModule.h:162
Belle2::SVD::SVDUnpackerModule::m_data32
uint32_t m_data32
Input 32-bit data word.
Definition: SVDUnpackerModule.h:175
Belle2::SVD::SVDUnpackerModule::beginRun
virtual void beginRun() override
begin run
Definition: SVDUnpackerModule.cc:97
Belle2::SVDModeByte
Class to store SVD mode information.
Definition: SVDModeByte.h:79
Belle2::SVD::SVDUnpackerModule::MainHeader::trgType
unsigned int trgType
Trigger Type.
Definition: SVDUnpackerModule.h:120
Belle2::SVD::SVDUnpackerModule::m_svdEventInfoName
std::string m_svdEventInfoName
SVDEventInfo name.
Definition: SVDUnpackerModule.h:81
Belle2::SVD::SVDUnpackerModule::APVHeader::apvErr
unsigned int apvErr
APV Errors field.
Definition: SVDUnpackerModule.h:134
Belle2::SVD::SVDUnpackerModule::APVHeader::pipelineAddr
unsigned int pipelineAddr
Pipeline Address.
Definition: SVDUnpackerModule.h:135
Belle2::SVD::SVDUnpackerModule::FTBHeader::eventNumber
unsigned int eventNumber
FTB event number.
Definition: SVDUnpackerModule.h:114
Belle2::SVD::SVDUnpackerModule::m_data_B
data_B m_data_B
Implementation of 2nd data word.
Definition: SVDUnpackerModule.h:180
Belle2::SVD::SVDUnpackerModule::FADCTrailer
implementation of FADC Trailer
Definition: SVDUnpackerModule.h:159
Belle2::SVD::SVDUnpackerModule::FTBHeader::errorsField
unsigned int errorsField
FTB error fields.
Definition: SVDUnpackerModule.h:113
Belle2::SVD::SVDUnpackerModule::nMissingAPVsErrors
int nMissingAPVsErrors
counter of missing APVs errors
Definition: SVDUnpackerModule.h:236
Belle2::SVD::SVDUnpackerModule::data_A::stripNum
unsigned int stripNum
Strip number.
Definition: SVDUnpackerModule.h:145
Belle2::SVD::SVDUnpackerModule::m_rawSVD
StoreArray< RawSVD > m_rawSVD
output for RawSVD
Definition: SVDUnpackerModule.h:189
Belle2::SVD::SVDUnpackerModule::m_shutUpFTBError
int m_shutUpFTBError
regulates the number of "Event number mismatch" errors reported
Definition: SVDUnpackerModule.h:191
Belle2::SVD::SVDUnpackerModule::MainHeader::FADCnum
unsigned int FADCnum
FADC number.
Definition: SVDUnpackerModule.h:123
Belle2::SVD::SVDUnpackerModule::m_svdEventInfoPtr
StoreObjPtr< SVDEventInfo > m_svdEventInfoPtr
SVDEventInfo output per event.
Definition: SVDUnpackerModule.h:186
Belle2::SVD::SVDUnpackerModule::seenHeadersAndTrailers
unsigned short seenHeadersAndTrailers
this 4-bits value should be 1111 if no headers/trailers are missing
Definition: SVDUnpackerModule.h:229
Belle2::SVD::SVDUnpackerModule::m_silentAppend
bool m_silentAppend
Silently append new SVDShaperDigits to a pre-existing non-empty SVDShaperDigits storeArray.
Definition: SVDUnpackerModule.h:213
Belle2::SVD::SVDUnpackerModule::FTBHeader
implementation of FTB Header
Definition: SVDUnpackerModule.h:112
Belle2::SVD::SVDUnpackerModule::nFTBFlagsErrors
int nFTBFlagsErrors
counter of errors in FTBFlags variable
Definition: SVDUnpackerModule.h:239
Belle2::SVD::SVDUnpackerModule::m_map
std::unique_ptr< SVDOnlineToOfflineMap > m_map
Pointer to online-to-offline map.
Definition: SVDUnpackerModule.h:95
Belle2::SVD::SVDUnpackerModule::printB2Debug
void printB2Debug(uint32_t *data32, uint32_t *data32_min, uint32_t *data32_max, int nWords)
additional function that prints raw data words
Definition: SVDUnpackerModule.cc:653
Belle2::SVD::SVDUnpackerModule::event
virtual void event() override
event
Definition: SVDUnpackerModule.cc:146
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::SVD::SVDUnpackerModule::m_MainHeader
MainHeader m_MainHeader
Implementation of FADC Header.
Definition: SVDUnpackerModule.h:177
Belle2::SVD::SVDUnpackerModule::m_FTBHeader
FTBHeader m_FTBHeader
Implementation of FTB Header.
Definition: SVDUnpackerModule.h:176
Belle2::StoreObjPtr
Type-safe access to single objects in the data store.
Definition: ParticleList.h:33
Belle2::SVD::SVDUnpackerModule::SVDUnpackerModule
SVDUnpackerModule()
Constructor of the module.
Definition: SVDUnpackerModule.cc:49
Belle2::SVD::SVDUnpackerModule::data_A::sample1
unsigned int sample1
1st data sample
Definition: SVDUnpackerModule.h:142
Belle2::SVD::SVDUnpackerModule::m_SVDTriggerType
SVDTriggerType m_SVDTriggerType
SVDTriggerType object.
Definition: SVDUnpackerModule.h:187
Belle2::SVD::SVDUnpackerModule::m_data_A
data_A m_data_A
Implementation of 1st data word.
Definition: SVDUnpackerModule.h:179
Belle2::SVD::SVDUnpackerModule::MainHeader::runType
unsigned int runType
Run Type.
Definition: SVDUnpackerModule.h:126
Belle2::SVD::SVDUnpackerModule::m_emulatePipelineAddress
bool m_emulatePipelineAddress
Software emulation of pipeline address This is a replacement of hardware pipeline address emulation.
Definition: SVDUnpackerModule.h:199
Belle2::SVD::SVDUnpackerModule::MainHeader::trgNumber
unsigned int trgNumber
Trigger Number.
Definition: SVDUnpackerModule.h:119
Belle2::SVD::SVDUnpackerModule::data_B::check
unsigned int check
MSB "1" - for Data word identification.
Definition: SVDUnpackerModule.h:155
Belle2::SVD::SVDUnpackerModule::nEventMatchErrors
int nEventMatchErrors
counter of Event match errors
Definition: SVDUnpackerModule.h:233
Belle2::SVD::SVDUnpackerModule::initialize
virtual void initialize() override
Initializes the Module.
Definition: SVDUnpackerModule.cc:78
Belle2::SVD::SVDUnpackerModule::data_B::sample6
unsigned int sample6
6th data sample
Definition: SVDUnpackerModule.h:153
Belle2::SVD::SVDUnpackerModule::APVHeader::CMC1
unsigned int CMC1
Common Mode Noise w/o masking out particle signals.
Definition: SVDUnpackerModule.h:132
Belle2::SVD::SVDUnpackerModule::nFADCMatchErrors
int nFADCMatchErrors
counter of FADC boards =/= n of RawData objects errors
Definition: SVDUnpackerModule.h:237
Belle2::SVD::SVDUnpackerModule::MainHeader::DAQMode
unsigned int DAQMode
Event type(2:1): "00"…1-sample, "01"…3-sample, "10"…6-sample.
Definition: SVDUnpackerModule.h:125
Belle2::SVD::SVDUnpackerModule::MainHeader::trgTiming
unsigned int trgTiming
Trigger Timing.
Definition: SVDUnpackerModule.h:121
Belle2::SVD::SVDUnpackerModule::nEventInfoMatchErrors
int nEventInfoMatchErrors
counter of inconsistencies in SVDEventInfo within an event
Definition: SVDUnpackerModule.h:240
Belle2::SVD::SVDUnpackerModule::data_B::stripNum
unsigned int stripNum
Strip number.
Definition: SVDUnpackerModule.h:154
Belle2::SVD::SVDUnpackerModule::m_SVDModeByte
SVDModeByte m_SVDModeByte
instance of SVDModeByte for the event
Definition: SVDUnpackerModule.h:104
Belle2::SVD::SVDUnpackerModule::~SVDUnpackerModule
virtual ~SVDUnpackerModule()
Destructor of the module.
Definition: SVDUnpackerModule.cc:74
Belle2::SVD::SVDUnpackerModule::MainHeader::xTalk
unsigned int xTalk
cross talk tag
Definition: SVDUnpackerModule.h:122
Belle2::SVD::SVDUnpackerModule::FTBTrailer
implementation of FTB Trailer
Definition: SVDUnpackerModule.h:168
Belle2::SVD::SVDUnpackerModule::m_badMappingFatal
bool m_badMappingFatal
Optionally we can stop the unpacking if there is a missing APV/FADC combination in the mapping -> wro...
Definition: SVDUnpackerModule.h:218
Belle2::SVD::SVDUnpackerModule::endRun
virtual void endRun() override
end run
Definition: SVDUnpackerModule.cc:634
Belle2::SVD::SVDUnpackerModule::APVHeader
implementation of APV Header
Definition: SVDUnpackerModule.h:131
Belle2::SVD::SVDUnpackerModule::m_svdDAQDiagnosticsListName
std::string m_svdDAQDiagnosticsListName
SVDDAQDiagnostic StoreArray name.
Definition: SVDUnpackerModule.h:80
Belle2::StoreArray
Accessor to arrays stored in the data store.
Definition: ECLMatchingPerformanceExpertModule.h:33
Belle2::SVD::SVDUnpackerModule::FADCTrailer::check
unsigned int check
MSB "1110" - for FADC Trailer identification.
Definition: SVDUnpackerModule.h:164
Belle2::SVD::SVDUnpackerModule::data_B
implementation of the second data word
Definition: SVDUnpackerModule.h:150
Belle2::SVD::SVDUnpackerModule::m_mapping
DBObjPtr< PayloadFile > m_mapping
pointer to the payload with the mapping
Definition: SVDUnpackerModule.h:101
Belle2::SVD::SVDUnpackerModule::m_relativeTimeShift
int m_relativeTimeShift
latency difference between the 3- and 6-sample acquired events in usint of APV clock / 4,...
Definition: SVDUnpackerModule.h:248
Belle2::SVD::SVDUnpackerModule::FADCTrailer::dataSizeCut
unsigned int dataSizeCut
APV data-size cut flag
Definition: SVDUnpackerModule.h:161
Belle2::SVD::SVDUnpackerModule::FTBTrailer::controlWord
unsigned int controlWord
MSB "ff55" - FADC Trailer ID.
Definition: SVDUnpackerModule.h:170
Belle2::SVD::SVDUnpackerModule::m_FADCTrailer
FADCTrailer m_FADCTrailer
Implementation of FADC Trailer.
Definition: SVDUnpackerModule.h:181
Belle2::SVD::SVDUnpackerModule::nAPVErrors
int nAPVErrors
counter of APV errors
Definition: SVDUnpackerModule.h:238
Belle2::SVD::SVDUnpackerModule::m_xmlFileName
static std::string m_xmlFileName
XML filename.
Definition: SVDUnpackerModule.h:98
Belle2::SVD::SVDUnpackerModule::nUpsetAPVsErrors
int nUpsetAPVsErrors
counter of upset APV errors
Definition: SVDUnpackerModule.h:234
Belle2::SVD::SVDUnpackerModule::m_killUpsetDigits
bool m_killUpsetDigits
Optionally, we can kill digits coming from upset APVs right in the unpacker.
Definition: SVDUnpackerModule.h:204
Belle2::SVD::SVDUnpackerModule::m_eventMetaDataPtr
StoreObjPtr< EventMetaData > m_eventMetaDataPtr
Required input for EventMetaData.
Definition: SVDUnpackerModule.h:185
Belle2::SVD::SVDUnpackerModule::m_printRaw
bool m_printRaw
Optionally we can get printout of Raw Data words.
Definition: SVDUnpackerModule.h:221
Belle2::SVD::SVDUnpackerModule::MainHeader::DAQType
unsigned int DAQType
(from 2020c) Event type(0): "0"…3 or …6 acquisition mode, "1"…3-mixed-6 acquisition mode
Definition: SVDUnpackerModule.h:124
Belle2::SVD::SVDUnpackerModule::m_errorRate
int m_errorRate
The parameter that indicates what fraction of B2ERRORs messages should be suppressed to not overload ...
Definition: SVDUnpackerModule.h:226