10#include <arich/modules/arichUnpacker/ARICHUnpackerModule.h>
12#include <arich/modules/arichUnpacker/ARICHRawDataHeader.h>
14#include <framework/core/ModuleManager.h>
17#include <framework/datastore/StoreArray.h>
18#include <framework/datastore/StoreObjPtr.h>
21#include <framework/logging/Logger.h>
24#include <framework/dataobjects/EventMetaData.h>
25#include <rawdata/dataobjects/RawARICH.h>
26#include <arich/dataobjects/ARICHDigit.h>
27#include <arich/dataobjects/ARICHInfo.h>
28#include <arich/dataobjects/ARICHRawDigit.h>
57 addParam(
"bitMask",
m_bitMask,
"hit bit mask (8 bits/channel, only used for unsuppresed format!)", (uint8_t)0xFF);
80 digits.registerInDataStore();
101 bool m_pciedata =
false;
103 double vth_thscan = 0.0;
106 std::cout << std::endl <<
"------------------------" << std::endl;
107 std::cout <<
"Run: " << evtMetaData->getRun() <<
" Event: " << evtMetaData->getEvent() << std::endl;
108 std::cout <<
"------------------------" << std::endl << std::endl;
111 unsigned thscan_mode = 0;
115 for (
auto& raw : rawData) {
117 if (raw.GetMaxNumOfCh(0) == 48) { m_pciedata =
true; }
118 else if (raw.GetMaxNumOfCh(0) == 4) { m_pciedata =
false; }
119 else { B2FATAL(
"ARICHUnpackerModule: Invalid value of GetMaxNumOfCh from raw data: " <<
LogVar(
"Number of ch: ", raw.GetMaxNumOfCh(0))); }
121 for (
int finesse = 0; finesse < raw.GetMaxNumOfCh(0); finesse++) {
122 const int* buffer = raw.GetDetectorBuffer(0, finesse);
123 int bufferSize = raw.GetDetectorNwords(0, finesse);
129 trgtype = raw.GetTRGType(0);
140 std::cout <<
"Merger header" << std::endl;
144 int type = (int)head.
type;
148 unsigned int length_all = (
unsigned int)head.
length;
149 unsigned int mrg_evtno = (
unsigned int)head.
trigger;
156 if (raw.GetNodeID(0) == 0x4000001) {
157 rawdigit->
setCopperId(raw.GetNodeID(0) + (int)(finesse / 4));
158 }
else if (raw.GetNodeID(0) == 0x4000002) {
159 rawdigit->
setCopperId(0x400000A + (
int)(finesse / 4));
161 B2FATAL(
"ARICHUnpackerModule: Invalid Node ID from readout: " <<
LogVar(
"NodeID: ", raw.GetNodeID(0)));
172 unsigned begin = ibyte;
174 while (ibyte < head.
length) {
184 B2ERROR(
"ARICHUnpackerModule: data in FEB header not consistent with data in merger HEADER " <<
LogVar(
"FEB ID",
197 if (mergID == 99) { B2ERROR(
"ARICHUnpackerModule: unknown merger number. Merger data will be skipped. " <<
LogVar(
"merger ID", mergID) <<
LogVar(
"Serial Number", (
unsigned)head.
mergerID));
break;}
201 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;}
204 if (
m_debug) std::cout <<
"Hit channels: " << std::endl;
205 if (febHead.
type == 1) {
206 for (
int i = 0; i < dataLen / 2; i++) {
207 int shift = (3 - ibyte % 4) * 8;
208 uint8_t asicCh = buffer[ibyte / 4] >> shift;
210 shift = (3 - ibyte % 4) * 8;
211 uint8_t hitBitSet = buffer[ibyte / 4] >> shift;
212 if (
m_debug && hitBitSet) std::cout <<
"ch: " << (unsigned)asicCh <<
" " << std::bitset<8>(hitBitSet) << std::endl;
214 digits.appendNew(moduleID, (
unsigned)asicCh, hitBitSet);
217 }
else if (febHead.
type == 2) {
218 unsigned asicCh = 143;
219 for (
int i = 0; i < dataLen; i++) {
220 int shift = (3 - ibyte % 4) * 8;
221 uint8_t hitBitSet = buffer[ibyte / 4] >> shift;
224 digits.appendNew(moduleID, asicCh, hitBitSet);
229 }
else B2ERROR(
"ARICHUnpackerModule: Unknown data type" <<
LogVar(
"type", febHead.
type));
233 if (ceil(ibyte / 4.) != (
unsigned)bufferSize)
234 B2WARNING(
"ARICHUnpackerModule: data buffer size mismatch " <<
LogVar(
"size from copper", bufferSize) <<
LogVar(
"size from merger",
241 if (thscan_mode == 0 &&
m_rawmode == 0)
continue;
248 int type_feb = febHead.
type;
253 vth_thscan = (febHead.
vth * 0.0024) - 1.27;
254 unsigned int length = febHead.
length;
256 unsigned int jbyte = 0;
257 std::stringstream ss;
258 ss <<
"type=" << type_feb <<
", ver=" << ver <<
" "
259 <<
", boardid=" << boardid <<
", febno=" << febno
260 <<
", length=" << length <<
", evtno=" << evtno <<
" ";
262 long long feb_trigno = 0;
263 for (
int i = 0; i < 10; i++) {
266 if (i > 1 && i < 6) {
267 feb_trigno |= (0xff & val) << (5 - i) * 8;
271 if (type_feb == 0x02) {
274 while (jbyte < length) {
278 ss <<
"ch# " << ch <<
"(" << val <<
") ";
280 if (febno < 0 || febno > 6) {
281 B2ERROR(
"FEB is bad : " <<
LogVar(
"FEB no.", febno) <<
LogVar(
"hslb", finesse) <<
LogVar(
"type", type_feb) <<
LogVar(
"ver",
282 ver) <<
LogVar(
"boardid", boardid) <<
LogVar(
"febno", febno) <<
LogVar(
"length", length) <<
LogVar(
"evtno", evtno));
289 }
else if (type_feb == 0x01) {
294 while (jbyte < length) {
300 ss <<
"ch# " << ch <<
"(" << val <<
") ";
302 if (febno < 0 || febno > 6) {
303 B2ERROR(
"FEB is bad : " <<
LogVar(
"FEB no.", febno) <<
LogVar(
"hslb", finesse) <<
LogVar(
"type", type_feb) <<
LogVar(
"ver",
304 ver) <<
LogVar(
"boardid", boardid) <<
LogVar(
"febno", febno) <<
LogVar(
"length", length) <<
LogVar(
"evtno", evtno));
311 rawdigit->
addFEB(feb, type, ver, boardid, febno, length, evtno, feb_trigno);
422 arichinfo->settrgtype(trgtype);
423 arichinfo->setpciedata(m_pciedata);
424 if (vth_thscan > -1.27) { arichinfo->setvth_thscan(vth_thscan); }
425 arichinfo->setntrack(0);
426 arichinfo->setnexthit(0);
427 arichinfo->setnhit(0);
429 { arichinfo->setthscan_mode(
true); }
431 { arichinfo->setthscan_mode(
false); }
441 for (
int i = 0; i < 4; i++) {
442 shift = (3 - ibyte % 4) * 8;
443 line1[3 - i] = buffer[ibyte / 4] >> shift;
447 head.
type = line1[3];
453 unsigned char len[4];
454 for (
int i = 0; i < 4; i++) {
455 shift = (3 - ibyte % 4) * 8;
456 len[3 - i] = buffer[ibyte / 4] >> shift;
460 unsigned seu = len[2];
464 uint32_t* tmp = (uint32_t*)len;
467 for (
int i = 0; i < 6; i ++) {
468 head.
SEU_FEB[i] = (seu & (1 << i)) != 0;
473 for (
int i = 0; i < 4; i++) {
474 shift = (3 - ibyte % 4) * 8;
475 trg[3 - i] = buffer[ibyte / 4] >> shift;
478 tmp = (uint32_t*)trg;
489 for (
int i = 0; i < 4; i++) {
490 shift = (3 - ibyte % 4) * 8;
491 line1[3 - i] = buffer[ibyte / 4] >> shift;
495 head.
type = line1[3];
501 unsigned char len[4];
502 for (
int i = 0; i < 4; i++) {
503 shift = (3 - ibyte % 4) * 8;
504 len[3 - i] = buffer[ibyte / 4] >> shift;
508 unsigned vth_info = len[3] * 256 + len[2];
509 if (vth_info >= 32768) { head.
thscan_mode =
true; vth_info -= 32768; }
514 uint32_t* tmp = (uint32_t*)len;
519 for (
int i = 0; i < 4; i++) {
520 shift = (3 - ibyte % 4) * 8;
521 trg[3 - i] = buffer[ibyte / 4] >> shift;
524 tmp = (uint32_t*)trg;
531 for (
int i = 0; i < bufferSize; i++) {
532 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.