Belle II Software release-09-00-11
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 <string>
26
27namespace Belle2 {
33 namespace TOP {
34
39 class DataArray {
40
41 public:
42
49 DataArray(const int* data, int size, bool swap = false)
50 {
51 m_data = data;
52 m_size = size;
53 m_i = -1;
54 m_swap = swap;
56 }
57
64 int getWord()
65 {
66 m_i++;
67 if (m_i < m_size) {
68 m_checksumCounter += (m_data[m_i] & 0xFFFF) + ((m_data[m_i] >> 16) & 0xFFFF);
69 if (m_swap) return swap32(m_data[m_i]);
70 return m_data[m_i];
71 }
72 B2ERROR("Bug in data format: DataArray - index out of range");
73 return 0;
74 }
75
81 {
82 if (m_i + 1 < m_size) {
83 if (m_swap) return swap32(m_data[m_i + 1]);
84 return m_data[m_i + 1];
85 }
86
87 return 0;
88 }
89
95 {
96 if (m_size <= 0) return 0;
97 if (m_swap) return swap32(m_data[m_size - 1]);
98 return m_data[m_size - 1];
99 }
100
105 unsigned int getIndex() const {return m_i;}
106
111 int getRemainingWords() const {return m_size - m_i - 1;}
112
118
123 unsigned int foldChecksum()
124 {
125 unsigned int chk = m_checksumCounter;
126 while ((chk >> 16) > 0) {
127 chk = (chk & 0xFFFF) + (chk >> 16);
128 }
129 return chk;
130 };
131
138 {
139 return (foldChecksum() == 0xFFFF);
140 }
141
142 private:
143
147 int swap32(int x)
148 {
149 return (((x << 24) & 0xFF000000) |
150 ((x << 8) & 0x00FF0000) |
151 ((x >> 8) & 0x0000FF00) |
152 ((x >> 24) & 0x000000FF));
153 }
154
155 int m_size = 0;
156 const int* m_data = 0;
157 int m_i = 0;
158 bool m_swap = false;
159 unsigned int m_checksumCounter;
161 };
162
163 } // TOP namespace
164
165
172 class TOPUnpackerModule : public Module {
173
174 public:
175
180
184 virtual ~TOPUnpackerModule();
185
190 virtual void initialize() override;
191
196 virtual void beginRun() override;
197
201 virtual void event() override;
202
207 virtual void endRun() override;
208
213 virtual void terminate() override;
214
215 private:
216
220 short expand13to16bits(unsigned short x) const
221 {
222 unsigned short signBit = x & 0x1000;
223 return ((x & 0x1FFF) | signBit << 1 | signBit << 2 | signBit << 3);
224 }
225
226
230 unsigned short sumShorts(unsigned int x) const
231 {
232 return x + (x >> 16);
233 }
234
241 std::string getFrontEndName(RawTOP& raw, int finesse) const;
242
247 bool printTheError();
248
254 void unpackProductionDraft(const int* buffer, int bufferSize);
255
261 void unpackType0Ver16(const int* buffer, int bufferSize);
262
270 int unpackInterimFEVer01(const int* buffer, int bufferSize, bool pedestalSubtracted);
271
280 bool unpackHeadersInterimFEVer01(const int* buffer, int bufferSize, bool swapBytes);
281
291 int unpackProdDebug(const int* buffer, int bufferSize, TOP::RawDataType dataFormat, bool pedestalSubtracted, int expNo);
292
293 // module steering parameters
294
295 std::string m_inputRawDataName;
296 std::string m_outputDigitsName;
305 // collections
306
318 // other
319
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;
327 };
328
330} // Belle2 namespace
Base class for Modules.
Definition: Module.h:72
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
short expand13to16bits(unsigned short x) const
Expand 13-bit signed-word to 16-bit signed-word.
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
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
unsigned short sumShorts(unsigned int x) const
sum both 16-bit words of 32-bit integer
StoreArray< RawTOP > m_rawData
collection of raw data
StoreArray< TOPInterimFEInfo > m_interimFEInfos
collection of interim informations
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
std::string m_inputRawDataName
name of RawTOP store array
unsigned m_errorSuppressFactor
error messages suppression factor
StoreArray< TOPDigit > m_digits
collection of digits
unsigned m_eventCount
event count since last printed error message
bool m_addRelations
switch ON/OFF relations to TOPProductionHitDebugs
std::string m_templateFitResultName
name of TOPTemplateFitResult store array
TOP::TOPGeometryPar * m_topgp
geometry param
Helper class for getting data words from a finesse buffer Keeps checksum counter for each extracted d...
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.
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
int swap32(int x)
Swap bytes of a 32-bit integer.
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)
std::string getFrontEndName(RawTOP &raw, int finesse) const
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.
virtual void terminate() override
Termination action.
virtual void beginRun() override
Called when entering a new run.
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.
virtual ~TOPUnpackerModule()
Destructor.
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.