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>
31 #define ARICH_BUFFER_NWORDS 252
43 m_nonSuppressed(0), m_bitMask(0), m_debug(0)
79 int nModules = N_MERGERS * N_FEB2MERGER;
81 std::vector<const ARICHDigit*>* sortedDigits =
new std::vector<const ARICHDigit*>[nModules];
82 for (
const auto& digit : digits) {
83 int moduleID = digit.getModuleID();
84 unsigned mergerID =
m_mergerMap->getMergerID(moduleID);
85 if (!mergerID) { B2WARNING(
"No module2merger mapping for module ID: " << moduleID <<
"; Digit will not be packed!");
continue;}
86 if (!
m_copperMap->getCopperID(mergerID)) { B2WARNING(
"No merger2copper mapping for merger ID: " << mergerID <<
"; Digit will not be packed!");
continue;}
87 sortedDigits[moduleID - 1].push_back(&digit);
90 int buffer[4][ARICH_BUFFER_NWORDS];
92 for (
const auto& copperID :
m_copperMap->getCopperIDs()) {
94 int bufferSize[4] = {0, 0, 0, 0};
95 for (
int finesse = 0; finesse < 4; finesse++) {
99 for (
int j = 0; j < ARICH_BUFFER_NWORDS; j++) {
100 buffer[finesse][j] = 0;
103 auto* buf = buffer[finesse];
106 unsigned mergerID =
m_copperMap->getMergerID(copperID, finesse);
107 unsigned mergerSN =
m_mergerMap->getMergerSN(mergerID);
108 if (!mergerID)
continue;
112 mergerHead.type = dataFormat;
114 mergerHead.mergerID = mergerSN;
115 mergerHead.FEBSlot = 0;
116 mergerHead.trigger = evtMetaData->getEvent();
119 ibyte += ARICHRAW_HEADER_SIZE;
121 int nboards = N_FEB2MERGER;
123 for (
int k = 0; k < nboards; k++) {
125 int moduleID =
m_mergerMap->getModuleID(mergerID, k + 1);
126 if (moduleID <= 0)
continue;
130 FEBHead.type = dataFormat;
132 FEBHead.mergerID = mergerSN;
134 FEBHead.trigger = evtMetaData->getEvent();
138 FEBHead.length = 144 + ARICHFEB_HEADER_SIZE;
140 ibyte += ARICHFEB_HEADER_SIZE;
143 for (
const auto& digit : sortedDigits[moduleID - 1]) {
144 unsigned chn = digit->getChannelID();
146 unsigned shift = 143 - chn;
147 unsigned bitmap = (unsigned)digit->getBitmap();
148 buf[(ibyte + shift) / 4] += (bitmap << (3 - (ibyte + shift) % 4) * 8);
152 FEBHead.length = ARICHFEB_HEADER_SIZE + sortedDigits[moduleID - 1].size() * 2;
154 ibyte += ARICHFEB_HEADER_SIZE;
156 for (
const auto& digit : sortedDigits[moduleID - 1]) {
157 unsigned chn = digit->getChannelID();
159 unsigned shift = (3 - ibyte % 4) * 8;
160 buf[ibyte / 4] += (chn << shift);
162 shift = (3 - ibyte % 4) * 8;
163 unsigned bitmap = (unsigned)digit->getBitmap();
164 buf[ibyte / 4] += (bitmap << shift);
171 mergerHead.length = ibyte - ARICHRAW_HEADER_SIZE;
174 bufferSize[finesse] = ceil(ibyte / 4.);
177 std::cout <<
"Pack finesse: " << finesse << std::endl;
178 for (
int i = 0; i < bufferSize[finesse]; i++) {
179 std::cout << i <<
"-th word bitset " << std::bitset<32>(buf[i]) << std::endl;
185 info.exp_num = evtMetaData->getExperiment();
186 info.run_subrun_num = (evtMetaData->getRun() << 8) +
187 (evtMetaData->getSubrun() & 0xFF);
188 info.eve_num = evtMetaData->getEvent();
189 info.node_id = ARICH_ID + copperID;
193 info.hslb_crc16_error_bit = 0;
194 info.truncation_mask = 0;
195 info.type_of_data = 0;
198 raw->PackDetectorBuf(buffer[0], bufferSize[0],
199 buffer[1], bufferSize[1],
200 buffer[2], bufferSize[2],
201 buffer[3], bufferSize[3],
206 delete [] sortedDigits;
213 unsigned char line1[4];
216 line1[3] = head.type;
217 line1[2] = head.version;
218 line1[1] = head.mergerID;
219 line1[0] = head.FEBSlot;
221 for (
int i = 0; i < 4; i++) {
222 shift = (3 - ibyte % 4) * 8;
223 buffer[ibyte / 4] |= line1[3 - i] << shift;
227 auto len =
reinterpret_cast<const unsigned char*
>(&head.length);
229 for (
int i = 0; i < 4; i++) {
230 shift = (3 - ibyte % 4) * 8;
231 buffer[ibyte / 4] |= len[3 - i] << shift;
236 auto trg =
reinterpret_cast<const unsigned char*
>(&head.trigger);
237 for (
int i = 0; i < 4; i++) {
238 shift = (3 - ibyte % 4) * 8;
239 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.
virtual void event() override
Event processor.
virtual ~ARICHPackerModule()
Destructor.
ARICHPackerModule()
Constructor.
REG_MODULE(arichBtest)
Register the Module.
void writeHeader(int *buffer, unsigned &ibyte, const ARICHRawHeader &head)
TODO!
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Abstract base class for different kinds of events.