9 #include <pxd/modules/pxdHelper/PXDRawDumper.h>
10 #include <boost/format.hpp>
11 #include <boost/endian/arithmetic.hpp>
17 using ulittle16_t = boost::endian::little_uint16_t;
18 using ulittle32_t = boost::endian::little_uint32_t;
19 using ubig16_t = boost::endian::big_uint16_t;
20 using ubig32_t = boost::endian::big_uint32_t;
27 void PXDRawDumperModule::initialize(
void)
29 m_storeRaw.isRequired();
32 void PXDRawDumperModule::event(
void)
36 unsigned int pxdTriggerNr = 0x0, tag = 0x0;
37 for (
auto& it : m_storeRaw) {
38 if (getTrigNr(it, pxdTriggerNr, tag))
break;
41 if (pxdTriggerNr != 0x0 && tag != 0x0) {
43 static int nr1 = 1000, nr2 = 1000;
49 for (
auto& it : m_storeRaw) {
51 string name = boost::str(boost::format(
"%08X_%08X_%d.pxd.dump") % tag % pxdTriggerNr % i);
52 B2ERROR(
"PXDRawDumper: Dump to " << name);
53 fh = fopen(name.c_str(),
"wt+");
55 fwrite(it.data(), 4, it.size(), fh);
64 bool PXDRawDumperModule::getTrigNr(
RawPXD& px,
unsigned int& innerDHH,
unsigned int& tag)
70 if (px.
size() <= 0 || px.
size() > 16 * 1024 * 1024) {
71 B2ERROR(
"PXD Unpacker --> invalid packet size (32bit words) " << hex << px.
size());
74 std::vector<unsigned int> data(px.
size());
75 fullsize = px.
size() * 4;
76 std::copy_n(px.
data(), px.
size(), data.begin());
80 B2ERROR(
"Data is to small to hold a valid Header! Will not unpack anything. Size:" << fullsize);
84 if (data[0] != 0xCAFEBABE && data[0] != 0xBEBAFECA) {
85 B2ERROR(
"Magic invalid: Will not unpack anything. Header corrupted! " << hex << data[0]);
89 Frames_in_event = ((
ubig32_t*)data.data())[1];
90 if (Frames_in_event < 0 || Frames_in_event > 256) {
91 B2ERROR(
"Number of Frames invalid: Will not unpack anything. Header corrupted! Frames in event: " << to_string(Frames_in_event));
95 unsigned int* tableptr;
98 unsigned int* dataptr;
99 dataptr = &tableptr[Frames_in_event];
100 datafullsize = fullsize - 2 * 4 - Frames_in_event * 4;
103 for (
int j = 0; j < Frames_in_event; j++) {
107 B2ERROR(
"size of frame invalid: " << j <<
"size " << lo <<
" at byte offset in dataptr " << ll);
110 if (ll + lo > datafullsize) {
111 B2ERROR(
"frames exceed packet size: " << j <<
" size " << lo <<
" at byte offset in dataptr " << ll <<
" of datafullsize " <<
112 datafullsize <<
" of fullsize " << fullsize);
116 B2ERROR(
"SKIP Frame with Data with not MOD 4 length " <<
" ( $" << hex << lo <<
" ) ");
117 ll += (lo + 3) & 0xFFFFFFFC;
119 B2INFO(
"unpack DHE(C) frame: " << j <<
" with size " << lo <<
" at byte offset in dataptr " << ll);
120 if (unpack_dhc_frame(ll + (
char*)dataptr, innerDHH, tag))
return true;
127 bool PXDRawDumperModule::unpack_dhc_frame(
void* data,
unsigned int& innerDHH,
unsigned int& tag)
130 #define DHC_FRAME_HEADER_DATA_TYPE_DHC_START 0xB
131 #define DHC_FRAME_HEADER_DATA_TYPE_DHC_END 0xC
133 switch (((*(
ubig16_t*)data) & 0x7800) >> 11) {
134 case DHC_FRAME_HEADER_DATA_TYPE_DHC_START: {
135 unsigned int hi = ((
ubig16_t*)data)[2];
136 innerDHH = (hi << 16) | ((
ubig16_t*)data)[1];
virtual int * data(void)
get pointer to data
virtual int size() const
get size of buffer in 32 Bit words
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
boost::endian::big_uint32_t ubig32_t
define alias ubig32_t
boost::endian::big_uint16_t ubig16_t
define alias ubig16_t
Abstract base class for different kinds of events.