20 : fData(nullptr), fBanksN(0), fBankList(nullptr), fAllocatedByUs(false)
131 if(
fData ==
nullptr) {
159 int status =
FindBank(name, &bklen, &bktype, pdata);
181 std::array<unsigned, 17> TID_SIZE = {0, 1, 1, 1, 2, 2, 4, 4, 4, 4, 8, 1, 0, 0, 0, 0, 0};
183 if(((pbkh->fFlags & (1 << 4)) > 0)) {
188 if(pbk32 ==
nullptr) {
192 if(name[0] == pbk32->
fName[0] && name[1] == pbk32->
fName[1] && name[2] == pbk32->
fName[2] &&
193 name[3] == pbk32->
fName[3]) {
195 if(TID_SIZE[pbk32->
fType & 0xFF] == 0) {
201 *bktype = pbk32->
fType;
208 if(name[0] == pbk->
fName[0] && name[1] == pbk->
fName[1] && name[2] == pbk->
fName[2] &&
209 name[3] == pbk->
fName[3]) {
211 if(TID_SIZE[pbk->
fType & 0xFF] == 0) {
217 *bktype = pbk->
fType;
220 pbk =
reinterpret_cast<TMidas_BANK*
>(
reinterpret_cast<char*
>(pbk + 1) + (((pbk->
fDataSize) + 7) & ~7));
221 }
while(
reinterpret_cast<char*
>(pbk) <
reinterpret_cast<char*
>(pbkh) + pbkh->fDataSize +
sizeof(
TMidas_BANK_HEADER));
239 std::cout <<
"Event start:" << std::endl;
251 std::cout <<
"Message event \"" <<
fData <<
"\"" << std::endl;
253 std::cout <<
"TMidasEvent::Print: Use SetBankList() before Print() to print bank data" << std::endl;
255 std::cout <<
"Banks: " <<
fBankList << std::endl;
257 for(
int i = 0; i <
fBanksN * 4; i += 4) {
260 void* pdata =
nullptr;
263 std::cout <<
"Bank " <<
fBankList[i] <<
fBankList[i + 1] <<
fBankList[i + 2] <<
fBankList[i + 3] <<
", length " << std::setw(6) << bankLength <<
", type " << bankType << std::endl;
266 if(strlen(option) > 1) {
267 highlight = atoi(option + 1);
270 if(option[0] ==
'a' && (found != 0)) {
273 for(
int j = 0; j < bankLength; j++) {
275 std::cout << ALERTTEXT << hex((reinterpret_cast<uint16_t*>(pdata))[j], 4) <<
RESET_COLOR << ((j % 10 == 9) ?
'\n' :
' ');
277 std::cout << hex((reinterpret_cast<uint16_t*>(pdata))[j], 4) << ((j % 10 == 9) ?
'\n' :
' ');
280 std::cout << std::endl;
283 for(
int j = 0; j < bankLength; j++) {
285 std::cout << ALERTTEXT << hex((reinterpret_cast<uint32_t*>(pdata))[j], 8) <<
RESET_COLOR << ((j % 10 == 9) ?
'\n' :
' ');
287 std::cout << hex((reinterpret_cast<uint32_t*>(pdata))[j], 8) << ((j % 10 == 9) ?
'\n' :
' ');
290 std::cout << std::endl;
293 for(
int j = 0; j < bankLength; j++) {
295 std::cout << ALERTTEXT << hex((reinterpret_cast<uint32_t*>(pdata))[j], 8) <<
RESET_COLOR << ((j % 10 == 9) ?
'\n' :
' ');
297 std::cout << hex((reinterpret_cast<uint32_t*>(pdata))[j], 8) << ((j % 10 == 9) ?
'\n' :
' ');
300 std::cout << std::endl;
303 for(
int j = 0; j < bankLength; j++) {
305 std::cout << ALERTTEXT << (reinterpret_cast<float*>(pdata))[j] <<
RESET_COLOR << ((j % 10 == 9) ?
'\n' :
' ');
307 std::cout << (reinterpret_cast<float*>(pdata))[j] << ((j % 10 == 9) ?
'\n' :
' ');
310 std::cout << std::endl;
313 for(
int j = 0; j < bankLength; j++) {
315 std::cout << ALERTTEXT << (reinterpret_cast<double*>(pdata))[j] <<
RESET_COLOR << ((j % 10 == 9) ?
'\n' :
' ');
317 std::cout << (reinterpret_cast<double*>(pdata))[j] << ((j % 10 == 9) ?
'\n' :
' ');
320 std::cout << std::endl;
323 std::cout <<
"TMidasEvent::Print: Do not know how to print bank of type " << bankType << std::endl;
364 char* pdata =
nullptr;
374 if(pmbk32 ==
nullptr) {
381 if(pmbk ==
nullptr) {
405 if(*pbk ==
nullptr) {
408 *pbk =
reinterpret_cast<TMidas_BANK*
>(
reinterpret_cast<char*
>(*pbk + 1) + ((((*pbk)->fDataSize) + 7) & ~7));
411 *pdata =
reinterpret_cast<char*
>((*pbk) + 1);
413 if(
reinterpret_cast<char*
>(*pbk) >=
428 if(*pbk ==
nullptr) {
431 uint32_t length = (*pbk)->fDataSize;
432 uint32_t length_adjusted = (length + 7) & ~7;
433 *pbk =
reinterpret_cast<TMidas_BANK32*
>(
reinterpret_cast<char*
>(*pbk + 1) + length_adjusted);
436 auto* bk4 =
reinterpret_cast<TMidas_BANK32*
>((
reinterpret_cast<char*
>(*pbk)) + 4);
438 if((*pbk)->fType > 17) {
439 if(bk4->fType <= 17) {
449 *pdata =
reinterpret_cast<char*
>((*pbk) + 1);
451 if(
reinterpret_cast<char*
>(*pbk) >=
reinterpret_cast<char*
>(event) + event->fDataSize +
sizeof(
TMidas_BANK_HEADER)) {
465#define QWORD_SWAP(x) \
468 _tmp = *((BYTE*)(x)); \
469 *((BYTE*)(x)) = *(((BYTE*)(x)) + 7); \
470 *(((BYTE*)(x)) + 7) = _tmp; \
471 _tmp = *(((BYTE*)(x)) + 1); \
472 *(((BYTE*)(x)) + 1) = *(((BYTE*)(x)) + 6); \
473 *(((BYTE*)(x)) + 6) = _tmp; \
474 _tmp = *(((BYTE*)(x)) + 2); \
475 *(((BYTE*)(x)) + 2) = *(((BYTE*)(x)) + 5); \
476 *(((BYTE*)(x)) + 5) = _tmp; \
477 _tmp = *(((BYTE*)(x)) + 3); \
478 *(((BYTE*)(x)) + 3) = *(((BYTE*)(x)) + 4); \
479 *(((BYTE*)(x)) + 4) = _tmp; \
484#define DWORD_SWAP(x) \
487 _tmp = *((BYTE*)(x)); \
488 *((BYTE*)(x)) = *(((BYTE*)(x)) + 3); \
489 *(((BYTE*)(x)) + 3) = _tmp; \
490 _tmp = *(((BYTE*)(x)) + 1); \
491 *(((BYTE*)(x)) + 1) = *(((BYTE*)(x)) + 2); \
492 *(((BYTE*)(x)) + 2) = _tmp; \
497#define WORD_SWAP(x) \
500 _tmp = *((BYTE*)(x)); \
501 *((BYTE*)(x)) = *(((BYTE*)(x)) + 1); \
502 *(((BYTE*)(x)) + 1) = _tmp; \
522 void* pdata =
nullptr;
533 if(pbh->
fFlags < 0x10000 && !force) {
572 type =
static_cast<uint16_t
>(pbk32->
fType);
584 pbk32 =
reinterpret_cast<TMidas_BANK32*
>(
reinterpret_cast<char*
>(pbk32 + 1) + (((pbk32->
fDataSize) + 7) & ~7));
588 pbk =
reinterpret_cast<TMidas_BANK*
>(
reinterpret_cast<char*
>(pbk + 1) + (((pbk->
fDataSize) + 7) & ~7));
597 pdata = (
reinterpret_cast<char*
>(pdata)) + 2;
606 pdata = (
reinterpret_cast<char*
>(pdata)) + 4;
612 pdata = (
reinterpret_cast<char*
>(pdata)) + 8;
std::string hex(T val, int width=-1)
bool IsBank32() const
returns "true" if event uses 32-bit banks
int IterateBank32(TMidas_BANK32 **, char **pdata) const
iterate through 32-bit data banks
TMidas_EVENT_HEADER * GetEventHeader()
return pointer to the event header
int fBanksN
number of banks in this event
int SetBankList()
create the list of data banks, return number of banks
void SetData(uint32_t size, char *data)
set an externally allocated data buffer
void Clear(Option_t *opt="") override
clear event for reuse
char * GetData() override
return pointer to the data buffer
void AllocateData()
allocate data buffer using the existing event header
const char * GetBankList() const
return a list of data banks
int IterateBank(TMidas_BANK **, char **pdata) const
iterate through 16-bit data banks
uint16_t GetEventId() const
return the event id
void Print(const char *option="") const override
show all event information
~TMidasEvent() override
destructor
uint32_t GetTimeStamp() const override
return the time stamp (unix time in seconds)
int FindBank(const char *name, int *bklen, int *bktype, void **pdata) const
TMidasEvent()
default constructor
TMidasEvent & operator=(const TMidasEvent &)
assignement operator
bool fAllocatedByUs
"true" if we own the data buffer
int LocateBank(const void *unused, const char *name, void **pdata) const
char * fData
event data buffer
uint32_t GetSerialNumber() const
return the serial number
uint16_t GetTriggerMask() const
return the triger mask
int SwapBytes(bool) override
convert event data between little-endian (Linux-x86) and big endian (MacOS-PPC)
TMidas_EVENT_HEADER fEventHeader
event header
bool IsGoodSize() const
validate the event length
uint32_t GetDataSize() const override
return the event size
void Copy(TObject &) const override
copy helper
char * fBankList
list of bank names in this event
void SwapBytesEventHeader()
convert event header between little-endian (Linux-x86) and big endian (MacOS-PPC)
void Clear(Option_t *="") override
clear event for reuse
uint32_t fDataSize
event size in bytes
uint16_t fTriggerMask
event trigger mask
uint16_t fEventId
event id
uint32_t fSerialNumber
event serial number
uint32_t fTimeStamp
event timestamp in seconds
char fName[4]
bank name // NOLINT(*-avoid-c-arrays)
char fName[4]
bank name // NOLINT(*-avoid-c-arrays)