Belle II Software prerelease-11-00-00a
TOPUnpackerModule.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 <top/geometry/TOPGeometryPar.h>
13#include <framework/datastore/StoreArray.h>
14#include <rawdata/dataobjects/RawTOP.h>
15#include <top/RawDataTypes.h>
16#include <top/dataobjects/TOPDigit.h>
17#include <top/dataobjects/TOPRawWaveform.h>
18#include <top/dataobjects/TOPRawDigit.h>
19#include <top/dataobjects/TOPSlowData.h>
20#include <top/dataobjects/TOPInterimFEInfo.h>
21#include <top/dataobjects/TOPTemplateFitResult.h>
22#include <top/dataobjects/TOPProductionEventDebug.h>
23#include <top/dataobjects/TOPProductionHitDebug.h>
24#include <top/dataobjects/TOPInjectionVeto.h>
25#include <top/dataobjects/TOPUnpackerErrors.h>
26#include <string>
27
28namespace Belle2 {
33
34 namespace TOP {
35
40 class DataArray {
41
42 public:
43
50 DataArray(const int* data, int size, bool swap = false)
51 {
52 m_data = data;
53 m_size = size;
54 m_i = -1;
55 m_swap = swap;
57 }
58
65 int getWord()
66 {
67 m_i++;
68 if (m_i < m_size) {
69 m_checksumCounter += (m_data[m_i] & 0xFFFF) + ((m_data[m_i] >> 16) & 0xFFFF);
70 if (m_swap) return swap32(m_data[m_i]);
71 return m_data[m_i];
72 }
73 B2ERROR("Bug in data format: DataArray - index out of range");
74 return 0;
75 }
76
82 {
83 if (m_i + 1 < m_size) {
84 if (m_swap) return swap32(m_data[m_i + 1]);
85 return m_data[m_i + 1];
86 }
87
88 return 0;
89 }
90
96 {
97 if (m_size <= 0) return 0;
98 if (m_swap) return swap32(m_data[m_size - 1]);
99 return m_data[m_size - 1];
100 }
101
106 unsigned int getIndex() const {return m_i;}
107
112 int getRemainingWords() const {return m_size - m_i - 1;}
113
119
124 unsigned int foldChecksum()
125 {
126 unsigned int chk = m_checksumCounter;
127 while ((chk >> 16) > 0) {
128 chk = (chk & 0xFFFF) + (chk >> 16);
129 }
130 return chk;
131 };
132
139 {
140 return (foldChecksum() == 0xFFFF);
141 }
142
143 private:
144
148 static int swap32(int x)
149 {
150 return (((x << 24) & 0xFF000000) |
151 ((x << 8) & 0x00FF0000) |
152 ((x >> 8) & 0x0000FF00) |
153 ((x >> 24) & 0x000000FF));
154 }
155
156 int m_size = 0;
157 const int* m_data = 0;
158 int m_i = 0;
159 bool m_swap = false;
160 unsigned int m_checksumCounter;
161
162 };
163
164 } // TOP namespace
165
166
173 class TOPUnpackerModule : public Module {
174
175 public:
176
181
186 virtual void initialize() override;
187
192 virtual void beginRun() override;
193
197 virtual void event() override;
198
203 virtual void endRun() override;
204
205 private:
206
210 static short expand13to16bits(unsigned short x)
211 {
212 unsigned short signBit = x & 0x1000;
213 return ((x & 0x1FFF) | signBit << 1 | signBit << 2 | signBit << 3);
214 }
215
216
220 static unsigned short sumShorts(unsigned int x)
221 {
222 return x + (x >> 16);
223 }
224
231 static std::string getFrontEndName(RawTOP& raw, int finesse);
232
239 static unsigned getFrontEndNumber(RawTOP& raw, int finesse);
240
245 bool printTheError();
246
252 void unpackProductionDraft(const int* buffer, int bufferSize);
253
259 void unpackType0Ver16(const int* buffer, int bufferSize);
260
268 int unpackInterimFEVer01(const int* buffer, int bufferSize, bool pedestalSubtracted);
269
278 static bool unpackHeadersInterimFEVer01(const int* buffer, int bufferSize, bool swapBytes);
279
289 int unpackProdDebug(const int* buffer, int bufferSize, TOP::RawDataType dataFormat, bool pedestalSubtracted, int expNo);
290
291 // module steering parameters
292
293 std::string m_inputRawDataName;
294 std::string m_outputDigitsName;
302
303 // collections
304
316
317 // other
318
319 bool m_swapBytes = false;
320 unsigned m_eventCount = 0;
321 unsigned m_errorCount = 0;
322 bool m_resetEventCount = false;
323 unsigned m_numErrors = 0;
325 std::map<int, int> m_channelStatistics;
326 unsigned m_BS = 0;
327
328 };
329
331} // Belle2 namespace
Module()
Constructor.
Definition Module.cc:30
The Raw TOP class Class for RawCOPPER class data taken by TOP Currently, this class is almost same as...
Definition RawTOP.h:27
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
StoreArray< TOPRawWaveform > m_waveforms
collection of waveforms
StoreArray< TOPRawDigit > m_rawDigits
collection of raw digits
unsigned m_numErrors
number of error messages per event
unsigned m_errorCount
error messages count within single event
std::map< int, int > m_channelStatistics
counts how many different channels have been parsed in a given SCROD packet
StoreArray< TOPSlowData > m_slowData
collection of slow data
bool m_swapBytes
if true, swap bytes (used in unpacking)
StoreArray< TOPProductionEventDebug > m_productionEventDebugs
collection of event debug data
std::string m_outputRawDigitsName
name of TOPRawDigit store array
std::string m_outputWaveformsName
name of TOPRawWaveform store array
StoreArray< RawTOP > m_rawData
collection of raw data
StoreArray< TOPInterimFEInfo > m_interimFEInfos
collection of interim information
bool m_resetEventCount
request for event count reset
StoreObjPtr< TOPInjectionVeto > m_injectionVeto
injection veto flag
StoreArray< TOPProductionHitDebug > m_productionHitDebugs
collection of hit debug data
std::string m_outputDigitsName
name of TOPDigit store array
StoreArray< TOPTemplateFitResult > m_templateFitResults
collection of template fit results
bool m_swapBytesDefault
if true, swap bytes (default by module parameter)
std::string m_inputRawDataName
name of RawTOP store array
StoreObjPtr< TOPUnpackerErrors > m_unpackerErrors
unpacker error flags
unsigned m_errorSuppressFactor
error messages suppression factor
static short expand13to16bits(unsigned short x)
Expand 13-bit signed-word to 16-bit signed-word.
StoreArray< TOPDigit > m_digits
collection of digits
unsigned m_BS
temporary boardstack number within the TOP detector
unsigned m_eventCount
event count since last printed error message
bool m_addRelations
switch ON/OFF relations to TOPProductionHitDebugs
static unsigned short sumShorts(unsigned int x)
sum both 16-bit words of 32-bit integer
std::string m_templateFitResultName
name of TOPTemplateFitResult store array
TOP::TOPGeometryPar * m_topgp
geometry param
int getRemainingWords() const
Returns number of remaining words in the buffer.
int getWord()
Returns consecutive data word Updates internal checksum counter for each extracted word.
DataArray(const int *data, int size, bool swap=false)
Constructor.
static int swap32(int x)
Swap bytes of a 32-bit integer.
void resetChecksum()
Resets internal checksum counter.
unsigned int getIndex() const
Returns index of last returned data word.
unsigned int foldChecksum()
Performs folding of carry bits into checksum until only 16 LSBs are populated.
const int * m_data
buffer data
bool m_swap
if true, swap bytes
int peekWord()
Returns next data word without incrementing the memory pointer and without modifying the checksum cou...
bool validateChecksum()
Validates current checksum counter status.
int getLastWord()
Returns last data word.
unsigned int m_checksumCounter
check sum counter
Singleton class for TOP Geometry Parameters.
static TOPGeometryPar * Instance()
Static method to obtain the pointer to its instance.
void unpackProductionDraft(const int *buffer, int bufferSize)
Unpack raw data given in a tentative production format (will vanish in future)
static std::string getFrontEndName(RawTOP &raw, int finesse)
Returns the name of the front-end.
virtual void initialize() override
Initialize the Module.
virtual void event() override
Event processor.
virtual void endRun() override
End-of-run action.
void unpackType0Ver16(const int *buffer, int bufferSize)
Unpack raw data given in feature-extraction production format.
static unsigned getFrontEndNumber(RawTOP &raw, int finesse)
Returns front-end number; this should be the same as the boardstack number within the TOP counted fro...
virtual void beginRun() override
Called when entering a new run.
static bool unpackHeadersInterimFEVer01(const int *buffer, int bufferSize, bool swapBytes)
Tries to unpack raw data assuming it is in feature-extraction interim format.
int unpackProdDebug(const int *buffer, int bufferSize, TOP::RawDataType dataFormat, bool pedestalSubtracted, int expNo)
Unpack raw data given in production debugging format.
int unpackInterimFEVer01(const int *buffer, int bufferSize, bool pedestalSubtracted)
Unpack raw data given in feature-extraction interim format.
bool printTheError()
Error messages suppression logic.
Abstract base class for different kinds of events.