10#include <arich/modules/arichPacker/ARICHPackerModule.h>
13#include <framework/datastore/StoreArray.h>
14#include <framework/datastore/StoreObjPtr.h>
17#include <framework/logging/Logger.h>
20#include <arich/dataobjects/ARICHDigit.h>
21#include <rawdata/dataobjects/RawARICH.h>
22#include <framework/dataobjects/EventMetaData.h>
35#define ARICH_BUFFER_NWORDS 252
47 m_nonSuppressed(0), m_bitMask(0), m_debug(0)
83 int nModules = N_MERGERS * N_FEB2MERGER;
85 std::vector<const ARICHDigit*>* sortedDigits =
new std::vector<const ARICHDigit*>[nModules];
86 for (
const auto& digit : digits) {
87 int moduleID = digit.getModuleID();
88 unsigned mergerID =
m_mergerMap->getMergerID(moduleID);
89 if (!mergerID) { B2WARNING(
"No module2merger mapping for module ID: " << moduleID <<
"; Digit will not be packed!");
continue;}
90 if (!
m_copperMap->getCopperID(mergerID)) { B2WARNING(
"No merger2copper mapping for merger ID: " << mergerID <<
"; Digit will not be packed!");
continue;}
91 sortedDigits[moduleID - 1].push_back(&digit);
96 for (
const auto& copperID :
m_copperMap->getCopperIDs()) {
98 int bufferSize[4] = {0, 0, 0, 0};
99 for (
int finesse = 0; finesse < 4; finesse++) {
104 buffer[finesse][j] = 0;
107 auto* buf = buffer[finesse];
110 unsigned mergerID =
m_copperMap->getMergerID(copperID, finesse);
111 unsigned mergerSN =
m_mergerMap->getMergerSN(mergerID);
112 if (!mergerID)
continue;
116 mergerHead.
type = dataFormat;
120 mergerHead.
trigger = evtMetaData->getEvent();
125 int nboards = N_FEB2MERGER;
127 for (
int k = 0; k < nboards; k++) {
129 int moduleID =
m_mergerMap->getModuleID(mergerID, k + 1);
130 if (moduleID <= 0)
continue;
134 FEBHead.
type = dataFormat;
138 FEBHead.
trigger = evtMetaData->getEvent();
147 for (
const auto& digit : sortedDigits[moduleID - 1]) {
148 unsigned chn = digit->getChannelID();
150 unsigned shift = 143 - chn;
151 unsigned bitmap = (unsigned)digit->getBitmap();
152 buf[(ibyte + shift) / 4] += (bitmap << (3 - (ibyte + shift) % 4) * 8);
160 for (
const auto& digit : sortedDigits[moduleID - 1]) {
161 unsigned chn = digit->getChannelID();
163 unsigned shift = (3 - ibyte % 4) * 8;
164 buf[ibyte / 4] += (chn << shift);
166 shift = (3 - ibyte % 4) * 8;
167 unsigned bitmap = (unsigned)digit->getBitmap();
168 buf[ibyte / 4] += (bitmap << shift);
178 bufferSize[finesse] = ceil(ibyte / 4.);
181 std::cout <<
"Pack finesse: " << finesse << std::endl;
182 for (
int i = 0; i < bufferSize[finesse]; i++) {
183 std::cout << i <<
"-th word bitset " << std::bitset<32>(buf[i]) << std::endl;
189 info.exp_num = evtMetaData->getExperiment();
190 info.run_subrun_num = (evtMetaData->getRun() << 8) +
191 (evtMetaData->getSubrun() & 0xFF);
192 info.eve_num = evtMetaData->getEvent();
193 info.node_id = ARICH_ID + copperID;
197 info.hslb_crc16_error_bit = 0;
198 info.truncation_mask = 0;
199 info.type_of_data = 0;
202 raw->PackDetectorBuf(buffer[0], bufferSize[0],
203 buffer[1], bufferSize[1],
204 buffer[2], bufferSize[2],
205 buffer[3], bufferSize[3],
210 delete [] sortedDigits;
217 unsigned char line1[4];
220 line1[3] = head.
type;
225 for (
int i = 0; i < 4; i++) {
226 shift = (3 - ibyte % 4) * 8;
227 buffer[ibyte / 4] |= line1[3 - i] << shift;
231 auto len =
reinterpret_cast<const unsigned char*
>(&head.
length);
233 for (
int i = 0; i < 4; i++) {
234 shift = (3 - ibyte % 4) * 8;
235 buffer[ibyte / 4] |= len[3 - i] << shift;
240 auto trg =
reinterpret_cast<const unsigned char*
>(&head.
trigger);
241 for (
int i = 0; i < 4; i++) {
242 shift = (3 - ibyte % 4) * 8;
243 buffer[ibyte / 4] |= trg[3 - i] << shift;
DBObjPtr< ARICHMergerMapping > m_mergerMap
mapping of modules to mergers
unsigned m_nonSuppressed
type of data (1 nonsuppressed, 0 suppressed)
unsigned m_version
dataformat version
std::string m_inputDigitsName
name of ARICHDigit store array
unsigned m_bitMask
bitmask for hit detection (4bit/hit)
std::string m_outputRawDataName
name of RawARICH store array
DBObjPtr< ARICHCopperMapping > m_copperMap
mapping of mergers to coppers
void setDescription(const std::string &description)
Sets the description of the module.
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
struct to contain header information used by RawCOPPERFormat::Packer()
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
Accessor to arrays stored in the data store.
T * appendNew()
Construct a new T object at the end of the array.
Type-safe access to single objects in the data store.
virtual void initialize() override
Initialize the Module.
#define ARICHFEB_HEADER_SIZE
FEB header size in bytes.
virtual void event() override
Event processor.
#define ARICH_BUFFER_NWORDS
Arich number of words (ints) in buffer: 3 + 33 + 6 * 36 (3 merger header words + 5....
virtual ~ARICHPackerModule()
Destructor.
ARICHPackerModule()
Constructor.
void writeHeader(int *buffer, unsigned &ibyte, const ARICHRawHeader &head)
TODO!
#define ARICHRAW_HEADER_SIZE
Raw header size in bytes.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.