10#include <arich/modules/arichUnpacker/ARICHUnpackerModule.h>
12#include <arich/modules/arichUnpacker/ARICHRawDataHeader.h>
15#include <framework/datastore/StoreArray.h>
16#include <framework/datastore/StoreObjPtr.h>
19#include <framework/logging/Logger.h>
22#include <framework/dataobjects/EventMetaData.h>
23#include <rawdata/dataobjects/RawARICH.h>
24#include <arich/dataobjects/ARICHDigit.h>
25#include <arich/dataobjects/ARICHInfo.h>
26#include <arich/dataobjects/ARICHRawDigit.h>
55 addParam(
"bitMask",
m_bitMask,
"hit bit mask (8 bits/channel, only used for unsuppresed format!)", (uint8_t)0xFF);
78 digits.registerInDataStore();
99 bool m_pciedata =
false;
101 double vth_thscan = 0.0;
104 std::cout << std::endl <<
"------------------------" << std::endl;
105 std::cout <<
"Run: " << evtMetaData->getRun() <<
" Event: " << evtMetaData->getEvent() << std::endl;
106 std::cout <<
"------------------------" << std::endl << std::endl;
109 unsigned thscan_mode = 0;
113 for (
auto& raw : rawData) {
115 if (raw.GetMaxNumOfCh(0) == 48) { m_pciedata =
true; }
116 else if (raw.GetMaxNumOfCh(0) == 4) { m_pciedata =
false; }
117 else { B2FATAL(
"ARICHUnpackerModule: Invalid value of GetMaxNumOfCh from raw data: " <<
LogVar(
"Number of ch: ", raw.GetMaxNumOfCh(0))); }
119 for (
int finesse = 0; finesse < raw.GetMaxNumOfCh(0); finesse++) {
120 const int* buffer = raw.GetDetectorBuffer(0, finesse);
121 int bufferSize = raw.GetDetectorNwords(0, finesse);
127 trgtype = raw.GetTRGType(0);
138 std::cout <<
"Merger header" << std::endl;
142 int type = (int)head.
type;
146 unsigned int length_all = (
unsigned int)head.
length;
147 unsigned int mrg_evtno = (
unsigned int)head.
trigger;
154 if (raw.GetNodeID(0) == 0x4000001) {
155 rawdigit->
setCopperId(raw.GetNodeID(0) + (int)(finesse / 4));
156 }
else if (raw.GetNodeID(0) == 0x4000002) {
157 rawdigit->
setCopperId(0x400000A + (
int)(finesse / 4));
159 B2FATAL(
"ARICHUnpackerModule: Invalid Node ID from readout: " <<
LogVar(
"NodeID: ", raw.GetNodeID(0)));
170 unsigned begin = ibyte;
172 while (ibyte < head.
length) {
182 B2ERROR(
"ARICHUnpackerModule: data in FEB header not consistent with data in merger HEADER " <<
LogVar(
"FEB ID",
195 if (mergID == 99) { B2ERROR(
"ARICHUnpackerModule: unknown merger number. Merger data will be skipped. " <<
LogVar(
"merger ID", mergID) <<
LogVar(
"Serial Number", (
unsigned)head.
mergerID));
break;}
199 if (!moduleID) { B2ERROR(
"ARICHUnpackerModule: no merger to FEB mapping. Merger data will be skipped. " <<
LogVar(
"merger ID", mergID) <<
LogVar(
"Serial Number", (
unsigned)head.
mergerID) <<
LogVar(
"FEB slot", (
unsigned)febHead.
FEBSlot));
break;}
202 if (
m_debug) std::cout <<
"Hit channels: " << std::endl;
203 if (febHead.
type == 1) {
204 for (
int i = 0; i < dataLen / 2; i++) {
205 int shift = (3 - ibyte % 4) * 8;
206 uint8_t asicCh = buffer[ibyte / 4] >> shift;
208 shift = (3 - ibyte % 4) * 8;
209 uint8_t hitBitSet = buffer[ibyte / 4] >> shift;
210 if (
m_debug && hitBitSet) std::cout <<
"ch: " << (unsigned)asicCh <<
" " << std::bitset<8>(hitBitSet) << std::endl;
212 digits.appendNew(moduleID, (
unsigned)asicCh, hitBitSet);
215 }
else if (febHead.
type == 2) {
216 unsigned asicCh = 143;
217 for (
int i = 0; i < dataLen; i++) {
218 int shift = (3 - ibyte % 4) * 8;
219 uint8_t hitBitSet = buffer[ibyte / 4] >> shift;
222 digits.appendNew(moduleID, asicCh, hitBitSet);
227 }
else B2ERROR(
"ARICHUnpackerModule: Unknown data type" <<
LogVar(
"type", febHead.
type));
231 if (ceil(ibyte / 4.) != (
unsigned)bufferSize)
232 B2WARNING(
"ARICHUnpackerModule: data buffer size mismatch " <<
LogVar(
"size from copper", bufferSize) <<
LogVar(
"size from merger",
239 if (thscan_mode == 0 &&
m_rawmode == 0)
continue;
246 int type_feb = febHead.
type;
251 vth_thscan = (febHead.
vth * 0.0024) - 1.27;
252 unsigned int length = febHead.
length;
254 unsigned int jbyte = 0;
255 std::stringstream ss;
256 ss <<
"type=" << type_feb <<
", ver=" << ver <<
" "
257 <<
", boardid=" << boardid <<
", febno=" << febno
258 <<
", length=" << length <<
", evtno=" << evtno <<
" ";
260 long long feb_trigno = 0;
261 for (
int i = 0; i < 10; i++) {
264 if (i > 1 && i < 6) {
265 feb_trigno |= (0xff & val) << (5 - i) * 8;
269 if (type_feb == 0x02) {
272 while (jbyte < length) {
276 ss <<
"ch# " << ch <<
"(" << val <<
") ";
278 if (febno < 0 || febno > 6) {
279 B2ERROR(
"FEB is bad : " <<
LogVar(
"FEB no.", febno) <<
LogVar(
"hslb", finesse) <<
LogVar(
"type", type_feb) <<
LogVar(
"ver",
280 ver) <<
LogVar(
"boardid", boardid) <<
LogVar(
"febno", febno) <<
LogVar(
"length", length) <<
LogVar(
"evtno", evtno));
287 }
else if (type_feb == 0x01) {
292 while (jbyte < length) {
298 ss <<
"ch# " << ch <<
"(" << val <<
") ";
300 if (febno < 0 || febno > 6) {
301 B2ERROR(
"FEB is bad : " <<
LogVar(
"FEB no.", febno) <<
LogVar(
"hslb", finesse) <<
LogVar(
"type", type_feb) <<
LogVar(
"ver",
302 ver) <<
LogVar(
"boardid", boardid) <<
LogVar(
"febno", febno) <<
LogVar(
"length", length) <<
LogVar(
"evtno", evtno));
309 rawdigit->
addFEB(feb, type, ver, boardid, febno, length, evtno, feb_trigno);
420 arichinfo->settrgtype(trgtype);
421 arichinfo->setpciedata(m_pciedata);
422 if (vth_thscan > -1.27) { arichinfo->setvth_thscan(vth_thscan); }
423 arichinfo->setntrack(0);
424 arichinfo->setnexthit(0);
425 arichinfo->setnhit(0);
427 { arichinfo->setthscan_mode(
true); }
429 { arichinfo->setthscan_mode(
false); }
439 for (
int i = 0; i < 4; i++) {
440 shift = (3 - ibyte % 4) * 8;
441 line1[3 - i] = buffer[ibyte / 4] >> shift;
445 head.
type = line1[3];
451 unsigned char len[4];
452 for (
int i = 0; i < 4; i++) {
453 shift = (3 - ibyte % 4) * 8;
454 len[3 - i] = buffer[ibyte / 4] >> shift;
458 unsigned seu = len[2];
462 uint32_t* tmp = (uint32_t*)len;
465 for (
int i = 0; i < 6; i ++) {
466 head.
SEU_FEB[i] = (seu & (1 << i)) != 0;
471 for (
int i = 0; i < 4; i++) {
472 shift = (3 - ibyte % 4) * 8;
473 trg[3 - i] = buffer[ibyte / 4] >> shift;
476 tmp = (uint32_t*)trg;
487 for (
int i = 0; i < 4; i++) {
488 shift = (3 - ibyte % 4) * 8;
489 line1[3 - i] = buffer[ibyte / 4] >> shift;
493 head.
type = line1[3];
499 unsigned char len[4];
500 for (
int i = 0; i < 4; i++) {
501 shift = (3 - ibyte % 4) * 8;
502 len[3 - i] = buffer[ibyte / 4] >> shift;
506 unsigned vth_info = len[3] * 256 + len[2];
507 if (vth_info >= 32768) { head.
thscan_mode =
true; vth_info -= 32768; }
512 uint32_t* tmp = (uint32_t*)len;
517 for (
int i = 0; i < 4; i++) {
518 shift = (3 - ibyte % 4) * 8;
519 trg[3 - i] = buffer[ibyte / 4] >> shift;
522 tmp = (uint32_t*)trg;
529 for (
int i = 0; i < bufferSize; i++) {
530 std::cout << i <<
"-th word bitset: " << std::bitset<32>(*(buffer + i)) << std::endl;
Class of ARICH raw digits.
void setCopperId(int id)
Set COPPER ID.
void setPcieChId(int id)
Set PCIe channel ID.
void setHslbId(int id)
Set HSLB ID.
void addFEB(FEBDigit &feb, int type, int ver, int boardid, int febno, unsigned int length, unsigned int trgno, unsigned int febtrgno)
Add properties of FEB.
void setPcieId(int id)
Set PCIe ID.
DBObjPtr< ARICHMergerMapping > m_mergerMap
mapping of modules to mergers
std::string m_outputarichinfoName
name of ARICHInfo store object
int m_rawmode
Activate Raw Unpacker.
std::string m_outputRawDigitsName
name of ARICHRawDigit store array
uint8_t m_bitMask
bitmask for hit detection (8bits/hit)
std::string m_outputDigitsName
name of ARICHDigit store array
int m_disable_unpacker
Disable regular Unpacker.
std::string m_inputRawDataName
name of RawARICH store array
unsigned int m_ibyte
bye index of raw unpacker
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...
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
bool create(bool replace=false)
Create a default object in the data store.
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.
Class to store variables with their name which were sent to the logging service.
unsigned int calbyte(const int *buf)
calculate number of bytes in raw Unpacker
ARICHUnpackerModule()
Constructor.
virtual void initialize() override
Initialize the Module.
#define ARICHFEB_HEADER_SIZE
FEB header size in bytes.
virtual void event() override
Event processor.
void printBits(const int *buffer, int bufferSize)
Unpack raw data given in production format.
void readHeader(const int *buffer, unsigned &ibyte, ARICHRawHeader &head)
Read Merger header.
void readFEHeader(const int *buffer, unsigned &ibyte, ARICHRawHeader &head)
Read FE header.
virtual ~ARICHUnpackerModule()
Destructor.
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.
Struct for front-end board.
void push_back(unsigned char ich, unsigned char val)
Add channel.